2 * Freescale QorIQ Platforms GUTS Driver
4 * Copyright (C) 2016 Freescale Semiconductor, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/of_fdt.h>
16 #include <linux/sys_soc.h>
17 #include <linux/of_address.h>
18 #include <linux/platform_device.h>
19 #include <linux/fsl/guts.h>
22 struct ccsr_guts __iomem *regs;
26 struct fsl_soc_die_attr {
32 static struct guts *guts;
33 static struct soc_device_attribute soc_dev_attr;
34 static struct soc_device *soc_dev;
35 static struct device_node *root;
38 /* SoC die attribute definition for QorIQ platform */
39 static const struct fsl_soc_die_attr fsl_soc_die[] = {
41 * Power Architecture-based SoCs T Series
44 /* Die: T4240, SoC: T4240/T4160/T4080 */
49 /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
54 /* Die: T2080, SoC: T2080/T2081 */
59 /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
66 * ARM-based SoCs LS Series
69 /* Die: LS1043A, SoC: LS1043A/LS1023A */
74 /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
79 /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
84 /* Die: LS1012A, SoC: LS1012A */
89 /* Die: LS1046A, SoC: LS1046A/LS1026A */
94 /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
99 /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
107 static const struct fsl_soc_die_attr *fsl_soc_die_match(
108 u32 svr, const struct fsl_soc_die_attr *matches)
110 while (matches->svr) {
111 if (matches->svr == (svr & matches->mask))
118 static u32 fsl_guts_get_svr(void)
122 if (!guts || !guts->regs)
125 if (guts->little_endian)
126 svr = ioread32(&guts->regs->svr);
128 svr = ioread32be(&guts->regs->svr);
133 static int fsl_guts_probe(struct platform_device *pdev)
135 struct device_node *np = pdev->dev.of_node;
136 struct device *dev = &pdev->dev;
137 struct resource *res;
138 const struct fsl_soc_die_attr *soc_die;
142 /* Initialize guts */
143 guts = devm_kzalloc(dev, sizeof(*guts), GFP_KERNEL);
147 guts->little_endian = of_property_read_bool(np, "little-endian");
149 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
150 guts->regs = devm_ioremap_resource(dev, res);
151 if (IS_ERR(guts->regs))
152 return PTR_ERR(guts->regs);
154 /* Register soc device */
155 root = of_find_node_by_path("/");
156 if (of_property_read_string(root, "model", &machine))
157 of_property_read_string_index(root, "compatible", 0, &machine);
159 soc_dev_attr.machine = machine;
161 svr = fsl_guts_get_svr();
162 soc_die = fsl_soc_die_match(svr, fsl_soc_die);
164 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL,
165 "QorIQ %s", soc_die->die);
167 soc_dev_attr.family = devm_kasprintf(dev, GFP_KERNEL, "QorIQ");
169 if (!soc_dev_attr.family)
171 soc_dev_attr.soc_id = devm_kasprintf(dev, GFP_KERNEL,
173 if (!soc_dev_attr.soc_id)
175 soc_dev_attr.revision = devm_kasprintf(dev, GFP_KERNEL, "%d.%d",
176 (svr >> 4) & 0xf, svr & 0xf);
177 if (!soc_dev_attr.revision)
180 soc_dev = soc_device_register(&soc_dev_attr);
182 return PTR_ERR(soc_dev);
184 pr_info("Machine: %s\n", soc_dev_attr.machine);
185 pr_info("SoC family: %s\n", soc_dev_attr.family);
186 pr_info("SoC ID: %s, Revision: %s\n",
187 soc_dev_attr.soc_id, soc_dev_attr.revision);
191 static int fsl_guts_remove(struct platform_device *dev)
193 soc_device_unregister(soc_dev);
199 * Table for matching compatible strings, for device tree
200 * guts node, for Freescale QorIQ SOCs.
202 static const struct of_device_id fsl_guts_of_match[] = {
203 { .compatible = "fsl,qoriq-device-config-1.0", },
204 { .compatible = "fsl,qoriq-device-config-2.0", },
205 { .compatible = "fsl,p1010-guts", },
206 { .compatible = "fsl,p1020-guts", },
207 { .compatible = "fsl,p1021-guts", },
208 { .compatible = "fsl,p1022-guts", },
209 { .compatible = "fsl,p1023-guts", },
210 { .compatible = "fsl,p2020-guts", },
211 { .compatible = "fsl,bsc9131-guts", },
212 { .compatible = "fsl,bsc9132-guts", },
213 { .compatible = "fsl,mpc8536-guts", },
214 { .compatible = "fsl,mpc8544-guts", },
215 { .compatible = "fsl,mpc8548-guts", },
216 { .compatible = "fsl,mpc8568-guts", },
217 { .compatible = "fsl,mpc8569-guts", },
218 { .compatible = "fsl,mpc8572-guts", },
219 { .compatible = "fsl,ls1021a-dcfg", },
220 { .compatible = "fsl,ls1043a-dcfg", },
221 { .compatible = "fsl,ls2080a-dcfg", },
222 { .compatible = "fsl,ls1088a-dcfg", },
223 { .compatible = "fsl,ls1012a-dcfg", },
224 { .compatible = "fsl,ls1046a-dcfg", },
227 MODULE_DEVICE_TABLE(of, fsl_guts_of_match);
229 static struct platform_driver fsl_guts_driver = {
232 .of_match_table = fsl_guts_of_match,
234 .probe = fsl_guts_probe,
235 .remove = fsl_guts_remove,
238 static int __init fsl_guts_init(void)
240 return platform_driver_register(&fsl_guts_driver);
242 core_initcall(fsl_guts_init);
244 static void __exit fsl_guts_exit(void)
246 platform_driver_unregister(&fsl_guts_driver);
248 module_exit(fsl_guts_exit);