lld.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 "spectraswconfig.h"
  20. #include "ffsport.h"
  21. #include "ffsdefs.h"
  22. #include "lld.h"
  23. #include "lld_nand.h"
  24. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  25. #if FLASH_EMU /* vector all the LLD calls to the LLD_EMU code */
  26. #include "lld_emu.h"
  27. #include "lld_cdma.h"
  28. /* common functions: */
  29. u16 GLOB_LLD_Flash_Reset(void)
  30. {
  31. return emu_Flash_Reset();
  32. }
  33. u16 GLOB_LLD_Read_Device_ID(void)
  34. {
  35. return emu_Read_Device_ID();
  36. }
  37. int GLOB_LLD_Flash_Release(void)
  38. {
  39. return emu_Flash_Release();
  40. }
  41. u16 GLOB_LLD_Flash_Init(void)
  42. {
  43. return emu_Flash_Init();
  44. }
  45. u16 GLOB_LLD_Erase_Block(u32 block_add)
  46. {
  47. return emu_Erase_Block(block_add);
  48. }
  49. u16 GLOB_LLD_Write_Page_Main(u8 *write_data, u32 block, u16 Page,
  50. u16 PageCount)
  51. {
  52. return emu_Write_Page_Main(write_data, block, Page, PageCount);
  53. }
  54. u16 GLOB_LLD_Read_Page_Main(u8 *read_data, u32 block, u16 Page,
  55. u16 PageCount)
  56. {
  57. return emu_Read_Page_Main(read_data, block, Page, PageCount);
  58. }
  59. u16 GLOB_LLD_Read_Page_Main_Polling(u8 *read_data,
  60. u32 block, u16 page, u16 page_count)
  61. {
  62. return emu_Read_Page_Main(read_data, block, page, page_count);
  63. }
  64. u16 GLOB_LLD_Write_Page_Main_Spare(u8 *write_data, u32 block,
  65. u16 Page, u16 PageCount)
  66. {
  67. return emu_Write_Page_Main_Spare(write_data, block, Page, PageCount);
  68. }
  69. u16 GLOB_LLD_Read_Page_Main_Spare(u8 *read_data, u32 block,
  70. u16 Page, u16 PageCount)
  71. {
  72. return emu_Read_Page_Main_Spare(read_data, block, Page, PageCount);
  73. }
  74. u16 GLOB_LLD_Write_Page_Spare(u8 *write_data, u32 block, u16 Page,
  75. u16 PageCount)
  76. {
  77. return emu_Write_Page_Spare(write_data, block, Page, PageCount);
  78. }
  79. u16 GLOB_LLD_Read_Page_Spare(u8 *read_data, u32 block, u16 Page,
  80. u16 PageCount)
  81. {
  82. return emu_Read_Page_Spare(read_data, block, Page, PageCount);
  83. }
  84. u16 GLOB_LLD_Get_Bad_Block(u32 block)
  85. {
  86. return emu_Get_Bad_Block(block);
  87. }
  88. #endif /* FLASH_EMU */
  89. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  90. #if FLASH_NAND /* vector all the LLD calls to the NAND controller code */
  91. #include "lld_nand.h"
  92. #include "lld_cdma.h"
  93. #include "flash.h"
  94. /* common functions for LLD_NAND */
  95. void GLOB_LLD_ECC_Control(int enable)
  96. {
  97. NAND_ECC_Ctrl(enable);
  98. }
  99. /* common functions for LLD_NAND */
  100. u16 GLOB_LLD_Flash_Reset(void)
  101. {
  102. return NAND_Flash_Reset();
  103. }
  104. u16 GLOB_LLD_Read_Device_ID(void)
  105. {
  106. return NAND_Read_Device_ID();
  107. }
  108. u16 GLOB_LLD_UnlockArrayAll(void)
  109. {
  110. return NAND_UnlockArrayAll();
  111. }
  112. u16 GLOB_LLD_Flash_Init(void)
  113. {
  114. return NAND_Flash_Init();
  115. }
  116. int GLOB_LLD_Flash_Release(void)
  117. {
  118. return nand_release();
  119. }
  120. u16 GLOB_LLD_Erase_Block(u32 block_add)
  121. {
  122. return NAND_Erase_Block(block_add);
  123. }
  124. u16 GLOB_LLD_Write_Page_Main(u8 *write_data, u32 block, u16 Page,
  125. u16 PageCount)
  126. {
  127. return NAND_Write_Page_Main(write_data, block, Page, PageCount);
  128. }
  129. u16 GLOB_LLD_Read_Page_Main(u8 *read_data, u32 block, u16 page,
  130. u16 page_count)
  131. {
  132. if (page_count == 1) /* Using polling to improve read speed */
  133. return NAND_Read_Page_Main_Polling(read_data, block, page, 1);
  134. else
  135. return NAND_Read_Page_Main(read_data, block, page, page_count);
  136. }
  137. u16 GLOB_LLD_Read_Page_Main_Polling(u8 *read_data,
  138. u32 block, u16 page, u16 page_count)
  139. {
  140. return NAND_Read_Page_Main_Polling(read_data,
  141. block, page, page_count);
  142. }
  143. u16 GLOB_LLD_Write_Page_Main_Spare(u8 *write_data, u32 block,
  144. u16 Page, u16 PageCount)
  145. {
  146. return NAND_Write_Page_Main_Spare(write_data, block, Page, PageCount);
  147. }
  148. u16 GLOB_LLD_Write_Page_Spare(u8 *write_data, u32 block, u16 Page,
  149. u16 PageCount)
  150. {
  151. return NAND_Write_Page_Spare(write_data, block, Page, PageCount);
  152. }
  153. u16 GLOB_LLD_Read_Page_Main_Spare(u8 *read_data, u32 block,
  154. u16 page, u16 page_count)
  155. {
  156. return NAND_Read_Page_Main_Spare(read_data, block, page, page_count);
  157. }
  158. u16 GLOB_LLD_Read_Page_Spare(u8 *read_data, u32 block, u16 Page,
  159. u16 PageCount)
  160. {
  161. return NAND_Read_Page_Spare(read_data, block, Page, PageCount);
  162. }
  163. u16 GLOB_LLD_Get_Bad_Block(u32 block)
  164. {
  165. return NAND_Get_Bad_Block(block);
  166. }
  167. #if CMD_DMA
  168. u16 GLOB_LLD_Event_Status(void)
  169. {
  170. return CDMA_Event_Status();
  171. }
  172. u16 glob_lld_execute_cmds(void)
  173. {
  174. return CDMA_Execute_CMDs();
  175. }
  176. u16 GLOB_LLD_MemCopy_CMD(u8 *dest, u8 *src,
  177. u32 ByteCount, u16 flag)
  178. {
  179. /* Replace the hardware memcopy with software memcpy function */
  180. if (CDMA_Execute_CMDs())
  181. return FAIL;
  182. memcpy(dest, src, ByteCount);
  183. return PASS;
  184. /* return CDMA_MemCopy_CMD(dest, src, ByteCount, flag); */
  185. }
  186. u16 GLOB_LLD_Erase_Block_cdma(u32 block, u16 flags)
  187. {
  188. return CDMA_Data_CMD(ERASE_CMD, 0, block, 0, 0, flags);
  189. }
  190. u16 GLOB_LLD_Write_Page_Main_cdma(u8 *data, u32 block, u16 page, u16 count)
  191. {
  192. return CDMA_Data_CMD(WRITE_MAIN_CMD, data, block, page, count, 0);
  193. }
  194. u16 GLOB_LLD_Read_Page_Main_cdma(u8 *data, u32 block, u16 page,
  195. u16 count, u16 flags)
  196. {
  197. return CDMA_Data_CMD(READ_MAIN_CMD, data, block, page, count, flags);
  198. }
  199. u16 GLOB_LLD_Write_Page_Main_Spare_cdma(u8 *data, u32 block, u16 page,
  200. u16 count, u16 flags)
  201. {
  202. return CDMA_Data_CMD(WRITE_MAIN_SPARE_CMD,
  203. data, block, page, count, flags);
  204. }
  205. u16 GLOB_LLD_Read_Page_Main_Spare_cdma(u8 *data,
  206. u32 block, u16 page, u16 count)
  207. {
  208. return CDMA_Data_CMD(READ_MAIN_SPARE_CMD, data, block, page, count,
  209. LLD_CMD_FLAG_MODE_CDMA);
  210. }
  211. #endif /* CMD_DMA */
  212. #endif /* FLASH_NAND */
  213. /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  214. /* end of LLD.c */