Skip to contentSkip to conversation

pinctrl: Introduce struct pinfunction and PINCTRL_PINFUNCTION() macro

PATCH In review Andy Shevchenko 3 participants 12 messages Dec 19, 2022 – Dec 29, 2022

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

PATCH 1/8 pinctrl: Introduce struct pinfunction and PINCTRL_PINFUNCTION() macro

There are many pin control drivers define their own data type for pin function representation which is the same or embed the same data as newly introduced one. Provide the data type and convenient macro for all pin control drivers.

---
 include/linux/pinctrl/pinctrl.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
include/linux/pinctrl/pinctrl.h +20 -0
index a0d39b303431..4d252ea00ed1 100644
@@ -206,6 +206,26 @@ extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
 				const char *pin_group, const unsigned **pins,
 				unsigned *num_pins);
 
+/**
+ * struct pinfunction - Description about a function
+ * @name: Name of the function
+ * @groups: An array of groups for this function
+ * @ngroups: Number of groups in @groups
+ */
+struct pinfunction {
+	const char *name;
+	const char * const *groups;
+	size_t ngroups;
+};
+
+/* Convenience macro to define a single named pinfunction */
+#define PINCTRL_PINFUNCTION(_name, _groups, _ngroups)	\
+(struct pinfunction) {					\
+		.name = (_name),			\
+		.groups = (_groups),			\
+		.ngroups = (_ngroups),			\
+	}
+
 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_PINCTRL)
 extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
 #else
Signature · 1 line
2.35.1
#1 lore raw

PATCH 2/8 pinctrl: intel: Make use of struct pinfunction and PINCTRL_PINFUNCTION()

Since pin control provides a generic data type and a macro for the pin function definition, use them in the Intel driver.

---

I went with the embedding a generic structure into intel_function instead of replacing the latter in order to keep symmetry with intel_pingroup. In the case we will need the additional memeber in the future there will be less churn, otherwise from the code generation perspective it's the same.

 drivers/pinctrl/intel/pinctrl-intel.c |  6 +++---
 drivers/pinctrl/intel/pinctrl-intel.h | 13 ++++++++-----
 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/pinctrl/intel/pinctrl-intel.c +3 -3
