dw_mmc.h 7.7 KB

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