linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
To: michael@walle.cc, linus.walleij@linaro.org, brgl@bgdev.pl
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] gpio: regmap: Support combined GPIO and pin control drivers
Date: Sun,  3 Jul 2022 12:10:56 +0100	[thread overview]
Message-ID: <20220703111057.23246-3-aidanmacdonald.0x0@gmail.com> (raw)
In-Reply-To: <20220703111057.23246-1-aidanmacdonald.0x0@gmail.com>

Allow gpio-regmap to be used for the GPIO portion of a combined
pin control and GPIO driver by setting the has_pinctrl flag. This
flag will cause GPIO direction set ops to be implemented as calls
to pinctrl_gpio_direction_input/output() instead of updating the
direction set registers directly.

Note that reg_dir_out/in_base is still required for implementing
the GPIO chip's ->get_direction() callback.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
 drivers/gpio/gpio-regmap.c  | 20 ++++++++++++++++++++
 include/linux/gpio/regmap.h |  6 ++++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index 9256b922c654..4bc01329fb14 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -24,6 +24,8 @@ struct gpio_regmap {
 	unsigned int reg_dir_in_base;
 	unsigned int reg_dir_out_base;
 
+	unsigned int has_pinctrl:1;
+
 	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
 			      unsigned int offset, unsigned int *reg,
 			      unsigned int *mask);
@@ -170,14 +172,24 @@ static int gpio_regmap_set_direction(struct gpio_chip *chip,
 static int gpio_regmap_direction_input(struct gpio_chip *chip,
 				       unsigned int offset)
 {
+	struct gpio_regmap *gpio = gpiochip_get_data(chip);
+
+	if (gpio->has_pinctrl)
+		return pinctrl_gpio_direction_input(chip->base + offset);
+
 	return gpio_regmap_set_direction(chip, offset, false);
 }
 
 static int gpio_regmap_direction_output(struct gpio_chip *chip,
 					unsigned int offset, int value)
 {
+	struct gpio_regmap *gpio = gpiochip_get_data(chip);
+
 	gpio_regmap_set(chip, offset, value);
 
+	if (gpio->has_pinctrl)
+		return pinctrl_gpio_direction_output(chip->base + offset);
+
 	return gpio_regmap_set_direction(chip, offset, true);
 }
 
@@ -218,6 +230,14 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
 	if (config->reg_dir_out_base && config->reg_dir_in_base)
 		return ERR_PTR(-EINVAL);
 
+	/*
+	 * we need a direction register for implementing ->get_direction
+	 * even if ->direction_input/output is handled by pin control
+	 */
+	if (config->has_pinctrl && !(config->reg_dir_in_base ||
+				     config->reg_dir_out_base))
+		return ERR_PTR(-EINVAL);
+
 	/* only one of these should be provided */
 	if (config->reg_field_xlate && config->reg_mask_xlate)
 		return ERR_PTR(-EINVAL);
diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
index a673dbfe88a3..47acea8cca32 100644
--- a/include/linux/gpio/regmap.h
+++ b/include/linux/gpio/regmap.h
@@ -33,6 +33,10 @@ struct regmap;
  * @ngpio_per_reg:	Number of GPIOs per register
  * @irq_domain:		(Optional) IRQ domain if the controller is
  *			interrupt-capable
+ * @has_pinctrl:	If set, the GPIO chip is part of a combined pin control
+ *			and GPIO driver; use pinctrl_gpio_direction_input() and
+ *			pinctrl_gpio_direction_output() to implement direction
+ *			set operations.
  * @reg_mask_xlate:     (Optional) Translates base address and GPIO
  *			offset to a register/bitmask pair. If not
  *			given the default gpio_regmap_simple_xlate()
@@ -88,6 +92,8 @@ struct gpio_regmap_config {
 	int ngpio_per_reg;
 	struct irq_domain *irq_domain;
 
+	unsigned int has_pinctrl:1;
+
 	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
 			      unsigned int offset, unsigned int *reg,
 			      unsigned int *mask);
-- 
2.35.1


  parent reply	other threads:[~2022-07-03 11:10 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-03 11:10 [PATCH 0/3] gpio-regmap support for register fields and other hooks Aidan MacDonald
2022-07-03 11:10 ` [PATCH 1/3] gpio: regmap: Support registers with more than one bit per GPIO Aidan MacDonald
2022-07-03 14:09   ` Andy Shevchenko
2022-07-04 16:03     ` Aidan MacDonald
2022-07-04 12:28   ` Michael Walle
2022-07-04 16:01     ` Aidan MacDonald
2022-07-04 19:46       ` Michael Walle
2022-07-06 20:46         ` Aidan MacDonald
2022-07-07  7:44           ` Michael Walle
2022-07-07 14:58             ` Aidan MacDonald
2022-07-03 11:10 ` Aidan MacDonald [this message]
2022-07-03 14:14   ` [PATCH 2/3] gpio: regmap: Support combined GPIO and pin control drivers Andy Shevchenko
2022-07-04 15:31     ` Aidan MacDonald
2022-07-03 11:10 ` [PATCH 3/3] gpio: regmap: Support a custom ->to_irq() hook Aidan MacDonald
2022-07-03 14:24   ` Andy Shevchenko
2022-07-04 16:38     ` Aidan MacDonald
2022-07-04 23:05   ` Linus Walleij
2022-07-05 11:09     ` Aidan MacDonald
2022-07-06 11:45       ` Andy Shevchenko
2022-07-06 20:53         ` Aidan MacDonald
2022-07-06 12:02       ` Linus Walleij
2022-07-06 13:50         ` Aidan MacDonald
2022-07-11 11:48           ` Linus Walleij

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=20220703111057.23246-3-aidanmacdonald.0x0@gmail.com \
    --to=aidanmacdonald.0x0@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@walle.cc \
    /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).