davinci_nand.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  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. * linux/drivers/mtd/nand/nand_davinci.c
  11. *
  12. * NAND Flash Driver
  13. *
  14. * Copyright (C) 2006 Texas Instruments.
  15. *
  16. * ----------------------------------------------------------------------------
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. * ----------------------------------------------------------------------------
  32. *
  33. * Overview:
  34. * This is a device driver for the NAND flash device found on the
  35. * DaVinci board which utilizes the Samsung k9k2g08 part.
  36. *
  37. Modifications:
  38. ver. 1.0: Feb 2005, Vinod/Sudhakar
  39. -
  40. *
  41. */
  42. #include <common.h>
  43. #include <asm/io.h>
  44. #include <nand.h>
  45. #include <asm/arch/nand_defs.h>
  46. #include <asm/arch/emif_defs.h>
  47. /* Definitions for 4-bit hardware ECC */
  48. #define NAND_TIMEOUT 10240
  49. #define NAND_ECC_BUSY 0xC
  50. #define NAND_4BITECC_MASK 0x03FF03FF
  51. #define EMIF_NANDFSR_ECC_STATE_MASK 0x00000F00
  52. #define ECC_STATE_NO_ERR 0x0
  53. #define ECC_STATE_TOO_MANY_ERRS 0x1
  54. #define ECC_STATE_ERR_CORR_COMP_P 0x2
  55. #define ECC_STATE_ERR_CORR_COMP_N 0x3
  56. static emif_registers *const emif_regs = (void *) DAVINCI_ASYNC_EMIF_CNTRL_BASE;
  57. /*
  58. * Exploit the little endianness of the ARM to do multi-byte transfers
  59. * per device read. This can perform over twice as quickly as individual
  60. * byte transfers when buffer alignment is conducive.
  61. *
  62. * NOTE: This only works if the NAND is not connected to the 2 LSBs of
  63. * the address bus. On Davinci EVM platforms this has always been true.
  64. */
  65. static void nand_davinci_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  66. {
  67. struct nand_chip *chip = mtd->priv;
  68. const u32 *nand = chip->IO_ADDR_R;
  69. /* Make sure that buf is 32 bit aligned */
  70. if (((int)buf & 0x3) != 0) {
  71. if (((int)buf & 0x1) != 0) {
  72. if (len) {
  73. *buf = readb(nand);
  74. buf += 1;
  75. len--;
  76. }
  77. }
  78. if (((int)buf & 0x3) != 0) {
  79. if (len >= 2) {
  80. *(u16 *)buf = readw(nand);
  81. buf += 2;
  82. len -= 2;
  83. }
  84. }
  85. }
  86. /* copy aligned data */
  87. while (len >= 4) {
  88. *(u32 *)buf = readl(nand);
  89. buf += 4;
  90. len -= 4;
  91. }
  92. /* mop up any remaining bytes */
  93. if (len) {
  94. if (len >= 2) {
  95. *(u16 *)buf = readw(nand);
  96. buf += 2;
  97. len -= 2;
  98. }
  99. if (len)
  100. *buf = readb(nand);
  101. }
  102. }
  103. static void nand_davinci_write_buf(struct mtd_info *mtd, const uint8_t *buf,
  104. int len)
  105. {
  106. struct nand_chip *chip = mtd->priv;
  107. const u32 *nand = chip->IO_ADDR_W;
  108. /* Make sure that buf is 32 bit aligned */
  109. if (((int)buf & 0x3) != 0) {
  110. if (((int)buf & 0x1) != 0) {
  111. if (len) {
  112. writeb(*buf, nand);
  113. buf += 1;
  114. len--;
  115. }
  116. }
  117. if (((int)buf & 0x3) != 0) {
  118. if (len >= 2) {
  119. writew(*(u16 *)buf, nand);
  120. buf += 2;
  121. len -= 2;
  122. }
  123. }
  124. }
  125. /* copy aligned data */
  126. while (len >= 4) {
  127. writel(*(u32 *)buf, nand);
  128. buf += 4;
  129. len -= 4;
  130. }
  131. /* mop up any remaining bytes */
  132. if (len) {
  133. if (len >= 2) {
  134. writew(*(u16 *)buf, nand);
  135. buf += 2;
  136. len -= 2;
  137. }
  138. if (len)
  139. writeb(*buf, nand);
  140. }
  141. }
  142. static void nand_davinci_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  143. {
  144. struct nand_chip *this = mtd->priv;
  145. u_int32_t IO_ADDR_W = (u_int32_t)this->IO_ADDR_W;
  146. if (ctrl & NAND_CTRL_CHANGE) {
  147. IO_ADDR_W &= ~(MASK_ALE|MASK_CLE);
  148. if ( ctrl & NAND_CLE )
  149. IO_ADDR_W |= MASK_CLE;
  150. if ( ctrl & NAND_ALE )
  151. IO_ADDR_W |= MASK_ALE;
  152. this->IO_ADDR_W = (void __iomem *) IO_ADDR_W;
  153. }
  154. if (cmd != NAND_CMD_NONE)
  155. writeb(cmd, IO_ADDR_W);
  156. }
  157. #ifdef CONFIG_SYS_NAND_HW_ECC
  158. static void nand_davinci_enable_hwecc(struct mtd_info *mtd, int mode)
  159. {
  160. int dummy;
  161. dummy = emif_regs->NANDF1ECC;
  162. /* FIXME: only chipselect 0 is supported for now */
  163. emif_regs->NANDFCR |= 1 << 8;
  164. }
  165. static u_int32_t nand_davinci_readecc(struct mtd_info *mtd, u_int32_t region)
  166. {
  167. u_int32_t ecc = 0;
  168. if (region == 1)
  169. ecc = emif_regs->NANDF1ECC;
  170. else if (region == 2)
  171. ecc = emif_regs->NANDF2ECC;
  172. else if (region == 3)
  173. ecc = emif_regs->NANDF3ECC;
  174. else if (region == 4)
  175. ecc = emif_regs->NANDF4ECC;
  176. return(ecc);
  177. }
  178. static int nand_davinci_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
  179. {
  180. u_int32_t tmp;
  181. const int region = 1;
  182. tmp = nand_davinci_readecc(mtd, region);
  183. /* Squeeze 4 bytes ECC into 3 bytes by removing RESERVED bits
  184. * and shifting. RESERVED bits are 31 to 28 and 15 to 12. */
  185. tmp = (tmp & 0x00000fff) | ((tmp & 0x0fff0000) >> 4);
  186. /* Invert so that erased block ECC is correct */
  187. tmp = ~tmp;
  188. *ecc_code++ = tmp;
  189. *ecc_code++ = tmp >> 8;
  190. *ecc_code++ = tmp >> 16;
  191. /* NOTE: the above code matches mainline Linux:
  192. * .PQR.stu ==> ~PQRstu
  193. *
  194. * MontaVista/TI kernels encode those bytes differently, use
  195. * complicated (and allegedly sometimes-wrong) correction code,
  196. * and usually shipped with U-Boot that uses software ECC:
  197. * .PQR.stu ==> PsQRtu
  198. *
  199. * If you need MV/TI compatible NAND I/O in U-Boot, it should
  200. * be possible to (a) change the mangling above, (b) reverse
  201. * that mangling in nand_davinci_correct_data() below.
  202. */
  203. return 0;
  204. }
  205. static int nand_davinci_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc)
  206. {
  207. struct nand_chip *this = mtd->priv;
  208. u_int32_t ecc_nand = read_ecc[0] | (read_ecc[1] << 8) |
  209. (read_ecc[2] << 16);
  210. u_int32_t ecc_calc = calc_ecc[0] | (calc_ecc[1] << 8) |
  211. (calc_ecc[2] << 16);
  212. u_int32_t diff = ecc_calc ^ ecc_nand;
  213. if (diff) {
  214. if ((((diff >> 12) ^ diff) & 0xfff) == 0xfff) {
  215. /* Correctable error */
  216. if ((diff >> (12 + 3)) < this->ecc.size) {
  217. uint8_t find_bit = 1 << ((diff >> 12) & 7);
  218. uint32_t find_byte = diff >> (12 + 3);
  219. dat[find_byte] ^= find_bit;
  220. MTDDEBUG(MTD_DEBUG_LEVEL0, "Correcting single "
  221. "bit ECC error at offset: %d, bit: "
  222. "%d\n", find_byte, find_bit);
  223. return 1;
  224. } else {
  225. return -1;
  226. }
  227. } else if (!(diff & (diff - 1))) {
  228. /* Single bit ECC error in the ECC itself,
  229. nothing to fix */
  230. MTDDEBUG(MTD_DEBUG_LEVEL0, "Single bit ECC error in "
  231. "ECC.\n");
  232. return 1;
  233. } else {
  234. /* Uncorrectable error */
  235. MTDDEBUG(MTD_DEBUG_LEVEL0, "ECC UNCORRECTED_ERROR 1\n");
  236. return -1;
  237. }
  238. }
  239. return(0);
  240. }
  241. #endif /* CONFIG_SYS_NAND_HW_ECC */
  242. #ifdef CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST
  243. static struct nand_ecclayout nand_davinci_4bit_layout_oobfirst = {
  244. #if defined(CONFIG_SYS_NAND_PAGE_2K)
  245. .eccbytes = 40,
  246. .eccpos = {
  247. 24, 25, 26, 27, 28,
  248. 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
  249. 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
  250. 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
  251. 59, 60, 61, 62, 63,
  252. },
  253. .oobfree = {
  254. {.offset = 2, .length = 22, },
  255. },
  256. #elif defined(CONFIG_SYS_NAND_PAGE_4K)
  257. .eccbytes = 80,
  258. .eccpos = {
  259. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
  260. 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
  261. 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
  262. 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
  263. 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
  264. 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
  265. 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
  266. 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
  267. },
  268. .oobfree = {
  269. {.offset = 2, .length = 46, },
  270. },
  271. #endif
  272. };
  273. static void nand_davinci_4bit_enable_hwecc(struct mtd_info *mtd, int mode)
  274. {
  275. u32 val;
  276. switch (mode) {
  277. case NAND_ECC_WRITE:
  278. case NAND_ECC_READ:
  279. /*
  280. * Start a new ECC calculation for reading or writing 512 bytes
  281. * of data.
  282. */
  283. val = (emif_regs->NANDFCR & ~(3 << 4)) | (1 << 12);
  284. emif_regs->NANDFCR = val;
  285. break;
  286. case NAND_ECC_READSYN:
  287. val = emif_regs->NAND4BITECC1;
  288. break;
  289. default:
  290. break;
  291. }
  292. }
  293. static u32 nand_davinci_4bit_readecc(struct mtd_info *mtd, unsigned int ecc[4])
  294. {
  295. ecc[0] = emif_regs->NAND4BITECC1 & NAND_4BITECC_MASK;
  296. ecc[1] = emif_regs->NAND4BITECC2 & NAND_4BITECC_MASK;
  297. ecc[2] = emif_regs->NAND4BITECC3 & NAND_4BITECC_MASK;
  298. ecc[3] = emif_regs->NAND4BITECC4 & NAND_4BITECC_MASK;
  299. return 0;
  300. }
  301. static int nand_davinci_4bit_calculate_ecc(struct mtd_info *mtd,
  302. const uint8_t *dat,
  303. uint8_t *ecc_code)
  304. {
  305. unsigned int hw_4ecc[4];
  306. unsigned int i;
  307. nand_davinci_4bit_readecc(mtd, hw_4ecc);
  308. /*Convert 10 bit ecc value to 8 bit */
  309. for (i = 0; i < 2; i++) {
  310. unsigned int hw_ecc_low = hw_4ecc[i * 2];
  311. unsigned int hw_ecc_hi = hw_4ecc[(i * 2) + 1];
  312. /* Take first 8 bits from val1 (count1=0) or val5 (count1=1) */
  313. *ecc_code++ = hw_ecc_low & 0xFF;
  314. /*
  315. * Take 2 bits as LSB bits from val1 (count1=0) or val5
  316. * (count1=1) and 6 bits from val2 (count1=0) or
  317. * val5 (count1=1)
  318. */
  319. *ecc_code++ =
  320. ((hw_ecc_low >> 8) & 0x3) | ((hw_ecc_low >> 14) & 0xFC);
  321. /*
  322. * Take 4 bits from val2 (count1=0) or val5 (count1=1) and
  323. * 4 bits from val3 (count1=0) or val6 (count1=1)
  324. */
  325. *ecc_code++ =
  326. ((hw_ecc_low >> 22) & 0xF) | ((hw_ecc_hi << 4) & 0xF0);
  327. /*
  328. * Take 6 bits from val3(count1=0) or val6 (count1=1) and
  329. * 2 bits from val4 (count1=0) or val7 (count1=1)
  330. */
  331. *ecc_code++ =
  332. ((hw_ecc_hi >> 4) & 0x3F) | ((hw_ecc_hi >> 10) & 0xC0);
  333. /* Take 8 bits from val4 (count1=0) or val7 (count1=1) */
  334. *ecc_code++ = (hw_ecc_hi >> 18) & 0xFF;
  335. }
  336. return 0;
  337. }
  338. static int nand_davinci_4bit_correct_data(struct mtd_info *mtd, uint8_t *dat,
  339. uint8_t *read_ecc, uint8_t *calc_ecc)
  340. {
  341. int i;
  342. unsigned int hw_4ecc[4];
  343. unsigned int iserror;
  344. unsigned short *ecc16;
  345. unsigned int numerrors, erroraddress, errorvalue;
  346. u32 val;
  347. /*
  348. * Check for an ECC where all bytes are 0xFF. If this is the case, we
  349. * will assume we are looking at an erased page and we should ignore
  350. * the ECC.
  351. */
  352. for (i = 0; i < 10; i++) {
  353. if (read_ecc[i] != 0xFF)
  354. break;
  355. }
  356. if (i == 10)
  357. return 0;
  358. /* Convert 8 bit in to 10 bit */
  359. ecc16 = (unsigned short *)&read_ecc[0];
  360. /*
  361. * Write the parity values in the NAND Flash 4-bit ECC Load register.
  362. * Write each parity value one at a time starting from 4bit_ecc_val8
  363. * to 4bit_ecc_val1.
  364. */
  365. /*Take 2 bits from 8th byte and 8 bits from 9th byte */
  366. writel(((ecc16[4]) >> 6) & 0x3FF, &emif_regs->NAND4BITECCLOAD);
  367. /* Take 4 bits from 7th byte and 6 bits from 8th byte */
  368. writel((((ecc16[3]) >> 12) & 0xF) | ((((ecc16[4])) << 4) & 0x3F0),
  369. &emif_regs->NAND4BITECCLOAD);
  370. /* Take 6 bits from 6th byte and 4 bits from 7th byte */
  371. writel((ecc16[3] >> 2) & 0x3FF, &emif_regs->NAND4BITECCLOAD);
  372. /* Take 8 bits from 5th byte and 2 bits from 6th byte */
  373. writel(((ecc16[2]) >> 8) | ((((ecc16[3])) << 8) & 0x300),
  374. &emif_regs->NAND4BITECCLOAD);
  375. /*Take 2 bits from 3rd byte and 8 bits from 4th byte */
  376. writel((((ecc16[1]) >> 14) & 0x3) | ((((ecc16[2])) << 2) & 0x3FC),
  377. &emif_regs->NAND4BITECCLOAD);
  378. /* Take 4 bits form 2nd bytes and 6 bits from 3rd bytes */
  379. writel(((ecc16[1]) >> 4) & 0x3FF, &emif_regs->NAND4BITECCLOAD);
  380. /* Take 6 bits from 1st byte and 4 bits from 2nd byte */
  381. writel((((ecc16[0]) >> 10) & 0x3F) | (((ecc16[1]) << 6) & 0x3C0),
  382. &emif_regs->NAND4BITECCLOAD);
  383. /* Take 10 bits from 0th and 1st bytes */
  384. writel((ecc16[0]) & 0x3FF, &emif_regs->NAND4BITECCLOAD);
  385. /*
  386. * Perform a dummy read to the EMIF Revision Code and Status register.
  387. * This is required to ensure time for syndrome calculation after
  388. * writing the ECC values in previous step.
  389. */
  390. val = emif_regs->NANDFSR;
  391. /*
  392. * Read the syndrome from the NAND Flash 4-Bit ECC 1-4 registers.
  393. * A syndrome value of 0 means no bit errors. If the syndrome is
  394. * non-zero then go further otherwise return.
  395. */
  396. nand_davinci_4bit_readecc(mtd, hw_4ecc);
  397. if (!(hw_4ecc[0] | hw_4ecc[1] | hw_4ecc[2] | hw_4ecc[3]))
  398. return 0;
  399. /*
  400. * Clear any previous address calculation by doing a dummy read of an
  401. * error address register.
  402. */
  403. val = emif_regs->NANDERRADD1;
  404. /*
  405. * Set the addr_calc_st bit(bit no 13) in the NAND Flash Control
  406. * register to 1.
  407. */
  408. emif_regs->NANDFCR |= 1 << 13;
  409. /*
  410. * Wait for the corr_state field (bits 8 to 11)in the
  411. * NAND Flash Status register to be equal to 0x0, 0x1, 0x2, or 0x3.
  412. */
  413. i = NAND_TIMEOUT;
  414. do {
  415. val = emif_regs->NANDFSR;
  416. val &= 0xc00;
  417. i--;
  418. } while ((i > 0) && val);
  419. iserror = emif_regs->NANDFSR;
  420. iserror &= EMIF_NANDFSR_ECC_STATE_MASK;
  421. iserror = iserror >> 8;
  422. /*
  423. * ECC_STATE_TOO_MANY_ERRS (0x1) means errors cannot be
  424. * corrected (five or more errors). The number of errors
  425. * calculated (err_num field) differs from the number of errors
  426. * searched. ECC_STATE_ERR_CORR_COMP_P (0x2) means error
  427. * correction complete (errors on bit 8 or 9).
  428. * ECC_STATE_ERR_CORR_COMP_N (0x3) means error correction
  429. * complete (error exists).
  430. */
  431. if (iserror == ECC_STATE_NO_ERR) {
  432. val = emif_regs->NANDERRVAL1;
  433. return 0;
  434. } else if (iserror == ECC_STATE_TOO_MANY_ERRS) {
  435. val = emif_regs->NANDERRVAL1;
  436. return -1;
  437. }
  438. numerrors = ((emif_regs->NANDFSR >> 16) & 0x3) + 1;
  439. /* Read the error address, error value and correct */
  440. for (i = 0; i < numerrors; i++) {
  441. if (i > 1) {
  442. erroraddress =
  443. ((emif_regs->NANDERRADD2 >>
  444. (16 * (i & 1))) & 0x3FF);
  445. erroraddress = ((512 + 7) - erroraddress);
  446. errorvalue =
  447. ((emif_regs->NANDERRVAL2 >>
  448. (16 * (i & 1))) & 0xFF);
  449. } else {
  450. erroraddress =
  451. ((emif_regs->NANDERRADD1 >>
  452. (16 * (i & 1))) & 0x3FF);
  453. erroraddress = ((512 + 7) - erroraddress);
  454. errorvalue =
  455. ((emif_regs->NANDERRVAL1 >>
  456. (16 * (i & 1))) & 0xFF);
  457. }
  458. /* xor the corrupt data with error value */
  459. if (erroraddress < 512)
  460. dat[erroraddress] ^= errorvalue;
  461. }
  462. return numerrors;
  463. }
  464. #endif /* CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST */
  465. static int nand_davinci_dev_ready(struct mtd_info *mtd)
  466. {
  467. return emif_regs->NANDFSR & 0x1;
  468. }
  469. static void nand_flash_init(void)
  470. {
  471. /* This is for DM6446 EVM and *very* similar. DO NOT GROW THIS!
  472. * Instead, have your board_init() set EMIF timings, based on its
  473. * knowledge of the clocks and what devices are hooked up ... and
  474. * don't even do that unless no UBL handled it.
  475. */
  476. #ifdef CONFIG_SOC_DM644X
  477. u_int32_t acfg1 = 0x3ffffffc;
  478. /*------------------------------------------------------------------*
  479. * NAND FLASH CHIP TIMEOUT @ 459 MHz *
  480. * *
  481. * AEMIF.CLK freq = PLL1/6 = 459/6 = 76.5 MHz *
  482. * AEMIF.CLK period = 1/76.5 MHz = 13.1 ns *
  483. * *
  484. *------------------------------------------------------------------*/
  485. acfg1 = 0
  486. | (0 << 31 ) /* selectStrobe */
  487. | (0 << 30 ) /* extWait */
  488. | (1 << 26 ) /* writeSetup 10 ns */
  489. | (3 << 20 ) /* writeStrobe 40 ns */
  490. | (1 << 17 ) /* writeHold 10 ns */
  491. | (1 << 13 ) /* readSetup 10 ns */
  492. | (5 << 7 ) /* readStrobe 60 ns */
  493. | (1 << 4 ) /* readHold 10 ns */
  494. | (3 << 2 ) /* turnAround ?? ns */
  495. | (0 << 0 ) /* asyncSize 8-bit bus */
  496. ;
  497. emif_regs->AB1CR = acfg1; /* CS2 */
  498. emif_regs->NANDFCR = 0x00000101; /* NAND flash on CS2 */
  499. #endif
  500. }
  501. void davinci_nand_init(struct nand_chip *nand)
  502. {
  503. nand->chip_delay = 0;
  504. #ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
  505. nand->options |= NAND_USE_FLASH_BBT;
  506. #endif
  507. #ifdef CONFIG_SYS_NAND_HW_ECC
  508. nand->ecc.mode = NAND_ECC_HW;
  509. nand->ecc.size = 512;
  510. nand->ecc.bytes = 3;
  511. nand->ecc.calculate = nand_davinci_calculate_ecc;
  512. nand->ecc.correct = nand_davinci_correct_data;
  513. nand->ecc.hwctl = nand_davinci_enable_hwecc;
  514. #else
  515. nand->ecc.mode = NAND_ECC_SOFT;
  516. #endif /* CONFIG_SYS_NAND_HW_ECC */
  517. #ifdef CONFIG_SYS_NAND_4BIT_HW_ECC_OOBFIRST
  518. nand->ecc.mode = NAND_ECC_HW_OOB_FIRST;
  519. nand->ecc.size = 512;
  520. nand->ecc.bytes = 10;
  521. nand->ecc.calculate = nand_davinci_4bit_calculate_ecc;
  522. nand->ecc.correct = nand_davinci_4bit_correct_data;
  523. nand->ecc.hwctl = nand_davinci_4bit_enable_hwecc;
  524. nand->ecc.layout = &nand_davinci_4bit_layout_oobfirst;
  525. #endif
  526. /* Set address of hardware control function */
  527. nand->cmd_ctrl = nand_davinci_hwcontrol;
  528. nand->read_buf = nand_davinci_read_buf;
  529. nand->write_buf = nand_davinci_write_buf;
  530. nand->dev_ready = nand_davinci_dev_ready;
  531. nand_flash_init();
  532. }
  533. int board_nand_init(struct nand_chip *chip) __attribute__((weak));
  534. int board_nand_init(struct nand_chip *chip)
  535. {
  536. davinci_nand_init(chip);
  537. return 0;
  538. }