pinctrl: renesas: Factor out common R-Car Gen3 bias handling
authorGeert Uytterhoeven <geert+renesas@glider.be>
Wed, 28 Oct 2020 15:16:34 +0000 (16:16 +0100)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Fri, 13 Nov 2020 14:37:41 +0000 (15:37 +0100)
All pin control drivers for R-Car Gen3 SoCs contain identical bias
handling.  Reduce code duplication by moving it to the common pinctrl.c
code.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20201028151637.1734130-6-geert+renesas@glider.be
drivers/pinctrl/renesas/core.h
drivers/pinctrl/renesas/pfc-r8a77950.c
drivers/pinctrl/renesas/pfc-r8a77951.c
drivers/pinctrl/renesas/pfc-r8a7796.c
drivers/pinctrl/renesas/pfc-r8a77965.c
drivers/pinctrl/renesas/pfc-r8a77990.c
drivers/pinctrl/renesas/pinctrl.c

index b5b1d16..5ca7e08 100644 (file)
@@ -33,4 +33,8 @@ const struct pinmux_bias_reg *
 sh_pfc_pin_to_bias_reg(const struct sh_pfc *pfc, unsigned int pin,
                       unsigned int *bit);
 
+unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
+void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
+                         unsigned int bias);
+
 #endif /* __SH_PFC_CORE_H__ */
index 04812e6..32b66b9 100644 (file)
@@ -5820,51 +5820,10 @@ static const struct pinmux_bias_reg pinmux_bias_regs[] = {
        { /* sentinel */ },
 };
 
-static unsigned int r8a77950_pinmux_get_bias(struct sh_pfc *pfc,
-                                            unsigned int pin)
-{
-       const struct pinmux_bias_reg *reg;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return PIN_CONFIG_BIAS_DISABLE;
-
-       if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
-               return PIN_CONFIG_BIAS_DISABLE;
-       else if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
-               return PIN_CONFIG_BIAS_PULL_UP;
-       else
-               return PIN_CONFIG_BIAS_PULL_DOWN;
-}
-
-static void r8a77950_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
-                                    unsigned int bias)
-{
-       const struct pinmux_bias_reg *reg;
-       u32 enable, updown;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return;
-
-       enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
-       if (bias != PIN_CONFIG_BIAS_DISABLE)
-               enable |= BIT(bit);
-
-       updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
-       if (bias == PIN_CONFIG_BIAS_PULL_UP)
-               updown |= BIT(bit);
-
-       sh_pfc_write(pfc, reg->pud, updown);
-       sh_pfc_write(pfc, reg->puen, enable);
-}
-
 static const struct sh_pfc_soc_operations r8a77950_pinmux_ops = {
        .pin_to_pocctrl = r8a77950_pin_to_pocctrl,
-       .get_bias = r8a77950_pinmux_get_bias,
-       .set_bias = r8a77950_pinmux_set_bias,
+       .get_bias = rcar_pinmux_get_bias,
+       .set_bias = rcar_pinmux_set_bias,
 };
 
 const struct sh_pfc_soc_info r8a77950_pinmux_info = {
index 8d1262c..72252fd 100644 (file)
@@ -6201,51 +6201,10 @@ static const struct pinmux_bias_reg pinmux_bias_regs[] = {
        { /* sentinel */ },
 };
 
-static unsigned int r8a77951_pinmux_get_bias(struct sh_pfc *pfc,
-                                            unsigned int pin)
-{
-       const struct pinmux_bias_reg *reg;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return PIN_CONFIG_BIAS_DISABLE;
-
-       if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
-               return PIN_CONFIG_BIAS_DISABLE;
-       else if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
-               return PIN_CONFIG_BIAS_PULL_UP;
-       else
-               return PIN_CONFIG_BIAS_PULL_DOWN;
-}
-
-static void r8a77951_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
-                                    unsigned int bias)
-{
-       const struct pinmux_bias_reg *reg;
-       u32 enable, updown;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return;
-
-       enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
-       if (bias != PIN_CONFIG_BIAS_DISABLE)
-               enable |= BIT(bit);
-
-       updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
-       if (bias == PIN_CONFIG_BIAS_PULL_UP)
-               updown |= BIT(bit);
-
-       sh_pfc_write(pfc, reg->pud, updown);
-       sh_pfc_write(pfc, reg->puen, enable);
-}
-
 static const struct sh_pfc_soc_operations r8a77951_pinmux_ops = {
        .pin_to_pocctrl = r8a77951_pin_to_pocctrl,
-       .get_bias = r8a77951_pinmux_get_bias,
-       .set_bias = r8a77951_pinmux_set_bias,
+       .get_bias = rcar_pinmux_get_bias,
+       .set_bias = rcar_pinmux_set_bias,
 };
 
 #ifdef CONFIG_PINCTRL_PFC_R8A774E1
