linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Anton Vorontsov <cbouatmailru@gmail.com>
To: Ravi Gupta <dceravigupta@gmail.com>
Cc: linuxppc-dev@ozlabs.org, MJ embd <mj.embd@gmail.com>,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: How to use mpc8xxx_gpio.c device driver
Date: Wed, 11 Aug 2010 20:45:27 +0400	[thread overview]
Message-ID: <20100811164527.GA19793@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <AANLkTimJ1+d7U2SN_SSHepo6u01RJqUEXUDQXUgBfCWK@mail.gmail.com>

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

  parent reply	other threads:[~2010-08-11 16:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-11 13:27 How to use mpc8xxx_gpio.c device driver Ravi Gupta
2010-08-11 14:19 ` Ravi Gupta
2010-08-11 16:25   ` Ira W. Snyder
2010-08-11 16:45   ` Anton Vorontsov [this message]
2010-08-13  9:59     ` Ravi Gupta
2010-08-13 13:16       ` Anton Vorontsov
2010-08-18 12:45         ` Ravi Gupta
2010-08-11 16:15 ` MJ embd
2010-08-12 10:25   ` Ravi Gupta
2010-08-12 15:36     ` Ira W. Snyder
2010-08-13 10:01       ` Ravi Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100811164527.GA19793@oksana.dev.rtsoft.ru \
    --to=cbouatmailru@gmail.com \
    --cc=dceravigupta@gmail.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mj.embd@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).