GPIO in kernel mode

I want to experiment with accessing Apalis GPIO pins from a kernel driver. To that end, I’m trying to use gpio_request_array() to request the gpio pins when I load the module. The call fails. The pins I want to access come pre-exported and I can’t seem to unexport any of them:

root@apalis-t30:~# cd /sys/class/gpio/
root@apalis-t30:/sys/class/gpio# ls
export       gpio147      gpio150      gpio220      gpio223      gpiochip0
gpio129      gpio148      gpio216      gpio221      gpio225      gpiochip256
gpio146      gpio149      gpio219      gpio222      gpio226      unexport
root@apalis-t30:/sys/class/gpio# echo 146 > unexport 
-sh: echo: write error: Invalid argument

So how do I get access to the pins in a kernel mode driver?

Those GPIOs are requested in linux kernel during platform initialisation. There is an array called apalis_t30_gpios in arch/arm/mach-tegra/board-apalis_t30.c that defines which GPIOs will be exported. Adjust it as required and rebuild the kernel.

And there it is, right in front of my eyes. Thanks, this is exactly what I’m looking for.

You are welcome. Thanks for the feedback.