blob: a9bb5adeb2095493613da12c449218167279df65 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8#include <common.h>
9#include <mpc8260.h>
10#include <asm/cpm_8260.h>
11#include <ioports.h>
12
Wolfgang Denk6405a152006-03-31 18:32:53 +020013DECLARE_GLOBAL_DATA_PTR;
14
Heiko Schocher3ec43662006-12-21 17:17:02 +010015#if defined(CONFIG_BOARD_GET_CPU_CLK_F)
16extern unsigned long board_get_cpu_clk_f (void);
17#endif
18
wdenkc6097192002-11-03 00:24:07 +000019static void config_8260_ioports (volatile immap_t * immr)
20{
21 int portnum;
22
23 for (portnum = 0; portnum < 4; portnum++) {
24 uint pmsk = 0,
25 ppar = 0,
26 psor = 0,
27 pdir = 0,
28 podr = 0,
29 pdat = 0;
30 iop_conf_t *iopc = (iop_conf_t *) & iop_conf_tab[portnum][0];
31 iop_conf_t *eiopc = iopc + 32;
32 uint msk = 1;
33
34 /*
35 * NOTE:
36 * index 0 refers to pin 31,
37 * index 31 refers to pin 0
38 */
39 while (iopc < eiopc) {
40 if (iopc->conf) {
41 pmsk |= msk;
42 if (iopc->ppar)
43 ppar |= msk;
44 if (iopc->psor)
45 psor |= msk;
46 if (iopc->pdir)
47 pdir |= msk;
48 if (iopc->podr)
49 podr |= msk;
50 if (iopc->pdat)
51 pdat |= msk;
52 }
53
54 msk <<= 1;
55 iopc++;
56 }
57
58 if (pmsk != 0) {
59 volatile ioport_t *iop = ioport_addr (immr, portnum);
60 uint tpmsk = ~pmsk;
61
62 /*
wdenk57b2d802003-06-27 21:31:46 +000063 * the (somewhat confused) paragraph at the
64 * bottom of page 35-5 warns that there might
65 * be "unknown behaviour" when programming
66 * PSORx and PDIRx, if PPARx = 1, so I
67 * decided this meant I had to disable the
68 * dedicated function first, and enable it
69 * last.
wdenkc6097192002-11-03 00:24:07 +000070 */
71 iop->ppar &= tpmsk;
72 iop->psor = (iop->psor & tpmsk) | psor;
wdenkb00ec162003-06-19 23:40:20 +000073 iop->podr = (iop->podr & tpmsk) | podr;
wdenkc6097192002-11-03 00:24:07 +000074 iop->pdat = (iop->pdat & tpmsk) | pdat;
75 iop->pdir = (iop->pdir & tpmsk) | pdir;
wdenkc6097192002-11-03 00:24:07 +000076 iop->ppar |= ppar;
77 }
78 }
79}
80
Heiko Schocher3ec43662006-12-21 17:17:02 +010081#define SET_VAL_MASK(a, b, mask) ((a & mask) | (b & ~mask))
wdenkc6097192002-11-03 00:24:07 +000082/*
83 * Breath some life into the CPU...
84 *
85 * Set up the memory map,
86 * initialize a bunch of registers,
87 * initialize the UPM's
88 */
89void cpu_init_f (volatile immap_t * immr)
90{
wdenke55402c2004-03-14 16:51:43 +000091 uint sccr;
Heiko Schocher3ec43662006-12-21 17:17:02 +010092#if defined(CONFIG_BOARD_GET_CPU_CLK_F)
93 unsigned long cpu_clk;
94#endif
wdenkc6097192002-11-03 00:24:07 +000095 volatile memctl8260_t *memctl = &immr->im_memctl;
96 extern void m8260_cpm_reset (void);
97
98 /* Pointer is writable since we allocated a register for it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099 gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
wdenkc6097192002-11-03 00:24:07 +0000100
101 /* Clear initial global data */
102 memset ((void *) gd, 0, sizeof (gd_t));
103
104 /* RSR - Reset Status Register - clear all status (5-4) */
Simon Glass4d6eaa32012-12-13 20:48:56 +0000105 gd->arch.reset_status = immr->im_clkrst.car_rsr;
wdenkc6097192002-11-03 00:24:07 +0000106 immr->im_clkrst.car_rsr = RSR_ALLBITS;
107
108 /* RMR - Reset Mode Register - contains checkstop reset enable (5-5) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109 immr->im_clkrst.car_rmr = CONFIG_SYS_RMR;
wdenkc6097192002-11-03 00:24:07 +0000110
111 /* BCR - Bus Configuration Register (4-25) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112#if defined(CONFIG_SYS_BCR_60x) && (CONFIG_SYS_BCR_SINGLE)
Heiko Schocher3ec43662006-12-21 17:17:02 +0100113 if (immr->im_siu_conf.sc_bcr & BCR_EBM) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200114 immr->im_siu_conf.sc_bcr = SET_VAL_MASK(immr->im_siu_conf.sc_bcr, CONFIG_SYS_BCR_60x, 0x80000010);
Heiko Schocher3ec43662006-12-21 17:17:02 +0100115 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200116 immr->im_siu_conf.sc_bcr = SET_VAL_MASK(immr->im_siu_conf.sc_bcr, CONFIG_SYS_BCR_SINGLE, 0x80000010);
Heiko Schocher3ec43662006-12-21 17:17:02 +0100117 }
118#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119 immr->im_siu_conf.sc_bcr = CONFIG_SYS_BCR;
Heiko Schocher3ec43662006-12-21 17:17:02 +0100120#endif
wdenkc6097192002-11-03 00:24:07 +0000121
122 /* SIUMCR - contains debug pin configuration (4-31) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200123#if defined(CONFIG_SYS_SIUMCR_LOW) && (CONFIG_SYS_SIUMCR_HIGH)
Heiko Schocher3ec43662006-12-21 17:17:02 +0100124 cpu_clk = board_get_cpu_clk_f ();
125 if (cpu_clk >= 100000000) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126 immr->im_siu_conf.sc_siumcr = SET_VAL_MASK(immr->im_siu_conf.sc_siumcr, CONFIG_SYS_SIUMCR_HIGH, 0x9f3cc000);
Heiko Schocher3ec43662006-12-21 17:17:02 +0100127 } else {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200128 immr->im_siu_conf.sc_siumcr = SET_VAL_MASK(immr->im_siu_conf.sc_siumcr, CONFIG_SYS_SIUMCR_LOW, 0x9f3cc000);
Heiko Schocher3ec43662006-12-21 17:17:02 +0100129 }
130#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131 immr->im_siu_conf.sc_siumcr = CONFIG_SYS_SIUMCR;
Heiko Schocher3ec43662006-12-21 17:17:02 +0100132#endif
wdenkc6097192002-11-03 00:24:07 +0000133
134 config_8260_ioports (immr);
135
136 /* initialize time counter status and control register (4-40) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200137 immr->im_sit.sit_tmcntsc = CONFIG_SYS_TMCNTSC;
wdenkc6097192002-11-03 00:24:07 +0000138
139 /* initialize the PIT (4-42) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140 immr->im_sit.sit_piscr = CONFIG_SYS_PISCR;
wdenkc6097192002-11-03 00:24:07 +0000141
wdenkc6097192002-11-03 00:24:07 +0000142 /* System clock control register (9-8) */
wdenke55402c2004-03-14 16:51:43 +0000143 sccr = immr->im_clkrst.car_sccr &
144 (SCCR_PCI_MODE | SCCR_PCI_MODCK | SCCR_PCIDF_MSK);
145 immr->im_clkrst.car_sccr = sccr |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146 (CONFIG_SYS_SCCR & ~(SCCR_PCI_MODE | SCCR_PCI_MODCK | SCCR_PCIDF_MSK) );
wdenkc6097192002-11-03 00:24:07 +0000147
148 /*
149 * Memory Controller:
150 */
151
152 /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
153 * addresses - these have to be modified later when FLASH size
154 * has been determined
155 */
156
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157#if defined(CONFIG_SYS_OR0_REMAP)
158 memctl->memc_or0 = CONFIG_SYS_OR0_REMAP;
wdenkc6097192002-11-03 00:24:07 +0000159#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200160#if defined(CONFIG_SYS_OR1_REMAP)
161 memctl->memc_or1 = CONFIG_SYS_OR1_REMAP;
wdenkc6097192002-11-03 00:24:07 +0000162#endif
163
164 /* now restrict to preliminary range */
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +0200165 /* the PS came from the HRCW, don't change it */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166 memctl->memc_br0 = SET_VAL_MASK(memctl->memc_br0 , CONFIG_SYS_BR0_PRELIM, BRx_PS_MSK);
167 memctl->memc_or0 = CONFIG_SYS_OR0_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000168
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200169#if defined(CONFIG_SYS_BR1_PRELIM) && defined(CONFIG_SYS_OR1_PRELIM)
170 memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
171 memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000172#endif
173
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200174#if defined(CONFIG_SYS_BR2_PRELIM) && defined(CONFIG_SYS_OR2_PRELIM)
175 memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM;
176 memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000177#endif
178
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200179#if defined(CONFIG_SYS_BR3_PRELIM) && defined(CONFIG_SYS_OR3_PRELIM)
180 memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
181 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000182#endif
183
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200184#if defined(CONFIG_SYS_BR4_PRELIM) && defined(CONFIG_SYS_OR4_PRELIM)
185 memctl->memc_or4 = CONFIG_SYS_OR4_PRELIM;
186 memctl->memc_br4 = CONFIG_SYS_BR4_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000187#endif
188
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200189#if defined(CONFIG_SYS_BR5_PRELIM) && defined(CONFIG_SYS_OR5_PRELIM)
190 memctl->memc_or5 = CONFIG_SYS_OR5_PRELIM;
191 memctl->memc_br5 = CONFIG_SYS_BR5_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000192#endif
193
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200194#if defined(CONFIG_SYS_BR6_PRELIM) && defined(CONFIG_SYS_OR6_PRELIM)
195 memctl->memc_or6 = CONFIG_SYS_OR6_PRELIM;
196 memctl->memc_br6 = CONFIG_SYS_BR6_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000197#endif
198
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200199#if defined(CONFIG_SYS_BR7_PRELIM) && defined(CONFIG_SYS_OR7_PRELIM)
200 memctl->memc_or7 = CONFIG_SYS_OR7_PRELIM;
201 memctl->memc_br7 = CONFIG_SYS_BR7_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000202#endif
203
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200204#if defined(CONFIG_SYS_BR8_PRELIM) && defined(CONFIG_SYS_OR8_PRELIM)
205 memctl->memc_or8 = CONFIG_SYS_OR8_PRELIM;
206 memctl->memc_br8 = CONFIG_SYS_BR8_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000207#endif
208
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200209#if defined(CONFIG_SYS_BR9_PRELIM) && defined(CONFIG_SYS_OR9_PRELIM)
210 memctl->memc_or9 = CONFIG_SYS_OR9_PRELIM;
211 memctl->memc_br9 = CONFIG_SYS_BR9_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000212#endif
213
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200214#if defined(CONFIG_SYS_BR10_PRELIM) && defined(CONFIG_SYS_OR10_PRELIM)
215 memctl->memc_or10 = CONFIG_SYS_OR10_PRELIM;
216 memctl->memc_br10 = CONFIG_SYS_BR10_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000217#endif
218
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200219#if defined(CONFIG_SYS_BR11_PRELIM) && defined(CONFIG_SYS_OR11_PRELIM)
220 memctl->memc_or11 = CONFIG_SYS_OR11_PRELIM;
221 memctl->memc_br11 = CONFIG_SYS_BR11_PRELIM;
wdenkc6097192002-11-03 00:24:07 +0000222#endif
223
224 m8260_cpm_reset ();
225}
226
227/*
228 * initialize higher level parts of CPU like time base and timers
229 */
230int cpu_init_r (void)
231{
wdenkc6097192002-11-03 00:24:07 +0000232 volatile immap_t *immr = (immap_t *) gd->bd->bi_immr_base;
233
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200234 immr->im_cpm.cp_rccr = CONFIG_SYS_RCCR;
wdenkc6097192002-11-03 00:24:07 +0000235
236 return (0);
237}
238
239/*
240 * print out the reason for the reset
241 */
242int prt_8260_rsr (void)
243{
wdenkc6097192002-11-03 00:24:07 +0000244 static struct {
245 ulong mask;
246 char *desc;
247 } bits[] = {
248 {
249 RSR_JTRS, "JTAG"}, {
250 RSR_CSRS, "Check Stop"}, {
251 RSR_SWRS, "Software Watchdog"}, {
252 RSR_BMRS, "Bus Monitor"}, {
253 RSR_ESRS, "External Soft"}, {
254 RSR_EHRS, "External Hard"}
255 };
256 static int n = sizeof bits / sizeof bits[0];
Simon Glass4d6eaa32012-12-13 20:48:56 +0000257 ulong rsr = gd->arch.reset_status;
wdenkc6097192002-11-03 00:24:07 +0000258 int i;
259 char *sep;
260
wdenkc08f1582003-04-27 22:52:51 +0000261 puts (CPU_ID_STR " Reset Status:");
wdenkc6097192002-11-03 00:24:07 +0000262
263 sep = " ";
264 for (i = 0; i < n; i++)
265 if (rsr & bits[i].mask) {
266 printf ("%s%s", sep, bits[i].desc);
267 sep = ", ";
268 }
269
270 puts ("\n\n");
271 return (0);
272}