dwmmc.h 8.6 KB

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