Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: s32: separate const device data from struct s32_pinctrl_soc_info

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.

Besides, use of_device_get_match_data() instead of of_match_device() since
the driver only needs to retrieve the .data from of_device_id.

Link: https://lore.kernel.org/r/20230329041630.8011-1-clin@suse.com/
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Chester Lin <clin@suse.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Chester Lin and committed by
Linus Walleij
0da4cebe 4d6366e6

+32 -26
+9 -5
drivers/pinctrl/nxp/pinctrl-s32.h
··· 34 34 unsigned int end; 35 35 }; 36 36 37 - struct s32_pinctrl_soc_info { 38 - struct device *dev; 37 + struct s32_pinctrl_soc_data { 39 38 const struct pinctrl_pin_desc *pins; 40 39 unsigned int npins; 40 + const struct s32_pin_range *mem_pin_ranges; 41 + unsigned int mem_regions; 42 + }; 43 + 44 + struct s32_pinctrl_soc_info { 45 + struct device *dev; 46 + const struct s32_pinctrl_soc_data *soc_data; 41 47 struct s32_pin_group *groups; 42 48 unsigned int ngroups; 43 49 struct pinfunction *functions; 44 50 unsigned int nfunctions; 45 51 unsigned int grp_index; 46 - const struct s32_pin_range *mem_pin_ranges; 47 - unsigned int mem_regions; 48 52 }; 49 53 50 54 #define S32_PINCTRL_PIN(pin) PINCTRL_PIN(pin, #pin) 51 55 #define S32_PIN_RANGE(_start, _end) { .start = _start, .end = _end } 52 56 53 57 int s32_pinctrl_probe(struct platform_device *pdev, 54 - struct s32_pinctrl_soc_info *info); 58 + const struct s32_pinctrl_soc_data *soc_data); 55 59 int s32_pinctrl_resume(struct device *dev); 56 60 int s32_pinctrl_suspend(struct device *dev); 57 61 #endif /* __DRIVERS_PINCTRL_S32_H */
+18 -12
drivers/pinctrl/nxp/pinctrl-s32cc.c
··· 106 106 { 107 107 struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); 108 108 const struct s32_pin_range *pin_range; 109 - unsigned int mem_regions = ipctl->info->mem_regions; 109 + unsigned int mem_regions = ipctl->info->soc_data->mem_regions; 110 110 unsigned int i; 111 111 112 112 for (i = 0; i < mem_regions; i++) { ··· 688 688 int ret; 689 689 unsigned int config; 690 690 691 - for (i = 0; i < info->npins; i++) { 692 - pin = &info->pins[i]; 691 + for (i = 0; i < info->soc_data->npins; i++) { 692 + pin = &info->soc_data->pins[i]; 693 693 694 694 if (!s32_pinctrl_should_save(ipctl, pin->number)) 695 695 continue; ··· 713 713 struct s32_pinctrl_context *saved_context = &ipctl->saved_context; 714 714 int ret, i; 715 715 716 - for (i = 0; i < info->npins; i++) { 717 - pin = &info->pins[i]; 716 + for (i = 0; i < info->soc_data->npins; i++) { 717 + pin = &info->soc_data->pins[i]; 718 718 719 719 if (!s32_pinctrl_should_save(ipctl, pin->number)) 720 720 continue; ··· 831 831 struct resource *res; 832 832 struct regmap *map; 833 833 void __iomem *base; 834 - int mem_regions = info->mem_regions; 834 + unsigned int mem_regions = info->soc_data->mem_regions; 835 835 int ret; 836 836 u32 nfuncs = 0; 837 837 u32 i = 0; ··· 869 869 } 870 870 871 871 ipctl->regions[i].map = map; 872 - ipctl->regions[i].pin_range = &info->mem_pin_ranges[i]; 872 + ipctl->regions[i].pin_range = &info->soc_data->mem_pin_ranges[i]; 873 873 } 874 874 875 875 nfuncs = of_get_child_count(np); ··· 904 904 } 905 905 906 906 int s32_pinctrl_probe(struct platform_device *pdev, 907 - struct s32_pinctrl_soc_info *info) 907 + const struct s32_pinctrl_soc_data *soc_data) 908 908 { 909 909 struct s32_pinctrl *ipctl; 910 910 int ret; 911 911 struct pinctrl_desc *s32_pinctrl_desc; 912 + struct s32_pinctrl_soc_info *info; 912 913 #ifdef CONFIG_PM_SLEEP 913 914 struct s32_pinctrl_context *saved_context; 914 915 #endif 915 916 916 - if (!info || !info->pins || !info->npins) { 917 + if (!soc_data || !soc_data->pins || !soc_data->npins) { 917 918 dev_err(&pdev->dev, "wrong pinctrl info\n"); 918 919 return -EINVAL; 919 920 } 920 921 922 + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 923 + if (!info) 924 + return -ENOMEM; 925 + 926 + info->soc_data = soc_data; 921 927 info->dev = &pdev->dev; 922 928 923 929 /* Create state holders etc for this driver */ ··· 944 938 return -ENOMEM; 945 939 946 940 s32_pinctrl_desc->name = dev_name(&pdev->dev); 947 - s32_pinctrl_desc->pins = info->pins; 948 - s32_pinctrl_desc->npins = info->npins; 941 + s32_pinctrl_desc->pins = info->soc_data->pins; 942 + s32_pinctrl_desc->npins = info->soc_data->npins; 949 943 s32_pinctrl_desc->pctlops = &s32_pctrl_ops; 950 944 s32_pinctrl_desc->pmxops = &s32_pmx_ops; 951 945 s32_pinctrl_desc->confops = &s32_pinconf_ops; ··· 966 960 #ifdef CONFIG_PM_SLEEP 967 961 saved_context = &ipctl->saved_context; 968 962 saved_context->pads = 969 - devm_kcalloc(&pdev->dev, info->npins, 963 + devm_kcalloc(&pdev->dev, info->soc_data->npins, 970 964 sizeof(*saved_context->pads), 971 965 GFP_KERNEL); 972 966 if (!saved_context->pads)
+5 -9
drivers/pinctrl/nxp/pinctrl-s32g2.c
··· 721 721 S32_PIN_RANGE(942, 1007), 722 722 }; 723 723 724 - static struct s32_pinctrl_soc_info s32_pinctrl_info = { 724 + static const struct s32_pinctrl_soc_data s32_pinctrl_data = { 725 725 .pins = s32_pinctrl_pads_siul2, 726 726 .npins = ARRAY_SIZE(s32_pinctrl_pads_siul2), 727 727 .mem_pin_ranges = s32_pin_ranges_siul2, ··· 730 730 731 731 static const struct of_device_id s32_pinctrl_of_match[] = { 732 732 { 733 - 734 733 .compatible = "nxp,s32g2-siul2-pinctrl", 735 - .data = (void *) &s32_pinctrl_info, 734 + .data = &s32_pinctrl_data, 736 735 }, 737 736 { /* sentinel */ } 738 737 }; ··· 739 740 740 741 static int s32g_pinctrl_probe(struct platform_device *pdev) 741 742 { 742 - const struct of_device_id *of_id = 743 - of_match_device(s32_pinctrl_of_match, &pdev->dev); 743 + const struct s32_pinctrl_soc_data *soc_data; 744 744 745 - if (!of_id) 746 - return -ENODEV; 745 + soc_data = of_device_get_match_data(&pdev->dev); 747 746 748 - return s32_pinctrl_probe 749 - (pdev, (struct s32_pinctrl_soc_info *) of_id->data); 747 + return s32_pinctrl_probe(pdev, soc_data); 750 748 } 751 749 752 750 static const struct dev_pm_ops s32g_pinctrl_pm_ops = {