dw_mmc.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. #define MAX_MCI_SLOTS 2
  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. EVENT_XFER_ERROR
  34. };
  35. struct mmc_data;
  36. /**
  37. * struct dw_mci - MMC controller state shared between all slots
  38. * @lock: Spinlock protecting the queue and associated data.
  39. * @regs: Pointer to MMIO registers.
  40. * @sg: Scatterlist entry currently being processed by PIO code, if any.
  41. * @sg_miter: PIO mapping scatterlist iterator.
  42. * @cur_slot: The slot which is currently using the controller.
  43. * @mrq: The request currently being processed on @cur_slot,
  44. * or NULL if the controller is idle.
  45. * @cmd: The command currently being sent to the card, or NULL.
  46. * @data: The data currently being transferred, or NULL if no data
  47. * transfer is in progress.
  48. * @use_dma: Whether DMA channel is initialized or not.
  49. * @using_dma: Whether DMA is in use for the current transfer.
  50. * @sg_dma: Bus address of DMA buffer.
  51. * @sg_cpu: Virtual address of DMA buffer.
  52. * @dma_ops: Pointer to platform-specific DMA callbacks.
  53. * @cmd_status: Snapshot of SR taken upon completion of the current
  54. * command. Only valid when EVENT_CMD_COMPLETE is pending.
  55. * @data_status: Snapshot of SR taken upon completion of the current
  56. * data transfer. Only valid when EVENT_DATA_COMPLETE or
  57. * EVENT_DATA_ERROR is pending.
  58. * @stop_cmdr: Value to be loaded into CMDR when the stop command is
  59. * to be sent.
  60. * @dir_status: Direction of current transfer.
  61. * @tasklet: Tasklet running the request state machine.
  62. * @card_tasklet: Tasklet handling card detect.
  63. * @pending_events: Bitmask of events flagged by the interrupt handler
  64. * to be processed by the tasklet.
  65. * @completed_events: Bitmask of events which the state machine has
  66. * processed.
  67. * @state: Tasklet state.
  68. * @queue: List of slots waiting for access to the controller.
  69. * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus
  70. * rate and timeout calculations.
  71. * @current_speed: Configured rate of the controller.
  72. * @num_slots: Number of slots available.
  73. * @verid: Denote Version ID.
  74. * @data_offset: Set the offset of DATA register according to VERID.
  75. * @dev: Device associated with the MMC controller.
  76. * @pdata: Platform data associated with the MMC controller.
  77. * @drv_data: Driver specific data for identified variant of the controller
  78. * @priv: Implementation defined private data.
  79. * @biu_clk: Pointer to bus interface unit clock instance.
  80. * @ciu_clk: Pointer to card interface unit clock instance.
  81. * @slot: Slots sharing this MMC controller.
  82. * @fifo_depth: depth of FIFO.
  83. * @data_shift: log2 of FIFO item size.
  84. * @part_buf_start: Start index in part_buf.
  85. * @part_buf_count: Bytes of partial data in part_buf.
  86. * @part_buf: Simple buffer for partial fifo reads/writes.
  87. * @push_data: Pointer to FIFO push function.
  88. * @pull_data: Pointer to FIFO pull function.
  89. * @quirks: Set of quirks that apply to specific versions of the IP.
  90. * @irq_flags: The flags to be passed to request_irq.
  91. * @irq: The irq value to be passed to request_irq.
  92. *
  93. * Locking
  94. * =======
  95. *
  96. * @lock is a softirq-safe spinlock protecting @queue as well as
  97. * @cur_slot, @mrq and @state. These must always be updated
  98. * at the same time while holding @lock.
  99. *
  100. * The @mrq field of struct dw_mci_slot is also protected by @lock,
  101. * and must always be written at the same time as the slot is added to
  102. * @queue.
  103. *
  104. * @pending_events and @completed_events are accessed using atomic bit
  105. * operations, so they don't need any locking.
  106. *
  107. * None of the fields touched by the interrupt handler need any
  108. * locking. However, ordering is important: Before EVENT_DATA_ERROR or
  109. * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
  110. * interrupts must be disabled and @data_status updated with a
  111. * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
  112. * CMDRDY interrupt must be disabled and @cmd_status updated with a
  113. * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
  114. * bytes_xfered field of @data must be written. This is ensured by
  115. * using barriers.
  116. */
  117. struct dw_mci {
  118. spinlock_t lock;
  119. void __iomem *regs;
  120. struct scatterlist *sg;
  121. struct sg_mapping_iter sg_miter;
  122. struct dw_mci_slot *cur_slot;
  123. struct mmc_request *mrq;
  124. struct mmc_command *cmd;
  125. struct mmc_data *data;
  126. struct mmc_command stop_abort;
  127. unsigned int prev_blksz;
  128. unsigned char timing;
  129. struct workqueue_struct *card_workqueue;
  130. /* DMA interface members*/
  131. int use_dma;
  132. int using_dma;
  133. dma_addr_t sg_dma;
  134. void *sg_cpu;
  135. const struct dw_mci_dma_ops *dma_ops;
  136. #ifdef CONFIG_MMC_DW_IDMAC
  137. unsigned int ring_size;
  138. #else
  139. struct dw_mci_dma_data *dma_data;
  140. #endif
  141. u32 cmd_status;
  142. u32 data_status;
  143. u32 stop_cmdr;
  144. u32 dir_status;
  145. struct tasklet_struct tasklet;
  146. struct work_struct card_work;
  147. unsigned long pending_events;
  148. unsigned long completed_events;
  149. enum dw_mci_state state;
  150. struct list_head queue;
  151. u32 bus_hz;
  152. u32 current_speed;
  153. u32 num_slots;
  154. u32 fifoth_val;
  155. u16 verid;
  156. u16 data_offset;
  157. struct device *dev;
  158. struct dw_mci_board *pdata;
  159. const struct dw_mci_drv_data *drv_data;
  160. void *priv;
  161. struct clk *biu_clk;
  162. struct clk *ciu_clk;
  163. struct dw_mci_slot *slot[MAX_MCI_SLOTS];
  164. /* FIFO push and pull */
  165. int fifo_depth;
  166. int data_shift;
  167. u8 part_buf_start;
  168. u8 part_buf_count;
  169. union {
  170. u16 part_buf16;
  171. u32 part_buf32;
  172. u64 part_buf;
  173. };
  174. void (*push_data)(struct dw_mci *host, void *buf, int cnt);
  175. void (*pull_data)(struct dw_mci *host, void *buf, int cnt);
  176. /* Workaround flags */
  177. u32 quirks;
  178. bool vqmmc_enabled;
  179. unsigned long irq_flags; /* IRQ flags */
  180. int irq;
  181. };
  182. /* DMA ops for Internal/External DMAC interface */
  183. struct dw_mci_dma_ops {
  184. /* DMA Ops */
  185. int (*init)(struct dw_mci *host);
  186. void (*start)(struct dw_mci *host, unsigned int sg_len);
  187. void (*complete)(struct dw_mci *host);
  188. void (*stop)(struct dw_mci *host);
  189. void (*cleanup)(struct dw_mci *host);
  190. void (*exit)(struct dw_mci *host);
  191. };
  192. /* IP Quirks/flags. */
  193. /* DTO fix for command transmission with IDMAC configured */
  194. #define DW_MCI_QUIRK_IDMAC_DTO BIT(0)
  195. /* delay needed between retries on some 2.11a implementations */
  196. #define DW_MCI_QUIRK_RETRY_DELAY BIT(1)
  197. /* High Speed Capable - Supports HS cards (up to 50MHz) */
  198. #define DW_MCI_QUIRK_HIGHSPEED BIT(2)
  199. /* Unreliable card detection */
  200. #define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3)
  201. /* No write protect */
  202. #define DW_MCI_QUIRK_NO_WRITE_PROTECT BIT(4)
  203. /* Slot level quirks */
  204. /* This slot has no write protect */
  205. #define DW_MCI_SLOT_QUIRK_NO_WRITE_PROTECT BIT(0)
  206. struct dma_pdata;
  207. struct block_settings {
  208. unsigned short max_segs; /* see blk_queue_max_segments */
  209. unsigned int max_blk_size; /* maximum size of one mmc block */
  210. unsigned int max_blk_count; /* maximum number of blocks in one req*/
  211. unsigned int max_req_size; /* maximum number of bytes in one req*/
  212. unsigned int max_seg_size; /* see blk_queue_max_segment_size */
  213. };
  214. /* Board platform data */
  215. struct dw_mci_board {
  216. u32 num_slots;
  217. u32 quirks; /* Workaround / Quirk flags */
  218. unsigned int bus_hz; /* Clock speed at the cclk_in pad */
  219. u32 caps; /* Capabilities */
  220. u32 caps2; /* More capabilities */
  221. u32 pm_caps; /* PM capabilities */
  222. /*
  223. * Override fifo depth. If 0, autodetect it from the FIFOTH register,
  224. * but note that this may not be reliable after a bootloader has used
  225. * it.
  226. */
  227. unsigned int fifo_depth;
  228. /* delay in mS before detecting cards after interrupt */
  229. u32 detect_delay_ms;
  230. struct dw_mci_dma_ops *dma_ops;
  231. struct dma_pdata *data;
  232. struct block_settings *blk_settings;
  233. };
  234. #endif /* LINUX_MMC_DW_MMC_H */