Solved Using both i2c_arm and i2c_vc on rpi4b

Hi!

I bought a Raspberry Pi 4b 8Gb recently and am currently trying to adapt the drivers I earlier wrote for armv7.
But I stumbled on the second i2c bus - can they both be used at the same time at all, iic0 and iic1 buses, on rpi4?
Code:
FreeBSD rhino 13.0-STABLE FreeBSD 13.0-STABLE #2 stable/13-n248706-c3593fcdfb0d: Sat Dec 25 19:01:13 +04 2021     root@rhino:/usr/obj/usr/src/arm64.aarch64/sys/RPI4_RHINO  arm64

I try to use an rtc "ds3231" on pins 2,3 and a lightsensor "bh1750" on pins 27,28.
My config.txt:
INI:
[all]
arm_64bit=1
dtparam=audio=on,i2c_arm=on,spi=off
dtparam=i2c_vc=on
gpio=0,1,2,3=a0
device_tree_address=0x4000
device_tree=bcm2711-rpi-4-b.dtb
kernel=u-boot.bin
dtoverlay=i2c-rtc,ds3231=on
My loader.conf:
INI:
fdt_overlays="tm1637-gpio-rpi4,rcrecv-gpio-rpi4,bh1750-rpi4-i2c"

bh1750-rpi4-i2c.dtso:
INI:
/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2711";
};

&i2c_arm {
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";
    bh1750: light-sensor@23 {
        compatible = "rohm,bh1750";
        reg = <0x23>;
        mtreg = <0x45>;
        status = "okay";
    };
};

After boot I check if devices are properly detected:
Bash:
[root@rhino /]# dmesg | grep iic
iichb0: <BCM2708/2835 BSC controller> mem 0x7e205000-0x7e2051ff irq 19 on simplebus0
iichb1: <BCM2708/2835 BSC controller> mem 0x7e804000-0x7e804fff irq 26 on simplebus0
iicbus0: <OFW I2C bus> on iichb0
iic0: <I2C generic I/O> on iicbus0
iicbus1: <OFW I2C bus> on iichb1
iic1: <I2C generic I/O> on iicbus1
iicbus1: <unknown card> at addr 0x46
ds32310: <Maxim DS3231 RTC> at addr 0xd0 on iicbus1
[root@rhino /]# i2c -s
Hardware may not support START/STOP scanning; trying less-reliable read method.
Scanning I2C devices on /dev/iic0: 23 
[root@rhino /]# i2c -s -f /dev/iic1
Hardware may not support START/STOP scanning; trying less-reliable read method.
Scanning I2C devices on /dev/iic1: 68

I see that the bh1750 (addr=23) is bond to iicbus1 (how can this be possible?), but i2c found it on /dev/iic0.
Bash:
[root@rhino /]# i2c -a 0x23  -f /dev/iic0 -m tr -d r -c 2 -v -w 0
dev: /dev/iic0, addr: 0x23, r/w: r, offset: 0x00, width: 0, count: 2

Data read (hex):
00 05
And of course "bh1750.ko" cannot find the device as it searches for it on iicbus1:
Code:
bh17500: <BH1750 Ambient light sensor with an i2c interface> at addr 0x46 on iicbus1
bh17500: failed to connect to the device

Is this a bug or am I doing something wrong?
 
I would advice you to either use the mailing lists or visit #bsdmips on EFNet (despite its channel name) and be patient :)
 
Many of us had some "discussions" with "manu".There is a golden rule, if you had a bad experience on the one or the other territory, you need to come back, because this is the only way to reclaim your place there. And of course this is also our place, we belong to there as well as "manu".

I cannot speak for the RPIs. On my BeagleBone Black, iic0 is reserved for the HDMI video (and perhaps other system stuff). The general advice from the BBB developers is, not to mess around with this, but some did it nonetheless. I do not remember the very details, however, it was quite complicated, and I refrained from even trying it. Anyway, the BBB got two more i2c busses and for my purpose these turned out to be sufficient.
 
On my BeagleBone Black, iic0 is reserved for the HDMI video
Same with a RPI4's arm_vc, but I have not need an HDMI there. I see it rather as a mini-server - dns/unbound, www/nginx as a frontend for a some static content, ntp-server (with a GPS module and a tm1637 display) and as an aarch64 platform for my drivers testing. Also I want to try a security/clamav for mail/rspamd currently running on amd64 (Couldn't run it on RPI2 with 1Gb). But before all of it I want to test and maybe correct an early written for armv7 drivers for do them more universal.
And now, I want to understand if I wrote the overlay incorrectly, this is a bug in FDT or "this is a feature".
 
After several iterations, I settled on the following configuration:
/boot/msdos/config.txt
INI:
dtparam=audio=on,i2c_arm=on,spi=off
gpio=2,3=a0
dtoverlay=i2c-rtc,ds3231=on
dtoverlay=i2c5,pins_12_13
gpio=12,13=a5
/boot/loader.conf
INI:
bh1750_load="YES"
fdt_overlays="tm1637-gpio-rpi4,bh1750-rpi4-i2c5"
/boot/dtb/operlays/bh1750-rpi4-i2c5.dtbo
INI:
/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2711";
};

&i2c5 {
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";
    bh1750: light-sensor@23 {
        compatible = "rohm,bh1750";
        reg = <0x23>;
        mtreg = <0x45>;
        status = "okay";
    };
};
In all cases I configure things for i2c5 bus. And the device also is connected to i2c5 pins.

What i got as a result - two i2c channels (/dev/iic0 is fully occupied by the module "RTC ds3231 for Raspberry Pi", and /dev/iic1 (Surprise!!!) is for other devices)
Bash:
[root@rhino /]# ls /dev | grep iic 
iic0
iic1
[root@rhino /]# sysctl dev.bh1750
dev.bh1750.0.ready-time: 120060
dev.bh1750.0.hres-mode: 1
dev.bh1750.0.quality-lack: 0
dev.bh1750.0.mtreg: 69
dev.bh1750.0.illuminance: 5000
dev.bh1750.0.sensitivity: 833
dev.bh1750.0.polling-time: 5
dev.bh1750.0.counts: 6
dev.bh1750.0.connected: 1
dev.bh1750.0.%parent: iicbus1
dev.bh1750.0.%pnpinfo: name=light-sensor@23 compat=rohm,bh1750
dev.bh1750.0.%location: addr=0x46
dev.bh1750.0.%driver: bh1750
dev.bh1750.0.%desc: BH1750 Ambient light sensor with an i2c interface
dev.bh1750.%parent:
... and a little broken brain.
 
Back
Top