[Banana BPI-R4] how to enable I2C?

Hi
I have just installed new OS: OpenWrt SNAPSHOT, r25331-0c18c5679a, kernel 6.1.79
. Now trying to work with some I2C devices attached but it seems it is not enabled.
Any idea how I can do it?
root@BPI-R4:/sys/class/i2c-dev/i2c-1# ls -ltr /sys/class/i2c-dev/i2c-1/new_device
ls: /sys/class/i2c-dev/i2c-1/new_device: No such file or directory
root@BPI-R4:/sys/class/i2c-dev/i2c-1# ls -ltr /sys/class/i2c-dev/i2c-0/new_device
ls: /sys/class/i2c-dev/i2c-0/new_device: No such file or directory

Good will be to get also any hint to get some wiring for Banana BPI-R4 :slight_smile:
Kindly

compile your kernel probably the only way

Did you see this?

I see here some points...

  1. if in my actual image, kernel supports I2C as below:

I2C support

CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_COMPAT=y
CONFIG_I2C_MT65XX=y

No idea as Im using what I get from openwrt firmware selector.
If it is dsabled in the kernel how to request to enable it?

  1. Unless point 1 possible that in BPI-R4 first of all we need to enable I2C on GPIO side loading some dts overlays as I know from RaspeberryPi or OrangePi. Maybe not needed here....

  2. Issue on hardware level with pullup resitors as I read on some BPI boards.

My understanding you need to enable i2c1 in mt7988a-bananapi-bpi-r4.dts and recompile the image.

Possibly...
First I wish to check if my kernel is enabling I2C but I have no /proc/config.gz and /etc/build.config so a bit stuck.

I2C on the MT7988 works very well, we are using 2 out of the 3 busses it on-board:
One for connecting the PMIC, the other bus is connected to I2C mux for SFP cages, RTC and some EEPROMs. All that works, so from driver and hardware point of view I2C it's all just fine.

Now to how to integrate your use of I2C for adding a peripheral device:
mt7988a-bananapi-bpi-r4.dts is representing the bare board, without anything added. The proper way to add a peripheral would be to create a Device Tree Overlay enabling the (in this case) i2c bus used and defining the peripheral there as a bus client with address and compatible string. If you want to control the peripheral from userspace, just enable the bus in the DT overlay.

Other than RaspberryPi there is no filesystem to store the DT overlays, but rather you have to include them in the uImage.FIT, like it is already done for the DT overlays selecting either SD or eMMC, for example.

2 Likes

thank you for your prompt answer and confirmation that all could be fine with hardware :slight_smile:
Im rather new here as I started working with openwrt 8 days ago :smiley:
Im a bit familiar with dts overaly as I was doing similar things for my orange pi board but here it is a bit complicated as I see. also for previous banana pi BPI-R router i2c was working from the box...
Anyway is it any tutorial how I can do that?

Open https://github.com/openwrt/openwrt/tree/master/target/linux/mediatek/files-6.1/arch/arm64/boot/dts/mediatek
and you will see a few files with bpi-r4 in the name, the recommendation was to create your own dtso file using existing file(s) as a reference.

Exactly. And then list your added overlay in target/linux/mediatek/image/filogic.mk.

I could be wrong but you can probably just clone mt7988a-bananapi-bpi-r4-rtc.dtso and replace &pcf8563 with &i2c1

1 Like

root@BPI-R4:/# find / -name ".dto"
root@BPI-R4:/# find / -name "filogic.mk"
root@BPI-R4:/#

I explained Im using Snapshot version already prepared in firmware selector.

No need to explain. You need to create/edit a file in your local build system and then build the image.

I have installed on my OPI5 env to build image but....

I cannot pickup my board which is obvious as offically BPI-R4 is not supported yet (only snpashot)

git tag:
..
v23.05.2 (no snpashot)

make menuconfig:
Target System (MediaTek Ralink ARM) --->
Subtarget (Filogic 8x0 (MT798x)) --->
Target Profile (Bananapi BPi-R3) ---> no option for Bananapi BPi-R4

Please start a separate topic for the build system related questions.

fixed building and testing

new image compiled, dts added for i2c0 and i2c1 but issue not solved :frowning: not discovering my i2c device attached.....

root@BPI-R4:~# dmesg |grep -i i2c
[ 2.168588] i2c_dev: i2c /dev entries driver
[ 5.779081] FIT: flat_dt sub-image 0x00551000..0x00551119 "fdt-mt7988a-bananapi-bpi-r4-i2c0" (ARM64 OpenWrt bananapi_bpi-r4 device tree overlay mt7988a-bananapi-bpi-r4-i2c0)
[ 5.795412] FIT: flat_dt sub-image 0x00552000..0x00552119 "fdt-mt7988a-bananapi-bpi-r4-i2c1" (ARM64 OpenWrt bananapi_bpi-r4 device tree overlay mt7988a-bananapi-bpi-r4-i2c1)
[ 10.918735] i2c i2c-1: Added multiplexed i2c bus 2
[ 10.923599] i2c i2c-1: Added multiplexed i2c bus 3
[ 10.928453] i2c i2c-1: Added multiplexed i2c bus 4
[ 10.933290] i2c i2c-1: Added multiplexed i2c bus 5
[ 10.938077] pca954x 1-0070: registered 4 multiplexed busses for I2C switch pca9545

mt7988a-bananapi-bpi-r4-i2c1:

/dts-v1/;
/plugin/;

/ {
compatible = "bananapi,bpi-r4", "mediatek,mt7988a";

fragment@0 {
	target = <&i2c1>;
	__overlay__ {
		status = "okay";
	};
};

};

root@BPI-R4:~# ls -ltr /sys/class/i2c-dev/i2c-1/new_device
ls: /sys/class/i2c-dev/i2c-1/new_device: No such file or directory
root@BPI-R4:~# ls -ltr /sys/class/i2c-dev/i2c-0/new_device
ls: /sys/class/i2c-dev/i2c-0/new_device: No such file or directory

Not sure what's wrong here, but for the check you need to run i2cdetect -l first and then, depending on the results, use numbers 0,1,2,etc : i2cdetect 0

it is discovering nothing...
Im rather thinking about dts file is not complete...maybe some sections are missing like:
&i2c0 {
pinctrl-names = "default";
pinctrl-0 = <&i2c0_pins>;
status = "okay";

but all that is already included in parent mt7988a-bananapi-bpi-r4.dts

check this chain:

in mt7988a-bananapi-bpi-r4.dts:
/dts-v1/;
#include "mt7988a.dtsi"

in mt7988a.dtsi

	i2c0: i2c@11003000 {
		compatible = "mediatek,mt7988-i2c",
			     "mediatek,mt7981-i2c";

...
status = "disabled";
};

	i2c1: i2c@11004000 {
		compatible = "mediatek,mt7988-i2c",
			     "mediatek,mt7981-i2c";

...
status = "disabled";
};