dwmmc.h 8.7 KB

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