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