lld_mtd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * NAND Flash Controller Device Driver
  3. * Copyright (c) 2009, Intel Corporation and its suppliers.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #include <linux/fs.h>
  20. #include <linux/slab.h>
  21. #include <linux/mtd/mtd.h>
  22. #include "flash.h"
  23. #include "ffsdefs.h"
  24. #include "lld_emu.h"
  25. #include "lld.h"
  26. #if CMD_DMA
  27. #include "lld_cdma.h"
  28. #endif
  29. #define GLOB_LLD_PAGES 64
  30. #define GLOB_LLD_PAGE_SIZE (512+16)
  31. #define GLOB_LLD_PAGE_DATA_SIZE 512
  32. #define GLOB_LLD_BLOCKS 2048
  33. #if CMD_DMA
  34. #include "lld_cdma.h"
  35. u32 totalUsedBanks;
  36. u32 valid_banks[MAX_CHANS];
  37. #endif
  38. static struct mtd_info *spectra_mtd;
  39. static int mtddev = -1;
  40. module_param(mtddev, int, 0);
  41. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  42. * Function: mtd_Flash_Init
  43. * Inputs: none
  44. * Outputs: PASS=0 (notice 0=ok here)
  45. * Description: Creates & initializes the flash RAM array.
  46. *
  47. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  48. u16 mtd_Flash_Init(void)
  49. {
  50. if (mtddev == -1) {
  51. printk(KERN_ERR "No MTD device specified. Give mtddev parameter\n");
  52. return FAIL;
  53. }
  54. spectra_mtd = get_mtd_device(NULL, mtddev);
  55. if (!spectra_mtd) {
  56. printk(KERN_ERR "Failed to obtain MTD device #%d\n", mtddev);
  57. return FAIL;
  58. }
  59. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  60. __FILE__, __LINE__, __func__);
  61. return PASS;
  62. }
  63. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  64. * Function: mtd_Flash_Release
  65. * Inputs: none
  66. * Outputs: PASS=0 (notice 0=ok here)
  67. * Description: Releases the flash.
  68. *
  69. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  70. int mtd_Flash_Release(void)
  71. {
  72. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  73. __FILE__, __LINE__, __func__);
  74. if (!spectra_mtd)
  75. return PASS;
  76. put_mtd_device(spectra_mtd);
  77. spectra_mtd = NULL;
  78. return PASS;
  79. }
  80. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  81. * Function: mtd_Read_Device_ID
  82. * Inputs: none
  83. * Outputs: PASS=1 FAIL=0
  84. * Description: Reads the info from the controller registers.
  85. * Sets up DeviceInfo structure with device parameters
  86. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  87. u16 mtd_Read_Device_ID(void)
  88. {
  89. uint64_t tmp;
  90. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  91. __FILE__, __LINE__, __func__);
  92. if (!spectra_mtd)
  93. return FAIL;
  94. DeviceInfo.wDeviceMaker = 0;
  95. DeviceInfo.wDeviceType = 8;
  96. DeviceInfo.wSpectraStartBlock = SPECTRA_START_BLOCK;
  97. tmp = spectra_mtd->size;
  98. do_div(tmp, spectra_mtd->erasesize);
  99. DeviceInfo.wTotalBlocks = tmp;
  100. DeviceInfo.wSpectraEndBlock = DeviceInfo.wTotalBlocks - 1;
  101. DeviceInfo.wPagesPerBlock = spectra_mtd->erasesize / spectra_mtd->writesize;
  102. DeviceInfo.wPageSize = spectra_mtd->writesize + spectra_mtd->oobsize;
  103. DeviceInfo.wPageDataSize = spectra_mtd->writesize;
  104. DeviceInfo.wPageSpareSize = spectra_mtd->oobsize;
  105. DeviceInfo.wBlockSize = DeviceInfo.wPageSize * DeviceInfo.wPagesPerBlock;
  106. DeviceInfo.wBlockDataSize = DeviceInfo.wPageDataSize * DeviceInfo.wPagesPerBlock;
  107. DeviceInfo.wDataBlockNum = (u32) (DeviceInfo.wSpectraEndBlock -
  108. DeviceInfo.wSpectraStartBlock
  109. + 1);
  110. DeviceInfo.MLCDevice = 0;//spectra_mtd->celltype & NAND_CI_CELLTYPE_MSK;
  111. DeviceInfo.nBitsInPageNumber =
  112. (u8)GLOB_Calc_Used_Bits(DeviceInfo.wPagesPerBlock);
  113. DeviceInfo.nBitsInPageDataSize =
  114. (u8)GLOB_Calc_Used_Bits(DeviceInfo.wPageDataSize);
  115. DeviceInfo.nBitsInBlockDataSize =
  116. (u8)GLOB_Calc_Used_Bits(DeviceInfo.wBlockDataSize);
  117. #if CMD_DMA
  118. totalUsedBanks = 4;
  119. valid_banks[0] = 1;
  120. valid_banks[1] = 1;
  121. valid_banks[2] = 1;
  122. valid_banks[3] = 1;
  123. #endif
  124. return PASS;
  125. }
  126. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  127. * Function: mtd_Flash_Reset
  128. * Inputs: none
  129. * Outputs: PASS=0 (notice 0=ok here)
  130. * Description: Reset the flash
  131. *
  132. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  133. u16 mtd_Flash_Reset(void)
  134. {
  135. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  136. __FILE__, __LINE__, __func__);
  137. return PASS;
  138. }
  139. void erase_callback(struct erase_info *e)
  140. {
  141. complete((void *)e->priv);
  142. }
  143. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  144. * Function: mtd_Erase_Block
  145. * Inputs: Address
  146. * Outputs: PASS=0 (notice 0=ok here)
  147. * Description: Erase a block
  148. *
  149. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  150. u16 mtd_Erase_Block(u32 block_add)
  151. {
  152. struct erase_info erase;
  153. DECLARE_COMPLETION_ONSTACK(comp);
  154. int ret;
  155. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  156. __FILE__, __LINE__, __func__);
  157. if (block_add >= DeviceInfo.wTotalBlocks) {
  158. printk(KERN_ERR "mtd_Erase_Block error! "
  159. "Too big block address: %d\n", block_add);
  160. return FAIL;
  161. }
  162. nand_dbg_print(NAND_DBG_DEBUG, "Erasing block %d\n",
  163. (int)block_add);
  164. erase.mtd = spectra_mtd;
  165. erase.callback = erase_callback;
  166. erase.addr = block_add * spectra_mtd->erasesize;
  167. erase.len = spectra_mtd->erasesize;
  168. erase.priv = (unsigned long)&comp;
  169. ret = spectra_mtd->erase(spectra_mtd, &erase);
  170. if (!ret) {
  171. wait_for_completion(&comp);
  172. if (erase.state != MTD_ERASE_DONE)
  173. ret = -EIO;
  174. }
  175. if (ret) {
  176. printk(KERN_WARNING "mtd_Erase_Block error! "
  177. "erase of region [0x%llx, 0x%llx] failed\n",
  178. erase.addr, erase.len);
  179. return FAIL;
  180. }
  181. return PASS;
  182. }
  183. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  184. * Function: mtd_Write_Page_Main
  185. * Inputs: Write buffer address pointer
  186. * Block number
  187. * Page number
  188. * Number of pages to process
  189. * Outputs: PASS=0 (notice 0=ok here)
  190. * Description: Write the data in the buffer to main area of flash
  191. *
  192. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  193. u16 mtd_Write_Page_Main(u8 *write_data, u32 Block,
  194. u16 Page, u16 PageCount)
  195. {
  196. size_t retlen;
  197. int ret = 0;
  198. if (Block >= DeviceInfo.wTotalBlocks)
  199. return FAIL;
  200. if (Page + PageCount > DeviceInfo.wPagesPerBlock)
  201. return FAIL;
  202. nand_dbg_print(NAND_DBG_DEBUG, "mtd_Write_Page_Main: "
  203. "lba %u Page %u PageCount %u\n",
  204. (unsigned int)Block,
  205. (unsigned int)Page, (unsigned int)PageCount);
  206. while (PageCount) {
  207. ret = spectra_mtd->write(spectra_mtd,
  208. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  209. DeviceInfo.wPageDataSize, &retlen, write_data);
  210. if (ret) {
  211. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  212. return FAIL;
  213. }
  214. write_data += DeviceInfo.wPageDataSize;
  215. Page++;
  216. PageCount--;
  217. }
  218. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  219. __FILE__, __LINE__, __func__);
  220. return PASS;
  221. }
  222. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  223. * Function: mtd_Read_Page_Main
  224. * Inputs: Read buffer address pointer
  225. * Block number
  226. * Page number
  227. * Number of pages to process
  228. * Outputs: PASS=0 (notice 0=ok here)
  229. * Description: Read the data from the flash main area to the buffer
  230. *
  231. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  232. u16 mtd_Read_Page_Main(u8 *read_data, u32 Block,
  233. u16 Page, u16 PageCount)
  234. {
  235. size_t retlen;
  236. int ret = 0;
  237. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  238. __FILE__, __LINE__, __func__);
  239. if (Block >= DeviceInfo.wTotalBlocks)
  240. return FAIL;
  241. if (Page + PageCount > DeviceInfo.wPagesPerBlock)
  242. return FAIL;
  243. nand_dbg_print(NAND_DBG_DEBUG, "mtd_Read_Page_Main: "
  244. "lba %u Page %u PageCount %u\n",
  245. (unsigned int)Block,
  246. (unsigned int)Page, (unsigned int)PageCount);
  247. while (PageCount) {
  248. ret = spectra_mtd->read(spectra_mtd,
  249. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  250. DeviceInfo.wPageDataSize, &retlen, read_data);
  251. if (ret) {
  252. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  253. return FAIL;
  254. }
  255. read_data += DeviceInfo.wPageDataSize;
  256. Page++;
  257. PageCount--;
  258. }
  259. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  260. __FILE__, __LINE__, __func__);
  261. return PASS;
  262. }
  263. #ifndef ELDORA
  264. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  265. * Function: mtd_Read_Page_Main_Spare
  266. * Inputs: Write Buffer
  267. * Address
  268. * Buffer size
  269. * Outputs: PASS=0 (notice 0=ok here)
  270. * Description: Read from flash main+spare area
  271. *
  272. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  273. u16 mtd_Read_Page_Main_Spare(u8 *read_data, u32 Block,
  274. u16 Page, u16 PageCount)
  275. {
  276. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  277. __FILE__, __LINE__, __func__);
  278. if (Block >= DeviceInfo.wTotalBlocks) {
  279. printk(KERN_ERR "Read Page Main+Spare "
  280. "Error: Block Address too big\n");
  281. return FAIL;
  282. }
  283. if (Page + PageCount > DeviceInfo.wPagesPerBlock) {
  284. printk(KERN_ERR "Read Page Main+Spare "
  285. "Error: Page number %d+%d too big in block %d\n",
  286. Page, PageCount, Block);
  287. return FAIL;
  288. }
  289. nand_dbg_print(NAND_DBG_DEBUG, "Read Page Main + Spare - "
  290. "No. of pages %u block %u start page %u\n",
  291. (unsigned int)PageCount,
  292. (unsigned int)Block, (unsigned int)Page);
  293. while (PageCount) {
  294. struct mtd_oob_ops ops;
  295. int ret;
  296. ops.mode = MTD_OOB_AUTO;
  297. ops.datbuf = read_data;
  298. ops.len = DeviceInfo.wPageDataSize;
  299. ops.oobbuf = read_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET;
  300. ops.ooblen = BTSIG_BYTES;
  301. ops.ooboffs = 0;
  302. ret = spectra_mtd->read_oob(spectra_mtd,
  303. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  304. &ops);
  305. if (ret) {
  306. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  307. return FAIL;
  308. }
  309. read_data += DeviceInfo.wPageSize;
  310. Page++;
  311. PageCount--;
  312. }
  313. return PASS;
  314. }
  315. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  316. * Function: mtd_Write_Page_Main_Spare
  317. * Inputs: Write buffer
  318. * address
  319. * buffer length
  320. * Outputs: PASS=0 (notice 0=ok here)
  321. * Description: Write the buffer to main+spare area of flash
  322. *
  323. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  324. u16 mtd_Write_Page_Main_Spare(u8 *write_data, u32 Block,
  325. u16 Page, u16 page_count)
  326. {
  327. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  328. __FILE__, __LINE__, __func__);
  329. if (Block >= DeviceInfo.wTotalBlocks) {
  330. printk(KERN_ERR "Write Page Main + Spare "
  331. "Error: Block Address too big\n");
  332. return FAIL;
  333. }
  334. if (Page + page_count > DeviceInfo.wPagesPerBlock) {
  335. printk(KERN_ERR "Write Page Main + Spare "
  336. "Error: Page number %d+%d too big in block %d\n",
  337. Page, page_count, Block);
  338. WARN_ON(1);
  339. return FAIL;
  340. }
  341. nand_dbg_print(NAND_DBG_DEBUG, "Write Page Main+Spare - "
  342. "No. of pages %u block %u start page %u\n",
  343. (unsigned int)page_count,
  344. (unsigned int)Block, (unsigned int)Page);
  345. while (page_count) {
  346. struct mtd_oob_ops ops;
  347. int ret;
  348. ops.mode = MTD_OOB_AUTO;
  349. ops.datbuf = write_data;
  350. ops.len = DeviceInfo.wPageDataSize;
  351. ops.oobbuf = write_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET;
  352. ops.ooblen = BTSIG_BYTES;
  353. ops.ooboffs = 0;
  354. ret = spectra_mtd->write_oob(spectra_mtd,
  355. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  356. &ops);
  357. if (ret) {
  358. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  359. return FAIL;
  360. }
  361. write_data += DeviceInfo.wPageSize;
  362. Page++;
  363. page_count--;
  364. }
  365. return PASS;
  366. }
  367. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  368. * Function: mtd_Write_Page_Spare
  369. * Inputs: Write buffer
  370. * Address
  371. * buffer size
  372. * Outputs: PASS=0 (notice 0=ok here)
  373. * Description: Write the buffer in the spare area
  374. *
  375. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  376. u16 mtd_Write_Page_Spare(u8 *write_data, u32 Block,
  377. u16 Page, u16 PageCount)
  378. {
  379. WARN_ON(1);
  380. return FAIL;
  381. }
  382. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  383. * Function: mtd_Read_Page_Spare
  384. * Inputs: Write Buffer
  385. * Address
  386. * Buffer size
  387. * Outputs: PASS=0 (notice 0=ok here)
  388. * Description: Read data from the spare area
  389. *
  390. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  391. u16 mtd_Read_Page_Spare(u8 *read_data, u32 Block,
  392. u16 Page, u16 PageCount)
  393. {
  394. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  395. __FILE__, __LINE__, __func__);
  396. if (Block >= DeviceInfo.wTotalBlocks) {
  397. printk(KERN_ERR "Read Page Spare "
  398. "Error: Block Address too big\n");
  399. return FAIL;
  400. }
  401. if (Page + PageCount > DeviceInfo.wPagesPerBlock) {
  402. printk(KERN_ERR "Read Page Spare "
  403. "Error: Page number too big\n");
  404. return FAIL;
  405. }
  406. nand_dbg_print(NAND_DBG_DEBUG, "Read Page Spare- "
  407. "block %u page %u (%u pages)\n",
  408. (unsigned int)Block, (unsigned int)Page, PageCount);
  409. while (PageCount) {
  410. struct mtd_oob_ops ops;
  411. int ret;
  412. ops.mode = MTD_OOB_AUTO;
  413. ops.datbuf = NULL;
  414. ops.len = 0;
  415. ops.oobbuf = read_data;
  416. ops.ooblen = BTSIG_BYTES;
  417. ops.ooboffs = 0;
  418. ret = spectra_mtd->read_oob(spectra_mtd,
  419. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  420. &ops);
  421. if (ret) {
  422. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  423. return FAIL;
  424. }
  425. read_data += DeviceInfo.wPageSize;
  426. Page++;
  427. PageCount--;
  428. }
  429. return PASS;
  430. }
  431. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  432. * Function: mtd_Enable_Disable_Interrupts
  433. * Inputs: enable or disable
  434. * Outputs: none
  435. * Description: NOP
  436. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  437. void mtd_Enable_Disable_Interrupts(u16 INT_ENABLE)
  438. {
  439. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  440. __FILE__, __LINE__, __func__);
  441. }
  442. u16 mtd_Get_Bad_Block(u32 block)
  443. {
  444. return 0;
  445. }
  446. #if CMD_DMA
  447. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  448. * Support for CDMA functions
  449. ************************************
  450. * mtd_CDMA_Flash_Init
  451. * CDMA_process_data command (use LLD_CDMA)
  452. * CDMA_MemCopy_CMD (use LLD_CDMA)
  453. * mtd_CDMA_execute all commands
  454. * mtd_CDMA_Event_Status
  455. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  456. u16 mtd_CDMA_Flash_Init(void)
  457. {
  458. u16 i;
  459. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  460. __FILE__, __LINE__, __func__);
  461. for (i = 0; i < MAX_DESCS + MAX_CHANS; i++) {
  462. PendingCMD[i].CMD = 0;
  463. PendingCMD[i].Tag = 0;
  464. PendingCMD[i].DataAddr = 0;
  465. PendingCMD[i].Block = 0;
  466. PendingCMD[i].Page = 0;
  467. PendingCMD[i].PageCount = 0;
  468. PendingCMD[i].DataDestAddr = 0;
  469. PendingCMD[i].DataSrcAddr = 0;
  470. PendingCMD[i].MemCopyByteCnt = 0;
  471. PendingCMD[i].ChanSync[0] = 0;
  472. PendingCMD[i].ChanSync[1] = 0;
  473. PendingCMD[i].ChanSync[2] = 0;
  474. PendingCMD[i].ChanSync[3] = 0;
  475. PendingCMD[i].ChanSync[4] = 0;
  476. PendingCMD[i].Status = 3;
  477. }
  478. return PASS;
  479. }
  480. static void mtd_isr(int irq, void *dev_id)
  481. {
  482. /* TODO: ... */
  483. }
  484. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  485. * Function: CDMA_Execute_CMDs
  486. * Inputs: tag_count: the number of pending cmds to do
  487. * Outputs: PASS/FAIL
  488. * Description: execute each command in the pending CMD array
  489. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  490. u16 mtd_CDMA_Execute_CMDs(u16 tag_count)
  491. {
  492. u16 i, j;
  493. u8 CMD; /* cmd parameter */
  494. u8 *data;
  495. u32 block;
  496. u16 page;
  497. u16 count;
  498. u16 status = PASS;
  499. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  500. __FILE__, __LINE__, __func__);
  501. nand_dbg_print(NAND_DBG_TRACE, "At start of Execute CMDs: "
  502. "Tag Count %u\n", tag_count);
  503. for (i = 0; i < totalUsedBanks; i++) {
  504. PendingCMD[i].CMD = DUMMY_CMD;
  505. PendingCMD[i].Tag = 0xFF;
  506. PendingCMD[i].Block =
  507. (DeviceInfo.wTotalBlocks / totalUsedBanks) * i;
  508. for (j = 0; j <= MAX_CHANS; j++)
  509. PendingCMD[i].ChanSync[j] = 0;
  510. }
  511. CDMA_Execute_CMDs(tag_count);
  512. #ifdef VERBOSE
  513. print_pending_cmds(tag_count);
  514. #endif
  515. #if DEBUG_SYNC
  516. }
  517. debug_sync_cnt++;
  518. #endif
  519. for (i = MAX_CHANS;
  520. i < tag_count + MAX_CHANS; i++) {
  521. CMD = PendingCMD[i].CMD;
  522. data = PendingCMD[i].DataAddr;
  523. block = PendingCMD[i].Block;
  524. page = PendingCMD[i].Page;
  525. count = PendingCMD[i].PageCount;
  526. switch (CMD) {
  527. case ERASE_CMD:
  528. mtd_Erase_Block(block);
  529. PendingCMD[i].Status = PASS;
  530. break;
  531. case WRITE_MAIN_CMD:
  532. mtd_Write_Page_Main(data, block, page, count);
  533. PendingCMD[i].Status = PASS;
  534. break;
  535. case WRITE_MAIN_SPARE_CMD:
  536. mtd_Write_Page_Main_Spare(data, block, page, count);
  537. PendingCMD[i].Status = PASS;
  538. break;
  539. case READ_MAIN_CMD:
  540. mtd_Read_Page_Main(data, block, page, count);
  541. PendingCMD[i].Status = PASS;
  542. break;
  543. case MEMCOPY_CMD:
  544. memcpy(PendingCMD[i].DataDestAddr,
  545. PendingCMD[i].DataSrcAddr,
  546. PendingCMD[i].MemCopyByteCnt);
  547. case DUMMY_CMD:
  548. PendingCMD[i].Status = PASS;
  549. break;
  550. default:
  551. PendingCMD[i].Status = FAIL;
  552. break;
  553. }
  554. }
  555. /*
  556. * Temperory adding code to reset PendingCMD array for basic testing.
  557. * It should be done at the end of event status function.
  558. */
  559. for (i = tag_count + MAX_CHANS; i < MAX_DESCS; i++) {
  560. PendingCMD[i].CMD = 0;
  561. PendingCMD[i].Tag = 0;
  562. PendingCMD[i].DataAddr = 0;
  563. PendingCMD[i].Block = 0;
  564. PendingCMD[i].Page = 0;
  565. PendingCMD[i].PageCount = 0;
  566. PendingCMD[i].DataDestAddr = 0;
  567. PendingCMD[i].DataSrcAddr = 0;
  568. PendingCMD[i].MemCopyByteCnt = 0;
  569. PendingCMD[i].ChanSync[0] = 0;
  570. PendingCMD[i].ChanSync[1] = 0;
  571. PendingCMD[i].ChanSync[2] = 0;
  572. PendingCMD[i].ChanSync[3] = 0;
  573. PendingCMD[i].ChanSync[4] = 0;
  574. PendingCMD[i].Status = CMD_NOT_DONE;
  575. }
  576. nand_dbg_print(NAND_DBG_TRACE, "At end of Execute CMDs.\n");
  577. mtd_isr(0, 0); /* This is a null isr now. Need fill it in future */
  578. return status;
  579. }
  580. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  581. * Function: mtd_Event_Status
  582. * Inputs: none
  583. * Outputs: Event_Status code
  584. * Description: This function can also be used to force errors
  585. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  586. u16 mtd_CDMA_Event_Status(void)
  587. {
  588. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  589. __FILE__, __LINE__, __func__);
  590. return EVENT_PASS;
  591. }
  592. #endif /* CMD_DMA */
  593. #endif /* !ELDORA */