This driver has been tested and is working. It has been accepted into the mainline kernel and the old char mode GPIO driver that didn't work with arch/powerpc has been removed from the tree.


There is some documentation in the kernel tree at Documentation/gpio.txt which is pretty good.

Kernel Configuration

The kernel needs the following configuration to make this work.


Using GPIO with SysFs

The GPIO driver fits in the Linux GPIO framework which is not a char mode driver. Yet it does provide access to the GPIO by user space thru the sysfs filesystem. This allows each GPIO signal to be read and written in similar manner to a char mode device. The interface is somewhat documented in the kernel tree at Documentation/gpio.txt. The following text is aimed to augment, not replace the existing documentation.

For the examples below, there are some important points with sysfs.

  1. The GPIO controllers are visible in /sys/class/gpio. Each controller controls a number of GPIO signals.
  2. The GPIO signals must be exported into the sysfs before they can be manipulated. The number of the GPIO signal must be written to the GPIO export file to cause this to happen.
  3. After exporting the GPIO signal, then a new directory based on the GPIO signal number will appear in /sys/class/gpio. Under that directory are direction and value files that can be read and written.

Mounting Sysfs

The root file system being used may not have sysfs mounted and it cannot be used if it's not mounted. The directory /sys is also needed to mount the sysfs on. The root file system must be writable to do the following steps.

bash> mkdir /sys
bash> mount -t sysfs sysfs /sys

Using the GPIO driver from User Space with Bash

Figuring out the exact GPIO was not totally obvious when there were multiple GPIOs in the system. One way to do is to go into
the gpiochips in /sys/class/gpio and view the label as it should reflect the address of the GPIO in the system. The name of the
the chip appears to be the 1st GPIO of the controller.

The following commands from the console setup the GPIO to be exported, set the direction of it to an output and write a 1 to the GPIO.

bash> echo 240 > /sys/class/gpio/export
bash> echo out > /sys/class/gpio/gpio240/direction
bash> echo 1 > /sys/class/gpio/gpio240/value

Using the GPIO Driver from a User Space Application

The performance of this is pretty good. Using nfs root, running open source linux on the ML507 reference system, the GPIO can be toggled about every 4 usec.

This page, GPIO User Space Application, shows the application and provides it for download.

User Mode GPIO Pseudo Driver

The purpose this is to show that users can get to devices in user mode for simple things like GPIO. This is not to say this should replace
a kernel driver, but does provide some short term solutions sometimes or a debug solution that can be helpful.

This test maps a GPIO in the hardware into the user space such that a GPIO signal can be toggled fast. On the ML507 reference system, the
signal could be toggled about every 50 ns which is pretty fast. This test was derived from devmem2.c.

This page, User Mode Pseudo Driver, shows the driver and provides it for download.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License