GPIO /dev Interface

This is a /dev interface to the PIO/GPIO controller which can be used to toggle GPIO pins from userspace.

Note: This interface is deprecated. Please use the GPIO sysfs interface instead, available in 2.6.27 and later kernels. Documentation can be found in Documentation/gpio.txt in the kernel source tree.

Usage

To set up a GPIO device, first mount configfs under /config like this:

mkdir /config
mount -t configfs config /config

GPIO "objects" are represented as subdirectories under /config/gpio. To create a new object, simply create a new directory:

mkdir /config/gpio/leds

After this, you will find four files under /config/gpio/leds:

So if you want to control the LEDS using bits 0-7 on PORTB, you can do it like this:

echo 1 > /config/gpio/leds/gpio_id
echo 0xff > /config/gpio/leds/pin_mask     # Use pins 0-7
echo 0xff > /config/gpio/leds/oe_mask      # Enable output on pins 0-7
echo 1 > /config/gpio/leds/enabled         # Create the device

If mdev is enabled, /dev/gpio0 should appear after this. If you've created other GPIO devices before, the number may be different. Please check "dmesg" if you're unsure.

Now, you can control the LEDs by writing to /dev/gpio0:

echo -ne '\x00\x00\x00\xaa' > /dev/gpio0    # Turn on all odd-numbered LEDs

Patches

Example programs

The "gpio-test" program demonstrates various ways to read data from the GPIO device. Depending on the command line options, it can use regular blocking reads, async I/O (signals), poll(), nonblocking I/O or a combination.

Attachment sort Action Size Date Who Comment
elsegpio-test.tar.gz manage 2.3 K 21 Jun 2007 - 09:51 HaavardSkinnemoen Example program for reading gpio devices
elseavr32-gpio-dev-interface.patch manage 17.7 K 21 Jun 2007 - 09:47 HaavardSkinnemoen GPIO /dev interface for AVR32 (against 2.6.22-rc5)