dw_mmc.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * Synopsys DesignWare Multimedia Card Interface driver
  3. * (Based on NXP driver for lpc 31xx)
  4. *
  5. * Copyright (C) 2009 NXP Semiconductors
  6. * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #ifndef _DW_MMC_H_
  14. #define _DW_MMC_H_
  15. #define DW_MMC_240A 0x240a
  16. #define SDMMC_CTRL 0x000
  17. #define SDMMC_PWREN 0x004
  18. #define SDMMC_CLKDIV 0x008
  19. #define SDMMC_CLKSRC 0x00c
  20. #define SDMMC_CLKENA 0x010
  21. #define SDMMC_TMOUT 0x014
  22. #define SDMMC_CTYPE 0x018
  23. #define SDMMC_BLKSIZ 0x01c
  24. #define SDMMC_BYTCNT 0x020
  25. #define SDMMC_INTMASK 0x024
  26. #define SDMMC_CMDARG 0x028
  27. #define SDMMC_CMD 0x02c
  28. #define SDMMC_RESP0 0x030
  29. #define SDMMC_RESP1 0x034
  30. #define SDMMC_RESP2 0x038
  31. #define SDMMC_RESP3 0x03c
  32. #define SDMMC_MINTSTS 0x040
  33. #define SDMMC_RINTSTS 0x044
  34. #define SDMMC_STATUS 0x048
  35. #define SDMMC_FIFOTH 0x04c
  36. #define SDMMC_CDETECT 0x050
  37. #define SDMMC_WRTPRT 0x054
  38. #define SDMMC_GPIO 0x058
  39. #define SDMMC_TCBCNT 0x05c
  40. #define SDMMC_TBBCNT 0x060
  41. #define SDMMC_DEBNCE 0x064
  42. #define SDMMC_USRID 0x068
  43. #define SDMMC_VERID 0x06c
  44. #define SDMMC_HCON 0x070
  45. #define SDMMC_UHS_REG 0x074
  46. #define SDMMC_BMOD 0x080
  47. #define SDMMC_PLDMND 0x084
  48. #define SDMMC_DBADDR 0x088
  49. #define SDMMC_IDSTS 0x08c
  50. #define SDMMC_IDINTEN 0x090
  51. #define SDMMC_DSCADDR 0x094
  52. #define SDMMC_BUFADDR 0x098
  53. #define SDMMC_CDTHRCTL 0x100
  54. #define SDMMC_DATA(x) (x)
  55. /*
  56. * Registers to support idmac 64-bit address mode
  57. */
  58. #define SDMMC_DBADDRL 0x088
  59. #define SDMMC_DBADDRU 0x08c
  60. #define SDMMC_IDSTS64 0x090
  61. #define SDMMC_IDINTEN64 0x094
  62. #define SDMMC_DSCADDRL 0x098
  63. #define SDMMC_DSCADDRU 0x09c
  64. #define SDMMC_BUFADDRL 0x0A0
  65. #define SDMMC_BUFADDRU 0x0A4
  66. /*
  67. * Data offset is difference according to Version
  68. * Lower than 2.40a : data register offest is 0x100
  69. */
  70. #define DATA_OFFSET 0x100
  71. #define DATA_240A_OFFSET 0x200
  72. /* shift bit field */
  73. #define _SBF(f, v) ((v) << (f))
  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(n) BIT(16 + (n))
  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_ERROR 0xbfc2
  119. /* Command register defines */
  120. #define SDMMC_CMD_START BIT(31)
  121. #define SDMMC_CMD_USE_HOLD_REG BIT(29)
  122. #define SDMMC_CMD_VOLT_SWITCH BIT(28)
  123. #define SDMMC_CMD_CCS_EXP BIT(23)
  124. #define SDMMC_CMD_CEATA_RD BIT(22)
  125. #define SDMMC_CMD_UPD_CLK BIT(21)
  126. #define SDMMC_CMD_INIT BIT(15)
  127. #define SDMMC_CMD_STOP BIT(14)
  128. #define SDMMC_CMD_PRV_DAT_WAIT BIT(13)
  129. #define SDMMC_CMD_SEND_STOP BIT(12)
  130. #define SDMMC_CMD_STRM_MODE BIT(11)
  131. #define SDMMC_CMD_DAT_WR BIT(10)
  132. #define SDMMC_CMD_DAT_EXP BIT(9)
  133. #define SDMMC_CMD_RESP_CRC BIT(8)
  134. #define SDMMC_CMD_RESP_LONG BIT(7)
  135. #define SDMMC_CMD_RESP_EXP BIT(6)
  136. #define SDMMC_CMD_INDX(n) ((n) & 0x1F)
  137. /* Status register defines */
  138. #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
  139. #define SDMMC_STATUS_DMA_REQ BIT(31)
  140. #define SDMMC_STATUS_BUSY BIT(9)
  141. /* FIFOTH register defines */
  142. #define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \
  143. ((r) & 0xFFF) << 16 | \
  144. ((t) & 0xFFF))
  145. /* Internal DMAC interrupt defines */
  146. #define SDMMC_IDMAC_INT_AI BIT(9)
  147. #define SDMMC_IDMAC_INT_NI BIT(8)
  148. #define SDMMC_IDMAC_INT_CES BIT(5)
  149. #define SDMMC_IDMAC_INT_DU BIT(4)
  150. #define SDMMC_IDMAC_INT_FBE BIT(2)
  151. #define SDMMC_IDMAC_INT_RI BIT(1)
  152. #define SDMMC_IDMAC_INT_TI BIT(0)
  153. /* Internal DMAC bus mode bits */
  154. #define SDMMC_IDMAC_ENABLE BIT(7)
  155. #define SDMMC_IDMAC_FB BIT(1)
  156. #define SDMMC_IDMAC_SWRESET BIT(0)
  157. /* Version ID register define */
  158. #define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
  159. /* Card read threshold */
  160. #define SDMMC_SET_RD_THLD(v, x) (((v) & 0x1FFF) << 16 | (x))
  161. #define SDMMC_UHS_18V BIT(0)
  162. /* All ctrl reset bits */
  163. #define SDMMC_CTRL_ALL_RESET_FLAGS \
  164. (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET)
  165. /* FIFO register access macros. These should not change the data endian-ness
  166. * as they are written to memory to be dealt with by the upper layers */
  167. #define mci_fifo_readw(__reg) __raw_readw(__reg)
  168. #define mci_fifo_readl(__reg) __raw_readl(__reg)
  169. #define mci_fifo_readq(__reg) __raw_readq(__reg)
  170. #define mci_fifo_writew(__value, __reg) __raw_writew(__reg, __value)
  171. #define mci_fifo_writel(__value, __reg) __raw_writel(__reg, __value)
  172. #define mci_fifo_writeq(__value, __reg) __raw_writeq(__reg, __value)
  173. /* Register access macros */
  174. #define mci_readl(dev, reg) \
  175. readl_relaxed((dev)->regs + SDMMC_##reg)
  176. #define mci_writel(dev, reg, value) \
  177. writel_relaxed((value), (dev)->regs + SDMMC_##reg)
  178. /* 16-bit FIFO access macros */
  179. #define mci_readw(dev, reg) \
  180. readw_relaxed((dev)->regs + SDMMC_##reg)
  181. #define mci_writew(dev, reg, value) \
  182. writew_relaxed((value), (dev)->regs + SDMMC_##reg)
  183. /* 64-bit FIFO access macros */
  184. #ifdef readq
  185. #define mci_readq(dev, reg) \
  186. readq_relaxed((dev)->regs + SDMMC_##reg)
  187. #define mci_writeq(dev, reg, value) \
  188. writeq_relaxed((value), (dev)->regs + SDMMC_##reg)
  189. #else
  190. /*
  191. * Dummy readq implementation for architectures that don't define it.
  192. *
  193. * We would assume that none of these architectures would configure
  194. * the IP block with a 64bit FIFO width, so this code will never be
  195. * executed on those machines. Defining these macros here keeps the
  196. * rest of the code free from ifdefs.
  197. */
  198. #define mci_readq(dev, reg) \
  199. (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg))
  200. #define mci_writeq(dev, reg, value) \
  201. (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value))
  202. #define __raw_writeq(__value, __reg) \
  203. (*(volatile u64 __force *)(__reg) = (__value))
  204. #define __raw_readq(__reg) (*(volatile u64 __force *)(__reg))
  205. #endif
  206. extern int dw_mci_probe(struct dw_mci *host);
  207. extern void dw_mci_remove(struct dw_mci *host);
  208. #ifdef CONFIG_PM_SLEEP
  209. extern int dw_mci_suspend(struct dw_mci *host);
  210. extern int dw_mci_resume(struct dw_mci *host);
  211. #endif
  212. /**
  213. * struct dw_mci_slot - MMC slot state
  214. * @mmc: The mmc_host representing this slot.
  215. * @host: The MMC controller this slot is using.
  216. * @quirks: Slot-level quirks (DW_MCI_SLOT_QUIRK_XXX)
  217. * @ctype: Card type for this slot.
  218. * @mrq: mmc_request currently being processed or waiting to be
  219. * processed, or NULL when the slot is idle.
  220. * @queue_node: List node for placing this node in the @queue list of
  221. * &struct dw_mci.
  222. * @clock: Clock rate configured by set_ios(). Protected by host->lock.
  223. * @__clk_old: The last updated clock with reflecting clock divider.
  224. * Keeping track of this helps us to avoid spamming the console
  225. * with CONFIG_MMC_CLKGATE.
  226. * @flags: Random state bits associated with the slot.
  227. * @id: Number of this slot.
  228. * @sdio_id: Number of this slot in the SDIO interrupt registers.
  229. */
  230. struct dw_mci_slot {
  231. struct mmc_host *mmc;
  232. struct dw_mci *host;
  233. int quirks;
  234. u32 ctype;
  235. struct mmc_request *mrq;
  236. struct list_head queue_node;
  237. unsigned int clock;
  238. unsigned int __clk_old;
  239. unsigned long flags;
  240. #define DW_MMC_CARD_PRESENT 0
  241. #define DW_MMC_CARD_NEED_INIT 1
  242. #define DW_MMC_CARD_NO_LOW_PWR 2
  243. int id;
  244. int sdio_id;
  245. };
  246. /**
  247. * dw_mci driver data - dw-mshc implementation specific driver data.
  248. * @caps: mmc subsystem specified capabilities of the controller(s).
  249. * @init: early implementation specific initialization.
  250. * @setup_clock: implementation specific clock configuration.
  251. * @prepare_command: handle CMD register extensions.
  252. * @set_ios: handle bus specific extensions.
  253. * @parse_dt: parse implementation specific device tree properties.
  254. * @execute_tuning: implementation specific tuning procedure.
  255. *
  256. * Provide controller implementation specific extensions. The usage of this
  257. * data structure is fully optional and usage of each member in this structure
  258. * is optional as well.
  259. */
  260. struct dw_mci_drv_data {
  261. unsigned long *caps;
  262. int (*init)(struct dw_mci *host);
  263. int (*setup_clock)(struct dw_mci *host);
  264. void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
  265. void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
  266. int (*parse_dt)(struct dw_mci *host);
  267. int (*execute_tuning)(struct dw_mci_slot *slot);
  268. int (*prepare_hs400_tuning)(struct dw_mci *host,
  269. struct mmc_ios *ios);
  270. };
  271. #endif /* _DW_MMC_H_ */