drv_sdhci.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __DRV_SDHCI__
  7. #define __DRV_SDHCI__
  8. #include "board.h"
  9. #define false 0
  10. #define true 1
  11. #define SDEMMC0_BASE 0x91580000
  12. #define SDEMMC1_BASE 0x91581000
  13. #define IRQN_SD0 K230_IRQ_SD0
  14. #define IRQN_SD1 K230_IRQ_SD1
  15. /*
  16. * Controller registers
  17. */
  18. #define SDHCI_DMA_ADDRESS 0x00
  19. #define SDHCI_ARGUMENT2 SDHCI_DMA_ADDRESS
  20. #define SDHCI_32BIT_BLK_CNT SDHCI_DMA_ADDRESS
  21. #define SDHCI_BLOCK_SIZE 0x04
  22. #define SDHCI_MAKE_BLKSZ(dma, blksz) (((dma & 0x7) << 12) | (blksz & 0xFFF))
  23. #define SDHCI_BLOCK_COUNT 0x06
  24. #define SDHCI_ARGUMENT 0x08
  25. #define SDHCI_TRANSFER_MODE 0x0C
  26. #define SDHCI_TRNS_DMA 0x01
  27. #define SDHCI_TRNS_BLK_CNT_EN 0x02
  28. #define SDHCI_TRNS_AUTO_CMD12 0x04
  29. #define SDHCI_TRNS_AUTO_CMD23 0x08
  30. #define SDHCI_TRNS_AUTO_SEL 0x0C
  31. #define SDHCI_TRNS_READ 0x10
  32. #define SDHCI_TRNS_MULTI 0x20
  33. #define SDHCI_COMMAND 0x0E
  34. #define SDHCI_CMD_RESP_MASK 0x03
  35. #define SDHCI_CMD_CRC 0x08
  36. #define SDHCI_CMD_INDEX 0x10
  37. #define SDHCI_CMD_DATA 0x20
  38. #define SDHCI_CMD_ABORTCMD 0xC0
  39. #define SDHCI_CMD_RESP_NONE 0x00
  40. #define SDHCI_CMD_RESP_LONG 0x01
  41. #define SDHCI_CMD_RESP_SHORT 0x02
  42. #define SDHCI_CMD_RESP_SHORT_BUSY 0x03
  43. #define SDHCI_MAKE_CMD(c, f) (((c & 0xff) << 8) | (f & 0xff))
  44. #define SDHCI_GET_CMD(c) ((c >> 8) & 0x3f)
  45. #define SDHCI_RESPONSE 0x10
  46. #define SDHCI_BUFFER 0x20
  47. #define SDHCI_PRESENT_STATE 0x24
  48. #define SDHCI_CMD_INHIBIT 0x00000001
  49. #define SDHCI_DATA_INHIBIT 0x00000002
  50. #define SDHCI_DOING_WRITE 0x00000100
  51. #define SDHCI_DOING_READ 0x00000200
  52. #define SDHCI_SPACE_AVAILABLE 0x00000400
  53. #define SDHCI_DATA_AVAILABLE 0x00000800
  54. #define SDHCI_CARD_PRESENT 0x00010000
  55. #define SDHCI_CARD_PRES_SHIFT 16
  56. #define SDHCI_CD_STABLE 0x00020000
  57. #define SDHCI_CD_LVL 0x00040000
  58. #define SDHCI_CD_LVL_SHIFT 18
  59. #define SDHCI_WRITE_PROTECT 0x00080000
  60. #define SDHCI_DATA_LVL_MASK 0x00F00000
  61. #define SDHCI_DATA_LVL_SHIFT 20
  62. #define SDHCI_DATA_0_LVL_MASK 0x00100000
  63. #define SDHCI_CMD_LVL 0x01000000
  64. #define SDHCI_HOST_CONTROL 0x28
  65. #define SDHCI_CTRL_LED 0x01
  66. #define SDHCI_CTRL_4BITBUS 0x02
  67. #define SDHCI_CTRL_HISPD 0x04
  68. #define SDHCI_CTRL_DMA_MASK 0x18
  69. #define SDHCI_CTRL_SDMA 0x00
  70. #define SDHCI_CTRL_ADMA1 0x08
  71. #define SDHCI_CTRL_ADMA32 0x10
  72. #define SDHCI_CTRL_ADMA64 0x18
  73. #define SDHCI_CTRL_ADMA3 0x18
  74. #define SDHCI_CTRL_8BITBUS 0x20
  75. #define SDHCI_CTRL_CDTEST_INS 0x40
  76. #define SDHCI_CTRL_CDTEST_EN 0x80
  77. #define SDHCI_POWER_CONTROL 0x29
  78. #define SDHCI_POWER_ON 0x01
  79. #define SDHCI_POWER_180 0x0A
  80. #define SDHCI_POWER_300 0x0C
  81. #define SDHCI_POWER_330 0x0E
  82. #define SDHCI_BLOCK_GAP_CONTROL 0x2A
  83. #define SDHCI_WAKE_UP_CONTROL 0x2B
  84. #define SDHCI_WAKE_ON_INT 0x01
  85. #define SDHCI_WAKE_ON_INSERT 0x02
  86. #define SDHCI_WAKE_ON_REMOVE 0x04
  87. #define SDHCI_CLOCK_CONTROL 0x2C
  88. #define SDHCI_DIVIDER_SHIFT 8
  89. #define SDHCI_DIVIDER_HI_SHIFT 6
  90. #define SDHCI_DIV_MASK 0xFF
  91. #define SDHCI_DIV_MASK_LEN 8
  92. #define SDHCI_DIV_HI_MASK 0x300
  93. #define SDHCI_PROG_CLOCK_MODE 0x0020
  94. #define SDHCI_CLOCK_CARD_EN 0x0004
  95. #define SDHCI_CLOCK_PLL_EN 0x0008
  96. #define SDHCI_CLOCK_INT_STABLE 0x0002
  97. #define SDHCI_CLOCK_INT_EN 0x0001
  98. #define SDHCI_TIMEOUT_CONTROL 0x2E
  99. #define SDHCI_SOFTWARE_RESET 0x2F
  100. #define SDHCI_RESET_ALL 0x01
  101. #define SDHCI_RESET_CMD 0x02
  102. #define SDHCI_RESET_DATA 0x04
  103. #define SDHCI_INT_STATUS 0x30
  104. #define SDHCI_INT_ENABLE 0x34
  105. #define SDHCI_SIGNAL_ENABLE 0x38
  106. #define SDHCI_INT_RESPONSE 0x00000001
  107. #define SDHCI_INT_DATA_END 0x00000002
  108. #define SDHCI_INT_BLK_GAP 0x00000004
  109. #define SDHCI_INT_DMA_END 0x00000008
  110. #define SDHCI_INT_SPACE_AVAIL 0x00000010
  111. #define SDHCI_INT_DATA_AVAIL 0x00000020
  112. #define SDHCI_INT_CARD_INSERT 0x00000040
  113. #define SDHCI_INT_CARD_REMOVE 0x00000080
  114. #define SDHCI_INT_CARD_INT 0x00000100
  115. #define SDHCI_INT_RETUNE 0x00001000
  116. #define SDHCI_INT_CQE 0x00004000
  117. #define SDHCI_INT_ERROR 0x00008000
  118. #define SDHCI_INT_TIMEOUT 0x00010000
  119. #define SDHCI_INT_CRC 0x00020000
  120. #define SDHCI_INT_END_BIT 0x00040000
  121. #define SDHCI_INT_INDEX 0x00080000
  122. #define SDHCI_INT_DATA_TIMEOUT 0x00100000
  123. #define SDHCI_INT_DATA_CRC 0x00200000
  124. #define SDHCI_INT_DATA_END_BIT 0x00400000
  125. #define SDHCI_INT_BUS_POWER 0x00800000
  126. #define SDHCI_INT_AUTO_CMD_ERR 0x01000000
  127. #define SDHCI_INT_ADMA_ERROR 0x02000000
  128. #define SDHCI_INT_NORMAL_MASK 0x00007FFF
  129. #define SDHCI_INT_ERROR_MASK 0xFFFF8000
  130. #define SDHCI_INT_CMD_MASK (SDHCI_INT_RESPONSE | SDHCI_INT_TIMEOUT | SDHCI_INT_CRC | SDHCI_INT_END_BIT | SDHCI_INT_INDEX | SDHCI_INT_AUTO_CMD_ERR)
  131. #define SDHCI_INT_DATA_MASK (SDHCI_INT_DATA_END | SDHCI_INT_DMA_END | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT | SDHCI_INT_ADMA_ERROR | SDHCI_INT_BLK_GAP)
  132. #define SDHCI_INT_ALL_MASK ((unsigned int)-1)
  133. #define SDHCI_CQE_INT_ERR_MASK ( \
  134. SDHCI_INT_ADMA_ERROR | SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_TIMEOUT | SDHCI_INT_INDEX | SDHCI_INT_END_BIT | SDHCI_INT_CRC | SDHCI_INT_TIMEOUT)
  135. #define SDHCI_CQE_INT_MASK (SDHCI_CQE_INT_ERR_MASK | SDHCI_INT_CQE)
  136. #define SDHCI_AUTO_CMD_STATUS 0x3C
  137. #define SDHCI_AUTO_CMD_TIMEOUT 0x00000002
  138. #define SDHCI_AUTO_CMD_CRC 0x00000004
  139. #define SDHCI_AUTO_CMD_END_BIT 0x00000008
  140. #define SDHCI_AUTO_CMD_INDEX 0x00000010
  141. #define SDHCI_HOST_CONTROL2 0x3E
  142. #define SDHCI_CTRL_UHS_MASK 0x0007
  143. #define SDHCI_CTRL_UHS_SDR12 0x0000
  144. #define SDHCI_CTRL_UHS_SDR25 0x0001
  145. #define SDHCI_CTRL_UHS_SDR50 0x0002
  146. #define SDHCI_CTRL_UHS_SDR104 0x0003
  147. #define SDHCI_CTRL_UHS_DDR50 0x0004
  148. #define SDHCI_CTRL_HS400 0x0005 /* Non-standard */
  149. #define SDHCI_CTRL_VDD_180 0x0008
  150. #define SDHCI_CTRL_DRV_TYPE_MASK 0x0030
  151. #define SDHCI_CTRL_DRV_TYPE_B 0x0000
  152. #define SDHCI_CTRL_DRV_TYPE_A 0x0010
  153. #define SDHCI_CTRL_DRV_TYPE_C 0x0020
  154. #define SDHCI_CTRL_DRV_TYPE_D 0x0030
  155. #define SDHCI_CTRL_EXEC_TUNING 0x0040
  156. #define SDHCI_CTRL_TUNED_CLK 0x0080
  157. #define SDHCI_CMD23_ENABLE 0x0800
  158. #define SDHCI_CTRL_V4_MODE 0x1000
  159. #define SDHCI_CTRL_64BIT_ADDR 0x2000
  160. #define SDHCI_CTRL_PRESET_VAL_ENABLE 0x8000
  161. #define SDHCI_CAPABILITIES 0x40
  162. #define SDHCI_TIMEOUT_CLK_MASK GENMASK(5, 0)
  163. #define SDHCI_TIMEOUT_CLK_UNIT 0x00000080
  164. #define SDHCI_CLOCK_BASE_MASK GENMASK(13, 8)
  165. #define SDHCI_CLOCK_V3_BASE_MASK GENMASK(15, 8)
  166. #define SDHCI_MAX_BLOCK_MASK 0x00030000
  167. #define SDHCI_MAX_BLOCK_SHIFT 16
  168. #define SDHCI_CAN_DO_8BIT 0x00040000
  169. #define SDHCI_CAN_DO_ADMA2 0x00080000
  170. #define SDHCI_CAN_DO_ADMA1 0x00100000
  171. #define SDHCI_CAN_DO_HISPD 0x00200000
  172. #define SDHCI_CAN_DO_SDMA 0x00400000
  173. #define SDHCI_CAN_DO_SUSPEND 0x00800000
  174. #define SDHCI_CAN_VDD_330 0x01000000
  175. #define SDHCI_CAN_VDD_300 0x02000000
  176. #define SDHCI_CAN_VDD_180 0x04000000
  177. #define SDHCI_CAN_64BIT_V4 0x08000000
  178. #define SDHCI_CAN_64BIT 0x10000000
  179. #define SDHCI_CAPABILITIES_1 0x44
  180. #define SDHCI_SUPPORT_SDR50 0x00000001
  181. #define SDHCI_SUPPORT_SDR104 0x00000002
  182. #define SDHCI_SUPPORT_DDR50 0x00000004
  183. #define SDHCI_DRIVER_TYPE_A 0x00000010
  184. #define SDHCI_DRIVER_TYPE_C 0x00000020
  185. #define SDHCI_DRIVER_TYPE_D 0x00000040
  186. #define SDHCI_RETUNING_TIMER_COUNT_MASK GENMASK(11, 8)
  187. #define SDHCI_USE_SDR50_TUNING 0x00002000
  188. #define SDHCI_RETUNING_MODE_MASK GENMASK(15, 14)
  189. #define SDHCI_CLOCK_MUL_MASK GENMASK(23, 16)
  190. #define SDHCI_CAN_DO_ADMA3 0x08000000
  191. #define SDHCI_SUPPORT_HS400 0x80000000 /* Non-standard */
  192. #define SDHCI_MAX_CURRENT 0x48
  193. #define SDHCI_MAX_CURRENT_LIMIT GENMASK(7, 0)
  194. #define SDHCI_MAX_CURRENT_330_MASK GENMASK(7, 0)
  195. #define SDHCI_MAX_CURRENT_300_MASK GENMASK(15, 8)
  196. #define SDHCI_MAX_CURRENT_180_MASK GENMASK(23, 16)
  197. #define SDHCI_MAX_CURRENT_MULTIPLIER 4
  198. /* 4C-4F reserved for more max current */
  199. #define SDHCI_SET_ACMD12_ERROR 0x50
  200. #define SDHCI_SET_INT_ERROR 0x52
  201. #define SDHCI_ADMA_ERROR 0x54
  202. /* 55-57 reserved */
  203. #define SDHCI_ADMA_ADDRESS 0x58
  204. #define SDHCI_ADMA_ADDRESS_HI 0x5C
  205. /* 60-FB reserved */
  206. #define SDHCI_PRESET_FOR_HIGH_SPEED 0x64
  207. #define SDHCI_PRESET_FOR_SDR12 0x66
  208. #define SDHCI_PRESET_FOR_SDR25 0x68
  209. #define SDHCI_PRESET_FOR_SDR50 0x6A
  210. #define SDHCI_PRESET_FOR_SDR104 0x6C
  211. #define SDHCI_PRESET_FOR_DDR50 0x6E
  212. #define SDHCI_PRESET_FOR_HS400 0x74 /* Non-standard */
  213. #define SDHCI_PRESET_DRV_MASK GENMASK(15, 14)
  214. #define SDHCI_PRESET_CLKGEN_SEL BIT(10)
  215. #define SDHCI_PRESET_SDCLK_FREQ_MASK GENMASK(9, 0)
  216. #define SDHCI_SLOT_INT_STATUS 0xFC
  217. #define SDHCI_HOST_VERSION 0xFE
  218. #define SDHCI_VENDOR_VER_MASK 0xFF00
  219. #define SDHCI_VENDOR_VER_SHIFT 8
  220. #define SDHCI_SPEC_VER_MASK 0x00FF
  221. #define SDHCI_SPEC_VER_SHIFT 0
  222. #define SDHCI_SPEC_100 0
  223. #define SDHCI_SPEC_200 1
  224. #define SDHCI_SPEC_300 2
  225. #define SDHCI_SPEC_400 3
  226. #define SDHCI_SPEC_410 4
  227. #define SDHCI_SPEC_420 5
  228. /*
  229. * End of controller registers.
  230. */
  231. #define SDHCI_MAX_DIV_SPEC_300 2046
  232. /*! @brief Transfer flag mask */
  233. enum sdhci_transfer_mode
  234. {
  235. sdhci_enable_dma_flag = SDHCI_TRNS_DMA, /*!< Enable DMA */
  236. sdhci_enable_block_count_flag = SDHCI_TRNS_BLK_CNT_EN, /*!< Enable block count */
  237. sdhci_enable_auto_command12_flag = SDHCI_TRNS_AUTO_CMD12, /*!< Enable auto CMD12 */
  238. sdhci_data_read_flag = SDHCI_TRNS_READ, /*!< Enable data read */
  239. sdhci_multiple_block_flag = SDHCI_TRNS_MULTI, /*!< Multiple block data read/write */
  240. sdhci_enable_auto_command23_flag = SDHCI_TRNS_AUTO_CMD23, /*!< Enable auto CMD23 */
  241. sdhci_enable_auto_commamd_sel_flag = SDHCI_TRNS_AUTO_SEL, /* Enable auto command sel*/
  242. };
  243. enum sdhci_command_flag
  244. {
  245. sdhci_cmd_resp_nono = SDHCI_CMD_RESP_NONE,
  246. sdhci_cmd_resp_long = SDHCI_CMD_RESP_LONG,
  247. sdhci_cmd_resp_short = SDHCI_CMD_RESP_SHORT,
  248. sdhci_cmd_resp_short_busy = SDHCI_CMD_RESP_SHORT_BUSY,
  249. sdhci_enable_cmd_crc_flag = SDHCI_CMD_CRC,
  250. sdhci_enable_cmd_index_chk_flag = SDHCI_CMD_INDEX,
  251. sdhci_enable_cmd_data_present_flag = SDHCI_CMD_DATA,
  252. sdhci_enable_command_type_normal = 0x00,
  253. sdhci_enable_command_type_suspend = 0x40,
  254. sdhci_enable_command_type_resume = 0x80,
  255. sdhci_enable_command_type_abort = 0xc0,
  256. };
  257. /*! @brief Present status flag mask */
  258. enum sdhci_present_status_flag
  259. {
  260. sdhci_command_inhibit_flag = 0x1, /*!< Command inhibit */
  261. sdhci_data_inhibit_flag = 0x2, /*!< Data inhibit */
  262. sdhci_data_line_active_flag = 0x4, /*!< Data line active */
  263. sdhci_write_transfer_active_flag = 0x100, /*!< Write transfer active */
  264. sdhci_read_transfer_active_flag = 0x200, /*!< Read transfer active */
  265. sdhci_buffer_write_enable_flag = 0x400, /*!< Buffer write enable */
  266. sdhci_buffer_read_enable_flag = 0x800, /*!< Buffer read enable */
  267. sdhci_card_insert_flag = 0x10000, /*!< Card inserted */
  268. sdhci_sd_clock_stable_flag = 0x20000, /*!< SD bus clock stable */
  269. sdhci_card_detect_pin_level_flag = 0x40000, /*!< card detect pin level */
  270. sdhci_write_protect_switch_pin_level_flag = 0x80000, /*<write protect switch pin level>*/
  271. sdhci_data0_line_level_flag = (1U << 20), /*!< Data0 line signal level */
  272. sdhci_data1_line_level_flag = (1U << (20 + 1U)), /*!< Data1 line signal level */
  273. sdhci_data2_line_level_flag = (1U << (20 + 2U)), /*!< Data2 line signal level */
  274. sdhci_data3_line_level_flag = (1U << (20 + 3U)), /*!< Data3 line signal level */
  275. sdhci_data4_line_level_flag = (1U << (4 + 0U)), /*!< Data4 line signal level */
  276. sdhci_data5_line_level_flag = (1U << (4 + 1U)), /*!< Data5 line signal level */
  277. sdhci_data6_line_level_flag = (1U << (4 + 2U)), /*!< Data6 line signal level */
  278. sdhci_data7_line_level_flag = (1U << (4 + 3U)), /*!< Data7 line signal level */
  279. sdhci_command_line_signal_level_flag =0x1000000,
  280. sdhci_host_reg_voltage_stable_flag = 0x2000000,
  281. sdhci_command_not_issued_by_error_flag = 0x8000000,
  282. sdhci_sub_command_status_flag = 0x10000000,
  283. sdhci_in_dormant_status_flag = 0x20000000,
  284. sdhci_lane_synchronization_flag = 0x40000000,
  285. sdhci_uhs_ii_interface_detection_flag = 0x80000000,
  286. };
  287. /*! @brief Interrupt status flag mask */
  288. enum sdhci_interrupt_status_flag
  289. {
  290. sdhci_command_complete_flag = 0x1, /*!< Command complete */
  291. sdhci_data_complete_flag = 0x2, /*!< Data complete */
  292. sdhci_block_gap_event_flag = 0x4, /*!< Block gap event */
  293. sdhci_dma_complete_flag = 0x8, /*!< DMA interrupt */
  294. sdhci_buffer_write_ready_flag = 0x10, /*!< Buffer write ready */
  295. sdhci_buffer_read_ready_flag = 0x20, /*!< Buffer read ready */
  296. sdhci_card_insertion_flag = 0x40, /*!< Card inserted */
  297. sdhci_card_removal_flag = 0x80, /*!< Card removed */
  298. sdhci_card_interrupt_flag = 0x100, /*!< Card interrupt */
  299. sdhci_command_timeout_flag = 0x10000, /*!< Command timeout error */
  300. sdhci_command_crc_error_flag = 0x20000, /*!< Command CRC error */
  301. sdhci_command_end_bit_error_flag = 0x40000, /*!< Command end bit error */
  302. sdhci_command_index_error_flag = 0x80000, /*!< Command index error */
  303. sdhci_data_timeout_flag = 0x100000, /*!< Data timeout error */
  304. sdhci_data_crc_error_flag = 0x200000, /*!< Data CRC error */
  305. sdhci_data_end_bit_error_flag = 0x400000, /*!< Data end bit error */
  306. sdhci_auto_command_error_flag = 0x1000000, /*!< Auto CMD error */
  307. sdhci_dma_error_flag = 0x2000000, /*!< ADMA error */
  308. sdhci_tuning_error_flag = 0x4000000, /* tuning err*/
  309. sdhci_response_err_flag = 0x8000000, /*resp error*/
  310. sdhci_command_error_flag = (sdhci_command_timeout_flag | sdhci_command_crc_error_flag | sdhci_command_end_bit_error_flag |
  311. sdhci_command_index_error_flag), /*!< Command error */
  312. sdhci_data_error_flag = (sdhci_data_timeout_flag | sdhci_data_crc_error_flag | sdhci_data_end_bit_error_flag |
  313. sdhci_auto_command_error_flag), /*!< Data error */
  314. sdhci_error_flag = (sdhci_command_error_flag | sdhci_data_error_flag | sdhci_dma_error_flag), /*!< All error */
  315. sdhci_data_flag = (sdhci_data_complete_flag | sdhci_dma_complete_flag | sdhci_buffer_write_ready_flag |
  316. sdhci_buffer_read_ready_flag | sdhci_data_error_flag | sdhci_dma_error_flag), /*!< Data interrupts */
  317. sdhci_command_flag = (sdhci_command_error_flag | sdhci_command_complete_flag), /*!< Command interrupts */
  318. sdhci_card_detect_flag = (sdhci_card_insertion_flag | sdhci_card_removal_flag), /*!< Card detection interrupts */
  319. sdhci_sdr104_tuning_flag = (sdhci_tuning_error_flag),
  320. sdhci_all_interrupt_flags = (sdhci_block_gap_event_flag | sdhci_card_detect_flag | sdhci_command_flag |
  321. sdhci_data_flag | sdhci_error_flag | sdhci_sdr104_tuning_flag), /*!< All flags mask */
  322. };
  323. /*! @brief USDHC status */
  324. enum sdhci_status
  325. {
  326. sdhci_status_busy_transferring = 65, /*!< Transfer is on-going */
  327. sdhci_status_prepare_adma_descriptor_failed = 66, /*!< Set DMA descriptor failed */
  328. sdhci_status_send_command_failed = 67, /*!< Send command failed */
  329. sdhci_status_transfer_data_failed = 68, /*!< Transfer data failed */
  330. sdhci_status_dma_data_addr_no_align = 69, /*!< data address not align */
  331. sdhci_status_retuning_request = 70, /*!< re-tuning request */
  332. sdhci_status_tuning_error = 71, /*!< tuning error */
  333. };
  334. /* ADMA2 data alignment */
  335. #define SDHCI_ADMA2_ALIGN 4
  336. #define SDHCI_ADMA2_MASK (SDHCI_ADMA2_ALIGN - 1)
  337. /*! @brief The bit shift for LENGTH field in ADMA2's descriptor */
  338. #define SDHCI_ADMA2_DESCRIPTOR_LENGTH_SHIFT (16U)
  339. /*! @brief The bit mask for LENGTH field in ADMA2's descriptor */
  340. #define SDHCI_ADMA2_DESCRIPTOR_LENGTH_MASK (0xFFFFU)
  341. /*! @brief The maximum value of LENGTH field in ADMA2's descriptor */
  342. #define SDHCI_ADMA2_DESCRIPTOR_MAX_LENGTH_PER_ENTRY (SDHCI_ADMA2_DESCRIPTOR_LENGTH_MASK - 3U)
  343. #define SDHCI_DESC_VALID (0x1U << 0)
  344. #define SDHCI_DESC_END (0x1U << 1)
  345. #define SDHCI_DESC_INT (0x1U << 2)
  346. #define SDHCI_DESC_TRAN (0x2U << 4)
  347. struct sdhci_64bit_adma2_descriptor
  348. {
  349. uint32_t attribute;
  350. uint32_t address;
  351. };
  352. /*! @brief The command type */
  353. enum sdhci_card_command_type
  354. {
  355. card_command_type_normal = 0U, /*!< Normal command */
  356. card_command_type_suspend = 1U, /*!< Suspend command */
  357. card_command_type_resume = 2U, /*!< Resume command */
  358. card_command_type_abort = 3U, /*!< Abort command */
  359. };
  360. /*!
  361. * @brief The command response type.
  362. *
  363. * Define the command response type from card to host controller.
  364. */
  365. enum sdhci_card_response_type
  366. {
  367. card_response_type_none = 0U, /*!< Response type: none */
  368. card_response_type_r1 = 1U, /*!< Response type: R1 */
  369. card_response_type_r1b = 2U, /*!< Response type: R1b */
  370. card_response_type_r2 = 3U, /*!< Response type: R2 */
  371. card_response_type_r3 = 4U, /*!< Response type: R3 */
  372. card_response_type_r4 = 5U, /*!< Response type: R4 */
  373. card_response_type_r5 = 6U, /*!< Response type: R5 */
  374. card_response_type_r5b = 7U, /*!< Response type: R5b */
  375. card_response_type_r6 = 8U, /*!< Response type: R6 */
  376. card_response_type_r7 = 9U, /*!< Response type: R7 */
  377. };
  378. /*!
  379. * @brief Card data descriptor
  380. *
  381. * Defines a structure to contain data-related attribute. 'enableIgnoreError' is used for the case that upper card
  382. * driver
  383. * want to ignore the error event to read/write all the data not to stop read/write immediately when error event
  384. * happen for example bus testing procedure for MMC card.
  385. */
  386. struct sdhci_data
  387. {
  388. rt_bool_t enableAutoCommand12; /*!< Enable auto CMD12 */
  389. rt_bool_t enableAutoCommand23; /*!< Enable auto CMD23 */
  390. rt_bool_t enableIgnoreError; /*!< Enable to ignore error event to read/write all the data */
  391. rt_bool_t executeTuning; /*!< execute tuning flag */
  392. size_t blockSize; /*!< Block size */
  393. uint32_t blockCount; /*!< Block count */
  394. uint32_t *rxData; /*!< Buffer to save data read */
  395. const uint32_t *txData; /*!< Data buffer to write */
  396. };
  397. /*!
  398. * @brief Card command descriptor
  399. *
  400. * Define card command-related attribute.
  401. */
  402. struct sdhci_command
  403. {
  404. uint32_t index; /*!< Command index */
  405. uint32_t argument; /*!< Command argument */
  406. enum sdhci_card_command_type type; /*!< Command type */
  407. enum sdhci_card_response_type responseType; /*!< Command response type */
  408. uint32_t response[4U]; /*!< Response for this command */
  409. uint32_t responseErrorFlags; /*!< response error flag, the flag which need to check
  410. the command reponse*/
  411. uint16_t flags; /*!< Cmd flags */
  412. uint16_t flags2; /*xfer mode*/
  413. };
  414. struct sdhci_host
  415. {
  416. struct rt_mmcsd_host *host;
  417. void *mapbase;
  418. struct sdhci_data *sdhci_data;
  419. struct sdhci_command *sdhci_command;
  420. void *usdhc_adma2_table;
  421. struct rt_event event;
  422. uint16_t error_code;
  423. uint32_t max_clk;
  424. uint8_t index;
  425. uint8_t is_emmc_card;
  426. uint8_t io_fixed_1v8;
  427. uint8_t have_phy;
  428. uint8_t mshc_ctrl_r;
  429. uint32_t rx_delay_line;
  430. uint32_t tx_delay_line;
  431. };
  432. #endif /*__DRV_SDHCI__*/