32

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?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Atilla Filiz
  • 2,383
  • 8
  • 29
  • 47

5 Answers5

39

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    

'

David Williams
  • 505
  • 4
  • 6
  • Thank you, this looks immensely useful. I wonder if it existed 3 years ago. – Atilla Filiz May 13 '16 at 20:34
  • Probably. I searched for the same question, and didn't find an answer, so I just did a `find /sys -name gpio` and found this, which let me know that I was requesting the wrong GPIO. – David Williams May 18 '16 at 16:17
7

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

AleFachini
  • 155
  • 1
  • 8
4

/sys/kernel/debug/gpio is part of the Legacy GPIO Interface and may not be present on newer kernels. A replacement is the gpioinfo tool of libgpio-tools; these tools use the newer character device interface for handling gpios.

If using buildroot, enable BR2_PACKAGE_LIBGPIOD and BR2_PACKAGE_LIBGPIOD_TOOLS.

buildroot:~ $ gpiodetect
gpiochip0 [30200000.gpio] (32 lines)
gpiochip1 [30210000.gpio] (32 lines)
gpiochip2 [30220000.gpio] (32 lines)
gpiochip3 [30230000.gpio] (32 lines)
gpiochip4 [30240000.gpio] (32 lines)
gpiochip5 [0-0023] (16 lines)

buildroot:~ $ gpioinfo
gpiochip0 - 32 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 "pci_usb_sel" output active-high [used]
    line   7:      unnamed       "dio0"   input  active-high [used]
    line   8:      unnamed       unused   input  active-high 
    line   9:      unnamed       "dio1"   input  active-high [used]
    line  10:      unnamed "regulator-usb-otg1" output active-high [used]
(...)
Robert Calhoun
  • 4,823
  • 1
  • 38
  • 34
1

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.

hich9n
  • 1,578
  • 2
  • 15
  • 32
  • 1
    That will not work as the sysfs node does not exist yet. Echoing the GPIO number to export should create the node, but it does not. – Atilla Filiz Aug 03 '13 at 12:14
  • If you load the right kernel module, you can see all of available gpio in /sys/devices/virtual/gpio/ directory. Whats your contents of directory? You can see the label file to follow its real position in schematics of board. – hich9n Aug 03 '13 at 16:04
1

We ended up using another GPIO pin. i.mx6 has 7 GPIO controllers with 32 pins each, and some conrollers were simply giving I/O errors out of seemingly nowhere.

Atilla Filiz
  • 2,383
  • 8
  • 29
  • 47