Re: How to use mpc8xxx_gpio.c device driver
From: Anton Vorontsov <hidden>
Date: 2010-08-11 16:45:33
Hi, On Wed, Aug 11, 2010 at 06:57:16PM +0530, Ravi Gupta wrote:
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 :
No, you don't have to modify anything, and yes, you can use standard kernel GPIO API.
#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");Before issing gpio_request() you must get GPIO number from the of_get_gpio() or of_get_gpio_flags() calls (the _flags variant will also retreive flags such as 'active-low'). The calls assume that you have gpio = <> specifier in the device tree, see arch/powerpc/boot/dts/mpc8377_rdb.dts's "leds" node as an example. As you want GPIO LEDs, you can use drivers/leds/leds-gpio.c (see of_gpio_leds_probe() call, it gets gpio numbers via of_get_gpio_flags() and then requests them via gpio_request()). Also see Documentation/powerpc/dts-bindings/gpio/gpio.txt Documentation/powerpc/dts-bindings/gpio/led.txt
if (ret) {
printk(KERN_WARNING "sample_driver: unable to request GPIO_PG%d\n",
i);
//return ret;
}
}
return 0;
}On Wed, Aug 11, 2010 at 07:49:40PM +0530, Ravi Gupta wrote:
Also, when I try to export a gpio in sysfs echo 9 > /sys/class/gpio/export
The gpio numbers are global, i.e. GPIO controller base + GPIO number within the controller. [...]
drwxr-xr-x 3 root root 0 Jan 1 00:00 gpiochip192
So, if you want GPIO9 within gpiochip192, you should issue "echo 201 > export". Thanks, -- Anton Vorontsov email: cbouatmailru@gmail.com irc://irc.freenode.net/bd2