1 // SPDX-License-Identifier: GPL-2.0+
4 * (C) Copyright 2000-2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
8 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
13 #include <asm/immap.h>
14 #include <asm/processor.h>
17 #include <linux/compiler.h>
19 #if defined(CONFIG_CMD_NET)
27 fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
29 #if !defined(CONFIG_SERIAL_BOOT)
30 #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
31 out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
32 out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
33 out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
37 #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
38 /* Latch chipselect */
39 out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
40 out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
41 out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
44 #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
45 out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
46 out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
47 out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
50 #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
51 out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
52 out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
53 out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
56 #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
57 out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
58 out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
59 out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
62 #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
63 out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
64 out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
65 out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
70 * Breath some life into the CPU...
72 * Set up the memory map,
73 * initialize a bunch of registers,
74 * initialize the UPM's
78 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
80 #ifdef CONFIG_MCF5441x
81 scm_t *scm = (scm_t *) MMAP_SCM;
82 pm_t *pm = (pm_t *) MMAP_PM;
85 *(unsigned long *)(MMAP_L2_SW0 + 0x00000024) = 0;
87 /* Disable core watchdog */
88 out_be16(&scm->cwcr, 0);
89 out_8(&gpio->par_fbctl,
90 GPIO_PAR_FBCTL_ALE_FB_ALE | GPIO_PAR_FBCTL_OE_FB_OE |
91 GPIO_PAR_FBCTL_FBCLK | GPIO_PAR_FBCTL_RW |
92 GPIO_PAR_FBCTL_TA_TA);
94 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
95 GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
98 out_8(&pm->pmcr0, 17);
101 out_8(&pm->pmcr0, 18);
102 out_8(&pm->pmcr0, 19);
103 out_8(&pm->pmcr0, 20);
106 out_8(&pm->pmcr0, 22);
107 out_8(&pm->pmcr1, 4);
108 out_8(&pm->pmcr1, 7);
111 out_8(&pm->pmcr0, 28);
112 out_8(&pm->pmcr0, 29);
113 out_8(&pm->pmcr0, 30);
114 out_8(&pm->pmcr0, 31);
117 out_8(&pm->pmcr0, 32);
118 out_8(&pm->pmcr0, 33);
119 out_8(&pm->pmcr0, 34);
120 out_8(&pm->pmcr0, 35);
123 out_8(&pm->pmcr0, 36);
124 out_8(&pm->pmcr0, 37);
127 out_8(&pm->pmcr0, 44);
129 out_8(&pm->pmcr0, 45);
132 out_8(&pm->pmcr0, 51);
135 out_8(&pm->pmcr0, 53);
136 out_8(&pm->pmcr0, 54);
139 out_8(&pm->pmcr0, 63);
141 #ifdef CONFIG_SYS_I2C_0
142 out_8(&gpio->par_cani2c, 0xF0);
144 out_be16(&gpio->pcr_b, 0x003C);
146 out_8(&gpio->srcr_cani2c, 0x03);
148 #ifdef CONFIG_SYS_I2C_2
150 out_8(&gpio->par_ssi0h, 0xA0);
152 out_8(&gpio->par_ssi0h, 0xA8);
154 out_8(&gpio->par_ssi0l, 0x2);
156 out_8(&gpio->par_cani2c, 0xAA);
158 out_8(&gpio->par_uart0, 0xAF);
160 out_8(&gpio->par_uart1, 0xAF);
162 out_8(&gpio->par_uart2, 0xAF);
164 out_be16(&gpio->pcr_h, 0xF000);
166 #ifdef CONFIG_SYS_I2C_5
168 out_8(&gpio->par_uart1, 0x0A);
170 out_be16(&gpio->pcr_e, 0x0003);
171 out_be16(&gpio->pcr_f, 0xC000);
174 /* Lowest slew rate for UART0,1,2 */
175 out_8(&gpio->srcr_uart, 0x00);
176 #endif /* CONFIG_MCF5441x */
178 #ifdef CONFIG_MCF5445x
179 scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
181 out_be32(&scm1->mpr, 0x77777777);
182 out_be32(&scm1->pacra, 0);
183 out_be32(&scm1->pacrb, 0);
184 out_be32(&scm1->pacrc, 0);
185 out_be32(&scm1->pacrd, 0);
186 out_be32(&scm1->pacre, 0);
187 out_be32(&scm1->pacrf, 0);
188 out_be32(&scm1->pacrg, 0);
192 GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
193 GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
194 out_8(&gpio->par_fbctl,
195 GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
196 GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
198 #ifdef CONFIG_SYS_FSL_I2C
199 out_be16(&gpio->par_feci2c,
200 GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
202 #endif /* CONFIG_MCF5445x */
204 /* FlexBus Chipselect */
207 #ifdef CONFIG_SYS_CS0_BASE
209 * now the flash base address is no longer at 0 (Newer ColdFire family
210 * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
211 * also move to the new location.
213 if (CONFIG_SYS_CS0_BASE != 0)
214 setvbr(CONFIG_SYS_CS0_BASE);
221 * initialize higher level parts of CPU like timers
226 rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
227 rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
229 out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
230 out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
236 void uart_port_conf(int port)
238 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
239 #ifdef CONFIG_MCF5441x
240 pm_t *pm = (pm_t *) MMAP_PM;
245 #ifdef CONFIG_MCF5441x
248 out_8(&pm->pmcr0, 24);
249 clrbits_8(&gpio->par_uart0,
250 ~(GPIO_PAR_UART0_U0RXD_MASK | GPIO_PAR_UART0_U0TXD_MASK));
251 setbits_8(&gpio->par_uart0,
252 GPIO_PAR_UART0_U0RXD_U0RXD | GPIO_PAR_UART0_U0TXD_U0TXD);
256 out_8(&pm->pmcr0, 25);
257 clrbits_8(&gpio->par_uart1,
258 ~(GPIO_PAR_UART1_U1RXD_MASK | GPIO_PAR_UART1_U1TXD_MASK));
259 setbits_8(&gpio->par_uart1,
260 GPIO_PAR_UART1_U1RXD_U1RXD | GPIO_PAR_UART1_U1TXD_U1TXD);
264 out_8(&pm->pmcr0, 26);
265 clrbits_8(&gpio->par_uart2,
266 ~(GPIO_PAR_UART2_U2RXD_MASK | GPIO_PAR_UART2_U2TXD_MASK));
267 setbits_8(&gpio->par_uart2,
268 GPIO_PAR_UART2_U2RXD_U2RXD | GPIO_PAR_UART2_U2TXD_U2TXD);
272 out_8(&pm->pmcr0, 27);
273 clrbits_8(&gpio->par_dspi0,
274 ~(GPIO_PAR_DSPI0_SIN_MASK | GPIO_PAR_DSPI0_SOUT_MASK));
275 setbits_8(&gpio->par_dspi0,
276 GPIO_PAR_DSPI0_SIN_U3RXD | GPIO_PAR_DSPI0_SOUT_U3TXD);
280 out_8(&pm->pmcr1, 24);
281 clrbits_8(&gpio->par_uart0,
282 ~(GPIO_PAR_UART0_U0CTS_MASK | GPIO_PAR_UART0_U0RTS_MASK));
283 setbits_8(&gpio->par_uart0,
284 GPIO_PAR_UART0_U0CTS_U4TXD | GPIO_PAR_UART0_U0RTS_U4RXD);
288 out_8(&pm->pmcr1, 25);
289 clrbits_8(&gpio->par_uart1,
290 ~(GPIO_PAR_UART1_U1CTS_MASK | GPIO_PAR_UART1_U1RTS_MASK));
291 setbits_8(&gpio->par_uart1,
292 GPIO_PAR_UART1_U1CTS_U5TXD | GPIO_PAR_UART1_U1RTS_U5RXD);
296 out_8(&pm->pmcr1, 26);
297 clrbits_8(&gpio->par_uart2,
298 ~(GPIO_PAR_UART2_U2CTS_MASK | GPIO_PAR_UART2_U2RTS_MASK));
299 setbits_8(&gpio->par_uart2,
300 GPIO_PAR_UART2_U2CTS_U6TXD | GPIO_PAR_UART2_U2RTS_U6RXD);
304 out_8(&pm->pmcr1, 27);
305 clrbits_8(&gpio->par_ssi0h, ~GPIO_PAR_SSI0H_RXD_MASK);
306 clrbits_8(&gpio->par_ssi0l, ~GPIO_PAR_SSI0L_BCLK_MASK);
307 setbits_8(&gpio->par_ssi0h, GPIO_PAR_SSI0H_FS_U7TXD);
308 setbits_8(&gpio->par_ssi0l, GPIO_PAR_SSI0L_BCLK_U7RXD);
312 out_8(&pm->pmcr0, 28);
313 clrbits_8(&gpio->par_cani2c,
314 ~(GPIO_PAR_CANI2C_I2C0SCL_MASK | GPIO_PAR_CANI2C_I2C0SDA_MASK));
315 setbits_8(&gpio->par_cani2c,
316 GPIO_PAR_CANI2C_I2C0SCL_U8TXD | GPIO_PAR_CANI2C_I2C0SDA_U8RXD);
320 out_8(&pm->pmcr1, 29);
321 clrbits_8(&gpio->par_cani2c,
322 ~(GPIO_PAR_CANI2C_CAN1TX_MASK | GPIO_PAR_CANI2C_CAN1RX_MASK));
323 setbits_8(&gpio->par_cani2c,
324 GPIO_PAR_CANI2C_CAN1TX_U9TXD | GPIO_PAR_CANI2C_CAN1RX_U9RXD);
327 #ifdef CONFIG_MCF5445x
329 clrbits_8(&gpio->par_uart,
330 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
331 setbits_8(&gpio->par_uart,
332 GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
335 #ifdef CONFIG_SYS_UART1_PRI_GPIO
336 clrbits_8(&gpio->par_uart,
337 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
338 setbits_8(&gpio->par_uart,
339 GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
340 #elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
341 clrbits_be16(&gpio->par_ssi,
342 ~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
343 setbits_be16(&gpio->par_ssi,
344 GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
348 #if defined(CONFIG_SYS_UART2_ALT1_GPIO)
349 clrbits_8(&gpio->par_timer,
350 ~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
351 setbits_8(&gpio->par_timer,
352 GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
353 #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
354 clrbits_8(&gpio->par_timer,
355 ~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
356 setbits_8(&gpio->par_timer,
357 GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
360 #endif /* CONFIG_MCF5445x */
364 #if defined(CONFIG_CMD_NET)
365 int fecpin_setclear(struct eth_device *dev, int setclear)
367 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
368 #ifdef CONFIG_MCF5445x
369 struct fec_info_s *info = (struct fec_info_s *)dev->priv;
372 #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
373 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
374 setbits_be16(&gpio->par_feci2c,
375 GPIO_PAR_FECI2C_MDC0_MDC0 |
376 GPIO_PAR_FECI2C_MDIO0_MDIO0);
378 setbits_be16(&gpio->par_feci2c,
379 GPIO_PAR_FECI2C_MDC1_MDC1 |
380 GPIO_PAR_FECI2C_MDIO1_MDIO1);
382 setbits_be16(&gpio->par_feci2c,
383 GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
386 if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
387 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
389 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
391 clrbits_be16(&gpio->par_feci2c,
392 GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
394 if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
395 #ifdef CONFIG_SYS_FEC_FULL_MII
396 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
398 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
401 #ifdef CONFIG_SYS_FEC_FULL_MII
402 setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
404 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
408 #endif /* CONFIG_MCF5445x */
410 #ifdef CONFIG_MCF5441x
412 out_8(&gpio->par_fec, 0x03);
413 out_8(&gpio->srcr_fec, 0x0F);
414 clrsetbits_8(&gpio->par_simp0h, ~GPIO_PAR_SIMP0H_DAT_MASK,
415 GPIO_PAR_SIMP0H_DAT_GPIO);
416 clrsetbits_8(&gpio->pddr_g, ~GPIO_PDDR_G4_MASK,
417 GPIO_PDDR_G4_OUTPUT);
418 clrbits_8(&gpio->podr_g, ~GPIO_PODR_G4_MASK);
421 clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC_MASK);
427 #ifdef CONFIG_CF_DSPI
428 void cfspi_port_conf(void)
430 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
432 #ifdef CONFIG_MCF5445x
433 out_8(&gpio->par_dspi,
434 GPIO_PAR_DSPI_SIN_SIN |
435 GPIO_PAR_DSPI_SOUT_SOUT |
436 GPIO_PAR_DSPI_SCK_SCK);
439 #ifdef CONFIG_MCF5441x
440 pm_t *pm = (pm_t *) MMAP_PM;
442 out_8(&gpio->par_dspi0,
443 GPIO_PAR_DSPI0_SIN_DSPI0SIN | GPIO_PAR_DSPI0_SOUT_DSPI0SOUT |
444 GPIO_PAR_DSPI0_SCK_DSPI0SCK);
445 out_8(&gpio->srcr_dspiow, 3);
448 out_8(&pm->pmcr0, 23);
452 int cfspi_claim_bus(uint bus, uint cs)
454 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
455 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
457 if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
460 /* Clear FIFO and resume transfer */
461 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
463 #ifdef CONFIG_MCF5445x
466 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
467 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
470 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
471 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
474 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
475 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
478 clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
479 setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3);
482 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
483 setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
488 #ifdef CONFIG_MCF5441x
491 clrbits_8(&gpio->par_dspi0, ~GPIO_PAR_DSPI0_PCS0_MASK);
492 setbits_8(&gpio->par_dspi0, GPIO_PAR_DSPI0_PCS0_DSPI0PCS0);
495 clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
496 setbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
504 void cfspi_release_bus(uint bus, uint cs)
506 dspi_t *dspi = (dspi_t *) MMAP_DSPI;
507 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
510 clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
512 #ifdef CONFIG_MCF5445x
515 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
518 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
521 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
524 clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
527 clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
532 #ifdef CONFIG_MCF5441x
534 clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);