tmio_mmc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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/dmaengine.h>
  18. #include <linux/highmem.h>
  19. #include <linux/mmc/tmio.h>
  20. #include <linux/mutex.h>
  21. #include <linux/pagemap.h>
  22. #include <linux/scatterlist.h>
  23. #include <linux/spinlock.h>
  24. /* Definitions for values the CTRL_SDIO_STATUS register can take. */
  25. #define TMIO_SDIO_STAT_IOIRQ 0x0001
  26. #define TMIO_SDIO_STAT_EXPUB52 0x4000
  27. #define TMIO_SDIO_STAT_EXWT 0x8000
  28. #define TMIO_SDIO_MASK_ALL 0xc007
  29. /* Define some IRQ masks */
  30. /* This is the mask used at reset by the chip */
  31. #define TMIO_MASK_ALL 0x837f031d
  32. #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
  33. #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
  34. #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \
  35. TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
  36. #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD)
  37. struct tmio_mmc_data;
  38. struct tmio_mmc_host;
  39. struct tmio_mmc_dma {
  40. enum dma_slave_buswidth dma_buswidth;
  41. bool (*filter)(struct dma_chan *chan, void *arg);
  42. void (*enable)(struct tmio_mmc_host *host, bool enable);
  43. };
  44. struct tmio_mmc_host {
  45. void __iomem *ctl;
  46. struct mmc_command *cmd;
  47. struct mmc_request *mrq;
  48. struct mmc_data *data;
  49. struct mmc_host *mmc;
  50. /* Callbacks for clock / power control */
  51. void (*set_pwr)(struct platform_device *host, int state);
  52. void (*set_clk_div)(struct platform_device *host, int state);
  53. /* pio related stuff */
  54. struct scatterlist *sg_ptr;
  55. struct scatterlist *sg_orig;
  56. unsigned int sg_len;
  57. unsigned int sg_off;
  58. unsigned long bus_shift;
  59. struct platform_device *pdev;
  60. struct tmio_mmc_data *pdata;
  61. struct tmio_mmc_dma *dma;
  62. /* DMA support */
  63. bool force_pio;
  64. struct dma_chan *chan_rx;
  65. struct dma_chan *chan_tx;
  66. struct tasklet_struct dma_complete;
  67. struct tasklet_struct dma_issue;
  68. struct scatterlist bounce_sg;
  69. u8 *bounce_buf;
  70. /* Track lost interrupts */
  71. struct delayed_work delayed_reset_work;
  72. struct work_struct done;
  73. /* Cache */
  74. u32 sdcard_irq_mask;
  75. u32 sdio_irq_mask;
  76. unsigned int clk_cache;
  77. spinlock_t lock; /* protect host private data */
  78. unsigned long last_req_ts;
  79. struct mutex ios_lock; /* protect set_ios() context */
  80. bool native_hotplug;
  81. bool sdio_irq_enabled;
  82. int (*write16_hook)(struct tmio_mmc_host *host, int addr);
  83. int (*clk_enable)(struct platform_device *pdev, unsigned int *f);
  84. void (*clk_disable)(struct platform_device *pdev);
  85. int (*multi_io_quirk)(struct mmc_card *card,
  86. unsigned int direction, int blk_size);
  87. };
  88. struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev);
  89. void tmio_mmc_host_free(struct tmio_mmc_host *host);
  90. int tmio_mmc_host_probe(struct tmio_mmc_host *host,
  91. struct tmio_mmc_data *pdata);
  92. void tmio_mmc_host_remove(struct tmio_mmc_host *host);
  93. void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
  94. void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
  95. void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
  96. irqreturn_t tmio_mmc_irq(int irq, void *devid);
  97. irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
  98. irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
  99. irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
  100. static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
  101. unsigned long *flags)
  102. {
  103. local_irq_save(*flags);
  104. return kmap_atomic(sg_page(sg)) + sg->offset;
  105. }
  106. static inline void tmio_mmc_kunmap_atomic(struct scatterlist *sg,
  107. unsigned long *flags, void *virt)
  108. {
  109. kunmap_atomic(virt - sg->offset);
  110. local_irq_restore(*flags);
  111. }
  112. #if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE)
  113. void tmio_mmc_start_dma(struct tmio_mmc_host *host, struct mmc_data *data);
  114. void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable);
  115. void tmio_mmc_request_dma(struct tmio_mmc_host *host, struct tmio_mmc_data *pdata);
  116. void tmio_mmc_release_dma(struct tmio_mmc_host *host);
  117. void tmio_mmc_abort_dma(struct tmio_mmc_host *host);
  118. #else
  119. static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host,
  120. struct mmc_data *data)
  121. {
  122. }
  123. static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
  124. {
  125. }
  126. static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host,
  127. struct tmio_mmc_data *pdata)
  128. {
  129. host->chan_tx = NULL;
  130. host->chan_rx = NULL;
  131. }
  132. static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host)
  133. {
  134. }
  135. static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
  136. {
  137. }
  138. #endif
  139. #ifdef CONFIG_PM
  140. int tmio_mmc_host_runtime_suspend(struct device *dev);
  141. int tmio_mmc_host_runtime_resume(struct device *dev);
  142. #endif
  143. static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr)
  144. {
  145. return readw(host->ctl + (addr << host->bus_shift));
  146. }
  147. static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
  148. u16 *buf, int count)
  149. {
  150. readsw(host->ctl + (addr << host->bus_shift), buf, count);
  151. }
  152. static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr)
  153. {
  154. return readw(host->ctl + (addr << host->bus_shift)) |
  155. readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
  156. }
  157. static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr, u16 val)
  158. {
  159. /* If there is a hook and it returns non-zero then there
  160. * is an error and the write should be skipped
  161. */
  162. if (host->write16_hook && host->write16_hook(host, addr))
  163. return;
  164. writew(val, host->ctl + (addr << host->bus_shift));
  165. }
  166. static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
  167. u16 *buf, int count)
  168. {
  169. writesw(host->ctl + (addr << host->bus_shift), buf, count);
  170. }
  171. static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val)
  172. {
  173. writew(val, host->ctl + (addr << host->bus_shift));
  174. writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
  175. }
  176. #endif