GPIO on ALIX.3D3

The AMD CS5536 Geode companion on the ALIX.3D3 board has several general purpose input/output pins. Most of them have different functions as well, and there are some registers to set if they should be used as special function GPIO pins. The ALIX.3D3 uses 4 GPIO pins for 3 LEDs and 1 mode switch. Accessing the leds is very easy using the leds-alix2 driver, but they can be addressed as GPIO as well. There is already a driver for the GPIO pins in the kernel named cs5535_gpio.c, but it uses a non standard interface to communicate with kernel. So, I wrote a new kernel driver using the GPIO interface.

Installating is very easy: Download the patch (GPIO drivers for AMD CS5535/CS5536 (Kernel 2.6.30-rc6)), patch it and compile the kernel:

wget http://www.twam.info/wp-content/uploads/2009/05/gpio.patch -O /root/gpio.patch
cd /usr/src/linux
patch -p1 < /root/gpio.patch

Now run kernel configuration and select

Device Drivers  --->
   [*] GPIO Support  --->
   [*]   /sys/class/gpio/... (sysfs interface)
   <*>   AMD CS5535/CS5536 (Geode Companion Device)

Compile the kernel and reboot. If you go to /sys/class/gpio there should be a file name gpiochip0. Now we can enable some pins and test them. By

echo 6 > /sys/class/gpio/export

we tell the kernel, that we want to use pin 6 from userspace. Pin 6 is connected to led. Now we configure pin 6 as an output by

echo out > /sys/class/gpio/GPIO6/direction

Now we can toggle the values by

echo 1 > /sys/class/gpio/GPIO6/value
sleep 1
echo 0 > /sys/class/gpio/GPIO6/value
ALIX.3D3: modeswitch pins

ALIX.3D3: modeswitch pins

Notice, that the LED is connected to 3.3V, so setting value to 0 it will be lit. The other LEDs are connected to pin 25 & pin 27. On pin 24 is a switch connected. We can read the value by enabling the pin, setting it as an input and reading the value:

echo 24 > /sys/class/gpio/export
echo in > /sys/class/gpio/GPIO24/direction
cat /sys/class/gpio/GPIO24/value

As the pin has an internal pull up, it will show 1 if the switch isn’t pressed or installed. If you press the switch or connect to the metal pins, it will result in 0.

Don’t forget to unexport all pins after when you’re done:

echo 6 > /sys/class/gpio/unexport
echo 24 > /sys/class/gpio/unexport

Any feedback on the driver is welcome!

If you like this article, feel free to flattr it:

May17