dwmmc.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * (C) Copyright 2012 SAMSUNG Electronics
  3. * Jaehoon Chung <jh80.chung@samsung.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __DWMMC_HW_H
  8. #define __DWMMC_HW_H
  9. #include <asm/io.h>
  10. #include <mmc.h>
  11. #define DWMCI_CTRL 0x000
  12. #define DWMCI_PWREN 0x004
  13. #define DWMCI_CLKDIV 0x008
  14. #define DWMCI_CLKSRC 0x00C
  15. #define DWMCI_CLKENA 0x010
  16. #define DWMCI_TMOUT 0x014
  17. #define DWMCI_CTYPE 0x018
  18. #define DWMCI_BLKSIZ 0x01C
  19. #define DWMCI_BYTCNT 0x020
  20. #define DWMCI_INTMASK 0x024
  21. #define DWMCI_CMDARG 0x028
  22. #define DWMCI_CMD 0x02C
  23. #define DWMCI_RESP0 0x030
  24. #define DWMCI_RESP1 0x034
  25. #define DWMCI_RESP2 0x038
  26. #define DWMCI_RESP3 0x03C
  27. #define DWMCI_MINTSTS 0x040
  28. #define DWMCI_RINTSTS 0x044
  29. #define DWMCI_STATUS 0x048
  30. #define DWMCI_FIFOTH 0x04C
  31. #define DWMCI_CDETECT 0x050
  32. #define DWMCI_WRTPRT 0x054
  33. #define DWMCI_GPIO 0x058
  34. #define DWMCI_TCMCNT 0x05C
  35. #define DWMCI_TBBCNT 0x060
  36. #define DWMCI_DEBNCE 0x064
  37. #define DWMCI_USRID 0x068
  38. #define DWMCI_VERID 0x06C
  39. #define DWMCI_HCON 0x070
  40. #define DWMCI_UHS_REG 0x074
  41. #define DWMCI_BMOD 0x080
  42. #define DWMCI_PLDMND 0x084
  43. #define DWMCI_DBADDR 0x088
  44. #define DWMCI_IDSTS 0x08C
  45. #define DWMCI_IDINTEN 0x090
  46. #define DWMCI_DSCADDR 0x094
  47. #define DWMCI_BUFADDR 0x098
  48. #define DWMCI_DATA 0x200
  49. /* Interrupt Mask register */
  50. #define DWMCI_INTMSK_ALL 0xffffffff
  51. #define DWMCI_INTMSK_RE (1 << 1)
  52. #define DWMCI_INTMSK_CDONE (1 << 2)
  53. #define DWMCI_INTMSK_DTO (1 << 3)
  54. #define DWMCI_INTMSK_TXDR (1 << 4)
  55. #define DWMCI_INTMSK_RXDR (1 << 5)
  56. #define DWMCI_INTMSK_DCRC (1 << 7)
  57. #define DWMCI_INTMSK_RTO (1 << 8)
  58. #define DWMCI_INTMSK_DRTO (1 << 9)
  59. #define DWMCI_INTMSK_HTO (1 << 10)
  60. #define DWMCI_INTMSK_FRUN (1 << 11)
  61. #define DWMCI_INTMSK_HLE (1 << 12)
  62. #define DWMCI_INTMSK_SBE (1 << 13)
  63. #define DWMCI_INTMSK_ACD (1 << 14)
  64. #define DWMCI_INTMSK_EBE (1 << 15)
  65. /* Raw interrupt Regsiter */
  66. #define DWMCI_DATA_ERR (DWMCI_INTMSK_EBE | DWMCI_INTMSK_SBE | DWMCI_INTMSK_HLE |\
  67. DWMCI_INTMSK_FRUN | DWMCI_INTMSK_EBE | DWMCI_INTMSK_DCRC)
  68. #define DWMCI_DATA_TOUT (DWMCI_INTMSK_HTO | DWMCI_INTMSK_DRTO)
  69. /* CTRL register */
  70. #define DWMCI_CTRL_RESET (1 << 0)
  71. #define DWMCI_CTRL_FIFO_RESET (1 << 1)
  72. #define DWMCI_CTRL_DMA_RESET (1 << 2)
  73. #define DWMCI_DMA_EN (1 << 5)
  74. #define DWMCI_CTRL_SEND_AS_CCSD (1 << 10)
  75. #define DWMCI_IDMAC_EN (1 << 25)
  76. #define DWMCI_RESET_ALL (DWMCI_CTRL_RESET | DWMCI_CTRL_FIFO_RESET |\
  77. DWMCI_CTRL_DMA_RESET)
  78. /* CMD register */
  79. #define DWMCI_CMD_RESP_EXP (1 << 6)
  80. #define DWMCI_CMD_RESP_LENGTH (1 << 7)
  81. #define DWMCI_CMD_CHECK_CRC (1 << 8)
  82. #define DWMCI_CMD_DATA_EXP (1 << 9)
  83. #define DWMCI_CMD_RW (1 << 10)
  84. #define DWMCI_CMD_SEND_STOP (1 << 12)
  85. #define DWMCI_CMD_ABORT_STOP (1 << 14)
  86. #define DWMCI_CMD_PRV_DAT_WAIT (1 << 13)
  87. #define DWMCI_CMD_UPD_CLK (1 << 21)
  88. #define DWMCI_CMD_USE_HOLD_REG (1 << 29)
  89. #define DWMCI_CMD_START (1 << 31)
  90. /* CLKENA register */
  91. #define DWMCI_CLKEN_ENABLE (1 << 0)
  92. #define DWMCI_CLKEN_LOW_PWR (1 << 16)
  93. /* Card-type registe */
  94. #define DWMCI_CTYPE_1BIT 0
  95. #define DWMCI_CTYPE_4BIT (1 << 0)
  96. #define DWMCI_CTYPE_8BIT (1 << 16)
  97. /* Status Register */
  98. #define DWMCI_BUSY (1 << 9)
  99. #define DWMCI_FIFO_MASK 0x1fff
  100. #define DWMCI_FIFO_SHIFT 17
  101. /* FIFOTH Register */
  102. #define MSIZE(x) ((x) << 28)
  103. #define RX_WMARK(x) ((x) << 16)
  104. #define TX_WMARK(x) (x)
  105. #define RX_WMARK_SHIFT 16
  106. #define RX_WMARK_MASK (0xfff << RX_WMARK_SHIFT)
  107. #define DWMCI_IDMAC_OWN (1 << 31)
  108. #define DWMCI_IDMAC_CH (1 << 4)
  109. #define DWMCI_IDMAC_FS (1 << 3)
  110. #define DWMCI_IDMAC_LD (1 << 2)
  111. /* Bus Mode Register */
  112. #define DWMCI_BMOD_IDMAC_RESET (1 << 0)
  113. #define DWMCI_BMOD_IDMAC_FB (1 << 1)
  114. #define DWMCI_BMOD_IDMAC_EN (1 << 7)
  115. /* UHS register */
  116. #define DWMCI_DDR_MODE (1 << 16)
  117. /* quirks */
  118. #define DWMCI_QUIRK_DISABLE_SMU (1 << 0)
  119. /**
  120. * struct dwmci_host - Information about a designware MMC host
  121. *
  122. * @name: Device name
  123. * @ioaddr: Base I/O address of controller
  124. * @quirks: Quick flags - see DWMCI_QUIRK_...
  125. * @caps: Capabilities - see MMC_MODE_...
  126. * @bus_hz: Bus speed in Hz, if @get_mmc_clk() is NULL
  127. * @div: Arbitrary clock divider value for use by controller
  128. * @dev_index: Arbitrary device index for use by controller
  129. * @dev_id: Arbitrary device ID for use by controller
  130. * @buswidth: Bus width in bits (8 or 4)
  131. * @fifoth_val: Value for FIFOTH register (or 0 to leave unset)
  132. * @mmc: Pointer to generic MMC structure for this device
  133. * @priv: Private pointer for use by controller
  134. */
  135. struct dwmci_host {
  136. const char *name;
  137. void *ioaddr;
  138. unsigned int quirks;
  139. unsigned int caps;
  140. unsigned int version;
  141. unsigned int clock;
  142. unsigned int bus_hz;
  143. unsigned int div;
  144. int dev_index;
  145. int dev_id;
  146. int buswidth;
  147. u32 fifoth_val;
  148. struct mmc *mmc;
  149. void *priv;
  150. void (*clksel)(struct dwmci_host *host);
  151. void (*board_init)(struct dwmci_host *host);
  152. /**
  153. * Get / set a particular MMC clock frequency
  154. *
  155. * This is used to request the current clock frequency of the clock
  156. * that drives the DWMMC peripheral. The caller will then use this
  157. * information to work out the divider it needs to achieve the
  158. * required MMC bus clock frequency. If you want to handle the
  159. * clock external to DWMMC, use @freq to select the frequency and
  160. * return that value too. Then DWMMC will put itself in bypass mode.
  161. *
  162. * @host: DWMMC host
  163. * @freq: Frequency the host is trying to achieve
  164. */
  165. unsigned int (*get_mmc_clk)(struct dwmci_host *host, uint freq);
  166. #ifndef CONFIG_BLK
  167. struct mmc_config cfg;
  168. #endif
  169. /* use fifo mode to read and write data */
  170. bool fifo_mode;
  171. };
  172. struct dwmci_idmac {
  173. u32 flags;
  174. u32 cnt;
  175. u32 addr;
  176. u32 next_addr;
  177. } __aligned(ARCH_DMA_MINALIGN);
  178. static inline void dwmci_writel(struct dwmci_host *host, int reg, u32 val)
  179. {
  180. writel(val, host->ioaddr + reg);
  181. }
  182. static inline void dwmci_writew(struct dwmci_host *host, int reg, u16 val)
  183. {
  184. writew(val, host->ioaddr + reg);
  185. }
  186. static inline void dwmci_writeb(struct dwmci_host *host, int reg, u8 val)
  187. {
  188. writeb(val, host->ioaddr + reg);
  189. }
  190. static inline u32 dwmci_readl(struct dwmci_host *host, int reg)
  191. {
  192. return readl(host->ioaddr + reg);
  193. }
  194. static inline u16 dwmci_readw(struct dwmci_host *host, int reg)
  195. {
  196. return readw(host->ioaddr + reg);
  197. }
  198. static inline u8 dwmci_readb(struct dwmci_host *host, int reg)
  199. {
  200. return readb(host->ioaddr + reg);
  201. }
  202. #ifdef CONFIG_BLK
  203. /**
  204. * dwmci_setup_cfg() - Set up the configuration for DWMMC
  205. *
  206. * This is used to set up a DWMMC device when you are using CONFIG_BLK.
  207. *
  208. * This should be called from your MMC driver's probe() method once you have
  209. * the information required.
  210. *
  211. * Generally your driver will have a platform data structure which holds both
  212. * the configuration (struct mmc_config) and the MMC device info (struct mmc).
  213. * For example:
  214. *
  215. * struct rockchip_mmc_plat {
  216. * struct mmc_config cfg;
  217. * struct mmc mmc;
  218. * };
  219. *
  220. * ...
  221. *
  222. * Inside U_BOOT_DRIVER():
  223. * .platdata_auto_alloc_size = sizeof(struct rockchip_mmc_plat),
  224. *
  225. * To access platform data:
  226. * struct rockchip_mmc_plat *plat = dev_get_platdata(dev);
  227. *
  228. * See rockchip_dw_mmc.c for an example.
  229. *
  230. * @cfg: Configuration structure to fill in (generally &plat->mmc)
  231. * @host: DWMMC host
  232. * @max_clk: Maximum supported clock speed in HZ (e.g. 150000000)
  233. * @min_clk: Minimum supported clock speed in HZ (e.g. 400000)
  234. */
  235. void dwmci_setup_cfg(struct mmc_config *cfg, struct dwmci_host *host,
  236. u32 max_clk, u32 min_clk);
  237. /**
  238. * dwmci_bind() - Set up a new MMC block device
  239. *
  240. * This is used to set up a DWMMC block device when you are using CONFIG_BLK.
  241. * It should be called from your driver's bind() method.
  242. *
  243. * See rockchip_dw_mmc.c for an example.
  244. *
  245. * @dev: Device to set up
  246. * @mmc: Pointer to mmc structure (normally &plat->mmc)
  247. * @cfg: Empty configuration structure (generally &plat->cfg). This is
  248. * normally all zeroes at this point. The only purpose of passing
  249. * this in is to set mmc->cfg to it.
  250. * @return 0 if OK, -ve if the block device could not be created
  251. */
  252. int dwmci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg);
  253. #else
  254. /**
  255. * add_dwmci() - Add a new DWMMC interface
  256. *
  257. * This is used when you are not using CONFIG_BLK. Convert your driver over!
  258. *
  259. * @host: DWMMC host structure
  260. * @max_clk: Maximum supported clock speed in HZ (e.g. 150000000)
  261. * @min_clk: Minimum supported clock speed in HZ (e.g. 400000)
  262. * @return 0 if OK, -ve on error
  263. */
  264. int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk);
  265. #endif /* !CONFIG_BLK */
  266. #ifdef CONFIG_DM_MMC_OPS
  267. /* Export the operations to drivers */
  268. int dwmci_probe(struct udevice *dev);
  269. extern const struct dm_mmc_ops dm_dwmci_ops;
  270. #endif
  271. #endif /* __DWMMC_HW_H */