tmio_mmc.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. struct tmio_mmc_host {
  38. void __iomem *ctl;
  39. unsigned long bus_shift;
  40. struct mmc_command *cmd;
  41. struct mmc_request *mrq;
  42. struct mmc_data *data;
  43. struct mmc_host *mmc;
  44. /* Controller power state */
  45. bool power;
  46. /* Callbacks for clock / power control */
  47. void (*set_pwr)(struct platform_device *host, int state);
  48. void (*set_clk_div)(struct platform_device *host, int state);
  49. /* pio related stuff */
  50. struct scatterlist *sg_ptr;
  51. struct scatterlist *sg_orig;
  52. unsigned int sg_len;
  53. unsigned int sg_off;
  54. struct platform_device *pdev;
  55. struct tmio_mmc_data *pdata;
  56. /* DMA support */
  57. bool force_pio;
  58. struct dma_chan *chan_rx;
  59. struct dma_chan *chan_tx;
  60. struct tasklet_struct dma_complete;
  61. struct tasklet_struct dma_issue;
  62. struct scatterlist bounce_sg;
  63. u8 *bounce_buf;
  64. /* Track lost interrupts */
  65. struct delayed_work delayed_reset_work;
  66. struct work_struct done;
  67. /* Cache IRQ mask */
  68. u32 sdcard_irq_mask;
  69. u32 sdio_irq_mask;
  70. spinlock_t lock; /* protect host private data */
  71. unsigned long last_req_ts;
  72. struct mutex ios_lock; /* protect set_ios() context */
  73. bool native_hotplug;
  74. };
  75. int tmio_mmc_host_probe(struct tmio_mmc_host **host,
  76. struct platform_device *pdev,
  77. struct tmio_mmc_data *pdata);
  78. void tmio_mmc_host_remove(struct tmio_mmc_host *host);
  79. void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
  80. void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
  81. void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
  82. irqreturn_t tmio_mmc_irq(int irq, void *devid);
  83. irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
  84. irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
  85. irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
  86. static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
  87. unsigned long *flags)
  88. {
  89. local_irq_save(*flags);
  90. return kmap_atomic(sg_page(sg)) + sg->offset;
  91. }
  92. static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg,
  93. unsigned long *flags, void *virt)
  94. {
  95. kunmap_atomic(virt - sg->offset);
  96. local_irq_restore(*flags);
  97. }
  98. #if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE)
  99. void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data);
  100. void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable);
  101. void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata);
  102. void tmio_mmc_release_dma(struct tmio_mmc_host *host);
  103. void tmio_mmc_abort_dma(struct tmio_mmc_host *host);
  104. #else
  105. static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host,
  106. struct mmc_data *data)
  107. {
  108. }
  109. static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
  110. {
  111. }
  112. static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host,
  113. struct tmio_mmc_data *pdata)
  114. {
  115. host->chan_tx = NULL;
  116. host->chan_rx = NULL;
  117. }
  118. static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host)
  119. {
  120. }
  121. static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
  122. {
  123. }
  124. #endif
  125. #ifdef CONFIG_PM
  126. int tmio_mmc_host_suspend(struct device *dev);
  127. int tmio_mmc_host_resume(struct device *dev);
  128. #else
  129. #define tmio_mmc_host_suspend NULL
  130. #define tmio_mmc_host_resume NULL
  131. #endif
  132. int tmio_mmc_host_runtime_suspend(struct device *dev);
  133. int tmio_mmc_host_runtime_resume(struct device *dev);
  134. static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr)
  135. {
  136. return readw(host->ctl + (addr << host->bus_shift));
  137. }
  138. static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
  139. u16 *buf, int count)
  140. {
  141. readsw(host->ctl + (addr << host->bus_shift), buf, count);
  142. }
  143. static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr)
  144. {
  145. return readw(host->ctl + (addr << host->bus_shift)) |
  146. readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
  147. }
  148. static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val)
  149. {
  150. /* If there is a hook and it returns non-zero then there
  151. * is an error and the write should be skipped
  152. */
  153. if (host->pdata->write16_hook && host->pdata->write16_hook(host, addr))
  154. return;
  155. writew(val, host->ctl + (addr << host->bus_shift));
  156. }
  157. static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
  158. u16 *buf, int count)
  159. {
  160. writesw(host->ctl + (addr << host->bus_shift), buf, count);
  161. }
  162. static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val)
  163. {
  164. writew(val, host->ctl + (addr << host->bus_shift));
  165. writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
  166. }
  167. #endif