]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/id.c
Merge branch 'omap-fixes'
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / id.c
1 /*
2  * linux/arch/arm/mach-omap2/id.c
3  *
4  * OMAP2 CPU identification code
5  *
6  * Copyright (C) 2005 Nokia Corporation
7  * Written by Tony Lindgren <tony@atomide.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/io.h>
18
19 #include <asm/cputype.h>
20
21 #include <mach/common.h>
22 #include <mach/control.h>
23 #include <mach/cpu.h>
24
25 static struct omap_chip_id omap_chip;
26 static unsigned int omap_revision;
27
28
29 unsigned int omap_rev(void)
30 {
31         return omap_revision;
32 }
33 EXPORT_SYMBOL(omap_rev);
34
35 /**
36  * omap_chip_is - test whether currently running OMAP matches a chip type
37  * @oc: omap_chip_t to test against
38  *
39  * Test whether the currently-running OMAP chip matches the supplied
40  * chip type 'oc'.  Returns 1 upon a match; 0 upon failure.
41  */
42 int omap_chip_is(struct omap_chip_id oci)
43 {
44         return (oci.oc & omap_chip.oc) ? 1 : 0;
45 }
46 EXPORT_SYMBOL(omap_chip_is);
47
48 int omap_type(void)
49 {
50         u32 val = 0;
51
52         if (cpu_is_omap24xx()) {
53                 val = omap_ctrl_readl(OMAP24XX_CONTROL_STATUS);
54         } else if (cpu_is_omap34xx()) {
55                 val = omap_ctrl_readl(OMAP343X_CONTROL_STATUS);
56         } else {
57                 pr_err("Cannot detect omap type!\n");
58                 goto out;
59         }
60
61         val &= OMAP2_DEVICETYPE_MASK;
62         val >>= 8;
63
64 out:
65         return val;
66 }
67 EXPORT_SYMBOL(omap_type);
68
69
70 /*----------------------------------------------------------------------------*/
71
72 #define OMAP_TAP_IDCODE         0x0204
73 #define OMAP_TAP_DIE_ID_0       0x0218
74 #define OMAP_TAP_DIE_ID_1       0x021C
75 #define OMAP_TAP_DIE_ID_2       0x0220
76 #define OMAP_TAP_DIE_ID_3       0x0224
77
78 #define read_tap_reg(reg)       __raw_readl(tap_base  + (reg))
79
80 struct omap_id {
81         u16     hawkeye;        /* Silicon type (Hawkeye id) */
82         u8      dev;            /* Device type from production_id reg */
83         u32     type;           /* Combined type id copied to omap_revision */
84 };
85
86 /* Register values to detect the OMAP version */
87 static struct omap_id omap_ids[] __initdata = {
88         { .hawkeye = 0xb5d9, .dev = 0x0, .type = 0x24200024 },
89         { .hawkeye = 0xb5d9, .dev = 0x1, .type = 0x24201024 },
90         { .hawkeye = 0xb5d9, .dev = 0x2, .type = 0x24202024 },
91         { .hawkeye = 0xb5d9, .dev = 0x4, .type = 0x24220024 },
92         { .hawkeye = 0xb5d9, .dev = 0x8, .type = 0x24230024 },
93         { .hawkeye = 0xb68a, .dev = 0x0, .type = 0x24300024 },
94 };
95
96 static void __iomem *tap_base;
97 static u16 tap_prod_id;
98
99 void __init omap24xx_check_revision(void)
100 {
101         int i, j;
102         u32 idcode, prod_id;
103         u16 hawkeye;
104         u8  dev_type, rev;
105
106         idcode = read_tap_reg(OMAP_TAP_IDCODE);
107         prod_id = read_tap_reg(tap_prod_id);
108         hawkeye = (idcode >> 12) & 0xffff;
109         rev = (idcode >> 28) & 0x0f;
110         dev_type = (prod_id >> 16) & 0x0f;
111
112         pr_debug("OMAP_TAP_IDCODE 0x%08x REV %i HAWKEYE 0x%04x MANF %03x\n",
113                  idcode, rev, hawkeye, (idcode >> 1) & 0x7ff);
114         pr_debug("OMAP_TAP_DIE_ID_0: 0x%08x\n",
115                  read_tap_reg(OMAP_TAP_DIE_ID_0));
116         pr_debug("OMAP_TAP_DIE_ID_1: 0x%08x DEV_REV: %i\n",
117                  read_tap_reg(OMAP_TAP_DIE_ID_1),
118                  (read_tap_reg(OMAP_TAP_DIE_ID_1) >> 28) & 0xf);
119         pr_debug("OMAP_TAP_DIE_ID_2: 0x%08x\n",
120                  read_tap_reg(OMAP_TAP_DIE_ID_2));
121         pr_debug("OMAP_TAP_DIE_ID_3: 0x%08x\n",
122                  read_tap_reg(OMAP_TAP_DIE_ID_3));
123         pr_debug("OMAP_TAP_PROD_ID_0: 0x%08x DEV_TYPE: %i\n",
124                  prod_id, dev_type);
125
126         /* Check hawkeye ids */
127         for (i = 0; i < ARRAY_SIZE(omap_ids); i++) {
128                 if (hawkeye == omap_ids[i].hawkeye)
129                         break;
130         }
131
132         if (i == ARRAY_SIZE(omap_ids)) {
133                 printk(KERN_ERR "Unknown OMAP CPU id\n");
134                 return;
135         }
136
137         for (j = i; j < ARRAY_SIZE(omap_ids); j++) {
138                 if (dev_type == omap_ids[j].dev)
139                         break;
140         }
141
142         if (j == ARRAY_SIZE(omap_ids)) {
143                 printk(KERN_ERR "Unknown OMAP device type. "
144                                 "Handling it as OMAP%04x\n",
145                                 omap_ids[i].type >> 16);
146                 j = i;
147         }
148
149         pr_info("OMAP%04x", omap_rev() >> 16);
150         if ((omap_rev() >> 8) & 0x0f)
151                 pr_info("ES%x", (omap_rev() >> 12) & 0xf);
152         pr_info("\n");
153 }
154
155 void __init omap34xx_check_revision(void)
156 {
157         u32 cpuid, idcode;
158         u16 hawkeye;
159         u8 rev;
160         char *rev_name = "ES1.0";
161
162         /*
163          * We cannot access revision registers on ES1.0.
164          * If the processor type is Cortex-A8 and the revision is 0x0
165          * it means its Cortex r0p0 which is 3430 ES1.0.
166          */
167         cpuid = read_cpuid(CPUID_ID);
168         if ((((cpuid >> 4) & 0xfff) == 0xc08) && ((cpuid & 0xf) == 0x0)) {
169                 omap_revision = OMAP3430_REV_ES1_0;
170                 goto out;
171         }
172
173         /*
174          * Detection for 34xx ES2.0 and above can be done with just
175          * hawkeye and rev. See TRM 1.5.2 Device Identification.
176          * Note that rev does not map directly to our defined processor
177          * revision numbers as ES1.0 uses value 0.
178          */
179         idcode = read_tap_reg(OMAP_TAP_IDCODE);
180         hawkeye = (idcode >> 12) & 0xffff;
181         rev = (idcode >> 28) & 0xff;
182
183         if (hawkeye == 0xb7ae) {
184                 switch (rev) {
185                 case 0:
186                         omap_revision = OMAP3430_REV_ES2_0;
187                         rev_name = "ES2.0";
188                         break;
189                 case 2:
190                         omap_revision = OMAP3430_REV_ES2_1;
191                         rev_name = "ES2.1";
192                         break;
193                 case 3:
194                         omap_revision = OMAP3430_REV_ES3_0;
195                         rev_name = "ES3.0";
196                         break;
197                 case 4:
198                         omap_revision = OMAP3430_REV_ES3_1;
199                         rev_name = "ES3.1";
200                         break;
201                 default:
202                         /* Use the latest known revision as default */
203                         omap_revision = OMAP3430_REV_ES3_1;
204                         rev_name = "Unknown revision\n";
205                 }
206         }
207
208 out:
209         pr_info("OMAP%04x %s\n", omap_rev() >> 16, rev_name);
210 }
211
212 /*
213  * Try to detect the exact revision of the omap we're running on
214  */
215 void __init omap2_check_revision(void)
216 {
217         /*
218          * At this point we have an idea about the processor revision set
219          * earlier with omap2_set_globals_tap().
220          */
221         if (cpu_is_omap24xx())
222                 omap24xx_check_revision();
223         else if (cpu_is_omap34xx())
224                 omap34xx_check_revision();
225         else
226                 pr_err("OMAP revision unknown, please fix!\n");
227
228         /*
229          * OK, now we know the exact revision. Initialize omap_chip bits
230          * for powerdowmain and clockdomain code.
231          */
232         if (cpu_is_omap243x()) {
233                 /* Currently only supports 2430ES2.1 and 2430-all */
234                 omap_chip.oc |= CHIP_IS_OMAP2430;
235         } else if (cpu_is_omap242x()) {
236                 /* Currently only supports 2420ES2.1.1 and 2420-all */
237                 omap_chip.oc |= CHIP_IS_OMAP2420;
238         } else if (cpu_is_omap343x()) {
239                 omap_chip.oc = CHIP_IS_OMAP3430;
240                 if (omap_rev() == OMAP3430_REV_ES1_0)
241                         omap_chip.oc |= CHIP_IS_OMAP3430ES1;
242                 else if (omap_rev() >= OMAP3430_REV_ES2_0 &&
243                          omap_rev() <= OMAP3430_REV_ES2_1)
244                         omap_chip.oc |= CHIP_IS_OMAP3430ES2;
245                 else if (omap_rev() == OMAP3430_REV_ES3_0)
246                         omap_chip.oc |= CHIP_IS_OMAP3430ES3_0;
247                 else if (omap_rev() == OMAP3430_REV_ES3_1)
248                         omap_chip.oc |= CHIP_IS_OMAP3430ES3_1;
249         } else {
250                 pr_err("Uninitialized omap_chip, please fix!\n");
251         }
252 }
253
254 /*
255  * Set up things for map_io and processor detection later on. Gets called
256  * pretty much first thing from board init. For multi-omap, this gets
257  * cpu_is_omapxxxx() working accurately enough for map_io. Then we'll try to
258  * detect the exact revision later on in omap2_detect_revision() once map_io
259  * is done.
260  */
261 void __init omap2_set_globals_tap(struct omap_globals *omap2_globals)
262 {
263         omap_revision = omap2_globals->class;
264         tap_base = omap2_globals->tap;
265
266         if (cpu_is_omap34xx())
267                 tap_prod_id = 0x0210;
268         else
269                 tap_prod_id = 0x0208;
270 }