MTK平台 通过adb shell 修改/显示 GPIO 状态

Posted bobuddy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MTK平台 通过adb shell 修改/显示 GPIO 状态相关的知识,希望对你有一定的参考价值。

 

adb_gpio.png

[DESCRIPTION]

通过adb shell 修改/显示 GPIO 状态.

[KEYWORD]
GPIO


[SOLUTION]

1. 显示 GPIO 状态:

1.1 MT6885之后的格式如下

cat /sys/devices/platform/pinctrl/mt_gpio
PIN: (MODE)(DIR)(DOUT)(DIN)(DRIVE)(SMT)(IES)(PULL_EN)(PULL_SEL)(R1 R0)
例如(kernel-4.14 DRIVE列宽度为2,其他列为1,其他kernel版本列宽度为1,注意对应关系):
cat sys/devices/platform/pinctrl/mt_gpio
pins base: 285, pins count: 227
PIN: (MODE)(DIR)(DOUT)(DIN)(DRIVE)(SMT)(IES)(PULL_EN)(PULL_SEL)(R1 R0)
000: 0001001111
001: 0000001110
002: 0000001110
......
NOTE:
各平台的mt_gpio的路径可能存在差异,可以使用以下命令进行查找
adb shell
find sys/ -name "mt_gpio"

例如:mt6763平台
find sys/ -name "mt_gpio" 输出如下
sys/devices/platform/10005000.pinctrl/mt_gpio

1.2 MT6763之后的格式如下

cat /sys/devices/platform/XXX.pinctrl/mt_gpio //XXX.pinctrl因平台而异
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R1] [R0] )
例如:mt6763平台
adb shell “cat /sys/devices/platform/10005000.pinctrl/mt_gpio” 输出如下:
PIN: [MODE] [DIR] [DOUT] [DIN] [PULL_EN] [PULL_SEL] [IES] [SMT] [DRIVE] ( [R1] [R0] )
0: 000111110
1: 010000110
2: 000010110
......

1.3 更旧的平台

cd /sys/class/misc/mtgpio 或者 cd /sys/devices/virtual/misc/mtgpio
cat pins

A、如果show出来的格式是xx: x x x x x x x x (冒号后面跟8个数字)
其对应的含义如下:
PIN: [MODE] [PULL_SEL] [DIN] [DOUT] [PULL_EN] [DIR] [IES] [SMT]

B、如果show出的格式是xx: x x x x x x x (冒号后面跟7个数字) //某些kernel-3.10
其对应的含义如下:
PIN: [MODE] [PULL_SEL] [DOUT] [PULL_EN] [DIR] [IES]

2. 各描述项含义

PIN IO编号
[MODE] 当前pin处于的mode
[DIR] 0:input pin, 1:output pin
[DOUT] 输出值
[DIN] 输入值
[PULL_EN] 只对input pin有效,使能上/下拉
[PULL_SEL] 只对input pin有效,1:上拉 0:下拉
[IES] 输入使能,1:input信号有效 0:input信号无效
[SMT] 使能施密特触发器
[DRIVE] 驱动能力,一般可取值0~7
([R1] [R0]) 当前GPIO pin的(上下拉)并联电阻的使能状态
1 0表示enable R1,disable R0
0 1表示disable R1,enable R0
1 1表示enable R1, enable R0
不打印出来,表示当前的GPIO pin不支持PUPD状况,即只有一个上拉电阻、一个下拉电阻

DTS中的设置相关问题:
支持PUPD的GPIO pin设置,举例:
bias-pull-up=<MTK_PUPD_SET_R1R0_01>//上拉R0
bias-pull-down=<MTK_PUPD_SET_R1R0_10> //下拉R1
bias-disabled;//即不上拉也不下拉

不支持PUPD的GPIO pin设置,举例:
bias-pull-up;//上拉
bias-pull-down;//下拉
bias-disabled;//即不上拉也不下拉

3.设置 GPIO 状态:

3.1 MT6885(kernel-4.14):

设置命令与MT6779一样,但注意mt_gpio节点属性为只读,如下,
-r--r--r-- 1 root root 4096 2019-07-01 08:20 sys/devices/platform/pinctrl/mt_gpio
进行设置前,需要root(user版本获取不了root权限)之后,chmod 0664 mt_gpio改变节点属性。

3.2 MT6768,MT6779:

