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!

18 thoughts on “GPIO on ALIX.3D3

  1. Dear twam:

    Thank you for your wonderfull articles about alix.3d3 board. I am working in a project in Voyage Linux for this board, and I am very pleased of how everything works with release 0.6.5. Very small bugs with a very good functionallity. I have readed your articles about LEDS, GPIO, etc... and they helped much. The problem I have, as I readed in one of your articles is that I want to use the gpio24 for a switch and I have asked about it and If I don't want to compile the kernell (I hate that) I can now use and load with modprobe the cs5535 as this:

    voyage:~# modprobe cs5535_gpio

    voyage:~# dmesg | grep gpio
    [ 14.847516] cs5535_gpio: base=0x6100 mask=0xb003c66 major=253

    voyage:~# lsmod | grep gpio
    cs5535_gpio 3744 0

    voyage:~# ls -l /dev/cs5535*
    crw-rw---- 1 root root 253, 1 Jun 6 21:37 /dev/cs5535_gpio1
    crw-rw---- 1 root root 253, 10 Jun 6 21:37 /dev/cs5535_gpio10
    crw-rw---- 1 root root 253, 11 Jun 6 21:37 /dev/cs5535_gpio11
    crw-rw---- 1 root root 253, 12 Jun 6 21:37 /dev/cs5535_gpio12
    crw-rw---- 1 root root 253, 13 Jun 6 21:37 /dev/cs5535_gpio13
    crw-rw---- 1 root root 253, 2 Jun 6 21:37 /dev/cs5535_gpio2
    crw-rw---- 1 root root 253, 24 Jun 6 21:37 /dev/cs5535_gpio24
    crw-rw---- 1 root root 253, 25 Jun 6 21:37 /dev/cs5535_gpio25
    crw-rw---- 1 root root 253, 27 Jun 6 21:37 /dev/cs5535_gpio27
    crw-rw---- 1 root root 253, 5 Jun 6 21:37 /dev/cs5535_gpio5
    crw-rw---- 1 root root 253, 6 Jun 6 21:37 /dev/cs5535_gpio6

    And it's very easy and is ok. But just a stupid question. How can I read when I want or as is changed the value of the switch: 0/1? Can you help me?

    Thank you

    Yago

  2. Hi twam, thank you for your help. Leds trough gpio are working ok but I have questions about modeswitch: is it safe to use it as output for another led? I see that its buffer type is smb and not gp24 as the ones for leds?

  3. @Bula
    I think you could use the modeswitch GPIO Port for an LED if you connect to thru a resistor to 3V. But I would recommend to use an I²C Port Extender if you need more GPIO Pins.

  4. For now I need only one LED so - do you mean to connect diode thru pull-up resistor on external 3V or directly on 3.3V that I get on the modeswitch pins?

  5. OK thanks, it is what I was thinking but I was not sure cause of difference in buffer types between modeswitch and leds GPIO ports. Only thing I need now is external 3V 🙂

  6. Hi twam, thanks for your tutorial. It's very best...:)
    But I have a question, in fact I have a problem. I built a power supply from use as battery, this system send a
    electric signal on CTS pin of the COM1, but this PIN is not enabled on CS5536 (alix6e2), I read this on the manual.
    I had an idea reading your tutorial, but I need help.
    Can I send a electric signal on the switch, and can I read the change status...???
    Also what would be the ideal power of the electrical signal...???

    Can you help me, please...???

    Thanks.

    Marco

  7. @Marco
    As far as I know, there is no support for pin change notifications in the GPIO interface yet. So your programm would need to poll the pin very often and your signal must be long enough.

  8. @twam

    Hi!
    I've been working with the Alix.3d3 for a while now but only lately I had the need to use external interrupts.
    I can understand that by polling one of the GPIO pins frequently enough, it could "almost" work as an interrupt. However, in my case, a "real" interrupt is necessary because I'm trying to connect a GPS PPS signal to this board (which in turn gives me precision for message time-stamping purposes). Do you know of any way to use the already "visible" pins on this board and make them interrupt inputs?

    Thanks a lot
    Ricardo

  9. @twam
    thanks for the prompt answer
    So I have no idea what to do now with this, as unfortunately the included Geode doesn't even support the serial port handshake signals (for the PPS people often use the DCD signal). If you have any suggestion (other than polling some port), it would be really welcome!

    Thanks
    Ricardo

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.