2023-12-11 19:04:29

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 00/13] pinctrl: Convert struct group_desc to use struct pingroup

The struct group_desc has a lot of duplication with struct pingroup.
Deduplicate that by embeddind the latter in the former and convert
users.

NB. The function_desc is in plan to follow the similar deduplication.

This time test-compiled with old GCC 8 for arm64, besides GCC 13 and
LLVM 16 for x86_64.

In v5:
- dropped applied patches
- elaborated the need of the conversion (Fabio)
- reworked to avoid build errors on old GCC (Marek, Krzysztof, Geert)

v4: https://lore.kernel.org/r/[email protected]

In v4:
- made pins also unsigned in struct group_desc (Geert)
- made local pins variable unsigned in renesas drivers (Geert)
- collected more tags (Paul, Geert)

v3: https://lore.kernel.org/r/[email protected]

In v3:
- fixed reported bug in equilibrium code (LKP) - collected tags (Emil, Florian, Paul)

v2: https://lore.kernel.org/r/[email protected]

In v2:
- added a few patches to fix multiple compile-time errors (LKP)
- added tag (Jonathan)

v1: https://lore.kernel.org/r/[email protected]

Andy Shevchenko (13):
pinctrl: core: Add a convenient define PINCTRL_GROUP_DESC()
pinctrl: mediatek: Use C99 initializers in PINCTRL_PIN_GROUP()
pinctrl: ingenic: Use C99 initializers in PINCTRL_PIN_GROUP()
pinctrl: core: Embed struct pingroup into struct group_desc
pinctrl: bcm: Convert to use grp member
pinctrl: equilibrium: Convert to use grp member
pinctrl: imx: Convert to use grp member
pinctrl: ingenic: Convert to use grp member
pinctrl: keembay: Convert to use grp member
pinctrl: mediatek: Convert to use grp member
pinctrl: renesas: Convert to use grp member
pinctrl: starfive: Convert to use grp member
pinctrl: core: Remove unused members from struct group_desc

drivers/pinctrl/bcm/pinctrl-ns.c | 4 +--
drivers/pinctrl/core.c | 11 +++---
drivers/pinctrl/core.h | 17 +++++----
drivers/pinctrl/freescale/pinctrl-imx.c | 31 ++++++++--------
drivers/pinctrl/mediatek/pinctrl-moore.c | 13 ++++---
drivers/pinctrl/mediatek/pinctrl-moore.h | 10 +++---
drivers/pinctrl/mediatek/pinctrl-paris.h | 10 +++---
drivers/pinctrl/pinctrl-equilibrium.c | 4 +--
drivers/pinctrl/pinctrl-ingenic.c | 35 ++++++++++---------
drivers/pinctrl/pinctrl-keembay.c | 2 +-
drivers/pinctrl/renesas/pinctrl-rza1.c | 2 +-
drivers/pinctrl/renesas/pinctrl-rza2.c | 10 +++---
drivers/pinctrl/renesas/pinctrl-rzg2l.c | 4 +--
drivers/pinctrl/renesas/pinctrl-rzv2m.c | 4 +--
.../starfive/pinctrl-starfive-jh7100.c | 8 ++---
.../starfive/pinctrl-starfive-jh7110.c | 8 ++---
16 files changed, 84 insertions(+), 89 deletions(-)

--
2.43.0.rc1.1.gbec44491f096


2023-12-11 19:04:30

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 08/13] pinctrl: ingenic: Convert to use grp member

Convert drivers to use grp member embedded in struct group_desc,
because other members will be removed to avoid duplication and
desynchronisation of the generic pin group description.

Acked-by: Paul Cercueil <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/pinctrl-ingenic.c | 26 +++++++++++---------------
1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c
index f5661dcdedf5..bc6358a686fc 100644
--- a/drivers/pinctrl/pinctrl-ingenic.c
+++ b/drivers/pinctrl/pinctrl-ingenic.c
@@ -84,17 +84,13 @@

