]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/bf537/init_sdram.S
Blackfin: BF537-stamp: cleanup spi flash driver
[karo-tx-uboot.git] / cpu / bf537 / 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 (BFIN_BOOT_MODE != BF537_UART_BOOT)
14 #if (CONFIG_CCLK_DIV == 1)
15 #define CONFIG_CCLK_ACT_DIV   CCLK_DIV1
16 #endif
17 #if (CONFIG_CCLK_DIV == 2)
18 #define CONFIG_CCLK_ACT_DIV   CCLK_DIV2
19 #endif
20 #if (CONFIG_CCLK_DIV == 4)
21 #define CONFIG_CCLK_ACT_DIV   CCLK_DIV4
22 #endif
23 #if (CONFIG_CCLK_DIV == 8)
24 #define CONFIG_CCLK_ACT_DIV   CCLK_DIV8
25 #endif
26 #ifndef CONFIG_CCLK_ACT_DIV
27 #define CONFIG_CCLK_ACT_DIV   CONFIG_CCLK_DIV_not_defined_properly
28 #endif
29 #endif
30
31 init_sdram:
32         [--SP] = ASTAT;
33         [--SP] = RETS;
34         [--SP] = (R7:0);
35         [--SP] = (P5:0);
36
37 #if (BFIN_BOOT_MODE == BF537_SPI_MASTER_BOOT)
38         p0.h = hi(SIC_IWR);
39         p0.l = lo(SIC_IWR);
40         r0.l = 0x1;
41         w[p0] = r0.l;
42         SSYNC;
43
44         p0.h = hi(SPI_BAUD);
45         p0.l = lo(SPI_BAUD);
46         r0.l = CONFIG_SPI_BAUD;
47         w[p0] = r0.l;
48         SSYNC;
49 #endif
50
51 #if (BFIN_BOOT_MODE != BF537_UART_BOOT)
52
53 #ifdef CONFIG_BF537
54         /* Enable PHY CLK buffer output */
55         p0.h = hi(VR_CTL);
56         p0.l = lo(VR_CTL);
57         r0.l = w[p0];
58         bitset(r0, 14);
59         w[p0] = r0.l;
60         ssync;
61 #endif
62         /*
63          * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable
64          */
65         p0.h = hi(PLL_LOCKCNT);
66         p0.l = lo(PLL_LOCKCNT);
67         r0 = 0x300(Z);
68         w[p0] = r0.l;
69         ssync;
70
71         /*
72          * Put SDRAM in self-refresh, incase anything is running
73          */
74         P2.H = hi(EBIU_SDGCTL);
75         P2.L = lo(EBIU_SDGCTL);
76         R0 = [P2];
77         BITSET (R0, 24);
78         [P2] = R0;
79         SSYNC;
80
81         /*
82          *  Set PLL_CTL with the value that we calculate in R0
83          *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
84          *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK
85          *   - [7]     = output delay (add 200ps of delay to mem signals)
86          *   - [6]     = input delay (add 200ps of input delay to mem signals)
87          *   - [5]     = PDWN      : 1=All Clocks off
88          *   - [3]     = STOPCK    : 1=Core Clock off
89          *   - [1]     = PLL_OFF   : 1=Disable Power to PLL
90          *   - [0]     = DF     : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
91          *   all other bits set to zero
92          */
93
94         r0 = CONFIG_VCO_MULT & 63;      /* Load the VCO multiplier */
95         r0 = r0 << 9;                   /* Shift it over */
96         r1 = CONFIG_CLKIN_HALF;         /* Do we need to divide CLKIN by 2?*/
97         r0 = r1 | r0;
98         r1 = CONFIG_PLL_BYPASS;         /* Bypass the PLL? */
99         r1 = r1 << 8;                   /* Shift it over */
100         r0 = r1 | r0;                   /* add them all together */
101
102         p0.h = hi(PLL_CTL);
103         p0.l = lo(PLL_CTL);             /* Load the address */
104         cli r2;                         /* Disable interrupts */
105         ssync;
106         w[p0] = r0.l;                   /* Set the value */
107         idle;                           /* Wait for the PLL to stablize */
108         sti r2;                         /* Enable interrupts */
109
110 check_again:
111         p0.h = hi(PLL_STAT);
112         p0.l = lo(PLL_STAT);
113         R0 = W[P0](Z);
114         CC = BITTST(R0,5);
115         if ! CC jump check_again;
116
117         /* Configure SCLK & CCLK Dividers */
118         r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
119         p0.h = hi(PLL_DIV);
120         p0.l = lo(PLL_DIV);
121         w[p0] = r0.l;
122         ssync;
123 #endif
124
125         /*
126          * Now, Initialize the SDRAM,
127          * start with the SDRAM Refresh Rate Control Register
128          */
129         p0.l = lo(EBIU_SDRRC);
130         p0.h = hi(EBIU_SDRRC);
131         r0 = mem_SDRRC;
132         w[p0] = r0.l;
133         ssync;
134
135         /*
136          * SDRAM Memory Bank Control Register - bank specific parameters
137          */
138         p0.l = (EBIU_SDBCTL & 0xFFFF);
139         p0.h = (EBIU_SDBCTL >> 16);
140         r0 = mem_SDBCTL;
141         w[p0] = r0.l;
142         ssync;
143
144         /*
145          * SDRAM Global Control Register - global programmable parameters
146          * Disable self-refresh
147          */
148         P2.H = hi(EBIU_SDGCTL);
149         P2.L = lo(EBIU_SDGCTL);
150         R0 = [P2];
151         BITCLR (R0, 24);
152
153         /*
154          * Check if SDRAM is already powered up, if it is, enable self-refresh
155          */
156         p0.h = hi(EBIU_SDSTAT);
157         p0.l = lo(EBIU_SDSTAT);
158         r2.l = w[p0];
159         cc = bittst(r2,3);
160         if !cc jump skip;
161         NOP;
162         BITSET (R0, 23);
163 skip:
164         [P2] = R0;
165         SSYNC;
166
167         /* Write in the new value in the register */
168         R0.L = lo(mem_SDGCTL);
169         R0.H = hi(mem_SDGCTL);
170         [P2] = R0;
171         SSYNC;
172         nop;
173
174         (P5:0) = [SP++];
175         (R7:0) = [SP++];
176         RETS   = [SP++];
177         ASTAT  = [SP++];
178         RTS;