Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 1 | /* |
| 2 | * initcode.c - Initialize the processor. This is usually entails things |
| 3 | * like external memory, voltage regulators, etc... Note that this file |
| 4 | * cannot make any function calls as it may be executed all by itself by |
| 5 | * the Blackfin's bootrom in LDR format. |
| 6 | * |
| 7 | * Copyright (c) 2004-2008 Analog Devices Inc. |
| 8 | * |
| 9 | * Licensed under the GPL-2 or later. |
| 10 | */ |
| 11 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 12 | #define BFIN_IN_INITCODE |
| 13 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 14 | #include <config.h> |
| 15 | #include <asm/blackfin.h> |
| 16 | #include <asm/mach-common/bits/bootrom.h> |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 17 | #include <asm/mach-common/bits/core.h> |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 18 | #include <asm/mach-common/bits/ebiu.h> |
| 19 | #include <asm/mach-common/bits/pll.h> |
| 20 | #include <asm/mach-common/bits/uart.h> |
| 21 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 22 | #include "serial.h" |
| 23 | |
| 24 | __attribute__((always_inline)) |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 25 | static inline void serial_init(void) |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 26 | { |
| 27 | #ifdef __ADSPBF54x__ |
| 28 | # ifdef BFIN_BOOT_UART_USE_RTS |
| 29 | # define BFIN_UART_USE_RTS 1 |
| 30 | # else |
| 31 | # define BFIN_UART_USE_RTS 0 |
| 32 | # endif |
| 33 | if (BFIN_UART_USE_RTS && CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_UART) { |
| 34 | size_t i; |
| 35 | |
| 36 | /* force RTS rather than relying on auto RTS */ |
Mike Frysinger | 3b7ed5a | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 37 | bfin_write16(&pUART->mcr, bfin_read16(&pUART->mcr) | FCPOL); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 38 | |
| 39 | /* Wait for the line to clear up. We cannot rely on UART |
| 40 | * registers as none of them reflect the status of the RSR. |
| 41 | * Instead, we'll sleep for ~10 bit times at 9600 baud. |
| 42 | * We can precalc things here by assuming boot values for |
| 43 | * PLL rather than loading registers and calculating. |
| 44 | * baud = SCLK / (16 ^ (1 - EDBO) * Divisor) |
| 45 | * EDB0 = 0 |
| 46 | * Divisor = (SCLK / baud) / 16 |
| 47 | * SCLK = baud * 16 * Divisor |
| 48 | * SCLK = (0x14 * CONFIG_CLKIN_HZ) / 5 |
| 49 | * CCLK = (16 * Divisor * 5) * (9600 / 10) |
| 50 | * In reality, this will probably be just about 1 second delay, |
| 51 | * so assuming 9600 baud is OK (both as a very low and too high |
| 52 | * speed as this will buffer things enough). |
| 53 | */ |
| 54 | #define _NUMBITS (10) /* how many bits to delay */ |
| 55 | #define _LOWBAUD (9600) /* low baud rate */ |
| 56 | #define _SCLK ((0x14 * CONFIG_CLKIN_HZ) / 5) /* SCLK based on PLL */ |
| 57 | #define _DIVISOR ((_SCLK / _LOWBAUD) / 16) /* UART DLL/DLH */ |
| 58 | #define _NUMINS (3) /* how many instructions in loop */ |
| 59 | #define _CCLK (((16 * _DIVISOR * 5) * (_LOWBAUD / _NUMBITS)) / _NUMINS) |
| 60 | i = _CCLK; |
| 61 | while (i--) |
| 62 | asm volatile("" : : : "memory"); |
| 63 | } |
| 64 | #endif |
| 65 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 66 | if (BFIN_DEBUG_EARLY_SERIAL) { |
Mike Frysinger | 3b7ed5a | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 67 | int ucen = bfin_read16(&pUART->gctl) & UCEN; |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 68 | serial_early_init(); |
| 69 | |
| 70 | /* If the UART is off, that means we need to program |
| 71 | * the baud rate ourselves initially. |
| 72 | */ |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 73 | if (ucen != UCEN) |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 74 | serial_early_set_baud(CONFIG_BAUDRATE); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 75 | } |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | __attribute__((always_inline)) |
| 79 | static inline void serial_deinit(void) |
| 80 | { |
| 81 | #ifdef __ADSPBF54x__ |
| 82 | if (BFIN_UART_USE_RTS && CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_UART) { |
| 83 | /* clear forced RTS rather than relying on auto RTS */ |
Mike Frysinger | 3b7ed5a | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 84 | bfin_write16(&pUART->mcr, bfin_read16(&pUART->mcr) & ~FCPOL); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 85 | } |
| 86 | #endif |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | __attribute__((always_inline)) |
| 90 | static inline void serial_putc(char c) |
| 91 | { |
| 92 | if (!BFIN_DEBUG_EARLY_SERIAL) |
| 93 | return; |
| 94 | |
| 95 | if (c == '\n') |
Mike Frysinger | e7851d0 | 2009-04-24 23:22:48 -0400 | [diff] [blame] | 96 | serial_putc('\r'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 97 | |
Mike Frysinger | 3b7ed5a | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 98 | bfin_write16(&pUART->thr, c); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 99 | |
Mike Frysinger | 3b7ed5a | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 100 | while (!(bfin_read16(&pUART->lsr) & TEMT)) |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 101 | continue; |
| 102 | } |
| 103 | |
Mike Frysinger | eb2a399 | 2010-05-05 02:07:44 -0400 | [diff] [blame] | 104 | __attribute__((always_inline)) static inline void |
| 105 | program_nmi_handler(void) |
| 106 | { |
| 107 | u32 tmp1, tmp2; |
| 108 | |
| 109 | /* Older bootroms don't create a dummy NMI handler, |
| 110 | * so make one ourselves ASAP in case it fires. |
| 111 | */ |
| 112 | if (CONFIG_BFIN_BOOT_MODE != BFIN_BOOT_BYPASS && !ANOMALY_05000219) |
| 113 | return; |
| 114 | |
| 115 | asm volatile ( |
| 116 | "%0 = RETS;" /* Save current RETS */ |
| 117 | "CALL 1f;" /* Figure out current PC */ |
| 118 | "RTN;" /* The simple NMI handler */ |
| 119 | "1:" |
| 120 | "%1 = RETS;" /* Load addr of NMI handler */ |
| 121 | "RETS = %0;" /* Restore RETS */ |
| 122 | "[%2] = %1;" /* Write NMI handler */ |
| 123 | : "=r"(tmp1), "=r"(tmp2) : "ab"(EVT2) |
| 124 | ); |
| 125 | } |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 126 | |
Mike Frysinger | 2c00197 | 2008-12-09 17:21:08 -0500 | [diff] [blame] | 127 | /* Max SCLK can be 133MHz ... dividing that by (2*4) gives |
| 128 | * us a freq of 16MHz for SPI which should generally be |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 129 | * slow enough for the slow reads the bootrom uses. |
| 130 | */ |
Mike Frysinger | 2c00197 | 2008-12-09 17:21:08 -0500 | [diff] [blame] | 131 | #if !defined(CONFIG_SPI_FLASH_SLOW_READ) && \ |
| 132 | ((defined(__ADSPBF52x__) && __SILICON_REVISION__ >= 2) || \ |
| 133 | (defined(__ADSPBF54x__) && __SILICON_REVISION__ >= 1)) |
| 134 | # define BOOTROM_SUPPORTS_SPI_FAST_READ 1 |
| 135 | #else |
| 136 | # define BOOTROM_SUPPORTS_SPI_FAST_READ 0 |
| 137 | #endif |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 138 | #ifndef CONFIG_SPI_BAUD_INITBLOCK |
Mike Frysinger | 2c00197 | 2008-12-09 17:21:08 -0500 | [diff] [blame] | 139 | # define CONFIG_SPI_BAUD_INITBLOCK (BOOTROM_SUPPORTS_SPI_FAST_READ ? 2 : 4) |
| 140 | #endif |
| 141 | #ifdef SPI0_BAUD |
| 142 | # define bfin_write_SPI_BAUD bfin_write_SPI0_BAUD |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 143 | #endif |
| 144 | |
| 145 | /* PLL_DIV defines */ |
| 146 | #ifndef CONFIG_PLL_DIV_VAL |
| 147 | # if (CONFIG_CCLK_DIV == 1) |
| 148 | # define CONFIG_CCLK_ACT_DIV CCLK_DIV1 |
| 149 | # elif (CONFIG_CCLK_DIV == 2) |
| 150 | # define CONFIG_CCLK_ACT_DIV CCLK_DIV2 |
| 151 | # elif (CONFIG_CCLK_DIV == 4) |
| 152 | # define CONFIG_CCLK_ACT_DIV CCLK_DIV4 |
| 153 | # elif (CONFIG_CCLK_DIV == 8) |
| 154 | # define CONFIG_CCLK_ACT_DIV CCLK_DIV8 |
| 155 | # else |
| 156 | # define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly |
| 157 | # endif |
| 158 | # define CONFIG_PLL_DIV_VAL (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV) |
| 159 | #endif |
| 160 | |
| 161 | #ifndef CONFIG_PLL_LOCKCNT_VAL |
| 162 | # define CONFIG_PLL_LOCKCNT_VAL 0x0300 |
| 163 | #endif |
| 164 | |
| 165 | #ifndef CONFIG_PLL_CTL_VAL |
Mike Frysinger | c13fc44 | 2008-06-01 01:26:29 -0400 | [diff] [blame] | 166 | # define CONFIG_PLL_CTL_VAL (SPORT_HYST | (CONFIG_VCO_MULT << 9) | CONFIG_CLKIN_HALF) |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 167 | #endif |
| 168 | |
| 169 | #ifndef CONFIG_EBIU_RSTCTL_VAL |
| 170 | # define CONFIG_EBIU_RSTCTL_VAL 0 /* only MDDRENABLE is useful */ |
| 171 | #endif |
Mike Frysinger | 4f7fb33 | 2008-10-11 21:46:52 -0400 | [diff] [blame] | 172 | #if ((CONFIG_EBIU_RSTCTL_VAL & 0xFFFFFFC4) != 0) |
| 173 | # error invalid EBIU_RSTCTL value: must not set reserved bits |
| 174 | #endif |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 175 | |
| 176 | #ifndef CONFIG_EBIU_MBSCTL_VAL |
| 177 | # define CONFIG_EBIU_MBSCTL_VAL 0 |
| 178 | #endif |
| 179 | |
Mike Frysinger | 4f7fb33 | 2008-10-11 21:46:52 -0400 | [diff] [blame] | 180 | #if defined(CONFIG_EBIU_DDRQUE_VAL) && ((CONFIG_EBIU_DDRQUE_VAL & 0xFFFF8000) != 0) |
| 181 | # error invalid EBIU_DDRQUE value: must not set reserved bits |
| 182 | #endif |
| 183 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 184 | /* Make sure our voltage value is sane so we don't blow up! */ |
| 185 | #ifndef CONFIG_VR_CTL_VAL |
| 186 | # define BFIN_CCLK ((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT) / CONFIG_CCLK_DIV) |
| 187 | # if defined(__ADSPBF533__) || defined(__ADSPBF532__) || defined(__ADSPBF531__) |
| 188 | # define CCLK_VLEV_120 400000000 |
| 189 | # define CCLK_VLEV_125 533000000 |
| 190 | # elif defined(__ADSPBF537__) || defined(__ADSPBF536__) || defined(__ADSPBF534__) |
| 191 | # define CCLK_VLEV_120 401000000 |
| 192 | # define CCLK_VLEV_125 401000000 |
| 193 | # elif defined(__ADSPBF561__) |
| 194 | # define CCLK_VLEV_120 300000000 |
| 195 | # define CCLK_VLEV_125 501000000 |
| 196 | # endif |
| 197 | # if BFIN_CCLK < CCLK_VLEV_120 |
| 198 | # define CONFIG_VR_CTL_VLEV VLEV_120 |
| 199 | # elif BFIN_CCLK < CCLK_VLEV_125 |
| 200 | # define CONFIG_VR_CTL_VLEV VLEV_125 |
| 201 | # else |
| 202 | # define CONFIG_VR_CTL_VLEV VLEV_130 |
| 203 | # endif |
| 204 | # if defined(__ADSPBF52x__) /* TBD; use default */ |
| 205 | # undef CONFIG_VR_CTL_VLEV |
| 206 | # define CONFIG_VR_CTL_VLEV VLEV_110 |
| 207 | # elif defined(__ADSPBF54x__) /* TBD; use default */ |
| 208 | # undef CONFIG_VR_CTL_VLEV |
| 209 | # define CONFIG_VR_CTL_VLEV VLEV_120 |
Mike Frysinger | a7ab10a | 2008-10-11 21:54:00 -0400 | [diff] [blame] | 210 | # elif defined(__ADSPBF538__) || defined(__ADSPBF539__) /* TBD; use default */ |
| 211 | # undef CONFIG_VR_CTL_VLEV |
| 212 | # define CONFIG_VR_CTL_VLEV VLEV_125 |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 213 | # endif |
| 214 | |
| 215 | # ifdef CONFIG_BFIN_MAC |
| 216 | # define CONFIG_VR_CTL_CLKBUF CLKBUFOE |
| 217 | # else |
| 218 | # define CONFIG_VR_CTL_CLKBUF 0 |
| 219 | # endif |
| 220 | |
| 221 | # if defined(__ADSPBF52x__) |
| 222 | # define CONFIG_VR_CTL_FREQ FREQ_1000 |
| 223 | # else |
| 224 | # define CONFIG_VR_CTL_FREQ (GAIN_20 | FREQ_1000) |
| 225 | # endif |
| 226 | |
| 227 | # define CONFIG_VR_CTL_VAL (CONFIG_VR_CTL_CLKBUF | CONFIG_VR_CTL_VLEV | CONFIG_VR_CTL_FREQ) |
| 228 | #endif |
| 229 | |
Mike Frysinger | 446d570 | 2008-10-11 21:56:08 -0400 | [diff] [blame] | 230 | /* some parts do not have an on-chip voltage regulator */ |
| 231 | #if defined(__ADSPBF51x__) |
| 232 | # define CONFIG_HAS_VR 0 |
| 233 | # undef CONFIG_VR_CTL_VAL |
| 234 | # define CONFIG_VR_CTL_VAL 0 |
| 235 | #else |
| 236 | # define CONFIG_HAS_VR 1 |
| 237 | #endif |
| 238 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 239 | #if CONFIG_MEM_SIZE |
Mike Frysinger | b0f1468 | 2008-06-01 01:28:24 -0400 | [diff] [blame] | 240 | #ifndef EBIU_RSTCTL |
| 241 | /* Blackfin with SDRAM */ |
| 242 | #ifndef CONFIG_EBIU_SDBCTL_VAL |
| 243 | # if CONFIG_MEM_SIZE == 16 |
| 244 | # define CONFIG_EBSZ_VAL EBSZ_16 |
| 245 | # elif CONFIG_MEM_SIZE == 32 |
| 246 | # define CONFIG_EBSZ_VAL EBSZ_32 |
| 247 | # elif CONFIG_MEM_SIZE == 64 |
| 248 | # define CONFIG_EBSZ_VAL EBSZ_64 |
| 249 | # elif CONFIG_MEM_SIZE == 128 |
| 250 | # define CONFIG_EBSZ_VAL EBSZ_128 |
| 251 | # elif CONFIG_MEM_SIZE == 256 |
| 252 | # define CONFIG_EBSZ_VAL EBSZ_256 |
| 253 | # elif CONFIG_MEM_SIZE == 512 |
| 254 | # define CONFIG_EBSZ_VAL EBSZ_512 |
| 255 | # else |
| 256 | # error You need to define CONFIG_EBIU_SDBCTL_VAL or CONFIG_MEM_SIZE |
| 257 | # endif |
| 258 | # if CONFIG_MEM_ADD_WDTH == 8 |
| 259 | # define CONFIG_EBCAW_VAL EBCAW_8 |
| 260 | # elif CONFIG_MEM_ADD_WDTH == 9 |
| 261 | # define CONFIG_EBCAW_VAL EBCAW_9 |
| 262 | # elif CONFIG_MEM_ADD_WDTH == 10 |
| 263 | # define CONFIG_EBCAW_VAL EBCAW_10 |
| 264 | # elif CONFIG_MEM_ADD_WDTH == 11 |
| 265 | # define CONFIG_EBCAW_VAL EBCAW_11 |
| 266 | # else |
| 267 | # error You need to define CONFIG_EBIU_SDBCTL_VAL or CONFIG_MEM_ADD_WDTH |
| 268 | # endif |
| 269 | # define CONFIG_EBIU_SDBCTL_VAL (CONFIG_EBCAW_VAL | CONFIG_EBSZ_VAL | EBE) |
| 270 | #endif |
| 271 | #endif |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 272 | #endif |
Mike Frysinger | b0f1468 | 2008-06-01 01:28:24 -0400 | [diff] [blame] | 273 | |
Mike Frysinger | 8c10be4 | 2009-04-04 08:40:13 -0400 | [diff] [blame] | 274 | /* Conflicting Column Address Widths Causes SDRAM Errors: |
| 275 | * EB2CAW and EB3CAW must be the same |
| 276 | */ |
| 277 | #if ANOMALY_05000362 |
| 278 | # if ((CONFIG_EBIU_SDBCTL_VAL & 0x30000000) >> 8) != (CONFIG_EBIU_SDBCTL_VAL & 0x00300000) |
| 279 | # error "Anomaly 05000362: EB2CAW and EB3CAW must be the same" |
| 280 | # endif |
| 281 | #endif |
| 282 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 283 | __attribute__((always_inline)) static inline void |
| 284 | program_early_devices(ADI_BOOT_DATA *bs, uint *sdivB, uint *divB, uint *vcoB) |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 285 | { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 286 | serial_putc('a'); |
Mike Frysinger | 0198676 | 2009-02-13 17:10:58 -0500 | [diff] [blame] | 287 | |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 288 | /* Save the clock pieces that are used in baud rate calculation */ |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 289 | if (BFIN_DEBUG_EARLY_SERIAL || CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_UART) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 290 | serial_putc('b'); |
| 291 | *sdivB = bfin_read_PLL_DIV() & 0xf; |
| 292 | *vcoB = (bfin_read_PLL_CTL() >> 9) & 0x3f; |
| 293 | *divB = serial_early_get_div(); |
| 294 | serial_putc('c'); |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 295 | } |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 296 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 297 | serial_putc('d'); |
Mike Frysinger | 0198676 | 2009-02-13 17:10:58 -0500 | [diff] [blame] | 298 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 299 | #ifdef CONFIG_HW_WATCHDOG |
| 300 | # ifndef CONFIG_HW_WATCHDOG_TIMEOUT_INITCODE |
| 301 | # define CONFIG_HW_WATCHDOG_TIMEOUT_INITCODE 20000 |
| 302 | # endif |
| 303 | /* Program the watchdog with an initial timeout of ~20 seconds. |
| 304 | * Hopefully that should be long enough to load the u-boot LDR |
| 305 | * (from wherever) and then the common u-boot code can take over. |
| 306 | * In bypass mode, the start.S would have already set a much lower |
| 307 | * timeout, so don't clobber that. |
| 308 | */ |
| 309 | if (CONFIG_BFIN_BOOT_MODE != BFIN_BOOT_BYPASS) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 310 | serial_putc('e'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 311 | bfin_write_WDOG_CNT(MSEC_TO_SCLK(CONFIG_HW_WATCHDOG_TIMEOUT_INITCODE)); |
| 312 | bfin_write_WDOG_CTL(0); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 313 | serial_putc('f'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 314 | } |
| 315 | #endif |
| 316 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 317 | serial_putc('g'); |
| 318 | |
| 319 | /* Blackfin bootroms use the SPI slow read opcode instead of the SPI |
| 320 | * fast read, so we need to slow down the SPI clock a lot more during |
| 321 | * boot. Once we switch over to u-boot's SPI flash driver, we'll |
| 322 | * increase the speed appropriately. |
| 323 | */ |
| 324 | if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_SPI_MASTER) { |
| 325 | serial_putc('h'); |
| 326 | if (BOOTROM_SUPPORTS_SPI_FAST_READ && CONFIG_SPI_BAUD_INITBLOCK < 4) |
| 327 | bs->dFlags |= BFLAG_FASTREAD; |
| 328 | bfin_write_SPI_BAUD(CONFIG_SPI_BAUD_INITBLOCK); |
| 329 | serial_putc('i'); |
| 330 | } |
| 331 | |
| 332 | serial_putc('j'); |
| 333 | } |
| 334 | |
| 335 | __attribute__((always_inline)) static inline bool |
| 336 | maybe_self_refresh(ADI_BOOT_DATA *bs) |
| 337 | { |
| 338 | serial_putc('a'); |
| 339 | |
| 340 | if (!CONFIG_MEM_SIZE) |
| 341 | return false; |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 342 | |
| 343 | /* If external memory is enabled, put it into self refresh first. */ |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 344 | #if defined(EBIU_RSTCTL) |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 345 | if (bfin_read_EBIU_RSTCTL() & DDR_SRESET) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 346 | serial_putc('b'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 347 | bfin_write_EBIU_RSTCTL(bfin_read_EBIU_RSTCTL() | SRREQ); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 348 | return true; |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 349 | } |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 350 | #elif defined(EBIU_SDGCTL) |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 351 | if (bfin_read_EBIU_SDBCTL() & EBE) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 352 | serial_putc('b'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 353 | bfin_write_EBIU_SDGCTL(bfin_read_EBIU_SDGCTL() | SRFS); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 354 | return true; |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 355 | } |
| 356 | #endif |
| 357 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 358 | serial_putc('c'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 359 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 360 | return false; |
| 361 | } |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 362 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 363 | __attribute__((always_inline)) static inline u16 |
| 364 | program_clocks(ADI_BOOT_DATA *bs, bool put_into_srfs) |
| 365 | { |
| 366 | u16 vr_ctl; |
| 367 | |
| 368 | serial_putc('a'); |
| 369 | |
| 370 | vr_ctl = bfin_read_VR_CTL(); |
| 371 | |
| 372 | serial_putc('b'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 373 | |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 374 | /* If we're entering self refresh, make sure it has happened. */ |
| 375 | if (put_into_srfs) |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 376 | #if defined(EBIU_RSTCTL) |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 377 | while (!(bfin_read_EBIU_RSTCTL() & SRACK)) |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 378 | continue; |
| 379 | #elif defined(EBIU_SDGCTL) |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 380 | while (!(bfin_read_EBIU_SDSTAT() & SDSRA)) |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 381 | continue; |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 382 | #else |
| 383 | ; |
| 384 | #endif |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 385 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 386 | serial_putc('c'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 387 | |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 388 | /* With newer bootroms, we use the helper function to set up |
| 389 | * the memory controller. Older bootroms lacks such helpers |
| 390 | * so we do it ourselves. |
| 391 | */ |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 392 | if (!ANOMALY_05000386) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 393 | serial_putc('d'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 394 | |
Mike Frysinger | e8aea4a | 2009-04-04 08:29:55 -0400 | [diff] [blame] | 395 | /* Always programming PLL_LOCKCNT avoids Anomaly 05000430 */ |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 396 | ADI_SYSCTRL_VALUES memory_settings; |
Mike Frysinger | b91d7d9 | 2010-10-14 14:29:17 -0400 | [diff] [blame] | 397 | uint32_t actions = SYSCTRL_WRITE | SYSCTRL_PLLCTL | SYSCTRL_LOCKCNT; |
| 398 | if (!ANOMALY_05000440) |
| 399 | actions |= SYSCTRL_PLLDIV; |
Mike Frysinger | 446d570 | 2008-10-11 21:56:08 -0400 | [diff] [blame] | 400 | if (CONFIG_HAS_VR) { |
| 401 | actions |= SYSCTRL_VRCTL; |
| 402 | if (CONFIG_VR_CTL_VAL & FREQ_MASK) |
| 403 | actions |= SYSCTRL_INTVOLTAGE; |
| 404 | else |
| 405 | actions |= SYSCTRL_EXTVOLTAGE; |
| 406 | memory_settings.uwVrCtl = CONFIG_VR_CTL_VAL; |
| 407 | } else |
| 408 | actions |= SYSCTRL_EXTVOLTAGE; |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 409 | memory_settings.uwPllCtl = CONFIG_PLL_CTL_VAL; |
| 410 | memory_settings.uwPllDiv = CONFIG_PLL_DIV_VAL; |
| 411 | memory_settings.uwPllLockCnt = CONFIG_PLL_LOCKCNT_VAL; |
Mike Frysinger | f9d004b | 2008-12-06 18:06:58 -0500 | [diff] [blame] | 412 | #if ANOMALY_05000432 |
| 413 | bfin_write_SIC_IWR1(0); |
| 414 | #endif |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 415 | serial_putc('e'); |
Mike Frysinger | 446d570 | 2008-10-11 21:56:08 -0400 | [diff] [blame] | 416 | bfrom_SysControl(actions, &memory_settings, NULL); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 417 | serial_putc('f'); |
Mike Frysinger | b91d7d9 | 2010-10-14 14:29:17 -0400 | [diff] [blame] | 418 | if (ANOMALY_05000440) |
| 419 | bfin_write_PLL_DIV(CONFIG_PLL_DIV_VAL); |
Mike Frysinger | f9d004b | 2008-12-06 18:06:58 -0500 | [diff] [blame] | 420 | #if ANOMALY_05000432 |
| 421 | bfin_write_SIC_IWR1(-1); |
| 422 | #endif |
Mike Frysinger | 1f1ac0a | 2009-04-04 08:09:24 -0400 | [diff] [blame] | 423 | #if ANOMALY_05000171 |
| 424 | bfin_write_SICA_IWR0(-1); |
| 425 | bfin_write_SICA_IWR1(-1); |
| 426 | #endif |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 427 | serial_putc('g'); |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 428 | } else { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 429 | serial_putc('h'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 430 | |
| 431 | /* Disable all peripheral wakeups except for the PLL event. */ |
| 432 | #ifdef SIC_IWR0 |
| 433 | bfin_write_SIC_IWR0(1); |
| 434 | bfin_write_SIC_IWR1(0); |
| 435 | # ifdef SIC_IWR2 |
| 436 | bfin_write_SIC_IWR2(0); |
| 437 | # endif |
| 438 | #elif defined(SICA_IWR0) |
| 439 | bfin_write_SICA_IWR0(1); |
| 440 | bfin_write_SICA_IWR1(0); |
| 441 | #else |
| 442 | bfin_write_SIC_IWR(1); |
| 443 | #endif |
| 444 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 445 | serial_putc('i'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 446 | |
Mike Frysinger | e8aea4a | 2009-04-04 08:29:55 -0400 | [diff] [blame] | 447 | /* Always programming PLL_LOCKCNT avoids Anomaly 05000430 */ |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 448 | bfin_write_PLL_LOCKCNT(CONFIG_PLL_LOCKCNT_VAL); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 449 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 450 | serial_putc('j'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 451 | |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 452 | /* Only reprogram when needed to avoid triggering unnecessary |
| 453 | * PLL relock sequences. |
| 454 | */ |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 455 | if (vr_ctl != CONFIG_VR_CTL_VAL) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 456 | serial_putc('?'); |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 457 | bfin_write_VR_CTL(CONFIG_VR_CTL_VAL); |
| 458 | asm("idle;"); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 459 | serial_putc('!'); |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 460 | } |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 461 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 462 | serial_putc('k'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 463 | |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 464 | bfin_write_PLL_DIV(CONFIG_PLL_DIV_VAL); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 465 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 466 | serial_putc('l'); |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 467 | |
| 468 | /* Only reprogram when needed to avoid triggering unnecessary |
| 469 | * PLL relock sequences. |
| 470 | */ |
Mike Frysinger | 43ed696 | 2009-04-04 08:10:22 -0400 | [diff] [blame] | 471 | if (ANOMALY_05000242 || bfin_read_PLL_CTL() != CONFIG_PLL_CTL_VAL) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 472 | serial_putc('?'); |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 473 | bfin_write_PLL_CTL(CONFIG_PLL_CTL_VAL); |
| 474 | asm("idle;"); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 475 | serial_putc('!'); |
Mike Frysinger | 1114d0e | 2008-06-01 01:29:57 -0400 | [diff] [blame] | 476 | } |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 477 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 478 | serial_putc('m'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 479 | |
| 480 | /* Restore all peripheral wakeups. */ |
| 481 | #ifdef SIC_IWR0 |
| 482 | bfin_write_SIC_IWR0(-1); |
| 483 | bfin_write_SIC_IWR1(-1); |
| 484 | # ifdef SIC_IWR2 |
| 485 | bfin_write_SIC_IWR2(-1); |
| 486 | # endif |
| 487 | #elif defined(SICA_IWR0) |
| 488 | bfin_write_SICA_IWR0(-1); |
| 489 | bfin_write_SICA_IWR1(-1); |
| 490 | #else |
| 491 | bfin_write_SIC_IWR(-1); |
| 492 | #endif |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 493 | |
| 494 | serial_putc('n'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 497 | serial_putc('o'); |
| 498 | |
| 499 | return vr_ctl; |
| 500 | } |
| 501 | |
| 502 | __attribute__((always_inline)) static inline void |
| 503 | update_serial_clocks(ADI_BOOT_DATA *bs, uint sdivB, uint divB, uint vcoB) |
| 504 | { |
| 505 | serial_putc('a'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 506 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 507 | /* Since we've changed the SCLK above, we may need to update |
| 508 | * the UART divisors (UART baud rates are based on SCLK). |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 509 | * Do the division by hand as there are no native instructions |
| 510 | * for dividing which means we'd generate a libgcc reference. |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 511 | */ |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 512 | if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_UART) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 513 | serial_putc('b'); |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 514 | unsigned int sdivR, vcoR; |
| 515 | sdivR = bfin_read_PLL_DIV() & 0xf; |
| 516 | vcoR = (bfin_read_PLL_CTL() >> 9) & 0x3f; |
| 517 | int dividend = sdivB * divB * vcoR; |
| 518 | int divisor = vcoB * sdivR; |
| 519 | unsigned int quotient; |
| 520 | for (quotient = 0; dividend > 0; ++quotient) |
| 521 | dividend -= divisor; |
| 522 | serial_early_put_div(quotient - ANOMALY_05000230); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 523 | serial_putc('c'); |
Mike Frysinger | 8445130 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 524 | } |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 525 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 526 | serial_putc('d'); |
| 527 | } |
| 528 | |
| 529 | __attribute__((always_inline)) static inline void |
| 530 | program_memory_controller(ADI_BOOT_DATA *bs, bool put_into_srfs) |
| 531 | { |
| 532 | serial_putc('a'); |
| 533 | |
| 534 | if (!CONFIG_MEM_SIZE) |
| 535 | return; |
| 536 | |
| 537 | serial_putc('b'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 538 | |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 539 | /* Program the external memory controller before we come out of |
| 540 | * self-refresh. This only works with our SDRAM controller. |
| 541 | */ |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 542 | #ifdef EBIU_SDGCTL |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 543 | # ifdef CONFIG_EBIU_SDRRC_VAL |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 544 | bfin_write_EBIU_SDRRC(CONFIG_EBIU_SDRRC_VAL); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 545 | # endif |
| 546 | # ifdef CONFIG_EBIU_SDBCTL_VAL |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 547 | bfin_write_EBIU_SDBCTL(CONFIG_EBIU_SDBCTL_VAL); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 548 | # endif |
| 549 | # ifdef CONFIG_EBIU_SDGCTL_VAL |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 550 | bfin_write_EBIU_SDGCTL(CONFIG_EBIU_SDGCTL_VAL); |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 551 | # endif |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 552 | #endif |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 553 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 554 | serial_putc('c'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 555 | |
| 556 | /* Now that we've reprogrammed, take things out of self refresh. */ |
| 557 | if (put_into_srfs) |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 558 | #if defined(EBIU_RSTCTL) |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 559 | bfin_write_EBIU_RSTCTL(bfin_read_EBIU_RSTCTL() & ~(SRREQ)); |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 560 | #elif defined(EBIU_SDGCTL) |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 561 | bfin_write_EBIU_SDGCTL(bfin_read_EBIU_SDGCTL() & ~(SRFS)); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 562 | #endif |
| 563 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 564 | serial_putc('d'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 565 | |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 566 | /* Our DDR controller sucks and cannot be programmed while in |
| 567 | * self-refresh. So we have to pull it out before programming. |
| 568 | */ |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 569 | #ifdef EBIU_RSTCTL |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 570 | # ifdef CONFIG_EBIU_RSTCTL_VAL |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 571 | bfin_write_EBIU_RSTCTL(bfin_read_EBIU_RSTCTL() | 0x1 /*DDRSRESET*/ | CONFIG_EBIU_RSTCTL_VAL); |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 572 | # endif |
| 573 | # ifdef CONFIG_EBIU_DDRCTL0_VAL |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 574 | bfin_write_EBIU_DDRCTL0(CONFIG_EBIU_DDRCTL0_VAL); |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 575 | # endif |
| 576 | # ifdef CONFIG_EBIU_DDRCTL1_VAL |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 577 | bfin_write_EBIU_DDRCTL1(CONFIG_EBIU_DDRCTL1_VAL); |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 578 | # endif |
| 579 | # ifdef CONFIG_EBIU_DDRCTL2_VAL |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 580 | bfin_write_EBIU_DDRCTL2(CONFIG_EBIU_DDRCTL2_VAL); |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 581 | # endif |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 582 | # ifdef CONFIG_EBIU_DDRCTL3_VAL |
| 583 | /* default is disable, so don't need to force this */ |
| 584 | bfin_write_EBIU_DDRCTL3(CONFIG_EBIU_DDRCTL3_VAL); |
| 585 | # endif |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 586 | # ifdef CONFIG_EBIU_DDRQUE_VAL |
| 587 | bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE() | CONFIG_EBIU_DDRQUE_VAL); |
| 588 | # endif |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 589 | #endif |
| 590 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 591 | serial_putc('e'); |
| 592 | } |
| 593 | |
| 594 | __attribute__((always_inline)) static inline void |
| 595 | check_hibernation(ADI_BOOT_DATA *bs, u16 vr_ctl, bool put_into_srfs) |
| 596 | { |
| 597 | serial_putc('a'); |
| 598 | |
| 599 | if (!CONFIG_MEM_SIZE) |
| 600 | return; |
| 601 | |
| 602 | serial_putc('b'); |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 603 | |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 604 | /* Are we coming out of hibernate (suspend to memory) ? |
| 605 | * The memory layout is: |
| 606 | * 0x0: hibernate magic for anomaly 307 (0xDEADBEEF) |
| 607 | * 0x4: return address |
| 608 | * 0x8: stack pointer |
| 609 | * |
| 610 | * SCKELOW is unreliable on older parts (anomaly 307) |
| 611 | */ |
| 612 | if (ANOMALY_05000307 || vr_ctl & 0x8000) { |
| 613 | uint32_t *hibernate_magic = 0; |
| 614 | __builtin_bfin_ssync(); /* make sure memory controller is done */ |
| 615 | if (hibernate_magic[0] == 0xDEADBEEF) { |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 616 | serial_putc('c'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 617 | bfin_write_EVT15(hibernate_magic[1]); |
| 618 | bfin_write_IMASK(EVT_IVG15); |
| 619 | __asm__ __volatile__ ( |
| 620 | /* load reti early to avoid anomaly 281 */ |
| 621 | "reti = %0;" |
| 622 | /* clear hibernate magic */ |
| 623 | "[%0] = %1;" |
| 624 | /* load stack pointer */ |
| 625 | "SP = [%0 + 8];" |
| 626 | /* lower ourselves from reset ivg to ivg15 */ |
| 627 | "raise 15;" |
| 628 | "rti;" |
| 629 | : |
| 630 | : "p"(hibernate_magic), "d"(0x2000 /* jump.s 0 */) |
| 631 | ); |
| 632 | } |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 633 | serial_putc('d'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 636 | serial_putc('e'); |
| 637 | } |
| 638 | |
| 639 | __attribute__((always_inline)) static inline void |
| 640 | program_async_controller(ADI_BOOT_DATA *bs) |
| 641 | { |
| 642 | serial_putc('a'); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 643 | |
| 644 | /* Program the async banks controller. */ |
| 645 | bfin_write_EBIU_AMBCTL0(CONFIG_EBIU_AMBCTL0_VAL); |
| 646 | bfin_write_EBIU_AMBCTL1(CONFIG_EBIU_AMBCTL1_VAL); |
| 647 | bfin_write_EBIU_AMGCTL(CONFIG_EBIU_AMGCTL_VAL); |
| 648 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 649 | serial_putc('b'); |
| 650 | |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 651 | /* Not all parts have these additional MMRs. */ |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 652 | #ifdef EBIU_MBSCTL |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 653 | bfin_write_EBIU_MBSCTL(CONFIG_EBIU_MBSCTL_VAL); |
Mike Frysinger | 134db0d | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 654 | #endif |
| 655 | #ifdef EBIU_MODE |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 656 | # ifdef CONFIG_EBIU_MODE_VAL |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 657 | bfin_write_EBIU_MODE(CONFIG_EBIU_MODE_VAL); |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 658 | # endif |
| 659 | # ifdef CONFIG_EBIU_FCTL_VAL |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 660 | bfin_write_EBIU_FCTL(CONFIG_EBIU_FCTL_VAL); |
Mike Frysinger | 4368ea2 | 2009-11-09 19:38:23 -0500 | [diff] [blame] | 661 | # endif |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 662 | #endif |
| 663 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 664 | serial_putc('c'); |
| 665 | } |
| 666 | |
| 667 | BOOTROM_CALLED_FUNC_ATTR |
| 668 | void initcode(ADI_BOOT_DATA *bs) |
| 669 | { |
| 670 | ADI_BOOT_DATA bootstruct_scratch; |
| 671 | |
Mike Frysinger | eb2a399 | 2010-05-05 02:07:44 -0400 | [diff] [blame] | 672 | /* Setup NMI handler before anything else */ |
| 673 | program_nmi_handler(); |
| 674 | |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 675 | serial_init(); |
| 676 | |
| 677 | serial_putc('A'); |
| 678 | |
| 679 | /* If the bootstruct is NULL, then it's because we're loading |
| 680 | * dynamically and not via LDR (bootrom). So set the struct to |
| 681 | * some scratch space. |
| 682 | */ |
| 683 | if (!bs) |
| 684 | bs = &bootstruct_scratch; |
| 685 | |
| 686 | serial_putc('B'); |
| 687 | bool put_into_srfs = maybe_self_refresh(bs); |
| 688 | |
| 689 | serial_putc('C'); |
| 690 | uint sdivB, divB, vcoB; |
| 691 | program_early_devices(bs, &sdivB, &divB, &vcoB); |
| 692 | |
| 693 | serial_putc('D'); |
| 694 | u16 vr_ctl = program_clocks(bs, put_into_srfs); |
| 695 | |
| 696 | serial_putc('E'); |
| 697 | update_serial_clocks(bs, sdivB, divB, vcoB); |
| 698 | |
| 699 | serial_putc('F'); |
| 700 | program_memory_controller(bs, put_into_srfs); |
| 701 | |
| 702 | serial_putc('G'); |
| 703 | check_hibernation(bs, vr_ctl, put_into_srfs); |
| 704 | |
| 705 | serial_putc('H'); |
| 706 | program_async_controller(bs); |
Mike Frysinger | 268dbf5 | 2008-10-11 21:58:33 -0400 | [diff] [blame] | 707 | |
Mike Frysinger | a48e0ed | 2009-04-24 23:39:41 -0400 | [diff] [blame] | 708 | #ifdef CONFIG_BFIN_BOOTROM_USES_EVT1 |
Mike Frysinger | 3343bfa | 2009-11-09 19:44:04 -0500 | [diff] [blame] | 709 | serial_putc('I'); |
Mike Frysinger | 1100b69 | 2010-04-29 02:49:41 -0400 | [diff] [blame] | 710 | /* Tell the bootrom where our entry point is so that it knows |
| 711 | * where to jump to when finishing processing the LDR. This |
| 712 | * allows us to avoid small jump blocks in the LDR, and also |
| 713 | * works around anomaly 05000389 (init address in external |
| 714 | * memory causes bootrom to trigger external addressing IVHW). |
| 715 | */ |
Mike Frysinger | 9959368 | 2008-10-18 04:04:49 -0400 | [diff] [blame] | 716 | if (CONFIG_BFIN_BOOT_MODE != BFIN_BOOT_BYPASS) |
| 717 | bfin_write_EVT1(CONFIG_SYS_MONITOR_BASE); |
Mike Frysinger | a48e0ed | 2009-04-24 23:39:41 -0400 | [diff] [blame] | 718 | #endif |
Mike Frysinger | 9959368 | 2008-10-18 04:04:49 -0400 | [diff] [blame] | 719 | |
Mike Frysinger | 94bae5c | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 720 | serial_putc('>'); |
| 721 | serial_putc('\n'); |
| 722 | |
| 723 | serial_deinit(); |
| 724 | } |