单个设置命令:
echo [option] $pin_num $value > /sys/devices/platform/pinctrl/mt_gpio
[option]表示要设置的状态,可选值:mode,dir,out,pullen,pullsel,ies,smt,driving
$pin_num表示设置的gpio编号
$value表示待写入的值
例如:
echo mode 99 6 > /sys/devices/platform/pinctrl/mt_gpio
echo dir 99 1 > /sys/devices/platform/pinctrl/mt_gpio
echo out 99 1 > /sys/devices/platform/pinctrl/mt_gpio
echo pullen 99 1 > /sys/devices/platform/pinctrl/mt_gpio
NOTE:设置pullen时,
For pin with 2 pull resistors, $value can be 0 (R1=0, R0=0), 1 (R1=0, R0=1), 2 (R1=1, R0=0), 3 (R1=1, R0=1)
For pin with 1 pull resistor, $value can be 0 or 1

一次全部设置命令:
echo set $pin_num $mode $dir $dout $din $driving $smt $ies $pullen $pullsel > /sys/devices/platform/pinctrl/mt_gpio
echo set $pin_num $mode $dir $dout $din $driving $smt $ies $pullen $pullsel $r1 $r0 > /sys/devices/platform/pinctrl/mt_gpio
NOTE:
▪Set all attributes in a single command
▪Note1: all attributes shall not be separated with space
▪Note2: all attributes is 1 digit except $driving is 2 digits
▪Note3: din cannot be changed, $din is leaved here for convenience of command typing. Therefore, user can change fields from read string (obtained via cat mt_gpio) without removing $din

3.3 MT6763后的设置:

单个设置命令(可参考上文说明):
echo mode $pin_num $value > /sys/devices/platform/10005000.pinctrl/mt_gpio

echo dir $pin_num $value > /sys/devices/platform/10005000.pinctrl/mt_gpio

echo dout $pin_num $value > /sys/devices/platform/10005000.pinctrl/mt_gpio

echo pullen $pin_num $value > /sys/devices/platform/10005000.pinctrl/mt_gpio
For pin with 2 pull resistors, $value can be 0 (R1=0, R0=0), 1 (R1=0, R0=1), 2 (R1=1, R0=0), 3 (R1=1, R0=1)
For pin with 1 pull resistor, $value can be 0 or 1

echo pullsel $pin_num $value > /sys/devices/platform/10005000.pinctrl/mt_gpio

一次性设置如下:
echo set $pin_num $mode $dir $dout $din $pullen $pullsel $ies $smt $driving > /sys/devices/platform/10005000.pinctrl/mt_gpio

echo set $pin_num $mode $dir $dout $din $pullen $pullsel $ies $smt $driving $r1 $r0 > /sys/devices/platform/10005000.pinctrl/mt_gpio

▪Set all attributes in a single command
▪Note1: all all attributes shall not be separated with space
▪Note2: din cannot be changed, $din is leaved here for convenience of command typing. Therefore, user can change fields from read string (obtained via cat mt_gpio) without removing $din

例如:
设置GPIO99 mode 3
echo mode 99 3 > mt_gpio

设置GPIO99 dir out
echo dir 99 1 > mt_gpio

设置GPIO99 dir in
echo dir 99 0 > mt_gpio
........

MT6763一次全部设置:
echo set 99 000011110 > /sys/devices/platform/10005000.pinctrl/mt_gpio

3.4 更旧平台的设置:

单独设置GPIO的某项信息如下:
echo -wmode num x > pin //num: pin number x: the mode 0~7
echo -wpsel num x > pin //x: 1,pull up; 0,pull down
echo -wdout num x > pin //x:1,high; 0,low
echo -wpen num x > pin //x: 1,pull enable; 0,pull disable
echo -wies num x > pin //x: 1,ies enable; 0, ies disable
echo -wdir num x > pin //x: 1,output; 0,input
一次性设置GPIO的所有项值如下:
echo -w=num:x x x x x x x > pin //x: [MODE] [PSEL] [DOUT] [PEN] [DIR] [IES] [SMT]
如上面某些kenrel-3.10只能show出来当前pin的7个数字的GPIO的一次性设置GPIO各项值
echo -w=num:x x x x x x > pin //x: [MODE] [PSEL] [DOUT] [PEN] [DIR] [IES]

例如:
adb shell "echo "-w=99:0 1 0 0 0 1 0" >/sys/devices/virtual/misc/mtgpio/pin"

以上是关于MTK平台 通过adb shell 修改/显示 GPIO 状态的主要内容,如果未能解决你的问题,请参考以下文章

如何通过adb shell 修改/显示 GPIO 状态

android MTK平台 user/eng 版本的差别

MTK(6737)平台wifi、省晶体总结

MTK6833_android12_user版本修改adb_root_&_apk_root

Android系统-MTK6833_android12_user版本修改adb_root_&_apk_root

mtk平台修改init.rc后如何快速编译啊