55eab2e479beb439937751de0dad846579c9fc9e
[kernel/u-boot.git] / board / samsung / universal / lowlevel_init.S
1 /*
2  * Memory Setup stuff - taken from blob memsetup.S
3  *
4  * Copyright (C) 2009 Samsung Electronics
5  * Kyungmin Park <kyungmin.park@samsung.com>
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25
26 #include <config.h>
27 #include <version.h>
28 #include <asm/arch/cpu.h>
29 #include <asm/arch/clock.h>
30 #include <asm/arch/power.h>
31
32 #define DEBUG_PM_C110
33 #undef DEBUG_PM_C110
34
35 /*
36  * Register usages:
37  *
38  * r5 has zero always
39  * r7 has S5PC100 GPIO base, 0xE0300000
40  * r8 has real GPIO base, 0xE0300000, 0xE0200000 at S5PC100, S5PC110 repectively
41  * r9 has Mobile DDR size, 1 means 1GiB, 2 means 2GiB and so on
42  */
43
44 _TEXT_BASE:
45         .word   TEXT_BASE
46
47         .globl lowlevel_init
48 lowlevel_init:
49         mov     r11, lr
50
51         /* r5 has always zero */
52         mov     r5, #0
53
54         ldr     r7, =S5PC100_GPIO_BASE
55         ldr     r8, =S5PC100_GPIO_BASE
56         /* Read CPU ID */
57         ldr     r2, =S5PC1XX_PRO_ID
58         ldr     r0, [r2]
59         mov     r1, #0x00010000
60         and     r0, r0, r1
61         cmp     r0, r5
62         beq     100f
63         ldr     r8, =S5PC110_GPIO_BASE
64 100:
65         /* Turn on KEY_LED_ON [GPJ4(1)] XMSMWEN */
66         cmp     r7, r8
67 #ifndef DEBUG_PM_C110
68         addeq   r0, r8, #0x280                          @S5PC100_GPIO_J4_OFFSET
69         addne   r0, r8, #0x2C0                          @S5PC110_GPIO_J4_OFFSET
70         ldr     r1, [r0, #0x0]                          @S5PC1XX_GPIO_CON_OFFSET
71         bic     r1, r1, #(0xf << 4)                     @ 1 * 4-bit
72         orr     r1, r1, #(0x1 << 4)
73         str     r1, [r0, #0x0]                          @S5PC1XX_GPIO_CON_OFFSET
74
75         ldr     r1, [r0, #0x4]                          @S5PC1XX_GPIO_DAT_OFFSET
76 #ifdef CONFIG_ONENAND_IPL
77         orr     r1, r1, #(1 << 1)                       @ 1 * 1-bit
78 #else
79         bic     r1, r1, #(1 << 1)
80 #endif
81         str     r1, [r0, #0x4]                          @S5PC1XX_GPIO_DAT_OFFSET
82 #endif
83
84         /* IO retension release */
85         ldreq   r0, =S5PC100_OTHERS                     @0xE0108200
86         ldrne   r0, =S5PC110_OTHERS                     @0xE010E000
87         ldr     r1, [r0]
88         ldreq   r2, =(1 << 31)                          @IO_RET_REL
89         ldrne   r2, =((1 << 31) | (1 << 29) | (1 << 28))        @ GPIO, UART_IO
90         orr     r1, r1, r2
91         str     r1, [r0]
92
93 #ifndef CONFIG_ONENAND_IPL
94         /* Disable Watchdog */
95         ldreq   r0, =S5PC100_WATCHDOG_BASE              @0xEA200000
96         ldrne   r0, =S5PC110_WATCHDOG_BASE              @0xE2700000
97         str     r5, [r0]
98
99         /* setting SRAM */
100         ldreq   r0, =S5PC100_SROMC_BASE
101         ldrne   r0, =S5PC110_SROMC_BASE
102         ldr     r1, =0x9
103         str     r1, [r0]
104 #endif
105
106         /* S5PC100 has 3 groups of interrupt sources */
107         ldreq   r0, =S5PC100_VIC0_BASE                  @0xE4000000
108         ldrne   r0, =S5PC110_VIC0_BASE                  @0xF2000000
109         add     r1, r0, #0x00100000
110         add     r2, r0, #0x00200000
111
112         /* Disable all interrupts (VIC0, VIC1 and VIC2) */
113         mvn     r3, #0x0
114         str     r3, [r0, #0x14]                         @INTENCLEAR
115         str     r3, [r1, #0x14]                         @INTENCLEAR
116         str     r3, [r2, #0x14]                         @INTENCLEAR
117
118 #ifndef CONFIG_ONENAND_IPL
119         /* Set all interrupts as IRQ */
120         str     r5, [r0, #0xc]                          @INTSELECT
121         str     r5, [r1, #0xc]                          @INTSELECT
122         str     r5, [r2, #0xc]                          @INTSELECT
123
124         /* Pending Interrupt Clear */
125         str     r5, [r0, #0xf00]                        @INTADDRESS
126         str     r5, [r1, #0xf00]                        @INTADDRESS
127         str     r5, [r2, #0xf00]                        @INTADDRESS
128 #endif
129
130 #ifndef CONFIG_ONENAND_IPL
131         /* for UART */
132         bl      uart_asm_init
133
134         bl      internal_ram_init
135 #endif
136
137 #ifdef CONFIG_ONENAND_IPL
138         /* init system clock */
139         bl      system_clock_init
140
141         /* Board detection to set proper memory configuration */
142         cmp     r7, r8
143         moveq   r9, #1          /* r9 has 1Gib default at s5pc100 */
144         movne   r9, #2          /* r9 has 2Gib default at s5pc110 */
145         /* FIXME 1Gib detection: Limo Universal */
146         /* Check Limo Real board
147          *      LR (suspend)    LU              J1B2
148          * 0x04 0x01 (0x01)     0x01 (0x01)     0x01 (0x01)
149          * 0x24 0x28 (0xA8)     0x28 (0x6A)     0x1C (0x1C)
150          * 0x44 0x00 (0xC7)     0x00 (0x47)     0x00 (0x47)
151          * 0x64 0x03 (0x1F)     0x07 (0x1F)     0x0f (0x0F)
152          *
153          * Check (0 << 3) at 0x64 at boot
154          * Check 0x47 at 0x44 at suspend
155          */
156         ldrne   r2, =0xE0200C00
157         ldrne   r1, [r2, #0x64]
158         and     r1, r1, #(1 << 2)
159         cmp     r1, #(1 << 2)
160         moveq   r9, #1
161         ldr     r1, [r2, #0x44]
162         cmp     r1, #0x47
163         moveq   r9, #1
164         /*
165          * Aquila Rev 0.5 : 4G3G1G x16 for Infineon ES3.1
166          * Aquila Rev 0.6 : 4G1G1G x32 for MSM6290
167          * Aquila Rev 0.7 : 4G2G1G x16 for Infineon ES3.1
168          * Aquila Rev 0.8 : 4G3G1G x16 for Infineon ES3.1
169          */
170         ldr     r2, =0xE0200200
171         ldr     r4, [r2, #0x48]
172         bic     r1, r4, #(0xFF << 2)    /* PULLUP_DISABLE: 4 * 2-bit */
173         str     r1, [r2, #0x48]
174         /* For write completion */
175         nop
176         nop
177
178         ldr     r3, [r2, #0x44]
179         and     r1, r3, #(0xf << 1)
180         cmp     r1, #(0x5 << 2)
181         moveq   r9, #3
182         cmp     r1, #(0x6 << 2)
183         moveq   r9, #1
184         cmp     r1, #(0x7 << 2)
185         moveq   r9, #2
186         cmp     r1, #(0x1 << 1)
187         moveq   r9, #3
188         str     r4, [r2, #0x48]         /* Restore PULLUP configuration */
189
190         bl      mem_ctrl_asm_init
191
192         /* OneNAND Sync Read Support at S5PC110 only
193          * RM[15]       : Sync Read
194          * BRWL[14:12]  : 7 CLK
195          * BL[11:9]     : Continuous
196          * VHF[3]       : Very High Frequency Enable (Over 83MHz)
197          * HF[2]        : High Frequency Enable (Over 66MHz)
198          */
199         cmp     r7, r8
200         ldrne   r1, =0xE00C
201
202         ldrne   r0, =0xB001E442
203         strneh  r1, [r0]
204
205         ldrne   r0, =0xB0600000
206         strne   r1, [r0, #0x100]                        @ ONENAND_IF_CTRL
207
208         /* Wakeup support. Don't know if it's going to be used, untested. */
209         ldreq   r0, =S5PC100_RST_STAT
210         ldrne   r0, =S5PC110_RST_STAT
211         ldr     r1, [r0]
212         biceq   r1, r1, #0xfffffff7
213         moveq   r2, #(1 << 3)
214         bicne   r1, r1, #0xfffeffff
215         movne   r2, #(1 << 16)
216         cmp     r1, r2
217         bne     1f
218 wakeup:
219 #ifdef DEBUG_PM_C110
220         mov     r0, r8
221         ldr     r1, =0x22222222
222         str     r1, [r0, #0x0]                  @S5PC100_GPIO_A0_OFFSET
223         ldr     r1, =0x00002222
224         str     r1, [r0, #0x20]                 @S5PC100_GPIO_A1_OFFSET
225
226         /* UART_SEL MP0_5[7] at S5PC110 */
227         add     r0, r8, #0x360                  @S5PC110_GPIO_MP0_5_OFFSET
228         ldr     r1, [r0, #0x0]                  @S5PC1XX_GPIO_CON_OFFSET
229         bic     r1, r1, #(0xf << 28)            @ 28 = 7 * 4-bit
230         orr     r1, r1, #(0x1 << 28)            @ Output
231         str     r1, [r0, #0x0]                  @S5PC1XX_GPIO_CON_OFFSET
232
233         ldr     r1, [r0, #0x8]                  @S5PC1XX_GPIO_PULL_OFFSET
234         bic     r1, r1, #(0x3 << 14)            @ 14 = 7 * 2-bit
235         orr     r1, r1, #(0x2 << 14)            @ Pull-up enabled
236         str     r1, [r0, #0x8]                  @S5PC1XX_GPIO_PULL_OFFSET
237
238         ldr     r1, [r0, #0x4]                  @S5PC1XX_GPIO_DAT_OFFSET
239         orr     r1, r1, #(1 << 7)               @ 7 = 7 * 1-bit
240         str     r1, [r0, #0x4]                  @S5PC1XX_GPIO_DAT_OFFSET
241
242         ldr     r0, =0xE2900000                 @ S5PC110_PA_UART
243         orr     r0, r0, #0x800
244         mov     r1, #0x3
245         str     r1, [r0, #0x000]                @ ULCON
246         ldr     r1, =0x245
247         str     r1, [r0, #0x004]                @ UCON
248         mov     r1, #0x23
249         str     r1, [r0, #0x028]                @ UBRDIV
250         mov     r1, #0x3
251         str     r1, [r0, #0x02C]                @ UDIVSLOT
252
253         mov     r2, #'W'
254         strb    r2, [r0, #0x020]                @ UTXH
255 1001:
256         ldrb    r3, [r0, #0x010]                @ UTRSTAT
257         tst     r3, #(1 << 2)
258         beq     1001b
259 #endif
260
261         /* turn off L2 cache */
262         bl      l2_cache_disable
263
264         cmp     r7, r8
265         ldreq   r0, =0xC100
266         ldrne   r0, =0xC110
267
268         /* invalidate L2 cache also */
269         bl      invalidate_dcache
270
271         /* turn on L2 cache */
272         bl      l2_cache_enable
273
274         cmp     r7, r8
275         /* Load return address and jump to kernel */
276         ldreq   r0, =S5PC100_INFORM0
277         ldrne   r0, =S5PC110_INFORM0
278
279         /* r1 = physical address of s5pc1xx_cpu_resume function */
280         ldr     r1, [r0]
281
282         /* Jump to kernel (sleep-s5pc1xx.S) */
283         mov     pc, r1
284         nop
285         nop
286 #else
287         cmp     r7, r8
288         /* Clear wakeup status register */
289         ldreq   r0, =S5PC100_WAKEUP_STAT
290         ldrne   r0, =S5PC110_WAKEUP_STAT
291         ldr     r1, [r0]
292         str     r1, [r0]
293 #endif
294 1:
295         mov     lr, r11
296         mov     pc, lr
297
298 /*
299  * system_clock_init: Initialize core clock and bus clock.
300  * void system_clock_init(void)
301  */
302 system_clock_init:
303         ldr     r0, =S5PC1XX_CLOCK_BASE         @ 0xE0100000
304
305         /* Check S5PC100 */
306         cmp     r7, r8
307         bne     110f
308 100:
309 #ifndef DEBUG_PM_C110
310         /* Set Lock Time */
311         ldr     r1, =0xe10                      @ Locktime : 0xe10 = 3600
312         str     r1, [r0, #0x000]                @ S5PC100_APLL_LOCK
313         str     r1, [r0, #0x004]                @ S5PC100_MPLL_LOCK
314         str     r1, [r0, #0x008]                @ S5PC100_EPLL_LOCK
315         str     r1, [r0, #0x00C]                @ S5PC100_HPLL_LOCK
316
317         /* S5P_APLL_CON */
318 #ifdef CONFIG_CLK_667_166_83
319         ldr     r1, =0x81bc0400         @ SDIV 0, PDIV 4, MDIV 444 (1333MHz)
320 #elif defined(CONFIG_CLK_666_166_66)
321         ldr     r1, =0x814d0301         @ SDIV 1, PDIV 3, MDIV 333 (1333MHz)
322 #elif defined(CONFIG_CLK_600_150_75)
323         ldr     r1, =0x812C0300         @ SDIV 0, PDIV 3, MDIV 300 (1200MHz)
324 #elif defined(CONFIG_CLK_533_133_66)
325         ldr     r1, =0x810b0300         @ SDIV 0, PDIV 3, MDIV 267 (1066MHz)
326 #elif defined(CONFIG_CLK_500_166_66)
327         ldr     r1, =0x81f40301         @ SDIV 1, PDIV 3, MDIV 500 (1000MHz)
328 #elif defined(CONFIG_CLK_467_117_59)
329         ldr     r1, =0x826E0401         @ SDIV 1, PDIV 4, MDIV 622 (933MHz)
330 #elif defined(CONFIG_CLK_400_100_50)
331         ldr     r1, =0x81900301         @ SDIV 1, PDIV 3, MDIV 400 (800MHz)
332 #else
333 #error you should set the correct clock configuration
334 #endif
335         str     r1, [r0, #0x100]
336         /* S5P_MPLL_CON */
337         ldr     r1, =0x80590201         @ SDIV 1, PDIV 2, MDIV 89 (267MHz)
338         str     r1, [r0, #0x104]
339         /* S5P_EPLL_CON */
340         ldr     r1, =0x80870303         @ SDIV 3, PDIV 3, MDIV 135 (67.5MHz)
341         str     r1, [r0, #0x108]
342         /* S5P_HPLL_CON */
343         ldr     r1, =0x80600603         @ SDIV 3, PDIV 6, MDIV 96
344         str     r1, [r0, #0x10C]
345
346         ldr     r1, [r0, #0x300]
347         ldr     r2, =0x00003fff
348         bic     r1, r1, r2
349 #ifdef CONFIG_CLK_800_166_66
350         ldr     r2, =0x00011401
351 #elif defined(CONFIG_CLK_500_166_66)
352         ldr     r2, =0x00011201
353 #elif defined(CONFIG_CLK_666_166_66)
354         ldr     r2, =0x00011300
355 #else
356         ldr     r2, =0x00011301
357 #endif
358         orr     r1, r1, r2
359         str     r1, [r0, #0x300]
360         ldr     r1, [r0, #0x304]
361         ldr     r2, =0x00011110
362         orr     r1, r1, r2
363         str     r1, [r0, #0x304]
364         ldr     r1, =0x00000001
365         str     r1, [r0, #0x308]
366
367         /* Set Source Clock */
368         ldr     r1, =0x00001111                 @ A, M, E, HPLL Muxing
369         str     r1, [r0, #0x200]                @ S5PC1XX_CLK_SRC0
370 #endif
371         b       200f
372 110:
373         /* Set Clock divider */
374         ldr     r1, =0x14131330                 @ 1:1:4:4, 1:4:5
375         str     r1, [r0, #0x300]
376         ldr     r1, =0x11110111                 @ UART[3210]: MMC[3210]
377         str     r1, [r0, #0x310]
378
379         /* Set Lock Time */
380         ldr     r1, =0xe10                      @ Locktime : 0xe10 = 3600
381         str     r1, [r0, #0x000]                @ S5PC110_APLL_LOCK
382         str     r1, [r0, #0x010]                @ S5PC110_MPLL_LOCK
383         str     r1, [r0, #0x018]                @ S5PC110_EPLL_LOCK
384         str     r1, [r0, #0x020]                @ S5PC110_VPLL_LOCK
385
386         /* S5PC110_APLL_CON */
387         ldr     r1, =0x80C80601                 @ 800MHz
388         str     r1, [r0, #0x100]
389         /* S5PC110_MPLL_CON */
390         ldr     r1, =0x829B0C01                 @ 667MHz
391         str     r1, [r0, #0x108]
392         /* S5PC110_EPLL_CON */
393         ldr     r1, =0x80600602                 @  96MHz VSEL 0 P 6 M 96 S 2
394         str     r1, [r0, #0x110]
395         /* S5PC110_VPLL_CON */
396         ldr     r1, =0x806C0603                 @  54MHz
397         str     r1, [r0, #0x120]
398
399         /* Set Source Clock */
400         ldr     r1, =0x10001111                 @ A, M, E, VPLL Muxing
401         str     r1, [r0, #0x200]                @ S5PC1XX_CLK_SRC0
402
403         /* OneDRAM(DMC0) clock setting */
404         ldr     r1, =0x01000000                 @ ONEDRAM_SEL[25:24] 1 SCLKMPLL
405         str     r1, [r0, #0x218]                @ S5PC110_CLK_SRC6
406         ldr     r1, =0x30000000                 @ ONEDRAM_RATIO[31:28] 3 + 1
407         str     r1, [r0, #0x318]                @ S5PC110_CLK_DIV6
408
409         /* XCLKOUT = XUSBXTI 24MHz */
410         add     r2, r0, #0xE000                 @ S5PC110_OTHERS
411         ldr     r1, [r2]
412         orr     r1, r1, #(0x3 << 8)             @ CLKOUT[9:8] 3 XUSBXTI
413         str     r1, [r2]
414
415         /* CLK_IP0 */
416         ldr     r1, =0x8fefeeb                  @ DMC[1:0] PDMA0[3] IMEM[5]
417         str     r1, [r0, #0x460]                @ S5PC110_CLK_IP0
418
419         /* CLK_IP1 */
420         ldr     r1, =0xe9fdf0f9                 @ FIMD[0] USBOTG[16]
421                                                 @ NANDXL[24]
422         str     r1, [r0, #0x464]                @ S5PC110_CLK_IP1
423
424         /* CLK_IP2 */
425         ldr     r1, =0xf75f7fc                  @ CORESIGHT[8] MODEM[9]
426                                                 @ HOSTIF[10] HSMMC0[16]
427                                                 @ HSMMC2[18] VIC[27:24]
428         str     r1, [r0, #0x468]                @ S5PC110_CLK_IP2
429
430         /* CLK_IP3 */
431         ldr     r1, =0x8edf038c                 @ I2C[8:6]
432                                                 @ SYSTIMER[16] UART0[17]
433                                                 @ UART1[18] UART2[19]
434                                                 @ UART3[20] WDT[22]
435                                                 @ PWM[23] GPIO[26] SYSCON[27]
436         str     r1, [r0, #0x46c]                @ S5PC110_CLK_IP3
437
438         /* CLK_IP4 */
439         ldr     r1, =0xfffffff1                 @ CHIP_ID[0] TZPC[8:5]
440         str     r1, [r0, #0x470]                @ S5PC110_CLK_IP3
441
442 200:
443         /* wait at least 200us to stablize all clock */
444         mov     r2, #0x10000
445 1:      subs    r2, r2, #1
446         bne     1b
447
448         mov     pc, lr
449
450 #ifndef CONFIG_ONENAND_IPL
451 internal_ram_init:
452         ldreq   r0, =0xE3800000
453         ldrne   r0, =0xF1500000
454         ldr     r1, =0x0
455         str     r1, [r0]
456
457         mov     pc, lr
458 #endif
459
460 #ifndef CONFIG_ONENAND_IPL
461 /*
462  * uart_asm_init: Initialize UART's pins
463  */
464 uart_asm_init:
465         /* set GPIO to enable UART0-UART4 */
466         mov     r0, r8
467         ldr     r1, =0x22222222
468         str     r1, [r0, #0x0]                  @S5PC100_GPIO_A0_OFFSET
469         ldr     r1, =0x00002222
470         str     r1, [r0, #0x20]                 @S5PC100_GPIO_A1_OFFSET
471
472         /* Check S5PC100 */
473         cmp     r7, r8
474         bne     110f
475
476 #ifndef DEBUG_PM_C110
477         /* UART_SEL GPK0[5] at S5PC100 */
478         add     r0, r8, #0x2A0                  @S5PC100_GPIO_K0_OFFSET
479         ldr     r1, [r0, #0x0]                  @S5PC1XX_GPIO_CON_OFFSET
480         bic     r1, r1, #(0xf << 20)            @ 20 = 5 * 4-bit
481         orr     r1, r1, #(0x1 << 20)            @ Output
482         str     r1, [r0, #0x0]                  @S5PC1XX_GPIO_CON_OFFSET
483
484         ldr     r1, [r0, #0x8]                  @S5PC1XX_GPIO_PULL_OFFSET
485         bic     r1, r1, #(0x3 << 10)            @ 10 = 5 * 2-bit
486         orr     r1, r1, #(0x2 << 10)            @ Pull-up enabled
487         str     r1, [r0, #0x8]                  @S5PC1XX_GPIO_PULL_OFFSET
488
489         ldr     r1, [r0, #0x4]                  @S5PC1XX_GPIO_DAT_OFFSET
490         orr     r1, r1, #(1 << 5)               @ 5 = 5 * 1-bit
491         str     r1, [r0, #0x4]                  @S5PC1XX_GPIO_DAT_OFFSET
492 #endif
493         b       200f
494 110:
495         /*
496          * Note that the following address
497          * 0xE020'0360 is reserved address at S5PC100
498          */
499         /* UART_SEL MP0_5[7] at S5PC110 */
500         add     r0, r8, #0x360                  @S5PC110_GPIO_MP0_5_OFFSET
501         ldr     r1, [r0, #0x0]                  @S5PC1XX_GPIO_CON_OFFSET
502         bic     r1, r1, #(0xf << 28)            @ 28 = 7 * 4-bit
503         orr     r1, r1, #(0x1 << 28)            @ Output
504         str     r1, [r0, #0x0]                  @S5PC1XX_GPIO_CON_OFFSET
505
506         ldr     r1, [r0, #0x8]                  @S5PC1XX_GPIO_PULL_OFFSET
507         bic     r1, r1, #(0x3 << 14)            @ 14 = 7 * 2-bit
508         orr     r1, r1, #(0x2 << 14)            @ Pull-up enabled
509         str     r1, [r0, #0x8]                  @S5PC1XX_GPIO_PULL_OFFSET
510
511         ldr     r1, [r0, #0x4]                  @S5PC1XX_GPIO_DAT_OFFSET
512         orr     r1, r1, #(1 << 7)               @ 7 = 7 * 1-bit
513         str     r1, [r0, #0x4]                  @S5PC1XX_GPIO_DAT_OFFSET
514 200:
515         mov     pc, lr
516 #endif