blob: 876f5c731a8595620588078b57274ff18b2979b2 [file] [log] [blame]
Eran Libertyf046ccd2005-07-28 10:08:46 -05001/*
Dave Liu03051c32007-09-18 12:36:11 +08002 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
Eran Libertyf046ccd2005-07-28 10:08:46 -05003 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
Eran Libertyf046ccd2005-07-28 10:08:46 -050021 */
22
23/*
24 * CPU specific code for the MPC83xx family.
25 *
26 * Derived from the MPC8260 and MPC85xx.
27 */
28
29#include <common.h>
30#include <watchdog.h>
31#include <command.h>
32#include <mpc83xx.h>
33#include <asm/processor.h>
Gerald Van Baren213bf8c2007-03-31 12:23:51 -040034#include <libfdt.h>
Andy Fleming75b9d4a2008-08-31 16:33:26 -050035#include <tsec.h>
Ben Warren0e8454e2008-10-22 23:32:48 -070036#include <netdev.h>
Andy Fleminge1ac3872008-10-30 16:50:14 -050037#include <fsl_esdhc.h>
Heiko Schocherf70fd132009-02-24 11:30:51 +010038#ifdef CONFIG_BOOTCOUNT_LIMIT
39#include <asm/immap_qe.h>
40#include <asm/io.h>
41#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -050042
Wolfgang Denkd87080b2006-03-31 18:32:53 +020043DECLARE_GLOBAL_DATA_PTR;
44
Eran Libertyf046ccd2005-07-28 10:08:46 -050045int checkcpu(void)
46{
Dave Liu5f820432006-11-03 19:33:44 -060047 volatile immap_t *immr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050048 ulong clock = gd->cpu_clk;
49 u32 pvr = get_pvr();
Dave Liu5f820432006-11-03 19:33:44 -060050 u32 spridr;
Eran Libertyf046ccd2005-07-28 10:08:46 -050051 char buf[32];
Kim Phillipse5c4ade2008-03-28 10:19:07 -050052 int i;
53
Kim Phillipse5c4ade2008-03-28 10:19:07 -050054 const struct cpu_type {
55 char name[15];
56 u32 partid;
57 } cpu_type_list [] = {
58 CPU_TYPE_ENTRY(8311),
59 CPU_TYPE_ENTRY(8313),
60 CPU_TYPE_ENTRY(8314),
61 CPU_TYPE_ENTRY(8315),
62 CPU_TYPE_ENTRY(8321),
63 CPU_TYPE_ENTRY(8323),
64 CPU_TYPE_ENTRY(8343),
65 CPU_TYPE_ENTRY(8347_TBGA_),
66 CPU_TYPE_ENTRY(8347_PBGA_),
67 CPU_TYPE_ENTRY(8349),
68 CPU_TYPE_ENTRY(8358_TBGA_),
69 CPU_TYPE_ENTRY(8358_PBGA_),
70 CPU_TYPE_ENTRY(8360),
71 CPU_TYPE_ENTRY(8377),
72 CPU_TYPE_ENTRY(8378),
73 CPU_TYPE_ENTRY(8379),
74 };
Eran Libertyf046ccd2005-07-28 10:08:46 -050075
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076 immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liu5f820432006-11-03 19:33:44 -060077
Kim Phillips54b2d432007-04-30 15:26:21 -050078 puts("CPU: ");
Scott Wood95e7ef82007-04-16 14:34:16 -050079
80 switch (pvr & 0xffff0000) {
81 case PVR_E300C1:
82 printf("e300c1, ");
83 break;
84
85 case PVR_E300C2:
86 printf("e300c2, ");
87 break;
88
89 case PVR_E300C3:
90 printf("e300c3, ");
91 break;
92
Dave Liu03051c32007-09-18 12:36:11 +080093 case PVR_E300C4:
94 printf("e300c4, ");
95 break;
96
Scott Wood95e7ef82007-04-16 14:34:16 -050097 default:
98 printf("Unknown core, ");
Eran Libertyf046ccd2005-07-28 10:08:46 -050099 }
100
Dave Liu5f820432006-11-03 19:33:44 -0600101 spridr = immr->sysconf.spridr;
Rafal Jaworowski6902df52005-10-17 02:39:53 +0200102
Kim Phillipse5c4ade2008-03-28 10:19:07 -0500103 for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
104 if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) {
105 puts("MPC");
106 puts(cpu_type_list[i].name);
107 if (IS_E_PROCESSOR(spridr))
108 puts("E");
109 if (REVID_MAJOR(spridr) >= 2)
110 puts("A");
111 printf(", Rev: %d.%d", REVID_MAJOR(spridr),
112 REVID_MINOR(spridr));
113 break;
114 }
115
116 if (i == ARRAY_SIZE(cpu_type_list))
117 printf("(SPRIDR %08x unknown), ", spridr);
118
119 printf(" at %s MHz, ", strmhz(buf, clock));
120
121 printf("CSB: %s MHz\n", strmhz(buf, gd->csb_clk));
Kim Phillips54b2d432007-04-30 15:26:21 -0500122
Eran Libertyf046ccd2005-07-28 10:08:46 -0500123 return 0;
124}
125
126
Timur Tabibe5e6182006-11-03 19:15:00 -0600127/*
Timur Tabi2ad6b512006-10-31 18:44:42 -0600128 * Program a UPM with the code supplied in the table.
129 *
130 * The 'dummy' variable is used to increment the MAD. 'dummy' is
131 * supposed to be a pointer to the memory of the device being
132 * programmed by the UPM. The data in the MDR is written into
Selvamuthukumar97245552008-10-09 10:29:14 +0530133 * memory and the MAD is incremented every time there's a write
134 * to 'dummy'. Unfortunately, the current prototype for this
Timur Tabi2ad6b512006-10-31 18:44:42 -0600135 * function doesn't allow for passing the address of this
136 * device, and changing the prototype will break a number lots
137 * of other code, so we need to use a round-about way of finding
138 * the value for 'dummy'.
139 *
140 * The value can be extracted from the base address bits of the
141 * Base Register (BR) associated with the specific UPM. To find
142 * that BR, we need to scan all 8 BRs until we find the one that
143 * has its MSEL bits matching the UPM we want. Once we know the
144 * right BR, we can extract the base address bits from it.
145 *
146 * The MxMR and the BR and OR of the chosen bank should all be
147 * configured before calling this function.
148 *
149 * Parameters:
150 * upm: 0=UPMA, 1=UPMB, 2=UPMC
151 * table: Pointer to an array of values to program
152 * size: Number of elements in the array. Must be 64 or less.
Timur Tabibe5e6182006-11-03 19:15:00 -0600153 */
Eran Libertyf046ccd2005-07-28 10:08:46 -0500154void upmconfig (uint upm, uint *table, uint size)
155{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200156 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Haiying Wang4e190b02008-10-29 11:05:55 -0400157 volatile fsl_lbus_t *lbus = &immap->lbus;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600158 volatile uchar *dummy = NULL;
159 const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
160 volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
161 uint i;
162
163 /* Scan all the banks to determine the base address of the device */
164 for (i = 0; i < 8; i++) {
165 if ((lbus->bank[i].br & BR_MSEL) == msel) {
166 dummy = (uchar *) (lbus->bank[i].br & BR_BA);
167 break;
168 }
169 }
170
171 if (!dummy) {
172 printf("Error: %s() could not find matching BR\n", __FUNCTION__);
173 hang();
174 }
175
176 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
177 *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
178
179 for (i = 0; i < size; i++) {
180 lbus->mdr = table[i];
181 __asm__ __volatile__ ("sync");
Selvamuthukumar97245552008-10-09 10:29:14 +0530182 *dummy = 0; /* Write the value to memory and increment MAD */
Timur Tabi2ad6b512006-10-31 18:44:42 -0600183 __asm__ __volatile__ ("sync");
Selvamuthukumar97245552008-10-09 10:29:14 +0530184 while(((*mxmr & 0x3f) != ((i + 1) & 0x3f)));
Timur Tabi2ad6b512006-10-31 18:44:42 -0600185 }
186
187 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
188 *mxmr &= 0xCFFFFFC0;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500189}
190
191
192int
193do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
194{
Wolfgang Denk07a25052005-08-05 19:49:35 +0200195 ulong msr;
196#ifndef MPC83xx_RESET
197 ulong addr;
198#endif
Eran Libertyf046ccd2005-07-28 10:08:46 -0500199
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200200 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500201
202#ifdef MPC83xx_RESET
203 /* Interrupts and MMU off */
204 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
205
206 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
207 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
208
209 /* enable Reset Control Reg */
210 immap->reset.rpr = 0x52535445;
Marian Balakowicz6d8ae5a2006-03-14 16:12:48 +0100211 __asm__ __volatile__ ("sync");
212 __asm__ __volatile__ ("isync");
Eran Libertyf046ccd2005-07-28 10:08:46 -0500213
214 /* confirm Reset Control Reg is enabled */
215 while(!((immap->reset.rcer) & RCER_CRE));
216
217 printf("Resetting the board.");
218 printf("\n");
219
220 udelay(200);
221
222 /* perform reset, only one bit */
Wolfgang Denk07a25052005-08-05 19:49:35 +0200223 immap->reset.rcr = RCR_SWHR;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500224
Wolfgang Denk07a25052005-08-05 19:49:35 +0200225#else /* ! MPC83xx_RESET */
226
227 immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
228
229 /* Interrupts and MMU off */
230 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
Eran Libertyf046ccd2005-07-28 10:08:46 -0500231
232 msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
233 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
234
235 /*
236 * Trying to execute the next instruction at a non-existing address
237 * should cause a machine check, resulting in reset
238 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200239 addr = CONFIG_SYS_RESET_ADDRESS;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500240
241 printf("resetting the board.");
242 printf("\n");
243 ((void (*)(void)) addr) ();
Wolfgang Denk07a25052005-08-05 19:49:35 +0200244#endif /* MPC83xx_RESET */
245
Eran Libertyf046ccd2005-07-28 10:08:46 -0500246 return 1;
247}
248
249
250/*
251 * Get timebase clock frequency (like cpu_clk in Hz)
252 */
253
254unsigned long get_tbclk(void)
255{
Eran Libertyf046ccd2005-07-28 10:08:46 -0500256 ulong tbclk;
257
258 tbclk = (gd->bus_clk + 3L) / 4L;
259
260 return tbclk;
261}
262
263
264#if defined(CONFIG_WATCHDOG)
265void watchdog_reset (void)
266{
Timur Tabi2ad6b512006-10-31 18:44:42 -0600267 int re_enable = disable_interrupts();
268
269 /* Reset the 83xx watchdog */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200270 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600271 immr->wdt.swsrr = 0x556c;
272 immr->wdt.swsrr = 0xaa39;
273
274 if (re_enable)
275 enable_interrupts ();
Eran Libertyf046ccd2005-07-28 10:08:46 -0500276}
Timur Tabi2ad6b512006-10-31 18:44:42 -0600277#endif
Kumar Gala62ec6412006-01-11 16:48:10 -0600278
Marian Balakowicz61f25152006-03-14 16:14:48 +0100279#if defined(CONFIG_DDR_ECC)
280void dma_init(void)
281{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200282 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500283 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100284 volatile u32 status = swab32(dma->dmasr0);
285 volatile u32 dmamr0 = swab32(dma->dmamr0);
286
287 debug("DMA-init\n");
288
289 /* initialize DMASARn, DMADAR and DMAABCRn */
290 dma->dmadar0 = (u32)0;
291 dma->dmasar0 = (u32)0;
292 dma->dmabcr0 = 0;
293
294 __asm__ __volatile__ ("sync");
295 __asm__ __volatile__ ("isync");
296
297 /* clear CS bit */
298 dmamr0 &= ~DMA_CHANNEL_START;
299 dma->dmamr0 = swab32(dmamr0);
300 __asm__ __volatile__ ("sync");
301 __asm__ __volatile__ ("isync");
302
303 /* while the channel is busy, spin */
304 while(status & DMA_CHANNEL_BUSY) {
305 status = swab32(dma->dmasr0);
306 }
307
308 debug("DMA-init end\n");
309}
310
311uint dma_check(void)
312{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200313 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500314 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100315 volatile u32 status = swab32(dma->dmasr0);
316 volatile u32 byte_count = swab32(dma->dmabcr0);
317
318 /* while the channel is busy, spin */
319 while (status & DMA_CHANNEL_BUSY) {
320 status = swab32(dma->dmasr0);
321 }
322
323 if (status & DMA_CHANNEL_TRANSFER_ERROR) {
324 printf ("DMA Error: status = %x @ %d\n", status, byte_count);
325 }
326
327 return status;
328}
329
330int dma_xfer(void *dest, u32 count, void *src)
331{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200332 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Dave Liuf6eda7f2006-10-25 14:41:21 -0500333 volatile dma83xx_t *dma = &immap->dma;
Marian Balakowicz61f25152006-03-14 16:14:48 +0100334 volatile u32 dmamr0;
335
336 /* initialize DMASARn, DMADAR and DMAABCRn */
337 dma->dmadar0 = swab32((u32)dest);
338 dma->dmasar0 = swab32((u32)src);
339 dma->dmabcr0 = swab32(count);
340
341 __asm__ __volatile__ ("sync");
342 __asm__ __volatile__ ("isync");
343
344 /* init direct transfer, clear CS bit */
345 dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
346 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
347 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
Wolfgang Denkcf48eb92006-04-16 10:51:58 +0200348
Marian Balakowicz61f25152006-03-14 16:14:48 +0100349 dma->dmamr0 = swab32(dmamr0);
350
351 __asm__ __volatile__ ("sync");
352 __asm__ __volatile__ ("isync");
353
354 /* set CS to start DMA transfer */
355 dmamr0 |= DMA_CHANNEL_START;
356 dma->dmamr0 = swab32(dmamr0);
357 __asm__ __volatile__ ("sync");
358 __asm__ __volatile__ ("isync");
359
360 return ((int)dma_check());
361}
362#endif /*CONFIG_DDR_ECC*/
Ben Warrendd354792008-06-23 22:57:27 -0700363
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500364/*
365 * Initializes on-chip ethernet controllers.
366 * to override, implement board_eth_init()
Ben Warrendd354792008-06-23 22:57:27 -0700367 */
Ben Warrendd354792008-06-23 22:57:27 -0700368int cpu_eth_init(bd_t *bis)
369{
Ben Warren0e8454e2008-10-22 23:32:48 -0700370#if defined(CONFIG_UEC_ETH1)
371 uec_initialize(0);
372#endif
373#if defined(CONFIG_UEC_ETH2)
374 uec_initialize(1);
375#endif
376#if defined(CONFIG_UEC_ETH3)
377 uec_initialize(2);
378#endif
379#if defined(CONFIG_UEC_ETH4)
380 uec_initialize(3);
381#endif
382#if defined(CONFIG_UEC_ETH5)
383 uec_initialize(4);
384#endif
385#if defined(CONFIG_UEC_ETH6)
386 uec_initialize(5);
387#endif
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500388#if defined(CONFIG_TSEC_ENET)
389 tsec_standard_init(bis);
Ben Warrendd354792008-06-23 22:57:27 -0700390#endif
Ben Warrendd354792008-06-23 22:57:27 -0700391 return 0;
392}
Andy Fleminge1ac3872008-10-30 16:50:14 -0500393
394/*
395 * Initializes on-chip MMC controllers.
396 * to override, implement board_mmc_init()
397 */
398int cpu_mmc_init(bd_t *bis)
399{
400#ifdef CONFIG_FSL_ESDHC
401 return fsl_esdhc_mmc_init(bis);
402#else
403 return 0;
404#endif
405}
Heiko Schocherf70fd132009-02-24 11:30:51 +0100406
407#ifdef CONFIG_BOOTCOUNT_LIMIT
408
409#if !defined(CONFIG_MPC8360)
410#error "CONFIG_BOOTCOUNT_LIMIT only for MPC8360 implemented"
411#endif
412
413#if !defined(CONFIG_BOOTCOUNT_ADDR)
414#define CONFIG_BOOTCOUNT_ADDR (0x110000 + QE_MURAM_SIZE - 2 * sizeof(unsigned long))
415#endif
416
417#include <asm/io.h>
418
419void bootcount_store (ulong a)
420{
421 void *reg = (void *)(CONFIG_SYS_IMMR + CONFIG_BOOTCOUNT_ADDR);
422 out_be32 (reg, a);
423 out_be32 (reg + 4, BOOTCOUNT_MAGIC);
424}
425
426ulong bootcount_load (void)
427{
428 void *reg = (void *)(CONFIG_SYS_IMMR + CONFIG_BOOTCOUNT_ADDR);
429
430 if (in_be32 (reg + 4) != BOOTCOUNT_MAGIC)
431 return 0;
432 else
433 return in_be32 (reg);
434}
435#endif /* CONFIG_BOOTCOUNT_LIMIT */