accessing GPIO from userspace

Hello,

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

Robert

Robert,

See this thread from last September:

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

John

See this thread from last September:

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

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

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

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

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