index 88e9c46..6e8e023 100644 (file)
@@ -6150,51 +6150,10 @@ static const struct pinmux_bias_reg pinmux_bias_regs[] = {
        { /* sentinel */ },
 };
 
-static unsigned int r8a7796_pinmux_get_bias(struct sh_pfc *pfc,
-                                           unsigned int pin)
-{
-       const struct pinmux_bias_reg *reg;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return PIN_CONFIG_BIAS_DISABLE;
-
-       if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
-               return PIN_CONFIG_BIAS_DISABLE;
-       else if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
-               return PIN_CONFIG_BIAS_PULL_UP;
-       else
-               return PIN_CONFIG_BIAS_PULL_DOWN;
-}
-
-static void r8a7796_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
-                                  unsigned int bias)
-{
-       const struct pinmux_bias_reg *reg;
-       u32 enable, updown;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return;
-
-       enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
-       if (bias != PIN_CONFIG_BIAS_DISABLE)
-               enable |= BIT(bit);
-
-       updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
-       if (bias == PIN_CONFIG_BIAS_PULL_UP)
-               updown |= BIT(bit);
-
-       sh_pfc_write(pfc, reg->pud, updown);
-       sh_pfc_write(pfc, reg->puen, enable);
-}
-
 static const struct sh_pfc_soc_operations r8a7796_pinmux_ops = {
        .pin_to_pocctrl = r8a7796_pin_to_pocctrl,
-       .get_bias = r8a7796_pinmux_get_bias,
-       .set_bias = r8a7796_pinmux_set_bias,
+       .get_bias = rcar_pinmux_get_bias,
+       .set_bias = rcar_pinmux_set_bias,
 };
 
 #ifdef CONFIG_PINCTRL_PFC_R8A774A1
index 38b7b84..590e5f8 100644 (file)
@@ -6404,51 +6404,10 @@ static const struct pinmux_bias_reg pinmux_bias_regs[] = {
        { /* sentinel */ },
 };
 
-static unsigned int r8a77965_pinmux_get_bias(struct sh_pfc *pfc,
-                                           unsigned int pin)
-{
-       const struct pinmux_bias_reg *reg;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return PIN_CONFIG_BIAS_DISABLE;
-
-       if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
-               return PIN_CONFIG_BIAS_DISABLE;
-       else if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
-               return PIN_CONFIG_BIAS_PULL_UP;
-       else
-               return PIN_CONFIG_BIAS_PULL_DOWN;
-}
-
-static void r8a77965_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
-                                  unsigned int bias)
-{
-       const struct pinmux_bias_reg *reg;
-       u32 enable, updown;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return;
-
-       enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
-       if (bias != PIN_CONFIG_BIAS_DISABLE)
-               enable |= BIT(bit);
-
-       updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
-       if (bias == PIN_CONFIG_BIAS_PULL_UP)
-               updown |= BIT(bit);
-
-       sh_pfc_write(pfc, reg->pud, updown);
-       sh_pfc_write(pfc, reg->puen, enable);
-}
-
 static const struct sh_pfc_soc_operations r8a77965_pinmux_ops = {
        .pin_to_pocctrl = r8a77965_pin_to_pocctrl,
-       .get_bias = r8a77965_pinmux_get_bias,
-       .set_bias = r8a77965_pinmux_set_bias,
+       .get_bias = rcar_pinmux_get_bias,
+       .set_bias = rcar_pinmux_set_bias,
 };
 
 #ifdef CONFIG_PINCTRL_PFC_R8A774B1
