soc: fsl: guts: remove module_exit() and fsl_guts_remove()
[platform/kernel/linux-starfive.git] / drivers / soc / fsl / guts.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Freescale QorIQ Platforms GUTS Driver
4  *
5  * Copyright (C) 2016 Freescale Semiconductor, Inc.
6  */
7
8 #include <linux/io.h>
9 #include <linux/slab.h>
10 #include <linux/module.h>
11 #include <linux/of_fdt.h>
12 #include <linux/sys_soc.h>
13 #include <linux/of_address.h>
14 #include <linux/platform_device.h>
15 #include <linux/fsl/guts.h>
16
17 struct guts {
18         struct ccsr_guts __iomem *regs;
19         bool little_endian;
20 };
21
22 struct fsl_soc_die_attr {
23         char    *die;
24         u32     svr;
25         u32     mask;
26 };
27
28 static struct guts *guts;
29 static struct soc_device_attribute soc_dev_attr;
30
31
32 /* SoC die attribute definition for QorIQ platform */
33 static const struct fsl_soc_die_attr fsl_soc_die[] = {
34         /*
35          * Power Architecture-based SoCs T Series
36          */
37
38         /* Die: T4240, SoC: T4240/T4160/T4080 */
39         { .die          = "T4240",
40           .svr          = 0x82400000,
41           .mask         = 0xfff00000,
42         },
43         /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
44         { .die          = "T1040",
45           .svr          = 0x85200000,
46           .mask         = 0xfff00000,
47         },
48         /* Die: T2080, SoC: T2080/T2081 */
49         { .die          = "T2080",
50           .svr          = 0x85300000,
51           .mask         = 0xfff00000,
52         },
53         /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
54         { .die          = "T1024",
55           .svr          = 0x85400000,
56           .mask         = 0xfff00000,
57         },
58
59         /*
60          * ARM-based SoCs LS Series
61          */
62
63         /* Die: LS1043A, SoC: LS1043A/LS1023A */
64         { .die          = "LS1043A",
65           .svr          = 0x87920000,
66           .mask         = 0xffff0000,
67         },
68         /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
69         { .die          = "LS2080A",
70           .svr          = 0x87010000,
71           .mask         = 0xff3f0000,
72         },
73         /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
74         { .die          = "LS1088A",
75           .svr          = 0x87030000,
76           .mask         = 0xff3f0000,
77         },
78         /* Die: LS1012A, SoC: LS1012A */
79         { .die          = "LS1012A",
80           .svr          = 0x87040000,
81           .mask         = 0xffff0000,
82         },
83         /* Die: LS1046A, SoC: LS1046A/LS1026A */
84         { .die          = "LS1046A",
85           .svr          = 0x87070000,
86           .mask         = 0xffff0000,
87         },
88         /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
89         { .die          = "LS2088A",
90           .svr          = 0x87090000,
91           .mask         = 0xff3f0000,
92         },
93         /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
94         { .die          = "LS1021A",
95           .svr          = 0x87000000,
96           .mask         = 0xfff70000,
97         },
98         /* Die: LX2160A, SoC: LX2160A/LX2120A/LX2080A */
99         { .die          = "LX2160A",
100           .svr          = 0x87360000,
101           .mask         = 0xff3f0000,
102         },
103         /* Die: LS1028A, SoC: LS1028A */
104         { .die          = "LS1028A",
105           .svr          = 0x870b0000,
106           .mask         = 0xff3f0000,
107         },
108         { },
109 };
110
111 static const struct fsl_soc_die_attr *fsl_soc_die_match(
112         u32 svr, const struct fsl_soc_die_attr *matches)
113 {
114         while (matches->svr) {
115                 if (matches->svr == (svr & matches->mask))
116                         return matches;
117                 matches++;
118         }
119         return NULL;
120 }
121
122 static u32 fsl_guts_get_svr(void)
123 {
124         u32 svr = 0;
125
126         if (!guts || !guts->regs)
127                 return svr;
128
129         if (guts->little_endian)
130                 svr = ioread32(&guts->regs->svr);
131         else
132                 svr = ioread32be(&guts->regs->svr);
133
134         return svr;
135 }
136
137 static int fsl_guts_probe(struct platform_device *pdev)
138 {
139         struct device_node *root, *np = pdev->dev.of_node;
140         static struct soc_device *soc_dev;
141         struct device *dev = &pdev->dev;
142         const struct fsl_soc_die_attr *soc_die;
143         const char *machine = NULL;
144         u32 svr;
145
146         /* Initialize guts */
147         guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL);
148         if (!guts)
149                 return -ENOMEM;
150
151         guts->little_endian = of_property_read_bool(np, "little-endian");
152
153         guts->regs = devm_platform_ioremap_resource(pdev, 0);
154         if (IS_ERR(guts->regs))
155                 return PTR_ERR(guts->regs);
156
157         /* Register soc device */
158         root = of_find_node_by_path("/");
159         if (of_property_read_string(root, "model", &machine))
160                 of_property_read_string_index(root, "compatible", 0, &machine);
161         if (machine) {
162                 soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL);
163                 if (!soc_dev_attr.machine) {
164                         of_node_put(root);
165                         return -ENOMEM;
166                 }
167         }
168         of_node_put(root);
169
170         svr = fsl_guts_get_svr();
171         soc_die = fsl_soc_die_match(svr, fsl_soc_die);
172         if (soc_die) {
173                 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL,
174                                                      "QorIQ %s", soc_die->die);
175         } else {
176                 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");
177         }
178         if (!soc_dev_attr.family)
179                 return -ENOMEM;
180         soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,
181                                              "svr:0x%08x", svr);
182         if (!soc_dev_attr.soc_id)
183                 return -ENOMEM;
184         soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",
185                                                (svr >>  4) & 0xf, svr & 0xf);
186         if (!soc_dev_attr.revision)
187                 return -ENOMEM;
188
189         soc_dev = soc_device_register(&soc_dev_attr);
190         if (IS_ERR(soc_dev))
191                 return PTR_ERR(soc_dev);
192
193         pr_info("Machine: %s\n", soc_dev_attr.machine);
194         pr_info("SoC family: %s\n", soc_dev_attr.family);
195         pr_info("SoC ID: %s, Revision: %s\n",
196                 soc_dev_attr.soc_id, soc_dev_attr.revision);
197         return 0;
198 }
199
200 /*
201  * Table for matching compatible strings, for device tree
202  * guts node, for Freescale QorIQ SOCs.
203  */
204 static const struct of_device_id fsl_guts_of_match[] = {
205         { .compatible = "fsl,qoriq-device-config-1.0", },
206         { .compatible = "fsl,qoriq-device-config-2.0", },
207         { .compatible = "fsl,p1010-guts", },
208         { .compatible = "fsl,p1020-guts", },
209         { .compatible = "fsl,p1021-guts", },
210         { .compatible = "fsl,p1022-guts", },
211         { .compatible = "fsl,p1023-guts", },
212         { .compatible = "fsl,p2020-guts", },
213         { .compatible = "fsl,bsc9131-guts", },
214         { .compatible = "fsl,bsc9132-guts", },
215         { .compatible = "fsl,mpc8536-guts", },
216         { .compatible = "fsl,mpc8544-guts", },
217         { .compatible = "fsl,mpc8548-guts", },
218         { .compatible = "fsl,mpc8568-guts", },
219         { .compatible = "fsl,mpc8569-guts", },
220         { .compatible = "fsl,mpc8572-guts", },
221         { .compatible = "fsl,ls1021a-dcfg", },
222         { .compatible = "fsl,ls1043a-dcfg", },
223         { .compatible = "fsl,ls2080a-dcfg", },
224         { .compatible = "fsl,ls1088a-dcfg", },
225         { .compatible = "fsl,ls1012a-dcfg", },
226         { .compatible = "fsl,ls1046a-dcfg", },
227         { .compatible = "fsl,lx2160a-dcfg", },
228         { .compatible = "fsl,ls1028a-dcfg", },
229         {}
230 };
231 MODULE_DEVICE_TABLE(of, fsl_guts_of_match);
232
233 static struct platform_driver fsl_guts_driver = {
234         .driver = {
235                 .name = "fsl-guts",
236                 .of_match_table = fsl_guts_of_match,
237         },
238         .probe = fsl_guts_probe,
239 };
240
241 static int __init fsl_guts_init(void)
242 {
243         return platform_driver_register(&fsl_guts_driver);
244 }
245 core_initcall(fsl_guts_init);