sh_mmcif.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * MMCIF driver.
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0
  7. */
  8. #ifndef _SH_MMCIF_H_
  9. #define _SH_MMCIF_H_
  10. struct sh_mmcif_regs {
  11. unsigned long ce_cmd_set;
  12. unsigned long reserved;
  13. unsigned long ce_arg;
  14. unsigned long ce_arg_cmd12;
  15. unsigned long ce_cmd_ctrl;
  16. unsigned long ce_block_set;
  17. unsigned long ce_clk_ctrl;
  18. unsigned long ce_buf_acc;
  19. unsigned long ce_resp3;
  20. unsigned long ce_resp2;
  21. unsigned long ce_resp1;
  22. unsigned long ce_resp0;
  23. unsigned long ce_resp_cmd12;
  24. unsigned long ce_data;
  25. unsigned long reserved2[2];
  26. unsigned long ce_int;
  27. unsigned long ce_int_mask;
  28. unsigned long ce_host_sts1;
  29. unsigned long ce_host_sts2;
  30. unsigned long reserved3[11];
  31. unsigned long ce_version;
  32. };
  33. /* CE_CMD_SET */
  34. #define CMD_MASK 0x3f000000
  35. #define CMD_SET_RTYP_NO ((0 << 23) | (0 << 22))
  36. /* R1/R1b/R3/R4/R5 */
  37. #define CMD_SET_RTYP_6B ((0 << 23) | (1 << 22))
  38. /* R2 */
  39. #define CMD_SET_RTYP_17B ((1 << 23) | (0 << 22))
  40. /* R1b */
  41. #define CMD_SET_RBSY (1 << 21)
  42. #define CMD_SET_CCSEN (1 << 20)
  43. /* 1: on data, 0: no data */
  44. #define CMD_SET_WDAT (1 << 19)
  45. /* 1: write to card, 0: read from card */
  46. #define CMD_SET_DWEN (1 << 18)
  47. /* 1: multi block trans, 0: single */
  48. #define CMD_SET_CMLTE (1 << 17)
  49. /* 1: CMD12 auto issue */
  50. #define CMD_SET_CMD12EN (1 << 16)
  51. /* index check */
  52. #define CMD_SET_RIDXC_INDEX ((0 << 15) | (0 << 14))
  53. /* check bits check */
  54. #define CMD_SET_RIDXC_BITS ((0 << 15) | (1 << 14))
  55. /* no check */
  56. #define CMD_SET_RIDXC_NO ((1 << 15) | (0 << 14))
  57. /* 1: CRC7 check*/
  58. #define CMD_SET_CRC7C ((0 << 13) | (0 << 12))
  59. /* 1: check bits check*/
  60. #define CMD_SET_CRC7C_BITS ((0 << 13) | (1 << 12))
  61. /* 1: internal CRC7 check*/
  62. #define CMD_SET_CRC7C_INTERNAL ((1 << 13) | (0 << 12))
  63. /* 1: CRC16 check*/
  64. #define CMD_SET_CRC16C (1 << 10)
  65. /* 1: not receive CRC status */
  66. #define CMD_SET_CRCSTE (1 << 8)
  67. /* 1: tran mission bit "Low" */
  68. #define CMD_SET_TBIT (1 << 7)
  69. /* 1: open/drain */
  70. #define CMD_SET_OPDM (1 << 6)
  71. #define CMD_SET_CCSH (1 << 5)
  72. /* 1bit */
  73. #define CMD_SET_DATW_1 ((0 << 1) | (0 << 0))
  74. /* 4bit */
  75. #define CMD_SET_DATW_4 ((0 << 1) | (1 << 0))
  76. /* 8bit */
  77. #define CMD_SET_DATW_8 ((1 << 1) | (0 << 0))
  78. /* CE_CMD_CTRL */
  79. #define CMD_CTRL_BREAK (1 << 0)
  80. /* CE_BLOCK_SET */
  81. #define BLOCK_SIZE_MASK 0x0000ffff
  82. /* CE_CLK_CTRL */
  83. #define CLK_ENABLE (1 << 24)
  84. #define CLK_CLEAR ((1 << 19) | (1 << 18) | (1 << 17) | (1 << 16))
  85. #define CLK_PCLK ((1 << 19) | (1 << 18) | (1 << 17) | (1 << 16))
  86. /* respons timeout */
  87. #define SRSPTO_256 ((1 << 13) | (0 << 12))
  88. /* respons busy timeout */
  89. #define SRBSYTO_29 ((1 << 11) | (1 << 10) | (1 << 9) | (1 << 8))
  90. /* read/write timeout */
  91. #define SRWDTO_29 ((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4))
  92. /* ccs timeout */
  93. #define SCCSTO_29 ((1 << 3) | (1 << 2) | (1 << 1) | (1 << 0))
  94. /* CE_BUF_ACC */
  95. #define BUF_ACC_DMAWEN (1 << 25)
  96. #define BUF_ACC_DMAREN (1 << 24)
  97. #define BUF_ACC_BUSW_32 (0 << 17)
  98. #define BUF_ACC_BUSW_16 (1 << 17)
  99. #define BUF_ACC_ATYP (1 << 16)
  100. /* CE_INT */
  101. #define INT_CCSDE (1 << 29)
  102. #define INT_CMD12DRE (1 << 26)
  103. #define INT_CMD12RBE (1 << 25)
  104. #define INT_CMD12CRE (1 << 24)
  105. #define INT_DTRANE (1 << 23)
  106. #define INT_BUFRE (1 << 22)
  107. #define INT_BUFWEN (1 << 21)
  108. #define INT_BUFREN (1 << 20)
  109. #define INT_CCSRCV (1 << 19)
  110. #define INT_RBSYE (1 << 17)
  111. #define INT_CRSPE (1 << 16)
  112. #define INT_CMDVIO (1 << 15)
  113. #define INT_BUFVIO (1 << 14)
  114. #define INT_WDATERR (1 << 11)
  115. #define INT_RDATERR (1 << 10)
  116. #define INT_RIDXERR (1 << 9)
  117. #define INT_RSPERR (1 << 8)
  118. #define INT_CCSTO (1 << 5)
  119. #define INT_CRCSTO (1 << 4)
  120. #define INT_WDATTO (1 << 3)
  121. #define INT_RDATTO (1 << 2)
  122. #define INT_RBSYTO (1 << 1)
  123. #define INT_RSPTO (1 << 0)
  124. #define INT_ERR_STS (INT_CMDVIO | INT_BUFVIO | INT_WDATERR | \
  125. INT_RDATERR | INT_RIDXERR | INT_RSPERR | \
  126. INT_CCSTO | INT_CRCSTO | INT_WDATTO | \
  127. INT_RDATTO | INT_RBSYTO | INT_RSPTO)
  128. #define INT_START_MAGIC 0xD80430C0
  129. /* CE_INT_MASK */
  130. #define MASK_ALL 0x00000000
  131. #define MASK_MCCSDE (1 << 29)
  132. #define MASK_MCMD12DRE (1 << 26)
  133. #define MASK_MCMD12RBE (1 << 25)
  134. #define MASK_MCMD12CRE (1 << 24)
  135. #define MASK_MDTRANE (1 << 23)
  136. #define MASK_MBUFRE (1 << 22)
  137. #define MASK_MBUFWEN (1 << 21)
  138. #define MASK_MBUFREN (1 << 20)
  139. #define MASK_MCCSRCV (1 << 19)
  140. #define MASK_MRBSYE (1 << 17)
  141. #define MASK_MCRSPE (1 << 16)
  142. #define MASK_MCMDVIO (1 << 15)
  143. #define MASK_MBUFVIO (1 << 14)
  144. #define MASK_MWDATERR (1 << 11)
  145. #define MASK_MRDATERR (1 << 10)
  146. #define MASK_MRIDXERR (1 << 9)
  147. #define MASK_MRSPERR (1 << 8)
  148. #define MASK_MCCSTO (1 << 5)
  149. #define MASK_MCRCSTO (1 << 4)
  150. #define MASK_MWDATTO (1 << 3)
  151. #define MASK_MRDATTO (1 << 2)
  152. #define MASK_MRBSYTO (1 << 1)
  153. #define MASK_MRSPTO (1 << 0)
  154. /* CE_HOST_STS1 */
  155. #define STS1_CMDSEQ (1 << 31)
  156. /* CE_HOST_STS2 */
  157. #define STS2_CRCSTE (1 << 31)
  158. #define STS2_CRC16E (1 << 30)
  159. #define STS2_AC12CRCE (1 << 29)
  160. #define STS2_RSPCRC7E (1 << 28)
  161. #define STS2_CRCSTEBE (1 << 27)
  162. #define STS2_RDATEBE (1 << 26)
  163. #define STS2_AC12REBE (1 << 25)
  164. #define STS2_RSPEBE (1 << 24)
  165. #define STS2_AC12IDXE (1 << 23)
  166. #define STS2_RSPIDXE (1 << 22)
  167. #define STS2_CCSTO (1 << 15)
  168. #define STS2_RDATTO (1 << 14)
  169. #define STS2_DATBSYTO (1 << 13)
  170. #define STS2_CRCSTTO (1 << 12)
  171. #define STS2_AC12BSYTO (1 << 11)
  172. #define STS2_RSPBSYTO (1 << 10)
  173. #define STS2_AC12RSPTO (1 << 9)
  174. #define STS2_RSPTO (1 << 8)
  175. #define STS2_CRC_ERR (STS2_CRCSTE | STS2_CRC16E | \
  176. STS2_AC12CRCE | STS2_RSPCRC7E | STS2_CRCSTEBE)
  177. #define STS2_TIMEOUT_ERR (STS2_CCSTO | STS2_RDATTO | \
  178. STS2_DATBSYTO | STS2_CRCSTTO | \
  179. STS2_AC12BSYTO | STS2_RSPBSYTO | \
  180. STS2_AC12RSPTO | STS2_RSPTO)
  181. /* CE_VERSION */
  182. #define SOFT_RST_ON (1 << 31)
  183. #define SOFT_RST_OFF (0 << 31)
  184. #define CLKDEV_EMMC_DATA 52000000 /* 52MHz */
  185. #ifdef CONFIG_ARCH_RMOBILE
  186. #define MMC_CLK_DIV_MIN(clk) (clk / (1 << 9))
  187. #define MMC_CLK_DIV_MAX(clk) (clk / (1 << 1))
  188. #else
  189. #define MMC_CLK_DIV_MIN(clk) (clk / (1 << 8))
  190. #define MMC_CLK_DIV_MAX(clk) CLKDEV_EMMC_DATA
  191. #endif
  192. #define MMC_BUS_WIDTH_1 0
  193. #define MMC_BUS_WIDTH_4 2
  194. #define MMC_BUS_WIDTH_8 3
  195. struct sh_mmcif_host {
  196. struct mmc_data *data;
  197. struct sh_mmcif_regs *regs;
  198. unsigned int clk;
  199. int bus_width;
  200. u16 wait_int;
  201. u16 sd_error;
  202. u8 last_cmd;
  203. };
  204. static inline u32 sh_mmcif_read(unsigned long *reg)
  205. {
  206. return readl(reg);
  207. }
  208. static inline void sh_mmcif_write(u32 val, unsigned long *reg)
  209. {
  210. writel(val, reg);
  211. }
  212. static inline void sh_mmcif_bitset(u32 val, unsigned long *reg)
  213. {
  214. sh_mmcif_write(val | sh_mmcif_read(reg), reg);
  215. }
  216. static inline void sh_mmcif_bitclr(u32 val, unsigned long *reg)
  217. {
  218. sh_mmcif_write(~val & sh_mmcif_read(reg), reg);
  219. }
  220. #endif /* _SH_MMCIF_H_ */