Defining in rpi_4b.dts for i2c-custom leads to weird GPIO 456 (SDA) and 457 (SCL)

I am trying to build a firmware with i2c-gpio module and because of kmod-i2c-gpio-custom is missing in 21.02 for my Raspberry PI 4B, I am editing .dts file (~/openwrt/build_dir/target-aarch64_cortex-a72_musl/linux-bcm27xx_bcm2711/linux-5.4.215/arch/arm/boot/dts/bcm2711.dtsi)

I am found out this topic, and edit file by adding this:

			i2c7: i2c@0 {
			compatible = "i2c-gpio";
			gpios = <&gpio 2 0 /* sda */
					&gpio 3 0 /* scl */
					>;
			i2c-gpio,sda-open-drain;
			i2c-gpio,scl-open-drain;
			i2c-gpio,delay-us = <2>;	/* ~100 kHz */
			#address-cells = <1>;
			#size-cells = <0>;
		};

but for my Raspberry 4B this works in weird way:

Thu Oct 13 22:33:38 2022 kern.info kernel: [    7.502126] i2c-gpio soc:i2c@0: using lines 456 (SDA) and 457 (SCL)

After that, I did rewrite .dts in according to kernel.org documentation,

        i2c: i2c {
                compatible = "i2c-gpio";

                sda-gpios = <&gpio  2 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
                scl-gpios = <&gpio 3 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
        };

but this leads to same result.

Thu Oct 13 22:33:38 2022 kern.info kernel: [    7.468387] i2c-gpio soc:i2c: using lines 456 (SDA) and 457 (SCL)

I have no idea why gpio2 means 456 and gpio3 means 457.
What is 454 offset comes from and how to fix it?

Any ideas would be appreciated.

I don't think you need to fix anything.
Please read about the gpio base here: https://openwrt.org/docs/techref/hardware/port.gpio#software

I'm probably missing something, but for boards with native I²C support no GPIO manipulation is usually necessary, we just need to make sure that the I²C lines are not configured as GPIO.

1 Like

You are right. I tested via a logical analyzer and indeed I don't need to fix GPIO. It works, I can see this. I2C tries to communicate (I have no devices on my bus at the moment)

But the number is strange.

I did some tests. I will execute this on various images:

cat /sys/kernel/debug/gpio

On 21.02.05 this outputs:

root@OpenWrt:~# cat /sys/kernel/debug/gpio
gpiochip1: GPIOs 446-453, parent: platform/soc:firmware:gpio, raspberrypi-exp-gpio, can sleep:
 gpio-446 (BT_ON               )
 gpio-447 (WL_ON               )
 gpio-448 (PWR_LED_OFF         |led1                ) out lo ACTIVE LOW
 gpio-449 (GLOBAL_RESET        )
 gpio-450 (VDD_SD_IO_SEL       |vdd-sd-io           ) out hi 
 gpio-451 (CAM_GPIO            )
 gpio-452 (SD_PWR_ON           |sd_vcc_reg          ) out hi 
 gpio-453 (SD_OC_N             )

