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