stardustJerry
Posts: 7
Joined: Mon Apr 04, 2016 11:11 pm

i2c-gpio dtoverlay bus number

Thu Feb 15, 2018 9:31 pm

(I originally posted this in the o/s Raspbian section, but I think it goes here. Sorry about that.)

I need to add 2 additional gpio buses. I'm using the usual i2c for a port expander and also need to read/write two different external eeproms that need to be plugged in on different pins.

Adding a line in config.txt like this only works once and the bus is always #3.
dtoverlay=i2c_gpio,i2c_gpio_sda=27,i2c_gpio_scl=22

After reboot you can see the device using i2cdetect -y -a 3 But adding a second line for another set of pins in config.txt doesn't work.

So, where is that bus number specified and is it possible for me to add another one and perhaps make a separate dtoverlay for it?
I looked at the dts source file for the i2c_gpio overlay on github, but I didn't see anywhere in that file
where the bus number was set.

Thanks for any help.
Jerry

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

Re: i2c-gpio dtoverlay bus number

Thu Feb 15, 2018 9:57 pm

Can you really not get the three I2C devices (or at least two of them) to share the hardware I2C bus? It would be more efficient.

stardustJerry
Posts: 7
Joined: Mon Apr 04, 2016 11:11 pm

Re: i2c-gpio dtoverlay bus number

Thu Feb 15, 2018 10:36 pm

I don't believe we can put all three devices on the one hardware i2c. The port expander needs to use a higher baud rate than the EEPROMS from what the engineer I am working with tells me. It may be possible to use just the one extra set of GPIO lines for both EEPROMS, but they both use the same ic2 address so I'm not sure how that would work.

If I can define one more additional GPIO i2c that would be a good solution for us. If it is not possible, then we will look for another way.

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

Re: i2c-gpio dtoverlay bus number

Thu Feb 15, 2018 10:47 pm

I'm sure it will be possible - there are many board .dts files with multiple i2c-gpio instances - it is just a question of figuring out the bus numbering and whether we can use one standard overlay repeatedly or whether it must be a custom overlay.

stardustJerry
Posts: 7
Joined: Mon Apr 04, 2016 11:11 pm

Re: i2c-gpio dtoverlay bus number

Thu Feb 15, 2018 11:46 pm

Yes, the bus numbering seems to be the trick and finding out where it gets set. Trying to use the same overlay twice with different pins doesn't work. The second one only takes effect and it always gets bus number 3.

In other words if I put
dtoverlay=i2c-gpio,i2c_gpio_sda=27,i2c_gpio_scl=22
dtoverlay=i2c-gpio,i2c_gpio_sda=05,i2c_gpio_scl=06

into config.txt and reboot, I only get the second one on bus number 3. No others show up when I type i2cdetect -a -l

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

Re: i2c-gpio dtoverlay bus number

Mon Feb 19, 2018 5:47 pm

Sorry for the delay, but I have a solution for you know. The 4.14 kernel tree now includes a modified i2c-gpio with a new parameter - "bus" - which defaults to zero. You can add multiple instances provided they all have unique bus values. In my test I found the busses (i.e. /dev/i2c-*) were given numbers counting upwards from 3. I'm not sure it is possible to guarantee the mapping, but the first one mentioned appeared as i2c-3 for me - more testing is required.

You can find the updated overlay source here. Compile it with:

Code: Select all

dtc [email protected] -I dts -O dtb -o i2c-gpio.dtbo i2c-gpio-overlay.dts
and copy it to /boot/overlays.

Use it like this:

Code: Select all

dtoverlay=i2c-gpio,bus=0,i2c_gpio_sda=23,i2c_gpio_scl=24
dtoverlay=i2c-gpio,bus=1,i2c_gpio_sda=16,i2c_gpio_scl=20
Note that "bus=0" is the default and could be omitted.

stardustJerry
Posts: 7
Joined: Mon Apr 04, 2016 11:11 pm

Re: i2c-gpio dtoverlay bus number

Mon Feb 19, 2018 6:19 pm

Wow, thank you so much!

That is just what I needed.

Regards,
Jerry :D

stardustJerry
Posts: 7
Joined: Mon Apr 04, 2016 11:11 pm

