_sdhost.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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 _ROM_DRIVER_CHIP_SDMMC__SDHOST_H_
  30. #define _ROM_DRIVER_CHIP_SDMMC__SDHOST_H_
  31. #include "platform_mmc.h"
  32. #include "hal_sdhost.h"
  33. #include <hal_gpio.h>
  34. #include "_sdhost.h"
  35. #define CONFIG_SDC_OS_USED
  36. #define __CONFIG_ARCH_APP_CORE
  37. #ifdef SD_SUPPORT_VERSION3
  38. #define CONFIG_SDC_SUPPORT_1V8 /* board not support */
  39. #endif
  40. #ifdef SD_SUPPORT_WRITEPROTECT
  41. #define CONFIG_SDC_READONLY_USED /* check readonly */
  42. #endif
  43. #ifdef CONFIG_SDC_OS_USED
  44. #include "os_semaphore.h"
  45. #include "os_mutex.h"
  46. #ifdef __CONFIG_ARCH_APP_CORE
  47. #include "os_timer.h"
  48. #endif
  49. #define SDC_Semaphore OS_Semaphore_t
  50. #define SDC_Mutex OS_Mutex_t
  51. #ifdef __CONFIG_ARCH_APP_CORE
  52. #define SDC_Timer OS_Timer_t
  53. #endif
  54. #endif
  55. #ifdef CONFIG_PM
  56. #define CONFIG_SD_PM
  57. #endif
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. #define CONFIG_SDC_EXCLUSIVE_HOST
  62. /*
  63. * the max length of buffer which IDMA description supported is 8192,
  64. * transport data by several IDMA descriptions if data lenght more than 8192,
  65. * and the max number IDMA description support is 1024.
  66. * which meas the mas length transport data is 1024 * 8192 = 8MB in a signal transfer.
  67. */
  68. #ifdef __CONFIG_ARCH_APP_CORE
  69. #define SDXC_MAX_TRANS_LEN (1 << 18 << 4) /* max len is 4M */
  70. #else
  71. #define SDXC_MAX_TRANS_LEN (1 << 14 << 8) /* max len is 4M */
  72. #endif
  73. #define SDXC_DES_NUM_SHIFT (13)
  74. #define SDXC_DES_BUFFER_MAX_LEN (1 << SDXC_DES_NUM_SHIFT) /* 8192 == 1<<13; */
  75. #define SDXC_MAX_DES_NUM (SDXC_MAX_TRANS_LEN >> SDXC_DES_NUM_SHIFT) /* 2 is the least */
  76. #define SDXC_DES_MODE (0) /* 0-chain mode, 1-fix length skip */
  77. struct scatterlist {
  78. void *buffer;
  79. uint32_t len;
  80. };
  81. /* IDMC structure */
  82. typedef struct {
  83. uint32_t config;
  84. #define SDXC_IDMAC_DES0_DIC BIT(1) /* disable interrupt on completion */
  85. #define SDXC_IDMAC_DES0_LD BIT(2) /* 1-this data buffer is the last buffer */
  86. #define SDXC_IDMAC_DES0_FD BIT(3) /* 1-data buffer is the first buffer, 0-data buffer contained in the next descriptor is the first data buffer */
  87. #define SDXC_IDMAC_DES0_CH BIT(4) /* 1-the 2nd address in the descriptor is the next descriptor address */
  88. #define SDXC_IDMAC_DES0_ER BIT(5) /* 1-last descriptor flag when using dual data buffer in descriptor */
  89. #define SDXC_IDMAC_DES0_CES BIT(30) /* transfer error flag */
  90. #define SDXC_IDMAC_DES0_OWN BIT(31) /* des owner:1-idma owns it, 0-host owns it */
  91. uint32_t data_buf1_sz :16,
  92. data_buf2_sz :16;
  93. uint32_t buf_addr_ptr1;
  94. uint32_t buf_addr_ptr2;
  95. } smc_idma_des;
  96. #ifdef SDC_DES_ADDR_SHIFT
  97. #define SDXC_IDMAC_DES_ADDR(a) ((a)>>SDC_DES_ADDR_SHIFT)
  98. #else
  99. #define SDXC_IDMAC_DES_ADDR(a) ((a)>>0)
  100. #endif
  101. typedef enum
  102. {
  103. SDC_STATE_RESET = 0x00, /* Peripheral is not yet Initialized */
  104. SDC_STATE_READY = 0x02, /* Peripheral Initialized and ready for use */
  105. SDC_STATE_BUSY = 0x04, /* An internal process is ongoing */
  106. SDC_STATE_ERROR = 0x08 /* Error */
  107. } SDC_StateTypeDef;
  108. struct __mci_ctrl_regs {
  109. uint32_t gctrl;
  110. uint32_t clkc;
  111. uint32_t timeout;
  112. uint32_t buswid;
  113. uint32_t waterlvl;
  114. uint32_t funcsel;
  115. uint32_t idmacc;
  116. };
  117. struct mmc_bus_ops {
  118. int (*suspend)(struct mmc_host *);
  119. int (*resume)(struct mmc_host *);
  120. };
  121. struct mmc_host {
  122. volatile void *reg_base; /* Mapped address */
  123. uint8_t sdc_id;
  124. uint8_t pin_ref;
  125. uint16_t ref;
  126. uint16_t debug_mask;
  127. uint16_t dma_use;
  128. struct mmc_card *card;
  129. #ifdef CONFIG_SDC_SUPPORT_1V8
  130. uint32_t voltage;
  131. #define SDC_WOLTAGE_3V3 (0)
  132. #define SDC_WOLTAGE_1V8 (1)
  133. #define SDC_WOLTAGE_1V2 (2)
  134. #define SDC_WOLTAGE_OFF (3)
  135. #define SDC_WOLTAGE_ON (4)
  136. uint32_t voltage_switching;
  137. #endif
  138. volatile uint32_t present;
  139. uint16_t power_on;
  140. uint16_t suspend;
  141. uint32_t int_err; /* for Interrupt Controller */
  142. uint32_t int_use; /* Control */
  143. uint32_t int_sum; /* interrupt summary */
  144. uint16_t trans_done;
  145. uint16_t dma_done;
  146. uint32_t buswidth; /* current card bus width */
  147. uint32_t blkcnt;
  148. /* NOTE: define idma_des here for aligned8! */
  149. smc_idma_des *idma_des;
  150. smc_idma_des *dma_hdle;
  151. int8_t *align_dma_buf;
  152. /* host specific block data */
  153. uint32_t max_seg_size; /* see blk_queue_max_segment_size */
  154. uint32_t max_segs; /* see blk_queue_max_segments */
  155. uint32_t max_req_size; /* maximum number of bytes in one req */
  156. uint32_t max_blk_size; /* maximum size of one mmc block */
  157. uint32_t max_blk_count; /* maximum number of blocks in one req */
  158. uint32_t ocr_avail;
  159. #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
  160. #define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */
  161. #define MMC_VDD_21_22 0x00000200 /* VDD voltage 2.1 ~ 2.2 */
  162. #define MMC_VDD_22_23 0x00000400 /* VDD voltage 2.2 ~ 2.3 */
  163. #define MMC_VDD_23_24 0x00000800 /* VDD voltage 2.3 ~ 2.4 */
  164. #define MMC_VDD_24_25 0x00001000 /* VDD voltage 2.4 ~ 2.5 */
  165. #define MMC_VDD_25_26 0x00002000 /* VDD voltage 2.5 ~ 2.6 */
  166. #define MMC_VDD_26_27 0x00004000 /* VDD voltage 2.6 ~ 2.7 */
  167. #define MMC_VDD_27_28 0x00008000 /* VDD voltage 2.7 ~ 2.8 */
  168. #define MMC_VDD_28_29 0x00010000 /* VDD voltage 2.8 ~ 2.9 */
  169. #define MMC_VDD_29_30 0x00020000 /* VDD voltage 2.9 ~ 3.0 */
  170. #define MMC_VDD_30_31 0x00040000 /* VDD voltage 3.0 ~ 3.1 */
  171. #define MMC_VDD_31_32 0x00080000 /* VDD voltage 3.1 ~ 3.2 */
  172. #define MMC_VDD_32_33 0x00100000 /* VDD voltage 3.2 ~ 3.3 */
  173. #define MMC_VDD_33_34 0x00200000 /* VDD voltage 3.3 ~ 3.4 */
  174. #define MMC_VDD_34_35 0x00400000 /* VDD voltage 3.4 ~ 3.5 */
  175. #define MMC_VDD_35_36 0x00800000 /* VDD voltage 3.5 ~ 3.6 */
  176. uint32_t caps; /* Host capabilities */
  177. #define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */
  178. #define MMC_CAP_MMC_HIGHSPEED (1 << 1) /* Can do MMC high-speed timing */
  179. #define MMC_CAP_SD_HIGHSPEED (1 << 2) /* Can do SD high-speed timing */
  180. #define MMC_CAP_SDIO_IRQ (1 << 3) /* Can signal pending SDIO IRQs */
  181. #define MMC_CAP_SPI (1 << 4) /* Talks only SPI protocols */
  182. #define MMC_CAP_NEEDS_POLL (1 << 5) /* Needs polling for card-detection */
  183. #define MMC_CAP_8_BIT_DATA (1 << 6) /* Can the host do 8 bit transfers */
  184. #define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */
  185. #define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */
  186. #define MMC_CAP_ERASE (1 << 10) /* Allow erase/trim commands */
  187. #define MMC_CAP_1_8V_DDR (1 << 11) /* can support */
  188. /* DDR mode at 1.8V */
  189. #define MMC_CAP_1_2V_DDR (1 << 12) /* can support */
  190. /* DDR mode at 1.2V */
  191. #define MMC_CAP_POWER_OFF_CARD (1 << 13) /* Can power off after boot */
  192. #define MMC_CAP_BUS_WIDTH_TEST (1 << 14) /* CMD14/CMD19 bus width ok */
  193. #define MMC_CAP_UHS_SDR12 (1 << 15) /* Host supports UHS SDR12 mode */
  194. #define MMC_CAP_UHS_SDR25 (1 << 16) /* Host supports UHS SDR25 mode */
  195. #define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50 mode */
  196. #define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104 mode */
  197. #define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50 mode */
  198. #define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports >150mA current at 3.3V */
  199. #define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports >150mA current at 3.0V */
  200. #define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports >150mA current at 1.8V */
  201. #define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */
  202. #define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */
  203. #define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */
  204. #define MMC_CAP_MAX_CURRENT_200 (1 << 26) /* Host max current limit is 200mA */
  205. #define MMC_CAP_MAX_CURRENT_400 (1 << 27) /* Host max current limit is 400mA */
  206. #define MMC_CAP_MAX_CURRENT_600 (1 << 28) /* Host max current limit is 600mA */
  207. #define MMC_CAP_MAX_CURRENT_800 (1 << 29) /* Host max current limit is 800mA */
  208. #define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */
  209. #define MMC_CAP_HW_RESET (1 << 31) /* Hardware reset */
  210. uint32_t caps2; /* More host capabilities */
  211. #define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */
  212. #define MMC_CAP2_CACHE_CTRL (1 << 1) /* Allow cache control */
  213. #define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */
  214. #define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */
  215. #define MMC_CAP2_NO_SLEEP_CMD (1 << 4) /* Don't allow sleep command */
  216. #define MMC_CAP2_HS200_1_8V_SDR (1 << 5) /* can support */
  217. #define MMC_CAP2_HS200_1_2V_SDR (1 << 6) /* can support */
  218. #define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | MMC_CAP2_HS200_1_2V_SDR)
  219. #define MMC_CAP2_BROKEN_VOLTAGE (1 << 7) /* Use the broken voltage */
  220. #define MMC_CAP2_DETECT_ON_ERR (1 << 8) /* On I/O err check card removal */
  221. #define MMC_CAP2_HC_ERASE_SZ (1 << 9) /* High-capacity erase size */
  222. #define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17)
  223. #ifdef CONFIG_SDC_OS_USED
  224. SDC_Semaphore lock;
  225. SDC_Mutex thread_lock;
  226. #ifdef CONFIG_DETECT_CARD
  227. SDC_Timer cd_timer;
  228. #endif
  229. #ifdef CONFIG_SDC_EXCLUSIVE_HOST
  230. SDC_Semaphore exclusive_lock; /* lock for claim and bus ops */
  231. #endif
  232. #endif
  233. //uint8_t bus_width; /* data bus width */
  234. uint32_t clk;
  235. #define MMC_BUS_WIDTH_1 0
  236. #define MMC_BUS_WIDTH_4 2
  237. #define MMC_BUS_WIDTH_8 3
  238. struct mmc_request *mrq;
  239. #define SDC_WAIT_NONE BIT(0)
  240. #define SDC_WAIT_CMD_DONE BIT(1)
  241. #define SDC_WAIT_DATA_OVER BIT(2)
  242. #define SDC_WAIT_AUTOCMD_DONE BIT(3)
  243. #define SDC_WAIT_IDMA_DONE BIT(4)
  244. #define SDC_WAIT_IDMA_ERR BIT(5)
  245. #define SDC_WAIT_ERROR BIT(6)
  246. #define SDC_WAIT_RXDATA_OVER (SDC_WAIT_DATA_OVER|SDC_WAIT_IDMA_DONE)
  247. #define SDC_WAIT_RXAUTOCMD_DONE (SDC_WAIT_AUTOCMD_DONE|SDC_WAIT_IDMA_DONE)
  248. #define SDC_WAIT_SWITCH1V8 BIT(7)
  249. #define SDC_WAIT_FINALIZE BIT(8)
  250. volatile uint32_t smc_cmd;
  251. uint32_t wait;
  252. //#ifdef CONFIG_SDIO_IRQ_SUPPORT
  253. uint32_t sdio_int;
  254. unsigned int sdio_irqs;
  255. OS_Thread_t sdio_irq_thread;
  256. uint32_t sdio_irq_pending;
  257. //atomic_t sdio_irq_thread_abort;
  258. uint32_t sdio_irq_thread_abort;
  259. uint32_t sdio_irq_thread_stop;
  260. SDC_Semaphore sdio_irq_stop_wait;
  261. SDC_Semaphore sdio_irq_signal;
  262. //#endif
  263. #ifdef CONFIG_SD_PM
  264. struct __mci_ctrl_regs regs_back;
  265. const struct mmc_bus_ops *bus_ops; /* current bus driver */
  266. uint32_t pm_flags; /* requested pm features */
  267. uint32_t pm_caps; /* supported pm features */
  268. #endif
  269. #ifdef __CONFIG_ARCH_APP_CORE
  270. SDC_InitTypeDef param;
  271. GPIO_Port cd_port;
  272. GPIO_Pin cd_pin;
  273. uint32_t cd_irq;
  274. gpio_pin_t cd_gpio_pin;
  275. irq_handler_t cd_gpio_isr;
  276. uint16_t cd_delay; /* delay interval (in ms) to wait power stable */
  277. uint8_t wait_voltage_stable; /* card voltage stable*/
  278. GPIO_PinState cd_pin_present_val;
  279. #endif
  280. #ifdef CONFIG_SDC_READONLY_USED
  281. uint32_t read_only;
  282. GPIO_PinMuxParam ro_gpio;
  283. #endif
  284. SDC_StateTypeDef State;
  285. uint32_t sdio_irq_mask;
  286. #ifdef SD_PERF_TRACE_ON
  287. uint64_t start_sdio_irq_times_ns;
  288. uint64_t sdio_irq_count;
  289. uint64_t sdio_irq_times_ns;
  290. uint64_t start_times_us;
  291. uint64_t rbytes;
  292. uint64_t wbytes;
  293. uint64_t rcount;
  294. uint64_t rtimes_us;
  295. uint64_t wtimes_us;
  296. uint64_t wcount;
  297. #endif
  298. };
  299. #define SDC_MAX_CPU_TRANS_LEN (4)
  300. //#define SDC_MAX_CPU_TRANS_LEN (64)
  301. //#define SMC_LOW_POWER_MODE 0 /* 1--Close Clock when Idle, 0--Clock always on */
  302. /* IDMA control */
  303. #define IDMAC_DES_MODE 0 /* 0-chain mode, 1-fix skip length */
  304. #define SMC_RX_WLEVEL 7
  305. #define SMC_TX_WLEVEL 248
  306. #define BURST_SIZE 2
  307. #define IDMA_MAX_TBKNUM_ONETIME 16
  308. /* registers define */
  309. //#define SMC0_BASE (SDC0_BASE)
  310. //#if defined(__CONFIG_CHIP_XR871_PLUS)
  311. //#define SMC1_BASE (0xA0001000)
  312. //#elif (__CONFIG_CHIP_ARCH_VER == 2)
  313. //#define SMC1_BASE (SDC1_BASE)
  314. //#endif
  315. #define SDXC_REG_GCTRL (0x00) /* SMC Global Control Register */
  316. #define SDXC_REG_CLKCR (0x04) /* SMC Clock Control Register */
  317. #define SDXC_REG_TMOUT (0x08) /* SMC Time Out Register */
  318. #define SDXC_REG_WIDTH (0x0C) /* SMC Bus Width Register */
  319. #define SDXC_REG_BLKSZ (0x10) /* SMC Block Size Register */
  320. #define SDXC_REG_BCNTR (0x14) /* SMC Byte Count Register */
  321. #define SDXC_REG_CMDR (0x18) /* SMC Command Register */
  322. #define SDXC_REG_CARG (0x1C) /* SMC Argument Register */
  323. #define SDXC_REG_RESP0 (0x20) /* SMC Response Register 0 */
  324. #define SDXC_REG_RESP1 (0x24) /* SMC Response Register 1 */
  325. #define SDXC_REG_RESP2 (0x28) /* SMC Response Register 2 */
  326. #define SDXC_REG_RESP3 (0x2C) /* SMC Response Register 3 */
  327. #define SDXC_REG_IMASK (0x30) /* SMC Interrupt Mask Register */
  328. #define SDXC_REG_MISTA (0x34) /* SMC Masked Interrupt Status Register */
  329. #define SDXC_REG_RINTR (0x38) /* SMC Raw Interrupt Status Register */
  330. #define SDXC_REG_STAS (0x3C) /* SMC Status Register */
  331. #define SDXC_REG_FTRGL (0x40) /* SMC FIFO Threshold Watermark Register */
  332. #define SDXC_REG_FUNS (0x44) /* SMC Function Select Register */
  333. #define SDXC_REG_CBCR (0x48) /* SMC CIU Byte Count Register */
  334. #define SDXC_REG_BBCR (0x4C) /* SMC BIU Byte Count Register */
  335. #define SDXC_REG_DBGC (0x50) /* SMC Debug Enable Register */
  336. #define SDXC_REG_A12A (0x58) /* SMC auto command 12 argument */
  337. #define SDXC_REG_NTSR (0x5C) /* SMC NewTiming Set Register(RX TX) */
  338. #define SDXC_REG_SDEG (0x60) /* SMC NewTiming Set debg */
  339. #define SDXC_REG_HWST (0x78) /* SMC SMC hardware reset register */
  340. #define SDXC_REG_DMAC (0x80) /* SMC IDMAC Control Register */
  341. #define SDXC_REG_DLBA (0x84) /* SMC IDMAC Descriptor List Base Address Register */
  342. #define SDXC_REG_IDST (0x88) /* SMC IDMAC Status Register */
  343. #define SDXC_REG_IDIE (0x8C) /* SMC IDMAC Interrupt Enable Register */
  344. #define SDXC_REG_CHDA (0x90) /* SMC Current Host Descriptor Address Register */
  345. #define SDXC_REG_CBDA (0x94) /* SMC Current Buffer Descriptor Address Register */
  346. #define SDXC_REG_THLDC (0x100) /* SMC Threshold Control Register */
  347. #define SDXC_REG_DSBD (0x10C)
  348. #define SDXC_REG_RESP_CRC (0x110)
  349. #define SDXC_REG_DAT7_CRC (0x114)
  350. #define SDXC_REG_DAT6_CRC (0x118)
  351. #define SDXC_REG_DAT5_CRC (0x11C)
  352. #define SDXC_REG_DAT4_CRC (0x120)
  353. #define SDXC_REG_DAT3_CRC (0x124)
  354. #define SDXC_REG_DAT2_CRC (0x128)
  355. #define SDXC_REG_DAT1_CRC (0x12C)
  356. #define SDXC_REG_DAT0_CRC (0x130)
  357. #define SDXC_REG_CRC_STA (0x134)
  358. #define SDXC_REG_FIFO (0x200) /* SMC FIFO Access Address */
  359. #define SDXC_REG_FCTL (0x64) /* SMC FIFO Access Address */
  360. #define SDXC_REG_FCTL_OS (0x64) /* SMC FIFO Access Address */
  361. /* global control register */
  362. #define SDXC_SoftReset BIT(0 )
  363. #define SDXC_FIFOReset BIT(1 )
  364. #define SDXC_DMAReset BIT(2 )
  365. #define SDXC_HWReset (SDXC_SoftReset|SDXC_FIFOReset|SDXC_DMAReset)
  366. #define SDXC_INTEnb BIT(4 )
  367. #define SDXC_DMAEnb BIT(5 )
  368. #define SDXC_DebounceEnb BIT(8 )
  369. #define SDXC_DDR_MODE BIT(10)
  370. #define SDXC_MemAccessDone BIT(29)
  371. #define SDXC_AccessDoneDirect BIT(30)
  372. #define SDXC_ACCESS_BY_AHB BIT(31)
  373. #define SDXC_ACCESS_BY_DMA (0x0U << 31)
  374. /* Clock control */
  375. #define SDXC_CardClkOn (0x1U << 16)
  376. #define SDXC_LowPowerOn (0x1U << 17)
  377. #define SDXC_Mask_Data0 BIT(31)
  378. /* bus width */
  379. #define SDXC_WIDTH1 (0)
  380. #define SDXC_WIDTH4 (1)
  381. #define SDXC_WIDTH8 (2)
  382. /* Struct for SMC Commands */
  383. #define SDXC_CMD_OPCODE (0x3F ) /* 0x00000040 */
  384. #define SDXC_RspExp BIT(6 ) /* 0x00000080 */
  385. #define SDXC_LongRsp BIT(7 ) /* 0x00000100 */
  386. #define SDXC_CheckRspCRC BIT(8 ) /* 0x00000200 */
  387. #define SDXC_DataExp BIT(9 ) /* 0x00000000 */
  388. #define SDXC_Read (0x0U<<10 ) /* 0x00000400 */
  389. #define SDXC_Write BIT(10) /* 0x00000000 */
  390. #define SDXC_Blockmod (0x0U<<11 ) /* 0x00000800 */
  391. #define SDXC_Seqmod BIT(11) /* 0x00001000 */
  392. #define SDXC_SendAutoStop BIT(12) /* 0x00002000 */
  393. #define SDXC_WaitPreOver BIT(13) /* 0x00004000 */
  394. #define SDXC_StopAbortCMD BIT(14) /* 0x00008000 */
  395. #define SDXC_SendInitSeq BIT(15) /* 0x00200000 */
  396. #define SDXC_UPCLKOnly BIT(21) /* 0x00400000 */
  397. #define SDXC_RdCEATADev BIT(22) /* 0x00800000 */
  398. #define SDXC_CCSExp BIT(23) /* 0x01000000 */
  399. #define SDXC_EnbBoot BIT(24) /* 0x02000000 */
  400. #define SDXC_AltBootOpt BIT(25) /* 0x00000000 */
  401. #define SDXC_MandBootOpt (0x0U<<25) /* 0x04000000 */
  402. #define SDXC_BootACKExp BIT(26) /* 0x08000000 */
  403. #define SDXC_DisableBoot BIT(27) /* 0x10000000 */
  404. #define SDXC_VolSwitch BIT(28) /* 0x80000000 */
  405. #define SDXC_Start BIT(31)
  406. /* Struct for Intrrrupt Information */
  407. #define SDXC_RespErr BIT(1) /* 0x00000002 */
  408. #define SDXC_CmdDone BIT(2) /* 0x00000004 */
  409. #define SDXC_DataOver BIT(3) /* 0x00000008 */
  410. #define SDXC_TxDataReq BIT(4) /* 0x00000010 */
  411. #define SDXC_RxDataReq BIT(5) /* 0x00000020 */
  412. #define SDXC_RespCRCErr BIT(6) /* 0x00000040 */
  413. #define SDXC_DataCRCErr BIT(7) /* 0x00000080 */
  414. #define SDXC_RespTimeout BIT(8) /* 0x00000100 */
  415. #define SDXC_ACKRcv BIT(8) /* 0x00000100 */
  416. #define SDXC_DataTimeout BIT(9) /* 0x00000200 */
  417. #define SDXC_BootStart BIT(9) /* 0x00000200 */
  418. #define SDXC_DataStarve BIT(10) /* 0x00000400 */
  419. #define SDXC_VolChgDone BIT(10) /* 0x00000400 */
  420. #define SDXC_FIFORunErr BIT(11) /* 0x00000800 */
  421. #define SDXC_HardWLocked BIT(12) /* 0x00001000 */
  422. #define SDXC_StartBitErr BIT(13) /* 0x00002000 */
  423. #define SDXC_AutoCMDDone BIT(14) /* 0x00004000 */
  424. #define SDXC_EndBitErr BIT(15) /* 0x00008000 */
  425. #define SDXC_SDIOInt BIT(16) /* 0x00010000 */
  426. #define SDXC_CardInsert BIT(30) /* 0x40000000 */
  427. #define SDXC_CardRemove BIT(31) /* 0x80000000 */
  428. #define SDXC_IntErrBit (SDXC_RespErr | SDXC_RespCRCErr | SDXC_DataCRCErr | SDXC_RespTimeout | SDXC_DataTimeout | \
  429. SDXC_FIFORunErr | SDXC_HardWLocked | SDXC_StartBitErr | SDXC_EndBitErr) /* 0xbbc2 */
  430. /* status */
  431. #define SDXC_RXWLFlag BIT(0)
  432. #define SDXC_TXWLFlag BIT(1)
  433. #define SDXC_FIFOEmpty BIT(2)
  434. #define SDXC_FIFOFull BIT(3)
  435. #define SDXC_CardPresent BIT(8)
  436. #define SDXC_CardDataBusy BIT(9)
  437. #define SDXC_DataFSMBusy BIT(10)
  438. #define SDXC_DMAReq BIT(31)
  439. /* Function select */
  440. #define SDXC_CEATAOn (0xceaaU << 16)
  441. #define SDXC_SendIrqRsp BIT(0)
  442. #define SDXC_SDIORdWait BIT(1)
  443. #define SDXC_AbtRdData BIT(2)
  444. #define SDXC_SendCCSD BIT(8)
  445. #define SDXC_SendAutoStopCCSD BIT(9)
  446. #define SDXC_CEATADevIntEnb BIT(10)
  447. /* status bit */
  448. #define SDXC_CardBusy BIT(9)
  449. /* IDMA controller bus mod bit field */
  450. #define SDXC_IDMACSoftRST BIT(0)
  451. #define SDXC_IDMACFixBurst BIT(1)
  452. #define SDXC_IDMACIDMAOn BIT(7)
  453. #define SDXC_IDMACRefetchDES BIT(31)
  454. /* IDMA status bit field */
  455. #define SDXC_IDMACTransmitInt BIT(0)
  456. #define SDXC_IDMACReceiveInt BIT(1)
  457. #define SDXC_IDMACFatalBusErr BIT(2)
  458. #define SDXC_IDMACDesInvalid BIT(4)
  459. #define SDXC_IDMACCardErrSum BIT(5)
  460. #define SDXC_IDMACNormalIntSum BIT(8)
  461. #define SDXC_IDMACAbnormalIntSum BIT(9)
  462. #define SDXC_IDMACHostAbtInTx BIT(10)
  463. #define SDXC_IDMACHostAbtInRx BIT(10)
  464. #define SDXC_IDMACIdle (0x0U << 13)
  465. #define SDXC_IDMACSuspend (0x1U << 13)
  466. #define SDXC_IDMACDESCRd (0x2U << 13)
  467. #define SDXC_IDMACDESCCheck (0x3U << 13)
  468. #define SDXC_IDMACRdReqWait (0x4U << 13)
  469. #define SDXC_IDMACWrReqWait (0x5U << 13)
  470. #define SDXC_IDMACRd (0x6U << 13)
  471. #define SDXC_IDMACWr (0x7U << 13)
  472. #define SDXC_IDMACDESCClose (0x8U << 13)
  473. #define SDXC_IDMA_OVER (SDXC_IDMACTransmitInt|SDXC_IDMACReceiveInt|SDXC_IDMACNormalIntSum)
  474. #define SDXC_IDMA_ERR (SDXC_IDMACFatalBusErr|SDXC_IDMACDesInvalid|SDXC_IDMACCardErrSum|SDXC_IDMACAbnormalIntSum)
  475. /*
  476. * These flags are used to describe power management features that
  477. * some cards (typically SDIO cards) might wish to benefit from when
  478. * the host system is being suspended. There are several layers of
  479. * abstractions involved, from the host controller driver, to the MMC core
  480. * code, to the SDIO core code, to finally get to the actual SDIO function
  481. * driver. This file is therefore used for common definitions shared across
  482. * all those layers.
  483. */
  484. #define MMC_PM_KEEP_POWER (1 << 0) /* preserve card power during suspend */
  485. #define MMC_PM_WAKE_SDIO_IRQ (1 << 1) /* wake up host system on SDIO IRQ assertion */
  486. #define MMC_PM_IGNORE_PM_NOTIFY (1 << 2) /* ignore mmc pm notify */
  487. #ifdef CONFIG_SD_PM
  488. static inline int mmc_card_keep_power(struct mmc_host *host)
  489. {
  490. return host->pm_flags & MMC_PM_KEEP_POWER;
  491. }
  492. static inline int mmc_card_wake_sdio_irq(struct mmc_host *host)
  493. {
  494. return host->pm_flags & MMC_PM_WAKE_SDIO_IRQ;
  495. }
  496. #endif
  497. #ifdef CONFIG_SDC_READONLY_USED
  498. extern int32_t HAL_SDC_Get_ReadOnly(struct mmc_host *host);
  499. #endif
  500. extern void HAL_SDC_Set_BusWidth(struct mmc_host *host, uint32_t width);
  501. extern uint32_t HAL_SDC_Is_Busy(struct mmc_host *host);
  502. #ifdef CONFIG_SDC_EXCLUSIVE_HOST
  503. extern int32_t HAL_SDC_Claim_Host(struct mmc_host *host);
  504. extern void HAL_SDC_Release_Host(struct mmc_host *host);
  505. #else
  506. static inline int32_t HAL_SDC_Claim_Host(struct mmc_host *host) { return 0; }
  507. static inline void HAL_SDC_Release_Host(struct mmc_host *host) { ; }
  508. #endif
  509. #ifdef __CONFIG_ROM
  510. #include "rom/ram_table.h"
  511. #define HAL_SDC_Update_Clk \
  512. RAM_TBL_FUN(int32_t (*)(struct mmc_host *host, uint32_t clk), HAL_SDC_Update_Clk)
  513. #define HAL_SDC_Clk_PWR_Opt \
  514. RAM_TBL_FUN(int32_t (*)(struct mmc_host *host, uint32_t oclk_en, uint32_t pwr_save), HAL_SDC_Clk_PWR_Opt)
  515. #define HAL_SDC_PowerOn \
  516. RAM_TBL_FUN(int32_t (*)(struct mmc_host *host), HAL_SDC_PowerOn)
  517. #define HAL_SDC_PowerOff \
  518. RAM_TBL_FUN(int32_t (*)(struct mmc_host *host), HAL_SDC_PowerOff)
  519. #define HAL_SDC_Request \
  520. RAM_TBL_FUN(int32_t (*)(struct mmc_host *host, struct mmc_request *mrq), HAL_SDC_Request)
  521. #define HAL_SDC_Enable_Sdio_Irq \
  522. RAM_TBL_FUN(void (*)(struct mmc_host *host, int enable), HAL_SDC_Enable_Sdio_Irq)
  523. #else
  524. extern int32_t HAL_SDC_Update_Clk(struct mmc_host *host, uint32_t clk);
  525. extern int32_t HAL_SDC_Clk_PWR_Opt(struct mmc_host *host, uint32_t oclk_en, uint32_t pwr_save);
  526. extern int32_t HAL_SDC_PowerOn(struct mmc_host *host);
  527. extern int32_t HAL_SDC_PowerOff(struct mmc_host *host);
  528. extern int32_t HAL_SDC_Request(struct mmc_host *host, struct mmc_request *mrq);
  529. extern void HAL_SDC_Enable_Sdio_Irq(struct mmc_host *host, int enable);
  530. #define rom_HAL_SDC_Update_Clk HAL_SDC_Update_Clk
  531. #define rom_HAL_SDC_Clk_PWR_Opt HAL_SDC_Clk_PWR_Opt
  532. #define rom_HAL_SDC_PowerOn HAL_SDC_PowerOn
  533. #define rom_HAL_SDC_PowerOff HAL_SDC_PowerOff
  534. #define rom_HAL_SDC_Request HAL_SDC_Request
  535. #define rom_HAL_SDC_Enable_Sdio_Irq HAL_SDC_Enable_Sdio_Irq
  536. #endif /* __CONFIG_ROM */
  537. #ifdef __cplusplus
  538. }
  539. #endif
  540. #endif /* _ROM_DRIVER_CHIP_SDMMC__SDHOST_H_ */