linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support
@ 2021-01-08 10:20 Geert Uytterhoeven
  2021-01-08 10:20 ` [PATCH v3 1/3] dt-bindings: gpio: rcar: Add r8a779a0 support Geert Uytterhoeven
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-08 10:20 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring
  Cc: linux-gpio, linux-renesas-soc, devicetree, Geert Uytterhoeven

	Hi Linus, Bartosz, Rob,

This patch series adds support for GPIOs on the R-Car V3U (r8a779a0)
SoC, to both DT bindings and the gpio-rcar driver.

Changes compared to v2:
  - Add Reviewed-by, Tested-by,
  - Fix SoC part number in oneline summary,
  - Reformat comment block to match coding style,
  - Rebase on top of commit 3a57026a83ba363e ("gpio: rcar: Remove
    redundant compatible values"),

Changes compared to v1:
  - Optimize GPIO pin state read on R-Car Gen3,
  - Enable input unconditionally in probe and resume, instead of during
    GPIO line configuration and depending on GPIO line direction,
  - Assumed authorship, as this patch is very different from v1, written
    by Phong Hoang,
  - Add Reviewed-by.

Thanks!

Geert Uytterhoeven (3):
  dt-bindings: gpio: rcar: Add r8a779a0 support
  gpio: rcar: Optimize GPIO pin state read on R-Car Gen3
  gpio: rcar: Add R-Car V3U (R8A779A0) support

 .../bindings/gpio/renesas,rcar-gpio.yaml      |  3 +
 drivers/gpio/gpio-rcar.c                      | 60 +++++++++++++++++--
 2 files changed, 58 insertions(+), 5 deletions(-)

-- 
2.25.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/3] dt-bindings: gpio: rcar: Add r8a779a0 support
  2021-01-08 10:20 [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Geert Uytterhoeven
@ 2021-01-08 10:20 ` Geert Uytterhoeven
  2021-01-08 10:20 ` [PATCH v3 2/3] gpio: rcar: Optimize GPIO pin state read on R-Car Gen3 Geert Uytterhoeven
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-08 10:20 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring
  Cc: linux-gpio, linux-renesas-soc, devicetree, Geert Uytterhoeven,
	Wolfram Sang

Document the compatible value for the GPIO block in the Renesas R-Car
V3U (R8A779A0) SoC.

While this GPIO block is mostly compatible with GPIO blocks on R-Car
Gen3 SoCs, there are small differences, and one of the new registers
needs to be configured differently from its initial reset state.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
v3:
  - No changes,

v2:
  - Add Reviewed-by.
---
 Documentation/devicetree/bindings/gpio/renesas,rcar-gpio.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/gpio/renesas,rcar-gpio.yaml b/Documentation/devicetree/bindings/gpio/renesas,rcar-gpio.yaml
index 5026662e45081b6c..f2541739ee3b9f7c 100644
--- a/Documentation/devicetree/bindings/gpio/renesas,rcar-gpio.yaml
+++ b/Documentation/devicetree/bindings/gpio/renesas,rcar-gpio.yaml
@@ -48,6 +48,9 @@ properties:
               - renesas,gpio-r8a77995     # R-Car D3
           - const: renesas,rcar-gen3-gpio # R-Car Gen3 or RZ/G2
 
+      - items:
+          - const: renesas,gpio-r8a779a0  # R-Car V3U
+
   reg:
     maxItems: 1
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/3] gpio: rcar: Optimize GPIO pin state read on R-Car Gen3
  2021-01-08 10:20 [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Geert Uytterhoeven
  2021-01-08 10:20 ` [PATCH v3 1/3] dt-bindings: gpio: rcar: Add r8a779a0 support Geert Uytterhoeven
@ 2021-01-08 10:20 ` Geert Uytterhoeven
  2021-01-08 10:20 ` [PATCH v3 3/3] gpio: rcar: Add R-Car V3U (R8A779A0) support Geert Uytterhoeven
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-08 10:20 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring
  Cc: linux-gpio, linux-renesas-soc, devicetree, Geert Uytterhoeven,
	Yoshihiro Shimoda, Wolfram Sang

Currently, the R-Car GPIO driver treats R-Car Gen2 and R-Car Gen3 GPIO
controllers the same.  However, there exist small differences, like the
behavior of the General Input Register (INDT):
  - On R-Car Gen1, R-Car Gen2, and RZ/G1, INDT only reflects the state
    of an input pin if the GPIO is configured for input,
  - On R-Car Gen3 and RZ/G2, INDT always reflects the state of the input
    pins.
Hence to accommodate all variants, the driver does not use the INDT
register to read the status of a GPIO line when configured for output,
at the expense of doing 2 or 3 register reads instead of 1.

Given register accesses are slow, change the .get() and .get_multiple()
callbacks to always use INDT to read pin state on SoCs where this is
supported.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
v3:
  - Add Reviewed-by, Tested-by,
  - Reformat comment block to match coding style,
  - Rebase on top of commit 3a57026a83ba363e ("gpio: rcar: Remove
    redundant compatible values"),

v2:
  - New.
---
 drivers/gpio/gpio-rcar.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index f3b8c4b44cabdfd2..edded6478792f7b8 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -35,6 +35,7 @@ struct gpio_rcar_bank_info {
 struct gpio_rcar_info {
 	bool has_outdtsel;
 	bool has_both_edge_trigger;
+	bool has_always_in;
 };
 
 struct gpio_rcar_priv {
@@ -302,9 +303,11 @@ static int gpio_rcar_get(struct gpio_chip *chip, unsigned offset)
 	struct gpio_rcar_priv *p = gpiochip_get_data(chip);
 	u32 bit = BIT(offset);
 
-	/* testing on r8a7790 shows that INDT does not show correct pin state
-	 * when configured as output, so use OUTDT in case of output pins */
-	if (gpio_rcar_read(p, INOUTSEL) & bit)
+	/*
+	 * Before R-Car Gen3, INDT does not show correct pin state when
+	 * configured as output, so use OUTDT in case of output pins
+	 */
+	if (!p->info.has_always_in && (gpio_rcar_read(p, INOUTSEL) & bit))
 		return !!(gpio_rcar_read(p, OUTDT) & bit);
 	else
 		return !!(gpio_rcar_read(p, INDT) & bit);
@@ -324,6 +327,11 @@ static int gpio_rcar_get_multiple(struct gpio_chip *chip, unsigned long *mask,
 	if (!bankmask)
 		return 0;
 
+	if (p->info.has_always_in) {
+		bits[0] = gpio_rcar_read(p, INDT) & bankmask;
+		return 0;
+	}
+
 	spin_lock_irqsave(&p->lock, flags);
 	outputs = gpio_rcar_read(p, INOUTSEL);
 	m = outputs & bankmask;
@@ -383,11 +391,19 @@ static int gpio_rcar_direction_output(struct gpio_chip *chip, unsigned offset,
 static const struct gpio_rcar_info gpio_rcar_info_gen1 = {
 	.has_outdtsel = false,
 	.has_both_edge_trigger = false,
+	.has_always_in = false,
 };
 
 static const struct gpio_rcar_info gpio_rcar_info_gen2 = {
 	.has_outdtsel = true,
 	.has_both_edge_trigger = true,
+	.has_always_in = false,
+};
+
+static const struct gpio_rcar_info gpio_rcar_info_gen3 = {
+	.has_outdtsel = true,
+	.has_both_edge_trigger = true,
+	.has_always_in = true,
 };
 
 static const struct of_device_id gpio_rcar_of_table[] = {
@@ -399,8 +415,7 @@ static const struct of_device_id gpio_rcar_of_table[] = {
 		.data = &gpio_rcar_info_gen2,
 	}, {
 		.compatible = "renesas,rcar-gen3-gpio",
-		/* Gen3 GPIO is identical to Gen2. */
-		.data = &gpio_rcar_info_gen2,
+		.data = &gpio_rcar_info_gen3,
 	}, {
 		.compatible = "renesas,gpio-rcar",
 		.data = &gpio_rcar_info_gen1,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 3/3] gpio: rcar: Add R-Car V3U (R8A779A0) support
  2021-01-08 10:20 [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Geert Uytterhoeven
  2021-01-08 10:20 ` [PATCH v3 1/3] dt-bindings: gpio: rcar: Add r8a779a0 support Geert Uytterhoeven
  2021-01-08 10:20 ` [PATCH v3 2/3] gpio: rcar: Optimize GPIO pin state read on R-Car Gen3 Geert Uytterhoeven
@ 2021-01-08 10:20 ` Geert Uytterhoeven
  2021-01-09  0:29 ` [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Linus Walleij
  2021-01-11 10:09 ` Bartosz Golaszewski
  4 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-08 10:20 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring
  Cc: linux-gpio, linux-renesas-soc, devicetree, Geert Uytterhoeven,
	Yoshihiro Shimoda, Wolfram Sang

Add support for the GPIO controller block in the R-Car V3U (R8A779A0)
SoC, which is very similar to the block found on other R-Car Gen3 SoCs.
However, this block has a new General Input Enable Register (INEN),
whose reset state is to have all inputs disabled.

Enable input for all available pins in probe and resume, to support the
use of the General Input Register (INDT) for reading pin state at all
times.  This preserves backwards compatibility with other R-Car Gen3
SoCs, as recommended by the Hardware Manual.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
v3:
  - Add Reviewed-by, Tested-by,
  - Fix SoC part number in oneline summary,
  - Rebase on top of commit 3a57026a83ba363e ("gpio: rcar: Remove
    redundant compatible values"),

v2:
  - Enable input unconditionally in probe and resume, instead of during
    GPIO line configuration and depending on GPIO line direction,
  - Assumed authorship, as this patch is very different from v1, written
    by Phong Hoang.
---
 drivers/gpio/gpio-rcar.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index edded6478792f7b8..e7092d5fe700d2ce 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -36,6 +36,7 @@ struct gpio_rcar_info {
 	bool has_outdtsel;
 	bool has_both_edge_trigger;
 	bool has_always_in;
+	bool has_inen;
 };
 
 struct gpio_rcar_priv {
@@ -63,6 +64,7 @@ struct gpio_rcar_priv {
 #define FILONOFF	0x28	/* Chattering Prevention On/Off Register */
 #define OUTDTSEL	0x40	/* Output Data Select Register */
 #define BOTHEDGE	0x4c	/* One Edge/Both Edge Select Register */
+#define INEN		0x50	/* General Input Enable Register */
 
 #define RCAR_MAX_GPIO_PER_BANK		32
 
@@ -392,22 +394,35 @@ static const struct gpio_rcar_info gpio_rcar_info_gen1 = {
 	.has_outdtsel = false,
 	.has_both_edge_trigger = false,
 	.has_always_in = false,
+	.has_inen = false,
 };
 
 static const struct gpio_rcar_info gpio_rcar_info_gen2 = {
 	.has_outdtsel = true,
 	.has_both_edge_trigger = true,
 	.has_always_in = false,
+	.has_inen = false,
 };
 
 static const struct gpio_rcar_info gpio_rcar_info_gen3 = {
 	.has_outdtsel = true,
 	.has_both_edge_trigger = true,
 	.has_always_in = true,
+	.has_inen = false,
+};
+
+static const struct gpio_rcar_info gpio_rcar_info_v3u = {
+	.has_outdtsel = true,
+	.has_both_edge_trigger = true,
+	.has_always_in = true,
+	.has_inen = true,
 };
 
 static const struct of_device_id gpio_rcar_of_table[] = {
 	{
+		.compatible = "renesas,gpio-r8a779a0",
+		.data = &gpio_rcar_info_v3u,
+	}, {
 		.compatible = "renesas,rcar-gen1-gpio",
 		.data = &gpio_rcar_info_gen1,
 	}, {
@@ -448,6 +463,17 @@ static int gpio_rcar_parse_dt(struct gpio_rcar_priv *p, unsigned int *npins)
 	return 0;
 }
 
+static void gpio_rcar_enable_inputs(struct gpio_rcar_priv *p)
+{
+	u32 mask = GENMASK(p->gpio_chip.ngpio - 1, 0);
+
+	/* Select "Input Enable" in INEN */
+	if (p->gpio_chip.valid_mask)
+		mask &= p->gpio_chip.valid_mask[0];
+	if (mask)
+		gpio_rcar_write(p, INEN, gpio_rcar_read(p, INEN) | mask);
+}
+
 static int gpio_rcar_probe(struct platform_device *pdev)
 {
 	struct gpio_rcar_priv *p;
@@ -537,6 +563,12 @@ static int gpio_rcar_probe(struct platform_device *pdev)
 		goto err1;
 	}
 
+	if (p->info.has_inen) {
+		pm_runtime_get_sync(p->dev);
+		gpio_rcar_enable_inputs(p);
+		pm_runtime_put(p->dev);
+	}
+
 	dev_info(dev, "driving %d GPIOs\n", npins);
 
 	return 0;
@@ -612,6 +644,9 @@ static int gpio_rcar_resume(struct device *dev)
 		}
 	}
 
+	if (p->info.has_inen)
+		gpio_rcar_enable_inputs(p);
+
 	return 0;
 }
 #endif /* CONFIG_PM_SLEEP*/
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support
  2021-01-08 10:20 [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Geert Uytterhoeven
                   ` (2 preceding siblings ...)
  2021-01-08 10:20 ` [PATCH v3 3/3] gpio: rcar: Add R-Car V3U (R8A779A0) support Geert Uytterhoeven
@ 2021-01-09  0:29 ` Linus Walleij
  2021-01-11 10:09 ` Bartosz Golaszewski
  4 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2021-01-09  0:29 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bartosz Golaszewski, Rob Herring, open list:GPIO SUBSYSTEM,
	Linux-Renesas,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS

On Fri, Jan 8, 2021 at 11:20 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:

> This patch series adds support for GPIOs on the R-Car V3U (r8a779a0)
> SoC, to both DT bindings and the gpio-rcar driver.

These all look good to me. The series:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support
  2021-01-08 10:20 [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Geert Uytterhoeven
                   ` (3 preceding siblings ...)
  2021-01-09  0:29 ` [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Linus Walleij
@ 2021-01-11 10:09 ` Bartosz Golaszewski
  4 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2021-01-11 10:09 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Linus Walleij, Rob Herring, linux-gpio, Linux-Renesas, linux-devicetree

On Fri, Jan 8, 2021 at 11:20 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>
>         Hi Linus, Bartosz, Rob,
>
> This patch series adds support for GPIOs on the R-Car V3U (r8a779a0)
> SoC, to both DT bindings and the gpio-rcar driver.
>
> Changes compared to v2:
>   - Add Reviewed-by, Tested-by,
>   - Fix SoC part number in oneline summary,
>   - Reformat comment block to match coding style,
>   - Rebase on top of commit 3a57026a83ba363e ("gpio: rcar: Remove
>     redundant compatible values"),
>
> Changes compared to v1:
>   - Optimize GPIO pin state read on R-Car Gen3,
>   - Enable input unconditionally in probe and resume, instead of during
>     GPIO line configuration and depending on GPIO line direction,
>   - Assumed authorship, as this patch is very different from v1, written
>     by Phong Hoang,
>   - Add Reviewed-by.
>
> Thanks!
>

All three applied, thanks!

Bartosz

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-11 10:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08 10:20 [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Geert Uytterhoeven
2021-01-08 10:20 ` [PATCH v3 1/3] dt-bindings: gpio: rcar: Add r8a779a0 support Geert Uytterhoeven
2021-01-08 10:20 ` [PATCH v3 2/3] gpio: rcar: Optimize GPIO pin state read on R-Car Gen3 Geert Uytterhoeven
2021-01-08 10:20 ` [PATCH v3 3/3] gpio: rcar: Add R-Car V3U (R8A779A0) support Geert Uytterhoeven
2021-01-09  0:29 ` [PATCH v3 0/3] gpio: rcar: Add R-Car V3U support Linus Walleij
2021-01-11 10:09 ` Bartosz Golaszewski

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).