From patchwork Thu May 24 13:01:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Einar Vading X-Patchwork-Id: 919823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=axis.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40s8fF5FXBz9ryk for ; Thu, 24 May 2018 23:01:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935591AbeEXNBl (ORCPT ); Thu, 24 May 2018 09:01:41 -0400 Received: from bastet.se.axis.com ([195.60.68.11]:34815 "EHLO bastet.se.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935615AbeEXNBi (ORCPT ); Thu, 24 May 2018 09:01:38 -0400 Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id E491F184EC; Thu, 24 May 2018 15:01:36 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id C1BmXecyLLtb; Thu, 24 May 2018 15:01:33 +0200 (CEST) Received: from boulder02.se.axis.com (boulder02.se.axis.com [10.0.8.16]) by bastet.se.axis.com (Postfix) with ESMTPS id 57B8718522; Thu, 24 May 2018 15:01:23 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A74AA1A095; Thu, 24 May 2018 15:01:22 +0200 (CEST) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9ACA01A093; Thu, 24 May 2018 15:01:22 +0200 (CEST) Received: from thoth.se.axis.com (unknown [10.0.2.173]) by boulder02.se.axis.com (Postfix) with ESMTP; Thu, 24 May 2018 15:01:22 +0200 (CEST) Received: from lnxeinarv.se.axis.com (lnxeinarv.se.axis.com [10.96.37.1]) by thoth.se.axis.com (Postfix) with ESMTP id 8E26D1DA8; Thu, 24 May 2018 15:01:22 +0200 (CEST) Received: by lnxeinarv.se.axis.com (Postfix, from userid 21281) id 8AD7894176; Thu, 24 May 2018 15:01:22 +0200 (CEST) Date: Thu, 24 May 2018 15:01:22 +0200 From: Einar Vading To: Linus Walleij , Arnd Bergmann Cc: linux-gpio@vger.kernel.org Subject: [PATCH] gpiolib-legacy: Request gpio without touching direction Message-ID: <20180524130117.2io3vjzj6x7nncfd@lnxeinarv.se.axis.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170609-29-71984f (1.8.3) X-TM-AS-GCONF: 00 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Adds function to request a gpio without touching the direction of the gpio upon export. This is useful if some user space application know what state the gpio should be in and it is important that this state is kept during reboot. Signed-off-by: Einar Vading --- drivers/gpio/gpiolib-legacy.c | 50 +++++++++++++++++++++++++---------- include/asm-generic/gpio.h | 2 ++ include/linux/gpio.h | 6 +++++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib-legacy.c b/drivers/gpio/gpiolib-legacy.c index 8b830996fe..521c8099bf 100644 --- a/drivers/gpio/gpiolib-legacy.c +++ b/drivers/gpio/gpiolib-legacy.c @@ -11,13 +11,8 @@ void gpio_free(unsigned gpio) } EXPORT_SYMBOL_GPL(gpio_free); -/** - * gpio_request_one - request a single GPIO with initial configuration - * @gpio: the GPIO number - * @flags: GPIO configuration as specified by GPIOF_* - * @label: a literal description string of this GPIO - */ -int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) +static int _gpio_request_one(unsigned gpio, unsigned long flags, + const char *label, bool set_dir) { struct gpio_desc *desc; int err; @@ -41,14 +36,16 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) if (flags & GPIOF_ACTIVE_LOW) set_bit(FLAG_ACTIVE_LOW, &desc->flags); - if (flags & GPIOF_DIR_IN) - err = gpiod_direction_input(desc); - else - err = gpiod_direction_output_raw(desc, - (flags & GPIOF_INIT_HIGH) ? 1 : 0); + if (set_dir) { + if (flags & GPIOF_DIR_IN) + err = gpiod_direction_input(desc); + else + err = gpiod_direction_output_raw(desc, + (flags & GPIOF_INIT_HIGH) ? 1 : 0); - if (err) - goto free_gpio; + if (err) + goto free_gpio; + } if (flags & GPIOF_EXPORT) { err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE); @@ -62,8 +59,33 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) gpiod_free(desc); return err; } + +/** + * gpio_request_one - request a single GPIO with initial configuration + * @gpio: the GPIO number + * @flags: GPIO configuration as specified by GPIOF_* + * @label: a literal description string of this GPIO + */ +int gpio_request_one(unsigned gpio, unsigned long flags, const char *label) +{ + return _gpio_request_one(gpio, flags, label, true); +} EXPORT_SYMBOL_GPL(gpio_request_one); +/** + * gpio_request_one_keepdir - request a single GPIO with initial configuration + * but without setting direction on export. + * @gpio: the GPIO number + * @flags: GPIO configuration as specified by GPIOF_* + * @label: a literal description string of this GPIO + */ +int gpio_request_one_keepdir(unsigned gpio, unsigned long flags, + const char *label) +{ + return _gpio_request_one(gpio, flags, label, false); +} +EXPORT_SYMBOL_GPL(gpio_request_one_keepdir); + int gpio_request(unsigned gpio, const char *label) { struct gpio_desc *desc = gpio_to_desc(gpio); diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 8b74cff7c0..9e7d64d04e 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -115,6 +115,8 @@ static inline int __gpio_to_irq(unsigned gpio) } extern int gpio_request_one(unsigned gpio, unsigned long flags, const char *label); +extern int gpio_request_one_keepdir(unsigned gpio, unsigned long flags, + const char *label); extern int gpio_request_array(const struct gpio *array, size_t num); extern void gpio_free_array(const struct gpio *array, size_t num); diff --git a/include/linux/gpio.h b/include/linux/gpio.h index 8ef7fc0ce0..adca31cd88 100644 --- a/include/linux/gpio.h +++ b/include/linux/gpio.h @@ -113,6 +113,12 @@ static inline int gpio_request_one(unsigned gpio, return -ENOSYS; } +static inline int gpio_request_one_keepdir(unsigned gpio, + unsigned long flags, const char *label) +{ + return -ENOSYS; +} + static inline int gpio_request_array(const struct gpio *array, size_t num) { return -ENOSYS;