Skip to contentSkip to conversation

pinctrl: Use struct pingroup and PINCTRL_PINGROUP()

PATCH In review Andy Shevchenko 3 participants 9 messages Dec 4, 2023 – Dec 7, 2023

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover pinctrl: Use struct pingroup and PINCTRL_PINGROUP()

This is an excerpt from v4 of the "pinctrl: Convert struct group_desc to use struct pingroup" [1]. The series has been compiled with GCC 8 for ARM64 besides x86_64 GCC 13 and LLVM 16.

Changelog to the mother series [1]:
- added a new patch against Renesas code, so no warnings will be seen

Andy Shevchenko (5):
pinctrl: renesas: Mark local variable with const in ->set_mux()
pinctrl: core: Make pins const unsigned int pointer in struct
group_desc
pinctrl: equilibrium: Convert to use struct pingroup
pinctrl: keembay: Convert to use struct pingroup
pinctrl: nuvoton: Convert to use struct pingroup and
PINCTRL_PINGROUP()

 drivers/pinctrl/core.c                    |  2 +-
 drivers/pinctrl/core.h                    |  4 ++--
 drivers/pinctrl/nuvoton/pinctrl-wpcm450.c |  9 ++++----
 drivers/pinctrl/pinctrl-equilibrium.c     | 26 +++++++++++------------
 drivers/pinctrl/pinctrl-keembay.c         |  4 ++--
 drivers/pinctrl/renesas/pinctrl-rzg2l.c   |  2 +-
 drivers/pinctrl/renesas/pinctrl-rzv2m.c   |  2 +-
 7 files changed, 24 insertions(+), 25 deletions(-)
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#1 lore raw

PATCH 1/5 pinctrl: renesas: Mark local variable with const in ->set_mux()

We are not going to change pins in the ->set_mux() callback. Mark the local variable with a const qualifier. While at it, make it also unsigned.

---
 drivers/pinctrl/renesas/pinctrl-rzg2l.c | 2 +-
 drivers/pinctrl/renesas/pinctrl-rzv2m.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/renesas/pinctrl-rzg2l.c +1 -1
index aed59c53207c..68fcc2a4efbc 100644
@@ -273,7 +273,7 @@ static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev,
 	struct function_desc *func;
 	unsigned int i, *psel_val;
 	struct group_desc *group;
-	int *pins;
+	const unsigned int *pins;
 
 	func = pinmux_generic_get_function(pctldev, func_selector);
 	if (!func)
