Enabling and using main_i2c3

Hi all,

Our HW department has produced a cape for the AI64 that has an rtc (i2c), a lon-interface (spi) and four rs485 ports.

However, they have not considered the standard overlays that are available per default. They have looked at Connectors — BeagleBoard Documentation and chosen buses from that list. The result is:

RTC hooked up to I2C3: P8-13(2) and P9-21B(2)
LON-SPI hooked up to SPI1: P8-35B(0), P9-18B(0), P9-24A(0) and P9-26A(0)

I got the SPI bus working by adding to k3-j721e-beagleboneai64-buses.dtsi:

BONE_PIN(P8_35, spi,       P8_35B(PIN_INPUT, 0))	/* spi1_cs0 */
BONE_PIN(P9_18, spi,       P9_18B(PIN_INPUT, 0))	/* spi1_d1 */
BONE_PIN(P9_24, spi,       P9_24A(PIN_OUTPUT, 0))	/* spi1_d0 */
BONE_PIN(P9_26, spi,       P9_26A(PIN_INPUT, 0))	/* spi1_clk */

For the I2C3, I have added:

BONE_PIN(P8_13, i2c,       P8_13(PIN_INPUT, 2))	/* i2c3_scl */
BONE_PIN(P9_21, i2c,       P9_21B(PIN_OUTPUT, 4))	/* i2c3_sda */

But the i2c-bus keeps getting timeout errors when probing:

root@beaglebone-ai64:~# dmesg | grep i2c
[    0.747719] i2c /dev entries driver
[    0.853214] omap_i2c 40b00000.i2c: bus 0 rev0.12 at 100 kHz
[    0.853740] omap_i2c 40b10000.i2c: bus 1 rev0.12 at 100 kHz
[    0.877804] omap_i2c 42120000.i2c: bus 2 rev0.12 at 400 kHz
[    0.878450] omap_i2c 2000000.i2c: bus 3 rev0.12 at 400 kHz
[    0.879454] omap_i2c 2010000.i2c: bus 4 rev0.12 at 400 kHz
[    0.880059] omap_i2c 2020000.i2c: bus 5 rev0.12 at 100 kHz
[    1.921709] omap_i2c 2030000.i2c: controller timed out
[    1.921810] omap_i2c 2030000.i2c: bus 6 rev0.12 at 100 kHz <-- Probed twice?
[    1.922665] omap_i2c 2040000.i2c: bus 7 rev0.12 at 100 kHz
[    1.923170] omap_i2c 2050000.i2c: bus 8 rev0.12 at 400 kHz
[    1.923606] omap_i2c 2060000.i2c: bus 9 rev0.12 at 100 kHz

and

root@beaglebone-ai64:~# i2cdetect -y -r 6
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         [  494.017639] omap_i2c 2030000.i2c: controller timed out
-- [  495.073641] omap_i2c 2030000.i2c: controller timed out
-- [  496.129645] omap_i2c 2030000.i2c: controller timed out
-- [  497.185644] omap_i2c 2030000.i2c: controller timed out
-- [  498.241644] omap_i2c 2030000.i2c: controller timed out
-- [  499.297638] omap_i2c 2030000.i2c: controller timed out
...

I have made sure that no other pinmux is touching the pins so I don’t really know what the issue could be. Before this, I have succesfully connected the RTC to the “standard” i2c-bus using jumper wires and the overlay BONE-I2C3.dts (connected to main_i2c4, confusing, I know), so I know that the RTC itself is working, but connecting it to main_i2c3 doesn’t seem to work.

Is main_i2c3 unavailable to us?

Thanks,

/Bo

OK, looking at the dtsi file, I think you will need to enable the peripheral.

It is a bit confusing as bone_i2c_3 actually maps to main_i2c4 in k3-j721e-beagleboneai64-bone-buses.dtsi

main_i2c3 is delacred and included in k3-j721e-beagleboneai64.dts with it looks like pin muxing set on pads T26 & T25 which are not connected to the headers. Also the perhiperal is not enabled and set to 400K clock if that is important

Thanks for the reply!

