Trunk, mt7621, i2c and gpio

Hi all, could somebody explain how to work with gpio in trunk on mt7621?

I'm going to add to router i2c RTC.

i2c pins are gpio 3 & 4:

First of all is very strange numbers of gpio:


root@router:~# cat /sys/kernel/debug/gpio
gpiochip4: GPIOs 396-405, parent: pci/0000:03:00.0, ath9k-phy1:
 gpio-404 (                    |ath9k-phy1          ) out hi

gpiochip3: GPIOs 406-415, parent: pci/0000:02:00.0, ath9k-phy0:
 gpio-407 (                    |ath9k-phy0          ) out lo

gpiochip2: GPIOs 416-447, parent: platform/1e000600.gpio, 1e000600.gpio-bank2:

gpiochip1: GPIOs 448-479, parent: platform/1e000600.gpio, 1e000600.gpio-bank1:

gpiochip0: GPIOs 480-511, parent: platform/1e000600.gpio, 1e000600.gpio-bank0:
 gpio-490 (                    |green:status        ) out lo ACTIVE LOW
 gpio-491 (                    |green:led4          ) out lo
 gpio-492 (                    |green:led5          ) out lo
 gpio-496 (                    |modem_reset         ) out hi ACTIVE LOW
 gpio-498 (                    |reset               ) in  hi IRQ
 gpio-499 (                    |reset               ) out hi ACTIVE LOW

Second -- I did not find at trunk kmod-i2c-gpio-custom to define i2c bus like described here:

/sbin/insmod i2c-dev
/sbin/insmod i2c-gpio-custom bus0=0,2,3

Third -- it looks like i2c driver does not start. Modules are compiled and present, driver reports that it works but in /dev there is no any device like i2c:

root@router:~# opkg list-installed | grep -i i2c
i2c-tools - 4.2-1
kmod-i2c-algo-bit - 5.4.72-1
kmod-i2c-core - 5.4.72-1
kmod-i2c-gpio - 5.4.72-1
libi2c - 4.2-1

root@router:~# lsmod | grep -i i2c
i2c_algo_bit            5037  1 i2c_gpio
i2c_dev                 5122  0
i2c_gpio                2514  0

root@router:~# dmesg | grep -i i2c
[   19.708770] i2c /dev entries driver

root@router:~# i2cdetect -y 0
Error: Could not open file `/dev/i2c-0' or `/dev/i2c/0': No such file or directory

root@router:~# i2cdetect -y 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory

root@router:~# i2cdetect -y 2
Error: Could not open file `/dev/i2c-2' or `/dev/i2c/2': No such file or directory

root@router:~# ls -l /dev | grep -i i2c

root@router:~#

i2c is disabled in the top-level .dtsi, you need to enable it in the .dts file for your board.

1 Like

Thanks, I will, only one question. What is correct way to modify it -- edit .dtsi directly or make a patch?

I would simply edit a local copy of mt7621_unielec_u7621-06.dtsi, assuming you're building the image yourself.
Note that you don't need kmod-i2c-gpio or kmod-i2c-gpio-custom if you're using native I²C ports.

2 Likes

You can simply add in your board dts-file:

&i2c {
	status = "okay";
};

and status property will be changed only for your board.

1 Like

Thank a lot, just have compiled new image with i2c enabled and all seems to work fine (RTC not connected):

root@router:~# dmesg | grep -i i2c
[    1.163116] i2c-mt7621 1e000900.i2c: clock 100 kHz
[  208.437865] i2c /dev entries driver

root@router:~# ls -l /dev | grep -i i2c
crw-------    1 root     root       89,   0 Oct 27 14:02 i2c-0

root@router:~# i2cdetect 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0.
I will probe address range 0x08-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
2 Likes

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