Linux加载i2c驱动

标签 linux driver i2c

我的主板上有 linux 4.4。我还有两个带有驱动程序的 i2c 设备。 当我将第一个设备连接到电路板时 - 我在 dmesg 中看到调用了 _probe 函数。 当我没有将任何设备连接到板上时 - 在 dmesg 中我看不到 _probe 函数。 当我连接第二个设备时 - 在 dmesg 中我看不到 _probe 函数。但我想看看。 如果我使用 i2cdetect 工具,我会看到正确的设备地址。驱动程序中的字段 .detect 未使用。我想在有第二个设备或没有设备的情况下在 dmesg 中看到 _probe 功能。

linux 如何检查连接的 i2c 设备以及它如何选择是否加载驱动程序?

这是我的设备树:

    i2c@546c0000 {
        #address-cells = <0x1>;
        #size-cells = <0x0>;
        compatible = "nvidia,tegra210-vii2c";
        reg = <0x0 0x546c0000 0x0 0x34000>;
        iommus = <0x52 0x12>;
        interrupts = <0x0 0x11 0x4>;
        scl-gpio = <0x7b 0x92 0x0>;
        sda-gpio = <0x7b 0x93 0x0>;
        status = "okay";
        clocks = <0x41 0xd0 0x41 0x51 0x41 0x1c>;
        clock-names = "vii2c", "i2cslow", "host1x";
        resets = <0x41 0xd0>;
        reset-names = "vii2c";
        clock-frequency = <0x61a80>;
        bus-pullup-supply = <0x69>;
        avdd_dsi_csi-supply = <0x67>;
        linux,phandle = <0xe0>;
        phandle = <0xe0>;

        newname_c@30 {
            compatible = "nvidia,newname";
            reg = <0x30>;
            devnode = "video0";
            physical_w = "3.674";
            physical_h = "2.738";
            vertical-flip = "true";
            avdd-reg = "vana";
            iovdd-reg = "vif";
            clocks = <0x41 0x117>;
            clock-names = "clk_out_3";
            clock-frequency = <0x16e3600>;
            mclk = "clk_out_3";
            reset-gpios = <0x7b 0x94 0x0>;
            pwdn-gpios = <0x7b 0x97 0x0>;
            vana-supply = <0x94>;
            vif-supply = <0x93>;
            status = "okay";
            linux,phandle = <0xe1>;
            phandle = <0xe1>;

最佳答案

在启动过程中,当内核解析设备树并到达您的设备节点时,它将查找具有 of_match_table 且其 compatible 条目之一的任何驱动程序匹配您节点的 compatible 属性。每个匹配的驱动程序都将被加载,它的 probe 函数将被运行,并根据您在节点中指定的(并包含)元素提供合适的 struct i2c_client 结构作为参数(我跳过了细节)。 因此,为了回答您的问题,Linux(实际上是 I2C 核心)检查任何连接的 i2c 设备。相应的设备驱动程序执行(通常在 probe 函数中,通常通过读取一个值预先已知的寄存器)。这就是为什么您必须提前声明您的设备。有a look here有关设备和驱动程序匹配以及模块自动加载的详细信息。

首先,请尝试确保内核中已启用对您的驱动程序的支持 使用以下命令进行配置:

zcat /proc/config.gz | grep <your_driver_kconfig_option>

您应该看到以 =y=m 结尾的内容。 现在,回到您的问题,有几个原因可能导致此方法不起作用:

  • 您的驱动程序未构建或未安装(如果构建为模块)
  • 驱动程序在其 of_match_table 中没有此兼容条目。你 可以尝试与驱动程序名称匹配(您节点的兼容值应与驱动程序代码中的 i2c_driver.driver.mame 元素相同)。这不是干净的,但可能有帮助。

PS:如果/proc/config.gz文件不存在,请先运行modprobe configs命令。

关于Linux加载i2c驱动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48053469/

相关文章:

c++ - 通过 I2C 增加传感器采样率

arduino - 如何将 i2c 连接到 arduino uno 上的 20x4 LCD 显示器上的背光调暗

linux - 如何为i2c传感器编写I2C设备驱动程序?

linux - 新的嵌入式项目;哪个 ARM CPU 对 Linux 的支持最好?

Linux 内核模块,创建后进先出设备

linux - OpenStack float IP 关联在底层是如何工作的?

python - pyodbc 与 DB2 的连接

linux - 如何在终端中添加一个 txt 文件而不在其中放入任何数据

android 建立 mysql 连接并获取一些数据

linux - ioctl 驱动程序函数是从 linux 2.6 下的原子上下文执行的吗?