1a4145534SPeter Tyser /* 2a4145534SPeter Tyser * 3a4145534SPeter Tyser * (C) Copyright 2000-2003 4a4145534SPeter Tyser * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 5a4145534SPeter Tyser * 6198cafbfSAlison Wang * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc. 7a4145534SPeter Tyser * TsiChung Liew (Tsi-Chung.Liew@freescale.com) 8a4145534SPeter Tyser * 91a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 10a4145534SPeter Tyser */ 11a4145534SPeter Tyser 12a4145534SPeter Tyser #include <common.h> 13a4145534SPeter Tyser #include <watchdog.h> 14a4145534SPeter Tyser #include <asm/immap.h> 15a4145534SPeter Tyser #include <asm/processor.h> 16a4145534SPeter Tyser #include <asm/rtc.h> 17198cafbfSAlison Wang #include <asm/io.h> 182b05593dSMarek Vasut #include <linux/compiler.h> 19a4145534SPeter Tyser 20a4145534SPeter Tyser #if defined(CONFIG_CMD_NET) 21a4145534SPeter Tyser #include <config.h> 22a4145534SPeter Tyser #include <net.h> 23a4145534SPeter Tyser #include <asm/fec.h> 24a4145534SPeter Tyser #endif 25a4145534SPeter Tyser 2645370e18SAlison Wang void init_fbcs(void) 27a4145534SPeter Tyser { 282b05593dSMarek Vasut fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS; 29a4145534SPeter Tyser 3045370e18SAlison Wang #if !defined(CONFIG_SERIAL_BOOT) 31a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) && defined(CONFIG_SYS_CS0_CTRL)) 32198cafbfSAlison Wang out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE); 33198cafbfSAlison Wang out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL); 34198cafbfSAlison Wang out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK); 35a4145534SPeter Tyser #endif 36a4145534SPeter Tyser #endif 37a4145534SPeter Tyser 38a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) && defined(CONFIG_SYS_CS1_CTRL)) 39a4145534SPeter Tyser /* Latch chipselect */ 40198cafbfSAlison Wang out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE); 41198cafbfSAlison Wang out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL); 42198cafbfSAlison Wang out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK); 43a4145534SPeter Tyser #endif 44a4145534SPeter Tyser 45a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) && defined(CONFIG_SYS_CS2_CTRL)) 46198cafbfSAlison Wang out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE); 47198cafbfSAlison Wang out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL); 48198cafbfSAlison Wang out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK); 49a4145534SPeter Tyser #endif 50a4145534SPeter Tyser 51a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) && defined(CONFIG_SYS_CS3_CTRL)) 52198cafbfSAlison Wang out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE); 53198cafbfSAlison Wang out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL); 54198cafbfSAlison Wang out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK); 55a4145534SPeter Tyser #endif 56a4145534SPeter Tyser 57a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) && defined(CONFIG_SYS_CS4_CTRL)) 58198cafbfSAlison Wang out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE); 59198cafbfSAlison Wang out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL); 60198cafbfSAlison Wang out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK); 61a4145534SPeter Tyser #endif 62a4145534SPeter Tyser 63a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) && defined(CONFIG_SYS_CS5_CTRL)) 64198cafbfSAlison Wang out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE); 65198cafbfSAlison Wang out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL); 66198cafbfSAlison Wang out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK); 67a4145534SPeter Tyser #endif 6845370e18SAlison Wang } 6945370e18SAlison Wang 7045370e18SAlison Wang /* 7145370e18SAlison Wang * Breath some life into the CPU... 7245370e18SAlison Wang * 7345370e18SAlison Wang * Set up the memory map, 7445370e18SAlison Wang * initialize a bunch of registers, 7545370e18SAlison Wang * initialize the UPM's 7645370e18SAlison Wang */ 7745370e18SAlison Wang void cpu_init_f(void) 7845370e18SAlison Wang { 7945370e18SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 8045370e18SAlison Wang 8145370e18SAlison Wang #ifdef CONFIG_MCF5441x 8245370e18SAlison Wang scm_t *scm = (scm_t *) MMAP_SCM; 8345370e18SAlison Wang pm_t *pm = (pm_t *) MMAP_PM; 8445370e18SAlison Wang 8545370e18SAlison Wang /* Disable Switch */ 8645370e18SAlison Wang *(unsigned long *)(MMAP_L2_SW0 + 0x00000024) = 0; 8745370e18SAlison Wang 8845370e18SAlison Wang /* Disable core watchdog */ 8945370e18SAlison Wang out_be16(&scm->cwcr, 0); 9045370e18SAlison Wang out_8(&gpio->par_fbctl, 9145370e18SAlison Wang GPIO_PAR_FBCTL_ALE_FB_ALE | GPIO_PAR_FBCTL_OE_FB_OE | 9245370e18SAlison Wang GPIO_PAR_FBCTL_FBCLK | GPIO_PAR_FBCTL_RW | 9345370e18SAlison Wang GPIO_PAR_FBCTL_TA_TA); 9445370e18SAlison Wang out_8(&gpio->par_be, 9545370e18SAlison Wang GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 | 9645370e18SAlison Wang GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0); 9745370e18SAlison Wang 9845370e18SAlison Wang /* eDMA */ 9945370e18SAlison Wang out_8(&pm->pmcr0, 17); 10045370e18SAlison Wang 10145370e18SAlison Wang /* INTR0 - INTR2 */ 10245370e18SAlison Wang out_8(&pm->pmcr0, 18); 10345370e18SAlison Wang out_8(&pm->pmcr0, 19); 10445370e18SAlison Wang out_8(&pm->pmcr0, 20); 10545370e18SAlison Wang 10645370e18SAlison Wang /* I2C */ 10745370e18SAlison Wang out_8(&pm->pmcr0, 22); 10845370e18SAlison Wang out_8(&pm->pmcr1, 4); 10945370e18SAlison Wang out_8(&pm->pmcr1, 7); 11045370e18SAlison Wang 11145370e18SAlison Wang /* DTMR0 - DTMR3*/ 11245370e18SAlison Wang out_8(&pm->pmcr0, 28); 11345370e18SAlison Wang out_8(&pm->pmcr0, 29); 11445370e18SAlison Wang out_8(&pm->pmcr0, 30); 11545370e18SAlison Wang out_8(&pm->pmcr0, 31); 11645370e18SAlison Wang 11745370e18SAlison Wang /* PIT0 - PIT3 */ 11845370e18SAlison Wang out_8(&pm->pmcr0, 32); 11945370e18SAlison Wang out_8(&pm->pmcr0, 33); 12045370e18SAlison Wang out_8(&pm->pmcr0, 34); 12145370e18SAlison Wang out_8(&pm->pmcr0, 35); 12245370e18SAlison Wang 12345370e18SAlison Wang /* Edge Port */ 12445370e18SAlison Wang out_8(&pm->pmcr0, 36); 12545370e18SAlison Wang out_8(&pm->pmcr0, 37); 12645370e18SAlison Wang 12745370e18SAlison Wang /* USB OTG */ 12845370e18SAlison Wang out_8(&pm->pmcr0, 44); 12945370e18SAlison Wang /* USB Host */ 13045370e18SAlison Wang out_8(&pm->pmcr0, 45); 13145370e18SAlison Wang 13245370e18SAlison Wang /* ESDHC */ 13345370e18SAlison Wang out_8(&pm->pmcr0, 51); 13445370e18SAlison Wang 13545370e18SAlison Wang /* ENET0 - ENET1 */ 13645370e18SAlison Wang out_8(&pm->pmcr0, 53); 13745370e18SAlison Wang out_8(&pm->pmcr0, 54); 13845370e18SAlison Wang 13945370e18SAlison Wang /* NAND */ 14045370e18SAlison Wang out_8(&pm->pmcr0, 63); 14145370e18SAlison Wang 14245370e18SAlison Wang #ifdef CONFIG_SYS_I2C_0 14345370e18SAlison Wang out_8(&gpio->par_cani2c, 0xF0); 14445370e18SAlison Wang /* I2C0 pull up */ 14545370e18SAlison Wang out_be16(&gpio->pcr_b, 0x003C); 14645370e18SAlison Wang /* I2C0 max speed */ 14745370e18SAlison Wang out_8(&gpio->srcr_cani2c, 0x03); 14845370e18SAlison Wang #endif 14945370e18SAlison Wang #ifdef CONFIG_SYS_I2C_2 15045370e18SAlison Wang /* I2C2 */ 15145370e18SAlison Wang out_8(&gpio->par_ssi0h, 0xA0); 15245370e18SAlison Wang /* I2C2, UART7 */ 15345370e18SAlison Wang out_8(&gpio->par_ssi0h, 0xA8); 15445370e18SAlison Wang /* UART7 */ 15545370e18SAlison Wang out_8(&gpio->par_ssi0l, 0x2); 15645370e18SAlison Wang /* UART8, UART9 */ 15745370e18SAlison Wang out_8(&gpio->par_cani2c, 0xAA); 15845370e18SAlison Wang /* UART4, UART0 */ 15945370e18SAlison Wang out_8(&gpio->par_uart0, 0xAF); 16045370e18SAlison Wang /* UART5, UART1 */ 16145370e18SAlison Wang out_8(&gpio->par_uart1, 0xAF); 16245370e18SAlison Wang /* UART6, UART2 */ 16345370e18SAlison Wang out_8(&gpio->par_uart2, 0xAF); 16445370e18SAlison Wang /* I2C2 pull up */ 16545370e18SAlison Wang out_be16(&gpio->pcr_h, 0xF000); 16645370e18SAlison Wang #endif 16745370e18SAlison Wang #ifdef CONFIG_SYS_I2C_5 16845370e18SAlison Wang /* I2C5 */ 16945370e18SAlison Wang out_8(&gpio->par_uart1, 0x0A); 17045370e18SAlison Wang /* I2C5 pull up */ 17145370e18SAlison Wang out_be16(&gpio->pcr_e, 0x0003); 17245370e18SAlison Wang out_be16(&gpio->pcr_f, 0xC000); 17345370e18SAlison Wang #endif 17445370e18SAlison Wang 17545370e18SAlison Wang /* Lowest slew rate for UART0,1,2 */ 17645370e18SAlison Wang out_8(&gpio->srcr_uart, 0x00); 17745370e18SAlison Wang #endif /* CONFIG_MCF5441x */ 17845370e18SAlison Wang 17945370e18SAlison Wang #ifdef CONFIG_MCF5445x 18045370e18SAlison Wang scm1_t *scm1 = (scm1_t *) MMAP_SCM1; 18145370e18SAlison Wang 18245370e18SAlison Wang out_be32(&scm1->mpr, 0x77777777); 18345370e18SAlison Wang out_be32(&scm1->pacra, 0); 18445370e18SAlison Wang out_be32(&scm1->pacrb, 0); 18545370e18SAlison Wang out_be32(&scm1->pacrc, 0); 18645370e18SAlison Wang out_be32(&scm1->pacrd, 0); 18745370e18SAlison Wang out_be32(&scm1->pacre, 0); 18845370e18SAlison Wang out_be32(&scm1->pacrf, 0); 18945370e18SAlison Wang out_be32(&scm1->pacrg, 0); 19045370e18SAlison Wang 19145370e18SAlison Wang /* FlexBus */ 19245370e18SAlison Wang out_8(&gpio->par_be, 19345370e18SAlison Wang GPIO_PAR_BE_BE3_BE3 | GPIO_PAR_BE_BE2_BE2 | 19445370e18SAlison Wang GPIO_PAR_BE_BE1_BE1 | GPIO_PAR_BE_BE0_BE0); 19545370e18SAlison Wang out_8(&gpio->par_fbctl, 19645370e18SAlison Wang GPIO_PAR_FBCTL_OE | GPIO_PAR_FBCTL_TA_TA | 19745370e18SAlison Wang GPIO_PAR_FBCTL_RW_RW | GPIO_PAR_FBCTL_TS_TS); 19845370e18SAlison Wang 19900f792e0SHeiko Schocher #ifdef CONFIG_SYS_FSL_I2C 20045370e18SAlison Wang out_be16(&gpio->par_feci2c, 20145370e18SAlison Wang GPIO_PAR_FECI2C_SCL_SCL | GPIO_PAR_FECI2C_SDA_SDA); 20245370e18SAlison Wang #endif 20345370e18SAlison Wang #endif /* CONFIG_MCF5445x */ 20445370e18SAlison Wang 20545370e18SAlison Wang /* FlexBus Chipselect */ 20645370e18SAlison Wang init_fbcs(); 207a4145534SPeter Tyser 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); 215a4145534SPeter Tyser 216a4145534SPeter Tyser icache_enable(); 217a4145534SPeter Tyser } 218a4145534SPeter Tyser 219a4145534SPeter Tyser /* 220a4145534SPeter Tyser * initialize higher level parts of CPU like timers 221a4145534SPeter Tyser */ 222a4145534SPeter Tyser int cpu_init_r(void) 223a4145534SPeter Tyser { 224a4145534SPeter Tyser #ifdef CONFIG_MCFRTC 225198cafbfSAlison Wang rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE); 226198cafbfSAlison Wang rtcex_t *rtcex = (rtcex_t *)&rtc->extended; 227a4145534SPeter Tyser 228198cafbfSAlison Wang out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff); 229198cafbfSAlison Wang out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff); 230a4145534SPeter Tyser #endif 231a4145534SPeter Tyser 232a4145534SPeter Tyser return (0); 233a4145534SPeter Tyser } 234a4145534SPeter Tyser 235a4145534SPeter Tyser void uart_port_conf(int port) 236a4145534SPeter Tyser { 237198cafbfSAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 23845370e18SAlison Wang #ifdef CONFIG_MCF5441x 23945370e18SAlison Wang pm_t *pm = (pm_t *) MMAP_PM; 24045370e18SAlison Wang #endif 241a4145534SPeter Tyser 242a4145534SPeter Tyser /* Setup Ports: */ 243a4145534SPeter Tyser switch (port) { 24445370e18SAlison Wang #ifdef CONFIG_MCF5441x 24545370e18SAlison Wang case 0: 24645370e18SAlison Wang /* UART0 */ 24745370e18SAlison Wang out_8(&pm->pmcr0, 24); 24845370e18SAlison Wang clrbits_8(&gpio->par_uart0, 24945370e18SAlison Wang ~(GPIO_PAR_UART0_U0RXD_MASK | GPIO_PAR_UART0_U0TXD_MASK)); 25045370e18SAlison Wang setbits_8(&gpio->par_uart0, 25145370e18SAlison Wang GPIO_PAR_UART0_U0RXD_U0RXD | GPIO_PAR_UART0_U0TXD_U0TXD); 25245370e18SAlison Wang break; 25345370e18SAlison Wang case 1: 25445370e18SAlison Wang /* UART1 */ 25545370e18SAlison Wang out_8(&pm->pmcr0, 25); 25645370e18SAlison Wang clrbits_8(&gpio->par_uart1, 25745370e18SAlison Wang ~(GPIO_PAR_UART1_U1RXD_MASK | GPIO_PAR_UART1_U1TXD_MASK)); 25845370e18SAlison Wang setbits_8(&gpio->par_uart1, 25945370e18SAlison Wang GPIO_PAR_UART1_U1RXD_U1RXD | GPIO_PAR_UART1_U1TXD_U1TXD); 26045370e18SAlison Wang break; 26145370e18SAlison Wang case 2: 26245370e18SAlison Wang /* UART2 */ 26345370e18SAlison Wang out_8(&pm->pmcr0, 26); 26445370e18SAlison Wang clrbits_8(&gpio->par_uart2, 26545370e18SAlison Wang ~(GPIO_PAR_UART2_U2RXD_MASK | GPIO_PAR_UART2_U2TXD_MASK)); 26645370e18SAlison Wang setbits_8(&gpio->par_uart2, 26745370e18SAlison Wang GPIO_PAR_UART2_U2RXD_U2RXD | GPIO_PAR_UART2_U2TXD_U2TXD); 26845370e18SAlison Wang break; 26945370e18SAlison Wang case 3: 27045370e18SAlison Wang /* UART3 */ 27145370e18SAlison Wang out_8(&pm->pmcr0, 27); 27245370e18SAlison Wang clrbits_8(&gpio->par_dspi0, 27345370e18SAlison Wang ~(GPIO_PAR_DSPI0_SIN_MASK | GPIO_PAR_DSPI0_SOUT_MASK)); 27445370e18SAlison Wang setbits_8(&gpio->par_dspi0, 27545370e18SAlison Wang GPIO_PAR_DSPI0_SIN_U3RXD | GPIO_PAR_DSPI0_SOUT_U3TXD); 27645370e18SAlison Wang break; 27745370e18SAlison Wang case 4: 27845370e18SAlison Wang /* UART4 */ 27945370e18SAlison Wang out_8(&pm->pmcr1, 24); 28045370e18SAlison Wang clrbits_8(&gpio->par_uart0, 28145370e18SAlison Wang ~(GPIO_PAR_UART0_U0CTS_MASK | GPIO_PAR_UART0_U0RTS_MASK)); 28245370e18SAlison Wang setbits_8(&gpio->par_uart0, 28345370e18SAlison Wang GPIO_PAR_UART0_U0CTS_U4TXD | GPIO_PAR_UART0_U0RTS_U4RXD); 28445370e18SAlison Wang break; 28545370e18SAlison Wang case 5: 28645370e18SAlison Wang /* UART5 */ 28745370e18SAlison Wang out_8(&pm->pmcr1, 25); 28845370e18SAlison Wang clrbits_8(&gpio->par_uart1, 28945370e18SAlison Wang ~(GPIO_PAR_UART1_U1CTS_MASK | GPIO_PAR_UART1_U1RTS_MASK)); 29045370e18SAlison Wang setbits_8(&gpio->par_uart1, 29145370e18SAlison Wang GPIO_PAR_UART1_U1CTS_U5TXD | GPIO_PAR_UART1_U1RTS_U5RXD); 29245370e18SAlison Wang break; 29345370e18SAlison Wang case 6: 29445370e18SAlison Wang /* UART6 */ 29545370e18SAlison Wang out_8(&pm->pmcr1, 26); 29645370e18SAlison Wang clrbits_8(&gpio->par_uart2, 29745370e18SAlison Wang ~(GPIO_PAR_UART2_U2CTS_MASK | GPIO_PAR_UART2_U2RTS_MASK)); 29845370e18SAlison Wang setbits_8(&gpio->par_uart2, 29945370e18SAlison Wang GPIO_PAR_UART2_U2CTS_U6TXD | GPIO_PAR_UART2_U2RTS_U6RXD); 30045370e18SAlison Wang break; 30145370e18SAlison Wang case 7: 30245370e18SAlison Wang /* UART7 */ 30345370e18SAlison Wang out_8(&pm->pmcr1, 27); 30445370e18SAlison Wang clrbits_8(&gpio->par_ssi0h, ~GPIO_PAR_SSI0H_RXD_MASK); 30545370e18SAlison Wang clrbits_8(&gpio->par_ssi0l, ~GPIO_PAR_SSI0L_BCLK_MASK); 30645370e18SAlison Wang setbits_8(&gpio->par_ssi0h, GPIO_PAR_SSI0H_FS_U7TXD); 30745370e18SAlison Wang setbits_8(&gpio->par_ssi0l, GPIO_PAR_SSI0L_BCLK_U7RXD); 30845370e18SAlison Wang break; 30945370e18SAlison Wang case 8: 31045370e18SAlison Wang /* UART8 */ 31145370e18SAlison Wang out_8(&pm->pmcr0, 28); 31245370e18SAlison Wang clrbits_8(&gpio->par_cani2c, 31345370e18SAlison Wang ~(GPIO_PAR_CANI2C_I2C0SCL_MASK | GPIO_PAR_CANI2C_I2C0SDA_MASK)); 31445370e18SAlison Wang setbits_8(&gpio->par_cani2c, 31545370e18SAlison Wang GPIO_PAR_CANI2C_I2C0SCL_U8TXD | GPIO_PAR_CANI2C_I2C0SDA_U8RXD); 31645370e18SAlison Wang break; 31745370e18SAlison Wang case 9: 31845370e18SAlison Wang /* UART9 */ 31945370e18SAlison Wang out_8(&pm->pmcr1, 29); 32045370e18SAlison Wang clrbits_8(&gpio->par_cani2c, 32145370e18SAlison Wang ~(GPIO_PAR_CANI2C_CAN1TX_MASK | GPIO_PAR_CANI2C_CAN1RX_MASK)); 32245370e18SAlison Wang setbits_8(&gpio->par_cani2c, 32345370e18SAlison Wang GPIO_PAR_CANI2C_CAN1TX_U9TXD | GPIO_PAR_CANI2C_CAN1RX_U9RXD); 32445370e18SAlison Wang break; 32545370e18SAlison Wang #endif 32645370e18SAlison Wang #ifdef CONFIG_MCF5445x 327a4145534SPeter Tyser case 0: 328198cafbfSAlison Wang clrbits_8(&gpio->par_uart, 329198cafbfSAlison Wang GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD); 330198cafbfSAlison Wang setbits_8(&gpio->par_uart, 331198cafbfSAlison Wang GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD); 332a4145534SPeter Tyser break; 333a4145534SPeter Tyser case 1: 334a4145534SPeter Tyser #ifdef CONFIG_SYS_UART1_PRI_GPIO 335198cafbfSAlison Wang clrbits_8(&gpio->par_uart, 336198cafbfSAlison Wang GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD); 337198cafbfSAlison Wang setbits_8(&gpio->par_uart, 338198cafbfSAlison Wang GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD); 339a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART1_ALT1_GPIO) 340198cafbfSAlison Wang clrbits_be16(&gpio->par_ssi, 341198cafbfSAlison Wang ~(GPIO_PAR_SSI_SRXD_UNMASK | GPIO_PAR_SSI_STXD_UNMASK)); 342198cafbfSAlison Wang setbits_be16(&gpio->par_ssi, 343198cafbfSAlison Wang GPIO_PAR_SSI_SRXD_U1RXD | GPIO_PAR_SSI_STXD_U1TXD); 344a4145534SPeter Tyser #endif 345a4145534SPeter Tyser break; 346a4145534SPeter Tyser case 2: 347a4145534SPeter Tyser #if defined(CONFIG_SYS_UART2_ALT1_GPIO) 348198cafbfSAlison Wang clrbits_8(&gpio->par_timer, 349198cafbfSAlison Wang ~(GPIO_PAR_TIMER_T3IN_UNMASK | GPIO_PAR_TIMER_T2IN_UNMASK)); 350198cafbfSAlison Wang setbits_8(&gpio->par_timer, 351198cafbfSAlison Wang GPIO_PAR_TIMER_T3IN_U2RXD | GPIO_PAR_TIMER_T2IN_U2TXD); 352a4145534SPeter Tyser #elif defined(CONFIG_SYS_UART2_ALT2_GPIO) 353198cafbfSAlison Wang clrbits_8(&gpio->par_timer, 354198cafbfSAlison Wang ~(GPIO_PAR_FECI2C_SCL_UNMASK | GPIO_PAR_FECI2C_SDA_UNMASK)); 355198cafbfSAlison Wang setbits_8(&gpio->par_timer, 356198cafbfSAlison Wang GPIO_PAR_FECI2C_SCL_U2TXD | GPIO_PAR_FECI2C_SDA_U2RXD); 357a4145534SPeter Tyser #endif 358a4145534SPeter Tyser break; 35945370e18SAlison Wang #endif /* CONFIG_MCF5445x */ 360a4145534SPeter Tyser } 361a4145534SPeter Tyser } 362a4145534SPeter Tyser 363a4145534SPeter Tyser #if defined(CONFIG_CMD_NET) 364a4145534SPeter Tyser int fecpin_setclear(struct eth_device *dev, int setclear) 365a4145534SPeter Tyser { 366198cafbfSAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 367*5744e534SMasahiro Yamada #ifdef CONFIG_MCF5445x 368a4145534SPeter Tyser struct fec_info_s *info = (struct fec_info_s *)dev->priv; 369a4145534SPeter Tyser 370a4145534SPeter Tyser if (setclear) { 371ae490997SWolfgang Wegner #ifdef CONFIG_SYS_FEC_NO_SHARED_PHY 372ae490997SWolfgang Wegner if (info->iobase == CONFIG_SYS_FEC0_IOBASE) 373198cafbfSAlison Wang setbits_be16(&gpio->par_feci2c, 374198cafbfSAlison Wang GPIO_PAR_FECI2C_MDC0_MDC0 | 375ae490997SWolfgang Wegner GPIO_PAR_FECI2C_MDIO0_MDIO0); 376ae490997SWolfgang Wegner else 377198cafbfSAlison Wang setbits_be16(&gpio->par_feci2c, 378198cafbfSAlison Wang GPIO_PAR_FECI2C_MDC1_MDC1 | 379ae490997SWolfgang Wegner GPIO_PAR_FECI2C_MDIO1_MDIO1); 380ae490997SWolfgang Wegner #else 381198cafbfSAlison Wang setbits_be16(&gpio->par_feci2c, 382198cafbfSAlison Wang GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0); 383ae490997SWolfgang Wegner #endif 384a4145534SPeter Tyser 385a4145534SPeter Tyser if (info->iobase == CONFIG_SYS_FEC0_IOBASE) 386198cafbfSAlison Wang setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_RMII_GPIO); 387a4145534SPeter Tyser else 388198cafbfSAlison Wang setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_RMII_ATA); 389a4145534SPeter Tyser } else { 390198cafbfSAlison Wang clrbits_be16(&gpio->par_feci2c, 391198cafbfSAlison Wang GPIO_PAR_FECI2C_MDC0_MDC0 | GPIO_PAR_FECI2C_MDIO0_MDIO0); 392a4145534SPeter Tyser 393adf55679SWolfgang Wegner if (info->iobase == CONFIG_SYS_FEC0_IOBASE) { 394adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII 395198cafbfSAlison Wang setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC0_MII); 396adf55679SWolfgang Wegner #else 397198cafbfSAlison Wang clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC0_UNMASK); 398adf55679SWolfgang Wegner #endif 399adf55679SWolfgang Wegner } else { 400adf55679SWolfgang Wegner #ifdef CONFIG_SYS_FEC_FULL_MII 401198cafbfSAlison Wang setbits_8(&gpio->par_fec, GPIO_PAR_FEC_FEC1_MII); 402adf55679SWolfgang Wegner #else 403198cafbfSAlison Wang clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC1_UNMASK); 404adf55679SWolfgang Wegner #endif 405adf55679SWolfgang Wegner } 406a4145534SPeter Tyser } 40745370e18SAlison Wang #endif /* CONFIG_MCF5445x */ 40845370e18SAlison Wang 40945370e18SAlison Wang #ifdef CONFIG_MCF5441x 41045370e18SAlison Wang if (setclear) { 41145370e18SAlison Wang out_8(&gpio->par_fec, 0x03); 41245370e18SAlison Wang out_8(&gpio->srcr_fec, 0x0F); 41345370e18SAlison Wang clrsetbits_8(&gpio->par_simp0h, ~GPIO_PAR_SIMP0H_DAT_MASK, 41445370e18SAlison Wang GPIO_PAR_SIMP0H_DAT_GPIO); 41545370e18SAlison Wang clrsetbits_8(&gpio->pddr_g, ~GPIO_PDDR_G4_MASK, 41645370e18SAlison Wang GPIO_PDDR_G4_OUTPUT); 41745370e18SAlison Wang clrbits_8(&gpio->podr_g, ~GPIO_PODR_G4_MASK); 41845370e18SAlison Wang 41945370e18SAlison Wang } else 42045370e18SAlison Wang clrbits_8(&gpio->par_fec, ~GPIO_PAR_FEC_FEC_MASK); 42145370e18SAlison Wang #endif 422a4145534SPeter Tyser return 0; 423a4145534SPeter Tyser } 424a4145534SPeter Tyser #endif 425a4145534SPeter Tyser 426a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI 427a4145534SPeter Tyser void cfspi_port_conf(void) 428a4145534SPeter Tyser { 429198cafbfSAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 430a4145534SPeter Tyser 43145370e18SAlison Wang #ifdef CONFIG_MCF5445x 432198cafbfSAlison Wang out_8(&gpio->par_dspi, 433198cafbfSAlison Wang GPIO_PAR_DSPI_SIN_SIN | 434198cafbfSAlison Wang GPIO_PAR_DSPI_SOUT_SOUT | 435198cafbfSAlison Wang GPIO_PAR_DSPI_SCK_SCK); 43645370e18SAlison Wang #endif 43745370e18SAlison Wang 43845370e18SAlison Wang #ifdef CONFIG_MCF5441x 43945370e18SAlison Wang pm_t *pm = (pm_t *) MMAP_PM; 44045370e18SAlison Wang 44145370e18SAlison Wang out_8(&gpio->par_dspi0, 44245370e18SAlison Wang GPIO_PAR_DSPI0_SIN_DSPI0SIN | GPIO_PAR_DSPI0_SOUT_DSPI0SOUT | 44345370e18SAlison Wang GPIO_PAR_DSPI0_SCK_DSPI0SCK); 44445370e18SAlison Wang out_8(&gpio->srcr_dspiow, 3); 44545370e18SAlison Wang 44645370e18SAlison Wang /* DSPI0 */ 44745370e18SAlison Wang out_8(&pm->pmcr0, 23); 44845370e18SAlison Wang #endif 449a4145534SPeter Tyser } 450a4145534SPeter Tyser 451a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs) 452a4145534SPeter Tyser { 453198cafbfSAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI; 454198cafbfSAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 455a4145534SPeter Tyser 456198cafbfSAlison Wang if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS) 457a4145534SPeter Tyser return -1; 458a4145534SPeter Tyser 459a4145534SPeter Tyser /* Clear FIFO and resume transfer */ 460198cafbfSAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); 461a4145534SPeter Tyser 46245370e18SAlison Wang #ifdef CONFIG_MCF5445x 463a4145534SPeter Tyser switch (cs) { 464a4145534SPeter Tyser case 0: 465198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); 466198cafbfSAlison Wang setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); 467a4145534SPeter Tyser break; 468a4145534SPeter Tyser case 1: 469198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1); 470198cafbfSAlison Wang setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1); 471a4145534SPeter Tyser break; 472a4145534SPeter Tyser case 2: 473198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2); 474198cafbfSAlison Wang setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2); 475a4145534SPeter Tyser break; 476e9b43caeSWolfgang Wegner case 3: 477198cafbfSAlison Wang clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK); 478198cafbfSAlison Wang setbits_8(&gpio->par_dma, GPIO_PAR_DMA_DACK0_PCS3); 479e9b43caeSWolfgang Wegner break; 480a4145534SPeter Tyser case 5: 481198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5); 482198cafbfSAlison Wang setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5); 483a4145534SPeter Tyser break; 484a4145534SPeter Tyser } 48545370e18SAlison Wang #endif 48645370e18SAlison Wang 48745370e18SAlison Wang #ifdef CONFIG_MCF5441x 48845370e18SAlison Wang switch (cs) { 48945370e18SAlison Wang case 0: 49045370e18SAlison Wang clrbits_8(&gpio->par_dspi0, ~GPIO_PAR_DSPI0_PCS0_MASK); 49145370e18SAlison Wang setbits_8(&gpio->par_dspi0, GPIO_PAR_DSPI0_PCS0_DSPI0PCS0); 49245370e18SAlison Wang break; 49345370e18SAlison Wang case 1: 49445370e18SAlison Wang clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1); 49545370e18SAlison Wang setbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1); 49645370e18SAlison Wang break; 49745370e18SAlison Wang } 49845370e18SAlison Wang #endif 499a4145534SPeter Tyser 500a4145534SPeter Tyser return 0; 501a4145534SPeter Tyser } 502a4145534SPeter Tyser 503a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs) 504a4145534SPeter Tyser { 505198cafbfSAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI; 506198cafbfSAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 507a4145534SPeter Tyser 508198cafbfSAlison Wang /* Clear FIFO */ 509198cafbfSAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); 510a4145534SPeter Tyser 51145370e18SAlison Wang #ifdef CONFIG_MCF5445x 512a4145534SPeter Tyser switch (cs) { 513a4145534SPeter Tyser case 0: 514198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); 515a4145534SPeter Tyser break; 516a4145534SPeter Tyser case 1: 517198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS1_PCS1); 518a4145534SPeter Tyser break; 519a4145534SPeter Tyser case 2: 520198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS2_PCS2); 521a4145534SPeter Tyser break; 522e9b43caeSWolfgang Wegner case 3: 523198cafbfSAlison Wang clrbits_8(&gpio->par_dma, ~GPIO_PAR_DMA_DACK0_UNMASK); 524e9b43caeSWolfgang Wegner break; 525a4145534SPeter Tyser case 5: 526198cafbfSAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS5_PCS5); 527a4145534SPeter Tyser break; 528a4145534SPeter Tyser } 52945370e18SAlison Wang #endif 53045370e18SAlison Wang 53145370e18SAlison Wang #ifdef CONFIG_MCF5441x 53245370e18SAlison Wang if (cs == 1) 53345370e18SAlison Wang clrbits_8(&gpio->par_dspiow, GPIO_PAR_DSPIOW_DSPI0PSC1); 53445370e18SAlison Wang #endif 535a4145534SPeter Tyser } 536a4145534SPeter Tyser #endif 537