TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * (C) Copyright 2000-2003 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 6 | * (C) Copyright 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 7 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
| 8 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <common.h> |
| 13 | #include <watchdog.h> |
| 14 | |
| 15 | #include <asm/immap.h> |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 16 | #include <asm/io.h> |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 17 | #include <asm/rtc.h> |
Alison Wang | 7adbd11e | 2012-10-21 21:27:48 +0000 | [diff] [blame] | 18 | #include <linux/compiler.h> |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 19 | |
| 20 | /* |
| 21 | * Breath some life into the CPU... |
| 22 | * |
| 23 | * Set up the memory map, |
| 24 | * initialize a bunch of registers, |
| 25 | * initialize the UPM's |
| 26 | */ |
| 27 | void cpu_init_f(void) |
| 28 | { |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 29 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
Alison Wang | 7adbd11e | 2012-10-21 21:27:48 +0000 | [diff] [blame] | 30 | fbcs_t *fbcs __maybe_unused = (fbcs_t *) MMAP_FBCS; |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 31 | |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 32 | #if !defined(CONFIG_CF_SBF) |
Alison Wang | 7adbd11e | 2012-10-21 21:27:48 +0000 | [diff] [blame] | 33 | scm1_t *scm1 = (scm1_t *) MMAP_SCM1; |
| 34 | pll_t *pll = (pll_t *)MMAP_PLL; |
| 35 | |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 36 | /* Workaround, must place before fbcs */ |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 37 | out_be32(&pll->psr, 0x12); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 38 | |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 39 | out_be32(&scm1->mpr, 0x77777777); |
| 40 | out_be32(&scm1->pacra, 0); |
| 41 | out_be32(&scm1->pacrb, 0); |
| 42 | out_be32(&scm1->pacrc, 0); |
| 43 | out_be32(&scm1->pacrd, 0); |
| 44 | out_be32(&scm1->pacre, 0); |
| 45 | out_be32(&scm1->pacrf, 0); |
| 46 | out_be32(&scm1->pacrg, 0); |
| 47 | out_be32(&scm1->pacri, 0); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 48 | |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 49 | #if (defined(CONFIG_SYS_CS0_BASE) && defined(CONFIG_SYS_CS0_MASK) \ |
| 50 | && defined(CONFIG_SYS_CS0_CTRL)) |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 51 | out_be32(&fbcs->csar0, CONFIG_SYS_CS0_BASE); |
| 52 | out_be32(&fbcs->cscr0, CONFIG_SYS_CS0_CTRL); |
| 53 | out_be32(&fbcs->csmr0, CONFIG_SYS_CS0_MASK); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 54 | #endif |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 55 | #endif /* CONFIG_CF_SBF */ |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 56 | |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 57 | #if (defined(CONFIG_SYS_CS1_BASE) && defined(CONFIG_SYS_CS1_MASK) \ |
| 58 | && defined(CONFIG_SYS_CS1_CTRL)) |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 59 | out_be32(&fbcs->csar1, CONFIG_SYS_CS1_BASE); |
| 60 | out_be32(&fbcs->cscr1, CONFIG_SYS_CS1_CTRL); |
| 61 | out_be32(&fbcs->csmr1, CONFIG_SYS_CS1_MASK); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 62 | #endif |
| 63 | |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 64 | #if (defined(CONFIG_SYS_CS2_BASE) && defined(CONFIG_SYS_CS2_MASK) \ |
| 65 | && defined(CONFIG_SYS_CS2_CTRL)) |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 66 | out_be32(&fbcs->csar2, CONFIG_SYS_CS2_BASE); |
| 67 | out_be32(&fbcs->cscr2, CONFIG_SYS_CS2_CTRL); |
| 68 | out_be32(&fbcs->csmr2, CONFIG_SYS_CS2_MASK); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 69 | #endif |
| 70 | |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 71 | #if (defined(CONFIG_SYS_CS3_BASE) && defined(CONFIG_SYS_CS3_MASK) \ |
| 72 | && defined(CONFIG_SYS_CS3_CTRL)) |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 73 | out_be32(&fbcs->csar3, CONFIG_SYS_CS3_BASE); |
| 74 | out_be32(&fbcs->cscr3, CONFIG_SYS_CS3_CTRL); |
| 75 | out_be32(&fbcs->csmr3, CONFIG_SYS_CS3_MASK); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 76 | #endif |
| 77 | |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 78 | #if (defined(CONFIG_SYS_CS4_BASE) && defined(CONFIG_SYS_CS4_MASK) \ |
| 79 | && defined(CONFIG_SYS_CS4_CTRL)) |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 80 | out_be32(&fbcs->csar4, CONFIG_SYS_CS4_BASE); |
| 81 | out_be32(&fbcs->cscr4, CONFIG_SYS_CS4_CTRL); |
| 82 | out_be32(&fbcs->csmr4, CONFIG_SYS_CS4_MASK); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 83 | #endif |
| 84 | |
TsiChung Liew | a21d0c2 | 2008-10-21 15:37:02 +0000 | [diff] [blame] | 85 | #if (defined(CONFIG_SYS_CS5_BASE) && defined(CONFIG_SYS_CS5_MASK) \ |
| 86 | && defined(CONFIG_SYS_CS5_CTRL)) |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 87 | out_be32(&fbcs->csar5, CONFIG_SYS_CS5_BASE); |
| 88 | out_be32(&fbcs->cscr5, CONFIG_SYS_CS5_CTRL); |
| 89 | out_be32(&fbcs->csmr5, CONFIG_SYS_CS5_MASK); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 90 | #endif |
| 91 | |
Heiko Schocher | 00f792e | 2012-10-24 13:48:22 +0200 | [diff] [blame] | 92 | #ifdef CONFIG_SYS_I2C_FSL |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 93 | out_8(&gpio->par_i2c, GPIO_PAR_I2C_SCL_SCL | GPIO_PAR_I2C_SDA_SDA); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | icache_enable(); |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * initialize higher level parts of CPU like timers |
| 101 | */ |
| 102 | int cpu_init_r(void) |
| 103 | { |
TsiChung Liew | bc3ccb1 | 2008-07-09 15:47:27 -0500 | [diff] [blame] | 104 | #ifdef CONFIG_MCFRTC |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 105 | rtc_t *rtc = (rtc_t *)(CONFIG_SYS_MCFRTC_BASE); |
| 106 | rtcex_t *rtcex = (rtcex_t *)&rtc->extended; |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 107 | |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 108 | out_be32(&rtcex->gocu, (CONFIG_SYS_RTC_OSCILLATOR >> 16) & 0xffff); |
| 109 | out_be32(&rtcex->gocl, CONFIG_SYS_RTC_OSCILLATOR & 0xffff); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 110 | #endif |
| 111 | |
| 112 | return (0); |
| 113 | } |
| 114 | |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 115 | void uart_port_conf(int port) |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 116 | { |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 117 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 118 | |
| 119 | /* Setup Ports: */ |
TsiChung Liew | 52affe0 | 2010-03-09 19:17:52 -0600 | [diff] [blame] | 120 | switch (port) { |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 121 | case 0: |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 122 | clrbits_be16(&gpio->par_uart, |
| 123 | ~(GPIO_PAR_UART_U0TXD_UNMASK & GPIO_PAR_UART_U0RXD_UNMASK)); |
| 124 | setbits_be16(&gpio->par_uart, |
| 125 | GPIO_PAR_UART_U0TXD_U0TXD | GPIO_PAR_UART_U0RXD_U0RXD); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 126 | break; |
| 127 | case 1: |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 128 | clrbits_be16(&gpio->par_uart, |
| 129 | ~(GPIO_PAR_UART_U1TXD_UNMASK & GPIO_PAR_UART_U1RXD_UNMASK)); |
| 130 | setbits_be16(&gpio->par_uart, |
| 131 | GPIO_PAR_UART_U1TXD_U1TXD | GPIO_PAR_UART_U1RXD_U1RXD); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 132 | break; |
| 133 | case 2: |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 134 | clrbits_8(&gpio->par_dspi, |
| 135 | ~(GPIO_PAR_DSPI_SIN_UNMASK & GPIO_PAR_DSPI_SOUT_UNMASK)); |
| 136 | out_8(&gpio->par_dspi, |
| 137 | GPIO_PAR_DSPI_SIN_U2RXD | GPIO_PAR_DSPI_SOUT_U2TXD); |
TsiChungLiew | c875810 | 2008-01-14 17:46:19 -0600 | [diff] [blame] | 138 | break; |
| 139 | } |
| 140 | } |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 141 | |
| 142 | #ifdef CONFIG_CF_DSPI |
| 143 | void cfspi_port_conf(void) |
| 144 | { |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 145 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 146 | |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 147 | out_8(&gpio->par_dspi, |
| 148 | GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT | |
| 149 | GPIO_PAR_DSPI_SCK_SCK); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | int cfspi_claim_bus(uint bus, uint cs) |
| 153 | { |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 154 | dspi_t *dspi = (dspi_t *) MMAP_DSPI; |
| 155 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 156 | |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 157 | if ((in_be32(&dspi->sr) & DSPI_SR_TXRXS) != DSPI_SR_TXRXS) |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 158 | return -1; |
| 159 | |
| 160 | /* Clear FIFO and resume transfer */ |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 161 | clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 162 | |
| 163 | switch (cs) { |
| 164 | case 0: |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 165 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_UNMASK); |
| 166 | setbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 167 | break; |
| 168 | case 2: |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 169 | clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK); |
| 170 | setbits_8(&gpio->par_timer, GPIO_PAR_TIMER_T2IN_DSPIPCS2); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 171 | break; |
| 172 | } |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | void cfspi_release_bus(uint bus, uint cs) |
| 178 | { |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 179 | dspi_t *dspi = (dspi_t *) MMAP_DSPI; |
| 180 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 181 | |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 182 | /* Clear FIFO */ |
| 183 | clrbits_be32(&dspi->mcr, DSPI_MCR_CTXF | DSPI_MCR_CRXF); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 184 | |
| 185 | switch (cs) { |
| 186 | case 0: |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 187 | clrbits_8(&gpio->par_dspi, GPIO_PAR_DSPI_PCS0_PCS0); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 188 | break; |
| 189 | case 2: |
Alison Wang | 849fc42 | 2012-03-26 21:49:03 +0000 | [diff] [blame] | 190 | clrbits_8(&gpio->par_timer, ~GPIO_PAR_TIMER_T2IN_UNMASK); |
TsiChung Liew | ee0a846 | 2009-06-30 14:18:29 +0000 | [diff] [blame] | 191 | break; |
| 192 | } |
| 193 | } |
| 194 | #endif |