sh_mmcif.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * include/linux/mmc/sh_mmcif.h
  3. *
  4. * platform data for eMMC driver
  5. *
  6. * Copyright (C) 2010 Renesas Solutions Corp.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License.
  11. *
  12. */
  13. #ifndef LINUX_MMC_SH_MMCIF_H
  14. #define LINUX_MMC_SH_MMCIF_H
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/sh_dma.h>
  18. /*
  19. * MMCIF : CE_CLK_CTRL [19:16]
  20. * 1000 : Peripheral clock / 512
  21. * 0111 : Peripheral clock / 256
  22. * 0110 : Peripheral clock / 128
  23. * 0101 : Peripheral clock / 64
  24. * 0100 : Peripheral clock / 32
  25. * 0011 : Peripheral clock / 16
  26. * 0010 : Peripheral clock / 8
  27. * 0001 : Peripheral clock / 4
  28. * 0000 : Peripheral clock / 2
  29. * 1111 : Peripheral clock (sup_pclk set '1')
  30. */
  31. struct sh_mmcif_dma {
  32. struct sh_dmae_slave chan_priv_tx;
  33. struct sh_dmae_slave chan_priv_rx;
  34. };
  35. struct sh_mmcif_plat_data {
  36. void (*set_pwr)(struct platform_device *pdev, int state);
  37. void (*down_pwr)(struct platform_device *pdev);
  38. int (*get_cd)(struct platform_device *pdef);
  39. struct sh_mmcif_dma *dma; /* Deprecated. Instead */
  40. unsigned int slave_id_tx; /* use embedded slave_id_[tr]x */
  41. unsigned int slave_id_rx;
  42. u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */
  43. unsigned long caps;
  44. u32 ocr;
  45. };
  46. #define MMCIF_CE_CMD_SET 0x00000000
  47. #define MMCIF_CE_ARG 0x00000008
  48. #define MMCIF_CE_ARG_CMD12 0x0000000C
  49. #define MMCIF_CE_CMD_CTRL 0x00000010
  50. #define MMCIF_CE_BLOCK_SET 0x00000014
  51. #define MMCIF_CE_CLK_CTRL 0x00000018
  52. #define MMCIF_CE_BUF_ACC 0x0000001C
  53. #define MMCIF_CE_RESP3 0x00000020
  54. #define MMCIF_CE_RESP2 0x00000024
  55. #define MMCIF_CE_RESP1 0x00000028
  56. #define MMCIF_CE_RESP0 0x0000002C
  57. #define MMCIF_CE_RESP_CMD12 0x00000030
  58. #define MMCIF_CE_DATA 0x00000034
  59. #define MMCIF_CE_INT 0x00000040
  60. #define MMCIF_CE_INT_MASK 0x00000044
  61. #define MMCIF_CE_HOST_STS1 0x00000048
  62. #define MMCIF_CE_HOST_STS2 0x0000004C
  63. #define MMCIF_CE_VERSION 0x0000007C
  64. /* CE_BUF_ACC */
  65. #define BUF_ACC_DMAWEN (1 << 25)
  66. #define BUF_ACC_DMAREN (1 << 24)
  67. #define BUF_ACC_BUSW_32 (0 << 17)
  68. #define BUF_ACC_BUSW_16 (1 << 17)
  69. #define BUF_ACC_ATYP (1 << 16)
  70. /* CE_CLK_CTRL */
  71. #define CLK_ENABLE (1 << 24) /* 1: output mmc clock */
  72. #define CLK_CLEAR (0xf << 16)
  73. #define CLK_SUP_PCLK (0xf << 16)
  74. #define CLKDIV_4 (1 << 16) /* mmc clock frequency.
  75. * n: bus clock/(2^(n+1)) */
  76. #define CLKDIV_256 (7 << 16) /* mmc clock frequency. (see above) */
  77. #define SRSPTO_256 (2 << 12) /* resp timeout */
  78. #define SRBSYTO_29 (0xf << 8) /* resp busy timeout */
  79. #define SRWDTO_29 (0xf << 4) /* read/write timeout */
  80. #define SCCSTO_29 (0xf << 0) /* ccs timeout */
  81. /* CE_VERSION */
  82. #define SOFT_RST_ON (1 << 31)
  83. #define SOFT_RST_OFF 0
  84. static inline u32 sh_mmcif_readl(void __iomem *addr, int reg)
  85. {
  86. return __raw_readl(addr + reg);
  87. }
  88. static inline void sh_mmcif_writel(void __iomem *addr, int reg, u32 val)
  89. {
  90. __raw_writel(val, addr + reg);
  91. }
  92. #define SH_MMCIF_BBS 512 /* boot block size */
  93. static inline void sh_mmcif_boot_cmd_send(void __iomem *base,
  94. unsigned long cmd, unsigned long arg)
  95. {
  96. sh_mmcif_writel(base, MMCIF_CE_INT, 0);
  97. sh_mmcif_writel(base, MMCIF_CE_ARG, arg);
  98. sh_mmcif_writel(base, MMCIF_CE_CMD_SET, cmd);
  99. }
  100. static inline int sh_mmcif_boot_cmd_poll(void __iomem *base, unsigned long mask)
  101. {
  102. unsigned long tmp;
  103. int cnt;
  104. for (cnt = 0; cnt < 1000000; cnt++) {
  105. tmp = sh_mmcif_readl(base, MMCIF_CE_INT);
  106. if (tmp & mask) {
  107. sh_mmcif_writel(base, MMCIF_CE_INT, tmp & ~mask);
  108. return 0;
  109. }
  110. }
  111. return -1;
  112. }
  113. static inline int sh_mmcif_boot_cmd(void __iomem *base,
  114. unsigned long cmd, unsigned long arg)
  115. {
  116. sh_mmcif_boot_cmd_send(base, cmd, arg);
  117. return sh_mmcif_boot_cmd_poll(base, 0x00010000);
  118. }
  119. static inline int sh_mmcif_boot_do_read_single(void __iomem *base,
  120. unsigned int block_nr,
  121. unsigned long *buf)
  122. {
  123. int k;
  124. /* CMD13 - Status */
  125. sh_mmcif_boot_cmd(base, 0x0d400000, 0x00010000);
  126. if (sh_mmcif_readl(base, MMCIF_CE_RESP0) != 0x0900)
  127. return -1;
  128. /* CMD17 - Read */
  129. sh_mmcif_boot_cmd(base, 0x11480000, block_nr * SH_MMCIF_BBS);
  130. if (sh_mmcif_boot_cmd_poll(base, 0x00100000) < 0)
  131. return -1;
  132. for (k = 0; k < (SH_MMCIF_BBS / 4); k++)
  133. buf[k] = sh_mmcif_readl(base, MMCIF_CE_DATA);
  134. return 0;
  135. }
  136. static inline int sh_mmcif_boot_do_read(void __iomem *base,
  137. unsigned long first_block,
  138. unsigned long nr_blocks,
  139. void *buf)
  140. {
  141. unsigned long k;
  142. int ret = 0;
  143. /* In data transfer mode: Set clock to Bus clock/4 (about 20Mhz) */
  144. sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
  145. CLK_ENABLE | CLKDIV_4 | SRSPTO_256 |
  146. SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
  147. /* CMD9 - Get CSD */
  148. sh_mmcif_boot_cmd(base, 0x09806000, 0x00010000);
  149. /* CMD7 - Select the card */
  150. sh_mmcif_boot_cmd(base, 0x07400000, 0x00010000);
  151. /* CMD16 - Set the block size */
  152. sh_mmcif_boot_cmd(base, 0x10400000, SH_MMCIF_BBS);
  153. for (k = 0; !ret && k < nr_blocks; k++)
  154. ret = sh_mmcif_boot_do_read_single(base, first_block + k,
  155. buf + (k * SH_MMCIF_BBS));
  156. return ret;
  157. }
  158. static inline void sh_mmcif_boot_init(void __iomem *base)
  159. {
  160. /* reset */
  161. sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_ON);
  162. sh_mmcif_writel(base, MMCIF_CE_VERSION, SOFT_RST_OFF);
  163. /* byte swap */
  164. sh_mmcif_writel(base, MMCIF_CE_BUF_ACC, BUF_ACC_ATYP);
  165. /* Set block size in MMCIF hardware */
  166. sh_mmcif_writel(base, MMCIF_CE_BLOCK_SET, SH_MMCIF_BBS);
  167. /* Enable the clock, set it to Bus clock/256 (about 325Khz). */
  168. sh_mmcif_writel(base, MMCIF_CE_CLK_CTRL,
  169. CLK_ENABLE | CLKDIV_256 | SRSPTO_256 |
  170. SRBSYTO_29 | SRWDTO_29 | SCCSTO_29);
  171. /* CMD0 */
  172. sh_mmcif_boot_cmd(base, 0x00000040, 0);
  173. /* CMD1 - Get OCR */
  174. do {
  175. sh_mmcif_boot_cmd(base, 0x01405040, 0x40300000); /* CMD1 */
  176. } while ((sh_mmcif_readl(base, MMCIF_CE_RESP0) & 0x80000000)
  177. != 0x80000000);
  178. /* CMD2 - Get CID */
  179. sh_mmcif_boot_cmd(base, 0x02806040, 0);
  180. /* CMD3 - Set card relative address */
  181. sh_mmcif_boot_cmd(base, 0x03400040, 0x00010000);
  182. }
  183. #endif /* LINUX_MMC_SH_MMCIF_H */