Merge branch 'master' of /home/git/u-boot
[oweals/u-boot.git] / cpu / bf561 / init_sdram_bootrom_initblock.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
36         p0.h = hi(SICA_IWR0);
37         p0.l = lo(SICA_IWR0);
38         r0.l = 0x1;
39         w[p0] = r0.l;
40         SSYNC;
41
42         p0.h = hi(SPI_BAUD);
43         p0.l = lo(SPI_BAUD);
44         r0.l = CONFIG_SPI_BAUD_INITBLOCK;
45         w[p0] = r0.l;
46         SSYNC;
47
48         /*
49          * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable
50          */
51         p0.h = hi(PLL_LOCKCNT);
52         p0.l = lo(PLL_LOCKCNT);
53         r0 = 0x300(Z);
54         w[p0] = r0.l;
55         ssync;
56
57         /*
58          * Put SDRAM in self-refresh, incase anything is running
59          */
60         P2.H = hi(EBIU_SDGCTL);
61         P2.L = lo(EBIU_SDGCTL);
62         R0 = [P2];
63         BITSET (R0, 24);
64         [P2] = R0;
65         SSYNC;
66
67         /*
68          *  Set PLL_CTL with the value that we calculate in R0
69          *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
70          *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK
71          *   - [7]     = output delay (add 200ps of delay to mem signals)
72          *   - [6]     = input delay (add 200ps of input delay to mem signals)
73          *   - [5]     = PDWN      : 1=All Clocks off
74          *   - [3]     = STOPCK    : 1=Core Clock off
75          *   - [1]     = PLL_OFF   : 1=Disable Power to PLL
76          *   - [0]     = DF        : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
77          *   all other bits set to zero
78          */
79
80         r0 = CONFIG_VCO_MULT & 63;      /* Load the VCO multiplier */
81         r0 = r0 << 9;                   /* Shift it over, */
82         r1 = CONFIG_CLKIN_HALF;         /* Do we need to divide CLKIN by 2? */
83         r0 = r1 | r0;
84         r1 = CONFIG_PLL_BYPASS;         /* Bypass the PLL? */
85         r1 = r1 << 8;                   /* Shift it over */
86         r0 = r1 | r0;                   /* add them all together */
87
88         p0.h = hi(PLL_CTL);
89         p0.l = lo(PLL_CTL);             /* Load the address */
90         cli r2;                         /* Disable interrupts */
91         ssync;
92         w[p0] = r0.l;                   /* Set the value */
93         idle;                           /* Wait for the PLL to stablize */
94         sti r2;                         /* Enable interrupts */
95
96 check_again:
97         p0.h = hi(PLL_STAT);
98         p0.l = lo(PLL_STAT);
99         R0 = W[P0](Z);
100         CC = BITTST(R0,5);
101         if ! CC jump check_again;
102
103         /* Configure SCLK & CCLK Dividers */
104         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
105         p0.h = hi(PLL_DIV);
106         p0.l = lo(PLL_DIV);
107         w[p0] = r0.l;
108         ssync;
109
110         /*
111          * We now are running at speed, time to set the Async mem bank wait states
112          * This will speed up execution, since we are normally running from FLASH.
113          */
114
115         p2.h = (EBIU_AMBCTL1 >> 16);
116         p2.l = (EBIU_AMBCTL1 & 0xFFFF);
117         r0.h = (AMBCTL1VAL >> 16);
118         r0.l = (AMBCTL1VAL & 0xFFFF);
119         [p2] = r0;
120         ssync;
121
122         p2.h = (EBIU_AMBCTL0 >> 16);
123         p2.l = (EBIU_AMBCTL0 & 0xFFFF);
124         r0.h = (AMBCTL0VAL >> 16);
125         r0.l = (AMBCTL0VAL & 0xFFFF);
126         [p2] = r0;
127         ssync;
128
129         p2.h = (EBIU_AMGCTL >> 16);
130         p2.l = (EBIU_AMGCTL & 0xffff);
131         r0 = AMGCTLVAL;
132         w[p2] = r0;
133         ssync;
134
135         /*
136          * Now, Initialize the SDRAM,
137          * start with the SDRAM Refresh Rate Control Register
138          */
139         p0.l = lo(EBIU_SDRRC);
140         p0.h = hi(EBIU_SDRRC);
141         r0 = mem_SDRRC;
142         w[p0] = r0.l;
143         ssync;
144
145         /*
146          * SDRAM Memory Bank Control Register - bank specific parameters
147          */
148         p0.l = (EBIU_SDBCTL & 0xFFFF);
149         p0.h = (EBIU_SDBCTL >> 16);
150         r0 = mem_SDBCTL;
151         w[p0] = r0.l;
152         ssync;
153
154         /*
155          * SDRAM Global Control Register - global programmable parameters
156          * Disable self-refresh
157          */
158         P2.H = hi(EBIU_SDGCTL);
159         P2.L = lo(EBIU_SDGCTL);
160         R0 = [P2];
161         BITCLR (R0, 24);
162
163         /*
164          * Check if SDRAM is already powered up, if it is, enable self-refresh
165          */
166         p0.h = hi(EBIU_SDSTAT);
167         p0.l = lo(EBIU_SDSTAT);
168         r2.l = w[p0];
169         cc = bittst(r2,3);
170         if !cc jump skip;
171         NOP;
172         BITSET (R0, 23);
173 skip:
174         [P2] = R0;
175         SSYNC;
176
177         /* Write in the new value in the register */
178         R0.L = lo(mem_SDGCTL);
179         R0.H = hi(mem_SDGCTL);
180         [P2] = R0;
181         SSYNC;
182         nop;
183
184
185         (P5:0) = [SP++];
186         (R7:0) = [SP++];
187         RETS   = [SP++];
188         ASTAT  = [SP++];
189         RTS;