On Wed, Aug 11, 2010 at 10:15 PM, Anton Vorontsov <cbouatmai...@gmail.com>wrote:
> 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: cbouatmai...@gmail.com > irc://irc.freenode.net/bd2 > Hi Anton, Thanks for the reply. 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. i...@e0000000 { #address-cells = <1>; #size-cells = <1>; device_type = "soc"; compatible = "simple-bus"; ranges = <0x0 0xe0000000 0x00100000>; reg = <0xe0000000 0x00000200>; bus-frequency = <0>; w...@200 { device_type = "watchdog"; compatible = "mpc83xx_wdt"; reg = <0x200 0x100>; }; gpio1: gpio-control...@c00 { #gpio-cells = <2>; compatible = "fsl,mpc8377-gpio", "fsl,mpc8349-gpio"; reg = <0xc00 0x100>; interrupts = <74 0x8>; interrupt-parent = <&ipic>; gpio-controller; }; gpio2: gpio-control...@d00 { #gpio-cells = <2>; compatible = "fsl,mpc8377-gpio", "fsl,mpc8349-gpio"; reg = <0xd00 0x100>; interrupts = <75 0x8>; interrupt-parent = <&ipic>; gpio-controller; }; * l...@0 { compatible = "gpio-leds"; label = "hdd"; gpios = <&gpio1 9 0>; }; l...@1 { compatible = "gpio-leds"; label = "rom"; gpios = <&gpio2 9 0>; };* . . . . }; 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. static int gpio_led_probe(struct platform_device *pdev) { struct gpio_led_platform_data *pdata = pdev->dev.platform_data; struct gpio_led *cur_led; struct gpio_led_data *leds_data, *led_dat; int i, ret = 0; *printk(KERN_INFO "led: inside gpio_led_probe.\n");* .... } 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. # ls /sys/devices/ -la drwxr-xr-x 7 root root 0 Jan 1 01:58 . drwxr-xr-x 12 root root 0 Jan 1 00:00 .. drwxr-xr-x 22 root root 0 Jan 1 01:58 *e0000000.immr* drwxr-xr-x 5 root root 0 Jan 1 01:58 e0005000.localbus drwxr-xr-x 4 root root 0 Jan 1 01:58 pci0000:00 drwxr-xr-x 9 root root 0 Jan 1 01:58 platform drwxr-xr-x 8 root root 0 Jan 1 01:58 system # ls /sys/devices/e0000000.immr/ bus e0004600.serial *led1.0* devspec e0007000.spi *led2.1* e0000200.wdt e00082a8.dma modalias e0000700.interrupt- e0018000.sata name e0000b00.power e0019000.sata power e0000c00.gpio-contr e0023000.usb sleep-nexus.2 e0000d00.gpio-contr e0024000.ethernet subsystem e0003100.i2c e0025000.ethernet uevent e0004500.serial e0030000.crypto Is there something that I am doing wrong? Please suggest. Thanks in Advance Ravi Gupta
mpc8377_rdb.dts
Description: Binary data
_______________________________________________ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev