983004d0fef20bc6f419e96358410f7015cada0b
[deliverable/linux.git] / arch / arm / mach-ux500 / id.c
1 /*
2 * Copyright (C) ST-Ericsson SA 2010
3 *
4 * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
5 * License terms: GNU General Public License (GPL) version 2
6 */
7
8 #include <linux/kernel.h>
9 #include <linux/init.h>
10 #include <linux/io.h>
11 #include <linux/random.h>
12 #include <linux/slab.h>
13 #include <linux/sys_soc.h>
14
15 #include <asm/cputype.h>
16 #include <asm/tlbflush.h>
17 #include <asm/cacheflush.h>
18 #include <asm/mach/map.h>
19
20 #include "setup.h"
21
22 #include "db8500-regs.h"
23
24 /**
25 * struct dbx500_asic_id - fields of the ASIC ID
26 * @process: the manufacturing process, 0x40 is 40 nm 0x00 is "standard"
27 * @partnumber: hithereto 0x8500 for DB8500
28 * @revision: version code in the series
29 */
30 struct dbx500_asic_id {
31 u16 partnumber;
32 u8 revision;
33 u8 process;
34 };
35
36 static struct dbx500_asic_id dbx500_id;
37
38 static unsigned int __init ux500_read_asicid(phys_addr_t addr)
39 {
40 void __iomem *virt = ioremap(addr, 4);
41 unsigned int asicid;
42
43 if (!virt)
44 return 0;
45
46 asicid = readl(virt);
47 iounmap(virt);
48
49 return asicid;
50 }
51
52 static void ux500_print_soc_info(unsigned int asicid)
53 {
54 unsigned int rev = dbx500_id.revision;
55
56 pr_info("DB%4x ", dbx500_id.partnumber);
57
58 if (rev == 0x01)
59 pr_cont("Early Drop");
60 else if (rev >= 0xA0)
61 pr_cont("v%d.%d" , (rev >> 4) - 0xA + 1, rev & 0xf);
62 else
63 pr_cont("Unknown");
64
65 pr_cont(" [%#010x]\n", asicid);
66 }
67
68 static unsigned int partnumber(unsigned int asicid)
69 {
70 return (asicid >> 8) & 0xffff;
71 }
72
73 /*
74 * SOC MIDR ASICID ADDRESS ASICID VALUE
75 * DB8500ed 0x410fc090 0x9001FFF4 0x00850001
76 * DB8500v1 0x411fc091 0x9001FFF4 0x008500A0
77 * DB8500v1.1 0x411fc091 0x9001FFF4 0x008500A1
78 * DB8500v2 0x412fc091 0x9001DBF4 0x008500B0
79 * DB8520v2.2 0x412fc091 0x9001DBF4 0x008500B2
80 * DB5500v1 0x412fc091 0x9001FFF4 0x005500A0
81 * DB9540 0x413fc090 0xFFFFDBF4 0x009540xx
82 */
83
84 static void __init ux500_setup_id(void)
85 {
86 unsigned int cpuid = read_cpuid_id();
87 unsigned int asicid = 0;
88 phys_addr_t addr = 0;
89
90 switch (cpuid) {
91 case 0x410fc090: /* DB8500ed */
92 case 0x411fc091: /* DB8500v1 */
93 addr = 0x9001FFF4;
94 break;
95
96 case 0x412fc091: /* DB8520 / DB8500v2 / DB5500v1 */
97 asicid = ux500_read_asicid(0x9001DBF4);
98 if (partnumber(asicid) == 0x8500 ||
99 partnumber(asicid) == 0x8520)
100 /* DB8500v2 */
101 break;
102
103 /* DB5500v1 */
104 addr = 0x9001FFF4;
105 break;
106
107 case 0x413fc090: /* DB9540 */
108 addr = 0xFFFFDBF4;
109 break;
110 }
111
112 if (addr)
113 asicid = ux500_read_asicid(addr);
114
115 if (!asicid) {
116 pr_err("Unable to identify SoC\n");
117 BUG();
118 }
119
120 dbx500_id.process = asicid >> 24;
121 dbx500_id.partnumber = partnumber(asicid);
122 dbx500_id.revision = asicid & 0xff;
123
124 ux500_print_soc_info(asicid);
125 }
126
127 static const char * __init ux500_get_machine(void)
128 {
129 return kasprintf(GFP_KERNEL, "DB%4x", dbx500_id.partnumber);
130 }
131
132 static const char * __init ux500_get_family(void)
133 {
134 return kasprintf(GFP_KERNEL, "ux500");
135 }
136
137 static const char * __init ux500_get_revision(void)
138 {
139 unsigned int rev = dbx500_id.revision;
140
141 if (rev == 0x01)
142 return kasprintf(GFP_KERNEL, "%s", "ED");
143 else if (rev >= 0xA0)
144 return kasprintf(GFP_KERNEL, "%d.%d",
145 (rev >> 4) - 0xA + 1, rev & 0xf);
146
147 return kasprintf(GFP_KERNEL, "%s", "Unknown");
148 }
149
150 static ssize_t ux500_get_process(struct device *dev,
151 struct device_attribute *attr,
152 char *buf)
153 {
154 if (dbx500_id.process == 0x00)
155 return sprintf(buf, "Standard\n");
156
157 return sprintf(buf, "%02xnm\n", dbx500_id.process);
158 }
159
160 static const char *db8500_read_soc_id(void)
161 {
162 void __iomem *uid;
163 const char *retstr;
164
165 uid = ioremap(U8500_BB_UID_BASE, 0x20);
166 if (!uid)
167 return NULL;
168 /* Throw these device-specific numbers into the entropy pool */
169 add_device_randomness(uid, 0x14);
170 retstr = kasprintf(GFP_KERNEL, "%08x%08x%08x%08x%08x",
171 readl((u32 *)uid+0),
172 readl((u32 *)uid+1), readl((u32 *)uid+2),
173 readl((u32 *)uid+3), readl((u32 *)uid+4));
174 iounmap(uid);
175 return retstr;
176 }
177
178 static void __init soc_info_populate(struct soc_device_attribute *soc_dev_attr)
179 {
180 soc_dev_attr->soc_id = db8500_read_soc_id();
181 soc_dev_attr->machine = ux500_get_machine();
182 soc_dev_attr->family = ux500_get_family();
183 soc_dev_attr->revision = ux500_get_revision();
184 }
185
186 static const struct device_attribute ux500_soc_attr =
187 __ATTR(process, S_IRUGO, ux500_get_process, NULL);
188
189 struct device * __init ux500_soc_device_init(void)
190 {
191 struct device *parent;
192 struct soc_device *soc_dev;
193 struct soc_device_attribute *soc_dev_attr;
194
195 ux500_setup_id();
196
197 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
198 if (!soc_dev_attr)
199 return ERR_PTR(-ENOMEM);
200
201 soc_info_populate(soc_dev_attr);
202
203 soc_dev = soc_device_register(soc_dev_attr);
204 if (IS_ERR(soc_dev)) {
205 kfree(soc_dev_attr);
206 return NULL;
207 }
208
209 parent = soc_device_to_device(soc_dev);
210 device_create_file(parent, &ux500_soc_attr);
211
212 return parent;
213 }
This page took 0.040869 seconds and 5 git commands to generate.