tmio_mmc.h 5.4 KB

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