Hello,
This patch series contains some improvements for s32 pinctrl drivers suggested
by upstream[1], such as
- Fix error shadowings and improve return value handlings.
- Fix print format.
- Remove unnecessary blanks.
- Use proper macros and helpers to simplify codes.
- Refactor config param parsing and remove config arguments that are never used.
- Use generic struct pingroup and struct pinfunction to describe pin data.
Regards,
Chester
[1] https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Remove unnecessary type casting and correct type qualifiers.
- Split the previous generic-struct patch [v2 4/4] into two separate patches.
- Add a new patch [v3 6/6] to attach a real const .data with of_device_id.
Changes in v2:
- Link: https://lore.kernel.org/lkml/[email protected]/
- Use of_device_get_match_data() to get matched of_device_id data.
- Enhance sizeof() arguments.
- Fix blanks and remove unnecessary parentheses.
- Drop unnecessary marcos and s32_pin_config() implemented in v1 and set/clear
mask/config values transparently.
- Put pull-function related cases together in s32_pin_set_pull().
- Simply use generic 'struct pinfunction' rather than having extra 'struct
s32_pmx_func'.
Chester Lin (6):
pinctrl: s32g2: use of_device_get_match_data() to get device data
pinctrl: s32: refine error/return/config checks and simplify driver
codes
pinctrl: s32cc: refactor pin config parsing
pinctrl: s32cc: embed generic struct pingroup
pinctrl: s32cc: Use generic struct data to describe pin function
pinctrl: s32: separate const device data from struct
s32_pinctrl_soc_info
drivers/pinctrl/nxp/pinctrl-s32.h | 40 ++--
drivers/pinctrl/nxp/pinctrl-s32cc.c | 282 ++++++++++++++++------------
drivers/pinctrl/nxp/pinctrl-s32g2.c | 17 +-
3 files changed, 178 insertions(+), 161 deletions(-)
--
2.37.3
Choose of_device_get_match_data() instead of indirect reference via
of_match_device() so that the implementation can be more concise.
Suggested-by: Andy Shevchenko <[email protected]>
Signed-off-by: Chester Lin <[email protected]>
---
Changes in v3:
- Declare the struct var 'info' as const and remove unnecessary type casting.
drivers/pinctrl/nxp/pinctrl-s32g2.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/pinctrl/nxp/pinctrl-s32g2.c b/drivers/pinctrl/nxp/pinctrl-s32g2.c
index 5028f4adc389..0e2d93681769 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32g2.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32g2.c
@@ -740,14 +740,11 @@ MODULE_DEVICE_TABLE(of, s32_pinctrl_of_match);
static int s32g_pinctrl_probe(struct platform_device *pdev)
{
- const struct of_device_id *of_id =
- of_match_device(s32_pinctrl_of_match, &pdev->dev);
+ const struct s32_pinctrl_soc_info *info;
- if (!of_id)
- return -ENODEV;
+ info = of_device_get_match_data(&pdev->dev);
- return s32_pinctrl_probe
- (pdev, (struct s32_pinctrl_soc_info *) of_id->data);
+ return s32_pinctrl_probe(pdev, info);
}
static const struct dev_pm_ops s32g_pinctrl_pm_ops = {
--
2.37.3
Improve error/return code handlings and config checks in order to have
better reliability and simplify driver codes such as removing/changing
improper macros, blanks, print formats and helper calls.
Signed-off-by: Chester Lin <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
---
(No change since v2)
drivers/pinctrl/nxp/pinctrl-s32cc.c | 141 +++++++++++++++-------------
drivers/pinctrl/nxp/pinctrl-s32g2.c | 4 +-
2 files changed, 76 insertions(+), 69 deletions(-)
diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index e1da332433a3..f698e1a240ef 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -28,7 +28,8 @@
#include "../pinctrl-utils.h"
#include "pinctrl-s32.h"
-#define S32_PIN_ID_MASK GENMASK(31, 4)
+#define S32_PIN_ID_SHIFT 4
+#define S32_PIN_ID_MASK GENMASK(31, S32_PIN_ID_SHIFT)
#define S32_MSCR_SSS_MASK GENMASK(2, 0)
#define S32_MSCR_PUS BIT(12)
@@ -46,7 +47,7 @@ static struct regmap_config s32_regmap_config = {
static u32 get_pin_no(u32 pinmux)
{
- return (pinmux & S32_PIN_ID_MASK) >> __ffs(S32_PIN_ID_MASK);
+ return (pinmux & S32_PIN_ID_MASK) >> S32_PIN_ID_SHIFT;
}
static u32 get_pin_func(u32 pinmux)
@@ -108,7 +109,7 @@ s32_get_region(struct pinctrl_dev *pctldev, unsigned int pin)
unsigned int mem_regions = ipctl->info->mem_regions;
unsigned int i;
- for (i = 0; i < mem_regions; ++i) {
+ for (i = 0; i < mem_regions; i++) {
pin_range = ipctl->regions[i].pin_range;
if (pin >= pin_range->start && pin <= pin_range->end)
return &ipctl->regions[i];
@@ -224,8 +225,7 @@ static int s32_dt_group_node_to_map(struct pinctrl_dev *pctldev,
n_pins = of_property_count_elems_of_size(np, "pinmux", sizeof(u32));
if (n_pins < 0) {
- dev_warn(dev, "Unable to find 'pinmux' property in node %s.\n",
- np->name);
+ dev_warn(dev, "Can't find 'pinmux' property in node %pOFn\n", np);
} else if (!n_pins) {
return -EINVAL;
}
@@ -317,20 +317,25 @@ static int s32_pmx_set(struct pinctrl_dev *pctldev, unsigned int selector,
info->functions[selector].name, grp->name);
/* Check beforehand so we don't have a partial config. */
- for (i = 0; i < grp->npins; ++i) {
+ for (i = 0; i < grp->npins; i++) {
if (s32_check_pin(pctldev, grp->pin_ids[i]) != 0) {
- dev_err(info->dev, "invalid pin: %d in group: %d\n",
+ dev_err(info->dev, "invalid pin: %u in group: %u\n",
grp->pin_ids[i], group);
return -EINVAL;
}
}
- for (i = 0, ret = 0; i < grp->npins && !ret; ++i) {
+ for (i = 0, ret = 0; i < grp->npins && !ret; i++) {
ret = s32_regmap_update(pctldev, grp->pin_ids[i],
S32_MSCR_SSS_MASK, grp->pin_sss[i]);
+ if (ret) {
+ dev_err(info->dev, "Failed to set pin %u\n",
+ grp->pin_ids[i]);
+ return ret;
+ }
}
- return ret;
+ return 0;
}
static int s32_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
@@ -375,8 +380,8 @@ static int s32_pmx_gpio_request_enable(struct pinctrl_dev *pctldev,
int ret;
ret = s32_regmap_read(pctldev, offset, &config);
- if (ret != 0)
- return -EINVAL;
+ if (ret)
+ return ret;
/* Save current configuration */
gpio_pin = kmalloc(sizeof(*gpio_pin), GFP_KERNEL);
@@ -387,7 +392,7 @@ static int s32_pmx_gpio_request_enable(struct pinctrl_dev *pctldev,
gpio_pin->config = config;
spin_lock_irqsave(&ipctl->gpio_configs_lock, flags);
- list_add(&(gpio_pin->list), &(ipctl->gpio_configs));
+ list_add(&gpio_pin->list, &ipctl->gpio_configs);
spin_unlock_irqrestore(&ipctl->gpio_configs_lock, flags);
/* GPIO pin means SSS = 0 */
@@ -401,23 +406,20 @@ static void s32_pmx_gpio_disable_free(struct pinctrl_dev *pctldev,
unsigned int offset)
{
struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
- struct list_head *pos, *tmp;
- struct gpio_pin_config *gpio_pin;
+ struct gpio_pin_config *gpio_pin, *tmp;
unsigned long flags;
int ret;
spin_lock_irqsave(&ipctl->gpio_configs_lock, flags);
- list_for_each_safe(pos, tmp, &ipctl->gpio_configs) {
- gpio_pin = list_entry(pos, struct gpio_pin_config, list);
-
+ list_for_each_entry_safe(gpio_pin, tmp, &ipctl->gpio_configs, list) {
if (gpio_pin->pin_id == offset) {
ret = s32_regmap_write(pctldev, gpio_pin->pin_id,
gpio_pin->config);
if (ret != 0)
goto unlock;
- list_del(pos);
+ list_del(&gpio_pin->list);
kfree(gpio_pin);
break;
}
@@ -461,7 +463,8 @@ static const int support_slew[] = {208, -1, -1, -1, 166, 150, 133, 83};
static int s32_get_slew_regval(int arg)
{
- int i;
+ unsigned int i;
+
/* Translate a real slew rate (MHz) to a register value */
for (i = 0; i < ARRAY_SIZE(support_slew); i++) {
if (arg == support_slew[i])
@@ -542,10 +545,11 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev,
unsigned int config = 0, mask = 0;
int i, ret;
- if (s32_check_pin(pctldev, pin_id) != 0)
- return -EINVAL;
+ ret = s32_check_pin(pctldev, pin_id);
+ if (ret)
+ return ret;
- dev_dbg(ipctl->dev, "pinconf set pin %s with %d configs\n",
+ dev_dbg(ipctl->dev, "pinconf set pin %s with %u configs\n",
pin_get_name(pctldev, pin_id), num_configs);
for (i = 0; i < num_configs; i++) {
@@ -559,11 +563,9 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev,
if (!config && !mask)
return 0;
- ret = s32_regmap_update(pctldev, pin_id, mask, config);
+ dev_dbg(ipctl->dev, "update: pin %u cfg 0x%x\n", pin_id, config);
- dev_dbg(ipctl->dev, "update: pin %d cfg 0x%x\n", pin_id, config);
-
- return ret;
+ return s32_regmap_update(pctldev, pin_id, mask, config);
}
static int s32_pinconf_get(struct pinctrl_dev *pctldev,
@@ -604,10 +606,13 @@ static void s32_pinconf_dbg_show(struct pinctrl_dev *pctldev,
struct seq_file *s, unsigned int pin_id)
{
unsigned int config;
- int ret = s32_regmap_read(pctldev, pin_id, &config);
+ int ret;
- if (!ret)
- seq_printf(s, "0x%x", config);
+ ret = s32_regmap_read(pctldev, pin_id, &config);
+ if (ret)
+ return;
+
+ seq_printf(s, "0x%x", config);
}
static void s32_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
@@ -710,7 +715,7 @@ int s32_pinctrl_resume(struct device *dev)
}
#endif
-static void s32_pinctrl_parse_groups(struct device_node *np,
+static int s32_pinctrl_parse_groups(struct device_node *np,
struct s32_pin_group *grp,
struct s32_pinctrl_soc_info *info)
{
@@ -722,21 +727,20 @@ static void s32_pinctrl_parse_groups(struct device_node *np,
dev = info->dev;
- dev_dbg(dev, "group: %s\n", np->name);
+ dev_dbg(dev, "group: %pOFn\n", np);
/* Initialise group */
grp->name = np->name;
npins = of_property_count_elems_of_size(np, "pinmux", sizeof(u32));
-
if (npins < 0) {
dev_err(dev, "Failed to read 'pinmux' property in node %s.\n",
- np->name);
- return;
+ grp->name);
+ return -EINVAL;
}
if (!npins) {
- dev_err(dev, "The group %s has no pins.\n", np->name);
- return;
+ dev_err(dev, "The group %s has no pins.\n", grp->name);
+ return -EINVAL;
}
grp->npins = npins;
@@ -745,12 +749,8 @@ static void s32_pinctrl_parse_groups(struct device_node *np,
sizeof(unsigned int), GFP_KERNEL);
grp->pin_sss = devm_kcalloc(info->dev, grp->npins,
sizeof(unsigned int), GFP_KERNEL);
-
- if (!grp->pin_ids || !grp->pin_sss) {
- dev_err(dev, "Failed to allocate memory for the group %s.\n",
- np->name);
- return;
- }
+ if (!grp->pin_ids || !grp->pin_sss)
+ return -ENOMEM;
i = 0;
of_property_for_each_u32(np, "pinmux", prop, p, pinmux) {
@@ -761,9 +761,11 @@ static void s32_pinctrl_parse_groups(struct device_node *np,
grp->pin_ids[i], grp->pin_sss[i]);
i++;
}
+
+ return 0;
}
-static void s32_pinctrl_parse_functions(struct device_node *np,
+static int s32_pinctrl_parse_functions(struct device_node *np,
struct s32_pinctrl_soc_info *info,
u32 index)
{
@@ -771,8 +773,9 @@ static void s32_pinctrl_parse_functions(struct device_node *np,
struct s32_pmx_func *func;
struct s32_pin_group *grp;
u32 i = 0;
+ int ret = 0;
- dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name);
+ dev_dbg(info->dev, "parse function(%u): %pOFn\n", index, np);
func = &info->functions[index];
@@ -780,18 +783,24 @@ static void s32_pinctrl_parse_functions(struct device_node *np,
func->name = np->name;
func->num_groups = of_get_child_count(np);
if (func->num_groups == 0) {
- dev_err(info->dev, "no groups defined in %s\n", np->full_name);
- return;
+ dev_err(info->dev, "no groups defined in %pOF\n", np);
+ return -EINVAL;
}
- func->groups = devm_kzalloc(info->dev,
- func->num_groups * sizeof(char *), GFP_KERNEL);
+ func->groups = devm_kcalloc(info->dev, func->num_groups,
+ sizeof(*func->groups), GFP_KERNEL);
+ if (!func->groups)
+ return -ENOMEM;
for_each_child_of_node(np, child) {
func->groups[i] = child->name;
grp = &info->groups[info->grp_index++];
- s32_pinctrl_parse_groups(child, grp, info);
+ ret = s32_pinctrl_parse_groups(child, grp, info);
+ if (ret)
+ return ret;
i++;
}
+
+ return 0;
}
static int s32_pinctrl_probe_dt(struct platform_device *pdev,
@@ -804,6 +813,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
struct regmap *map;
void __iomem *base;
int mem_regions = info->mem_regions;
+ int ret;
u32 nfuncs = 0;
u32 i = 0;
@@ -815,13 +825,12 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
return -EINVAL;
}
- ipctl->regions = devm_kzalloc(&pdev->dev,
- mem_regions * sizeof(*(ipctl->regions)),
- GFP_KERNEL);
+ ipctl->regions = devm_kcalloc(&pdev->dev, mem_regions,
+ sizeof(*ipctl->regions), GFP_KERNEL);
if (!ipctl->regions)
return -ENOMEM;
- for (i = 0; i < mem_regions; ++i) {
+ for (i = 0; i < mem_regions; i++) {
base = devm_platform_get_and_ioremap_resource(pdev, i, &res);
if (IS_ERR(base))
return PTR_ERR(base);
@@ -851,24 +860,26 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
}
info->nfunctions = nfuncs;
- info->functions = devm_kzalloc(&pdev->dev,
- nfuncs * sizeof(struct s32_pmx_func),
- GFP_KERNEL);
+ info->functions = devm_kcalloc(&pdev->dev, nfuncs,
+ sizeof(*info->functions), GFP_KERNEL);
if (!info->functions)
return -ENOMEM;
info->ngroups = 0;
for_each_child_of_node(np, child)
info->ngroups += of_get_child_count(child);
- info->groups = devm_kzalloc(&pdev->dev,
- info->ngroups * sizeof(struct s32_pin_group),
- GFP_KERNEL);
+
+ info->groups = devm_kcalloc(&pdev->dev, info->ngroups,
+ sizeof(*info->groups), GFP_KERNEL);
if (!info->groups)
return -ENOMEM;
i = 0;
- for_each_child_of_node(np, child)
- s32_pinctrl_parse_functions(child, info, i++);
+ for_each_child_of_node(np, child) {
+ ret = s32_pinctrl_parse_functions(child, info, i++);
+ if (ret)
+ return ret;
+ }
return 0;
}
@@ -923,11 +934,9 @@ int s32_pinctrl_probe(struct platform_device *pdev,
ipctl->pctl = devm_pinctrl_register(&pdev->dev, s32_pinctrl_desc,
ipctl);
-
- if (IS_ERR(ipctl->pctl)) {
- dev_err(&pdev->dev, "could not register s32 pinctrl driver\n");
- return PTR_ERR(ipctl->pctl);
- }
+ if (IS_ERR(ipctl->pctl))
+ return dev_err_probe(&pdev->dev, PTR_ERR(ipctl->pctl),
+ "could not register s32 pinctrl driver\n");
#ifdef CONFIG_PM_SLEEP
saved_context = &ipctl->saved_context;
diff --git a/drivers/pinctrl/nxp/pinctrl-s32g2.c b/drivers/pinctrl/nxp/pinctrl-s32g2.c
index 0e2d93681769..9124c6c5e5d4 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32g2.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32g2.c
@@ -754,14 +754,12 @@ static const struct dev_pm_ops s32g_pinctrl_pm_ops = {
static struct platform_driver s32g_pinctrl_driver = {
.driver = {
.name = "s32g-siul2-pinctrl",
- .owner = THIS_MODULE,
.of_match_table = s32_pinctrl_of_match,
- .pm = &s32g_pinctrl_pm_ops,
+ .pm = pm_sleep_ptr(&s32g_pinctrl_pm_ops),
.suppress_bind_attrs = true,
},
.probe = s32g_pinctrl_probe,
};
-
builtin_platform_driver(s32g_pinctrl_driver);
MODULE_AUTHOR("Matthew Nunez <[email protected]>");
--
2.37.3
Move common codes into smaller inline functions and remove argument checks
that are not actually used by pull up/down bits in S32 MSCR register.
Signed-off-by: Chester Lin <[email protected]>
---
Changes v3:
- Move the PIN_CONFIG_BIAS_DISABLE case to be with PU and PD cases since
they have the same function call.
- Roll back the argument checks of OUTPUT_ENABLE and INPUT_ENABLE cases
since they were wrongly removed with the PU & PD parts in v2.
drivers/pinctrl/nxp/pinctrl-s32cc.c | 52 ++++++++++++++++++-----------
1 file changed, 33 insertions(+), 19 deletions(-)
diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index f698e1a240ef..36f323f87785 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -474,11 +474,38 @@ static int s32_get_slew_regval(int arg)
return -EINVAL;
}
-static int s32_get_pin_conf(enum pin_config_param param, u32 arg,
- unsigned int *mask, unsigned int *config)
+static inline void s32_pin_set_pull(enum pin_config_param param,
+ unsigned int *mask, unsigned int *config)
{
+ switch (param) {
+ case PIN_CONFIG_BIAS_DISABLE:
+ case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
+ *config &= ~(S32_MSCR_PUS | S32_MSCR_PUE);
+ break;
+ case PIN_CONFIG_BIAS_PULL_UP:
+ *config |= S32_MSCR_PUS | S32_MSCR_PUE;
+ break;
+ case PIN_CONFIG_BIAS_PULL_DOWN:
+ *config &= ~S32_MSCR_PUS;
+ *config |= S32_MSCR_PUE;
+ break;
+ default:
+ return;
+ }
+
+ *mask |= S32_MSCR_PUS | S32_MSCR_PUE;
+}
+
+static int s32_parse_pincfg(unsigned long pincfg, unsigned int *mask,
+ unsigned int *config)
+{
+ enum pin_config_param param;
+ u32 arg;
int ret;
+ param = pinconf_to_config_param(pincfg);
+ arg = pinconf_to_config_argument(pincfg);
+
switch (param) {
/* All pins are persistent over suspend */
case PIN_CONFIG_PERSIST_STATE:
@@ -508,26 +535,15 @@ static int s32_get_pin_conf(enum pin_config_param param, u32 arg,
*config |= S32_MSCR_SRE((u32)ret);
*mask |= S32_MSCR_SRE(~0);
break;
+ case PIN_CONFIG_BIAS_DISABLE:
case PIN_CONFIG_BIAS_PULL_UP:
- if (arg)
- *config |= S32_MSCR_PUS;
- else
- *config &= ~S32_MSCR_PUS;
- fallthrough;
case PIN_CONFIG_BIAS_PULL_DOWN:
- if (arg)
- *config |= S32_MSCR_PUE;
- else
- *config &= ~S32_MSCR_PUE;
- *mask |= S32_MSCR_PUE | S32_MSCR_PUS;
+ s32_pin_set_pull(param, mask, config);
break;
case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
*config &= ~(S32_MSCR_ODE | S32_MSCR_OBE | S32_MSCR_IBE);
*mask |= S32_MSCR_ODE | S32_MSCR_OBE | S32_MSCR_IBE;
- fallthrough;
- case PIN_CONFIG_BIAS_DISABLE:
- *config &= ~(S32_MSCR_PUS | S32_MSCR_PUE);
- *mask |= S32_MSCR_PUS | S32_MSCR_PUE;
+ s32_pin_set_pull(param, mask, config);
break;
default:
return -EOPNOTSUPP;
@@ -553,9 +569,7 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev,
pin_get_name(pctldev, pin_id), num_configs);
for (i = 0; i < num_configs; i++) {
- ret = s32_get_pin_conf(pinconf_to_config_param(configs[i]),
- pinconf_to_config_argument(configs[i]),
- &mask, &config);
+ ret = s32_parse_pincfg(configs[i], &mask, &config);
if (ret)
return ret;
}
--
2.37.3
Replace struct s32_pmx_func with generic struct pinfunction since they
have the same data fields.
Suggested-by: Andy Shevchenko <[email protected]>
Signed-off-by: Chester Lin <[email protected]>
---
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
The .data field in struct of_device_id is used as a const member so it's
inappropriate to attach struct s32_pinctrl_soc_info with of_device_id
because some members in s32_pinctrl_soc_info need to be filled by
pinctrl-s32cc at runtime.
For this reason, struct s32_pinctrl_soc_info must be allocated in
pinctrl-s32cc and then create a new struct s32_pinctrl_soc_data in order
to represent const .data in of_device_id. To combine these two structures,
a s32_pinctrl_soc_data pointer is introduced in s32_pinctrl_soc_info.
Signed-off-by: Chester Lin <[email protected]>
---
(Initial version in v3)
drivers/pinctrl/nxp/pinctrl-s32.h | 14 +++++++++-----
drivers/pinctrl/nxp/pinctrl-s32cc.c | 30 +++++++++++++++++------------
drivers/pinctrl/nxp/pinctrl-s32g2.c | 10 +++++-----
3 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/drivers/pinctrl/nxp/pinctrl-s32.h b/drivers/pinctrl/nxp/pinctrl-s32.h
index 2f7aecd462e4..add3c77ddfed 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32.h
+++ b/drivers/pinctrl/nxp/pinctrl-s32.h
@@ -34,24 +34,28 @@ struct s32_pin_range {
unsigned int end;
};
-struct s32_pinctrl_soc_info {
- struct device *dev;
+struct s32_pinctrl_soc_data {
const struct pinctrl_pin_desc *pins;
unsigned int npins;
+ const struct s32_pin_range *mem_pin_ranges;
+ unsigned int mem_regions;
+};
+
+struct s32_pinctrl_soc_info {
+ struct device *dev;
+ const struct s32_pinctrl_soc_data *soc_data;
struct s32_pin_group *groups;
unsigned int ngroups;
struct pinfunction *functions;
unsigned int nfunctions;
unsigned int grp_index;
- const struct s32_pin_range *mem_pin_ranges;
- unsigned int mem_regions;
};
#define S32_PINCTRL_PIN(pin) PINCTRL_PIN(pin, #pin)
#define S32_PIN_RANGE(_start, _end) { .start = _start, .end = _end }
int s32_pinctrl_probe(struct platform_device *pdev,
- struct s32_pinctrl_soc_info *info);
+ const struct s32_pinctrl_soc_data *soc_data);
int s32_pinctrl_resume(struct device *dev);
int s32_pinctrl_suspend(struct device *dev);
#endif /* __DRIVERS_PINCTRL_S32_H */
diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index 8373468719b6..41e024160f36 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -106,7 +106,7 @@ s32_get_region(struct pinctrl_dev *pctldev, unsigned int pin)
{
struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
const struct s32_pin_range *pin_range;
- unsigned int mem_regions = ipctl->info->mem_regions;
+ unsigned int mem_regions = ipctl->info->soc_data->mem_regions;
unsigned int i;
for (i = 0; i < mem_regions; i++) {
@@ -688,8 +688,8 @@ int s32_pinctrl_suspend(struct device *dev)
int ret;
unsigned int config;
- for (i = 0; i < info->npins; i++) {
- pin = &info->pins[i];
+ for (i = 0; i < info->soc_data->npins; i++) {
+ pin = &info->soc_data->pins[i];
if (!s32_pinctrl_should_save(ipctl, pin->number))
continue;
@@ -713,8 +713,8 @@ int s32_pinctrl_resume(struct device *dev)
struct s32_pinctrl_context *saved_context = &ipctl->saved_context;
int ret, i;
- for (i = 0; i < info->npins; i++) {
- pin = &info->pins[i];
+ for (i = 0; i < info->soc_data->npins; i++) {
+ pin = &info->soc_data->pins[i];
if (!s32_pinctrl_should_save(ipctl, pin->number))
continue;
@@ -831,7 +831,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
struct resource *res;
struct regmap *map;
void __iomem *base;
- int mem_regions = info->mem_regions;
+ unsigned int mem_regions = info->soc_data->mem_regions;
int ret;
u32 nfuncs = 0;
u32 i = 0;
@@ -869,7 +869,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
}
ipctl->regions[i].map = map;
- ipctl->regions[i].pin_range = &info->mem_pin_ranges[i];
+ ipctl->regions[i].pin_range = &info->soc_data->mem_pin_ranges[i];
}
nfuncs = of_get_child_count(np);
@@ -904,20 +904,26 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
}
int s32_pinctrl_probe(struct platform_device *pdev,
- struct s32_pinctrl_soc_info *info)
+ const struct s32_pinctrl_soc_data *soc_data)
{
struct s32_pinctrl *ipctl;
int ret;
struct pinctrl_desc *s32_pinctrl_desc;
+ struct s32_pinctrl_soc_info *info;
#ifdef CONFIG_PM_SLEEP
struct s32_pinctrl_context *saved_context;
#endif
- if (!info || !info->pins || !info->npins) {
+ if (!soc_data || !soc_data->pins || !soc_data->npins) {
dev_err(&pdev->dev, "wrong pinctrl info\n");
return -EINVAL;
}
+ info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
+
+ info->soc_data = soc_data;
info->dev = &pdev->dev;
/* Create state holders etc for this driver */
@@ -938,8 +944,8 @@ int s32_pinctrl_probe(struct platform_device *pdev,
return -ENOMEM;
s32_pinctrl_desc->name = dev_name(&pdev->dev);
- s32_pinctrl_desc->pins = info->pins;
- s32_pinctrl_desc->npins = info->npins;
+ s32_pinctrl_desc->pins = info->soc_data->pins;
+ s32_pinctrl_desc->npins = info->soc_data->npins;
s32_pinctrl_desc->pctlops = &s32_pctrl_ops;
s32_pinctrl_desc->pmxops = &s32_pmx_ops;
s32_pinctrl_desc->confops = &s32_pinconf_ops;
@@ -960,7 +966,7 @@ int s32_pinctrl_probe(struct platform_device *pdev,
#ifdef CONFIG_PM_SLEEP
saved_context = &ipctl->saved_context;
saved_context->pads =
- devm_kcalloc(&pdev->dev, info->npins,
+ devm_kcalloc(&pdev->dev, info->soc_data->npins,
sizeof(*saved_context->pads),
GFP_KERNEL);
if (!saved_context->pads)
diff --git a/drivers/pinctrl/nxp/pinctrl-s32g2.c b/drivers/pinctrl/nxp/pinctrl-s32g2.c
index 9124c6c5e5d4..e0944c071c8c 100644
--- a/drivers/pinctrl/nxp/pinctrl-s32g2.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32g2.c
@@ -721,7 +721,7 @@ static const struct s32_pin_range s32_pin_ranges_siul2[] = {
S32_PIN_RANGE(942, 1007),
};
-static struct s32_pinctrl_soc_info s32_pinctrl_info = {
+static struct s32_pinctrl_soc_data s32_pinctrl_data = {
.pins = s32_pinctrl_pads_siul2,
.npins = ARRAY_SIZE(s32_pinctrl_pads_siul2),
.mem_pin_ranges = s32_pin_ranges_siul2,
@@ -732,7 +732,7 @@ static const struct of_device_id s32_pinctrl_of_match[] = {
{
.compatible = "nxp,s32g2-siul2-pinctrl",
- .data = (void *) &s32_pinctrl_info,
+ .data = (void *) &s32_pinctrl_data,
},
{ /* sentinel */ }
};
@@ -740,11 +740,11 @@ MODULE_DEVICE_TABLE(of, s32_pinctrl_of_match);
static int s32g_pinctrl_probe(struct platform_device *pdev)
{
- const struct s32_pinctrl_soc_info *info;
+ const struct s32_pinctrl_soc_data *soc_data;
- info = of_device_get_match_data(&pdev->dev);
+ soc_data = of_device_get_match_data(&pdev->dev);
- return s32_pinctrl_probe(pdev, info);
+ return s32_pinctrl_probe(pdev, soc_data);
}
static const struct dev_pm_ops s32g_pinctrl_pm_ops = {
--
2.37.3
Hi Chester,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linusw-pinctrl/devel]
[also build test WARNING on linusw-pinctrl/for-next next-20230323]
[cannot apply to linus/master v6.3-rc3]
[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/Chester-Lin/pinctrl-s32g2-use-of_device_get_match_data-to-get-device-data/20230323-225141
base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
patch link: https://lore.kernel.org/r/20230323144833.28562-2-clin%40suse.com
patch subject: [PATCH v3 1/6] pinctrl: s32g2: use of_device_get_match_data() to get device data
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20230324/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/b716f96ba217e92e79b0d888f187ba0f30d705cf
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chester-Lin/pinctrl-s32g2-use-of_device_get_match_data-to-get-device-data/20230323-225141
git checkout b716f96ba217e92e79b0d888f187ba0f30d705cf
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/pinctrl/nxp/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/pinctrl/nxp/pinctrl-s32g2.c: In function 's32g_pinctrl_probe':
>> drivers/pinctrl/nxp/pinctrl-s32g2.c:747:40: warning: passing argument 2 of 's32_pinctrl_probe' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
747 | return s32_pinctrl_probe(pdev, info);
| ^~~~
In file included from drivers/pinctrl/nxp/pinctrl-s32g2.c:18:
drivers/pinctrl/nxp/pinctrl-s32.h:70:54: note: expected 'struct s32_pinctrl_soc_info *' but argument is of type 'const struct s32_pinctrl_soc_info *'
70 | struct s32_pinctrl_soc_info *info);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
vim +747 drivers/pinctrl/nxp/pinctrl-s32g2.c
740
741 static int s32g_pinctrl_probe(struct platform_device *pdev)
742 {
743 const struct s32_pinctrl_soc_info *info;
744
745 info = of_device_get_match_data(&pdev->dev);
746
> 747 return s32_pinctrl_probe(pdev, info);
748 }
749
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
On Fri, Mar 24, 2023 at 01:11:37AM +0800, kernel test robot wrote:
> Hi Chester,
>
> I love your patch! Perhaps something to improve:
>
> [auto build test WARNING on linusw-pinctrl/devel]
> [also build test WARNING on linusw-pinctrl/for-next next-20230323]
> [cannot apply to linus/master v6.3-rc3]
> [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/Chester-Lin/pinctrl-s32g2-use-of_device_get_match_data-to-get-device-data/20230323-225141
> base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
> patch link: https://lore.kernel.org/r/20230323144833.28562-2-clin%40suse.com
> patch subject: [PATCH v3 1/6] pinctrl: s32g2: use of_device_get_match_data() to get device data
> config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20230324/[email protected]/config)
> compiler: aarch64-linux-gcc (GCC) 12.1.0
> reproduce (this is a W=1 build):
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # https://github.com/intel-lab-lkp/linux/commit/b716f96ba217e92e79b0d888f187ba0f30d705cf
> git remote add linux-review https://github.com/intel-lab-lkp/linux
> git fetch --no-tags linux-review Chester-Lin/pinctrl-s32g2-use-of_device_get_match_data-to-get-device-data/20230323-225141
> git checkout b716f96ba217e92e79b0d888f187ba0f30d705cf
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 olddefconfig
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/pinctrl/nxp/
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
> | Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
>
> All warnings (new ones prefixed by >>):
>
> drivers/pinctrl/nxp/pinctrl-s32g2.c: In function 's32g_pinctrl_probe':
> >> drivers/pinctrl/nxp/pinctrl-s32g2.c:747:40: warning: passing argument 2 of 's32_pinctrl_probe' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
> 747 | return s32_pinctrl_probe(pdev, info);
> | ^~~~
> In file included from drivers/pinctrl/nxp/pinctrl-s32g2.c:18:
> drivers/pinctrl/nxp/pinctrl-s32.h:70:54: note: expected 'struct s32_pinctrl_soc_info *' but argument is of type 'const struct s32_pinctrl_soc_info *'
> 70 | struct s32_pinctrl_soc_info *info);
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
>
I will appreciate if someone can give me suggestions. In fact the patch [v3 6/6]
in this series can solve this warning properly rather than casting data type,
should I combine [1/6, changed from v2] and [6/6, new in v3] together since
they are relevant?
Thanks,
Chester
>
> vim +747 drivers/pinctrl/nxp/pinctrl-s32g2.c
>
> 740
> 741 static int s32g_pinctrl_probe(struct platform_device *pdev)
> 742 {
> 743 const struct s32_pinctrl_soc_info *info;
> 744
> 745 info = of_device_get_match_data(&pdev->dev);
> 746
> > 747 return s32_pinctrl_probe(pdev, info);
> 748 }
> 749
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests
On Thu, Mar 23, 2023 at 4:49 PM Chester Lin <[email protected]> wrote:
>
> Move common codes into smaller inline functions and remove argument checks
> that are not actually used by pull up/down bits in S32 MSCR register.
in the S32
Reviewed-by: Andy Shevchenko <[email protected]>
> Signed-off-by: Chester Lin <[email protected]>
> ---
> Changes v3:
> - Move the PIN_CONFIG_BIAS_DISABLE case to be with PU and PD cases since
> they have the same function call.
> - Roll back the argument checks of OUTPUT_ENABLE and INPUT_ENABLE cases
> since they were wrongly removed with the PU & PD parts in v2.
>
> drivers/pinctrl/nxp/pinctrl-s32cc.c | 52 ++++++++++++++++++-----------
> 1 file changed, 33 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
> index f698e1a240ef..36f323f87785 100644
> --- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
> +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
> @@ -474,11 +474,38 @@ static int s32_get_slew_regval(int arg)
> return -EINVAL;
> }
>
> -static int s32_get_pin_conf(enum pin_config_param param, u32 arg,
> - unsigned int *mask, unsigned int *config)
> +static inline void s32_pin_set_pull(enum pin_config_param param,
> + unsigned int *mask, unsigned int *config)
> {
> + switch (param) {
> + case PIN_CONFIG_BIAS_DISABLE:
> + case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
> + *config &= ~(S32_MSCR_PUS | S32_MSCR_PUE);
> + break;
> + case PIN_CONFIG_BIAS_PULL_UP:
> + *config |= S32_MSCR_PUS | S32_MSCR_PUE;
> + break;
> + case PIN_CONFIG_BIAS_PULL_DOWN:
> + *config &= ~S32_MSCR_PUS;
> + *config |= S32_MSCR_PUE;
> + break;
> + default:
> + return;
> + }
> +
> + *mask |= S32_MSCR_PUS | S32_MSCR_PUE;
> +}
> +
> +static int s32_parse_pincfg(unsigned long pincfg, unsigned int *mask,
> + unsigned int *config)
> +{
> + enum pin_config_param param;
> + u32 arg;
> int ret;
>
> + param = pinconf_to_config_param(pincfg);
> + arg = pinconf_to_config_argument(pincfg);
> +
> switch (param) {
> /* All pins are persistent over suspend */
> case PIN_CONFIG_PERSIST_STATE:
> @@ -508,26 +535,15 @@ static int s32_get_pin_conf(enum pin_config_param param, u32 arg,
> *config |= S32_MSCR_SRE((u32)ret);
> *mask |= S32_MSCR_SRE(~0);
> break;
> + case PIN_CONFIG_BIAS_DISABLE:
> case PIN_CONFIG_BIAS_PULL_UP:
> - if (arg)
> - *config |= S32_MSCR_PUS;
> - else
> - *config &= ~S32_MSCR_PUS;
> - fallthrough;
> case PIN_CONFIG_BIAS_PULL_DOWN:
> - if (arg)
> - *config |= S32_MSCR_PUE;
> - else
> - *config &= ~S32_MSCR_PUE;
> - *mask |= S32_MSCR_PUE | S32_MSCR_PUS;
> + s32_pin_set_pull(param, mask, config);
> break;
> case PIN_CONFIG_BIAS_HIGH_IMPEDANCE:
> *config &= ~(S32_MSCR_ODE | S32_MSCR_OBE | S32_MSCR_IBE);
> *mask |= S32_MSCR_ODE | S32_MSCR_OBE | S32_MSCR_IBE;
> - fallthrough;
> - case PIN_CONFIG_BIAS_DISABLE:
> - *config &= ~(S32_MSCR_PUS | S32_MSCR_PUE);
> - *mask |= S32_MSCR_PUS | S32_MSCR_PUE;
> + s32_pin_set_pull(param, mask, config);
> break;
> default:
> return -EOPNOTSUPP;
> @@ -553,9 +569,7 @@ static int s32_pinconf_mscr_update(struct pinctrl_dev *pctldev,
> pin_get_name(pctldev, pin_id), num_configs);
>
> for (i = 0; i < num_configs; i++) {
> - ret = s32_get_pin_conf(pinconf_to_config_param(configs[i]),
> - pinconf_to_config_argument(configs[i]),
> - &mask, &config);
> + ret = s32_parse_pincfg(configs[i], &mask, &config);
> if (ret)
> return ret;
> }
> --
> 2.37.3
>
--
With Best Regards,
Andy Shevchenko
On Thu, Mar 23, 2023 at 4:49 PM Chester Lin <[email protected]> wrote:
>
> Replace struct s32_pmx_func with generic struct pinfunction since they
> have the same data fields.
LGTM,
Reviewed-by: Andy Shevchenko <[email protected]>
> Suggested-by: Andy Shevchenko <[email protected]>
> Signed-off-by: Chester Lin <[email protected]>
> ---
> 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
>
--
With Best Regards,
Andy Shevchenko
On Thu, Mar 23, 2023 at 4:49 PM Chester Lin <[email protected]> wrote:
>
> The .data field in struct of_device_id is used as a const member so it's
> inappropriate to attach struct s32_pinctrl_soc_info with of_device_id
> because some members in s32_pinctrl_soc_info need to be filled by
> pinctrl-s32cc at runtime.
>
> For this reason, struct s32_pinctrl_soc_info must be allocated in
> pinctrl-s32cc and then create a new struct s32_pinctrl_soc_data in order
> to represent const .data in of_device_id. To combine these two structures,
> a s32_pinctrl_soc_data pointer is introduced in s32_pinctrl_soc_info.
So, the first patch has to be embedded in this one, correct?
Don't forget to compile and test your contributions beforehand.
--
With Best Regards,
Andy Shevchenko
Hi Andy,
Thanks for reviewing this patch!
On Thu, Mar 23, 2023 at 08:50:41PM +0200, Andy Shevchenko wrote:
> On Thu, Mar 23, 2023 at 4:49 PM Chester Lin <[email protected]> wrote:
> >
> > The .data field in struct of_device_id is used as a const member so it's
> > inappropriate to attach struct s32_pinctrl_soc_info with of_device_id
> > because some members in s32_pinctrl_soc_info need to be filled by
> > pinctrl-s32cc at runtime.
> >
> > For this reason, struct s32_pinctrl_soc_info must be allocated in
> > pinctrl-s32cc and then create a new struct s32_pinctrl_soc_data in order
> > to represent const .data in of_device_id. To combine these two structures,
> > a s32_pinctrl_soc_data pointer is introduced in s32_pinctrl_soc_info.
>
> So, the first patch has to be embedded in this one, correct?
Correct. Leave the first patch alone will cause a compiler warning.
> Don't forget to compile and test your contributions beforehand.
Will do.
Regards,
Chester
>
> --
> With Best Regards,
> Andy Shevchenko