From patchwork Tue Jan 9 00:27:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 123792 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3378968qgn; Mon, 8 Jan 2018 16:29:54 -0800 (PST) X-Google-Smtp-Source: ACJfBos3TtFLzNH+YGMfpniSu4pDYegbK5xGSaP1TJEac6QgVC/4908NIxP6jfwx1rDBZCV9RxfF X-Received: by 10.84.228.214 with SMTP id y22mr8461877pli.444.1515457794551; Mon, 08 Jan 2018 16:29:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515457794; cv=none; d=google.com; s=arc-20160816; b=E8912psGP9kGyYUrDHSaSPheknA4qh1zDVBZ5ku8Lfz9b0qFJJC0aVSyj7VuONgnh3 6fLfbpKLd7QEz/sIHunwecyJxB6kiV4Aq3uN8LMF1yejZGxXdSQ+xJOY1oo4BCajtq6i kmrFU8nMI36rMa+Bacxjj4dGhsfhcHmsfEz0oaJLEj3GlAhEceutfx+VOOL91Boh1RFi 24hi1Cd6Z/qR294/0z4+VomPvsVkxSvrTx4vsnNhJTqGx8Q4hmNCWuBmjoqxiNbk/OxM zwc9a4bYd2q96HlGSR08n3iat/1YB9ByRHsodulcvdZ4hs4pStyPVoVikzx5UzcWO1rq egWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=QOYtIlbjnWlmBCvIEZEY6MoTuX2H4NRTFIfi6Mqhx3I=; b=cGi4lV8IgI0K/ogGSVUMNZGmpGVwse/dJLnoRAjB5tItzNyJJXMXfKmEL55X6RWevp ubEoCDRfseePXbYmgGBG1AJaXFnj8Wri6kAG6wAgqeLpNPe+kR5xEBYt55lGjfX58cu6 YhOVExZTvoiZEULW55HianhJvpG8+X4LXyA8cuWPSarmAV7UaGL/3ZvfEetcVJH6mu0J eU28BFzrp0Qb3doGqsbXiKjOW4u1q3bRyIqZ/tY4cUMS9uESTCN9r6kRCwQDFeUM0p+0 BODeiT2viVPwh+hwI1ikjqFAxRkLVHrR8jWbgEamjJ+l0EAMRqbklkz9ZtjSJ26QSNWF MqCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TRfDC3Lb; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si5089290plc.215.2018.01.08.16.29.54; Mon, 08 Jan 2018 16:29:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TRfDC3Lb; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753989AbeAIA3x (ORCPT + 6 others); Mon, 8 Jan 2018 19:29:53 -0500 Received: from mail-lf0-f68.google.com ([209.85.215.68]:41320 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753381AbeAIA3w (ORCPT ); Mon, 8 Jan 2018 19:29:52 -0500 Received: by mail-lf0-f68.google.com with SMTP id h137so14021571lfe.8 for ; Mon, 08 Jan 2018 16:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=avkwYsRDLnEN8RMuyk5MqCgDUscrPjP5mDXuM3OajSs=; b=TRfDC3LbDNUX3eNPES/k2bJgH7mZvZT49yehDvwg49gnuaqPsaFPvRVYZgz482oxsu ar5mOpK7bhIhQEZfVkkScCu991K0oryHpti6qVfs0DnxH1xUmUOF3LjAVusA7xyNSJBn jUtLNzn6oHXRDG7VNeEbe5iF/34RIj+BwxFTU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=avkwYsRDLnEN8RMuyk5MqCgDUscrPjP5mDXuM3OajSs=; b=gJ5ZNOucJu43j5mwWQqvVaMfXGrqgYGqeU+5QnFGI2Sya0WX+dHSHJRCxE1N7x5AfG P3C8yDuFW0ypgZiZtB+6Y2IiYREM+xSn7Hh6rkyMPrp003MzQAjBh8bbAc7GN2l5IRic jyF954ZDVYRTen6/cxfx/hK4+67LAaGV4HjcAnD/gmD2BxwG8JKFsEFW//+mnPv6wv+I h3zKZpIjT+PTxWOvQRDsBWO4Nj+AzagpqiKxg6Dje6GPXfCui7B7KwyX69XIrT4Umy4/ XYu0FNjq4S36C5LRrrQzfpJGrZVsCqT/DerztT8y/B9hO7XMBEyx+oDX47QLwyLCBOri 7Bzg== X-Gm-Message-State: AKwxyteUztwuRrDiJ4U9VytpLTKrLIx2PgttyUiJyoHVS7UOJhrOmYV2 vjxzXoKIN2OnczgVOlTvVYBowQ== X-Received: by 10.25.24.147 with SMTP id 19mr1818035lfy.132.1515457790851; Mon, 08 Jan 2018 16:29:50 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id 2sm2583013lju.17.2018.01.08.16.29.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 16:29:50 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown , linux-gpio@vger.kernel.org, Rob Herring Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 2/4] gpio: Break out code to get a descriptor from a DT node Date: Tue, 9 Jan 2018 01:27:27 +0100 Message-Id: <20180109002727.22676-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Sometimes a GPIO needs to be taken from a node without a device associated with it. The fwnode accessor does this, let's however break out the DT code for now. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 117 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 34 deletions(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index aad84a6306c4..294c255e6227 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3629,18 +3629,83 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, } EXPORT_SYMBOL_GPL(gpiod_get_index); +/** + * gpiod_get_from_of_node() - obtain a GPIO from an OF node + * @node: handle of the OF node + * @propname: name of the DT property representing the GPIO + * @index: index of the GPIO to obtain for the consumer + * @dflags: GPIO initialization flags + * @label: label to attach to the requested GPIO + * + * Returns: + * On successful request the GPIO pin is configured in accordance with + * provided @dflags. If the node does not have the requested GPIO + * property, NULL is returned. + * + * In case of error an ERR_PTR() is returned. + */ +static struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label) +{ + struct gpio_desc *desc = ERR_PTR(-ENODEV); + unsigned long lflags = 0; + enum of_gpio_flags flags; + bool active_low = false; + bool single_ended = false; + bool open_drain = false; + int ret; + + desc = of_get_named_gpiod_flags(node, propname, + index, &flags); + + if (!desc || IS_ERR(desc)) { + /* If it is not there, just return NULL */ + if (PTR_ERR(desc) == -ENOENT) + return NULL; + return desc; + } + + active_low = flags & OF_GPIO_ACTIVE_LOW; + single_ended = flags & OF_GPIO_SINGLE_ENDED; + open_drain = flags & OF_GPIO_OPEN_DRAIN; + + ret = gpiod_request(desc, label); + if (ret) + return ERR_PTR(ret); + + if (active_low) + lflags |= GPIO_ACTIVE_LOW; + + if (single_ended) { + if (open_drain) + lflags |= GPIO_OPEN_DRAIN; + else + lflags |= GPIO_OPEN_SOURCE; + } + + ret = gpiod_configure_flags(desc, propname, lflags, dflags); + if (ret < 0) { + gpiod_put(desc); + return ERR_PTR(ret); + } + + return desc; +} + /** * fwnode_get_named_gpiod - obtain a GPIO from firmware node * @fwnode: handle of the firmware node * @propname: name of the firmware property representing the GPIO - * @index: index of the GPIO to obtain in the consumer + * @index: index of the GPIO to obtain for the consumer * @dflags: GPIO initialization flags * @label: label to attach to the requested GPIO * * This function can be used for drivers that get their configuration - * from firmware. + * from opaque firmware. * - * Function properly finds the corresponding GPIO using whatever is the + * The function properly finds the corresponding GPIO using whatever is the * underlying firmware interface and then makes sure that the GPIO * descriptor is requested before it is returned to the caller. * @@ -3657,53 +3722,37 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, { struct gpio_desc *desc = ERR_PTR(-ENODEV); unsigned long lflags = 0; - bool active_low = false; - bool single_ended = false; - bool open_drain = false; int ret; if (!fwnode) return ERR_PTR(-EINVAL); if (is_of_node(fwnode)) { - enum of_gpio_flags flags; - - desc = of_get_named_gpiod_flags(to_of_node(fwnode), propname, - index, &flags); - if (!IS_ERR(desc)) { - active_low = flags & OF_GPIO_ACTIVE_LOW; - single_ended = flags & OF_GPIO_SINGLE_ENDED; - open_drain = flags & OF_GPIO_OPEN_DRAIN; - } + desc = gpiod_get_from_of_node(to_of_node(fwnode), + propname, index, + dflags, + label); + return desc; } else if (is_acpi_node(fwnode)) { struct acpi_gpio_info info; desc = acpi_node_get_gpiod(fwnode, propname, index, &info); - if (!IS_ERR(desc)) { - active_low = info.polarity == GPIO_ACTIVE_LOW; - ret = acpi_gpio_update_gpiod_flags(&dflags, info.flags); - if (ret) - pr_debug("Override GPIO initialization flags\n"); - } - } + if (IS_ERR(desc)) + return desc; - if (IS_ERR(desc)) - return desc; + ret = acpi_gpio_update_gpiod_flags(&dflags, info.flags); + if (ret) + pr_debug("Override GPIO initialization flags\n"); + if (info.polarity == GPIO_ACTIVE_LOW) + lflags |= GPIO_ACTIVE_LOW; + } + + /* Currently only ACPI takes this path */ ret = gpiod_request(desc, label); if (ret) return ERR_PTR(ret); - if (active_low) - lflags |= GPIO_ACTIVE_LOW; - - if (single_ended) { - if (open_drain) - lflags |= GPIO_OPEN_DRAIN; - else - lflags |= GPIO_OPEN_SOURCE; - } - ret = gpiod_configure_flags(desc, propname, lflags, dflags); if (ret < 0) { gpiod_put(desc); From patchwork Tue Jan 9 00:29:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 123793 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3380759qgn; Mon, 8 Jan 2018 16:32:08 -0800 (PST) X-Google-Smtp-Source: ACJfBotYpJgM0DF54iv6HgkKa63Oc1b8FP3lldmFX4cGvFAkgqRXlbQ5thfE0YE+COVHBhkWuISN X-Received: by 10.99.180.5 with SMTP id s5mr1726115pgf.5.1515457928814; Mon, 08 Jan 2018 16:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515457928; cv=none; d=google.com; s=arc-20160816; b=vSmtZ+FPU6lRXNJDdpxUcP4QX4rdpT2s53cM+cbVHT4r7Z7p5GmNO+bJmr4/1Q1Fan PqbLNpQ1aURNL72lfjyMUFlhnW8sJzFOatnvj9sFVP3cEOyAEjz+Z4RI7ih1ntEm6cfm n6YdtVK2IeskGP9MGtQkOsld6BO0/+PrLYN3RnwERfx5wXrh7mVLqyCic/FLjAnO5rqI JZidfFo5I89utiP/3WWd1U4fHLZXmuRueHjAYZg/2DKzux85TTO1NK1H5Ap/TNNEzHe6 CmZw17L3QaGqLyGrbKCF1bWzJZLMYQQ7144dZ7rPPg6QALx5DqOzG86OrcwHXs7Tvhce U3Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=XYiu0RY6XlSvSsceOOnAIankAoChgp160KXlTIQFUGA=; b=WjwzokxmwqlzQ8YdeAmy5Sy/OR2gO50jSd60oE+zSkA22cM1h0fZOx9pSOmNJk+8yA ALvacxBXxzA67PzAzniOwmqdc88gT4JRB82O782RhIK0a663v2nAgnRJi6L1dDLp0SX2 r2WF3+P4CiF1OuB1gNGacan3AKj+MDhHW0GDmbwN/D3YSKD60aDp7Ml8+oUTM/8Djcxr /jmmYlhaWF6eO3Ty+y95FhsUW6KYpn40/BxSi1nUe6ouxEO1DXqOsF1rd7XHpiF5RSDZ MIZ/85FONza/ttar+WbgMB0SLzcpGil2TxP8G7ZBgAk4cU1POKoNn7ajNTCfLXSytdGC UWpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LI8uvDxm; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s9si8168320pgr.775.2018.01.08.16.32.08; Mon, 08 Jan 2018 16:32:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LI8uvDxm; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752769AbeAIAcH (ORCPT + 6 others); Mon, 8 Jan 2018 19:32:07 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:39281 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752446AbeAIAcG (ORCPT ); Mon, 8 Jan 2018 19:32:06 -0500 Received: by mail-lf0-f67.google.com with SMTP id m8so7958304lfc.6 for ; Mon, 08 Jan 2018 16:32:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=hYzVO1NfD7aLCNyYOxGjiQZDW/K2oo2pqJ2cUszNCb8=; b=LI8uvDxm6pFnIfJ5TYCZekkxsQIwMhs0Hf3NnkBFfdB3/X016I+LitE1VDiKFddqSe vCKNbpeZpADDhUkgJUPLnTrJQr/rbCmLku7HO7RTuh+a0XcEd97bsYxRSFMKxB+v/mYd 4nr+dffqM8HB29cbbo/VYVI4kfL5XxHC/NSas= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=hYzVO1NfD7aLCNyYOxGjiQZDW/K2oo2pqJ2cUszNCb8=; b=djNDpP6xezBYm00O7w3iZR4qkQRuW46TMBML0P4p/innwQ2p/rh2awN4vqwzzOABI6 YaT30UbwJxs94K4NkVl+fxHjBy8SfN1XHTN/D9ziPPtX3UZWOBUnDNnnwdT4G6yc2621 1PCJkAn1QADlAf+fwvpwLhkglKdWIddl2pPdtvhVpWeAKTPWTMLhTcr9DZ0VpG+WciTt PZHNGrSUSoW7cenLph0cg3ChLl6vYkdg1f6737TDMw3g717cfuRooiZbIMP87/KjQTSP lBKZ2Y3L8piPau0dkvWwwpwysFUZTkKx2wmx30ixE6xJR88vrIELFGEJTXFVXogB+2bY 9aDQ== X-Gm-Message-State: AKwxytdftZdjgDiTiRKswQ5uO9UYQzR9AIxspha2b1ktrTsvW4AKoWo8 18HsJbvOLcSQXqTEyELv89kVzWfWc0g= X-Received: by 10.25.79.84 with SMTP id a20mr6000979lfk.123.1515457925244; Mon, 08 Jan 2018 16:32:05 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id h97sm2622629lji.77.2018.01.08.16.32.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 16:32:04 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown , linux-gpio@vger.kernel.org, Rob Herring Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 3/4] gpio: Export devm_gpiod_get_from_of_node() for consumers Date: Tue, 9 Jan 2018 01:29:59 +0100 Message-Id: <20180109002959.22738-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org We have been holding back on adding an API for fetching GPIO handles directly from device nodes, strongly preferring to get it from the spawn devices instead. The fwnode interface however already contains an API for doing this, as it is used for opaque device tree nodes or ACPI nodes for getting handles to LEDs and keys that use GPIO: those are specified as one child per LED/key in the device tree and are not individual devices. However regulators present a special problem as they already have helper functions to traverse the device tree from a regulator node and two levels down to fill in data, and as it already traverses GPIO nodes in its own way, and already holds a pointer to each regulators device tree node, it makes most sense to export an API to fetch the GPIO descriptor directly from the node. We only support the devm_* version for now, hopefully no non-devres version will be needed. Signed-off-by: Linus Walleij --- drivers/gpio/devres.c | 42 ++++++++++++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib.c | 9 +++++---- drivers/gpio/gpiolib.h | 6 ++++++ include/linux/gpio/consumer.h | 17 +++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c index afbff155a0ba..e82cc763633c 100644 --- a/drivers/gpio/devres.c +++ b/drivers/gpio/devres.c @@ -124,6 +124,48 @@ struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, } EXPORT_SYMBOL(devm_gpiod_get_index); +/** + * devm_gpiod_get_from_of_node() - obtain a GPIO from an OF node + * @dev: device for lifecycle management + * @node: handle of the OF node + * @propname: name of the DT property representing the GPIO + * @index: index of the GPIO to obtain for the consumer + * @dflags: GPIO initialization flags + * @label: label to attach to the requested GPIO + * + * Returns: + * On successful request the GPIO pin is configured in accordance with + * provided @dflags. + * + * In case of error an ERR_PTR() is returned. + */ +struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, + struct device_node *node, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label) +{ + struct gpio_desc **dr; + struct gpio_desc *desc; + + dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), + GFP_KERNEL); + if (!dr) + return ERR_PTR(-ENOMEM); + + desc = gpiod_get_from_of_node(node, propname, index, dflags, label); + if (IS_ERR(desc)) { + devres_free(dr); + return desc; + } + + *dr = desc; + devres_add(dev, dr); + + return desc; +} +EXPORT_SYMBOL(devm_gpiod_get_from_of_node); + /** * devm_fwnode_get_index_gpiod_from_child - get a GPIO descriptor from a * device's child node diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 294c255e6227..762a470030ce 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3644,10 +3644,10 @@ EXPORT_SYMBOL_GPL(gpiod_get_index); * * In case of error an ERR_PTR() is returned. */ -static struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, - const char *propname, int index, - enum gpiod_flags dflags, - const char *label) +struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label) { struct gpio_desc *desc = ERR_PTR(-ENODEV); unsigned long lflags = 0; @@ -3693,6 +3693,7 @@ static struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, return desc; } +EXPORT_SYMBOL(gpiod_get_from_of_node); /** * fwnode_get_named_gpiod - obtain a GPIO from firmware node diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index af48322839c3..187056b8c6a6 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -189,6 +189,12 @@ void gpiod_set_array_value_complex(bool raw, bool can_sleep, struct gpio_desc **desc_array, int *value_array); +/* This is just passed between gpiolib and devres */ +struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label); + extern struct spinlock gpio_lock; extern struct list_head gpio_devices; diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 7447d85dbe2f..9f3cb651cb3c 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -150,8 +150,14 @@ struct gpio_desc *gpio_to_desc(unsigned gpio); int desc_to_gpio(const struct gpio_desc *desc); /* Child properties interface */ +struct device_node; struct fwnode_handle; +struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, + struct device_node *node, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label); struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, const char *propname, int index, enum gpiod_flags dflags, @@ -464,8 +470,19 @@ static inline int desc_to_gpio(const struct gpio_desc *desc) } /* Child properties interface */ +struct device_node; struct fwnode_handle; +static inline +struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, + struct device_node *node, + const char *propname, int index, + enum gpiod_flags dflags, + const char *label) +{ + return ERR_PTR(-ENOSYS); +} + static inline struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, const char *propname, int index, From patchwork Tue Jan 9 00:32:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 123794 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3382832qgn; Mon, 8 Jan 2018 16:34:47 -0800 (PST) X-Google-Smtp-Source: ACJfBovVn+Y63VI9ynfN6dxh5QKwvACRXuFNlT26NtmehhB8Nvg/98HFPDaWQhcr5GafwzBFP4qr X-Received: by 10.98.87.17 with SMTP id l17mr12169589pfb.201.1515458086986; Mon, 08 Jan 2018 16:34:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515458086; cv=none; d=google.com; s=arc-20160816; b=q8dJ3hNIU8nZnSdIIVKy2BEyKO4A3anDXysVuHUse49PxACvcKMHpIQ2jehbM2o9Gc poUaP+hT15bi5VJPXaig9XGdgraPIzHByQz+iwEq2sTfR4JwolvVaQL23L+eXhxKqcxO 3nEzD4Is+ESIkuH0zwYrGO64+7b2vYyEvp934jE/OSBUa4pc7NWvtFr7JLpTcx5lxu7v LcitNTPJpmyr7k50L2om9TGrabIvyDKc3fZSn+xVOQdPyxaV63XW0pk8Rt1sCqOLiiRD xgPe51CeU1lHuUWEBETxF2lFaZcKCPHxNkBPzFOCdLogQX018lfE2ZoeXpWLe+u0HL/l oUPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=WHpl7OvcPtsyKBkBZtMb9izgIbKDinJO/YTjTAtNvyU=; b=JMXRGT/2AKh8o0cSjZ1K8BiowFbW/cb6e2yc5tHh3/FpJS5uC3YA8czLLJfO2+8LUn Aqakq7G6U9lR25keflLQ5WOGROnWcMNU4eeNAdhGyp9CHKwUkDn/hce7cdYFogPQxAml RfrIGUG+iEKJyZdSy1VR3FAKVcPfhQztEtk37wHQYuOg3Xsr9oUsCVozXWACwPOoKhKi kgZHVbs9SRnLpcbNWcsAmgSbfK5hGn5vKqXMAQwpQVEMcgRO2Fvcz2m0wUjSNCnQwMDn H6iVXoju+/YBBV1dMwHLEn4ZV+BT8Soiv65X86y/58WOcuzEq564t2yoJ9arJ9rZkm/9 xZ2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LPpTmnwK; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n16si9408314pll.476.2018.01.08.16.34.46; Mon, 08 Jan 2018 16:34:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LPpTmnwK; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755022AbeAIAeq (ORCPT + 6 others); Mon, 8 Jan 2018 19:34:46 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:34284 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752907AbeAIAep (ORCPT ); Mon, 8 Jan 2018 19:34:45 -0500 Received: by mail-lf0-f66.google.com with SMTP id h140so14038814lfg.1 for ; Mon, 08 Jan 2018 16:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=8po5DbOU+D2gLBjycWLFcgyH4oDl6KaDXH+9d2m8vS8=; b=LPpTmnwKO3D+Q4t+b1/M+yxC7ZNLvjCyrhAGW+iPKZfRnzK7JOv1n3TCAVpERHNPUA ya001lavZkcoqN4fhbq1meWvLjzi2L51GC1ofkSUOLzLUrcKH0EfoxSNTeR/iKTWg+LX tpS7lryELa3O0wPcqmiCsRiojOVc/PQ+rDCEI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8po5DbOU+D2gLBjycWLFcgyH4oDl6KaDXH+9d2m8vS8=; b=PaI3s6qGkdeT2F/gIqjDi2lOsmiJoC5ymw/vPHK5pZTU6UJF90U2mVA93lkFJYtz+d B67dKnH5dAP3wgcs5/auYYUygeKdwpWu11s2EgDJU8RTHj3+nwmuwpswhqee3wHEWsnv S8wpEFk5753Mb8nZ7jjM0bRptY0PO5yT45Vu5SI7v7R3gcFIdruWEAPAix90//wUCfh9 ie7dbtogY/m1JHBuDS2CsJLnMq9K7mou+oImPbicE6erBXkzHVPZez7Qf3hLPNPIdP1g 03wWcLKHdYiiiZA0HNbR4a8gjba2wbpjBpyfGN3xu3ufKgT0G3knJjSA1KJSCTJvwtRT xtTw== X-Gm-Message-State: AKwxytfHDIhbJ/6jmdf+DEsRPhAgT7MlSTdLbnUdq4VIy8pxV3/Ss198 lqAxTc1k6CKPTBBmBeXjZ8FwsA== X-Received: by 10.25.215.223 with SMTP id q92mr5914496lfi.107.1515458083645; Mon, 08 Jan 2018 16:34:43 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id g192sm2342786lfg.69.2018.01.08.16.34.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2018 16:34:42 -0800 (PST) From: Linus Walleij To: Liam Girdwood , Mark Brown , linux-gpio@vger.kernel.org, Rob Herring Cc: linux-kernel@vger.kernel.org, Linus Walleij Subject: [PATCH 4/4] gpio: of: Add special quirk to parse regulator flags Date: Tue, 9 Jan 2018 01:32:40 +0100 Message-Id: <20180109003240.22924-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org While most GPIOs are indicated to be active low or open drain using their twocell flags, we have legacy regulator bindings to take into account. Add a quirk respecting the special boolean active-high and open drain flags when parsing regulator nodes for GPIOs. This makes it possible to get rid of duplicated inversion semantics handling in the regulator core and any regulator drivers parsing and handling this separately. Unfortunately the old regulator inversion semantics are specified such that the presence or absence of "enable-active-high" solely controls the semantics, so we cannot deprecate this in favor of the phandle-provided inversion flag, instead any such phandle inversion flag provided in the second cell of a GPIO handle must be actively ignored, so we print a warning to contain the situation and make things easy for the users. Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib-of.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 9686922310a4..37bd3e8f2b0b 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -56,6 +56,42 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, return gpiochip_get_desc(chip, ret); } +static void of_gpio_flags_quirks(struct device_node *np, + enum of_gpio_flags *flags) +{ + /* + * Some GPIO fixed regulator quirks. + * Note that active low is the default. + */ + if (IS_ENABLED(CONFIG_REGULATOR) && + (of_device_is_compatible(np, "reg-fixed-voltage") || + of_device_is_compatible(np, "regulator-gpio"))) { + /* + * The regulator GPIO handles are specified such that the + * presence or absence of "enable-active-high" solely controls + * the polarity of the GPIO line. Any phandle flags must + * be actively ignored. + */ + if (*flags & OF_GPIO_ACTIVE_LOW) { + pr_warn("%s GPIO handle specifies active low - ignored\n", + of_node_full_name(np)); + *flags &= ~OF_GPIO_ACTIVE_LOW; + } + if (!of_property_read_bool(np, "enable-active-high")) + *flags |= OF_GPIO_ACTIVE_LOW; + } + /* + * Legacy open drain handling for fixed voltage regulators. + */ + if (IS_ENABLED(CONFIG_REGULATOR) && + of_device_is_compatible(np, "reg-fixed-voltage") && + of_property_read_bool(np, "gpio-open-drain")) { + *flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN); + pr_info("%s uses legacy open drain flag - update the DTS if you can\n", + of_node_full_name(np)); + } +} + /** * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API * @np: device node to get GPIO from @@ -93,6 +129,8 @@ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, if (IS_ERR(desc)) goto out; + of_gpio_flags_quirks(np, flags); + pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", __func__, propname, np, index, PTR_ERR_OR_ZERO(desc));