I have a pad multiplxed as GPIO on my board. When I try to export it via /sys/class/gpio/export, I get
-sh: echo: write error: Device or resource busy
My guess is some other driver is requesting this pad before I get that chance. How can I find out what is reserving it?
Linux kernel GPIO interface Internally, the Linux kernel implements the access to GPIOs via a producer/consumer model. There are drivers that produce GPIO lines (GPIO controllers drivers) and drivers that consume GPIO lines (keyboard, touchscreen, sensors, etc).
A GPIO controller driver is a KMDF driver that manages all hardware-specific operations for a GPIO controller. The GPIO controller driver cooperates with GpioClx to handle I/O requests for groups of GPIO pins that are configured as data inputs and data outputs.
The Linux GPIO number for a certain GPIO pin can be determined by adding the GPIO pin index to the port base index. For instance: i. MX6 GPIO2_4 (port 2, pin 4) is: 32 + 4 = 36.
You can use 'lsof' command to list the open files. according to fact that gpio files are regular files. (e.g /sys/class/gpio/gpio242/value). Also you should be sure of loading the right kernel modules (with insmod or modprobe) into memory.
On the Boundary Devices kernel, and maybe others, you can use cat /sys/kernel/debug/gpio
to get a list of the mapped gpios, their states, and name given when it was allocated. You can grep the kernel source for the name and find out what module grabbed it.
root@nitrogen6x:/opt# cat /sys/kernel/debug/gpio GPIOs 0-31, platform/209c000.gpio, 209c000.gpio: gpio-2 (flexcan-trx-stby ) out lo gpio-17 (DISP_SCL ) out lo GPIOs 32-63, platform/20a0000.gpio, 20a0000.gpio: gpio-33 (sysfs ) out lo gpio-35 (sysfs ) in hi gpio-36 (sysfs ) in hi gpio-37 (DISP_SDI ) out lo gpio-38 (219c000.usdhc cd ) in hi GPIOs 64-95, platform/20a4000.gpio, 20a4000.gpio: gpio-83 (spi_imx ) out lo gpio-86 (usb_otg_vbus ) out lo GPIOs 96-127, platform/20a8000.gpio, 20a8000.gpio: gpio-101 (sysfs ) in hi gpio-116 (rst-gpios ) out lo GPIOs 128-159, platform/20ac000.gpio, 20ac000.gpio: GPIOs 160-191, platform/20b0000.gpio, 20b0000.gpio: gpio-175 (wlan-en ) out lo gpio-176 (bt_rfkill_reset ) out lo GPIOs 192-223, platform/20b4000.gpio, 20b4000.gpio: gpio-192 (2198000.usdhc cd ) in lo gpio-204 (ehci_reset_gpio ) out lo gpio-205 (sysfs ) in lo
'
if you try to use cat /sys/kernel/debug/gpio
and it is not working, first try:
mount -t debugfs debugfs /sys/kernel/debug
and then use the aforementioned cat
command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With