This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

kernel and i2c write command

Does someone an example of write on i2c into kernel. I'm trying to write in a i2c peripheral in kernel start sequence, file: board_am335xevm.c 

I tried i2c_master_send function but I'm confuse about what puts in the first parameter of the function. Where get the it.

thanks in advanced.

  • Hi Daniel,

    I will forward this to the Linux experts.

  • Hi Daniel,

    The first parameter of i2c_master_send() function is basically just a handle to the slave device, pointer to i2c_client structure.

    Detailed explanation of i2c_client structure can be found in include/linux/i2c.h file (bellow explanation is taken from sources for AM57xx, but this is a general rule and should be very similar in the AM335x sources):


     * struct i2c_client - represent an I2C slave device
     * @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address;
     *    I2C_CLIENT_PEC indicates it uses SMBus Packet Error Checking
     * @addr: Address used on the I2C bus connected to the parent adapter.
     * @name: Indicates the type of the device, usually a chip name that's
     *    generic enough to hide second-sourcing and compatible revisions.
     * @adapter: manages the bus segment hosting this I2C device
     * @driver: device's driver, hence pointer to access routines
     * @dev: Driver model device node for the slave.
     * @irq: indicates the IRQ generated by this device (if any)
     * @detected: member of an i2c_driver.clients list or i2c-core's
     *    userspace_devices list
     *
     * An i2c_client identifies a single device (i.e. chip) connected to an
     * i2c bus. The behaviour exposed to Linux is defined by the driver
     * managing the device.

    The structure should be populated upon registering of the I2C functionality of the slave device.

    Hope this helps you.

    Best Regards,

    Yordan

  • Ok Yordan, I see this information, but that is not enough. I tried many ways to write in i2c. To use the drive, I need the correct client struct memory pointer. As you can see it is necessary in functions like: 

      int ret = i2c_master_send( &client, value, 4);

    or 

    s32 i2c_smbus_write_byte(const struct i2c_client *client, u8 value)

     

    I tried unsuccesfull recover client pointer with the bellow code:

    adapter = i2c_get_adapter(i2c_instance); // in my case i2c_instance could be 1, 2, or 3.
    client.adapter = adapter;
    client.addr = 0x70;  // the bus adress of my component linked to i2c-2
    client.flags = I2C_M_TEN;

    I attached the file board-am335xevm.c  that has backlinght_on function were is the above code. In the same file is the definition of the component attached to i2c-2. It works very well in linux user space, but in kernel space I can't communicate with it.

    check by:

    static struct i2c_board_info am335x_i2c2_boardinfo[]

    I tried to write in u-boot, even with no success. At board.c file:

    //df db
    {
       udelay(9999999);
       uchar data[] = { 0xFF, 0XFF, 0XCF, 0X00};
       int ret = i2c_write(0X70, 0, 0, data, 4); /// it was tried bus 0,1,2 and 3.
       if( ret!=0 )
            puts("\n\n ---------------------> ERROR \n\n");
       else
            puts("\n\n ---------------------> DISPLAY OK\n\n");
    }

    Is in u-boot possible to write in i2c different of 0? attached are board.c and mux.c of u-boot

    do you have an alternative?

    0250.fonts.zip