1a4145534SPeter Tyser /* 2a4145534SPeter Tyser * 3a4145534SPeter Tyser * (C) Copyright 2000-2003 4a4145534SPeter Tyser * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 5a4145534SPeter Tyser * 6849fc424SAlison 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> 32849fc424SAlison Wang #include <asm/io.h> 33a4145534SPeter Tyser #include <asm/rtc.h> 347adbd11eSAlison Wang #include <linux/compiler.h> 35a4145534SPeter Tyser 36a4145534SPeter Tyser /* 37a4145534SPeter Tyser * Breath some life into the CPU... 38a4145534SPeter Tyser * 39a4145534SPeter Tyser * Set up the memory map, 40a4145534SPeter Tyser * initialize a bunch of registers, 41a4145534SPeter Tyser * initialize the UPM's 42a4145534SPeter Tyser */ 43a4145534SPeter Tyser void cpu_init_f(void) 44a4145534SPeter Tyser { 45849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 467adbd11eSAlison Wang fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS; 47a4145534SPeter Tyser 48a4145534SPeter Tyser #if !defined(CONFIG_CF_SBF) 497adbd11eSAlison Wang scm1_t *scm1 = (scm1_t *) MMAP_SCM1; 507adbd11eSAlison Wang pll_t *pll = (pll_t *)MMAP_PLL; 517adbd11eSAlison Wang 52a4145534SPeter Tyser /* Workaround, must place before fbcs */ 53849fc424SAlison Wang out_be32(&pll->psr, 0x12); 54a4145534SPeter Tyser 55849fc424SAlison Wang out_be32(&scm1->mpr, 0x77777777); 56849fc424SAlison Wang out_be32(&scm1->pacra, 0); 57849fc424SAlison Wang out_be32(&scm1->pacrb, 0); 58849fc424SAlison Wang out_be32(&scm1->pacrc, 0); 59849fc424SAlison Wang out_be32(&scm1->pacrd, 0); 60849fc424SAlison Wang out_be32(&scm1->pacre, 0); 61849fc424SAlison Wang out_be32(&scm1->pacrf, 0); 62849fc424SAlison Wang out_be32(&scm1->pacrg, 0); 63849fc424SAlison Wang out_be32(&scm1->pacri, 0); 64a4145534SPeter Tyser 65a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \ 66a4145534SPeter Tyser && defined(CONFIG_SYS_CS0_CTRL)) 67849fc424SAlison Wang out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE); 68849fc424SAlison Wang out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL); 69849fc424SAlison Wang out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK); 70a4145534SPeter Tyser #endif 71a4145534SPeter Tyser #endif /* CONFIG_CF_SBF */ 72a4145534SPeter Tyser 73a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \ 74a4145534SPeter Tyser && defined(CONFIG_SYS_CS1_CTRL)) 75849fc424SAlison Wang out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE); 76849fc424SAlison Wang out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL); 77849fc424SAlison Wang out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK); 78a4145534SPeter Tyser #endif 79a4145534SPeter Tyser 80a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \ 81a4145534SPeter Tyser && defined(CONFIG_SYS_CS2_CTRL)) 82849fc424SAlison Wang out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE); 83849fc424SAlison Wang out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL); 84849fc424SAlison Wang out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK); 85a4145534SPeter Tyser #endif 86a4145534SPeter Tyser 87a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \ 88a4145534SPeter Tyser && defined(CONFIG_SYS_CS3_CTRL)) 89849fc424SAlison Wang out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE); 90849fc424SAlison Wang out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL); 91849fc424SAlison Wang out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK); 92a4145534SPeter Tyser #endif 93a4145534SPeter Tyser 94a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \ 95a4145534SPeter Tyser && defined(CONFIG_SYS_CS4_CTRL)) 96849fc424SAlison Wang out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE); 97849fc424SAlison Wang out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL); 98849fc424SAlison Wang out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK); 99a4145534SPeter Tyser #endif 100a4145534SPeter Tyser 101a4145534SPeter Tyser #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \ 102a4145534SPeter Tyser && defined(CONFIG_SYS_CS5_CTRL)) 103849fc424SAlison Wang out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE); 104849fc424SAlison Wang out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL); 105849fc424SAlison Wang out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK); 106a4145534SPeter Tyser #endif 107a4145534SPeter Tyser 108*00f792e0SHeiko Schocher #ifdef CONFIG_SYS_I2C_FSL 109849fc424SAlison Wang out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA); 110a4145534SPeter Tyser #endif 111a4145534SPeter Tyser 112a4145534SPeter Tyser icache_enable(); 113a4145534SPeter Tyser } 114a4145534SPeter Tyser 115a4145534SPeter Tyser /* 116a4145534SPeter Tyser * initialize higher level parts of CPU like timers 117a4145534SPeter Tyser */ 118a4145534SPeter Tyser int cpu_init_r(void) 119a4145534SPeter Tyser { 120a4145534SPeter Tyser #ifdef CONFIG_MCFRTC 121849fc424SAlison Wang rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE); 122849fc424SAlison Wang rtcex_t *rtcex = (rtcex_t *)&rtc->extended; 123a4145534SPeter Tyser 124849fc424SAlison Wang out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff); 125849fc424SAlison Wang out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff); 126a4145534SPeter Tyser #endif 127a4145534SPeter Tyser 128a4145534SPeter Tyser return (0); 129a4145534SPeter Tyser } 130a4145534SPeter Tyser 131a4145534SPeter Tyser void uart_port_conf(int port) 132a4145534SPeter Tyser { 133849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 134a4145534SPeter Tyser 135a4145534SPeter Tyser /* Setup Ports: */ 136a4145534SPeter Tyser switch (port) { 137a4145534SPeter Tyser case 0: 138849fc424SAlison Wang clrbits_be16(&gpio->par_uart, 139849fc424SAlison Wang ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK)); 140849fc424SAlison Wang setbits_be16(&gpio->par_uart, 141849fc424SAlison Wang GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD); 142a4145534SPeter Tyser break; 143a4145534SPeter Tyser case 1: 144849fc424SAlison Wang clrbits_be16(&gpio->par_uart, 145849fc424SAlison Wang ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK)); 146849fc424SAlison Wang setbits_be16(&gpio->par_uart, 147849fc424SAlison Wang GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD); 148a4145534SPeter Tyser break; 149a4145534SPeter Tyser case 2: 150849fc424SAlison Wang clrbits_8(&gpio->par_dspi, 151849fc424SAlison Wang ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK)); 152849fc424SAlison Wang out_8(&gpio->par_dspi, 153849fc424SAlison Wang GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD); 154a4145534SPeter Tyser break; 155a4145534SPeter Tyser } 156a4145534SPeter Tyser } 157a4145534SPeter Tyser 158a4145534SPeter Tyser #ifdef CONFIG_CF_DSPI 159a4145534SPeter Tyser void cfspi_port_conf(void) 160a4145534SPeter Tyser { 161849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 162a4145534SPeter Tyser 163849fc424SAlison Wang out_8(&gpio->par_dspi, 164a4145534SPeter Tyser GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT | 165849fc424SAlison Wang GPIO_PAR_DSPI_SCK_SCK); 166a4145534SPeter Tyser } 167a4145534SPeter Tyser 168a4145534SPeter Tyser int cfspi_claim_bus(uint bus, uint cs) 169a4145534SPeter Tyser { 170849fc424SAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI; 171849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 172a4145534SPeter Tyser 173849fc424SAlison Wang if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS) 174a4145534SPeter Tyser return -1; 175a4145534SPeter Tyser 176a4145534SPeter Tyser /* Clear FIFO and resume transfer */ 177849fc424SAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); 178a4145534SPeter Tyser 179a4145534SPeter Tyser switch (cs) { 180a4145534SPeter Tyser case 0: 181849fc424SAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK); 182849fc424SAlison Wang setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); 183a4145534SPeter Tyser break; 184a4145534SPeter Tyser case 2: 185849fc424SAlison Wang clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK); 186849fc424SAlison Wang setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2); 187a4145534SPeter Tyser break; 188a4145534SPeter Tyser } 189a4145534SPeter Tyser 190a4145534SPeter Tyser return 0; 191a4145534SPeter Tyser } 192a4145534SPeter Tyser 193a4145534SPeter Tyser void cfspi_release_bus(uint bus, uint cs) 194a4145534SPeter Tyser { 195849fc424SAlison Wang dspi_t *dspi = (dspi_t *) MMAP_DSPI; 196849fc424SAlison Wang gpio_t *gpio = (gpio_t *) MMAP_GPIO; 197a4145534SPeter Tyser 198849fc424SAlison Wang /* Clear FIFO */ 199849fc424SAlison Wang clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); 200a4145534SPeter Tyser 201a4145534SPeter Tyser switch (cs) { 202a4145534SPeter Tyser case 0: 203849fc424SAlison Wang clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); 204a4145534SPeter Tyser break; 205a4145534SPeter Tyser case 2: 206849fc424SAlison Wang clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK); 207a4145534SPeter Tyser break; 208a4145534SPeter Tyser } 209a4145534SPeter Tyser } 210a4145534SPeter Tyser #endif 211