jicku
Posts: 3
Joined: Mon Jun 17, 2019 8:27 am

Device tree overlays and i2c_vc

Mon Jun 17, 2019 9:01 am

I am working on a project that uses a CM3 on a custom carrier board. The designers of the board have decided to put the i2c devices on the i2c_vc (or i2c0) bus. My problem comes in when I try to use the default overlays with slight modifications, for example the i2c-rtc overlay with the target property changed to <&i2c_vc>. I assume using an overlay modified like that and used like "dtoverlay=i2c_vc-rtc,ds1307" in the config.txt should result in the loading of kernel module rtc_ds1307 at boot. Instead I get no effect. These changes were done on a freshly flashed Raspbian.

Here are the relevant lines from config.txt:

Code: Select all

...
dtparam=i2c_arm=on
dtparam=i2c_vc=on
dtoverlay=i2c_vc-rtc,ds1307
...
Here is the output of i2cdetect -y 0 before and after adding the dtoverlay to config.txt (no effect):

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- 6c -- -- --
70: -- -- -- -- -- -- -- --
And the relevant output from vcdbg log msg:

Code: Select all

...
002775.424: dtparam: i2c_vc=on
002845.731: brfs: File read: 1116 bytes
002853.588: brfs: File read: /mfs/sd/overlays/i2c_vc-rtc.dtbo
002875.044: Loaded overlay 'i2c_vc-rtc'
002875.098: dtparam: ds1307=true
004150.214: Device tree loaded to 0x2eff9b00 (size 0x6450)
...
That small edit seemed too easy, so I'm not suprised it's not working :D I think I don't understand the whole device tree concept well enough. Is there something more to this than just editing the target property of the default overlay?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6876
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Device tree overlays and i2c_vc

Mon Jun 17, 2019 9:49 am

Changing the target from <&i2c_arm> to <&i2c_vc> in all the fragments, recompiling, and copying to /boot/overlays, should be sufficient.

Check the output of dmesg for any evidence of issues when probing the rtc. "vcdbg log msg" will only give information from the firmware as it merges the DT fragment in, whilst dmesg is the kernel having parsed the DT and trying to load the drivers.

You can also have a look at the running device tree via /proc/device-tree. For i2c-0 you'll be wanting to look under /proc/device-tree/soc/[email protected] You should get a [email protected] directory under there with any properties you configured.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jicku
Posts: 3
Joined: Mon Jun 17, 2019 8:27 am

Re: Device tree overlays and i2c_vc

Mon Jun 17, 2019 10:55 am

Output of dmesg has nothing related to loading of the device driver or any errors related to this. The [email protected] directory does get created under /proc/device-tree/soc/[email protected], but still no kernel modules loaded :? Does this atleast mean that the overlay is successfully applied to the device tree?

Loading the rtc_ds1307 module with modprobe does work and I can access the rtc via the hwclock program. This is what should happen automagically via adding the overlay, correct?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6876
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Device tree overlays and i2c_vc

Mon Jun 17, 2019 11:18 am

Check "/proc/device-tree/soc/[email protected]/[email protected]/status" is "okay", and "/proc/device-tree/soc/[email protected]/[email protected]/compatible" is "maxim,ds1307".

Bells are ringing for me now. https://github.com/raspberrypi/linux/issues/2989, however I don't think that is the condition here.
"modinfo ds1307" is returning "of:N*T*dallas,ds1307", not "maxim,ds1307".
I think a combination of "7ef6d2c rts: ds1307: Add OF device ID table" and "af50371 i2c: core: report OF style module alias for devices registered via OF" has changed the compatible name.

In the overlay, try swapping "maxim,ds1307" for "dallas,ds1307", and hopefully it'll find the right thing.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jicku
Posts: 3
Joined: Mon Jun 17, 2019 8:27 am

Re: Device tree overlays and i2c_vc

Mon Jun 17, 2019 12:14 pm

Yep, that fixed it. rtc_ds1307 gets loaded at boot and everything works, many thanks. What was the problem here exactly though? Was it simply a mismatch between the compatible string and the aliases of the kernel module? This is probably fixed in newer versions since the default i2c-rtc overlay wouldn't work either?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6876
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Device tree overlays and i2c_vc

Mon Jun 17, 2019 1:36 pm

jicku wrote:
Mon Jun 17, 2019 12:14 pm
What was the problem here exactly though? Was it simply a mismatch between the compatible string and the aliases of the kernel module? This is probably fixed in newer versions since the default i2c-rtc overlay wouldn't work either?
Yes, it's a simple mismatch on the compatible string. I'm not quite sure where the maxim prefix had come from as it's not apparently in the bindings at all.

I'm not the DT expert, but that other issue reminded me that there had been a change with 4.19 to the DT parsing for I2C devices. That nudged me to look at the commit history for rtc-ds1307, and there was the answer in the manufacturer string.
The i2c-rtc overlay won't work for DS1307 either and needs patching - that should get done in the next few days.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6876
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Device tree overlays and i2c_vc

Mon Jun 17, 2019 1:52 pm

Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Interfacing (DSI, CSI, I2C, etc.)”