From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: [PATCH v2 02/62] pinctrl: provide new GPIO-to-pinctrl glue helpers
Date: Wed, 11 Oct 2023 14:07:30 +0200 [thread overview]
Message-ID: <20231011120830.49324-3-brgl@bgdev.pl> (raw)
In-Reply-To: <20231011120830.49324-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Currently the pinctrl GPIO helpers all take a number from the global
GPIO numberspace - of which we're trying to get rid of as argument.
These helpers are almost universally called from GPIOLIB driver
callbacks which take a pointer to the backing gpio_chip and the
controller-relative offset as arguments.
Let's provide improved variants of these functions that match the
GPIOLIB signatures as the first step in removing the older flavor.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/pinctrl/core.c | 108 ++++++++++++++++++++++---------
include/linux/pinctrl/consumer.h | 46 +++++++++++++
2 files changed, 125 insertions(+), 29 deletions(-)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 2bf95d8f30cc..13a6fa85c462 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -23,6 +23,8 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
+#include <linux/gpio/driver.h>
+
#include <linux/pinctrl/consumer.h>
#include <linux/pinctrl/devinfo.h>
#include <linux/pinctrl/machine.h>
@@ -781,14 +783,13 @@ bool pinctrl_gpio_can_use_line(unsigned gpio)
}
EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line);
-/**
- * pinctrl_gpio_request() - request a single pin to be used as GPIO
- * @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_request() semantics, platforms and individual drivers
- * shall *NOT* request GPIO pins to be muxed in.
- */
+bool pinctrl_gpio_can_use_line_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return pinctrl_gpio_can_use_line(gc->base + offset);
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line_new);
+
+/* This function is deprecated and will be removed. Don't use. */
int pinctrl_gpio_request(unsigned gpio)
{
struct pinctrl_dev *pctldev;
@@ -817,13 +818,21 @@ int pinctrl_gpio_request(unsigned gpio)
EXPORT_SYMBOL_GPL(pinctrl_gpio_request);
/**
- * pinctrl_gpio_free() - free control on a single pin, currently used as GPIO
- * @gpio: the GPIO pin number from the GPIO subsystem number space
+ * pinctrl_gpio_request_new() - request a single pin to be used as GPIO
+ * @gc: GPIO chip structure from the GPIO subsystem
+ * @offset: hardware offset of the GPIO relative to the controller
*
* This function should *ONLY* be used from gpiolib-based GPIO drivers,
- * as part of their gpio_free() semantics, platforms and individual drivers
- * shall *NOT* request GPIO pins to be muxed out.
+ * as part of their gpio_request() semantics, platforms and individual drivers
+ * shall *NOT* request GPIO pins to be muxed in.
*/
+int pinctrl_gpio_request_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return pinctrl_gpio_request(gc->base + offset);
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_request_new);
+
+/* This function is deprecated and will be removed. Don't use. */
void pinctrl_gpio_free(unsigned gpio)
{
struct pinctrl_dev *pctldev;
@@ -846,6 +855,21 @@ void pinctrl_gpio_free(unsigned gpio)
}
EXPORT_SYMBOL_GPL(pinctrl_gpio_free);
+/**
+ * pinctrl_gpio_free_new() - free control on a single pin, currently used as GPIO
+ * @gc: GPIO chip structure from the GPIO subsystem
+ * @offset: hardware offset of the GPIO relative to the controller
+ *
+ * This function should *ONLY* be used from gpiolib-based GPIO drivers,
+ * as part of their gpio_request() semantics, platforms and individual drivers
+ * shall *NOT* request GPIO pins to be muxed in.
+ */
+void pinctrl_gpio_free_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return pinctrl_gpio_free(gc->base + offset);
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_free_new);
+
static int pinctrl_gpio_direction(unsigned gpio, bool input)
{
struct pinctrl_dev *pctldev;
@@ -869,14 +893,7 @@ static int pinctrl_gpio_direction(unsigned gpio, bool input)
return ret;
}
-/**
- * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
- * @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_direction_input() semantics, platforms and individual
- * drivers shall *NOT* touch pin control GPIO calls.
- */
+/* This function is deprecated and will be removed. Don't use. */
int pinctrl_gpio_direction_input(unsigned gpio)
{
return pinctrl_gpio_direction(gpio, true);
@@ -884,13 +901,21 @@ int pinctrl_gpio_direction_input(unsigned gpio)
EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
/**
- * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
- * @gpio: the GPIO pin number from the GPIO subsystem number space
+ * pinctrl_gpio_direction_input_new() - request a GPIO pin to go into input mode
+ * @gc: GPIO chip structure from the GPIO subsystem
+ * @offset: hardware offset of the GPIO relative to the controller
*
* This function should *ONLY* be used from gpiolib-based GPIO drivers,
- * as part of their gpio_direction_output() semantics, platforms and individual
+ * as part of their gpio_direction_input() semantics, platforms and individual
* drivers shall *NOT* touch pin control GPIO calls.
*/
+int pinctrl_gpio_direction_input_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return pinctrl_gpio_direction_input(gc->base + offset);
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input_new);
+
+/* This function is deprecated and will be removed. Don't use. */
int pinctrl_gpio_direction_output(unsigned gpio)
{
return pinctrl_gpio_direction(gpio, false);
@@ -898,14 +923,22 @@ int pinctrl_gpio_direction_output(unsigned gpio)
EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
/**
- * 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
+ * pinctrl_gpio_direction_output_new() - request a GPIO pin to go into output
+ * mode
+ * @gc: GPIO chip structure from the GPIO subsystem
+ * @offset: hardware offset of the GPIO relative to the controller
*
- * This function should *ONLY* be used from gpiolib-based GPIO drivers, if
- * they need to call the underlying pin controller to change GPIO config
- * (for example set debounce time).
+ * This function should *ONLY* be used from gpiolib-based GPIO drivers,
+ * as part of their gpio_direction_output() semantics, platforms and individual
+ * drivers shall *NOT* touch pin control GPIO calls.
*/
+int pinctrl_gpio_direction_output_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return pinctrl_gpio_direction_output(gc->base + offset);
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output_new);
+
+/* This function is deprecated and will be removed. Don't use. */
int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
{
unsigned long configs[] = { config };
@@ -926,6 +959,23 @@ int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
}
EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config);
+/**
+ * pinctrl_gpio_set_config_new() - Apply config to given GPIO pin
+ * @gc: GPIO chip structure from the GPIO subsystem
+ * @offset: hardware offset of the GPIO relative to the controller
+ * @config: the configuration to apply to the GPIO
+ *
+ * This function should *ONLY* be used from gpiolib-based GPIO drivers, if
+ * they need to call the underlying pin controller to change GPIO config
+ * (for example set debounce time).
+ */
+int pinctrl_gpio_set_config_new(struct gpio_chip *gc, unsigned int offset,
+ unsigned long config)
+{
+ return pinctrl_gpio_set_config(gc->base + offset, config);
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config_new);
+
static struct pinctrl_state *find_state(struct pinctrl *p,
const char *name)
{
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
index 22eef0a513ce..c95c13983376 100644
--- a/include/linux/pinctrl/consumer.h
+++ b/include/linux/pinctrl/consumer.h
@@ -17,6 +17,7 @@
#include <linux/pinctrl/pinctrl-state.h>
struct device;
+struct gpio_chip;
/* This struct is private to the core and should be regarded as a cookie */
struct pinctrl;
@@ -26,11 +27,20 @@ struct pinctrl_state;
/* External interface to pin control */
bool pinctrl_gpio_can_use_line(unsigned gpio);
+bool pinctrl_gpio_can_use_line_new(struct gpio_chip *gc, unsigned int offset);
int pinctrl_gpio_request(unsigned gpio);
+int pinctrl_gpio_request_new(struct gpio_chip *gc, unsigned int offset);
void pinctrl_gpio_free(unsigned gpio);
+void pinctrl_gpio_free_new(struct gpio_chip *gc, unsigned int offset);
int pinctrl_gpio_direction_input(unsigned gpio);
+int pinctrl_gpio_direction_input_new(struct gpio_chip *gc,
+ unsigned int offset);
int pinctrl_gpio_direction_output(unsigned gpio);
+int pinctrl_gpio_direction_output_new(struct gpio_chip *gc,
+ unsigned int offset);
int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
+int pinctrl_gpio_set_config_new(struct gpio_chip *gc, unsigned int offset,
+ unsigned long config);
struct pinctrl * __must_check pinctrl_get(struct device *dev);
void pinctrl_put(struct pinctrl *p);
@@ -68,30 +78,66 @@ static inline bool pinctrl_gpio_can_use_line(unsigned gpio)
return true;
}
+static inline bool
+pinctrl_gpio_can_use_line_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return true;
+}
+
static inline int pinctrl_gpio_request(unsigned gpio)
{
return 0;
}
+static inline int
+pinctrl_gpio_request_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return 0;
+}
+
static inline void pinctrl_gpio_free(unsigned gpio)
{
}
+static inline void
+pinctrl_gpio_free_new(struct gpio_chip *gc, unsigned int offset)
+{
+}
+
static inline int pinctrl_gpio_direction_input(unsigned gpio)
{
return 0;
}
+static inline int
+pinctrl_gpio_direction_input_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return 0;
+}
+
static inline int pinctrl_gpio_direction_output(unsigned gpio)
{
return 0;
}
+static inline int
+pinctrl_gpio_direction_output_new(struct gpio_chip *gc, unsigned int offset)
+{
+ return 0;
+}
+
static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
{
return 0;
}
+static inline int
+pinctrl_gpio_set_config_new(struct gpio_chip *gc, unsigned int offset,
+ unsigned long config)
+{
+ return 0;
+}
+
static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
{
return NULL;
--
2.39.2
next prev parent reply other threads:[~2023-10-11 12:09 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 12:07 [PATCH v2 00/62] pinctrl: don't use GPIOLIB global numberspace in helpers Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 01/62] pinctrl: remove unneeded extern specifiers from consumer.h Bartosz Golaszewski
2023-10-11 16:44 ` Andy Shevchenko
2023-10-11 12:07 ` Bartosz Golaszewski [this message]
2023-10-11 12:07 ` [PATCH v2 03/62] gpiolib: generic: use new pinctrl GPIO helpers Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 04/62] gpio: cdev: use pinctrl_gpio_can_use_line_new() Bartosz Golaszewski
2023-10-11 16:58 ` Andy Shevchenko
2023-10-11 12:07 ` [PATCH v2 05/62] gpio: rcar: use new pinctrl GPIO helpers Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 06/62] gpio: tegra: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 07/62] gpio: em: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 08/62] gpio: aspeed: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 09/62] gpio: mvebu: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 10/62] gpio: pxa: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 11/62] gpio: rockchip: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 12/62] gpio: vf610: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 13/62] pinctrl: nuvoton: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 14/62] pinctrl: renesas: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 15/62] pinctrl: bcm: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 16/62] pinctrl: stm32: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 17/62] pinctrl: spear: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 18/62] pinctrl: starfive: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 19/62] pinctrl: ocelot: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 20/62] pinctrl: rk805: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 21/62] pinctrl: cirrus: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 22/62] pinctrl: mediatek: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 23/62] pinctrl: axp209: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 24/62] pinctrl: vt8500: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 25/62] pinctrl: cy8c95x0: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 26/62] pinctrl: as3722: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 27/62] pinctrl: ingenic: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 28/62] pinctrl: intel: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 29/62] pinctrl: st: " Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 30/62] pinctrl: remove pinctrl_gpio_can_use_line() Bartosz Golaszewski
2023-10-11 12:07 ` [PATCH v2 31/62] pinctrl: remove pinctrl_gpio_request() Bartosz Golaszewski
2023-10-11 16:54 ` Andy Shevchenko
2023-10-12 19:43 ` Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 32/62] pinctrl: remove pinctrl_gpio_free() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 33/62] pinctrl: remove pinctrl_gpio_direction_input() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 34/62] pinctrl: remove pinctrl_gpio_direction_output() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 35/62] pinctrl: remove pinctrl_gpio_set_config() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 36/62] treewide: rename pinctrl_gpio_can_use_line_new() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 37/62] treewide: rename pinctrl_gpio_request_new() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 38/62] treewide: rename pinctrl_gpio_free_new() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 39/62] treewide: rename pinctrl_gpio_direction_input_new() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 40/62] treewide: rename pinctrl_gpio_direction_output_new() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 41/62] treewide: rename pinctrl_gpio_set_config_new() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 42/62] pinctrl: change the signature of pinctrl_gpio_direction() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 43/62] pinctrl: change the signature of pinctrl_get_device_gpio_range() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 44/62] pinctrl: change the signature of pinctrl_match_gpio_range() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 45/62] pinctrl: change the signature of gpio_to_pin() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 46/62] pinctrl: change the signature of pinctrl_ready_for_gpio_range() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 47/62] pinctrl: intel: drop the wrappers around pinctrl_gpio_direction_input() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 48/62] pinctrl: st: drop the wrapper " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 49/62] pinctrl: ingenic: " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 50/62] pinctrl: as3722: " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 51/62] pinctrl: cy8c95x0: " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 52/62] pinctrl: vt8500: " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 53/62] pinctrl: axp209: " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 54/62] pinctrl: rk805: " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 55/62] pinctrl: mediatek: drop the wrappers " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 56/62] pinctrl: cirrus: drop the wrapper " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 57/62] pinctrl: ocelot: " Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 58/62] pinctrl: starfive: drop wrappers around pinctrl_gpio_request/free() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 59/62] pinctrl: stm32: drop wrappers around pinctrl_gpio_free/input() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 60/62] pinctrl: nuvoton: drop wrappers around pinctrl_gpio_request/free() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 61/62] pinctrl: em: drop the wrapper around pinctrl_gpio_request() Bartosz Golaszewski
2023-10-11 12:08 ` [PATCH v2 62/62] pinctrl: tegra: " Bartosz Golaszewski
2023-10-11 17:04 ` [PATCH v2 00/62] pinctrl: don't use GPIOLIB global numberspace in helpers Andy Shevchenko
2023-10-12 7:08 ` Linus Walleij
2023-10-12 13:23 ` Bartosz Golaszewski
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=20231011120830.49324-3-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--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;
as well as URLs for NNTP newsgroup(s).