xref: /openbmc/u-boot/arch/m68k/cpu/mcf532x/cpu_init.c (revision a65b25d1)
1 /*
2  *
3  * (C) Copyright 2000-2003
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  *
6  * (C) Copyright 2004-2008, 2012 Freescale Semiconductor, Inc.
7  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8  *
9  * SPDX-License-Identifier:	GPL-2.0+
10  */
11 
12 #include <common.h>
13 #include <watchdog.h>
14 #include <asm/immap.h>
15 #include <asm/io.h>
16 
17 #if defined(CONFIG_CMD_NET)
18 #include <config.h>
19 #include <net.h>
20 #include <asm/fec.h>
21 #endif
22 
23 #ifdef CONFIG_MCF5301x
24 void cpu_init_f(void)
25 {
26 	scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
27 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
28 	fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
29 
30 	out_be32(&scm1->mpr, 0x77777777);
31 	out_be32(&scm1->pacra, 0);
32 	out_be32(&scm1->pacrb, 0);
33 	out_be32(&scm1->pacrc, 0);
34 	out_be32(&scm1->pacrd, 0);
35 	out_be32(&scm1->pacre, 0);
36 	out_be32(&scm1->pacrf, 0);
37 	out_be32(&scm1->pacrg, 0);
38 
39 #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
40      && defined(CONFIG_SYS_CS0_CTRL))
41 	setbits_8(&gpio->par_cs, GPIO_PAR_CS0_CS0);
42 	out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
43 	out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
44 	out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
45 #endif
46 
47 #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
48      && defined(CONFIG_SYS_CS1_CTRL))
49 	setbits_8(&gpio->par_cs, GPIO_PAR_CS1_CS1);
50 	out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
51 	out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
52 	out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
53 #endif
54 
55 #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
56      && defined(CONFIG_SYS_CS2_CTRL))
57 	out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
58 	out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
59 	out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
60 #endif
61 
62 #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
63      && defined(CONFIG_SYS_CS3_CTRL))
64 	out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
65 	out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
66 	out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
67 #endif
68 
69 #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
70      && defined(CONFIG_SYS_CS4_CTRL))
71 	setbits_8(&gpio->par_cs, GPIO_PAR_CS4);
72 	out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
73 	out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
74 	out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
75 #endif
76 
77 #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
78      && defined(CONFIG_SYS_CS5_CTRL))
79 	setbits_8(&gpio->par_cs, GPIO_PAR_CS5);
80 	out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
81 	out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
82 	out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
83 #endif
84 
85 #ifdef CONFIG_SYS_I2C_FSL
86 	out_8(&gpio->par_feci2c,
87 		GPIO_PAR_FECI2C_SDA_SDA | GPIO_PAR_FECI2C_SCL_SCL);
88 #endif
89 
90 	icache_enable();
91 }
92 
93 /* initialize higher level parts of CPU like timers */
94 int cpu_init_r(void)
95 {
96 #ifdef CONFIG_MCFFEC
97 	ccm_t *ccm = (ccm_t *) MMAP_CCM;
98 #endif
99 #ifdef CONFIG_MCFRTC
100 	rtc_t *rtc = (rtc_t *) (CONFIG_SYS_MCFRTC_BASE);
101 	rtcex_t *rtcex = (rtcex_t *) &rtc->extended;
102 
103 	out_be32(&rtcex->gocu, CONFIG_SYS_RTC_CNT);
104 	out_be32(&rtcex->gocl, CONFIG_SYS_RTC_SETUP);
105 
106 #endif
107 #ifdef CONFIG_MCFFEC
108 	if (CONFIG_SYS_FEC0_MIIBASE != CONFIG_SYS_FEC1_MIIBASE)
109 		setbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
110 	else
111 		clrbits_be16(&ccm->misccr, CCM_MISCCR_FECM);
112 #endif
113 
114 	return (0);
115 }
116 
117 void uart_port_conf(int port)
118 {
119 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
120 
121 	/* Setup Ports: */
122 	switch (port) {
123 	case 0:
124 		clrbits_8(&gpio->par_uart,
125 			GPIO_PAR_UART_U0TXD | GPIO_PAR_UART_U0RXD);
126 		setbits_8(&gpio->par_uart,
127 			GPIO_PAR_UART_U0TXD | GPIO_PAR_UART_U0RXD);
128 		break;
129 	case 1:
130 #ifdef CONFIG_SYS_UART1_ALT1_GPIO
131 		clrbits_8(&gpio->par_simp1h,
132 			GPIO_PAR_SIMP1H_DATA1_UNMASK |
133 			GPIO_PAR_SIMP1H_VEN1_UNMASK);
134 		setbits_8(&gpio->par_simp1h,
135 			GPIO_PAR_SIMP1H_DATA1_U1TXD |
136 			GPIO_PAR_SIMP1H_VEN1_U1RXD);
137 #elif defined(CONFIG_SYS_UART1_ALT2_GPIO)
138 		clrbits_8(&gpio->par_ssih,
139 			GPIO_PAR_SSIH_RXD_UNMASK |
140 			GPIO_PAR_SSIH_TXD_UNMASK);
141 		setbits_8(&gpio->par_ssih,
142 			GPIO_PAR_SSIH_RXD_U1RXD |
143 			GPIO_PAR_SSIH_TXD_U1TXD);
144 #endif
145 		break;
146 	case 2:
147 #ifdef CONFIG_SYS_UART2_PRI_GPIO
148 		setbits_8(&gpio->par_uart,
149 			GPIO_PAR_UART_U2TXD |
150 			GPIO_PAR_UART_U2RXD);
151 #elif defined(CONFIG_SYS_UART2_ALT1_GPIO)
152 		clrbits_8(&gpio->par_dspih,
153 			GPIO_PAR_DSPIH_SIN_UNMASK |
154 			GPIO_PAR_DSPIH_SOUT_UNMASK);
155 		setbits_8(&gpio->par_dspih,
156 			GPIO_PAR_DSPIH_SIN_U2RXD |
157 			GPIO_PAR_DSPIH_SOUT_U2TXD);
158 #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
159 		clrbits_8(&gpio->par_feci2c,
160 			GPIO_PAR_FECI2C_SDA_UNMASK |
161 			GPIO_PAR_FECI2C_SCL_UNMASK);
162 		setbits_8(&gpio->par_feci2c,
163 			GPIO_PAR_FECI2C_SDA_U2TXD |
164 			GPIO_PAR_FECI2C_SCL_U2RXD);
165 #endif
166 		break;
167 	}
168 }
169 
170 #if defined(CONFIG_CMD_NET)
171 int fecpin_setclear(struct eth_device *dev, int setclear)
172 {
173 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
174 	struct fec_info_s *info = (struct fec_info_s *)dev->priv;
175 
176 	if (setclear) {
177 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
178 			setbits_8(&gpio->par_fec,
179 				GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
180 			setbits_8(&gpio->par_feci2c,
181 				GPIO_PAR_FECI2C_MDC0 | GPIO_PAR_FECI2C_MDIO0);
182 		} else {
183 			setbits_8(&gpio->par_fec,
184 				GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC);
185 			setbits_8(&gpio->par_feci2c,
186 				GPIO_PAR_FECI2C_MDC1 | GPIO_PAR_FECI2C_MDIO1);
187 		}
188 	} else {
189 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
190 			clrbits_8(&gpio->par_fec,
191 				GPIO_PAR_FEC0_7W_FEC | GPIO_PAR_FEC0_RMII_FEC);
192 			clrbits_8(&gpio->par_feci2c, ~GPIO_PAR_FECI2C_RMII0_UNMASK);
193 		} else {
194 			clrbits_8(&gpio->par_fec,
195 				GPIO_PAR_FEC1_7W_FEC | GPIO_PAR_FEC1_RMII_FEC);
196 			clrbits_8(&gpio->par_feci2c, ~GPIO_PAR_FECI2C_RMII1_UNMASK);
197 		}
198 	}
199 	return 0;
200 }
201 #endif				/* CONFIG_CMD_NET */
202 #endif				/* CONFIG_MCF5301x */
203 
204 #ifdef CONFIG_MCF532x
205 void cpu_init_f(void)
206 {
207 	scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
208 	scm2_t *scm2 = (scm2_t *) MMAP_SCM2;
209 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
210 	fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
211 #ifndef CONFIG_WATCHDOG
212 	wdog_t *wdog = (wdog_t *) MMAP_WDOG;
213 
214 	/* watchdog is enabled by default - disable the watchdog */
215 	out_be16(&wdog->cr, 0);
216 #endif
217 
218 	out_be32(&scm1->mpr0, 0x77777777);
219 	out_be32(&scm2->pacra, 0);
220 	out_be32(&scm2->pacrb, 0);
221 	out_be32(&scm2->pacrc, 0);
222 	out_be32(&scm2->pacrd, 0);
223 	out_be32(&scm2->pacre, 0);
224 	out_be32(&scm2->pacrf, 0);
225 	out_be32(&scm2->pacrg, 0);
226 	out_be32(&scm1->pacrh, 0);
227 
228 	/* Port configuration */
229 	out_8(&gpio->par_cs, 0);
230 
231 #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \
232      && defined(CONFIG_SYS_CS0_CTRL))
233 	out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
234 	out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
235 	out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
236 #endif
237 
238 #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \
239      && defined(CONFIG_SYS_CS1_CTRL))
240 	/* Latch chipselect */
241 	setbits_8(&gpio->par_cs, GPIO_PAR_CS1);
242 	out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
243 	out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
244 	out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
245 #endif
246 
247 #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \
248      && defined(CONFIG_SYS_CS2_CTRL))
249 	setbits_8(&gpio->par_cs, GPIO_PAR_CS2);
250 	out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
251 	out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
252 	out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
253 #endif
254 
255 #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \
256      && defined(CONFIG_SYS_CS3_CTRL))
257 	setbits_8(&gpio->par_cs, GPIO_PAR_CS3);
258 	out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
259 	out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
260 	out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
261 #endif
262 
263 #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \
264      && defined(CONFIG_SYS_CS4_CTRL))
265 	setbits_8(&gpio->par_cs, GPIO_PAR_CS4);
266 	out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
267 	out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
268 	out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
269 #endif
270 
271 #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \
272      && defined(CONFIG_SYS_CS5_CTRL))
273 	setbits_8(&gpio->par_cs, GPIO_PAR_CS5);
274 	out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
275 	out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
276 	out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
277 #endif
278 
279 #ifdef CONFIG_SYS_I2C_FSL
280 	out_8(&gpio->par_feci2c,
281 		GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
282 #endif
283 
284 	icache_enable();
285 }
286 
287 /*
288  * initialize higher level parts of CPU like timers
289  */
290 int cpu_init_r(void)
291 {
292 	return (0);
293 }
294 
295 void uart_port_conf(int port)
296 {
297 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
298 
299 	/* Setup Ports: */
300 	switch (port) {
301 	case 0:
302 		clrbits_be16(&gpio->par_uart,
303 			GPIO_PAR_UART_TXD0 | GPIO_PAR_UART_RXD0);
304 		setbits_be16(&gpio->par_uart,
305 			GPIO_PAR_UART_TXD0 | GPIO_PAR_UART_RXD0);
306 		break;
307 	case 1:
308 		clrbits_be16(&gpio->par_uart,
309 			GPIO_PAR_UART_TXD1(3) | GPIO_PAR_UART_RXD1(3));
310 		setbits_be16(&gpio->par_uart,
311 			GPIO_PAR_UART_TXD1(3) | GPIO_PAR_UART_RXD1(3));
312 		break;
313 	case 2:
314 #ifdef CONFIG_SYS_UART2_ALT1_GPIO
315 		clrbits_8(&gpio->par_timer, 0xf0);
316 		setbits_8(&gpio->par_timer,
317 			GPIO_PAR_TIN3_URXD2 | GPIO_PAR_TIN2_UTXD2);
318 #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
319 		clrbits_8(&gpio->par_feci2c, 0x00ff);
320 		setbits_8(&gpio->par_feci2c,
321 			GPIO_PAR_FECI2C_SCL_UTXD2 | GPIO_PAR_FECI2C_SDA_URXD2);
322 #elif defined(CONFIG_SYS_UART2_ALT3_GPIO)
323 		clrbits_be16(&gpio->par_ssi, 0x0f00);
324 		setbits_be16(&gpio->par_ssi,
325 			GPIO_PAR_SSI_RXD(2) | GPIO_PAR_SSI_TXD(2));
326 #endif
327 		break;
328 	}
329 }
330 
331 #if defined(CONFIG_CMD_NET)
332 int fecpin_setclear(struct eth_device *dev, int setclear)
333 {
334 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
335 
336 	if (setclear) {
337 		setbits_8(&gpio->par_fec,
338 			GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
339 		setbits_8(&gpio->par_feci2c,
340 			GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
341 	} else {
342 		clrbits_8(&gpio->par_fec,
343 			GPIO_PAR_FEC_7W_FEC | GPIO_PAR_FEC_MII_FEC);
344 		clrbits_8(&gpio->par_feci2c,
345 			GPIO_PAR_FECI2C_MDC_EMDC | GPIO_PAR_FECI2C_MDIO_EMDIO);
346 	}
347 	return 0;
348 }
349 #endif
350 #endif				/* CONFIG_MCF532x */
351