blob: 41a95685f6d1acc4f44fd84ad05a121dfdd5f737 [file] [log] [blame]
Sergey Kubushyne8f39122007-08-10 20:26:18 +02001/*
2 * NAND driver for TI DaVinci based boards.
3 *
4 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
5 *
6 * Based on Linux DaVinci NAND driver by TI. Original copyright follows:
7 */
8
9/*
10 *
11 * linux/drivers/mtd/nand/nand_davinci.c
12 *
13 * NAND Flash Driver
14 *
15 * Copyright (C) 2006 Texas Instruments.
16 *
17 * ----------------------------------------------------------------------------
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 * ----------------------------------------------------------------------------
33 *
34 * Overview:
35 * This is a device driver for the NAND flash device found on the
36 * DaVinci board which utilizes the Samsung k9k2g08 part.
37 *
38 Modifications:
39 ver. 1.0: Feb 2005, Vinod/Sudhakar
40 -
41 *
42 */
43
44#include <common.h>
William Juul52c07962007-10-31 13:53:06 +010045#include <asm/io.h>
Sergey Kubushyne8f39122007-08-10 20:26:18 +020046#include <nand.h>
47#include <asm/arch/nand_defs.h>
48#include <asm/arch/emif_defs.h>
49
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -040050/* Definitions for 4-bit hardware ECC */
51#define NAND_TIMEOUT 10240
52#define NAND_ECC_BUSY 0xC
53#define NAND_4BITECC_MASK 0x03FF03FF
54#define EMIF_NANDFSR_ECC_STATE_MASK 0x00000F00
55#define ECC_STATE_NO_ERR 0x0
56#define ECC_STATE_TOO_MANY_ERRS 0x1
57#define ECC_STATE_ERR_CORR_COMP_P 0x2
58#define ECC_STATE_ERR_CORR_COMP_N 0x3
59
David Brownell0bf53c42009-04-28 13:19:50 -070060static emif_registers *const emif_regs = (void *) DAVINCI_ASYNC_EMIF_CNTRL_BASE;
61
William Juul52c07962007-10-31 13:53:06 +010062static void nand_davinci_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
Sergey Kubushyne8f39122007-08-10 20:26:18 +020063{
64 struct nand_chip *this = mtd->priv;
65 u_int32_t IO_ADDR_W = (u_int32_t)this->IO_ADDR_W;
66
67 IO_ADDR_W &= ~(MASK_ALE|MASK_CLE);
68
William Juul52c07962007-10-31 13:53:06 +010069 if (ctrl & NAND_CTRL_CHANGE) {
70 if ( ctrl & NAND_CLE )
Sergey Kubushyne8f39122007-08-10 20:26:18 +020071 IO_ADDR_W |= MASK_CLE;
William Juul52c07962007-10-31 13:53:06 +010072 if ( ctrl & NAND_ALE )
Sergey Kubushyne8f39122007-08-10 20:26:18 +020073 IO_ADDR_W |= MASK_ALE;
William Juul52c07962007-10-31 13:53:06 +010074 this->IO_ADDR_W = (void __iomem *) IO_ADDR_W;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020075 }
76
William Juul9e9c2c12007-11-09 13:32:30 +010077 if (cmd != NAND_CMD_NONE)
William Juul52c07962007-10-31 13:53:06 +010078 writeb(cmd, this->IO_ADDR_W);
Sergey Kubushyne8f39122007-08-10 20:26:18 +020079}
80
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081#ifdef CONFIG_SYS_NAND_HW_ECC
Sergey Kubushyne8f39122007-08-10 20:26:18 +020082
83static void nand_davinci_enable_hwecc(struct mtd_info *mtd, int mode)
84{
Sergey Kubushyne8f39122007-08-10 20:26:18 +020085 int dummy;
86
David Brownell0bf53c42009-04-28 13:19:50 -070087 dummy = emif_regs->NANDF1ECC;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020088
David Brownell0bf53c42009-04-28 13:19:50 -070089 /* FIXME: only chipselect 0 is supported for now */
90 emif_regs->NANDFCR |= 1 << 8;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020091}
92
93static u_int32_t nand_davinci_readecc(struct mtd_info *mtd, u_int32_t region)
94{
95 u_int32_t ecc = 0;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020096
97 if (region == 1)
David Brownell0bf53c42009-04-28 13:19:50 -070098 ecc = emif_regs->NANDF1ECC;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020099 else if (region == 2)
David Brownell0bf53c42009-04-28 13:19:50 -0700100 ecc = emif_regs->NANDF2ECC;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200101 else if (region == 3)
David Brownell0bf53c42009-04-28 13:19:50 -0700102 ecc = emif_regs->NANDF3ECC;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200103 else if (region == 4)
David Brownell0bf53c42009-04-28 13:19:50 -0700104 ecc = emif_regs->NANDF4ECC;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200105
106 return(ecc);
107}
108
109static int nand_davinci_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
110{
111 u_int32_t tmp;
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400112 const int region = 1;
113
114 tmp = nand_davinci_readecc(mtd, region);
115
116 /* Squeeze 4 bytes ECC into 3 bytes by removing RESERVED bits
117 * and shifting. RESERVED bits are 31 to 28 and 15 to 12. */
118 tmp = (tmp & 0x00000fff) | ((tmp & 0x0fff0000) >> 4);
119
120 /* Invert so that erased block ECC is correct */
121 tmp = ~tmp;
122
123 *ecc_code++ = tmp;
124 *ecc_code++ = tmp >> 8;
125 *ecc_code++ = tmp >> 16;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200126
David Brownell962d4c12009-04-28 13:19:53 -0700127 /* NOTE: the above code matches mainline Linux:
128 * .PQR.stu ==> ~PQRstu
129 *
130 * MontaVista/TI kernels encode those bytes differently, use
131 * complicated (and allegedly sometimes-wrong) correction code,
132 * and usually shipped with U-Boot that uses software ECC:
133 * .PQR.stu ==> PsQRtu
134 *
135 * If you need MV/TI compatible NAND I/O in U-Boot, it should
136 * be possible to (a) change the mangling above, (b) reverse
137 * that mangling in nand_davinci_correct_data() below.
138 */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200139
David Brownell962d4c12009-04-28 13:19:53 -0700140 return 0;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200141}
142
143static int nand_davinci_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
144{
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400145 struct nand_chip *this = mtd->priv;
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400146 u_int32_t ecc_nand = read_ecc[0] | (read_ecc[1] << 8) |
147 (read_ecc[2] << 16);
148 u_int32_t ecc_calc = calc_ecc[0] | (calc_ecc[1] << 8) |
149 (calc_ecc[2] << 16);
150 u_int32_t diff = ecc_calc ^ ecc_nand;
151
152 if (diff) {
153 if ((((diff >> 12) ^ diff) & 0xfff) == 0xfff) {
154 /* Correctable error */
155 if ((diff >> (12 + 3)) < this->ecc.size) {
156 uint8_t find_bit = 1 << ((diff >> 12) & 7);
157 uint32_t find_byte = diff >> (12 + 3);
158
159 dat[find_byte] ^= find_bit;
160 MTDDEBUG(MTD_DEBUG_LEVEL0, "Correcting single "
161 "bit ECC error at offset: %d, bit: "
162 "%d\n", find_byte, find_bit);
163 return 1;
164 } else {
165 return -1;
166 }
167 } else if (!(diff & (diff - 1))) {
168 /* Single bit ECC error in the ECC itself,
169 nothing to fix */
170 MTDDEBUG(MTD_DEBUG_LEVEL0, "Single bit ECC error in "
171 "ECC.\n");
172 return 1;
173 } else {
174 /* Uncorrectable error */
175 MTDDEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR 1\n");
176 return -1;
177 }
178 }
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200179 return(0);
180}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200181#endif /* CONFIG_SYS_NAND_HW_ECC */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200182
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400183#ifdef CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST
184static struct nand_ecclayout nand_davinci_4bit_layout_oobfirst = {
Sandeep Paulrajd3482862009-11-19 23:04:42 -0500185#if defined(CONFIG_SYS_NAND_PAGE_2K)
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400186 .eccbytes = 40,
187 .eccpos = {
188 24, 25, 26, 27, 28,
189 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
190 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
191 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
192 59, 60, 61, 62, 63,
193 },
194 .oobfree = {
195 {.offset = 2, .length = 22, },
196 },
Sandeep Paulrajd3482862009-11-19 23:04:42 -0500197#elif defined(CONFIG_SYS_NAND_PAGE_4K)
198 .eccbytes = 80,
199 .eccpos = {
200 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
201 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
202 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
203 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
204 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
205 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
206 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
207 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
208 },
209 .oobfree = {
210 {.offset = 2, .length = 46, },
211 },
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400212#endif
213};
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400214
215static void nand_davinci_4bit_enable_hwecc(struct mtd_info *mtd, int mode)
216{
217 u32 val;
218
219 switch (mode) {
220 case NAND_ECC_WRITE:
221 case NAND_ECC_READ:
222 /*
223 * Start a new ECC calculation for reading or writing 512 bytes
224 * of data.
225 */
226 val = (emif_regs->NANDFCR & ~(3 << 4)) | (1 << 12);
227 emif_regs->NANDFCR = val;
228 break;
229 case NAND_ECC_READSYN:
230 val = emif_regs->NAND4BITECC1;
231 break;
232 default:
233 break;
234 }
235}
236
237static u32 nand_davinci_4bit_readecc(struct mtd_info *mtd, unsigned int ecc[4])
238{
239 ecc[0] = emif_regs->NAND4BITECC1 & NAND_4BITECC_MASK;
240 ecc[1] = emif_regs->NAND4BITECC2 & NAND_4BITECC_MASK;
241 ecc[2] = emif_regs->NAND4BITECC3 & NAND_4BITECC_MASK;
242 ecc[3] = emif_regs->NAND4BITECC4 & NAND_4BITECC_MASK;
243
244 return 0;
245}
246
247static int nand_davinci_4bit_calculate_ecc(struct mtd_info *mtd,
248 const uint8_t *dat,
249 uint8_t *ecc_code)
250{
251 unsigned int hw_4ecc[4] = { 0, 0, 0, 0 };
252 unsigned int const1 = 0, const2 = 0;
253 unsigned char count1 = 0;
254
255 nand_davinci_4bit_readecc(mtd, hw_4ecc);
256
257 /*Convert 10 bit ecc value to 8 bit */
258 for (count1 = 0; count1 < 2; count1++) {
259 const2 = count1 * 5;
260 const1 = count1 * 2;
261
262 /* Take first 8 bits from val1 (count1=0) or val5 (count1=1) */
263 ecc_code[const2] = hw_4ecc[const1] & 0xFF;
264
265 /*
266 * Take 2 bits as LSB bits from val1 (count1=0) or val5
267 * (count1=1) and 6 bits from val2 (count1=0) or
268 * val5 (count1=1)
269 */
270 ecc_code[const2 + 1] =
271 ((hw_4ecc[const1] >> 8) & 0x3) | ((hw_4ecc[const1] >> 14) &
272 0xFC);
273
274 /*
275 * Take 4 bits from val2 (count1=0) or val5 (count1=1) and
276 * 4 bits from val3 (count1=0) or val6 (count1=1)
277 */
278 ecc_code[const2 + 2] =
279 ((hw_4ecc[const1] >> 22) & 0xF) |
280 ((hw_4ecc[const1 + 1] << 4) & 0xF0);
281
282 /*
283 * Take 6 bits from val3(count1=0) or val6 (count1=1) and
284 * 2 bits from val4 (count1=0) or val7 (count1=1)
285 */
286 ecc_code[const2 + 3] =
287 ((hw_4ecc[const1 + 1] >> 4) & 0x3F) |
288 ((hw_4ecc[const1 + 1] >> 10) & 0xC0);
289
290 /* Take 8 bits from val4 (count1=0) or val7 (count1=1) */
291 ecc_code[const2 + 4] = (hw_4ecc[const1 + 1] >> 18) & 0xFF;
292 }
293 return 0;
294}
295
296
297static int nand_davinci_4bit_correct_data(struct mtd_info *mtd, uint8_t *dat,
298 uint8_t *read_ecc, uint8_t *calc_ecc)
299{
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400300 unsigned short ecc_10bit[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
301 int i;
302 unsigned int hw_4ecc[4] = { 0, 0, 0, 0 }, iserror = 0;
303 unsigned short *pspare = NULL, *pspare1 = NULL;
304 unsigned int numerrors, erroraddress, errorvalue;
305 u32 val;
306
307 /*
308 * Check for an ECC where all bytes are 0xFF. If this is the case, we
309 * will assume we are looking at an erased page and we should ignore
310 * the ECC.
311 */
312 for (i = 0; i < 10; i++) {
313 if (read_ecc[i] != 0xFF)
314 break;
315 }
316 if (i == 10)
317 return 0;
318
319 /* Convert 8 bit in to 10 bit */
320 pspare = (unsigned short *)&read_ecc[2];
321 pspare1 = (unsigned short *)&read_ecc[0];
322
323 /* Take 10 bits from 0th and 1st bytes */
324 ecc_10bit[0] = (*pspare1) & 0x3FF;
325
326 /* Take 6 bits from 1st byte and 4 bits from 2nd byte */
327 ecc_10bit[1] = (((*pspare1) >> 10) & 0x3F)
328 | (((pspare[0]) << 6) & 0x3C0);
329
330 /* Take 4 bits form 2nd bytes and 6 bits from 3rd bytes */
331 ecc_10bit[2] = ((pspare[0]) >> 4) & 0x3FF;
332
333 /*Take 2 bits from 3rd byte and 8 bits from 4th byte */
334 ecc_10bit[3] = (((pspare[0]) >> 14) & 0x3)
335 | ((((pspare[1])) << 2) & 0x3FC);
336
337 /* Take 8 bits from 5th byte and 2 bits from 6th byte */
338 ecc_10bit[4] = ((pspare[1]) >> 8)
339 | ((((pspare[2])) << 8) & 0x300);
340
341 /* Take 6 bits from 6th byte and 4 bits from 7th byte */
342 ecc_10bit[5] = (pspare[2] >> 2) & 0x3FF;
343
344 /* Take 4 bits from 7th byte and 6 bits from 8th byte */
345 ecc_10bit[6] = (((pspare[2]) >> 12) & 0xF)
346 | ((((pspare[3])) << 4) & 0x3F0);
347
348 /*Take 2 bits from 8th byte and 8 bits from 9th byte */
349 ecc_10bit[7] = ((pspare[3]) >> 6) & 0x3FF;
350
351 /*
352 * Write the parity values in the NAND Flash 4-bit ECC Load register.
353 * Write each parity value one at a time starting from 4bit_ecc_val8
354 * to 4bit_ecc_val1.
355 */
356 for (i = 7; i >= 0; i--)
357 emif_regs->NAND4BITECCLOAD = ecc_10bit[i];
358
359 /*
360 * Perform a dummy read to the EMIF Revision Code and Status register.
361 * This is required to ensure time for syndrome calculation after
362 * writing the ECC values in previous step.
363 */
364
365 val = emif_regs->NANDFSR;
366
367 /*
368 * Read the syndrome from the NAND Flash 4-Bit ECC 1-4 registers.
369 * A syndrome value of 0 means no bit errors. If the syndrome is
370 * non-zero then go further otherwise return.
371 */
372 nand_davinci_4bit_readecc(mtd, hw_4ecc);
373
374 if (hw_4ecc[0] == ECC_STATE_NO_ERR && hw_4ecc[1] == ECC_STATE_NO_ERR &&
375 hw_4ecc[2] == ECC_STATE_NO_ERR && hw_4ecc[3] == ECC_STATE_NO_ERR)
376 return 0;
377
378 /*
379 * Clear any previous address calculation by doing a dummy read of an
380 * error address register.
381 */
382 val = emif_regs->NANDERRADD1;
383
384 /*
385 * Set the addr_calc_st bit(bit no 13) in the NAND Flash Control
386 * register to 1.
387 */
388 emif_regs->NANDFCR |= 1 << 13;
389
390 /*
391 * Wait for the corr_state field (bits 8 to 11)in the
392 * NAND Flash Status register to be equal to 0x0, 0x1, 0x2, or 0x3.
393 */
394 i = NAND_TIMEOUT;
395 do {
396 val = emif_regs->NANDFSR;
397 val &= 0xc00;
398 i--;
399 } while ((i > 0) && val);
400
401 iserror = emif_regs->NANDFSR;
402 iserror &= EMIF_NANDFSR_ECC_STATE_MASK;
403 iserror = iserror >> 8;
404
405 /*
406 * ECC_STATE_TOO_MANY_ERRS (0x1) means errors cannot be
407 * corrected (five or more errors). The number of errors
408 * calculated (err_num field) differs from the number of errors
409 * searched. ECC_STATE_ERR_CORR_COMP_P (0x2) means error
410 * correction complete (errors on bit 8 or 9).
411 * ECC_STATE_ERR_CORR_COMP_N (0x3) means error correction
412 * complete (error exists).
413 */
414
415 if (iserror == ECC_STATE_NO_ERR) {
416 val = emif_regs->NANDERRVAL1;
417 return 0;
418 } else if (iserror == ECC_STATE_TOO_MANY_ERRS) {
419 val = emif_regs->NANDERRVAL1;
420 return -1;
421 }
422
423 numerrors = ((emif_regs->NANDFSR >> 16) & 0x3) + 1;
424
425 /* Read the error address, error value and correct */
426 for (i = 0; i < numerrors; i++) {
427 if (i > 1) {
428 erroraddress =
429 ((emif_regs->NANDERRADD2 >>
430 (16 * (i & 1))) & 0x3FF);
431 erroraddress = ((512 + 7) - erroraddress);
432 errorvalue =
433 ((emif_regs->NANDERRVAL2 >>
434 (16 * (i & 1))) & 0xFF);
435 } else {
436 erroraddress =
437 ((emif_regs->NANDERRADD1 >>
438 (16 * (i & 1))) & 0x3FF);
439 erroraddress = ((512 + 7) - erroraddress);
440 errorvalue =
441 ((emif_regs->NANDERRVAL1 >>
442 (16 * (i & 1))) & 0xFF);
443 }
444 /* xor the corrupt data with error value */
445 if (erroraddress < 512)
446 dat[erroraddress] ^= errorvalue;
447 }
448
449 return numerrors;
450}
Scott Woodce630312009-09-28 16:33:18 -0500451#endif /* CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST */
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400452
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200453static int nand_davinci_dev_ready(struct mtd_info *mtd)
454{
David Brownell0bf53c42009-04-28 13:19:50 -0700455 return emif_regs->NANDFSR & 0x1;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200456}
457
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200458static void nand_flash_init(void)
459{
David Brownell0bf53c42009-04-28 13:19:50 -0700460 /* This is for DM6446 EVM and *very* similar. DO NOT GROW THIS!
461 * Instead, have your board_init() set EMIF timings, based on its
462 * knowledge of the clocks and what devices are hooked up ... and
463 * don't even do that unless no UBL handled it.
464 */
David Brownellbb289292009-07-13 16:29:04 -0700465#ifdef CONFIG_SOC_DM644X
Wolfgang Denka48499f2008-04-11 15:11:26 +0200466 u_int32_t acfg1 = 0x3ffffffc;
Wolfgang Denka48499f2008-04-11 15:11:26 +0200467
468 /*------------------------------------------------------------------*
469 * NAND FLASH CHIP TIMEOUT @ 459 MHz *
470 * *
471 * AEMIF.CLK freq = PLL1/6 = 459/6 = 76.5 MHz *
472 * AEMIF.CLK period = 1/76.5 MHz = 13.1 ns *
473 * *
474 *------------------------------------------------------------------*/
475 acfg1 = 0
Wolfgang Denka1be4762008-05-20 16:00:29 +0200476 | (0 << 31 ) /* selectStrobe */
477 | (0 << 30 ) /* extWait */
478 | (1 << 26 ) /* writeSetup 10 ns */
479 | (3 << 20 ) /* writeStrobe 40 ns */
480 | (1 << 17 ) /* writeHold 10 ns */
481 | (1 << 13 ) /* readSetup 10 ns */
482 | (5 << 7 ) /* readStrobe 60 ns */
483 | (1 << 4 ) /* readHold 10 ns */
484 | (3 << 2 ) /* turnAround ?? ns */
485 | (0 << 0 ) /* asyncSize 8-bit bus */
486 ;
Wolfgang Denka48499f2008-04-11 15:11:26 +0200487
Thomas Langeb4aeefd2009-06-20 11:02:17 +0200488 emif_regs->AB1CR = acfg1; /* CS2 */
489
490 emif_regs->NANDFCR = 0x00000101; /* NAND flash on CS2 */
David Brownell0bf53c42009-04-28 13:19:50 -0700491#endif
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200492}
493
David Brownellf4b0b9d2009-05-10 15:43:01 -0700494void davinci_nand_init(struct nand_chip *nand)
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200495{
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200496 nand->chip_delay = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200497#ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400498 nand->options |= NAND_USE_FLASH_BBT;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200499#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200500#ifdef CONFIG_SYS_NAND_HW_ECC
William Juul9e9c2c12007-11-09 13:32:30 +0100501 nand->ecc.mode = NAND_ECC_HW;
William Juul9e9c2c12007-11-09 13:32:30 +0100502 nand->ecc.size = 512;
503 nand->ecc.bytes = 3;
William Juul52c07962007-10-31 13:53:06 +0100504 nand->ecc.calculate = nand_davinci_calculate_ecc;
505 nand->ecc.correct = nand_davinci_correct_data;
William Juulb76ec382007-11-08 10:39:53 +0100506 nand->ecc.hwctl = nand_davinci_enable_hwecc;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200507#else
William Juul9e9c2c12007-11-09 13:32:30 +0100508 nand->ecc.mode = NAND_ECC_SOFT;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200509#endif /* CONFIG_SYS_NAND_HW_ECC */
Sandeep Paulrajbfeb0fd2009-08-18 10:10:42 -0400510#ifdef CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST
511 nand->ecc.mode = NAND_ECC_HW_OOB_FIRST;
512 nand->ecc.size = 512;
513 nand->ecc.bytes = 10;
514 nand->ecc.calculate = nand_davinci_4bit_calculate_ecc;
515 nand->ecc.correct = nand_davinci_4bit_correct_data;
516 nand->ecc.hwctl = nand_davinci_4bit_enable_hwecc;
517 nand->ecc.layout = &nand_davinci_4bit_layout_oobfirst;
518#endif
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200519 /* Set address of hardware control function */
William Juul52c07962007-10-31 13:53:06 +0100520 nand->cmd_ctrl = nand_davinci_hwcontrol;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200521
522 nand->dev_ready = nand_davinci_dev_ready;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200523
524 nand_flash_init();
David Brownellf4b0b9d2009-05-10 15:43:01 -0700525}
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200526
David Brownellf4b0b9d2009-05-10 15:43:01 -0700527int board_nand_init(struct nand_chip *chip) __attribute__((weak));
528
529int board_nand_init(struct nand_chip *chip)
530{
531 davinci_nand_init(chip);
532 return 0;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200533}