blob: 8694ca2c2ca6c612d446ecd0fc99a69e8409c68c [file] [log] [blame]
Aubrey.Li3f0606a2007-03-09 13:38:44 +08001#define ASSEMBLY
2
3#include <linux/config.h>
4#include <config.h>
5#include <asm/blackfin.h>
6#include <asm/mem_init.h>
Mike Frysingerd4d77302008-02-04 19:26:55 -05007#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.Li3f0606a2007-03-09 13:38:44 +080011.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
29init_sdram:
30 [--SP] = ASTAT;
31 [--SP] = RETS;
32 [--SP] = (R7:0);
33 [--SP] = (P5:0);
34
Aubrey Li8db13d62007-03-10 23:49:29 +080035#if (BFIN_BOOT_MODE == BF533_SPI_BOOT)
Aubrey.Li3f0606a2007-03-09 13:38:44 +080036 p0.h = hi(SPI_BAUD);
37 p0.l = lo(SPI_BAUD);
38 r0.l = CONFIG_SPI_BAUD_INITBLOCK;
39 w[p0] = r0.l;
Aubrey Li8db13d62007-03-10 23:49:29 +080040 SSYNC;
Aubrey.Li3f0606a2007-03-09 13:38:44 +080041#endif
42
43 /*
Aubrey Li8db13d62007-03-10 23:49:29 +080044 * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable
45 */
Aubrey.Li3f0606a2007-03-09 13:38:44 +080046 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 Li8db13d62007-03-10 23:49:29 +080053 * 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.Li3f0606a2007-03-09 13:38:44 +080061
Aubrey Li8db13d62007-03-10 23:49:29 +080062 /*
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.Li3f0606a2007-03-09 13:38:44 +080074
Aubrey Li8db13d62007-03-10 23:49:29 +080075 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.Li3f0606a2007-03-09 13:38:44 +080082
Aubrey Li8db13d62007-03-10 23:49:29 +080083 p0.h = hi(PLL_CTL);
84 p0.l = lo(PLL_CTL); /* Load the address */
85 cli r2; /* Disable interrupts */
Aubrey.Li3f0606a2007-03-09 13:38:44 +080086 ssync;
Aubrey Li8db13d62007-03-10 23:49:29 +080087 w[p0] = r0.l; /* Set the value */
88 idle; /* Wait for the PLL to stablize */
89 sti r2; /* Enable interrupts */
Aubrey.Li3f0606a2007-03-09 13:38:44 +080090
91check_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 Li8db13d62007-03-10 23:49:29 +080099 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.Li3f0606a2007-03-09 13:38:44 +0800104
105 /*
Aubrey Li8db13d62007-03-10 23:49:29 +0800106 * We now are running at speed, time to set the Async mem bank wait states
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800107 * This will speed up execution, since we are normally running from FLASH.
108 */
109
Aubrey Li8db13d62007-03-10 23:49:29 +0800110 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 Li8440bb12007-03-12 00:25:14 +0800116
Aubrey Li8db13d62007-03-10 23:49:29 +0800117 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 Li8440bb12007-03-12 00:25:14 +0800123
Aubrey Li8db13d62007-03-10 23:49:29 +0800124 p2.h = (EBIU_AMGCTL >> 16);
125 p2.l = (EBIU_AMGCTL & 0xffff);
126 r0 = AMGCTLVAL;
127 w[p2] = r0;
128 ssync;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800129
130 /*
131 * Now, Initialize the SDRAM,
132 * start with the SDRAM Refresh Rate Control Register
Aubrey Li8db13d62007-03-10 23:49:29 +0800133 */
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800134 p0.l = lo(EBIU_SDRRC);
Aubrey Li8db13d62007-03-10 23:49:29 +0800135 p0.h = hi(EBIU_SDRRC);
136 r0 = mem_SDRRC;
137 w[p0] = r0.l;
138 ssync;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800139
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 Li8db13d62007-03-10 23:49:29 +0800154 P2.L = lo(EBIU_SDGCTL);
155 R0 = [P2];
156 BITCLR (R0, 24);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800157
158 /*
Aubrey Li8db13d62007-03-10 23:49:29 +0800159 * Check if SDRAM is already powered up, if it is, enable self-refresh
160 */
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800161 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 Li8db13d62007-03-10 23:49:29 +0800166 NOP;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800167 BITSET (R0, 23);
168skip:
169 [P2] = R0;
Aubrey Li8db13d62007-03-10 23:49:29 +0800170 SSYNC;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800171
172 /* Write in the new value in the register */
Aubrey Li8db13d62007-03-10 23:49:29 +0800173 R0.L = lo(mem_SDGCTL);
174 R0.H = hi(mem_SDGCTL);
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800175 [P2] = R0;
Aubrey Li8db13d62007-03-10 23:49:29 +0800176 SSYNC;
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800177 nop;
178
Aubrey.Li3f0606a2007-03-09 13:38:44 +0800179 (P5:0) = [SP++];
180 (R7:0) = [SP++];
181 RETS = [SP++];
182 ASTAT = [SP++];
183 RTS;