[Voyage-linux] GPIO on Alix 1.D working!
QmQ
(spam-protected)
Sat Mar 21 10:00:01 HKT 2009
After A LOT of reading I've finally 'cracked' Alix 1.D (and probably
1.C) GPIO! :D
I've searched A LOT for a *working* GPIO solution on the Internet but
found none. If however there is one out there please let me know :) But
I'll write my own anyway :P
I'm releasing a VERY UGLY and highly incomplete code snippet that
proves it does work. Now that I know what and how I will write a much
better piece of code to ease GPIO access for myself (and everyone else
if someone will be interested).
This method does not require any drivers whatsoever.
Compile: gcc gpio.c -O2 -Wall
Run as root!
This test assumes the board GPIOs are at their defaults. If they are
not (i.e. changed via BIOS) do NOT do what follows. Why? By default the
GPIOs are configured as INPUT. In the following test I'm going to short
circuit one of the GPIO pins with the ground. If that pin would be
configured as output...I have no idea what would happen, but better not
try ;)
To test it I've attached a switch between GPIO11 and GND (GPIO pins 4
and 2). When I run the test program I get 0xFF which means no button is
pressed. When I switch the switch (short circuit the pins) and run the
program I get 0xFD. Bit #1 has changed == GPIO11 works!
And that's it! No big deal now that I think about it, but for me it's a
huge breakthrough (many hours well spent) so I needed to tell someone ;)
I will investigate GPIO further and if anyone is interested post some
more detail. I have attached the code (gpio.c) and the zipped program.
In the process I've learned how to access/control the hardware monitor,
so if anyone is interested in that - let me know.
*USE AT YOUR OWN RISK!*
Some additional system info:
---------------------
Board: Alix 1.D
BIOS: 8/27/08
Settings: default
Voyage: lenny on USB stick
GCC 4.3.2
---------------------
Now I can rest in peace - 3AM here :)
Regards,
QmQ
PS
I still don't know why my system "sees" 3 LEDs and allows me to control
them - I'm beginning to think the LED module is either statically built
for board(s) which have LEDs or that my system somewhere has pins for 3
LEDs (which would be cool - the disk/CPU usage functionality might come
in handy).
PPS
I hope this will get archived some day so here are some additional
keywords that might help someone find this. They certainly would've
helped me :)
winbond W83627HF configuration register
--
This message has been scanned by ArcaMail, ArcaVir 2009
scanned 2009-03-21 03:00:06, engine: 2009.0010, base: 2009.03.20 12:20:35
www.arcabit.pl
-------------- next part --------------
/*
QmQ at qmq.pl
Alix 1.D (ugly) GPIO test.
Use at your own risk!
*/
#include <sys/io.h>
#include <stdio.h>
#include <unistd.h>
#define PORT_INDEX 0x2e
#define PORT_DATA 0x2f
typedef unsigned char BYTE;
const char* toBin(const BYTE c)
{
static char buff[9];
BYTE mask = 128;
int i=0;
while(mask)
{
sprintf(buff+i++, mask & c ? "1" : "0");
mask >>= 1;
}
sprintf(buff+i, "%c", '\0');
return buff;
}
void init()
{
outb_p(0x87, PORT_INDEX);
outb_p(0x87, PORT_INDEX);
}
void done()
{
outb_p(0xAA, PORT_INDEX);
}
void set(BYTE idx, BYTE val)
{
outb_p(idx, PORT_INDEX);
outb_p(val, PORT_DATA);
}
BYTE get(BYTE idx)
{
outb_p(idx, PORT_INDEX);
return inb_p(PORT_DATA);
}
int main(int nargs, char **argv)
{
BYTE byte = 0;
iopl(3);
init();
// check if OK - must be 0x52
byte = get(0x20);
fprintf(stderr, "0x52 = [0x%02x] (%s)\n", byte, toBin(byte));
// check if GPIO11 is active
byte = get(0x2a);
fprintf(stderr, "CR2A = [0x%02x] (%s)\n", byte, toBin(byte));
// set (and get) logical device to #7 - GPIO1
const BYTE devIdx = 0x07;
set(devIdx, 0x07);
byte = get(devIdx);
fprintf(stderr, "LOGICAL DEVICE# = [0x%02x] (%s)\n", byte, toBin(byte));
// check GPIO1 functions [1:input, 0:output]
const BYTE funcIdx = 0xf0;
byte = get(funcIdx);
fprintf(stderr, "FUNCTION = [0x%02x] (%s)\n", byte, toBin(byte));
// GPIO1 data
const BYTE dataIdx = 0xf1;
byte = get(dataIdx);
fprintf(stderr, "DATA = [0x%02x] (%s)\n", byte, toBin(byte));
done();
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gpio.zip
Type: application/zip
Size: 3173 bytes
Desc: not available
Url : http://list.voyage.hk/pipermail/voyage-linux/attachments/20090321/7b232dbd/gpio-0003.zip
More information about the Voyage-linux
mailing list