Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 1 | #define ASSEMBLY |
| 2 | |
| 3 | #include <linux/config.h> |
| 4 | #include <config.h> |
| 5 | #include <asm/blackfin.h> |
| 6 | #include <asm/mem_init.h> |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 7 | #include <asm/mach-common/bits/bootrom.h> |
| 8 | #include <asm/mach-common/bits/ebiu.h> |
| 9 | #include <asm/mach-common/bits/pll.h> |
| 10 | #include <asm/mach-common/bits/uart.h> |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 11 | .global init_sdram; |
| 12 | |
| 13 | #if (CONFIG_CCLK_DIV == 1) |
| 14 | #define CONFIG_CCLK_ACT_DIV CCLK_DIV1 |
| 15 | #endif |
| 16 | #if (CONFIG_CCLK_DIV == 2) |
| 17 | #define CONFIG_CCLK_ACT_DIV CCLK_DIV2 |
| 18 | #endif |
| 19 | #if (CONFIG_CCLK_DIV == 4) |
| 20 | #define CONFIG_CCLK_ACT_DIV CCLK_DIV4 |
| 21 | #endif |
| 22 | #if (CONFIG_CCLK_DIV == 8) |
| 23 | #define CONFIG_CCLK_ACT_DIV CCLK_DIV8 |
| 24 | #endif |
| 25 | #ifndef CONFIG_CCLK_ACT_DIV |
| 26 | #define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly |
| 27 | #endif |
| 28 | |
| 29 | init_sdram: |
| 30 | [--SP] = ASTAT; |
| 31 | [--SP] = RETS; |
| 32 | [--SP] = (R7:0); |
| 33 | [--SP] = (P5:0); |
| 34 | |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 35 | #if (BFIN_BOOT_MODE == BF533_SPI_BOOT) |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 36 | p0.h = hi(SPI_BAUD); |
| 37 | p0.l = lo(SPI_BAUD); |
| 38 | r0.l = CONFIG_SPI_BAUD; |
| 39 | w[p0] = r0.l; |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 40 | SSYNC; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 41 | #endif |
| 42 | |
| 43 | /* |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 44 | * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable |
| 45 | */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 46 | p0.h = hi(PLL_LOCKCNT); |
| 47 | p0.l = lo(PLL_LOCKCNT); |
| 48 | r0 = 0x300(Z); |
| 49 | w[p0] = r0.l; |
| 50 | ssync; |
| 51 | |
| 52 | /* |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 53 | * Put SDRAM in self-refresh, incase anything is running |
| 54 | */ |
| 55 | P2.H = hi(EBIU_SDGCTL); |
| 56 | P2.L = lo(EBIU_SDGCTL); |
| 57 | R0 = [P2]; |
| 58 | BITSET (R0, 24); |
| 59 | [P2] = R0; |
| 60 | SSYNC; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 61 | |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 62 | /* |
| 63 | * Set PLL_CTL with the value that we calculate in R0 |
| 64 | * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors |
| 65 | * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK |
| 66 | * - [7] = output delay (add 200ps of delay to mem signals) |
| 67 | * - [6] = input delay (add 200ps of input delay to mem signals) |
| 68 | * - [5] = PDWN : 1=All Clocks off |
| 69 | * - [3] = STOPCK : 1=Core Clock off |
| 70 | * - [1] = PLL_OFF : 1=Disable Power to PLL |
| 71 | * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL |
| 72 | * all other bits set to zero |
| 73 | */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 74 | |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 75 | r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */ |
| 76 | r0 = r0 << 9; /* Shift it over, */ |
| 77 | r1 = CONFIG_CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/ |
| 78 | r0 = r1 | r0; |
| 79 | r1 = CONFIG_PLL_BYPASS; /* Bypass the PLL? */ |
| 80 | r1 = r1 << 8; /* Shift it over */ |
| 81 | r0 = r1 | r0; /* add them all together */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 82 | |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 83 | p0.h = hi(PLL_CTL); |
| 84 | p0.l = lo(PLL_CTL); /* Load the address */ |
| 85 | cli r2; /* Disable interrupts */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 86 | ssync; |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 87 | w[p0] = r0.l; /* Set the value */ |
| 88 | idle; /* Wait for the PLL to stablize */ |
| 89 | sti r2; /* Enable interrupts */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 90 | |
| 91 | check_again: |
| 92 | p0.h = hi(PLL_STAT); |
| 93 | p0.l = lo(PLL_STAT); |
| 94 | R0 = W[P0](Z); |
| 95 | CC = BITTST(R0,5); |
| 96 | if ! CC jump check_again; |
| 97 | |
| 98 | /* Configure SCLK & CCLK Dividers */ |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 99 | r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV); |
| 100 | p0.h = hi(PLL_DIV); |
| 101 | p0.l = lo(PLL_DIV); |
| 102 | w[p0] = r0.l; |
| 103 | ssync; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 104 | |
| 105 | /* |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 106 | * We now are running at speed, time to set the Async mem bank wait states |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 107 | * This will speed up execution, since we are normally running from FLASH. |
| 108 | */ |
| 109 | |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 110 | p2.h = (EBIU_AMBCTL1 >> 16); |
| 111 | p2.l = (EBIU_AMBCTL1 & 0xFFFF); |
| 112 | r0.h = (AMBCTL1VAL >> 16); |
| 113 | r0.l = (AMBCTL1VAL & 0xFFFF); |
| 114 | [p2] = r0; |
| 115 | ssync; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 116 | |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 117 | p2.h = (EBIU_AMBCTL0 >> 16); |
| 118 | p2.l = (EBIU_AMBCTL0 & 0xFFFF); |
| 119 | r0.h = (AMBCTL0VAL >> 16); |
| 120 | r0.l = (AMBCTL0VAL & 0xFFFF); |
| 121 | [p2] = r0; |
| 122 | ssync; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 123 | |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 124 | p2.h = (EBIU_AMGCTL >> 16); |
| 125 | p2.l = (EBIU_AMGCTL & 0xffff); |
| 126 | r0 = AMGCTLVAL; |
| 127 | w[p2] = r0; |
| 128 | ssync; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * Now, Initialize the SDRAM, |
| 132 | * start with the SDRAM Refresh Rate Control Register |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 133 | */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 134 | p0.l = lo(EBIU_SDRRC); |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 135 | p0.h = hi(EBIU_SDRRC); |
| 136 | r0 = mem_SDRRC; |
| 137 | w[p0] = r0.l; |
| 138 | ssync; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | * SDRAM Memory Bank Control Register - bank specific parameters |
| 142 | */ |
| 143 | p0.l = (EBIU_SDBCTL & 0xFFFF); |
| 144 | p0.h = (EBIU_SDBCTL >> 16); |
| 145 | r0 = mem_SDBCTL; |
| 146 | w[p0] = r0.l; |
| 147 | ssync; |
| 148 | |
| 149 | /* |
| 150 | * SDRAM Global Control Register - global programmable parameters |
| 151 | * Disable self-refresh |
| 152 | */ |
| 153 | P2.H = hi(EBIU_SDGCTL); |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 154 | P2.L = lo(EBIU_SDGCTL); |
| 155 | R0 = [P2]; |
| 156 | BITCLR (R0, 24); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 157 | |
| 158 | /* |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 159 | * Check if SDRAM is already powered up, if it is, enable self-refresh |
| 160 | */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 161 | p0.h = hi(EBIU_SDSTAT); |
| 162 | p0.l = lo(EBIU_SDSTAT); |
| 163 | r2.l = w[p0]; |
| 164 | cc = bittst(r2,3); |
| 165 | if !cc jump skip; |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 166 | NOP; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 167 | BITSET (R0, 23); |
| 168 | skip: |
| 169 | [P2] = R0; |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 170 | SSYNC; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 171 | |
| 172 | /* Write in the new value in the register */ |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 173 | R0.L = lo(mem_SDGCTL); |
| 174 | R0.H = hi(mem_SDGCTL); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 175 | [P2] = R0; |
Aubrey Li | 8db13d6 | 2007-03-10 23:49:29 +0800 | [diff] [blame] | 176 | SSYNC; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 177 | nop; |
| 178 | |
| 179 | (P5:0) = [SP++]; |
| 180 | (R7:0) = [SP++]; |
| 181 | RETS = [SP++]; |
| 182 | ASTAT = [SP++]; |
| 183 | RTS; |