dw_mmc.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 LINUX_MMC_DW_MMC_H
  14. #define LINUX_MMC_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. #define MAX_MCI_SLOTS 2
  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. struct mmc_data;
  37. enum {
  38. TRANS_MODE_PIO = 0,
  39. TRANS_MODE_IDMAC,
  40. TRANS_MODE_EDMAC
  41. };
  42. struct dw_mci_dma_slave {
  43. struct dma_chan *ch;
  44. enum dma_transfer_direction direction;
  45. };
  46. /**
  47. * struct dw_mci - MMC controller state shared between all slots
  48. * @lock: Spinlock protecting the queue and associated data.
  49. * @irq_lock: Spinlock protecting the INTMASK setting.
  50. * @regs: Pointer to MMIO registers.
  51. * @fifo_reg: Pointer to MMIO registers for data FIFO
  52. * @sg: Scatterlist entry currently being processed by PIO code, if any.
  53. * @sg_miter: PIO mapping scatterlist iterator.
  54. * @cur_slot: The slot which is currently using the controller.
  55. * @mrq: The request currently being processed on @cur_slot,
  56. * or NULL if the controller is idle.
  57. * @cmd: The command currently being sent to the card, or NULL.
  58. * @data: The data currently being transferred, or NULL if no data
  59. * transfer is in progress.
  60. * @stop_abort: The command currently prepared for stoping transfer.
  61. * @prev_blksz: The former transfer blksz record.
  62. * @timing: Record of current ios timing.
  63. * @use_dma: Whether DMA channel is initialized or not.
  64. * @using_dma: Whether DMA is in use for the current transfer.
  65. * @dma_64bit_address: Whether DMA supports 64-bit address mode or not.
  66. * @sg_dma: Bus address of DMA buffer.
  67. * @sg_cpu: Virtual address of DMA buffer.
  68. * @dma_ops: Pointer to platform-specific DMA callbacks.
  69. * @cmd_status: Snapshot of SR taken upon completion of the current
  70. * @ring_size: Buffer size for idma descriptors.
  71. * command. Only valid when EVENT_CMD_COMPLETE is pending.
  72. * @dms: structure of slave-dma private data.
  73. * @phy_regs: physical address of controller's register map
  74. * @data_status: Snapshot of SR taken upon completion of the current
  75. * data transfer. Only valid when EVENT_DATA_COMPLETE or
  76. * EVENT_DATA_ERROR is pending.
  77. * @stop_cmdr: Value to be loaded into CMDR when the stop command is
  78. * to be sent.
  79. * @dir_status: Direction of current transfer.
  80. * @tasklet: Tasklet running the request state machine.
  81. * @pending_events: Bitmask of events flagged by the interrupt handler
  82. * to be processed by the tasklet.
  83. * @completed_events: Bitmask of events which the state machine has
  84. * processed.
  85. * @state: Tasklet state.
  86. * @queue: List of slots waiting for access to the controller.
  87. * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus
  88. * rate and timeout calculations.
  89. * @current_speed: Configured rate of the controller.
  90. * @num_slots: Number of slots available.
  91. * @fifoth_val: The value of FIFOTH register.
  92. * @verid: Denote Version ID.
  93. * @dev: Device associated with the MMC controller.
  94. * @pdata: Platform data associated with the MMC controller.
  95. * @drv_data: Driver specific data for identified variant of the controller
  96. * @priv: Implementation defined private data.
  97. * @biu_clk: Pointer to bus interface unit clock instance.
  98. * @ciu_clk: Pointer to card interface unit clock instance.
  99. * @slot: Slots sharing this MMC controller.
  100. * @fifo_depth: depth of FIFO.
  101. * @data_shift: log2 of FIFO item size.
  102. * @part_buf_start: Start index in part_buf.
  103. * @part_buf_count: Bytes of partial data in part_buf.
  104. * @part_buf: Simple buffer for partial fifo reads/writes.
  105. * @push_data: Pointer to FIFO push function.
  106. * @pull_data: Pointer to FIFO pull function.
  107. * @vqmmc_enabled: Status of vqmmc, should be true or false.
  108. * @irq_flags: The flags to be passed to request_irq.
  109. * @irq: The irq value to be passed to request_irq.
  110. * @sdio_id0: Number of slot0 in the SDIO interrupt registers.
  111. * @cmd11_timer: Timer for SD3.0 voltage switch over scheme.
  112. * @dto_timer: Timer for broken data transfer over scheme.
  113. *
  114. * Locking
  115. * =======
  116. *
  117. * @lock is a softirq-safe spinlock protecting @queue as well as
  118. * @cur_slot, @mrq and @state. These must always be updated
  119. * at the same time while holding @lock.
  120. *
  121. * @irq_lock is an irq-safe spinlock protecting the INTMASK register
  122. * to allow the interrupt handler to modify it directly. Held for only long
  123. * enough to read-modify-write INTMASK and no other locks are grabbed when
  124. * holding this one.
  125. *
  126. * The @mrq field of struct dw_mci_slot is also protected by @lock,
  127. * and must always be written at the same time as the slot is added to
  128. * @queue.
  129. *
  130. * @pending_events and @completed_events are accessed using atomic bit
  131. * operations, so they don't need any locking.
  132. *
  133. * None of the fields touched by the interrupt handler need any
  134. * locking. However, ordering is important: Before EVENT_DATA_ERROR or
  135. * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
  136. * interrupts must be disabled and @data_status updated with a
  137. * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
  138. * CMDRDY interrupt must be disabled and @cmd_status updated with a
  139. * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
  140. * bytes_xfered field of @data must be written. This is ensured by
  141. * using barriers.
  142. */
  143. struct dw_mci {
  144. spinlock_t lock;
  145. spinlock_t irq_lock;
  146. void __iomem *regs;
  147. void __iomem *fifo_reg;
  148. struct scatterlist *sg;
  149. struct sg_mapping_iter sg_miter;
  150. struct dw_mci_slot *cur_slot;
  151. struct mmc_request *mrq;
  152. struct mmc_command *cmd;
  153. struct mmc_data *data;
  154. struct mmc_command stop_abort;
  155. unsigned int prev_blksz;
  156. unsigned char timing;
  157. /* DMA interface members*/
  158. int use_dma;
  159. int using_dma;
  160. int dma_64bit_address;
  161. dma_addr_t sg_dma;
  162. void *sg_cpu;
  163. const struct dw_mci_dma_ops *dma_ops;
  164. /* For idmac */
  165. unsigned int ring_size;
  166. /* For edmac */
  167. struct dw_mci_dma_slave *dms;
  168. /* Registers's physical base address */
  169. resource_size_t phy_regs;
  170. u32 cmd_status;
  171. u32 data_status;
  172. u32 stop_cmdr;
  173. u32 dir_status;
  174. struct tasklet_struct tasklet;
  175. unsigned long pending_events;
  176. unsigned long completed_events;
  177. enum dw_mci_state state;
  178. struct list_head queue;
  179. u32 bus_hz;
  180. u32 current_speed;
  181. u32 num_slots;
  182. u32 fifoth_val;
  183. u16 verid;
  184. struct device *dev;
  185. struct dw_mci_board *pdata;
  186. const struct dw_mci_drv_data *drv_data;
  187. void *priv;
  188. struct clk *biu_clk;
  189. struct clk *ciu_clk;
  190. struct dw_mci_slot *slot[MAX_MCI_SLOTS];
  191. /* FIFO push and pull */
  192. int fifo_depth;
  193. int data_shift;
  194. u8 part_buf_start;
  195. u8 part_buf_count;
  196. union {
  197. u16 part_buf16;
  198. u32 part_buf32;
  199. u64 part_buf;
  200. };
  201. void (*push_data)(struct dw_mci *host, void *buf, int cnt);
  202. void (*pull_data)(struct dw_mci *host, void *buf, int cnt);
  203. bool vqmmc_enabled;
  204. unsigned long irq_flags; /* IRQ flags */
  205. int irq;
  206. int sdio_id0;
  207. struct timer_list cmd11_timer;
  208. struct timer_list dto_timer;
  209. };
  210. /* DMA ops for Internal/External DMAC interface */
  211. struct dw_mci_dma_ops {
  212. /* DMA Ops */
  213. int (*init)(struct dw_mci *host);
  214. int (*start)(struct dw_mci *host, unsigned int sg_len);
  215. void (*complete)(void *host);
  216. void (*stop)(struct dw_mci *host);
  217. void (*cleanup)(struct dw_mci *host);
  218. void (*exit)(struct dw_mci *host);
  219. };
  220. struct dma_pdata;
  221. /* Board platform data */
  222. struct dw_mci_board {
  223. u32 num_slots;
  224. unsigned int bus_hz; /* Clock speed at the cclk_in pad */
  225. u32 caps; /* Capabilities */
  226. u32 caps2; /* More capabilities */
  227. u32 pm_caps; /* PM capabilities */
  228. /*
  229. * Override fifo depth. If 0, autodetect it from the FIFOTH register,
  230. * but note that this may not be reliable after a bootloader has used
  231. * it.
  232. */
  233. unsigned int fifo_depth;
  234. /* delay in mS before detecting cards after interrupt */
  235. u32 detect_delay_ms;
  236. struct reset_control *rstc;
  237. struct dw_mci_dma_ops *dma_ops;
  238. struct dma_pdata *data;
  239. };
  240. #endif /* LINUX_MMC_DW_MMC_H */