Go to the documentation of this file.
24 #ifndef __REALTEK_RTSX_CHIP_H
25 #define __REALTEK_RTSX_CHIP_H
31 #define SUPPORT_SDIO_ASPM
32 #define SUPPORT_MAGIC_GATE
34 #define SUPPORT_SD_LOCK
36 #define HW_AUTO_SWITCH_SD_BUS
38 #define HW_INT_WRITE_CLR
42 #ifdef SUPPORT_MAGIC_GATE
44 #define MG_SET_ICV_SLOW
46 #define MS_SAMPLE_INT_ERR
48 #define READ_BYTES_WAIT_INT
53 #define SUPPORT_PCGL_1P18
56 #ifndef LED_AUTO_BLINK
60 #define LED_BLINK_SPEED 5
61 #define LED_TOGGLE_INTERVAL 6
62 #define GPIO_TOGGLE_THRESHOLD 1024
65 #define POLLING_INTERVAL 30
67 #define TRACE_ITEM_CNT 64
69 #ifndef STATUS_SUCCESS
70 #define STATUS_SUCCESS 0
75 #ifndef STATUS_TIMEDOUT
76 #define STATUS_TIMEDOUT 2
79 #define STATUS_NOMEM 3
81 #ifndef STATUS_READ_FAIL
82 #define STATUS_READ_FAIL 4
84 #ifndef STATUS_WRITE_FAIL
85 #define STATUS_WRITE_FAIL 5
88 #define STATUS_ERROR 10
98 #define TRANSPORT_GOOD 0
99 #define TRANSPORT_FAILED 1
100 #define TRANSPORT_NO_SENSE 2
101 #define TRANSPORT_ERROR 3
107 #define STOP_MEDIUM 0x00
108 #define MAKE_MEDIUM_READY 0x01
109 #define UNLOAD_MEDIUM 0x02
110 #define LOAD_MEDIUM 0x03
115 #define QULIFIRE 0x00
116 #define AENC_FNC 0x00
117 #define TRML_IOP 0x00
127 #define PRDCT_ID_LEN 16
128 #define PRDCT_REV_LEN 4
131 #define RTSX_FLIDX_TRANS_ACTIVE 18
132 #define RTSX_FLIDX_ABORTING 20
133 #define RTSX_FLIDX_DISCONNECTING 21
134 #define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
135 (1UL << US_FLIDX_DISCONNECTING))
136 #define RTSX_FLIDX_RESETTING 22
137 #define RTSX_FLIDX_TIMED_OUT 23
139 #define DRCT_ACCESS_DEV 0x00
140 #define RMB_DISC 0x80
141 #define ANSI_SCSI2 0x02
145 #define WRITE_PROTECTED_MEDIA 0x07
150 #define NO_SENSE 0x00
151 #define RECOVER_ERR 0x01
152 #define NOT_READY 0x02
153 #define MEDIA_ERR 0x03
154 #define HARDWARE_ERR 0x04
155 #define ILGAL_REQ 0x05
156 #define UNIT_ATTENTION 0x06
157 #define DAT_PRTCT 0x07
158 #define BLNC_CHK 0x08
160 #define CPY_ABRT 0x0a
161 #define ABRT_CMD 0x0b
163 #define VLM_OVRFLW 0x0d
169 #define FIRST_RESET 0x01
170 #define USED_EXIST 0x02
176 #define SENSE_VALID 0x80
177 #define SENSE_INVALID 0x00
184 #define SNSKEYINFO_LEN 3
187 #define CDB_ILLEGAL 0x40
188 #define DAT_ILLEGAL 0x00
190 #define BIT_ILLEGAL0 0
191 #define BIT_ILLEGAL1 1
192 #define BIT_ILLEGAL2 2
193 #define BIT_ILLEGAL3 3
194 #define BIT_ILLEGAL4 4
195 #define BIT_ILLEGAL5 5
196 #define BIT_ILLEGAL6 6
197 #define BIT_ILLEGAL7 7
200 #define ASC_NO_INFO 0x00
201 #define ASC_MISCMP 0x1d
202 #define ASC_INVLD_CDB 0x24
203 #define ASC_INVLD_PARA 0x26
204 #define ASC_LU_NOT_READY 0x04
205 #define ASC_WRITE_ERR 0x0c
206 #define ASC_READ_ERR 0x11
207 #define ASC_LOAD_EJCT_ERR 0x53
208 #define ASC_MEDIA_NOT_PRESENT 0x3A
209 #define ASC_MEDIA_CHANGED 0x28
210 #define ASC_MEDIA_IN_PROCESS 0x04
211 #define ASC_WRITE_PROTECT 0x27
212 #define ASC_LUN_NOT_SUPPORTED 0x25
215 #define ASCQ_NO_INFO 0x00
216 #define ASCQ_MEDIA_IN_PROCESS 0x01
217 #define ASCQ_MISCMP 0x00
218 #define ASCQ_INVLD_CDB 0x00
219 #define ASCQ_INVLD_PARA 0x02
220 #define ASCQ_LU_NOT_READY 0x02
221 #define ASCQ_WRITE_ERR 0x02
222 #define ASCQ_READ_ERR 0x00
223 #define ASCQ_LOAD_EJCT_ERR 0x00
224 #define ASCQ_WRITE_PROTECT 0x00
238 unsigned char info[4];
248 #define RTSX_HCBAR 0x00
249 #define RTSX_HCBCTLR 0x04
250 #define RTSX_HDBAR 0x08
251 #define RTSX_HDBCTLR 0x0C
252 #define RTSX_HAIMR 0x10
253 #define RTSX_BIPR 0x14
254 #define RTSX_BIER 0x18
257 #define STOP_CMD (0x01 << 28)
260 #define SDMA_MODE 0x00
261 #define ADMA_MODE (0x02 << 26)
262 #define STOP_DMA (0x01 << 28)
263 #define TRIG_DMA (0x01 << 31)
266 #define CMD_DONE_INT (1 << 31)
267 #define DATA_DONE_INT (1 << 30)
268 #define TRANS_OK_INT (1 << 29)
269 #define TRANS_FAIL_INT (1 << 28)
270 #define XD_INT (1 << 27)
271 #define MS_INT (1 << 26)
272 #define SD_INT (1 << 25)
273 #define GPIO0_INT (1 << 24)
274 #define OC_INT (1 << 23)
275 #define SD_WRITE_PROTECT (1 << 19)
276 #define XD_EXIST (1 << 18)
277 #define MS_EXIST (1 << 17)
278 #define SD_EXIST (1 << 16)
279 #define DELINK_INT GPIO0_INT
280 #define MS_OC_INT (1 << 23)
281 #define SD_OC_INT (1 << 22)
283 #define CARD_INT (XD_INT | MS_INT | SD_INT)
284 #define NEED_COMPLETE_INT (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
285 #define RTSX_INT (CMD_DONE_INT | NEED_COMPLETE_INT | CARD_INT | GPIO0_INT | OC_INT)
287 #define CARD_EXIST (XD_EXIST | MS_EXIST | SD_EXIST)
290 #define CMD_DONE_INT_EN (1 << 31)
291 #define DATA_DONE_INT_EN (1 << 30)
292 #define TRANS_OK_INT_EN (1 << 29)
293 #define TRANS_FAIL_INT_EN (1 << 28)
294 #define XD_INT_EN (1 << 27)
295 #define MS_INT_EN (1 << 26)
296 #define SD_INT_EN (1 << 25)
297 #define GPIO0_INT_EN (1 << 24)
298 #define OC_INT_EN (1 << 23)
299 #define DELINK_INT_EN GPIO0_INT_EN
300 #define MS_OC_INT_EN (1 << 23)
301 #define SD_OC_INT_EN (1 << 22)
304 #define READ_REG_CMD 0
305 #define WRITE_REG_CMD 1
306 #define CHECK_REG_CMD 2
308 #define HOST_TO_DEVICE 0
309 #define DEVICE_TO_HOST 1
312 #define RTSX_RESV_BUF_LEN 4096
313 #define HOST_CMDS_BUF_LEN 1024
314 #define HOST_SG_TBL_BUF_LEN (RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
320 #define SD_CARD (1 << SD_NR)
321 #define MS_CARD (1 << MS_NR)
322 #define XD_CARD (1 << XD_NR)
323 #define SPI_CARD (1 << SPI_NR)
325 #define MAX_ALLOWED_LUN_CNT 8
327 #define XD_FREE_TABLE_CNT 1200
328 #define MS_FREE_TABLE_CNT 512
332 #define SET_BIT(data, idx) ((data) |= 1 << (idx))
333 #define CLR_BIT(data, idx) ((data) &= ~(1 << (idx)))
334 #define CHK_BIT(data, idx) ((data) & (1 << (idx)))
339 #define SG_VALID 0x01
341 #define SG_NO_OP 0x00
342 #define SG_TRANS_DATA (0x02 << 4)
343 #define SG_LINK_DESC (0x03 << 4)
356 #define MAX_RESET_CNT 3
359 #define MAX_DEFECTIVE_BLOCK 10
373 #define TYPE_SD 0x0000
374 #define TYPE_MMC 0x0001
378 #define SD_SDR50 0x0200
379 #define SD_DDR50 0x0400
380 #define SD_SDR104 0x0800
381 #define SD_HCXC 0x1000
384 #define MMC_26M 0x0100
385 #define MMC_52M 0x0200
386 #define MMC_4BIT 0x0400
387 #define MMC_8BIT 0x0800
388 #define MMC_SECTOR_MODE 0x1000
389 #define MMC_DDR52 0x2000
392 #define CHK_SD(sd_card) (((sd_card)->sd_type & 0xFF) == TYPE_SD)
393 #define CHK_SD_HS(sd_card) (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_HS))
394 #define CHK_SD_SDR50(sd_card) (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_SDR50))
395 #define CHK_SD_DDR50(sd_card) (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_DDR50))
396 #define CHK_SD_SDR104(sd_card) (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_SDR104))
397 #define CHK_SD_HCXC(sd_card) (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_HCXC))
398 #define CHK_SD_HC(sd_card) (CHK_SD_HCXC(sd_card) && ((sd_card)->capacity <= 0x4000000))
399 #define CHK_SD_XC(sd_card) (CHK_SD_HCXC(sd_card) && ((sd_card)->capacity > 0x4000000))
400 #define CHK_SD30_SPEED(sd_card) (CHK_SD_SDR50(sd_card) || CHK_SD_DDR50(sd_card) || CHK_SD_SDR104(sd_card))
402 #define SET_SD(sd_card) ((sd_card)->sd_type = TYPE_SD)
403 #define SET_SD_HS(sd_card) ((sd_card)->sd_type |= SD_HS)
404 #define SET_SD_SDR50(sd_card) ((sd_card)->sd_type |= SD_SDR50)
405 #define SET_SD_DDR50(sd_card) ((sd_card)->sd_type |= SD_DDR50)
406 #define SET_SD_SDR104(sd_card) ((sd_card)->sd_type |= SD_SDR104)
407 #define SET_SD_HCXC(sd_card) ((sd_card)->sd_type |= SD_HCXC)
409 #define CLR_SD_HS(sd_card) ((sd_card)->sd_type &= ~SD_HS)
410 #define CLR_SD_SDR50(sd_card) ((sd_card)->sd_type &= ~SD_SDR50)
411 #define CLR_SD_DDR50(sd_card) ((sd_card)->sd_type &= ~SD_DDR50)
412 #define CLR_SD_SDR104(sd_card) ((sd_card)->sd_type &= ~SD_SDR104)
413 #define CLR_SD_HCXC(sd_card) ((sd_card)->sd_type &= ~SD_HCXC)
416 #define CHK_MMC(sd_card) (((sd_card)->sd_type & 0xFF) == TYPE_MMC)
417 #define CHK_MMC_26M(sd_card) (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_26M))
418 #define CHK_MMC_52M(sd_card) (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_52M))
419 #define CHK_MMC_4BIT(sd_card) (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_4BIT))
420 #define CHK_MMC_8BIT(sd_card) (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_8BIT))
421 #define CHK_MMC_SECTOR_MODE(sd_card) (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_SECTOR_MODE))
422 #define CHK_MMC_DDR52(sd_card) (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_DDR52))
424 #define SET_MMC(sd_card) ((sd_card)->sd_type = TYPE_MMC)
425 #define SET_MMC_26M(sd_card) ((sd_card)->sd_type |= MMC_26M)
426 #define SET_MMC_52M(sd_card) ((sd_card)->sd_type |= MMC_52M)
427 #define SET_MMC_4BIT(sd_card) ((sd_card)->sd_type |= MMC_4BIT)
428 #define SET_MMC_8BIT(sd_card) ((sd_card)->sd_type |= MMC_8BIT)
429 #define SET_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type |= MMC_SECTOR_MODE)
430 #define SET_MMC_DDR52(sd_card) ((sd_card)->sd_type |= MMC_DDR52)
432 #define CLR_MMC_26M(sd_card) ((sd_card)->sd_type &= ~MMC_26M)
433 #define CLR_MMC_52M(sd_card) ((sd_card)->sd_type &= ~MMC_52M)
434 #define CLR_MMC_4BIT(sd_card) ((sd_card)->sd_type &= ~MMC_4BIT)
435 #define CLR_MMC_8BIT(sd_card) ((sd_card)->sd_type &= ~MMC_8BIT)
436 #define CLR_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type &= ~MMC_SECTOR_MODE)
437 #define CLR_MMC_DDR52(sd_card) ((sd_card)->sd_type &= ~MMC_DDR52)
439 #define CHK_MMC_HS(sd_card) (CHK_MMC_52M(sd_card) && CHK_MMC_26M(sd_card))
440 #define CLR_MMC_HS(sd_card) \
442 CLR_MMC_DDR52(sd_card); \
443 CLR_MMC_52M(sd_card); \
444 CLR_MMC_26M(sd_card); \
447 #define SD_SUPPORT_CLASS_TEN 0x01
448 #define SD_SUPPORT_1V8 0x02
450 #define SD_SET_CLASS_TEN(sd_card) ((sd_card)->sd_setting |= SD_SUPPORT_CLASS_TEN)
451 #define SD_CHK_CLASS_TEN(sd_card) ((sd_card)->sd_setting & SD_SUPPORT_CLASS_TEN)
452 #define SD_CLR_CLASS_TEN(sd_card) ((sd_card)->sd_setting &= ~SD_SUPPORT_CLASS_TEN)
453 #define SD_SET_1V8(sd_card) ((sd_card)->sd_setting |= SD_SUPPORT_1V8)
454 #define SD_CHK_1V8(sd_card) ((sd_card)->sd_setting & SD_SUPPORT_1V8)
455 #define SD_CLR_1V8(sd_card) ((sd_card)->sd_setting &= ~SD_SUPPORT_1V8)
494 #ifdef SUPPORT_SD_LOCK
530 #define MODE_512_SEQ 0x01
531 #define MODE_2K_SEQ 0x02
533 #define TYPE_MS 0x0000
534 #define TYPE_MSPRO 0x0001
536 #define MS_4BIT 0x0100
537 #define MS_8BIT 0x0200
541 #define HG8BIT (MS_HG | MS_8BIT)
543 #define CHK_MSPRO(ms_card) (((ms_card)->ms_type & 0xFF) == TYPE_MSPRO)
544 #define CHK_HG8BIT(ms_card) (CHK_MSPRO(ms_card) && (((ms_card)->ms_type & HG8BIT) == HG8BIT))
545 #define CHK_MSXC(ms_card) (CHK_MSPRO(ms_card) && ((ms_card)->ms_type & MS_XC))
546 #define CHK_MSHG(ms_card) (CHK_MSPRO(ms_card) && ((ms_card)->ms_type & MS_HG))
548 #define CHK_MS8BIT(ms_card) (((ms_card)->ms_type & MS_8BIT))
549 #define CHK_MS4BIT(ms_card) (((ms_card)->ms_type & MS_4BIT))
578 #ifdef SUPPORT_PCGL_1P18
597 #ifdef SUPPORT_MAGIC_GATE
617 #define MSG_FUNC_LEN 64
619 #define MSG_FILE_LEN 32
621 #define TIME_VAL_LEN 16
631 #define DEFAULT_SINGLE 0
637 #define LAST_LUN_MODE 2
647 #define SD_PUSH_POINT_CTL_MASK 0x03
648 #define SD_PUSH_POINT_DELAY 0x01
649 #define SD_PUSH_POINT_AUTO 0x02
651 #define SD_SAMPLE_POINT_CTL_MASK 0x0C
652 #define SD_SAMPLE_POINT_DELAY 0x04
653 #define SD_SAMPLE_POINT_AUTO 0x08
655 #define SD_DDR_TX_PHASE_SET_BY_USER 0x10
657 #define MMC_DDR_TX_PHASE_SET_BY_USER 0x20
659 #define SUPPORT_MMC_DDR_MODE 0x40
661 #define RESET_MMC_FIRST 0x80
663 #define SEQ_START_CRITERIA 0x20
666 #define POWER_CLASS_2_EN 0x02
667 #define POWER_CLASS_1_EN 0x01
669 #define MAX_SHOW_CNT 10
670 #define MAX_RESET_CNT 3
672 #define SDIO_EXIST 0x01
673 #define SDIO_IGNORED 0x02
675 #define CHK_SDIO_EXIST(chip) ((chip)->sdio_func_exist & SDIO_EXIST)
676 #define SET_SDIO_EXIST(chip) ((chip)->sdio_func_exist |= SDIO_EXIST)
677 #define CLR_SDIO_EXIST(chip) ((chip)->sdio_func_exist &= ~SDIO_EXIST)
679 #define CHK_SDIO_IGNORED(chip) ((chip)->sdio_func_exist & SDIO_IGNORED)
680 #define SET_SDIO_IGNORED(chip) ((chip)->sdio_func_exist |= SDIO_IGNORED)
681 #define CLR_SDIO_IGNORED(chip) ((chip)->sdio_func_exist &= ~SDIO_IGNORED)
728 #ifndef LED_AUTO_BLINK
792 #ifdef HW_AUTO_SWITCH_SD_BUS
913 #define rtsx_set_stat(chip, stat) \
915 if ((stat) != RTSX_STAT_IDLE) { \
916 (chip)->idle_counter = 0; \
918 (chip)->rtsx_stat = (enum RTSX_STAT)(stat); \
920 #define rtsx_get_stat(chip) ((chip)->rtsx_stat)
921 #define rtsx_chk_stat(chip, stat) ((chip)->rtsx_stat == (stat))
923 #define RTSX_SET_DELINK(chip) ((chip)->rtsx_flag |= 0x01)
924 #define RTSX_CLR_DELINK(chip) ((chip)->rtsx_flag &= 0xFE)
925 #define RTSX_TST_DELINK(chip) ((chip)->rtsx_flag & 0x01)
927 #define CHECK_PID(chip, pid) ((chip)->product_id == (pid))
928 #define CHECK_BARO_PKG(chip, pkg) ((chip)->baro_pkg == (pkg))
929 #define CHECK_LUN_MODE(chip, mode) ((chip)->lun_mode == (mode))
932 #define SSC_PDCTL 0x01
933 #define OC_PDCTL 0x02
973 #define RTSX_WRITE_REG(chip, addr, mask, data) \
975 int retval = rtsx_write_register((chip), (addr), (mask), (data)); \
976 if (retval != STATUS_SUCCESS) { \
977 TRACE_RET((chip), retval); \
981 #define RTSX_READ_REG(chip, addr, data) \
983 int retval = rtsx_read_register((chip), (addr), (data)); \
984 if (retval != STATUS_SUCCESS) { \
985 TRACE_RET((chip), retval); \