sd.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* Driver for Realtek PCI-Express card reader
  2. * Header file
  3. *
  4. * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * Author:
  20. * Wei WANG (wei_wang@realsil.com.cn)
  21. * Micky Ching (micky_ching@realsil.com.cn)
  22. */
  23. #ifndef __REALTEK_RTSX_SD_H
  24. #define __REALTEK_RTSX_SD_H
  25. #include "rtsx_chip.h"
  26. #define SUPPORT_VOLTAGE 0x003C0000
  27. /* Error Code */
  28. #define SD_NO_ERROR 0x0
  29. #define SD_CRC_ERR 0x80
  30. #define SD_TO_ERR 0x40
  31. #define SD_NO_CARD 0x20
  32. #define SD_BUSY 0x10
  33. #define SD_STS_ERR 0x08
  34. #define SD_RSP_TIMEOUT 0x04
  35. #define SD_IO_ERR 0x02
  36. /* Return code for MMC switch bus */
  37. #define SWITCH_SUCCESS 0
  38. #define SWITCH_ERR 1
  39. #define SWITCH_FAIL 2
  40. /* MMC/SD Command Index */
  41. /* Basic command (class 0) */
  42. #define GO_IDLE_STATE 0
  43. #define SEND_OP_COND 1
  44. #define ALL_SEND_CID 2
  45. #define SET_RELATIVE_ADDR 3
  46. #define SEND_RELATIVE_ADDR 3
  47. #define SET_DSR 4
  48. #define IO_SEND_OP_COND 5
  49. #define SWITCH 6
  50. #define SELECT_CARD 7
  51. #define DESELECT_CARD 7
  52. /* CMD8 is "SEND_EXT_CSD" for MMC4.x Spec
  53. * while is "SEND_IF_COND" for SD 2.0
  54. */
  55. #define SEND_EXT_CSD 8
  56. #define SEND_IF_COND 8
  57. #define SEND_CSD 9
  58. #define SEND_CID 10
  59. #define VOLTAGE_SWITCH 11
  60. #define READ_DAT_UTIL_STOP 11
  61. #define STOP_TRANSMISSION 12
  62. #define SEND_STATUS 13
  63. #define GO_INACTIVE_STATE 15
  64. #define SET_BLOCKLEN 16
  65. #define READ_SINGLE_BLOCK 17
  66. #define READ_MULTIPLE_BLOCK 18
  67. #define SEND_TUNING_PATTERN 19
  68. #define BUSTEST_R 14
  69. #define BUSTEST_W 19
  70. #define WRITE_BLOCK 24
  71. #define WRITE_MULTIPLE_BLOCK 25
  72. #define PROGRAM_CSD 27
  73. #define ERASE_WR_BLK_START 32
  74. #define ERASE_WR_BLK_END 33
  75. #define ERASE_CMD 38
  76. #define LOCK_UNLOCK 42
  77. #define IO_RW_DIRECT 52
  78. #define APP_CMD 55
  79. #define GEN_CMD 56
  80. #define SET_BUS_WIDTH 6
  81. #define SD_STATUS 13
  82. #define SEND_NUM_WR_BLOCKS 22
  83. #define SET_WR_BLK_ERASE_COUNT 23
  84. #define SD_APP_OP_COND 41
  85. #define SET_CLR_CARD_DETECT 42
  86. #define SEND_SCR 51
  87. #define SD_READ_COMPLETE 0x00
  88. #define SD_READ_TO 0x01
  89. #define SD_READ_ADVENCE 0x02
  90. #define SD_CHECK_MODE 0x00
  91. #define SD_SWITCH_MODE 0x80
  92. #define SD_FUNC_GROUP_1 0x01
  93. #define SD_FUNC_GROUP_2 0x02
  94. #define SD_FUNC_GROUP_3 0x03
  95. #define SD_FUNC_GROUP_4 0x04
  96. #define SD_CHECK_SPEC_V1_1 0xFF
  97. #define NO_ARGUMENT 0x00
  98. #define CHECK_PATTERN 0x000000AA
  99. #define VOLTAGE_SUPPLY_RANGE 0x00000100
  100. #define SUPPORT_HIGH_AND_EXTENDED_CAPACITY 0x40000000
  101. #define SUPPORT_MAX_POWER_PERMANCE 0x10000000
  102. #define SUPPORT_1V8 0x01000000
  103. #define SWTICH_NO_ERR 0x00
  104. #define CARD_NOT_EXIST 0x01
  105. #define SPEC_NOT_SUPPORT 0x02
  106. #define CHECK_MODE_ERR 0x03
  107. #define CHECK_NOT_READY 0x04
  108. #define SWITCH_CRC_ERR 0x05
  109. #define SWITCH_MODE_ERR 0x06
  110. #define SWITCH_PASS 0x07
  111. #ifdef SUPPORT_SD_LOCK
  112. #define SD_ERASE 0x08
  113. #define SD_LOCK 0x04
  114. #define SD_UNLOCK 0x00
  115. #define SD_CLR_PWD 0x02
  116. #define SD_SET_PWD 0x01
  117. #define SD_PWD_LEN 0x10
  118. #define SD_LOCKED 0x80
  119. #define SD_LOCK_1BIT_MODE 0x40
  120. #define SD_PWD_EXIST 0x20
  121. #define SD_UNLOCK_POW_ON 0x01
  122. #define SD_SDR_RST 0x02
  123. #define SD_NOT_ERASE 0x00
  124. #define SD_UNDER_ERASING 0x01
  125. #define SD_COMPLETE_ERASE 0x02
  126. #define SD_RW_FORBIDDEN 0x0F
  127. #endif
  128. #define HS_SUPPORT 0x01
  129. #define SDR50_SUPPORT 0x02
  130. #define SDR104_SUPPORT 0x03
  131. #define DDR50_SUPPORT 0x04
  132. #define HS_SUPPORT_MASK 0x02
  133. #define SDR50_SUPPORT_MASK 0x04
  134. #define SDR104_SUPPORT_MASK 0x08
  135. #define DDR50_SUPPORT_MASK 0x10
  136. #define HS_QUERY_SWITCH_OK 0x01
  137. #define SDR50_QUERY_SWITCH_OK 0x02
  138. #define SDR104_QUERY_SWITCH_OK 0x03
  139. #define DDR50_QUERY_SWITCH_OK 0x04
  140. #define HS_SWITCH_BUSY 0x02
  141. #define SDR50_SWITCH_BUSY 0x04
  142. #define SDR104_SWITCH_BUSY 0x08
  143. #define DDR50_SWITCH_BUSY 0x10
  144. #define FUNCTION_GROUP1_SUPPORT_OFFSET 0x0D
  145. #define FUNCTION_GROUP1_QUERY_SWITCH_OFFSET 0x10
  146. #define FUNCTION_GROUP1_CHECK_BUSY_OFFSET 0x1D
  147. #define DRIVING_TYPE_A 0x01
  148. #define DRIVING_TYPE_B 0x00
  149. #define DRIVING_TYPE_C 0x02
  150. #define DRIVING_TYPE_D 0x03
  151. #define DRIVING_TYPE_A_MASK 0x02
  152. #define DRIVING_TYPE_B_MASK 0x01
  153. #define DRIVING_TYPE_C_MASK 0x04
  154. #define DRIVING_TYPE_D_MASK 0x08
  155. #define TYPE_A_QUERY_SWITCH_OK 0x01
  156. #define TYPE_B_QUERY_SWITCH_OK 0x00
  157. #define TYPE_C_QUERY_SWITCH_OK 0x02
  158. #define TYPE_D_QUERY_SWITCH_OK 0x03
  159. #define TYPE_A_SWITCH_BUSY 0x02
  160. #define TYPE_B_SWITCH_BUSY 0x01
  161. #define TYPE_C_SWITCH_BUSY 0x04
  162. #define TYPE_D_SWITCH_BUSY 0x08
  163. #define FUNCTION_GROUP3_SUPPORT_OFFSET 0x09
  164. #define FUNCTION_GROUP3_QUERY_SWITCH_OFFSET 0x0F
  165. #define FUNCTION_GROUP3_CHECK_BUSY_OFFSET 0x19
  166. #define CURRENT_LIMIT_200 0x00
  167. #define CURRENT_LIMIT_400 0x01
  168. #define CURRENT_LIMIT_600 0x02
  169. #define CURRENT_LIMIT_800 0x03
  170. #define CURRENT_LIMIT_200_MASK 0x01
  171. #define CURRENT_LIMIT_400_MASK 0x02
  172. #define CURRENT_LIMIT_600_MASK 0x04
  173. #define CURRENT_LIMIT_800_MASK 0x08
  174. #define CURRENT_LIMIT_200_QUERY_SWITCH_OK 0x00
  175. #define CURRENT_LIMIT_400_QUERY_SWITCH_OK 0x01
  176. #define CURRENT_LIMIT_600_QUERY_SWITCH_OK 0x02
  177. #define CURRENT_LIMIT_800_QUERY_SWITCH_OK 0x03
  178. #define CURRENT_LIMIT_200_SWITCH_BUSY 0x01
  179. #define CURRENT_LIMIT_400_SWITCH_BUSY 0x02
  180. #define CURRENT_LIMIT_600_SWITCH_BUSY 0x04
  181. #define CURRENT_LIMIT_800_SWITCH_BUSY 0x08
  182. #define FUNCTION_GROUP4_SUPPORT_OFFSET 0x07
  183. #define FUNCTION_GROUP4_QUERY_SWITCH_OFFSET 0x0F
  184. #define FUNCTION_GROUP4_CHECK_BUSY_OFFSET 0x17
  185. #define DATA_STRUCTURE_VER_OFFSET 0x11
  186. #define MAX_PHASE 31
  187. #define MMC_8BIT_BUS 0x0010
  188. #define MMC_4BIT_BUS 0x0020
  189. #define MMC_SWITCH_ERR 0x80
  190. #define SD_IO_3V3 0
  191. #define SD_IO_1V8 1
  192. #define TUNE_TX 0x00
  193. #define TUNE_RX 0x01
  194. #define CHANGE_TX 0x00
  195. #define CHANGE_RX 0x01
  196. #define DCM_HIGH_FREQUENCY_MODE 0x00
  197. #define DCM_LOW_FREQUENCY_MODE 0x01
  198. #define DCM_HIGH_FREQUENCY_MODE_SET 0x0C
  199. #define DCM_Low_FREQUENCY_MODE_SET 0x00
  200. #define MULTIPLY_BY_1 0x00
  201. #define MULTIPLY_BY_2 0x01
  202. #define MULTIPLY_BY_3 0x02
  203. #define MULTIPLY_BY_4 0x03
  204. #define MULTIPLY_BY_5 0x04
  205. #define MULTIPLY_BY_6 0x05
  206. #define MULTIPLY_BY_7 0x06
  207. #define MULTIPLY_BY_8 0x07
  208. #define MULTIPLY_BY_9 0x08
  209. #define MULTIPLY_BY_10 0x09
  210. #define DIVIDE_BY_2 0x01
  211. #define DIVIDE_BY_3 0x02
  212. #define DIVIDE_BY_4 0x03
  213. #define DIVIDE_BY_5 0x04
  214. #define DIVIDE_BY_6 0x05
  215. #define DIVIDE_BY_7 0x06
  216. #define DIVIDE_BY_8 0x07
  217. #define DIVIDE_BY_9 0x08
  218. #define DIVIDE_BY_10 0x09
  219. struct timing_phase_path {
  220. int start;
  221. int end;
  222. int mid;
  223. int len;
  224. };
  225. int sd_select_card(struct rtsx_chip *chip, int select);
  226. int sd_pull_ctl_enable(struct rtsx_chip *chip);
  227. int reset_sd_card(struct rtsx_chip *chip);
  228. int sd_switch_clock(struct rtsx_chip *chip);
  229. void sd_stop_seq_mode(struct rtsx_chip *chip);
  230. int sd_rw(struct scsi_cmnd *srb, struct rtsx_chip *chip,
  231. u32 start_sector, u16 sector_cnt);
  232. void sd_cleanup_work(struct rtsx_chip *chip);
  233. int sd_power_off_card3v3(struct rtsx_chip *chip);
  234. int release_sd_card(struct rtsx_chip *chip);
  235. #ifdef SUPPORT_CPRM
  236. int soft_reset_sd_card(struct rtsx_chip *chip);
  237. int ext_sd_send_cmd_get_rsp(struct rtsx_chip *chip, u8 cmd_idx,
  238. u32 arg, u8 rsp_type, u8 *rsp, int rsp_len, bool special_check);
  239. int ext_sd_get_rsp(struct rtsx_chip *chip, int len, u8 *rsp, u8 rsp_type);
  240. int sd_pass_thru_mode(struct scsi_cmnd *srb, struct rtsx_chip *chip);
  241. int sd_execute_no_data(struct scsi_cmnd *srb, struct rtsx_chip *chip);
  242. int sd_execute_read_data(struct scsi_cmnd *srb, struct rtsx_chip *chip);
  243. int sd_execute_write_data(struct scsi_cmnd *srb, struct rtsx_chip *chip);
  244. int sd_get_cmd_rsp(struct scsi_cmnd *srb, struct rtsx_chip *chip);
  245. int sd_hw_rst(struct scsi_cmnd *srb, struct rtsx_chip *chip);
  246. #endif
  247. #endif /* __REALTEK_RTSX_SD_H */