dw_mmc.h 18 KB

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