accessing GPIO from userspace

476 views
Skip to first unread message

Robert Kuhn

unread,
Nov 12, 2008, 7:12:50 AM11/12/08
to beagl...@googlegroups.com
Hello,

has someonme an example for accessing the gpios from userspace using
the "low level I/O API", like read(), write(), also mmap()?

Robert

John Beetem

unread,
Nov 12, 2008, 8:36:12 PM11/12/08
to Beagle Board
Robert,

See this thread from last September:

http://groups.google.com/group/beagleboard/browse_thread/thread/ff6f6aa843afd950

John

Robert Kuhn

unread,
Nov 13, 2008, 6:42:07 AM11/13/08
to beagl...@googlegroups.com

Okay, I wrote a little kernel module and tried to use gpio_is_valid.
But with every gpio value between 0 and 180 it fails:
Code of the init kernel mod routine:
static int hello_init(void)
{
int gpio, rv;
for(gpio=0; gpio<180; gpio++)
{
rv = gpio_is_valid(gpio);
printk(KERN_ALERT "GPIO %i: %i\n", gpio, rv);
}
return 0;
}

output:
Nov 4 08:02:36 beagleboard user.alert kernel: GPIO 0: 1
Nov 4 08:02:36 beagleboard user.alert kernel: GPIO 1: 1
Nov 4 08:02:36 beagleboard user.alert kernel: GPIO 2: 1
...
Nov 4 08:02:36 beagleboard user.alert kernel: GPIO 177: 1
Nov 4 08:02:36 beagleboard user.alert kernel: GPIO 178: 1
Nov 4 08:02:36 beagleboard user.alert kernel: GPIO 179: 1

What else is needed? I read through the bb manual and read something
about setting the mux register of the omap?!?!
Robert

John Beetem

unread,
Nov 13, 2008, 11:26:15 AM11/13/08
to Beagle Board
Robert,

I've never used gpio_is_valid() personally, but from a quick Yahoo
search I get the idea that gpio_is_valid(gpio) returns 1 (TRUE) if
gpio is valid, otherwise 0 (FALSE), so your example is reporting that
all GPIOs 0-179 are valid. You might try gpio_is_valid(-1) to see
what it reports for a known invalid GPIO.

FYI, my own GPIO experiments are limited to playing with the
BeagleBoard LEDs from user space, using mmap() to get a pointer to the
OMAP registers. I've never done anything with Linux kernel or GPIO
device drivers.

John

On Nov 13, 3:42 am, "Robert Kuhn" <rowka...@googlemail.com> wrote:
> > See this thread from last September:
>
> >http://groups.google.com/group/beagleboard/browse_thread/thread/ff6f6...

Preston Wilson

unread,
Nov 13, 2008, 12:00:20 PM11/13/08
to Beagle Board


On Nov 13, 11:26 am, John Beetem <johnbee...@yahoo.com> wrote:
> Robert,
>
> I've never used gpio_is_valid() personally, but from a quick Yahoo
> search I get the idea that gpio_is_valid(gpio) returns 1 (TRUE) if
> gpio is valid, otherwise 0 (FALSE), so your example is reporting that
> all GPIOs 0-179 are valid. You might try gpio_is_valid(-1) to see
> what it reports for a known invalid GPIO.
> ...

In my Open Embedded build
gpio_is_valid() is defined in
beagleboard-angstrom-linux-gnueabi/linux-omap2-2.6.26-r64/git/include/
asm-generic/gpio.h

Which returns true for any non-negative number less than 256.

Just in case it helps ... it looks like the actual implementation of
the gpio functions are in
beagleboard-angstrom-linux-gnueabi/linux-omap2-2.6.26-r64/git/arch/arm/
plat-omap/gpio.c

This is based on looking at the .o's produced in the build.

I am working on a project that uses some of the GPIO pins from the
kernel, but I am not to the point of writing actual code yet.

-Preston

Galo Cinza

unread,
Nov 13, 2008, 2:53:12 PM11/13/08
to Beagle Board
i wrote this small driver that turn off the led USR0 (gpio 149) of
the beagle board

#define GPIO5 0x49056000
#define SYSCONFIG 0x10
#define OE 0X34
#define SETDATAOUT 0X94
#define DATAOUT 0X3C

registers = ioremap(GPIO5, 0x1000); //4K

writel(0x015,SYSCONFIG + registers);
writel(0x0,OE + registers); //all output
writel(0x200000,DATAOUT + registers);
writel(0x200000,SETDATAOUT + registers);

Regards,
João paulo
Reply all
Reply to author
Forward
0 new messages