lld_mtd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  90. __FILE__, __LINE__, __func__);
  91. if (!spectra_mtd)
  92. return FAIL;
  93. DeviceInfo.wDeviceMaker = 0;
  94. DeviceInfo.wDeviceType = 8;
  95. DeviceInfo.wSpectraStartBlock = SPECTRA_START_BLOCK;
  96. DeviceInfo.wTotalBlocks = spectra_mtd->size / spectra_mtd->erasesize;
  97. DeviceInfo.wSpectraEndBlock = DeviceInfo.wTotalBlocks - 1;
  98. DeviceInfo.wPagesPerBlock = spectra_mtd->erasesize / spectra_mtd->writesize;
  99. DeviceInfo.wPageSize = spectra_mtd->writesize + spectra_mtd->oobsize;
  100. DeviceInfo.wPageDataSize = spectra_mtd->writesize;
  101. DeviceInfo.wPageSpareSize = spectra_mtd->oobsize;
  102. DeviceInfo.wBlockSize = DeviceInfo.wPageSize * DeviceInfo.wPagesPerBlock;
  103. DeviceInfo.wBlockDataSize = DeviceInfo.wPageDataSize * DeviceInfo.wPagesPerBlock;
  104. DeviceInfo.wDataBlockNum = (u32) (DeviceInfo.wSpectraEndBlock -
  105. DeviceInfo.wSpectraStartBlock
  106. + 1);
  107. DeviceInfo.MLCDevice = 0;//spectra_mtd->celltype & NAND_CI_CELLTYPE_MSK;
  108. DeviceInfo.nBitsInPageNumber =
  109. (u8)GLOB_Calc_Used_Bits(DeviceInfo.wPagesPerBlock);
  110. DeviceInfo.nBitsInPageDataSize =
  111. (u8)GLOB_Calc_Used_Bits(DeviceInfo.wPageDataSize);
  112. DeviceInfo.nBitsInBlockDataSize =
  113. (u8)GLOB_Calc_Used_Bits(DeviceInfo.wBlockDataSize);
  114. #if CMD_DMA
  115. totalUsedBanks = 4;
  116. valid_banks[0] = 1;
  117. valid_banks[1] = 1;
  118. valid_banks[2] = 1;
  119. valid_banks[3] = 1;
  120. #endif
  121. return PASS;
  122. }
  123. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  124. * Function: mtd_Flash_Reset
  125. * Inputs: none
  126. * Outputs: PASS=0 (notice 0=ok here)
  127. * Description: Reset the flash
  128. *
  129. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  130. u16 mtd_Flash_Reset(void)
  131. {
  132. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  133. __FILE__, __LINE__, __func__);
  134. return PASS;
  135. }
  136. void erase_callback(struct erase_info *e)
  137. {
  138. complete((void *)e->priv);
  139. }
  140. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  141. * Function: mtd_Erase_Block
  142. * Inputs: Address
  143. * Outputs: PASS=0 (notice 0=ok here)
  144. * Description: Erase a block
  145. *
  146. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  147. u16 mtd_Erase_Block(u32 block_add)
  148. {
  149. struct erase_info erase;
  150. DECLARE_COMPLETION_ONSTACK(comp);
  151. int ret;
  152. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  153. __FILE__, __LINE__, __func__);
  154. if (block_add >= DeviceInfo.wTotalBlocks) {
  155. printk(KERN_ERR "mtd_Erase_Block error! "
  156. "Too big block address: %d\n", block_add);
  157. return FAIL;
  158. }
  159. nand_dbg_print(NAND_DBG_DEBUG, "Erasing block %d\n",
  160. (int)block_add);
  161. erase.mtd = spectra_mtd;
  162. erase.callback = erase_callback;
  163. erase.addr = block_add * spectra_mtd->erasesize;
  164. erase.len = spectra_mtd->erasesize;
  165. erase.priv = (unsigned long)&comp;
  166. ret = spectra_mtd->erase(spectra_mtd, &erase);
  167. if (!ret) {
  168. wait_for_completion(&comp);
  169. if (erase.state != MTD_ERASE_DONE)
  170. ret = -EIO;
  171. }
  172. if (ret) {
  173. printk(KERN_WARNING "mtd_Erase_Block error! "
  174. "erase of region [0x%llx, 0x%llx] failed\n",
  175. erase.addr, erase.len);
  176. return FAIL;
  177. }
  178. return PASS;
  179. }
  180. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  181. * Function: mtd_Write_Page_Main
  182. * Inputs: Write buffer address pointer
  183. * Block number
  184. * Page number
  185. * Number of pages to process
  186. * Outputs: PASS=0 (notice 0=ok here)
  187. * Description: Write the data in the buffer to main area of flash
  188. *
  189. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  190. u16 mtd_Write_Page_Main(u8 *write_data, u32 Block,
  191. u16 Page, u16 PageCount)
  192. {
  193. size_t retlen;
  194. int ret = 0;
  195. if (Block >= DeviceInfo.wTotalBlocks)
  196. return FAIL;
  197. if (Page + PageCount > DeviceInfo.wPagesPerBlock)
  198. return FAIL;
  199. nand_dbg_print(NAND_DBG_DEBUG, "mtd_Write_Page_Main: "
  200. "lba %u Page %u PageCount %u\n",
  201. (unsigned int)Block,
  202. (unsigned int)Page, (unsigned int)PageCount);
  203. while (PageCount) {
  204. ret = spectra_mtd->write(spectra_mtd,
  205. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  206. DeviceInfo.wPageDataSize, &retlen, write_data);
  207. if (ret) {
  208. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  209. return FAIL;
  210. }
  211. write_data += DeviceInfo.wPageDataSize;
  212. Page++;
  213. PageCount--;
  214. }
  215. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  216. __FILE__, __LINE__, __func__);
  217. return PASS;
  218. }
  219. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  220. * Function: mtd_Read_Page_Main
  221. * Inputs: Read buffer address pointer
  222. * Block number
  223. * Page number
  224. * Number of pages to process
  225. * Outputs: PASS=0 (notice 0=ok here)
  226. * Description: Read the data from the flash main area to the buffer
  227. *
  228. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  229. u16 mtd_Read_Page_Main(u8 *read_data, u32 Block,
  230. u16 Page, u16 PageCount)
  231. {
  232. size_t retlen;
  233. int ret = 0;
  234. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  235. __FILE__, __LINE__, __func__);
  236. if (Block >= DeviceInfo.wTotalBlocks)
  237. return FAIL;
  238. if (Page + PageCount > DeviceInfo.wPagesPerBlock)
  239. return FAIL;
  240. nand_dbg_print(NAND_DBG_DEBUG, "mtd_Read_Page_Main: "
  241. "lba %u Page %u PageCount %u\n",
  242. (unsigned int)Block,
  243. (unsigned int)Page, (unsigned int)PageCount);
  244. while (PageCount) {
  245. ret = spectra_mtd->read(spectra_mtd,
  246. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  247. DeviceInfo.wPageDataSize, &retlen, read_data);
  248. if (ret) {
  249. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  250. return FAIL;
  251. }
  252. read_data += DeviceInfo.wPageDataSize;
  253. Page++;
  254. PageCount--;
  255. }
  256. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  257. __FILE__, __LINE__, __func__);
  258. return PASS;
  259. }
  260. #ifndef ELDORA
  261. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  262. * Function: mtd_Read_Page_Main_Spare
  263. * Inputs: Write Buffer
  264. * Address
  265. * Buffer size
  266. * Outputs: PASS=0 (notice 0=ok here)
  267. * Description: Read from flash main+spare area
  268. *
  269. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  270. u16 mtd_Read_Page_Main_Spare(u8 *read_data, u32 Block,
  271. u16 Page, u16 PageCount)
  272. {
  273. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  274. __FILE__, __LINE__, __func__);
  275. if (Block >= DeviceInfo.wTotalBlocks) {
  276. printk(KERN_ERR "Read Page Main+Spare "
  277. "Error: Block Address too big\n");
  278. return FAIL;
  279. }
  280. if (Page + PageCount > DeviceInfo.wPagesPerBlock) {
  281. printk(KERN_ERR "Read Page Main+Spare "
  282. "Error: Page number %d+%d too big in block %d\n",
  283. Page, PageCount, Block);
  284. return FAIL;
  285. }
  286. nand_dbg_print(NAND_DBG_DEBUG, "Read Page Main + Spare - "
  287. "No. of pages %u block %u start page %u\n",
  288. (unsigned int)PageCount,
  289. (unsigned int)Block, (unsigned int)Page);
  290. while (PageCount) {
  291. struct mtd_oob_ops ops;
  292. int ret;
  293. ops.mode = MTD_OOB_AUTO;
  294. ops.datbuf = read_data;
  295. ops.len = DeviceInfo.wPageDataSize;
  296. ops.oobbuf = read_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET;
  297. ops.ooblen = BTSIG_BYTES;
  298. ops.ooboffs = 0;
  299. ret = spectra_mtd->read_oob(spectra_mtd,
  300. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  301. &ops);
  302. if (ret) {
  303. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  304. return FAIL;
  305. }
  306. read_data += DeviceInfo.wPageSize;
  307. Page++;
  308. PageCount--;
  309. }
  310. return PASS;
  311. }
  312. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  313. * Function: mtd_Write_Page_Main_Spare
  314. * Inputs: Write buffer
  315. * address
  316. * buffer length
  317. * Outputs: PASS=0 (notice 0=ok here)
  318. * Description: Write the buffer to main+spare area of flash
  319. *
  320. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  321. u16 mtd_Write_Page_Main_Spare(u8 *write_data, u32 Block,
  322. u16 Page, u16 page_count)
  323. {
  324. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  325. __FILE__, __LINE__, __func__);
  326. if (Block >= DeviceInfo.wTotalBlocks) {
  327. printk(KERN_ERR "Write Page Main + Spare "
  328. "Error: Block Address too big\n");
  329. return FAIL;
  330. }
  331. if (Page + page_count > DeviceInfo.wPagesPerBlock) {
  332. printk(KERN_ERR "Write Page Main + Spare "
  333. "Error: Page number %d+%d too big in block %d\n",
  334. Page, page_count, Block);
  335. WARN_ON(1);
  336. return FAIL;
  337. }
  338. nand_dbg_print(NAND_DBG_DEBUG, "Write Page Main+Spare - "
  339. "No. of pages %u block %u start page %u\n",
  340. (unsigned int)page_count,
  341. (unsigned int)Block, (unsigned int)Page);
  342. while (page_count) {
  343. struct mtd_oob_ops ops;
  344. int ret;
  345. ops.mode = MTD_OOB_AUTO;
  346. ops.datbuf = write_data;
  347. ops.len = DeviceInfo.wPageDataSize;
  348. ops.oobbuf = write_data + DeviceInfo.wPageDataSize + BTSIG_OFFSET;
  349. ops.ooblen = BTSIG_BYTES;
  350. ops.ooboffs = 0;
  351. ret = spectra_mtd->write_oob(spectra_mtd,
  352. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  353. &ops);
  354. if (ret) {
  355. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  356. return FAIL;
  357. }
  358. write_data += DeviceInfo.wPageSize;
  359. Page++;
  360. page_count--;
  361. }
  362. return PASS;
  363. }
  364. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  365. * Function: mtd_Write_Page_Spare
  366. * Inputs: Write buffer
  367. * Address
  368. * buffer size
  369. * Outputs: PASS=0 (notice 0=ok here)
  370. * Description: Write the buffer in the spare area
  371. *
  372. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  373. u16 mtd_Write_Page_Spare(u8 *write_data, u32 Block,
  374. u16 Page, u16 PageCount)
  375. {
  376. WARN_ON(1);
  377. return FAIL;
  378. }
  379. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  380. * Function: mtd_Read_Page_Spare
  381. * Inputs: Write Buffer
  382. * Address
  383. * Buffer size
  384. * Outputs: PASS=0 (notice 0=ok here)
  385. * Description: Read data from the spare area
  386. *
  387. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  388. u16 mtd_Read_Page_Spare(u8 *read_data, u32 Block,
  389. u16 Page, u16 PageCount)
  390. {
  391. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  392. __FILE__, __LINE__, __func__);
  393. if (Block >= DeviceInfo.wTotalBlocks) {
  394. printk(KERN_ERR "Read Page Spare "
  395. "Error: Block Address too big\n");
  396. return FAIL;
  397. }
  398. if (Page + PageCount > DeviceInfo.wPagesPerBlock) {
  399. printk(KERN_ERR "Read Page Spare "
  400. "Error: Page number too big\n");
  401. return FAIL;
  402. }
  403. nand_dbg_print(NAND_DBG_DEBUG, "Read Page Spare- "
  404. "block %u page %u (%u pages)\n",
  405. (unsigned int)Block, (unsigned int)Page, PageCount);
  406. while (PageCount) {
  407. struct mtd_oob_ops ops;
  408. int ret;
  409. ops.mode = MTD_OOB_AUTO;
  410. ops.datbuf = NULL;
  411. ops.len = 0;
  412. ops.oobbuf = read_data;
  413. ops.ooblen = BTSIG_BYTES;
  414. ops.ooboffs = 0;
  415. ret = spectra_mtd->read_oob(spectra_mtd,
  416. (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize),
  417. &ops);
  418. if (ret) {
  419. printk(KERN_ERR "%s failed %d\n", __func__, ret);
  420. return FAIL;
  421. }
  422. read_data += DeviceInfo.wPageSize;
  423. Page++;
  424. PageCount--;
  425. }
  426. return PASS;
  427. }
  428. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  429. * Function: mtd_Enable_Disable_Interrupts
  430. * Inputs: enable or disable
  431. * Outputs: none
  432. * Description: NOP
  433. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  434. void mtd_Enable_Disable_Interrupts(u16 INT_ENABLE)
  435. {
  436. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  437. __FILE__, __LINE__, __func__);
  438. }
  439. u16 mtd_Get_Bad_Block(u32 block)
  440. {
  441. return 0;
  442. }
  443. #if CMD_DMA
  444. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  445. * Support for CDMA functions
  446. ************************************
  447. * mtd_CDMA_Flash_Init
  448. * CDMA_process_data command (use LLD_CDMA)
  449. * CDMA_MemCopy_CMD (use LLD_CDMA)
  450. * mtd_CDMA_execute all commands
  451. * mtd_CDMA_Event_Status
  452. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  453. u16 mtd_CDMA_Flash_Init(void)
  454. {
  455. u16 i;
  456. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  457. __FILE__, __LINE__, __func__);
  458. for (i = 0; i < MAX_DESCS + MAX_CHANS; i++) {
  459. PendingCMD[i].CMD = 0;
  460. PendingCMD[i].Tag = 0;
  461. PendingCMD[i].DataAddr = 0;
  462. PendingCMD[i].Block = 0;
  463. PendingCMD[i].Page = 0;
  464. PendingCMD[i].PageCount = 0;
  465. PendingCMD[i].DataDestAddr = 0;
  466. PendingCMD[i].DataSrcAddr = 0;
  467. PendingCMD[i].MemCopyByteCnt = 0;
  468. PendingCMD[i].ChanSync[0] = 0;
  469. PendingCMD[i].ChanSync[1] = 0;
  470. PendingCMD[i].ChanSync[2] = 0;
  471. PendingCMD[i].ChanSync[3] = 0;
  472. PendingCMD[i].ChanSync[4] = 0;
  473. PendingCMD[i].Status = 3;
  474. }
  475. return PASS;
  476. }
  477. static void mtd_isr(int irq, void *dev_id)
  478. {
  479. /* TODO: ... */
  480. }
  481. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  482. * Function: CDMA_Execute_CMDs
  483. * Inputs: tag_count: the number of pending cmds to do
  484. * Outputs: PASS/FAIL
  485. * Description: execute each command in the pending CMD array
  486. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  487. u16 mtd_CDMA_Execute_CMDs(u16 tag_count)
  488. {
  489. u16 i, j;
  490. u8 CMD; /* cmd parameter */
  491. u8 *data;
  492. u32 block;
  493. u16 page;
  494. u16 count;
  495. u16 status = PASS;
  496. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  497. __FILE__, __LINE__, __func__);
  498. nand_dbg_print(NAND_DBG_TRACE, "At start of Execute CMDs: "
  499. "Tag Count %u\n", tag_count);
  500. for (i = 0; i < totalUsedBanks; i++) {
  501. PendingCMD[i].CMD = DUMMY_CMD;
  502. PendingCMD[i].Tag = 0xFF;
  503. PendingCMD[i].Block =
  504. (DeviceInfo.wTotalBlocks / totalUsedBanks) * i;
  505. for (j = 0; j <= MAX_CHANS; j++)
  506. PendingCMD[i].ChanSync[j] = 0;
  507. }
  508. CDMA_Execute_CMDs(tag_count);
  509. #ifdef VERBOSE
  510. print_pending_cmds(tag_count);
  511. #endif
  512. #if DEBUG_SYNC
  513. }
  514. debug_sync_cnt++;
  515. #endif
  516. for (i = MAX_CHANS;
  517. i < tag_count + MAX_CHANS; i++) {
  518. CMD = PendingCMD[i].CMD;
  519. data = PendingCMD[i].DataAddr;
  520. block = PendingCMD[i].Block;
  521. page = PendingCMD[i].Page;
  522. count = PendingCMD[i].PageCount;
  523. switch (CMD) {
  524. case ERASE_CMD:
  525. mtd_Erase_Block(block);
  526. PendingCMD[i].Status = PASS;
  527. break;
  528. case WRITE_MAIN_CMD:
  529. mtd_Write_Page_Main(data, block, page, count);
  530. PendingCMD[i].Status = PASS;
  531. break;
  532. case WRITE_MAIN_SPARE_CMD:
  533. mtd_Write_Page_Main_Spare(data, block, page, count);
  534. PendingCMD[i].Status = PASS;
  535. break;
  536. case READ_MAIN_CMD:
  537. mtd_Read_Page_Main(data, block, page, count);
  538. PendingCMD[i].Status = PASS;
  539. break;
  540. case MEMCOPY_CMD:
  541. memcpy(PendingCMD[i].DataDestAddr,
  542. PendingCMD[i].DataSrcAddr,
  543. PendingCMD[i].MemCopyByteCnt);
  544. case DUMMY_CMD:
  545. PendingCMD[i].Status = PASS;
  546. break;
  547. default:
  548. PendingCMD[i].Status = FAIL;
  549. break;
  550. }
  551. }
  552. /*
  553. * Temperory adding code to reset PendingCMD array for basic testing.
  554. * It should be done at the end of event status function.
  555. */
  556. for (i = tag_count + MAX_CHANS; i < MAX_DESCS; i++) {
  557. PendingCMD[i].CMD = 0;
  558. PendingCMD[i].Tag = 0;
  559. PendingCMD[i].DataAddr = 0;
  560. PendingCMD[i].Block = 0;
  561. PendingCMD[i].Page = 0;
  562. PendingCMD[i].PageCount = 0;
  563. PendingCMD[i].DataDestAddr = 0;
  564. PendingCMD[i].DataSrcAddr = 0;
  565. PendingCMD[i].MemCopyByteCnt = 0;
  566. PendingCMD[i].ChanSync[0] = 0;
  567. PendingCMD[i].ChanSync[1] = 0;
  568. PendingCMD[i].ChanSync[2] = 0;
  569. PendingCMD[i].ChanSync[3] = 0;
  570. PendingCMD[i].ChanSync[4] = 0;
  571. PendingCMD[i].Status = CMD_NOT_DONE;
  572. }
  573. nand_dbg_print(NAND_DBG_TRACE, "At end of Execute CMDs.\n");
  574. mtd_isr(0, 0); /* This is a null isr now. Need fill it in future */
  575. return status;
  576. }
  577. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  578. * Function: mtd_Event_Status
  579. * Inputs: none
  580. * Outputs: Event_Status code
  581. * Description: This function can also be used to force errors
  582. *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  583. u16 mtd_CDMA_Event_Status(void)
  584. {
  585. nand_dbg_print(NAND_DBG_TRACE, "%s, Line %d, Function: %s\n",
  586. __FILE__, __LINE__, __func__);
  587. return EVENT_PASS;
  588. }
  589. #endif /* CMD_DMA */
  590. #endif /* !ELDORA */