sdmmc.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #ifndef _SDMMC_H
  2. #define _SDMMC_H
  3. #define MMC_FEQ_MIN 400000
  4. #define MMC_FEQ_MAX 24000000
  5. #define CARD_UNPLUGED 1
  6. #define CARD_PLUGED 0
  7. #define IDMAC_INT_CLR (SDMMC_IDMAC_INT_AI | SDMMC_IDMAC_INT_NI | \
  8. SDMMC_IDMAC_INT_CES | SDMMC_IDMAC_INT_DU | \
  9. SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \
  10. SDMMC_IDMAC_INT_TI)
  11. #define DESC_RING_BUF_SZ (128*1024)//PAGE_SIZE
  12. #define GFP_KERNEL ((gfp_t) 0)
  13. enum {
  14. TRANS_MODE_PIO = 0,
  15. TRANS_MODE_IDMAC,
  16. TRANS_MODE_EDMAC
  17. };
  18. struct dw_mci_dma_slave {
  19. struct dma_chan *ch;
  20. enum dma_transfer_direction direction;
  21. };
  22. #define SDMMC_CTRL 0x000
  23. #define SDMMC_PWREN 0x004
  24. #define SDMMC_CLKDIV 0x008
  25. #define SDMMC_CLKSRC 0x00c
  26. #define SDMMC_CLKENA 0x010
  27. #define SDMMC_TMOUT 0x014
  28. #define SDMMC_CTYPE 0x018
  29. #define SDMMC_BLKSIZ 0x01c
  30. #define SDMMC_BYTCNT 0x020
  31. #define SDMMC_INTMASK 0x024
  32. #define SDMMC_CMDARG 0x028
  33. #define SDMMC_CMD 0x02c
  34. #define SDMMC_RESP0 0x030
  35. #define SDMMC_RESP1 0x034
  36. #define SDMMC_RESP2 0x038
  37. #define SDMMC_RESP3 0x03c
  38. #define SDMMC_MINTSTS 0x040
  39. #define SDMMC_RINTSTS 0x044
  40. #define SDMMC_STATUS 0x048
  41. #define SDMMC_FIFOTH 0x04c
  42. #define SDMMC_CDETECT 0x050
  43. #define SDMMC_WRTPRT 0x054
  44. #define SDMMC_GPIO 0x058
  45. #define SDMMC_TCBCNT 0x05c
  46. #define SDMMC_TBBCNT 0x060
  47. #define SDMMC_DEBNCE 0x064
  48. #define SDMMC_USRID 0x068
  49. #define SDMMC_VERID 0x06c
  50. #define SDMMC_HCON 0x070
  51. #define SDMMC_UHS_REG 0x074
  52. #define SDMMC_RST_N 0x078
  53. #define SDMMC_BMOD 0x080
  54. #define SDMMC_PLDMND 0x084
  55. #define SDMMC_DBADDR 0x088
  56. #define SDMMC_IDSTS 0x08c
  57. #define SDMMC_IDINTEN 0x090
  58. #define SDMMC_DSCADDR 0x094
  59. #define SDMMC_BUFADDR 0x098
  60. #define SDMMC_FIFO 0x200 // 0x100
  61. #define SDMMC_DATA(x) (x)
  62. /*
  63. * Registers to support idmac 64-bit address mode
  64. */
  65. #define SDMMC_DBADDRL 0x088
  66. #define SDMMC_DBADDRU 0x08c
  67. #define SDMMC_IDSTS64 0x090
  68. #define SDMMC_IDINTEN64 0x094
  69. #define SDMMC_DSCADDRL 0x098
  70. #define SDMMC_DSCADDRU 0x09c
  71. #define SDMMC_BUFADDRL 0x0A0
  72. #define SDMMC_BUFADDRU 0x0A4
  73. #define SDMMC_FIFO_DEPTH 64//32
  74. /* Control register defines */
  75. #define SDMMC_CTRL_USE_IDMAC BIT(25)
  76. #define SDMMC_CTRL_CEATA_INT_EN BIT(11)
  77. #define SDMMC_CTRL_SEND_AS_CCSD BIT(10)
  78. #define SDMMC_CTRL_SEND_CCSD BIT(9)
  79. #define SDMMC_CTRL_ABRT_READ_DATA BIT(8)
  80. #define SDMMC_CTRL_SEND_IRQ_RESP BIT(7)
  81. #define SDMMC_CTRL_READ_WAIT BIT(6)
  82. #define SDMMC_CTRL_DMA_ENABLE BIT(5)
  83. #define SDMMC_CTRL_INT_ENABLE BIT(4)
  84. #define SDMMC_CTRL_DMA_RESET BIT(2)
  85. #define SDMMC_CTRL_FIFO_RESET BIT(1)
  86. #define SDMMC_CTRL_RESET BIT(0)
  87. /* Clock Enable register defines */
  88. #define SDMMC_CLKEN_LOW_PWR BIT(16)
  89. #define SDMMC_CLKEN_ENABLE BIT(0)
  90. /* time-out register defines */
  91. #define SDMMC_TMOUT_DATA(n) _SBF(8, (n))
  92. #define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00
  93. #define SDMMC_TMOUT_RESP(n) ((n) & 0xFF)
  94. #define SDMMC_TMOUT_RESP_MSK 0xFF
  95. /* card-type register defines */
  96. #define SDMMC_CTYPE_8BIT BIT(16)
  97. #define SDMMC_CTYPE_4BIT BIT(0)
  98. #define SDMMC_CTYPE_1BIT 0
  99. /* Interrupt status & mask register defines */
  100. #define SDMMC_INT_SDIO BIT(16)
  101. #define SDMMC_INT_EBE BIT(15)
  102. #define SDMMC_INT_ACD BIT(14)
  103. #define SDMMC_INT_SBE BIT(13)
  104. #define SDMMC_INT_HLE BIT(12)
  105. #define SDMMC_INT_FRUN BIT(11)
  106. #define SDMMC_INT_HTO BIT(10)
  107. #define SDMMC_INT_VOLT_SWITCH BIT(10) /* overloads bit 10! */
  108. #define SDMMC_INT_DRTO BIT(9)
  109. #define SDMMC_INT_RTO BIT(8)
  110. #define SDMMC_INT_DCRC BIT(7)
  111. #define SDMMC_INT_RCRC BIT(6)
  112. #define SDMMC_INT_RXDR BIT(5)
  113. #define SDMMC_INT_TXDR BIT(4)
  114. #define SDMMC_INT_DATA_OVER BIT(3)
  115. #define SDMMC_INT_CMD_DONE BIT(2)
  116. #define SDMMC_INT_RESP_ERR BIT(1)
  117. #define SDMMC_INT_CD BIT(0)
  118. #define SDMMC_INT_ALL (~0)
  119. #define SDMMC_INT_DATA_ERROR (SDMMC_INT_DCRC | SDMMC_INT_SBE | SDMMC_INT_EBE)
  120. #define SDMMC_INT_STATUS_DATA (SDMMC_INT_DATA_OVER | SDMMC_INT_DATA_ERROR \
  121. | SDMMC_INT_TXDR | SDMMC_INT_RXDR)
  122. /* Common flag combinations */
  123. #define SDMMC_DATA_ERROR_FLAGS (SDMMC_INT_DRTO | SDMMC_INT_DCRC | \
  124. SDMMC_INT_HTO | SDMMC_INT_SBE | \
  125. SDMMC_INT_EBE | SDMMC_INT_HLE)
  126. #define SDMMC_CMD_ERROR_FLAGS (SDMMC_INT_RTO | SDMMC_INT_RCRC | \
  127. SDMMC_INT_RESP_ERR | SDMMC_INT_HLE)
  128. #define SDMMC_ERROR_FLAGS (SDMMC_DATA_ERROR_FLAGS | \
  129. SDMMC_CMD_ERROR_FLAGS)
  130. #define SDMMC_INT_ERROR 0xbfc2
  131. /* Command register defines */
  132. #define SDMMC_CMD_START BIT(31)
  133. #define SDMMC_CMD_USE_HOLD_REG BIT(29)
  134. #define SDMMC_CMD_VOLT_SWITCH BIT(28)
  135. #define SDMMC_CMD_CCS_EXP BIT(23)
  136. #define SDMMC_CMD_CEATA_RD BIT(22)
  137. #define SDMMC_CMD_UPD_CLK BIT(21)
  138. #define SDMMC_CMD_INIT BIT(15)
  139. #define SDMMC_CMD_STOP BIT(14)
  140. #define SDMMC_CMD_PRV_DAT_WAIT BIT(13)
  141. #define SDMMC_CMD_SEND_STOP BIT(12)
  142. #define SDMMC_CMD_STRM_MODE BIT(11)
  143. #define SDMMC_CMD_DAT_WR BIT(10)
  144. #define SDMMC_CMD_DAT_EXP BIT(9)
  145. #define SDMMC_CMD_RESP_CRC BIT(8)
  146. #define SDMMC_CMD_RESP_LONG BIT(7)
  147. #define SDMMC_CMD_RESP_EXP BIT(6)
  148. #define SDMMC_CMD_INDX(n) ((n) & 0x1F)
  149. /* Status register defines */
  150. #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
  151. #define SDMMC_STATUS_DMA_REQ BIT(31)
  152. #define SDMMC_STATUS_BUSY BIT(9)
  153. /* FIFOTH register defines */
  154. #define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \
  155. ((r) & 0xFFF) << 16 | \
  156. ((t) & 0xFFF))
  157. /* HCON register defines */
  158. #define DMA_INTERFACE_IDMA (0x0)
  159. #define DMA_INTERFACE_DWDMA (0x1)
  160. #define DMA_INTERFACE_GDMA (0x2)
  161. #define DMA_INTERFACE_NODMA (0x3)
  162. #define SDMMC_GET_TRANS_MODE(x) (((x)>>16) & 0x3)
  163. #define SDMMC_GET_SLOT_NUM(x) ((((x)>>1) & 0x1F) + 1)
  164. #define SDMMC_GET_HDATA_WIDTH(x) (((x)>>7) & 0x7)
  165. #define SDMMC_GET_ADDR_CONFIG(x) (((x)>>27) & 0x1)
  166. /* Internal DMAC interrupt defines */
  167. #define SDMMC_IDMAC_INT_AI BIT(9)
  168. #define SDMMC_IDMAC_INT_NI BIT(8)
  169. #define SDMMC_IDMAC_INT_CES BIT(5)
  170. #define SDMMC_IDMAC_INT_DU BIT(4)
  171. #define SDMMC_IDMAC_INT_FBE BIT(2)
  172. #define SDMMC_IDMAC_INT_RI BIT(1)
  173. #define SDMMC_IDMAC_INT_TI BIT(0)
  174. /* Internal DMAC bus mode bits */
  175. #define SDMMC_IDMAC_ENABLE BIT(7)
  176. #define SDMMC_IDMAC_FB BIT(1)
  177. #define SDMMC_IDMAC_SWRESET BIT(0)
  178. /* H/W reset */
  179. #define SDMMC_RST_HWACTIVE 0x1
  180. /* Version ID register define */
  181. #define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
  182. /* Card read threshold */
  183. #define SDMMC_SET_THLD(v, x) (((v) & 0xFFF) << 16 | (x))
  184. #define SDMMC_CARD_WR_THR_EN BIT(2)
  185. #define SDMMC_CARD_RD_THR_EN BIT(0)
  186. /* UHS-1 register defines */
  187. #define SDMMC_UHS_18V BIT(0)
  188. #define IDMAC_DES0_ER BIT(5)
  189. /* All ctrl reset bits */
  190. #define SDMMC_CTRL_ALL_RESET_FLAGS \
  191. (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET)
  192. struct mmc_driver
  193. {
  194. uint32_t max_desc;
  195. struct mmcsd_host *host;
  196. struct mmcsd_req *req;
  197. struct mmcsd_data *data;
  198. struct mmcsd_cmd *cmd;
  199. void* priv;
  200. };
  201. struct ark_mmc_obj;
  202. /* DMA ops for Internal/External DMAC interface */
  203. struct dw_mci_dma_ops {
  204. /* DMA Ops */
  205. int (*init)(struct ark_mmc_obj *mmc_obj);
  206. int (*start)(struct ark_mmc_obj *mmc_obj, struct mmcsd_data *data);
  207. void (*stop)(struct ark_mmc_obj *mmc_obj);
  208. void (*cleanup)(struct ark_mmc_obj *mmc_obj);
  209. void (*exit)(struct ark_mmc_obj *mmc_obj);
  210. };
  211. struct ark_mmc_obj
  212. {
  213. uint32_t id;
  214. uint32_t irq;
  215. uint32_t base;
  216. int softreset_id;
  217. int clk_id;
  218. int sema_id;
  219. uint32_t power_pin_gpio;
  220. uint32_t fifoth_val;
  221. uint32_t prev_blksz;
  222. int result;
  223. int use_dma;
  224. int using_dma;
  225. struct dw_mci_dma_ops *dma_ops;
  226. struct dw_mci_dma_slave *dms;
  227. struct mmcsd_data *data;
  228. QueueHandle_t transfer_completion;
  229. char *tx_dummy_buffer;
  230. char *rx_dummy_buffer;
  231. int dummy_buffer_used;
  232. void (*mmc_reset)(struct ark_mmc_obj *);
  233. int dma_64bit_address;
  234. dma_addr_t sg_dma;
  235. void *sg_cpu;
  236. };
  237. int mmc_init(void);
  238. #endif /* _SDMMC_H */