As promised to Linus W. there is a series that converts struct function_desc
to use struct pinfunction. With this it both struct group_desc and struct
function_desc will rely on the generic data types (struct pingroup and struct
pinfunction respectively). I haven't compiled everything, some builds might
fail. Anyway, comments, reviews, testing are all appreciated.
In v2:
- fixed compilation problems found so far by LKP
Andy Shevchenko (11):
pinctrl: berlin: Make use of struct pinfunction
pinctrl: equilibrium: Make use of struct pinfunction
pinctrl: ingenic: Provide a helper macro INGENIC_PIN_FUNCTION()
pinctrl: mediatek: Provide a helper macro PINCTRL_PIN_FUNCTION()
pinctrl: pinmux: Add a convenient define PINCTRL_FUNCTION_DESC()
pinctrl: pinmux: Embed struct pinfunction into struct function_desc
pinctrl: imx: Convert to use func member
pinctrl: ingenic: Convert to use func member
pinctrl: keembay: Convert to use func member
pinctrl: mediatek: Convert to use func member
pinctrl: pinmux: Remove unused members from struct function_desc
drivers/pinctrl/berlin/berlin.c | 21 +-
drivers/pinctrl/berlin/berlin.h | 6 -
drivers/pinctrl/core.h | 2 +-
drivers/pinctrl/freescale/pinctrl-imx.c | 14 +-
drivers/pinctrl/mediatek/pinctrl-moore.c | 10 +-
drivers/pinctrl/mediatek/pinctrl-moore.h | 6 +
drivers/pinctrl/mediatek/pinctrl-mt7622.c | 32 +-
drivers/pinctrl/mediatek/pinctrl-mt7623.c | 42 +-
drivers/pinctrl/mediatek/pinctrl-mt7629.c | 20 +-
drivers/pinctrl/mediatek/pinctrl-mt7981.c | 34 +-
drivers/pinctrl/mediatek/pinctrl-mt7986.c | 24 +-
drivers/pinctrl/pinctrl-equilibrium.c | 24 +-
drivers/pinctrl/pinctrl-equilibrium.h | 12 -
drivers/pinctrl/pinctrl-ingenic.c | 707 +++++++++++-----------
drivers/pinctrl/pinctrl-keembay.c | 22 +-
drivers/pinctrl/pinmux.c | 19 +-
drivers/pinctrl/pinmux.h | 19 +-
17 files changed, 503 insertions(+), 511 deletions(-)
--
2.45.1
From: Andy Shevchenko <[email protected]>
Since pin control provides a generic data type for the pin function,
use it in the driver.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/berlin/berlin.c | 21 +++++++++------------
drivers/pinctrl/berlin/berlin.h | 6 ------
2 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berlin.c
index 9550cc8095c2..c372a2a24be4 100644
--- a/drivers/pinctrl/berlin/berlin.c
+++ b/drivers/pinctrl/berlin/berlin.c
@@ -27,7 +27,7 @@ struct berlin_pinctrl {
struct regmap *regmap;
struct device *dev;
const struct berlin_pinctrl_desc *desc;
- struct berlin_pinctrl_function *functions;
+ struct pinfunction *functions;
unsigned nfunctions;
struct pinctrl_dev *pctrl_dev;
};
@@ -120,12 +120,12 @@ static const char *berlin_pinmux_get_function_name(struct pinctrl_dev *pctrl_dev
static int berlin_pinmux_get_function_groups(struct pinctrl_dev *pctrl_dev,
unsigned function,
const char * const **groups,
- unsigned * const num_groups)
+ unsigned * const ngroups)
{
struct berlin_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctrl_dev);
*groups = pctrl->functions[function].groups;
- *num_groups = pctrl->functions[function].ngroups;
+ *ngroups = pctrl->functions[function].ngroups;
return 0;
}
@@ -153,7 +153,7 @@ static int berlin_pinmux_set(struct pinctrl_dev *pctrl_dev,
{
struct berlin_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctrl_dev);
const struct berlin_desc_group *group_desc = pctrl->desc->groups + group;
- struct berlin_pinctrl_function *func = pctrl->functions + function;
+ struct pinfunction *func = pctrl->functions + function;
struct berlin_desc_function *function_desc =
berlin_pinctrl_find_function_by_name(pctrl, group_desc,
func->name);
@@ -180,7 +180,7 @@ static const struct pinmux_ops berlin_pinmux_ops = {
static int berlin_pinctrl_add_function(struct berlin_pinctrl *pctrl,
const char *name)
{
- struct berlin_pinctrl_function *function = pctrl->functions;
+ struct pinfunction *function = pctrl->functions;
while (function->name) {
if (!strcmp(function->name, name)) {
@@ -214,8 +214,7 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
}
/* we will reallocate later */
- pctrl->functions = kcalloc(max_functions,
- sizeof(*pctrl->functions), GFP_KERNEL);
+ pctrl->functions = kcalloc(max_functions, sizeof(*pctrl->functions), GFP_KERNEL);
if (!pctrl->functions)
return -ENOMEM;
@@ -242,8 +241,7 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
desc_function = desc_group->functions;
while (desc_function->name) {
- struct berlin_pinctrl_function
- *function = pctrl->functions;
+ struct pinfunction *function = pctrl->functions;
const char **groups;
bool found = false;
@@ -264,16 +262,15 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
function->groups =
devm_kcalloc(&pdev->dev,
function->ngroups,
- sizeof(char *),
+ sizeof(*function->groups),
GFP_KERNEL);
-
if (!function->groups) {
kfree(pctrl->functions);
return -ENOMEM;
}
}
- groups = function->groups;
+ groups = (const char **)function->groups;
while (*groups)
groups++;
diff --git a/drivers/pinctrl/berlin/berlin.h b/drivers/pinctrl/berlin/berlin.h
index d7787754d1ed..231aab61d415 100644
--- a/drivers/pinctrl/berlin/berlin.h
+++ b/drivers/pinctrl/berlin/berlin.h
@@ -28,12 +28,6 @@ struct berlin_pinctrl_desc {
unsigned ngroups;
};
-struct berlin_pinctrl_function {
- const char *name;
- const char **groups;
- unsigned ngroups;
-};
-
#define BERLIN_PINCTRL_GROUP(_name, _offset, _width, _lsb, ...) \
{ \
.name = _name, \
--
2.45.1
From: Andy Shevchenko <[email protected]>
Since pin control provides a generic data type for the pin function,
use it in the driver.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/pinctrl-equilibrium.c | 24 +++++++++++++-----------
drivers/pinctrl/pinctrl-equilibrium.h | 12 ------------
2 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-equilibrium.c b/drivers/pinctrl/pinctrl-equilibrium.c
index 6e1be38865c3..a6d089eaaae5 100644
--- a/drivers/pinctrl/pinctrl-equilibrium.c
+++ b/drivers/pinctrl/pinctrl-equilibrium.c
@@ -566,8 +566,8 @@ static const struct pinconf_ops eqbr_pinconf_ops = {
.pin_config_config_dbg_show = pinconf_generic_dump_config,
};
-static bool is_func_exist(struct eqbr_pmx_func *funcs, const char *name,
- unsigned int nr_funcs, unsigned int *idx)
+static bool is_func_exist(struct pinfunction *funcs, const char *name,
+ unsigned int nr_funcs, unsigned int *idx)
{
int i;
@@ -584,13 +584,14 @@ static bool is_func_exist(struct eqbr_pmx_func *funcs, const char *name,
return false;
}
-static int funcs_utils(struct device *dev, struct eqbr_pmx_func *funcs,
+static int funcs_utils(struct device *dev, struct pinfunction *funcs,
unsigned int *nr_funcs, funcs_util_ops op)
{
struct device_node *node = dev->of_node;
struct device_node *np;
struct property *prop;
const char *fn_name;
+ const char **groups;
unsigned int fid;
int i, j;
@@ -620,15 +621,16 @@ static int funcs_utils(struct device *dev, struct eqbr_pmx_func *funcs,
case OP_COUNT_NR_FUNC_GRPS:
if (is_func_exist(funcs, fn_name, *nr_funcs, &fid))
- funcs[fid].nr_groups++;
+ funcs[fid].ngroups++;
break;
case OP_ADD_FUNC_GRPS:
if (is_func_exist(funcs, fn_name, *nr_funcs, &fid)) {
- for (j = 0; j < funcs[fid].nr_groups; j++)
- if (!funcs[fid].groups[j])
+ groups = (const char **)funcs[fid].groups;
+ for (j = 0; j < funcs[fid].ngroups; j++)
+ if (!groups[j])
break;
- funcs[fid].groups[j] = prop->value;
+ groups[j] = prop->value;
}
break;
@@ -645,7 +647,7 @@ static int funcs_utils(struct device *dev, struct eqbr_pmx_func *funcs,
static int eqbr_build_functions(struct eqbr_pinctrl_drv_data *drvdata)
{
struct device *dev = drvdata->dev;
- struct eqbr_pmx_func *funcs = NULL;
+ struct pinfunction *funcs = NULL;
unsigned int nr_funcs = 0;
int i, ret;
@@ -666,9 +668,9 @@ static int eqbr_build_functions(struct eqbr_pinctrl_drv_data *drvdata)
return ret;
for (i = 0; i < nr_funcs; i++) {
- if (!funcs[i].nr_groups)
+ if (!funcs[i].ngroups)
continue;
- funcs[i].groups = devm_kcalloc(dev, funcs[i].nr_groups,
+ funcs[i].groups = devm_kcalloc(dev, funcs[i].ngroups,
sizeof(*(funcs[i].groups)),
GFP_KERNEL);
if (!funcs[i].groups)
@@ -688,7 +690,7 @@ static int eqbr_build_functions(struct eqbr_pinctrl_drv_data *drvdata)
ret = pinmux_generic_add_function(drvdata->pctl_dev,
funcs[i].name,
funcs[i].groups,
- funcs[i].nr_groups,
+ funcs[i].ngroups,
drvdata);
if (ret < 0) {
dev_err(dev, "Failed to register function %s\n",
diff --git a/drivers/pinctrl/pinctrl-equilibrium.h b/drivers/pinctrl/pinctrl-equilibrium.h
index 83768cc8b3db..b4d149bde39d 100644
--- a/drivers/pinctrl/pinctrl-equilibrium.h
+++ b/drivers/pinctrl/pinctrl-equilibrium.h
@@ -67,18 +67,6 @@ struct gpio_irq_type {
unsigned int logic_type;
};
-/**
- * struct eqbr_pmx_func: represent a pin function.
- * @name: name of the pin function, used to lookup the function.
- * @groups: one or more names of pin groups that provide this function.
- * @nr_groups: number of groups included in @groups.
- */
-struct eqbr_pmx_func {
- const char *name;
- const char **groups;
- unsigned int nr_groups;
-};
-
/**
* struct eqbr_pin_bank: represent a pin bank.
* @membase: base address of the pin bank register.
--
2.45.1
Convert drivers to use func member embedded in struct function_desc,
because other members will be removed to avoid duplication and
desynchronisation of the generic pin function description.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/pinctrl-ingenic.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-ingenic.c b/drivers/pinctrl/pinctrl-ingenic.c
index 959b9ea83a66..31703737731b 100644
--- a/drivers/pinctrl/pinctrl-ingenic.c
+++ b/drivers/pinctrl/pinctrl-ingenic.c
@@ -96,9 +96,7 @@
#define INGENIC_PIN_FUNCTION(_name_, id) \
{ \
- .name = _name_, \
- .group_names = id##_groups, \
- .num_group_names = ARRAY_SIZE(id##_groups), \
+ .func = PINCTRL_PINFUNCTION(_name_, id##_groups, ARRAY_SIZE(id##_groups)), \
.data = NULL, \
}
@@ -3769,7 +3767,7 @@ 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->grp.name);
+ func->func.name, grp->grp.name);
mode = (uintptr_t)grp->data;
if (mode <= 3) {
@@ -4317,14 +4315,14 @@ static int __init ingenic_pinctrl_probe(struct platform_device *pdev)
}
for (i = 0; i < chip_info->num_functions; i++) {
- const struct function_desc *func = &chip_info->functions[i];
+ const struct function_desc *function = &chip_info->functions[i];
+ const struct pinfunction *func = &function->func;
err = pinmux_generic_add_function(jzpc->pctl, func->name,
- func->group_names, func->num_group_names,
- func->data);
+ func->groups, func->ngroups,
+ function->data);
if (err < 0) {
- dev_err(dev, "Failed to register function %s\n",
- func->name);
+ dev_err(dev, "Failed to register function %s\n", func->name);
return err;
}
}
--
2.45.1
Convert drivers to use func member embedded in struct function_desc,
because other members will be removed to avoid duplication and
desynchronisation of the generic pin function description.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/freescale/pinctrl-imx.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index 2d3d80921c0d..44921e3bdb94 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -266,7 +266,7 @@ static int imx_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
npins = grp->grp.npins;
dev_dbg(ipctl->dev, "enable function %s group %s\n",
- func->name, grp->grp.name);
+ func->func.name, grp->grp.name);
for (i = 0; i < npins; i++) {
/*
@@ -593,21 +593,21 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
return -EINVAL;
/* Initialise function */
- func->name = np->name;
- func->num_group_names = of_get_child_count(np);
- if (func->num_group_names == 0) {
+ func->func.name = np->name;
+ func->func.ngroups = of_get_child_count(np);
+ if (func->func.ngroups == 0) {
dev_info(ipctl->dev, "no groups defined in %pOF\n", np);
return -EINVAL;
}
- group_names = devm_kcalloc(ipctl->dev, func->num_group_names,
- sizeof(char *), GFP_KERNEL);
+ group_names = devm_kcalloc(ipctl->dev, func->ngroups, sizeof(*func->func.groups),
+ GFP_KERNEL);
if (!group_names)
return -ENOMEM;
i = 0;
for_each_child_of_node(np, child)
group_names[i++] = child->name;
- func->group_names = group_names;
+ func->func.groups = group_names;
i = 0;
for_each_child_of_node(np, child) {
--
2.45.1
From: Andy Shevchenko <[email protected]>
Add PINCTRL_FUNCTION_DESC() macro for inline use.
While at it, fix adjective form in the comment of PINCTRL_GROUP_DESC().
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pinctrl/core.h | 2 +-
drivers/pinctrl/pinmux.c | 9 +++------
drivers/pinctrl/pinmux.h | 11 ++++++++++-
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h
index 837fd5bd903d..4e07707d2435 100644
--- a/drivers/pinctrl/core.h
+++ b/drivers/pinctrl/core.h
@@ -206,7 +206,7 @@ struct group_desc {
void *data;
};
-/* Convenience macro to define a generic pin group descriptor */
+/* Convenient macro to define a generic pin group descriptor */
#define PINCTRL_GROUP_DESC(_name, _pins, _num_pins, _data) \
(struct group_desc) { \
.grp = PINCTRL_PINGROUP(_name, _pins, _num_pins), \
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index addba55334d9..8d69fa1b0bff 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -852,13 +852,13 @@ EXPORT_SYMBOL_GPL(pinmux_generic_get_function);
* @pctldev: pin controller device
* @name: name of the function
* @groups: array of pin groups
- * @num_groups: number of pin groups
+ * @ngroups: number of pin groups
* @data: pin controller driver specific data
*/
int pinmux_generic_add_function(struct pinctrl_dev *pctldev,
const char *name,
const char * const *groups,
- const unsigned int num_groups,
+ const unsigned int ngroups,
void *data)
{
struct function_desc *function;
@@ -877,10 +877,7 @@ int pinmux_generic_add_function(struct pinctrl_dev *pctldev,
if (!function)
return -ENOMEM;
- function->name = name;
- function->group_names = groups;
- function->num_group_names = num_groups;
- function->data = data;
+ *function = PINCTRL_FUNCTION_DESC(name, groups, ngroups, data);
error = radix_tree_insert(&pctldev->pin_function_tree, selector, function);
if (error)
diff --git a/drivers/pinctrl/pinmux.h b/drivers/pinctrl/pinmux.h
index 7c8aa25ccc80..52e6e4db88b4 100644
--- a/drivers/pinctrl/pinmux.h
+++ b/drivers/pinctrl/pinmux.h
@@ -145,6 +145,15 @@ struct function_desc {
void *data;
};
+/* Convenient macro to define a generic pin function descriptor */
+#define PINCTRL_FUNCTION_DESC(_name, _grps, _num_grps, _data) \
+(struct function_desc) { \
+ .name = _name, \
+ .group_names = _grps, \
+ .num_group_names = _num_grps, \
+ .data = _data, \
+}
+
int pinmux_generic_get_function_count(struct pinctrl_dev *pctldev);
const char *
@@ -162,7 +171,7 @@ struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev,
int pinmux_generic_add_function(struct pinctrl_dev *pctldev,
const char *name,
const char * const *groups,
- unsigned int const num_groups,
+ unsigned int const ngroups,
void *data);
int pinmux_generic_remove_function(struct pinctrl_dev *pctldev,
--
2.45.1
Hi Andy,
kernel test robot noticed the following build errors:
[auto build test ERROR on linusw-pinctrl/devel]
[also build test ERROR on linusw-pinctrl/for-next linus/master v6.10-rc1 next-20240529]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/pinctrl-berlin-Make-use-of-struct-pinfunction/20240529-035554
base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
patch link: https://lore.kernel.org/r/20240528194951.1489887-8-andy.shevchenko%40gmail.com
patch subject: [PATCH v2 07/11] pinctrl: imx: Convert to use func member
config: microblaze-allyesconfig (https://download.01.org/0day-ci/archive/20240530/[email protected]/config)
compiler: microblaze-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240530/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/pinctrl/freescale/pinctrl-imx.c: In function 'imx_pinctrl_parse_functions':
>> drivers/pinctrl/freescale/pinctrl-imx.c:603:52: error: 'struct function_desc' has no member named 'ngroups'
603 | group_names = devm_kcalloc(ipctl->dev, func->ngroups, sizeof(*func->func.groups),
| ^~
vim +603 drivers/pinctrl/freescale/pinctrl-imx.c
577
578 static int imx_pinctrl_parse_functions(struct device_node *np,
579 struct imx_pinctrl *ipctl,
580 u32 index)
581 {
582 struct pinctrl_dev *pctl = ipctl->pctl;
583 struct device_node *child;
584 struct function_desc *func;
585 struct group_desc *grp;
586 const char **group_names;
587 u32 i;
588
589 dev_dbg(pctl->dev, "parse function(%d): %pOFn\n", index, np);
590
591 func = pinmux_generic_get_function(pctl, index);
592 if (!func)
593 return -EINVAL;
594
595 /* Initialise function */
596 func->func.name = np->name;
597 func->func.ngroups = of_get_child_count(np);
598 if (func->func.ngroups == 0) {
599 dev_info(ipctl->dev, "no groups defined in %pOF\n", np);
600 return -EINVAL;
601 }
602
> 603 group_names = devm_kcalloc(ipctl->dev, func->ngroups, sizeof(*func->func.groups),
604 GFP_KERNEL);
605 if (!group_names)
606 return -ENOMEM;
607 i = 0;
608 for_each_child_of_node(np, child)
609 group_names[i++] = child->name;
610 func->func.groups = group_names;
611
612 i = 0;
613 for_each_child_of_node(np, child) {
614 grp = devm_kzalloc(ipctl->dev, sizeof(*grp), GFP_KERNEL);
615 if (!grp) {
616 of_node_put(child);
617 return -ENOMEM;
618 }
619
620 mutex_lock(&ipctl->mutex);
621 radix_tree_insert(&pctl->pin_group_tree,
622 ipctl->group_index++, grp);
623 mutex_unlock(&ipctl->mutex);
624
625 imx_pinctrl_parse_groups(child, grp, ipctl, i++);
626 }
627
628 return 0;
629 }
630
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki