linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
@ 2020-03-15 12:13 Chuanhong Guo
  2020-03-15 12:13 ` [PATCH 1/2] " Chuanhong Guo
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Chuanhong Guo @ 2020-03-15 12:13 UTC (permalink / raw)
  To: linux-gpio
  Cc: Chuanhong Guo, Linus Walleij, Bartosz Golaszewski,
	Sergio Paracuellos, René van Dorst, open list

Currently gpio-hog doesn't work on gpio-mt7621 driver. On further
debugging, I noticed that set/clear register on this controller
only works on output pins. We need to setup pin direction before
writing values in bgpio_dir_out for a correct gpio-hog behavior.
This patchset introduces a new flag BGPIOF_NO_SET_ON_INPUT for
these kind of controller and set this flag for gpio-mt7621.

Chuanhong Guo (2):
  gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
  gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag

 drivers/gpio/gpio-mmio.c    | 23 +++++++++++++++++++----
 drivers/gpio/gpio-mt7621.c  |  4 ++--
 include/linux/gpio/driver.h |  1 +
 3 files changed, 22 insertions(+), 6 deletions(-)

-- 
2.24.1


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

* [PATCH 1/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
  2020-03-15 12:13 [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT Chuanhong Guo
@ 2020-03-15 12:13 ` Chuanhong Guo
  2020-03-16  9:27   ` Bartosz Golaszewski
  2020-03-15 12:13 ` [PATCH 2/2] gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag Chuanhong Guo
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Chuanhong Guo @ 2020-03-15 12:13 UTC (permalink / raw)
  To: linux-gpio
  Cc: Chuanhong Guo, Linus Walleij, Bartosz Golaszewski,
	Sergio Paracuellos, René van Dorst, open list

Some gpio controllers ignores pin value writing when that pin is
configured as input mode. As a result, bgpio_dir_out should set
pin to output before configuring pin values or gpio pin values
can't be set up properly.
Introduce two variants of bgpio_dir_out: bgpio_dir_out_val_first
and bgpio_dir_out_dir_first, and assign direction_output according
to a new flag: BGPIOF_NO_SET_ON_INPUT.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
---
 drivers/gpio/gpio-mmio.c    | 23 +++++++++++++++++++----
 include/linux/gpio/driver.h |  1 +
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index f729e3e9e983..b778f33cc6af 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -389,12 +389,10 @@ static int bgpio_get_dir(struct gpio_chip *gc, unsigned int gpio)
 	return GPIO_LINE_DIRECTION_IN;
 }
 
-static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
+static void bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
 {
 	unsigned long flags;
 
-	gc->set(gc, gpio, val);
-
 	spin_lock_irqsave(&gc->bgpio_lock, flags);
 
 	gc->bgpio_dir |= bgpio_line2mask(gc, gpio);
@@ -405,7 +403,21 @@ static int bgpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
 		gc->write_reg(gc->reg_dir_out, gc->bgpio_dir);
 
 	spin_unlock_irqrestore(&gc->bgpio_lock, flags);
+}
 
+static int bgpio_dir_out_dir_first(struct gpio_chip *gc, unsigned int gpio,
+				   int val)
+{
+	bgpio_dir_out(gc, gpio, val);
+	gc->set(gc, gpio, val);
+	return 0;
+}
+
+static int bgpio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio,
+				   int val)
+{
+	gc->set(gc, gpio, val);
+	bgpio_dir_out(gc, gpio, val);
 	return 0;
 }
 
