cristicsordas / raspi_robot

0 stars 0 forks source link

The PCF8591 and PCA9685 drivers cannot be both loaded #9

Closed cristicsordas closed 1 year ago

cristicsordas commented 1 year ago
  1. The address for the PCF8591 controller is 0x40. Using the instructions: "echo pca 0x40 > /sys/bus/i2c/devices/i2c-1/new_device" "/usr/bin/pca_load" (does a modprobe on the pca driver) the driver is loaded and works correctly.

The instruction "i2cdetect -y 1" shows this: 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: UU -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: 70 -- -- -- -- -- -- --

The logs displayed with dmesg shows that the driver was loaded by the kernel:

  1. The address for the PCA9685 controller is 0x48. Using the instructions: echo pca 0x48 > /sys/bus/i2c/devices/i2c-1/new_device /usr/bin/pcf_load (does a modprobe on the pcf driver) the driver PCF8591 fails to be loaded correctly. The logs from dmesg show this messages:

    • i2c i2c-1: new_device: Instantiated device pcf at 0x48
    • pcf8591: pcf_probe is entered on pcf8591
    • pcf8591: create elem 16 (log message sent by the function create_list() )
    • pcf: probe of 1-0048 failed with error -16.
  2. The following steps will make PCF8591 to work:

    • echo 0x48 > /sys/bus/i2c/devices/i2c-1/delete_device
    • echo 0x40 > /sys/bus/i2c/devices/i2c-1/delete_device
    • /usr/bin/pca_unload
    • /usr/bin/pcf_unload i2cdetect -y 1 displays this: 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: 70 -- -- -- -- -- -- --
    • echo pcf 0x48 > /sys/bus/i2c/devices/i2c-1/new_device
    • /usr/bin/pcf_load i2cdetect -y 1 displays this: 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: 40 -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: 70 -- -- -- -- -- -- -- message from dmesg: i2c i2c-1: new_device: Instantiated device pcf at 0x48 pcf8591: pcf_probe is entered on pcf8591 pcf8591: create elem 16 At this moment the PCF8591 is working correctly. The sensor controlled by the PCF8591 sends expected values. Now I try loading the PCA9685:
    • echo pca 0x40 > /sys/bus/i2c/devices/i2c-1/new_device
    • /usr/bin/pca_load
    • i2cdetect -y 1 show no changes
    • this is the message from dmesg: "i2c i2c-1: new_device: Instantiated device pca at 0x40 pca9685: pca_probe is entered on pca9685 pca: probe of 1-0040 failed with error -16"
      Now pcf is working and pca not. Error -16 means that the driver is BUSY, but there is no driver loaded for that address.

The commit for the PCF8591 driver implementation is here: https://github.com/cristicsordas/raspi_robot/commit/02bb8846b8c3149c107f66bfd4882cf4726fda03#diff-b0ee59f04a5847d2756ac57c330b08528eec445c6fbb8f4634928bc96391a4c9

The commit for the PCA9685 implementation is here: https://github.com/cristicsordas/raspi_robot/commit/08700a4a0fc44f712919389077988b5f2b3dcf16

dwalkes commented 1 year ago

@cristicsordas I'd look into why misc_register can/does return EBUSY. Based on https://github.com/torvalds/linux/blob/4b810bf037e524b54669acbe4e0df54b15d87ea1/drivers/char/misc.c#L233 it looks like one way this would happen would be due to a minor number conflict. Can you prove this isn't happening?

cristicsordas commented 1 year ago

@dwalkes I changed the minor version of the pcf driver. Now they can both be loaded. Thank you

cristicsordas commented 1 year ago

fixed with the commit d7681b09dbf7f67b6ea0f54f48d215e4724b0bc9