tmio_mmc.h 5.2 KB

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