Tizen 2.1 base
[platform/kernel/u-boot.git] / board / samsung / trats2 / lowlevel_init.S
1 /*
2  * Lowlevel setup for MIDAS board based on EXYNOS4
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  * Kyungmin Park <kyungmin.park@samsung.com>
6  * Sanghee Kim <sh0130.kim@samsung.com>
7  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26
27 #include <config.h>
28 #include <version.h>
29 #include <asm/arch/cpu.h>
30 #include <asm/arch/clock.h>
31 #include <asm/arch/power.h>
32
33 /*
34  * Register usages:
35  *
36  * r5 has zero always
37  * r7 has GPIO part1 base 0x11400000
38  * r6 has GPIO part2 base 0x11000000
39  */
40
41         .globl lowlevel_init
42 lowlevel_init:
43         mov     r11, lr
44
45         /* r5 has always zero */
46         mov     r5, #0
47
48         ldr     r7, =EXYNOS4_GPIO_PART1_BASE
49         ldr     r6, =EXYNOS4_GPIO_PART2_BASE
50
51         /* System Timer */
52         ldr     r0, =EXYNOS4_MCT_BASE
53         ldr     r1, =0x100
54         str     r1, [r0, #0x240]
55
56         /* Workaround: PMIC manual reset */
57         /* nPOWER: XEINT_23: GPX2[7] */
58         add     r0, r6, #0xC40                  @ EXYNOS4_GPIO_X2_OFFSET
59         ldr     r1, [r0, #0x0]
60         bic     r1, r1, #(0xf << 28)            @ 28 = 7 * 4-bit
61         orr     r1, r1, #(0x1 << 28)            @ Output
62         str     r1, [r0, #0x0]
63
64         ldr     r1, [r0, #0x4]
65         orr     r1, r1, #(1 << 7)               @ 7 = 7 * 1-bit
66         str     r1, [r0, #0x4]
67
68         /* init system clock */
69         bl      system_clock_init
70
71         /* Disable Watchdog */
72         ldr     r0, =EXYNOS4_WDT_BASE           @0x10060000
73         str     r5, [r0]
74
75         /* UART */
76         bl      uart_asm_init
77
78         /* PMU init */
79         bl      system_power_init
80
81 /*      bl      tzpc_init
82 */
83
84         mov     lr, r11
85         mov     pc, lr
86         nop
87         nop
88         nop
89
90 /*
91  * uart_asm_init: Initialize UART's pins
92  */
93 uart_asm_init:
94         /*
95          * setup UART0-UART4 GPIOs (part1)
96          * GPA1CON[3] = I2C_3_SCL (3)
97          * GPA1CON[2] = I2C_3_SDA (3)
98          */
99         mov     r0, r7
100         ldr     r1, =0x22222222
101         str     r1, [r0, #0x00]                 @ EXYNOS4_GPIO_A0_OFFSET
102         ldr     r1, =0x00223322
103         str     r1, [r0, #0x20]                 @ EXYNOS4_GPIO_A1_OFFSET
104
105         /* UART_SEL GPY4[7] (part2) */
106         add     r0, r6, #0x1A0                  @ EXYNOS4_GPIO_Y4_OFFSET
107         ldr     r1, [r0, #0x0]
108         bic     r1, r1, #(0xf << 28)            @ 28 = 7 * 4-bit
109         orr     r1, r1, #(0x1 << 28)
110         str     r1, [r0, #0x0]
111
112         ldr     r1, [r0, #0x8]
113         bic     r1, r1, #(0x3 << 14)            @ 14 = 7 * 2-bit
114         orr     r1, r1, #(0x3 << 14)            @ Pull-up enabled
115         str     r1, [r0, #0x8]
116
117         ldr     r1, [r0, #0x4]
118         orr     r1, r1, #(1 << 7)               @ 7 = 7 * 1-bit
119         str     r1, [r0, #0x4]
120
121 #if 0
122         ldr     r0, =EXYNOS4_UART_BASE
123         orr     r0, r0, #0x20000                @ UART2
124         mov     r1, #0x3
125         str     r1, [r0, #0x000]                @ ULCON
126         ldr     r1, =0x245
127         str     r1, [r0, #0x004]                @ UCON
128         mov     r1, #0x35
129         str     r1, [r0, #0x028]                @ UBRDIV
130         mov     r1, #0x4
131         str     r1, [r0, #0x02C]                @ UFRACVAL
132
133         mov     r2, #'W'
134         strb    r2, [r0, #0x020]                @ UTXH
135 1001:
136         ldrb    r3, [r0, #0x010]                @ UTRSTAT
137         tst     r3, #(1 << 2)
138         beq     1001b
139 #endif
140
141         mov     pc, lr
142         nop
143         nop
144         nop
145         .align  5
146
147 system_clock_init:
148         ldr     r0, =EXYNOS4_CLOCK_BASE
149
150         /* CMU_CPU MUX / DIV */
151         ldr     r1, =0x01000000
152         ldr     r2, =0x14200                    @ CLK_SRC_CPU
153         str     r1, [r0, r2]
154         /* wait ?us */
155         mov     r1, #0x10000
156 1:      subs    r1, r1, #1
157         bne     1b
158
159         /* CMU_DMC MUX / DIV */
160         ldr     r1, =0x00011000
161         ldr     r2, =0x10200                    @ CLK_SRC_DMC
162         str     r1, [r0, r2]
163         /* wait ?us */
164         mov     r1, #0x10000
165 2:      subs    r1, r1, #1
166         bne     2b
167         ldr     r1, =0x00111113
168         ldr     r2, =0x10500                    @ CLK_DIV_DMC0
169         str     r1, [r0, r2]
170         ldr     r1, =0x05051013
171         ldr     r2, =0x10504                    @ CLK_DIV_DMC1
172         str     r1, [r0, r2]
173
174         /* CMU_TOP MUX / DIV */
175         ldr     r1, =0x00000000
176         ldr     r2, =0x0C210                    @ CLK_SRC_TOP0
177         str     r1, [r0, r2]
178         ldr     r1, =0x00001000
179         ldr     r2, =0x0C214                    @ CLK_SRC_TOP1
180         str     r1, [r0, r2]
181         /* wait ?us */
182         mov     r1, #0x10000
183 3:      subs    r1, r1, #1
184         bne     3b
185         ldr     r1, =0x01205474
186         ldr     r2, =0x0C510                    @ CLK_DIV_TOP
187         str     r1, [r0, r2]
188
189         /* CMU_LEFTBUS MUX / DIV */
190         ldr     r1, =0x10
191         ldr     r2, =0x04200                    @ CLK_SRC_LEFTBUS
192         str     r1, [r0, r2]
193         /* wait ?us */
194         mov     r1, #0x10000
195 4:      subs    r1, r1, #1
196         bne     4b
197         ldr     r1, =0x13
198         ldr     r2, =0x04500                    @ CLK_DIV_LEFTBUS
199         str     r1, [r0, r2]
200
201         /* CMU_RIGHTBUS MUX / DIV */
202         ldr     r1, =0x10
203         ldr     r2, =0x08200                    @ CLK_SRC_RIGHTBUS
204         str     r1, [r0, r2]
205         /* wait ?us */
206         mov     r1, #0x10000
207 5:      subs    r1, r1, #1
208         bne     5b
209         ldr     r1, =0x13
210         ldr     r2, =0x08500                    @ CLK_DIV_RIGHTBUS
211         str     r1, [r0, r2]
212
213         /* MMC[0:1] */
214         ldr     r1, =0x000f000f                 /* 800(MPLL) / (15 + 1) */
215         ldr     r2, =0x0C544                    @ CLK_DIV_FSYS1
216         str     r1, [r0, r2]
217         /* wait for CLK_DIV_STAT_FSYS1 */
218         ldr     r2, =0x0C644
219         ldr     r3, =0x01010101 /* On changing bits */
220 6:      ldr     r1, [r0, r2]
221         and     r1, r1, r3
222         cmp     r1, #0
223         bne     6b
224
225         /* MMC[2:3] */
226         ldr     r1, =0x000f000f                 /* 800(MPLL) / (15 + 1) */
227         ldr     r2, =0x0C548                    @ CLK_DIV_FSYS2
228         str     r1, [r0, r2]
229         /* wait for CLK_DIV_STAT_FSYS2 */
230         ldr     r2, =0x0C648
231         ldr     r3, =0x01010101 /* On changing bits */
232 7:      ldr     r1, [r0, r2]
233         and     r1, r1, r3
234         cmp     r1, #0
235         bne     7b
236
237         /* MMC4 */
238         ldr     r1, =0x0003                     /* 800(MPLL) / (3 + 1) */
239         ldr     r2, =0x0C54C                    @ CLK_DIV_FSYS3
240         str     r1, [r0, r2]
241         /* wait for CLK_DIV_STAT_FSYS3 */
242         ldr     r2, =0x0C64C
243         ldr     r3, =0x00000101 /* On changing bits */
244 8:      ldr     r1, [r0, r2]
245         and     r1, r1, r3
246         cmp     r1, #0
247         bne     8b
248
249         /* UART[0:5] */
250         ldr     r1, =0x774777
251         ldr     r2, =0x0C550                    @ CLK_DIV_PERIL0
252         str     r1, [r0, r2]
253         /* wait for CLK_DIV_STAT_PERIL0 */
254         ldr     r2, =0x0C650
255         ldr     r3, =0x00111111 /* On changing bits */
256 9:      ldr     r1, [r0, r2]
257         and     r1, r1, r3
258         cmp     r1, #0
259         bne     9b
260
261         /* Set PLL locktime */
262         ldr     r1, =0x03E8
263         ldr     r2, =0x14000                    @ APLL_LOCK
264         str     r1, [r0, r2]
265         ldr     r1, =0x02F1
266         ldr     r2, =0x14008                    @ MPLL_LOCK
267         str     r1, [r0, r2]
268         ldr     r1, =0x2321
269         ldr     r2, =0x0C010                    @ EPLL_LOCK
270         str     r1, [r0, r2]
271         ldr     r1, =0x2321
272         ldr     r2, =0x0C020                    @ VPLL_LOCK
273         str     r1, [r0, r2]
274
275 /* FIXME: check this */
276         /* SATA: SCLKMPLL(0), MMC[0:4]: SCLKMPLL(6) */
277         ldr     r1, =0x0066666
278         ldr     r2, =0x0C240                    @ CLK_SRC_FSYS
279         str     r1, [r0, r2]
280         /* UART[0:5], PWM: SCLKMPLL(6) */
281         ldr     r1, =0x6666666
282         ldr     r2, =0x0C250                    @ CLK_SRC_PERIL0_OFFSET
283         str     r1, [r0, r2]
284         /* wait ?us */
285         mov     r1, #0x10000
286 10:     subs    r1, r1, #1
287         bne     10b
288 /* FIXME END */
289
290 #ifdef CONFIG_CLK_ARM_800
291         ldr     r1, =0x00133730
292         ldr     r2, =0x14500                    @ CLK_DIV_CPU0
293         str     r1, [r0, r2]
294         ldr     r1, =0x00000003
295         ldr     r2, =0x14504                    @ CLK_DIV_CPU1
296         str     r1, [r0, r2]
297         /* APLL */
298         ldr     r1, =0x00803800
299         ldr     r2, =0x14104                    @ APLL_CON1
300         str     r1, [r0, r2]
301         ldr     r1, =0x80640300                 @ 100:3:0
302         ldr     r2, =0x14100                    @ APLL_CON0
303         str     r1, [r0, r2]
304 #endif
305 #ifdef CONFIG_CLK_ARM_1000
306         ldr     r1, =0x00143730
307         ldr     r2, =0x14500                    @ CLK_DIV_CPU0
308         str     r1, [r0, r2]
309         ldr     r1, =0x00000004
310         ldr     r2, =0x14504                    @ CLK_DIV_CPU1
311         str     r1, [r0, r2]
312         /* APLL */
313         ldr     r1, =0x00803800
314         ldr     r2, =0x14104                    @ APLL_CON1
315         str     r1, [r0, r2]
316         ldr     r1, =0x807D0300                 @ 125:3:0
317         ldr     r2, =0x14100                    @ APLL_CON0
318         str     r1, [r0, r2]
319 #endif
320 #ifdef CONFIG_CLK_ARM_1200
321         ldr     r1, =0x00143730
322         ldr     r2, =0x14500                    @ CLK_DIV_CPU0
323         str     r1, [r0, r2]
324         ldr     r1, =0x00000005
325         ldr     r2, =0x14504                    @ CLK_DIV_CPU1
326         str     r1, [r0, r2]
327         /* APLL */
328         ldr     r1, =0x00803800
329         ldr     r2, =0x14104                    @ APLL_CON1
330         str     r1, [r0, r2]
331         ldr     r1, =0x80960300                 @ 150:3:0
332         ldr     r2, =0x14100                    @ APLL_CON0
333         str     r1, [r0, r2]
334 #endif
335
336         /* check C2C_CTRL enable bit */
337         ldr     r3, =EXYNOS4_POWER_BASE
338         ldr     r1, [r3, #0x24]
339         and     r1, r1, #1
340         cmp     r1, #0
341         bne     skip_mpll
342
343 #ifdef CONFIG_CLK_BUS_DMC_165_330
344         /* MPLL */
345         ldr     r1, =0x00803800
346         ldr     r2, =0x1010C                    @ MPLL_CON1
347         str     r1, [r0, r2]
348         ldr     r1, =0x81160501                 @ 667MHz (278:5:1)
349         ldr     r2, =0x10108                    @ MPLL_CON0
350         str     r1, [r0, r2]
351 #endif
352 #ifdef CONFIG_CLK_BUS_DMC_200_400
353         /* MPLL */
354         ldr     r1, =0x00803800
355         ldr     r2, =0x1010C                    @ MPLL_CON1
356         str     r1, [r0, r2]
357         ldr     r1, =0x80640300                 @ 800MHz (100:3:0)
358         ldr     r2, =0x10108                    @ MPLL_CON0
359         str     r1, [r0, r2]
360 #endif
361 skip_mpll:
362
363         /* EPLL */
364         ldr     r1, =0x00000080
365         ldr     r2, =0x0C118                    @ EPLL_CON2
366         str     r1, [r0, r2]
367         ldr     r1, =0x66010000
368         ldr     r2, =0x0C114                    @ EPLL_CON1
369         str     r1, [r0, r2]
370         ldr     r1, =0x80400203                 @ 96MHz (64:2:3)
371         ldr     r2, =0x0C110                    @ EPLL_CON0
372         str     r1, [r0, r2]
373
374         /* VPLL */
375         ldr     r1, =0x00000080
376         ldr     r2, =0x0C128                    @ VPLL_CON2
377         str     r1, [r0, r2]
378         ldr     r1, =0x66010000
379         ldr     r2, =0x0C124                    @ VPLL_CON1
380         str     r1, [r0, r2]
381         ldr     r1, =0x80480203                 @ 108MHz (72:2:3)
382         ldr     r2, =0x0C120                    @ VPLL_CON0
383         str     r1, [r0, r2]
384
385         /* wait ?us */
386         mov     r1, #0x40000
387 11:     subs    r1, r1, #1
388         bne     11b
389
390         ldr     r1, =0x01000001
391         ldr     r2, =0x14200                    @ CLK_SRC_CPU
392         str     r1, [r0, r2]
393
394         ldr     r1, =0x00011000
395         ldr     r2, =0x10200                    @ CLK_SRC_DMC
396         str     r1, [r0, r2]
397
398         ldr     r1, =0x00000110
399         ldr     r2, =0x0C210                    @ CLK_SRC_TOP0
400         str     r1, [r0, r2]
401         ldr     r1, =0x01111000
402         ldr     r2, =0x0C214                    @ CLK_SRC_TOP1
403         str     r1, [r0, r2]
404
405         /* wait ?us */
406         mov     r1, #0x10000
407 12:     subs    r1, r1, #1
408         bne     12b
409
410 #if 0
411         /*
412          * SMMUJPEG[11], JPEG[6], CSIS1[5]              : 0111 1001
413          * Turn off all
414          */
415         ldr     r1, =0xFFF80000
416         ldr     r2, =0x0C920                    @ CLK_GATE_IP_CAM
417         str     r1, [r0, r2]
418
419         /* Turn off all */
420         ldr     r1, =0xFFFFFFC0
421         ldr     r2, =0x0C924                    @ CLK_GATE_IP_VP
422         str     r1, [r0, r2]
423
424         /* Turn off all */
425         ldr     r1, =0xFFFFFFFE
426         ldr     r2, =0x0C928                    @ CLK_GATE_IP_MFC
427         str     r1, [r0, r2]
428
429         /* Turn off all */
430         ldr     r1, =0xFFFFFFFE
431         ldr     r2, =0x0C92C                    @ CLK_GATE_IP_G3D
432         str     r1, [r0, r2]
433
434         /* Turn off all */
435         ldr     r1, =0xFFFFFC00
436         ldr     r2, =0x0C930                    @ CLK_GATE_IP_IMAGE
437         str     r1, [r0, r2]
438
439         /* DSIM0[3], MDNIE0[2], MIE0[1]                 : 0001 */
440         ldr     r1, =0xFFFFFFF1
441         ldr     r2, =0x0C934                    @ CLK_GATE_IP_LCD0
442         str     r1, [r0, r2]
443
444         /* Turn off all */
445         ldr     r1, =0xFFFFFFC0
446         ldr     r2, =0x0C938                    @ CLK_GATE_IP_LCD1
447         str     r1, [r0, r2]
448
449         /*
450          * SMMUPCIE[18], NFCON[16]                      : 1111 1010
451          * ONENAND[15], PCIE[14], SATA[10], SDMMC43[9:8]: 0011 1000
452          * SDMMC1[6], TSI[4], SATAPHY[3], PCIEPHY[2]    : 1010 0011
453          */
454         ldr     r1, =0xFFFA38A3
455         ldr     r2, =0x0C940                    @ CLK_GATE_IP_FSYS
456         str     r1, [r0, r2]
457
458         /* Turn off all */
459         ldr     r1, =0xFFFFFFFE
460         ldr     r2, =0x0C94C                    @ CLK_GATE_IP_GPS
461         str     r1, [r0, r2]
462
463         /*
464          * AC97[27], SPDIF[26], SLIMBUS[25]             : 1111 0001
465          * I2C2[8]                                      : 1111 1110
466          */
467         ldr     r1, =0xF1FFFEFF
468         ldr     r2, =0x0C950                    @ CLK_GATE_IP_PERIL
469         str     r1, [r0, r2]
470
471         /*
472          * KEYIF[16]                                    : 1111 1110
473          */
474         ldr     r1, =0xFFFEFFFF
475         ldr     r2, =0x0C960                    @ CLK_GATE_IP_PERIR
476         str     r1, [r0, r2]
477
478         /* GPS[7], LCD1[5], G3D[3], MFC[2], TV[1]       : 0101 0001 */
479         ldr     r1, =0xFFFFFF51
480         ldr     r2, =0x0C970                    @ CLK_GATE_BLOCK
481         str     r1, [r0, r2]
482 #endif
483         mov     pc, lr
484         nop
485         nop
486         nop
487
488 system_power_init:
489         ldr     r0, =EXYNOS4_POWER_BASE         @ 0x10020000
490
491         ldr     r2, =0x330C                     @ PS_HOLD_CONTROL
492         ldr     r1, [r0, r2]
493         orr     r1, r1, #(0x3 << 8)             @ Data High, Output En
494         str     r1, [r0, r2]
495
496         mov     pc, lr
497         nop
498         nop
499         nop
500
501 tzpc_init:
502         ldr     r0, =0x10110000
503         mov     r1, #0x0
504         str     r1, [r0]
505         mov     r1, #0xff
506         str     r1, [r0, #0x0804]
507         str     r1, [r0, #0x0810]
508         str     r1, [r0, #0x081C]
509         str     r1, [r0, #0x0828]
510
511         ldr     r0, =0x10120000
512         str     r1, [r0, #0x0804]
513         str     r1, [r0, #0x0810]
514         str     r1, [r0, #0x081C]
515         str     r1, [r0, #0x0828]
516
517         ldr     r0, =0x10130000
518         str     r1, [r0, #0x0804]
519         str     r1, [r0, #0x0810]
520         str     r1, [r0, #0x081C]
521         str     r1, [r0, #0x0828]
522
523         ldr     r0, =0x10140000
524         str     r1, [r0, #0x0804]
525         str     r1, [r0, #0x0810]
526         str     r1, [r0, #0x081C]
527         str     r1, [r0, #0x0828]
528
529         ldr     r0, =0x10150000
530         str     r1, [r0, #0x0804]
531         str     r1, [r0, #0x0810]
532         str     r1, [r0, #0x081C]
533         str     r1, [r0, #0x0828]
534
535         mov     pc, lr