From: Paul Cercueil <paul@crapouillou.net>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Paul Cercueil <paul@crapouillou.net>
Subject: [PATCH 2/5] pinctrl: Add API function pinctrl_gpio_get_direction
Date: Wed, 27 Jun 2018 13:49:01 +0200 [thread overview]
Message-ID: <20180627114904.10890-3-paul@crapouillou.net> (raw)
In-Reply-To: <20180627114904.10890-1-paul@crapouillou.net>
This function can be used to retrieve the direction (input/output) of a
given GPIO.
It should *ONLY* be used from gpiolib-based GPIO drivers, as part of their
gpio_get_direction() semantics, platforms and individual drivers shall
*NOT* touch pin control GPIO calls.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
drivers/pinctrl/core.c | 31 +++++++++++++++++++++++++++++++
include/linux/pinctrl/consumer.h | 1 +
2 files changed, 32 insertions(+)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index e5a303002021..7fee8347fb51 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -849,6 +849,37 @@ int pinctrl_gpio_direction_output(unsigned gpio)
EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
/**
+ * pinctrl_gpio_get_direction() - Get the direction (input/output) of a GPIO pin
+ * @gpio: the GPIO pin number from the GPIO subsystem number space
+ *
+ * This function should *ONLY* be used from gpiolib-based GPIO drivers,
+ * as part of their gpio_get_direction() semantics, platforms and individual
+ * drivers shall *NOT* touch pin control GPIO calls.
+ */
+int pinctrl_gpio_get_direction(unsigned int gpio)
+{
+ struct pinctrl_dev *pctldev;
+ struct pinctrl_gpio_range *range;
+ int ret;
+ int pin;
+
+ ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
+ if (ret)
+ return ret;
+
+ mutex_lock(&pctldev->mutex);
+
+ /* Convert to the pin controllers number space */
+ pin = gpio_to_pin(range, gpio);
+ ret = pinmux_gpio_get_direction(pctldev, range, pin);
+
+ mutex_unlock(&pctldev->mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_get_direction);
+
+/**
* pinctrl_gpio_set_config() - Apply config to given GPIO pin
* @gpio: the GPIO pin number from the GPIO subsystem number space
* @config: the configuration to apply to the GPIO
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
index 0412cc9833e9..5f945c329f1c 100644
--- a/include/linux/pinctrl/consumer.h
+++ b/include/linux/pinctrl/consumer.h
@@ -29,6 +29,7 @@ extern int pinctrl_gpio_request(unsigned gpio);
extern void pinctrl_gpio_free(unsigned gpio);
extern int pinctrl_gpio_direction_input(unsigned gpio);
extern int pinctrl_gpio_direction_output(unsigned gpio);
+extern int pinctrl_gpio_get_direction(unsigned gpio);
extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
--
2.11.0
next prev parent reply other threads:[~2018-06-27 11:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-27 11:48 [PATCH 0/5] pinctrl_gpio_get_direction & ingenic fixes Paul Cercueil
2018-06-27 11:49 ` [PATCH 1/5] pinctrl: Add core function pinmux_gpio_get_direction Paul Cercueil
2018-06-27 11:49 ` Paul Cercueil [this message]
2018-06-27 14:07 ` [PATCH 2/5] pinctrl: Add API function pinctrl_gpio_get_direction kbuild test robot
2018-06-27 15:24 ` kbuild test robot
2018-06-27 11:49 ` [PATCH 3/5] pinctrl: ingenic: Fix inverted direction for < JZ4770 Paul Cercueil
2018-07-09 11:58 ` Linus Walleij
2018-06-27 11:49 ` [PATCH 4/5] pinctrl: ingenic: Implement pinmux callback .gpio_get_direction Paul Cercueil
2018-06-27 11:49 ` [PATCH 5/5] GPIO: ingenic: Implement .get_direction Paul Cercueil
2018-06-27 17:18 ` [PATCH 0/5] pinctrl_gpio_get_direction & ingenic fixes Andy Shevchenko
2018-06-28 19:11 ` Paul Cercueil
2018-06-29 15:29 ` Andy Shevchenko
2018-07-09 12:18 ` Linus Walleij
2018-07-09 12:09 ` Linus Walleij
2018-07-11 23:22 ` Paul Cercueil
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=20180627114904.10890-3-paul@crapouillou.net \
--to=paul@crapouillou.net \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®