TEXT_BASE is in board/sandpoint/config.mk so say so...
[u-boot.git] / cpu / mcf52x2 / cpu_init.c
1 /*
2  * (C) Copyright 2003
3  * Josef Baumgartner <josef.baumgartner@telex.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 #include <common.h>
25 #include <watchdog.h>
26
27 #ifdef  CONFIG_M5272
28 #include <asm/m5272.h>
29 #include <asm/immap_5272.h>
30 #endif
31
32 #ifdef  CONFIG_M5282
33 #include <asm/m5282.h>
34 #include <asm/immap_5282.h>
35 #endif
36
37 #ifdef  CONFIG_M5249
38 #include <asm/m5249.h>
39 #endif
40
41 #if defined(CONFIG_M5272)
42 /*
43  * Breath some life into the CPU...
44  *
45  * Set up the memory map,
46  * initialize a bunch of registers,
47  * initialize the UPM's
48  */
49 void cpu_init_f (void)
50 {
51         /* if we come from RAM we assume the CPU is
52          * already initialized.
53          */
54 #ifndef CONFIG_MONITOR_IS_IN_RAM
55         volatile immap_t *regp = (immap_t *)CFG_MBAR;
56
57         volatile unsigned char  *mbar;
58         mbar = (volatile unsigned char *) CFG_MBAR;
59
60         regp->sysctrl_reg.sc_scr = CFG_SCR;
61         regp->sysctrl_reg.sc_spr = CFG_SPR;
62
63         /* Setup Ports: */
64         regp->gpio_reg.gpio_pacnt = CFG_PACNT;
65         regp->gpio_reg.gpio_paddr = CFG_PADDR;
66         regp->gpio_reg.gpio_padat = CFG_PADAT;
67         regp->gpio_reg.gpio_pbcnt = CFG_PBCNT;
68         regp->gpio_reg.gpio_pbddr = CFG_PBDDR;
69         regp->gpio_reg.gpio_pbdat = CFG_PBDAT;
70         regp->gpio_reg.gpio_pdcnt = CFG_PDCNT;
71
72         /* Memory Controller: */
73         regp->csctrl_reg.cs_br0 = CFG_BR0_PRELIM;
74         regp->csctrl_reg.cs_or0 = CFG_OR0_PRELIM;
75
76 #if (defined(CFG_OR1_PRELIM) && defined(CFG_BR1_PRELIM))
77         regp->csctrl_reg.cs_br1 = CFG_BR1_PRELIM;
78         regp->csctrl_reg.cs_or1 = CFG_OR1_PRELIM;
79 #endif
80
81 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
82         regp->csctrl_reg.cs_br2 = CFG_BR2_PRELIM;
83         regp->csctrl_reg.cs_or2 = CFG_OR2_PRELIM;
84 #endif
85
86 #if defined(CFG_OR3_PRELIM) && defined(CFG_BR3_PRELIM)
87         regp->csctrl_reg.cs_br3 = CFG_BR3_PRELIM;
88         regp->csctrl_reg.cs_or3 = CFG_OR3_PRELIM;
89 #endif
90
91 #if defined(CFG_OR4_PRELIM) && defined(CFG_BR4_PRELIM)
92         regp->csctrl_reg.cs_br4 = CFG_BR4_PRELIM;
93         regp->csctrl_reg.cs_or4 = CFG_OR4_PRELIM;
94 #endif
95
96 #if defined(CFG_OR5_PRELIM) && defined(CFG_BR5_PRELIM)
97         regp->csctrl_reg.cs_br5 = CFG_BR5_PRELIM;
98         regp->csctrl_reg.cs_or5 = CFG_OR5_PRELIM;
99 #endif
100
101 #if defined(CFG_OR6_PRELIM) && defined(CFG_BR6_PRELIM)
102         regp->csctrl_reg.cs_br6 = CFG_BR6_PRELIM;
103         regp->csctrl_reg.cs_or6 = CFG_OR6_PRELIM;
104 #endif
105
106 #if defined(CFG_OR7_PRELIM) && defined(CFG_BR7_PRELIM)
107         regp->csctrl_reg.cs_br7 = CFG_BR7_PRELIM;
108         regp->csctrl_reg.cs_or7 = CFG_OR7_PRELIM;
109 #endif
110
111 #endif /* #ifndef CONFIG_MONITOR_IS_IN_RAM */
112
113     /* enable instruction cache now */
114     icache_enable();
115
116 }
117
118 /*
119  * initialize higher level parts of CPU like timers
120  */
121 int cpu_init_r  (void)
122 {
123         return (0);
124 }
125 #endif /* #if defined(CONFIG_M5272) */
126
127
128 #ifdef  CONFIG_M5282
129 /*
130  * Breath some life into the CPU...
131  *
132  * Set up the memory map,
133  * initialize a bunch of registers,
134  * initialize the UPM's
135  */
136 void cpu_init_f (void)
137 {
138
139 }
140
141 /*
142  * initialize higher level parts of CPU like timers
143  */
144 int cpu_init_r  (void)
145 {
146         return (0);
147 }
148 #endif
149
150 #if defined(CONFIG_M5249)
151 /*
152  * Breath some life into the CPU...
153  *
154  * Set up the memory map,
155  * initialize a bunch of registers,
156  * initialize the UPM's
157  */
158 void cpu_init_f (void)
159 {
160 #ifndef CFG_PLL_BYPASS
161         /*
162          *  Setup the PLL to run at the specified speed
163          *
164          */
165         volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
166         unsigned long pllcr;
167 #ifdef CFG_FAST_CLK
168         pllcr = 0x925a3100;                       /* ~140MHz clock (PLL bypass = 0) */
169 #else
170         pllcr = 0x135a4140;                       /* ~72MHz clock (PLL bypass = 0) */
171 #endif
172         cpll = cpll & 0xfffffffe;                 /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
173         mbar2_writeLong(MCFSIM_PLLCR, cpll);      /* Set the PLL to bypass mode (PSTCLK = crystal) */
174         mbar2_writeLong(MCFSIM_PLLCR, pllcr);     /* set the clock speed */
175         pllcr ^= 0x00000001;                      /* Set pll bypass to 1 */
176         mbar2_writeLong(MCFSIM_PLLCR, pllcr);     /* Start locking (pll bypass = 1) */
177         udelay(0x20);                             /* Wait for a lock ... */
178 #endif /* #ifndef CFG_PLL_BYPASS */
179
180         /*
181          *  NOTE: by setting the GPIO_FUNCTION registers, we ensure that the UART pins
182          *        (UART0: gpio 30,27, UART1: gpio 31, 28) will be used as UART pins
183          *        which is their primary function.
184          *        ~Jeremy
185          */
186         mbar2_writeLong(MCFSIM_GPIO_FUNC, CFG_GPIO_FUNC);
187         mbar2_writeLong(MCFSIM_GPIO1_FUNC, CFG_GPIO1_FUNC);
188         mbar2_writeLong(MCFSIM_GPIO_EN, CFG_GPIO_EN);
189         mbar2_writeLong(MCFSIM_GPIO1_EN, CFG_GPIO1_EN);
190         mbar2_writeLong(MCFSIM_GPIO_OUT, CFG_GPIO_OUT);
191         mbar2_writeLong(MCFSIM_GPIO1_OUT, CFG_GPIO1_OUT);
192
193         /*
194          *  dBug Compliance:
195          *    You can verify these values by using dBug's 'ird'
196          *    (Internal Register Display) command
197          *    ~Jeremy
198          *
199          */
200         mbar_writeByte(MCFSIM_MPARK, 0x30);    /* 5249 Internal Core takes priority over DMA */
201         mbar_writeByte(MCFSIM_SYPCR, 0x00);
202         mbar_writeByte(MCFSIM_SWIVR, 0x0f);
203         mbar_writeByte(MCFSIM_SWSR, 0x00);
204         mbar_writeLong(MCFSIM_IMR, 0xfffffbff);
205         mbar_writeByte(MCFSIM_SWDICR, 0x00);
206         mbar_writeByte(MCFSIM_TIMER1ICR, 0x00);
207         mbar_writeByte(MCFSIM_TIMER2ICR, 0x88);
208         mbar_writeByte(MCFSIM_I2CICR, 0x00);
209         mbar_writeByte(MCFSIM_UART1ICR, 0x00);
210         mbar_writeByte(MCFSIM_UART2ICR, 0x00);
211         mbar_writeByte(MCFSIM_ICR6, 0x00);
212         mbar_writeByte(MCFSIM_ICR7, 0x00);
213         mbar_writeByte(MCFSIM_ICR8, 0x00);
214         mbar_writeByte(MCFSIM_ICR9, 0x00);
215         mbar_writeByte(MCFSIM_QSPIICR, 0x00);
216
217         mbar2_writeLong(MCFSIM_GPIO_INT_EN, 0x00000080);
218         mbar2_writeByte(MCFSIM_INTBASE, 0x40);  /* Base interrupts at 64 */
219         mbar2_writeByte(MCFSIM_SPURVEC, 0x00);
220         mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020);  /* Enable a 1 cycle pre-drive cycle on CS1 */
221
222         /* Setup interrupt priorities for gpio7 */
223         /* mbar2_writeLong(MCFSIM_INTLEV5, 0x70000000); */
224
225         /* IDE Config registers */
226         mbar2_writeLong(MCFSIM_IDECONFIG1, 0x00000020);
227         mbar2_writeLong(MCFSIM_IDECONFIG2, 0x00000000);
228
229         /*
230          *  Setup chip selects...
231          */
232
233         mbar_writeShort(MCFSIM_CSAR1, CFG_CSAR1);
234         mbar_writeShort(MCFSIM_CSCR1, CFG_CSCR1);
235         mbar_writeLong(MCFSIM_CSMR1, CFG_CSMR1);
236
237         mbar_writeShort(MCFSIM_CSAR0, CFG_CSAR0);
238         mbar_writeShort(MCFSIM_CSCR0, CFG_CSCR0);
239         mbar_writeLong(MCFSIM_CSMR0, CFG_CSMR0);
240
241         /* enable instruction cache now */
242         icache_enable();
243 }
244
245 /*
246  * initialize higher level parts of CPU like timers
247  */
248 int cpu_init_r  (void)
249 {
250         return (0);
251 }
252 #endif /* #if defined(CONFIG_M5249) */