sdmmc.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*
  2. * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the
  12. * distribution.
  13. * 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef _DRIVER_CHIP_SDMMC_SDMMC_H_
  30. #define _DRIVER_CHIP_SDMMC_SDMMC_H_
  31. #include "card.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. #define SD_EXCLUSIVE_HOST
  36. /* SD commands type argument response */
  37. /* class 0 */
  38. /* This is basically the same command as for MMC with some quirks. */
  39. #define SD_SEND_RELATIVE_ADDR 3 /* bcr R6, ask the card to publish a new relative address */
  40. #define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7, sends Sd memory card interface condition, for sd 2.0 */
  41. #define SD_SWITCH_VOLTAGE 11 /* ac R1, switch to 1.8V bus signaling level */
  42. /* class 10 */
  43. #define SD_SWITCH 6 /* adtc [31:0] See below R1, checks swithcable function(mode 0),And swtich card function(mode 1), for sd 1.x */
  44. /* class 5 */
  45. #define SD_ERASE_WR_BLK_START 32 /* ac [31:0] data addr R1 */
  46. #define SD_ERASE_WR_BLK_END 33 /* ac [31:0] data addr R1 */
  47. /* Application commands */
  48. #define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */
  49. #define SD_APP_SD_STATUS 13 /* adtc R1 */
  50. #define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */
  51. #define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */
  52. #define SD_APP_SEND_SCR 51 /* adtc R1 */
  53. /* OCR bit definitions */
  54. #define SD_OCR_S18R (1 << 24) /* 1.8V switching request */
  55. #define SD_ROCR_S18A SD_OCR_S18R /* 1.8V switching accepted by card */
  56. #define SD_OCR_XPC (1 << 28) /* SDXC power control */
  57. #define SD_OCR_CCS (1 << 30) /* Card Capacity Status */
  58. /*
  59. * SD_SWITCH argument format:
  60. *
  61. * [31] Check (0) or switch (1)
  62. * [30:24] Reserved (0)
  63. * [23:20] Function group 6
  64. * [19:16] Function group 5
  65. * [15:12] Function group 4
  66. * [11:8] Function group 3
  67. * [7:4] Function group 2
  68. * [3:0] Function group 1
  69. */
  70. /*
  71. * SD_SEND_IF_COND argument format:
  72. *
  73. * [31:12] Reserved (0)
  74. * [11:8] Host Voltage Supply Flags
  75. * [7:0] Check Pattern (0xAA)
  76. */
  77. /*
  78. * SCR field definitions
  79. */
  80. #define SCR_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.01 */
  81. #define SCR_SPEC_VER_1 1 /* Implements system specification 1.10 */
  82. #define SCR_SPEC_VER_2 2 /* Implements system specification 2.00-3.0X */
  83. /*
  84. * SD bus widths
  85. */
  86. #define SD_BUS_WIDTH_1 0
  87. #define SD_BUS_WIDTH_4 2
  88. /*
  89. * SD_SWITCH mode
  90. */
  91. #define SD_SWITCH_CHECK 0
  92. #define SD_SWITCH_SET 1
  93. /*
  94. * SD_SWITCH function groups
  95. */
  96. #define SD_SWITCH_GRP_ACCESS 0
  97. /*
  98. * SD_SWITCH access modes
  99. */
  100. #define SD_SWITCH_ACCESS_DEF 0
  101. #define SD_SWITCH_ACCESS_HS 1
  102. /*command index*/
  103. /*basic commands*/
  104. #define MMC_GO_IDLE_STATE 0 /* bc,rest all cards to idle state */
  105. #define MMC_ALL_SEND_CID 2 /* bcr R2, asks any card to send CID numbers */
  106. #define MMC_SET_RELATIVE_ADDR 3 /* bcr,ask the card to publish a new relative address,R6 */
  107. #define MMC_SET_DSR 4 /* bc,program the DSR of all cards,for sd 2.0 */
  108. #define MMC_SELECT_CARD 7 /* ac [31:16] RCA R1, select or deselect one card */
  109. #define MMC_SEND_EXT_CSD 8 /* adtc,the card sends it's ex_csd as a block of data,R1 */
  110. #define MMC_SEND_CSD 9 /* ac [31:16] RCA R2, addressed card send CSD */
  111. #define MMC_SEND_CID 10 /* ac, addressed card send CID,R2 */
  112. #define MMC_READ_DATA_UNTIL_STOP 11 /* atdc,read data stream from catd until a STOP_TRANSMITISSION follows,R1 */
  113. #define MMC_STOP_TRANSMISSION 12 /* ac, termilate a multiple block read/write operation,R1b */
  114. #define MMC_SEND_STATUS 13 /* ac, addressed card send its status regesiter,R1 */
  115. #define MMC_GO_INACTIVE_STATE 15 /* ac, sets the card to inactive state */
  116. #define MMC_SEND_TUNING_PATTERN 19 /* adtc, send 64 bytes pattern for sdr50 and sdr104 mode */
  117. /* erase commands*/
  118. #define MMC_ERASE_WR_BLK_START 32 /* ac,sets the address of the first write bloock to be erased,R1 */
  119. #define MMC_ERASE_WR_BLK_END 33 /* ac,sets the address of the last write bloock to be erased,R1 */
  120. /*MMC private command*/
  121. #define MMC_SEND_OP_COND 1 /* bcr,Activates the card's initialization process,R3 */
  122. #define MMC_SWITCH 6 /* ac,switch the mode of operation of the selected card or modifies tge EXT_CSD,R1b */
  123. #define MMC_BUSTEST_R 14 /* adtc,a host reads the reversed testing data pattern from a card,R1 */
  124. #define MMC_BUSTEST_W 19 /* adtc,a host sends the bus teset data pattern to a card,R1 */
  125. /*sd io command*/
  126. #define IO_SEND_OP_COND 5 /* for SD IO.similar to ACMD41 for sd mem */
  127. #define IO_RW_DIRECT 52
  128. #define IO_RW_EXTENDED 53
  129. #define SD_IO_CMD54 54
  130. /* class 2 */
  131. #define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1, select a block length for all read/write cmds */
  132. #define MMC_READ_SINGLE_BLOCK 17 /* adtc [31:0] data addr R1, reads a block of the size seclected by SET_BLOCKLEN */
  133. #define MMC_READ_MULTIPLE_BLOCK 18 /* adtc [31:0] data addr R1, continuously send blocks of data until interrupted by a stop transmission commmad */
  134. #define MMC_SEND_TUNING_BLOCK 19 /* adtc R1 */
  135. #define MMC_SEND_TUNING_BLOCK_HS200 21 /* adtc R1 */
  136. /* class 3 */
  137. #define MMC_WRITE_DAT_UNTIL_STOP 20 /* adtc [31:0] data addr R1 */
  138. /* class 4 */
  139. #define MMC_SET_BLOCK_COUNT 23 /* adtc [31:0] data addr R1 */
  140. #define MMC_WRITE_SINGLE_BLOCK 24 /* adtc [31:0] data addr R1, writes a block of the size seclected by SET_BLOCKLEN */
  141. #define MMC_WRITE_MULTIPLE_BLOCK 25 /* adtc R1, continuously writes blocks of data until interrupted by a stop transmission commmad */
  142. #define MMC_PROGRAM_CID 26 /* adtc R1 */
  143. #define MMC_PROGRAM_CSD 27 /* adtc R1, program the programmable bits of CSD */
  144. /* class 6 */
  145. #define MMC_SET_WRITE_PROT 28 /* ac [31:0] data addr R1b, sets the write protect bit of the addressed group */
  146. #define MMC_CLR_WRITE_PROT 29 /* ac [31:0] data addr R1b, clears the write protect bit of the addressed group */
  147. #define MMC_SEND_WRITE_PROT 30 /* adtc [31:0] wpdata addr R1, ask the card to send status of the write protection bits */
  148. /* class 5 */
  149. #define MMC_ERASE_GROUP_START 35 /* ac [31:0] data addr R1 */
  150. #define MMC_ERASE_GROUP_END 36 /* ac [31:0] data addr R1 */
  151. #define MMC_ERASE 38 /* ac R1b, erase all selected write blocks */
  152. /* class 9 */
  153. #define MMC_FAST_IO 39 /* ac <Complex> R4, used to read or write 8 bit registers */
  154. #define MMC_GO_IRQ_STATE 40 /* bcr R5, sets the system info interrupt mode */
  155. /* class 7 */
  156. #define MMC_LOCK_UNLOCK 42 /* adtc R1b, lock or unlock sd card */
  157. /* class 8 */
  158. #define MMC_APP_CMD 55 /* ac [31:16] RCA R1, indicates the next cmd is an specific cmd */
  159. #define MMC_GEN_CMD 56 /* adtc [0] RD/WR R1, send or get a block of data */
  160. static inline uint32_t mmc_op_multi(uint32_t opcode)
  161. {
  162. return opcode == MMC_WRITE_MULTIPLE_BLOCK ||
  163. opcode == MMC_READ_MULTIPLE_BLOCK;
  164. }
  165. /*
  166. * MMC_SWITCH argument format:
  167. *
  168. * [31:26] Always 0
  169. * [25:24] Access Mode
  170. * [23:16] Location of target Byte in EXT_CSD
  171. * [15:08] Value Byte
  172. * [07:03] Always 0
  173. * [02:00] Command Set
  174. */
  175. /*
  176. MMC status in R1, for native mode (SPI bits are different)
  177. Type
  178. e : error bit
  179. s : status bit
  180. r : detected and set for the actual command response
  181. x : detected and set during command execution. the host must poll
  182. the card by sending status command in order to read these bits.
  183. Clear condition
  184. a : according to the card state
  185. b : always related to the previous command. Reception of
  186. a valid command will clear it (with a delay of one command)
  187. c : clear by read
  188. */
  189. #define R1_OUT_OF_RANGE (1 << 31) /* er, c */
  190. #define R1_ADDRESS_ERROR (1 << 30) /* erx, c */
  191. #define R1_BLOCK_LEN_ERROR (1 << 29) /* er, c */
  192. #define R1_ERASE_SEQ_ERROR (1 << 28) /* er, c */
  193. #define R1_ERASE_PARAM (1 << 27) /* ex, c */
  194. #define R1_WP_VIOLATION (1 << 26) /* erx, c */
  195. #define R1_CARD_IS_LOCKED (1 << 25) /* sx, a */
  196. #define R1_LOCK_UNLOCK_FAILED (1 << 24) /* erx, c */
  197. #define R1_COM_CRC_ERROR (1 << 23) /* er, b */
  198. #define R1_ILLEGAL_COMMAND (1 << 22) /* er, b */
  199. #define R1_CARD_ECC_FAILED (1 << 21) /* ex, c */
  200. #define R1_CC_ERROR (1 << 20) /* erx, c */
  201. #define R1_ERROR (1 << 19) /* erx, c */
  202. #define R1_UNDERRUN (1 << 18) /* ex, c */
  203. #define R1_OVERRUN (1 << 17) /* ex, c */
  204. #define R1_CID_CSD_OVERWRITE (1 << 16) /* erx, c, CID/CSD overwrite */
  205. #define R1_WP_ERASE_SKIP (1 << 15) /* sx, c */
  206. #define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */
  207. #define R1_ERASE_RESET (1 << 13) /* sr, c */
  208. #define R1_STATUS(x) (x & 0xFFFFE000)
  209. #define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */
  210. #define R1_READY_FOR_DATA (1 << 8) /* sx, a */
  211. #define R1_SWITCH_ERROR (1 << 7) /* sx, c */
  212. #define R1_APP_CMD (1 << 5) /* sr, c */
  213. #define R1_STATE_IDLE 0
  214. #define R1_STATE_READY 1
  215. #define R1_STATE_IDENT 2
  216. #define R1_STATE_STBY 3
  217. #define R1_STATE_TRAN 4
  218. #define R1_STATE_DATA 5
  219. #define R1_STATE_RCV 6
  220. #define R1_STATE_PRG 7
  221. #define R1_STATE_DIS 8
  222. /*ce-ata command*/
  223. #define CEATA_RW_MULTIPLE_REGISTER 60
  224. #define CEATA_RW_MULTIPLE_BLOCK 61
  225. /*application specific commands used by sd mem*/
  226. #define SET_BUS_WIDTH 6 /* ac,define the bus width(00 = 1bit, 10 = 4bit),R1 */
  227. #define SD_STATUS 13 /* adtc,send the sd card status,R1 */
  228. #define SEND_NUM_WR_BLOCKS 22 /* adtc,send the number of written write blocks,R1 */
  229. #define SET_WR_BLK_ERASE_CNT 23 /* ac,set the number of write blocks to be pre-erased before writing,R1 */
  230. #define SD_APP_OP_COND 41 /* bcr,asks the accessed card to send its OCR(operating conditon register) content,R3 */
  231. #define SET_CLR_CARD_DETECT 42 /* ac,connect or disconnect the pull up resistor of the card for card detect,R1 */
  232. #define SEND_SCR 51 /* adtc,reads the SCR(sd configure register),R1 */
  233. /* MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
  234. * R1 is the low order byte; R2 is the next highest byte, when present.
  235. */
  236. #define R1_SPI_IDLE (1 << 0)
  237. #define R1_SPI_ERASE_RESET (1 << 1)
  238. #define R1_SPI_ILLEGAL_COMMAND (1 << 2)
  239. #define R1_SPI_COM_CRC (1 << 3)
  240. #define R1_SPI_ERASE_SEQ (1 << 4)
  241. #define R1_SPI_ADDRESS (1 << 5)
  242. #define R1_SPI_PARAMETER (1 << 6)
  243. /* R1 bit 7 is always zero */
  244. #define R2_SPI_CARD_LOCKED (1 << 8)
  245. #define R2_SPI_WP_ERASE_SKIP (1 << 9) /* or lock/unlock fail */
  246. #define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP
  247. #define R2_SPI_ERROR (1 << 10)
  248. #define R2_SPI_CC_ERROR (1 << 11)
  249. #define R2_SPI_CARD_ECC_ERROR (1 << 12)
  250. #define R2_SPI_WP_VIOLATION (1 << 13)
  251. #define R2_SPI_ERASE_PARAM (1 << 14)
  252. #define R2_SPI_OUT_OF_RANGE (1 << 15) /* or CSD overwrite */
  253. #define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE
  254. #define CEATA_INDENTIFY_DEVICE 0xec
  255. #define CEATA_READ_DMA_EXT 0x25
  256. #define CEATA_WRITE_DMA_EXT 0x35
  257. #define CEATA_STANBY_IMMIDIATE 0xe0
  258. #define CEATA_FLUSH_CACHE_EXT 0Xea
  259. /*
  260. * OCR bits are mostly in host.h
  261. */
  262. #define MMC_CARD_BUSY 0x80000000 /* Card Power up status bit */
  263. /* Card Command Classes (CCC) */
  264. #define CCC_BASIC (1<<0) /* (0) Basic protocol functions */
  265. /* (CMD0,1,2,3,4,7,9,10,12,13,15) */
  266. /* (and for SPI, CMD58,59) */
  267. #define CCC_STREAM_READ (1<<1) /* (1) Stream read commands */
  268. /* (CMD11) */
  269. #define CCC_BLOCK_READ (1<<2) /* (2) Block read commands */
  270. /* (CMD16,17,18) */
  271. #define CCC_STREAM_WRITE (1<<3) /* (3) Stream write commands */
  272. /* (CMD20) */
  273. #define CCC_BLOCK_WRITE (1<<4) /* (4) Block write commands */
  274. /* (CMD16,24,25,26,27) */
  275. #define CCC_ERASE (1<<5) /* (5) Ability to erase blocks */
  276. /* (CMD32,33,34,35,36,37,38,39) */
  277. #define CCC_WRITE_PROT (1<<6) /* (6) Able to write protect blocks */
  278. /* (CMD28,29,30) */
  279. #define CCC_LOCK_CARD (1<<7) /* (7) Able to lock down card */
  280. /* (CMD16,CMD42) */
  281. #define CCC_APP_SPEC (1<<8) /* (8) Application specific */
  282. /* (CMD55,56,57,ACMD*) */
  283. #define CCC_IO_MODE (1<<9) /* (9) I/O mode */
  284. /* (CMD5,39,40,52,53) */
  285. #define CCC_SWITCH (1<<10) /* (10) High speed switch */
  286. /* (CMD6,34,35,36,37,50) */
  287. /* (11) Reserved */
  288. /* (CMD?) */
  289. /* CSD field definitions */
  290. #define MMC_CSD_STRUCT_VER_1_0 0 /* Valid for system specification 1.0 - 1.2 */
  291. #define MMC_CSD_STRUCT_VER_1_1 1 /* Valid for system specification 1.4 - 2.2 */
  292. #define MMC_CSD_STRUCT_VER_1_2 2 /* Valid for system specification 3.1 - 3.2 - 3.31 - 4.0 - 4.1 */
  293. #define MMC_CSD_STRUCT_EXT_CSD 3 /* Version is coded in CSD_STRUCTURE in EXT_CSD */
  294. #define MMC_CSD_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.2 */
  295. #define MMC_CSD_SPEC_VER_1 1 /* Implements system specification 1.4 */
  296. #define MMC_CSD_SPEC_VER_2 2 /* Implements system specification 2.0 - 2.2 */
  297. #define MMC_CSD_SPEC_VER_3 3 /* Implements system specification 3.1 - 3.2 - 3.31 */
  298. #define MMC_CSD_SPEC_VER_4 4 /* Implements system specification 4.0 - 4.1 */
  299. /* EXT_CSD fields */
  300. #define MMC_EXT_CSD_BOOT_BUS_COND 177 /* R/W */
  301. #define MMC_EXT_CSD_PART_CONF 179 /* R/W */
  302. #define MMC_EXT_CSD_BUS_WIDTH 183 /* R/W */
  303. #define MMC_EXT_CSD_HS_TIMING 185 /* R/W */
  304. #define MMC_EXT_CSD_CARD_TYPE 196 /* RO */
  305. #define MMC_EXT_CSD_REV 192 /* RO */
  306. #define MMC_EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
  307. /* EXT_CSD field definitions */
  308. #define MMC_EXT_CSD_CMD_SET_NORMAL (1<<0)
  309. #define MMC_EXT_CSD_CMD_SET_SECURE (1<<1)
  310. #define MMC_EXT_CSD_CMD_SET_CPSECURE (1<<2)
  311. #define MMC_EXT_CSD_CARD_TYPE_26 (1<<0) /* Card can run at 26MHz */
  312. #define MMC_EXT_CSD_CARD_TYPE_52 (1<<1) /* Card can run at 52MHz */
  313. #define MMC_EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */
  314. #define MMC_EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
  315. #define MMC_EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
  316. #define MMC_EXT_CSD_BUS_WIDTH_4_DDR 5 /* Card is in 4 bit mode in DDR mode */
  317. #define MMC_EXT_CSD_BUS_WIDTH_8_DDR 6 /* Card is in 8 bit mode in DDR mode */
  318. /* MMC_SWITCH access modes */
  319. #define MMC_SWITCH_MODE_CMD_SET 0x00 /* Change the command set */
  320. #define MMC_SWITCH_MODE_SET_BITS 0x01 /* Set bits which are 1 in value */
  321. #define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits which are 1 in value */
  322. #define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */
  323. /* MMC_SWITCH boot modes */
  324. #define MMC_SWITCH_MMCPART_NOAVAILABLE (0xff)
  325. #define MMC_SWITCH_PART_ACCESS_MASK (0x7)
  326. #define MMC_SWITCH_PART_SUPPORT (0x1)
  327. #define MMC_SWITCH_PART_BOOT_PART_MASK (0x7 << 3)
  328. #define MMC_SWITCH_PART_BOOT_PART_NONE (0x0)
  329. #define MMC_SWITCH_PART_BOOT_PART_1 (0x1)
  330. #define MMC_SWITCH_PART_BOOT_PART_2 (0x2)
  331. #define MMC_SWITCH_PART_BOOT_USER (0x7)
  332. #define MMC_SWITCH_PART_BOOT_ACK_MASK (0x1 << 6)
  333. #define MMC_SWITCH_PART_BOOT_ACK_ENB (0x1)
  334. /* MMC_SWITCH boot condition */
  335. #define MMC_SWITCH_MMCBOOT_BUS_NOAVAILABLE (0xff)
  336. #define MMC_SWITCH_BOOT_MODE_MASK (0x3 << 3)
  337. #define MMC_SWITCH_BOOT_SDR_NORMAL (0x0)
  338. #define MMC_SWITCH_BOOT_SDR_HS (0x1)
  339. #define MMC_SWITCH_BOOT_DDR (0x2)
  340. #define MMC_SWITCH_BOOT_RST_BUS_COND_MASK (0x1 << 2)
  341. #define MMC_SWITCH_BOOT_RST_BUS_COND (0x0)
  342. #define MMC_SWITCH_BOOT_RETAIN_BUS_COND (0x1)
  343. #define MMC_SWITCH_BOOT_BUS_WIDTH_MASK (0x3 << 0)
  344. #define MMC_SWITCH_BOOT_BUS_SDRx1_DDRx4 (0x0)
  345. #define MMC_SWITCH_BOOT_BUS_SDRx4_DDRx4 (0x1)
  346. #define MMC_SWITCH_BOOT_BUS_SDRx8_DDRx8 (0x2)
  347. /* SD_SWITCH function groups */
  348. #define SD_SWITCH_GRP_ACCESS_MODE 0
  349. #define SD_SWITCH_GRP_CMD_SYSTEM 1
  350. #define SD_SWITCH_GRP_DRV_STRENGTH 2
  351. #define SD_SWITCH_GRP_CUR_LIMIT 3
  352. /* SD_SWITCH access modes */
  353. #define SD_SWITCH_ACCESS_DEF_SDR12 0
  354. #define SD_SWITCH_ACCESS_HS_SDR25 1
  355. #define SD_SWITCH_ACCESS_SDR50 2
  356. #define SD_SWITCH_ACCESS_SDR104 3
  357. #define SD_SWITCH_ACCESS_DDR50 4
  358. /* SD_SWITCH cmd system */
  359. #define SD_SWITCH_CMDSYS_DEF 0
  360. #define SD_SWITCH_CMDSYS_EC 1
  361. #define SD_SWITCH_CMDSYS_OTP 3
  362. #define SD_SWITCH_CMDSYS_ASSD 4
  363. #define SD_SWITCH_CMDSYS_ESD 0xc
  364. /* SD_SWITCH driver strength */
  365. #define SD_SWITCH_DRVSTR_DEF_TB 0
  366. #define SD_SWITCH_DRVSTR_DEF_TA 1
  367. #define SD_SWITCH_DRVSTR_DEF_TC 2
  368. #define SD_SWITCH_DRVSTR_DEF_TD 3
  369. /* SD_SWITCH current limit */
  370. #define SD_SWITCH_CURLMT_DEF_200MA 0
  371. #define SD_SWITCH_CURLMT_DEF_400MA 1
  372. #define SD_SWITCH_CURLMT_DEF_600MA 2
  373. #define SD_SWITCH_CURLMT_DEF_800MA 3
  374. /**
  375. * @brief read SD card.
  376. * @param card:
  377. * @arg card->card handler.
  378. * @param buf:
  379. * @arg buf->for store readed data.
  380. * @param sblk:
  381. * @arg sblk->start block num.
  382. * @param nblk:
  383. * @arg nblk->number of blocks.
  384. * @retval 0 if success or other if failed.
  385. */
  386. extern int32_t mmc_block_read(struct mmc_card *card, uint8_t *buf, uint64_t sblk, uint32_t nblk);
  387. /**
  388. * @brief write SD card.
  389. * @param card:
  390. * @arg card->card handler.
  391. * @param buf:
  392. * @arg buf->data will be write.
  393. * @param sblk:
  394. * @arg sblk->start block num.
  395. * @param nblk:
  396. * @arg nblk->number of blocks.
  397. * @retval 0 if success or other if failed.
  398. */
  399. extern int32_t mmc_block_write(struct mmc_card *card, const uint8_t *buf, uint64_t sblk, uint32_t nblk);
  400. /**
  401. * @brief scan or rescan SD card.
  402. * @param card:
  403. * @arg card->card handler.
  404. * @param sdc_id:
  405. * @arg sdc_id->SDC ID which card on.
  406. * @retval 0 if success or other if failed.
  407. */
  408. extern int32_t mmc_rescan(struct mmc_card *card, uint32_t sdc_id);
  409. /**
  410. * @brief deinit SD card.
  411. * @param card:
  412. * @arg card->card handler.
  413. * @retval 0 if success or other if failed.
  414. */
  415. extern int32_t mmc_card_deinit(struct mmc_card *card);
  416. /**
  417. * @brief malloc for card_info.
  418. * @param card_id:
  419. * @arg card ID.
  420. * @retval 0 if success or other if failed.
  421. */
  422. extern int32_t mmc_card_create(uint8_t card_id, SDCard_InitTypeDef *param);
  423. /**
  424. * @brief free for card_info.
  425. * @param card_id:
  426. * @arg card ID.
  427. * @retval 0 if success or other if failed.
  428. */
  429. extern int32_t mmc_card_delete(uint8_t card_id);
  430. /**
  431. * @brief get pointer of mmc_card.
  432. * @param card_id:
  433. * @arg card ID.
  434. * @retval pointer of mmc_card if success or NULL if failed.
  435. */
  436. extern struct mmc_card* mmc_card_open(uint8_t card_id);
  437. /**
  438. * @brief close mmc_card.
  439. * @param card_id:
  440. * @arg card ID.
  441. * @retval 0 if success or other if failed.
  442. */
  443. extern int32_t mmc_card_close(uint8_t card_id);
  444. extern struct mmc_card_info* mmc_card_save(uint8_t card_id);
  445. extern int32_t mmc_card_restore(struct mmc_card_info *s_card_info);
  446. #ifdef __cplusplus
  447. }
  448. #endif
  449. #endif /* _DRIVER_CHIP_SDMMC_SDMMC_H_ */