TX2/Xavier Linux GPIO 计算
Linux GPIO子系统
Linux命令行常用echo, cat等操作GPIO:
# 列出Linux GPIO空间目录
$ ls /sys/class/gpio
export gpiochip232 gpiochip240 gpiochip256 gpiochip320 unexport
# 导出GPIO到用户空间
# GPIO4_CAM_STROBE -> GPIO3_PV.05 -> V=>2, 2*8+256+5=277
$ echo 277 > /sys/class/gpio/export
# 取消导出把export换成unexport
$ ls /sys/class/gpio
export gpio277 gpiochip232 gpiochip240 gpiochip256 gpiochip320 unexport
# 设置GPIO方向为输出
$ echo out > /sys/class/gpio/gpio277/direction
# 输出高电平
$ echo 1 > /sys/class/gpio/gpio277/value
# 查看电平
$ cat /sys/class/gpio/gpio277/value
1
当然这些命令断电失效, 可以写成脚本设置开机运行, 有兴趣搜索Ubuntu16,或者Ubuntu18设置开机脚本.
TX2 Linux GPIO计算
于上面277的由来 GPIO4_CAM_STROBE -> GPIO3_PV.05 -> V=>2, 2*8+256+5=277
原理图中用的是GPIO4_CAM_STROBE这个引脚:

查 Jetson TX2 Series Pinmux 这个xls表格:

