Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5558324ybc; Wed, 27 Nov 2019 06:01:46 -0800 (PST) X-Google-Smtp-Source: APXvYqwNlZkoaADqA152LyTdbLP8w75P2QCIAeosyIeWw7QeIKEIGXTR/Yu1O09t64ofXPpPLnMX X-Received: by 2002:a17:906:e289:: with SMTP id gg9mr48721069ejb.71.1574863306248; Wed, 27 Nov 2019 06:01:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574863306; cv=none; d=google.com; s=arc-20160816; b=O519DfT5mBTqsNkCrTJ8gHhHg8aR/mlwj6s3ELRGSExbpcTrL9JzWm6PwH+RZgEtze rxrbi2U3YSlAMMmhe+CcuggvgPdpcSYKhX05Up9WFS9ppXthUMXKIlK3MkK8bB7a2Yj2 Z0u1Ve2Jq0aUFhmVP3r/357VtlggxtC+nTRvFIVU8ts1mtah2Sf3yDyyZ7GKdxsCzVY3 hZBics87TgB9yx83pG6Wj101qlNRdotGNP0EbUU4Vt3FFkN/FB196spSWZwdn9tF8eIG UmF+g8SOgwh+zsSBhqKQTC+uFMaRX/TPkGuzLldFd+wSTPoxW4iD3DiFMcrrCC+wjHAk POPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/TwUT9QBGJXk/Tc+zfOQ+LrNU7bESoet6WEaqLV7dwk=; b=Kf7CvNp8D4HAMVYncgeAIQiwSh8wwiZT23haHTICfvsqr4Rug8TGNhuM/5Ll/YLj4r ClWPw1RJL5zdERdMsvmxZV+LsPs5KMKfA1vL9cwN3ZWKTVYO2pZ3Rv/Lr8eDR3bjCplR yLpeWPb18+qiHqLu5t8QLgwr16qq0epGZy96WETdWYJ0McizX/DsYHkAujJ7XoW92xC5 4QkVE1dNgAWdjx2HD+uLmUFFdiAh/rWMNSx7xsJuACIZp61Lg33gSBjgJVvd1o5h0njm nPUmWroISdtXMwOoo7foZwEzRRhCREL7iFIapwfINYhyHsneNd/CAkI3TpVrEbWwcct8 9Tew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z26si9014135ejb.223.2019.11.27.06.01.18; Wed, 27 Nov 2019 06:01:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727127AbfK0N7x (ORCPT + 99 others); Wed, 27 Nov 2019 08:59:53 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:39739 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726987AbfK0N7k (ORCPT ); Wed, 27 Nov 2019 08:59:40 -0500 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.lab.pengutronix.de) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iZxqv-0005PC-Jd; Wed, 27 Nov 2019 14:59:33 +0100 Received: from mfe by dude02.lab.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1iZxqv-0008EN-3R; Wed, 27 Nov 2019 14:59:33 +0100 From: Marco Felsch To: bgolaszewski@baylibre.com, linus.walleij@linaro.org, support.opensource@diasemi.com, lee.jones@linaro.org, robh+dt@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, stwiss.opensource@diasemi.com, Adam.Thomson.Opensource@diasemi.com Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH v2 1/5] gpio: add support to get local gpio number Date: Wed, 27 Nov 2019 14:59:28 +0100 Message-Id: <20191127135932.7223-2-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127135932.7223-1-m.felsch@pengutronix.de> References: <20191127135932.7223-1-m.felsch@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sometimes consumers needs to know the gpio-chip local gpio number of a 'struct gpio_desc' for further configuration. This is often the case for mfd devices. Signed-off-by: Marco Felsch --- drivers/gpio/gpiolib.c | 6 ++++++ include/linux/gpio/consumer.h | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 104ed299d5ea..7709648313fc 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -4377,6 +4377,12 @@ int gpiod_count(struct device *dev, const char *con_id) } EXPORT_SYMBOL_GPL(gpiod_count); +int gpiod_to_offset(struct gpio_desc *desc) +{ + return gpio_chip_hwgpio(desc); +} +EXPORT_SYMBOL_GPL(gpiod_to_offset); + /** * gpiod_get - obtain a GPIO for a given GPIO function * @dev: GPIO consumer, can be NULL for system-global GPIOs diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index b70af921c614..e2178c3bf7fd 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h @@ -60,6 +60,9 @@ enum gpiod_flags { /* Return the number of GPIOs associated with a device / function */ int gpiod_count(struct device *dev, const char *con_id); +/* Get the local chip offset from a global desc */ +int gpiod_to_offset(struct gpio_desc *desc); + /* Acquire and dispose GPIOs */ struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id, @@ -189,6 +192,13 @@ static inline int gpiod_count(struct device *dev, const char *con_id) return 0; } +static inline int gpiod_to_offset(struct gpio_desc *desc) +{ + /* GPIO can never have been requested */ + WARN_ON(desc); + return 0; +} + static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id, enum gpiod_flags flags) -- 2.20.1