drv_sdio.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * File : drv_sdio.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-02-08 RT-Thread the first version
  23. */
  24. #ifndef __DRV_SDIO_H__
  25. #define __DRV_SDIO_H__
  26. #define MMC0_BASE_ADDR 0x01C0F000
  27. #define MMC1_BASE_ADDR 0x01C10000
  28. struct tina_mmc
  29. {
  30. volatile rt_uint32_t gctl_reg; /* (0x000) */
  31. volatile rt_uint32_t ckcr_reg; /* (0x004) */
  32. volatile rt_uint32_t tmor_reg; /* (0x008) */
  33. volatile rt_uint32_t bwdr_reg; /* (0x00C) */
  34. volatile rt_uint32_t bksr_reg; /* (0x010) */
  35. volatile rt_uint32_t bycr_reg; /* (0x014) */
  36. volatile rt_uint32_t cmdr_reg; /* (0x018) */
  37. volatile rt_uint32_t cagr_reg; /* (0x01C) */
  38. volatile rt_uint32_t resp0_reg; /* (0x020) */
  39. volatile rt_uint32_t resp1_reg; /* (0x024) */
  40. volatile rt_uint32_t resp2_reg; /* (0x028) */
  41. volatile rt_uint32_t resp3_reg; /* (0x02C) */
  42. volatile rt_uint32_t imkr_reg; /* (0x030) */
  43. volatile rt_uint32_t misr_reg; /* (0x034) */
  44. volatile rt_uint32_t risr_reg; /* (0x038) */
  45. volatile rt_uint32_t star_reg; /* (0x03C) */
  46. volatile rt_uint32_t fwlr_reg; /* (0x040) */
  47. volatile rt_uint32_t funs_reg; /* (0x044) */
  48. volatile rt_uint32_t cbcr_reg; /* (0x048) */
  49. volatile rt_uint32_t bbcr_reg; /* (0x04C) */
  50. volatile rt_uint32_t dbgc_reg; /* (0x050) */
  51. volatile rt_uint32_t reserved0;
  52. volatile rt_uint32_t a12a_reg; /* (0x058) */
  53. volatile rt_uint32_t reserved1[7];
  54. volatile rt_uint32_t hwrst_reg; /* (0x078) */
  55. volatile rt_uint32_t reserved2;
  56. volatile rt_uint32_t dmac_reg; /* (0x080) */
  57. volatile rt_uint32_t dlba_reg; /* (0x084) */
  58. volatile rt_uint32_t idst_reg; /* (0x088) */
  59. volatile rt_uint32_t idie_reg; /* (0x08C) */
  60. volatile rt_uint32_t chda_reg; /* (0x090) */
  61. volatile rt_uint32_t cbda_reg; /* (0x094) */
  62. volatile rt_uint32_t reserved3[26];
  63. volatile rt_uint32_t card_thldc_reg; /* (0x100) */
  64. volatile rt_uint32_t reserved4[2];
  65. volatile rt_uint32_t emmc_dsbd_reg; /* (0x10c) */
  66. volatile rt_uint32_t reserved5[12];
  67. volatile rt_uint32_t reserved6[48];
  68. volatile rt_uint32_t fifo_reg; /* (0x200) */
  69. };
  70. typedef struct tina_mmc *tina_mmc_t;
  71. #define MMC0 ((tina_mmc_t)MMC0_BASE_ADDR)
  72. #define MMC1 ((tina_mmc_t)MMC1_BASE_ADDR)
  73. #define BIT(x) (1<<(x))
  74. /* Struct for Intrrrupt Information */
  75. #define SDXC_RespErr BIT(1) //0x2
  76. #define SDXC_CmdDone BIT(2) //0x4
  77. #define SDXC_DataOver BIT(3) //0x8
  78. #define SDXC_TxDataReq BIT(4) //0x10
  79. #define SDXC_RxDataReq BIT(5) //0x20
  80. #define SDXC_RespCRCErr BIT(6) //0x40
  81. #define SDXC_DataCRCErr BIT(7) //0x80
  82. #define SDXC_RespTimeout BIT(8) //0x100
  83. #define SDXC_ACKRcv BIT(8) //0x100
  84. #define SDXC_DataTimeout BIT(9) //0x200
  85. #define SDXC_BootStart BIT(9) //0x200
  86. #define SDXC_DataStarve BIT(10) //0x400
  87. #define SDXC_VolChgDone BIT(10) //0x400
  88. #define SDXC_FIFORunErr BIT(11) //0x800
  89. #define SDXC_HardWLocked BIT(12) //0x1000
  90. #define SDXC_StartBitErr BIT(13) //0x2000
  91. #define SDXC_AutoCMDDone BIT(14) //0x4000
  92. #define SDXC_EndBitErr BIT(15) //0x8000
  93. #define SDXC_SDIOInt BIT(16) //0x10000
  94. #define SDXC_CardInsert BIT(30) //0x40000000
  95. #define SDXC_CardRemove BIT(31) //0x80000000
  96. #define SDXC_IntErrBit (SDXC_RespErr | SDXC_RespCRCErr | SDXC_DataCRCErr \
  97. | SDXC_RespTimeout | SDXC_DataTimeout | SDXC_FIFORunErr \
  98. | SDXC_HardWLocked | SDXC_StartBitErr | SDXC_EndBitErr) //0xbfc2
  99. /*
  100. SD CMD reg
  101. REG[0-5] : Cmd ID
  102. REG[6] : Has response
  103. REG[7] : Long response
  104. REG[8] : Check response CRC
  105. REG[9] : Has data
  106. REG[10] : Write
  107. REG[11] : Steam mode
  108. REG[12] : Auto stop
  109. REG[13] : Wait previous over
  110. REG[14] : About cmd
  111. REG[15] : Send initialization
  112. REG[21] : Update clock
  113. REG[31] : Load cmd
  114. */
  115. #define SDXC_RESPONSE_CMD BIT(6)
  116. #define SDXC_LONG_RESPONSE_CMD BIT(7)
  117. #define SDXC_CHECK_CRC_CMD BIT(8)
  118. #define SDXC_HAS_DATA_CMD BIT(9)
  119. #define SDXC_WRITE_CMD BIT(10)
  120. #define SDXC_STEAM_CMD BIT(11)
  121. #define SDXC_AUTO_STOP_CMD BIT(12)
  122. #define SDXC_WAIT_OVER_CMD BIT(13)
  123. #define SDXC_ABOUT_CMD BIT(14)
  124. #define SDXC_SEND_INIT_CMD BIT(15)
  125. #define SDXC_UPDATE_CLOCK_CMD BIT(21)
  126. #define SDXC_LOAD_CMD BIT(31)
  127. /*
  128. SD status reg
  129. REG[0] : FIFO_RX_LEVEL
  130. REG[1] : FIFO_TX_LEVEL
  131. REG[2] : FIFO_EMPTY
  132. REG[3] : FIFO_FULL
  133. REG[4-7] : FSM_STA
  134. REG[8] : CARD_PRESENT
  135. REG[9] : CARD_BUSY
  136. REG[10] : FSM_BUSY
  137. REG[11-16]: RESP_IDX
  138. REG[17-21]: FIFO_LEVEL
  139. REG[31] : DMA_REQ
  140. */
  141. #define SDXC_FIFO_RX_LEVEL BIT(0)
  142. #define SDXC_FIFO_TX_LEVEL BIT(1)
  143. #define SDXC_FIFO_EMPTY BIT(2)
  144. #define SDXC_FIFO_FULL BIT(3)
  145. #define SDXC_CARD_PRESENT BIT(8)
  146. #define SDXC_CARD_BUSY BIT(9)
  147. #define SDXC_FSM_BUSY BIT(10)
  148. #define SDXC_DMA_REQ BIT(31)
  149. struct mmc_des_v4p1
  150. {
  151. rt_uint32_t : 1,
  152. dic : 1, /* disable interrupt on completion */
  153. last_des : 1, /* 1-this data buffer is the last buffer */
  154. first_des : 1, /* 1-data buffer is the first buffer,0-data buffer contained in the next descriptor is 1st buffer */
  155. des_chain : 1, /* 1-the 2nd address in the descriptor is the next descriptor address */
  156. end_of_ring : 1, /* 1-last descriptor flag when using dual data buffer in descriptor */
  157. : 24,
  158. card_err_sum : 1, /* transfer error flag */
  159. own : 1; /* des owner:1-idma owns it, 0-host owns it */
  160. #define SDXC_DES_NUM_SHIFT 12 /* smhc2!! */
  161. #define SDXC_DES_BUFFER_MAX_LEN (1 << SDXC_DES_NUM_SHIFT)
  162. rt_uint32_t data_buf1_sz : 16,
  163. data_buf2_sz : 16;
  164. rt_uint32_t buf_addr_ptr1;
  165. rt_uint32_t buf_addr_ptr2;
  166. };
  167. #endif