index 6f9f763..a51c1e6 100644 (file)
@@ -5237,51 +5237,10 @@ static const struct pinmux_bias_reg pinmux_bias_regs[] = {
        { /* sentinel */ },
 };
 
-static unsigned int r8a77990_pinmux_get_bias(struct sh_pfc *pfc,
-                                            unsigned int pin)
-{
-       const struct pinmux_bias_reg *reg;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return PIN_CONFIG_BIAS_DISABLE;
-
-       if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
-               return PIN_CONFIG_BIAS_DISABLE;
-       else if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
-               return PIN_CONFIG_BIAS_PULL_UP;
-       else
-               return PIN_CONFIG_BIAS_PULL_DOWN;
-}
-
-static void r8a77990_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
-                                    unsigned int bias)
-{
-       const struct pinmux_bias_reg *reg;
-       u32 enable, updown;
-       unsigned int bit;
-
-       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
-       if (!reg)
-               return;
-
-       enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
-       if (bias != PIN_CONFIG_BIAS_DISABLE)
-               enable |= BIT(bit);
-
-       updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
-       if (bias == PIN_CONFIG_BIAS_PULL_UP)
-               updown |= BIT(bit);
-
-       sh_pfc_write(pfc, reg->pud, updown);
-       sh_pfc_write(pfc, reg->puen, enable);
-}
-
 static const struct sh_pfc_soc_operations r8a77990_pinmux_ops = {
        .pin_to_pocctrl = r8a77990_pin_to_pocctrl,
-       .get_bias = r8a77990_pinmux_get_bias,
-       .set_bias = r8a77990_pinmux_set_bias,
+       .get_bias = rcar_pinmux_get_bias,
+       .set_bias = rcar_pinmux_set_bias,
 };
 
 #ifdef CONFIG_PINCTRL_PFC_R8A774C0
index d340797..4a03060 100644 (file)
@@ -823,3 +823,43 @@ int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
 
        return pinctrl_enable(pmx->pctl);
 }
+
+unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin)
+{
+       const struct pinmux_bias_reg *reg;
+       unsigned int bit;
+
+       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
+       if (!reg)
+               return PIN_CONFIG_BIAS_DISABLE;
+
+       if (!(sh_pfc_read(pfc, reg->puen) & BIT(bit)))
+               return PIN_CONFIG_BIAS_DISABLE;
+       else if (sh_pfc_read(pfc, reg->pud) & BIT(bit))
+               return PIN_CONFIG_BIAS_PULL_UP;
+       else
+               return PIN_CONFIG_BIAS_PULL_DOWN;
+}
+
+void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
+                         unsigned int bias)
+{
+       const struct pinmux_bias_reg *reg;
+       u32 enable, updown;
+       unsigned int bit;
+
+       reg = sh_pfc_pin_to_bias_reg(pfc, pin, &bit);
+       if (!reg)
+               return;
+
+       enable = sh_pfc_read(pfc, reg->puen) & ~BIT(bit);
+       if (bias != PIN_CONFIG_BIAS_DISABLE)
+               enable |= BIT(bit);
+
+       updown = sh_pfc_read(pfc, reg->pud) & ~BIT(bit);
+       if (bias == PIN_CONFIG_BIAS_PULL_UP)
+               updown |= BIT(bit);
+
+       sh_pfc_write(pfc, reg->pud, updown);
+       sh_pfc_write(pfc, reg->puen, enable);
+}