tmio_mmc.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* Definitons for use with the tmio_mmc.c
  2. *
  3. * (c) 2004 Ian Molton <spyro@f2s.com>
  4. * (c) 2007 Ian Molton <spyro@f2s.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/highmem.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/dmaengine.h>
  14. #define CTL_SD_CMD 0x00
  15. #define CTL_ARG_REG 0x04
  16. #define CTL_STOP_INTERNAL_ACTION 0x08
  17. #define CTL_XFER_BLK_COUNT 0xa
  18. #define CTL_RESPONSE 0x0c
  19. #define CTL_STATUS 0x1c
  20. #define CTL_IRQ_MASK 0x20
  21. #define CTL_SD_CARD_CLK_CTL 0x24
  22. #define CTL_SD_XFER_LEN 0x26
  23. #define CTL_SD_MEM_CARD_OPT 0x28
  24. #define CTL_SD_ERROR_DETAIL_STATUS 0x2c
  25. #define CTL_SD_DATA_PORT 0x30
  26. #define CTL_TRANSACTION_CTL 0x34
  27. #define CTL_RESET_SD 0xe0
  28. #define CTL_SDIO_REGS 0x100
  29. #define CTL_CLK_AND_WAIT_CTL 0x138
  30. #define CTL_RESET_SDIO 0x1e0
  31. /* Definitions for values the CTRL_STATUS register can take. */
  32. #define TMIO_STAT_CMDRESPEND 0x00000001
  33. #define TMIO_STAT_DATAEND 0x00000004
  34. #define TMIO_STAT_CARD_REMOVE 0x00000008
  35. #define TMIO_STAT_CARD_INSERT 0x00000010
  36. #define TMIO_STAT_SIGSTATE 0x00000020
  37. #define TMIO_STAT_WRPROTECT 0x00000080
  38. #define TMIO_STAT_CARD_REMOVE_A 0x00000100
  39. #define TMIO_STAT_CARD_INSERT_A 0x00000200
  40. #define TMIO_STAT_SIGSTATE_A 0x00000400
  41. #define TMIO_STAT_CMD_IDX_ERR 0x00010000
  42. #define TMIO_STAT_CRCFAIL 0x00020000
  43. #define TMIO_STAT_STOPBIT_ERR 0x00040000
  44. #define TMIO_STAT_DATATIMEOUT 0x00080000
  45. #define TMIO_STAT_RXOVERFLOW 0x00100000
  46. #define TMIO_STAT_TXUNDERRUN 0x00200000
  47. #define TMIO_STAT_CMDTIMEOUT 0x00400000
  48. #define TMIO_STAT_RXRDY 0x01000000
  49. #define TMIO_STAT_TXRQ 0x02000000
  50. #define TMIO_STAT_ILL_FUNC 0x20000000
  51. #define TMIO_STAT_CMD_BUSY 0x40000000
  52. #define TMIO_STAT_ILL_ACCESS 0x80000000
  53. /* Define some IRQ masks */
  54. /* This is the mask used at reset by the chip */
  55. #define TMIO_MASK_ALL 0x837f031d
  56. #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND)
  57. #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND)
  58. #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \
  59. TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
  60. #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD)
  61. #define enable_mmc_irqs(host, i) \
  62. do { \
  63. u32 mask;\
  64. mask = sd_ctrl_read32((host), CTL_IRQ_MASK); \
  65. mask &= ~((i) & TMIO_MASK_IRQ); \
  66. sd_ctrl_write32((host), CTL_IRQ_MASK, mask); \
  67. } while (0)
  68. #define disable_mmc_irqs(host, i) \
  69. do { \
  70. u32 mask;\
  71. mask = sd_ctrl_read32((host), CTL_IRQ_MASK); \
  72. mask |= ((i) & TMIO_MASK_IRQ); \
  73. sd_ctrl_write32((host), CTL_IRQ_MASK, mask); \
  74. } while (0)
  75. #define ack_mmc_irqs(host, i) \
  76. do { \
  77. u32 mask;\
  78. mask = sd_ctrl_read32((host), CTL_STATUS); \
  79. mask &= ~((i) & TMIO_MASK_IRQ); \
  80. sd_ctrl_write32((host), CTL_STATUS, mask); \
  81. } while (0)
  82. struct tmio_mmc_host {
  83. void __iomem *ctl;
  84. unsigned long bus_shift;
  85. struct mmc_command *cmd;
  86. struct mmc_request *mrq;
  87. struct mmc_data *data;
  88. struct mmc_host *mmc;
  89. int irq;
  90. /* Callbacks for clock / power control */
  91. void (*set_pwr)(struct platform_device *host, int state);
  92. void (*set_clk_div)(struct platform_device *host, int state);
  93. /* pio related stuff */
  94. struct scatterlist *sg_ptr;
  95. unsigned int sg_len;
  96. unsigned int sg_off;
  97. struct platform_device *pdev;
  98. /* DMA support */
  99. struct dma_chan *chan_rx;
  100. struct dma_chan *chan_tx;
  101. struct tasklet_struct dma_complete;
  102. struct tasklet_struct dma_issue;
  103. #ifdef CONFIG_TMIO_MMC_DMA
  104. struct dma_async_tx_descriptor *desc;
  105. unsigned int dma_sglen;
  106. dma_cookie_t cookie;
  107. #endif
  108. };
  109. #include <linux/io.h>
  110. static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr)
  111. {
  112. return readw(host->ctl + (addr << host->bus_shift));
  113. }
  114. static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
  115. u16 *buf, int count)
  116. {
  117. readsw(host->ctl + (addr << host->bus_shift), buf, count);
  118. }
  119. static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr)
  120. {
  121. return readw(host->ctl + (addr << host->bus_shift)) |
  122. readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
  123. }
  124. static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr,
  125. u16 val)
  126. {
  127. writew(val, host->ctl + (addr << host->bus_shift));
  128. }
  129. static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
  130. u16 *buf, int count)
  131. {
  132. writesw(host->ctl + (addr << host->bus_shift), buf, count);
  133. }
  134. static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr,
  135. u32 val)
  136. {
  137. writew(val, host->ctl + (addr << host->bus_shift));
  138. writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
  139. }
  140. #include <linux/scatterlist.h>
  141. #include <linux/blkdev.h>
  142. static inline void tmio_mmc_init_sg(struct tmio_mmc_host *host,
  143. struct mmc_data *data)
  144. {
  145. host->sg_len = data->sg_len;
  146. host->sg_ptr = data->sg;
  147. host->sg_off = 0;
  148. }
  149. static inline int tmio_mmc_next_sg(struct tmio_mmc_host *host)
  150. {
  151. host->sg_ptr = sg_next(host->sg_ptr);
  152. host->sg_off = 0;
  153. return --host->sg_len;
  154. }
  155. static inline char *tmio_mmc_kmap_atomic(struct tmio_mmc_host *host,
  156. unsigned long *flags)
  157. {
  158. struct scatterlist *sg = host->sg_ptr;
  159. local_irq_save(*flags);
  160. return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
  161. }
  162. static inline void tmio_mmc_kunmap_atomic(struct tmio_mmc_host *host,
  163. unsigned long *flags)
  164. {
  165. kunmap_atomic(sg_page(host->sg_ptr), KM_BIO_SRC_IRQ);
  166. local_irq_restore(*flags);
  167. }
  168. #ifdef CONFIG_MMC_DEBUG
  169. #define STATUS_TO_TEXT(a) \
  170. do { \
  171. if (status & TMIO_STAT_##a) \
  172. printk(#a); \
  173. } while (0)
  174. void pr_debug_status(u32 status)
  175. {
  176. printk(KERN_DEBUG "status: %08x = ", status);
  177. STATUS_TO_TEXT(CARD_REMOVE);
  178. STATUS_TO_TEXT(CARD_INSERT);
  179. STATUS_TO_TEXT(SIGSTATE);
  180. STATUS_TO_TEXT(WRPROTECT);
  181. STATUS_TO_TEXT(CARD_REMOVE_A);
  182. STATUS_TO_TEXT(CARD_INSERT_A);
  183. STATUS_TO_TEXT(SIGSTATE_A);
  184. STATUS_TO_TEXT(CMD_IDX_ERR);
  185. STATUS_TO_TEXT(STOPBIT_ERR);
  186. STATUS_TO_TEXT(ILL_FUNC);
  187. STATUS_TO_TEXT(CMD_BUSY);
  188. STATUS_TO_TEXT(CMDRESPEND);
  189. STATUS_TO_TEXT(DATAEND);
  190. STATUS_TO_TEXT(CRCFAIL);
  191. STATUS_TO_TEXT(DATATIMEOUT);
  192. STATUS_TO_TEXT(CMDTIMEOUT);
  193. STATUS_TO_TEXT(RXOVERFLOW);
  194. STATUS_TO_TEXT(TXUNDERRUN);
  195. STATUS_TO_TEXT(RXRDY);
  196. STATUS_TO_TEXT(TXRQ);
  197. STATUS_TO_TEXT(ILL_ACCESS);
  198. printk("\n");
  199. }
  200. #else
  201. #define pr_debug_status(s) do { } while (0)
  202. #endif