index 2f7931d9602c..682fd902009f 100644
@@ -372,7 +372,7 @@ static const char *intel_get_function_name(struct pinctrl_dev *pctldev,
 {
 	struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
 
-	return pctrl->soc->functions[function].name;
+	return pctrl->soc->functions[function].func.name;
 }
 
 static int intel_get_function_groups(struct pinctrl_dev *pctldev,
@@ -382,8 +382,8 @@ static int intel_get_function_groups(struct pinctrl_dev *pctldev,
 {
 	struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
 
-	*groups = pctrl->soc->functions[function].groups;
-	*ngroups = pctrl->soc->functions[function].ngroups;
+	*groups = pctrl->soc->functions[function].func.groups;
+	*ngroups = pctrl->soc->functions[function].func.ngroups;
 	return 0;
 }
 
drivers/pinctrl/intel/pinctrl-intel.h +8 -5
index 3b0e2d3f15d5..91e5bedba00b 100644
@@ -36,11 +36,13 @@ struct intel_pingroup {
 
 /**
  * struct intel_function - Description about a function
+ * @func: Generic data of the pin function (name and groups of pins)
  * @name: Name of the function
  * @groups: An array of groups for this function
  * @ngroups: Number of groups in @groups
  */
 struct intel_function {
+	struct pinfunction func;
 	const char *name;
 	const char * const *groups;
 	size_t ngroups;
@@ -183,11 +185,12 @@ struct intel_community {
 		.modes = __builtin_choose_expr(__builtin_constant_p((m)), NULL, (m)),	\
 	}
 
-#define FUNCTION(n, g)				\
-	{					\
-		.name = (n),			\
-		.groups = (g),			\
-		.ngroups = ARRAY_SIZE((g)),	\
+#define FUNCTION(n, g)							\
+	{								\
+		.func = PINCTRL_PINFUNCTION((n), (g), ARRAY_SIZE(g)),	\
+		.name = (n),						\
+		.groups = (g),						\
+		.ngroups = ARRAY_SIZE((g)),				\
 	}
 
 /**
Signature · 1 line
2.35.1
#2 lore raw

PATCH 3/8 pinctrl: baytrail: Convert to use new memeber in struct intel_function

In reply to Andy Shevchenko

Convert driver to use generic data type and hence a new member in the struct intel_function. No functional change intended.

---
 drivers/pinctrl/intel/pinctrl-baytrail.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pinctrl/intel/pinctrl-baytrail.c +5 -5
index 67db79f38051..770a2723ef81 100644
@@ -637,18 +637,18 @@ static const char *byt_get_function_name(struct pinctrl_dev *pctldev,
 {
 	struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctldev);
 
-	return vg->soc->functions[selector].name;
+	return vg->soc->functions[selector].func.name;
 }
 
 static int byt_get_function_groups(struct pinctrl_dev *pctldev,
 				   unsigned int selector,
 				   const char * const **groups,
-				   unsigned int *num_groups)
+				   unsigned int *ngroups)
 {
 	struct intel_pinctrl *vg = pinctrl_dev_get_drvdata(pctldev);
 
-	*groups		= vg->soc->functions[selector].groups;
-	*num_groups	= vg->soc->functions[selector].ngroups;
+	*groups		= vg->soc->functions[selector].func.groups;
+	*ngroups	= vg->soc->functions[selector].func.ngroups;
 
 	return 0;
 }
@@ -722,7 +722,7 @@ static int byt_set_mux(struct pinctrl_dev *pctldev, unsigned int func_selector,
 
 	if (group.modes)
 		byt_set_group_mixed_mux(vg, group, group.modes);
-	else if (!strcmp(func.name, "gpio"))
+	else if (!strcmp(func.func.name, "gpio"))
 		byt_set_group_simple_mux(vg, group, BYT_DEFAULT_GPIO_MUX);
 	else
 		byt_set_group_simple_mux(vg, group, group.mode);
Signature · 1 line
2.35.1
#3 lore raw

PATCH 4/8 pinctrl: cherryview: Convert to use new memeber in struct intel_function

In reply to Andy Shevchenko

Convert driver to use generic data type and hence a new member in the struct intel_function. No functional change intended.

---
 drivers/pinctrl/intel/pinctrl-cherryview.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/intel/pinctrl-cherryview.c +3 -3
index 11b81213922d..722990e27836 100644
@@ -694,7 +694,7 @@ static const char *chv_get_function_name(struct pinctrl_dev *pctldev,
 {
 	struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
 
-	return pctrl->soc->functions[function].name;
+	return pctrl->soc->functions[function].func.name;
 }
 
 static int chv_get_function_groups(struct pinctrl_dev *pctldev,
@@ -704,8 +704,8 @@ static int chv_get_function_groups(struct pinctrl_dev *pctldev,
 {
 	struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
 
-	*groups = pctrl->soc->functions[function].groups;
-	*ngroups = pctrl->soc->functions[function].ngroups;
+	*groups = pctrl->soc->functions[function].func.groups;
+	*ngroups = pctrl->soc->functions[function].func.ngroups;
 	return 0;
 }
 
Signature · 1 line
2.35.1
#4 lore raw

PATCH 5/8 pinctrl: lynxpoint: Convert to use new memeber in struct intel_function

In reply to Andy Shevchenko

Convert driver to use generic data type and hence a new member in the struct intel_function. No functional change intended.

---
 drivers/pinctrl/intel/pinctrl-lynxpoint.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pinctrl/intel/pinctrl-lynxpoint.c +4 -4
index 8d05dad38556..cdace55aaeac 100644
@@ -341,18 +341,18 @@ static const char *lp_get_function_name(struct pinctrl_dev *pctldev,
 {
 	struct intel_pinctrl *lg = pinctrl_dev_get_drvdata(pctldev);
 
-	return lg->soc->functions[selector].name;
+	return lg->soc->functions[selector].func.name;
 }
 
 static int lp_get_function_groups(struct pinctrl_dev *pctldev,
 				  unsigned int selector,
 				  const char * const **groups,
-				  unsigned int *num_groups)
+				  unsigned int *ngroups)
 {
 	struct intel_pinctrl *lg = pinctrl_dev_get_drvdata(pctldev);
 
-	*groups		= lg->soc->functions[selector].groups;
-	*num_groups	= lg->soc->functions[selector].ngroups;
+	*groups		= lg->soc->functions[selector].func.groups;
+	*ngroups	= lg->soc->functions[selector].func.ngroups;
 
 	return 0;
 }
Signature · 1 line
2.35.1
#5 lore raw

PATCH 6/8 pinctrl: merrifield: Convert to use new memeber in struct intel_function

In reply to Andy Shevchenko

Convert driver to use generic data type and hence a new member in the struct intel_function. No functional change intended.

---
 drivers/pinctrl/intel/pinctrl-merrifield.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/intel/pinctrl-merrifield.c +3 -3
index c0845bb1e9e3..365c391c97a3 100644
@@ -576,7 +576,7 @@ static const char *mrfld_get_function_name(struct pinctrl_dev *pctldev,
 {
 	struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
 
-	return mp->functions[function].name;
+	return mp->functions[function].func.name;
 }
 
 static int mrfld_get_function_groups(struct pinctrl_dev *pctldev,
@@ -586,8 +586,8 @@ static int mrfld_get_function_groups(struct pinctrl_dev *pctldev,
 {
 	struct mrfld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
 
-	*groups = mp->functions[function].groups;
-	*ngroups = mp->functions[function].ngroups;
+	*groups = mp->functions[function].func.groups;
+	*ngroups = mp->functions[function].func.ngroups;
 	return 0;
 }
 
Signature · 1 line
2.35.1
#6 lore raw

PATCH 7/8 pinctrl: moorefield: Convert to use new memeber in struct intel_function

In reply to Andy Shevchenko

Convert driver to use generic data type and hence a new member in the struct intel_function. No functional change intended.

---
 drivers/pinctrl/intel/pinctrl-moorefield.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pinctrl/intel/pinctrl-moorefield.c +3 -3
index e3eec671e15d..3c9a8484b442 100644
@@ -530,7 +530,7 @@ static const char *mofld_get_function_name(struct pinctrl_dev *pctldev, unsigned
 {
 	struct mofld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
 
-	return mp->functions[function].name;
+	return mp->functions[function].func.name;
 }
 
 static int mofld_get_function_groups(struct pinctrl_dev *pctldev, unsigned int function,
@@ -538,8 +538,8 @@ static int mofld_get_function_groups(struct pinctrl_dev *pctldev, unsigned int f
 {
 	struct mofld_pinctrl *mp = pinctrl_dev_get_drvdata(pctldev);
 
-	*groups = mp->functions[function].groups;
-	*ngroups = mp->functions[function].ngroups;
+	*groups = mp->functions[function].func.groups;
+	*ngroups = mp->functions[function].func.ngroups;
 	return 0;
 }
 
Signature · 1 line
2.35.1
#7 lore raw

PATCH 8/8 pinctrl: intel: Get rid of unused members in struct intel_function

In reply to Andy Shevchenko

The driver has been converted to a generic data type and macro for the pin function definition, hence get rid of not used members in the struct intel_function.

---
 drivers/pinctrl/intel/pinctrl-intel.h | 9 ---------
 1 file changed, 9 deletions(-)
drivers/pinctrl/intel/pinctrl-intel.h +0 -9
index 91e5bedba00b..1faf2ada480a 100644
@@ -37,15 +37,9 @@ struct intel_pingroup {
 /**
  * struct intel_function - Description about a function
  * @func: Generic data of the pin function (name and groups of pins)
- * @name: Name of the function
- * @groups: An array of groups for this function
- * @ngroups: Number of groups in @groups
  */
 struct intel_function {
 	struct pinfunction func;
-	const char *name;
-	const char * const *groups;
-	size_t ngroups;
 };
 
 #define INTEL_PINCTRL_MAX_GPP_SIZE	32
@@ -188,9 +182,6 @@ struct intel_community {
 #define FUNCTION(n, g)							\
 	{								\
 		.func = PINCTRL_PINFUNCTION((n), (g), ARRAY_SIZE(g)),	\
-		.name = (n),						\
-		.groups = (g),						\
-		.ngroups = ARRAY_SIZE((g)),				\
 	}
 
 /**
Signature · 1 line
2.35.1
#8 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are many pin control drivers define their own data type for pin function representation which is the same or embed the same data as newly introduced one. Provide the data type and convenient macro for all pin control drivers.

The stats for the entire series:

drivers/pinctrl/intel/pinctrl-baytrail.c   | 10 +++++-----
drivers/pinctrl/intel/pinctrl-cherryview.c |  6 +++---
drivers/pinctrl/intel/pinctrl-intel.c      |  6 +++---
drivers/pinctrl/intel/pinctrl-intel.h      | 16 +++++-----------
drivers/pinctrl/intel/pinctrl-lynxpoint.c  |  8 ++++----
drivers/pinctrl/intel/pinctrl-merrifield.c |  6 +++---
drivers/pinctrl/intel/pinctrl-moorefield.c |  6 +++---
include/linux/pinctrl/pinctrl.h            | 20 ++++++++++++++++++++
8 files changed, 46 insertions(+), 32 deletions(-)
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Acked-by
#9 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are many pin control drivers define their own data type for pin function representation which is the same or embed the same data as newly introduced one. Provide the data type and convenient macro for all pin control drivers.

The stats for the entire series:

Quoted 9 lines
drivers/pinctrl/intel/pinctrl-baytrail.c   | 10 +++++-----
drivers/pinctrl/intel/pinctrl-cherryview.c |  6 +++---
drivers/pinctrl/intel/pinctrl-intel.c      |  6 +++---
drivers/pinctrl/intel/pinctrl-intel.h      | 16 +++++-----------
drivers/pinctrl/intel/pinctrl-lynxpoint.c  |  8 ++++----
drivers/pinctrl/intel/pinctrl-merrifield.c |  6 +++---
drivers/pinctrl/intel/pinctrl-moorefield.c |  6 +++---
include/linux/pinctrl/pinctrl.h            | 20 ++++++++++++++++++++
8 files changed, 46 insertions(+), 32 deletions(-)

Thanks!

For the series,

#10 lore raw
Quoted 19 lines · Mika Westerberg
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

There are many pin control drivers define their own data type for pin function representation which is the same or embed the same data as newly introduced one. Provide the data type and convenient macro for all pin control drivers.

The stats for the entire series:

Quoted 9 lines
drivers/pinctrl/intel/pinctrl-baytrail.c   | 10 +++++-----
drivers/pinctrl/intel/pinctrl-cherryview.c |  6 +++---
drivers/pinctrl/intel/pinctrl-intel.c      |  6 +++---
drivers/pinctrl/intel/pinctrl-intel.h      | 16 +++++-----------
drivers/pinctrl/intel/pinctrl-lynxpoint.c  |  8 ++++----
drivers/pinctrl/intel/pinctrl-merrifield.c |  6 +++---
drivers/pinctrl/intel/pinctrl-moorefield.c |  6 +++---
include/linux/pinctrl/pinctrl.h            | 20 ++++++++++++++++++++
8 files changed, 46 insertions(+), 32 deletions(-)
Quoted 5 lines

Thanks!

For the series,

Pushed to my review and testing queue, thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v1 1/8
#11 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

There are many pin control drivers define their own data type for pin function representation which is the same or embed the same data as newly introduced one. Provide the data type and convenient macro for all pin control drivers.

Very nice and helpful!

Yours,
Linus Walleij