AI-64 - GPIO sysfs

Hi Guys,

I have been bumbling around trying to get this to work and have managed it, so though I would add this here to help any other poor bumblers. I’m sure this is basic stuff but I found it hard to find a worked example on the internet.

This example is for pin P8_07:

First find the gpiochips:

root@AI64:/sys/class/gpio# gpiodetect
gpiochip0 [42110000.gpio] (84 lines)
gpiochip1 [600000.gpio] (128 lines)
gpiochip2 [601000.gpio] (36 lines)

Then find the gpio details for the pin:

root@AI64:/sys/class/gpio# gpiofind P8_07
gpiochip1 15

Now have a look for the gpiochips:

root@AI64:/sys/class/gpio# ls -ltr /sys/class/gpio/gpiochip*
lrwxrwxrwx 1 root root 0 Jan  1  1970 /sys/class/gpio/gpiochip428 -> ../../devices/platform/bus@100000/bus@100000:bus@28380000/42110000.gpio/gpio/gpiochip428
lrwxrwxrwx 1 root root 0 Jan  1  1970 /sys/class/gpio/gpiochip264 -> ../../devices/platform/bus@100000/601000.gpio/gpio/gpiochip264
lrwxrwxrwx 1 root root 0 Jan  1  1970 /sys/class/gpio/gpiochip300 -> ../../devices/platform/bus@100000/600000.gpio/gpio/gpiochip300

Match via the address, 600000 for gpiochip1->gpiochip300

Calculate the gpio number the 300 in gpiochip is the base and we need to add 15 (from gpiofind command) so we have 315.

So export 315:

root@AI64:/sys/class/gpio# echo 315 > /sys/class/gpio/export
root@AI64:/sys/class/gpio# ls /sys/class/gpio/      
export	gpio315  gpiochip264  gpiochip300  gpiochip428	unexport

Now you have the gpio mapped, for example we can set it to an output and set the value to 1:

root@AI64:/sys/class/gpio# echo out > /sys/class/gpio/gpio315/direction 
root@AI64:/sys/class/gpio# echo 1 > /sys/class/gpio/gpio315/value
1 Like

and a quick update, we (@jkridner ) has a patchset to label all these gpio’s, it just didn’t get merged beforew we both went to Embedded World. So early next week i’ll merge those in… (after recovering from the flight/time/zone/travel/etc…)…

Regards,

1 Like