GPIO Pins

SYSFS

Squidge 1.7 introduces the new GPIO SYSFS interface, which allows one to control IO pins using files under the /sys directory. This is similar to the adm5120-leds kernel module, but provides more options. The adm5120-leds module is therefore deprecated.

When the system boots, all GPIO pins are owned by the kernel. They won't show up in the sysfs system until they are 'exported'. In order to export them, echo the pin number (for example 0) to the file /sys/class/gpio/export:

$ echo 0 > /sys/class/gpio/export

This will result in the pseudo-files for pin 0 showing up under /sys/class/gpio/gpio0 as:

/sys/class/gpio/gpio0/direction
/sys/class/gpio/gpio0/value
etc...

You can set the direction to either 'in' or 'out':

$ echo out > /sys/class/gpio/gpio0/direction

And then set the pin value with:

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

In the first command, the power LED will go off, and in the second it will go on. Of course, you need to know which pin values correspond to which LEDs, so see below for the mapping. You can read back the status of a pin by looking at the value file:

$ cat /sys/class/gpio/gpio0/value
1

Finally, if you want to load a kernel module which uses one of the GPIO pins (perhaps for an MMC card or 1-wire system), simply unexport the pin:

# echo 0 > /sys/class/gpio/unexport

The gpio<n> directory will be removed from the filesystem and available to kernel modules. Simple huh?

Find that GPIO pin!

On the board, LED pins used for link status are marked D3-12. There are two more marked D15, D16, which are the USB port status. Below is the list of kernel-defined pins, and their corresponding board markings:

  Pin kernel name    pin ID  Board marking
ADM5120_GPIO_PIN0       0      D13   (Power)
ADM5120_GPIO_PIN1       1      D15   (USB)
ADM5120_GPIO_PIN2       2
ADM5120_GPIO_PIN3       3      D16   (USB)
ADM5120_GPIO_PIN4       4
ADM5120_GPIO_PIN5       5
ADM5120_GPIO_PIN6       6
ADM5120_GPIO_PIN7       7
ADM5120_GPIO_P0L0       8      D3
ADM5120_GPIO_P0L1       9      D4
ADM5120_GPIO_P0L2       10
ADM5120_GPIO_P1L0       11     D5
ADM5120_GPIO_P1L1       12     D6
ADM5120_GPIO_P1L2       13
ADM5120_GPIO_P2L0       14     D7
ADM5120_GPIO_P2L1       15     D8
ADM5120_GPIO_P2L2       16
ADM5120_GPIO_P3L0       17     D9
ADM5120_GPIO_P3L1       18     D10
ADM5120_GPIO_P3L2       19
ADM5120_GPIO_P4L0       20     D11
ADM5120_GPIO_P4L1       21     D12
ADM5120_GPIO_P4L2       22