<br><div class="gmail_quote">On Wed, Aug 11, 2010 at 10:15 PM, Anton Vorontsov <span dir="ltr"><<a href="mailto:cbouatmailru@gmail.com" target="_blank">cbouatmailru@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi,<br>
<div><br>
On Wed, Aug 11, 2010 at 06:57:16PM +0530, Ravi Gupta wrote:<br>
> I am new to device driver development. I am trying to access the GPIO of<br>
> MPC837xERDB eval board. I have upgraded its kernel to linux-2.6.28.9 and<br>
> enable support for mpc8xxx_gpio.c. On boot up, it successfully detect two<br>
> gpio controllers. Now my question is how I am going to use it to communicate<br>
> with the gpio pins? Do I have to modify the code in mpc8xxx_gpio.c file to<br>
> do whatever I want to do with gpios or I can use the standard gpio API<br>
> provided in kernel ( gpio_request()/gpio_free() ). I also tries the standard<br>
> kernel API, but it fails. Here is my code :<br>
<br>
</div>No, you don't have to modify anything, and yes, you can<br>
use standard kernel GPIO API.<br>
<div><br>
> #include <linux/module.h><br>
> #include <linux/errno.h> /* error codes */<br>
> #include <linux/gpio.h><br>
><br>
> static __init int sample_module_init(void)<br>
> {<br>
> int ret;<br>
><br>
> int i;<br>
> for (i=1; i<32; i++) {<br>
> ret = gpio_request(i, "Sample Driver");<br>
<br>
</div>Before issing gpio_request() you must get GPIO number from the<br>
of_get_gpio() or of_get_gpio_flags() calls (the _flags variant<br>
will also retreive flags such as 'active-low').<br>
<br>
The calls assume that you have gpio = <> specifier in the<br>
device tree, see arch/powerpc/boot/dts/mpc8377_rdb.dts's<br>
"leds" node as an example.<br>
<br>
As you want GPIO LEDs, you can use drivers/leds/leds-gpio.c<br>
(see of_gpio_leds_probe() call, it gets gpio numbers via<br>
of_get_gpio_flags() and then requests them via gpio_request()).<br>
<br>
Also see<br>
<br>
Documentation/powerpc/dts-bindings/gpio/gpio.txt<br>
Documentation/powerpc/dts-bindings/gpio/led.txt<br>
<div><br>
> if (ret) {<br>
> printk(KERN_WARNING "sample_driver: unable to request GPIO_PG%d\n",<br>
> i);<br>
> //return ret;<br>
> }<br>
> }<br>
><br>
> return 0;<br>
> }<br>
<br>
<br>
</div><div>On Wed, Aug 11, 2010 at 07:49:40PM +0530, Ravi Gupta wrote:<br>
</div><div>> Also, when I try to export a gpio in sysfs<br>
><br>
> echo 9 > /sys/class/gpio/export<br>
<br>
</div>The gpio numbers are global, i.e. GPIO controller base + GPIO<br>
number within the controller.<br>
<br>
[...]<br>
<div>> drwxr-xr-x 3 root root 0 Jan 1 00:00 gpiochip192<br>
<br>
</div>So, if you want GPIO9 within gpiochip192, you should issue<br>
"echo 201 > export".<br>
<br>
Thanks,<br>
<font color="#888888"><br>
--<br>
Anton Vorontsov<br>
email: <a href="mailto:cbouatmailru@gmail.com" target="_blank">cbouatmailru@gmail.com</a><br>
irc://<a href="http://irc.freenode.net/bd2" target="_blank">irc.freenode.net/bd2</a><br>
</font></blockquote></div><br>Hi Anton,<br><br>Thanks for the reply.<br>I had added the entries for
gpio pin 9 for both controllers(I was not sure with controller's pin is
connected to LED, but now I know it is pin no. 233 i.e 224+9) in the
mpc8377_rdb.dts file. Below is a portion of my dts file, I have attached
the complete dts file as attachment.<br><br>immr@e0000000 {<br> #address-cells = <1>;<br> #size-cells = <1>;<br> device_type = "soc";<br> compatible = "simple-bus";<br> ranges = <0x0 0xe0000000 0x00100000>;<br>
reg = <0xe0000000 0x00000200>;<br> bus-frequency = <0>;<br><br> wdt@200 {<br> device_type = "watchdog";<br> compatible = "mpc83xx_wdt";<br> reg = <0x200 0x100>;<br>
};<br><br> gpio1: gpio-controller@c00 {<br> #gpio-cells = <2>;<br> compatible = "fsl,mpc8377-gpio", "fsl,mpc8349-gpio";<br> reg = <0xc00 0x100>;<br> interrupts = <74 0x8>;<br>
interrupt-parent = <&ipic>;<br> gpio-controller; <br> };<br><br> gpio2: gpio-controller@d00 {<br> #gpio-cells = <2>;<br> compatible = "fsl,mpc8377-gpio", "fsl,mpc8349-gpio";<br>
reg = <0xd00 0x100>;<br> interrupts = <75 0x8>;<br> interrupt-parent = <&ipic>;<br> gpio-controller;<br> };<br><br> <b> led@0 {<br>
compatible = "gpio-leds";<br>
label = "hdd";<br>
gpios = <&gpio1 9 0>;<br>
};<br>
<br>
led@1 {<br>
compatible = "gpio-leds";<br>
label = "rom";<br>
gpios = <&gpio2 9 0>;<br>
};</b><br> .<br> .<br> .<br> .<br>};<br><br><br>Also I
have enabled drivers/leds/leds-gpio.c in my kernel. To test whether the
leds entires in dts file get attached to leds-gpio driver, I added
printks in the probe function of the driver.<br><br>static int gpio_led_probe(struct platform_device *pdev)<br>{<br> struct gpio_led_platform_data *pdata = pdev->dev.platform_data;<br> struct gpio_led *cur_led;<br> struct gpio_led_data *leds_data, *led_dat;<br>
int i, ret = 0;<br><br> <b>printk(KERN_INFO "led: inside gpio_led_probe.\n");</b><br><br> ....<br>}<br><br>But
I couldn't see "led: inside gpio_led_probe." message in dmesg. I
checked sysfs and I can see entries of leds. Here is contents of sysfs
on my machine.<br><br># ls /sys/devices/ -la<br>drwxr-xr-x 7 root root 0 Jan 1 01:58 .<br>drwxr-xr-x 12 root root 0 Jan 1 00:00 ..<br>drwxr-xr-x 22 root root 0 Jan 1 01:58 <b>e0000000.immr</b><br>
drwxr-xr-x 5 root root 0 Jan 1 01:58 e0005000.localbus<br>drwxr-xr-x 4 root root 0 Jan 1 01:58 pci0000:00<br>drwxr-xr-x 9 root root 0 Jan 1 01:58 platform<br>drwxr-xr-x 8 root root 0 Jan 1 01:58 system<br>
<br><br># ls /sys/devices/e0000000.immr/<br>bus e0004600.serial <b>led1.0</b><br>devspec e0007000.spi <b>led2.1</b><br>e0000200.wdt e00082a8.dma modalias<br>
e0000700.interrupt- e0018000.sata name<br>e0000b00.power e0019000.sata power<br>e0000c00.gpio-contr e0023000.usb sleep-nexus.2<br>e0000d00.gpio-contr e0024000.ethernet subsystem<br>
e0003100.i2c e0025000.ethernet uevent<br>e0004500.serial e0030000.crypto<br><br>Is there something that I am doing wrong? Please suggest.<br><br>Thanks in Advance<br>
Ravi Gupta<br>