drivers/pinctrl/renesas/pinctrl-rzv2m.c +1 -1
index 21d7d5ac8c4a..eb304fab1796 100644
@@ -165,7 +165,7 @@ static int rzv2m_pinctrl_set_mux(struct pinctrl_dev *pctldev,
 	struct function_desc *func;
 	unsigned int i, *psel_val;
 	struct group_desc *group;
-	int *pins;
+	const unsigned int *pins;
 
 	func = pinmux_generic_get_function(pctldev, func_selector);
 	if (!func)
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
Reviewed-by Acked-by on v1 1/5
#2 lore raw

Re: [PATCH v1 1/5] pinctrl: renesas: Mark local variable with const in ->set_mux()

Quoted 5 lines · Andy Shevchenko

We are not going to change pins in the ->set_mux() callback. Mark the local variable with a const qualifier. While at it, make it also unsigned.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#3 lore raw

PATCH 2/5 pinctrl: core: Make pins const unsigned int pointer in struct group_desc

In reply to Andy Shevchenko

It's unclear why it's not a const unsigned int pointer from day 1. Make the pins member const unsigned int pointer in struct group_desc. Update necessary APIs.

---
 drivers/pinctrl/core.c | 2 +-
 drivers/pinctrl/core.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/core.c +1 -1
index 12daf0bb091e..6380e1fa6509 100644
@@ -640,7 +640,7 @@ static int pinctrl_generic_group_name_to_selector(struct pinctrl_dev *pctldev,
  * Note that the caller must take care of locking.
  */
 int pinctrl_generic_add_group(struct pinctrl_dev *pctldev, const char *name,
-			      int *pins, int num_pins, void *data)
+			      const unsigned int *pins, int num_pins, void *data)
 {
 	struct group_desc *group;
 	int selector, error;
drivers/pinctrl/core.h +2 -2
index 8b59dd72e4ff..8ef4b536bca5 100644
@@ -203,7 +203,7 @@ struct pinctrl_maps {
  */
 struct group_desc {
 	const char *name;
-	int *pins;
+	const unsigned int *pins;
 	int num_pins;
 	void *data;
 };
@@ -222,7 +222,7 @@ struct group_desc *pinctrl_generic_get_group(struct pinctrl_dev *pctldev,
 					     unsigned int group_selector);
 
 int pinctrl_generic_add_group(struct pinctrl_dev *pctldev, const char *name,
-			      int *gpins, int ngpins, void *data);
+			      const unsigned int *pins, int num_pins, void *data);
 
 int pinctrl_generic_remove_group(struct pinctrl_dev *pctldev,
 				 unsigned int group_selector);
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#4 lore raw

PATCH 3/5 pinctrl: equilibrium: Convert to use struct pingroup

In reply to Andy Shevchenko

The pin control header provides struct pingroup. Utilize it instead of open coded variants in the driver.

---
 drivers/pinctrl/pinctrl-equilibrium.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/pinctrl/pinctrl-equilibrium.c +13 -13
index fd59cfdeefac..4ebae516d1b1 100644
@@ -705,7 +705,7 @@ static int eqbr_build_groups(struct eqbr_pinctrl_drv_data *drvdata)
 	struct device *dev = drvdata->dev;
 	struct device_node *node = dev->of_node;
 	unsigned int *pins, *pinmux, pin_id, pinmux_id;
-	struct group_desc group;
+	struct pingroup group, *grp = &group;
 	struct device_node *np;
 	struct property *prop;
 	int j, err;
@@ -721,49 +721,49 @@ static int eqbr_build_groups(struct eqbr_pinctrl_drv_data *drvdata)
 			of_node_put(np);
 			return err;
 		}
-		group.num_pins = err;
-		group.name = prop->value;
-		pins = devm_kcalloc(dev, group.num_pins, sizeof(*pins), GFP_KERNEL);
+		grp->npins = err;
+		grp->name = prop->value;
+		pins = devm_kcalloc(dev, grp->npins, sizeof(*pins), GFP_KERNEL);
 		if (!pins) {
 			of_node_put(np);
 			return -ENOMEM;
 		}
-		group.pins = pins;
+		grp->pins = pins;
 
-		pinmux = devm_kcalloc(dev, group.num_pins, sizeof(*pinmux), GFP_KERNEL);
+		pinmux = devm_kcalloc(dev, grp->npins, sizeof(*pinmux), GFP_KERNEL);
 		if (!pinmux) {
 			of_node_put(np);
 			return -ENOMEM;
 		}
 
-		for (j = 0; j < group.num_pins; j++) {
+		for (j = 0; j < grp->npins; j++) {
 			if (of_property_read_u32_index(np, "pins", j, &pin_id)) {
 				dev_err(dev, "Group %s: Read intel pins id failed\n",
-					group.name);
+					grp->name);
 				of_node_put(np);
 				return -EINVAL;
 			}
 			if (pin_id >= drvdata->pctl_desc.npins) {
 				dev_err(dev, "Group %s: Invalid pin ID, idx: %d, pin %u\n",
-					group.name, j, pin_id);
+					grp->name, j, pin_id);
 				of_node_put(np);
 				return -EINVAL;
 			}
 			pins[j] = pin_id;
 			if (of_property_read_u32_index(np, "pinmux", j, &pinmux_id)) {
 				dev_err(dev, "Group %s: Read intel pinmux id failed\n",
-					group.name);
+					grp->name);
 				of_node_put(np);
 				return -EINVAL;
 			}
 			pinmux[j] = pinmux_id;
 		}
 
-		err = pinctrl_generic_add_group(drvdata->pctl_dev, group.name,
-						group.pins, group.num_pins,
+		err = pinctrl_generic_add_group(drvdata->pctl_dev,
+						grp->name, grp->pins, grp->npins,
 						pinmux);
 		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);
 			of_node_put(np);
 			return err;
 		}
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#5 lore raw

