devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marco Felsch <m.felsch@pengutronix.de>
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	[thread overview]
Message-ID: <20191127135932.7223-2-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20191127135932.7223-1-m.felsch@pengutronix.de>

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 <m.felsch@pengutronix.de>
---
 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


  reply	other threads:[~2019-11-27 13:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 13:59 [PATCH v2 0/5] DA9062 PMIC features Marco Felsch
2019-11-27 13:59 ` Marco Felsch [this message]
2019-11-28 10:46   ` [PATCH v2 1/5] gpio: add support to get local gpio number Bartosz Golaszewski
2019-11-28 12:49     ` Marco Felsch
2019-11-29  7:45       ` Uwe Kleine-König
2019-11-29  7:50         ` Marco Felsch
2019-11-29  9:32   ` Linus Walleij
2019-11-29 10:15     ` Marco Felsch
2019-11-29 10:19       ` Linus Walleij
2019-11-29 11:36         ` Marco Felsch
2019-11-29 12:46           ` Linus Walleij
2019-11-27 13:59 ` [PATCH v2 2/5] dt-bindings: mfd: da9062: add regulator voltage selection documentation Marco Felsch
2019-11-27 13:59 ` [PATCH v2 3/5] regulator: da9062: add voltage selection gpio support Marco Felsch
2019-11-29  8:29   ` Linus Walleij
2019-11-27 13:59 ` [PATCH v2 4/5] dt-bindings: mfd: da9062: add regulator gpio enable/disable documentation Marco Felsch
2019-11-29  8:33   ` Linus Walleij
2019-11-27 13:59 ` [PATCH v2 5/5] regulator: da9062: add gpio based regulator dis-/enable support Marco Felsch
2019-11-29  8:25   ` Linus Walleij
2019-11-29  9:11     ` Marco Felsch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191127135932.7223-2-m.felsch@pengutronix.de \
    --to=m.felsch@pengutronix.de \
    --cc=Adam.Thomson.Opensource@diasemi.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=stwiss.opensource@diasemi.com \
    --cc=support.opensource@diasemi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).