@@ -538,7 +550,10 @@ static int bgpio_setup_direction(struct gpio_chip *gc,
 	if (dirout || dirin) {
 		gc->reg_dir_out = dirout;
 		gc->reg_dir_in = dirin;
-		gc->direction_output = bgpio_dir_out;
+		if (flags & BGPIOF_NO_SET_ON_INPUT)
+			gc->direction_output = bgpio_dir_out_dir_first;
+		else
+			gc->direction_output = bgpio_dir_out_val_first;
 		gc->direction_input = bgpio_dir_in;
 		gc->get_direction = bgpio_get_dir;
 	} else {
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 6ef05bccc0a6..ed65e00ee977 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -572,6 +572,7 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev,
 #define BGPIOF_BIG_ENDIAN_BYTE_ORDER	BIT(3)
 #define BGPIOF_READ_OUTPUT_REG_SET	BIT(4) /* reg_set stores output value */
 #define BGPIOF_NO_OUTPUT		BIT(5) /* only input */
+#define BGPIOF_NO_SET_ON_INPUT		BIT(6)
 
 int gpiochip_irq_map(struct irq_domain *d, unsigned int irq,
 		     irq_hw_number_t hwirq);
-- 
2.24.1


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

* [PATCH 2/2] gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag
  2020-03-15 12:13 [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT Chuanhong Guo
  2020-03-15 12:13 ` [PATCH 1/2] " Chuanhong Guo
@ 2020-03-15 12:13 ` Chuanhong Guo
  2020-03-16  9:27   ` Bartosz Golaszewski
  2020-03-15 12:48 ` [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT René van Dorst
  2020-03-15 14:17 ` Sergio Paracuellos
  3 siblings, 1 reply; 7+ messages in thread
From: Chuanhong Guo @ 2020-03-15 12:13 UTC (permalink / raw)
  To: linux-gpio
  Cc: Chuanhong Guo, Linus Walleij, Bartosz Golaszewski,
	Sergio Paracuellos, René van Dorst, open list

DSET/DCLR registers only works on output pins. Add corresponding
BGPIOF_NO_SET_ON_INPUT flag to bgpio_init call to fix direction_out
behavior.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
---
 drivers/gpio/gpio-mt7621.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-mt7621.c b/drivers/gpio/gpio-mt7621.c
index b992321bb852..82fb20dca53a 100644
--- a/drivers/gpio/gpio-mt7621.c
+++ b/drivers/gpio/gpio-mt7621.c
@@ -227,8 +227,8 @@ mediatek_gpio_bank_probe(struct device *dev,
 	ctrl = mtk->base + GPIO_REG_DCLR + (rg->bank * GPIO_BANK_STRIDE);
 	diro = mtk->base + GPIO_REG_CTRL + (rg->bank * GPIO_BANK_STRIDE);
 
-	ret = bgpio_init(&rg->chip, dev, 4,
-			 dat, set, ctrl, diro, NULL, 0);
+	ret = bgpio_init(&rg->chip, dev, 4, dat, set, ctrl, diro, NULL,
+			 BGPIOF_NO_SET_ON_INPUT);
 	if (ret) {
 		dev_err(dev, "bgpio_init() failed\n");
 		return ret;
-- 
2.24.1


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

* Re: [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
  2020-03-15 12:13 [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT Chuanhong Guo
  2020-03-15 12:13 ` [PATCH 1/2] " Chuanhong Guo
  2020-03-15 12:13 ` [PATCH 2/2] gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag Chuanhong Guo
@ 2020-03-15 12:48 ` René van Dorst
  2020-03-15 14:17 ` Sergio Paracuellos
  3 siblings, 0 replies; 7+ messages in thread
From: René van Dorst @ 2020-03-15 12:48 UTC (permalink / raw)
  To: Chuanhong Guo
  Cc: linux-gpio, Linus Walleij, Bartosz Golaszewski,
	Sergio Paracuellos, linux-kernel

Quoting Chuanhong Guo <gch981213@gmail.com>:

> Currently gpio-hog doesn't work on gpio-mt7621 driver. On further
> debugging, I noticed that set/clear register on this controller
> only works on output pins. We need to setup pin direction before
> writing values in bgpio_dir_out for a correct gpio-hog behavior.
> This patchset introduces a new flag BGPIOF_NO_SET_ON_INPUT for
> these kind of controller and set this flag for gpio-mt7621.
>
> Chuanhong Guo (2):
>   gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
>   gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag
>
>  drivers/gpio/gpio-mmio.c    | 23 +++++++++++++++++++----
>  drivers/gpio/gpio-mt7621.c  |  4 ++--
>  include/linux/gpio/driver.h |  1 +
>  3 files changed, 22 insertions(+), 6 deletions(-)
>
> --
> 2.24.1
Thanks Chuanhong for debugging the problem!

With this patch gpio-hog works again.

For the series:

Tested-by: René van Dorst <opensource@vdorst.com>

Greats,

René


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

* Re: [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
  2020-03-15 12:13 [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT Chuanhong Guo
                   ` (2 preceding siblings ...)
  2020-03-15 12:48 ` [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT René van Dorst
@ 2020-03-15 14:17 ` Sergio Paracuellos
  3 siblings, 0 replies; 7+ messages in thread
From: Sergio Paracuellos @ 2020-03-15 14:17 UTC (permalink / raw)
  To: Chuanhong Guo
  Cc: open list:GPIO SUBSYSTEM, Linus Walleij, Bartosz Golaszewski,
	René van Dorst, open list

Hi,

On Sun, Mar 15, 2020 at 1:14 PM Chuanhong Guo <gch981213@gmail.com> wrote:
>
> Currently gpio-hog doesn't work on gpio-mt7621 driver. On further
> debugging, I noticed that set/clear register on this controller
> only works on output pins. We need to setup pin direction before
> writing values in bgpio_dir_out for a correct gpio-hog behavior.
> This patchset introduces a new flag BGPIOF_NO_SET_ON_INPUT for
> these kind of controller and set this flag for gpio-mt7621.
>
> Chuanhong Guo (2):
>   gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
>   gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag
>
>  drivers/gpio/gpio-mmio.c    | 23 +++++++++++++++++++----
>  drivers/gpio/gpio-mt7621.c  |  4 ++--
>  include/linux/gpio/driver.h |  1 +
>  3 files changed, 22 insertions(+), 6 deletions(-)
>

This series looks good to me.

Reviewed-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>

Best regards,
    Sergio Paracuellos

> --
> 2.24.1
>

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

* Re: [PATCH 1/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT
  2020-03-15 12:13 ` [PATCH 1/2] " Chuanhong Guo
@ 2020-03-16  9:27   ` Bartosz Golaszewski
  0 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2020-03-16  9:27 UTC (permalink / raw)
  To: Chuanhong Guo
  Cc: linux-gpio, Linus Walleij, Sergio Paracuellos,
	René van Dorst, open list

niedz., 15 mar 2020 o 13:14 Chuanhong Guo <gch981213@gmail.com> napisał(a):
>
> Some gpio controllers ignores pin value writing when that pin is
> configured as input mode. As a result, bgpio_dir_out should set
> pin to output before configuring pin values or gpio pin values
> can't be set up properly.
> Introduce two variants of bgpio_dir_out: bgpio_dir_out_val_first
> and bgpio_dir_out_dir_first, and assign direction_output according
> to a new flag: BGPIOF_NO_SET_ON_INPUT.
>
> Signed-off-by: Chuanhong Guo <gch981213@gmail.com>

Patch applied with Rene's and Sergio's tags.

Bartosz

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

* Re: [PATCH 2/2] gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag
  2020-03-15 12:13 ` [PATCH 2/2] gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag Chuanhong Guo
@ 2020-03-16  9:27   ` Bartosz Golaszewski
  0 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2020-03-16  9:27 UTC (permalink / raw)
  To: Chuanhong Guo
  Cc: linux-gpio, Linus Walleij, Sergio Paracuellos,
	René van Dorst, open list

niedz., 15 mar 2020 o 13:14 Chuanhong Guo <gch981213@gmail.com> napisał(a):
>
> DSET/DCLR registers only works on output pins. Add corresponding
> BGPIOF_NO_SET_ON_INPUT flag to bgpio_init call to fix direction_out
> behavior.
>
> Signed-off-by: Chuanhong Guo <gch981213@gmail.com>

Patch applied with Rene's and Sergio's tags.

Bartosz

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

end of thread, other threads:[~2020-03-16  9:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-15 12:13 [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT Chuanhong Guo
2020-03-15 12:13 ` [PATCH 1/2] " Chuanhong Guo
2020-03-16  9:27   ` Bartosz Golaszewski
2020-03-15 12:13 ` [PATCH 2/2] gpio: mt7621: add BGPIOF_NO_SET_ON_INPUT flag Chuanhong Guo
2020-03-16  9:27   ` Bartosz Golaszewski
2020-03-15 12:48 ` [PATCH 0/2] gpio: mmio: introduce BGPIOF_NO_SET_ON_INPUT René van Dorst
2020-03-15 14:17 ` Sergio Paracuellos

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