Skip to content

Commit 0da4ceb

Browse files
chesterlintwlinusw
authored andcommitted
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/[email protected]/ Suggested-by: Andy Shevchenko <[email protected]> Signed-off-by: Chester Lin <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 4d6366e commit 0da4ceb

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

drivers/pinctrl/nxp/pinctrl-s32.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,28 @@ struct s32_pin_range {
3434
unsigned int end;
3535
};
3636

37-
struct s32_pinctrl_soc_info {
38-
struct device *dev;
37+
struct s32_pinctrl_soc_data {
3938
const struct pinctrl_pin_desc *pins;
4039
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;
4147
struct s32_pin_group *groups;
4248
unsigned int ngroups;
4349
struct pinfunction *functions;
4450
unsigned int nfunctions;
4551
unsigned int grp_index;
46-
const struct s32_pin_range *mem_pin_ranges;
47-
unsigned int mem_regions;
4852
};
4953

5054
#define S32_PINCTRL_PIN(pin) PINCTRL_PIN(pin, #pin)
5155
#define S32_PIN_RANGE(_start, _end) { .start = _start, .end = _end }
5256

5357
int s32_pinctrl_probe(struct platform_device *pdev,
54-
struct s32_pinctrl_soc_info *info);
58+
const struct s32_pinctrl_soc_data *soc_data);
5559
int s32_pinctrl_resume(struct device *dev);
5660
int s32_pinctrl_suspend(struct device *dev);
5761
#endif /* __DRIVERS_PINCTRL_S32_H */

drivers/pinctrl/nxp/pinctrl-s32cc.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ s32_get_region(struct pinctrl_dev *pctldev, unsigned int pin)
106106
{
107107
struct s32_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
108108
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;
110110
unsigned int i;
111111

112112
for (i = 0; i < mem_regions; i++) {
@@ -688,8 +688,8 @@ int s32_pinctrl_suspend(struct device *dev)
688688
int ret;
689689
unsigned int config;
690690

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];
693693

694694
if (!s32_pinctrl_should_save(ipctl, pin->number))
695695
continue;
@@ -713,8 +713,8 @@ int s32_pinctrl_resume(struct device *dev)
713713
struct s32_pinctrl_context *saved_context = &ipctl->saved_context;
714714
int ret, i;
715715

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];
718718

719719
if (!s32_pinctrl_should_save(ipctl, pin->number))
720720
continue;
@@ -831,7 +831,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
831831
struct resource *res;
832832
struct regmap *map;
833833
void __iomem *base;
834-
int mem_regions = info->mem_regions;
834+
unsigned int mem_regions = info->soc_data->mem_regions;
835835
int ret;
836836
u32 nfuncs = 0;
837837
u32 i = 0;
@@ -869,7 +869,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
869869
}
870870

871871
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];
873873
}
874874

875875
nfuncs = of_get_child_count(np);
@@ -904,20 +904,26 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
904904
}
905905

906906
int s32_pinctrl_probe(struct platform_device *pdev,
907-
struct s32_pinctrl_soc_info *info)
907+
const struct s32_pinctrl_soc_data *soc_data)
908908
{
909909
struct s32_pinctrl *ipctl;
910910
int ret;
911911
struct pinctrl_desc *s32_pinctrl_desc;
912+
struct s32_pinctrl_soc_info *info;
912913
#ifdef CONFIG_PM_SLEEP
913914
struct s32_pinctrl_context *saved_context;
914915
#endif
915916

916-
if (!info || !info->pins || !info->npins) {
917+
if (!soc_data || !soc_data->pins || !soc_data->npins) {
917918
dev_err(&pdev->dev, "wrong pinctrl info\n");
918919
return -EINVAL;
919920
}
920921

922+
info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
923+
if (!info)
924+
return -ENOMEM;
925+
926+
info->soc_data = soc_data;
921927
info->dev = &pdev->dev;
922928

923929
/* Create state holders etc for this driver */
@@ -938,8 +944,8 @@ int s32_pinctrl_probe(struct platform_device *pdev,
938944
return -ENOMEM;
939945

940946
s32_pinctrl_desc->name = dev_name(&pdev->dev);
941-
s32_pinctrl_desc->pins = info->pins;
942-
s32_pinctrl_desc->npins = info->npins;
947+
s32_pinctrl_desc->pins = info->soc_data->pins;
948+
s32_pinctrl_desc->npins = info->soc_data->npins;
943949
s32_pinctrl_desc->pctlops = &s32_pctrl_ops;
944950
s32_pinctrl_desc->pmxops = &s32_pmx_ops;
945951
s32_pinctrl_desc->confops = &s32_pinconf_ops;
@@ -960,7 +966,7 @@ int s32_pinctrl_probe(struct platform_device *pdev,
960966
#ifdef CONFIG_PM_SLEEP
961967
saved_context = &ipctl->saved_context;
962968
saved_context->pads =
963-
devm_kcalloc(&pdev->dev, info->npins,
969+
devm_kcalloc(&pdev->dev, info->soc_data->npins,
964970
sizeof(*saved_context->pads),
965971
GFP_KERNEL);
966972
if (!saved_context->pads)

drivers/pinctrl/nxp/pinctrl-s32g2.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ static const struct s32_pin_range s32_pin_ranges_siul2[] = {
721721
S32_PIN_RANGE(942, 1007),
722722
};
723723

724-
static struct s32_pinctrl_soc_info s32_pinctrl_info = {
724+
static const struct s32_pinctrl_soc_data s32_pinctrl_data = {
725725
.pins = s32_pinctrl_pads_siul2,
726726
.npins = ARRAY_SIZE(s32_pinctrl_pads_siul2),
727727
.mem_pin_ranges = s32_pin_ranges_siul2,
@@ -730,24 +730,20 @@ static struct s32_pinctrl_soc_info s32_pinctrl_info = {
730730

731731
static const struct of_device_id s32_pinctrl_of_match[] = {
732732
{
733-
734733
.compatible = "nxp,s32g2-siul2-pinctrl",
735-
.data = (void *) &s32_pinctrl_info,
734+
.data = &s32_pinctrl_data,
736735
},
737736
{ /* sentinel */ }
738737
};
739738
MODULE_DEVICE_TABLE(of, s32_pinctrl_of_match);
740739

741740
static int s32g_pinctrl_probe(struct platform_device *pdev)
742741
{
743-
const struct of_device_id *of_id =
744-
of_match_device(s32_pinctrl_of_match, &pdev->dev);
742+
const struct s32_pinctrl_soc_data *soc_data;
745743

746-
if (!of_id)
747-
return -ENODEV;
744+
soc_data = of_device_get_match_data(&pdev->dev);
748745

749-
return s32_pinctrl_probe
750-
(pdev, (struct s32_pinctrl_soc_info *) of_id->data);
746+
return s32_pinctrl_probe(pdev, soc_data);
751747
}
752748

753749
static const struct dev_pm_ops s32g_pinctrl_pm_ops = {

0 commit comments

Comments
 (0)