* [PATCH v2 1/3] pinctrl: sh-pfc: add new flags into struct sh_pfc_pin_config
2019-08-08 6:19 [PATCH v2 0/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
@ 2019-08-08 6:19 ` Yoshihiro Shimoda
2019-08-09 18:52 ` Simon Horman
2019-08-08 6:19 ` [PATCH v2 2/3] pinctrl: sh-pfc: remove incomplete flag "cfg->type" Yoshihiro Shimoda
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Yoshihiro Shimoda @ 2019-08-08 6:19 UTC (permalink / raw)
To: linus.walleij, geert+renesas
Cc: linux-gpio, linux-renesas-soc, Yoshihiro Shimoda
To clean/modify the code up later, this patch just adds new flags
"mux_set" and "gpio_enabled" into the struct sh_pfc_pin_config.
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/pinctrl/sh-pfc/pinctrl.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c
index 2824be4..864da24 100644
--- a/drivers/pinctrl/sh-pfc/pinctrl.c
+++ b/drivers/pinctrl/sh-pfc/pinctrl.c
@@ -27,6 +27,8 @@
struct sh_pfc_pin_config {
u32 type;
+ bool mux_set;
+ bool gpio_enabled;
};
struct sh_pfc_pinctrl {
@@ -364,7 +366,15 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
for (i = 0; i < grp->nr_pins; ++i) {
ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
if (ret < 0)
- break;
+ goto done;
+ }
+
+ /* All group pins are configured, mark the pins as mux_set */
+ for (i = 0; i < grp->nr_pins; ++i) {
+ int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
+ struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
+
+ cfg->mux_set = true;
}
done:
@@ -405,6 +415,7 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
}
cfg->type = PINMUX_TYPE_GPIO;
+ cfg->gpio_enabled = true;
ret = 0;
@@ -426,6 +437,7 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
spin_lock_irqsave(&pfc->lock, flags);
cfg->type = PINMUX_TYPE_NONE;
+ cfg->gpio_enabled = false;
spin_unlock_irqrestore(&pfc->lock, flags);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v2 2/3] pinctrl: sh-pfc: remove incomplete flag "cfg->type"
2019-08-08 6:19 [PATCH v2 0/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
2019-08-08 6:19 ` [PATCH v2 1/3] pinctrl: sh-pfc: add new flags into struct sh_pfc_pin_config Yoshihiro Shimoda
@ 2019-08-08 6:19 ` Yoshihiro Shimoda
2019-08-09 18:52 ` Simon Horman
2019-08-08 6:19 ` [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
2019-08-08 8:31 ` [PATCH v2 0/3] " Geert Uytterhoeven
3 siblings, 1 reply; 10+ messages in thread
From: Yoshihiro Shimoda @ 2019-08-08 6:19 UTC (permalink / raw)
To: linus.walleij, geert+renesas
Cc: linux-gpio, linux-renesas-soc, Yoshihiro Shimoda
The old commit c58d9c1b26e3 ("sh-pfc: Implement generic pinconf
support") broke the cfg->type flag to PINMUX_TYPE_FUNCTION because
sh_pfc_pinconf_set() didn't call sh_pfc_reconfig_pin().
Now if we fix the cfg->type condition, it gets worse because:
- Some drivers might be deferred so that .set_mux() will be called
multiple times.
- In such the case, the sh-pfc driver returns -EBUSY even if
the group is the same, and then that driver fails to probe.
Since the pinctrl subsystem already has such conditions according
to @set_mux and @gpio_request_enable, this patch just remove
the incomplete flag from sh-pfc/pinctrl.c.
Fixes: c58d9c1b26e3 ("sh-pfc: Implement generic pinconf support")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/pinctrl/sh-pfc/pinctrl.c | 26 --------------------------
1 file changed, 26 deletions(-)
diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c
index 864da24..ab2aa93 100644
--- a/drivers/pinctrl/sh-pfc/pinctrl.c
+++ b/drivers/pinctrl/sh-pfc/pinctrl.c
@@ -26,7 +26,6 @@
#include "../pinconf.h"
struct sh_pfc_pin_config {
- u32 type;
bool mux_set;
bool gpio_enabled;
};
@@ -354,16 +353,6 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
spin_lock_irqsave(&pfc->lock, flags);
for (i = 0; i < grp->nr_pins; ++i) {
- int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
- struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
-
- if (cfg->type != PINMUX_TYPE_NONE) {
- ret = -EBUSY;
- goto done;
- }
- }
-
- for (i = 0; i < grp->nr_pins; ++i) {
ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
if (ret < 0)
goto done;
@@ -395,14 +384,6 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
spin_lock_irqsave(&pfc->lock, flags);
- if (cfg->type != PINMUX_TYPE_NONE) {
- dev_err(pfc->dev,
- "Pin %u is busy, can't configure it as GPIO.\n",
- offset);
- ret = -EBUSY;
- goto done;
- }
-
if (!pfc->gpio) {
/* If GPIOs are handled externally the pin mux type need to be
* set to GPIO here.
@@ -414,7 +395,6 @@ static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
goto done;
}
- cfg->type = PINMUX_TYPE_GPIO;
cfg->gpio_enabled = true;
ret = 0;
@@ -436,7 +416,6 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
unsigned long flags;
spin_lock_irqsave(&pfc->lock, flags);
- cfg->type = PINMUX_TYPE_NONE;
cfg->gpio_enabled = false;
spin_unlock_irqrestore(&pfc->lock, flags);
}
@@ -450,7 +429,6 @@ static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
int idx = sh_pfc_get_pin_index(pfc, offset);
const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
- struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
unsigned long flags;
unsigned int dir;
int ret;
@@ -470,8 +448,6 @@ static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
if (ret < 0)
goto done;
- cfg->type = new_type;
-
done:
spin_unlock_irqrestore(&pfc->lock, flags);
return ret;
@@ -794,13 +770,11 @@ static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
for (i = 0; i < pfc->info->nr_pins; ++i) {
const struct sh_pfc_pin *info = &pfc->info->pins[i];
- struct sh_pfc_pin_config *cfg = &pmx->configs[i];
struct pinctrl_pin_desc *pin = &pmx->pins[i];
/* If the pin number is equal to -1 all pins are considered */
pin->number = info->pin != (u16)-1 ? info->pin : i;
pin->name = info->name;
- cfg->type = PINMUX_TYPE_NONE;
}
return 0;
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/3] pinctrl: sh-pfc: remove incomplete flag "cfg->type"
2019-08-08 6:19 ` [PATCH v2 2/3] pinctrl: sh-pfc: remove incomplete flag "cfg->type" Yoshihiro Shimoda
@ 2019-08-09 18:52 ` Simon Horman
0 siblings, 0 replies; 10+ messages in thread
From: Simon Horman @ 2019-08-09 18:52 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: linus.walleij, geert+renesas, linux-gpio, linux-renesas-soc
On Thu, Aug 08, 2019 at 03:19:02PM +0900, Yoshihiro Shimoda wrote:
> The old commit c58d9c1b26e3 ("sh-pfc: Implement generic pinconf
> support") broke the cfg->type flag to PINMUX_TYPE_FUNCTION because
> sh_pfc_pinconf_set() didn't call sh_pfc_reconfig_pin().
> Now if we fix the cfg->type condition, it gets worse because:
> - Some drivers might be deferred so that .set_mux() will be called
> multiple times.
> - In such the case, the sh-pfc driver returns -EBUSY even if
> the group is the same, and then that driver fails to probe.
>
> Since the pinctrl subsystem already has such conditions according
> to @set_mux and @gpio_request_enable, this patch just remove
> the incomplete flag from sh-pfc/pinctrl.c.
>
> Fixes: c58d9c1b26e3 ("sh-pfc: Implement generic pinconf support")
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed
2019-08-08 6:19 [PATCH v2 0/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
2019-08-08 6:19 ` [PATCH v2 1/3] pinctrl: sh-pfc: add new flags into struct sh_pfc_pin_config Yoshihiro Shimoda
2019-08-08 6:19 ` [PATCH v2 2/3] pinctrl: sh-pfc: remove incomplete flag "cfg->type" Yoshihiro Shimoda
@ 2019-08-08 6:19 ` Yoshihiro Shimoda
2019-08-08 8:29 ` Geert Uytterhoeven
2019-08-09 18:52 ` Simon Horman
2019-08-08 8:31 ` [PATCH v2 0/3] " Geert Uytterhoeven
3 siblings, 2 replies; 10+ messages in thread
From: Yoshihiro Shimoda @ 2019-08-08 6:19 UTC (permalink / raw)
To: linus.walleij, geert+renesas
Cc: linux-gpio, linux-renesas-soc, Yoshihiro Shimoda
R-Car PWM controller requires the gpio to output zero duty,
this patch allows to roll it back from gpio to mux when the gpio
is freed.
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
drivers/pinctrl/sh-pfc/pinctrl.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/pinctrl/sh-pfc/pinctrl.c b/drivers/pinctrl/sh-pfc/pinctrl.c
index ab2aa93..c9bdca5 100644
--- a/drivers/pinctrl/sh-pfc/pinctrl.c
+++ b/drivers/pinctrl/sh-pfc/pinctrl.c
@@ -26,6 +26,7 @@
#include "../pinconf.h"
struct sh_pfc_pin_config {
+ unsigned int mux_mark;
bool mux_set;
bool gpio_enabled;
};
@@ -353,6 +354,16 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
spin_lock_irqsave(&pfc->lock, flags);
for (i = 0; i < grp->nr_pins; ++i) {
+ int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
+ struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
+
+ /*
+ * This driver cannot manage both gpio and mux when the gpio
+ * pin is already enabled. So, this function failed.
+ */
+ if (cfg->gpio_enabled)
+ return -EBUSY;
+
ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
if (ret < 0)
goto done;
@@ -364,6 +375,7 @@ static int sh_pfc_func_set_mux(struct pinctrl_dev *pctldev, unsigned selector,
struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
cfg->mux_set = true;
+ cfg->mux_mark = grp->mux[i];
}
done:
@@ -417,6 +429,9 @@ static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
spin_lock_irqsave(&pfc->lock, flags);
cfg->gpio_enabled = false;
+ /* If mux is already set, this configures it here */
+ if (cfg->mux_set)
+ sh_pfc_config_mux(pfc, cfg->mux_mark, PINMUX_TYPE_FUNCTION);
spin_unlock_irqrestore(&pfc->lock, flags);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed
2019-08-08 6:19 ` [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
@ 2019-08-08 8:29 ` Geert Uytterhoeven
2019-08-23 7:10 ` Geert Uytterhoeven
2019-08-09 18:52 ` Simon Horman
1 sibling, 1 reply; 10+ messages in thread
From: Geert Uytterhoeven @ 2019-08-08 8:29 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Linus Walleij, Geert Uytterhoeven, open list:GPIO SUBSYSTEM,
Linux-Renesas
On Thu, Aug 8, 2019 at 8:20 AM Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> R-Car PWM controller requires the gpio to output zero duty,
> this patch allows to roll it back from gpio to mux when the gpio
> is freed.
>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
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] 10+ messages in thread
* Re: [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed
2019-08-08 8:29 ` Geert Uytterhoeven
@ 2019-08-23 7:10 ` Geert Uytterhoeven
0 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2019-08-23 7:10 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Linus Walleij, Geert Uytterhoeven, open list:GPIO SUBSYSTEM,
Linux-Renesas
On Thu, Aug 8, 2019 at 10:29 AM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> On Thu, Aug 8, 2019 at 8:20 AM Yoshihiro Shimoda
> <yoshihiro.shimoda.uh@renesas.com> wrote:
> > R-Car PWM controller requires the gpio to output zero duty,
> > this patch allows to roll it back from gpio to mux when the gpio
> > is freed.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
FTR: as the PWM work is put on hold, I have changed the commit
description to:
pinctrl: sh-pfc: Rollback to mux if required when the gpio is freed
Some drivers require switching between function and gpio at run-time.
Allow to roll back from gpio to mux when the gpio is freed.
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] 10+ messages in thread
* Re: [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed
2019-08-08 6:19 ` [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
2019-08-08 8:29 ` Geert Uytterhoeven
@ 2019-08-09 18:52 ` Simon Horman
1 sibling, 0 replies; 10+ messages in thread
From: Simon Horman @ 2019-08-09 18:52 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: linus.walleij, geert+renesas, linux-gpio, linux-renesas-soc
On Thu, Aug 08, 2019 at 03:19:03PM +0900, Yoshihiro Shimoda wrote:
> R-Car PWM controller requires the gpio to output zero duty,
> this patch allows to roll it back from gpio to mux when the gpio
> is freed.
>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Reviewed-by: Simon Horman <horms+renesas@verge.net.au>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 0/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed
2019-08-08 6:19 [PATCH v2 0/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
` (2 preceding siblings ...)
2019-08-08 6:19 ` [PATCH v2 3/3] pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed Yoshihiro Shimoda
@ 2019-08-08 8:31 ` Geert Uytterhoeven
3 siblings, 0 replies; 10+ messages in thread
From: Geert Uytterhoeven @ 2019-08-08 8:31 UTC (permalink / raw)
To: Yoshihiro Shimoda
Cc: Linus Walleij, Geert Uytterhoeven, open list:GPIO SUBSYSTEM,
Linux-Renesas
Hi Shimoda-san,
On Thu, Aug 8, 2019 at 8:20 AM Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> This patch series is based on renesas-drivers.git /
> renesas-drivers-2019-07-30-v5.3-rc2 tag.
>
> About R-Car PWM driver modification, it seems to need more time to achieve
> output duty zero about suitable gpio vs pinctrl handling. But, I believe
> this pinctrl patches could be applied into the mainline regardless
> the R-Car PWM modification.
Thank you! I plan to apply this next week, after I've sent a first sh-pfc pull
request for v5.4, and let it soak in renesas-drivers.
> Changes from v1:
> - Spin-off the pinctrl patches (from 1/7 to 3/7).
> - Add Geert-san's Reviewed-by on 1/3 and 2/3.
> - Add Fixes tag on 2/3.
> https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=143129
>
> Yoshihiro Shimoda (3):
> pinctrl: sh-pfc: add new flags into struct sh_pfc_pin_config
> pinctrl: sh-pfc: remove incomplete flag "cfg->type"
> pinctrl: sh-pfc: Rollback to mux if requires when the gpio is freed
>
> drivers/pinctrl/sh-pfc/pinctrl.c | 45 ++++++++++++++++++++--------------------
> 1 file changed, 23 insertions(+), 22 deletions(-)
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] 10+ messages in thread