PATCH 4/5 pinctrl: keembay: Convert to use struct pingroup

In reply to Andy Shevchenko

The pin control header provides struct pingroup. Utilize it instead of open coded variants in the driver.

---
 drivers/pinctrl/pinctrl-keembay.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-keembay.c +2 -2
index 152c35bce8ec..87d328853ae4 100644
@@ -1517,7 +1517,7 @@ static int keembay_gpiochip_probe(struct keembay_pinctrl *kpc,
 
 static int keembay_build_groups(struct keembay_pinctrl *kpc)
 {
-	struct group_desc *grp;
+	struct pingroup *grp;
 	unsigned int i;
 
 	kpc->ngroups = kpc->npins;
@@ -1528,7 +1528,7 @@ static int keembay_build_groups(struct keembay_pinctrl *kpc)
 	/* Each pin is categorised as one group */
 	for (i = 0; i < kpc->ngroups; i++) {
 		const struct pinctrl_pin_desc *pdesc = keembay_pins + i;
-		struct group_desc *kmb_grp = grp + i;
+		struct pingroup *kmb_grp = grp + i;
 
 		kmb_grp->name = pdesc->name;
 		kmb_grp->pins = (int *)&pdesc->number;
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#6 lore raw

PATCH 5/5 pinctrl: nuvoton: Convert to use struct pingroup and PINCTRL_PINGROUP()

In reply to Andy Shevchenko

The pin control header provides struct pingroup and PINCTRL_PINGROUP() macro. Utilize them instead of open coded variants in the driver.

---
 drivers/pinctrl/nuvoton/pinctrl-wpcm450.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +4 -5
index 0cff44b07b29..4589900244c7 100644
@@ -474,9 +474,8 @@ enum {
 #undef WPCM450_GRP
 };
 
-static struct group_desc wpcm450_groups[] = {
-#define WPCM450_GRP(x) { .name = #x, .pins = x ## _pins, \
-			.num_pins = ARRAY_SIZE(x ## _pins) }
+static struct pingroup wpcm450_groups[] = {
+#define WPCM450_GRP(x) PINCTRL_PINGROUP(#x, x ## _pins, ARRAY_SIZE(x ## _pins))
 	WPCM450_GRPS
 #undef WPCM450_GRP
 };
@@ -852,7 +851,7 @@ static int wpcm450_get_group_pins(struct pinctrl_dev *pctldev,
 				  const unsigned int **pins,
 				  unsigned int *npins)
 {
-	*npins = wpcm450_groups[selector].num_pins;
+	*npins = wpcm450_groups[selector].npins;
 	*pins  = wpcm450_groups[selector].pins;
 
 	return 0;
@@ -901,7 +900,7 @@ static int wpcm450_pinmux_set_mux(struct pinctrl_dev *pctldev,
 	struct wpcm450_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
 
 	wpcm450_setfunc(pctrl->gcr_regmap, wpcm450_groups[group].pins,
-			wpcm450_groups[group].num_pins, function);
+			wpcm450_groups[group].npins, function);
 
 	return 0;
 }
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#7 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

This is an excerpt from v4 of the "pinctrl: Convert struct group_desc to use struct pingroup" [1]. The series has been compiled with GCC 8 for ARM64 besides x86_64 GCC 13 and LLVM 16.

Changelog to the mother series [1]:
- added a new patch against Renesas code, so no warnings will be seen

Patches applied!

Yours,
Linus Walleij

#8 lore raw
Quoted 11 lines · Linus Walleij
Quoted 6 lines · Andy Shevchenko

This is an excerpt from v4 of the "pinctrl: Convert struct group_desc to use struct pingroup" [1]. The series has been compiled with GCC 8 for ARM64 besides x86_64 GCC 13 and LLVM 16.

Changelog to the mother series [1]:
- added a new patch against Renesas code, so no warnings will be seen

Patches applied!

Thank you!
I will send the rest after this part appears in Linux Next.

Signature · 2 lines
With Best Regards,
Andy Shevchenko