davinci_nand.c 17 KB

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