表格中 GPIO4_CAM_STROBE -> GPIO3_PV.05.
https://github.com/torvalds/linux/blob/master/include/dt-bindings/gpio/tegra186-gpio.h github , linux的代码对TX2端口进行了编号(TX2->tegra186-gpio.h, Xavier->tegra194-gpio.h):
/* GPIOs implemented by main GPIO controller */
#define TEGRA186_MAIN_GPIO_PORT_A 0
#define TEGRA186_MAIN_GPIO_PORT_B 1
#define TEGRA186_MAIN_GPIO_PORT_C 2
#define TEGRA186_MAIN_GPIO_PORT_D 3
#define TEGRA186_MAIN_GPIO_PORT_E 4
#define TEGRA186_MAIN_GPIO_PORT_F 5
#define TEGRA186_MAIN_GPIO_PORT_G 6
#define TEGRA186_MAIN_GPIO_PORT_H 7
#define TEGRA186_MAIN_GPIO_PORT_I 8
#define TEGRA186_MAIN_GPIO_PORT_J 9
#define TEGRA186_MAIN_GPIO_PORT_K 10
#define TEGRA186_MAIN_GPIO_PORT_L 11
#define TEGRA186_MAIN_GPIO_PORT_M 12
#define TEGRA186_MAIN_GPIO_PORT_N 13
#define TEGRA186_MAIN_GPIO_PORT_O 14
#define TEGRA186_MAIN_GPIO_PORT_P 15
#define TEGRA186_MAIN_GPIO_PORT_Q 16
#define TEGRA186_MAIN_GPIO_PORT_R 17
#define TEGRA186_MAIN_GPIO_PORT_T 18
#define TEGRA186_MAIN_GPIO_PORT_X 19
#define TEGRA186_MAIN_GPIO_PORT_Y 20
#define TEGRA186_MAIN_GPIO_PORT_BB 21
#define TEGRA186_MAIN_GPIO_PORT_CC 22
#define TEGRA186_MAIN_GPIO(port, offset) \
((TEGRA186_MAIN_GPIO_PORT_##port * 8) + offset)
/* GPIOs implemented by AON GPIO controller */
#define TEGRA186_AON_GPIO_PORT_S 0
#define TEGRA186_AON_GPIO_PORT_U 1
#define TEGRA186_AON_GPIO_PORT_V 2
#define TEGRA186_AON_GPIO_PORT_W 3
#define TEGRA186_AON_GPIO_PORT_Z 4
#define TEGRA186_AON_GPIO_PORT_AA 5
#define TEGRA186_AON_GPIO_PORT_EE 6
#define TEGRA186_AON_GPIO_PORT_FF 7
#define TEGRA186_AON_GPIO(port, offset) \
((TEGRA186_AON_GPIO_PORT_##port * 8) + offset)
- TEGRA186_MAIN_GPIO, 也就是tegra-gpio, at base index 320, 来源 TX2 GPIO Changes
- TEGRA186_AON_GPIO, 也就是tegra-gpio-aon, at base index 256
- offset = base + pin
- TEGRA186_AON_GPIO_PORT_V对应2, 属于tegra-gpio-aon组, 基值是256, 那么 GPIO3_PV.05 对应的就是TEGRA186_MAIN_GPIO(V, (256+5)) => ((TEGRA186_MAIN_GPIO_PORT_V* 8) + offset) = 2*8+256+5 = 277.
Xavier Linux GPIO计算
tegra194-gpio.h, 这里把Xavier的 linux/include/dt-bindings/gpio/tegra194-gpio.h github也贴过来方便查阅:
#ifndef _DT_BINDINGS_GPIO_TEGRA194_GPIO_H
#define _DT_BINDINGS_GPIO_TEGRA194_GPIO_H
#include <dt-bindings/gpio/gpio.h>
/* GPIOs implemented by main GPIO controller */
#define TEGRA194_MAIN_GPIO_PORT_A 0
#define TEGRA194_MAIN_GPIO_PORT_B 1
#define TEGRA194_MAIN_GPIO_PORT_C 2
#define TEGRA194_MAIN_GPIO_PORT_D 3
#define TEGRA194_MAIN_GPIO_PORT_E 4
#define TEGRA194_MAIN_GPIO_PORT_F 5
#define TEGRA194_MAIN_GPIO_PORT_G 6
#define TEGRA194_MAIN_GPIO_PORT_H 7
#define TEGRA194_MAIN_GPIO_PORT_I 8
#define TEGRA194_MAIN_GPIO_PORT_J 9
#define TEGRA194_MAIN_GPIO_PORT_K 10
#define TEGRA194_MAIN_GPIO_PORT_L 11
#define TEGRA194_MAIN_GPIO_PORT_M 12
#define TEGRA194_MAIN_GPIO_PORT_N 13
#define TEGRA194_MAIN_GPIO_PORT_O 14
#define TEGRA194_MAIN_GPIO_PORT_P 15
#define TEGRA194_MAIN_GPIO_PORT_Q 16
#define TEGRA194_MAIN_GPIO_PORT_R 17
#define TEGRA194_MAIN_GPIO_PORT_S 18
#define TEGRA194_MAIN_GPIO_PORT_T 19
#define TEGRA194_MAIN_GPIO_PORT_U 20
#define TEGRA194_MAIN_GPIO_PORT_V 21
#define TEGRA194_MAIN_GPIO_PORT_W 22
#define TEGRA194_MAIN_GPIO_PORT_X 23
#define TEGRA194_MAIN_GPIO_PORT_Y 24
#define TEGRA194_MAIN_GPIO_PORT_Z 25
#define TEGRA194_MAIN_GPIO_PORT_FF 26
#define TEGRA194_MAIN_GPIO_PORT_GG 27
#define TEGRA194_MAIN_GPIO(port, offset) \
((TEGRA194_MAIN_GPIO_PORT_##port * 8) + offset)
/* GPIOs implemented by AON GPIO controller */
#define TEGRA194_AON_GPIO_PORT_AA 0
#define TEGRA194_AON_GPIO_PORT_BB 1
#define TEGRA194_AON_GPIO_PORT_CC 2
#define TEGRA194_AON_GPIO_PORT_DD 3
#define TEGRA194_AON_GPIO_PORT_EE 4
#define TEGRA194_AON_GPIO(port, offset) \
((TEGRA194_AON_GPIO_PORT_##port * 8) + offset)
#endif
基地值也变了:
- tegra-gpio, at base index 288
- tegra-gpio-aon, at base index 248
如 原理图中的信号 SPI1_SCK: - 查 Jetson AGX Xavier Pinmux表格, 对应 GPIO3_PZ.03
- 上面头文件tegra194-gpio.h定义了#define TEGRA194_MAIN_GPIO_PORT_Z 25
- TEGRA194_MAIN_GPIO, 也就是tegra-gpio, 基值为288
- Linux GPIO计算结果: 25*8 + 288 + 3 = 491
待续…
TX2/Xavier Linux GPIO 计算

这篇博客详细介绍了如何在Jetson TX2和Xavier上进行Linux GPIO的计算和配置。通过Linux命令行操作GPIO,如导出、设置方向和读写值,并解析了GPIO编号的计算方法,引用了相关的Linux内核头文件。还提供了开机脚本设置的提示,以及针对不同设备GPIO计算的差异。
1797

被折叠的 条评论
为什么被折叠?



