Be careful of that if something kernel-side is using those same registers--- you
might interrupt each other, and end up with incoherent values in the registers.
The sysfs interface to gpiolib (see gpio.txt) is pretty lightweight, avoids
having to interact with GPIO peripheral control registers directly from
userspace, and thereby avoids the risk of clobbering register values due to
contention with kernel context. But that interface only works for
machines/platforms that use gpiolib (which I think includes Beagleboard).
Where nothing kernel-side is touching the area being mmap'ed, then your code
works fine--- for any peripheral, not just gpio.
b.g.
--
Bill Gatliff
bg...@billgatliff.com
But if I do in gpio_test.c
---------------------------------------------
#include <stdio.h>
#define u8 unsigned char
#define u16 unsigned short
#define u32 unsigned int
#include <asm/arch/gpio.h>
main()
{ ..
gpio_direction_input(3);
.. }
---------------------------------------------
I get
uilding file: ../gpio_test.c
Invoking: Sourcery G++ C Compiler
arm-none-linux-gnueabi-gcc -I/opt/src/2.6_kernel/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"gpio_test.d" -MT"gpio_test.d" -o"gpio_test.o" "../gpio_test.c"
In file included from /opt/src/2.6_kernel/include/asm/arch/gpio.h:142,
from ../gpio_test.c:13:
/opt/src/2.6_kernel/include/asm-generic/gpio.h: In function 'gpio_get_value_cansleep':
/opt/src/2.6_kernel/include/asm-generic/gpio.h:15: warning: implicit declaration of function 'might_sleep'
../gpio_test.c: At top level:
../gpio_test.c:40: warning: return type defaults to 'int'
../gpio_test.c: In function 'main':
../gpio_test.c:98: warning: control reaches end of non-void function
Finished building: ../gpio_test.c
Building target: gpio
Invoking: Sourcery G++ C Linker
arm-none-linux-gnueabi-gcc -o"gpio" ./gpio_test.o
./gpio_test.o: In function `__gpio_set_direction':
/opt/src/2.6_kernel/include/asm/arch/gpio.h:117: undefined reference to `omap_set_gpio_direction'
collect2: ld returned 1 exit status
make: *** [gpio] Fehler 1
..
My kernel config has:
CONFIG_GENERIC_GPIO=y
CONFIG_OMAP_GPIO_SWITCH=y
> -----Ursprüngliche Nachricht-----
> Von: "Philip Balister" <philip....@gmail.com>
> Gesendet: 23.09.08 15:09:24
> An: beagl...@googlegroups.com
> Betreff: [beagleboard] Re: GPIO - how to ?
>
> On Tue, Sep 23, 2008 at 8:51 AM, Arno Steffen <arno.s...@web.de> wrote:
> >
> > How can I access GPIO pins from userspace, so read or write?
> > Is there already a kernel driver for Omap35xx and how to work with that?
> > Help is very much welcome!
>
> Take a look at:
>
> http://source.mvista.com/git/gitweb.cgi?p=linux-omap-2.6.git;a=blob;f=Documentation/gpio.txt;h=18022e249c53dc1ad991d74d160551fa32f32070;hb=HEAD
>
> Philip
________________________________________________________________________
"50 erste Dates" mit Adam Sandler u. Drew Barrymore kostenlos anschauen!
Exklusiv für alle WEB.DE Nutzer. http://www.blockbuster.web.de
>
Can you explain handling that more in detail?
What exactly is the gpiolib? In my kernel source I found
arch/arm/plat-omap/gpio.c
arch/arm/plat-omap/gpio.c
arch/arm/plat-omap/gpio-switch.c
arch/arm/plat-omap/gpio-switch.o
but for some reasons I can't work with that - or don't know how.
In my Kernel config I did:
CONFIG_GENERIC_GPIO=y
CONFIG_OMAP_GPIO_SWITCH=y
But loading the kernel gives me neither a sys/class/gpio nor a /dev/gpio or something to work with from userspace.
_________________________________________________________________________
In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und gestalten!
Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114
I write a 0x2 to GPIO.SYSCONFIG and read back 0, which seems to be ok.
But in GPIO.OE I read a 0xfffffff (all Input), and can't change that value.
I also tried to mmap the area where the MUX bits are. But get a message:
"Mapped failed".
Mpfhhhh.
> -----Ursprüngliche Nachricht-----
> Von: "John Beetem" <johnb...@yahoo.com>
> Gesendet: 23.09.08 17:17:16
> An: Beagle Board <beagl...@googlegroups.com>
> Betreff: [beagleboard] Re: GPIO - how to ?
> On the Ångström demo I've been able to use mmap() and /dev/mem to map
> OMAP peripheral memory into my user space application. This way I can
> access OMAP registers directly instead of having to go through device
> drivers. So far I've
> only accessed the GPIO registers so I could play with the user LEDs.
>
> The C code looks something like this:
>
> int fd = open("/dev/mem", O_RDWR); volatile ulong *A;
> if (fd < 0) {printf("Could not open file\n"); return;}
> A = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE,
> MAP_SHARED, fd, 0x49050000);
> if (A == MAP_FAILED) {printf("Mapping failed\n"); close(fd);
> return;}
> A[0x603C / 4] |= 0x600000; // Turn on LEDs
>
_______________________________________________________________________
Jetzt neu! Schützen Sie Ihren PC mit McAfee und WEB.DE. 30 Tage
kostenlos testen. http://www.pc-sicherheit.web.de/startseite/?mc=022220
Indeed. Your addresses and sizes must be 4K-aligned on ARM.
> Another common issue with device registers is making sure they're in
> an uncacheable memory. I would hope that mmap() would take care of
> this automatically.
Funny you should mention that. AT91 has had problems with that in the past, I
wonder if OMAP does too?
But, I think we should also support dynamic configuring of PAD registers
Regards,
Khasim