rtsx_usb.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* Driver for Realtek RTS5139 USB card reader
  3. *
  4. * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
  5. *
  6. * Author:
  7. * Roger Tseng <[email protected]>
  8. */
  9. #ifndef __RTSX_USB_H
  10. #define __RTSX_USB_H
  11. #include <linux/usb.h>
  12. /* related module names */
  13. #define RTSX_USB_SD_CARD 0
  14. #define RTSX_USB_MS_CARD 1
  15. /* endpoint numbers */
  16. #define EP_BULK_OUT 1
  17. #define EP_BULK_IN 2
  18. #define EP_INTR_IN 3
  19. /* USB vendor requests */
  20. #define RTSX_USB_REQ_REG_OP 0x00
  21. #define RTSX_USB_REQ_POLL 0x02
  22. /* miscellaneous parameters */
  23. #define MIN_DIV_N 60
  24. #define MAX_DIV_N 120
  25. #define MAX_PHASE 15
  26. #define RX_TUNING_CNT 3
  27. #define QFN24 0
  28. #define LQFP48 1
  29. #define CHECK_PKG(ucr, pkg) ((ucr)->package == (pkg))
  30. /* data structures */
  31. struct rtsx_ucr {
  32. u16 vendor_id;
  33. u16 product_id;
  34. int package;
  35. u8 ic_version;
  36. bool is_rts5179;
  37. unsigned int cur_clk;
  38. u8 *cmd_buf;
  39. unsigned int cmd_idx;
  40. u8 *rsp_buf;
  41. struct usb_device *pusb_dev;
  42. struct usb_interface *pusb_intf;
  43. struct usb_sg_request current_sg;
  44. struct timer_list sg_timer;
  45. struct mutex dev_mutex;
  46. };
  47. /* buffer size */
  48. #define IOBUF_SIZE 1024
  49. /* prototypes of exported functions */
  50. extern int rtsx_usb_get_card_status(struct rtsx_ucr *ucr, u16 *status);
  51. extern int rtsx_usb_read_register(struct rtsx_ucr *ucr, u16 addr, u8 *data);
  52. extern int rtsx_usb_write_register(struct rtsx_ucr *ucr, u16 addr, u8 mask,
  53. u8 data);
  54. extern int rtsx_usb_ep0_write_register(struct rtsx_ucr *ucr, u16 addr, u8 mask,
  55. u8 data);
  56. extern int rtsx_usb_ep0_read_register(struct rtsx_ucr *ucr, u16 addr,
  57. u8 *data);
  58. extern void rtsx_usb_add_cmd(struct rtsx_ucr *ucr, u8 cmd_type,
  59. u16 reg_addr, u8 mask, u8 data);
  60. extern int rtsx_usb_send_cmd(struct rtsx_ucr *ucr, u8 flag, int timeout);
  61. extern int rtsx_usb_get_rsp(struct rtsx_ucr *ucr, int rsp_len, int timeout);
  62. extern int rtsx_usb_transfer_data(struct rtsx_ucr *ucr, unsigned int pipe,
  63. void *buf, unsigned int len, int use_sg,
  64. unsigned int *act_len, int timeout);
  65. extern int rtsx_usb_read_ppbuf(struct rtsx_ucr *ucr, u8 *buf, int buf_len);
  66. extern int rtsx_usb_write_ppbuf(struct rtsx_ucr *ucr, u8 *buf, int buf_len);
  67. extern int rtsx_usb_switch_clock(struct rtsx_ucr *ucr, unsigned int card_clock,
  68. u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
  69. extern int rtsx_usb_card_exclusive_check(struct rtsx_ucr *ucr, int card);
  70. /* card status */
  71. #define SD_CD 0x01
  72. #define MS_CD 0x02
  73. #define XD_CD 0x04
  74. #define CD_MASK (SD_CD | MS_CD | XD_CD)
  75. #define SD_WP 0x08
  76. /* reader command field offset & parameters */
  77. #define READ_REG_CMD 0
  78. #define WRITE_REG_CMD 1
  79. #define CHECK_REG_CMD 2
  80. #define PACKET_TYPE 4
  81. #define CNT_H 5
  82. #define CNT_L 6
  83. #define STAGE_FLAG 7
  84. #define CMD_OFFSET 8
  85. #define SEQ_WRITE_DATA_OFFSET 12
  86. #define BATCH_CMD 0
  87. #define SEQ_READ 1
  88. #define SEQ_WRITE 2
  89. #define STAGE_R 0x01
  90. #define STAGE_DI 0x02
  91. #define STAGE_DO 0x04
  92. #define STAGE_MS_STATUS 0x08
  93. #define STAGE_XD_STATUS 0x10
  94. #define MODE_C 0x00
  95. #define MODE_CR (STAGE_R)
  96. #define MODE_CDIR (STAGE_R | STAGE_DI)
  97. #define MODE_CDOR (STAGE_R | STAGE_DO)
  98. #define EP0_OP_SHIFT 14
  99. #define EP0_READ_REG_CMD 2
  100. #define EP0_WRITE_REG_CMD 3
  101. #define rtsx_usb_cmd_hdr_tag(ucr) \
  102. do { \
  103. ucr->cmd_buf[0] = 'R'; \
  104. ucr->cmd_buf[1] = 'T'; \
  105. ucr->cmd_buf[2] = 'C'; \
  106. ucr->cmd_buf[3] = 'R'; \
  107. } while (0)
  108. static inline void rtsx_usb_init_cmd(struct rtsx_ucr *ucr)
  109. {
  110. rtsx_usb_cmd_hdr_tag(ucr);
  111. ucr->cmd_idx = 0;
  112. ucr->cmd_buf[PACKET_TYPE] = BATCH_CMD;
  113. }
  114. /* internal register address */
  115. #define FPDCTL 0xFC00
  116. #define SSC_DIV_N_0 0xFC07
  117. #define SSC_CTL1 0xFC09
  118. #define SSC_CTL2 0xFC0A
  119. #define CFG_MODE 0xFC0E
  120. #define CFG_MODE_1 0xFC0F
  121. #define RCCTL 0xFC14
  122. #define SOF_WDOG 0xFC28
  123. #define SYS_DUMMY0 0xFC30
  124. #define MS_BLKEND 0xFD30
  125. #define MS_READ_START 0xFD31
  126. #define MS_READ_COUNT 0xFD32
  127. #define MS_WRITE_START 0xFD33
  128. #define MS_WRITE_COUNT 0xFD34
  129. #define MS_COMMAND 0xFD35
  130. #define MS_OLD_BLOCK_0 0xFD36
  131. #define MS_OLD_BLOCK_1 0xFD37
  132. #define MS_NEW_BLOCK_0 0xFD38
  133. #define MS_NEW_BLOCK_1 0xFD39
  134. #define MS_LOG_BLOCK_0 0xFD3A
  135. #define MS_LOG_BLOCK_1 0xFD3B
  136. #define MS_BUS_WIDTH 0xFD3C
  137. #define MS_PAGE_START 0xFD3D
  138. #define MS_PAGE_LENGTH 0xFD3E
  139. #define MS_CFG 0xFD40
  140. #define MS_TPC 0xFD41
  141. #define MS_TRANS_CFG 0xFD42
  142. #define MS_TRANSFER 0xFD43
  143. #define MS_INT_REG 0xFD44
  144. #define MS_BYTE_CNT 0xFD45
  145. #define MS_SECTOR_CNT_L 0xFD46
  146. #define MS_SECTOR_CNT_H 0xFD47
  147. #define MS_DBUS_H 0xFD48
  148. #define CARD_DMA1_CTL 0xFD5C
  149. #define CARD_PULL_CTL1 0xFD60
  150. #define CARD_PULL_CTL2 0xFD61
  151. #define CARD_PULL_CTL3 0xFD62
  152. #define CARD_PULL_CTL4 0xFD63
  153. #define CARD_PULL_CTL5 0xFD64
  154. #define CARD_PULL_CTL6 0xFD65
  155. #define CARD_EXIST 0xFD6F
  156. #define CARD_INT_PEND 0xFD71
  157. #define LDO_POWER_CFG 0xFD7B
  158. #define SD_CFG1 0xFDA0
  159. #define SD_CFG2 0xFDA1
  160. #define SD_CFG3 0xFDA2
  161. #define SD_STAT1 0xFDA3
  162. #define SD_STAT2 0xFDA4
  163. #define SD_BUS_STAT 0xFDA5
  164. #define SD_PAD_CTL 0xFDA6
  165. #define SD_SAMPLE_POINT_CTL 0xFDA7
  166. #define SD_PUSH_POINT_CTL 0xFDA8
  167. #define SD_CMD0 0xFDA9
  168. #define SD_CMD1 0xFDAA
  169. #define SD_CMD2 0xFDAB
  170. #define SD_CMD3 0xFDAC
  171. #define SD_CMD4 0xFDAD
  172. #define SD_CMD5 0xFDAE
  173. #define SD_BYTE_CNT_L 0xFDAF
  174. #define SD_BYTE_CNT_H 0xFDB0
  175. #define SD_BLOCK_CNT_L 0xFDB1
  176. #define SD_BLOCK_CNT_H 0xFDB2
  177. #define SD_TRANSFER 0xFDB3
  178. #define SD_CMD_STATE 0xFDB5
  179. #define SD_DATA_STATE 0xFDB6
  180. #define SD_VPCLK0_CTL 0xFC2A
  181. #define SD_VPCLK1_CTL 0xFC2B
  182. #define SD_DCMPS0_CTL 0xFC2C
  183. #define SD_DCMPS1_CTL 0xFC2D
  184. #define CARD_DMA1_CTL 0xFD5C
  185. #define HW_VERSION 0xFC01
  186. #define SSC_CLK_FPGA_SEL 0xFC02
  187. #define CLK_DIV 0xFC03
  188. #define SFSM_ED 0xFC04
  189. #define CD_DEGLITCH_WIDTH 0xFC20
  190. #define CD_DEGLITCH_EN 0xFC21
  191. #define AUTO_DELINK_EN 0xFC23
  192. #define FPGA_PULL_CTL 0xFC1D
  193. #define CARD_CLK_SOURCE 0xFC2E
  194. #define CARD_SHARE_MODE 0xFD51
  195. #define CARD_DRIVE_SEL 0xFD52
  196. #define CARD_STOP 0xFD53
  197. #define CARD_OE 0xFD54
  198. #define CARD_AUTO_BLINK 0xFD55
  199. #define CARD_GPIO 0xFD56
  200. #define SD30_DRIVE_SEL 0xFD57
  201. #define CARD_DATA_SOURCE 0xFD5D
  202. #define CARD_SELECT 0xFD5E
  203. #define CARD_CLK_EN 0xFD79
  204. #define CARD_PWR_CTL 0xFD7A
  205. #define OCPCTL 0xFD80
  206. #define OCPPARA1 0xFD81
  207. #define OCPPARA2 0xFD82
  208. #define OCPSTAT 0xFD83
  209. #define HS_USB_STAT 0xFE01
  210. #define HS_VCONTROL 0xFE26
  211. #define HS_VSTAIN 0xFE27
  212. #define HS_VLOADM 0xFE28
  213. #define HS_VSTAOUT 0xFE29
  214. #define MC_IRQ 0xFF00
  215. #define MC_IRQEN 0xFF01
  216. #define MC_FIFO_CTL 0xFF02
  217. #define MC_FIFO_BC0 0xFF03
  218. #define MC_FIFO_BC1 0xFF04
  219. #define MC_FIFO_STAT 0xFF05
  220. #define MC_FIFO_MODE 0xFF06
  221. #define MC_FIFO_RD_PTR0 0xFF07
  222. #define MC_FIFO_RD_PTR1 0xFF08
  223. #define MC_DMA_CTL 0xFF10
  224. #define MC_DMA_TC0 0xFF11
  225. #define MC_DMA_TC1 0xFF12
  226. #define MC_DMA_TC2 0xFF13
  227. #define MC_DMA_TC3 0xFF14
  228. #define MC_DMA_RST 0xFF15
  229. #define RBUF_SIZE_MASK 0xFBFF
  230. #define RBUF_BASE 0xF000
  231. #define PPBUF_BASE1 0xF800
  232. #define PPBUF_BASE2 0xFA00
  233. /* internal register value macros */
  234. #define POWER_OFF 0x03
  235. #define PARTIAL_POWER_ON 0x02
  236. #define POWER_ON 0x00
  237. #define POWER_MASK 0x03
  238. #define LDO3318_PWR_MASK 0x0C
  239. #define LDO_ON 0x00
  240. #define LDO_SUSPEND 0x08
  241. #define LDO_OFF 0x0C
  242. #define DV3318_AUTO_PWR_OFF 0x10
  243. #define FORCE_LDO_POWERB 0x60
  244. /* LDO_POWER_CFG */
  245. #define TUNE_SD18_MASK 0x1C
  246. #define TUNE_SD18_1V7 0x00
  247. #define TUNE_SD18_1V8 (0x01 << 2)
  248. #define TUNE_SD18_1V9 (0x02 << 2)
  249. #define TUNE_SD18_2V0 (0x03 << 2)
  250. #define TUNE_SD18_2V7 (0x04 << 2)
  251. #define TUNE_SD18_2V8 (0x05 << 2)
  252. #define TUNE_SD18_2V9 (0x06 << 2)
  253. #define TUNE_SD18_3V3 (0x07 << 2)
  254. /* CLK_DIV */
  255. #define CLK_CHANGE 0x80
  256. #define CLK_DIV_1 0x00
  257. #define CLK_DIV_2 0x01
  258. #define CLK_DIV_4 0x02
  259. #define CLK_DIV_8 0x03
  260. #define SSC_POWER_MASK 0x01
  261. #define SSC_POWER_DOWN 0x01
  262. #define SSC_POWER_ON 0x00
  263. #define FPGA_VER 0x80
  264. #define HW_VER_MASK 0x0F
  265. #define EXTEND_DMA1_ASYNC_SIGNAL 0x02
  266. /* CFG_MODE*/
  267. #define XTAL_FREE 0x80
  268. #define CLK_MODE_MASK 0x03
  269. #define CLK_MODE_12M_XTAL 0x00
  270. #define CLK_MODE_NON_XTAL 0x01
  271. #define CLK_MODE_24M_OSC 0x02
  272. #define CLK_MODE_48M_OSC 0x03
  273. /* CFG_MODE_1*/
  274. #define RTS5179 0x02
  275. #define NYET_EN 0x01
  276. #define NYET_MSAK 0x01
  277. #define SD30_DRIVE_MASK 0x07
  278. #define SD20_DRIVE_MASK 0x03
  279. #define DISABLE_SD_CD 0x08
  280. #define DISABLE_MS_CD 0x10
  281. #define DISABLE_XD_CD 0x20
  282. #define SD_CD_DEGLITCH_EN 0x01
  283. #define MS_CD_DEGLITCH_EN 0x02
  284. #define XD_CD_DEGLITCH_EN 0x04
  285. #define CARD_SHARE_LQFP48 0x04
  286. #define CARD_SHARE_QFN24 0x00
  287. #define CARD_SHARE_LQFP_SEL 0x04
  288. #define CARD_SHARE_XD 0x00
  289. #define CARD_SHARE_SD 0x01
  290. #define CARD_SHARE_MS 0x02
  291. #define CARD_SHARE_MASK 0x03
  292. /* SD30_DRIVE_SEL */
  293. #define DRIVER_TYPE_A 0x05
  294. #define DRIVER_TYPE_B 0x03
  295. #define DRIVER_TYPE_C 0x02
  296. #define DRIVER_TYPE_D 0x01
  297. /* SD_BUS_STAT */
  298. #define SD_CLK_TOGGLE_EN 0x80
  299. #define SD_CLK_FORCE_STOP 0x40
  300. #define SD_DAT3_STATUS 0x10
  301. #define SD_DAT2_STATUS 0x08
  302. #define SD_DAT1_STATUS 0x04
  303. #define SD_DAT0_STATUS 0x02
  304. #define SD_CMD_STATUS 0x01
  305. /* SD_PAD_CTL */
  306. #define SD_IO_USING_1V8 0x80
  307. #define SD_IO_USING_3V3 0x7F
  308. #define TYPE_A_DRIVING 0x00
  309. #define TYPE_B_DRIVING 0x01
  310. #define TYPE_C_DRIVING 0x02
  311. #define TYPE_D_DRIVING 0x03
  312. /* CARD_CLK_EN */
  313. #define SD_CLK_EN 0x04
  314. #define MS_CLK_EN 0x08
  315. /* CARD_SELECT */
  316. #define SD_MOD_SEL 2
  317. #define MS_MOD_SEL 3
  318. /* CARD_SHARE_MODE */
  319. #define CARD_SHARE_LQFP48 0x04
  320. #define CARD_SHARE_QFN24 0x00
  321. #define CARD_SHARE_LQFP_SEL 0x04
  322. #define CARD_SHARE_XD 0x00
  323. #define CARD_SHARE_SD 0x01
  324. #define CARD_SHARE_MS 0x02
  325. #define CARD_SHARE_MASK 0x03
  326. /* SSC_CTL1 */
  327. #define SSC_RSTB 0x80
  328. #define SSC_8X_EN 0x40
  329. #define SSC_FIX_FRAC 0x20
  330. #define SSC_SEL_1M 0x00
  331. #define SSC_SEL_2M 0x08
  332. #define SSC_SEL_4M 0x10
  333. #define SSC_SEL_8M 0x18
  334. /* SSC_CTL2 */
  335. #define SSC_DEPTH_MASK 0x03
  336. #define SSC_DEPTH_DISALBE 0x00
  337. #define SSC_DEPTH_2M 0x01
  338. #define SSC_DEPTH_1M 0x02
  339. #define SSC_DEPTH_512K 0x03
  340. /* SD_VPCLK0_CTL */
  341. #define PHASE_CHANGE 0x80
  342. #define PHASE_NOT_RESET 0x40
  343. /* SD_TRANSFER */
  344. #define SD_TRANSFER_START 0x80
  345. #define SD_TRANSFER_END 0x40
  346. #define SD_STAT_IDLE 0x20
  347. #define SD_TRANSFER_ERR 0x10
  348. #define SD_TM_NORMAL_WRITE 0x00
  349. #define SD_TM_AUTO_WRITE_3 0x01
  350. #define SD_TM_AUTO_WRITE_4 0x02
  351. #define SD_TM_AUTO_READ_3 0x05
  352. #define SD_TM_AUTO_READ_4 0x06
  353. #define SD_TM_CMD_RSP 0x08
  354. #define SD_TM_AUTO_WRITE_1 0x09
  355. #define SD_TM_AUTO_WRITE_2 0x0A
  356. #define SD_TM_NORMAL_READ 0x0C
  357. #define SD_TM_AUTO_READ_1 0x0D
  358. #define SD_TM_AUTO_READ_2 0x0E
  359. #define SD_TM_AUTO_TUNING 0x0F
  360. /* SD_CFG1 */
  361. #define SD_CLK_DIVIDE_0 0x00
  362. #define SD_CLK_DIVIDE_256 0xC0
  363. #define SD_CLK_DIVIDE_128 0x80
  364. #define SD_CLK_DIVIDE_MASK 0xC0
  365. #define SD_BUS_WIDTH_1BIT 0x00
  366. #define SD_BUS_WIDTH_4BIT 0x01
  367. #define SD_BUS_WIDTH_8BIT 0x02
  368. #define SD_ASYNC_FIFO_RST 0x10
  369. #define SD_20_MODE 0x00
  370. #define SD_DDR_MODE 0x04
  371. #define SD_30_MODE 0x08
  372. /* SD_CFG2 */
  373. #define SD_CALCULATE_CRC7 0x00
  374. #define SD_NO_CALCULATE_CRC7 0x80
  375. #define SD_CHECK_CRC16 0x00
  376. #define SD_NO_CHECK_CRC16 0x40
  377. #define SD_WAIT_CRC_TO_EN 0x20
  378. #define SD_WAIT_BUSY_END 0x08
  379. #define SD_NO_WAIT_BUSY_END 0x00
  380. #define SD_CHECK_CRC7 0x00
  381. #define SD_NO_CHECK_CRC7 0x04
  382. #define SD_RSP_LEN_0 0x00
  383. #define SD_RSP_LEN_6 0x01
  384. #define SD_RSP_LEN_17 0x02
  385. #define SD_RSP_TYPE_R0 0x04
  386. #define SD_RSP_TYPE_R1 0x01
  387. #define SD_RSP_TYPE_R1b 0x09
  388. #define SD_RSP_TYPE_R2 0x02
  389. #define SD_RSP_TYPE_R3 0x05
  390. #define SD_RSP_TYPE_R4 0x05
  391. #define SD_RSP_TYPE_R5 0x01
  392. #define SD_RSP_TYPE_R6 0x01
  393. #define SD_RSP_TYPE_R7 0x01
  394. /* SD_STAT1 */
  395. #define SD_CRC7_ERR 0x80
  396. #define SD_CRC16_ERR 0x40
  397. #define SD_CRC_WRITE_ERR 0x20
  398. #define SD_CRC_WRITE_ERR_MASK 0x1C
  399. #define GET_CRC_TIME_OUT 0x02
  400. #define SD_TUNING_COMPARE_ERR 0x01
  401. /* SD_DATA_STATE */
  402. #define SD_DATA_IDLE 0x80
  403. /* CARD_DATA_SOURCE */
  404. #define PINGPONG_BUFFER 0x01
  405. #define RING_BUFFER 0x00
  406. /* CARD_OE */
  407. #define SD_OUTPUT_EN 0x04
  408. #define MS_OUTPUT_EN 0x08
  409. /* CARD_STOP */
  410. #define SD_STOP 0x04
  411. #define MS_STOP 0x08
  412. #define SD_CLR_ERR 0x40
  413. #define MS_CLR_ERR 0x80
  414. /* CARD_CLK_SOURCE */
  415. #define CRC_FIX_CLK (0x00 << 0)
  416. #define CRC_VAR_CLK0 (0x01 << 0)
  417. #define CRC_VAR_CLK1 (0x02 << 0)
  418. #define SD30_FIX_CLK (0x00 << 2)
  419. #define SD30_VAR_CLK0 (0x01 << 2)
  420. #define SD30_VAR_CLK1 (0x02 << 2)
  421. #define SAMPLE_FIX_CLK (0x00 << 4)
  422. #define SAMPLE_VAR_CLK0 (0x01 << 4)
  423. #define SAMPLE_VAR_CLK1 (0x02 << 4)
  424. /* SD_SAMPLE_POINT_CTL */
  425. #define DDR_FIX_RX_DAT 0x00
  426. #define DDR_VAR_RX_DAT 0x80
  427. #define DDR_FIX_RX_DAT_EDGE 0x00
  428. #define DDR_FIX_RX_DAT_14_DELAY 0x40
  429. #define DDR_FIX_RX_CMD 0x00
  430. #define DDR_VAR_RX_CMD 0x20
  431. #define DDR_FIX_RX_CMD_POS_EDGE 0x00
  432. #define DDR_FIX_RX_CMD_14_DELAY 0x10
  433. #define SD20_RX_POS_EDGE 0x00
  434. #define SD20_RX_14_DELAY 0x08
  435. #define SD20_RX_SEL_MASK 0x08
  436. /* SD_PUSH_POINT_CTL */
  437. #define DDR_FIX_TX_CMD_DAT 0x00
  438. #define DDR_VAR_TX_CMD_DAT 0x80
  439. #define DDR_FIX_TX_DAT_14_TSU 0x00
  440. #define DDR_FIX_TX_DAT_12_TSU 0x40
  441. #define DDR_FIX_TX_CMD_NEG_EDGE 0x00
  442. #define DDR_FIX_TX_CMD_14_AHEAD 0x20
  443. #define SD20_TX_NEG_EDGE 0x00
  444. #define SD20_TX_14_AHEAD 0x10
  445. #define SD20_TX_SEL_MASK 0x10
  446. #define DDR_VAR_SDCLK_POL_SWAP 0x01
  447. /* MS_CFG */
  448. #define SAMPLE_TIME_RISING 0x00
  449. #define SAMPLE_TIME_FALLING 0x80
  450. #define PUSH_TIME_DEFAULT 0x00
  451. #define PUSH_TIME_ODD 0x40
  452. #define NO_EXTEND_TOGGLE 0x00
  453. #define EXTEND_TOGGLE_CHK 0x20
  454. #define MS_BUS_WIDTH_1 0x00
  455. #define MS_BUS_WIDTH_4 0x10
  456. #define MS_BUS_WIDTH_8 0x18
  457. #define MS_2K_SECTOR_MODE 0x04
  458. #define MS_512_SECTOR_MODE 0x00
  459. #define MS_TOGGLE_TIMEOUT_EN 0x00
  460. #define MS_TOGGLE_TIMEOUT_DISEN 0x01
  461. #define MS_NO_CHECK_INT 0x02
  462. /* MS_TRANS_CFG */
  463. #define WAIT_INT 0x80
  464. #define NO_WAIT_INT 0x00
  465. #define NO_AUTO_READ_INT_REG 0x00
  466. #define AUTO_READ_INT_REG 0x40
  467. #define MS_CRC16_ERR 0x20
  468. #define MS_RDY_TIMEOUT 0x10
  469. #define MS_INT_CMDNK 0x08
  470. #define MS_INT_BREQ 0x04
  471. #define MS_INT_ERR 0x02
  472. #define MS_INT_CED 0x01
  473. /* MS_TRANSFER */
  474. #define MS_TRANSFER_START 0x80
  475. #define MS_TRANSFER_END 0x40
  476. #define MS_TRANSFER_ERR 0x20
  477. #define MS_BS_STATE 0x10
  478. #define MS_TM_READ_BYTES 0x00
  479. #define MS_TM_NORMAL_READ 0x01
  480. #define MS_TM_WRITE_BYTES 0x04
  481. #define MS_TM_NORMAL_WRITE 0x05
  482. #define MS_TM_AUTO_READ 0x08
  483. #define MS_TM_AUTO_WRITE 0x0C
  484. #define MS_TM_SET_CMD 0x06
  485. #define MS_TM_COPY_PAGE 0x07
  486. #define MS_TM_MULTI_READ 0x02
  487. #define MS_TM_MULTI_WRITE 0x03
  488. /* MC_FIFO_CTL */
  489. #define FIFO_FLUSH 0x01
  490. /* MC_DMA_RST */
  491. #define DMA_RESET 0x01
  492. /* MC_DMA_CTL */
  493. #define DMA_TC_EQ_0 0x80
  494. #define DMA_DIR_TO_CARD 0x00
  495. #define DMA_DIR_FROM_CARD 0x02
  496. #define DMA_EN 0x01
  497. #define DMA_128 (0 << 2)
  498. #define DMA_256 (1 << 2)
  499. #define DMA_512 (2 << 2)
  500. #define DMA_1024 (3 << 2)
  501. #define DMA_PACK_SIZE_MASK 0x0C
  502. /* CARD_INT_PEND */
  503. #define XD_INT 0x10
  504. #define MS_INT 0x08
  505. #define SD_INT 0x04
  506. /* LED operations*/
  507. static inline int rtsx_usb_turn_on_led(struct rtsx_ucr *ucr)
  508. {
  509. return rtsx_usb_ep0_write_register(ucr, CARD_GPIO, 0x03, 0x02);
  510. }
  511. static inline int rtsx_usb_turn_off_led(struct rtsx_ucr *ucr)
  512. {
  513. return rtsx_usb_ep0_write_register(ucr, CARD_GPIO, 0x03, 0x03);
  514. }
  515. /* HW error clearing */
  516. static inline void rtsx_usb_clear_fsm_err(struct rtsx_ucr *ucr)
  517. {
  518. rtsx_usb_ep0_write_register(ucr, SFSM_ED, 0xf8, 0xf8);
  519. }
  520. static inline void rtsx_usb_clear_dma_err(struct rtsx_ucr *ucr)
  521. {
  522. rtsx_usb_ep0_write_register(ucr, MC_FIFO_CTL,
  523. FIFO_FLUSH, FIFO_FLUSH);
  524. rtsx_usb_ep0_write_register(ucr, MC_DMA_RST, DMA_RESET, DMA_RESET);
  525. }
  526. #endif /* __RTS51139_H */