Re: at91_get_gpio_value() always low

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hello Tomas,

> have written a module for getting GPIO pin status in userspace. Hope this
> will help You as it works 100% for me on 9263 board, 2.6.24 kernel

As I already mentioned, it is part of the debug_fs interface, so you
do not need to load an additional module ;-))

Remy


> (Angstrom).
>
> // ============ Source begin ===============
> /* Module for controling GPIO pins in userspace */
> /* Please leave the author of the module and add yourself after a  comma if
> you edit the code */
> /* Last edit: 2008-07-01 */
> /* Example: echo /dev/gpiopb21 returns 1(high) or 0(low) depending on pin
> value */
>
> #include <linux/init.h>
> #include <linux/module.h>
> #include <linux/delay.h>
> #include <asm/gpio.h>
> #include <linux/fs.h>
> #include <linux/miscdevice.h>
> #include <asm/uaccess.h>
>
> MODULE_AUTHOR("Tomas 'Socrates' D.");
> MODULE_LICENSE("GPL");
>
> /* Globals */
> unsigned int pin = AT91_PIN_PB21; /* Setting PB21 as INPUT */
>
> /* Begin */
> static ssize_t user_gpio_read(struct file *file, char *buf, size_t count,
> loff_t *ppos)
> {
>       int lenght = 2;
>       int level = at91_get_gpio_value(pin); /* Getting pin value */
>       char *string;
>       sprintf(string, "%d\n",level); /*Printing output*/
>       copy_to_user(buf,string,lenght); /*Integer to string*/
>       if (*ppos == 0) {
>       *ppos+=1;
>      return lenght; /* Securing of kernel panic */
>  } else {
>    return 0;
>  }
> };
>
> static const struct file_operations user_gpio_file_fops = {
>        .owner             = THIS_MODULE,
>        .read              = user_gpio_read,
> };
>
> static struct miscdevice gpiopb21 = {
>        MISC_DYNAMIC_MINOR,
>        "gpiopb21", /*Naming a device in /dev, here will be /dev/gpiopb21 */
>        &user_gpio_file_fops
> };
>
> /* INIT */
> static int socgpioinit(void)
> {
> gpio_direction_input(pin);
> int ret;
>   printk(KERN_ALERT "Loading Socrates GPIO PIN PB21 as INPUT\n");
>     ret = misc_register(&gpiopb21);
>   return ret;
> };
>
> /* EXIT */
> static void socgpioexit(void)
> {
>   printk(KERN_ALERT "Unloading Socrates GPIO PIN PB21 as INPUT\n");
>   misc_deregister(&gpiopb21);
> }
>
> module_init(socgpioinit);
> module_exit(socgpioexit);
>
> // ============ Source end ================
>
> Regards,
> Tomas Daujotas
>
> ----- Original Message -----
> From: "Andrejs Cainikovs" <AndrejsC@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
> To: <linux-arm@xxxxxxxxxxxxxxxxxxxxxx>
> Cc: "Tomas D." <mailsoc@xxxxxxxxx>
> Sent: Saturday, September 27, 2008 4:00 PM
> Subject: Re: at91_get_gpio_value() always low
>
>
>>
>> Nope, changing code to new gpio functions didn't helped. Probably this
>> topic got hidden eggs.
>> The only idea i have is to debug while keeping an eye on cpu gpio related
>> registers. Argh, it's just gpio input!
>>
>> Kind regards,
>> Andrejs Cainikovs
>
>
> -------------------------------------------------------------------
> List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
> FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
> Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php
>

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php

[Linux ARM]     [Linux ARM MSM]     [Linux ARM Kernel]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

Add to Google Follow linuxarm on Twitter