user_2019
Posts: 6
Joined: Wed Aug 14, 2019 9:13 pm

I2C client driver instantiation using Device Tree - probe did not get called

Wed Aug 14, 2019 9:26 pm

I am writing a sample and simple i2c driver in which I am trying to instantiate the
i2c client device using device tree overlay. I have got some DTE overlay sample which i have complied to .dtbo and placed it in /boot/overlays directory and also updated the /boot/config.txt followed by system reboot.

Now when I load the module the probe method does not get called. The i2c_add_driver() returns 0. I am doing nothing but just printing a message in the probe function. I am not sure if the problem is with the DTE overlay i am using. Please help.

Since I am not manipulating the real device and just printing the messages so in that case can i use any "i2c compatible" DTE entry which is already present in the system and see if that matches and probe function gets called ? This is to confirm if the problem is with the DTE overlay and not with my driver module ?

Platform - RPI 3B+, Raspbian

The DTE overlay i have used:

/dts-v1/; /plugin/;

/ {

fragment@0 {
target = <&i2c_arm>;
__overlay__ {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;

sampledev {
compatible = "i2c-eeprom";
};
};
};
2019-08-15-021301_1920x1080_scrot.png
driver code
2019-08-15-021301_1920x1080_scrot.png (149.58 KiB) Viewed 583 times
Thanks in advanced!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2279
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C client driver instantiation using Device Tree - probe did not get called

Thu Aug 15, 2019 9:00 am

The I2C subsystem manages one or more buses, with devices on those buses having 7-bit addresses. This organisation is replicated in the Device Tree for I2C. The "#address-cells = <1>;" property tells Device Tree parsing tools that subnodes there should have a one-word address, where that address appears as a "reg" property of the subnode and as the part of the name of that subnode after an "@" (although the naming part is more of a convention than an absolute requirement - uniqueness is sufficient).

When the I2C bus is registered with the framework, it walks through all of the subnodes, trying to parse them as valid declarations of I2C devices. Your overlay (apart from missing the final closing "};") defines a subnode with no "reg" property, which causes the kernel to log an error:

Code: Select all

 $ dmesg -l err
[    4.962014] i2c i2c-1: of_i2c: invalid reg on /soc/i2c@7e804000/sampledev
[    4.962033] i2c i2c-1: Failed to create I2C device for /soc/i2c@7e804000/sampledev
...
Adding a "reg" property will get you further:

Code: Select all

/dts-v1/;
/plugin/;

/ {
        fragment@0 {
                target = <&i2c_arm>;
                __overlay__ {
                        status = "okay";
                        #address-cells = <1>;
                        #size-cells = <0>;

                        sampledev@10 {
                                compatible = "i2c-eeprom";
                                reg = < 0x10 >;
                        };
                };
        };
};
(I've include the address in the node name to get you into good habits)
This will allow the I2C device parsing to succeed. You can monitor your progress by loading the overlay at runtime (not from config.txt) while monitoring udev activity.

In one window:

Code: Select all

$ sudo udevadm monitor -k -p -u
And in another:

Code: Select all

sudo dtoverlay myoverlayname
The udevadm output will include the device address and compatible string. Provided your module has the correct compatible string and is registered correctly it should get as far as your probe function. At some point after that it will become important that you have a device on the bus with the expected address, most of the work has been done.

user_2019
Posts: 6
Joined: Wed Aug 14, 2019 9:13 pm

Re: I2C client driver instantiation using Device Tree - probe did not get called

Thu Aug 15, 2019 12:55 pm

Thanks for your response!

I have updated the right <reg> value (0x50) since my RPI connected to the EEPROM at i2c address 0x50.
But the probe still does not get invoked. I have already defined i2c_device_id register in the driver with the "i2c-eeprom" compatible string but it does not match.

Below is the output from the udevadm command when module is loaded.

onitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[100.669322] add /module/i2c_eeprom_client (module)
ACTION=add
DEVPATH=/module/i2c_eeprom_client
SUBSYSTEM=module
SEQNUM=1361

KERNEL[100.674114] add /bus/i2c/drivers/i2c_eeprom_dev (drivers)
ACTION=add
DEVPATH=/bus/i2c/drivers/i2c_eeprom_dev
SUBSYSTEM=drivers
SEQNUM=1362

UDEV [100.678364] add /module/i2c_eeprom_client (module)
ACTION=add
DEVPATH=/module/i2c_eeprom_client
SUBSYSTEM=module
SEQNUM=1361
USEC_INITIALIZED=100677865

UDEV [100.681606] add /bus/i2c/drivers/i2c_eeprom_dev (drivers)
ACTION=add
DEVPATH=/bus/i2c/drivers/i2c_eeprom_dev
SUBSYSTEM=drivers
SEQNUM=1362
USEC_INITIALIZED=100681126


And below is the output of the udevadm command when dtoverlay ran.

monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[221.797424] add /devices/platform/soc/3f804000.i2c/i2c-1/1-0050 (i2c)
ACTION=add
DEVPATH=/devices/platform/soc/3f804000.i2c/i2c-1/1-0050
SUBSYSTEM=i2c
OF_NAME=sampledev
OF_FULLNAME=/soc/i2c@7e804000/sampledev@50
OF_COMPATIBLE_0=i2c-eeprom
OF_COMPATIBLE_N=1
MODALIAS=of:NsampledevT<NULL>Ci2c-eeprom
SEQNUM=1363

KERNEL[221.797837] bind /devices/platform/soc/3f804000.i2c/i2c-1/1-0050 (i2c)
ACTION=bind
DEVPATH=/devices/platform/soc/3f804000.i2c/i2c-1/1-0050
SUBSYSTEM=i2c
DRIVER=i2c_eeprom_dev
OF_NAME=sampledev
OF_FULLNAME=/soc/i2c@7e804000/sampledev@50
OF_COMPATIBLE_0=i2c-eeprom
OF_COMPATIBLE_N=1
MODALIAS=of:NsampledevT<NULL>Ci2c-eeprom
SEQNUM=1364

UDEV [221.892974] add /devices/platform/soc/3f804000.i2c/i2c-1/1-0050 (i2c)
ACTION=add
DEVPATH=/devices/platform/soc/3f804000.i2c/i2c-1/1-0050
SUBSYSTEM=i2c
OF_NAME=sampledev
OF_FULLNAME=/soc/i2c@7e804000/sampledev@50
OF_COMPATIBLE_0=i2c-eeprom
OF_COMPATIBLE_N=1
MODALIAS=of:NsampledevT<NULL>Ci2c-eeprom
SEQNUM=1363
USEC_INITIALIZED=221803285
DRIVER=i2c_eeprom_dev

UDEV [221.939567] bind /devices/platform/soc/3f804000.i2c/i2c-1/1-0050 (i2c)
ACTION=bind
DEVPATH=/devices/platform/soc/3f804000.i2c/i2c-1/1-0050
SUBSYSTEM=i2c
DRIVER=i2c_eeprom_dev
OF_NAME=sampledev
OF_FULLNAME=/soc/i2c@7e804000/sampledev@50
OF_COMPATIBLE_0=i2c-eeprom
OF_COMPATIBLE_N=1
MODALIAS=of:NsampledevT<NULL>Ci2c-eeprom
SEQNUM=1364
USEC_INITIALIZED=221895640


Thanks!

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2279
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C client driver instantiation using Device Tree - probe did not get called

Thu Aug 15, 2019 1:01 pm

That's looking good so far. The problem is likely to be in the mapping from the compatible string to your module, via the module alias. Can you run modinfo on your module .ko file and:

Code: Select all

pi@raspberrypi:~$ grep eeprom /lib/modules/`uname -r`/modules.alias
?


PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2279
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C client driver instantiation using Device Tree - probe did not get called

Thu Aug 15, 2019 1:38 pm

And did you run modinfo on your module .ko file?

user_2019
Posts: 6
Joined: Wed Aug 14, 2019 9:13 pm

Re: I2C client driver instantiation using Device Tree - probe did not get called

Thu Aug 15, 2019 7:58 pm

Below is the output of modinfo:

filename: /home/pi/i2c_eeprom_client.ko
license: GPL
srcversion: AC36BDB1094FE8C563ED2B3
alias: i2c:i2c-eeprom
depends:
name: i2c_eeprom_client
vermagic: 4.19.58-v7+ SMP mod_unload modversions ARMv7 p2v8

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2279
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C client driver instantiation using Device Tree - probe did not get called

Thu Aug 15, 2019 9:44 pm

You need to run sudo depmod to register the aliases (amongst other things).

user_2019
Posts: 6
Joined: Wed Aug 14, 2019 9:13 pm

Re: I2C client driver instantiation using Device Tree - probe did not get called

Fri Aug 16, 2019 8:54 am

I have executed depmod to resolve dependencies but the command did not work as expected.

I have posted the problem here:

https://raspberrypi.stackexchange.com/q ... ing-depmod

user_2019
Posts: 6
Joined: Wed Aug 14, 2019 9:13 pm

Re: I2C client driver instantiation using Device Tree - probe did not get called

Fri Aug 16, 2019 11:01 am

Can you explain the steps on what has to be done to fix the problem ?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2279
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C client driver instantiation using Device Tree - probe did not get called

Fri Aug 16, 2019 11:35 am

Show the output from running "sudo depmod" - I'm not interested in what you've already done. You should probably manually copy your module somewhere within /lib/modules/`uname -r`/ first.

Return to “Device Tree”