emmc_hal.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. /*
  2. * Copyright (c) 2015-2020, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef EMMC_HAL_H
  7. #define EMMC_HAL_H
  8. /* memory card error/status types */
  9. #define HAL_MEMCARD_OUT_OF_RANGE 0x80000000L
  10. #define HAL_MEMCARD_ADDRESS_ERROR 0x40000000L
  11. #define HAL_MEMCARD_BLOCK_LEN_ERROR 0x20000000L
  12. #define HAL_MEMCARD_ERASE_SEQ_ERROR 0x10000000L
  13. #define HAL_MEMCARD_ERASE_PARAM 0x08000000L
  14. #define HAL_MEMCARD_WP_VIOLATION 0x04000000L
  15. #define HAL_MEMCARD_CARD_IS_LOCKED 0x02000000L
  16. #define HAL_MEMCARD_LOCK_UNLOCK_FAILED 0x01000000L
  17. #define HAL_MEMCARD_COM_CRC_ERROR 0x00800000L
  18. #define HAL_MEMCARD_ILEGAL_COMMAND 0x00400000L
  19. #define HAL_MEMCARD_CARD_ECC_FAILED 0x00200000L
  20. #define HAL_MEMCARD_CC_ERROR 0x00100000L
  21. #define HAL_MEMCARD_ERROR 0x00080000L
  22. #define HAL_MEMCARD_UNDERRUN 0x00040000L
  23. #define HAL_MEMCARD_OVERRUN 0x00020000L
  24. #define HAL_MEMCARD_CIDCSD_OVERWRITE 0x00010000L
  25. #define HAL_MEMCARD_WP_ERASE_SKIP 0x00008000L
  26. #define HAL_MEMCARD_CARD_ECC_DISABLED 0x00004000L
  27. #define HAL_MEMCARD_ERASE_RESET 0x00002000L
  28. #define HAL_MEMCARD_CARD_STATE 0x00001E00L
  29. #define HAL_MEMCARD_CARD_READY_FOR_DATA 0x00000100L
  30. #define HAL_MEMCARD_APP_CMD 0x00000020L
  31. #define HAL_MEMCARD_SWITCH_ERROR 0x00000080L
  32. #define HAL_MEMCARD_AKE_SEQ_ERROR 0x00000008L
  33. #define HAL_MEMCARD_NO_ERRORS 0x00000000L
  34. /* Memory card response types */
  35. #define HAL_MEMCARD_COMMAND_INDEX_MASK 0x0003f
  36. /* Type of the return value. */
  37. typedef enum {
  38. HAL_MEMCARD_FAIL = 0U,
  39. HAL_MEMCARD_OK = 1U,
  40. HAL_MEMCARD_DMA_ALLOC_FAIL = 2U, /* DMA channel allocation failed */
  41. HAL_MEMCARD_DMA_TRANSFER_FAIL = 3U, /* DMA transfer failed */
  42. HAL_MEMCARD_CARD_STATUS_ERROR = 4U, /* card status non-masked error */
  43. HAL_MEMCARD_CMD_TIMEOUT = 5U, /* Command timeout occurred */
  44. HAL_MEMCARD_DATA_TIMEOUT = 6U, /* Data timeout occurred */
  45. HAL_MEMCARD_CMD_CRC_ERROR = 7U, /* Command CRC error occurred */
  46. HAL_MEMCARD_DATA_CRC_ERROR = 8U /* Data CRC error occurred */
  47. } HAL_MEMCARD_RETURN;
  48. /* memory access operation */
  49. typedef enum {
  50. HAL_MEMCARD_READ = 0U, /* read */
  51. HAL_MEMCARD_WRITE = 1U /* write */
  52. } HAL_MEMCARD_OPERATION;
  53. /* Type of data width on memorycard bus */
  54. typedef enum {
  55. HAL_MEMCARD_DATA_WIDTH_1_BIT = 0U,
  56. HAL_MEMCARD_DATA_WIDTH_4_BIT = 1U,
  57. HAL_MEMCARD_DATA_WIDTH_8_BIT = 2U
  58. } HAL_MEMCARD_DATA_WIDTH; /* data (bus) width types */
  59. /* Presence of the memory card */
  60. typedef enum {
  61. HAL_MEMCARD_CARD_IS_IN = 0U,
  62. HAL_MEMCARD_CARD_IS_OUT = 1U
  63. } HAL_MEMCARD_PRESENCE_STATUS; /* presence status of the memory card */
  64. /* mode of data transfer */
  65. typedef enum {
  66. HAL_MEMCARD_DMA = 0U,
  67. HAL_MEMCARD_NOT_DMA = 1U
  68. } HAL_MEMCARD_DATA_TRANSFER_MODE;
  69. /* Memory card response types. */
  70. typedef enum hal_memcard_response_type {
  71. HAL_MEMCARD_RESPONSE_NONE = 0x00000U,
  72. HAL_MEMCARD_RESPONSE_R1 = 0x00100U,
  73. HAL_MEMCARD_RESPONSE_R1b = 0x00200U,
  74. HAL_MEMCARD_RESPONSE_R2 = 0x00300U,
  75. HAL_MEMCARD_RESPONSE_R3 = 0x00400U,
  76. HAL_MEMCARD_RESPONSE_R4 = 0x00500U,
  77. HAL_MEMCARD_RESPONSE_R5 = 0x00600U,
  78. HAL_MEMCARD_RESPONSE_R6 = 0x00700U,
  79. HAL_MEMCARD_RESPONSE_R7 = 0x00800U,
  80. HAL_MEMCARD_RESPONSE_TYPE_MASK = 0x00f00U
  81. } HAL_MEMCARD_RESPONSE_TYPE;
  82. /* Memory card command types. */
  83. typedef enum hal_memcard_command_type {
  84. HAL_MEMCARD_COMMAND_TYPE_BC = 0x00000U,
  85. HAL_MEMCARD_COMMAND_TYPE_BCR = 0x01000U,
  86. HAL_MEMCARD_COMMAND_TYPE_AC = 0x02000U,
  87. HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE = 0x03000U,
  88. HAL_MEMCARD_COMMAND_TYPE_ADTC_READ = 0x04000U,
  89. HAL_MEMCARD_COMMAND_TYPE_MASK = 0x07000U
  90. } HAL_MEMCARD_COMMAND_TYPE;
  91. /* Type of memory card */
  92. typedef enum hal_memcard_command_card_type {
  93. HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON = 0x00000U,
  94. HAL_MEMCARD_COMMAND_CARD_TYPE_MMC = 0x08000U,
  95. HAL_MEMCARD_COMMAND_CARD_TYPE_SD = 0x10000U,
  96. HAL_MEMCARD_COMMAND_CARD_TYPE_MASK = 0x18000U
  97. } HAL_MEMCARD_COMMAND_CARD_TYPE;
  98. /* Memory card application command. */
  99. typedef enum hal_memcard_command_app_norm {
  100. HAL_MEMCARD_COMMAND_NORMAL = 0x00000U,
  101. HAL_MEMCARD_COMMAND_APP = 0x20000U,
  102. HAL_MEMCARD_COMMAND_APP_NORM_MASK = 0x20000U
  103. } HAL_MEMCARD_COMMAND_APP_NORM;
  104. /* Memory card command codes. */
  105. typedef enum {
  106. /* class 0 and class 1 */
  107. /* CMD0 */
  108. CMD0_GO_IDLE_STATE =
  109. 0U | (uint32_t)HAL_MEMCARD_RESPONSE_NONE |
  110. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BC |
  111. (uint32_t) HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  112. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  113. /* CMD1 */
  114. CMD1_SEND_OP_COND =
  115. 1U | (uint32_t)HAL_MEMCARD_RESPONSE_R3 |
  116. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BCR |
  117. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  118. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  119. /* CMD2 */
  120. CMD2_ALL_SEND_CID_MMC =
  121. 2U | (uint32_t)HAL_MEMCARD_RESPONSE_R2 |
  122. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BCR |
  123. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  124. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  125. CMD2_ALL_SEND_CID_SD =
  126. 2U | (uint32_t)HAL_MEMCARD_RESPONSE_R2 |
  127. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BCR |
  128. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  129. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  130. /* CMD3 */
  131. CMD3_SET_RELATIVE_ADDR =
  132. 3U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  133. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  134. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  135. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  136. CMD3_SEND_RELATIVE_ADDR =
  137. 3U | (uint32_t)HAL_MEMCARD_RESPONSE_R6 |
  138. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  139. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  140. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  141. /* CMD4 */
  142. CMD4_SET_DSR =
  143. 4U | (uint32_t)HAL_MEMCARD_RESPONSE_NONE |
  144. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BC |
  145. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  146. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  147. /* CMD5 */
  148. CMD5_SLEEP_AWAKE =
  149. 5U | (uint32_t)HAL_MEMCARD_RESPONSE_R1b |
  150. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  151. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  152. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  153. /* CMD6 */
  154. CMD6_SWITCH =
  155. 6U | (uint32_t)HAL_MEMCARD_RESPONSE_R1b |
  156. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  157. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  158. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  159. CMD6_SWITCH_FUNC =
  160. 6U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  161. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  162. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  163. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  164. ACMD6_SET_BUS_WIDTH =
  165. 6U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  166. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  167. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  168. (uint32_t)HAL_MEMCARD_COMMAND_APP,
  169. /* CMD7 */
  170. CMD7_SELECT_CARD =
  171. 7U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  172. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  173. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  174. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  175. /* CMD7(from Disconnected State to Programming State) */
  176. CMD7_SELECT_CARD_PROG =
  177. 7U | (uint32_t)HAL_MEMCARD_RESPONSE_R1b |
  178. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  179. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  180. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  181. CMD7_DESELECT_CARD =
  182. 7U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  183. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  184. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  185. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  186. /* CMD8 */
  187. CMD8_SEND_EXT_CSD =
  188. 8U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  189. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  190. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  191. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  192. CMD8_SEND_IF_COND =
  193. 8U | (uint32_t)HAL_MEMCARD_RESPONSE_R7 |
  194. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BCR |
  195. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  196. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  197. /* CMD9 */
  198. CMD9_SEND_CSD =
  199. 9U | (uint32_t)HAL_MEMCARD_RESPONSE_R2 |
  200. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  201. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  202. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  203. /* CMD10 */
  204. CMD10_SEND_CID =
  205. 10U | (uint32_t)HAL_MEMCARD_RESPONSE_R2 |
  206. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  207. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  208. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  209. /* CMD11 */
  210. CMD11_READ_DAT_UNTIL_STOP =
  211. 11U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  212. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  213. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  214. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  215. /* CMD12 */
  216. CMD12_STOP_TRANSMISSION =
  217. 12U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  218. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  219. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  220. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  221. /* CMD12(R1b : write case) */
  222. CMD12_STOP_TRANSMISSION_WRITE =
  223. 12U | (uint32_t)HAL_MEMCARD_RESPONSE_R1b |
  224. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  225. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  226. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  227. /* CMD13 */
  228. CMD13_SEND_STATUS =
  229. 13U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  230. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  231. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  232. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  233. ACMD13_SD_STATUS =
  234. 13U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  235. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  236. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  237. (uint32_t)HAL_MEMCARD_COMMAND_APP,
  238. /* CMD14 */
  239. CMD14_BUSTEST_R =
  240. 14U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  241. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  242. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  243. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  244. /* CMD15 */
  245. CMD15_GO_INACTIVE_STATE =
  246. 15U | (uint32_t)HAL_MEMCARD_RESPONSE_NONE |
  247. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  248. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  249. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  250. /* class 2 */
  251. /* CMD16 */
  252. CMD16_SET_BLOCKLEN =
  253. 16U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  254. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  255. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  256. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  257. /* CMD17 */
  258. CMD17_READ_SINGLE_BLOCK =
  259. 17U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  260. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  261. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  262. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  263. /* CMD18 */
  264. CMD18_READ_MULTIPLE_BLOCK =
  265. 18U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  266. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  267. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  268. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  269. /* CMD19 */
  270. CMD19_BUS_TEST_W =
  271. 19U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  272. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  273. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  274. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  275. /* class 3 */
  276. /* CMD20 */
  277. CMD20_WRITE_DAT_UNTIL_STOP =
  278. 20U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  279. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  280. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  281. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  282. /* CMD21 */
  283. CMD21 = 21U,
  284. /* CMD22 */
  285. CMD22 = 22U,
  286. ACMD22_SEND_NUM_WR_BLOCKS =
  287. 22U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  288. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  289. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  290. (uint32_t)HAL_MEMCARD_COMMAND_APP,
  291. /* class 4 */
  292. /* CMD23 */
  293. CMD23_SET_BLOCK_COUNT =
  294. 23U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  295. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  296. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  297. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  298. ACMD23_SET_WR_BLK_ERASE_COUNT =
  299. 23U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  300. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  301. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  302. (uint32_t)HAL_MEMCARD_COMMAND_APP,
  303. /* CMD24 */
  304. CMD24_WRITE_BLOCK =
  305. 24U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  306. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  307. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  308. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  309. /* CMD25 */
  310. CMD25_WRITE_MULTIPLE_BLOCK =
  311. 25U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  312. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  313. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  314. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  315. /* CMD26 */
  316. CMD26_PROGRAM_CID =
  317. 26U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  318. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  319. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  320. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  321. /* CMD27 */
  322. CMD27_PROGRAM_CSD =
  323. 27U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  324. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  325. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  326. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  327. /* class 6 */
  328. /* CMD28 */
  329. CMD28_SET_WRITE_PROT =
  330. 28U | (uint32_t)HAL_MEMCARD_RESPONSE_R1b |
  331. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  332. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  333. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  334. /* CMD29 */
  335. CMD29_CLR_WRITE_PROT =
  336. 29U | (uint32_t)HAL_MEMCARD_RESPONSE_R1b |
  337. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  338. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  339. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  340. /* CMD30 */
  341. CMD30_SEND_WRITE_PROT =
  342. 30U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  343. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  344. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  345. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  346. /* CMD31 */
  347. CMD30_SEND_WRITE_PROT_TYPE =
  348. 31U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  349. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  350. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  351. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  352. /* class 5 */
  353. /* CMD32 */
  354. CMD32_ERASE_WR_BLK_START =
  355. 32U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  356. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  357. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  358. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  359. /* CMD33 */
  360. CMD33_ERASE_WR_BLK_END =
  361. 33U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  362. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  363. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  364. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  365. /* CMD34 */
  366. CMD34 = 34U,
  367. /* CMD35 */
  368. CMD35_ERASE_GROUP_START =
  369. 35U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  370. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  371. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  372. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  373. /* CMD36 */
  374. CMD36_ERASE_GROUP_END =
  375. 36U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  376. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  377. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  378. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  379. /* CMD37 */
  380. CMD37 = 37U,
  381. /* CMD38 */
  382. CMD38_ERASE =
  383. 38U | (uint32_t)HAL_MEMCARD_RESPONSE_R1b |
  384. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  385. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  386. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  387. /* class 9 */
  388. /* CMD39 */
  389. CMD39_FASTIO =
  390. 39U | (uint32_t)HAL_MEMCARD_RESPONSE_R4 |
  391. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  392. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  393. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  394. /* CMD40 */
  395. CMD40_GO_IRQSTATE =
  396. 40U | (uint32_t)HAL_MEMCARD_RESPONSE_R5 |
  397. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BCR |
  398. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_MMC |
  399. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  400. /* CMD41 */
  401. CMD41 = 41,
  402. ACMD41_SD_SEND_OP_COND =
  403. 41U | (uint32_t)HAL_MEMCARD_RESPONSE_R3 |
  404. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_BCR |
  405. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  406. (uint32_t)HAL_MEMCARD_COMMAND_APP,
  407. /* class 7 */
  408. /* CMD42 */
  409. CMD42_LOCK_UNLOCK =
  410. 42U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  411. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  412. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  413. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  414. ACMD42_SET_CLR_CARD_DETECT =
  415. 42U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  416. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  417. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  418. (uint32_t)HAL_MEMCARD_COMMAND_APP,
  419. CMD43 = 43U, /* CMD43 */
  420. CMD44 = 44U, /* CMD44 */
  421. CMD45 = 45U, /* CMD45 */
  422. CMD46 = 46U, /* CMD46 */
  423. CMD47 = 47U, /* CMD47 */
  424. CMD48 = 48U, /* CMD48 */
  425. CMD49 = 49U, /* CMD49 */
  426. CMD50 = 50U, /* CMD50 */
  427. CMD51 = 51U, /* CMD51 */
  428. ACMD51_SEND_SCR =
  429. 51U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  430. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_READ |
  431. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_SD |
  432. (uint32_t)HAL_MEMCARD_COMMAND_APP,
  433. CMD52 = 52U, /* CMD52 */
  434. CMD53 = 53U, /* CMD53 */
  435. CMD54 = 54U, /* CMD54 */
  436. /* class 8 */
  437. /* CMD55 */
  438. CMD55_APP_CMD =
  439. 55U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  440. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_AC |
  441. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  442. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  443. /* CMD56 */
  444. CMD56_GEN_CMD =
  445. 56U | (uint32_t)HAL_MEMCARD_RESPONSE_R1 |
  446. (uint32_t)HAL_MEMCARD_COMMAND_TYPE_ADTC_WRITE |
  447. (uint32_t)HAL_MEMCARD_COMMAND_CARD_TYPE_COMMON |
  448. (uint32_t)HAL_MEMCARD_COMMAND_NORMAL,
  449. CMD57 = 57U, /* CMD57 */
  450. CMD58 = 58U, /* CMD58 */
  451. CMD59 = 59U, /* CMD59 */
  452. CMD60 = 60U, /* CMD60 */
  453. CMD61 = 61U, /* CMD61 */
  454. CMD62 = 62U, /* CMD62 */
  455. CMD63 = 63U /* CMD63 */
  456. } HAL_MEMCARD_COMMAND;
  457. /*
  458. * Configuration structure from HAL layer.
  459. *
  460. * If some field is not available it should be filled with 0xFF.
  461. * The API version is 32-bit unsigned integer telling the version of the API.
  462. * The integer is divided to four sections which each can be treated as a 8-bit
  463. * unsigned number:
  464. * Bits 31-24 make the most significant part of the version number. This number
  465. * starts from 1 i.e. the second version of the API will be 0x02xxxxxx. This
  466. * number changes only, if the API itself changes so much that it is not
  467. * compatible anymore with older releases.
  468. * Bits 23-16 API minor version number. For example API version 2.1 would be
  469. * 0x0201xxxx.
  470. * Bits 15-8 are the number of the year when release is done. The 0 is year
  471. * 2000, 1 is year 2001 and so on
  472. * Bits 7- are the week number when release is done. First full week of the
  473. * year is 1
  474. *
  475. * Example: let's assume that release 2.1 is done on week 10 year 2008
  476. * the version will get the value 0x0201080A
  477. */
  478. typedef struct {
  479. /*
  480. * Version of the chipset API implementation
  481. *
  482. * bits [31:24] API specification major version number.<br>
  483. * bits [23:16] API specification minor version number.<br>
  484. * bits [15:8] API implementation year. (2000 = 0, 2001 = 1, ...)
  485. * bits [7:0] API implementation week.
  486. * Example: API spec version 4.0, implementation w46 2008 => 0x0400082E
  487. */
  488. uint32_t api_version;
  489. /* maximum block count which can be transferred at once */
  490. uint32_t max_block_count;
  491. /* maximum clock frequency in Hz supported by HW */
  492. uint32_t max_clock_freq;
  493. /* maximum data bus width supported by HW */
  494. uint16_t max_data_width;
  495. /* Is high-speed mode supported by HW (yes=1, no=0) */
  496. uint8_t hs_mode_supported;
  497. /* Is memory card removable (yes=1, no=0) */
  498. uint8_t card_removable;
  499. } HAL_MEMCARD_HW_CONF;
  500. /* Configuration structure to HAL layer. */
  501. typedef struct {
  502. /* how many times to try after fail, for instance sending command */
  503. uint32_t retries_after_fail;
  504. } HAL_MEMCARD_INIT_CONF;
  505. #endif /* EMMC_HAL_H */