User's Manual

Intel Quark - Programming GPIO From Linux
Most of GPIO capabilities of ECS board are exposed through Linux Sysfs interface, and can be
controlled using file based I/O. I will show how to use some of these capabilities using simple shell
commands. Of course instead of shell you can implement I/O using file manipulations from your
program written using your favorite programming language.
Digital GPIO - Sysfs Interface
GPIO Information
The following command gives information about GPIO in the system and shows if an IO port was
allocated to a module or Sysfs (user).
root@WRIDPB072:~#cat/sys/kernel/debug/gpio
GPIOs07,platform/sch_gpio.2398,sch_gpio.2398:
gpio5(pcal9555aexp0int)inhi
GPIOs815,intel_qrk_gip_gpio:
GPIOs1631,i2c/00025,pcal9555a,cansleep:
As you can see from the output all the GPIOs of ECS board is divided into 5 chunks:
1. GPIOs 0-1 - Intel Quark X1021 - GPIO[8:9] pins. These are GPIO pins on Legacy I/O bridge.
They are powered and active in S0 state only.
2. GPIOs 2-7 - Intel Quark X1021 - GPIO_SUS[0:5] pins. These are GPIO pins on Legacy I/O
bridge. They are powered and active in S3 (suspend) and S0 states.
3. GPIOs 8-15 - Intel Quark X1021 - GPIO[0:7] pins. These are GPIO pins on GPIO controller.
They are powered and active in S0 state only.
4. GPIOs 16-31 – pcal9555a(pcal9535a) I/O expander.
Exporting a GPIO Port to Sysfs
To make GPIO port controllable from sysfs you'll need to export it. This is done by writing GPIO port
number to /sys/class/gpio/export:
root@WRIDPB072:~#echo‐n"27">/sys/class/gpio/export
When this operation completes successfully a directory corresponding to the GPIO port number will
appear in sysfs. In this case /sys/class/gpio/gpio27. Once you finished working with I/O you should un-
export it by writing the GPIO port number to /sys/class/gpio/unexport.
Setting GPIO Port Direction
I/O direction is set by writing "in" (for input) or "out" (for output) to /sys/class/gpio/gpioXX/direction file.
root@WRIDPB072:~#echo‐n"out">/sys/class/gpio/gpio27/direction
2.3 Sample code
GWS-RFID RFID Reader 10