#define INGENIC_PIN_GROUP_FUNCS(_name_, id, funcs) \
{ \
- .name = _name_, \
- .pins = id##_pins, \
- .num_pins = ARRAY_SIZE(id##_pins), \
+ .grp = PINCTRL_PINGROUP(_name_, id##_pins, ARRAY_SIZE(id##_pins)), \
.data = funcs, \
}

#define INGENIC_PIN_GROUP(_name_, id, func) \
{ \
- .name = _name_, \
- .pins = id##_pins, \
- .num_pins = ARRAY_SIZE(id##_pins), \
+ .grp = PINCTRL_PINGROUP(_name_, id##_pins, ARRAY_SIZE(id##_pins)), \
.data = (void *)func, \
}

@@ -3766,17 +3762,17 @@ static int ingenic_pinmux_set_mux(struct pinctrl_dev *pctldev,
return -EINVAL;

dev_dbg(pctldev->dev, "enable function %s group %s\n",
- func->name, grp->name);
+ func->name, grp->grp.name);

mode = (uintptr_t)grp->data;
if (mode <= 3) {
- for (i = 0; i < grp->num_pins; i++)
- ingenic_pinmux_set_pin_fn(jzpc, grp->pins[i], mode);
+ for (i = 0; i < grp->grp.npins; i++)
+ ingenic_pinmux_set_pin_fn(jzpc, grp->grp.pins[i], mode);
} else {
pin_modes = grp->data;

- for (i = 0; i < grp->num_pins; i++)
- ingenic_pinmux_set_pin_fn(jzpc, grp->pins[i], pin_modes[i]);
+ for (i = 0; i < grp->grp.npins; i++)
+ ingenic_pinmux_set_pin_fn(jzpc, grp->grp.pins[i], pin_modes[i]);
}

return 0;
@@ -4303,12 +4299,12 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev)

for (i = 0; i < chip_info->num_groups; i++) {
const struct group_desc *group = &chip_info->groups[i];
+ const struct pingroup *grp = &group->grp;

- err = pinctrl_generic_add_group(jzpc->pctl, group->name,
- group->pins, group->num_pins, group->data);
+ err = pinctrl_generic_add_group(jzpc->pctl, grp->name, grp->pins, grp->npins,
+ group->data);
if (err < 0) {
- dev_err(dev, "Failed to register group %s\n",
- group->name);
+ dev_err(dev, "Failed to register group %s\n", grp->name);
return err;
}
}
--
2.43.0.rc1.1.gbec44491f096

2023-12-11 19:04:31

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 09/13] pinctrl: keembay: Convert to use grp member

Convert drivers to use grp member embedded in struct group_desc,
because other members will be removed to avoid duplication and
desynchronisation of the generic pin group description.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/pinctrl-keembay.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-keembay.c b/drivers/pinctrl/pinctrl-keembay.c
index 87d328853ae4..b1349ee22799 100644
--- a/drivers/pinctrl/pinctrl-keembay.c
+++ b/drivers/pinctrl/pinctrl-keembay.c
@@ -945,7 +945,7 @@ static int keembay_set_mux(struct pinctrl_dev *pctldev, unsigned int fun_sel,
return -EINVAL;

/* Change modes for pins in the selected group */
- pin = *grp->pins;
+ pin = *grp->grp.pins;
pin_mode = *(u8 *)(func->data);

val = keembay_read_reg(kpc->base1 + KEEMBAY_GPIO_MODE, pin);
--
2.43.0.rc1.1.gbec44491f096

2023-12-11 19:04:32

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 12/13] pinctrl: starfive: Convert to use grp member

Convert drivers to use grp member embedded in struct group_desc,
because other members will be removed to avoid duplication and
desynchronisation of the generic pin group description.

Reviewed-by: Emil Renner Berthing <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c | 8 ++++----
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 8 ++++----
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c
index b29b0ab9892b..6df7a310c7ed 100644
--- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c
+++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7100.c
@@ -654,7 +654,7 @@ static int starfive_set_mux(struct pinctrl_dev *pctldev,
return -EINVAL;

pinmux = group->data;
- for (i = 0; i < group->num_pins; i++) {
+ for (i = 0; i < group->grp.npins; i++) {
u32 v = pinmux[i];
unsigned int gpio = starfive_pinmux_to_gpio(v);
u32 dout = starfive_pinmux_to_dout(v);
@@ -797,7 +797,7 @@ static int starfive_pinconf_group_get(struct pinctrl_dev *pctldev,
if (!group)
return -EINVAL;

- return starfive_pinconf_get(pctldev, group->pins[0], config);
+ return starfive_pinconf_get(pctldev, group->grp.pins[0], config);
}

static int starfive_pinconf_group_set(struct pinctrl_dev *pctldev,
@@ -876,8 +876,8 @@ static int starfive_pinconf_group_set(struct pinctrl_dev *pctldev,
}
}

- for (i = 0; i < group->num_pins; i++)
- starfive_padctl_rmw(sfp, group->pins[i], mask, value);
+ for (i = 0; i < group->grp.npins; i++)
+ starfive_padctl_rmw(sfp, group->grp.pins[i], mask, value);

return 0;
}
diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
index 6de11a405734..9609eb1ecc3d 100644
--- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
+++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
@@ -307,7 +307,7 @@ static int jh7110_set_mux(struct pinctrl_dev *pctldev,
return -EINVAL;

pinmux = group->data;
- for (i = 0; i < group->num_pins; i++) {
+ for (i = 0; i < group->grp.npins; i++) {
u32 v = pinmux[i];

if (info->jh7110_set_one_pin_mux)
@@ -437,7 +437,7 @@ static int jh7110_pinconf_group_get(struct pinctrl_dev *pctldev,
if (!group)
return -EINVAL;

- return jh7110_pinconf_get(pctldev, group->pins[0], config);
+ return jh7110_pinconf_get(pctldev, group->grp.pins[0], config);
}

static int jh7110_pinconf_group_set(struct pinctrl_dev *pctldev,
@@ -508,8 +508,8 @@ static int jh7110_pinconf_group_set(struct pinctrl_dev *pctldev,
}
}

- for (i = 0; i < group->num_pins; i++)
- jh7110_padcfg_rmw(sfp, group->pins[i], mask, value);
+ for (i = 0; i < group->grp.npins; i++)
+ jh7110_padcfg_rmw(sfp, group->grp.pins[i], mask, value);

return 0;
}
--
2.43.0.rc1.1.gbec44491f096

2023-12-11 19:04:33

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 10/13] pinctrl: mediatek: Convert to use grp member

Convert drivers to use grp member embedded in struct group_desc,
because other members will be removed to avoid duplication and
desynchronisation of the generic pin group description.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/mediatek/pinctrl-moore.c | 13 ++++++-------
drivers/pinctrl/mediatek/pinctrl-moore.h | 4 +---
drivers/pinctrl/mediatek/pinctrl-paris.h | 4 +---
3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
index c3d59eddd994..d972584c0519 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -56,12 +56,12 @@ static int mtk_pinmux_set_mux(struct pinctrl_dev *pctldev,
return -EINVAL;

dev_dbg(pctldev->dev, "enable function %s group %s\n",
- func->name, grp->name);
+ func->name, grp->grp.name);

- for (i = 0; i < grp->num_pins; i++) {
+ for (i = 0; i < grp->grp.npins; i++) {
const struct mtk_pin_desc *desc;
int *pin_modes = grp->data;
- int pin = grp->pins[i];
+ int pin = grp->grp.pins[i];

desc = (const struct mtk_pin_desc *)&hw->soc->pins[pin];
if (!desc->name)
@@ -602,13 +602,12 @@ static int mtk_build_groups(struct mtk_pinctrl *hw)

for (i = 0; i < hw->soc->ngrps; i++) {
const struct group_desc *group = hw->soc->grps + i;
+ const struct pingroup *grp = &group->grp;

- err = pinctrl_generic_add_group(hw->pctrl, group->name,
- group->pins, group->num_pins,
+ err = pinctrl_generic_add_group(hw->pctrl, grp->name, grp->pins, grp->npins,
group->data);
if (err < 0) {
- dev_err(hw->dev, "Failed to register group %s\n",
- group->name);
+ dev_err(hw->dev, "Failed to register group %s\n", grp->name);
return err;
}
}
diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.h b/drivers/pinctrl/mediatek/pinctrl-moore.h
index 36ee0021cf7e..e0313e7a1fe0 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.h
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.h
@@ -39,9 +39,7 @@

#define PINCTRL_PIN_GROUP(_name_, id) \
{ \
- .name = _name_, \
- .pins = id##_pins, \
- .num_pins = ARRAY_SIZE(id##_pins), \
+ .grp = PINCTRL_PINGROUP(_name_, id##_pins, ARRAY_SIZE(id##_pins)), \
.data = id##_funcs, \
}

diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.h b/drivers/pinctrl/mediatek/pinctrl-paris.h
index 5c4e5b74e43e..948ce126aa0c 100644
--- a/drivers/pinctrl/mediatek/pinctrl-paris.h
+++ b/drivers/pinctrl/mediatek/pinctrl-paris.h
@@ -51,9 +51,7 @@

#define PINCTRL_PIN_GROUP(_name_, id) \
{ \
- .name = _name_, \
- .pins = id##_pins, \
- .num_pins = ARRAY_SIZE(id##_pins), \
+ .grp = PINCTRL_PINGROUP(_name_,id##_pins, ARRAY_SIZE(id##_pins)), \
.data = id##_funcs, \
}

--
2.43.0.rc1.1.gbec44491f096

2023-12-11 19:04:45

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 11/13] pinctrl: renesas: Convert to use grp member

Convert drivers to use grp member embedded in struct group_desc,
because other members will be removed to avoid duplication and
desynchronisation of the generic pin group description.

Reviewed-by: Geert Uytterhoeven <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/renesas/pinctrl-rza1.c | 2 +-
drivers/pinctrl/renesas/pinctrl-rza2.c | 10 +++++-----
drivers/pinctrl/renesas/pinctrl-rzg2l.c | 4 ++--
drivers/pinctrl/renesas/pinctrl-rzv2m.c | 4 ++--
4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/pinctrl/renesas/pinctrl-rza1.c b/drivers/pinctrl/renesas/pinctrl-rza1.c
index ab334de89b69..b03f22c54ca8 100644
--- a/drivers/pinctrl/renesas/pinctrl-rza1.c
+++ b/drivers/pinctrl/renesas/pinctrl-rza1.c
@@ -1131,7 +1131,7 @@ static int rza1_set_mux(struct pinctrl_dev *pctldev, unsigned int selector,
return -EINVAL;

mux_confs = (struct rza1_mux_conf *)func->data;
- for (i = 0; i < grp->num_pins; ++i) {
+ for (i = 0; i < grp->grp.npins; ++i) {
int ret;

ret = rza1_pin_mux_single(rza1_pctl, &mux_confs[i]);
diff --git a/drivers/pinctrl/renesas/pinctrl-rza2.c b/drivers/pinctrl/renesas/pinctrl-rza2.c
index 990b96d45967..af689d7c117f 100644
--- a/drivers/pinctrl/renesas/pinctrl-rza2.c
+++ b/drivers/pinctrl/renesas/pinctrl-rza2.c
@@ -447,15 +447,15 @@ static int rza2_set_mux(struct pinctrl_dev *pctldev, unsigned int selector,

psel_val = func->data;

- for (i = 0; i < grp->num_pins; ++i) {
+ for (i = 0; i < grp->grp.npins; ++i) {
dev_dbg(priv->dev, "Setting P%c_%d to PSEL=%d\n",
- port_names[RZA2_PIN_ID_TO_PORT(grp->pins[i])],
- RZA2_PIN_ID_TO_PIN(grp->pins[i]),
+ port_names[RZA2_PIN_ID_TO_PORT(grp->grp.pins[i])],
+ RZA2_PIN_ID_TO_PIN(grp->grp.pins[i]),
psel_val[i]);
rza2_set_pin_function(
priv->base,
- RZA2_PIN_ID_TO_PORT(grp->pins[i]),
- RZA2_PIN_ID_TO_PIN(grp->pins[i]),
+ RZA2_PIN_ID_TO_PORT(grp->grp.pins[i]),
+ RZA2_PIN_ID_TO_PIN(grp->grp.pins[i]),
psel_val[i]);
}

diff --git a/drivers/pinctrl/renesas/pinctrl-rzg2l.c b/drivers/pinctrl/renesas/pinctrl-rzg2l.c
index 68fcc2a4efbc..f01aa51b00c4 100644
--- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c
+++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c
@@ -283,9 +283,9 @@ static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev,
return -EINVAL;

psel_val = func->data;
- pins = group->pins;
+ pins = group->grp.pins;

- for (i = 0; i < group->num_pins; i++) {
+ for (i = 0; i < group->grp.npins; i++) {
unsigned int *pin_data = pctrl->desc.pins[pins[i]].drv_data;
u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET(*pin_data);
u32 pin = RZG2L_PIN_ID_TO_PIN(pins[i]);
diff --git a/drivers/pinctrl/renesas/pinctrl-rzv2m.c b/drivers/pinctrl/renesas/pinctrl-rzv2m.c
index eb304fab1796..0767a5ac23e0 100644
--- a/drivers/pinctrl/renesas/pinctrl-rzv2m.c
+++ b/drivers/pinctrl/renesas/pinctrl-rzv2m.c
@@ -175,9 +175,9 @@ static int rzv2m_pinctrl_set_mux(struct pinctrl_dev *pctldev,
return -EINVAL;

psel_val = func->data;
- pins = group->pins;
+ pins = group->grp.pins;

- for (i = 0; i < group->num_pins; i++) {
+ for (i = 0; i < group->grp.npins; i++) {
dev_dbg(pctrl->dev, "port:%u pin: %u PSEL:%u\n",
RZV2M_PIN_ID_TO_PORT(pins[i]), RZV2M_PIN_ID_TO_PIN(pins[i]),
psel_val[i]);
--
2.43.0.rc1.1.gbec44491f096

2023-12-11 19:04:54

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v5 13/13] pinctrl: core: Remove unused members from struct group_desc

All drivers are converted to use embedded struct pingroup.
Remove unused members from struct group_desc.

Reviewed-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/core.c | 9 ---------
drivers/pinctrl/core.h | 9 ---------
2 files changed, 18 deletions(-)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 48cc5571dea6..ee56856cb80c 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -557,9 +557,6 @@ const char *pinctrl_generic_get_group_name(struct pinctrl_dev *pctldev,
if (!group)
return NULL;

- if (group->name)
- return group->name;
-
return group->grp.name;
}
EXPORT_SYMBOL_GPL(pinctrl_generic_get_group_name);
@@ -586,12 +583,6 @@ int pinctrl_generic_get_group_pins(struct pinctrl_dev *pctldev,
return -EINVAL;
}

- if (group->pins) {
- *pins = group->pins;
- *num_pins = group->num_pins;
- return 0;
- }
-
*pins = group->grp.pins;
*num_pins = group->grp.npins;

diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index a3b75ec7b54b..837fd5bd903d 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -199,16 +199,10 @@ struct pinctrl_maps {
/**
* struct group_desc - generic pin group descriptor
* @grp: generic data of the pin group (name and pins)
- * @name: name of the pin group
- * @pins: array of pins that belong to the group
- * @num_pins: number of pins in the group
* @data: pin controller driver specific data
*/
struct group_desc {
struct pingroup grp;
- const char *name;
- const unsigned int *pins;
- int num_pins;
void *data;
};

@@ -216,9 +210,6 @@ struct group_desc {
#define PINCTRL_GROUP_DESC(_name, _pins, _num_pins, _data) \
(struct group_desc) { \
.grp = PINCTRL_PINGROUP(_name, _pins, _num_pins), \
- .name = _name, \
- .pins = _pins, \
- .num_pins = _num_pins, \
.data = _data, \
}

--
2.43.0.rc1.1.gbec44491f096

2023-12-11 23:49:00

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH v5 00/13] pinctrl: Convert struct group_desc to use struct pingroup

On Mon, Dec 11, 2023 at 8:03 PM Andy Shevchenko
<[email protected]> wrote:

> The struct group_desc has a lot of duplication with struct pingroup.
> Deduplicate that by embeddind the latter in the former and convert
> users.
>
> NB. The function_desc is in plan to follow the similar deduplication.
>
> This time test-compiled with old GCC 8 for arm64, besides GCC 13 and
> LLVM 16 for x86_64.

Applied to my pin control devel branch for v6.8.

Yours,
Linus Walleij