From patchwork Fri Oct 20 03:37:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 828442 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yJBPh54nQz9tXP for ; Fri, 20 Oct 2017 14:39:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="DcwdqxDU"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="FfmcKGSs"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yJBPh3y1kzDqN4 for ; Fri, 20 Oct 2017 14:39:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="DcwdqxDU"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="FfmcKGSs"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="DcwdqxDU"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="FfmcKGSs"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yJBND3M2HzDqBc; Fri, 20 Oct 2017 14:38:36 +1100 (AEDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 636DC20DA7; Thu, 19 Oct 2017 23:38:34 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 19 Oct 2017 23:38:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=44qfK8ueCz4SYWv/d gS7FTT6m50rawmWP+xcfKvWNy4=; b=DcwdqxDUYhBSNSz+OAi/1BKfrbarfrsd1 5/GZ6Wt63T3Zv/ey9XMX40M+HAejtseR9JzvhojtzOGGphfapL8PfMHy5y8OC2ek gKUGXI+r/CNKvqAjkwTdwJuZEhjs0iMfVaXDQ2U7fxuekU0qHKNjYpsZUH0rAOy5 kinnF6TBJtvRC+J6YUS+QWnyvAKfCwmY3WSF0aXPRT4nRRyoQ7J5O8fs290TIPyk +oHvQHl8+S4rfxfQA2konqNEPgjsp6/fH8CzEpPCbC+PnAZzf7LRwAcUMGn3a7Vq 9Dm8ZGl5Q09Zb5a7dhXpDgyfFfp+bnH/Cu31PUbrlgbmaV6BniMrw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=44qfK8ueCz4SYWv/dgS7FTT6m50rawmWP+xcfKvWNy4=; b=FfmcKGSs VuxJw/VWxQTruHn+P9W1AO0TyfGGryQc1PkrJGYCIDO/PuaffNka/6yS4fUpcoh2 3FgO/8BhEXjwAyb42NdEeuje0mbOjkgXbN4ipVhtpBNChpjFTEbQd7CrRy9L07Jo hdT5xTLsxlZKwje1MYSOEfjIz4pFTQuogCc8nzcuY22mXGgapNZTjd839RqfQcEq u0WzMCBNDpb9X2vM+Zk8ZDBD8RwqnSlxTs8b59BsXQW5fZbgkppZO7i33CmKkCUa YFzh0hOGt3FBuPrAPM9AFa6XKaL0BcG7+QxeHVXPvaxmHwyqsj4V7bSd/WO6df0h JrSMBWzc1d3OYw== X-ME-Sender: Received: from keelia.lan (220-253-53-78.dyn.iinet.net.au [220.253.53.78]) by mail.messagingengine.com (Postfix) with ESMTPA id DB7FA247AD; Thu, 19 Oct 2017 23:38:28 -0400 (EDT) From: Andrew Jeffery To: linux-gpio@vger.kernel.org Subject: [RFC PATCH 1/5] gpio: gpiolib: Add core support for maintaining GPIO values on reset Date: Fri, 20 Oct 2017 14:07:23 +1030 Message-Id: <20171020033727.21557-2-andrew@aj.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171020033727.21557-1-andrew@aj.id.au> References: <20171020033727.21557-1-andrew@aj.id.au> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ryan_chen@aspeedtech.com, linux-aspeed@lists.ozlabs.org, corbet@lwn.net, patches@opensource.cirrus.com, linus.walleij@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, ldewangan@nvidia.com, ckeepax@opensource.wolfsonmicro.com, frowand.list@gmail.com, openbmc@lists.ozlabs.org Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" GPIO state reset tolerance is implemented in gpiolib through the addition of a new pinconf parameter. With that, some renaming of helpers is done to clarify the scope of the already existing gpiochip_line_is_persistent(), as it's now ambiguous as to whether that means on suspend, reset or both. This in-turn impacts gpio-arizona, but not in any complicated way. This change lays the groundwork for implementing reset tolerance support in all of the external interfaces that can influence GPIOs. Signed-off-by: Andrew Jeffery --- drivers/gpio/gpio-arizona.c | 4 +-- drivers/gpio/gpiolib.c | 55 +++++++++++++++++++++++++++++++-- drivers/gpio/gpiolib.h | 1 + include/linux/gpio/consumer.h | 9 ++++++ include/linux/gpio/driver.h | 5 ++- include/linux/gpio/machine.h | 2 ++ include/linux/pinctrl/pinconf-generic.h | 2 ++ 7 files changed, 73 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-arizona.c b/drivers/gpio/gpio-arizona.c index d4e6ba0301bc..d3fe23569811 100644 --- a/drivers/gpio/gpio-arizona.c +++ b/drivers/gpio/gpio-arizona.c @@ -33,7 +33,7 @@ static int arizona_gpio_direction_in(struct gpio_chip *chip, unsigned offset) { struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); struct arizona *arizona = arizona_gpio->arizona; - bool persistent = gpiochip_line_is_persistent(chip, offset); + bool persistent = gpiochip_line_is_persistent_suspend(chip, offset); bool change; int ret; @@ -99,7 +99,7 @@ static int arizona_gpio_direction_out(struct gpio_chip *chip, { struct arizona_gpio *arizona_gpio = gpiochip_get_data(chip); struct arizona *arizona = arizona_gpio->arizona; - bool persistent = gpiochip_line_is_persistent(chip, offset); + bool persistent = gpiochip_line_is_persistent_suspend(chip, offset); unsigned int val; int ret; diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a56b29fd8bb1..d9dc7e588699 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2414,6 +2414,40 @@ int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) EXPORT_SYMBOL_GPL(gpiod_set_debounce); /** + * gpiod_set_reset_tolerant - Hold state across controller reset + * @desc: descriptor of the GPIO for which to set debounce time + * @tolerant: True to hold state across a controller reset, false otherwise + * + * Returns: + * 0 on success, %-ENOTSUPP if the controller doesn't support setting the + * reset tolerance or less than zero on other failures. + */ +int gpiod_set_reset_tolerant(struct gpio_desc *desc, bool tolerant) +{ + struct gpio_chip *chip; + unsigned long packed; + int rc; + + chip = desc->gdev->chip; + if (!chip->set_config) + return -ENOTSUPP; + + packed = pinconf_to_config_packed(PIN_CONFIG_RESET_TOLERANT, tolerant); + + rc = chip->set_config(chip, gpio_chip_hwgpio(desc), packed); + if (rc < 0) + return rc; + + if (tolerant) + set_bit(FLAG_RESET_TOLERANT, &desc->flags); + else + clear_bit(FLAG_RESET_TOLERANT, &desc->flags); + + return 0; +} +EXPORT_SYMBOL_GPL(gpiod_set_reset_tolerant); + +/** * gpiod_is_active_low - test whether a GPIO is active-low or not * @desc: the gpio descriptor to test * @@ -2885,7 +2919,8 @@ bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset) } EXPORT_SYMBOL_GPL(gpiochip_line_is_open_source); -bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset) +bool gpiochip_line_is_persistent_suspend(struct gpio_chip *chip, + unsigned int offset) { if (offset >= chip->ngpio) return false; @@ -2893,7 +2928,18 @@ bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset) return !test_bit(FLAG_SLEEP_MAY_LOSE_VALUE, &chip->gpiodev->descs[offset].flags); } -EXPORT_SYMBOL_GPL(gpiochip_line_is_persistent); +EXPORT_SYMBOL_GPL(gpiochip_line_is_persistent_suspend); + +bool gpiochip_line_is_persistent_reset(struct gpio_chip *chip, + unsigned int offset) +{ + if (offset >= chip->ngpio) + return false; + + return test_bit(FLAG_RESET_TOLERANT, + &chip->gpiodev->descs[offset].flags); +} +EXPORT_SYMBOL_GPL(gpiochip_line_is_persistent_reset); /** * gpiod_get_raw_value_cansleep() - return a gpio's raw value @@ -3271,6 +3317,11 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, if (lflags & GPIO_SLEEP_MAY_LOSE_VALUE) set_bit(FLAG_SLEEP_MAY_LOSE_VALUE, &desc->flags); + status = gpiod_set_reset_tolerant(desc, + !!(lflags & GPIO_RESET_TOLERANT)); + if (status < 0) + return status; + /* No particular flag request, return here... */ if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) { pr_debug("no flags found for %s\n", con_id); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 799208fc189a..4ce36f14c1ad 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -202,6 +202,7 @@ struct gpio_desc { #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */ #define FLAG_IS_HOGGED 11 /* GPIO is hogged */ #define FLAG_SLEEP_MAY_LOSE_VALUE 12 /* GPIO may lose value in sleep */ +#define FLAG_RESET_TOLERANT 13 /* GPIO to maintain state at shutdown */ /* Connection label */ const char *label; diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 8f702fcbe485..ee5e125c8fec 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -121,6 +121,7 @@ void gpiod_set_raw_array_value_cansleep(unsigned int array_size, int *value_array); int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); +int gpiod_set_reset_tolerant(struct gpio_desc *desc, bool tolerant); int gpiod_is_active_low(const struct gpio_desc *desc); int gpiod_cansleep(const struct gpio_desc *desc); @@ -381,6 +382,14 @@ static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) return -ENOSYS; } +static inline int gpiod_set_reset_tolerant(struct gpio_desc *desc, + bool tolerant) +{ + /* GPIO can never have been requested */ + WARN_ON(1); + return -ENOSYS; +} + static inline int gpiod_is_active_low(const struct gpio_desc *desc) { /* GPIO can never have been requested */ diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index c97f8325e8bf..6e9d32bdab55 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -233,7 +233,10 @@ bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset); bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset); /* Sleep persistence inquiry for drivers */ -bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset); +bool gpiochip_line_is_persistent_suspend(struct gpio_chip *chip, + unsigned int offset); +bool gpiochip_line_is_persistent_reset(struct gpio_chip *chip, + unsigned int offset); /* get driver data */ void *gpiochip_get_data(struct gpio_chip *chip); diff --git a/include/linux/gpio/machine.h b/include/linux/gpio/machine.h index 5e9f294c29eb..11b7209c7ab9 100644 --- a/include/linux/gpio/machine.h +++ b/include/linux/gpio/machine.h @@ -11,6 +11,8 @@ enum gpio_lookup_flags { GPIO_OPEN_SOURCE = (1 << 2), GPIO_SLEEP_MAINTAIN_VALUE = (0 << 3), GPIO_SLEEP_MAY_LOSE_VALUE = (1 << 3), + GPIO_RESET_INTOLERANT = (0 << 4), + GPIO_RESET_TOLERANT = (1 << 4), }; /** diff --git a/include/linux/pinctrl/pinconf-generic.h b/include/linux/pinctrl/pinconf-generic.h index 5d8bc7f21c2a..487cc863cb36 100644 --- a/include/linux/pinctrl/pinconf-generic.h +++ b/include/linux/pinctrl/pinconf-generic.h @@ -90,6 +90,7 @@ * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to * this parameter (on a custom format) tells the driver which alternative * slew rate to use. + * @PIN_CONFIG_RESET_TOLERANT: retains the pin state across a system reset * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if * you need to pass in custom configurations to the pin controller, use * PIN_CONFIG_END+1 as the base offset. @@ -117,6 +118,7 @@ enum pin_config_param { PIN_CONFIG_POWER_SOURCE, PIN_CONFIG_SLEEP_HARDWARE_STATE, PIN_CONFIG_SLEW_RATE, + PIN_CONFIG_RESET_TOLERANT, PIN_CONFIG_END = 0x7F, PIN_CONFIG_MAX = 0xFF, }; From patchwork Fri Oct 20 03:37:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 828443 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yJBPj0dwqz9tXl for ; Fri, 20 Oct 2017 14:39:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="mjIwLowF"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q6NJwZmh"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yJBPh6g79zDqKs for ; Fri, 20 Oct 2017 14:39:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="mjIwLowF"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q6NJwZmh"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="mjIwLowF"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q6NJwZmh"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yJBNL1gbYzDqBc; Fri, 20 Oct 2017 14:38:42 +1100 (AEDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 389A520F98; Thu, 19 Oct 2017 23:38:40 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 19 Oct 2017 23:38:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=+/U+i58U0yt6M3/Wv 4Mvsf8+TWrJQfxSm+GG6W2R0Qc=; b=mjIwLowF0qaOFSLIAjBfRj10cdsz6Myp3 gUILfTN7wR309mS3EIW3PXVVhaC2b6mp5vVl772AzuZLBM3y44h+2DXsvSqerSPW BFhOAOWKCD2KyiUkqoOsGqdl0f3Ga4xc/c9ZMpJ/cZzrHu77jN+NR/xJ4iHP18nl CYJ9crgtbQoIUsryv+Y4BbPAFvJL5fv1RxQiyyDOtA3wfUTwlLavxWpgHx8P6DJ+ 1BUQMOr44ttUgGohlH2CfeF/EU38sQrJjNUjFe5fAYR0vzDF6bDq73ngsO6Rlgdt uNpaMJXW2bMyFYZOfpFWvV8eUhz7nnN2EO8xRBbjVk5p8rGguQkqg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=+/U+i58U0yt6M3/Wv4Mvsf8+TWrJQfxSm+GG6W2R0Qc=; b=Q6NJwZmh tRJ5aF0b4R8+b1gj7RWobU8ZeqvoqAJHv3kGo0BfdHzcISKuSIboJRF6GXzYKBbI gq3AVtbNXX/yM/sYkVX7gf0i3NFV2hET+ZWe1im2B9VGUA+Dq2UwFh3zPj1u7idm zAvdn0bQWe2Qx8PbaprYdU67czHtb61AW9xBiRQguMw/5HXsSts8thSd95USIpTz tEGy+Q0IERw98O0/Ollphl6vY4B82jDFBLCdf9Cjv/oVYtpOR/4KFOlb0oSUbB8H Jg3YkVLqouaHI/DpHsDazmhxFdjvs1RN5wwt3Um7tzeznlTrTc/97/uTPlHAxY1n 6JLYCK1CZnLT/w== X-ME-Sender: Received: from keelia.lan (220-253-53-78.dyn.iinet.net.au [220.253.53.78]) by mail.messagingengine.com (Postfix) with ESMTPA id B43132489B; Thu, 19 Oct 2017 23:38:34 -0400 (EDT) From: Andrew Jeffery To: linux-gpio@vger.kernel.org Subject: [RFC PATCH 2/5] gpio: gpiolib: Add OF support for maintaining GPIO values on reset Date: Fri, 20 Oct 2017 14:07:24 +1030 Message-Id: <20171020033727.21557-3-andrew@aj.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171020033727.21557-1-andrew@aj.id.au> References: <20171020033727.21557-1-andrew@aj.id.au> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ryan_chen@aspeedtech.com, linux-aspeed@lists.ozlabs.org, corbet@lwn.net, patches@opensource.cirrus.com, linus.walleij@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, ldewangan@nvidia.com, ckeepax@opensource.wolfsonmicro.com, frowand.list@gmail.com, openbmc@lists.ozlabs.org Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" Add flags and the associated flag mappings between interfaces to enable GPIO reset tolerance to be specified via devicetree. Signed-off-by: Andrew Jeffery --- drivers/gpio/gpiolib-of.c | 2 ++ drivers/gpio/gpiolib.c | 5 +++++ include/dt-bindings/gpio/gpio.h | 4 ++++ include/linux/of_gpio.h | 1 + 4 files changed, 12 insertions(+) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index e0d59e61b52f..4a268ba52998 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -155,6 +155,8 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id, if (of_flags & OF_GPIO_SLEEP_MAY_LOSE_VALUE) *flags |= GPIO_SLEEP_MAY_LOSE_VALUE; + if (of_flags & OF_GPIO_RESET_TOLERANT) + *flags |= GPIO_RESET_TOLERANT; return desc; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d9dc7e588699..6b4c5df10e84 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3434,6 +3434,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, bool active_low = false; bool single_ended = false; bool open_drain = false; + bool reset_tolerant = false; int ret; if (!fwnode) @@ -3448,6 +3449,7 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, active_low = flags & OF_GPIO_ACTIVE_LOW; single_ended = flags & OF_GPIO_SINGLE_ENDED; open_drain = flags & OF_GPIO_OPEN_DRAIN; + reset_tolerant = flags & OF_GPIO_RESET_TOLERANT; } } else if (is_acpi_node(fwnode)) { struct acpi_gpio_info info; @@ -3478,6 +3480,9 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, lflags |= GPIO_OPEN_SOURCE; } + if (reset_tolerant) + lflags |= GPIO_RESET_TOLERANT; + ret = gpiod_configure_flags(desc, propname, lflags, dflags); if (ret < 0) { gpiod_put(desc); diff --git a/include/dt-bindings/gpio/gpio.h b/include/dt-bindings/gpio/gpio.h index 70de5b7a6c9b..01c75d9e308e 100644 --- a/include/dt-bindings/gpio/gpio.h +++ b/include/dt-bindings/gpio/gpio.h @@ -32,4 +32,8 @@ #define GPIO_SLEEP_MAINTAIN_VALUE 0 #define GPIO_SLEEP_MAY_LOSE_VALUE 8 +/* Bit 4 express GPIO persistence on reset */ +#define GPIO_RESET_INTOLERANT 0 +#define GPIO_RESET_TOLERANT 16 + #endif diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h index 1fe205582111..9b34737706a7 100644 --- a/include/linux/of_gpio.h +++ b/include/linux/of_gpio.h @@ -32,6 +32,7 @@ enum of_gpio_flags { OF_GPIO_SINGLE_ENDED = 0x2, OF_GPIO_OPEN_DRAIN = 0x4, OF_GPIO_SLEEP_MAY_LOSE_VALUE = 0x8, + OF_GPIO_RESET_TOLERANT = 0x16, }; #ifdef CONFIG_OF_GPIO From patchwork Fri Oct 20 03:37:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 828447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yJBQc4Tjxz9tXP for ; Fri, 20 Oct 2017 14:40:40 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="t3rRi87Z"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="qUtMClsq"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yJBQc0MclzDqKX for ; Fri, 20 Oct 2017 14:40:40 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="t3rRi87Z"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="qUtMClsq"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="t3rRi87Z"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="qUtMClsq"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yJBNR5fShzDqJl; Fri, 20 Oct 2017 14:38:47 +1100 (AEDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id C436520DA7; Thu, 19 Oct 2017 23:38:45 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 19 Oct 2017 23:38:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Qkjt7F+1bNzgCEoXu /43rmDfStMrzLff3C9TeEgV/+Q=; b=t3rRi87ZusR07ccmkZ63KNPfjnwfqJk66 aeEbbTQMvoDk/5ptk5EYo7wTFmG7Rc9MnOhSWo/DgWdPyN0w84z9SOWdrkZ1STfF wNPbsQA+4CJF8eELHQpE3WiuMFljoN0ByjkuWdh5P7rNkK+zsKYvXviDe4DEPKCK 0+ej39RmGMmGMpLQs3xd82p1pxQUrUMaqNmPd/FDK3xyprQ0oPcwYVSEvTUgyB0C ggbPA+D8/WhgKTbZc/Hz0hmVGOVxKkWdv9kPK5UP5Svuvva36mX0Vscd9LvtKzYE OUbunE3E/lL1KPVBNp4+Crqn40FrutFNT4mwETa2fglLCh+jGqR6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=Qkjt7F+1bNzgCEoXu/43rmDfStMrzLff3C9TeEgV/+Q=; b=qUtMClsq WLiCDYZgOg1WozCR8DdtM6w53zhGzfWMQpnABF1OKRfIoWPOJX7kHROhjJQPgcdL U+Q1DfJYpZa1v6siC7rd/PzBZCXLv69TwUzruheiQppvRFh8tIkJ+61zOV5F5os+ KWt1uepOQO8SdPJwCbGkwiCT8OzXz74phcPI7Wd/SbsI4b4lKz71tMZpIFvGIZ8O rX0C9X7m3DEXmEeiubojwghm3UDarscSqCfCu5OF/1sKn6wrVAKrm0IcgAu4Nf73 GttSqhZuVoZUoW+Qa0xlJW23xQ2wyFNnzBlLJXaHQDXQC+ayNnS7OzNhbW65ZAZ/ sNn9hR5/WyoSqw== X-ME-Sender: Received: from keelia.lan (220-253-53-78.dyn.iinet.net.au [220.253.53.78]) by mail.messagingengine.com (Postfix) with ESMTPA id 8C582248B1; Thu, 19 Oct 2017 23:38:40 -0400 (EDT) From: Andrew Jeffery To: linux-gpio@vger.kernel.org Subject: [RFC PATCH 3/5] gpio: gpiolib: Add chardev support for maintaining GPIO values on reset Date: Fri, 20 Oct 2017 14:07:25 +1030 Message-Id: <20171020033727.21557-4-andrew@aj.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171020033727.21557-1-andrew@aj.id.au> References: <20171020033727.21557-1-andrew@aj.id.au> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ryan_chen@aspeedtech.com, linux-aspeed@lists.ozlabs.org, corbet@lwn.net, patches@opensource.cirrus.com, linus.walleij@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, ldewangan@nvidia.com, ckeepax@opensource.wolfsonmicro.com, frowand.list@gmail.com, openbmc@lists.ozlabs.org Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" Similar to devicetree support, add flags and mappings to expose reset tolerance configuration through the chardev interface. Signed-off-by: Andrew Jeffery --- drivers/gpio/gpiolib.c | 14 +++++++++++++- include/uapi/linux/gpio.h | 11 ++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6b4c5df10e84..442ee5ceee08 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -357,7 +357,8 @@ struct linehandle_state { GPIOHANDLE_REQUEST_OUTPUT | \ GPIOHANDLE_REQUEST_ACTIVE_LOW | \ GPIOHANDLE_REQUEST_OPEN_DRAIN | \ - GPIOHANDLE_REQUEST_OPEN_SOURCE) + GPIOHANDLE_REQUEST_OPEN_SOURCE | \ + GPIOHANDLE_REQUEST_RESET_TOLERANT) static long linehandle_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) @@ -498,6 +499,17 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) set_bit(FLAG_OPEN_SOURCE, &desc->flags); /* + * Unconditionally configure reset tolerance, as it's possible + * that the tolerance flag itself becomes tolerant to resets. + * Thus it could remain set from a previous environment, but + * the current environment may not expect it so. + */ + ret = gpiod_set_reset_tolerant(desc, + !!(lflags & GPIOHANDLE_REQUEST_RESET_TOLERANT)); + if (ret < 0) + goto out_free_descs; + + /* * Lines have to be requested explicitly for input * or output, else the line will be treated "as is". */ diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h index 333d3544c964..1b1ce1af8653 100644 --- a/include/uapi/linux/gpio.h +++ b/include/uapi/linux/gpio.h @@ -56,11 +56,12 @@ struct gpioline_info { #define GPIOHANDLES_MAX 64 /* Linerequest flags */ -#define GPIOHANDLE_REQUEST_INPUT (1UL << 0) -#define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1) -#define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2) -#define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3) -#define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4) +#define GPIOHANDLE_REQUEST_INPUT (1UL << 0) +#define GPIOHANDLE_REQUEST_OUTPUT (1UL << 1) +#define GPIOHANDLE_REQUEST_ACTIVE_LOW (1UL << 2) +#define GPIOHANDLE_REQUEST_OPEN_DRAIN (1UL << 3) +#define GPIOHANDLE_REQUEST_OPEN_SOURCE (1UL << 4) +#define GPIOHANDLE_REQUEST_RESET_TOLERANT (1UL << 5) /** * struct gpiohandle_request - Information about a GPIO handle request From patchwork Fri Oct 20 03:37:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 828448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yJBQd0YSjz9tXl for ; Fri, 20 Oct 2017 14:40:41 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="KJA4cEBq"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OjtOm8ij"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yJBQc6TL5zDqJ7 for ; Fri, 20 Oct 2017 14:40:40 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="KJA4cEBq"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OjtOm8ij"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="KJA4cEBq"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OjtOm8ij"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yJBNY4f8jzDqKX; Fri, 20 Oct 2017 14:38:53 +1100 (AEDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 9D28C20683; Thu, 19 Oct 2017 23:38:51 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 19 Oct 2017 23:38:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=Dn4ZA2gHALxqqOoAH /HtByP0kBRcjbCEn6PakPjdoNA=; b=KJA4cEBq+RIdkc6YZzJRW+UJGKBZW5zCt jIHvU5YBX1cmFynW4Ig5SC72ZjzYazawr3mTiNHZOvyU4SruPcWsnuRKbzhFvonN MZY8jqsZ0bC0c+57YA47PILBjR2vQU1dtmjgB0ygt/ZazBQYtnzouMV7bDw2qMFR fl9NmGcSlMdv56g3721+IisDByxABHCOrTbMywOSxISOdWl9CyIXdD4+9JrO6aeX cFo8Z0pr1Xe5G4EpZqupdO2aQ/KZY8gYZKuHRYIEnK3L4Ofn4Zb9Q+ahuskjIoYL WoTTW7uUVmQbDugZFVJaPAFZ2K1o6KiJRUv5Y95l1qDJdyELwSfbg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=Dn4ZA2gHALxqqOoAH/HtByP0kBRcjbCEn6PakPjdoNA=; b=OjtOm8ij 073/Qfs+z11yct8tyUpZGmkmV8/wIYvUP69s18gCRbfEtsTk6IQax+C+FOno/WLi MDMcheiJAsUqs2N6fba3QmaGXvuc5ASpzE1TwGZa1XinVtQKBX/byWtkeRcgskKY wA2KQG0ITNuhCBcZk9Q5xDr4J6Jyq73tHHDLFHoAOlzT5eeaEDudvuGavNzthj2M LEczvWm4LDuocshN4K+qvfhP0S816+dPkmmQqP/i/e63068GxY84BUyGImPX2/Mh OFVqXIEJ/hTUS9Jw2Gu1VJL1zenEq0DcrXVArV53RqyYVzzyRseo755pnqqk5x09 +C2AtBqFvrj1SA== X-ME-Sender: Received: from keelia.lan (220-253-53-78.dyn.iinet.net.au [220.253.53.78]) by mail.messagingengine.com (Postfix) with ESMTPA id 213AB2489B; Thu, 19 Oct 2017 23:38:45 -0400 (EDT) From: Andrew Jeffery To: linux-gpio@vger.kernel.org Subject: [RFC PATCH 4/5] gpio: gpiolib: Add sysfs support for maintaining GPIO values on reset Date: Fri, 20 Oct 2017 14:07:26 +1030 Message-Id: <20171020033727.21557-5-andrew@aj.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171020033727.21557-1-andrew@aj.id.au> References: <20171020033727.21557-1-andrew@aj.id.au> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ryan_chen@aspeedtech.com, linux-aspeed@lists.ozlabs.org, corbet@lwn.net, patches@opensource.cirrus.com, linus.walleij@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, ldewangan@nvidia.com, ckeepax@opensource.wolfsonmicro.com, frowand.list@gmail.com, openbmc@lists.ozlabs.org Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" Expose a new 'maintain' sysfs attribute to control both suspend and reset tolerance. Signed-off-by: Andrew Jeffery --- Documentation/gpio/sysfs.txt | 9 +++++ drivers/gpio/gpiolib-sysfs.c | 88 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/Documentation/gpio/sysfs.txt b/Documentation/gpio/sysfs.txt index aeab01aa4d00..f447f0746884 100644 --- a/Documentation/gpio/sysfs.txt +++ b/Documentation/gpio/sysfs.txt @@ -96,6 +96,15 @@ and have the following read/write attributes: for "rising" and "falling" edges will follow this setting. + "maintain" ... displays and controls whether the state of the GPIO is + maintained or lost on suspend or reset. The valid values take + the following meanings: + + 0: Do not maintain state on either suspend or reset + 1: Maintain state for suspend only + 2: Maintain state for reset only + 3: Maintain state for both suspend and reset + GPIO controllers have paths like /sys/class/gpio/gpiochip42/ (for the controller implementing GPIOs starting at #42) and have the following read-only attributes: diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 3f454eaf2101..bfa186e73e26 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -289,6 +289,74 @@ static ssize_t edge_store(struct device *dev, } static DEVICE_ATTR_RW(edge); +#define GPIOLIB_SYSFS_MAINTAIN_SUSPEND BIT(0) +#define GPIOLIB_SYSFS_MAINTAIN_RESET BIT(1) +#define GPIOLIB_SYSFS_MAINTAIN_ALL GENMASK(1, 0) +static ssize_t maintain_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct gpiod_data *data = dev_get_drvdata(dev); + ssize_t status = 0; + int val = 0; + + mutex_lock(&data->mutex); + + if (!test_bit(FLAG_SLEEP_MAY_LOSE_VALUE, &data->desc->flags)) + val |= GPIOLIB_SYSFS_MAINTAIN_SUSPEND; + + if (test_bit(FLAG_RESET_TOLERANT, &data->desc->flags)) + val |= GPIOLIB_SYSFS_MAINTAIN_RESET; + + status = sprintf(buf, "%d\n", val); + + mutex_unlock(&data->mutex); + + return status; +} + +static ssize_t maintain_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t size) +{ + struct gpiod_data *data = dev_get_drvdata(dev); + struct gpio_chip *chip; + ssize_t status; + long provided; + + mutex_lock(&data->mutex); + + chip = data->desc->gdev->chip; + + if (!chip->set_config) + return -ENOTSUPP; + + status = kstrtol(buf, 0, &provided); + if (status < 0) + goto out; + + if (provided & ~GPIOLIB_SYSFS_MAINTAIN_ALL) { + status = -EINVAL; + goto out; + } + + if (!(provided & GPIOLIB_SYSFS_MAINTAIN_SUSPEND)) + set_bit(FLAG_SLEEP_MAY_LOSE_VALUE, &data->desc->flags); + else + clear_bit(FLAG_SLEEP_MAY_LOSE_VALUE, + &data->desc->flags); + + /* Configure reset tolerance */ + status = gpiod_set_reset_tolerant(data->desc, + !!(provided & GPIOLIB_SYSFS_MAINTAIN_RESET)); +out: + mutex_unlock(&data->mutex); + + return status ? : size; + +} +static DEVICE_ATTR_RW(maintain); + /* Caller holds gpiod-data mutex. */ static int gpio_sysfs_set_active_low(struct device *dev, int value) { @@ -378,6 +446,7 @@ static struct attribute *gpio_attrs[] = { &dev_attr_edge.attr, &dev_attr_value.attr, &dev_attr_active_low.attr, + &dev_attr_maintain.attr, NULL, }; @@ -474,11 +543,22 @@ static ssize_t export_store(struct class *class, status = -ENODEV; goto done; } - status = gpiod_export(desc, true); - if (status < 0) + + /* + * If userspace is requesting the GPIO via sysfs, make them explicitly + * configure reset tolerance each time by unconditionally disabling it + * here, as the export and configuration steps are not atomic. + */ + status = gpiod_set_reset_tolerant(desc, false); + if (status < 0) { gpiod_free(desc); - else - set_bit(FLAG_SYSFS, &desc->flags); + } else { + status = gpiod_export(desc, true); + if (status < 0) + gpiod_free(desc); + else + set_bit(FLAG_SYSFS, &desc->flags); + } done: if (status) From patchwork Fri Oct 20 03:37:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 828451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yJBRS4C70z9tXP for ; Fri, 20 Oct 2017 14:41:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="muVfYOw0"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="rXmEXnC+"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yJBRS30qCzDqXj for ; Fri, 20 Oct 2017 14:41:24 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="muVfYOw0"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="rXmEXnC+"; dkim-atps=neutral X-Original-To: linux-aspeed@lists.ozlabs.org Delivered-To: linux-aspeed@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="muVfYOw0"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="rXmEXnC+"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yJBNg4JcCzDqRQ; Fri, 20 Oct 2017 14:38:59 +1100 (AEDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7520E20BF1; Thu, 19 Oct 2017 23:38:57 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Thu, 19 Oct 2017 23:38:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=yoh1CaMONAFLRi9+P fS7AYrUFtUqN1k3CcqjucPe+oE=; b=muVfYOw0VJMaksowju739fQcrv/zSnELc mFrJzveWv65I1ek8uFXSAUZd/+iQqrEtF87x8hLd+JMP5EMLTJ5MRECqrWT8UR+T oOn7GR7M/tC5OlrzgH2JBs61PcvKYg2krVzXUQdyHjmIK7InX/nMrwBnSVMjb7mc CdaYHOo4jKmu1qDF9L/tUbksqgroCVEYJ33gnbdb9PTzo4XwpKrTS9rxfEt45w5/ 41Hps95q05Gl8CzBpxuQIYK+JXkHyb9w7ZT4N01HRgjAmEX3SJKFqg35yqwLX5Tg a79tlYrE/O6XWac8u0LYRgS4xxSFma078DwoOKo7ogFWeQlgQVk9Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=yoh1CaMONAFLRi9+PfS7AYrUFtUqN1k3CcqjucPe+oE=; b=rXmEXnC+ dbOQTLIZWBov0WKudlp3a9cXmumZubDe18806lEMg9SfejtJ+WLcTGtjcqgkK27T vvA4jzTnNTg6HEw0vOuXKFPqt9A8hNijIxaUJFc+J2UH+42Vfpi2LbY0RkYdVX7W a2Gc/KDeWRa843Oyv7enQI0bygPIRIPs2uMVPSD6Xo1wFGhR2NQQay/VUeSdAIpR vxXFi/1Q/xUJG9nk9RcxxP6OHGUQ+UPIbIoCQeSOnO3vW4LOy86rvYxEX2Mcyasz MQv9CWjSHcijSIBuFwk24HQx4WrC7vZhvrIOO2aMbVTNjfj1Culo4evNqZcvZKza KKMDhK5UqKom9Q== X-ME-Sender: Received: from keelia.lan (220-253-53-78.dyn.iinet.net.au [220.253.53.78]) by mail.messagingengine.com (Postfix) with ESMTPA id 0ADBA2489B; Thu, 19 Oct 2017 23:38:51 -0400 (EDT) From: Andrew Jeffery To: linux-gpio@vger.kernel.org Subject: [RFC PATCH 5/5] gpio: aspeed: Add support for reset tolerance Date: Fri, 20 Oct 2017 14:07:27 +1030 Message-Id: <20171020033727.21557-6-andrew@aj.id.au> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171020033727.21557-1-andrew@aj.id.au> References: <20171020033727.21557-1-andrew@aj.id.au> X-BeenThere: linux-aspeed@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux ASPEED SoC development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, ryan_chen@aspeedtech.com, linux-aspeed@lists.ozlabs.org, corbet@lwn.net, patches@opensource.cirrus.com, linus.walleij@linaro.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, ldewangan@nvidia.com, ckeepax@opensource.wolfsonmicro.com, frowand.list@gmail.com, openbmc@lists.ozlabs.org Errors-To: linux-aspeed-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linux-aspeed" Use the new pinconf parameter for reset tolerance to expose the associated capability of the Aspeed GPIO controller. Signed-off-by: Andrew Jeffery --- drivers/gpio/gpio-aspeed.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c index bfc53995064a..0492cd917178 100644 --- a/drivers/gpio/gpio-aspeed.c +++ b/drivers/gpio/gpio-aspeed.c @@ -60,6 +60,7 @@ struct aspeed_gpio_bank { uint16_t val_regs; uint16_t irq_regs; uint16_t debounce_regs; + uint16_t tolerance_regs; const char names[4][3]; }; @@ -70,48 +71,56 @@ static const struct aspeed_gpio_bank aspeed_gpio_banks[] = { .val_regs = 0x0000, .irq_regs = 0x0008, .debounce_regs = 0x0040, + .tolerance_regs = 0x001c, .names = { "A", "B", "C", "D" }, }, { .val_regs = 0x0020, .irq_regs = 0x0028, .debounce_regs = 0x0048, + .tolerance_regs = 0x003c, .names = { "E", "F", "G", "H" }, }, { .val_regs = 0x0070, .irq_regs = 0x0098, .debounce_regs = 0x00b0, + .tolerance_regs = 0x00ac, .names = { "I", "J", "K", "L" }, }, { .val_regs = 0x0078, .irq_regs = 0x00e8, .debounce_regs = 0x0100, + .tolerance_regs = 0x00fc, .names = { "M", "N", "O", "P" }, }, { .val_regs = 0x0080, .irq_regs = 0x0118, .debounce_regs = 0x0130, + .tolerance_regs = 0x012c, .names = { "Q", "R", "S", "T" }, }, { .val_regs = 0x0088, .irq_regs = 0x0148, .debounce_regs = 0x0160, + .tolerance_regs = 0x015c, .names = { "U", "V", "W", "X" }, }, { .val_regs = 0x01E0, .irq_regs = 0x0178, .debounce_regs = 0x0190, + .tolerance_regs = 0x018c, .names = { "Y", "Z", "AA", "AB" }, }, { - .val_regs = 0x01E8, - .irq_regs = 0x01A8, + .val_regs = 0x01e8, + .irq_regs = 0x01a8, .debounce_regs = 0x01c0, + .tolerance_regs = 0x01bc, .names = { "AC", "", "", "" }, }, }; @@ -531,6 +540,30 @@ static int aspeed_gpio_setup_irqs(struct aspeed_gpio *gpio, return 0; } +static int aspeed_gpio_reset_tolerance(struct gpio_chip *chip, + unsigned int offset, bool enable) +{ + struct aspeed_gpio *gpio = gpiochip_get_data(chip); + const struct aspeed_gpio_bank *bank; + unsigned long flags; + u32 val; + + bank = to_bank(offset); + + spin_lock_irqsave(&gpio->lock, flags); + val = readl(gpio->base + bank->tolerance_regs); + + if (enable) + val |= GPIO_BIT(offset); + else + val &= ~GPIO_BIT(offset); + + writel(val, gpio->base + bank->tolerance_regs); + spin_unlock_irqrestore(&gpio->lock, flags); + + return 0; +} + static int aspeed_gpio_request(struct gpio_chip *chip, unsigned int offset) { if (!have_gpio(gpiochip_get_data(chip), offset)) @@ -768,6 +801,8 @@ static int aspeed_gpio_set_config(struct gpio_chip *chip, unsigned int offset, param == PIN_CONFIG_DRIVE_OPEN_SOURCE) /* Return -ENOTSUPP to trigger emulation, as per datasheet */ return -ENOTSUPP; + else if (param == PIN_CONFIG_RESET_TOLERANT) + return aspeed_gpio_reset_tolerance(chip, offset, arg); return -ENOTSUPP; }