1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Freescale QorIQ Platforms GUTS Driver
5 * Copyright (C) 2016 Freescale Semiconductor, Inc.
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>
18 struct ccsr_guts __iomem
*regs
;
22 struct fsl_soc_die_attr
{
28 static struct guts
*guts
;
29 static struct soc_device_attribute soc_dev_attr
;
30 static struct soc_device
*soc_dev
;
31 static struct device_node
*root
;
34 /* SoC die attribute definition for QorIQ platform */
35 static const struct fsl_soc_die_attr fsl_soc_die
[] = {
37 * Power Architecture-based SoCs T Series
40 /* Die: T4240, SoC: T4240/T4160/T4080 */
45 /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
50 /* Die: T2080, SoC: T2080/T2081 */
55 /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
62 * ARM-based SoCs LS Series
65 /* Die: LS1043A, SoC: LS1043A/LS1023A */
70 /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
75 /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
80 /* Die: LS1012A, SoC: LS1012A */
85 /* Die: LS1046A, SoC: LS1046A/LS1026A */
90 /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
95 /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
100 /* Die: LX2160A, SoC: LX2160A/LX2120A/LX2080A */
105 /* Die: LS1028A, SoC: LS1028A */
113 static const struct fsl_soc_die_attr
*fsl_soc_die_match(
114 u32 svr
, const struct fsl_soc_die_attr
*matches
)
116 while (matches
->svr
) {
117 if (matches
->svr
== (svr
& matches
->mask
))
124 static u32
fsl_guts_get_svr(void)
128 if (!guts
|| !guts
->regs
)
131 if (guts
->little_endian
)
132 svr
= ioread32(&guts
->regs
->svr
);
134 svr
= ioread32be(&guts
->regs
->svr
);
139 static int fsl_guts_probe(struct platform_device
*pdev
)
141 struct device_node
*np
= pdev
->dev
.of_node
;
142 struct device
*dev
= &pdev
->dev
;
143 struct resource
*res
;
144 const struct fsl_soc_die_attr
*soc_die
;
148 /* Initialize guts */
149 guts
= devm_kzalloc(dev
, sizeof(*guts
), GFP_KERNEL
);
153 guts
->little_endian
= of_property_read_bool(np
, "little-endian");
155 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
156 guts
->regs
= devm_ioremap_resource(dev
, res
);
157 if (IS_ERR(guts
->regs
))
158 return PTR_ERR(guts
->regs
);
160 /* Register soc device */
161 root
= of_find_node_by_path("/");
162 if (of_property_read_string(root
, "model", &machine
))
163 of_property_read_string_index(root
, "compatible", 0, &machine
);
165 soc_dev_attr
.machine
= machine
;
167 svr
= fsl_guts_get_svr();
168 soc_die
= fsl_soc_die_match(svr
, fsl_soc_die
);
170 soc_dev_attr
.family
= devm_kasprintf(dev
, GFP_KERNEL
,
171 "QorIQ %s", soc_die
->die
);
173 soc_dev_attr
.family
= devm_kasprintf(dev
, GFP_KERNEL
, "QorIQ");
175 if (!soc_dev_attr
.family
)
177 soc_dev_attr
.soc_id
= devm_kasprintf(dev
, GFP_KERNEL
,
179 if (!soc_dev_attr
.soc_id
)
181 soc_dev_attr
.revision
= devm_kasprintf(dev
, GFP_KERNEL
, "%d.%d",
182 (svr
>> 4) & 0xf, svr
& 0xf);
183 if (!soc_dev_attr
.revision
)
186 soc_dev
= soc_device_register(&soc_dev_attr
);
188 return PTR_ERR(soc_dev
);
190 pr_info("Machine: %s\n", soc_dev_attr
.machine
);
191 pr_info("SoC family: %s\n", soc_dev_attr
.family
);
192 pr_info("SoC ID: %s, Revision: %s\n",
193 soc_dev_attr
.soc_id
, soc_dev_attr
.revision
);
197 static int fsl_guts_remove(struct platform_device
*dev
)
199 soc_device_unregister(soc_dev
);
205 * Table for matching compatible strings, for device tree
206 * guts node, for Freescale QorIQ SOCs.
208 static const struct of_device_id fsl_guts_of_match
[] = {
209 { .compatible
= "fsl,qoriq-device-config-1.0", },
210 { .compatible
= "fsl,qoriq-device-config-2.0", },
211 { .compatible
= "fsl,p1010-guts", },
212 { .compatible
= "fsl,p1020-guts", },
213 { .compatible
= "fsl,p1021-guts", },
214 { .compatible
= "fsl,p1022-guts", },
215 { .compatible
= "fsl,p1023-guts", },
216 { .compatible
= "fsl,p2020-guts", },
217 { .compatible
= "fsl,bsc9131-guts", },
218 { .compatible
= "fsl,bsc9132-guts", },
219 { .compatible
= "fsl,mpc8536-guts", },
220 { .compatible
= "fsl,mpc8544-guts", },
221 { .compatible
= "fsl,mpc8548-guts", },
222 { .compatible
= "fsl,mpc8568-guts", },
223 { .compatible
= "fsl,mpc8569-guts", },
224 { .compatible
= "fsl,mpc8572-guts", },
225 { .compatible
= "fsl,ls1021a-dcfg", },
226 { .compatible
= "fsl,ls1043a-dcfg", },
227 { .compatible
= "fsl,ls2080a-dcfg", },
228 { .compatible
= "fsl,ls1088a-dcfg", },
229 { .compatible
= "fsl,ls1012a-dcfg", },
230 { .compatible
= "fsl,ls1046a-dcfg", },
231 { .compatible
= "fsl,lx2160a-dcfg", },
232 { .compatible
= "fsl,ls1028a-dcfg", },
235 MODULE_DEVICE_TABLE(of
, fsl_guts_of_match
);
237 static struct platform_driver fsl_guts_driver
= {
240 .of_match_table
= fsl_guts_of_match
,
242 .probe
= fsl_guts_probe
,
243 .remove
= fsl_guts_remove
,
246 static int __init
fsl_guts_init(void)
248 return platform_driver_register(&fsl_guts_driver
);
250 core_initcall(fsl_guts_init
);
252 static void __exit
fsl_guts_exit(void)
254 platform_driver_unregister(&fsl_guts_driver
);
256 module_exit(fsl_guts_exit
);