I commented out the pin-muxing in the beagleboneai64.dts:

// &main_i2c3 {
// 	pinctrl-names = "default";
// 	pinctrl-0 = <&main_i2c3_pins_default>;
// 	clock-frequency = <400000>;
// };

I have disabled everything but the necessary in the buses-dtsi, keeping these two:

bone_i2c_rtc: &main_i2c3 {
};

and

bone_spi_lon: &main_spi1 {
};

Those are just declarations for the overlays, which look like this:

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2022 BeagleBoard.org - https://beagleboard.org/
 *
 * https://elinux.org/Beagleboard:BeagleBone_cape_interface_spec#SPI
 */

/dts-v1/;
/plugin/;

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */
&{/chosen} {
	overlays {
		BONE-SPI_LON.kernel = __TIMESTAMP__;
	};
};

&bone_spi_lon {
	pinctrl-names = "default";
	pinctrl-0 = <
		&P8_35_spi_pin /* spi1_cs0 NB: Added SPI capabilitites in k3-j721e-beagleboneai64-bone-buses.dtsi*/
		&P9_26_spi_pin /* spi1_clk NB: Added SPI capabilitites ... */
		&P9_24_spi_pin /* spi1_d0  NB: Added SPI capabilitites ... */
		&P9_18_spi_pin /* spi1_d1  NB: Changed from A to B in ... */
	>;
	ti,spi-num-cs = <1>;
	ti,pindir-d0-out-d1-in;

	status = "okay";

	spidev@0 {
		symlink = "bone/spi/lon";
		compatible = "rohm,dh2228fv";
		reg = <0>;	/* CE0 */
		#address-cells = <1>;
		#size-cells = <0>;
		spi-max-frequency = <125000000>;
	};
};

and

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2022 BeagleBoard.org - https://beagleboard.org/
 *
 * https://elinux.org/Beagleboard:BeagleBone_cape_interface_spec#I2C
 */

/dts-v1/;
/plugin/;

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */
&{/chosen} {
	overlays {
		BONE-I2C_RTC.kernel = __TIMESTAMP__;
	};
};

&bone_i2c_rtc {
	pinctrl-names = "default";
	pinctrl-0 = <
		&P9_21_i2c_pin /* i2c3_sda */
		&P8_13_i2c_pin /* i2c3_scl */
	>;
	clock-frequency = <100000>;

	status = "okay";

	rtc@32 {
		symlink = "bone/i2c/rtc";
		compatible = "epson,rx8010";
		reg = <0x32>;
	};
};

What am I missing?

/Bo

you probably need to enable main_i2c3

Where have you declared bone_i2c_rtc ?

If it is just in the above, then you need to change it to I would guess, and include status=“okay”

bone_i2c_rtc : &main_i2c3 {
status = “okay”
};

ok missed the bit further up. you probably just need to set the status

But I have already done that in the overlay. Shouldn’t that be enough?

Sorry missed that, yes it should

Does the symlink appear?
Does dmesg highlight any issues?

No symlink in /dev (not even the folder “bone”).

dmesg shows the messages you see above.

I don’t suppose you have a serial console cable. Would be nice to see if ubiot is loading the overlay

I have console connected. Both overlays are loading fine, and I can insmod the spidev that enables the spi.

Might be tracking down the pin mux macros for the I2C pins, there might be a typo there.

I will try and see if I can make it work on my board over the weekend. I don’t think I have an I2C device to test, but I can stick some scope probes on the pins to see if it clocks when using i2cdetect.

For any of the pin macros that have either A or B on the header pin, you need to make sure you set the other to an input.

so the above should be

BONE_PIN(P9_21, i2c,       P9_21B(PIN_OUTPUT, 4), P9_21A(PIN_INPUT,7))	/* i2c3_sda */

That might not be your issue as the alternative pin may well default to an input. It might also be used by another peripheral and being changed somewhere.

I am working my way through the various devicetree files, trying to find out where the I2C busses are enabled as there are 7 i2c devices in /dev