gpiochip0: GPIOs 454-511, parent: platform/fe200000.gpio, pinctrl-bcm2711:
 gpio-454 (ID_SDA              )
 gpio-455 (ID_SCL              )
 gpio-456 (SDA1                )
 gpio-457 (SCL1                )
 gpio-458 (GPIO_GCLK           )
 gpio-459 (GPIO5               )
 gpio-460 (GPIO6               )
 gpio-461 (SPI_CE1_N           )
 gpio-462 (SPI_CE0_N           )
 gpio-463 (SPI_MISO            )
 gpio-464 (SPI_MOSI            )
 gpio-465 (SPI_SCLK            )
 gpio-466 (GPIO12              )
 gpio-467 (GPIO13              )
 gpio-468 (TXD1                )
 gpio-469 (RXD1                )
 gpio-470 (GPIO16              )
 gpio-471 (GPIO17              )
 gpio-472 (GPIO18              )
 gpio-473 (GPIO19              )
 gpio-474 (GPIO20              )
 gpio-475 (GPIO21              )
 gpio-476 (GPIO22              )
 gpio-477 (GPIO23              )
 gpio-478 (GPIO24              )
 gpio-479 (GPIO25              )
 gpio-480 (GPIO26              )
 gpio-481 (GPIO27              )
 gpio-482 (RGMII_MDIO          )
 gpio-483 (RGMIO_MDC           )
 gpio-484 (CTS0                )
 gpio-485 (RTS0                )
 gpio-486 (TXD0                )
 gpio-487 (RXD0                )
 gpio-488 (SD1_CLK             )
 gpio-489 (SD1_CMD             )
 gpio-490 (SD1_DATA0           )
 gpio-491 (SD1_DATA1           )
 gpio-492 (SD1_DATA2           )
 gpio-493 (SD1_DATA3           )
 gpio-494 (PWM0_MISO           )
 gpio-495 (PWM1_MOSI           )
 gpio-496 (STATUS_LED_G_CLK    |led0                ) out lo 
 gpio-497 (SPIFLASH_CE_N       )
 gpio-498 (SDA0                )
 gpio-499 (SCL0                )
 gpio-500 (RGMII_RXCLK         )
 gpio-501 (RGMII_RXCTL         )
 gpio-502 (RGMII_RXD0          )
 gpio-503 (RGMII_RXD1          )
 gpio-504 (RGMII_RXD2          )
 gpio-505 (RGMII_RXD3          )
 gpio-506 (RGMII_TXCLK         )
 gpio-507 (RGMII_TXCTL         )
 gpio-508 (RGMII_TXD0          )
 gpio-509 (RGMII_TXD1          )
 gpio-510 (RGMII_TXD2          )
 gpio-511 (RGMII_TXD3          )

Which is my case and the same as my built image. 456 and 457 for SDA and SCL respectively instead GPIO2 and GPIO3.

For 22.03.3

gpiochip0: GPIOs 0-57, parent: platform/fe200000.gpio, pinctrl-bcm2711:
 gpio-0   (ID_SDA              )
 gpio-1   (ID_SCL              )
 gpio-2   (SDA1                )
 gpio-3   (SCL1                )
 gpio-4   (GPIO_GCLK           )
 gpio-5   (GPIO5               )
 gpio-6   (GPIO6               )
 gpio-7   (SPI_CE1_N           )
 gpio-8   (SPI_CE0_N           )
 gpio-9   (SPI_MISO            )
 gpio-10  (SPI_MOSI            )
 gpio-11  (SPI_SCLK            )
 gpio-12  (GPIO12              )
 gpio-13  (GPIO13              )
 gpio-14  (TXD1                )
 gpio-15  (RXD1                )
 gpio-16  (GPIO16              )
 gpio-17  (GPIO17              )
 gpio-18  (GPIO18              )
 gpio-19  (GPIO19              )
 gpio-20  (GPIO20              )
 gpio-21  (GPIO21              )
 gpio-22  (GPIO22              )
 gpio-23  (GPIO23              )
 gpio-24  (GPIO24              )
 gpio-25  (GPIO25              )
 gpio-26  (GPIO26              )
 gpio-27  (GPIO27              )
 gpio-28  (RGMII_MDIO          )
 gpio-29  (RGMIO_MDC           )
 gpio-30  (CTS0                )
 gpio-31  (RTS0                )
 gpio-32  (TXD0                )
 gpio-33  (RXD0                )
 gpio-34  (SD1_CLK             )
 gpio-35  (SD1_CMD             )
 gpio-36  (SD1_DATA0           )
 gpio-37  (SD1_DATA1           )
 gpio-38  (SD1_DATA2           )
 gpio-39  (SD1_DATA3           )
 gpio-40  (PWM0_MISO           )
 gpio-41  (PWM1_MOSI           )
 gpio-42  (STATUS_LED_G_CLK    |led0                ) out lo 
 gpio-43  (SPIFLASH_CE_N       )
 gpio-44  (SDA0                )
 gpio-45  (SCL0                )
 gpio-46  (RGMII_RXCLK         )
 gpio-47  (RGMII_RXCTL         )
 gpio-48  (RGMII_RXD0          )
 gpio-49  (RGMII_RXD1          )
 gpio-50  (RGMII_RXD2          )
 gpio-51  (RGMII_RXD3          )
 gpio-52  (RGMII_TXCLK         )
 gpio-53  (RGMII_TXCTL         )
 gpio-54  (RGMII_TXD0          )
 gpio-55  (RGMII_TXD1          )
 gpio-56  (RGMII_TXD2          )
 gpio-57  (RGMII_TXD3          )

