]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - cpu/arm_cortexa8/mx51/mxc_nand_load.S
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / cpu / arm_cortexa8 / mx51 / mxc_nand_load.S
1 /*
2  * (C) Copyright 2009 Freescale Semiconductor, Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <config.h>
24 #include <asm/arch/mx51.h>
25 .macro do_wait_op_done
26 1:      ldr r7, [r3, #0x2C]
27         ands r7, r7, #0x80000000
28         beq 1b
29         mov r7, #0x0
30         str r7, [r3, #0x2C]
31 .endm   // do_wait_op_done
32
33 .section ".text.load", "x"
34 .globl mxc_nand_load
35 /*
36  * R0:  NFC BUF base address
37  * R1:  NFC BUF data end address
38  * R2: RAM destination offset address
39  * R3: NFC IP control register base
40  * R4: NAND block address
41  * R5: RAM destination end address
42  * R6: NFC DATA register base
43  * R7 - r14: 8 working buffer registers
44  */
45 mxc_nand_load:
46         ldr r0, =NFC_BASE_ADDR_AXI
47         add r1, r0, #NFC_BUF_SIZE
48
49         /* For non-nand-boot, directly quit */
50         cmp pc, r0
51         movlo pc, lr
52         cmp pc, r1
53         movhi pc, lr
54
55         mov r4, #NFC_BUF_SIZE
56         /* Get NAND page size */
57         ldr r3, =NFC_BASE_ADDR
58         ldr r2, [r3, #0x24]
59         and r2, r2, #0x3
60         cmp r2, #1
61         moveq r2, #0x800
62         movlt r2, #0x200
63         adrls r5, NFC_PAGE_MODE
64         strls r2, [r5]
65         /* Get actually pre-loading size*/
66         subls r1, r1, #0x800
67         subls r4, r4, #0x800
68
69         /* r1 ~ r3, r12, lr(r14) must not change in relocated operation */
70         ldr r2, U_BOOT_NAND_START
71 1:      ldmia r0!, {r5-r11, r13}
72         stmia r2!, {r5-r11, r13}
73         cmp r0, r1
74         blo 1b
75
76         ldr r0, CONST_0X0FFF
77         ldr r5, U_BOOT_NAND_START
78         and lr, lr, r0
79         add lr, lr, r5
80         and r12, r12, r0
81         add r12, r12, r5
82         add r5, r5, #0x8
83         and r0, pc, r0
84         add pc, r5, r0
85         nop
86         nop
87         nop
88         nop
89         nop
90         adr r0, SAVE_REGS       /* Save r12 & R14(lr) */
91         str r12, [r0]
92         str lr, [r0, #4]
93 Copy_Main:
94         ldr r0, =NFC_BASE_ADDR_AXI
95
96         add r6, r0, #0x1E00
97         ldr r5, =_end           /* Try get right image size */
98         add r5, r2, #0x00040000 /* Fixme to get actual image size */
99
100         mov r7, #0xFF000000
101         add r7, r7, #0x00FF0000
102         str r7, [r3, #0x4]
103         str r7, [r3, #0x8]
104         str r7, [r3, #0xC]
105         str r7, [r3, #0x10]
106         str r7, [r3, #0x14]
107         str r7, [r3, #0x18]
108         str r7, [r3, #0x1C]
109         str r7, [r3, #0x20]
110         mov r8, #0x7
111         mov r7, #0x84
112 1:      add r9, r7, r8, lsr #3
113         str r9, [r3, #0x0]
114         subs r8, r8, #0x01
115         bne 1b
116
117         mov r7, #0
118         str r7, [r3, #0x2C]
119
120         ldr r7, NFC_PAGE_MODE
121 Read_Page:
122         /* start_nfc_addr_ops1(pg_no, pg_off) */
123         cmp r7, #0x800
124         movgt r7, r4, lsr #12   /* Get the page number for 4K page */
125         moveq r7, r4, lsr #11   /* Get the page number for 2K page */
126         mov r7, r7, lsl #16
127         str r7, [r6, #0x04]     /* Set the address */
128
129         /* writel((FLASH_Read_Mode1_LG << 8) | FLASH_Read_Mode1, NAND_CMD_REG)*/
130         mov r7, #0x3000
131         str r7, [r6,#0x0]
132
133         /* writel(0x00000000, NAND_CONFIGURATION1_REG) */
134         mov r7, #0x0
135         str r7, [r6, #0x34]
136
137         /* start auto-read
138          * writel(NAND_LAUNCH_AUTO_READ, NAND_LAUNCH_REG);
139          */
140         mov r7, #0x80
141         str r7, [r6, #0x40]
142
143         do_wait_op_done
144
145 Copy_Good_Blk:
146 1:      ldmia r0!, {r7-r14}
147         stmia r2!, {r7-r14}
148         cmp r0, r1
149         blo 1b
150         cmp r2, r5
151         bge Copy_Main_done
152         ldr r7, NFC_PAGE_MODE
153         add r4, r4, r7
154         ldr r0, =NFC_BASE_ADDR_AXI
155         b       Read_Page
156
157 Copy_Main_done:
158         adr r0, SAVE_REGS
159         ldr r12, [r0]
160         ldr lr, [r0, #4]
161         mov pc, lr
162
163 U_BOOT_NAND_START: .word TEXT_BASE
164 CONST_0X0FFF:   .word 0x0FFF
165 NFC_PAGE_MODE:  .word 0x1000
166 SAVE_REGS:      .word 0x0
167                 .word 0x0