tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / include / asm / arch-sc8830 / nand_controller.h
1 /******************************************************************************
2  ** File Name:      nand_controller.h                                         *
3  ** Author:         Nick.zhao                                                 *
4  ** DATE:           01/03/2005                                                *
5  ** Copyright:      2005 Spreatrum, Incoporated. All Rights Reserved.         *
6  ** Description:                                                              *
7  ******************************************************************************/
8 #ifndef NAND_CONTROLLER_H
9 #define NAND_CONTROLLER_H
10 #include "sci_types.h"
11
12 /******************************************************************************
13                           Macro define
14 ******************************************************************************/
15 //Nand Controller register
16 #define NFC_MBUF_ADDR      0x60000000
17 #define NFC_SBUF_ADDR      0x60000C00
18 #define NFC_WPN            0x60001c38
19 #define NFC_CMD            0x60001C00
20 #define NFC_STR0           0x60001C04
21 #define NFC_STR1           0x60001C08
22 #define NFC_STR2           0x60001C0C
23 #define NFC_STR3           0x60001C10
24 #define NFC_END0           0x60001C14
25 #define NFC_END1           0x60001C18
26 #define NFC_END2           0x60001C1C
27 #define NFC_END3           0x60001C20
28 #define NFC_PARA           0x60001C24
29 #define NFC_ID_STATUS      0x60001c3c
30 #define NFC_CMD_CLR        0x60001c68
31 #define NFC_ECC_EN         0x60001d00
32 #define NFC_TIMEOUT        0x60001d18
33 #define NFC_ENDIAN         0x60001d40
34 #define NFC_CMD_SET        0x60001d44
35
36 //INT CTL
37 #define NFC_INT_SRC        0x60001c84
38 #define NFC_INT_EN         0x60001c88
39 #define NFC_INT_MSK        0x60001c8c
40
41 //Nand
42 #define NAND_CTL_BASE                   0x60001c00
43
44 typedef enum
45 {
46     ERR_NF_SUCCESS = 0, // Success,no error
47     ERR_NF_FAIL,        // Oprate nand flash fail
48     ERR_NF_TIMEOUT,     // Oprate nand flash timeout;
49     ERR_NF_BUSY,        // Current device is busy;
50     ERR_NF_PROTECTED    // Current device is protected;
51 } ERR_NF_E;
52 /******************************************************************************
53                           Struct define
54 ******************************************************************************/
55 //Nand control register
56 typedef struct nand_tag
57 {
58     VOLATILE uint32 cmd;
59     VOLATILE uint32 start_addr0;
60     VOLATILE uint32 start_addr1;
61     VOLATILE uint32 start_addr2;
62     VOLATILE uint32 start_addr3;
63     VOLATILE uint32 end_addr0;
64     VOLATILE uint32 end_addr1;
65     VOLATILE uint32 end_addr2;
66     VOLATILE uint32 end_addr3;
67     VOLATILE uint32 para;
68     VOLATILE uint32 ecc0;
69     VOLATILE uint32 ecc1;
70     VOLATILE uint32 ecc2;
71     VOLATILE uint32 ecc3;
72     VOLATILE uint32 wpn;
73     VOLATILE uint32 idstatus;
74 } NAND_CTL_REG_T;
75 typedef struct
76 {
77     uint16 acycle;        //address cycle, which can be set 3,4,5
78     uint16 pagesize;      //page size, which can be set 512 or 2048
79     uint16 sparesize;     //spare size, which can be set 16 or 64
80     uint16 buswidth;      //bus width, which can be set 0 or 1
81     uint16 advance;       //advance property, which can be set 0 or 1
82     uint16 eccpos;        //ECC position
83 } NAND_PARA_T;
84
85
86 typedef struct
87 {
88     uint32 nTrTime;       //Read wait R/B ready
89     uint32 nTpTime;      //Program wait R/B ready
90     uint32 nTeTime;      //Erase wait R/B ready
91     uint32 nTwcTime;   //Read/Write cycle time
92 } NAND_TIMING_T, *NAND_TIMING_PTR;
93
94 /******************************************************************************/
95 //  Description:   Set NF parameter according to AHB_CLK
96 //  Parameter:
97 //      ahb_clk    the frequency of AHB_CLK
98 //  Return:
99 //      ERR_NF_SUCCESS    Set NF parameter successfully
100 /******************************************************************************/
101 PUBLIC ERR_NF_E NANDCTL_SetParam (uint32 ahb_clk);
102
103 /******************************************************************************/
104 //  Description:   Init nand controller
105 //  Parameter:
106 //      ahb_clk:   the frequency of AHB clock
107 //  Return:
108 //      ERR_NF_SUCCESS    Init nand controller successfully
109 /******************************************************************************/
110 PUBLIC ERR_NF_E NANDCTL_Init (uint32 ahb_clk);
111
112 /******************************************************************************/
113 //  Description:   Open nand controller
114 //  Parameter:
115 //      pNandPara    the parameter of nandflash
116 //  Return:
117 //      ERR_NF_SUCCESS    Open nand controller successfully
118 /******************************************************************************/
119 PUBLIC ERR_NF_E NANDCTL_Open (NAND_PARA_T *pNandPara);
120
121 /******************************************************************************/
122 //  Description:   Close nand controller
123 //  Parameter:
124 //      NULL
125 //  Return:
126 //      ERR_NF_SUCCESS    Close nand controller successfully
127 /******************************************************************************/
128 PUBLIC ERR_NF_E NANDCTL_Close (void);
129
130 /******************************************************************************/
131 //  Description:   Read nandflash ID
132 //  Parameter:
133 //      pID      in  the address of nandflash id
134 //  Return:
135 //      ERR_NF_SUCCESS     Get the ID successfully
136 /******************************************************************************/
137 PUBLIC ERR_NF_E NANDCTL_Read_ID (uint8 *pID);
138
139 /******************************************************************************/
140 //  Description:   Get nand status
141 //  Parameter:
142 //      none
143 //  Return:
144 //      ERR_NF_SUCCESS    NAND is ready
145 //      ERR_NF_BUSY       nand is busy
146 //      ERR_NF_FAIL       Program or erase nand failed
147 /******************************************************************************/
148 PUBLIC ERR_NF_E NANDCTL_Read_Status (void);
149
150 /******************************************************************************/
151 //  Description:   Reset NandFlash
152 //  Parameter:
153 //      None
154 //  Return:
155 //      ERR_NF_SUCCESS     Reset nandflash successfully
156 /******************************************************************************/
157 PUBLIC ERR_NF_E NANDCTL_Reset (void);
158
159 /******************************************************************************/
160 //  Description:   Read main part and spare part of nand, ECC value can be get
161 //                 if necessary. This function is used for small page nandflash.
162 //  Parameter:
163 //      page_addr:   in   the nand page address.
164 //      pMBuf:       in   the address of Main part
165 //      pSBuf:       in   the address of Spare part
166 //      pEcc:        out  the address of ECC value
167 //  Return:
168 //      ERR_NF_SUCCESS    Read nand successfully
169 /******************************************************************************/
170 PUBLIC ERR_NF_E NANDCTL_MS_Read_S (
171     uint32 page_addr,
172     uint8 *pMBuf,
173     uint8 *pSBuf,
174     uint8 *pEcc
175 );
176 /******************************************************************************/
177 //  Description:   Read main part of nand, ECC value can be get
178 //                 if necessary.
179 //  Parameter:
180 //      page_addr:   in   the nand page address.
181 //      pMBuf:       in   the address of Main part
182 //  Return:
183 //      ERR_NF_SUCCESS    Read nand successfully
184 /******************************************************************************/
185 PUBLIC ERR_NF_E NANDCTL_M_Read_S (
186     uint32 page_addr,
187     uint8 *pMBuf
188 );
189 /******************************************************************************/
190 //  Description:   Read spare part of nand
191 //  Parameter:
192 //      page_addr:   in   the nand page address.
193 //      pSBuf:       in   the address of Spare part
194 //  Return:
195 //      ERR_NF_SUCCESS    Read nand successfully
196 /******************************************************************************/
197 PUBLIC ERR_NF_E NANDCTL_S_Read_S (
198     uint32 page_addr,
199     uint8 *pSBuf
200 );
201 /******************************************************************************/
202 //  Description:   Write main part and spare part of nand
203 //  Parameter:
204 //      page_addr:  in   the nand page address.
205 //      pMBuf:      in   the address of main part
206 //      pSBuf:      in   the address of spare part
207 //      ecc_en:     in   the flag to enable ECC
208 //  Return:
209 //      ERR_NF_SUCCESS    Control nand successfully
210 //      ERR_NF_BUSY       nand is busy
211 //      ERR_NF_FAIL       Program or erase nand failed
212 /******************************************************************************/
213 PUBLIC ERR_NF_E NANDCTL_MS_Write_S (
214     uint32 page_addr,
215     uint8 *pMBuf,
216     uint8 *pSBuf,
217     uint8 ecc_en
218 );
219 /******************************************************************************/
220 //  Description:   Write main part of nand
221 //  Parameter:
222 //      page_addr: in    the nand page address.
223 //      pMBuf:     in    the main part address.
224 //  Return:
225 //      ERR_NF_SUCCESS    Control nand successfully
226 //      ERR_NF_BUSY       nand is busy
227 //      ERR_NF_FAIL       Program or erase nand failed
228 /******************************************************************************/
229 PUBLIC ERR_NF_E NANDCTL_M_Write_S (uint32 page_addr,uint8 *pMBuf);
230
231 /******************************************************************************/
232 //  Description:   Write spare part of nand
233 //  Parameter:
234 //      page_addr:  in   the nand page address.
235 //      pSBuf       in   the address of spare part
236 //  Return:
237 //      ERR_NF_SUCCESS    Control nand successfully
238 //      ERR_NF_BUSY       nand is busy
239 //      ERR_NF_FAIL       Program or erase nand failed
240 /******************************************************************************/
241 PUBLIC ERR_NF_E NANDCTL_S_Write_S (uint32 page_addr,uint8 *pSBuf);
242
243 /******************************************************************************/
244 //  Description:   Erase a block of nandflash
245 //  Parameter:
246 //      block_addr:  in   the nand block address.
247 //  Return:
248 //      ERR_NF_SUCCESS    Control nand successfully
249 //      ERR_NF_BUSY       nand is busy
250 //      ERR_NF_FAIL       Program or erase nand failed
251 /******************************************************************************/
252 PUBLIC ERR_NF_E NANDCTL_Erase_Block_S (uint32 block_addr);
253 /******************************************************************************/
254 //  Description:   Read main part and spare part of nand, ECC value can be get
255 //                 if necessary. This function is used for large page nandflash.
256 //  Parameter:
257 //      page_addr:   in   the nand page address.
258 //      index        in   the sector index of one page
259 //      nSct         in   the sector number
260 //      pMBuf:       in   the address of Main part
261 //      pSBuf:       in   the address of Spare part
262 //      pEcc:        out  the address of ECC value
263 //  Return:
264 //      ERR_NF_SUCCESS    Read nand successfully
265 /******************************************************************************/
266 PUBLIC ERR_NF_E NANDCTL_MS_Read_L (
267     uint32 page_addr,
268     uint8 index,
269     uint8 nSct,
270     uint8 *pMBuf,
271     uint8 *pSBuf,
272     uint8 *pEcc
273 );
274 /******************************************************************************/
275 //  Description:   Read main part of nand, ECC value can be get
276 //                 if necessary.
277 //  Parameter:
278 //      page_addr:   in   the nand page address.
279 //      index        in   the sector index of one page
280 //      nSct         in   the sector number
281 //      pMBuf:       in   the address of Main part
282 //  Return:
283 //      ERR_NF_SUCCESS    Read nand successfully
284 /******************************************************************************/
285 PUBLIC ERR_NF_E NANDCTL_M_Read_L (
286     uint32 page_addr,
287     uint8 index,
288     uint8 nSct,
289     uint8 *pMBuf
290 );
291 /******************************************************************************/
292 //  Description:   Read spare part of nand
293 //  Parameter:
294 //      page_addr:   in   the nand page address.
295 //      index        in   the sector index of one page
296 //      nSct         in   the sector number
297 //      pSBuf:       in   the address of Spare part
298 //  Return:
299 //      ERR_NF_SUCCESS    Read nand successfully
300 /******************************************************************************/
301 PUBLIC ERR_NF_E NANDCTL_S_Read_L (
302     uint32 page_addr,
303     uint8 index,
304     uint8 nSct,
305     uint8 *pSBuf
306 );
307 /******************************************************************************/
308 //  Description:   Write main part and spare part of nand
309 //  Parameter:
310 //      page_addr:   in   the nand page address.
311 //      index        in   the sector index of one page
312 //      nSct         in   the sector number
313 //      pMBuf:       in   the address of Main part
314 //      pSBuf:       in   the address of Spare part
315 //      ecc_en:      in   the flag to enable ECC
316 //  Return:
317 //      ERR_NF_SUCCESS    Control nand successfully
318 //      ERR_NF_BUSY       nand is busy
319 //      ERR_NF_FAIL       Program or erase nand failed
320 /******************************************************************************/
321 PUBLIC ERR_NF_E NANDCTL_MS_Write_L (
322     uint32 page_addr,
323     uint8 index,
324     uint8 nSct,
325     uint8 *pMBuf,
326     uint8 *pSBuf,
327     uint8 ecc_en
328 );
329 /******************************************************************************/
330 //  Description:   Write main part of nand
331 //  Parameter:
332 //      page_addr:   in   the nand page address.
333 //      index        in   the sector index of one page
334 //      nSct         in   the sector number
335 //      pMBuf:       in   the address of Main part
336 //  Return:
337 //      ERR_NF_SUCCESS    Control nand successfully
338 //      ERR_NF_BUSY       nand is busy
339 //      ERR_NF_FAIL       Program or erase nand failed
340 /******************************************************************************/
341 PUBLIC ERR_NF_E NANDCTL_M_Write_L (uint32 page_addr,uint8 index,uint8 nSct,uint8 *pMBuf);
342 /******************************************************************************/
343 //  Description:   Write spare part of nand
344 //  Parameter:
345 //      page_addr:   in   the nand page address.
346 //      index        in   the sector index of one page
347 //      nSct         in   the sector number
348 //      pSBuf:       in   the address of Spare part
349 //  Return:
350 //      ERR_NF_SUCCESS    Control nand successfully
351 //      ERR_NF_BUSY       nand is busy
352 //      ERR_NF_FAIL       Program or erase nand failed
353 /******************************************************************************/
354 PUBLIC ERR_NF_E NANDCTL_S_Write_L (uint32 page_addr,uint8 index,uint8 nSct,uint8 *pSBuf);
355 /******************************************************************************/
356 //  Description:   Erase a block of nandflash
357 //  Parameter:
358 //      block_addr:  in    the nand block address.
359 //  Return:
360 //      ERR_NF_SUCCESS    Control nand successfully
361 //      ERR_NF_BUSY       nand is busy
362 //      ERR_NF_FAIL       Program or erase nand failed
363 /******************************************************************************/
364 PUBLIC ERR_NF_E NANDCTL_Erase_Block_L (uint32 block_addr);
365 /******************************************************************************/
366 //  Description:   Input the nandflash parameter
367 //  Parameter:
368 //      pNandTiming    the frequency of AHB_CLK
369 //  Return:
370 //      ERR_NF_SUCCESS    Set NF parameter successfully
371 /******************************************************************************/
372 PUBLIC ERR_NF_E NANDCTL_InitParam (NAND_TIMING_PTR pNandTiming);
373 #endif // NAND_CONTROLLER_H