yanghn2002

View My GitHub Profile

在 T113S3 上面用 Tina Linux 5 ,发现 I2C-1 怎么改 DTS 死活配不上去:

i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

最后发现是全志的 pinctrl 写错了 !!!

	SUNXI_PIN(SUNXI_PINCTRL_PIN(G, 8),
		SUNXI_FUNCTION(0x0, "gpio_in"),
		SUNXI_FUNCTION(0x1, "gpio_out"),
		SUNXI_FUNCTION(0x2, "uart1"),		/* RTS */
		SUNXI_FUNCTION(0x3, "twi1"),		/* SCK */
		SUNXI_FUNCTION(0x4, "gmac0"),		/* RXD2/NULL */
		SUNXI_FUNCTION(0x5, "uart3"),		/* TX */
		SUNXI_FUNCTION_IRQ_BANK(0xE, 5, 8),
		SUNXI_FUNCTION(0xF, "io_disabled")),
	SUNXI_PIN(SUNXI_PINCTRL_PIN(G, 9),
		SUNXI_FUNCTION(0x0, "gpio_in"),
		SUNXI_FUNCTION(0x1, "gpio_out"),
		SUNXI_FUNCTION(0x2, "uart1"),		/* CTS */
		SUNXI_FUNCTION(0x3, "twi0"),		/* SDA */
		SUNXI_FUNCTION(0x4, "gmac0"),		/* RXD3/NULL */
		SUNXI_FUNCTION(0x5, "uart3"),		/* RX */
		SUNXI_FUNCTION_IRQ_BANK(0xE, 5, 9),
		SUNXI_FUNCTION(0xF, "io_disabled")),

这里 PG8 的 function 3 明明是 "twi1",这里 PG9 的 function 3 就写成了 "twi0"
我们看 datasheet : t113s3-datasheet-pg8pg9 明明 PG9 的 function 3 是 TWI1-SDA !!!

如何排查

可以用 debugfs 来查看这些设置。
首先 cat /sys/kernel/debug/pinctrl/pinctrl-handles 查看当前的功能配置:

Requested pin control handlers their pinmux maps:
...
device: 2502400.twi current state: sleep
  state: default
    type: MUX_GROUP controller 2000000.pinctrl group: PG8 (77) function: twi1 (18)
    type: CONFIGS_GROUP controller 2000000.pinctrl group PG8 (77)config 00000a09
  state: sleep
    type: MUX_GROUP controller 2000000.pinctrl group: PG8 (77) function: gpio_in (0)
    type: MUX_GROUP controller 2000000.pinctrl group: PG9 (78) function: gpio_in (0)
device: 2502800.twi current state: sleep
  state: default
    type: MUX_GROUP controller 2000000.pinctrl group: PD20 (41) function: twi2 (4)
    type: CONFIGS_GROUP controller 2000000.pinctrl group PD20 (41)config 00000a09
    type: MUX_GROUP controller 2000000.pinctrl group: PD21 (42) function: twi2 (4)
    type: CONFIGS_GROUP controller 2000000.pinctrl group PD21 (42)config 00000a09
  state: sleep
    type: MUX_GROUP controller 2000000.pinctrl group: PD20 (41) function: gpio_in (0)
    type: MUX_GROUP controller 2000000.pinctrl group: PD21 (42) function: gpio_in (0)
device: 2502c00.twi current state: sleep
  state: default
    type: MUX_GROUP controller 2000000.pinctrl group: PG10 (79) function: twi3 (22)
    type: CONFIGS_GROUP controller 2000000.pinctrl group PG10 (79)config 00000a09
    type: MUX_GROUP controller 2000000.pinctrl group: PG11 (80) function: twi3 (22)
    type: CONFIGS_GROUP controller 2000000.pinctrl group PG11 (80)config 00000a09
  state: sleep
    type: MUX_GROUP controller 2000000.pinctrl group: PG10 (79) function: gpio_in (0)
    type: MUX_GROUP controller 2000000.pinctrl group: PG11 (80) function: gpio_in (0)

很明显, PG9 没有配置上去,然后 cat /sys/kernel/debug/pinctrl/2000000.pinctrl/pinmux-pins 查看所有引脚的配置:

Pinmux settings per pin
Format: pin (name): mux_owner|gpio_owner (strict) hog?
...
pin 116 (PD20): device 2502800.twi function gpio_in group PD20
pin 117 (PD21): device 2502800.twi function gpio_in group PD21
...
pin 200 (PG8): device 2502400.twi function gpio_in group PG8
pin 201 (PG9): device 2502400.twi function gpio_in group PG9
pin 202 (PG10): device 2502c00.twi function gpio_in group PG10
pin 203 (PG11): device 2502c00.twi function gpio_in group PG11

这里参考 datasheet 说明 PG9 在 DTS 里面的配置是正确的,然后 cat /sys/kernel/debug/pinctrl/2000000.pinctrl/pinmux-functions 引脚复用功能:

...
function: twi2, groups = [ PB0 PB1 PB8 PB9 PC0 PC1 PD20 PD21 PE4 PE5 PE12 PE13 PG6 PG7 PG14 PG15 ]
...
function: twi1, groups = [ PB4 PB5 PE0 PE1 PE14 PE15 PG8 ]
...
function: twi3, groups = [ PB6 PB7 PC6 PC7 PE6 PE7 PE16 PE17 PG10 PG11 PG17 PG18 ]
...

然后, twi1 没有 PG9 ?所以是全志的 pinctrl 写错了。

这里, 2000000.pinctrl 叫什么由系统决定,见 cat /sys/kernel/debug/pinctrl/pinctrl-devices