0

I am using Raspberry pi 4b with Linux raspberrypi 5.10.63-v7l+. I am writing simple userspace program for control one GPIO by ioctl() (in my case GPIO 13 for example). However program responses: Device or resource busy when I try to handle it. The investigation shows that all pins on gpiochip0 are occupied by sysfs:

root@raspberrypi:/home/pi# cat /sys/kernel/debug/gpio 
gpiochip0: GPIOs 0-57, parent: platform/fe200000.gpio, pinctrl-bcm2711:
 gpio-0   (ID_SDA              )
 gpio-1   (ID_SCL              )
 gpio-2   (SDA1                |sysfs               ) in  hi 
 gpio-3   (SCL1                |sysfs               ) in  hi 
 gpio-4   (GPIO_GCLK           |sysfs               ) in  hi 
 gpio-5   (GPIO5               |sysfs               ) in  hi 
 gpio-6   (GPIO6               |sysfs               ) in  hi 
 gpio-7   (SPI_CE1_N           |spi0 CS1            ) out hi ACTIVE LOW
 gpio-8   (SPI_CE0_N           |spi0 CS0            ) out hi ACTIVE LOW
 gpio-9   (SPI_MISO            |sysfs               ) in  lo 
 gpio-10  (SPI_MOSI            |sysfs               ) in  lo 
 gpio-11  (SPI_SCLK            |sysfs               ) in  lo 
 gpio-12  (GPIO12              |sysfs               ) in  lo 
 gpio-13  (GPIO13              |sysfs               ) in  lo 
 gpio-14  (TXD1                |sysfs               ) in  hi 
 gpio-15  (RXD1                |sysfs               ) in  hi 
 gpio-16  (GPIO16              |sysfs               ) in  lo 
 gpio-17  (GPIO17              |sysfs               ) in  lo 
 gpio-18  (GPIO18              |sysfs               ) in  lo 
 gpio-19  (GPIO19              |sysfs               ) in  lo 
 gpio-20  (GPIO20              |sysfs               ) in  lo 
 gpio-21  (GPIO21              |sysfs               ) in  lo 
 gpio-22  (GPIO22              |sysfs               ) in  lo 
 gpio-23  (GPIO23              |sysfs               ) in  lo 
 gpio-24  (GPIO24              |sysfs               ) in  lo 
 gpio-25  (GPIO25              |sysfs               ) in  lo 
 gpio-26  (GPIO26              |sysfs               ) in  lo 
 gpio-27  (GPIO27              |sysfs               ) in  lo 
 gpio-28  (RGMII_MDIO          )
 gpio-29  (RGMIO_MDC           )
 gpio-30  (CTS0                )
 gpio-31  (RTS0                )
 gpio-32  (TXD0                )
 gpio-33  (RXD0                )
 gpio-34  (SD1_CLK             )
 gpio-35  (SD1_CMD             )
 gpio-36  (SD1_DATA0           )
 gpio-37  (SD1_DATA1           )
 gpio-38  (SD1_DATA2           )
 gpio-39  (SD1_DATA3           )
 gpio-40  (PWM0_MISO           )
 gpio-41  (PWM1_MOSI           )
 gpio-42  (STATUS_LED_G_CLK    |led0                ) out lo 
 gpio-43  (SPIFLASH_CE_N       )
 gpio-44  (SDA0                )
 gpio-45  (SCL0                )
 gpio-46  (RGMII_RXCLK         )
 gpio-47  (RGMII_RXCTL         )
 gpio-48  (RGMII_RXD0          )
 gpio-49  (RGMII_RXD1          )
 gpio-50  (RGMII_RXD2          )
 gpio-51  (RGMII_RXD3          )
 gpio-52  (RGMII_TXCLK         )
 gpio-53  (RGMII_TXCTL         )
 gpio-54  (RGMII_TXD0          )
 gpio-55  (RGMII_TXD1          )
 gpio-56  (RGMII_TXD2          )
 gpio-57  (RGMII_TXD3          )

gpiochip1: GPIOs 504-511, parent: platform/soc:firmware:gpio, raspberrypi-exp-gpio, can sleep:
 gpio-504 (BT_ON               )
 gpio-505 (WL_ON               )
 gpio-506 (PWR_LED_OFF         |led1                ) out lo ACTIVE LOW
 gpio-507 (GLOBAL_RESET        )
 gpio-508 (VDD_SD_IO_SEL       |vdd-sd-io           ) out hi 
 gpio-509 (CAM_GPIO            )
 gpio-510 (SD_PWR_ON           |sd_vcc_reg          ) out hi 
 gpio-511 (SD_OC_N            

same thing if try to run gpioinfo:

pi@raspberrypi:~ $ gpioinfo
gpiochip0 - 58 lines:
    line   0:     "ID_SDA"       unused   input  active-high 
    line   1:     "ID_SCL"       unused   input  active-high 
    line   2:       "SDA1"      "sysfs"   input  active-high [used]
    line   3:       "SCL1"      "sysfs"   input  active-high [used]
    line   4:  "GPIO_GCLK"      "sysfs"   input  active-high [used]
    line   5:      "GPIO5"      "sysfs"   input  active-high [used]
    line   6:      "GPIO6"      "sysfs"   input  active-high [used]
    line   7:  "SPI_CE1_N"   "spi0 CS1"  output   active-low [used]
    line   8:  "SPI_CE0_N"   "spi0 CS0"  output   active-low [used]
    line   9:   "SPI_MISO"      "sysfs"   input  active-high [used]
    line  10:   "SPI_MOSI"      "sysfs"   input  active-high [used]
    line  11:   "SPI_SCLK"      "sysfs"   input  active-high [used]
    line  12:     "GPIO12"      "sysfs"   input  active-high [used]
    line  13:     "GPIO13"      "sysfs"   input  active-high [used]
    line  14:       "TXD1"      "sysfs"   input  active-high [used]
    line  15:       "RXD1"      "sysfs"   input  active-high [used]
    line  16:     "GPIO16"      "sysfs"   input  active-high [used]
    line  17:     "GPIO17"      "sysfs"   input  active-high [used]
    line  18:     "GPIO18"      "sysfs"   input  active-high [used]
    line  19:     "GPIO19"      "sysfs"   input  active-high [used]
    line  20:     "GPIO20"      "sysfs"   input  active-high [used]
    line  21:     "GPIO21"      "sysfs"   input  active-high [used]
    line  22:     "GPIO22"      "sysfs"   input  active-high [used]
    line  23:     "GPIO23"      "sysfs"   input  active-high [used]
    line  24:     "GPIO24"      "sysfs"   input  active-high [used]
    line  25:     "GPIO25"      "sysfs"   input  active-high [used]
    line  26:     "GPIO26"      "sysfs"   input  active-high [used]
    line  27:     "GPIO27"      "sysfs"   input  active-high [used]

The situation is strange because first minute after kernel restart gpio pins are not occupied and I can run my program but then somehow they become "used" by sysfs. Even if I don't run any program situation is same. Of course it is possible to unexport each pin by echo in sysfs and run my program without problem but I can't understand reason of this behavior. How to find who is occupying gpiochip0?

2
  • This does not happen for me on a Pi400. I can only assume you start a GPIO program which has this behaviour. What GPIO related programs are you running?
    – joan
    Jan 28, 2022 at 16:58
  • @joan Thank you for reply. I am trying to control GPIO by ioctl() requests. The example could be find here on github I guess that there is other program or service tries to use GPIO because on another OS image everything works without problem
    – Aro Math
    Jan 29, 2022 at 17:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.