简体   繁体   中英

Linux I2C kernel driver binding

I am learning about how to develop a Linux I2C kernel driver, and I learn from websites below.
How to instantiate I2C devices
I2C Driver for Linux Based Embedded System
...
Next, I found a sample that shows how to implement a I2C touchpad driver, but it really confused me .
linux/drivers/input/mouse/synaptics_i2c.c

My question is, how Linux kernel bind this driver to correctly device?
This driver don't provide 'detect' callback, no specify the I2C slave address via i2c_driver.address_list, and there is seems no anyone to call i2c_board_info to register the address info (I grep a whole Linux codebase).
I thought the driver MUST be specify the slave address or provide the 'detect' callback, just like
drivers/hwmon/adc128d818.c
or linux/drivers/rtc/rtc-ds1307.c (it will be register by i2c_board_info)

Please let me know what I missed, thanks.

The i2c device declaration is start from device tree.

Declare the i2c devices in device tree.

Example:

i2c1: i2c@400a0000 {
    /* ... master properties skipped ... */
    clock-frequency = <100000>;

    flash@50 {
        compatible = "atmel,24c256";
        reg = <0x50>;
    };

    pca9532: gpio@60 {
        compatible = "nxp,pca9532";
        gpio-controller;
        #gpio-cells = <2>;
        reg = <0x60>;
    };
};

Where,

1) 400a000 is a i2c bus address 2) pca9532 and flash are driver names 3) @50 and @60 are slave address 4) the attribute “compatible” to find and map device with the driver 5) other attribute which is inside cell of each entries are specific to the driver which will be used for device initialization during the probe

https://www.kernel.org/doc/Documentation/i2c/instantiating-devices

I finally figured out my question.
Refer to http://www.embedded-bits.co.uk/2009/i2c-in-the-2632-linux-kernel/
There is need to register my I2C device with i2c_new_probed_device() or i2c_new_device on Kernel to let it have a mapping table about slave address and device name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM