lkml.org 
[lkml]   [2012]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: How about a gpio_get(device *, char *) function?
Date
On Thursday 08 November 2012 05:24:19 Linus Walleij wrote:
> I would prefer to create, e.g. in <linux/gpio/consumer.h>
> something like:
>
> struct gpio;
>
> struct gpio *gpio_get(struct device *dev, const char *name);
>
> int gpio_get_value(struct gpio *g);
>
> Nothing more! I.e. struct gpio is an opaque cookie, nothing to be known
> about it.
>
> And then have the drivers using this *ONLY* include <linux/gpio/consumer.h>
> and not <linux/gpio.h>. So drivers have no clue what struct gpio is and
> will only operate on it using functions.
>
> This follows the pattern set by Thomas Gleixner for e.g. IRQ descriptors,
> and the style was also used in the redesign of the struct clk *.

Also pretty similar to the regulator framework, which might itself have been
inspired by IRQs and clocks.

> Of course the cross-referencing implementation can in e.g.
> drivers/gpio/gpiodev.c internally define that like this:
>
> #include <linux/gpio.h>
>
> /**
> * @gpio: pointer to global GPIO number
> */
> struct gpio {
> int gpio;
> };
>
> struct gpio *gpio_get(struct device *dev, const char *name)
> {
> /* Lookup in cross-ref table etc */
> }
>
> int gpioh_get_value(struct gpio *g)
> {
> return gpio_get_value(g->gpio);
> }
>
> (...)
>
> Then we can work from there. I think it adds the proper
> opaqueness factor.

Looks nice, simple and to the point! Let's see if I can find the time to cook
something based on this.

Thanks!
Alex.



\
 
 \ /
  Last update: 2012-11-08 08:02    [W:0.073 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site