blob: 7302b37f2095a688c0c354ac86fc64f3447c2ee8 [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];
Simon Glassc04d5b92017-03-28 10:27:29 -060053 int ret;
wdenk4a9cbbe2002-08-27 09:48:53 +000054
Simon Glassc04d5b92017-03-28 10:27:29 -060055 ret = prt_8260_rsr();
56 if (ret)
57 return ret;
58 ret = prt_8260_clks();
59 if (ret)
60 return ret;
wdenk4a9cbbe2002-08-27 09:48:53 +000061 puts ("CPU: ");
62
wdenkdccbda02003-07-14 22:13:32 +000063 switch (pvr) {
64 case PVR_8260:
65 case PVR_8260_HIP3:
66 k = 3;
67 break;
68 case PVR_8260_HIP4:
69 k = 4;
70 break;
wdenk86765902003-12-06 23:55:10 +000071 case PVR_8260_HIP7R1:
wdenk391b5742004-10-10 23:27:33 +000072 case PVR_8260_HIP7RA:
wdenkdccbda02003-07-14 22:13:32 +000073 case PVR_8260_HIP7:
74 k = 7;
75 break;
76 default:
wdenk4a9cbbe2002-08-27 09:48:53 +000077 return -1; /* whoops! not an MPC8260 */
wdenkdccbda02003-07-14 22:13:32 +000078 }
wdenk4a9cbbe2002-08-27 09:48:53 +000079 rev = pvr & 0xff;
80
81 immr = immap->im_memctl.memc_immr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082 if ((immr & IMMR_ISB_MSK) != CONFIG_SYS_IMMR)
wdenk4a9cbbe2002-08-27 09:48:53 +000083 return -1; /* whoops! someone moved the IMMR */
84
Heiko Schocher3ec43662006-12-21 17:17:02 +010085#if defined(CONFIG_GET_CPU_STR_F)
86 get_cpu_str_f (buf);
87 printf ("%s (HiP%d Rev %02x, Mask ", buf, k, rev);
88#else
wdenkdccbda02003-07-14 22:13:32 +000089 printf (CPU_ID_STR " (HiP%d Rev %02x, Mask ", k, rev);
Heiko Schocher3ec43662006-12-21 17:17:02 +010090#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000091
92 /*
93 * the bottom 16 bits of the immr are the Part Number and Mask Number
94 * (4-34); the 16 bits at PROFF_REVNUM (0x8af0) in dual port ram is the
95 * RISC Microcode Revision Number (13-10).
96 * For the 8260, Motorola doesn't include the Microcode Revision
97 * in the mask.
98 */
99 m = immr & (IMMR_PARTNUM_MSK | IMMR_MASKNUM_MSK);
Scott Wood8a88e9f2013-05-17 20:01:54 -0500100 k = immap->im_dprambase16[PROFF_REVNUM / sizeof(u16)];
wdenk4a9cbbe2002-08-27 09:48:53 +0000101
102 switch (m) {
103 case 0x0000:
wdenk42c05472004-03-23 22:14:11 +0000104 puts ("0.2 2J24M");
wdenk4a9cbbe2002-08-27 09:48:53 +0000105 break;
106 case 0x0010:
wdenk42c05472004-03-23 22:14:11 +0000107 puts ("A.0 K22A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000108 break;
109 case 0x0011:
wdenk42c05472004-03-23 22:14:11 +0000110 puts ("A.1 1K22A-XC");
wdenk4a9cbbe2002-08-27 09:48:53 +0000111 break;
112 case 0x0001:
wdenk42c05472004-03-23 22:14:11 +0000113 puts ("B.1 1K23A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000114 break;
115 case 0x0021:
wdenk42c05472004-03-23 22:14:11 +0000116 puts ("B.2 2K23A-XC");
wdenk4a9cbbe2002-08-27 09:48:53 +0000117 break;
118 case 0x0023:
wdenk42c05472004-03-23 22:14:11 +0000119 puts ("B.3 3K23A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000120 break;
121 case 0x0024:
wdenk42c05472004-03-23 22:14:11 +0000122 puts ("C.2 6K23A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000123 break;
124 case 0x0060:
wdenk42c05472004-03-23 22:14:11 +0000125 puts ("A.0(A) 2K25A");
wdenk4a9cbbe2002-08-27 09:48:53 +0000126 break;
wdenkc08f1582003-04-27 22:52:51 +0000127 case 0x0062:
wdenk42c05472004-03-23 22:14:11 +0000128 puts ("B.1 4K25A");
wdenkc08f1582003-04-27 22:52:51 +0000129 break;
wdenk2f0812d2003-10-08 22:45:44 +0000130 case 0x0064:
wdenk42c05472004-03-23 22:14:11 +0000131 puts ("C.0 5K25A");
wdenk2f0812d2003-10-08 22:45:44 +0000132 break;
wdenkdccbda02003-07-14 22:13:32 +0000133 case 0x0A00:
wdenk42c05472004-03-23 22:14:11 +0000134 puts ("0.0 0K49M");
wdenkdccbda02003-07-14 22:13:32 +0000135 break;
136 case 0x0A01:
wdenk42c05472004-03-23 22:14:11 +0000137 puts ("0.1 1K49M");
wdenkdccbda02003-07-14 22:13:32 +0000138 break;
wdenk391b5742004-10-10 23:27:33 +0000139 case 0x0A10:
140 puts ("1.0 1K49M");
141 break;
wdenk3902d702004-04-15 18:22:41 +0000142 case 0x0C00:
wdenk391b5742004-10-10 23:27:33 +0000143 puts ("0.0 0K50M");
144 break;
145 case 0x0C10:
Wolfgang Denke37c98a2005-08-06 02:03:03 +0200146 puts ("1.0 1K50M");
wdenk391b5742004-10-10 23:27:33 +0000147 break;
wdenk3902d702004-04-15 18:22:41 +0000148 case 0x0D00:
wdenk391b5742004-10-10 23:27:33 +0000149 puts ("0.0 0K50M");
150 break;
151 case 0x0D10:
Wolfgang Denke37c98a2005-08-06 02:03:03 +0200152 puts ("1.0 1K50M");
wdenk3902d702004-04-15 18:22:41 +0000153 break;
wdenk4a9cbbe2002-08-27 09:48:53 +0000154 default:
155 printf ("unknown [immr=0x%04x,k=0x%04x]", m, k);
156 break;
157 }
158
159 printf (") at %s MHz\n", strmhz (buf, clock));
160
161 return 0;
162}
163
164/* ------------------------------------------------------------------------- */
165/* configures a UPM by writing into the UPM RAM array */
166/* uses bank 11 and a dummy physical address (=BRx_BA_MSK) */
167/* NOTE: the physical address chosen must not overlap into any other area */
168/* mapped by the memory controller because bank 11 has the lowest priority */
169
170void upmconfig (uint upm, uint * table, uint size)
171{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000173 volatile memctl8260_t *memctl = &immap->im_memctl;
174 volatile uchar *dummy = (uchar *) BRx_BA_MSK; /* set all BA bits */
175 uint i;
176
177 /* first set up bank 11 to reference the correct UPM at a dummy address */
178
179 memctl->memc_or11 = ORxU_AM_MSK; /* set all AM bits */
180
181 switch (upm) {
182
183 case UPMA:
184 memctl->memc_br11 =
185 ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMA |
186 BRx_V;
187 memctl->memc_mamr = MxMR_OP_WARR;
188 break;
189
190 case UPMB:
191 memctl->memc_br11 =
192 ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMB |
193 BRx_V;
194 memctl->memc_mbmr = MxMR_OP_WARR;
195 break;
196
197 case UPMC:
198 memctl->memc_br11 =
199 ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMC |
200 BRx_V;
201 memctl->memc_mcmr = MxMR_OP_WARR;
202 break;
203
204 default:
205 panic ("upmconfig passed invalid UPM number (%u)\n", upm);
206 break;
207
208 }
209
210 /*
211 * at this point, the dummy address is set up to access the selected UPM,
212 * the MAD pointer is zero, and the MxMR OP is set for writing to RAM
213 *
214 * now we simply load the mdr with each word and poke the dummy address.
215 * the MAD is incremented on each access.
216 */
217
218 for (i = 0; i < size; i++) {
219 memctl->memc_mdr = table[i];
220 *dummy = 0;
221 }
222
223 /* now kill bank 11 */
224 memctl->memc_br11 = 0;
225}
226
227/* ------------------------------------------------------------------------- */
228
wdenkc28149c2005-05-30 23:55:42 +0000229#if !defined(CONFIG_HAVE_OWN_RESET)
wdenk4a9cbbe2002-08-27 09:48:53 +0000230int
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200231do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
wdenk4a9cbbe2002-08-27 09:48:53 +0000232{
233 ulong msr, addr;
234
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200235 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk4a9cbbe2002-08-27 09:48:53 +0000236
237 immap->im_clkrst.car_rmr = RMR_CSRE; /* Checkstop Reset enable */
238
239 /* Interrupts and MMU off */
240 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
241
242 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
243 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
244
245 /*
246 * Trying to execute the next instruction at a non-existing address
247 * should cause a machine check, resulting in reset
248 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200249#ifdef CONFIG_SYS_RESET_ADDRESS
250 addr = CONFIG_SYS_RESET_ADDRESS;
wdenk4a9cbbe2002-08-27 09:48:53 +0000251#else
252 /*
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200253 * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address, CONFIG_SYS_MONITOR_BASE
wdenk4a9cbbe2002-08-27 09:48:53 +0000254 * - sizeof (ulong) is usually a valid address. Better pick an address
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200255 * known to be invalid on your system and assign it to CONFIG_SYS_RESET_ADDRESS.
wdenk4a9cbbe2002-08-27 09:48:53 +0000256 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200257 addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong);
wdenk4a9cbbe2002-08-27 09:48:53 +0000258#endif
259 ((void (*)(void)) addr) ();
260 return 1;
261
262}
wdenkc28149c2005-05-30 23:55:42 +0000263#endif /* CONFIG_HAVE_OWN_RESET */
wdenk4a9cbbe2002-08-27 09:48:53 +0000264
265/* ------------------------------------------------------------------------- */
266
267/*
268 * Get timebase clock frequency (like cpu_clk in Hz)
269 *
270 */
271unsigned long get_tbclk (void)
272{
wdenk4a9cbbe2002-08-27 09:48:53 +0000273 ulong tbclk;
274
275 tbclk = (gd->bus_clk + 3L) / 4L;
276
277 return (tbclk);
278}
279
280/* ------------------------------------------------------------------------- */
281
282#if defined(CONFIG_WATCHDOG)
283void watchdog_reset (void)
284{
285 int re_enable = disable_interrupts ();
286
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200287 reset_8260_watchdog ((immap_t *) CONFIG_SYS_IMMR);
wdenk4a9cbbe2002-08-27 09:48:53 +0000288 if (re_enable)
289 enable_interrupts ();
290}
291#endif /* CONFIG_WATCHDOG */
292
293/* ------------------------------------------------------------------------- */
Robert P. J. Day3c757002016-05-19 15:23:12 -0400294#ifdef CONFIG_OF_BOARD_SETUP
Sergej Stepanovd61257a2007-10-17 11:13:51 +0200295void ft_cpu_setup (void *blob, bd_t *bd)
296{
Scott Wood7f6381b2009-04-02 16:10:36 -0500297 do_fixup_by_compat_u32(blob, "fsl,cpm2-brg",
298 "clock-frequency", bd->bi_brgfreq, 1);
299
Wolfgang Denk082f66e2009-05-12 15:17:35 +0200300 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
301 "bus-frequency", bd->bi_busfreq, 1);
302 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
303 "timebase-frequency", OF_TBCLK, 1);
304 do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
305 "clock-frequency", bd->bi_intfreq, 1);
Marcel Ziswiler2534d232009-10-01 23:55:17 +0200306 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Sergej Stepanovd61257a2007-10-17 11:13:51 +0200307}
Robert P. J. Day3c757002016-05-19 15:23:12 -0400308#endif /* CONFIG_OF_BOARD_SETUP */
Ben Warren70618a32008-10-22 23:20:29 -0700309
310/*
311 * Initializes on-chip ethernet controllers.
312 * to override, implement board_eth_init()
313 */
314int cpu_eth_init(bd_t *bis)
315{
316#if defined(CONFIG_ETHER_ON_FCC)
317 fec_initialize(bis);
318#endif
Gary Jennejohn5ebdb1f2008-11-20 12:28:38 +0100319#if defined(CONFIG_ETHER_ON_SCC)
ksi@koi8.netc5474772009-02-06 16:27:55 -0800320 mpc82xx_scc_enet_initialize(bis);
Gary Jennejohn5ebdb1f2008-11-20 12:28:38 +0100321#endif
Ben Warren70618a32008-10-22 23:20:29 -0700322 return 0;
323}