dw_mmc.h 7.9 KB

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