tmio_mmc.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. #define CNF_CMD 0x04
  13. #define CNF_CTL_BASE 0x10
  14. #define CNF_INT_PIN 0x3d
  15. #define CNF_STOP_CLK_CTL 0x40
  16. #define CNF_GCLK_CTL 0x41
  17. #define CNF_SD_CLK_MODE 0x42
  18. #define CNF_PIN_STATUS 0x44
  19. #define CNF_PWR_CTL_1 0x48
  20. #define CNF_PWR_CTL_2 0x49
  21. #define CNF_PWR_CTL_3 0x4a
  22. #define CNF_CARD_DETECT_MODE 0x4c
  23. #define CNF_SD_SLOT 0x50
  24. #define CNF_EXT_GCLK_CTL_1 0xf0
  25. #define CNF_EXT_GCLK_CTL_2 0xf1
  26. #define CNF_EXT_GCLK_CTL_3 0xf9
  27. #define CNF_SD_LED_EN_1 0xfa
  28. #define CNF_SD_LED_EN_2 0xfe
  29. #define SDCREN 0x2 /* Enable access to MMC CTL regs. (flag in COMMAND_REG)*/
  30. #define CTL_SD_CMD 0x00
  31. #define CTL_ARG_REG 0x04
  32. #define CTL_STOP_INTERNAL_ACTION 0x08
  33. #define CTL_XFER_BLK_COUNT 0xa
  34. #define CTL_RESPONSE 0x0c
  35. #define CTL_STATUS 0x1c
  36. #define CTL_IRQ_MASK 0x20
  37. #define CTL_SD_CARD_CLK_CTL 0x24
  38. #define CTL_SD_XFER_LEN 0x26
  39. #define CTL_SD_MEM_CARD_OPT 0x28
  40. #define CTL_SD_ERROR_DETAIL_STATUS 0x2c
  41. #define CTL_SD_DATA_PORT 0x30
  42. #define CTL_TRANSACTION_CTL 0x34
  43. #define CTL_RESET_SD 0xe0
  44. #define CTL_SDIO_REGS 0x100
  45. #define CTL_CLK_AND_WAIT_CTL 0x138
  46. #define CTL_RESET_SDIO 0x1e0
  47. /* Definitions for values the CTRL_STATUS register can take. */
  48. #define TMIO_STAT_CMDRESPEND 0x00000001
  49. #define TMIO_STAT_DATAEND 0x00000004
  50. #define TMIO_STAT_CARD_REMOVE 0x00000008
  51. #define TMIO_STAT_CARD_INSERT 0x00000010
  52. #define TMIO_STAT_SIGSTATE 0x00000020
  53. #define TMIO_STAT_WRPROTECT 0x00000080
  54. #define TMIO_STAT_CARD_REMOVE_A 0x00000100
  55. #define TMIO_STAT_CARD_INSERT_A 0x00000200
  56. #define TMIO_STAT_SIGSTATE_A 0x00000400
  57. #define TMIO_STAT_CMD_IDX_ERR 0x00010000
  58. #define TMIO_STAT_CRCFAIL 0x00020000
  59. #define TMIO_STAT_STOPBIT_ERR 0x00040000
  60. #define TMIO_STAT_DATATIMEOUT 0x00080000
  61. #define TMIO_STAT_RXOVERFLOW 0x00100000
  62. #define TMIO_STAT_TXUNDERRUN 0x00200000
  63. #define TMIO_STAT_CMDTIMEOUT 0x00400000
  64. #define TMIO_STAT_RXRDY 0x01000000
  65. #define TMIO_STAT_TXRQ 0x02000000
  66. #define TMIO_STAT_ILL_FUNC 0x20000000
  67. #define TMIO_STAT_CMD_BUSY 0x40000000
  68. #define TMIO_STAT_ILL_ACCESS 0x80000000
  69. /* Define some IRQ masks */
  70. /* This is the mask used at reset by the chip */
  71. #define TMIO_MASK_ALL 0x837f031d
  72. #define TMIO_MASK_READOP (TMIO_STAT_RXRDY | TMIO_STAT_DATAEND | \
  73. TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
  74. #define TMIO_MASK_WRITEOP (TMIO_STAT_TXRQ | TMIO_STAT_DATAEND | \
  75. TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
  76. #define TMIO_MASK_CMD (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT | \
  77. TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT)
  78. #define TMIO_MASK_IRQ (TMIO_MASK_READOP | TMIO_MASK_WRITEOP | TMIO_MASK_CMD)
  79. #define enable_mmc_irqs(host, i) \
  80. do { \
  81. u32 mask;\
  82. mask = sd_ctrl_read32((host), CTL_IRQ_MASK); \
  83. mask &= ~((i) & TMIO_MASK_IRQ); \
  84. sd_ctrl_write32((host), CTL_IRQ_MASK, mask); \
  85. } while (0)
  86. #define disable_mmc_irqs(host, i) \
  87. do { \
  88. u32 mask;\
  89. mask = sd_ctrl_read32((host), CTL_IRQ_MASK); \
  90. mask |= ((i) & TMIO_MASK_IRQ); \
  91. sd_ctrl_write32((host), CTL_IRQ_MASK, mask); \
  92. } while (0)
  93. #define ack_mmc_irqs(host, i) \
  94. do { \
  95. u32 mask;\
  96. mask = sd_ctrl_read32((host), CTL_STATUS); \
  97. mask &= ~((i) & TMIO_MASK_IRQ); \
  98. sd_ctrl_write32((host), CTL_STATUS, mask); \
  99. } while (0)
  100. struct tmio_mmc_host {
  101. void __iomem *cnf;
  102. void __iomem *ctl;
  103. unsigned long bus_shift;
  104. struct mmc_command *cmd;
  105. struct mmc_request *mrq;
  106. struct mmc_data *data;
  107. struct mmc_host *mmc;
  108. int irq;
  109. /* pio related stuff */
  110. struct scatterlist *sg_ptr;
  111. unsigned int sg_len;
  112. unsigned int sg_off;
  113. };
  114. #include <linux/io.h>
  115. static inline u16 sd_ctrl_read16(struct tmio_mmc_host *host, int addr)
  116. {
  117. return readw(host->ctl + (addr << host->bus_shift));
  118. }
  119. static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
  120. u16 *buf, int count)
  121. {
  122. readsw(host->ctl + (addr << host->bus_shift), buf, count);
  123. }
  124. static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr)
  125. {
  126. return readw(host->ctl + (addr << host->bus_shift)) |
  127. readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
  128. }
  129. static inline void sd_ctrl_write16(struct tmio_mmc_host *host, int addr,
  130. u16 val)
  131. {
  132. writew(val, host->ctl + (addr << host->bus_shift));
  133. }
  134. static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
  135. u16 *buf, int count)
  136. {
  137. writesw(host->ctl + (addr << host->bus_shift), buf, count);
  138. }
  139. static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr,
  140. u32 val)
  141. {
  142. writew(val, host->ctl + (addr << host->bus_shift));
  143. writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
  144. }
  145. static inline void sd_config_write8(struct tmio_mmc_host *host, int addr,
  146. u8 val)
  147. {
  148. writeb(val, host->cnf + (addr << host->bus_shift));
  149. }
  150. static inline void sd_config_write16(struct tmio_mmc_host *host, int addr,
  151. u16 val)
  152. {
  153. writew(val, host->cnf + (addr << host->bus_shift));
  154. }
  155. static inline void sd_config_write32(struct tmio_mmc_host *host, int addr,
  156. u32 val)
  157. {
  158. writew(val, host->cnf + (addr << host->bus_shift));
  159. writew(val >> 16, host->cnf + ((addr + 2) << host->bus_shift));
  160. }
  161. #include <linux/scatterlist.h>
  162. #include <linux/blkdev.h>
  163. static inline void tmio_mmc_init_sg(struct tmio_mmc_host *host,
  164. struct mmc_data *data)
  165. {
  166. host->sg_len = data->sg_len;
  167. host->sg_ptr = data->sg;
  168. host->sg_off = 0;
  169. }
  170. static inline int tmio_mmc_next_sg(struct tmio_mmc_host *host)
  171. {
  172. host->sg_ptr = sg_next(host->sg_ptr);
  173. host->sg_off = 0;
  174. return --host->sg_len;
  175. }
  176. static inline char *tmio_mmc_kmap_atomic(struct tmio_mmc_host *host,
  177. unsigned long *flags)
  178. {
  179. struct scatterlist *sg = host->sg_ptr;
  180. local_irq_save(*flags);
  181. return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
  182. }
  183. static inline void tmio_mmc_kunmap_atomic(struct tmio_mmc_host *host,
  184. unsigned long *flags)
  185. {
  186. kunmap_atomic(sg_page(host->sg_ptr), KM_BIO_SRC_IRQ);
  187. local_irq_restore(*flags);
  188. }
  189. #ifdef CONFIG_MMC_DEBUG
  190. #define STATUS_TO_TEXT(a) \
  191. do { \
  192. if (status & TMIO_STAT_##a) \
  193. printk(#a); \
  194. } while (0)
  195. void pr_debug_status(u32 status)
  196. {
  197. printk(KERN_DEBUG "status: %08x = ", status);
  198. STATUS_TO_TEXT(CARD_REMOVE);
  199. STATUS_TO_TEXT(CARD_INSERT);
  200. STATUS_TO_TEXT(SIGSTATE);
  201. STATUS_TO_TEXT(WRPROTECT);
  202. STATUS_TO_TEXT(CARD_REMOVE_A);
  203. STATUS_TO_TEXT(CARD_INSERT_A);
  204. STATUS_TO_TEXT(SIGSTATE_A);
  205. STATUS_TO_TEXT(CMD_IDX_ERR);
  206. STATUS_TO_TEXT(STOPBIT_ERR);
  207. STATUS_TO_TEXT(ILL_FUNC);
  208. STATUS_TO_TEXT(CMD_BUSY);
  209. STATUS_TO_TEXT(CMDRESPEND);
  210. STATUS_TO_TEXT(DATAEND);
  211. STATUS_TO_TEXT(CRCFAIL);
  212. STATUS_TO_TEXT(DATATIMEOUT);
  213. STATUS_TO_TEXT(CMDTIMEOUT);
  214. STATUS_TO_TEXT(RXOVERFLOW);
  215. STATUS_TO_TEXT(TXUNDERRUN);
  216. STATUS_TO_TEXT(RXRDY);
  217. STATUS_TO_TEXT(TXRQ);
  218. STATUS_TO_TEXT(ILL_ACCESS);
  219. printk("\n");
  220. }
  221. #else
  222. #define pr_debug_status(s) do { } while (0)
  223. #endif