blob: a974667dc94661441c12fb13667a2d1b36a15ab0 [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
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050extern struct nand_chip nand_dev_desc[CONFIG_SYS_MAX_NAND_DEVICE];
Sergey Kubushyne8f39122007-08-10 20:26:18 +020051
William Juul52c07962007-10-31 13:53:06 +010052static void nand_davinci_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
Sergey Kubushyne8f39122007-08-10 20:26:18 +020053{
54 struct nand_chip *this = mtd->priv;
55 u_int32_t IO_ADDR_W = (u_int32_t)this->IO_ADDR_W;
56
57 IO_ADDR_W &= ~(MASK_ALE|MASK_CLE);
58
William Juul52c07962007-10-31 13:53:06 +010059 if (ctrl & NAND_CTRL_CHANGE) {
60 if ( ctrl & NAND_CLE )
Sergey Kubushyne8f39122007-08-10 20:26:18 +020061 IO_ADDR_W |= MASK_CLE;
William Juul52c07962007-10-31 13:53:06 +010062 if ( ctrl & NAND_ALE )
Sergey Kubushyne8f39122007-08-10 20:26:18 +020063 IO_ADDR_W |= MASK_ALE;
William Juul52c07962007-10-31 13:53:06 +010064 this->IO_ADDR_W = (void __iomem *) IO_ADDR_W;
Sergey Kubushyne8f39122007-08-10 20:26:18 +020065 }
66
William Juul9e9c2c12007-11-09 13:32:30 +010067 if (cmd != NAND_CMD_NONE)
William Juul52c07962007-10-31 13:53:06 +010068 writeb(cmd, this->IO_ADDR_W);
Sergey Kubushyne8f39122007-08-10 20:26:18 +020069}
70
71/* Set WP on deselect, write enable on select */
72static void nand_davinci_select_chip(struct mtd_info *mtd, int chip)
73{
74#define GPIO_SET_DATA01 0x01c67018
75#define GPIO_CLR_DATA01 0x01c6701c
76#define GPIO_NAND_WP (1 << 4)
77#ifdef SONATA_BOARD_GPIOWP
78 if (chip < 0) {
79 REG(GPIO_CLR_DATA01) |= GPIO_NAND_WP;
80 } else {
81 REG(GPIO_SET_DATA01) |= GPIO_NAND_WP;
82 }
83#endif
84}
85
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086#ifdef CONFIG_SYS_NAND_HW_ECC
87#ifdef CONFIG_SYS_DAVINCI_BROKEN_ECC
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -040088/* Linux-compatible ECC uses MTD defaults. */
89/* These layouts are not compatible with Linux or RBL/UBL. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090#ifdef CONFIG_SYS_NAND_LARGEPAGE
Sergey Kubushynd7be2ee2008-01-09 15:36:20 +010091static struct nand_ecclayout davinci_nand_ecclayout = {
Sergey Kubushyne8f39122007-08-10 20:26:18 +020092 .eccbytes = 12,
93 .eccpos = {8, 9, 10, 24, 25, 26, 40, 41, 42, 56, 57, 58},
Sergey Kubushynd7be2ee2008-01-09 15:36:20 +010094 .oobfree = {
95 {.offset = 2, .length = 6},
96 {.offset = 12, .length = 12},
97 {.offset = 28, .length = 12},
98 {.offset = 44, .length = 12},
99 {.offset = 60, .length = 4}
100 }
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200101};
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102#elif defined(CONFIG_SYS_NAND_SMALLPAGE)
Sergey Kubushynd7be2ee2008-01-09 15:36:20 +0100103static struct nand_ecclayout davinci_nand_ecclayout = {
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200104 .eccbytes = 3,
105 .eccpos = {0, 1, 2},
Sergey Kubushynd7be2ee2008-01-09 15:36:20 +0100106 .oobfree = {
107 {.offset = 6, .length = 2},
108 {.offset = 8, .length = 8}
109 }
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200110};
111#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112#error "Either CONFIG_SYS_NAND_LARGEPAGE or CONFIG_SYS_NAND_SMALLPAGE must be defined!"
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200113#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200114#endif /* CONFIG_SYS_DAVINCI_BROKEN_ECC */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200115
116static void nand_davinci_enable_hwecc(struct mtd_info *mtd, int mode)
117{
118 emifregs emif_addr;
119 int dummy;
120
121 emif_addr = (emifregs)DAVINCI_ASYNC_EMIF_CNTRL_BASE;
122
123 dummy = emif_addr->NANDF1ECC;
124 dummy = emif_addr->NANDF2ECC;
125 dummy = emif_addr->NANDF3ECC;
126 dummy = emif_addr->NANDF4ECC;
127
Wolfgang Denka48499f2008-04-11 15:11:26 +0200128 emif_addr->NANDFCR |= (1 << 8);
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200129}
130
131static u_int32_t nand_davinci_readecc(struct mtd_info *mtd, u_int32_t region)
132{
133 u_int32_t ecc = 0;
134 emifregs emif_base_addr;
135
136 emif_base_addr = (emifregs)DAVINCI_ASYNC_EMIF_CNTRL_BASE;
137
138 if (region == 1)
139 ecc = emif_base_addr->NANDF1ECC;
140 else if (region == 2)
141 ecc = emif_base_addr->NANDF2ECC;
142 else if (region == 3)
143 ecc = emif_base_addr->NANDF3ECC;
144 else if (region == 4)
145 ecc = emif_base_addr->NANDF4ECC;
146
147 return(ecc);
148}
149
150static int nand_davinci_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
151{
152 u_int32_t tmp;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153#ifdef CONFIG_SYS_DAVINCI_BROKEN_ECC
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400154 /*
155 * This is not how you should read ECCs on large page Davinci devices.
156 * The region parameter gets you ECCs for flash chips on different chip
157 * selects, not the 4x512 byte pages in a 2048 byte page.
158 *
159 * Preserved for backwards compatibility though.
160 */
161
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200162 int region, n;
163 struct nand_chip *this = mtd->priv;
164
William Juul52c07962007-10-31 13:53:06 +0100165 n = (this->ecc.size/512);
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200166
Wolfgang Denka48499f2008-04-11 15:11:26 +0200167 region = 1;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200168 while (n--) {
169 tmp = nand_davinci_readecc(mtd, region);
170 *ecc_code++ = tmp;
171 *ecc_code++ = tmp >> 16;
172 *ecc_code++ = ((tmp >> 8) & 0x0f) | ((tmp >> 20) & 0xf0);
173 region++;
174 }
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400175#else
176 const int region = 1;
177
178 tmp = nand_davinci_readecc(mtd, region);
179
180 /* Squeeze 4 bytes ECC into 3 bytes by removing RESERVED bits
181 * and shifting. RESERVED bits are 31 to 28 and 15 to 12. */
182 tmp = (tmp & 0x00000fff) | ((tmp & 0x0fff0000) >> 4);
183
184 /* Invert so that erased block ECC is correct */
185 tmp = ~tmp;
186
187 *ecc_code++ = tmp;
188 *ecc_code++ = tmp >> 8;
189 *ecc_code++ = tmp >> 16;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200190#endif /* CONFIG_SYS_DAVINCI_BROKEN_ECC */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200191 return(0);
192}
193
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200194#ifdef CONFIG_SYS_DAVINCI_BROKEN_ECC
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200195static void nand_davinci_gen_true_ecc(u_int8_t *ecc_buf)
196{
197 u_int32_t tmp = ecc_buf[0] | (ecc_buf[1] << 16) | ((ecc_buf[2] & 0xf0) << 20) | ((ecc_buf[2] & 0x0f) << 8);
198
199 ecc_buf[0] = ~(P64o(tmp) | P64e(tmp) | P32o(tmp) | P32e(tmp) | P16o(tmp) | P16e(tmp) | P8o(tmp) | P8e(tmp));
200 ecc_buf[1] = ~(P1024o(tmp) | P1024e(tmp) | P512o(tmp) | P512e(tmp) | P256o(tmp) | P256e(tmp) | P128o(tmp) | P128e(tmp));
201 ecc_buf[2] = ~( P4o(tmp) | P4e(tmp) | P2o(tmp) | P2e(tmp) | P1o(tmp) | P1e(tmp) | P2048o(tmp) | P2048e(tmp));
202}
203
204static int nand_davinci_compare_ecc(u_int8_t *ecc_nand, u_int8_t *ecc_calc, u_int8_t *page_data)
205{
206 u_int32_t i;
207 u_int8_t tmp0_bit[8], tmp1_bit[8], tmp2_bit[8];
208 u_int8_t comp0_bit[8], comp1_bit[8], comp2_bit[8];
209 u_int8_t ecc_bit[24];
210 u_int8_t ecc_sum = 0;
211 u_int8_t find_bit = 0;
212 u_int32_t find_byte = 0;
213 int is_ecc_ff;
214
215 is_ecc_ff = ((*ecc_nand == 0xff) && (*(ecc_nand + 1) == 0xff) && (*(ecc_nand + 2) == 0xff));
216
217 nand_davinci_gen_true_ecc(ecc_nand);
218 nand_davinci_gen_true_ecc(ecc_calc);
219
220 for (i = 0; i <= 2; i++) {
221 *(ecc_nand + i) = ~(*(ecc_nand + i));
222 *(ecc_calc + i) = ~(*(ecc_calc + i));
223 }
224
225 for (i = 0; i < 8; i++) {
226 tmp0_bit[i] = *ecc_nand % 2;
227 *ecc_nand = *ecc_nand / 2;
228 }
229
230 for (i = 0; i < 8; i++) {
231 tmp1_bit[i] = *(ecc_nand + 1) % 2;
232 *(ecc_nand + 1) = *(ecc_nand + 1) / 2;
233 }
234
235 for (i = 0; i < 8; i++) {
236 tmp2_bit[i] = *(ecc_nand + 2) % 2;
237 *(ecc_nand + 2) = *(ecc_nand + 2) / 2;
238 }
239
240 for (i = 0; i < 8; i++) {
241 comp0_bit[i] = *ecc_calc % 2;
242 *ecc_calc = *ecc_calc / 2;
243 }
244
245 for (i = 0; i < 8; i++) {
246 comp1_bit[i] = *(ecc_calc + 1) % 2;
247 *(ecc_calc + 1) = *(ecc_calc + 1) / 2;
248 }
249
250 for (i = 0; i < 8; i++) {
251 comp2_bit[i] = *(ecc_calc + 2) % 2;
252 *(ecc_calc + 2) = *(ecc_calc + 2) / 2;
253 }
254
255 for (i = 0; i< 6; i++)
256 ecc_bit[i] = tmp2_bit[i + 2] ^ comp2_bit[i + 2];
257
258 for (i = 0; i < 8; i++)
259 ecc_bit[i + 6] = tmp0_bit[i] ^ comp0_bit[i];
260
261 for (i = 0; i < 8; i++)
262 ecc_bit[i + 14] = tmp1_bit[i] ^ comp1_bit[i];
263
264 ecc_bit[22] = tmp2_bit[0] ^ comp2_bit[0];
265 ecc_bit[23] = tmp2_bit[1] ^ comp2_bit[1];
266
267 for (i = 0; i < 24; i++)
268 ecc_sum += ecc_bit[i];
269
270 switch (ecc_sum) {
271 case 0:
272 /* Not reached because this function is not called if
273 ECC values are equal */
274 return 0;
275 case 1:
276 /* Uncorrectable error */
Scott Wooddf83c472008-06-20 12:38:57 -0500277 MTDDEBUG (MTD_DEBUG_LEVEL0,
278 "ECC UNCORRECTED_ERROR 1\n");
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200279 return(-1);
280 case 12:
281 /* Correctable error */
282 find_byte = (ecc_bit[23] << 8) +
283 (ecc_bit[21] << 7) +
284 (ecc_bit[19] << 6) +
285 (ecc_bit[17] << 5) +
286 (ecc_bit[15] << 4) +
287 (ecc_bit[13] << 3) +
288 (ecc_bit[11] << 2) +
289 (ecc_bit[9] << 1) +
290 ecc_bit[7];
291
292 find_bit = (ecc_bit[5] << 2) + (ecc_bit[3] << 1) + ecc_bit[1];
293
Scott Wooddf83c472008-06-20 12:38:57 -0500294 MTDDEBUG (MTD_DEBUG_LEVEL0, "Correcting single bit ECC "
295 "error at offset: %d, bit: %d\n",
296 find_byte, find_bit);
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200297
298 page_data[find_byte] ^= (1 << find_bit);
299
300 return(0);
301 default:
302 if (is_ecc_ff) {
303 if (ecc_calc[0] == 0 && ecc_calc[1] == 0 && ecc_calc[2] == 0)
304 return(0);
305 }
Scott Wooddf83c472008-06-20 12:38:57 -0500306 MTDDEBUG (MTD_DEBUG_LEVEL0,
307 "UNCORRECTED_ERROR default\n");
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200308 return(-1);
309 }
310}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200311#endif /* CONFIG_SYS_DAVINCI_BROKEN_ECC */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200312
313static int nand_davinci_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
314{
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400315 struct nand_chip *this = mtd->priv;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200316#ifdef CONFIG_SYS_DAVINCI_BROKEN_ECC
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200317 int block_count = 0, i, rc;
318
William Juul52c07962007-10-31 13:53:06 +0100319 block_count = (this->ecc.size/512);
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200320 for (i = 0; i < block_count; i++) {
321 if (memcmp(read_ecc, calc_ecc, 3) != 0) {
322 rc = nand_davinci_compare_ecc(read_ecc, calc_ecc, dat);
323 if (rc < 0) {
324 return(rc);
325 }
326 }
327 read_ecc += 3;
328 calc_ecc += 3;
329 dat += 512;
330 }
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400331#else
332 u_int32_t ecc_nand = read_ecc[0] | (read_ecc[1] << 8) |
333 (read_ecc[2] << 16);
334 u_int32_t ecc_calc = calc_ecc[0] | (calc_ecc[1] << 8) |
335 (calc_ecc[2] << 16);
336 u_int32_t diff = ecc_calc ^ ecc_nand;
337
338 if (diff) {
339 if ((((diff >> 12) ^ diff) & 0xfff) == 0xfff) {
340 /* Correctable error */
341 if ((diff >> (12 + 3)) < this->ecc.size) {
342 uint8_t find_bit = 1 << ((diff >> 12) & 7);
343 uint32_t find_byte = diff >> (12 + 3);
344
345 dat[find_byte] ^= find_bit;
346 MTDDEBUG(MTD_DEBUG_LEVEL0, "Correcting single "
347 "bit ECC error at offset: %d, bit: "
348 "%d\n", find_byte, find_bit);
349 return 1;
350 } else {
351 return -1;
352 }
353 } else if (!(diff & (diff - 1))) {
354 /* Single bit ECC error in the ECC itself,
355 nothing to fix */
356 MTDDEBUG(MTD_DEBUG_LEVEL0, "Single bit ECC error in "
357 "ECC.\n");
358 return 1;
359 } else {
360 /* Uncorrectable error */
361 MTDDEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR 1\n");
362 return -1;
363 }
364 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200365#endif /* CONFIG_SYS_DAVINCI_BROKEN_ECC */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200366 return(0);
367}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200368#endif /* CONFIG_SYS_NAND_HW_ECC */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200369
370static int nand_davinci_dev_ready(struct mtd_info *mtd)
371{
372 emifregs emif_addr;
373
374 emif_addr = (emifregs)DAVINCI_ASYNC_EMIF_CNTRL_BASE;
375
376 return(emif_addr->NANDFSR & 0x1);
377}
378
William Juul52c07962007-10-31 13:53:06 +0100379static int nand_davinci_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200380{
381 while(!nand_davinci_dev_ready(mtd)) {;}
382 *NAND_CE0CLE = NAND_STATUS;
383 return(*NAND_CE0DATA);
384}
385
386static void nand_flash_init(void)
387{
Wolfgang Denka48499f2008-04-11 15:11:26 +0200388 u_int32_t acfg1 = 0x3ffffffc;
389 u_int32_t acfg2 = 0x3ffffffc;
390 u_int32_t acfg3 = 0x3ffffffc;
391 u_int32_t acfg4 = 0x3ffffffc;
392 emifregs emif_regs;
393
394 /*------------------------------------------------------------------*
395 * NAND FLASH CHIP TIMEOUT @ 459 MHz *
396 * *
397 * AEMIF.CLK freq = PLL1/6 = 459/6 = 76.5 MHz *
398 * AEMIF.CLK period = 1/76.5 MHz = 13.1 ns *
399 * *
400 *------------------------------------------------------------------*/
401 acfg1 = 0
Wolfgang Denka1be4762008-05-20 16:00:29 +0200402 | (0 << 31 ) /* selectStrobe */
403 | (0 << 30 ) /* extWait */
404 | (1 << 26 ) /* writeSetup 10 ns */
405 | (3 << 20 ) /* writeStrobe 40 ns */
406 | (1 << 17 ) /* writeHold 10 ns */
407 | (1 << 13 ) /* readSetup 10 ns */
408 | (5 << 7 ) /* readStrobe 60 ns */
409 | (1 << 4 ) /* readHold 10 ns */
410 | (3 << 2 ) /* turnAround ?? ns */
411 | (0 << 0 ) /* asyncSize 8-bit bus */
412 ;
Wolfgang Denka48499f2008-04-11 15:11:26 +0200413
414 emif_regs = (emifregs)DAVINCI_ASYNC_EMIF_CNTRL_BASE;
415
416 emif_regs->AWCCR |= 0x10000000;
417 emif_regs->AB1CR = acfg1; /* 0x08244128 */;
418 emif_regs->AB2CR = acfg2;
419 emif_regs->AB3CR = acfg3;
420 emif_regs->AB4CR = acfg4;
421 emif_regs->NANDFCR = 0x00000101;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200422}
423
424int board_nand_init(struct nand_chip *nand)
425{
426 nand->IO_ADDR_R = (void __iomem *)NAND_CE0DATA;
427 nand->IO_ADDR_W = (void __iomem *)NAND_CE0DATA;
428 nand->chip_delay = 0;
429 nand->select_chip = nand_davinci_select_chip;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200430#ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200431 nand->options = NAND_USE_FLASH_BBT;
432#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200433#ifdef CONFIG_SYS_NAND_HW_ECC
William Juul9e9c2c12007-11-09 13:32:30 +0100434 nand->ecc.mode = NAND_ECC_HW;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200435#ifdef CONFIG_SYS_DAVINCI_BROKEN_ECC
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400436 nand->ecc.layout = &davinci_nand_ecclayout;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200437#ifdef CONFIG_SYS_NAND_LARGEPAGE
William Juul9e9c2c12007-11-09 13:32:30 +0100438 nand->ecc.size = 2048;
439 nand->ecc.bytes = 12;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200440#elif defined(CONFIG_SYS_NAND_SMALLPAGE)
William Juul9e9c2c12007-11-09 13:32:30 +0100441 nand->ecc.size = 512;
442 nand->ecc.bytes = 3;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200443#else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200444#error "Either CONFIG_SYS_NAND_LARGEPAGE or CONFIG_SYS_NAND_SMALLPAGE must be defined!"
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200445#endif
Hugo Villeneuve73dc0e42008-08-30 17:06:55 -0400446#else
447 nand->ecc.size = 512;
448 nand->ecc.bytes = 3;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200449#endif /* CONFIG_SYS_DAVINCI_BROKEN_ECC */
William Juul52c07962007-10-31 13:53:06 +0100450 nand->ecc.calculate = nand_davinci_calculate_ecc;
451 nand->ecc.correct = nand_davinci_correct_data;
William Juulb76ec382007-11-08 10:39:53 +0100452 nand->ecc.hwctl = nand_davinci_enable_hwecc;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200453#else
William Juul9e9c2c12007-11-09 13:32:30 +0100454 nand->ecc.mode = NAND_ECC_SOFT;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200455#endif /* CONFIG_SYS_NAND_HW_ECC */
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200456
457 /* Set address of hardware control function */
William Juul52c07962007-10-31 13:53:06 +0100458 nand->cmd_ctrl = nand_davinci_hwcontrol;
Sergey Kubushyne8f39122007-08-10 20:26:18 +0200459
460 nand->dev_ready = nand_davinci_dev_ready;
461 nand->waitfunc = nand_davinci_waitfunc;
462
463 nand_flash_init();
464
465 return(0);
466}