tmio_mmc.h 6.0 KB

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