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>
17 struct fsl_soc_die_attr {
24 const char *sfp_compat;
28 /* SoC die attribute definition for QorIQ platform */
29 static const struct fsl_soc_die_attr fsl_soc_die[] = {
31 * Power Architecture-based SoCs T Series
34 /* Die: T4240, SoC: T4240/T4160/T4080 */
39 /* Die: T1040, SoC: T1040/T1020/T1042/T1022 */
44 /* Die: T2080, SoC: T2080/T2081 */
49 /* Die: T1024, SoC: T1024/T1014/T1023/T1013 */
56 * ARM-based SoCs LS Series
59 /* Die: LS1043A, SoC: LS1043A/LS1023A */
64 /* Die: LS2080A, SoC: LS2080A/LS2040A/LS2085A */
69 /* Die: LS1088A, SoC: LS1088A/LS1048A/LS1084A/LS1044A */
74 /* Die: LS1012A, SoC: LS1012A */
79 /* Die: LS1046A, SoC: LS1046A/LS1026A */
84 /* Die: LS2088A, SoC: LS2088A/LS2048A/LS2084A/LS2044A */
89 /* Die: LS1021A, SoC: LS1021A/LS1020A/LS1022A */
94 /* Die: LX2160A, SoC: LX2160A/LX2120A/LX2080A */
99 /* Die: LS1028A, SoC: LS1028A */
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 u64 fsl_guts_get_soc_uid(const char *compat, unsigned int offset)
120 struct device_node *np;
121 void __iomem *sfp_base;
124 np = of_find_compatible_node(NULL, NULL, compat);
128 sfp_base = of_iomap(np, 0);
134 uid = ioread32(sfp_base + offset);
136 uid |= ioread32(sfp_base + offset + 4);
144 static const struct fsl_soc_data ls1028a_data = {
145 .sfp_compat = "fsl,ls1028a-sfp",
150 * Table for matching compatible strings, for device tree
151 * guts node, for Freescale QorIQ SOCs.
153 static const struct of_device_id fsl_guts_of_match[] = {
154 { .compatible = "fsl,qoriq-device-config-1.0", },
155 { .compatible = "fsl,qoriq-device-config-2.0", },
156 { .compatible = "fsl,p1010-guts", },
157 { .compatible = "fsl,p1020-guts", },
158 { .compatible = "fsl,p1021-guts", },
159 { .compatible = "fsl,p1022-guts", },
160 { .compatible = "fsl,p1023-guts", },
161 { .compatible = "fsl,p2020-guts", },
162 { .compatible = "fsl,bsc9131-guts", },
163 { .compatible = "fsl,bsc9132-guts", },
164 { .compatible = "fsl,mpc8536-guts", },
165 { .compatible = "fsl,mpc8544-guts", },
166 { .compatible = "fsl,mpc8548-guts", },
167 { .compatible = "fsl,mpc8568-guts", },
168 { .compatible = "fsl,mpc8569-guts", },
169 { .compatible = "fsl,mpc8572-guts", },
170 { .compatible = "fsl,ls1021a-dcfg", },
171 { .compatible = "fsl,ls1043a-dcfg", },
172 { .compatible = "fsl,ls2080a-dcfg", },
173 { .compatible = "fsl,ls1088a-dcfg", },
174 { .compatible = "fsl,ls1012a-dcfg", },
175 { .compatible = "fsl,ls1046a-dcfg", },
176 { .compatible = "fsl,lx2160a-dcfg", },
177 { .compatible = "fsl,ls1028a-dcfg", .data = &ls1028a_data},
181 static int __init fsl_guts_init(void)
183 struct soc_device_attribute *soc_dev_attr;
184 static struct soc_device *soc_dev;
185 const struct fsl_soc_die_attr *soc_die;
186 const struct fsl_soc_data *soc_data;
187 const struct of_device_id *match;
188 struct ccsr_guts __iomem *regs;
189 const char *machine = NULL;
190 struct device_node *np;
196 np = of_find_matching_node_and_match(NULL, fsl_guts_of_match, &match);
199 soc_data = match->data;
201 regs = of_iomap(np, 0);
207 little_endian = of_property_read_bool(np, "little-endian");
209 svr = ioread32(®s->svr);
211 svr = ioread32be(®s->svr);
215 /* Register soc device */
216 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
220 if (of_property_read_string(of_root, "model", &machine))
221 of_property_read_string_index(of_root, "compatible", 0, &machine);
223 soc_dev_attr->machine = kstrdup(machine, GFP_KERNEL);
224 if (!soc_dev_attr->machine)
228 soc_die = fsl_soc_die_match(svr, fsl_soc_die);
230 soc_dev_attr->family = kasprintf(GFP_KERNEL, "QorIQ %s",
233 soc_dev_attr->family = kasprintf(GFP_KERNEL, "QorIQ");
235 if (!soc_dev_attr->family)
238 soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "svr:0x%08x", svr);
239 if (!soc_dev_attr->soc_id)
242 soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d.%d",
243 (svr >> 4) & 0xf, svr & 0xf);
244 if (!soc_dev_attr->revision)
248 soc_uid = fsl_guts_get_soc_uid(soc_data->sfp_compat,
249 soc_data->uid_offset);
251 soc_dev_attr->serial_number = kasprintf(GFP_KERNEL, "%016llX",
254 soc_dev = soc_device_register(soc_dev_attr);
255 if (IS_ERR(soc_dev)) {
256 ret = PTR_ERR(soc_dev);
260 pr_info("Machine: %s\n", soc_dev_attr->machine);
261 pr_info("SoC family: %s\n", soc_dev_attr->family);
262 pr_info("SoC ID: %s, Revision: %s\n",
263 soc_dev_attr->soc_id, soc_dev_attr->revision);
270 kfree(soc_dev_attr->machine);
271 kfree(soc_dev_attr->family);
272 kfree(soc_dev_attr->soc_id);
273 kfree(soc_dev_attr->revision);
274 kfree(soc_dev_attr->serial_number);
279 core_initcall(fsl_guts_init);