Hello all,
I’m hoping someone here might be able to point me in the right direction. I’ve been trying to attach a button to the GPIO header on my Radxa Zero, configured by an overlay that uses gpio-keys. I’m unable to get it working though. I’m interested in using an overlay so that I don’t have to have another program (MRAA program, python script, etc.) running and I want to trigger keyboard presses. Here are some details:
- Radxa Zero v1.51 (no eMMC)
- Running Ubuntu (originally downloaded
radxa-zero-ubuntu-focal-server-arm64-20220801-0346-mbr.img.xz
from https://github.com/radxa-build/radxa-zero/releases)
$ uname -a
Linux radxa-zero 5.10.69-13-amlogic-g104342c59952 #amlogic SMP PREEMPT Thu Sep 15 13:06:12 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal
I attached a button, with one end at pin 12 (GPIOX_9, “GPIO Number” 501) and the other at pin 14 (GND).
I downloaded the kernel source and I created this DTS file (arch/arm64/boot/dts/amlogic/overlay/meson-g12a-gpio-keyboard.dts
), referencing various sources:
/dts-v1/;
/plugin/;
#include <dt-bindings/input/input.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/gpio/meson-g12a-gpio.h>
/ {
compatible = "radxa,zero", "amlogic,g12a";
fragment@0 {
target-path = "/";
__overlay__ {
gpio-keys {
compatible = "gpio-keys";
#address-cells = <1>;
#size-cells = <0>;
autorepeat;
5-key {
label = "5";
linux,code = <KEY_5>;
gpios = <&gpio GPIOX_9 (GPIO_ACTIVE_LOW)>;
gpio-key,wakeup;
autorepeat;
};
};
};
};
};
Then ran the following commands:
make dtbs
sudo cp arch/arm64/boot/dts/amlogic/overlay/meson-g12a-gpio-keyboard.dtbo /boot/dtbs/$(uname -r)/amlogic/overlay/
Then I edited /boot/uEnv.txt
to change the overlays line to: overlays=meson-g12a-gpio-keyboard
When I reboot, I can see that the overlay is being read in the boot messages, but the device is fully booted and I press the button, it does not trigger a keyboard press. I believe it has something to do with the GPIO pins not being configured correctly but something else might be happening. Below is what I’ve done to troubleshoot. I appreciate any help. Thanks in advance.
I’m guessing this indicates why nothing is happening, but I have so far been unable to find out any further information to help me.
$ dmesg | grep -i gpio-keys
[ 1.782937] gpio-keys gpio-keys: Unable to get irq number for GPIO 0, error -6
It appears that the overlay is loaded and even seen by the kernel.
$ ls -al /proc/device-tree/gpio-keys/
total 0
-r--r--r-- 1 root root 4 Apr 12 20:02 '#address-cells'
-r--r--r-- 1 root root 4 Apr 12 20:02 '#size-cells'
drwxr-xr-x 3 root root 0 Apr 12 20:02 .
drwxr-xr-x 36 root root 0 Sep 8 2022 ..
drwxr-xr-x 2 root root 0 Apr 12 20:02 5-key
-r--r--r-- 1 root root 0 Apr 12 20:02 autorepeat
-r--r--r-- 1 root root 10 Apr 12 20:02 compatible
-r--r--r-- 1 root root 10 Apr 12 20:02 name
$ dtc -I fs -O dts /sys/firmware/devicetree/base | less; # Then search for "gpio-keys"
gpio-keys {
#address-cells = <0x01>;
autorepeat;
#size-cells = <0x00>;
compatible = "gpio-keys";
5-key {
autorepeat;
label = [35 00];
gpio-key,wakeup;
linux,code = <0x06>;
gpios = <0x30 0x4a 0x01>;
};
};
It looks like gpio-keys
is active within the kernel. gpio-keys-polled
is not, which is why I haven’t tried to use that. I don’t want to have to recompile the kernel or have something break when the device is updated.
$ zcat /proc/config.gz | grep KEYBOARD_GPIO
CONFIG_KEYBOARD_GPIO=y
# CONFIG_KEYBOARD_GPIO_POLLED is not set
Other places I’ve checked seem to indicate that the pin has not been set correctly:
$ sudo cat /sys/kernel/debug/gpio
gpiochip1: GPIOs 412-426, parent: platform/ff800000.sys-ctrl:pinctrl@14, aobus-banks:
gpio-420 ( |radxa-zero:green ) out lo
gpiochip0: GPIOs 427-511, parent: platform/ff634400.bus:pinctrl@40, periphs-banks:
gpio-451 ( |regulator-vcc_5v ) out lo ACTIVE LOW
gpio-464 ( |reset ) out hi ACTIVE LOW
gpio-474 ( |cd ) in lo ACTIVE LOW
gpio-475 ( |sysfs ) out lo
gpio-498 ( |reset ) out hi ACTIVE LOW
gpio-501 ( |sysfs ) out lo
gpio-509 ( |shutdown ) out hi
$ sudo cat /sys/kernel/debug/pinctrl/ff634400.bus:pinctrl@40-pinctrl-meson/pinconf-pins
Pin config settings per pin
Format: pin (name): configs
pin 0 (GPIOZ_0): input bias pull up, output drive strength (500 uA)
pin 1 (GPIOZ_1): input bias pull up, output drive strength (500 uA)
pin 2 (GPIOZ_2): input bias pull up, output drive strength (500 uA)
pin 3 (GPIOZ_3): input bias pull up, output drive strength (500 uA)
pin 4 (GPIOZ_4): input bias pull up, output drive strength (500 uA)
pin 5 (GPIOZ_5): input bias pull up, output drive strength (500 uA)
pin 6 (GPIOZ_6): input bias pull up, output drive strength (500 uA)
pin 7 (GPIOZ_7): input bias pull up, output drive strength (500 uA)
pin 8 (GPIOZ_8): input bias pull up, output drive strength (500 uA)
pin 9 (GPIOZ_9): input bias pull down, output drive strength (500 uA)
pin 10 (GPIOZ_10): input bias pull down, output drive strength (500 uA)
pin 11 (GPIOZ_11): input bias pull down, output drive strength (500 uA)
pin 12 (GPIOZ_12): input bias pull down, output drive strength (500 uA)
pin 13 (GPIOZ_13): input bias pull down, output drive strength (500 uA)
pin 14 (GPIOZ_14): input bias disabled, output drive strength (500 uA)
pin 15 (GPIOZ_15): input bias disabled, output drive strength (500 uA)
pin 16 (GPIOH_0): input bias disabled, output drive strength (4000 uA)
pin 17 (GPIOH_1): input bias disabled, output drive strength (4000 uA)
pin 18 (GPIOH_2): input bias disabled, output drive strength (500 uA)
pin 19 (GPIOH_3): input bias pull up, output drive strength (500 uA)
pin 20 (GPIOH_4): input bias pull down, output drive strength (500 uA)
pin 21 (GPIOH_5): input bias pull down, output drive strength (500 uA)
pin 22 (GPIOH_6): input bias pull down, output drive strength (500 uA)
pin 23 (GPIOH_7): input bias pull down, output drive strength (500 uA)
pin 24 (GPIOH_8): input bias pull up, output drive strength (500 uA), output enabled, pin output (0 level)
pin 25 (BOOT_0): input bias pull up, output drive strength (4000 uA)
pin 26 (BOOT_1): input bias pull up, output drive strength (4000 uA)
pin 27 (BOOT_2): input bias pull up, output drive strength (4000 uA)
pin 28 (BOOT_3): input bias pull up, output drive strength (4000 uA)
pin 29 (BOOT_4): input bias pull up, output drive strength (4000 uA)
pin 30 (BOOT_5): input bias pull up, output drive strength (4000 uA)
pin 31 (BOOT_6): input bias pull up, output drive strength (4000 uA)
pin 32 (BOOT_7): input bias pull up, output drive strength (4000 uA)
pin 33 (BOOT_8): input bias pull down, output drive strength (4000 uA)
pin 34 (BOOT_9): input bias pull down, output drive strength (4000 uA)
pin 35 (BOOT_10): input bias pull up, output drive strength (4000 uA)
pin 36 (BOOT_11): input bias pull up, output drive strength (4000 uA)
pin 37 (BOOT_12): input bias pull up, output drive strength (4000 uA), output enabled, pin output (1 level)
pin 38 (BOOT_13): input bias pull down, output drive strength (4000 uA)
pin 39 (BOOT_14): input bias pull up, output drive strength (4000 uA)
pin 40 (BOOT_15): input bias pull up, output drive strength (4000 uA)
pin 41 (GPIOC_0): input bias pull up, output drive strength (4000 uA)
pin 42 (GPIOC_1): input bias pull up, output drive strength (4000 uA)
pin 43 (GPIOC_2): input bias pull up, output drive strength (4000 uA)
pin 44 (GPIOC_3): input bias pull up, output drive strength (4000 uA)
pin 45 (GPIOC_4): input bias disabled, output drive strength (4000 uA)
pin 46 (GPIOC_5): input bias pull up, output drive strength (4000 uA)
pin 47 (GPIOC_6): input bias pull up, output drive strength (4000 uA)
pin 48 (GPIOC_7): input bias pull up, output drive strength (4000 uA), output enabled, pin output (0 level)
pin 49 (GPIOA_0): input bias pull down, output drive strength (500 uA)
pin 50 (GPIOA_1): input bias pull down, output drive strength (500 uA)
pin 51 (GPIOA_2): input bias pull down, output drive strength (500 uA)
pin 52 (GPIOA_3): input bias pull down, output drive strength (500 uA)
pin 53 (GPIOA_4): input bias pull down, output drive strength (500 uA)
pin 54 (GPIOA_5): input bias pull down, output drive strength (500 uA)
pin 55 (GPIOA_6): input bias pull down, output drive strength (500 uA)
pin 56 (GPIOA_7): input bias pull down, output drive strength (500 uA)
pin 57 (GPIOA_8): input bias pull down, output drive strength (500 uA)
pin 58 (GPIOA_9): input bias pull down, output drive strength (500 uA)
pin 59 (GPIOA_10): input bias pull down, output drive strength (500 uA)
pin 60 (GPIOA_11): input bias pull down, output drive strength (500 uA)
pin 61 (GPIOA_12): input bias pull down, output drive strength (500 uA)
pin 62 (GPIOA_13): input bias pull down, output drive strength (500 uA)
pin 63 (GPIOA_14): input bias disabled, output drive strength (3000 uA)
pin 64 (GPIOA_15): input bias disabled, output drive strength (3000 uA)
pin 65 (GPIOX_0): input bias disabled, output drive strength (4000 uA)
pin 66 (GPIOX_1): input bias disabled, output drive strength (4000 uA)
pin 67 (GPIOX_2): input bias disabled, output drive strength (4000 uA)
pin 68 (GPIOX_3): input bias disabled, output drive strength (4000 uA)
pin 69 (GPIOX_4): input bias disabled, output drive strength (4000 uA)
pin 70 (GPIOX_5): input bias disabled, output drive strength (4000 uA)
pin 71 (GPIOX_6): input bias pull down, output drive strength (500 uA), output enabled, pin output (1 level)
pin 72 (GPIOX_7): input bias pull up, output drive strength (500 uA)
pin 73 (GPIOX_8): input bias pull up, output drive strength (500 uA)
pin 74 (GPIOX_9): input bias pull up, output drive strength (500 uA), output enabled, pin output (0 level)
pin 75 (GPIOX_10): input bias pull up, output drive strength (500 uA)
pin 76 (GPIOX_11): input bias pull up, output drive strength (500 uA)
pin 77 (GPIOX_12): input bias disabled, output drive strength (500 uA)
pin 78 (GPIOX_13): input bias disabled, output drive strength (500 uA)
pin 79 (GPIOX_14): input bias disabled, output drive strength (500 uA)
pin 80 (GPIOX_15): input bias disabled, output drive strength (500 uA)
pin 81 (GPIOX_16): input bias disabled, output drive strength (500 uA)
pin 82 (GPIOX_17): input bias pull down, output drive strength (500 uA), output enabled, pin output (1 level)
pin 83 (GPIOX_18): input bias pull up, output drive strength (500 uA)
pin 84 (GPIOX_19): input bias disabled, output drive strength (500 uA)
$ sudo gpioinfo
gpiochip0 - 85 lines:
line 0: unnamed unused input active-high
line 1: unnamed unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed unused input active-high
line 4: unnamed unused input active-high
line 5: unnamed unused input active-high
line 6: unnamed unused input active-high
line 7: unnamed unused input active-high
line 8: unnamed unused input active-high
line 9: unnamed unused input active-high
line 10: unnamed unused input active-high
line 11: unnamed unused input active-high
line 12: unnamed unused input active-high
line 13: unnamed unused input active-high
line 14: unnamed unused input active-high
line 15: unnamed unused input active-high
line 16: unnamed unused input active-high
line 17: unnamed unused input active-high
line 18: unnamed unused input active-high
line 19: unnamed unused input active-high
line 20: unnamed unused input active-high
line 21: unnamed unused input active-high
line 22: unnamed unused input active-high
line 23: unnamed unused input active-high
line 24: unnamed "regulator-vcc_5v" output active-low [used open-drain]
line 25: unnamed unused input active-high
line 26: unnamed unused input active-high
line 27: unnamed unused input active-high
line 28: unnamed unused input active-high
line 29: unnamed unused input active-high
line 30: unnamed unused input active-high
line 31: unnamed unused input active-high
line 32: unnamed unused input active-high
line 33: unnamed unused input active-high
line 34: unnamed unused input active-high
line 35: unnamed unused input active-high
line 36: unnamed unused input active-high
line 37: unnamed "reset" output active-low [used]
line 38: unnamed unused input active-high
line 39: unnamed unused input active-high
line 40: unnamed unused input active-high
line 41: unnamed unused input active-high
line 42: unnamed unused input active-high
line 43: unnamed unused input active-high
line 44: unnamed unused input active-high
line 45: unnamed unused input active-high
line 46: unnamed unused input active-high
line 47: unnamed "cd" input active-low [used]
line 48: unnamed "sysfs" output active-high [used]
line 49: unnamed unused input active-high
line 50: unnamed unused input active-high
line 51: unnamed unused input active-high
line 52: unnamed unused input active-high
line 53: unnamed unused input active-high
line 54: unnamed unused input active-high
line 55: unnamed unused input active-high
line 56: unnamed unused input active-high
line 57: unnamed unused input active-high
line 58: unnamed unused input active-high
line 59: unnamed unused input active-high
line 60: unnamed unused input active-high
line 61: unnamed unused input active-high
line 62: unnamed unused input active-high
line 63: unnamed unused input active-high
line 64: unnamed unused input active-high
line 65: unnamed unused input active-high
line 66: unnamed unused input active-high
line 67: unnamed unused input active-high
line 68: unnamed unused input active-high
line 69: unnamed unused input active-high
line 70: unnamed unused input active-high
line 71: unnamed "reset" output active-low [used]
line 72: unnamed unused input active-high
line 73: unnamed unused input active-high
line 74: unnamed "sysfs" output active-high [used]
line 75: unnamed unused input active-high
line 76: unnamed unused input active-high
line 77: unnamed unused input active-high
line 78: unnamed unused input active-high
line 79: unnamed unused input active-high
line 80: unnamed unused input active-high
line 81: unnamed unused input active-high
line 82: unnamed "shutdown" output active-high [used]
line 83: unnamed unused input active-high
line 84: unnamed unused input active-high
gpiochip1 - 15 lines:
line 0: unnamed unused input active-high
line 1: unnamed unused input active-high
line 2: unnamed unused input active-high
line 3: unnamed unused input active-high
line 4: unnamed unused input active-high
line 5: unnamed unused input active-high
line 6: unnamed unused input active-high
line 7: unnamed unused input active-high
line 8: unnamed "radxa-zero:green" output active-high [used]
line 9: unnamed unused input active-high
line 10: unnamed unused input active-high
line 11: unnamed unused input active-high
line 12: unnamed unused input active-high
line 13: unnamed unused input active-high
line 14: unnamed unused input active-high
$ mraa-gpio list
01 3V3:
02 5V:
03 I2C_EE_M3_S: GPIO I2C
04 5V:
05 I2C_EE_M3_S: GPIO I2C
06 GND:
07 I2C_AO_M0_S: GPIO I2C UART
08 UART_AO_A_T: GPIO UART
09 GND:
10 UART_AO_A_R: GPIO UART
11 I2C_AO_M0_S: GPIO I2C UART
12 SPI_A_MISO: GPIO SPI
13 I2C_EE_M1_S: GPIO I2C SPI
14 GND:
15 SARADC_CH1:
16 I2C_EE_M1_S: GPIO I2C SPI
17 3V3:
18 SPI_A_MOSI,: GPIO SPI PWM
19 SPI_B_MOSI: GPIO SPI
20 GND:
21 SPI_B_MISO: GPIO SPI
22 GPIOC_7: GPIO
23 I2C_EE_M1_S: GPIO I2C SPI UART
24 UART_EE_C_R: GPIO I2C SPI UART
25 GND:
26 SARADC_CH2:
27 I2C_AO_M0_S: GPIO I2C UART
28 I2C_AO_M0_S: GPIO I2C UART
29 NC:
30 GND:
31 NC:
32 GPIOAO_4: GPIO
33 NC:
34 GND:
35 UART_AO_B_T: GPIO UART
36 GPIOH_8: GPIO
37 UART_AO_B_R: GPIO UART
38 GPIOAO_10: GPIO
39 GND:
40 PWMAO_A: GPIO PWM
lsinput
shows no information (unless a USB keyboard is plugged in)
gpiofind returns no information, so I can’t run gpiomon
$ sudo gpiofind PIN_12
$ sudo gpiomon -f $(sudo gpiofind PIN_12)
gpiomon: gpiochip must be specified
Thanks again,
- George