pinctrl: s32: driver improvements and generic struct use
Subsystems (4)
cover pinctrl: s32: driver improvements and generic struct use
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]/
Chester Lin (3):
pinctrl: s32: refine error/return/config checks and simplify driver
codes
pinctrl: s32cc: refactor pin config parsing
pinctrl: s32cc: embed generic struct pingroup and pinfunction
drivers/pinctrl/nxp/pinctrl-s32.h | 22 +-- drivers/pinctrl/nxp/pinctrl-s32cc.c | 283 ++++++++++++++++------------ drivers/pinctrl/nxp/pinctrl-s32g2.c | 8 +- 3 files changed, 168 insertions(+), 145 deletions(-)
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/3 pinctrl: s32: refine error/return/config checks and simplify driver codes
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.
--- drivers/pinctrl/nxp/pinctrl-s32cc.c | 141 +++++++++++++++------------- drivers/pinctrl/nxp/pinctrl-s32g2.c | 8 +- 2 files changed, 78 insertions(+), 71 deletions(-)
drivers/pinctrl/nxp/pinctrl-s32cc.c +75 -66
@@ -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,15 +406,13 @@ 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,
@@ -417,7 +420,7 @@ static void s32_pmx_gpio_disable_free(struct pinctrl_dev *pctldev,if (ret !=0 ) goto unlock; -list_del (pos); +list_del (&gpio_pin->list);kfree (gpio_pin);break ; }
@@ -461,7 +464,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 +546,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 +564,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 %d cfg 0x%x\n" , pin_id, config); +dev_dbg (ipctl->dev,"update: pin %u 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 +607,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; + + ret =s32_regmap_read (pctldev, pin_id, &config); +if (ret) +return ; -if (!ret) -seq_printf (s,"0x%x" , config); +seq_printf (s,"0x%x" , config); } static void s32_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
@@ -710,7 +716,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 +728,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 +750,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 +762,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 +774,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 +784,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 (char *),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 +814,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 +826,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 +861,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 (struct s32_pmx_func ),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 (struct s32_pin_group ),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,12 +935,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; saved_context->pads =
drivers/pinctrl/nxp/pinctrl-s32g2.c +3 -5
@@ -746,8 +746,8 @@ static int s32g_pinctrl_probe(struct platform_device *pdev)if (!of_id)return -ENODEV ; -return s32_pinctrl_probe - (pdev, (struct s32_pinctrl_soc_info *) of_id->data); +return s32_pinctrl_probe (pdev, + (struct s32_pinctrl_soc_info *) of_id->data); }static const struct dev_pm_ops s32g_pinctrl_pm_ops = {
@@ -757,14 +757,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]>" );
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 2/3 pinctrl: s32cc: refactor pin config parsing
In reply to Chester LinMove common codes into smaller inline functions and remove some argument handlings that are not actually used by either S32 MSCR register or generic config params.
--- drivers/pinctrl/nxp/pinctrl-s32cc.c | 82 ++++++++++++++++++----------- 1 file changed, 50 insertions(+), 32 deletions(-)
drivers/pinctrl/nxp/pinctrl-s32cc.c +50 -32
@@ -39,6 +39,9 @@#define S32_MSCR_ODE BIT(20)#define S32_MSCR_OBE BIT(21) +#define S32_CFG_SET true +#define S32_CFG_CLR false +static struct regmap_config s32_regmap_config = { .reg_bits =32 , .val_bits =32 ,
@@ -475,32 +478,57 @@ 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_config (unsigned int *mask,unsigned int *config, +unsigned int bits,bool set) +{ +if (set) + *config |= bits; +else + *config &= ~bits; + *mask |= bits; +} + +static inline void s32_pull_enable (enum pin_config_param param, +unsigned int *mask,unsigned int *config) +{ + +if (param ==PIN_CONFIG_BIAS_PULL_UP ) { +s32_pin_config (mask, config,S32_MSCR_PUS |S32_MSCR_PUE , +S32_CFG_SET ); + }else if (param ==PIN_CONFIG_BIAS_PULL_DOWN ) { + *config &= ~S32_MSCR_PUS ; + *config |=S32_MSCR_PUE ; + *mask |=S32_MSCR_PUS |S32_MSCR_PUE ; + } +} + +static inline void s32_pull_disable (unsigned int *mask,unsigned int *config) +{ +s32_pin_config (mask, config,S32_MSCR_PUS |S32_MSCR_PUE ,S32_CFG_CLR ); +} + +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 :return 0 ;case PIN_CONFIG_DRIVE_OPEN_DRAIN : - *config |=S32_MSCR_ODE ; - *mask |=S32_MSCR_ODE ; +s32_pin_config (mask, config,S32_MSCR_ODE ,S32_CFG_SET );break ;case PIN_CONFIG_OUTPUT_ENABLE : -if (arg) - *config |=S32_MSCR_OBE ; -else - *config &= ~S32_MSCR_OBE ; - *mask |=S32_MSCR_OBE ; +s32_pin_config (mask, config,S32_MSCR_OBE ,S32_CFG_SET );break ;case PIN_CONFIG_INPUT_ENABLE : -if (arg) - *config |=S32_MSCR_IBE ; -else - *config &= ~S32_MSCR_IBE ; - *mask |=S32_MSCR_IBE ; +s32_pin_config (mask, config,S32_MSCR_IBE ,S32_CFG_SET );break ;case PIN_CONFIG_SLEW_RATE : ret =s32_get_slew_regval (arg);
@@ -510,25 +538,17 @@ static int s32_get_pin_conf(enum pin_config_param param, u32 arg, *mask |=S32_MSCR_SRE (~0 );break ;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_pull_enable (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; +s32_pin_config (mask, config, +S32_MSCR_ODE |S32_MSCR_OBE |S32_MSCR_IBE , +S32_CFG_CLR ); +s32_pull_disable (mask, config); +break ;case PIN_CONFIG_BIAS_DISABLE : - *config &= ~(S32_MSCR_PUS |S32_MSCR_PUE ); - *mask |=S32_MSCR_PUS |S32_MSCR_PUE ; +s32_pull_disable (mask, config);break ;default :return -EOPNOTSUPP ;
@@ -554,9 +574,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; }
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 3/3 pinctrl: s32cc: embed generic struct pingroup and pinfunction
In reply to Chester LinUse generic data structure to describe pin control functions and groups in S32 SoC family and drop duplicated struct members.
--- drivers/pinctrl/nxp/pinctrl-s32.h | 22 +++----- drivers/pinctrl/nxp/pinctrl-s32cc.c | 78 ++++++++++++++++------------- 2 files changed, 49 insertions(+), 51 deletions(-)
drivers/pinctrl/nxp/pinctrl-s32.h +7 -15
@@ -15,29 +15,21 @@ struct platform_device;/** * struct s32_pin_group - describes an S32 pin group -* @name: the name of this specific pin group -* @npins: the number of pins in this group array, i.e. the number of -* elements in pin_ids and pin_sss so we can iterate over that array -* @pin_ids: an array of pin IDs in this group -* @pin_sss: an array of source signal select configs paired with pin_ids +* @data: generic data describes group name, number of pins, and a pin array in +this group. +* @pin_sss: an array of source signal select configs paired with pin array. */ struct s32_pin_group { -const char *name; -unsigned int npins; -unsigned int *pin_ids; +struct pingroup data;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 - describes an S32 pinmux function +* @data: generic data to describe function name and associated groups. */ struct s32_pmx_func { -const char *name; -const char **groups; -unsigned int num_groups; +struct pinfunction data; };/**
drivers/pinctrl/nxp/pinctrl-s32cc.c +42 -36
187 lines not on this page · raw message
Signature · 7 lines
2.37.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 1/3] pinctrl: s32: refine error/return/config checks and simplify driver codes
In reply to Chester LinQuoted 4 lines · Chester Lin
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.
I dunno if the maintainer wants this to be split to logically unified changes, but either way it's fine to me.
Also see below some additional minor things you might be interested in fixing. With these being addressed:
Quoted 105 lines
Signed-off-by Chester Lin <[email protected]>--- drivers/pinctrl/nxp/pinctrl-s32cc.c | 141 +++++++++++++++------------- drivers/pinctrl/nxp/pinctrl-s32g2.c | 8 +- 2 files changed, 78 insertions(+), 71 deletions(-)drivers/pinctrl/nxp/pinctrl-s32cc.c +18
-14@@ -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,15 +406,13 @@ 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;
drivers/pinctrl/nxp/pinctrl-s32cc.c static void s32_pmx_gpio_disable_free(struct pinctrl_dev *pctldev, · line 417
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +1
-2unsigned 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) {
This blank line now can be removed.
Quoted 146 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +0
-0if (gpio_pin->pin_id == offset) {ret = s32_regmap_write(pctldev, gpio_pin->pin_id,drivers/pinctrl/nxp/pinctrl-s32cc.c +28
-27@@ -417,7 +420,7 @@ static void s32_pmx_gpio_disable_free(struct pinctrl_dev *pctldev,if (ret !=0 ) goto unlock; -list_del (pos); +list_del (&gpio_pin->list);kfree (gpio_pin);break ; }@@ -461,7 +464,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 +546,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 +564,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 %d cfg 0x%x\n" , pin_id, config); +dev_dbg (ipctl->dev,"update: pin %u 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 +607,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; + + ret =s32_regmap_read (pctldev, pin_id, &config); +if (ret) +return ; -if (!ret) -seq_printf (s,"0x%x" , config); +seq_printf (s,"0x%x" , config); } static void s32_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,@@ -710,7 +716,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 +728,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 +750,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 +762,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 +774,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 +784,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 ) {
drivers/pinctrl/nxp/pinctrl-s32cc.c static void s32_pinctrl_parse_functions(struct device_node *np, · line 792
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +4
-4-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 (char *),GFP_KERNEL );
sizeof(*func->groups) ?
Quoted 26 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +7
-1+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,drivers/pinctrl/nxp/pinctrl-s32cc.c +1
-0@@ -804,6 +814,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 ;
drivers/pinctrl/nxp/pinctrl-s32cc.c static int s32_pinctrl_probe_dt(struct platform_device *pdev, · line 830
Quoted 8 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +2
-3@@ -815,13 +826,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 );
Too many parentheses.
Quoted 9 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +1
-1if (!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);
drivers/pinctrl/nxp/pinctrl-s32cc.c static int s32_pinctrl_probe_dt(struct platform_device *pdev, · line 865
Quoted 8 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +2
-3@@ -851,24 +861,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 (struct s32_pmx_func ),GFP_KERNEL );
sizeof(*info->functions)
drivers/pinctrl/nxp/pinctrl-s32cc.c static int s32_pinctrl_probe_dt(struct platform_device *pdev, · line 874
Quoted 12 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +3
-3if (!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 (struct s32_pin_group ),GFP_KERNEL );
sizeof (*info->groups) ?
Quoted 15 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +5
-2if (!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 ; }
drivers/pinctrl/nxp/pinctrl-s32cc.c int s32_pinctrl_probe(struct platform_device *pdev, · line 932
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +0
-6@@ -923,12 +935,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); - } -
Don't drop this blank line, see below.
drivers/pinctrl/nxp/pinctrl-s32cc.c int s32_pinctrl_probe(struct platform_device *pdev, · line 940
Quoted 3 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +3
-0+if (IS_ERR (ipctl->pctl)) +return dev_err_probe (&pdev->dev,PTR_ERR (ipctl->pctl), +"could not register s32 pinctrl driver\n" );
It should be here.
Quoted 8 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +0
-0#ifdef CONFIG_PM_SLEEP saved_context = &ipctl->saved_context;saved_context->pads =drivers/pinctrl/nxp/pinctrl-s32g2.c +0
-0
drivers/pinctrl/nxp/pinctrl-s32g2.c static int s32g_pinctrl_probe(struct platform_device *pdev) · line 750
Quoted 7 lines
drivers/pinctrl/nxp/pinctrl-s32g2.c +2
-2@@ -746,8 +746,8 @@ static int s32g_pinctrl_probe(struct platform_device *pdev)if (!of_id)return -ENODEV ; -return s32_pinctrl_probe - (pdev, (struct s32_pinctrl_soc_info *) of_id->data); +return s32_pinctrl_probe (pdev, + (struct s32_pinctrl_soc_info *) of_id->data);
No space after casting, but why is it using this interface? Convert to of_device_get_match_data().
(In a separate patch before this one)
Quoted 22 lines
drivers/pinctrl/nxp/pinctrl-s32g2.c +1
-4}static const struct dev_pm_ops s32g_pinctrl_pm_ops = {@@ -757,14 +757,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
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/3] pinctrl: s32cc: refactor pin config parsing
In reply to Chester LinQuoted 4 lines · Chester Lin
Move common codes into smaller inline functions and remove some argument handlings that are not actually used by either S32 MSCR register or generic config params.
...
drivers/pinctrl/nxp/pinctrl-s32cc.c line 43
Quoted 2 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +2
-0+#define S32_CFG_SET true +#define S32_CFG_CLR false
Have no value, use boolean values directly.
...
Quoted 5 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +5
-0+static inline void s32_pin_config (unsigned int *mask,unsigned int *config, +unsigned int bits,bool set) +{ +if (set) + *config |= bits;
drivers/pinctrl/nxp/pinctrl-s32cc.c static int s32_get_slew_regval(int arg) · line 519
Quoted 10 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +9
-0+else + *config &= ~bits; + *mask |= bits; +} + +static inline void s32_pull_enable (enum pin_config_param param, +unsigned int *mask,unsigned int *config) +{ +
Unneeded blank line
drivers/pinctrl/nxp/pinctrl-s32cc.c static int s32_get_slew_regval(int arg) · line 502
Quoted 8 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +8
-0+if (param ==PIN_CONFIG_BIAS_PULL_UP ) { +s32_pin_config (mask, config,S32_MSCR_PUS |S32_MSCR_PUE , +S32_CFG_SET ); + }else if (param ==PIN_CONFIG_BIAS_PULL_DOWN ) { + *config &= ~S32_MSCR_PUS ; + *config |=S32_MSCR_PUE ; + *mask |=S32_MSCR_PUS |S32_MSCR_PUE ; + }
This looks intransparent.
Just use your common sense and write it without that s32_pin_config() helper.
drivers/pinctrl/nxp/pinctrl-s32cc.c static int s32_get_slew_regval(int arg) · line 508
Quoted 6 lines
drivers/pinctrl/nxp/pinctrl-s32cc.c +6
-0+} + +static inline void s32_pull_disable (unsigned int *mask,unsigned int *config) +{ +s32_pin_config (mask, config,S32_MSCR_PUS |S32_MSCR_PUE ,S32_CFG_CLR ); +}
This should go with above together, just use switch and make the configuration based on it.
Before the switch-case, clear what has to be cleared for all cases (some cases may override some bits afterwards), set what has to be set for all cases (some cases may override some bits afterwards) and adjust.
Look into pinctrl-intel.c for the rough example.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/3] pinctrl: s32cc: embed generic struct pingroup and pinfunction
In reply to Chester LinQuoted 3 lines · Chester Lin
Use generic data structure to describe pin control functions and groups in S32 SoC family and drop duplicated struct members.
...
drivers/pinctrl/nxp/pinctrl-s32.h struct platform_device; · line 33
Quoted 6 lines
struct
s32_pmx_func{drivers/pinctrl/nxp/pinctrl-s32.h +1
-3-const char *name; -const char **groups; -unsigned int num_groups; +struct pinfunction data; };
Since you have a single driver with this, just kill the entire custom structure.
The way it's done in the pinctrl-intel.c is due to dozens of drivers sharing the same data type and hence converting that will provoke quite a noise for no benefit. Here it's not the case, so just kill it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Chester Lin
Hello,
This patch series contains some improvements for s32 pinctrl drivers suggested by upstream[1], such as
Quoted 6 lines
- 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.
Overall it looks not bad, thank you for doing this. Individual patches have been reviewed and commented accordingly.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
Quoted 14 lines · Andy Shevchenko
Quoted 6 lines · Chester Lin
Hello,
This patch series contains some improvements for s32 pinctrl drivers suggested by upstream[1], such as
Quoted 6 lines
- 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.
Quoted 2 lines
Overall it looks not bad, thank you for doing this. Individual patches have been reviewed and commented accordingly.
Thank you for reviewing this patch. I will fix the rest in v2 soon.
Regards,
Chester
Quoted 4 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko