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