xref: /openbmc/u-boot/arch/m68k/cpu/mcf5445x/cpu_init.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a4145534SPeter Tyser /*
3a4145534SPeter Tyser  *
4a4145534SPeter Tyser  * (C) Copyright 2000-2003
5a4145534SPeter Tyser  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6a4145534SPeter Tyser  *
7198cafbfSAlison Wang  * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc.
8a4145534SPeter Tyser  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
9a4145534SPeter Tyser  */
10a4145534SPeter Tyser 
11a4145534SPeter Tyser #include <common.h>
12a4145534SPeter Tyser #include <watchdog.h>
13a4145534SPeter Tyser #include <asm/immap.h>
14a4145534SPeter Tyser #include <asm/processor.h>
15a4145534SPeter Tyser #include <asm/rtc.h>
16198cafbfSAlison Wang #include <asm/io.h>
172b05593dSMarek Vasut #include <linux/compiler.h>
18a4145534SPeter Tyser 
19a4145534SPeter Tyser #if defined(CONFIG_CMD_NET)
20a4145534SPeter Tyser #include <config.h>
21a4145534SPeter Tyser #include <net.h>
22a4145534SPeter Tyser #include <asm/fec.h>
23a4145534SPeter Tyser #endif
24a4145534SPeter Tyser 
2545370e18SAlison Wang void init_fbcs(void)
26a4145534SPeter Tyser {
272b05593dSMarek Vasut 	fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS;
28a4145534SPeter Tyser 
2945370e18SAlison Wang #if !defined(CONFIG_SERIAL_BOOT)
30a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL))
31198cafbfSAlison Wang 	out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE);
32198cafbfSAlison Wang 	out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL);
33198cafbfSAlison Wang 	out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK);
34a4145534SPeter Tyser #endif
35a4145534SPeter Tyser #endif
36a4145534SPeter Tyser 
37a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL))
38a4145534SPeter Tyser 	/* Latch chipselect */
39198cafbfSAlison Wang 	out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE);
40198cafbfSAlison Wang 	out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL);
41198cafbfSAlison Wang 	out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK);
42a4145534SPeter Tyser #endif
43a4145534SPeter Tyser 
44a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL))
45198cafbfSAlison Wang 	out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE);
46198cafbfSAlison Wang 	out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL);
47198cafbfSAlison Wang 	out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK);
48a4145534SPeter Tyser #endif
49a4145534SPeter Tyser 
50a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL))
51198cafbfSAlison Wang 	out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE);
52198cafbfSAlison Wang 	out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL);
53198cafbfSAlison Wang 	out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK);
54a4145534SPeter Tyser #endif
55a4145534SPeter Tyser 
56a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL))
57198cafbfSAlison Wang 	out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE);
58198cafbfSAlison Wang 	out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL);
59198cafbfSAlison Wang 	out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK);
60a4145534SPeter Tyser #endif
61a4145534SPeter Tyser 
62a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL))
63198cafbfSAlison Wang 	out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE);
64198cafbfSAlison Wang 	out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL);
65198cafbfSAlison Wang 	out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK);
66a4145534SPeter Tyser #endif
6745370e18SAlison Wang }
6845370e18SAlison Wang 
6945370e18SAlison Wang /*
7045370e18SAlison Wang  * Breath some life into the CPU...
7145370e18SAlison Wang  *
7245370e18SAlison Wang  * Set up the memory map,
7345370e18SAlison Wang  * initialize a bunch of registers,
7445370e18SAlison Wang  * initialize the UPM's
7545370e18SAlison Wang  */
7645370e18SAlison Wang void cpu_init_f(void)
7745370e18SAlison Wang {
7845370e18SAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
7945370e18SAlison Wang 
8045370e18SAlison Wang #ifdef CONFIG_MCF5441x
8145370e18SAlison Wang 	scm_t *scm = (scm_t *) MMAP_SCM;
8245370e18SAlison Wang 	pm_t *pm = (pm_t *) MMAP_PM;
8345370e18SAlison Wang 
8445370e18SAlison Wang 	/* Disable Switch */
8545370e18SAlison Wang 	*(unsigned long *)(MMAP_L2_SW0 + 0x00000024) = 0;
8645370e18SAlison Wang 
8745370e18SAlison Wang 	/* Disable core watchdog */
8845370e18SAlison Wang 	out_be16(&scm->cwcr, 0);
8945370e18SAlison Wang 	out_8(&gpio->par_fbctl,
9045370e18SAlison Wang 		GPIO_PAR_FBCTL_ALE_FB_ALE | GPIO_PAR_FBCTL_OE_FB_OE |
9145370e18SAlison Wang 		GPIO_PAR_FBCTL_FBCLK | GPIO_PAR_FBCTL_RW |
9245370e18SAlison Wang 		GPIO_PAR_FBCTL_TA_TA);
9345370e18SAlison Wang 	out_8(&gpio->par_be,
9445370e18SAlison Wang 		GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
9545370e18SAlison Wang 		GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
9645370e18SAlison Wang 
9745370e18SAlison Wang 	/* eDMA */
9845370e18SAlison Wang 	out_8(&pm->pmcr0, 17);
9945370e18SAlison Wang 
10045370e18SAlison Wang 	/* INTR0 - INTR2 */
10145370e18SAlison Wang 	out_8(&pm->pmcr0, 18);
10245370e18SAlison Wang 	out_8(&pm->pmcr0, 19);
10345370e18SAlison Wang 	out_8(&pm->pmcr0, 20);
10445370e18SAlison Wang 
10545370e18SAlison Wang 	/* I2C */
10645370e18SAlison Wang 	out_8(&pm->pmcr0, 22);
10745370e18SAlison Wang 	out_8(&pm->pmcr1, 4);
10845370e18SAlison Wang 	out_8(&pm->pmcr1, 7);
10945370e18SAlison Wang 
11045370e18SAlison Wang 	/* DTMR0 - DTMR3*/
11145370e18SAlison Wang 	out_8(&pm->pmcr0, 28);
11245370e18SAlison Wang 	out_8(&pm->pmcr0, 29);
11345370e18SAlison Wang 	out_8(&pm->pmcr0, 30);
11445370e18SAlison Wang 	out_8(&pm->pmcr0, 31);
11545370e18SAlison Wang 
11645370e18SAlison Wang 	/* PIT0 - PIT3 */
11745370e18SAlison Wang 	out_8(&pm->pmcr0, 32);
11845370e18SAlison Wang 	out_8(&pm->pmcr0, 33);
11945370e18SAlison Wang 	out_8(&pm->pmcr0, 34);
12045370e18SAlison Wang 	out_8(&pm->pmcr0, 35);
12145370e18SAlison Wang 
12245370e18SAlison Wang 	/* Edge Port */
12345370e18SAlison Wang 	out_8(&pm->pmcr0, 36);
12445370e18SAlison Wang 	out_8(&pm->pmcr0, 37);
12545370e18SAlison Wang 
12645370e18SAlison Wang 	/* USB OTG */
12745370e18SAlison Wang 	out_8(&pm->pmcr0, 44);
12845370e18SAlison Wang 	/* USB Host */
12945370e18SAlison Wang 	out_8(&pm->pmcr0, 45);
13045370e18SAlison Wang 
13145370e18SAlison Wang 	/* ESDHC */
13245370e18SAlison Wang 	out_8(&pm->pmcr0, 51);
13345370e18SAlison Wang 
13445370e18SAlison Wang 	/* ENET0 - ENET1 */
13545370e18SAlison Wang 	out_8(&pm->pmcr0, 53);
13645370e18SAlison Wang 	out_8(&pm->pmcr0, 54);
13745370e18SAlison Wang 
13845370e18SAlison Wang 	/* NAND */
13945370e18SAlison Wang 	out_8(&pm->pmcr0, 63);
14045370e18SAlison Wang 
14145370e18SAlison Wang #ifdef CONFIG_SYS_I2C_0
14245370e18SAlison Wang 	out_8(&gpio->par_cani2c, 0xF0);
14345370e18SAlison Wang 	/* I2C0 pull up */
14445370e18SAlison Wang 	out_be16(&gpio->pcr_b, 0x003C);
14545370e18SAlison Wang 	/* I2C0 max speed */
14645370e18SAlison Wang 	out_8(&gpio->srcr_cani2c, 0x03);
14745370e18SAlison Wang #endif
14845370e18SAlison Wang #ifdef CONFIG_SYS_I2C_2
14945370e18SAlison Wang 	/* I2C2 */
15045370e18SAlison Wang 	out_8(&gpio->par_ssi0h, 0xA0);
15145370e18SAlison Wang 	/* I2C2, UART7 */
15245370e18SAlison Wang 	out_8(&gpio->par_ssi0h, 0xA8);
15345370e18SAlison Wang 	/* UART7 */
15445370e18SAlison Wang 	out_8(&gpio->par_ssi0l, 0x2);
15545370e18SAlison Wang 	/* UART8, UART9 */
15645370e18SAlison Wang 	out_8(&gpio->par_cani2c, 0xAA);
15745370e18SAlison Wang 	/* UART4, UART0 */
15845370e18SAlison Wang 	out_8(&gpio->par_uart0, 0xAF);
15945370e18SAlison Wang 	/* UART5, UART1 */
16045370e18SAlison Wang 	out_8(&gpio->par_uart1, 0xAF);
16145370e18SAlison Wang 	/* UART6, UART2 */
16245370e18SAlison Wang 	out_8(&gpio->par_uart2, 0xAF);
16345370e18SAlison Wang 	/* I2C2 pull up */
16445370e18SAlison Wang 	out_be16(&gpio->pcr_h, 0xF000);
16545370e18SAlison Wang #endif
16645370e18SAlison Wang #ifdef CONFIG_SYS_I2C_5
16745370e18SAlison Wang 	/* I2C5 */
16845370e18SAlison Wang 	out_8(&gpio->par_uart1, 0x0A);
16945370e18SAlison Wang 	/* I2C5 pull up */
17045370e18SAlison Wang 	out_be16(&gpio->pcr_e, 0x0003);
17145370e18SAlison Wang 	out_be16(&gpio->pcr_f, 0xC000);
17245370e18SAlison Wang #endif
17345370e18SAlison Wang 
17445370e18SAlison Wang 	/* Lowest slew rate for UART0,1,2 */
17545370e18SAlison Wang 	out_8(&gpio->srcr_uart, 0x00);
17645370e18SAlison Wang #endif		/* CONFIG_MCF5441x */
17745370e18SAlison Wang 
17845370e18SAlison Wang #ifdef CONFIG_MCF5445x
17945370e18SAlison Wang 	scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
18045370e18SAlison Wang 
18145370e18SAlison Wang 	out_be32(&scm1->mpr, 0x77777777);
18245370e18SAlison Wang 	out_be32(&scm1->pacra, 0);
18345370e18SAlison Wang 	out_be32(&scm1->pacrb, 0);
18445370e18SAlison Wang 	out_be32(&scm1->pacrc, 0);
18545370e18SAlison Wang 	out_be32(&scm1->pacrd, 0);
18645370e18SAlison Wang 	out_be32(&scm1->pacre, 0);
18745370e18SAlison Wang 	out_be32(&scm1->pacrf, 0);
18845370e18SAlison Wang 	out_be32(&scm1->pacrg, 0);
18945370e18SAlison Wang 
19045370e18SAlison Wang 	/* FlexBus */
19145370e18SAlison Wang 	out_8(&gpio->par_be,
19245370e18SAlison Wang 		GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
19345370e18SAlison Wang 		GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
19445370e18SAlison Wang 	out_8(&gpio->par_fbctl,
19545370e18SAlison Wang 		GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
19645370e18SAlison Wang 		GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
19745370e18SAlison Wang 
19800f792e0SHeiko Schocher #ifdef CONFIG_SYS_FSL_I2C
19945370e18SAlison Wang 	out_be16(&gpio->par_feci2c,
20045370e18SAlison Wang 		GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
20145370e18SAlison Wang #endif
20245370e18SAlison Wang #endif		/* CONFIG_MCF5445x */
20345370e18SAlison Wang 
20445370e18SAlison Wang 	/* FlexBus Chipselect */
20545370e18SAlison Wang 	init_fbcs();
206a4145534SPeter Tyser 
20702a6eddaSAngelo Dureghello #ifdef CONFIG_SYS_CS0_BASE
208a4145534SPeter Tyser 	/*
209a4145534SPeter Tyser 	 * now the flash base address is no longer at 0 (Newer ColdFire family
210a4145534SPeter Tyser 	 * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
211a4145534SPeter Tyser 	 * also move to the new location.
212a4145534SPeter Tyser 	 */
213a4145534SPeter Tyser 	if (CONFIG_SYS_CS0_BASE != 0)
214a4145534SPeter Tyser 		setvbr(CONFIG_SYS_CS0_BASE);
21502a6eddaSAngelo Dureghello #endif
216a4145534SPeter Tyser 
217a4145534SPeter Tyser 	icache_enable();
218a4145534SPeter Tyser }
219a4145534SPeter Tyser 
220a4145534SPeter Tyser /*
221a4145534SPeter Tyser  * initialize higher level parts of CPU like timers
222a4145534SPeter Tyser  */
223a4145534SPeter Tyser int cpu_init_r(void)
224a4145534SPeter Tyser {
225a4145534SPeter Tyser #ifdef CONFIG_MCFRTC
226198cafbfSAlison Wang 	rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
227198cafbfSAlison Wang 	rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
228a4145534SPeter Tyser 
229198cafbfSAlison Wang 	out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
230198cafbfSAlison Wang 	out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
231a4145534SPeter Tyser #endif
232a4145534SPeter Tyser 
233a4145534SPeter Tyser 	return (0);
234a4145534SPeter Tyser }
235a4145534SPeter Tyser 
236a4145534SPeter Tyser void uart_port_conf(int port)
237a4145534SPeter Tyser {
238198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
23945370e18SAlison Wang #ifdef CONFIG_MCF5441x
24045370e18SAlison Wang 	pm_t *pm = (pm_t *) MMAP_PM;
24145370e18SAlison Wang #endif
242a4145534SPeter Tyser 
243a4145534SPeter Tyser 	/* Setup Ports: */
244a4145534SPeter Tyser 	switch (port) {
24545370e18SAlison Wang #ifdef CONFIG_MCF5441x
24645370e18SAlison Wang 	case 0:
24745370e18SAlison Wang 		/* UART0 */
24845370e18SAlison Wang 		out_8(&pm->pmcr0, 24);
24945370e18SAlison Wang 		clrbits_8(&gpio->par_uart0,
25045370e18SAlison Wang 			~(GPIO_PAR_UART0_U0RXD_MASK | GPIO_PAR_UART0_U0TXD_MASK));
25145370e18SAlison Wang 		setbits_8(&gpio->par_uart0,
25245370e18SAlison Wang 			GPIO_PAR_UART0_U0RXD_U0RXD | GPIO_PAR_UART0_U0TXD_U0TXD);
25345370e18SAlison Wang 		break;
25445370e18SAlison Wang 	case 1:
25545370e18SAlison Wang 		/* UART1 */
25645370e18SAlison Wang 		out_8(&pm->pmcr0, 25);
25745370e18SAlison Wang 		clrbits_8(&gpio->par_uart1,
25845370e18SAlison Wang 			~(GPIO_PAR_UART1_U1RXD_MASK | GPIO_PAR_UART1_U1TXD_MASK));
25945370e18SAlison Wang 		setbits_8(&gpio->par_uart1,
26045370e18SAlison Wang 			GPIO_PAR_UART1_U1RXD_U1RXD | GPIO_PAR_UART1_U1TXD_U1TXD);
26145370e18SAlison Wang 		break;
26245370e18SAlison Wang 	case 2:
26345370e18SAlison Wang 		/* UART2 */
26445370e18SAlison Wang 		out_8(&pm->pmcr0, 26);
26545370e18SAlison Wang 		clrbits_8(&gpio->par_uart2,
26645370e18SAlison Wang 			~(GPIO_PAR_UART2_U2RXD_MASK | GPIO_PAR_UART2_U2TXD_MASK));
26745370e18SAlison Wang 		setbits_8(&gpio->par_uart2,
26845370e18SAlison Wang 			GPIO_PAR_UART2_U2RXD_U2RXD | GPIO_PAR_UART2_U2TXD_U2TXD);
26945370e18SAlison Wang 		break;
27045370e18SAlison Wang 	case 3:
27145370e18SAlison Wang 		/* UART3 */
27245370e18SAlison Wang 		out_8(&pm->pmcr0, 27);
27345370e18SAlison Wang 		clrbits_8(&gpio->par_dspi0,
27445370e18SAlison Wang 			~(GPIO_PAR_DSPI0_SIN_MASK | GPIO_PAR_DSPI0_SOUT_MASK));
27545370e18SAlison Wang 		setbits_8(&gpio->par_dspi0,
27645370e18SAlison Wang 			GPIO_PAR_DSPI0_SIN_U3RXD | GPIO_PAR_DSPI0_SOUT_U3TXD);
27745370e18SAlison Wang 		break;
27845370e18SAlison Wang 	case 4:
27945370e18SAlison Wang 		/* UART4 */
28045370e18SAlison Wang 		out_8(&pm->pmcr1, 24);
28145370e18SAlison Wang 		clrbits_8(&gpio->par_uart0,
28245370e18SAlison Wang 			~(GPIO_PAR_UART0_U0CTS_MASK | GPIO_PAR_UART0_U0RTS_MASK));
28345370e18SAlison Wang 		setbits_8(&gpio->par_uart0,
28445370e18SAlison Wang 			GPIO_PAR_UART0_U0CTS_U4TXD | GPIO_PAR_UART0_U0RTS_U4RXD);
28545370e18SAlison Wang 		break;
28645370e18SAlison Wang 	case 5:
28745370e18SAlison Wang 		/* UART5 */
28845370e18SAlison Wang 		out_8(&pm->pmcr1, 25);
28945370e18SAlison Wang 		clrbits_8(&gpio->par_uart1,
29045370e18SAlison Wang 			~(GPIO_PAR_UART1_U1CTS_MASK | GPIO_PAR_UART1_U1RTS_MASK));
29145370e18SAlison Wang 		setbits_8(&gpio->par_uart1,
29245370e18SAlison Wang 			GPIO_PAR_UART1_U1CTS_U5TXD | GPIO_PAR_UART1_U1RTS_U5RXD);
29345370e18SAlison Wang 		break;
29445370e18SAlison Wang 	case 6:
29545370e18SAlison Wang 		/* UART6 */
29645370e18SAlison Wang 		out_8(&pm->pmcr1, 26);
29745370e18SAlison Wang 		clrbits_8(&gpio->par_uart2,
29845370e18SAlison Wang 			~(GPIO_PAR_UART2_U2CTS_MASK | GPIO_PAR_UART2_U2RTS_MASK));
29945370e18SAlison Wang 		setbits_8(&gpio->par_uart2,
30045370e18SAlison Wang 			GPIO_PAR_UART2_U2CTS_U6TXD | GPIO_PAR_UART2_U2RTS_U6RXD);
30145370e18SAlison Wang 		break;
30245370e18SAlison Wang 	case 7:
30345370e18SAlison Wang 		/* UART7 */
30445370e18SAlison Wang 		out_8(&pm->pmcr1, 27);
30545370e18SAlison Wang 		clrbits_8(&gpio->par_ssi0h, ~GPIO_PAR_SSI0H_RXD_MASK);
30645370e18SAlison Wang 		clrbits_8(&gpio->par_ssi0l, ~GPIO_PAR_SSI0L_BCLK_MASK);
30745370e18SAlison Wang 		setbits_8(&gpio->par_ssi0h, GPIO_PAR_SSI0H_FS_U7TXD);
30845370e18SAlison Wang 		setbits_8(&gpio->par_ssi0l, GPIO_PAR_SSI0L_BCLK_U7RXD);
30945370e18SAlison Wang 		break;
31045370e18SAlison Wang 	case 8:
31145370e18SAlison Wang 		/* UART8 */
31245370e18SAlison Wang 		out_8(&pm->pmcr0, 28);
31345370e18SAlison Wang 		clrbits_8(&gpio->par_cani2c,
31445370e18SAlison Wang 			~(GPIO_PAR_CANI2C_I2C0SCL_MASK | GPIO_PAR_CANI2C_I2C0SDA_MASK));
31545370e18SAlison Wang 		setbits_8(&gpio->par_cani2c,
31645370e18SAlison Wang 			GPIO_PAR_CANI2C_I2C0SCL_U8TXD | GPIO_PAR_CANI2C_I2C0SDA_U8RXD);
31745370e18SAlison Wang 		break;
31845370e18SAlison Wang 	case 9:
31945370e18SAlison Wang 		/* UART9 */
32045370e18SAlison Wang 		out_8(&pm->pmcr1, 29);
32145370e18SAlison Wang 		clrbits_8(&gpio->par_cani2c,
32245370e18SAlison Wang 			~(GPIO_PAR_CANI2C_CAN1TX_MASK | GPIO_PAR_CANI2C_CAN1RX_MASK));
32345370e18SAlison Wang 		setbits_8(&gpio->par_cani2c,
32445370e18SAlison Wang 			GPIO_PAR_CANI2C_CAN1TX_U9TXD | GPIO_PAR_CANI2C_CAN1RX_U9RXD);
32545370e18SAlison Wang 		break;
32645370e18SAlison Wang #endif
32745370e18SAlison Wang #ifdef CONFIG_MCF5445x
328a4145534SPeter Tyser 	case 0:
329198cafbfSAlison Wang 		clrbits_8(&gpio->par_uart,
330198cafbfSAlison Wang 			GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
331198cafbfSAlison Wang 		setbits_8(&gpio->par_uart,
332198cafbfSAlison Wang 			GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
333a4145534SPeter Tyser 		break;
334a4145534SPeter Tyser 	case 1:
335a4145534SPeter Tyser #ifdef CONFIG_SYS_UART1_PRI_GPIO
336198cafbfSAlison Wang 		clrbits_8(&gpio->par_uart,
337198cafbfSAlison Wang 			GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
338198cafbfSAlison Wang 		setbits_8(&gpio->par_uart,
339198cafbfSAlison Wang 			GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
340a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
341198cafbfSAlison Wang 		clrbits_be16(&gpio->par_ssi,
342198cafbfSAlison Wang 			~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
343198cafbfSAlison Wang 		setbits_be16(&gpio->par_ssi,
344198cafbfSAlison Wang 			GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
345a4145534SPeter Tyser #endif
346a4145534SPeter Tyser 		break;
347a4145534SPeter Tyser 	case 2:
348a4145534SPeter Tyser #if defined(CONFIG_SYS_UART2_ALT1_GPIO)
349198cafbfSAlison Wang 		clrbits_8(&gpio->par_timer,
350198cafbfSAlison Wang 			~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
351198cafbfSAlison Wang 		setbits_8(&gpio->par_timer,
352198cafbfSAlison Wang 			GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
353a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
354198cafbfSAlison Wang 		clrbits_8(&gpio->par_timer,
355198cafbfSAlison Wang 			~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
356198cafbfSAlison Wang 		setbits_8(&gpio->par_timer,
357198cafbfSAlison Wang 			GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
358a4145534SPeter Tyser #endif
359a4145534SPeter Tyser 		break;
36045370e18SAlison Wang #endif	/* CONFIG_MCF5445x */
361a4145534SPeter Tyser 	}
362a4145534SPeter Tyser }
363a4145534SPeter Tyser 
364a4145534SPeter Tyser #if defined(CONFIG_CMD_NET)
365a4145534SPeter Tyser int fecpin_setclear(struct eth_device *dev, int setclear)
366a4145534SPeter Tyser {
367198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
3685744e534SMasahiro Yamada #ifdef CONFIG_MCF5445x
369a4145534SPeter Tyser 	struct fec_info_s *info = (struct fec_info_s *)dev->priv;
370a4145534SPeter Tyser 
371a4145534SPeter Tyser 	if (setclear) {
372ae490997SWolfgang Wegner #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
373ae490997SWolfgang Wegner 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
374198cafbfSAlison Wang 			setbits_be16(&gpio->par_feci2c,
375198cafbfSAlison Wang 				GPIO_PAR_FECI2C_MDC0_MDC0 |
376ae490997SWolfgang Wegner 				GPIO_PAR_FECI2C_MDIO0_MDIO0);
377ae490997SWolfgang Wegner 		else
378198cafbfSAlison Wang 			setbits_be16(&gpio->par_feci2c,
379198cafbfSAlison Wang 				GPIO_PAR_FECI2C_MDC1_MDC1 |
380ae490997SWolfgang Wegner 				GPIO_PAR_FECI2C_MDIO1_MDIO1);
381ae490997SWolfgang Wegner #else
382198cafbfSAlison Wang 		setbits_be16(&gpio->par_feci2c,
383198cafbfSAlison Wang 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
384ae490997SWolfgang Wegner #endif
385a4145534SPeter Tyser 
386a4145534SPeter Tyser 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
387198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
388a4145534SPeter Tyser 		else
389198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
390a4145534SPeter Tyser 	} else {
391198cafbfSAlison Wang 		clrbits_be16(&gpio->par_feci2c,
392198cafbfSAlison Wang 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
393a4145534SPeter Tyser 
394adf55679SWolfgang Wegner 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
395adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII
396198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
397adf55679SWolfgang Wegner #else
398198cafbfSAlison Wang 			clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
399adf55679SWolfgang Wegner #endif
400adf55679SWolfgang Wegner 		} else {
401adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII
402198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
403adf55679SWolfgang Wegner #else
404198cafbfSAlison Wang 			clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
405adf55679SWolfgang Wegner #endif
406adf55679SWolfgang Wegner 		}
407a4145534SPeter Tyser 	}
40845370e18SAlison Wang #endif	/* CONFIG_MCF5445x */
40945370e18SAlison Wang 
41045370e18SAlison Wang #ifdef CONFIG_MCF5441x
41145370e18SAlison Wang 	if (setclear) {
41245370e18SAlison Wang 		out_8(&gpio->par_fec, 0x03);
41345370e18SAlison Wang 		out_8(&gpio->srcr_fec, 0x0F);
41445370e18SAlison Wang 		clrsetbits_8(&gpio->par_simp0h, ~GPIO_PAR_SIMP0H_DAT_MASK,
41545370e18SAlison Wang 			GPIO_PAR_SIMP0H_DAT_GPIO);
41645370e18SAlison Wang 		clrsetbits_8(&gpio->pddr_g, ~GPIO_PDDR_G4_MASK,
41745370e18SAlison Wang 			GPIO_PDDR_G4_OUTPUT);
41845370e18SAlison Wang 		clrbits_8(&gpio->podr_g, ~GPIO_PODR_G4_MASK);
41945370e18SAlison Wang 
42045370e18SAlison Wang 	} else
42145370e18SAlison Wang 		clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC_MASK);
42245370e18SAlison Wang #endif
423a4145534SPeter Tyser 	return 0;
424a4145534SPeter Tyser }
425a4145534SPeter Tyser #endif
426a4145534SPeter Tyser 
427a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI
428a4145534SPeter Tyser void cfspi_port_conf(void)
429a4145534SPeter Tyser {
430198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
431a4145534SPeter Tyser 
43245370e18SAlison Wang #ifdef CONFIG_MCF5445x
433198cafbfSAlison Wang 	out_8(&gpio->par_dspi,
434198cafbfSAlison Wang 		GPIO_PAR_DSPI_SIN_SIN |
435198cafbfSAlison Wang 		GPIO_PAR_DSPI_SOUT_SOUT |
436198cafbfSAlison Wang 		GPIO_PAR_DSPI_SCK_SCK);
43745370e18SAlison Wang #endif
43845370e18SAlison Wang 
43945370e18SAlison Wang #ifdef CONFIG_MCF5441x
44045370e18SAlison Wang 	pm_t *pm = (pm_t *) MMAP_PM;
44145370e18SAlison Wang 
44245370e18SAlison Wang 	out_8(&gpio->par_dspi0,
44345370e18SAlison Wang 		GPIO_PAR_DSPI0_SIN_DSPI0SIN | GPIO_PAR_DSPI0_SOUT_DSPI0SOUT |
44445370e18SAlison Wang 		GPIO_PAR_DSPI0_SCK_DSPI0SCK);
44545370e18SAlison Wang 	out_8(&gpio->srcr_dspiow, 3);
44645370e18SAlison Wang 
44745370e18SAlison Wang 	/* DSPI0 */
44845370e18SAlison Wang 	out_8(&pm->pmcr0, 23);
44945370e18SAlison Wang #endif
450a4145534SPeter Tyser }
451a4145534SPeter Tyser 
452a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs)
453a4145534SPeter Tyser {
454198cafbfSAlison Wang 	dspi_t *dspi = (dspi_t *) MMAP_DSPI;
455198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
456a4145534SPeter Tyser 
457198cafbfSAlison Wang 	if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
458a4145534SPeter Tyser 		return -1;
459a4145534SPeter Tyser 
460a4145534SPeter Tyser 	/* Clear FIFO and resume transfer */
461198cafbfSAlison Wang 	clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
462a4145534SPeter Tyser 
46345370e18SAlison Wang #ifdef CONFIG_MCF5445x
464a4145534SPeter Tyser 	switch (cs) {
465a4145534SPeter Tyser 	case 0:
466198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
467198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
468a4145534SPeter Tyser 		break;
469a4145534SPeter Tyser 	case 1:
470198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
471198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
472a4145534SPeter Tyser 		break;
473a4145534SPeter Tyser 	case 2:
474198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
475198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
476a4145534SPeter Tyser 		break;
477e9b43caeSWolfgang Wegner 	case 3:
478198cafbfSAlison Wang 		clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
479198cafbfSAlison Wang 		setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3);
480e9b43caeSWolfgang Wegner 		break;
481a4145534SPeter Tyser 	case 5:
482198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
483198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
484a4145534SPeter Tyser 		break;
485a4145534SPeter Tyser 	}
48645370e18SAlison Wang #endif
48745370e18SAlison Wang 
48845370e18SAlison Wang #ifdef CONFIG_MCF5441x
48945370e18SAlison Wang 	switch (cs) {
49045370e18SAlison Wang 	case 0:
49145370e18SAlison Wang 		clrbits_8(&gpio->par_dspi0, ~GPIO_PAR_DSPI0_PCS0_MASK);
49245370e18SAlison Wang 		setbits_8(&gpio->par_dspi0, GPIO_PAR_DSPI0_PCS0_DSPI0PCS0);
49345370e18SAlison Wang 		break;
49445370e18SAlison Wang 	case 1:
49545370e18SAlison Wang 		clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
49645370e18SAlison Wang 		setbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
49745370e18SAlison Wang 		break;
49845370e18SAlison Wang 	}
49945370e18SAlison Wang #endif
500a4145534SPeter Tyser 
501a4145534SPeter Tyser 	return 0;
502a4145534SPeter Tyser }
503a4145534SPeter Tyser 
504a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs)
505a4145534SPeter Tyser {
506198cafbfSAlison Wang 	dspi_t *dspi = (dspi_t *) MMAP_DSPI;
507198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
508a4145534SPeter Tyser 
509198cafbfSAlison Wang 	/* Clear FIFO */
510198cafbfSAlison Wang 	clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
511a4145534SPeter Tyser 
51245370e18SAlison Wang #ifdef CONFIG_MCF5445x
513a4145534SPeter Tyser 	switch (cs) {
514a4145534SPeter Tyser 	case 0:
515198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
516a4145534SPeter Tyser 		break;
517a4145534SPeter Tyser 	case 1:
518198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
519a4145534SPeter Tyser 		break;
520a4145534SPeter Tyser 	case 2:
521198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
522a4145534SPeter Tyser 		break;
523e9b43caeSWolfgang Wegner 	case 3:
524198cafbfSAlison Wang 		clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
525e9b43caeSWolfgang Wegner 		break;
526a4145534SPeter Tyser 	case 5:
527198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
528a4145534SPeter Tyser 		break;
529a4145534SPeter Tyser 	}
53045370e18SAlison Wang #endif
53145370e18SAlison Wang 
53245370e18SAlison Wang #ifdef CONFIG_MCF5441x
53345370e18SAlison Wang 	if (cs == 1)
53445370e18SAlison Wang 		clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
53545370e18SAlison Wang #endif
536a4145534SPeter Tyser }
537a4145534SPeter Tyser #endif
538