Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752970Ab2KGVYV (ORCPT ); Wed, 7 Nov 2012 16:24:21 -0500 Received: from mail-ee0-f46.google.com ([74.125.83.46]:38278 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751029Ab2KGVYU (ORCPT ); Wed, 7 Nov 2012 16:24:20 -0500 MIME-Version: 1.0 In-Reply-To: <1801189.6J3flQFRCq@percival> References: <38620644.IyR5R8rjKP@percival> <5097F8CF.5090100@wwwdotorg.org> <1801189.6J3flQFRCq@percival> Date: Wed, 7 Nov 2012 22:24:19 +0100 Message-ID: Subject: Re: How about a gpio_get(device *, char *) function? From: Linus Walleij To: Alex Courbot Cc: Stephen Warren , Grant Likely , "devicetree-discuss@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" , Thomas Gleixner Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2039 Lines: 68 On Tue, Nov 6, 2012 at 2:33 AM, Alex Courbot wrote: > How about, in a first time (and because I'd also like to get the power seqs > moving on), a typedef from int to gpio_handle_t and a first implementation of > the gpio_handle_*() API that would just call the existing integer-based API > (apart from gpio_handle_get())? That way things will not break when we switch > to a real handle. I'm afraid of typedef:ing gpio_handle_t to int because it sort of encourages non-handlers to be used mixed with the old integers. 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 *. 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. I don't really like the "gpioh_*" prefix instead of just gpio_* but I guess there is not polymorphism to exploit as transition path here :-P Yours, Linus Walleij -- 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/