From: Alex Courbot <acourbot@nvidia.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Grant Likely <grant.likely@secretlab.ca>,
Linus Walleij <linus.walleij@linaro.org>,
Arnd Bergmann <arnd@arndb.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"gnurou@gmail.com" <gnurou@gmail.com>
Subject: Re: [RFC] gpiolib: introduce descriptor-based GPIO interface
Date: Fri, 7 Dec 2012 16:02:02 +0900 [thread overview]
Message-ID: <2562815.JQOcF2Dmj3@percival> (raw)
In-Reply-To: <20121207024947.GA25121@roeck-us.net>
Hi Guenter,
On Friday 07 December 2012 10:49:47 Guenter Roeck wrote:
> My own idea for a solution was to keep integer based handles, but replace
> gpio_desc[] with a hash table. But ultimately I don't really care how
> it is done.
>
> Do you have a solution for gpiochip_find_base() in mind, and how to handle
> reservations ? I had thought about using bit maps, but maybe there is
> a better solution.
My plan so far is to use a sorted linked list of gpio_chips. Each chip
contains its base address and size, so this will make it possible to find
usable areas through a single parse. Current gpiochip_find_base() start from
ARCH_NR_GPIOS and look backwards in the integer space to find a free range, a
similar behavior can also be done if this is deemed better (GPIO numbers might
become high, but since we want to hide them this should not matter).
The counterpart of the list is that fetching the descriptor corresponding to a
GPIO number is going to be linear instead of constant, but (1) the number of
gpio_chips on the system should never grow very high and (2) this is a good
incentive to use the descriptor-based API instead. :) Existing code could
easily be converted - once a GPIO is acquired, its number should be converted
immediatly to a descriptor and the gpiod_* functions used from them on. We can
probably write a sed or Coccinelle rule to do that through the whole kernel.
gpiochip_reserve() will require some more thinking using this model, but
something like a dummy chip can probably be introduced in the list. It will
need to be statically allocated however since memory allocation cannot be used
there.
Actually the only user of gpiochip_reserve() seems to be Tosa, so I wonder if
there would be no way to simply get rid of it?
> If/when you have some code to test, please let me know.
Sure!
> > + mutex_lock(&sysfs_lock);
> >
> > /* can't export until sysfs is available ... */
> > if (!gpio_class.p) {
> >
> > @@ -713,13 +743,7 @@ int gpio_export(unsigned gpio, bool
> > direction_may_change)>
> > return -ENOENT;
>
> mutex is not released here.
Oops.
> > - chip = gpio_to_chip(gpio);
> > + chip = desc->chip;
> > + gpio = gpio_chip_offset(desc);
>
> Might be better to use a separate variable named 'offset' when dealing with
> the offset, to avoid confusion and accidential bugs. You are doing it
> below, so you might as well do it everywhere. This would also simplify the
> code in a couple of places where gpio is first converted into an offset
> only to use "chip->base + gpio" later on.
Makes sense. Fixed, thanks.
> > - __func__, gpio, err);
> > + __func__, offset + chip->base, err);
>
> I know I am nitpicking, but everywhere in the existing code it is
> "chip->base + offset/gpio".
Fixed.
> > return chip->to_irq ? chip->to_irq(chip, gpio - chip->base) :
> > -ENXIO;
>
> s/gpio - chip->base/gpio_chip_offset(desc)/
>
> then you don't need gpio at all.
Done, thanks.
> > - chip = gpio_to_chip(gpio);
> > + chip = desc->chip;
> > + gpio = desc_to_gpio(desc);
> >
> > trace_gpio_value(gpio, 0, value);
> > if (test_bit(FLAG_OPEN_DRAIN, &gpio_desc[gpio].flags))
>
> Use desc directly.
>
> > - _gpio_set_open_drain_value(gpio, chip, value);
> > + _gpio_set_open_drain_value(desc, value);
> >
> > else if (test_bit(FLAG_OPEN_SOURCE, &gpio_desc[gpio].flags))
>
> Use desc directly.
Right.
Thanks,
Alex.
next prev parent reply other threads:[~2012-12-07 7:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-06 7:45 [RFC] gpiolib: introduce descriptor-based GPIO interface Alexandre Courbot
2012-12-06 7:45 ` Alexandre Courbot
2012-12-06 14:42 ` Grant Likely
2012-12-06 14:42 ` Grant Likely
2012-12-07 2:06 ` Alex Courbot
2012-12-07 8:24 ` Linus Walleij
2012-12-10 22:34 ` Grant Likely
2012-12-06 20:19 ` Linus Walleij
2012-12-07 2:49 ` Guenter Roeck
2012-12-07 7:02 ` Alex Courbot [this message]
2012-12-07 15:07 ` Guenter Roeck
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=2562815.JQOcF2Dmj3@percival \
--to=acourbot@nvidia.com \
--cc=arnd@arndb.de \
--cc=gnurou@gmail.com \
--cc=grant.likely@secretlab.ca \
--cc=linus.walleij@linaro.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/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