xref: /openbmc/u-boot/arch/m68k/cpu/mcf5445x/cpu_init.c (revision 0eee446ee811ea3ebbade82cb1d19558736e5603)
183d290c5STom 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 
init_fbcs(void)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  */
cpu_init_f(void)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);
176*2c92e4fbSAngelo Dureghello 
177*2c92e4fbSAngelo Dureghello #ifdef CONFIG_FSL_ESDHC
178*2c92e4fbSAngelo Dureghello 	/* eSDHC pin as faster speed */
179*2c92e4fbSAngelo Dureghello 	out_8(&gpio->srcr_sdhc, 0x03);
180*2c92e4fbSAngelo Dureghello 
181*2c92e4fbSAngelo Dureghello 	/* All esdhc pins as SD */
182*2c92e4fbSAngelo Dureghello 	out_8(&gpio->par_sdhch, 0xff);
183*2c92e4fbSAngelo Dureghello 	out_8(&gpio->par_sdhcl, 0xff);
184*2c92e4fbSAngelo Dureghello #endif
18545370e18SAlison Wang #endif		/* CONFIG_MCF5441x */
18645370e18SAlison Wang 
18745370e18SAlison Wang #ifdef CONFIG_MCF5445x
18845370e18SAlison Wang 	scm1_t *scm1 = (scm1_t *) MMAP_SCM1;
18945370e18SAlison Wang 
19045370e18SAlison Wang 	out_be32(&scm1->mpr, 0x77777777);
19145370e18SAlison Wang 	out_be32(&scm1->pacra, 0);
19245370e18SAlison Wang 	out_be32(&scm1->pacrb, 0);
19345370e18SAlison Wang 	out_be32(&scm1->pacrc, 0);
19445370e18SAlison Wang 	out_be32(&scm1->pacrd, 0);
19545370e18SAlison Wang 	out_be32(&scm1->pacre, 0);
19645370e18SAlison Wang 	out_be32(&scm1->pacrf, 0);
19745370e18SAlison Wang 	out_be32(&scm1->pacrg, 0);
19845370e18SAlison Wang 
19945370e18SAlison Wang 	/* FlexBus */
20045370e18SAlison Wang 	out_8(&gpio->par_be,
20145370e18SAlison Wang 		GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 |
20245370e18SAlison Wang 		GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0);
20345370e18SAlison Wang 	out_8(&gpio->par_fbctl,
20445370e18SAlison Wang 		GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA |
20545370e18SAlison Wang 		GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS);
20645370e18SAlison Wang 
20700f792e0SHeiko Schocher #ifdef CONFIG_SYS_FSL_I2C
20845370e18SAlison Wang 	out_be16(&gpio->par_feci2c,
20945370e18SAlison Wang 		GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA);
21045370e18SAlison Wang #endif
21145370e18SAlison Wang #endif		/* CONFIG_MCF5445x */
21245370e18SAlison Wang 
21345370e18SAlison Wang 	/* FlexBus Chipselect */
21445370e18SAlison Wang 	init_fbcs();
215a4145534SPeter Tyser 
21602a6eddaSAngelo Dureghello #ifdef CONFIG_SYS_CS0_BASE
217a4145534SPeter Tyser 	/*
218a4145534SPeter Tyser 	 * now the flash base address is no longer at 0 (Newer ColdFire family
219a4145534SPeter Tyser 	 * boot at address 0 instead of 0xFFnn_nnnn). The vector table must
220a4145534SPeter Tyser 	 * also move to the new location.
221a4145534SPeter Tyser 	 */
222a4145534SPeter Tyser 	if (CONFIG_SYS_CS0_BASE != 0)
223a4145534SPeter Tyser 		setvbr(CONFIG_SYS_CS0_BASE);
22402a6eddaSAngelo Dureghello #endif
225a4145534SPeter Tyser 
226a4145534SPeter Tyser 	icache_enable();
227a4145534SPeter Tyser }
228a4145534SPeter Tyser 
229a4145534SPeter Tyser /*
230a4145534SPeter Tyser  * initialize higher level parts of CPU like timers
231a4145534SPeter Tyser  */
cpu_init_r(void)232a4145534SPeter Tyser int cpu_init_r(void)
233a4145534SPeter Tyser {
234a4145534SPeter Tyser #ifdef CONFIG_MCFRTC
235198cafbfSAlison Wang 	rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE);
236198cafbfSAlison Wang 	rtcex_t *rtcex = (rtcex_t *)&rtc->extended;
237a4145534SPeter Tyser 
238198cafbfSAlison Wang 	out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff);
239198cafbfSAlison Wang 	out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff);
240a4145534SPeter Tyser #endif
241a4145534SPeter Tyser 
242a4145534SPeter Tyser 	return (0);
243a4145534SPeter Tyser }
244a4145534SPeter Tyser 
uart_port_conf(int port)245a4145534SPeter Tyser void uart_port_conf(int port)
246a4145534SPeter Tyser {
247198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
24845370e18SAlison Wang #ifdef CONFIG_MCF5441x
24945370e18SAlison Wang 	pm_t *pm = (pm_t *) MMAP_PM;
25045370e18SAlison Wang #endif
251a4145534SPeter Tyser 
252a4145534SPeter Tyser 	/* Setup Ports: */
253a4145534SPeter Tyser 	switch (port) {
25445370e18SAlison Wang #ifdef CONFIG_MCF5441x
25545370e18SAlison Wang 	case 0:
25645370e18SAlison Wang 		/* UART0 */
25745370e18SAlison Wang 		out_8(&pm->pmcr0, 24);
25845370e18SAlison Wang 		clrbits_8(&gpio->par_uart0,
25945370e18SAlison Wang 			~(GPIO_PAR_UART0_U0RXD_MASK | GPIO_PAR_UART0_U0TXD_MASK));
26045370e18SAlison Wang 		setbits_8(&gpio->par_uart0,
26145370e18SAlison Wang 			GPIO_PAR_UART0_U0RXD_U0RXD | GPIO_PAR_UART0_U0TXD_U0TXD);
26245370e18SAlison Wang 		break;
26345370e18SAlison Wang 	case 1:
26445370e18SAlison Wang 		/* UART1 */
26545370e18SAlison Wang 		out_8(&pm->pmcr0, 25);
26645370e18SAlison Wang 		clrbits_8(&gpio->par_uart1,
26745370e18SAlison Wang 			~(GPIO_PAR_UART1_U1RXD_MASK | GPIO_PAR_UART1_U1TXD_MASK));
26845370e18SAlison Wang 		setbits_8(&gpio->par_uart1,
26945370e18SAlison Wang 			GPIO_PAR_UART1_U1RXD_U1RXD | GPIO_PAR_UART1_U1TXD_U1TXD);
27045370e18SAlison Wang 		break;
27145370e18SAlison Wang 	case 2:
27245370e18SAlison Wang 		/* UART2 */
27345370e18SAlison Wang 		out_8(&pm->pmcr0, 26);
27445370e18SAlison Wang 		clrbits_8(&gpio->par_uart2,
27545370e18SAlison Wang 			~(GPIO_PAR_UART2_U2RXD_MASK | GPIO_PAR_UART2_U2TXD_MASK));
27645370e18SAlison Wang 		setbits_8(&gpio->par_uart2,
27745370e18SAlison Wang 			GPIO_PAR_UART2_U2RXD_U2RXD | GPIO_PAR_UART2_U2TXD_U2TXD);
27845370e18SAlison Wang 		break;
27945370e18SAlison Wang 	case 3:
28045370e18SAlison Wang 		/* UART3 */
28145370e18SAlison Wang 		out_8(&pm->pmcr0, 27);
28245370e18SAlison Wang 		clrbits_8(&gpio->par_dspi0,
28345370e18SAlison Wang 			~(GPIO_PAR_DSPI0_SIN_MASK | GPIO_PAR_DSPI0_SOUT_MASK));
28445370e18SAlison Wang 		setbits_8(&gpio->par_dspi0,
28545370e18SAlison Wang 			GPIO_PAR_DSPI0_SIN_U3RXD | GPIO_PAR_DSPI0_SOUT_U3TXD);
28645370e18SAlison Wang 		break;
28745370e18SAlison Wang 	case 4:
28845370e18SAlison Wang 		/* UART4 */
28945370e18SAlison Wang 		out_8(&pm->pmcr1, 24);
29045370e18SAlison Wang 		clrbits_8(&gpio->par_uart0,
29145370e18SAlison Wang 			~(GPIO_PAR_UART0_U0CTS_MASK | GPIO_PAR_UART0_U0RTS_MASK));
29245370e18SAlison Wang 		setbits_8(&gpio->par_uart0,
29345370e18SAlison Wang 			GPIO_PAR_UART0_U0CTS_U4TXD | GPIO_PAR_UART0_U0RTS_U4RXD);
29445370e18SAlison Wang 		break;
29545370e18SAlison Wang 	case 5:
29645370e18SAlison Wang 		/* UART5 */
29745370e18SAlison Wang 		out_8(&pm->pmcr1, 25);
29845370e18SAlison Wang 		clrbits_8(&gpio->par_uart1,
29945370e18SAlison Wang 			~(GPIO_PAR_UART1_U1CTS_MASK | GPIO_PAR_UART1_U1RTS_MASK));
30045370e18SAlison Wang 		setbits_8(&gpio->par_uart1,
30145370e18SAlison Wang 			GPIO_PAR_UART1_U1CTS_U5TXD | GPIO_PAR_UART1_U1RTS_U5RXD);
30245370e18SAlison Wang 		break;
30345370e18SAlison Wang 	case 6:
30445370e18SAlison Wang 		/* UART6 */
30545370e18SAlison Wang 		out_8(&pm->pmcr1, 26);
30645370e18SAlison Wang 		clrbits_8(&gpio->par_uart2,
30745370e18SAlison Wang 			~(GPIO_PAR_UART2_U2CTS_MASK | GPIO_PAR_UART2_U2RTS_MASK));
30845370e18SAlison Wang 		setbits_8(&gpio->par_uart2,
30945370e18SAlison Wang 			GPIO_PAR_UART2_U2CTS_U6TXD | GPIO_PAR_UART2_U2RTS_U6RXD);
31045370e18SAlison Wang 		break;
31145370e18SAlison Wang 	case 7:
31245370e18SAlison Wang 		/* UART7 */
31345370e18SAlison Wang 		out_8(&pm->pmcr1, 27);
31445370e18SAlison Wang 		clrbits_8(&gpio->par_ssi0h, ~GPIO_PAR_SSI0H_RXD_MASK);
31545370e18SAlison Wang 		clrbits_8(&gpio->par_ssi0l, ~GPIO_PAR_SSI0L_BCLK_MASK);
31645370e18SAlison Wang 		setbits_8(&gpio->par_ssi0h, GPIO_PAR_SSI0H_FS_U7TXD);
31745370e18SAlison Wang 		setbits_8(&gpio->par_ssi0l, GPIO_PAR_SSI0L_BCLK_U7RXD);
31845370e18SAlison Wang 		break;
31945370e18SAlison Wang 	case 8:
32045370e18SAlison Wang 		/* UART8 */
32145370e18SAlison Wang 		out_8(&pm->pmcr0, 28);
32245370e18SAlison Wang 		clrbits_8(&gpio->par_cani2c,
32345370e18SAlison Wang 			~(GPIO_PAR_CANI2C_I2C0SCL_MASK | GPIO_PAR_CANI2C_I2C0SDA_MASK));
32445370e18SAlison Wang 		setbits_8(&gpio->par_cani2c,
32545370e18SAlison Wang 			GPIO_PAR_CANI2C_I2C0SCL_U8TXD | GPIO_PAR_CANI2C_I2C0SDA_U8RXD);
32645370e18SAlison Wang 		break;
32745370e18SAlison Wang 	case 9:
32845370e18SAlison Wang 		/* UART9 */
32945370e18SAlison Wang 		out_8(&pm->pmcr1, 29);
33045370e18SAlison Wang 		clrbits_8(&gpio->par_cani2c,
33145370e18SAlison Wang 			~(GPIO_PAR_CANI2C_CAN1TX_MASK | GPIO_PAR_CANI2C_CAN1RX_MASK));
33245370e18SAlison Wang 		setbits_8(&gpio->par_cani2c,
33345370e18SAlison Wang 			GPIO_PAR_CANI2C_CAN1TX_U9TXD | GPIO_PAR_CANI2C_CAN1RX_U9RXD);
33445370e18SAlison Wang 		break;
33545370e18SAlison Wang #endif
33645370e18SAlison Wang #ifdef CONFIG_MCF5445x
337a4145534SPeter Tyser 	case 0:
338198cafbfSAlison Wang 		clrbits_8(&gpio->par_uart,
339198cafbfSAlison Wang 			GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
340198cafbfSAlison Wang 		setbits_8(&gpio->par_uart,
341198cafbfSAlison Wang 			GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD);
342a4145534SPeter Tyser 		break;
343a4145534SPeter Tyser 	case 1:
344a4145534SPeter Tyser #ifdef CONFIG_SYS_UART1_PRI_GPIO
345198cafbfSAlison Wang 		clrbits_8(&gpio->par_uart,
346198cafbfSAlison Wang 			GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
347198cafbfSAlison Wang 		setbits_8(&gpio->par_uart,
348198cafbfSAlison Wang 			GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD);
349a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART1_ALT1_GPIO)
350198cafbfSAlison Wang 		clrbits_be16(&gpio->par_ssi,
351198cafbfSAlison Wang 			~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK));
352198cafbfSAlison Wang 		setbits_be16(&gpio->par_ssi,
353198cafbfSAlison Wang 			GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD);
354a4145534SPeter Tyser #endif
355a4145534SPeter Tyser 		break;
356a4145534SPeter Tyser 	case 2:
357a4145534SPeter Tyser #if defined(CONFIG_SYS_UART2_ALT1_GPIO)
358198cafbfSAlison Wang 		clrbits_8(&gpio->par_timer,
359198cafbfSAlison Wang 			~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK));
360198cafbfSAlison Wang 		setbits_8(&gpio->par_timer,
361198cafbfSAlison Wang 			GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD);
362a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART2_ALT2_GPIO)
363198cafbfSAlison Wang 		clrbits_8(&gpio->par_timer,
364198cafbfSAlison Wang 			~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK));
365198cafbfSAlison Wang 		setbits_8(&gpio->par_timer,
366198cafbfSAlison Wang 			GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD);
367a4145534SPeter Tyser #endif
368a4145534SPeter Tyser 		break;
36945370e18SAlison Wang #endif	/* CONFIG_MCF5445x */
370a4145534SPeter Tyser 	}
371a4145534SPeter Tyser }
372a4145534SPeter Tyser 
373a4145534SPeter Tyser #if defined(CONFIG_CMD_NET)
fecpin_setclear(struct eth_device * dev,int setclear)374a4145534SPeter Tyser int fecpin_setclear(struct eth_device *dev, int setclear)
375a4145534SPeter Tyser {
376198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
3775744e534SMasahiro Yamada #ifdef CONFIG_MCF5445x
378a4145534SPeter Tyser 	struct fec_info_s *info = (struct fec_info_s *)dev->priv;
379a4145534SPeter Tyser 
380a4145534SPeter Tyser 	if (setclear) {
381ae490997SWolfgang Wegner #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY
382ae490997SWolfgang Wegner 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
383198cafbfSAlison Wang 			setbits_be16(&gpio->par_feci2c,
384198cafbfSAlison Wang 				GPIO_PAR_FECI2C_MDC0_MDC0 |
385ae490997SWolfgang Wegner 				GPIO_PAR_FECI2C_MDIO0_MDIO0);
386ae490997SWolfgang Wegner 		else
387198cafbfSAlison Wang 			setbits_be16(&gpio->par_feci2c,
388198cafbfSAlison Wang 				GPIO_PAR_FECI2C_MDC1_MDC1 |
389ae490997SWolfgang Wegner 				GPIO_PAR_FECI2C_MDIO1_MDIO1);
390ae490997SWolfgang Wegner #else
391198cafbfSAlison Wang 		setbits_be16(&gpio->par_feci2c,
392198cafbfSAlison Wang 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
393ae490997SWolfgang Wegner #endif
394a4145534SPeter Tyser 
395a4145534SPeter Tyser 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE)
396198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO);
397a4145534SPeter Tyser 		else
398198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA);
399a4145534SPeter Tyser 	} else {
400198cafbfSAlison Wang 		clrbits_be16(&gpio->par_feci2c,
401198cafbfSAlison Wang 			GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0);
402a4145534SPeter Tyser 
403adf55679SWolfgang Wegner 		if (info->iobase == CONFIG_SYS_FEC0_IOBASE) {
404adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII
405198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII);
406adf55679SWolfgang Wegner #else
407198cafbfSAlison Wang 			clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK);
408adf55679SWolfgang Wegner #endif
409adf55679SWolfgang Wegner 		} else {
410adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII
411198cafbfSAlison Wang 			setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII);
412adf55679SWolfgang Wegner #else
413198cafbfSAlison Wang 			clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK);
414adf55679SWolfgang Wegner #endif
415adf55679SWolfgang Wegner 		}
416a4145534SPeter Tyser 	}
41745370e18SAlison Wang #endif	/* CONFIG_MCF5445x */
41845370e18SAlison Wang 
41945370e18SAlison Wang #ifdef CONFIG_MCF5441x
42045370e18SAlison Wang 	if (setclear) {
42145370e18SAlison Wang 		out_8(&gpio->par_fec, 0x03);
42245370e18SAlison Wang 		out_8(&gpio->srcr_fec, 0x0F);
42345370e18SAlison Wang 		clrsetbits_8(&gpio->par_simp0h, ~GPIO_PAR_SIMP0H_DAT_MASK,
42445370e18SAlison Wang 			GPIO_PAR_SIMP0H_DAT_GPIO);
42545370e18SAlison Wang 		clrsetbits_8(&gpio->pddr_g, ~GPIO_PDDR_G4_MASK,
42645370e18SAlison Wang 			GPIO_PDDR_G4_OUTPUT);
42745370e18SAlison Wang 		clrbits_8(&gpio->podr_g, ~GPIO_PODR_G4_MASK);
42845370e18SAlison Wang 
42945370e18SAlison Wang 	} else
43045370e18SAlison Wang 		clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC_MASK);
43145370e18SAlison Wang #endif
432a4145534SPeter Tyser 	return 0;
433a4145534SPeter Tyser }
434a4145534SPeter Tyser #endif
435a4145534SPeter Tyser 
436a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI
cfspi_port_conf(void)437a4145534SPeter Tyser void cfspi_port_conf(void)
438a4145534SPeter Tyser {
439198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
440a4145534SPeter Tyser 
44145370e18SAlison Wang #ifdef CONFIG_MCF5445x
442198cafbfSAlison Wang 	out_8(&gpio->par_dspi,
443198cafbfSAlison Wang 		GPIO_PAR_DSPI_SIN_SIN |
444198cafbfSAlison Wang 		GPIO_PAR_DSPI_SOUT_SOUT |
445198cafbfSAlison Wang 		GPIO_PAR_DSPI_SCK_SCK);
44645370e18SAlison Wang #endif
44745370e18SAlison Wang 
44845370e18SAlison Wang #ifdef CONFIG_MCF5441x
44945370e18SAlison Wang 	pm_t *pm = (pm_t *) MMAP_PM;
45045370e18SAlison Wang 
45145370e18SAlison Wang 	out_8(&gpio->par_dspi0,
45245370e18SAlison Wang 		GPIO_PAR_DSPI0_SIN_DSPI0SIN | GPIO_PAR_DSPI0_SOUT_DSPI0SOUT |
45345370e18SAlison Wang 		GPIO_PAR_DSPI0_SCK_DSPI0SCK);
45445370e18SAlison Wang 	out_8(&gpio->srcr_dspiow, 3);
45545370e18SAlison Wang 
45645370e18SAlison Wang 	/* DSPI0 */
45745370e18SAlison Wang 	out_8(&pm->pmcr0, 23);
45845370e18SAlison Wang #endif
459a4145534SPeter Tyser }
460a4145534SPeter Tyser 
cfspi_claim_bus(uint bus,uint cs)461a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs)
462a4145534SPeter Tyser {
463198cafbfSAlison Wang 	dspi_t *dspi = (dspi_t *) MMAP_DSPI;
464198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
465a4145534SPeter Tyser 
466198cafbfSAlison Wang 	if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS)
467a4145534SPeter Tyser 		return -1;
468a4145534SPeter Tyser 
469a4145534SPeter Tyser 	/* Clear FIFO and resume transfer */
470198cafbfSAlison Wang 	clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
471a4145534SPeter Tyser 
47245370e18SAlison Wang #ifdef CONFIG_MCF5445x
473a4145534SPeter Tyser 	switch (cs) {
474a4145534SPeter Tyser 	case 0:
475198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
476198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
477a4145534SPeter Tyser 		break;
478a4145534SPeter Tyser 	case 1:
479198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
480198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
481a4145534SPeter Tyser 		break;
482a4145534SPeter Tyser 	case 2:
483198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
484198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
485a4145534SPeter Tyser 		break;
486e9b43caeSWolfgang Wegner 	case 3:
487198cafbfSAlison Wang 		clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
488198cafbfSAlison Wang 		setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3);
489e9b43caeSWolfgang Wegner 		break;
490a4145534SPeter Tyser 	case 5:
491198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
492198cafbfSAlison Wang 		setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
493a4145534SPeter Tyser 		break;
494a4145534SPeter Tyser 	}
49545370e18SAlison Wang #endif
49645370e18SAlison Wang 
49745370e18SAlison Wang #ifdef CONFIG_MCF5441x
49845370e18SAlison Wang 	switch (cs) {
49945370e18SAlison Wang 	case 0:
50045370e18SAlison Wang 		clrbits_8(&gpio->par_dspi0, ~GPIO_PAR_DSPI0_PCS0_MASK);
50145370e18SAlison Wang 		setbits_8(&gpio->par_dspi0, GPIO_PAR_DSPI0_PCS0_DSPI0PCS0);
50245370e18SAlison Wang 		break;
50345370e18SAlison Wang 	case 1:
50445370e18SAlison Wang 		clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
50545370e18SAlison Wang 		setbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
50645370e18SAlison Wang 		break;
50745370e18SAlison Wang 	}
50845370e18SAlison Wang #endif
509a4145534SPeter Tyser 
510a4145534SPeter Tyser 	return 0;
511a4145534SPeter Tyser }
512a4145534SPeter Tyser 
cfspi_release_bus(uint bus,uint cs)513a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs)
514a4145534SPeter Tyser {
515198cafbfSAlison Wang 	dspi_t *dspi = (dspi_t *) MMAP_DSPI;
516198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
517a4145534SPeter Tyser 
518198cafbfSAlison Wang 	/* Clear FIFO */
519198cafbfSAlison Wang 	clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF);
520a4145534SPeter Tyser 
52145370e18SAlison Wang #ifdef CONFIG_MCF5445x
522a4145534SPeter Tyser 	switch (cs) {
523a4145534SPeter Tyser 	case 0:
524198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0);
525a4145534SPeter Tyser 		break;
526a4145534SPeter Tyser 	case 1:
527198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1);
528a4145534SPeter Tyser 		break;
529a4145534SPeter Tyser 	case 2:
530198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2);
531a4145534SPeter Tyser 		break;
532e9b43caeSWolfgang Wegner 	case 3:
533198cafbfSAlison Wang 		clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK);
534e9b43caeSWolfgang Wegner 		break;
535a4145534SPeter Tyser 	case 5:
536198cafbfSAlison Wang 		clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5);
537a4145534SPeter Tyser 		break;
538a4145534SPeter Tyser 	}
53945370e18SAlison Wang #endif
54045370e18SAlison Wang 
54145370e18SAlison Wang #ifdef CONFIG_MCF5441x
54245370e18SAlison Wang 	if (cs == 1)
54345370e18SAlison Wang 		clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1);
54445370e18SAlison Wang #endif
545a4145534SPeter Tyser }
546*2c92e4fbSAngelo Dureghello 
547a4145534SPeter Tyser #endif
548