From patchwork Fri Sep 13 03:22:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1161839 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n/tuaB6x"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46V1DB0q1Nz9sNF for ; Fri, 13 Sep 2019 13:22:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbfIMDWq (ORCPT ); Thu, 12 Sep 2019 23:22:46 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37420 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726032AbfIMDWq (ORCPT ); Thu, 12 Sep 2019 23:22:46 -0400 Received: by mail-pl1-f195.google.com with SMTP id b10so12679017plr.4; Thu, 12 Sep 2019 20:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j2w8J4UIC3b5lx+y07rDcDaGRQCf9wYAm17Az5VE72U=; b=n/tuaB6xgyYLZm6SYFCTRFe3KmESaMOVF6EfoNHoJ0tCj/fDo9E/aw0VR4W3pT2EFO yBc5GrKxprdsOpN5hk91bIek1gusbADc0YpTGoFShKji48PbS4Gv8+UN4xIhh9xgdjGW BIchaTn8Z7ZiANO5sBO8Sa3si7qnB8sSYN/0ZmYjkC6m9cllvN0Ipyc01EJWLPIXyW5c DfvXsJJZ5nFUkdzVtjUa8ivK3WY1qfDZzE/g8ejVT8pDnaIubXgKnlDOsOgKLeBIgLOW z76dcmF9SA/ACmwqv06msRGspJmZB1m8RlURiJLkfXjuzo8V2hn48zQuYWdgtSWLGOig n6ug== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=j2w8J4UIC3b5lx+y07rDcDaGRQCf9wYAm17Az5VE72U=; b=gwD0bSel5ZCRusNht2XLMAqdRgs6zCOgtGuBpjQrz5BQ1V2o2r/AdDlTmd8b20lc9r XGckxhts7MvF0kF8zpjaHFT8obRzaq38vVGoF6/E66eU5GW5emnvC4VEBmf96/whWjm9 gyZ6yaJU1bH9uYI8lzgaKucIYeG+M89vQ4RGI3KNySGshWVoTilGfLR5JwMCTDNo/xyP y+Ik+2lHOVuU1cvXPeC4RoiWREyQt7bgOzD2nwFc+zyevM0tJ2+RaUgeRjkEiR8wlX40 ZWKXoG83FuGmaA7hh9Fojn9JdDDuvReTw31BfV4FJPlhb2GDc9gEl12hOSrGQpnEZ+I2 gVUw== X-Gm-Message-State: APjAAAWKO+191sOHaK+Fn37IEJ1YW9LoHB4/5HJuTyufu6Z9cB1DpWoY eW5lgQvXZAnXAXzYtfliZUU= X-Google-Smtp-Source: APXvYqxnlVkiDm54lrpwZsA79zz1AIvNF9KSRuQ2CNfyHmOoET6qxnunvpxE8X3ZgVg7Wd58xZxWMQ== X-Received: by 2002:a17:902:7596:: with SMTP id j22mr34288450pll.280.1568344965348; Thu, 12 Sep 2019 20:22:45 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id b2sm8060936pfd.81.2019.09.12.20.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2019 20:22:43 -0700 (PDT) From: Dmitry Torokhov To: Linus Walleij Cc: Andy Shevchenko , Mika Westerberg , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 1/2] gpiolib: introduce devm_fwnode_gpiod_get_index() Date: Thu, 12 Sep 2019 20:22:38 -0700 Message-Id: <20190913032240.50333-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog In-Reply-To: <20190913032240.50333-1-dmitry.torokhov@gmail.com> References: <20190913032240.50333-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org devm_fwnode_get_index_gpiod_from_child() is too long, besides the fwnode in question does not have to be a child of device node. Let's rename it to devm_fwnode_gpiod_get_index() and keep the old name for compatibility for now. Also let's add a devm_fwnode_gpiod_get() wrapper as majority of the callers need a single GPIO. Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov Reviewed-by: Mika Westerberg --- Changes in v2: - switched export to be EXPORT_SYMBOL_GPL to match the new export markings for the rest of GPIO devres functions - rebased on top of Linus W devel branch - added Andy's Reviewed-by drivers/gpio/gpiolib-devres.c | 19 ++++++++-------- include/linux/gpio/consumer.h | 41 ++++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c index 98e3c20d9730..9a0475c87f95 100644 --- a/drivers/gpio/gpiolib-devres.c +++ b/drivers/gpio/gpiolib-devres.c @@ -185,12 +185,11 @@ struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, EXPORT_SYMBOL_GPL(devm_gpiod_get_from_of_node); /** - * devm_fwnode_get_index_gpiod_from_child - get a GPIO descriptor from a - * device's child node + * devm_fwnode_gpiod_get_index - get a GPIO descriptor from a given node * @dev: GPIO consumer + * @fwnode: firmware node containing GPIO reference * @con_id: function within the GPIO consumer * @index: index of the GPIO to obtain in the consumer - * @child: firmware node (child of @dev) * @flags: GPIO initialization flags * @label: label to attach to the requested GPIO * @@ -200,11 +199,11 @@ EXPORT_SYMBOL_GPL(devm_gpiod_get_from_of_node); * On successful request the GPIO pin is configured in accordance with * provided @flags. */ -struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, - const char *con_id, int index, - struct fwnode_handle *child, - enum gpiod_flags flags, - const char *label) +struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, + struct fwnode_handle *fwnode, + const char *con_id, int index, + enum gpiod_flags flags, + const char *label) { char prop_name[32]; /* 32 is max size of property name */ struct gpio_desc **dr; @@ -224,7 +223,7 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, snprintf(prop_name, sizeof(prop_name), "%s", gpio_suffixes[i]); - desc = fwnode_get_named_gpiod(child, prop_name, index, flags, + desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags, label); if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) break; @@ -239,7 +238,7 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, return desc; } -EXPORT_SYMBOL_GPL(devm_fwnode_get_index_gpiod_from_child); +EXPORT_SYMBOL_GPL(devm_fwnode_gpiod_get_index); /** * devm_gpiod_get_index_optional - Resource-managed gpiod_get_index_optional() diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index b70af921c614..dc0ddcd30515 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -176,11 +176,11 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, const char *propname, int index, enum gpiod_flags dflags, const char *label); -struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, - const char *con_id, int index, - struct fwnode_handle *child, - enum gpiod_flags flags, - const char *label); +struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, + struct fwnode_handle *child, + const char *con_id, int index, + enum gpiod_flags flags, + const char *label); #else /* CONFIG_GPIOLIB */ @@ -531,6 +531,29 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, return ERR_PTR(-ENOSYS); } +static inline +struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, + struct fwnode_handle *fwnode, + const char *con_id, int index, + enum gpiod_flags flags, + const char *label) +{ + return ERR_PTR(-ENOSYS); +} + +#endif /* CONFIG_GPIOLIB */ + +static inline +struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev, + struct fwnode_handle *fwnode, + const char *con_id, + enum gpiod_flags flags, + const char *label) +{ + return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0, + flags, label); +} + static inline struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, const char *con_id, int index, @@ -538,11 +561,10 @@ struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, enum gpiod_flags flags, const char *label) { - return ERR_PTR(-ENOSYS); + return devm_fwnode_gpiod_get_index(dev, child, con_id, index, + flags, label); } -#endif /* CONFIG_GPIOLIB */ - static inline struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev, const char *con_id, @@ -550,8 +572,7 @@ struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev, enum gpiod_flags flags, const char *label) { - return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child, - flags, label); + return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label); } #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO) From patchwork Fri Sep 13 03:22:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 1161840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rmgYQxJ4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46V1DB6Dbmz9s4Y for ; Fri, 13 Sep 2019 13:22:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbfIMDWt (ORCPT ); Thu, 12 Sep 2019 23:22:49 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42580 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726032AbfIMDWt (ORCPT ); Thu, 12 Sep 2019 23:22:49 -0400 Received: by mail-pf1-f194.google.com with SMTP id w22so17198010pfi.9; Thu, 12 Sep 2019 20:22:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qe2h9NfhcUmoPESIDtsAXWHsKPsyhEADzKG8omWLqSM=; b=rmgYQxJ4cZAskQbfVPERybuMb0Dl9tUFzioHbDqTUtIEWrauDr0t5m1UgZTnf+SyKf /iM4v1a6CukTZFa9dnGIMNKmuIFiK0cUlC3XxPwhjGxNv9BHQ1HR+LUBGuqmXi3MUwBx M71xyAjYpdnCmS8/vCfac5bu91xvWlDhbYfjkoRiSVamtNz71B37w3qHvP/e5L20a9AG n9Zw98X8RMPbe4PEXbJV6ZxP4O0uAz/SLE1JUCjxNLt1k43j3mG5l2K5Md2mISjSSjhV i1jGrn29gEcdqGfW2GvlqHR48nIU+p0YbffPJW5X8E5+MhvY7uPuycGUbqS5clc71/T/ DsTw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qe2h9NfhcUmoPESIDtsAXWHsKPsyhEADzKG8omWLqSM=; b=YnPVlfnLxcvo/IjBE+28adLTGcmMvZ6jAHcPw4cEsN6oiTtHSrmvFwbgQV2+DSGakY oHAvvwAHFWY1TcrdhsFYadHpIUHzsulsWt1ANNDSdIO2iQtncrkMFPUYRXRmBbv2mEfO L7Zk1v24zohPMErVQ6kM0hb1IulDdF34+i5oKgmue5OlOcC871pCNHowE8gigA05DBgx Fps7Icn5ggB025QfaCOyGEhlaGd9U2/B+/63H32h/WRrZbiO+wZKa9WyYRf4lu7I3ehn m+CfT5Of5/xU+/3r6l5hep5ReT+iBBt/41l9uTZrsL2/5QWNeYkbWzBeCbvKtY7+FDQL 0DSA== X-Gm-Message-State: APjAAAVX7wL1YnBDjnmNrKhm2IRdTVeQncdGjc6Jk7HjEpMNz4xOJUkO kS1AdqJGeEc7a5+LFYVot6Un8usvumY= X-Google-Smtp-Source: APXvYqwnCcBzoRXJqlbD5UgaqK1idemNl6UNFB40/cc29W2d/CmEtBZh8z6Ik+hdu8CCyUxb/W3Fnw== X-Received: by 2002:a63:c107:: with SMTP id w7mr40148025pgf.283.1568344966677; Thu, 12 Sep 2019 20:22:46 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id b2sm8060936pfd.81.2019.09.12.20.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2019 20:22:45 -0700 (PDT) From: Dmitry Torokhov To: Linus Walleij Cc: Andy Shevchenko , Mika Westerberg , linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 2/2] gpiolib: introduce fwnode_gpiod_get_index() Date: Thu, 12 Sep 2019 20:22:39 -0700 Message-Id: <20190913032240.50333-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog In-Reply-To: <20190913032240.50333-1-dmitry.torokhov@gmail.com> References: <20190913032240.50333-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org This introduces fwnode_gpiod_get_index() that iterates through common gpio suffixes when trying to locate a GPIO within a given firmware node. We also switch devm_fwnode_gpiod_get_index() to call fwnode_gpiod_get_index() instead of iterating through GPIO suffixes on its own. Reviewed-by: Andy Shevchenko Signed-off-by: Dmitry Torokhov Reviewed-by: Mika Westerberg --- Changes in v2: - rebased on top of Linus W devel branch - added Andy's Reviewed-by drivers/gpio/gpiolib-devres.c | 16 +----------- drivers/gpio/gpiolib.c | 48 +++++++++++++++++++++++++++++++++++ include/linux/gpio/consumer.h | 13 ++++++++++ 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpiolib-devres.c b/drivers/gpio/gpiolib-devres.c index 9a0475c87f95..4421be09b960 100644 --- a/drivers/gpio/gpiolib-devres.c +++ b/drivers/gpio/gpiolib-devres.c @@ -205,29 +205,15 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, enum gpiod_flags flags, const char *label) { - char prop_name[32]; /* 32 is max size of property name */ struct gpio_desc **dr; struct gpio_desc *desc; - unsigned int i; dr = devres_alloc(devm_gpiod_release, sizeof(struct gpio_desc *), GFP_KERNEL); if (!dr) return ERR_PTR(-ENOMEM); - for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { - if (con_id) - snprintf(prop_name, sizeof(prop_name), "%s-%s", - con_id, gpio_suffixes[i]); - else - snprintf(prop_name, sizeof(prop_name), "%s", - gpio_suffixes[i]); - - desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags, - label); - if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) - break; - } + desc = fwnode_gpiod_get_index(fwnode, con_id, index, flags, label); if (IS_ERR(desc)) { devres_free(dr); return desc; diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 158e327a1285..11a6f4777436 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4317,6 +4317,54 @@ static int platform_gpio_count(struct device *dev, const char *con_id) return count; } +/** + * fwnode_gpiod_get_index - obtain a GPIO from firmware node + * @fwnode: handle of the firmware node + * @con_id: function within the GPIO consumer + * @index: index of the GPIO to obtain for the consumer + * @flags: GPIO initialization flags + * @label: label to attach to the requested GPIO + * + * This function can be used for drivers that get their configuration + * from opaque firmware. + * + * 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. + * + * Returns: + * On successful request the GPIO pin is configured in accordance with + * provided @flags. + * + * In case of error an ERR_PTR() is returned. + */ +struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, + const char *con_id, int index, + enum gpiod_flags flags, + const char *label) +{ + struct gpio_desc *desc; + char prop_name[32]; /* 32 is max size of property name */ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) { + if (con_id) + snprintf(prop_name, sizeof(prop_name), "%s-%s", + con_id, gpio_suffixes[i]); + else + snprintf(prop_name, sizeof(prop_name), "%s", + gpio_suffixes[i]); + + desc = fwnode_get_named_gpiod(fwnode, prop_name, index, flags, + label); + if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT)) + break; + } + + return desc; +} +EXPORT_SYMBOL_GPL(fwnode_gpiod_get_index); + /** * gpiod_count - return the number of GPIOs associated with a device / function * or -ENOENT if no GPIO has been assigned to the requested function diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index dc0ddcd30515..5215fdba6b9a 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -176,6 +176,10 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, const char *propname, int index, enum gpiod_flags dflags, const char *label); +struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, + const char *con_id, int index, + enum gpiod_flags flags, + const char *label); struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, struct fwnode_handle *child, const char *con_id, int index, @@ -531,6 +535,15 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, return ERR_PTR(-ENOSYS); } +static inline +struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, + const char *con_id, int index, + enum gpiod_flags flags, + const char *label) +{ + return ERR_PTR(-ENOSYS); +} + static inline struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, struct fwnode_handle *fwnode,