Re: i2c-gpio dtoverlay bus number

Mon Feb 19, 2018 8:17 pm

I've been playing around with the new overlay and found that I can use it which is great, but there is an oddity which I don't understand.
if I put lines like this in /boot/config.txt
dtoverlay=hifiberry-dac
dtoverlay=i2s-mmap
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=27,i2c_gpio_scl=22,,i2c_gpio_delay_us=625
dtoverlay=i2c-gpio,bus=4,i2c_gpio_sda=05,i2c_gpio_scl=06

Using i2cdetect, The order of the assigned buses is reversed. 3 seems to always get assigned to the second one. Even if I use different numbers that don't include 3, it still assigns 3 to the last one I specify and the first one I specify always gets bus number 4.

I can certainly work with it as it is, but it is a bit of a curiosity.

Cheers,
Jerry

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

Re: i2c-gpio dtoverlay bus number

Mon Feb 19, 2018 8:21 pm

I tried to make it clear that this is a bit of a grey area. I'll have a look and see if there's a way to force an order (at least), but if it's like MMC/SD interfaces then it's first come first served (in the upstream kernel - we have a patch to force particular instance numbers).

stardustJerry
Posts: 7
Joined: Mon Apr 04, 2016 11:11 pm

Re: i2c-gpio dtoverlay bus number

Mon Feb 19, 2018 10:35 pm

I really do appreciate how you have helped me. I wasn't complaining at all, just noticing the curious way the bus numbers were assigned. It works fine for me.

Cheers,
Jerry

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

Re: i2c-gpio dtoverlay bus number

Tue Feb 20, 2018 11:23 am

The bus IDs are derived from Device Tree aliases, but the current overlay parameter mechanism isn't flexible enough to be able to generate matching aliases. Instead I've added a small patch to the i2c-gpio driver that allows the "reg" property to be used as the real bus number (unless there is a clash), so your test case will use the expected bus numbering. This patch will be in the next firmware release.

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

Re: i2c-gpio dtoverlay bus number

Tue Feb 20, 2018 9:55 pm

The patched driver and updated overlay are in the current rpi-update release.

centralware
Posts: 15
Joined: Thu Apr 02, 2015 8:57 am

Re: i2c-gpio dtoverlay bus number

Mon Sep 10, 2018 2:51 am

