Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753788Ab2KHGMu (ORCPT ); Thu, 8 Nov 2012 01:12:50 -0500 Received: from hqemgate04.nvidia.com ([216.228.121.35]:9043 "EHLO hqemgate04.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751407Ab2KHGMt (ORCPT ); Thu, 8 Nov 2012 01:12:49 -0500 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Wed, 07 Nov 2012 21:59:26 -0800 From: Alex Courbot To: Linus Walleij CC: Stephen Warren , Grant Likely , "devicetree-discuss@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" , Thomas Gleixner Subject: Re: How about a gpio_get(device *, char *) function? Date: Thu, 8 Nov 2012 15:14:34 +0900 Message-ID: <1908355.tpLPJU8MKg@percival> Organization: NVIDIA User-Agent: KMail/4.9.2 (Linux/3.6.4-1-ARCH; KDE/4.9.2; x86_64; ; ) In-Reply-To: References: <38620644.IyR5R8rjKP@percival> <1801189.6J3flQFRCq@percival> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1708 Lines: 61 On Thursday 08 November 2012 05:24:19 Linus Walleij wrote: > I would prefer to create, e.g. in > 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 > and not . 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 > > /** > * @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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/