From patchwork Wed Nov 21 10:14:08 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Christophe PLAGNIOL-VILLARD X-Patchwork-Id: 1779341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 71F933FCA5 for ; Wed, 21 Nov 2012 10:18:21 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tb7M2-0003a4-03; Wed, 21 Nov 2012 10:16:26 +0000 Received: from 17.mo4.mail-out.ovh.net ([46.105.41.16] helo=mo4.mail-out.ovh.net) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tb7Lr-0003UA-4C for linux-arm-kernel@lists.infradead.org; Wed, 21 Nov 2012 10:16:21 +0000 Received: from mail92.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo4.mail-out.ovh.net (Postfix) with SMTP id 131681054E64 for ; Wed, 21 Nov 2012 11:23:58 +0100 (CET) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 21 Nov 2012 12:16:10 +0200 Received: from ns32433.ovh.net (HELO localhost) (plagnioj%jcrosoft.com@213.251.161.87) by ns0.ovh.net with SMTP; 21 Nov 2012 12:16:06 +0200 From: Jean-Christophe PLAGNIOL-VILLARD To: linux-arm-kernel@lists.infradead.org X-Ovh-Mailout: 178.32.228.4 (mo4.mail-out.ovh.net) Subject: [PATCH 1/2] gpiolib: add gpio_export_with_name Date: Wed, 21 Nov 2012 11:14:08 +0100 Message-Id: <1353492849-29397-1-git-send-email-plagnioj@jcrosoft.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <20121121101259.GQ4398@game.jcrosoft.org> References: <20121121101259.GQ4398@game.jcrosoft.org> X-Ovh-Tracer-Id: 12242472638410370045 X-Ovh-Remote: 213.251.161.87 (ns32433.ovh.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: 0 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehgedrudeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpeflvggrnhdqvehhrhhishhtohhphhgvucfrnfetiffpkffqnfdqggfknffnteftffcuoehplhgrghhnihhojhesjhgtrhhoshhofhhtrdgtohhmqeenucfjughrpefhvffufffkofgjfhestddtredtredttd X-Spam-Check: DONE|U 0.5/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehgedrudeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpeflvggrnhdqvehhrhhishhtohhphhgvucfrnfetiffpkffqnfdqggfknffnteftffcuoehplhgrghhnihhojhesjhgtrhhoshhofhhtrdgtohhmqeenucfjughrpefhvffufffkofgjfhestddtredtredttd X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121121_051615_478393_00F53942 X-CRM114-Status: GOOD ( 19.89 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [46.105.41.16 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: devicetree-discuss@lists.ozlabs.org, Jean-Christophe PLAGNIOL-VILLARD X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org allow to specify a name to an exported gpio Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD --- arch/mips/include/asm/mach-au1x00/gpio-au1000.h | 3 ++- arch/mips/include/asm/mach-au1x00/gpio-au1300.h | 3 ++- drivers/gpio/gpiolib.c | 12 +++++++----- include/asm-generic/gpio.h | 6 ++++-- include/linux/gpio.h | 23 ++++++++++++++++++++++- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/arch/mips/include/asm/mach-au1x00/gpio-au1000.h b/arch/mips/include/asm/mach-au1x00/gpio-au1000.h index 73853b5a..af4accb 100644 --- a/arch/mips/include/asm/mach-au1x00/gpio-au1000.h +++ b/arch/mips/include/asm/mach-au1x00/gpio-au1000.h @@ -633,7 +633,8 @@ static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) return -ENOSYS; } -static inline int gpio_export(unsigned gpio, bool direction_may_change) +static inline int gpio_export_with_name(unsigned gpio, + bool direction_may_change, const char *name) { return -ENOSYS; } diff --git a/arch/mips/include/asm/mach-au1x00/gpio-au1300.h b/arch/mips/include/asm/mach-au1x00/gpio-au1300.h index fb9975c..fcd152e 100644 --- a/arch/mips/include/asm/mach-au1x00/gpio-au1300.h +++ b/arch/mips/include/asm/mach-au1x00/gpio-au1300.h @@ -234,7 +234,8 @@ static inline void gpio_unexport(unsigned gpio) { } -static inline int gpio_export(unsigned gpio, bool direction_may_change) +static inline int gpio_export_with_name(unsigned gpio, + bool direction_may_change, const char *name) { return -ENOSYS; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index b667f76..2141165 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -714,9 +714,10 @@ static struct class gpio_class = { /** - * gpio_export - export a GPIO through sysfs + * gpio_export_with_name - export a GPIO through sysfs * @gpio: gpio to make available, already requested * @direction_may_change: true if userspace may change gpio direction + * @name: gpio name * Context: arch_initcall or later * * When drivers want to make a GPIO accessible to userspace after they @@ -728,7 +729,7 @@ static struct class gpio_class = { * * Returns zero on success, else an error. */ -int gpio_export(unsigned gpio, bool direction_may_change) +int gpio_export_with_name(unsigned gpio, bool direction_may_change, const char *name) { unsigned long flags; struct gpio_desc *desc; @@ -766,7 +767,9 @@ int gpio_export(unsigned gpio, bool direction_may_change) direction_may_change = false; spin_unlock_irqrestore(&gpio_lock, flags); - if (desc->chip->names && desc->chip->names[gpio - desc->chip->base]) + if (name) + ioname = name; + else if (desc->chip->names && desc->chip->names[gpio - desc->chip->base]) ioname = desc->chip->names[gpio - desc->chip->base]; dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), @@ -804,7 +807,7 @@ fail_unlock: pr_debug("%s: gpio%d status %d\n", __func__, gpio, status); return status; } -EXPORT_SYMBOL_GPL(gpio_export); +EXPORT_SYMBOL_GPL(gpio_export_with_name); static int match_export(struct device *dev, void *data) { @@ -856,7 +859,6 @@ done: } EXPORT_SYMBOL_GPL(gpio_export_link); - /** * gpio_sysfs_set_active_low - set the polarity of gpio sysfs value * @gpio: gpio to change diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index b6516f3..d04fc55 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -204,7 +204,8 @@ void devm_gpio_free(struct device *dev, unsigned int gpio); * A sysfs interface can be exported by individual drivers if they want, * but more typically is configured entirely from userspace. */ -extern int gpio_export(unsigned gpio, bool direction_may_change); +extern int gpio_export_with_name(unsigned gpio, bool direction_may_change, + const char *name); extern int gpio_export_link(struct device *dev, const char *name, unsigned gpio); extern int gpio_sysfs_set_active_low(unsigned gpio, int value); @@ -249,7 +250,8 @@ struct device; /* sysfs support is only available with gpiolib, where it's optional */ -static inline int gpio_export(unsigned gpio, bool direction_may_change) +static inline int gpio_export_with_name(unsigned gpio, + bool direction_may_change, const char *name) { return -ENOSYS; } diff --git a/include/linux/gpio.h b/include/linux/gpio.h index 7ba2762..6e01b8c 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h @@ -189,7 +189,8 @@ static inline void gpio_set_value_cansleep(unsigned gpio, int value) WARN_ON(1); } -static inline int gpio_export(unsigned gpio, bool direction_may_change) +static inline int gpio_export_with_name(unsigned gpio, + bool direction_may_change, const char *name) { /* GPIO can never have been requested or set as {in,out}put */ WARN_ON(1); @@ -247,4 +248,24 @@ gpiochip_remove_pin_ranges(struct gpio_chip *chip) #endif /* ! CONFIG_GENERIC_GPIO */ +/** + * gpio_export - export a GPIO through sysfs + * @gpio: gpio to make available, already requested + * @direction_may_change: true if userspace may change gpio direction + * Context: arch_initcall or later + * + * When drivers want to make a GPIO accessible to userspace after they + * have requested it -- perhaps while debugging, or as part of their + * public interface -- they may use this routine. If the GPIO can + * change direction (some can't) and the caller allows it, userspace + * will see "direction" sysfs attribute which may be used to change + * the gpio's direction. A "value" attribute will always be provided. + * + * Returns zero on success, else an error. + */ +static inline int gpio_export(unsigned gpio,bool direction_may_change) +{ + return gpio_export_with_name(gpio, direction_may_change, NULL); +} + #endif /* __LINUX_GPIO_H */