davinci_nand.c 17 KB

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