Merge branch '080208_dupint' of git://linux-arm.org/u-boot-armdev
[platform/kernel/u-boot.git] / cpu / bf533 / init_sdram.S
1 #define ASSEMBLY
2
3 #include <linux/config.h>
4 #include <config.h>
5 #include <asm/blackfin.h>
6 #include <asm/mem_init.h>
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>
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
35 #if (BFIN_BOOT_MODE == BF533_SPI_BOOT)
36         p0.h = hi(SPI_BAUD);
37         p0.l = lo(SPI_BAUD);
38         r0.l = CONFIG_SPI_BAUD;
39         w[p0] = r0.l;
40         SSYNC;
41 #endif
42
43         /*
44          * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable
45          */
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         /*
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;
61
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          */
74
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           */
82
83         p0.h = hi(PLL_CTL);
84         p0.l = lo(PLL_CTL);             /* Load the address                */
85         cli r2;                         /* Disable interrupts              */
86         ssync;
87         w[p0] = r0.l;                   /* Set the value                   */
88         idle;                           /* Wait for the PLL to stablize    */
89         sti r2;                         /* Enable interrupts               */
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 */
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;
104
105         /*
106          * We now are running at speed, time to set the Async mem bank wait states
107          * This will speed up execution, since we are normally running from FLASH.
108          */
109
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;
116
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;
123
124         p2.h = (EBIU_AMGCTL >> 16);
125         p2.l = (EBIU_AMGCTL & 0xffff);
126         r0 = AMGCTLVAL;
127         w[p2] = r0;
128         ssync;
129
130         /*
131          * Now, Initialize the SDRAM,
132          * start with the SDRAM Refresh Rate Control Register
133          */
134         p0.l = lo(EBIU_SDRRC);
135         p0.h = hi(EBIU_SDRRC);
136         r0 = mem_SDRRC;
137         w[p0] = r0.l;
138         ssync;
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);
154         P2.L = lo(EBIU_SDGCTL);
155         R0 = [P2];
156         BITCLR (R0, 24);
157
158         /*
159          * Check if SDRAM is already powered up, if it is, enable self-refresh
160          */
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;
166         NOP;
167         BITSET (R0, 23);
168 skip:
169         [P2] = R0;
170         SSYNC;
171
172         /* Write in the new value in the register */
173         R0.L = lo(mem_SDGCTL);
174         R0.H = hi(mem_SDGCTL);
175         [P2] = R0;
176         SSYNC;
177         nop;
178
179         (P5:0) = [SP++];
180         (R7:0) = [SP++];
181         RETS   = [SP++];
182         ASTAT  = [SP++];
183         RTS;