TX2: read keyboard key GPIO pin state


I’m trying to read Volume Up button status in a yocto linux distro without X.

I figured out on my carrier the GPIO pin is 313

# cat /sys/kernel/debug/gpio 
gpiochip2: GPIOs 248-255, parent: platform/max77620-gpio, max77620-gpio, can sleep:
 gpio-248 (                    |external-connection:) in  hi    
 gpio-253 (                    |spmic_gpio_input    ) in  lo    
 gpio-254 (                    |spmic_gpio_input    ) in  hi    

gpiochip1: GPIOs 256-319, parent: platform/c2f0000.gpio, tegra-gpio-aon:
 gpio-272 (                    |temp-alert          ) in  hi    
 gpio-312 (                    |Power               ) in  hi    
 gpio-313 (                    |Volume Up           ) in  hi    
 gpio-314 (                    |Volume Down         ) in  hi    
 gpio-315 (                    |wifi-wake-ap        ) in  hi    
 gpio-316 (                    |bt_host_wake        ) in  hi 

If I try to export GPIO pin 313 I get a Busy device error.

I need to read the state, not react to an event.


The GPIO is owned by the “gpio-keys” driver in the kernel. You can’t export it and use it as a generic GPIO at the same time as having it be a GPIO key.

Search for this fragment in your *.dtsi file for your board:

  volume_up {
  	label = "Volume Up";
  	gpios = <&tegra_aon_gpio TEGRA_AON_GPIO(FF, 1) GPIO_ACTIVE_LOW>;
  	linux,code = <KEY_VOLUMEUP>;

If you delete that from your dtsi file for your board and rebuild, load, etc. the new dtb you will be able to use it as a generic GPIO instead of a key.

Thanks, I saw the same as well.

I decided to read the button state in u-boot instead and pass the state up to kernel boot parameters.