*** EDIT**** I just notice you have set it to mux mode 4, that should be 2 for I2C3_SDA. I can’t get it to work either currently.

Ok finally have this figured out.

So I have the following devicetree

root@BeagleBone:/sys/bus/i2c# cat /opt/source/dtb-5.10-ti/src/arm64/overlays/BEN-I2C3.dts
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2022 BeagleBoard.org - https://beagleboard.org/
 *
 * https://elinux.org/Beagleboard:BeagleBone_cape_interface_spec#I2C
 */
/dts-v1/;
/plugin/;

#include <dt-bindings/pinctrl/k3.h>

/*
 * Helper to show loaded overlays under: /proc/device-tree/chosen/overlays/
 */
&{/chosen} {
        overlays {
                ben-i2c-debug.kernel = __TIMESTAMP__;
        };
};

&main_pmx0 {
        ben_i2c3_pins_default: ben-i2c3-pins-default {
                pinctrl-single,pins = <
                        J721E_IOPAD(0xA0, PIN_INPUT, 7)               /* (AJ22) P9_21A */
                        J721E_IOPAD(0x16C, PIN_INPUT_PULLUP, 2)       /* (U28)  P9_21B */
                        J721E_IOPAD(0x168, PIN_INPUT_PULLUP, 2)       /* (V27)  P8_13 */
                >;
        };
};

&main_i2c3 {
        pinctrl-names = "default";
        pinctrl-0 = <&ben_i2c3_pins_default>;
        status = "okay";
        clock-frequency = <100000>;
};

So rebooted and everything seems fine, however i2cdetect on bus 3 does not work !

So after some reading, doing the following -

root@BeagleBone:/sys/bus/i2c# ls -l /sys/bus/i2c/devices/
total 0
lrwxrwxrwx 1 root root 0 Jan  1  1970 2-0050 -> ../../../devices/platform/bus@100000/bus@100000:bus@28380000/42120000.i2c/i2c-2/2-0050
lrwxrwxrwx 1 root root 0 Jan  1  1970 2-0051 -> ../../../devices/platform/bus@100000/bus@100000:bus@28380000/42120000.i2c/i2c-2/2-0051
lrwxrwxrwx 1 root root 0 Jan  1  1970 4-0047 -> ../../../devices/platform/bus@100000/2010000.i2c/i2c-4/4-0047
lrwxrwxrwx 1 root root 0 Jan  1  1970 i2c-0 -> ../../../devices/platform/bus@100000/bus@100000:bus@28380000/40b00000.i2c/i2c-0
lrwxrwxrwx 1 root root 0 Jan  1  1970 i2c-1 -> ../../../devices/platform/bus@100000/bus@100000:bus@28380000/40b10000.i2c/i2c-1
lrwxrwxrwx 1 root root 0 Jan  1  1970 i2c-2 -> ../../../devices/platform/bus@100000/bus@100000:bus@28380000/42120000.i2c/i2c-2
lrwxrwxrwx 1 root root 0 Jan  1  1970 i2c-3 -> ../../../devices/platform/bus@100000/2000000.i2c/i2c-3
lrwxrwxrwx 1 root root 0 Jan  1  1970 i2c-4 -> ../../../devices/platform/bus@100000/2010000.i2c/i2c-4
lrwxrwxrwx 1 root root 0 Jan  1  1970 i2c-5 -> ../../../devices/platform/bus@100000/2030000.i2c/i2c-5
lrwxrwxrwx 1 root root 0 Jan  1  1970 i2c-6 -> ../../../devices/platform/bus@100000/2050000.i2c/i2c-6

I can see that the physical I2C3 device actually maps to i2c-5 and running i2cdetect on that does indeed toggle P9.21 and P8.13

1 Like

That is beyond helpful!

Thank you so much for digging into this, I was pulling my hair.

I can’t wait to try it out on Monday. I will let you know as soon as I have anything to report.

Again, many thanks. This is what forums are about!

/Bo

1 Like

This was the culprit. Plus the fact that it should be an INPUT solved it for me.

I really appriciate your help, so thank you very much!

/Bo

1 Like