diff mbox series

[v3,5/6] pinctrl: s32cc: Use generic struct data to describe pin function

Message ID 20230323144833.28562-6-clin@suse.com (mailing list archive)
State New, archived
Headers show
Series pinctrl: s32: driver improvements and generic struct use | expand

Commit Message

Chester Lin March 23, 2023, 2:48 p.m. UTC
Replace struct s32_pmx_func with generic struct pinfunction since they
have the same data fields.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Chester Lin <clin@suse.com>
---
Changes in v3:
- Separate the generic pinfunction patch from [PATCH v2 4/4]
- Fix the data type declaration and remove unncessary type casting
  developed in v2.

 drivers/pinctrl/nxp/pinctrl-s32.h   | 14 +-------------
 drivers/pinctrl/nxp/pinctrl-s32cc.c | 18 +++++++++++-------
 2 files changed, 12 insertions(+), 20 deletions(-)

Comments

Andy Shevchenko March 23, 2023, 6:49 p.m. UTC | #1
On Thu, Mar 23, 2023 at 4:49 PM Chester Lin <clin@suse.com> wrote:
>
> Replace struct s32_pmx_func with generic struct pinfunction since they
> have the same data fields.

LGTM,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Chester Lin <clin@suse.com>
> ---
> Changes in v3:
> - Separate the generic pinfunction patch from [PATCH v2 4/4]
> - Fix the data type declaration and remove unncessary type casting
>   developed in v2.
>
>  drivers/pinctrl/nxp/pinctrl-s32.h   | 14 +-------------
>  drivers/pinctrl/nxp/pinctrl-s32cc.c | 18 +++++++++++-------
>  2 files changed, 12 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/pinctrl/nxp/pinctrl-s32.h b/drivers/pinctrl/nxp/pinctrl-s32.h
> index 850cd668f406..2f7aecd462e4 100644
> --- a/drivers/pinctrl/nxp/pinctrl-s32.h
> +++ b/drivers/pinctrl/nxp/pinctrl-s32.h
> @@ -24,18 +24,6 @@ struct s32_pin_group {
>         unsigned int *pin_sss;
>  };
>
> -/**
> - * struct s32_pmx_func - describes S32 pinmux functions
> - * @name: the name of this specific function
> - * @groups: corresponding pin groups
> - * @num_groups: the number of groups
> - */
> -struct s32_pmx_func {
> -       const char *name;
> -       const char **groups;
> -       unsigned int num_groups;
> -};
> -
>  /**
>   * struct s32_pin_range - pin ID range for each memory region.
>   * @start: start pin ID
> @@ -52,7 +40,7 @@ struct s32_pinctrl_soc_info {
>         unsigned int npins;
>         struct s32_pin_group *groups;
>         unsigned int ngroups;
> -       struct s32_pmx_func *functions;
> +       struct pinfunction *functions;
>         unsigned int nfunctions;
>         unsigned int grp_index;
>         const struct s32_pin_range *mem_pin_ranges;
> diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
> index e65c88162d7f..8373468719b6 100644
> --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
> +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
> @@ -364,7 +364,7 @@ static int s32_pmx_get_groups(struct pinctrl_dev *pctldev,
>         const struct s32_pinctrl_soc_info *info = ipctl->info;
>
>         *groups = info->functions[selector].groups;
> -       *num_groups = info->functions[selector].num_groups;
> +       *num_groups = info->functions[selector].ngroups;
>
>         return 0;
>  }
> @@ -785,8 +785,9 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
>                                         u32 index)
>  {
>         struct device_node *child;
> -       struct s32_pmx_func *func;
> +       struct pinfunction *func;
>         struct s32_pin_group *grp;
> +       const char **groups;
>         u32 i = 0;
>         int ret = 0;
>
> @@ -796,18 +797,19 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
>
>         /* Initialise function */
>         func->name = np->name;
> -       func->num_groups = of_get_child_count(np);
> -       if (func->num_groups == 0) {
> +       func->ngroups = of_get_child_count(np);
> +       if (func->ngroups == 0) {
>                 dev_err(info->dev, "no groups defined in %pOF\n", np);
>                 return -EINVAL;
>         }
> -       func->groups = devm_kcalloc(info->dev, func->num_groups,
> +
> +       groups = devm_kcalloc(info->dev, func->ngroups,
>                                     sizeof(*func->groups), GFP_KERNEL);
> -       if (!func->groups)
> +       if (!groups)
>                 return -ENOMEM;
>
>         for_each_child_of_node(np, child) {
> -               func->groups[i] = child->name;
> +               groups[i] = child->name;
>                 grp = &info->groups[info->grp_index++];
>                 ret = s32_pinctrl_parse_groups(child, grp, info);
>                 if (ret)
> @@ -815,6 +817,8 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
>                 i++;
>         }
>
> +       func->groups = groups;
> +
>         return 0;
>  }
>
> --
> 2.37.3
>
diff mbox series

Patch

diff --git a/drivers/pinctrl/nxp/pinctrl-s32.h b/drivers/pinctrl/nxp/pinctrl-s32.h
index 850cd668f406..2f7aecd462e4 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32.h
+++ b/drivers/pinctrl/nxp/pinctrl-s32.h
@@ -24,18 +24,6 @@  struct s32_pin_group {
 	unsigned int *pin_sss;
 };
 
-/**
- * struct s32_pmx_func - describes S32 pinmux functions
- * @name: the name of this specific function
- * @groups: corresponding pin groups
- * @num_groups: the number of groups
- */
-struct s32_pmx_func {
-	const char *name;
-	const char **groups;
-	unsigned int num_groups;
-};
-
 /**
  * struct s32_pin_range - pin ID range for each memory region.
  * @start: start pin ID
@@ -52,7 +40,7 @@  struct s32_pinctrl_soc_info {
 	unsigned int npins;
 	struct s32_pin_group *groups;
 	unsigned int ngroups;
-	struct s32_pmx_func *functions;
+	struct pinfunction *functions;
 	unsigned int nfunctions;
 	unsigned int grp_index;
 	const struct s32_pin_range *mem_pin_ranges;
diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index e65c88162d7f..8373468719b6 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -364,7 +364,7 @@  static int s32_pmx_get_groups(struct pinctrl_dev *pctldev,
 	const struct s32_pinctrl_soc_info *info = ipctl->info;
 
 	*groups = info->functions[selector].groups;
-	*num_groups = info->functions[selector].num_groups;
+	*num_groups = info->functions[selector].ngroups;
 
 	return 0;
 }
@@ -785,8 +785,9 @@  static int s32_pinctrl_parse_functions(struct device_node *np,
 					u32 index)
 {
 	struct device_node *child;
-	struct s32_pmx_func *func;
+	struct pinfunction *func;
 	struct s32_pin_group *grp;
+	const char **groups;
 	u32 i = 0;
 	int ret = 0;
 
@@ -796,18 +797,19 @@  static int s32_pinctrl_parse_functions(struct device_node *np,
 
 	/* Initialise function */
 	func->name = np->name;
-	func->num_groups = of_get_child_count(np);
-	if (func->num_groups == 0) {
+	func->ngroups = of_get_child_count(np);
+	if (func->ngroups == 0) {
 		dev_err(info->dev, "no groups defined in %pOF\n", np);
 		return -EINVAL;
 	}
-	func->groups = devm_kcalloc(info->dev, func->num_groups,
+
+	groups = devm_kcalloc(info->dev, func->ngroups,
 				    sizeof(*func->groups), GFP_KERNEL);
-	if (!func->groups)
+	if (!groups)
 		return -ENOMEM;
 
 	for_each_child_of_node(np, child) {
-		func->groups[i] = child->name;
+		groups[i] = child->name;
 		grp = &info->groups[info->grp_index++];
 		ret = s32_pinctrl_parse_groups(child, grp, info);
 		if (ret)
@@ -815,6 +817,8 @@  static int s32_pinctrl_parse_functions(struct device_node *np,
 		i++;
 	}
 
+	func->groups = groups;
+
 	return 0;
 }