dw_mmc.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. * @pdev: Platform device associated with the MMC controller.
  70. * @pdata: Platform data associated with the MMC controller.
  71. * @slot: Slots sharing this MMC controller.
  72. * @fifo_depth: depth of FIFO.
  73. * @data_shift: log2 of FIFO item size.
  74. * @part_buf_start: Start index in part_buf.
  75. * @part_buf_count: Bytes of partial data in part_buf.
  76. * @part_buf: Simple buffer for partial fifo reads/writes.
  77. * @push_data: Pointer to FIFO push function.
  78. * @pull_data: Pointer to FIFO pull function.
  79. * @quirks: Set of quirks that apply to specific versions of the IP.
  80. *
  81. * Locking
  82. * =======
  83. *
  84. * @lock is a softirq-safe spinlock protecting @queue as well as
  85. * @cur_slot, @mrq and @state. These must always be updated
  86. * at the same time while holding @lock.
  87. *
  88. * The @mrq field of struct dw_mci_slot is also protected by @lock,
  89. * and must always be written at the same time as the slot is added to
  90. * @queue.
  91. *
  92. * @pending_events and @completed_events are accessed using atomic bit
  93. * operations, so they don't need any locking.
  94. *
  95. * None of the fields touched by the interrupt handler need any
  96. * locking. However, ordering is important: Before EVENT_DATA_ERROR or
  97. * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
  98. * interrupts must be disabled and @data_status updated with a
  99. * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
  100. * CMDRDY interrupt must be disabled and @cmd_status updated with a
  101. * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
  102. * bytes_xfered field of @data must be written. This is ensured by
  103. * using barriers.
  104. */
  105. struct dw_mci {
  106. spinlock_t lock;
  107. void __iomem *regs;
  108. struct scatterlist *sg;
  109. unsigned int pio_offset;
  110. struct dw_mci_slot *cur_slot;
  111. struct mmc_request *mrq;
  112. struct mmc_command *cmd;
  113. struct mmc_data *data;
  114. /* DMA interface members*/
  115. int use_dma;
  116. int using_dma;
  117. dma_addr_t sg_dma;
  118. void *sg_cpu;
  119. struct dw_mci_dma_ops *dma_ops;
  120. #ifdef CONFIG_MMC_DW_IDMAC
  121. unsigned int ring_size;
  122. #else
  123. struct dw_mci_dma_data *dma_data;
  124. #endif
  125. u32 cmd_status;
  126. u32 data_status;
  127. u32 stop_cmdr;
  128. u32 dir_status;
  129. struct tasklet_struct tasklet;
  130. struct work_struct card_work;
  131. unsigned long pending_events;
  132. unsigned long completed_events;
  133. enum dw_mci_state state;
  134. struct list_head queue;
  135. u32 bus_hz;
  136. u32 current_speed;
  137. u32 num_slots;
  138. u32 fifoth_val;
  139. struct platform_device *pdev;
  140. struct dw_mci_board *pdata;
  141. struct dw_mci_slot *slot[MAX_MCI_SLOTS];
  142. /* FIFO push and pull */
  143. int fifo_depth;
  144. int data_shift;
  145. u8 part_buf_start;
  146. u8 part_buf_count;
  147. union {
  148. u16 part_buf16;
  149. u32 part_buf32;
  150. u64 part_buf;
  151. };
  152. void (*push_data)(struct dw_mci *host, void *buf, int cnt);
  153. void (*pull_data)(struct dw_mci *host, void *buf, int cnt);
  154. /* Workaround flags */
  155. u32 quirks;
  156. struct regulator *vmmc; /* Power regulator */
  157. };
  158. /* DMA ops for Internal/External DMAC interface */
  159. struct dw_mci_dma_ops {
  160. /* DMA Ops */
  161. int (*init)(struct dw_mci *host);
  162. void (*start)(struct dw_mci *host, unsigned int sg_len);
  163. void (*complete)(struct dw_mci *host);
  164. void (*stop)(struct dw_mci *host);
  165. void (*cleanup)(struct dw_mci *host);
  166. void (*exit)(struct dw_mci *host);
  167. };
  168. /* IP Quirks/flags. */
  169. /* DTO fix for command transmission with IDMAC configured */
  170. #define DW_MCI_QUIRK_IDMAC_DTO BIT(0)
  171. /* delay needed between retries on some 2.11a implementations */
  172. #define DW_MCI_QUIRK_RETRY_DELAY BIT(1)
  173. /* High Speed Capable - Supports HS cards (up to 50MHz) */
  174. #define DW_MCI_QUIRK_HIGHSPEED BIT(2)
  175. /* Unreliable card detection */
  176. #define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3)
  177. struct dma_pdata;
  178. struct block_settings {
  179. unsigned short max_segs; /* see blk_queue_max_segments */
  180. unsigned int max_blk_size; /* maximum size of one mmc block */
  181. unsigned int max_blk_count; /* maximum number of blocks in one req*/
  182. unsigned int max_req_size; /* maximum number of bytes in one req*/
  183. unsigned int max_seg_size; /* see blk_queue_max_segment_size */
  184. };
  185. /* Board platform data */
  186. struct dw_mci_board {
  187. u32 num_slots;
  188. u32 quirks; /* Workaround / Quirk flags */
  189. unsigned int bus_hz; /* Bus speed */
  190. unsigned int caps; /* Capabilities */
  191. /*
  192. * Override fifo depth. If 0, autodetect it from the FIFOTH register,
  193. * but note that this may not be reliable after a bootloader has used
  194. * it.
  195. */
  196. unsigned int fifo_depth;
  197. /* delay in mS before detecting cards after interrupt */
  198. u32 detect_delay_ms;
  199. int (*init)(u32 slot_id, irq_handler_t , void *);
  200. int (*get_ro)(u32 slot_id);
  201. int (*get_cd)(u32 slot_id);
  202. int (*get_ocr)(u32 slot_id);
  203. int (*get_bus_wd)(u32 slot_id);
  204. /*
  205. * Enable power to selected slot and set voltage to desired level.
  206. * Voltage levels are specified using MMC_VDD_xxx defines defined
  207. * in linux/mmc/host.h file.
  208. */
  209. void (*setpower)(u32 slot_id, u32 volt);
  210. void (*exit)(u32 slot_id);
  211. void (*select_slot)(u32 slot_id);
  212. struct dw_mci_dma_ops *dma_ops;
  213. struct dma_pdata *data;
  214. struct block_settings *blk_settings;
  215. };
  216. #endif /* LINUX_MMC_DW_MMC_H */