]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/arm1136/mx35/mxc_nand_load.S
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / cpu / arm1136 / mx35 / mxc_nand_load.S
1 /*
2  * (C) Copyright 2008 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/mx35.h>
25
26 .macro nfc_cmd_input
27         strh r3, [r12, #NAND_FLASH_CMD_REG_OFF]
28         mov r3, #NAND_FLASH_CONFIG2_FCMD_EN;
29         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
30         bl do_wait_op_done
31 .endm   // nfc_cmd_input
32
33 .macro do_addr_input
34         and r3, r3, #0xFF
35         strh r3, [r12, #NAND_FLASH_ADD_REG_OFF]
36         mov r3, #NAND_FLASH_CONFIG2_FADD_EN
37         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
38         bl do_wait_op_done
39 .endm   // do_addr_input
40
41 .section ".text.load", "x"
42 .globl mxc_nand_load
43 mxc_nand_load:
44         ldr r2, U_BOOT_NAND_START
45 1:      ldmia r0!, {r3-r10}
46         stmia r2!, {r3-r10}
47         cmp r0, r1
48         blo 1b
49
50         ldr r1, CONST_0X0FFF
51         ldr r2, U_BOOT_NAND_START
52         and lr, lr, r1
53         add lr, lr, r2
54         and r12, r12, r1
55         add r12, r12, r2
56         add r2, r2, #0x8
57         and r0, pc, r1
58         add pc, r0, r2
59         nop
60         nop
61         nop
62         nop
63         nop
64         adr r0, SAVE_REGS
65         str r12, [r0]
66         str lr, [r0, #4]
67 Copy_Main:
68         mov r0, #NFC_BASE_ADDR
69         add r12, r0, #0x1E00
70         ldrh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
71         orr r3, r3, #1
72
73         /* Setting NFC */
74         ldr r7, =CCM_BASE_ADDR
75         ldr r1, [r7, #CLKCTL_RCSR]
76         /*BUS WIDTH setting*/
77         tst r1, #0x20000000
78         orrne r1, r1, #0x4000
79         biceq r1, r1, #0x4000
80
81         /*4K PAGE*/
82         tst r1, #0x10000000
83         orrne r1, r1, #0x200
84         bne  1f
85         /*2K PAGE*/
86         bic r1, r1, #0x200
87         tst r1, #0x08000000
88         orrne r1, r1, #0x100 /*2KB page size*/
89         biceq r1, r1, #0x100 /*512B page size*/
90         movne r2, #32 /*64 bytes*/
91         moveq r2, #8  /*16 bytes*/
92         b NAND_setup
93 1:
94         tst r1, #0x08000000
95         bicne r3, r3, #1   /*Enable 8bit ECC mode*/
96         movne r2, #109 /*218 bytes*/
97         moveq r2, #64  /*128 bytes*/
98 NAND_setup:
99         str r1, [r7, #CLKCTL_RCSR]
100         strh r2, [r12, #ECC_RSLT_SPARE_AREA_REG_OFF]
101         strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
102
103         //unlock internal buffer
104         mov r3, #0x2
105         strh r3, [r12, #NFC_CONFIGURATION_REG_OFF]
106         //unlock nand device
107         mov r3, #0
108         strh r3, [r12, #UNLOCK_START_BLK_ADD_REG_OFF]
109         sub r3, r3, #1
110         strh r3, [r12, #UNLOCK_END_BLK_ADD_REG_OFF]
111         mov r3, #4
112         strh r3, [r12, #NF_WR_PROT_REG_OFF]
113
114         /* r0: NFC base address. RAM buffer base address. [constantly]
115          * r1: starting flash address to be copied. [constantly]
116          * r2: page size. [Doesn't change]
117          * r3: used as argument.
118          * r11: starting SDRAM address for copying. [Updated constantly].
119          * r12: NFC register base address. [constantly].
120          * r13: end of SDRAM address for copying. [Doesn't change].
121          */
122
123         mov r1, #0x1000
124         ldr r3, [r7, #CLKCTL_RCSR]
125         tst r3, #0x200
126         movne r2, #0x1000
127         bne 1f
128         tst r3, #0x100
129         mov r1, #0x800  /*Strange Why is not 4K offset*/
130         movne r2, #0x800
131         moveq r2, #0x200
132 1: /*Update the indicator of copy area */
133         ldr r11, U_BOOT_NAND_START
134         add r13, r11, #0x00088000; /*512K + 32K*/
135         add r11, r11, r1
136
137 Nfc_Read_Page:
138         mov r3, #0x0
139         nfc_cmd_input
140
141         cmp r2, #0x800
142         bhi nfc_addr_ops_4kb
143         beq nfc_addr_ops_2kb
144
145         mov r3, r1
146         do_addr_input       //1st addr cycle
147         mov r3, r1, lsr #9
148         do_addr_input       //2nd addr cycle
149         mov r3, r1, lsr #17
150         do_addr_input       //3rd addr cycle
151         mov r3, r1, lsr #25
152         do_addr_input       //4th addr cycle
153         b end_of_nfc_addr_ops
154
155 nfc_addr_ops_2kb:
156         mov r3, #0
157         do_addr_input       //1st addr cycle
158         mov r3, #0
159         do_addr_input       //2nd addr cycle
160         mov r3, r1, lsr #11
161         do_addr_input       //3rd addr cycle
162         mov r3, r1, lsr #19
163         do_addr_input       //4th addr cycle
164         mov r3, r1, lsr #27
165         do_addr_input       //5th addr cycle
166
167         mov r3, #0x30
168         nfc_cmd_input
169         b end_of_nfc_addr_ops
170
171 nfc_addr_ops_4kb:
172         mov r3, #0
173         do_addr_input       //1st addr cycle
174         mov r3, #0
175         do_addr_input       //2nd addr cycle
176         mov r3, r1, lsr #12
177         do_addr_input       //3rd addr cycle
178         mov r3, r1, lsr #20
179         do_addr_input       //4th addr cycle
180         mov r3, r1, lsr #27
181         do_addr_input       //5th addr cycle
182
183         mov r3, #0x30
184         nfc_cmd_input
185
186 end_of_nfc_addr_ops:
187         mov r8, #0
188         bl nfc_data_output
189         bl do_wait_op_done
190         // Check if x16/2kb page
191         cmp r2, #0x800
192         bhi nfc_addr_data_output_done_4k
193         beq nfc_addr_data_output_done_2k
194         beq nfc_addr_data_output_done_512
195
196         // check for bad block
197         //    mov r3, r1, lsl #(32-17)    // get rid of block number
198         //    cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
199         b nfc_addr_data_output_done
200
201 nfc_addr_data_output_done_4k:
202 //TODO
203         b nfc_addr_data_output_done
204
205 nfc_addr_data_output_done_2k:
206         // end of 4th
207         // check for bad block
208         //TODO    mov r3, r1, lsl #(32-17)    // get rid of block number
209         //    cmp r3, #(0x800 << (32-17)) // check if not page 0 or 1
210         b nfc_addr_data_output_done
211
212 nfc_addr_data_output_done_512:
213         // check for bad block
214         // TODO   mov r3, r1, lsl #(32-5-9)    // get rid of block number
215         // TODO   cmp r3, #(512 << (32-5-9))   // check if not page 0 or 1
216
217 nfc_addr_data_output_done:
218 Copy_Good_Blk:
219     //copying page
220         add r2, r2, #NFC_BASE_ADDR
221 1:      ldmia r0!, {r3-r10}
222         stmia r11!, {r3-r10}
223         cmp r0, r2
224         blo 1b
225         sub r2, r2, #NFC_BASE_ADDR
226
227         cmp r11, r13
228         bge NAND_Copy_Main_done
229         // Check if x16/2kb page
230         add r1, r1, r2
231         mov r0, #NFC_BASE_ADDR
232         b Nfc_Read_Page
233
234 NAND_Copy_Main_done:
235         adr r0, SAVE_REGS
236         ldr r12, [r0]
237         ldr lr, [r0, #4]
238         mov pc, lr
239
240 do_wait_op_done:
241 1:
242         ldrh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
243         ands r3, r3, #NAND_FLASH_CONFIG2_INT_DONE
244         beq 1b
245         bx lr     // do
246
247 nfc_data_output:
248         ldrh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
249         orr r3, r3, #(NAND_FLASH_CONFIG1_INT_MSK | NAND_FLASH_CONFIG1_ECC_EN)
250         strh r3, [r12, #NAND_FLASH_CONFIG1_REG_OFF]
251
252         strh r8, [r12, #RAM_BUFFER_ADDRESS_REG_OFF]
253
254         mov r3, #FDO_PAGE_SPARE_VAL
255         strh r3, [r12, #NAND_FLASH_CONFIG2_REG_OFF]
256         bx lr
257
258 U_BOOT_NAND_START: .word TEXT_BASE
259 CONST_0X0FFF:   .word 0x0FFF
260 SAVE_REGS:      .word 0x0
261                 .word 0x0