MCP23017 I2C Device driver probe function is not c

2019-05-28 21:56发布

问题:

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.

回答1:

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.