sddwc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. sddwc.h
  9. Abstract:
  10. This header contains definitions for the DesignWare SD/MMC device library.
  11. Author:
  12. Chris Stevens 16-Jul-2015
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. #include <dev/sd.h>
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. //
  22. // These macros read and write SD DesignWare controller registers.
  23. //
  24. #define SD_DWC_READ_REGISTER(_Controller, _Register) \
  25. EfiReadRegister32((_Controller)->ControllerBase + (_Register))
  26. #define SD_DWC_WRITE_REGISTER(_Controller, _Register, _Value) \
  27. EfiWriteRegister32((_Controller)->ControllerBase + (_Register), (_Value))
  28. //
  29. // ---------------------------------------------------------------- Definitions
  30. //
  31. //
  32. // Define the amount of time to wait in microseconds for the controller to
  33. // respond.
  34. //
  35. #define EFI_SD_DWC_CONTROLLER_TIMEOUT 1000000
  36. //
  37. // Define the block sized used by the SD library.
  38. //
  39. #define SD_DWC_BLOCK_SIZE 512
  40. //
  41. // Define the SD control register bits.
  42. //
  43. #define SD_DWC_CONTROL_USE_INTERNAL_DMAC (1 << 25)
  44. #define SD_DWC_CONTROL_ENABLE_OD_PULLUP (1 << 24)
  45. #define SD_DWC_CONTROL_CARD_VOLTAGE_B_MASK (0xF << 20)
  46. #define SD_DWC_CONTROL_CARD_VOLTAGE_B_SHIFT 20
  47. #define SD_DWC_CONTROL_CARD_VOLTAGE_A_MASK (0xF << 16)
  48. #define SD_DWC_CONTROL_CARD_VOLTAGE_A_SHIFT 16
  49. #define SD_DWC_CONTROL_CE_ATA_INTERRUPT_ENABLE (1 << 11)
  50. #define SD_DWC_CONTROL_SEND_AUTO_STOP_CCSD (1 << 10)
  51. #define SD_DWC_CONTROL_SEND_CCSD (1 << 9)
  52. #define SD_DWC_CONTROL_ABORT_READ_DATA (1 << 8)
  53. #define SD_DWC_CONTROL_SEND_IRQ_RESPONSE (1 << 7)
  54. #define SD_DWC_CONTROL_READ_WAIT (1 << 6)
  55. #define SD_DWC_CONTROL_DMA_ENABLE (1 << 5)
  56. #define SD_DWC_CONTROL_INTERRUPT_ENABLE (1 << 4)
  57. #define SD_DWC_CONTROL_DMA_RESET (1 << 2)
  58. #define SD_DWC_CONTROL_FIFO_RESET (1 << 1)
  59. #define SD_DWC_CONTROL_CONTROLLER_RESET (1 << 0)
  60. //
  61. // Define the SD power register bits.
  62. //
  63. #define SD_DWC_POWER_DISABLE (0 << 0)
  64. #define SD_DWC_POWER_ENABLE (1 << 0)
  65. //
  66. // Define the SD clock divider register bits.
  67. //
  68. #define SD_DWC_CLOCK_DIVIDER_3_MASK (0xFF << 24)
  69. #define SD_DWC_CLOCK_DIVIDER_3_SHIFT 24
  70. #define SD_DWC_CLOCK_DIVIDER_2_MASK (0xFF << 16)
  71. #define SD_DWC_CLOCK_DIVIDER_2_SHIFT 16
  72. #define SD_DWC_CLOCK_DIVIDER_1_MASK (0xFF << 8)
  73. #define SD_DWC_CLOCK_DIVIDER_1_SHIFT 8
  74. #define SD_DWC_CLOCK_DIVIDER_0_MASK (0xFF << 0)
  75. #define SD_DWC_CLOCK_DIVIDER_0_SHIFT 0
  76. #define SD_DWC_MAX_DIVISOR (0xFF * 2)
  77. //
  78. // Define the SD clock source register bits.
  79. //
  80. #define SD_DWC_CLOCK_SOURCE_DIVIDER_3 0x3
  81. #define SD_DWC_CLOCK_SOURCE_DIVIDER_2 0x2
  82. #define SD_DWC_CLOCK_SOURCE_DIVIDER_1 0x1
  83. #define SD_DWC_CLOCK_SOURCE_DIVIDER_0 0x0
  84. #define SD_DWC_CLOCK_SOURCE_DIVIDER_MASK (0x3 << 0)
  85. #define SD_DWC_CLOCK_SOURCE_DIVIDER_SHIFT 0
  86. //
  87. // Define the SD clock enable register bits.
  88. //
  89. #define SD_DWC_CLOCK_ENABLE_LOW_POWER (1 << 16)
  90. #define SD_DWC_CLOCK_ENABLE_ON (1 << 0)
  91. //
  92. // Define the SD clock timeout register bits.
  93. //
  94. #define SD_DWC_TIMEOUT_DATA_MASK (0xFFFFFF << 8)
  95. #define SD_DWC_TIMEOUT_DATA_SHIFT 8
  96. #define SD_DWC_TIMEOUT_RESPONSE_MASK (0xFF << 0)
  97. #define SD_DWC_TIMEOUT_RESPONSE_SHIFT 0
  98. #define SD_DWC_TIMEOUT_DEFAULT 0xFFFFFF40
  99. //
  100. // Define the SD card type register bits.
  101. //
  102. #define SD_DWC_CARD_TYPE_8_BIT_WIDTH (1 << 16)
  103. #define SD_DWC_CARD_TYPE_4_BIT_WIDTH (1 << 0)
  104. #define SD_DWC_CARD_TYPE_1_BIT_WIDTH (0 << 0)
  105. //
  106. // Define the SD block size register bits.
  107. //
  108. #define SD_DWC_BLOCK_SIZE_MASK (0xFFFF << 0)
  109. #define SD_DWC_BLOCK_SIZE_SHIFT 0
  110. #define SD_DWC_BLOCK_SIZE_MAX 0xFFFF
  111. //
  112. // Define the SD interrupt mask register bits.
  113. //
  114. #define SD_DWC_INTERRUPT_MASK_SDIO (1 << 24)
  115. #define SD_DWC_INTERRUPT_MASK_DATA_NO_BUSY (1 << 16)
  116. #define SD_DWC_INTERRUPT_MASK_ERROR_END_BIT (1 << 15)
  117. #define SD_DWC_INTERRUPT_MASK_AUTO_COMMAND_DONE (1 << 14)
  118. #define SD_DWC_INTERRUPT_MASK_ERROR_START_BIT (1 << 13)
  119. #define SD_DWC_INTERRUPT_MASK_ERROR_HARDWARE_LOCKED (1 << 12)
  120. #define SD_DWC_INTERRUPT_MASK_ERROR_FIFO_UNDERRUN (1 << 11)
  121. #define SD_DWC_INTERRUPT_MASK_ERROR_HOST_TIMEOUT (1 << 10)
  122. #define SD_DWC_INTERRUPT_MASK_ERROR_DATA_READ_TIMEOUT (1 << 9)
  123. #define SD_DWC_INTERRUPT_MASK_ERROR_RESPONSE_TIMEOUT (1 << 8)
  124. #define SD_DWC_INTERRUPT_MASK_ERROR_DATA_CRC (1 << 7)
  125. #define SD_DWC_INTERRUPT_MASK_ERROR_RESPONSE_CRC (1 << 6)
  126. #define SD_DWC_INTERRUPT_MASK_RECEIVE_FIFO_DATA_REQUEST (1 << 5)
  127. #define SD_DWC_INTERRUPT_MASK_TRANSMIT_FIFO_DATA_REQUEST (1 << 4)
  128. #define SD_DWC_INTERRUPT_MASK_DATA_TRANSFER_OVER (1 << 3)
  129. #define SD_DWC_INTERRUPT_MASK_COMMAND_DONE (1 << 2)
  130. #define SD_DWC_INTERRUPT_MASK_ERROR_RESPONSE (1 << 1)
  131. #define SD_DWC_INTERRUPT_MASK_CARD_DETECT (1 << 0)
  132. #define SD_DWC_INTERRUPT_ERROR_MASK \
  133. (SD_DWC_INTERRUPT_MASK_ERROR_END_BIT | \
  134. SD_DWC_INTERRUPT_MASK_ERROR_START_BIT | \
  135. SD_DWC_INTERRUPT_MASK_ERROR_DATA_READ_TIMEOUT | \
  136. SD_DWC_INTERRUPT_MASK_ERROR_RESPONSE_TIMEOUT | \
  137. SD_DWC_INTERRUPT_MASK_ERROR_DATA_CRC | \
  138. SD_DWC_INTERRUPT_MASK_ERROR_RESPONSE_CRC | \
  139. SD_DWC_INTERRUPT_MASK_ERROR_RESPONSE)
  140. #define SD_DWC_INTERRUPT_DEFAULT_MASK SD_DWC_INTERRUPT_MASK_CARD_DETECT
  141. //
  142. // Define the SD interrupt status register bits.
  143. //
  144. #define SD_DWC_INTERRUPT_STATUS_SDIO (1 << 24)
  145. #define SD_DWC_INTERRUPT_STATUS_DATA_NO_BUSY_DISABLE (1 << 16)
  146. #define SD_DWC_INTERRUPT_STATUS_ERROR_END_BIT (1 << 15)
  147. #define SD_DWC_INTERRUPT_STATUS_AUTO_COMMAND_DONE (1 << 14)
  148. #define SD_DWC_INTERRUPT_STATUS_ERROR_START_BIT (1 << 13)
  149. #define SD_DWC_INTERRUPT_STATUS_ERROR_HARDWARE_LOCKED (1 << 12)
  150. #define SD_DWC_INTERRUPT_STATUS_ERROR_FIFO_UNDERRUN (1 << 11)
  151. #define SD_DWC_INTERRUPT_STATUS_ERROR_HOST_TIMEOUT (1 << 10)
  152. #define SD_DWC_INTERRUPT_STATUS_ERROR_DATA_READ_TIMEOUT (1 << 9)
  153. #define SD_DWC_INTERRUPT_STATUS_ERROR_RESPONSE_TIMEOUT (1 << 8)
  154. #define SD_DWC_INTERRUPT_STATUS_ERROR_DATA_CRC (1 << 7)
  155. #define SD_DWC_INTERRUPT_STATUS_ERROR_RESPONSE_CRC (1 << 6)
  156. #define SD_DWC_INTERRUPT_STATUS_RECEIVE_FIFO_DATA_REQUEST (1 << 5)
  157. #define SD_DWC_INTERRUPT_STATUS_TRANSMIT_FIFO_DATA_REQUEST (1 << 4)
  158. #define SD_DWC_INTERRUPT_STATUS_DATA_TRANSFER_OVER (1 << 3)
  159. #define SD_DWC_INTERRUPT_STATUS_COMMAND_DONE (1 << 2)
  160. #define SD_DWC_INTERRUPT_STATUS_ERROR_RESPONSE (1 << 1)
  161. #define SD_DWC_INTERRUPT_STATUS_CARD_DETECT (1 << 0)
  162. #define SD_DWC_INTERRUPT_STATUS_ALL_MASK 0xFFFFFFFF
  163. #define SD_DWC_INTERRUPT_STATUS_COMMAND_ERROR_MASK \
  164. (SD_DWC_INTERRUPT_STATUS_ERROR_RESPONSE | \
  165. SD_DWC_INTERRUPT_STATUS_ERROR_RESPONSE_CRC)
  166. #define SD_DWC_INTERRUPT_STATUS_DATA_ERROR_MASK \
  167. (SD_DWC_INTERRUPT_STATUS_ERROR_DATA_CRC | \
  168. SD_DWC_INTERRUPT_STATUS_ERROR_DATA_READ_TIMEOUT | \
  169. SD_DWC_INTERRUPT_STATUS_ERROR_HOST_TIMEOUT | \
  170. SD_DWC_INTERRUPT_STATUS_ERROR_START_BIT | \
  171. SD_DWC_INTERRUPT_STATUS_ERROR_END_BIT)
  172. //
  173. // Define the SD command register bits.
  174. //
  175. #define SD_DWC_COMMAND_START (1 << 31)
  176. #define SD_DWC_COMMAND_USE_HOLD_REGISTER (1 << 29)
  177. #define SD_DWC_COMMAND_VOLT_SWITCH (1 << 28)
  178. #define SD_DWC_COMMAND_BOOT_MODE (1 << 27)
  179. #define SD_DWC_COMMAND_DISABLE_BOOT (1 << 26)
  180. #define SD_DWC_COMMAND_EXPECT_BOOT_ACK (1 << 25)
  181. #define SD_DWC_COMMAND_ENABLE_BOOT (1 << 24)
  182. #define SD_DWC_COMMAND_CSS_EXPECTED (1 << 23)
  183. #define SD_DWC_COMMAND_READ_CE_ATA (1 << 22)
  184. #define SD_DWC_COMMAND_UPDATE_CLOCK_REGISTERS (1 << 21)
  185. #define SD_DWC_COMMAND_CARD_NUMBER_MASK (0x1F << 16)
  186. #define SD_DWC_COMMAND_CARD_NUMBER_SHIFT 16
  187. #define SD_DWC_COMMAND_SEND_INITIALIZATION (1 << 15)
  188. #define SD_DWC_COMMAND_STOP_ABORT (1 << 14)
  189. #define SD_DWC_COMMAND_WAIT_PREVIOUS_DATA_COMPLETE (1 << 13)
  190. #define SD_DWC_COMMAND_SEND_AUTO_STOP (1 << 12)
  191. #define SD_DWC_COMMAND_TRANSFER_MODE_BLOCK (0 << 11)
  192. #define SD_DWC_COMMAND_TRANSFER_MODE_STREAM (1 << 11)
  193. #define SD_DWC_COMMAND_READ (0 << 10)
  194. #define SD_DWC_COMMAND_WRITE (1 << 10)
  195. #define SD_DWC_COMMAND_DATA_EXPECTED (1 << 9)
  196. #define SD_DWC_COMMAND_CHECK_RESPONSE_CRC (1 << 8)
  197. #define SD_DWC_COMMAND_LONG_RESPONSE (1 << 7)
  198. #define SD_DWC_COMMAND_RESPONSE_EXPECTED (1 << 6)
  199. #define SD_DWC_COMMAND_INDEX_MASK (0x3F << 0)
  200. #define SD_DWC_COMMAND_INDEX_SHIFT 0
  201. //
  202. // Define the SD status register bits.
  203. //
  204. #define SD_DWC_STATUS_DMA_REQUEST (1 << 31)
  205. #define SD_DWC_STATUS_DMA_ACK (1 << 30)
  206. #define SD_DWC_STATUS_FIFO_COUNT_MASK (0x1FFF << 17)
  207. #define SD_DWC_STATUS_FIFO_COUNT_SHIFT 17
  208. #define SD_DWC_STATUS_RESPONSE_INDEX_MASK (0x3F << 11)
  209. #define SD_DWC_STATUS_RESPONSE_INDEX_SHIFT 11
  210. #define SD_DWC_STATUS_DATA_STATE_MACHINE_BUSY (1 << 10)
  211. #define SD_DWC_STATUS_DATA_BUSY (1 << 9)
  212. #define SD_DWC_STATUS_DATA_3_STATUS (1 << 8)
  213. #define SD_DWC_STATUS_COMMAND_FSM_STATE_MASK (0xF << 4)
  214. #define SD_DWC_STATUS_COMMAND_FSM_STATE_SHIFT 4
  215. #define SD_DWC_STATUS_FIFO_FULL (1 << 3)
  216. #define SD_DWC_STATUS_FIFO_EMPTY (1 << 2)
  217. #define SD_DWC_STATUS_FIFO_TRANSMIT_WATERMARK (1 << 1)
  218. #define SD_DWC_STATUS_FIFO_RECEIVE_WATERMARK (1 << 0)
  219. //
  220. // Define the SD FIFO threshold register bits.
  221. //
  222. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_1 0
  223. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_4 1
  224. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_8 2
  225. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_16 3
  226. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_32 4
  227. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_64 5
  228. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_128 6
  229. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_256 7
  230. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_MASK (0x7 << 28)
  231. #define SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_SHIFT 28
  232. #define SD_DWC_FIFO_THRESHOLD_RECEIVE_WATERMARK_MASK (0xFFF << 16)
  233. #define SD_DWC_FIFO_THRESHOLD_RECEIVE_WATERMARK_SHIFT 16
  234. #define SD_DWC_FIFO_THRESHOLD_TRANSMIT_WATERMARK_MASK (0xFFF << 0)
  235. #define SD_DWC_FIFO_THRESHOLD_TRANSMIT_WATERMARK_SHIFT 0
  236. #define SD_DWC_FIFO_THRESHOLD_DEFAULT \
  237. ((SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_16 << \
  238. SD_DWC_FIFO_THRESHOLD_DMA_MULTIPLE_TRANSACTION_SIZE_SHIFT) | \
  239. ((((SD_DWC_FIFO_DEPTH / 2) - 1) << \
  240. SD_DWC_FIFO_THRESHOLD_RECEIVE_WATERMARK_SHIFT) & \
  241. SD_DWC_FIFO_THRESHOLD_RECEIVE_WATERMARK_MASK) | \
  242. (((SD_DWC_FIFO_DEPTH / 2) << \
  243. SD_DWC_FIFO_THRESHOLD_TRANSMIT_WATERMARK_SHIFT) & \
  244. SD_DWC_FIFO_THRESHOLD_TRANSMIT_WATERMARK_MASK))
  245. #define SD_DWC_FIFO_DEPTH 0x100
  246. //
  247. // Define the SD UHS register bits.
  248. //
  249. #define SD_DWC_UHS_DDR_MODE (1 << 16)
  250. #define SD_DWC_UHS_VOLTAGE_MASK (1 << 0)
  251. #define SD_DWC_UHS_VOLTAGE_3V3 (0 << 0)
  252. #define SD_DWC_UHS_VOLTAGE_1V8 (1 << 0)
  253. //
  254. // Define the SD reset register bits.
  255. //
  256. #define SD_DWC_RESET_ENABLE (1 << 0)
  257. //
  258. // Define the SD bus mode register bits.
  259. //
  260. #define SD_DWC_BUS_MODE_BURST_LENGTH_1 0
  261. #define SD_DWC_BUS_MODE_BURST_LENGTH_4 1
  262. #define SD_DWC_BUS_MODE_BURST_LENGTH_8 2
  263. #define SD_DWC_BUS_MODE_BURST_LENGTH_16 3
  264. #define SD_DWC_BUS_MODE_BURST_LENGTH_32 4
  265. #define SD_DWC_BUS_MODE_BURST_LENGTH_64 5
  266. #define SD_DWC_BUS_MODE_BURST_LENGTH_128 6
  267. #define SD_DWC_BUS_MODE_BURST_LENGTH_256 7
  268. #define SD_DWC_BUS_MODE_BURST_LENGTH_MASK (0x7 << 8)
  269. #define SD_DWC_BUS_MODE_BURST_LENGTH_SHIFT 8
  270. #define SD_DWC_BUS_MODE_IDMAC_ENABLE (1 << 7)
  271. #define SD_DWC_BUS_MODE_DESCRIPTOR_SKIP_LENGTH_MASK (0x1F << 2)
  272. #define SD_DWC_BUS_MODE_DESCRIPTOR_SKIP_LENGTH_SHIFT 2
  273. #define SD_DWC_BUS_MODE_FIXED_BURST (1 << 1)
  274. #define SD_DWC_BUS_MODE_INTERNAL_DMA_RESET (1 << 0)
  275. //
  276. // ------------------------------------------------------ Data Type Definitions
  277. //
  278. typedef enum _SD_DWC_REGISTER {
  279. SdDwcControl = 0x000,
  280. SdDwcPower = 0x004,
  281. SdDwcClockDivider = 0x008,
  282. SdDwcClockSource = 0x00C,
  283. SdDwcClockEnable = 0x010,
  284. SdDwcTimeout = 0x014,
  285. SdDwcCardType = 0x018,
  286. SdDwcBlockSize = 0x01C,
  287. SdDwcByteCount = 0x020,
  288. SdDwcInterruptMask = 0x024,
  289. SdDwcCommandArgument = 0x028,
  290. SdDwcCommand = 0x02C,
  291. SdDwcResponse0 = 0x030,
  292. SdDwcResponse1 = 0x034,
  293. SdDwcResponse2 = 0x038,
  294. SdDwcResponse3 = 0x03C,
  295. SdDwcMaskedInterruptStatus = 0x040,
  296. SdDwcInterruptStatus = 0x044,
  297. SdDwcStatus = 0x048,
  298. SdDwcFifoThreshold = 0x04C,
  299. SdDwcCardDetect = 0x050,
  300. SdDwcWriteProtect = 0x054,
  301. SdDwcTransferredCiuByteCount = 0x058,
  302. SdDwcTransferredBiuByteCount = 0x05C,
  303. SdDwcUhs = 0x074,
  304. SdDwcResetN = 0x078,
  305. SdDwcBusMode = 0x080,
  306. SdDwcDescriptorBaseAddress = 0x088,
  307. SdDwcFifoBase = 0x200,
  308. } SD_DWC_REGISTER, *PSD_DWC_REGISTER;
  309. /*++
  310. Structure Description:
  311. This structure defines the initialization parameters passed upon creation
  312. of a new DesignWare SD controller.
  313. Members:
  314. ControllerBase - Stores a pointer to the base address of the host
  315. controller registers.
  316. Voltages - Stores a bitmask of supported voltages. See SD_VOLTAGE_*
  317. definitions.
  318. FundamentalClock - Stores the fundamental clock speed in Hertz.
  319. HostCapabilities - Stores the host controller capability bits See SD_MODE_*
  320. definitions.
  321. OverrideFunctionTable - Stores an optional pointer to a set of functions
  322. for which the instantiator would like to override the default
  323. DesignWare behavior. If these are NULL, the default DesignWare SD
  324. functions are used.
  325. OverrideContext - Stores a pointer passed to the override functions.
  326. --*/
  327. typedef struct _EFI_SD_DWC_INITIALIZATION_BLOCK {
  328. VOID *ControllerBase;
  329. UINT32 Voltages;
  330. UINT32 FundamentalClock;
  331. UINT32 HostCapabilities;
  332. PSD_FUNCTION_TABLE OverrideFunctionTable;
  333. VOID *OverrideContext;
  334. } EFI_SD_DWC_INITIALIZATION_BLOCK, *PEFI_SD_DWC_INITIALIZATION_BLOCK;
  335. /*++
  336. Structure Description:
  337. This structure defines the context for a DesignWare SD/MMC controller
  338. instance.
  339. Members:
  340. ControllerBase - Stores a pointer to the base address of the host
  341. controller registers.
  342. SdController - Stores a pointer to the controller for the SD/MMC library
  343. instance.
  344. Voltages - Stores a bitmask of supported voltages.
  345. HostCapabilities - Stores the host controller capability bits.
  346. FundamentalClock - Stores the fundamental clock speed in Hertz.
  347. OverrideFunctionTable - Stores a set of functions for which the
  348. instantiator would like to override the default DesignWare behavior. If
  349. these are NULL, the default DesignWare SD functions are used.
  350. OverrideContext - Stores a pointer passed to the override functions.
  351. --*/
  352. typedef struct _EFI_SD_DWC_CONTROLLER {
  353. VOID *ControllerBase;
  354. PEFI_SD_CONTROLLER SdController;
  355. UINT32 Voltages;
  356. UINT32 HostCapabilities;
  357. UINT32 FundamentalClock;
  358. SD_FUNCTION_TABLE OverrideFunctionTable;
  359. VOID *OverrideContext;
  360. } EFI_SD_DWC_CONTROLLER, *PEFI_SD_DWC_CONTROLLER;
  361. //
  362. // -------------------------------------------------------------------- Globals
  363. //
  364. //
  365. // -------------------------------------------------------- Function Prototypes
  366. //
  367. PEFI_SD_DWC_CONTROLLER
  368. EfiSdDwcCreateController (
  369. PEFI_SD_DWC_INITIALIZATION_BLOCK Parameters
  370. );
  371. /*++
  372. Routine Description:
  373. This routine creates a new DesignWare SD controller object.
  374. Arguments:
  375. Parameters - Supplies a pointer to the parameters to use when creating the
  376. controller. This can be stack allocated, as the Rockchip SD device
  377. won't use this memory after this routine returns.
  378. Return Value:
  379. Returns a pointer to the controller structure on success.
  380. NULL on allocation failure or if a required parameter was not filled in.
  381. --*/
  382. VOID
  383. EfiSdDwcDestroyController (
  384. PEFI_SD_DWC_CONTROLLER Controller
  385. );
  386. /*++
  387. Routine Description:
  388. This routine destroys a DesignWare SD controller object.
  389. Arguments:
  390. Controller - Supplies a pointer to the controller to destroy.
  391. Return Value:
  392. None.
  393. --*/
  394. EFI_STATUS
  395. EfiSdDwcInitializeController (
  396. PEFI_SD_DWC_CONTROLLER Controller,
  397. BOOLEAN SoftReset
  398. );
  399. /*++
  400. Routine Description:
  401. This routine resets and initializes the DesignWare SD host controller.
  402. Arguments:
  403. Controller - Supplies a pointer to the controller to initialize.
  404. SoftReset - Supplies a boolean indicating whether or not to perform a soft
  405. reset on the controller.
  406. Return Value:
  407. Status code.
  408. --*/
  409. EFI_STATUS
  410. EfiSdDwcBlockIoPolled (
  411. PEFI_SD_DWC_CONTROLLER Controller,
  412. UINT64 BlockOffset,
  413. UINTN BlockCount,
  414. VOID *BufferVirtual,
  415. BOOLEAN Write
  416. );
  417. /*++
  418. Routine Description:
  419. This routine performs a block I/O read or write using the CPU and not
  420. DMA.
  421. Arguments:
  422. Controller - Supplies a pointer to the controller.
  423. BlockOffset - Supplies the logical block address of the I/O.
  424. BlockCount - Supplies the number of blocks to read or write.
  425. BufferVirtual - Supplies the virtual address of the I/O buffer.
  426. Write - Supplies a boolean indicating if this is a read operation (FALSE)
  427. or a write operation.
  428. Return Value:
  429. Status code.
  430. --*/
  431. EFI_STATUS
  432. EfiSdDwcGetMediaParameters (
  433. PEFI_SD_DWC_CONTROLLER Controller,
  434. UINT64 *BlockCount,
  435. UINT32 *BlockSize
  436. );
  437. /*++
  438. Routine Description:
  439. This routine returns information about the media card.
  440. Arguments:
  441. Controller - Supplies a pointer to the controller.
  442. BlockCount - Supplies a pointer where the number of blocks in the user
  443. area of the medium will be returned.
  444. BlockSize - Supplies a pointer where the block size of the medium will be
  445. returned.
  446. Return Value:
  447. EFI_SUCCESS on success.
  448. EFI_NO_MEDIA if there is no card in the slot.
  449. --*/
  450. EFI_STATUS
  451. EfiSdDwcSetClockSpeed (
  452. PEFI_SD_DWC_CONTROLLER DwcController,
  453. UINT32 ClockSpeed
  454. );
  455. /*++
  456. Routine Description:
  457. This routine sets the controller's clock speed.
  458. Arguments:
  459. DwcController - Supplies a pointer to this SD Rockchip controller.
  460. ClockSpeed - Supplies the desired clock speed in Hertz.
  461. Return Value:
  462. Status code.
  463. --*/