tmio_mmc.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * linux/drivers/mmc/host/tmio_mmc.h
  3. *
  4. * Copyright (C) 2007 Ian Molton
  5. * Copyright (C) 2004 Ian Molton
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Driver for the MMC / SD / SDIO cell found in:
  12. *
  13. * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
  14. */
  15. #ifndef TMIO_MMC_H
  16. #define TMIO_MMC_H
  17. #include <linux/highmem.h>
  18. #include <linux/mmc/tmio.h>
  19. #include <linux/mutex.h>
  20. #include <linux/pagemap.h>
  21. #include <linux/scatterlist.h>
  22. #include <linux/spinlock.h>
  23. /* Definitions for values the CTRL_SDIO_STATUS register can take. */
  24. #define TMIO_SDIO_STAT_IOIRQ 0x0001
  25. #define TMIO_SDIO_STAT_EXPUB52 0x4000
  26. #define TMIO_SDIO_STAT_EXWT 0x8000
  27. #define TMIO_SDIO_MASK_ALL 0xc007
  28. /* Define some IRQ masks */
  29. /* This is the mask used at reset by the chip */
  30. #define TMIO_MASK_ALL 0x837f031d
  31. #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
  32. #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
  33. #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \
  34. TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
  35. #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD)
  36. struct tmio_mmc_data;
  37. /*
  38. * We differentiate between the following 3 power states:
  39. * 1. card slot powered off, controller stopped. This is used, when either there
  40. * is no card in the slot, or the card really has to be powered down.
  41. * 2. card slot powered on, controller stopped. This is used, when a card is in
  42. * the slot, but no activity is currently taking place. This is a power-
  43. * saving mode with card-state preserved. This state can be entered, e.g.
  44. * when MMC clock-gating is used.
  45. * 3. card slot powered on, controller running. This is the actual active state.
  46. */
  47. enum tmio_mmc_power {
  48. TMIO_MMC_OFF_STOP, /* card power off, controller stopped */
  49. TMIO_MMC_ON_STOP, /* card power on, controller stopped */
  50. TMIO_MMC_ON_RUN, /* card power on, controller running */
  51. };
  52. struct tmio_mmc_host {
  53. void __iomem *ctl;
  54. unsigned long bus_shift;
  55. struct mmc_command *cmd;
  56. struct mmc_request *mrq;
  57. struct mmc_data *data;
  58. struct mmc_host *mmc;
  59. /* Controller and card power state */
  60. enum tmio_mmc_power power;
  61. /* Callbacks for clock / power control */
  62. void (*set_pwr)(struct platform_device *host, int state);
  63. void (*set_clk_div)(struct platform_device *host, int state);
  64. /* pio related stuff */
  65. struct scatterlist *sg_ptr;
  66. struct scatterlist *sg_orig;
  67. unsigned int sg_len;
  68. unsigned int sg_off;
  69. struct platform_device *pdev;
  70. struct tmio_mmc_data *pdata;
  71. /* DMA support */
  72. bool force_pio;
  73. struct dma_chan *chan_rx;
  74. struct dma_chan *chan_tx;
  75. struct tasklet_struct dma_complete;
  76. struct tasklet_struct dma_issue;
  77. struct scatterlist bounce_sg;
  78. u8 *bounce_buf;
  79. /* Track lost interrupts */
  80. struct delayed_work delayed_reset_work;
  81. struct work_struct done;
  82. /* Cache IRQ mask */
  83. u32 sdcard_irq_mask;
  84. u32 sdio_irq_mask;
  85. spinlock_t lock; /* protect host private data */
  86. unsigned long last_req_ts;
  87. struct mutex ios_lock; /* protect set_ios() context */
  88. bool native_hotplug;
  89. bool resuming;
  90. };
  91. int tmio_mmc_host_probe(struct tmio_mmc_host **host,
  92. struct platform_device *pdev,
  93. struct tmio_mmc_data *pdata);
  94. void tmio_mmc_host_remove(struct tmio_mmc_host *host);
  95. void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
  96. void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
  97. void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
  98. irqreturn_t tmio_mmc_irq(int irq, void *devid);
  99. irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
  100. irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
  101. irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
  102. static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
  103. unsigned long *flags)
  104. {
  105. local_irq_save(*flags);
  106. return kmap_atomic(sg_page(sg)) + sg->offset;
  107. }
  108. static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg,
  109. unsigned long *flags, void *virt)
  110. {
  111. kunmap_atomic(virt - sg->offset);
  112. local_irq_restore(*flags);
  113. }
  114. #if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE)
  115. void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data);
  116. void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable);
  117. void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata);
  118. void tmio_mmc_release_dma(struct tmio_mmc_host *host);
  119. void tmio_mmc_abort_dma(struct tmio_mmc_host *host);
  120. #else
  121. static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host,
  122. struct mmc_data *data)
  123. {
  124. }
  125. static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
  126. {
  127. }
  128. static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host,
  129. struct tmio_mmc_data *pdata)
  130. {
  131. host->chan_tx = NULL;
  132. host->chan_rx = NULL;
  133. }
  134. static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host)
  135. {
  136. }
  137. static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
  138. {
  139. }
  140. #endif
  141. #ifdef CONFIG_PM
  142. int tmio_mmc_host_suspend(struct device *dev);
  143. int tmio_mmc_host_resume(struct device *dev);
  144. #else
  145. #define tmio_mmc_host_suspend NULL
  146. #define tmio_mmc_host_resume NULL
  147. #endif
  148. int tmio_mmc_host_runtime_suspend(struct device *dev);
  149. int tmio_mmc_host_runtime_resume(struct device *dev);
  150. static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr)
  151. {
  152. return readw(host->ctl + (addr << host->bus_shift));
  153. }
  154. static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
  155. u16 *buf, int count)
  156. {
  157. readsw(host->ctl + (addr << host->bus_shift), buf, count);
  158. }
  159. static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr)
  160. {
  161. return readw(host->ctl + (addr << host->bus_shift)) |
  162. readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
  163. }
  164. static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val)
  165. {
  166. /* If there is a hook and it returns non-zero then there
  167. * is an error and the write should be skipped
  168. */
  169. if (host->pdata->write16_hook && host->pdata->write16_hook(host, addr))
  170. return;
  171. writew(val, host->ctl + (addr << host->bus_shift));
  172. }
  173. static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
  174. u16 *buf, int count)
  175. {
  176. writesw(host->ctl + (addr << host->bus_shift), buf, count);
  177. }
  178. static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val)
  179. {
  180. writew(val, host->ctl + (addr << host->bus_shift));
  181. writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
  182. }
  183. #endif