1a4145534SPeter Tyser /* 2a4145534SPeter Tyser * 3a4145534SPeter Tyser * (C) Copyright 2000-2003 4a4145534SPeter Tyser * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 5a4145534SPeter Tyser * 6*849fc424SAlison Wang * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc. 7a4145534SPeter Tyser * TsiChung Liew (Tsi-Chung.Liew@freescale.com) 8a4145534SPeter Tyser * 9a4145534SPeter Tyser * See file CREDITS for list of people who contributed to this 10a4145534SPeter Tyser * project. 11a4145534SPeter Tyser * 12a4145534SPeter Tyser * This program is free software; you can redistribute it and/or 13a4145534SPeter Tyser * modify it under the terms of the GNU General Public License as 14a4145534SPeter Tyser * published by the Free Software Foundation; either version 2 of 15a4145534SPeter Tyser * the License, or (at your option) any later version. 16a4145534SPeter Tyser * 17a4145534SPeter Tyser * This program is distributed in the hope that it will be useful, 18a4145534SPeter Tyser * but WITHOUT ANY WARRANTY; without even the implied warranty of 19a4145534SPeter Tyser * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20a4145534SPeter Tyser * GNU General Public License for more details. 21a4145534SPeter Tyser * 22a4145534SPeter Tyser * You should have received a copy of the GNU General Public License 23a4145534SPeter Tyser * along with this program; if not, write to the Free Software 24a4145534SPeter Tyser * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 25a4145534SPeter Tyser * MA 02111-1307 USA 26a4145534SPeter Tyser */ 27a4145534SPeter Tyser 28a4145534SPeter Tyser #include <common.h> 29a4145534SPeter Tyser #include <watchdog.h> 30a4145534SPeter Tyser 31a4145534SPeter Tyser #include <asm/immap.h> 32*849fc424SAlison Wang #include <asm/io.h> 33a4145534SPeter Tyser #include <asm/rtc.h> 34a4145534SPeter Tyser 35a4145534SPeter Tyser /* 36a4145534SPeter Tyser * Breath some life into the CPU... 37a4145534SPeter Tyser * 38a4145534SPeter Tyser * Set up the memory map, 39a4145534SPeter Tyser * initialize a bunch of registers, 40a4145534SPeter Tyser * initialize the UPM's 41a4145534SPeter Tyser */ 42a4145534SPeter Tyser void cpu_init_f(void) 43a4145534SPeter Tyser { 44*849fc424SAlison Wang scm1_t *scm1 = (scm1_t *) MMAP_SCM1; 45*849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 46*849fc424SAlison Wang fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS; 47*849fc424SAlison Wang pll_t *pll = (pll_t *)MMAP_PLL; 48a4145534SPeter Tyser 49a4145534SPeter Tyser #if !defined(CONFIG_CF_SBF) 50a4145534SPeter Tyser /* Workaround, must place before fbcs */ 51*849fc424SAlison Wang out_be32(&pll->psr, 0x12); 52a4145534SPeter Tyser 53*849fc424SAlison Wang out_be32(&scm1->mpr, 0x77777777); 54*849fc424SAlison Wang out_be32(&scm1->pacra, 0); 55*849fc424SAlison Wang out_be32(&scm1->pacrb, 0); 56*849fc424SAlison Wang out_be32(&scm1->pacrc, 0); 57*849fc424SAlison Wang out_be32(&scm1->pacrd, 0); 58*849fc424SAlison Wang out_be32(&scm1->pacre, 0); 59*849fc424SAlison Wang out_be32(&scm1->pacrf, 0); 60*849fc424SAlison Wang out_be32(&scm1->pacrg, 0); 61*849fc424SAlison Wang out_be32(&scm1->pacri, 0); 62a4145534SPeter Tyser 63a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \ 64a4145534SPeter Tyser && defined(CONFIG_SYS_CS0_CTRL)) 65*849fc424SAlison Wang out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE); 66*849fc424SAlison Wang out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL); 67*849fc424SAlison Wang out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK); 68a4145534SPeter Tyser #endif 69a4145534SPeter Tyser #endif /* CONFIG_CF_SBF */ 70a4145534SPeter Tyser 71a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \ 72a4145534SPeter Tyser && defined(CONFIG_SYS_CS1_CTRL)) 73*849fc424SAlison Wang out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE); 74*849fc424SAlison Wang out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL); 75*849fc424SAlison Wang out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK); 76a4145534SPeter Tyser #endif 77a4145534SPeter Tyser 78a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \ 79a4145534SPeter Tyser && defined(CONFIG_SYS_CS2_CTRL)) 80*849fc424SAlison Wang out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE); 81*849fc424SAlison Wang out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL); 82*849fc424SAlison Wang out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK); 83a4145534SPeter Tyser #endif 84a4145534SPeter Tyser 85a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \ 86a4145534SPeter Tyser && defined(CONFIG_SYS_CS3_CTRL)) 87*849fc424SAlison Wang out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE); 88*849fc424SAlison Wang out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL); 89*849fc424SAlison Wang out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK); 90a4145534SPeter Tyser #endif 91a4145534SPeter Tyser 92a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \ 93a4145534SPeter Tyser && defined(CONFIG_SYS_CS4_CTRL)) 94*849fc424SAlison Wang out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE); 95*849fc424SAlison Wang out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL); 96*849fc424SAlison Wang out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK); 97a4145534SPeter Tyser #endif 98a4145534SPeter Tyser 99a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \ 100a4145534SPeter Tyser && defined(CONFIG_SYS_CS5_CTRL)) 101*849fc424SAlison Wang out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE); 102*849fc424SAlison Wang out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL); 103*849fc424SAlison Wang out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK); 104a4145534SPeter Tyser #endif 105a4145534SPeter Tyser 106a4145534SPeter Tyser #ifdef CONFIG_FSL_I2C 107*849fc424SAlison Wang out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA); 108a4145534SPeter Tyser #endif 109a4145534SPeter Tyser 110a4145534SPeter Tyser icache_enable(); 111a4145534SPeter Tyser } 112a4145534SPeter Tyser 113a4145534SPeter Tyser /* 114a4145534SPeter Tyser * initialize higher level parts of CPU like timers 115a4145534SPeter Tyser */ 116a4145534SPeter Tyser int cpu_init_r(void) 117a4145534SPeter Tyser { 118a4145534SPeter Tyser #ifdef CONFIG_MCFRTC 119*849fc424SAlison Wang rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE); 120*849fc424SAlison Wang rtcex_t *rtcex = (rtcex_t *)&rtc->extended; 121a4145534SPeter Tyser 122*849fc424SAlison Wang out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff); 123*849fc424SAlison Wang out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff); 124a4145534SPeter Tyser #endif 125a4145534SPeter Tyser 126a4145534SPeter Tyser return (0); 127a4145534SPeter Tyser } 128a4145534SPeter Tyser 129a4145534SPeter Tyser void uart_port_conf(int port) 130a4145534SPeter Tyser { 131*849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 132a4145534SPeter Tyser 133a4145534SPeter Tyser /* Setup Ports: */ 134a4145534SPeter Tyser switch (port) { 135a4145534SPeter Tyser case 0: 136*849fc424SAlison Wang clrbits_be16(&gpio->par_uart, 137*849fc424SAlison Wang ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK)); 138*849fc424SAlison Wang setbits_be16(&gpio->par_uart, 139*849fc424SAlison Wang GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD); 140a4145534SPeter Tyser break; 141a4145534SPeter Tyser case 1: 142*849fc424SAlison Wang clrbits_be16(&gpio->par_uart, 143*849fc424SAlison Wang ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK)); 144*849fc424SAlison Wang setbits_be16(&gpio->par_uart, 145*849fc424SAlison Wang GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD); 146a4145534SPeter Tyser break; 147a4145534SPeter Tyser case 2: 148*849fc424SAlison Wang clrbits_8(&gpio->par_dspi, 149*849fc424SAlison Wang ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK)); 150*849fc424SAlison Wang out_8(&gpio->par_dspi, 151*849fc424SAlison Wang GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD); 152a4145534SPeter Tyser break; 153a4145534SPeter Tyser } 154a4145534SPeter Tyser } 155a4145534SPeter Tyser 156a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI 157a4145534SPeter Tyser void cfspi_port_conf(void) 158a4145534SPeter Tyser { 159*849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 160a4145534SPeter Tyser 161*849fc424SAlison Wang out_8(&gpio->par_dspi, 162a4145534SPeter Tyser GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT | 163*849fc424SAlison Wang GPIO_PAR_DSPI_SCK_SCK); 164a4145534SPeter Tyser } 165a4145534SPeter Tyser 166a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs) 167a4145534SPeter Tyser { 168*849fc424SAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI; 169*849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 170a4145534SPeter Tyser 171*849fc424SAlison Wang if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS) 172a4145534SPeter Tyser return -1; 173a4145534SPeter Tyser 174a4145534SPeter Tyser /* Clear FIFO and resume transfer */ 175*849fc424SAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); 176a4145534SPeter Tyser 177a4145534SPeter Tyser switch (cs) { 178a4145534SPeter Tyser case 0: 179*849fc424SAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK); 180*849fc424SAlison Wang setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); 181a4145534SPeter Tyser break; 182a4145534SPeter Tyser case 2: 183*849fc424SAlison Wang clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK); 184*849fc424SAlison Wang setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2); 185a4145534SPeter Tyser break; 186a4145534SPeter Tyser } 187a4145534SPeter Tyser 188a4145534SPeter Tyser return 0; 189a4145534SPeter Tyser } 190a4145534SPeter Tyser 191a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs) 192a4145534SPeter Tyser { 193*849fc424SAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI; 194*849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 195a4145534SPeter Tyser 196*849fc424SAlison Wang /* Clear FIFO */ 197*849fc424SAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); 198a4145534SPeter Tyser 199a4145534SPeter Tyser switch (cs) { 200a4145534SPeter Tyser case 0: 201*849fc424SAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); 202a4145534SPeter Tyser break; 203a4145534SPeter Tyser case 2: 204*849fc424SAlison Wang clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK); 205a4145534SPeter Tyser break; 206a4145534SPeter Tyser } 207a4145534SPeter Tyser } 208a4145534SPeter Tyser #endif 209