gschorcht / spi-ch341-usb

Linux kernel driver for CH341A USB to SPI and GPIO adapters
161 stars 63 forks source link

Device or resource busy #5

Open DasPez opened 6 years ago

DasPez commented 6 years ago

Hello, I would like to use the character device interface /dev/gpiochip1. The sysfs interface works perfectly fine

# echo 1 > /sys/class/gpio/gpio0/value 
# echo 0 > /sys/class/gpio/gpio0/value 

but the character device is busy

# gpiodetect
gpiochip0 [INT345D:00] (203 lines)
gpiochip1 [ch341] (8 lines)
# gpioinfo gpiochip1
gpiochip1 - 8 lines:
    line   0:      "gpio0"      "gpio0"  output  active-high [used]
    line   1:      "gpio1"      "gpio1"  output  active-high [used]
    line   2:      "gpio2"      "gpio2"  output  active-high [used]
    line   3:      "gpio3"      "gpio3"  output  active-high [used]
    line   4:      "gpio4"      "gpio4"   input  active-high [used]
    line   5:      "gpio5"      "gpio5"   input  active-high [used]
    line   6:      "gpio6"      "gpio6"   input  active-high [used]
    line   7:      "gpio7"      "gpio7"   input  active-high [used]

# gpioset gpiochip1 0=1
gpioset: error setting the GPIO line values: Device or resource busy

I tried unexporting gpio0

# ls /sys/class/gpio/
export  gpio0  gpio1  gpio2  gpio3  gpio4  gpio5  gpio6  gpio7  gpiochip301  gpiochip309  unexport
# echo 0 > /sys/class/gpio/unexport 
bash: echo: write error: Invalid argument

Why are the gpio pin indices starting at 0 even though the controller base index is 301?

# cat /sys/class/gpio/gpiochip301/label 
ch341
# cat /sys/class/gpio/gpiochip301/base 
301
geeksville commented 4 years ago

It seems like @gschorcht is busy with other things, so I won't bother to send in a PR for this great driver. But I've merged various fixes from others needed to make the driver work for modern kernels and then I fixed the EBUSY problem you discovered (because it also happened to me).

In case it is useful, here's my fork: https://github.com/geeksville/spi-ch341-usb