nand.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * (C) Copyright 2006 DENX Software Engineering
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  24. #ifdef CONFIG_NEW_NAND_CODE
  25. #include <nand.h>
  26. #include <asm/arch/pxa-regs.h>
  27. /* mk@tbd move this to pxa-regs */
  28. #define OSCR_CLK_FREQ 3.250 /* MHz */
  29. #define CFG_DFC_DEBUG1
  30. #define CFG_DFC_DEBUG2
  31. #ifdef CFG_DFC_DEBUG1
  32. # define DFC_DEBUG1(fmt, args...) printf(fmt, ##args)
  33. #else
  34. # define DFC_DEBUG1(fmt, args...)
  35. #endif
  36. #ifdef CFG_DFC_DEBUG2
  37. # define DFC_DEBUG2(fmt, args...) printf(fmt, ##args)
  38. #else
  39. # define DFC_DEBUG2(fmt, args...)
  40. #endif
  41. static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
  42. static struct nand_bbt_descr delta_bbt_descr = {
  43. .options = 0,
  44. .offs = 0,
  45. .len = 2,
  46. .pattern = scan_ff_pattern
  47. };
  48. static struct nand_oobinfo delta_oob = {
  49. .useecc = MTD_NANDECC_AUTOPLACE,
  50. .eccbytes = 6,
  51. .eccpos = {2, 3, 4, 5, 6, 7},
  52. .oobfree = { {8, 2}, {12, 4} }
  53. };
  54. /*
  55. * not required for Monahans DFC
  56. */
  57. static void delta_hwcontrol(struct mtd_info *mtdinfo, int cmd)
  58. {
  59. return;
  60. }
  61. /* read device ready pin */
  62. static int delta_device_ready(struct mtd_info *mtdinfo)
  63. {
  64. if(NDSR & NDSR_RDY)
  65. return 1;
  66. else
  67. return 0;
  68. return 0;
  69. }
  70. /*
  71. * Write buf to the DFC Controller Data Buffer
  72. */
  73. static void delta_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
  74. {
  75. unsigned long bytes_multi = len & 0xfffffffc;
  76. unsigned long rest = len & 0x3;
  77. unsigned long *long_buf;
  78. int i;
  79. if(bytes_multi) {
  80. for(i=0; i<bytes_multi; i+=4) {
  81. long_buf = (unsigned long*) &buf[i];
  82. NDDB = *long_buf;
  83. }
  84. }
  85. if(rest) {
  86. printf("delta_write_buf: ERROR, writing non 4-byte aligned data.\n");
  87. }
  88. return;
  89. }
  90. /*
  91. * These functions are quite problematic for the DFC. Luckily they are
  92. * not used in the current nand code, except for nand_command, which
  93. * we've defined our own anyway. The problem is, that we always need
  94. * to write 4 bytes to the DFC Data Buffer, but in these functions we
  95. * don't know if to buffer the bytes/half words until we've gathered 4
  96. * bytes or if to send them straight away.
  97. *
  98. * Solution: Don't use these with Mona's DFC and complain loudly.
  99. */
  100. static void delta_write_word(struct mtd_info *mtd, u16 word)
  101. {
  102. printf("delta_write_word: WARNING, this function does not work with the Monahans DFC!\n");
  103. }
  104. static void delta_write_byte(struct mtd_info *mtd, u_char byte)
  105. {
  106. printf("delta_write_byte: WARNING, this function does not work with the Monahans DFC!\n");
  107. }
  108. /* The original:
  109. * static void delta_read_buf(struct mtd_info *mtd, const u_char *buf, int len)
  110. *
  111. * Shouldn't this be "u_char * const buf" ?
  112. */
  113. static void delta_read_buf(struct mtd_info *mtd, u_char* const buf, int len)
  114. {
  115. int i, j;
  116. /* we have to be carefull not to overflow the buffer if len is
  117. * not a multiple of 4 */
  118. unsigned long bytes_multi = len & 0xfffffffc;
  119. unsigned long rest = len & 0x3;
  120. unsigned long *long_buf;
  121. /* if there are any, first copy multiple of 4 bytes */
  122. if(bytes_multi) {
  123. for(i=0; i<bytes_multi; i+=4) {
  124. long_buf = (unsigned long*) &buf[i];
  125. *long_buf = NDDB;
  126. }
  127. }
  128. /* ...then the rest */
  129. if(rest) {
  130. unsigned long rest_data = NDDB;
  131. for(j=0;j<rest; j++)
  132. buf[i+j] = (u_char) ((rest_data>>j) & 0xff);
  133. }
  134. return;
  135. }
  136. /*
  137. * read a word. Not implemented as not used in NAND code.
  138. */
  139. static u16 delta_read_word(struct mtd_info *mtd)
  140. {
  141. printf("delta_write_byte: UNIMPLEMENTED.\n");
  142. }
  143. /* global var, too bad: mk@tbd: move to ->priv pointer */
  144. static unsigned long read_buf = 0;
  145. static int bytes_read = -1;
  146. /* read a byte from NDDB Because we can only read 4 bytes from NDDB at
  147. * a time, we buffer the remaining bytes. The buffer is reset when a
  148. * new command is sent to the chip.
  149. */
  150. static u_char delta_read_byte(struct mtd_info *mtd)
  151. {
  152. /* struct nand_chip *this = mtd->priv; */
  153. unsigned char byte;
  154. if(bytes_read < 0) {
  155. read_buf = NDDB;
  156. bytes_read = 0;
  157. }
  158. byte = (unsigned char) (read_buf>>(8 * bytes_read++));
  159. if(bytes_read >= 4)
  160. bytes_read = -1;
  161. DFC_DEBUG2("delta_read_byte: byte %u: 0x%x of (0x%x).\n", bytes_read, byte, read_buf);
  162. return byte;
  163. }
  164. /* calculate delta between OSCR values start and now */
  165. static unsigned long get_delta(unsigned long start)
  166. {
  167. unsigned long cur = OSCR;
  168. if(cur < start) /* OSCR overflowed */
  169. return (cur + (start^0xffffffff));
  170. else
  171. return (cur - start);
  172. }
  173. /* delay function, this doesn't belong here */
  174. static void wait_us(unsigned long us)
  175. {
  176. unsigned long start = OSCR;
  177. us *= OSCR_CLK_FREQ;
  178. while (get_delta(start) < us) {
  179. /* do nothing */
  180. }
  181. }
  182. static void delta_clear_nddb()
  183. {
  184. NDCR &= ~NDCR_ND_RUN;
  185. wait_us(CFG_NAND_OTHER_TO);
  186. }
  187. /* wait_event with timeout */
  188. static unsigned long delta_wait_event2(unsigned long event)
  189. {
  190. unsigned long ndsr, timeout, start = OSCR;
  191. if(!event)
  192. return 0xff000000;
  193. else if(event & (NDSR_CS0_CMDD | NDSR_CS0_BBD))
  194. timeout = CFG_NAND_PROG_ERASE_TO * OSCR_CLK_FREQ;
  195. else
  196. timeout = CFG_NAND_OTHER_TO * OSCR_CLK_FREQ;
  197. while(1) {
  198. ndsr = NDSR;
  199. if(ndsr & event) {
  200. NDSR |= event;
  201. break;
  202. }
  203. if(get_delta(start) > timeout) {
  204. DFC_DEBUG1("delta_wait_event: TIMEOUT waiting for event: 0x%x.\n", event);
  205. return 0xff000000;
  206. }
  207. }
  208. return ndsr;
  209. }
  210. #if DEADCODE
  211. /* poll the NAND Controller Status Register for event */
  212. static void delta_wait_event(unsigned long event)
  213. {
  214. if(!event)
  215. return;
  216. while(1) {
  217. if(NDSR & event) {
  218. NDSR |= event;
  219. break;
  220. }
  221. }
  222. }
  223. #endif
  224. /* we don't always wan't to do this */
  225. static void delta_new_cmd()
  226. {
  227. int retry = 0;
  228. unsigned long status;
  229. while(retry++ <= CFG_NAND_SENDCMD_RETRY) {
  230. /* Clear NDSR */
  231. NDSR = 0xFFF;
  232. /* set NDCR[NDRUN] */
  233. if(!(NDCR & NDCR_ND_RUN))
  234. NDCR |= NDCR_ND_RUN;
  235. status = delta_wait_event2(NDSR_WRCMDREQ);
  236. if(status & NDSR_WRCMDREQ)
  237. return;
  238. DFC_DEBUG2("delta_new_cmd: FAILED to get WRITECMDREQ, retry: %d.\n", retry);
  239. delta_clear_nddb();
  240. }
  241. DFC_DEBUG1("delta_new_cmd: giving up after %d retries.\n", retry);
  242. #if DEADCODE
  243. while(1) {
  244. if(NDSR & NDSR_WRCMDREQ) {
  245. NDSR |= NDSR_WRCMDREQ; /* Ack */
  246. break;
  247. }
  248. }
  249. #endif
  250. }
  251. /* this function is called after Programm and Erase Operations to
  252. * check for success or failure */
  253. static int delta_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
  254. {
  255. unsigned long ndsr=0, event=0;
  256. /* mk@tbd set appropriate timeouts */
  257. /* if (state == FL_ERASING) */
  258. /* timeo = CFG_HZ * 400; */
  259. /* else */
  260. /* timeo = CFG_HZ * 20; */
  261. if(state == FL_WRITING) {
  262. event = NDSR_CS0_CMDD | NDSR_CS0_BBD;
  263. } else if(state == FL_ERASING) {
  264. event = NDSR_CS0_CMDD | NDSR_CS0_BBD;
  265. }
  266. ndsr = delta_wait_event2(event);
  267. if((ndsr & NDSR_CS0_BBD) || (ndsr & 0xff000000))
  268. return(0x1); /* Status Read error */
  269. return 0;
  270. }
  271. /* cmdfunc send commands to the DFC */
  272. static void delta_cmdfunc(struct mtd_info *mtd, unsigned command,
  273. int column, int page_addr)
  274. {
  275. /* register struct nand_chip *this = mtd->priv; */
  276. unsigned long ndcb0=0, ndcb1=0, ndcb2=0, event=0;
  277. unsigned long what_the_hack;
  278. /* clear the ugly byte read buffer */
  279. bytes_read = -1;
  280. read_buf = 0;
  281. /* if command is a double byte cmd, we set bit double cmd bit 19 */
  282. /* command2 = (command>>8) & 0xFF; */
  283. /* ndcb0 = command | ((command2 ? 1 : 0) << 19); *\/ */
  284. switch (command) {
  285. case NAND_CMD_READ0:
  286. delta_new_cmd();
  287. ndcb0 = (NAND_CMD_READ0 | (4<<16));
  288. column >>= 1; /* adjust for 16 bit bus */
  289. ndcb1 = (((column>>1) & 0xff) |
  290. ((page_addr<<8) & 0xff00) |
  291. ((page_addr<<8) & 0xff0000) |
  292. ((page_addr<<8) & 0xff000000)); /* make this 0x01000000 ? */
  293. event = NDSR_RDDREQ;
  294. goto write_cmd;
  295. case NAND_CMD_READID:
  296. delta_new_cmd();
  297. DFC_DEBUG2("delta_cmdfunc: NAND_CMD_READID.\n");
  298. ndcb0 = (NAND_CMD_READID | (3 << 21) | (1 << 16)); /* addr cycles*/
  299. event = NDSR_RDDREQ;
  300. goto write_cmd;
  301. case NAND_CMD_PAGEPROG:
  302. /* sent as a multicommand in NAND_CMD_SEQIN */
  303. DFC_DEBUG2("delta_cmdfunc: NAND_CMD_PAGEPROG empty due to multicmd.\n");
  304. goto end;
  305. case NAND_CMD_ERASE1:
  306. DFC_DEBUG2("delta_cmdfunc: NAND_CMD_ERASE1.\n");
  307. delta_new_cmd();
  308. ndcb0 = (0xd060 | (1<<25) | (2<<21) | (1<<19) | (3<<16));
  309. ndcb1 = (page_addr & 0x00ffffff);
  310. goto write_cmd;
  311. case NAND_CMD_ERASE2:
  312. DFC_DEBUG2("delta_cmdfunc: NAND_CMD_ERASE2 empty due to multicmd.\n");
  313. goto end;
  314. case NAND_CMD_SEQIN:
  315. /* send PAGE_PROG command(0x1080) */
  316. delta_new_cmd();
  317. DFC_DEBUG2("delta_cmdfunc: NAND_CMD_SEQIN/PAGE_PROG.\n");
  318. ndcb0 = (0x1080 | (1<<25) | (1<<21) | (1<<19) | (4<<16));
  319. column >>= 1; /* adjust for 16 bit bus */
  320. ndcb1 = (((column>>1) & 0xff) |
  321. ((page_addr<<8) & 0xff00) |
  322. ((page_addr<<8) & 0xff0000) |
  323. ((page_addr<<8) & 0xff000000)); /* make this 0x01000000 ? */
  324. event = NDSR_WRDREQ;
  325. goto write_cmd;
  326. /* case NAND_CMD_SEQIN_pointer_operation: */
  327. /* /\* This is confusing because the command names are */
  328. /* * different compared to the ones in the K9K12Q0C */
  329. /* * datasheet. Infact this has nothing to do with */
  330. /* * reading, as the but with page programming */
  331. /* * (writing). */
  332. /* * Here we send the multibyte commands */
  333. /* * cmd1=0x00, cmd2=0x80 (for programming main area) or */
  334. /* * cmd1=0x50, cmd2=0x80 (for spare area) */
  335. /* * */
  336. /* * When all data is written to the buffer, the page */
  337. /* * program command (0x10) is sent to actually write */
  338. /* * the data. */
  339. /* *\/ */
  340. /* printf("delta_cmdfunc: NAND_CMD_SEQIN pointer op called.\n"); */
  341. /* ndcb0 = (NAND_CMD_SEQIN<<8) | (1<<21) | (1<<19) | (4<<16); */
  342. /* if(column >= mtd->oobblock) { */
  343. /* /\* OOB area *\/ */
  344. /* column -= mtd->oobblock; */
  345. /* ndcb0 |= NAND_CMD_READOOB; */
  346. /* } else if (column < 256) { */
  347. /* /\* First 256 bytes --> READ0 *\/ */
  348. /* ndcb0 |= NAND_CMD_READ0; */
  349. /* } else { */
  350. /* /\* Only for 8 bit devices - not delta!!! *\/ */
  351. /* column -= 256; */
  352. /* ndcb0 |= NAND_CMD_READ1; */
  353. /* } */
  354. /* event = NDSR_WRDREQ; */
  355. /* break; */
  356. case NAND_CMD_STATUS:
  357. DFC_DEBUG2("delta_cmdfunc: NAND_CMD_STATUS.\n");
  358. /* oh, this is not nice. for some reason the real
  359. * status byte is in the second read from the data
  360. * buffer. The hack is to read the first byte right
  361. * here, so the next read access by the nand code
  362. * yields the right one.
  363. */
  364. delta_new_cmd();
  365. ndcb0 = NAND_CMD_STATUS | (4<<21);
  366. event = NDSR_RDDREQ;
  367. #undef READ_STATUS_BUG
  368. #ifdef READ_STATUS_BUG
  369. NDCB0 = ndcb0;
  370. NDCB0 = ndcb1;
  371. NDCB0 = ndcb2;
  372. delta_wait_event2(event);
  373. what_the_hack = NDDB;
  374. if(what_the_hack != 0xffffffff) {
  375. DFC_DEBUG2("what the hack.\n");
  376. read_buf = what_the_hack;
  377. bytes_read = 0;
  378. }
  379. goto end;
  380. #endif
  381. goto write_cmd;
  382. case NAND_CMD_RESET:
  383. DFC_DEBUG2("delta_cmdfunc: NAND_CMD_RESET.\n");
  384. ndcb0 = NAND_CMD_RESET | (5<<21);
  385. event = NDSR_CS0_CMDD;
  386. goto write_cmd;
  387. default:
  388. printk("delta_cmdfunc: error, unsupported command.\n");
  389. goto end;
  390. }
  391. write_cmd:
  392. NDCB0 = ndcb0;
  393. NDCB0 = ndcb1;
  394. NDCB0 = ndcb2;
  395. wait_event:
  396. delta_wait_event2(event);
  397. end:
  398. return;
  399. }
  400. static void delta_dfc_gpio_init()
  401. {
  402. DFC_DEBUG2("Setting up DFC GPIO's.\n");
  403. /* no idea what is done here, see zylonite.c */
  404. GPIO4 = 0x1;
  405. DF_ALE_WE1 = 0x00000001;
  406. DF_ALE_WE2 = 0x00000001;
  407. DF_nCS0 = 0x00000001;
  408. DF_nCS1 = 0x00000001;
  409. DF_nWE = 0x00000001;
  410. DF_nRE = 0x00000001;
  411. DF_IO0 = 0x00000001;
  412. DF_IO8 = 0x00000001;
  413. DF_IO1 = 0x00000001;
  414. DF_IO9 = 0x00000001;
  415. DF_IO2 = 0x00000001;
  416. DF_IO10 = 0x00000001;
  417. DF_IO3 = 0x00000001;
  418. DF_IO11 = 0x00000001;
  419. DF_IO4 = 0x00000001;
  420. DF_IO12 = 0x00000001;
  421. DF_IO5 = 0x00000001;
  422. DF_IO13 = 0x00000001;
  423. DF_IO6 = 0x00000001;
  424. DF_IO14 = 0x00000001;
  425. DF_IO7 = 0x00000001;
  426. DF_IO15 = 0x00000001;
  427. DF_nWE = 0x1901;
  428. DF_nRE = 0x1901;
  429. DF_CLE_NOE = 0x1900;
  430. DF_ALE_WE1 = 0x1901;
  431. DF_INT_RnB = 0x1900;
  432. }
  433. /*
  434. * Board-specific NAND initialization. The following members of the
  435. * argument are board-specific (per include/linux/mtd/nand_new.h):
  436. * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device
  437. * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device
  438. * - hwcontrol: hardwarespecific function for accesing control-lines
  439. * - dev_ready: hardwarespecific function for accesing device ready/busy line
  440. * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must
  441. * only be provided if a hardware ECC is available
  442. * - eccmode: mode of ecc, see defines
  443. * - chip_delay: chip dependent delay for transfering data from array to
  444. * read regs (tR)
  445. * - options: various chip options. They can partly be set to inform
  446. * nand_scan about special functionality. See the defines for further
  447. * explanation
  448. * Members with a "?" were not set in the merged testing-NAND branch,
  449. * so they are not set here either.
  450. */
  451. void board_nand_init(struct nand_chip *nand)
  452. {
  453. unsigned long tCH, tCS, tWH, tWP, tRH, tRP, tRP_high, tR, tWHR, tAR;
  454. /* set up GPIO Control Registers */
  455. delta_dfc_gpio_init();
  456. /* turn on the NAND Controller Clock (104 MHz @ D0) */
  457. CKENA |= (CKENA_4_NAND | CKENA_9_SMC);
  458. /* wait ? */
  459. /* printf("stupid loop start...\n"); */
  460. /* wait(200); */
  461. /* printf("stupid loop end.\n"); */
  462. /* NAND Timing Parameters (in ns) */
  463. #define NAND_TIMING_tCH 10
  464. #define NAND_TIMING_tCS 0
  465. #define NAND_TIMING_tWH 20
  466. #define NAND_TIMING_tWP 40
  467. #define NAND_TIMING_tRH 20
  468. #define NAND_TIMING_tRP 40
  469. /* #define NAND_TIMING_tRH 25 */
  470. /* #define NAND_TIMING_tRP 50 */
  471. #define NAND_TIMING_tR 11123
  472. /* #define NAND_TIMING_tWHR 110 */
  473. #define NAND_TIMING_tWHR 100
  474. #define NAND_TIMING_tAR 10
  475. /* Maximum values for NAND Interface Timing Registers in DFC clock
  476. * periods */
  477. #define DFC_MAX_tCH 7
  478. #define DFC_MAX_tCS 7
  479. #define DFC_MAX_tWH 7
  480. #define DFC_MAX_tWP 7
  481. #define DFC_MAX_tRH 7
  482. #define DFC_MAX_tRP 15
  483. #define DFC_MAX_tR 65535
  484. #define DFC_MAX_tWHR 15
  485. #define DFC_MAX_tAR 15
  486. #define DFC_CLOCK 104 /* DFC Clock is 104 MHz */
  487. #define DFC_CLK_PER_US DFC_CLOCK/1000 /* clock period in ns */
  488. #define MIN(x, y) ((x < y) ? x : y)
  489. #ifndef CFG_TIMING_TIGHT
  490. tCH = MIN(((unsigned long) (NAND_TIMING_tCH * DFC_CLK_PER_US) + 1),
  491. DFC_MAX_tCH);
  492. tCS = MIN(((unsigned long) (NAND_TIMING_tCS * DFC_CLK_PER_US) + 1),
  493. DFC_MAX_tCS);
  494. tWH = MIN(((unsigned long) (NAND_TIMING_tWH * DFC_CLK_PER_US) + 1),
  495. DFC_MAX_tWH);
  496. tWP = MIN(((unsigned long) (NAND_TIMING_tWP * DFC_CLK_PER_US) + 1),
  497. DFC_MAX_tWP);
  498. tRH = MIN(((unsigned long) (NAND_TIMING_tRH * DFC_CLK_PER_US) + 1),
  499. DFC_MAX_tRH);
  500. tRP = MIN(((unsigned long) (NAND_TIMING_tRP * DFC_CLK_PER_US) + 1),
  501. DFC_MAX_tRP);
  502. tR = MIN(((unsigned long) (NAND_TIMING_tR * DFC_CLK_PER_US) + 1),
  503. DFC_MAX_tR);
  504. tWHR = MIN(((unsigned long) (NAND_TIMING_tWHR * DFC_CLK_PER_US) + 1),
  505. DFC_MAX_tWHR);
  506. tAR = MIN(((unsigned long) (NAND_TIMING_tAR * DFC_CLK_PER_US) + 1),
  507. DFC_MAX_tAR);
  508. #else /* this is the tight timing */
  509. tCH = MIN(((unsigned long) (NAND_TIMING_tCH * DFC_CLK_PER_US)),
  510. DFC_MAX_tCH);
  511. tCS = MIN(((unsigned long) (NAND_TIMING_tCS * DFC_CLK_PER_US)),
  512. DFC_MAX_tCS);
  513. tWH = MIN(((unsigned long) (NAND_TIMING_tWH * DFC_CLK_PER_US)),
  514. DFC_MAX_tWH);
  515. tWP = MIN(((unsigned long) (NAND_TIMING_tWP * DFC_CLK_PER_US)),
  516. DFC_MAX_tWP);
  517. tRH = MIN(((unsigned long) (NAND_TIMING_tRH * DFC_CLK_PER_US)),
  518. DFC_MAX_tRH);
  519. tRP = MIN(((unsigned long) (NAND_TIMING_tRP * DFC_CLK_PER_US)),
  520. DFC_MAX_tRP);
  521. tR = MIN(((unsigned long) (NAND_TIMING_tR * DFC_CLK_PER_US) - tCH - 2),
  522. DFC_MAX_tR);
  523. tWHR = MIN(((unsigned long) (NAND_TIMING_tWHR * DFC_CLK_PER_US) - tCH - 2),
  524. DFC_MAX_tWHR);
  525. tAR = MIN(((unsigned long) (NAND_TIMING_tAR * DFC_CLK_PER_US) - 2),
  526. DFC_MAX_tAR);
  527. #endif /* CFG_TIMING_TIGHT */
  528. DFC_DEBUG2("tCH=%u, tCS=%u, tWH=%u, tWP=%u, tRH=%u, tRP=%u, tR=%u, tWHR=%u, tAR=%u.\n", tCH, tCS, tWH, tWP, tRH, tRP, tR, tWHR, tAR);
  529. /* tRP value is split in the register */
  530. if(tRP & (1 << 4)) {
  531. tRP_high = 1;
  532. tRP &= ~(1 << 4);
  533. } else {
  534. tRP_high = 0;
  535. }
  536. NDTR0CS0 = (tCH << 19) |
  537. (tCS << 16) |
  538. (tWH << 11) |
  539. (tWP << 8) |
  540. (tRP_high << 6) |
  541. (tRH << 3) |
  542. (tRP << 0);
  543. NDTR1CS0 = (tR << 16) |
  544. (tWHR << 4) |
  545. (tAR << 0);
  546. /* If it doesn't work (unlikely) think about:
  547. * - ecc enable
  548. * - chip select don't care
  549. * - read id byte count
  550. *
  551. * Intentionally enabled by not setting bits:
  552. * - dma (DMA_EN)
  553. * - page size = 512
  554. * - cs don't care, see if we can enable later!
  555. * - row address start position (after second cycle)
  556. * - pages per block = 32
  557. * - ND_RDY : clears command buffer
  558. */
  559. /* NDCR_NCSX | /\* Chip select busy don't care *\/ */
  560. NDCR = (NDCR_SPARE_EN | /* use the spare area */
  561. NDCR_DWIDTH_C | /* 16bit DFC data bus width */
  562. NDCR_DWIDTH_M | /* 16 bit Flash device data bus width */
  563. (7 << 16) | /* read id count = 7 ???? mk@tbd */
  564. NDCR_ND_ARB_EN | /* enable bus arbiter */
  565. NDCR_RDYM | /* flash device ready ir masked */
  566. NDCR_CS0_PAGEDM | /* ND_nCSx page done ir masked */
  567. NDCR_CS1_PAGEDM |
  568. NDCR_CS0_CMDDM | /* ND_CSx command done ir masked */
  569. NDCR_CS1_CMDDM |
  570. NDCR_CS0_BBDM | /* ND_CSx bad block detect ir masked */
  571. NDCR_CS1_BBDM |
  572. NDCR_DBERRM | /* double bit error ir masked */
  573. NDCR_SBERRM | /* single bit error ir masked */
  574. NDCR_WRDREQM | /* write data request ir masked */
  575. NDCR_RDDREQM | /* read data request ir masked */
  576. NDCR_WRCMDREQM); /* write command request ir masked */
  577. /* wait 10 us due to cmd buffer clear reset */
  578. /* wait(10); */
  579. nand->hwcontrol = delta_hwcontrol;
  580. /* nand->dev_ready = delta_device_ready; */
  581. nand->eccmode = NAND_ECC_SOFT;
  582. nand->chip_delay = NAND_DELAY_US;
  583. nand->options = NAND_BUSWIDTH_16;
  584. nand->waitfunc = delta_wait;
  585. nand->read_byte = delta_read_byte;
  586. nand->write_byte = delta_write_byte;
  587. nand->read_word = delta_read_word;
  588. nand->write_word = delta_write_word;
  589. nand->read_buf = delta_read_buf;
  590. nand->write_buf = delta_write_buf;
  591. nand->cmdfunc = delta_cmdfunc;
  592. nand->autooob = &delta_oob;
  593. nand->badblock_pattern = &delta_bbt_descr;
  594. }
  595. #else
  596. #error "U-Boot legacy NAND support not available for delta board."
  597. #endif
  598. #endif