blob: 6eed6f53a3a184df7463dbb4416796fb2f78a3a5 [file] [log] [blame]
wdenk4a9cbbe2002-08-27 09:48:53 +00001/*
Wolfgang Denk6405a152006-03-31 18:32:53 +02002 * (C) Copyright 2000-2006
wdenk4a9cbbe2002-08-27 09:48:53 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk4a9cbbe2002-08-27 09:48:53 +00006 */
7
8/*
wdenkdccbda02003-07-14 22:13:32 +00009 * CPU specific code for the MPC825x / MPC826x / MPC827x / MPC828x
wdenk4a9cbbe2002-08-27 09:48:53 +000010 *
11 * written or collected and sometimes rewritten by
12 * Magnus Damm <damm@bitsmart.com>
13 *
wdenkc08f1582003-04-27 22:52:51 +000014 * modified by
wdenk4a9cbbe2002-08-27 09:48:53 +000015 * Wolfgang Denk <wd@denx.de>
16 *
17 * modified for 8260 by
18 * Murray Jensen <Murray.Jensen@cmst.csiro.au>
19 *
20 * added 8260 masks by
21 * Marius Groeger <mag@sysgo.de>
wdenkdccbda02003-07-14 22:13:32 +000022 *
wdenk3902d702004-04-15 18:22:41 +000023 * added HiP7 (824x/827x/8280) processors support by
wdenkdccbda02003-07-14 22:13:32 +000024 * Yuli Barcohen <yuli@arabellasw.com>
wdenk4a9cbbe2002-08-27 09:48:53 +000025 */
26
27#include <common.h>
28#include <watchdog.h>
29#include <command.h>
30#include <mpc8260.h>
Ben Warren70618a32008-10-22 23:20:29 -070031#include <netdev.h>
wdenk4a9cbbe2002-08-27 09:48:53 +000032#include <asm/processor.h>
33#include <asm/cpm_8260.h>
34
Sergej Stepanovd61257a2007-10-17 11:13:51 +020035#if defined(CONFIG_OF_LIBFDT)
36#include <libfdt.h>
Kumar Gala7e64cf82007-11-03 19:46:28 -050037#include <fdt_support.h>
Sergej Stepanovd61257a2007-10-17 11:13:51 +020038#endif
39
Wolfgang Denk6405a152006-03-31 18:32:53 +020040DECLARE_GLOBAL_DATA_PTR;
41
Heiko Schocher3ec43662006-12-21 17:17:02 +010042#if defined(CONFIG_GET_CPU_STR_F)
43extern int get_cpu_str_f (char *buf);
44#endif
45
wdenk4a9cbbe2002-08-27 09:48:53 +000046int checkcpu (void)
47{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020048 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +000049 ulong clock = gd->cpu_clk;
50 uint pvr = get_pvr ();
51 uint immr, rev, m, k;
52 char buf[32];
53
54 puts ("CPU: ");
55
wdenkdccbda02003-07-14 22:13:32 +000056 switch (pvr) {
57 case PVR_8260:
58 case PVR_8260_HIP3:
59 k = 3;
60 break;
61 case PVR_8260_HIP4:
62 k = 4;
63 break;
wdenk86765902003-12-06 23:55:10 +000064 case PVR_8260_HIP7R1:
wdenk391b5742004-10-10 23:27:33 +000065 case PVR_8260_HIP7RA:
wdenkdccbda02003-07-14 22:13:32 +000066 case PVR_8260_HIP7:
67 k = 7;
68 break;
69 default:
wdenk4a9cbbe2002-08-27 09:48:53 +000070 return -1; /* whoops! not an MPC8260 */
wdenkdccbda02003-07-14 22:13:32 +000071 }
wdenk4a9cbbe2002-08-27 09:48:53 +000072 rev = pvr & 0xff;
73
74 immr = immap->im_memctl.memc_immr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020075 if ((immr & IMMR_ISB_MSK) != CONFIG_SYS_IMMR)
wdenk4a9cbbe2002-08-27 09:48:53 +000076 return -1; /* whoops! someone moved the IMMR */
77
Heiko Schocher3ec43662006-12-21 17:17:02 +010078#if defined(CONFIG_GET_CPU_STR_F)
79 get_cpu_str_f (buf);
80 printf ("%s (HiP%d Rev %02x, Mask ", buf, k, rev);
81#else
wdenkdccbda02003-07-14 22:13:32 +000082 printf (CPU_ID_STR " (HiP%d Rev %02x, Mask ", k, rev);
Heiko Schocher3ec43662006-12-21 17:17:02 +010083#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000084
85 /*
86 * the bottom 16 bits of the immr are the Part Number and Mask Number
87 * (4-34); the 16 bits at PROFF_REVNUM (0x8af0) in dual port ram is the
88 * RISC Microcode Revision Number (13-10).
89 * For the 8260, Motorola doesn't include the Microcode Revision
90 * in the mask.
91 */
92 m = immr & (IMMR_PARTNUM_MSK | IMMR_MASKNUM_MSK);
Scott Wood8a88e9f2013-05-17 20:01:54 -050093 k = immap->im_dprambase16[PROFF_REVNUM / sizeof(u16)];
wdenk4a9cbbe2002-08-27 09:48:53 +000094
95 switch (m) {
96 case 0x0000:
wdenk42c05472004-03-23 22:14:11 +000097 puts ("0.2 2J24M");
wdenk4a9cbbe2002-08-27 09:48:53 +000098 break;
99 case 0x0010:
wdenk42c05472004-03-23 22:14:11 +0000100 puts ("A.0 K22A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000101 break;
102 case 0x0011:
wdenk42c05472004-03-23 22:14:11 +0000103 puts ("A.1 1K22A-XC");
wdenk4a9cbbe2002-08-27 09:48:53 +0000104 break;
105 case 0x0001:
wdenk42c05472004-03-23 22:14:11 +0000106 puts ("B.1 1K23A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000107 break;
108 case 0x0021:
wdenk42c05472004-03-23 22:14:11 +0000109 puts ("B.2 2K23A-XC");
wdenk4a9cbbe2002-08-27 09:48:53 +0000110 break;
111 case 0x0023:
wdenk42c05472004-03-23 22:14:11 +0000112 puts ("B.3 3K23A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000113 break;
114 case 0x0024:
wdenk42c05472004-03-23 22:14:11 +0000115 puts ("C.2 6K23A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000116 break;
117 case 0x0060:
wdenk42c05472004-03-23 22:14:11 +0000118 puts ("A.0(A) 2K25A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000119 break;
wdenkc08f1582003-04-27 22:52:51 +0000120 case 0x0062:
wdenk42c05472004-03-23 22:14:11 +0000121 puts ("B.1 4K25A");
wdenkc08f1582003-04-27 22:52:51 +0000122 break;
wdenk2f0812d2003-10-08 22:45:44 +0000123 case 0x0064:
wdenk42c05472004-03-23 22:14:11 +0000124 puts ("C.0 5K25A");
wdenk2f0812d2003-10-08 22:45:44 +0000125 break;
wdenkdccbda02003-07-14 22:13:32 +0000126 case 0x0A00:
wdenk42c05472004-03-23 22:14:11 +0000127 puts ("0.0 0K49M");
wdenkdccbda02003-07-14 22:13:32 +0000128 break;
129 case 0x0A01:
wdenk42c05472004-03-23 22:14:11 +0000130 puts ("0.1 1K49M");
wdenkdccbda02003-07-14 22:13:32 +0000131 break;
wdenk391b5742004-10-10 23:27:33 +0000132 case 0x0A10:
133 puts ("1.0 1K49M");
134 break;
wdenk3902d702004-04-15 18:22:41 +0000135 case 0x0C00:
wdenk391b5742004-10-10 23:27:33 +0000136 puts ("0.0 0K50M");
137 break;
138 case 0x0C10:
Wolfgang Denke37c98a2005-08-06 02:03:03 +0200139 puts ("1.0 1K50M");
wdenk391b5742004-10-10 23:27:33 +0000140 break;
wdenk3902d702004-04-15 18:22:41 +0000141 case 0x0D00:
wdenk391b5742004-10-10 23:27:33 +0000142 puts ("0.0 0K50M");
143 break;
144 case 0x0D10:
Wolfgang Denke37c98a2005-08-06 02:03:03 +0200145 puts ("1.0 1K50M");
wdenk3902d702004-04-15 18:22:41 +0000146 break;
wdenk4a9cbbe2002-08-27 09:48:53 +0000147 default:
148 printf ("unknown [immr=0x%04x,k=0x%04x]", m, k);
149 break;
150 }
151
152 printf (") at %s MHz\n", strmhz (buf, clock));
153
154 return 0;
155}
156
157/* ------------------------------------------------------------------------- */
158/* configures a UPM by writing into the UPM RAM array */
159/* uses bank 11 and a dummy physical address (=BRx_BA_MSK) */
160/* NOTE: the physical address chosen must not overlap into any other area */
161/* mapped by the memory controller because bank 11 has the lowest priority */
162
163void upmconfig (uint upm, uint * table, uint size)
164{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200165 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000166 volatile memctl8260_t *memctl = &immap->im_memctl;
167 volatile uchar *dummy = (uchar *) BRx_BA_MSK; /* set all BA bits */
168 uint i;
169
170 /* first set up bank 11 to reference the correct UPM at a dummy address */
171
172 memctl->memc_or11 = ORxU_AM_MSK; /* set all AM bits */
173
174 switch (upm) {
175
176 case UPMA:
177 memctl->memc_br11 =
178 ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMA |
179 BRx_V;
180 memctl->memc_mamr = MxMR_OP_WARR;
181 break;
182
183 case UPMB:
184 memctl->memc_br11 =
185 ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMB |
186 BRx_V;
187 memctl->memc_mbmr = MxMR_OP_WARR;
188 break;
189
190 case UPMC:
191 memctl->memc_br11 =
192 ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMC |
193 BRx_V;
194 memctl->memc_mcmr = MxMR_OP_WARR;
195 break;
196
197 default:
198 panic ("upmconfig passed invalid UPM number (%u)\n", upm);
199 break;
200
201 }
202
203 /*
204 * at this point, the dummy address is set up to access the selected UPM,
205 * the MAD pointer is zero, and the MxMR OP is set for writing to RAM
206 *
207 * now we simply load the mdr with each word and poke the dummy address.
208 * the MAD is incremented on each access.
209 */
210
211 for (i = 0; i < size; i++) {
212 memctl->memc_mdr = table[i];
213 *dummy = 0;
214 }
215
216 /* now kill bank 11 */
217 memctl->memc_br11 = 0;
218}
219
220/* ------------------------------------------------------------------------- */
221
wdenkc28149c2005-05-30 23:55:42 +0000222#if !defined(CONFIG_HAVE_OWN_RESET)
wdenk4a9cbbe2002-08-27 09:48:53 +0000223int
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200224do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk4a9cbbe2002-08-27 09:48:53 +0000225{
226 ulong msr, addr;
227
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200228 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000229
230 immap->im_clkrst.car_rmr = RMR_CSRE; /* Checkstop Reset enable */
231
232 /* Interrupts and MMU off */
233 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
234
235 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
236 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
237
238 /*
239 * Trying to execute the next instruction at a non-existing address
240 * should cause a machine check, resulting in reset
241 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200242#ifdef CONFIG_SYS_RESET_ADDRESS
243 addr = CONFIG_SYS_RESET_ADDRESS;
wdenk4a9cbbe2002-08-27 09:48:53 +0000244#else
245 /*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200246 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address, CONFIG_SYS_MONITOR_BASE
wdenk4a9cbbe2002-08-27 09:48:53 +0000247 * - sizeof (ulong) is usually a valid address. Better pick an address
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200248 * known to be invalid on your system and assign it to CONFIG_SYS_RESET_ADDRESS.
wdenk4a9cbbe2002-08-27 09:48:53 +0000249 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200250 addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong);
wdenk4a9cbbe2002-08-27 09:48:53 +0000251#endif
252 ((void (*)(void)) addr) ();
253 return 1;
254
255}
wdenkc28149c2005-05-30 23:55:42 +0000256#endif /* CONFIG_HAVE_OWN_RESET */
wdenk4a9cbbe2002-08-27 09:48:53 +0000257
258/* ------------------------------------------------------------------------- */
259
260/*
261 * Get timebase clock frequency (like cpu_clk in Hz)
262 *
263 */
264unsigned long get_tbclk (void)
265{
wdenk4a9cbbe2002-08-27 09:48:53 +0000266 ulong tbclk;
267
268 tbclk = (gd->bus_clk + 3L) / 4L;
269
270 return (tbclk);
271}
272
273/* ------------------------------------------------------------------------- */
274
275#if defined(CONFIG_WATCHDOG)
276void watchdog_reset (void)
277{
278 int re_enable = disable_interrupts ();
279
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200280 reset_8260_watchdog ((immap_t *) CONFIG_SYS_IMMR);
wdenk4a9cbbe2002-08-27 09:48:53 +0000281 if (re_enable)
282 enable_interrupts ();
283}
284#endif /* CONFIG_WATCHDOG */
285
286/* ------------------------------------------------------------------------- */
Marian Balakowiczf4891a12008-02-21 17:20:18 +0100287#if defined(CONFIG_OF_LIBFDT) && defined (CONFIG_OF_BOARD_SETUP)
Sergej Stepanovd61257a2007-10-17 11:13:51 +0200288void ft_cpu_setup (void *blob, bd_t *bd)
289{
Esben Haabendalde0fe0b2008-06-18 11:03:57 +0200290#if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\
291 defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
Kumar Galafabda922008-08-19 15:41:18 -0500292 fdt_fixup_ethernet(blob);
Esben Haabendalde0fe0b2008-06-18 11:03:57 +0200293#endif
294
Scott Wood7f6381b2009-04-02 16:10:36 -0500295 do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
296 "clock-frequency", bd->bi_brgfreq, 1);
297
Wolfgang Denk082f66e2009-05-12 15:17:35 +0200298 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
299 "bus-frequency", bd->bi_busfreq, 1);
300 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
301 "timebase-frequency", OF_TBCLK, 1);
302 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
303 "clock-frequency", bd->bi_intfreq, 1);
Marcel Ziswiler2534d232009-10-01 23:55:17 +0200304 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Sergej Stepanovd61257a2007-10-17 11:13:51 +0200305}
306#endif /* CONFIG_OF_LIBFDT */
Ben Warren70618a32008-10-22 23:20:29 -0700307
308/*
309 * Initializes on-chip ethernet controllers.
310 * to override, implement board_eth_init()
311 */
312int cpu_eth_init(bd_t *bis)
313{
314#if defined(CONFIG_ETHER_ON_FCC)
315 fec_initialize(bis);
316#endif
Gary Jennejohn5ebdb1f2008-11-20 12:28:38 +0100317#if defined(CONFIG_ETHER_ON_SCC)
ksi@koi8.netc5474772009-02-06 16:27:55 -0800318 mpc82xx_scc_enet_initialize(bis);
Gary Jennejohn5ebdb1f2008-11-20 12:28:38 +0100319#endif
Ben Warren70618a32008-10-22 23:20:29 -0700320 return 0;
321}