dw_mmc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Synopsys DesignWare Multimedia Card Interface driver
  4. * (Based on NXP driver for lpc 31xx)
  5. *
  6. * Copyright (C) 2009 NXP Semiconductors
  7. * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
  8. */
  9. #ifndef _DW_MMC_H_
  10. #define _DW_MMC_H_
  11. #include <linux/scatterlist.h>
  12. #include <linux/mmc/core.h>
  13. #include <linux/dmaengine.h>
  14. #include <linux/reset.h>
  15. #include <linux/fault-inject.h>
  16. #include <linux/hrtimer.h>
  17. #include <linux/interrupt.h>
  18. enum dw_mci_state {
  19. STATE_IDLE = 0,
  20. STATE_SENDING_CMD,
  21. STATE_SENDING_DATA,
  22. STATE_DATA_BUSY,
  23. STATE_SENDING_STOP,
  24. STATE_DATA_ERROR,
  25. STATE_SENDING_CMD11,
  26. STATE_WAITING_CMD11_DONE,
  27. };
  28. enum {
  29. EVENT_CMD_COMPLETE = 0,
  30. EVENT_XFER_COMPLETE,
  31. EVENT_DATA_COMPLETE,
  32. EVENT_DATA_ERROR,
  33. };
  34. enum dw_mci_cookie {
  35. COOKIE_UNMAPPED,
  36. COOKIE_PRE_MAPPED, /* mapped by pre_req() of dwmmc */
  37. COOKIE_MAPPED, /* mapped by prepare_data() of dwmmc */
  38. };
  39. struct mmc_data;
  40. enum {
  41. TRANS_MODE_PIO = 0,
  42. TRANS_MODE_IDMAC,
  43. TRANS_MODE_EDMAC
  44. };
  45. struct dw_mci_dma_slave {
  46. struct dma_chan *ch;
  47. enum dma_transfer_direction direction;
  48. };
  49. /**
  50. * struct dw_mci - MMC controller state shared between all slots
  51. * @lock: Spinlock protecting the queue and associated data.
  52. * @irq_lock: Spinlock protecting the INTMASK setting.
  53. * @regs: Pointer to MMIO registers.
  54. * @fifo_reg: Pointer to MMIO registers for data FIFO
  55. * @sg: Scatterlist entry currently being processed by PIO code, if any.
  56. * @sg_miter: PIO mapping scatterlist iterator.
  57. * @mrq: The request currently being processed on @slot,
  58. * or NULL if the controller is idle.
  59. * @cmd: The command currently being sent to the card, or NULL.
  60. * @data: The data currently being transferred, or NULL if no data
  61. * transfer is in progress.
  62. * @stop_abort: The command currently prepared for stoping transfer.
  63. * @prev_blksz: The former transfer blksz record.
  64. * @timing: Record of current ios timing.
  65. * @use_dma: Which DMA channel is in use for the current transfer, zero
  66. * denotes PIO mode.
  67. * @using_dma: Whether DMA is in use for the current transfer.
  68. * @dma_64bit_address: Whether DMA supports 64-bit address mode or not.
  69. * @sg_dma: Bus address of DMA buffer.
  70. * @sg_cpu: Virtual address of DMA buffer.
  71. * @dma_ops: Pointer to platform-specific DMA callbacks.
  72. * @cmd_status: Snapshot of SR taken upon completion of the current
  73. * @ring_size: Buffer size for idma descriptors.
  74. * command. Only valid when EVENT_CMD_COMPLETE is pending.
  75. * @dms: structure of slave-dma private data.
  76. * @phy_regs: physical address of controller's register map
  77. * @data_status: Snapshot of SR taken upon completion of the current
  78. * data transfer. Only valid when EVENT_DATA_COMPLETE or
  79. * EVENT_DATA_ERROR is pending.
  80. * @stop_cmdr: Value to be loaded into CMDR when the stop command is
  81. * to be sent.
  82. * @dir_status: Direction of current transfer.
  83. * @tasklet: Tasklet running the request state machine.
  84. * @pending_events: Bitmask of events flagged by the interrupt handler
  85. * to be processed by the tasklet.
  86. * @completed_events: Bitmask of events which the state machine has
  87. * processed.
  88. * @state: Tasklet state.
  89. * @queue: List of slots waiting for access to the controller.
  90. * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus
  91. * rate and timeout calculations.
  92. * @current_speed: Configured rate of the controller.
  93. * @minimum_speed: Stored minimum rate of the controller.
  94. * @fifoth_val: The value of FIFOTH register.
  95. * @verid: Denote Version ID.
  96. * @dev: Device associated with the MMC controller.
  97. * @pdata: Platform data associated with the MMC controller.
  98. * @drv_data: Driver specific data for identified variant of the controller
  99. * @priv: Implementation defined private data.
  100. * @biu_clk: Pointer to bus interface unit clock instance.
  101. * @ciu_clk: Pointer to card interface unit clock instance.
  102. * @slot: Slots sharing this MMC controller.
  103. * @fifo_depth: depth of FIFO.
  104. * @data_addr_override: override fifo reg offset with this value.
  105. * @wm_aligned: force fifo watermark equal with data length in PIO mode.
  106. * Set as true if alignment is needed.
  107. * @data_shift: log2 of FIFO item size.
  108. * @part_buf_start: Start index in part_buf.
  109. * @part_buf_count: Bytes of partial data in part_buf.
  110. * @part_buf: Simple buffer for partial fifo reads/writes.
  111. * @push_data: Pointer to FIFO push function.
  112. * @pull_data: Pointer to FIFO pull function.
  113. * @quirks: Set of quirks that apply to specific versions of the IP.
  114. * @vqmmc_enabled: Status of vqmmc, should be true or false.
  115. * @irq_flags: The flags to be passed to request_irq.
  116. * @irq: The irq value to be passed to request_irq.
  117. * @sdio_id0: Number of slot0 in the SDIO interrupt registers.
  118. * @cmd11_timer: Timer for SD3.0 voltage switch over scheme.
  119. * @cto_timer: Timer for broken command transfer over scheme.
  120. * @dto_timer: Timer for broken data transfer over scheme.
  121. *
  122. * Locking
  123. * =======
  124. *
  125. * @lock is a softirq-safe spinlock protecting @queue as well as
  126. * @slot, @mrq and @state. These must always be updated
  127. * at the same time while holding @lock.
  128. * The @mrq field of struct dw_mci_slot is also protected by @lock,
  129. * and must always be written at the same time as the slot is added to
  130. * @queue.
  131. *
  132. * @irq_lock is an irq-safe spinlock protecting the INTMASK register
  133. * to allow the interrupt handler to modify it directly. Held for only long
  134. * enough to read-modify-write INTMASK and no other locks are grabbed when
  135. * holding this one.
  136. *
  137. * @pending_events and @completed_events are accessed using atomic bit
  138. * operations, so they don't need any locking.
  139. *
  140. * None of the fields touched by the interrupt handler need any
  141. * locking. However, ordering is important: Before EVENT_DATA_ERROR or
  142. * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
  143. * interrupts must be disabled and @data_status updated with a
  144. * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
  145. * CMDRDY interrupt must be disabled and @cmd_status updated with a
  146. * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
  147. * bytes_xfered field of @data must be written. This is ensured by
  148. * using barriers.
  149. */
  150. struct dw_mci {
  151. spinlock_t lock;
  152. spinlock_t irq_lock;
  153. void __iomem *regs;
  154. void __iomem *fifo_reg;
  155. u32 data_addr_override;
  156. bool wm_aligned;
  157. struct scatterlist *sg;
  158. struct sg_mapping_iter sg_miter;
  159. struct mmc_request *mrq;
  160. struct mmc_command *cmd;
  161. struct mmc_data *data;
  162. struct mmc_command stop_abort;
  163. unsigned int prev_blksz;
  164. unsigned char timing;
  165. /* DMA interface members*/
  166. int use_dma;
  167. int using_dma;
  168. int dma_64bit_address;
  169. dma_addr_t sg_dma;
  170. void *sg_cpu;
  171. const struct dw_mci_dma_ops *dma_ops;
  172. /* For idmac */
  173. unsigned int ring_size;
  174. /* For edmac */
  175. struct dw_mci_dma_slave *dms;
  176. /* Registers's physical base address */
  177. resource_size_t phy_regs;
  178. u32 cmd_status;
  179. u32 data_status;
  180. u32 stop_cmdr;
  181. u32 dir_status;
  182. struct tasklet_struct tasklet;
  183. unsigned long pending_events;
  184. unsigned long completed_events;
  185. enum dw_mci_state state;
  186. struct list_head queue;
  187. u32 bus_hz;
  188. u32 current_speed;
  189. u32 minimum_speed;
  190. u32 fifoth_val;
  191. u16 verid;
  192. struct device *dev;
  193. struct dw_mci_board *pdata;
  194. const struct dw_mci_drv_data *drv_data;
  195. void *priv;
  196. struct clk *biu_clk;
  197. struct clk *ciu_clk;
  198. struct dw_mci_slot *slot;
  199. /* FIFO push and pull */
  200. int fifo_depth;
  201. int data_shift;
  202. u8 part_buf_start;
  203. u8 part_buf_count;
  204. union {
  205. u16 part_buf16;
  206. u32 part_buf32;
  207. u64 part_buf;
  208. };
  209. void (*push_data)(struct dw_mci *host, void *buf, int cnt);
  210. void (*pull_data)(struct dw_mci *host, void *buf, int cnt);
  211. u32 quirks;
  212. bool vqmmc_enabled;
  213. unsigned long irq_flags; /* IRQ flags */
  214. int irq;
  215. int sdio_id0;
  216. struct timer_list cmd11_timer;
  217. struct timer_list cto_timer;
  218. struct timer_list dto_timer;
  219. #ifdef CONFIG_FAULT_INJECTION
  220. struct fault_attr fail_data_crc;
  221. struct hrtimer fault_timer;
  222. #endif
  223. };
  224. /* DMA ops for Internal/External DMAC interface */
  225. struct dw_mci_dma_ops {
  226. /* DMA Ops */
  227. int (*init)(struct dw_mci *host);
  228. int (*start)(struct dw_mci *host, unsigned int sg_len);
  229. void (*complete)(void *host);
  230. void (*stop)(struct dw_mci *host);
  231. void (*cleanup)(struct dw_mci *host);
  232. void (*exit)(struct dw_mci *host);
  233. };
  234. struct dma_pdata;
  235. /* Board platform data */
  236. struct dw_mci_board {
  237. unsigned int bus_hz; /* Clock speed at the cclk_in pad */
  238. u32 caps; /* Capabilities */
  239. u32 caps2; /* More capabilities */
  240. u32 pm_caps; /* PM capabilities */
  241. /*
  242. * Override fifo depth. If 0, autodetect it from the FIFOTH register,
  243. * but note that this may not be reliable after a bootloader has used
  244. * it.
  245. */
  246. unsigned int fifo_depth;
  247. /* delay in mS before detecting cards after interrupt */
  248. u32 detect_delay_ms;
  249. struct reset_control *rstc;
  250. struct dw_mci_dma_ops *dma_ops;
  251. struct dma_pdata *data;
  252. };
  253. /* Support for longer data read timeout */
  254. #define DW_MMC_QUIRK_EXTENDED_TMOUT BIT(0)
  255. #define DW_MMC_240A 0x240a
  256. #define DW_MMC_280A 0x280a
  257. #define SDMMC_CTRL 0x000
  258. #define SDMMC_PWREN 0x004
  259. #define SDMMC_CLKDIV 0x008
  260. #define SDMMC_CLKSRC 0x00c
  261. #define SDMMC_CLKENA 0x010
  262. #define SDMMC_TMOUT 0x014
  263. #define SDMMC_CTYPE 0x018
  264. #define SDMMC_BLKSIZ 0x01c
  265. #define SDMMC_BYTCNT 0x020
  266. #define SDMMC_INTMASK 0x024
  267. #define SDMMC_CMDARG 0x028
  268. #define SDMMC_CMD 0x02c
  269. #define SDMMC_RESP0 0x030
  270. #define SDMMC_RESP1 0x034
  271. #define SDMMC_RESP2 0x038
  272. #define SDMMC_RESP3 0x03c
  273. #define SDMMC_MINTSTS 0x040
  274. #define SDMMC_RINTSTS 0x044
  275. #define SDMMC_STATUS 0x048
  276. #define SDMMC_FIFOTH 0x04c
  277. #define SDMMC_CDETECT 0x050
  278. #define SDMMC_WRTPRT 0x054
  279. #define SDMMC_GPIO 0x058
  280. #define SDMMC_TCBCNT 0x05c
  281. #define SDMMC_TBBCNT 0x060
  282. #define SDMMC_DEBNCE 0x064
  283. #define SDMMC_USRID 0x068
  284. #define SDMMC_VERID 0x06c
  285. #define SDMMC_HCON 0x070
  286. #define SDMMC_UHS_REG 0x074
  287. #define SDMMC_RST_N 0x078
  288. #define SDMMC_BMOD 0x080
  289. #define SDMMC_PLDMND 0x084
  290. #define SDMMC_DBADDR 0x088
  291. #define SDMMC_IDSTS 0x08c
  292. #define SDMMC_IDINTEN 0x090
  293. #define SDMMC_DSCADDR 0x094
  294. #define SDMMC_BUFADDR 0x098
  295. #define SDMMC_CDTHRCTL 0x100
  296. #define SDMMC_UHS_REG_EXT 0x108
  297. #define SDMMC_DDR_REG 0x10c
  298. #define SDMMC_ENABLE_SHIFT 0x110
  299. #define SDMMC_DATA(x) (x)
  300. /*
  301. * Registers to support idmac 64-bit address mode
  302. */
  303. #define SDMMC_DBADDRL 0x088
  304. #define SDMMC_DBADDRU 0x08c
  305. #define SDMMC_IDSTS64 0x090
  306. #define SDMMC_IDINTEN64 0x094
  307. #define SDMMC_DSCADDRL 0x098
  308. #define SDMMC_DSCADDRU 0x09c
  309. #define SDMMC_BUFADDRL 0x0A0
  310. #define SDMMC_BUFADDRU 0x0A4
  311. /*
  312. * Data offset is difference according to Version
  313. * Lower than 2.40a : data register offest is 0x100
  314. */
  315. #define DATA_OFFSET 0x100
  316. #define DATA_240A_OFFSET 0x200
  317. /* shift bit field */
  318. #define _SBF(f, v) ((v) << (f))
  319. /* Control register defines */
  320. #define SDMMC_CTRL_USE_IDMAC BIT(25)
  321. #define SDMMC_CTRL_CEATA_INT_EN BIT(11)
  322. #define SDMMC_CTRL_SEND_AS_CCSD BIT(10)
  323. #define SDMMC_CTRL_SEND_CCSD BIT(9)
  324. #define SDMMC_CTRL_ABRT_READ_DATA BIT(8)
  325. #define SDMMC_CTRL_SEND_IRQ_RESP BIT(7)
  326. #define SDMMC_CTRL_READ_WAIT BIT(6)
  327. #define SDMMC_CTRL_DMA_ENABLE BIT(5)
  328. #define SDMMC_CTRL_INT_ENABLE BIT(4)
  329. #define SDMMC_CTRL_DMA_RESET BIT(2)
  330. #define SDMMC_CTRL_FIFO_RESET BIT(1)
  331. #define SDMMC_CTRL_RESET BIT(0)
  332. /* Clock Enable register defines */
  333. #define SDMMC_CLKEN_LOW_PWR BIT(16)
  334. #define SDMMC_CLKEN_ENABLE BIT(0)
  335. /* time-out register defines */
  336. #define SDMMC_TMOUT_DATA(n) _SBF(8, (n))
  337. #define SDMMC_TMOUT_DATA_MSK 0xFFFFFF00
  338. #define SDMMC_TMOUT_RESP(n) ((n) & 0xFF)
  339. #define SDMMC_TMOUT_RESP_MSK 0xFF
  340. /* card-type register defines */
  341. #define SDMMC_CTYPE_8BIT BIT(16)
  342. #define SDMMC_CTYPE_4BIT BIT(0)
  343. #define SDMMC_CTYPE_1BIT 0
  344. /* Interrupt status & mask register defines */
  345. #define SDMMC_INT_SDIO(n) BIT(16 + (n))
  346. #define SDMMC_INT_EBE BIT(15)
  347. #define SDMMC_INT_ACD BIT(14)
  348. #define SDMMC_INT_SBE BIT(13)
  349. #define SDMMC_INT_HLE BIT(12)
  350. #define SDMMC_INT_FRUN BIT(11)
  351. #define SDMMC_INT_HTO BIT(10)
  352. #define SDMMC_INT_VOLT_SWITCH BIT(10) /* overloads bit 10! */
  353. #define SDMMC_INT_DRTO BIT(9)
  354. #define SDMMC_INT_RTO BIT(8)
  355. #define SDMMC_INT_DCRC BIT(7)
  356. #define SDMMC_INT_RCRC BIT(6)
  357. #define SDMMC_INT_RXDR BIT(5)
  358. #define SDMMC_INT_TXDR BIT(4)
  359. #define SDMMC_INT_DATA_OVER BIT(3)
  360. #define SDMMC_INT_CMD_DONE BIT(2)
  361. #define SDMMC_INT_RESP_ERR BIT(1)
  362. #define SDMMC_INT_CD BIT(0)
  363. #define SDMMC_INT_ERROR 0xbfc2
  364. /* Command register defines */
  365. #define SDMMC_CMD_START BIT(31)
  366. #define SDMMC_CMD_USE_HOLD_REG BIT(29)
  367. #define SDMMC_CMD_VOLT_SWITCH BIT(28)
  368. #define SDMMC_CMD_CCS_EXP BIT(23)
  369. #define SDMMC_CMD_CEATA_RD BIT(22)
  370. #define SDMMC_CMD_UPD_CLK BIT(21)
  371. #define SDMMC_CMD_INIT BIT(15)
  372. #define SDMMC_CMD_STOP BIT(14)
  373. #define SDMMC_CMD_PRV_DAT_WAIT BIT(13)
  374. #define SDMMC_CMD_SEND_STOP BIT(12)
  375. #define SDMMC_CMD_STRM_MODE BIT(11)
  376. #define SDMMC_CMD_DAT_WR BIT(10)
  377. #define SDMMC_CMD_DAT_EXP BIT(9)
  378. #define SDMMC_CMD_RESP_CRC BIT(8)
  379. #define SDMMC_CMD_RESP_LONG BIT(7)
  380. #define SDMMC_CMD_RESP_EXP BIT(6)
  381. #define SDMMC_CMD_INDX(n) ((n) & 0x1F)
  382. /* Status register defines */
  383. #define SDMMC_GET_FCNT(x) (((x)>>17) & 0x1FFF)
  384. #define SDMMC_STATUS_DMA_REQ BIT(31)
  385. #define SDMMC_STATUS_BUSY BIT(9)
  386. /* FIFOTH register defines */
  387. #define SDMMC_SET_FIFOTH(m, r, t) (((m) & 0x7) << 28 | \
  388. ((r) & 0xFFF) << 16 | \
  389. ((t) & 0xFFF))
  390. /* HCON register defines */
  391. #define DMA_INTERFACE_IDMA (0x0)
  392. #define DMA_INTERFACE_DWDMA (0x1)
  393. #define DMA_INTERFACE_GDMA (0x2)
  394. #define DMA_INTERFACE_NODMA (0x3)
  395. #define SDMMC_GET_TRANS_MODE(x) (((x)>>16) & 0x3)
  396. #define SDMMC_GET_SLOT_NUM(x) ((((x)>>1) & 0x1F) + 1)
  397. #define SDMMC_GET_HDATA_WIDTH(x) (((x)>>7) & 0x7)
  398. #define SDMMC_GET_ADDR_CONFIG(x) (((x)>>27) & 0x1)
  399. /* Internal DMAC interrupt defines */
  400. #define SDMMC_IDMAC_INT_AI BIT(9)
  401. #define SDMMC_IDMAC_INT_NI BIT(8)
  402. #define SDMMC_IDMAC_INT_CES BIT(5)
  403. #define SDMMC_IDMAC_INT_DU BIT(4)
  404. #define SDMMC_IDMAC_INT_FBE BIT(2)
  405. #define SDMMC_IDMAC_INT_RI BIT(1)
  406. #define SDMMC_IDMAC_INT_TI BIT(0)
  407. /* Internal DMAC bus mode bits */
  408. #define SDMMC_IDMAC_ENABLE BIT(7)
  409. #define SDMMC_IDMAC_FB BIT(1)
  410. #define SDMMC_IDMAC_SWRESET BIT(0)
  411. /* H/W reset */
  412. #define SDMMC_RST_HWACTIVE 0x1
  413. /* Version ID register define */
  414. #define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
  415. /* Card read threshold */
  416. #define SDMMC_SET_THLD(v, x) (((v) & 0xFFF) << 16 | (x))
  417. #define SDMMC_CARD_WR_THR_EN BIT(2)
  418. #define SDMMC_CARD_RD_THR_EN BIT(0)
  419. /* UHS-1 register defines */
  420. #define SDMMC_UHS_DDR BIT(16)
  421. #define SDMMC_UHS_18V BIT(0)
  422. /* DDR register defines */
  423. #define SDMMC_DDR_HS400 BIT(31)
  424. /* Enable shift register defines */
  425. #define SDMMC_ENABLE_PHASE BIT(0)
  426. /* All ctrl reset bits */
  427. #define SDMMC_CTRL_ALL_RESET_FLAGS \
  428. (SDMMC_CTRL_RESET | SDMMC_CTRL_FIFO_RESET | SDMMC_CTRL_DMA_RESET)
  429. /* FIFO register access macros. These should not change the data endian-ness
  430. * as they are written to memory to be dealt with by the upper layers
  431. */
  432. #define mci_fifo_readw(__reg) __raw_readw(__reg)
  433. #define mci_fifo_readl(__reg) __raw_readl(__reg)
  434. #define mci_fifo_readq(__reg) __raw_readq(__reg)
  435. #define mci_fifo_writew(__value, __reg) __raw_writew(__reg, __value)
  436. #define mci_fifo_writel(__value, __reg) __raw_writel(__reg, __value)
  437. #define mci_fifo_writeq(__value, __reg) __raw_writeq(__reg, __value)
  438. /* Register access macros */
  439. #define mci_readl(dev, reg) \
  440. readl_relaxed((dev)->regs + SDMMC_##reg)
  441. #define mci_writel(dev, reg, value) \
  442. writel_relaxed((value), (dev)->regs + SDMMC_##reg)
  443. /* 16-bit FIFO access macros */
  444. #define mci_readw(dev, reg) \
  445. readw_relaxed((dev)->regs + SDMMC_##reg)
  446. #define mci_writew(dev, reg, value) \
  447. writew_relaxed((value), (dev)->regs + SDMMC_##reg)
  448. /* 64-bit FIFO access macros */
  449. #ifdef readq
  450. #define mci_readq(dev, reg) \
  451. readq_relaxed((dev)->regs + SDMMC_##reg)
  452. #define mci_writeq(dev, reg, value) \
  453. writeq_relaxed((value), (dev)->regs + SDMMC_##reg)
  454. #else
  455. /*
  456. * Dummy readq implementation for architectures that don't define it.
  457. *
  458. * We would assume that none of these architectures would configure
  459. * the IP block with a 64bit FIFO width, so this code will never be
  460. * executed on those machines. Defining these macros here keeps the
  461. * rest of the code free from ifdefs.
  462. */
  463. #define mci_readq(dev, reg) \
  464. (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg))
  465. #define mci_writeq(dev, reg, value) \
  466. (*(volatile u64 __force *)((dev)->regs + SDMMC_##reg) = (value))
  467. #define __raw_writeq(__value, __reg) \
  468. (*(volatile u64 __force *)(__reg) = (__value))
  469. #define __raw_readq(__reg) (*(volatile u64 __force *)(__reg))
  470. #endif
  471. extern int dw_mci_probe(struct dw_mci *host);
  472. extern void dw_mci_remove(struct dw_mci *host);
  473. #ifdef CONFIG_PM
  474. extern int dw_mci_runtime_suspend(struct device *device);
  475. extern int dw_mci_runtime_resume(struct device *device);
  476. #endif
  477. /**
  478. * struct dw_mci_slot - MMC slot state
  479. * @mmc: The mmc_host representing this slot.
  480. * @host: The MMC controller this slot is using.
  481. * @ctype: Card type for this slot.
  482. * @mrq: mmc_request currently being processed or waiting to be
  483. * processed, or NULL when the slot is idle.
  484. * @queue_node: List node for placing this node in the @queue list of
  485. * &struct dw_mci.
  486. * @clock: Clock rate configured by set_ios(). Protected by host->lock.
  487. * @__clk_old: The last clock value that was requested from core.
  488. * Keeping track of this helps us to avoid spamming the console.
  489. * @flags: Random state bits associated with the slot.
  490. * @id: Number of this slot.
  491. * @sdio_id: Number of this slot in the SDIO interrupt registers.
  492. */
  493. struct dw_mci_slot {
  494. struct mmc_host *mmc;
  495. struct dw_mci *host;
  496. u32 ctype;
  497. struct mmc_request *mrq;
  498. struct list_head queue_node;
  499. unsigned int clock;
  500. unsigned int __clk_old;
  501. unsigned long flags;
  502. #define DW_MMC_CARD_PRESENT 0
  503. #define DW_MMC_CARD_NEED_INIT 1
  504. #define DW_MMC_CARD_NO_LOW_PWR 2
  505. #define DW_MMC_CARD_NO_USE_HOLD 3
  506. #define DW_MMC_CARD_NEEDS_POLL 4
  507. int id;
  508. int sdio_id;
  509. };
  510. /**
  511. * dw_mci driver data - dw-mshc implementation specific driver data.
  512. * @caps: mmc subsystem specified capabilities of the controller(s).
  513. * @num_caps: number of capabilities specified by @caps.
  514. * @common_caps: mmc subsystem specified capabilities applicable to all of
  515. * the controllers
  516. * @init: early implementation specific initialization.
  517. * @set_ios: handle bus specific extensions.
  518. * @parse_dt: parse implementation specific device tree properties.
  519. * @execute_tuning: implementation specific tuning procedure.
  520. * @set_data_timeout: implementation specific timeout.
  521. * @get_drto_clks: implementation specific cycle count for data read timeout.
  522. *
  523. * Provide controller implementation specific extensions. The usage of this
  524. * data structure is fully optional and usage of each member in this structure
  525. * is optional as well.
  526. */
  527. struct dw_mci_drv_data {
  528. unsigned long *caps;
  529. u32 num_caps;
  530. u32 common_caps;
  531. int (*init)(struct dw_mci *host);
  532. void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
  533. int (*parse_dt)(struct dw_mci *host);
  534. int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode);
  535. int (*prepare_hs400_tuning)(struct dw_mci *host,
  536. struct mmc_ios *ios);
  537. int (*switch_voltage)(struct mmc_host *mmc,
  538. struct mmc_ios *ios);
  539. void (*set_data_timeout)(struct dw_mci *host,
  540. unsigned int timeout_ns);
  541. u32 (*get_drto_clks)(struct dw_mci *host);
  542. };
  543. #endif /* _DW_MMC_H_ */