论坛元老
- 积分
- 3571
- 金钱
- 3571
- 注册时间
- 2014-12-2
- 在线时间
- 365 小时
|
发表于 2021-1-6 11:48:25
|
显示全部楼层
传统的GPIO接口是从0开始排数字,取决于一组GPIO有8个或16个或32个端口,你需要自己手动计算需要的号码。
比如我的芯片一组GPIO有8个端口,那么GPIO5_4的号码就是44(=5*8+4),如图:
- ~ # ls -l /sys/class/gpio/
- total 0
- --w------- 1 root root 4096 Jan 1 1970 export
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip0 -> ../../devices/soc/soc:amba/12140000.gpio_chip/gpio/gpiochip0
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip104 -> ../../devices/soc/soc:amba/1214d000.gpio_chip/gpio/gpiochip104
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip112 -> ../../devices/soc/soc:amba/1214e000.gpio_chip/gpio/gpiochip112
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip128 -> ../../devices/soc/soc:amba/12150000.gpio_chip/gpio/gpiochip128
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip16 -> ../../devices/soc/soc:amba/12142000.gpio_chip/gpio/gpiochip16
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip24 -> ../../devices/soc/soc:amba/12143000.gpio_chip/gpio/gpiochip24
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip32 -> ../../devices/soc/soc:amba/12144000.gpio_chip/gpio/gpiochip32
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip40 -> ../../devices/soc/soc:amba/12145000.gpio_chip/gpio/gpiochip40
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip48 -> ../../devices/soc/soc:amba/12146000.gpio_chip/gpio/gpiochip48
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip56 -> ../../devices/soc/soc:amba/12147000.gpio_chip/gpio/gpiochip56
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip64 -> ../../devices/soc/soc:amba/12148000.gpio_chip/gpio/gpiochip64
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip72 -> ../../devices/soc/soc:amba/12149000.gpio_chip/gpio/gpiochip72
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip8 -> ../../devices/soc/soc:amba/12141000.gpio_chip/gpio/gpiochip8
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip80 -> ../../devices/soc/soc:amba/1214a000.gpio_chip/gpio/gpiochip80
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip88 -> ../../devices/soc/soc:amba/1214b000.gpio_chip/gpio/gpiochip88
- lrwxrwxrwx 1 root root 0 Jan 1 1970 gpiochip96 -> ../../devices/soc/soc:amba/1214c000.gpio_chip/gpio/gpiochip96
- --w------- 1 root root 4096 Jan 1 1970 unexport
- ~ #
复制代码
新版的Linux一般不建议用这种方式使用GPIO,而是改用设备树管理,用到时根据名字去申请,比如:
- my_cd_gpio = devm_gpiod_get(&pdev->dev, "cd");
复制代码
意思是申请这个设备下属的名为"cd"的gpio,会得到struct gpio_desc *的结构,后续可以用gpiod_set_value/gpiod_direction_input等新版gpiod_*系列接口操作它 |
|