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
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!
The cs5535-gpio support via the GPIO interface is in kernel mainline since version 2.6.33-rc1. Commits are 5f0a96b044d8edaee20f4a32ef6c393599ca55f8 and 1ea3fa7bbfbe81cfbdcc35748a57c35f9b32c5d6.
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
@Yago Fernandez Hansen
I never used the old device module as I is not compatible with the GPIO interface of the kernel. Also this will be removed in future kernel version, so it is better not to use it in new projects.
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?
@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.
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?
@Bula
here you can find the schematic of the ALIX.3D3. You should connect the LED to same way as the other 3 LEDs.
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 🙂
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
@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.
Ok.thanks.
But Can I use the signal on the switch for status change...?
Or isn't there a possible solution...?
thanks.
Marco
@Marco
The switch is connected to a GPIO pin. So you can use it as long as your are polling it frequently enough.
Ok, thanks for your help.
I try this solution.
Thank you.
Best regards,Marco
hi.
can you please provide step-by-step tutorials on how to compile the kernel? i am having errors. please help.
@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
@Ricardo
As far as I know it is not possible to use them as a real interrupt source.
@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
@Ricardo
I'm trying to do the same thing you are; utilize a PPS signal to drive a GPS input pin in interrupt context. Please reply if you found a solution.