rtsx_usb.h 16 KB

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