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,