dw_mmc.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. * @sg_dma: Bus address of DMA buffer.
  46. * @sg_cpu: Virtual address of DMA buffer.
  47. * @dma_ops: Pointer to platform-specific DMA callbacks.
  48. * @cmd_status: Snapshot of SR taken upon completion of the current
  49. * command. Only valid when EVENT_CMD_COMPLETE is pending.
  50. * @data_status: Snapshot of SR taken upon completion of the current
  51. * data transfer. Only valid when EVENT_DATA_COMPLETE or
  52. * EVENT_DATA_ERROR is pending.
  53. * @stop_cmdr: Value to be loaded into CMDR when the stop command is
  54. * to be sent.
  55. * @dir_status: Direction of current transfer.
  56. * @tasklet: Tasklet running the request state machine.
  57. * @card_tasklet: Tasklet handling card detect.
  58. * @pending_events: Bitmask of events flagged by the interrupt handler
  59. * to be processed by the tasklet.
  60. * @completed_events: Bitmask of events which the state machine has
  61. * processed.
  62. * @state: Tasklet state.
  63. * @queue: List of slots waiting for access to the controller.
  64. * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus
  65. * rate and timeout calculations.
  66. * @current_speed: Configured rate of the controller.
  67. * @num_slots: Number of slots available.
  68. * @pdev: Platform device associated with the MMC controller.
  69. * @pdata: Platform data associated with the MMC controller.
  70. * @slot: Slots sharing this MMC controller.
  71. * @data_shift: log2 of FIFO item size.
  72. * @push_data: Pointer to FIFO push function.
  73. * @pull_data: Pointer to FIFO pull function.
  74. * @quirks: Set of quirks that apply to specific versions of the IP.
  75. *
  76. * Locking
  77. * =======
  78. *
  79. * @lock is a softirq-safe spinlock protecting @queue as well as
  80. * @cur_slot, @mrq and @state. These must always be updated
  81. * at the same time while holding @lock.
  82. *
  83. * The @mrq field of struct dw_mci_slot is also protected by @lock,
  84. * and must always be written at the same time as the slot is added to
  85. * @queue.
  86. *
  87. * @pending_events and @completed_events are accessed using atomic bit
  88. * operations, so they don't need any locking.
  89. *
  90. * None of the fields touched by the interrupt handler need any
  91. * locking. However, ordering is important: Before EVENT_DATA_ERROR or
  92. * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
  93. * interrupts must be disabled and @data_status updated with a
  94. * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
  95. * CMDRDY interrupt must be disabled and @cmd_status updated with a
  96. * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
  97. * bytes_xfered field of @data must be written. This is ensured by
  98. * using barriers.
  99. */
  100. struct dw_mci {
  101. spinlock_t lock;
  102. void __iomem *regs;
  103. struct scatterlist *sg;
  104. unsigned int pio_offset;
  105. struct dw_mci_slot *cur_slot;
  106. struct mmc_request *mrq;
  107. struct mmc_command *cmd;
  108. struct mmc_data *data;
  109. /* DMA interface members*/
  110. int use_dma;
  111. dma_addr_t sg_dma;
  112. void *sg_cpu;
  113. struct dw_mci_dma_ops *dma_ops;
  114. #ifdef CONFIG_MMC_DW_IDMAC
  115. unsigned int ring_size;
  116. #else
  117. struct dw_mci_dma_data *dma_data;
  118. #endif
  119. u32 cmd_status;
  120. u32 data_status;
  121. u32 stop_cmdr;
  122. u32 dir_status;
  123. struct tasklet_struct tasklet;
  124. struct tasklet_struct card_tasklet;
  125. unsigned long pending_events;
  126. unsigned long completed_events;
  127. enum dw_mci_state state;
  128. struct list_head queue;
  129. u32 bus_hz;
  130. u32 current_speed;
  131. u32 num_slots;
  132. u32 fifoth_val;
  133. struct platform_device *pdev;
  134. struct dw_mci_board *pdata;
  135. struct dw_mci_slot *slot[MAX_MCI_SLOTS];
  136. /* FIFO push and pull */
  137. int data_shift;
  138. void (*push_data)(struct dw_mci *host, void *buf, int cnt);
  139. void (*pull_data)(struct dw_mci *host, void *buf, int cnt);
  140. /* Workaround flags */
  141. u32 quirks;
  142. struct regulator *vmmc; /* Power regulator */
  143. };
  144. /* DMA ops for Internal/External DMAC interface */
  145. struct dw_mci_dma_ops {
  146. /* DMA Ops */
  147. int (*init)(struct dw_mci *host);
  148. void (*start)(struct dw_mci *host, unsigned int sg_len);
  149. void (*complete)(struct dw_mci *host);
  150. void (*stop)(struct dw_mci *host);
  151. void (*cleanup)(struct dw_mci *host);
  152. void (*exit)(struct dw_mci *host);
  153. };
  154. /* IP Quirks/flags. */
  155. /* DTO fix for command transmission with IDMAC configured */
  156. #define DW_MCI_QUIRK_IDMAC_DTO BIT(0)
  157. /* delay needed between retries on some 2.11a implementations */
  158. #define DW_MCI_QUIRK_RETRY_DELAY BIT(1)
  159. /* High Speed Capable - Supports HS cards (up to 50MHz) */
  160. #define DW_MCI_QUIRK_HIGHSPEED BIT(2)
  161. /* Unreliable card detection */
  162. #define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3)
  163. struct dma_pdata;
  164. struct block_settings {
  165. unsigned short max_segs; /* see blk_queue_max_segments */
  166. unsigned int max_blk_size; /* maximum size of one mmc block */
  167. unsigned int max_blk_count; /* maximum number of blocks in one req*/
  168. unsigned int max_req_size; /* maximum number of bytes in one req*/
  169. unsigned int max_seg_size; /* see blk_queue_max_segment_size */
  170. };
  171. /* Board platform data */
  172. struct dw_mci_board {
  173. u32 num_slots;
  174. u32 quirks; /* Workaround / Quirk flags */
  175. unsigned int bus_hz; /* Bus speed */
  176. unsigned int caps; /* Capabilities */
  177. /* delay in mS before detecting cards after interrupt */
  178. u32 detect_delay_ms;
  179. int (*init)(u32 slot_id, irq_handler_t , void *);
  180. int (*get_ro)(u32 slot_id);
  181. int (*get_cd)(u32 slot_id);
  182. int (*get_ocr)(u32 slot_id);
  183. int (*get_bus_wd)(u32 slot_id);
  184. /*
  185. * Enable power to selected slot and set voltage to desired level.
  186. * Voltage levels are specified using MMC_VDD_xxx defines defined
  187. * in linux/mmc/host.h file.
  188. */
  189. void (*setpower)(u32 slot_id, u32 volt);
  190. void (*exit)(u32 slot_id);
  191. void (*select_slot)(u32 slot_id);
  192. struct dw_mci_dma_ops *dma_ops;
  193. struct dma_pdata *data;
  194. struct block_settings *blk_settings;
  195. };
  196. #endif /* _LINUX_MMC_DW_MMC_H_ */