1 /******************************************************************************
2 ** File Name: nand_controller.h *
5 ** Copyright: 2005 Spreatrum, Incoporated. All Rights Reserved. *
7 ******************************************************************************/
8 #ifndef NAND_CONTROLLER_H
9 #define NAND_CONTROLLER_H
10 #include "sci_types.h"
12 /******************************************************************************
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
37 #define NFC_INT_SRC 0x60001c84
38 #define NFC_INT_EN 0x60001c88
39 #define NFC_INT_MSK 0x60001c8c
42 #define NAND_CTL_BASE 0x60001c00
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;
52 /******************************************************************************
54 ******************************************************************************/
55 //Nand control register
56 typedef struct nand_tag
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;
73 VOLATILE uint32 idstatus;
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
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;
94 /******************************************************************************/
95 // Description: Set NF parameter according to AHB_CLK
97 // ahb_clk the frequency of AHB_CLK
99 // ERR_NF_SUCCESS Set NF parameter successfully
100 /******************************************************************************/
101 PUBLIC ERR_NF_E NANDCTL_SetParam (uint32 ahb_clk);
103 /******************************************************************************/
104 // Description: Init nand controller
106 // ahb_clk: the frequency of AHB clock
108 // ERR_NF_SUCCESS Init nand controller successfully
109 /******************************************************************************/
110 PUBLIC ERR_NF_E NANDCTL_Init (uint32 ahb_clk);
112 /******************************************************************************/
113 // Description: Open nand controller
115 // pNandPara the parameter of nandflash
117 // ERR_NF_SUCCESS Open nand controller successfully
118 /******************************************************************************/
119 PUBLIC ERR_NF_E NANDCTL_Open (NAND_PARA_T *pNandPara);
121 /******************************************************************************/
122 // Description: Close nand controller
126 // ERR_NF_SUCCESS Close nand controller successfully
127 /******************************************************************************/
128 PUBLIC ERR_NF_E NANDCTL_Close (void);
130 /******************************************************************************/
131 // Description: Read nandflash ID
133 // pID in the address of nandflash id
135 // ERR_NF_SUCCESS Get the ID successfully
136 /******************************************************************************/
137 PUBLIC ERR_NF_E NANDCTL_Read_ID (uint8 *pID);
139 /******************************************************************************/
140 // Description: Get nand status
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);
150 /******************************************************************************/
151 // Description: Reset NandFlash
155 // ERR_NF_SUCCESS Reset nandflash successfully
156 /******************************************************************************/
157 PUBLIC ERR_NF_E NANDCTL_Reset (void);
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.
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
168 // ERR_NF_SUCCESS Read nand successfully
169 /******************************************************************************/
170 PUBLIC ERR_NF_E NANDCTL_MS_Read_S (
176 /******************************************************************************/
177 // Description: Read main part of nand, ECC value can be get
180 // page_addr: in the nand page address.
181 // pMBuf: in the address of Main part
183 // ERR_NF_SUCCESS Read nand successfully
184 /******************************************************************************/
185 PUBLIC ERR_NF_E NANDCTL_M_Read_S (
189 /******************************************************************************/
190 // Description: Read spare part of nand
192 // page_addr: in the nand page address.
193 // pSBuf: in the address of Spare part
195 // ERR_NF_SUCCESS Read nand successfully
196 /******************************************************************************/
197 PUBLIC ERR_NF_E NANDCTL_S_Read_S (
201 /******************************************************************************/
202 // Description: Write main part and spare part of nand
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
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 (
219 /******************************************************************************/
220 // Description: Write main part of nand
222 // page_addr: in the nand page address.
223 // pMBuf: in the main part address.
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);
231 /******************************************************************************/
232 // Description: Write spare part of nand
234 // page_addr: in the nand page address.
235 // pSBuf in the address of spare part
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);
243 /******************************************************************************/
244 // Description: Erase a block of nandflash
246 // block_addr: in the nand block address.
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.
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
264 // ERR_NF_SUCCESS Read nand successfully
265 /******************************************************************************/
266 PUBLIC ERR_NF_E NANDCTL_MS_Read_L (
274 /******************************************************************************/
275 // Description: Read main part of nand, ECC value can be get
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
283 // ERR_NF_SUCCESS Read nand successfully
284 /******************************************************************************/
285 PUBLIC ERR_NF_E NANDCTL_M_Read_L (
291 /******************************************************************************/
292 // Description: Read spare part of nand
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
299 // ERR_NF_SUCCESS Read nand successfully
300 /******************************************************************************/
301 PUBLIC ERR_NF_E NANDCTL_S_Read_L (
307 /******************************************************************************/
308 // Description: Write main part and spare part of nand
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
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 (
329 /******************************************************************************/
330 // Description: Write main part of nand
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
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
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
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
358 // block_addr: in the nand block address.
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
368 // pNandTiming the frequency of AHB_CLK
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