【问题标题】:Change I2C address Linux driver kernel更改 I2C 地址 Linux 驱动内核
【发布时间】:2016-04-23 09:04:14
【问题描述】:

我有一个系统,它使用模块传感器 LM75 和两个 I2C 地址(0x48 和 0x49)。我想取消一个地址(0x48),但是我不明白它的初始化在哪里。

normal_i2c 中的所有更改都不相关....

/* Addresses scanned */
static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
                    0x4d, 0x4e, 0x4f, I2C_CLIENT_END };

【问题讨论】:

  • 你的帖子被删了吗?似乎缺少有关该 normal_i2c 的信息(它来自哪里?)。你已经尝试过什么?
  • normal_i2c[] - 它是 lm75.c 中的数组。我认为驱动程序从这个数组中获取 i2c 地址。但这是不对的。

标签: c linux-kernel linux-device-driver i2c


【解决方案1】:

驱动程序lm75.c 将自己注册到内核,作为所有 i2c 设备的处理程序,这些设备具有normal_i2c 数组中列出的任何 7 位地址。

/* Addresses scanned */
static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
0x4d, 0x4e, 0x4f, I2C_CLIENT_END };

接下来,数组是pointed to by struct lm75_driveri2c_driver 类型)

.address_list   = normal_i2c,

另请注意,i2c_driver 结构的 classdetect 成员已正确初始化

.class          = I2C_CLASS_HWMON,
.detect         = lm75_detect,
  • .class 的各种选项已列出here
  • .detect 是一个在初始化新 i2c-bus 或 i2c-driver 时调用的函数。

当驱动程序向 Linux 内核注册时,this i2c_driver struct is passed on to the Linux kernel(带有与该驱动程序关联的 i2c 地址列表)。

module_i2c_driver(lm75_driver);

在运行时,接下来发生的事情总结在以下调用图中:

i2c_register_driver()

__process_new_adapter()

i2c_do_add_adapter()

i2c_detect()

lm75_detect() 使用driver->detect()调用

lm75_detect() 函数包含特定于设备的逻辑,用于确定在当前 i2c 总线上检测到的 i2c 设备是否应由当前驱动程序(在本例中为 lm75.c)处理。

对于自动设备检测,必须同时定义 detectaddress_listclass 也应该设置,否则会创建强制使用模块参数的设备。

检测函数必须至少填写成功检测到的i2c_board_info 结构的名称字段,还可能还填写flags 字段。

【讨论】:

  • 嗨,我在 i2c 总线上有一块带有 TMP75 温度传感器的板,由 lm75 驱动程序处理。它位于地址 0x4a。我正在加载驱动程序并且它正在加载但它没有检测到设备。在 /sys/bus/i2c/drivers/lm75/ 中,我只看到以下文件/文件夹:bindmoduleueventunbind。我没有看到任何其他可能存在 temp_input 等设备属性的条目。不知道如何进一步调试..
猜你喜欢
  • 2017-07-18
  • 1970-01-01
  • 2016-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-19
  • 2016-02-08
相关资源
最近更新 更多