LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-11-2010, 09:30 AM   #1
ramukaka
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Rep: Reputation: 0
How to use mpc8xxx_gpio.c device driver


Hi,

I am new to device driver development. I am trying to access the GPIO of MPC837xERDB eval board. I have upgraded its kernel to linux-2.6.28.9 and enable support for mpc8xxx_gpio.c. On boot up, it successfully detect two gpio controllers. Now my question is how I am going to use it to communicate with the gpio pins? Do I have to modify the code in mpc8xxx_gpio.c file to do whatever I want to do with gpios or I can use the standard gpio API provided in kernel ( gpio_request()/gpio_free() ). I also tries the standard kernel API, but it fails. Here is my code :

#include <linux/module.h>
#include <linux/errno.h> /* error codes */
#include <linux/gpio.h>

static __init int sample_module_init(void)
{
int ret;

int i;
for (i=1; i<32; i++) {
ret = gpio_request(i, "Sample Driver");
if (ret) {
printk(KERN_WARNING "sample_driver: unable to request GPIO_PG%d\n", i);
//return ret;
}
}

return 0;
}

static __exit void sample_module_exit(void)
{
gpio_free(9);
}

MODULE_LICENSE("GPL");

module_init(sample_module_init);
module_exit(sample_module_exit);

It give the following O/P:

[ 617.075329] sample_driver: unable to request GPIO_PG1
[ 617.080418] sample_driver: unable to request GPIO_PG2
[ 617.085470] sample_driver: unable to request GPIO_PG3
[ 617.090522] sample_driver: unable to request GPIO_PG4
[ 617.095574] sample_driver: unable to request GPIO_PG5
[ 617.100625] sample_driver: unable to request GPIO_PG6
[ 617.105676] sample_driver: unable to request GPIO_PG7
[ 617.110727] sample_driver: unable to request GPIO_PG8
[ 617.115779] sample_driver: unable to request GPIO_PG9
[ 617.120830] sample_driver: unable to request GPIO_PG10
[ 617.125968] sample_driver: unable to request GPIO_PG11
[ 617.131106] sample_driver: unable to request GPIO_PG12
[ 617.136245] sample_driver: unable to request GPIO_PG13
[ 617.141383] sample_driver: unable to request GPIO_PG14
[ 617.146521] sample_driver: unable to request GPIO_PG15
[ 617.151660] sample_driver: unable to request GPIO_PG16
[ 617.156798] sample_driver: unable to request GPIO_PG17
[ 617.161936] sample_driver: unable to request GPIO_PG18
[ 617.167074] sample_driver: unable to request GPIO_PG19
[ 617.172213] sample_driver: unable to request GPIO_PG20
[ 617.177351] sample_driver: unable to request GPIO_PG21
[ 617.182489] sample_driver: unable to request GPIO_PG22
[ 617.187628] sample_driver: unable to request GPIO_PG23
[ 617.192767] sample_driver: unable to request GPIO_PG24
[ 617.197905] sample_driver: unable to request GPIO_PG25
[ 617.203042] sample_driver: unable to request GPIO_PG26
[ 617.208182] sample_driver: unable to request GPIO_PG27
[ 617.213319] sample_driver: unable to request GPIO_PG28
[ 617.218458] sample_driver: unable to request GPIO_PG29
[ 617.223597] sample_driver: unable to request GPIO_PG30
[ 617.228735] sample_driver: unable to request GPIO_PG31
[ 617.233873] sample_driver: unable to request GPIO_PG32

Can someone provide me a sample code or something else. Actually I am trying to set the GPIO pin no. 9 to active low as it is connected to a LED on board.

Thanks in advance
Ravi Gupta
 
Old 08-11-2010, 10:24 AM   #2
ramukaka
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Also, when I try to export a gpio in sysfs

echo 9 > /sys/class/gpio/export

It gives me an error in dmesg
gpio_request: gpio-9 (sysfs) status -22
export_store: status -22

Here is a look of sysfs on my machine

# ls /sys/class/gpio/ -la
drwxr-xr-x 4 root root 0 Jan 1 00:00 .
drwxr-xr-x 24 root root 0 Jan 1 00:00 ..
--w------- 1 root root 4096 Jan 1 00:10 export
drwxr-xr-x 3 root root 0 Jan 1 00:00 gpiochip192
drwxr-xr-x 3 root root 0 Jan 1 00:00 gpiochip224
--w------- 1 root root 4096 Jan 1 00:00 unexport
 
  


Reply

Tags
kernel


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mtd driver as block device and char device Linux_Kid_ Linux - Kernel 1 12-27-2009 01:17 PM
Question about usb storage device and device driver balteo Linux - Hardware 2 11-21-2009 10:37 AM
Device driver for USB storage device linuxdeveloper29 Linux - Hardware 1 10-24-2008 09:30 AM
Multiple Device driver from single device driver???? rickhg12hs Linux - Kernel 3 05-25-2008 01:11 AM
Which driver is a device using? abovett Linux - Hardware 5 10-16-2006 03:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration