From patchwork Sun Aug 30 07:44:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Pargmann X-Patchwork-Id: 7096721 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D812D9F32B for ; Sun, 30 Aug 2015 07:47:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C2B51206DD for ; Sun, 30 Aug 2015 07:47:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB61B206DE for ; Sun, 30 Aug 2015 07:47:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZVxIs-0004eE-IU; Sun, 30 Aug 2015 07:45:26 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZVxIj-0003SF-Vl for linux-arm-kernel@lists.infradead.org; Sun, 30 Aug 2015 07:45:18 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1ZVxIL-0001Vw-Rd; Sun, 30 Aug 2015 09:44:53 +0200 Received: from mpa by dude.hi.pengutronix.de with local (Exim 4.86) (envelope-from ) id 1ZVxIJ-0001rm-Tv; Sun, 30 Aug 2015 09:44:51 +0200 From: Markus Pargmann To: Linus Walleij Subject: [PATCH v2 3/3] gpiolib: Add GPIO initialization Date: Sun, 30 Aug 2015 09:44:46 +0200 Message-Id: <1440920686-6892-4-git-send-email-mpa@pengutronix.de> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1440920686-6892-1-git-send-email-mpa@pengutronix.de> References: <1440920686-6892-1-git-send-email-mpa@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mpa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150830_004518_207946_1319D520 X-CRM114-Status: GOOD ( 15.70 ) X-Spam-Score: -2.9 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Courbot , chrisrfq@gmail.com, Arun Bharadwaj , devicetree@vger.kernel.org, Johan Hovold , linux-gpio@vger.kernel.org, kernel@pengutronix.de, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Markus Pargmann , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This functions adds a way to initialize a GPIO without hogging it. Signed-off-by: Markus Pargmann --- Documentation/devicetree/bindings/gpio/gpio.txt | 29 +++++++------ drivers/gpio/gpiolib-of.c | 9 ++++ drivers/gpio/gpiolib.c | 55 ++++++++++++++++++++----- drivers/gpio/gpiolib.h | 2 + 4 files changed, 73 insertions(+), 22 deletions(-) diff --git a/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt index 5788d5cf1252..55d58983ba43 100644 --- a/Documentation/devicetree/bindings/gpio/gpio.txt +++ b/Documentation/devicetree/bindings/gpio/gpio.txt @@ -116,29 +116,34 @@ Every GPIO controller node must contain both an empty "gpio-controller" property, and a #gpio-cells integer property, which indicates the number of cells in a gpio-specifier. -The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism -providing automatic GPIO request and configuration as part of the -gpio-controller's driver probe function. +The GPIO chip may contain GPIO definitions. These define properties for single +GPIOs of this controller. -Each GPIO hog definition is represented as a child node of the GPIO controller. +GPIO hogging is a mechanism providing automatic GPIO request and configuration +as part of the gpio-controller's driver probe function. + +GPIO initialization provides an automatic initialization to known save values. +Instead of GPIO hogging the GPIO's value and direction can be modified by other +users after it was initialized. + +Each GPIO definition is represented as a child node of the GPIO controller. Required properties: -- gpio-hog: A property specifying that this child node represent a GPIO hog. - gpios: Store the GPIO information (id, flags, ...). Shall contain the number of cells specified in its parent node (GPIO controller node). -Only one of the following properties scanned in the order shown below. -This means that when multiple properties are present they will be searched -in the order presented below and the first match is taken as the intended -configuration. + +Optional properties: +- line-name: The GPIO label name. If not present the node name is used. + Only one of gpio-hog and gpio-initval may be specified. +- gpio-hog: A property specifying that this child node represent a GPIO hog. +- gpio-initval: This GPIO should be initialized to the specified configuration. + Only one of input, output-low and output-high may be specified: - input: A property specifying to set the GPIO direction as input. - output-low A property specifying to set the GPIO direction as output with the value low. - output-high A property specifying to set the GPIO direction as output with the value high. -Optional properties: -- line-name: The GPIO label name. If not present the node name is used. - Example of two SOC GPIO banks defined as gpio-controller nodes: qe_pio_a: gpio-controller@1400 { diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index f1fe5123da28..ee00c2c63f57 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -234,6 +234,15 @@ static void of_gpiochip_scan_gpios(struct gpio_chip *chip) if (gpiod_hog(desc, lflags, dflags)) continue; + } else if (of_property_read_bool(np, "gpio-initval")) { + if (!dflags) { + dev_warn(chip->dev, "GPIO line %d (%s): no initialization state specified, bailing out\n", + desc_to_gpio(desc), np->name); + continue; + } + + if (gpiod_initialize(desc, lflags, dflags)) + continue; } } } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f1559fa72c36..d7aa27a92e82 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2178,15 +2178,8 @@ struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, } EXPORT_SYMBOL_GPL(__gpiod_get_index_optional); -/** - * gpiod_hog - Hog the specified GPIO desc given the provided flags - * @desc: gpio whose value will be assigned - * @lflags: gpio_lookup_flags - returned from of_find_gpio() or - * of_get_gpio_hog() - * @dflags: gpiod_flags - optional GPIO initialization flags - */ -int gpiod_hog(struct gpio_desc *desc, unsigned long lflags, - enum gpiod_flags dflags) +static int _gpiod_initialize(struct gpio_desc *desc, unsigned long lflags, + enum gpiod_flags dflags) { int status; const char *name = desc->name; @@ -2202,11 +2195,31 @@ int gpiod_hog(struct gpio_desc *desc, unsigned long lflags, status = gpiod_configure_flags(desc, name, lflags, dflags); if (status < 0) { pr_err("setup of hog GPIO %s (chip %s, offset %d) failed\n", - name, gpiod_to_chip(desc)->label, gpio_chip_hwgpio(desc)); + name, gpiod_to_chip(desc)->label, + gpio_chip_hwgpio(desc)); gpiochip_free_own_desc(desc); return status; } + return 0; +} + +/** + * gpiod_hog - Hog the specified GPIO desc given the provided flags + * @desc: gpio whose value will be assigned + * @lflags: gpio_lookup_flags - returned from of_find_gpio() or + * of_get_gpio_hog() + * @dflags: gpiod_flags - optional GPIO initialization flags + */ +int gpiod_hog(struct gpio_desc *desc, unsigned long lflags, + enum gpiod_flags dflags) +{ + int ret; + + ret = _gpiod_initialize(desc, lflags, dflags); + if (ret) + return ret; + /* Mark GPIO as hogged so it can be identified and removed later */ set_bit(FLAG_IS_HOGGED, &desc->flags); @@ -2236,6 +2249,28 @@ static void gpiochip_free_hogs(struct gpio_chip *chip) } /** + * gpiod_initialize - Initialize a GPIO with a given value + * @desc: gpio whose value will be assigned + * @lflags: gpio_lookup_flags - returned from of_find_gpio() or + * of_get_gpio_hog() + * @dflags: gpiod_flags - optional GPIO initialization flags + * + * This is used to initialize GPIOs that were defined in DT + */ +int gpiod_initialize(struct gpio_desc *desc, unsigned long lflags, + enum gpiod_flags dflags) +{ + int ret; + + ret = _gpiod_initialize(desc, lflags, dflags); + if (ret) + return ret; + + __gpiod_free(desc); + return ret; +} + +/** * gpiod_get_array - obtain multiple GPIOs from a multi-index GPIO function * @dev: GPIO consumer, can be NULL for system-global GPIOs * @con_id: function within the GPIO consumer diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 6c2aeff59f86..b6dfa3526e3a 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -99,6 +99,8 @@ int gpiod_request(struct gpio_desc *desc, const char *label); void gpiod_free(struct gpio_desc *desc); int gpiod_hog(struct gpio_desc *desc, unsigned long lflags, enum gpiod_flags dflags); +int gpiod_initialize(struct gpio_desc *desc, unsigned long lflags, + enum gpiod_flags dflags); /* * Return the GPIO number of the passed descriptor relative to its chip