[Soekris] GPIO support for the net-4801 on Linux

Arnau Sanchez arnau at ehas.org
Sat Nov 4 22:58:51 UTC 2006


Hello,

I have a Soekris net4801 with voyage v0.2 installed (it includes a kernel 
2.6.15-486-voyage). I needed to use the GPIO for digital input/output, and 
looking for information I found this message from Jim Cromie:

http://lists.soekris.com/pipermail/soekris-tech/2006-June/010550.html

So I compilled a 2.6.17 kernel (from debian 'testing') with those patches 
applied and installed it. Then, my first problem was that I didn't know how to 
create the /dev/gpio-* files to interface the GPIO. Playing with the board I 
finally found the correspondance between the minor device values and the 12 GPIO 
pins (16 17 18 19 20 21 22 23 4 5 11 10)

Then I added this to /etc/modules:

pc87360 -> that's because I use sensors
pc8736x_gpio

and created /etc/modprobe.d/gpio:

options pc87360 init=3
# not really sure of that... :-(
install pc8736x_gpio /sbin/modprobe --ignore-install pc8736x_gpio && 
/usr/local/sbin/gpio-dev create

with gpio-dev being:

#!/bin/sh
# Create/remove device files for net4801 GPIO

MAJOR=254
BASE="/dev/gpio"
# Minor values from GPIO0 to GPIO11 (tested on net4801)
MINOR_LIST="16 17 18 19 20 21 22 23 4 5 11 10"

OP=$1
if [ "$OP" != "create" -a "$OP" != "remove" ]; then
	echo "usage: gpio-dev create|remove"
	exit 1
fi

NUM=0
for MINOR in $MINOR_LIST; do
	FILE=$BASE-$NUM
	if [ -e $FILE ]; then rm -f $FILE; fi
	if [ "$OP" = create ]; then
		mknod $FILE c $MAJOR $MINOR
	fi
	let NUM=NUM+1
done

Surprisingly, it worked smoothly.

Inspecting the kernel source I found how to configure the pins:

echo VALUE > /dev/gpio-X

where VALUE can be: O (output), o (input), T (push-pull), t (open drain), P 
(pull-up enabled), p (pull-up disabled), v (print settings), c (get driven and 
read value). And of course, 1 to output high, and 0 to output low.

Example: input from GPIO-0 with pull-up enabled:

echo "oP" > /dev/gpio-0
cat /dev/gpio-0

Example: output 1 to GPIO-0 with open-drain:

echo "Ot1" > /dev/gpio-0

...

By the way, I have a problem with the pc8736x_gpio module: if I rmmod it and 
then do a modprobe, it fails:

meta:~# modprobe pc8736x_gpio
meta:~# rmmod pc8736x_gpio
meta:~# modprobe pc8736x_gpio
FATAL: Error inserting pc8736x_gpio 
(/lib/modules/2.6.17-voyage-ehas/kernel/drivers/char/pc8736x_gpio.ko): No such 
device
FATAL: Error running install command for pc8736x_gpio

...

Well, now the question is: although all of this works, I am not sure if this is 
the correct procedure, is there any better way to do it?

Anyway, I expect this info helps other people... :-)

By the way, has anybody tested the TTL COM2 included in the 20-pin GPIO connector?

regads
arnau

pd: many thanks, of course, to Jim for this great work on the GPIO interface! I 
hope the official kernel include his patches soon.


More information about the Soekris-tech mailing list