Linux 如何从OpenWRT构建的UBoot读取GPIO值

Linux 如何从OpenWRT构建的UBoot读取GPIO值,linux,gpio,openwrt,u-boot,Linux,Gpio,Openwrt,U Boot,我正试图在OpenWRT驱动的板上实现恢复模式。 我有一个按钮连接到一些GPIO:GPIO_PL4 我使用下一个表达式将gpio名称转换为数字表示: (position of letter in alphabet - 1) * 32 + pin number 所以我得到了PL4--356映射 我试图将下面几行添加到uboot环境文件uEnv default.txt: if gpio input 356; then echo "The button is pressed"; f

我正试图在OpenWRT驱动的板上实现恢复模式。 我有一个按钮连接到一些GPIO:GPIO_PL4

我使用下一个表达式将gpio名称转换为数字表示:

(position of letter in alphabet - 1) * 32 + pin number
所以我得到了
PL4
--
356
映射

我试图将下面几行添加到uboot环境文件
uEnv default.txt

  if gpio input 356; then
     echo "The button is pressed";
  fi;
但在启动过程中收到错误消息:

  gpio: requesting pin 356 failed
  gpio - query and control gpio pins

  Usage:
  gpio <input|set|clear|toggle> <pin>
      - input/set/clear/toggle the specified pin
  gpio status [-a] [<bank> | <pin>]  - show [all/claimed] GPIOs
并得到下一个输出:

Bank PA:
...
Bank PL:
PL0: func
...
PL4: func     // does it mean that I'm not able to use it as an input
...
PL11: func
PL12: input: 0 [ ]
PL13: input: 0 [ ]
....
所以问题是:我是否能够使用PL4 gpio引脚作为当前gpio配置的输入,如果不能,我如何更改该引脚的gpio配置,如果可能的话


我想,我必须在U-Boot上应用补丁才能做出正确的gpio配置,对吗?

我找到了解决方案。有两个问题:

  • sunxi-8设备的U-boot(2018.11)至少没有使用上述表达式将gpio名称强制转换为数字表示(可以为U-boot
    gpio
    命令键入gpio名称:
    gpio输入pl4
  • 默认情况下,端口L在sunxi-8 CPU(至少是sun8i-h2-plus-orangepi-zero板)上未锁定/未通电,因此必须通过
    prcm\u apb0\u enable
    对其进行时钟/供电。看
  • Bank PA:
    ...
    Bank PL:
    PL0: func
    ...
    PL4: func     // does it mean that I'm not able to use it as an input
    ...
    PL11: func
    PL12: input: 0 [ ]
    PL13: input: 0 [ ]
    ....