RasPi 2B (chosen against 3B just due to both act/pwr_led_gpio options)
Updated firmware overlay/*.dtb* files against github earlier today as a precaution.

config.txt contains

dtparam=i2c=on
dtoverlay=i2c-gpio,i2c_gpio_sda=25,i2c_gpio_scl=24,reg=9 (and tried bus=9) both to no avail

After probing i2c-dev, i2c1 is the only device shown (and functional) in /dev
The goal here is to create a total of nine software I2C ports but for the life of me, I haven't been able to get more than the default i2c-1.
I've tried commenting all but one of the overlay lines out just in case one or more had busy GPIO where the pins were locked (etc.) - no luck.
Any thoughts would be highly appreciated!

uname -r: 4.9.22-piCore-v7

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

Re: i2c-gpio dtoverlay bus number

Mon Sep 10, 2018 8:09 am

It sounds like either your firmware or the overlay (or both) is too old to support the feature. What do the following commands report?:

Code: Select all

[email protected]:~$ strings /boot/start.elf  | grep BUILD_ID_TIME
[email protected]:~$ dtoverlay -h i2c-gpio | grep bus

centralware
Posts: 15
Joined: Thu Apr 02, 2015 8:57 am

Re: i2c-gpio dtoverlay bus number

Mon Sep 10, 2018 7:48 pm

start.elf:
VC_BUILD_ID_TIME: 18:41:29
VC_BUILD_ID_TIME: Apr 4 2017

dtoverlay:
* No help found for overlay 'i2c-gpio'

NOTE: Using TinyCore Linux thus things like the dtoverlay binary aren't part of the base operating system.
Additionally, I threw together an "update" script which basically loops through the file names in OVERLAYS and downloads the most recent from github. If memory serves, the same applied to the start*,elf files. In the README (help) for the updated overlays (which came in HTML formatted which is likely why dtoverlay above couldn't find help topics) it does in fact support BUS as an argument.

I'm going to manually update the image and try again as a precautionary measure, but I'm "pretty" sure they're as new as are available at
https://github.com/raspberrypi/firmware ... t/overlays

Thanks!

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

Re: i2c-gpio dtoverlay bus number

Mon Sep 10, 2018 9:07 pm

Try updating the firmware - start*.elf, fixup*.dat - and see if that fixes the problem.

centralware
Posts: 15
Joined: Thu Apr 02, 2015 8:57 am

Re: i2c-gpio dtoverlay bus number

Tue Sep 11, 2018 11:14 am

Good morning, Phil!

Okay, we're half way home!
(Turns out my update script had an oops... went to overlays directory, did it's thing... went to update start*.elf and friends and somehow I failed to tell it to go back a directory, so my elfs ended up in overlays :/ )

NOTE: Once the updates were doing what was expected, if I update bootcode.bin and/or Broadcom 270* files (which are part of a single download batch) all USB functionality (including the onboard NIC) become dysfunctional. It's unrelated to I2C... but noteworthy. Once I down-graded this batch I was able to get back into the RPi remotely, usb keyboard worked once again, etc.

SO... I have dtoverlay i2c-gpio launching eight additional ports, bus=10 through 17.
When the system completes boot-up I have... eight new ports. numbered 3-10. BUS= and/or REG= "seem" to have no effect.

Code: Select all

dtoverlay=i2c-gpio,i2c_gpio_sda=27,i2c_gpio_scl=17,bus=10
dtoverlay=i2c-gpio,i2c_gpio_sda=10,i2c_gpio_scl=22,bus=11
dtoverlay=i2c-gpio,i2c_gpio_sda=11,i2c_gpio_scl=9,bus=12
dtoverlay=i2c-gpio,i2c_gpio_sda=13,i2c_gpio_scl=6,bus=13
dtoverlay=i2c-gpio,i2c_gpio_sda=26,i2c_gpio_scl=19,bus=14
dtoverlay=i2c-gpio,i2c_gpio_sda=15,i2c_gpio_scl=14,bus=15
dtoverlay=i2c-gpio,i2c_gpio_sda=23,i2c_gpio_scl=18,bus=16
dtoverlay=i2c-gpio,i2c_gpio_sda=25,i2c_gpio_scl=24,bus=17
NOTE: Tried with/without reg= with no change in outcome. Placed bus= first in the argument order; no difference.
GOAL: The preference is merely to have eight ports in numeric order; bus=2 doesn't seem to be an option but that may be due to what ever we're missing here though it was attempted (bus=2 through bus=9).
Please check i2c-gpio.dtbo bus() and see if there's anything special needed. Thanks!

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

Re: i2c-gpio dtoverlay bus number

Tue Sep 11, 2018 12:40 pm

That's progress. The remaining problem is that the ability to specify the bus number was only added in rpi-4.14.y. The commit in question (32e356678ebe "i2c-gpio: Also set bus numbers from reg property") should back-port easily, but it isn't there by default.

centralware
Posts: 15
Joined: Thu Apr 02, 2015 8:57 am

Re: i2c-gpio dtoverlay bus number

Tue Sep 11, 2018 1:02 pm

Attempting to back-port to 4.4.21.
Thank you for the tip! It made hunting through the hub's history a little less daunting! :)

centralware
Posts: 15
Joined: Thu Apr 02, 2015 8:57 am

Re: i2c-gpio dtoverlay bus number

Tue Sep 11, 2018 2:22 pm

Ran out of ideas to try.

Updated the system to 4.14.21, 22, 24, 26 and 29
The following files were updated each time:
*.elf
*.dat
overlays/i2c*.dtbo

config.txt: dtoverlay bus 10 through 17 (tried with or without i2c=on)

Boot script checks the existence of eth0 (which vanishes if bootcode/Broadcom files are updated) and then check i2c-gpio.dtbo for the bus function. It then runs i2cdetect on port 1 and then lists all i2c devices listed.

/dev/i2c* lists i2c-1 (when dtparam=i2c=on) followed by i2c-3,4,5,6,7,8,9,10 regardless if what I've attempted thus far. Any insight would be very appreciated!

Return to “Device Tree”

Who is online

Users browsing this forum: No registered users and 2 guests