]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/sh/kernel/cpu/sh4/probe.c
ARM: OMAP: Misc compile fixes after syncing with mainline
[linux-2.6-omap-h63xx.git] / arch / sh / kernel / cpu / sh4 / probe.c
1 /*
2  * arch/sh/kernel/cpu/sh4/probe.c
3  *
4  * CPU Subtype Probing for SH-4.
5  *
6  * Copyright (C) 2001 - 2007  Paul Mundt
7  * Copyright (C) 2003  Richard Curnow
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License.  See the file "COPYING" in the main directory of this archive
11  * for more details.
12  */
13 #include <linux/init.h>
14 #include <linux/io.h>
15 #include <asm/processor.h>
16 #include <asm/cache.h>
17
18 int __init detect_cpu_and_cache_system(void)
19 {
20         unsigned long pvr, prr, cvr;
21         unsigned long size;
22
23         static unsigned long sizes[16] = {
24                 [1] = (1 << 12),
25                 [2] = (1 << 13),
26                 [4] = (1 << 14),
27                 [8] = (1 << 15),
28                 [9] = (1 << 16)
29         };
30
31         pvr = (ctrl_inl(CCN_PVR) >> 8) & 0xffffff;
32         prr = (ctrl_inl(CCN_PRR) >> 4) & 0xff;
33         cvr = (ctrl_inl(CCN_CVR));
34
35         /*
36          * Setup some sane SH-4 defaults for the icache
37          */
38         boot_cpu_data.icache.way_incr           = (1 << 13);
39         boot_cpu_data.icache.entry_shift        = 5;
40         boot_cpu_data.icache.sets               = 256;
41         boot_cpu_data.icache.ways               = 1;
42         boot_cpu_data.icache.linesz             = L1_CACHE_BYTES;
43
44         /*
45          * And again for the dcache ..
46          */
47         boot_cpu_data.dcache.way_incr           = (1 << 14);
48         boot_cpu_data.dcache.entry_shift        = 5;
49         boot_cpu_data.dcache.sets               = 512;
50         boot_cpu_data.dcache.ways               = 1;
51         boot_cpu_data.dcache.linesz             = L1_CACHE_BYTES;
52
53         /*
54          * Setup some generic flags we can probe on SH-4A parts
55          */
56         if (((pvr >> 16) & 0xff) == 0x10) {
57                 if ((cvr & 0x10000000) == 0)
58                         boot_cpu_data.flags |= CPU_HAS_DSP;
59
60                 boot_cpu_data.flags |= CPU_HAS_LLSC;
61         }
62
63         /* FPU detection works for everyone */
64         if ((cvr & 0x20000000) == 1)
65                 boot_cpu_data.flags |= CPU_HAS_FPU;
66
67         /* Mask off the upper chip ID */
68         pvr &= 0xffff;
69
70         /*
71          * Probe the underlying processor version/revision and
72          * adjust cpu_data setup accordingly.
73          */
74         switch (pvr) {
75         case 0x205:
76                 boot_cpu_data.type = CPU_SH7750;
77                 boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
78                                    CPU_HAS_PERF_COUNTER;
79                 break;
80         case 0x206:
81                 boot_cpu_data.type = CPU_SH7750S;
82                 boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU |
83                                    CPU_HAS_PERF_COUNTER;
84                 break;
85         case 0x1100:
86                 boot_cpu_data.type = CPU_SH7751;
87                 boot_cpu_data.flags |= CPU_HAS_FPU;
88                 break;
89         case 0x2001:
90         case 0x2004:
91                 boot_cpu_data.type = CPU_SH7770;
92                 boot_cpu_data.icache.ways = 4;
93                 boot_cpu_data.dcache.ways = 4;
94
95                 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_LLSC;
96                 break;
97         case 0x2006:
98         case 0x200A:
99                 if (prr == 0x61)
100                         boot_cpu_data.type = CPU_SH7781;
101                 else if (prr == 0xa1)
102                         boot_cpu_data.type = CPU_SH7763;
103                 else
104                         boot_cpu_data.type = CPU_SH7780;
105
106                 boot_cpu_data.icache.ways = 4;
107                 boot_cpu_data.dcache.ways = 4;
108
109                 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
110                                    CPU_HAS_LLSC;
111                 break;
112         case 0x3000:
113         case 0x3003:
114         case 0x3009:
115                 boot_cpu_data.type = CPU_SH7343;
116                 boot_cpu_data.icache.ways = 4;
117                 boot_cpu_data.dcache.ways = 4;
118                 boot_cpu_data.flags |= CPU_HAS_LLSC;
119                 break;
120         case 0x3004:
121         case 0x3007:
122                 boot_cpu_data.type = CPU_SH7785;
123                 boot_cpu_data.icache.ways = 4;
124                 boot_cpu_data.dcache.ways = 4;
125                 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
126                                           CPU_HAS_LLSC;
127                 break;
128         case 0x3008:
129                 if (prr == 0xa0) {
130                         boot_cpu_data.type = CPU_SH7722;
131                         boot_cpu_data.icache.ways = 4;
132                         boot_cpu_data.dcache.ways = 4;
133                         boot_cpu_data.flags |= CPU_HAS_LLSC;
134                 }
135                 break;
136         case 0x4000:    /* 1st cut */
137         case 0x4001:    /* 2nd cut */
138                 boot_cpu_data.type = CPU_SHX3;
139                 boot_cpu_data.icache.ways = 4;
140                 boot_cpu_data.dcache.ways = 4;
141                 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
142                                           CPU_HAS_LLSC;
143                 break;
144         case 0x700:
145                 boot_cpu_data.type = CPU_SH4_501;
146                 boot_cpu_data.icache.ways = 2;
147                 boot_cpu_data.dcache.ways = 2;
148                 break;
149         case 0x600:
150                 boot_cpu_data.type = CPU_SH4_202;
151                 boot_cpu_data.icache.ways = 2;
152                 boot_cpu_data.dcache.ways = 2;
153                 boot_cpu_data.flags |= CPU_HAS_FPU;
154                 break;
155         case 0x500 ... 0x501:
156                 switch (prr) {
157                 case 0x10:
158                         boot_cpu_data.type = CPU_SH7750R;
159                         break;
160                 case 0x11:
161                         boot_cpu_data.type = CPU_SH7751R;
162                         break;
163                 case 0x50 ... 0x5f:
164                         boot_cpu_data.type = CPU_SH7760;
165                         break;
166                 }
167
168                 boot_cpu_data.icache.ways = 2;
169                 boot_cpu_data.dcache.ways = 2;
170
171                 boot_cpu_data.flags |= CPU_HAS_FPU;
172
173                 break;
174         default:
175                 boot_cpu_data.type = CPU_SH_NONE;
176                 break;
177         }
178
179 #ifdef CONFIG_SH_DIRECT_MAPPED
180         boot_cpu_data.icache.ways = 1;
181         boot_cpu_data.dcache.ways = 1;
182 #endif
183
184 #ifdef CONFIG_CPU_HAS_PTEA
185         boot_cpu_data.flags |= CPU_HAS_PTEA;
186 #endif
187
188         /*
189          * On anything that's not a direct-mapped cache, look to the CVR
190          * for I/D-cache specifics.
191          */
192         if (boot_cpu_data.icache.ways > 1) {
193                 size = sizes[(cvr >> 20) & 0xf];
194                 boot_cpu_data.icache.way_incr   = (size >> 1);
195                 boot_cpu_data.icache.sets       = (size >> 6);
196
197         }
198
199         /* And the rest of the D-cache */
200         if (boot_cpu_data.dcache.ways > 1) {
201                 size = sizes[(cvr >> 16) & 0xf];
202                 boot_cpu_data.dcache.way_incr   = (size >> 1);
203                 boot_cpu_data.dcache.sets       = (size >> 6);
204         }
205
206         /*
207          * Setup the L2 cache desc
208          *
209          * SH-4A's have an optional PIPT L2.
210          */
211         if (boot_cpu_data.flags & CPU_HAS_L2_CACHE) {
212                 /*
213                  * Size calculation is much more sensible
214                  * than it is for the L1.
215                  *
216                  * Sizes are 128KB, 258KB, 512KB, and 1MB.
217                  */
218                 size = (cvr & 0xf) << 17;
219
220                 BUG_ON(!size);
221
222                 boot_cpu_data.scache.way_incr           = (1 << 16);
223                 boot_cpu_data.scache.entry_shift        = 5;
224                 boot_cpu_data.scache.ways               = 4;
225                 boot_cpu_data.scache.linesz             = L1_CACHE_BYTES;
226
227                 boot_cpu_data.scache.entry_mask =
228                         (boot_cpu_data.scache.way_incr -
229                          boot_cpu_data.scache.linesz);
230
231                 boot_cpu_data.scache.sets       = size /
232                         (boot_cpu_data.scache.linesz *
233                          boot_cpu_data.scache.ways);
234
235                 boot_cpu_data.scache.way_size   =
236                         (boot_cpu_data.scache.sets *
237                          boot_cpu_data.scache.linesz);
238         }
239
240         return 0;
241 }