简体   繁体   English

Linux I2C内核驱动程序绑定

[英]Linux I2C kernel driver binding

I am learning about how to develop a Linux I2C kernel driver, and I learn from websites below. 我正在学习如何开发Linux I2C内核驱动程序,并且可以从下面的网站中学习。
How to instantiate I2C devices 如何实例化I2C设备
I2C Driver for Linux Based Embedded System 用于基于Linux的嵌入式系统的I2C驱动程序
... ...
Next, I found a sample that shows how to implement a I2C touchpad driver, but it really confused me . 接下来,我找到了一个示例,该示例显示了如何实现I2C触摸板驱动程序, 但这确实让我感到困惑
linux/drivers/input/mouse/synaptics_i2c.c linux / drivers / input / mouse / synaptics_i2c.c

My question is, how Linux kernel bind this driver to correctly device? 我的问题是,Linux内核如何将该驱动程序绑定到正确的设备?
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). 该驱动程序不提供“检测”回调,也不通过i2c_driver.address_list指定I2C从设备地址,而且似乎没有人可以调用i2c_board_info来注册地址信息(我将其复制为整个Linux代码库)。
I thought the driver MUST be specify the slave address or provide the 'detect' callback, just like 我认为驱动程序必须指定从属地址或提供“检测”回调,就像
drivers/hwmon/adc128d818.c 驱动程序/hwmon/adc128d818.c
or linux/drivers/rtc/rtc-ds1307.c (it will be register by i2c_board_info) linux / drivers / rtc / rtc-ds1307.c (它将由i2c_board_info注册)

Please let me know what I missed, thanks. 请让我知道我错过了什么,谢谢。

The i2c device declaration is start from device tree. i2c设备声明从设备树开始。

Declare the i2c devices in device tree. 在设备树中声明i2c设备。

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 1)400a000是i2c总线地址2)pca9532和flash是驱动程序名称3)@ 50和@ 60是从机地址4)属性“兼容”以与驱动程序查找和映射设备5)其他属性位于驱动器的单元内每个条目都是特定于驱动程序的,将在探测期间用于设备初始化

https://www.kernel.org/doc/Documentation/i2c/instantiating-devices 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/ 请参阅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. 需要在内核上的i2c_new_probed_device()或i2c_new_device中注册我的I2C设备,以使其具有有关从站地址和设备名称的映射表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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