gpiochip1: GPIOs 504-511, parent: platform/soc:firmware:gpio, raspberrypi-exp-gpio, can sleep:
 gpio-504 (BT_ON               )
 gpio-505 (WL_ON               )
 gpio-506 (PWR_LED_OFF         |led1                ) out lo ACTIVE LOW
 gpio-507 (GLOBAL_RESET        )
 gpio-508 (VDD_SD_IO_SEL       |vdd-sd-io           ) out hi 
 gpio-509 (CAM_GPIO            )
 gpio-510 (SD_PWR_ON           |sd_vcc_reg          ) out hi 
 gpio-511 (SD_OC_N 

Which is quite better, although there is still large numbers present.

It looks like an error in .dts or something. I believe there should be setting where I can fix it. It is confusing numbers and the numbers is not in the accordance to any real world info. It is fake numbers, if you want.

From my standpoint you should not worry about GPIOs at all with 1 exception.
Your board has a number of I²C controllers (3?), each of them has its own SDA and SCL and each of them can be used as a GPIO instead of I²C. You need to find which pair of pins is not currently used as a GPIO or you need to exclude those pins from GPIO list. In other words, you should see that the function of the pin is i2c.

This is an example from absolutely different board but I suppose you should be able to see something similar on yours:

root@OpenWrt:/# cat /sys/kernel/debug/pinctrl/pinctrl-ralink-pinmux/pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
pin 0 (io0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 1 (io1): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 2 (io2): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 3 (io3): 1e000900.i2c (GPIO UNCLAIMED) function i2c group i2c
pin 4 (io4): 1e000900.i2c (GPIO UNCLAIMED) function i2c group i2c

and another board:

root@orange:~# cat /sys/kernel/debug/pinctrl/*/pinmux-pins | grep i2c
pin 352 (PL0): 1f02400.i2c (GPIO UNCLAIMED) function s_i2c group PL0
pin 353 (PL1): 1f02400.i2c (GPIO UNCLAIMED) function s_i2c group PL1
1 Like

I did recompile the whole system with make clean. And suddenly I noticed that

cat /sys/kernel/debug/pinctrl/*/pinmux-pins

outputs with normal numbers

Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
pin 0 (gpio0): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 1 (gpio1): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 2 (gpio2): fe804000.i2c (GPIO UNCLAIMED) function alt0 group gpio2
pin 3 (gpio3): fe804000.i2c (GPIO UNCLAIMED) function alt0 group gpio3
pin 4 (gpio4): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 5 (gpio5): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 6 (gpio6): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 7 (gpio7): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 8 (gpio8): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 9 (gpio9): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 10 (gpio10): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 11 (gpio11): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 12 (gpio12): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 13 (gpio13): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 14 (gpio14): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 15 (gpio15): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 16 (gpio16): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 17 (gpio17): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 18 (gpio18): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 19 (gpio19): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 20 (gpio20): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 21 (gpio21): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 22 (gpio22): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 23 (gpio23): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 24 (gpio24): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 25 (gpio25): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 26 (gpio26): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 27 (gpio27): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 28 (gpio28): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 29 (gpio29): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 30 (gpio30): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 31 (gpio31): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 32 (gpio32): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 33 (gpio33): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 34 (gpio34): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio34
pin 35 (gpio35): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio35
pin 36 (gpio36): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio36
pin 37 (gpio37): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio37
pin 38 (gpio38): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio38
pin 39 (gpio39): fe300000.mmcnr (GPIO UNCLAIMED) function alt3 group gpio39
pin 40 (gpio40): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 41 (gpio41): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 42 (gpio42): (MUX UNCLAIMED) pinctrl-bcm2711:496
pin 43 (gpio43): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 44 (gpio44): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 45 (gpio45): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 46 (gpio46): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 47 (gpio47): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 48 (gpio48): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 49 (gpio49): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 50 (gpio50): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 51 (gpio51): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 52 (gpio52): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 53 (gpio53): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 54 (gpio54): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 55 (gpio55): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 56 (gpio56): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 57 (gpio57): (MUX UNCLAIMED) (GPIO UNCLAIMED)

The only weird number is 496 but at least this is not a GPIO number.

pin 42 (gpio42): (MUX UNCLAIMED) pinctrl-bcm2711:496

So the question is resolved by make clean

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.