dw_mmc.h 20 KB

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