未调用MCP23017 I2C设备驱动程序探针功能 [英] MCP23017 I2C Device driver probe function is not called

查看:650
本文介绍了未调用MCP23017 I2C设备驱动程序探针功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下I2C/GPIO 设备驱动程序访问MCP23017 GPIO.使用insmod命令,我可以加载驱动程序及其在/proc/modules中列出的驱动程序.我有两个MCP23017芯片连接到我的Raspberry Pi.两者都在地址0x200x21处检测到.对驱动程序的initcall会注册驱动程序.我通过打印一条消息检查了这一点.但是不会调用驱动程序探测函数.设备未打开/无法在其他位置放置.

  1. 如何调用探测函数?
  2. 是否应手动进行探测以找到设备?
  3. probe呼叫类似于open呼叫吗?
  4. 我尝试使用此echo mcp23017 0x20 > new_device手动创建具有该地址的新设备.但是它没有用.我收到以下消息:Driver 'mcp23s08' is already registered, aborting...

任何帮助将不胜感激.

当驱动程序与设备树中的设备描述匹配时,将调用

解决方案

probe()函数.当在设备树中找到驱动程序的兼容字段时发生(对于驱动程序,该字符串为"microchip,mcp23017"字符串).

显然,您没有在设备树中描述您的设备(MCP23017),这就是为什么未调用probe()的原因.您可以加载相应的设备树覆盖图以解决此问题.您在评论中指出的一个正确的.在此处详细了解.

您可以尝试按照该文章中的说明加载叠加层:

$ sudo dtoverlay mcp23017.dtbo

或者您可以尝试为此目的使用 Capemgr .就我个人而言,我没有尝试过任何一种方法,因此您应该查看哪种方法最适合您.

更新

在评论中回复您的问题.

但是当我尝试使用i2cdetect命令时,它会显示UU.

请参见 man i2cdetect .因此,"UU"表示i2cdetect跳过了探测,因为驱动程序已经使用了位于您指定地址的设备.我猜它符合您的意图,没关系.

使用rmmod mcp23017命令,我看到设备仍在设备下,但i2cdetect显示0x20

因此,您卸载了驱动程序,现在i2cdetect显示0x20地址上有某些设备.我猜这是正确的行为.另外,如果您想完全摆脱设备的麻烦,请尝试卸载DT覆盖层以及驱动程序.

我还连接了两个MCP23017芯片.但是我只能在0x20下的devices下看到该设备.尽管驱动程序说它最多支持8个芯片

,但仍未检测到0x21处的I2C芯片.

我可以看到导致此问题的两种可能原因.

  1. DT覆盖仅具有地址为0x20的设备的描述,而缺少地址为0x21的设备的描述.在这种情况下,您应该找到DT叠加层的来源,为其余设备添加说明,编译修改后的DT叠加层,然后加载它,而不是预先构建的DT叠加层.
  2. 可以将所有设备配置为使用0x20地址.有关详细信息,请参见 MCP23017 数据表中的1.4 Hardware Address Decoder部分.检查芯片上的A0A1A2引脚.

I am using the following I2C/GPIO Device driver to access the MCP23017 GPIOs. With the insmod command I am able to load the driver and its listed in /proc/modules. I have two MCP23017 chips connected to my Raspberry Pi. Both are detected at addresses 0x20 and 0x21. The initcall to the driver registers the driver. I checked this by printing out a message. But the driver probe function is not called. The devices are not opened/ cannot be located elsewhere.

  1. How is the probe function called?
  2. Should the probe be done manually to locate the devices?
  3. Is the probe call similar to the open call?
  4. I tried this echo mcp23017 0x20 > new_device to manually create a new device with the address. But it didnt work. I got the followin message: Driver 'mcp23s08' is already registered, aborting...

Any help would be appreciated.

解决方案

probe() function is called when driver is matched with your device description in Device Tree. Matching happens when compatible field of your driver found in Device Tree (for your driver it's "microchip,mcp23017" string).

Apparently you don't have your device (MCP23017) described in Device Tree, that's why probe() is not called. You can load corresponding Device Tree Overlay to overcome this issue. The one you pointed out in your comment seems to be correct. Read more about loading overlays in Raspberry Pi ecosystem here.

You can try to load your overlay like described in that article:

$ sudo dtoverlay mcp23017.dtbo

Or you can try to use Capemgr for this purpose. Personally I didn't try any of those, so you should look which works for you best.

Update

Replying to your questions in comments.

But when I try the i2cdetect command it shows UU.

See man i2cdetect. So "UU" means that i2cdetect skipped probing because device at the address you specified is already used by driver. I guess it what you intended, so it's ok.

With a rmmod mcp23017 command I see the device still under devices but i2cdetect shows 0x20

So you unloaded the driver and now i2cdetect shows you that there is some device on 0x20 address. I guess it's correct behavior. Also if you want to get rid completely of your device -- try to unload DT overlay along with driver.

Also I have connected two MCP23017 chips. But I can see only the device at 0x20 under devices. The I2C chip at 0x21 is still not detected, though the driver says it supports up to 8 chips

I can see two possible causes to this issue.

  1. DT overlay only has description for device with 0x20 address, but missing description for device with 0x21 address. If this is the case, you should find sources for your DT overlay, add description for rest of your devices, compile that modified DT overlay and then load it instead of pre-built one.
  2. All devices may be configured for using 0x20 address. See section 1.4 Hardware Address Decoder in MCP23017 datasheet for details. Check A0, A1, A2 pins on your chips.

这篇关于未调用MCP23017 I2C设备驱动程序探针功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