1

Hello I am looking at this documentation. https://www.kernel.org/doc/html/v4.11/driver-api/i2c.html My goal is simply to write some data to an EEPROM using an I2C bus. I am a bit confused on which functions to use and how to populate the structures that are needed for those functions. My guess is that I will need to create an i2c_client to represent the EEPROM. I have the location of the EEPROM from this device tree.

&i2c0 {
    status = "okay";
    clock-frequency = <400000>;
    pinctrl-names = "default";

    i2cswitch@74 {
        compatible = "nxp,pca9548";
        #address-cells = <1>;
        #size-cells = <0>;
        reg = <0x74>;

        i2c@2 {
            #address-cells = <1>;
            #size-cells = <0>;
            reg = <2>;
            eeprom@54 {
                compatible = "at,24c08";
                reg = <0x54>;
            };
        };
    };
};

How would I go about filling the i2c_client struct with this data?

Then I am guessing I would use this function

int i2c_master_send(const struct i2c_client * client, const char * buf, int count)

And provid it the client struct and a string that I want to write as well as the length of that string with the stipulation it is less than 64k. In this case the CPU is the master?

What header files will I need to included to use the functions and structs that are provided by the documentation?

Thanks.

John Frye
  • 255
  • 6
  • 22
  • Since the EEPROM in that device tree has a "compatible" string that matches the "at24" driver (drivers/misc/eeprom/at24.c), you could use the NVMEM framework to access the EEPROM contents. See "4. Direct NVRAM device based consumer APIs" in "Documentation/nvmem/nvmem.txt" for the API, and "Documentation/devicetree/bindings/nvmem/nvmem.txt" for the device tree bindings. I think your device tree node will just need the "nvmem" property containing a device tree phandle to the EEPROM devicetree node, and a "nvmem-names" property to supply a name that your driver will use to get the NVMEM device. – Ian Abbott Nov 07 '17 at 16:45
  • I had used i2c-dev driver? how do you know which drivers are best for which apps? – John Frye Nov 07 '17 at 16:54
  • The i2c-dev driver provides userspace access to the I2C adapter and allows you to bypass the I2C client drivers, so you'd have to be careful not to screw things up. You should be able to access the EEPROM contents from userspace without going anywhere near I2C in your code. See "6. Userspace binary interface" in the NVMEM documentation. (You need to configure the kernel appropriately of course, e.g. `CONFIG_EEPROM_AT24` for the "at24" driver.) – Ian Abbott Nov 07 '17 at 17:16
  • I will take a look. My question is then, how does one figure out which driver is the best for the job? do most device vendors supply their own Linux drivers that can be included in a kernel build if specified in the configs? – John Frye Nov 07 '17 at 18:31

0 Answers0