[INKA4x0] NG hardware: flash support
[platform/kernel/u-boot.git] / cpu / mpc8260 / cpu.c
1 /*
2  * (C) Copyright 2000-2006
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 /*
25  * CPU specific code for the MPC825x / MPC826x / MPC827x / MPC828x
26  *
27  * written or collected and sometimes rewritten by
28  * Magnus Damm <damm@bitsmart.com>
29  *
30  * modified by
31  * Wolfgang Denk <wd@denx.de>
32  *
33  * modified for 8260 by
34  * Murray Jensen <Murray.Jensen@cmst.csiro.au>
35  *
36  * added 8260 masks by
37  * Marius Groeger <mag@sysgo.de>
38  *
39  * added HiP7 (824x/827x/8280) processors support by
40  * Yuli Barcohen <yuli@arabellasw.com>
41  */
42
43 #include <common.h>
44 #include <watchdog.h>
45 #include <command.h>
46 #include <mpc8260.h>
47 #include <asm/processor.h>
48 #include <asm/cpm_8260.h>
49
50 #if defined(CONFIG_OF_LIBFDT)
51 #include <libfdt.h>
52 #include <libfdt_env.h>
53 #endif
54
55 DECLARE_GLOBAL_DATA_PTR;
56
57 #if defined(CONFIG_GET_CPU_STR_F)
58 extern int get_cpu_str_f (char *buf);
59 #endif
60
61 int checkcpu (void)
62 {
63         volatile immap_t *immap = (immap_t *) CFG_IMMR;
64         ulong clock = gd->cpu_clk;
65         uint pvr = get_pvr ();
66         uint immr, rev, m, k;
67         char buf[32];
68
69         puts ("CPU:   ");
70
71         switch (pvr) {
72         case PVR_8260:
73         case PVR_8260_HIP3:
74                 k = 3;
75                 break;
76         case PVR_8260_HIP4:
77                 k = 4;
78                 break;
79         case PVR_8260_HIP7R1:
80         case PVR_8260_HIP7RA:
81         case PVR_8260_HIP7:
82                 k = 7;
83                 break;
84         default:
85                 return -1;      /* whoops! not an MPC8260 */
86         }
87         rev = pvr & 0xff;
88
89         immr = immap->im_memctl.memc_immr;
90         if ((immr & IMMR_ISB_MSK) != CFG_IMMR)
91                 return -1;      /* whoops! someone moved the IMMR */
92
93 #if defined(CONFIG_GET_CPU_STR_F)
94         get_cpu_str_f (buf);
95         printf ("%s (HiP%d Rev %02x, Mask ", buf, k, rev);
96 #else
97         printf (CPU_ID_STR " (HiP%d Rev %02x, Mask ", k, rev);
98 #endif
99
100         /*
101          * the bottom 16 bits of the immr are the Part Number and Mask Number
102          * (4-34); the 16 bits at PROFF_REVNUM (0x8af0) in dual port ram is the
103          * RISC Microcode Revision Number (13-10).
104          * For the 8260, Motorola doesn't include the Microcode Revision
105          * in the mask.
106          */
107         m = immr & (IMMR_PARTNUM_MSK | IMMR_MASKNUM_MSK);
108         k = *((ushort *) & immap->im_dprambase[PROFF_REVNUM]);
109
110         switch (m) {
111         case 0x0000:
112                 puts ("0.2 2J24M");
113                 break;
114         case 0x0010:
115                 puts ("A.0 K22A");
116                 break;
117         case 0x0011:
118                 puts ("A.1 1K22A-XC");
119                 break;
120         case 0x0001:
121                 puts ("B.1 1K23A");
122                 break;
123         case 0x0021:
124                 puts ("B.2 2K23A-XC");
125                 break;
126         case 0x0023:
127                 puts ("B.3 3K23A");
128                 break;
129         case 0x0024:
130                 puts ("C.2 6K23A");
131                 break;
132         case 0x0060:
133                 puts ("A.0(A) 2K25A");
134                 break;
135         case 0x0062:
136                 puts ("B.1 4K25A");
137                 break;
138         case 0x0064:
139                 puts ("C.0 5K25A");
140                 break;
141         case 0x0A00:
142                 puts ("0.0 0K49M");
143                 break;
144         case 0x0A01:
145                 puts ("0.1 1K49M");
146                 break;
147         case 0x0A10:
148                 puts ("1.0 1K49M");
149                 break;
150         case 0x0C00:
151                 puts ("0.0 0K50M");
152                 break;
153         case 0x0C10:
154                 puts ("1.0 1K50M");
155                 break;
156         case 0x0D00:
157                 puts ("0.0 0K50M");
158                 break;
159         case 0x0D10:
160                 puts ("1.0 1K50M");
161                 break;
162         default:
163                 printf ("unknown [immr=0x%04x,k=0x%04x]", m, k);
164                 break;
165         }
166
167         printf (") at %s MHz\n", strmhz (buf, clock));
168
169         return 0;
170 }
171
172 /* ------------------------------------------------------------------------- */
173 /* configures a UPM by writing into the UPM RAM array                        */
174 /* uses bank 11 and a dummy physical address (=BRx_BA_MSK)                   */
175 /* NOTE: the physical address chosen must not overlap into any other area    */
176 /* mapped by the memory controller because bank 11 has the lowest priority   */
177
178 void upmconfig (uint upm, uint * table, uint size)
179 {
180         volatile immap_t *immap = (immap_t *) CFG_IMMR;
181         volatile memctl8260_t *memctl = &immap->im_memctl;
182         volatile uchar *dummy = (uchar *) BRx_BA_MSK;   /* set all BA bits */
183         uint i;
184
185         /* first set up bank 11 to reference the correct UPM at a dummy address */
186
187         memctl->memc_or11 = ORxU_AM_MSK;        /* set all AM bits */
188
189         switch (upm) {
190
191         case UPMA:
192                 memctl->memc_br11 =
193                         ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMA |
194                         BRx_V;
195                 memctl->memc_mamr = MxMR_OP_WARR;
196                 break;
197
198         case UPMB:
199                 memctl->memc_br11 =
200                         ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMB |
201                         BRx_V;
202                 memctl->memc_mbmr = MxMR_OP_WARR;
203                 break;
204
205         case UPMC:
206                 memctl->memc_br11 =
207                         ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMC |
208                         BRx_V;
209                 memctl->memc_mcmr = MxMR_OP_WARR;
210                 break;
211
212         default:
213                 panic ("upmconfig passed invalid UPM number (%u)\n", upm);
214                 break;
215
216         }
217
218         /*
219          * at this point, the dummy address is set up to access the selected UPM,
220          * the MAD pointer is zero, and the MxMR OP is set for writing to RAM
221          *
222          * now we simply load the mdr with each word and poke the dummy address.
223          * the MAD is incremented on each access.
224          */
225
226         for (i = 0; i < size; i++) {
227                 memctl->memc_mdr = table[i];
228                 *dummy = 0;
229         }
230
231         /* now kill bank 11 */
232         memctl->memc_br11 = 0;
233 }
234
235 /* ------------------------------------------------------------------------- */
236
237 #if !defined(CONFIG_HAVE_OWN_RESET)
238 int
239 do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
240 {
241         ulong msr, addr;
242
243         volatile immap_t *immap = (immap_t *) CFG_IMMR;
244
245         immap->im_clkrst.car_rmr = RMR_CSRE;    /* Checkstop Reset enable */
246
247         /* Interrupts and MMU off */
248         __asm__ __volatile__ ("mfmsr    %0":"=r" (msr):);
249
250         msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
251         __asm__ __volatile__ ("mtmsr    %0"::"r" (msr));
252
253         /*
254          * Trying to execute the next instruction at a non-existing address
255          * should cause a machine check, resulting in reset
256          */
257 #ifdef CFG_RESET_ADDRESS
258         addr = CFG_RESET_ADDRESS;
259 #else
260         /*
261          * note: when CFG_MONITOR_BASE points to a RAM address, CFG_MONITOR_BASE
262          * - sizeof (ulong) is usually a valid address. Better pick an address
263          * known to be invalid on your system and assign it to CFG_RESET_ADDRESS.
264          */
265         addr = CFG_MONITOR_BASE - sizeof (ulong);
266 #endif
267         ((void (*)(void)) addr) ();
268         return 1;
269
270 }
271 #endif  /* CONFIG_HAVE_OWN_RESET */
272
273 /* ------------------------------------------------------------------------- */
274
275 /*
276  * Get timebase clock frequency (like cpu_clk in Hz)
277  *
278  */
279 unsigned long get_tbclk (void)
280 {
281         ulong tbclk;
282
283         tbclk = (gd->bus_clk + 3L) / 4L;
284
285         return (tbclk);
286 }
287
288 /* ------------------------------------------------------------------------- */
289
290 #if defined(CONFIG_WATCHDOG)
291 void watchdog_reset (void)
292 {
293         int re_enable = disable_interrupts ();
294
295         reset_8260_watchdog ((immap_t *) CFG_IMMR);
296         if (re_enable)
297                 enable_interrupts ();
298 }
299 #endif /* CONFIG_WATCHDOG */
300
301 /* ------------------------------------------------------------------------- */
302 #if defined(CONFIG_OF_LIBFDT)
303 static void do_fixup(void *fdt, const char *node, const char *prop,
304                         const void *val, int len, int create)
305 {
306 #if defined(DEBUG)
307         int i;
308         debug("Updating property '%s/%s' = ", node, prop);
309         for (i = 0; i < len; i++)
310                 debug(" %.2x", *(u8*)(val+i));
311         debug("\n");
312 #endif
313         int rc = fdt_find_and_setprop(fdt, node, prop, val, len, create);
314         if (rc)
315                 printf("Unable to update property %s:%s, err=%s\n",
316                         node, prop, fdt_strerror(rc));
317 }
318
319 static void do_fixup_u32(void *fdt, const char *node, const char *prop,
320                          u32 val, int create)
321 {
322         val = cpu_to_fdt32(val);
323         do_fixup(fdt, node, prop, &val, sizeof(val), create);
324 }
325
326 void ft_cpu_setup (void *blob, bd_t *bd)
327 {
328         char * cpu_path = "/cpus/" OF_CPU;
329
330         do_fixup_u32(blob, cpu_path, "bus-frequency", bd->bi_busfreq, 1);
331         do_fixup_u32(blob, cpu_path, "timebase-frequency", OF_TBCLK, 1);
332         do_fixup_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1);
333 }
334 #endif /* CONFIG_OF_LIBFDT */