Go to the documentation of this file.
27 #ifndef __RTS51X_CHIP_H
28 #define __RTS51X_CHIP_H
40 #define SUPPORT_MAGIC_GATE
42 #define USING_POLLING_CYCLE_DELINK
44 #ifdef SUPPORT_MAGIC_GA
46 #define MG_SET_ICV_SLOW
51 #define SUPPORT_PCGL_1P18
54 #define GET_CARD_STATUS_USING_EPC
56 #define CLOSE_SSC_POWER
62 #define SD_XD_IO_FOLLOW_PWR
67 #define SD_CARD (1 << SD_NR)
68 #define MS_CARD (1 << MS_NR)
69 #define XD_CARD (1 << XD_NR)
76 #define MAX_ALLOWED_LUN_CNT 8
77 #define CMD_BUF_LEN 1024
78 #define POLLING_INTERVAL 50
80 #define XD_FREE_TABLE_CNT 1200
81 #define MS_FREE_TABLE_CNT 512
84 #define SET_BIT(data, idx) ((data) |= 1 << (idx))
85 #define CLR_BIT(data, idx) ((data) &= ~(1 << (idx)))
86 #define CHK_BIT(data, idx) ((data) & (1 << (idx)))
89 #define READ_REG_CMD 0
90 #define WRITE_REG_CMD 1
91 #define CHECK_REG_CMD 2
106 #define STAGE_DI 0x02
107 #define STAGE_DO 0x04
109 #define STAGE_MS_STATUS 0x08
111 #define STAGE_XD_STATUS 0x10
114 #define MODE_CR (STAGE_R)
115 #define MODE_CDIR (STAGE_R | STAGE_DI)
116 #define MODE_CDOR (STAGE_R | STAGE_DO)
119 #ifndef STATUS_SUCCESS
120 #define STATUS_SUCCESS 0
123 #define STATUS_FAIL 1
124 #define STATUS_TIMEDOUT 4
125 #define STATUS_NOMEM 5
126 #define STATUS_TRANS_SHORT 6
127 #define STATUS_TRANS_LONG 7
128 #define STATUS_STALLED 8
129 #define STATUS_ERROR 10
131 #define IDLE_MAX_COUNT 10
132 #define POLLING_WAIT_CNT 1
146 #define TRANSPORT_GOOD 0
148 #define TRANSPORT_FAILED 1
150 #define TRANSPORT_ERROR 3
157 #define TRACE_ITEM_CNT 64
161 #define MSG_FUNC_LEN 64
163 #define MSG_FILE_LEN 32
165 #define TIME_VAL_LEN 16
173 #define SENSE_SIZE 18
176 #define SENSE_TYPE_NO_SENSE 0
177 #define SENSE_TYPE_MEDIA_CHANGE 1
178 #define SENSE_TYPE_MEDIA_NOT_PRESENT 2
179 #define SENSE_TYPE_MEDIA_LBA_OVER_RANGE 3
180 #define SENSE_TYPE_MEDIA_LUN_NOT_SUPPORT 4
181 #define SENSE_TYPE_MEDIA_WRITE_PROTECT 5
182 #define SENSE_TYPE_MEDIA_INVALID_CMD_FIELD 6
183 #define SENSE_TYPE_MEDIA_UNRECOVER_READ_ERR 7
184 #define SENSE_TYPE_MEDIA_WRITE_ERR 8
185 #define SENSE_TYPE_FORMAT_CMD_FAILED 10
186 #ifdef SUPPORT_MAGIC_GATE
188 #define SENSE_TYPE_MG_KEY_FAIL_NOT_ESTAB 0x0b
190 #define SENSE_TYPE_MG_KEY_FAIL_NOT_AUTHEN 0x0c
192 #define SENSE_TYPE_MG_INCOMPATIBLE_MEDIUM 0x0d
194 #define SENSE_TYPE_MG_WRITE_ERR 0x0e
198 #define ILGAL_REQ 0x05
210 #define CDB_ILLEGAL 0x40
213 #define ASC_INVLD_CDB 0x24
216 #define ASCQ_INVLD_CDB 0x00
240 #define SD_PUSH_POINT_CTL_MASK 0x03
241 #define SD_PUSH_POINT_DELAY 0x01
242 #define SD_PUSH_POINT_AUTO 0x02
244 #define SD_SAMPLE_POINT_CTL_MASK 0x0C
245 #define SD_SAMPLE_POINT_DELAY 0x04
246 #define SD_SAMPLE_POINT_AUTO 0x08
248 #define SD_DDR_TX_PHASE_SET_BY_USER 0x10
250 #define MMC_DDR_TX_PHASE_SET_BY_USER 0x20
253 #define SUPPORT_UHS50_MMC44 0x40
340 #define MS_FORMATTER_ENABLED(chip) ((chip)->option.mspro_formatter_enable)
345 u32 sec_addr,
u16 sec_cnt);
348 #define MAX_DEFECTIVE_BLOCK 10
391 #define TYPE_SD 0x0000
392 #define TYPE_MMC 0x0001
396 #define SD_SDR50 0x0200
397 #define SD_DDR50 0x0400
398 #define SD_SDR104 0x0800
399 #define SD_HCXC 0x1000
402 #define MMC_26M 0x0100
403 #define MMC_52M 0x0200
404 #define MMC_4BIT 0x0400
405 #define MMC_8BIT 0x0800
406 #define MMC_SECTOR_MODE 0x1000
407 #define MMC_DDR52 0x2000
410 #define CHK_SD(sd_card) (((sd_card)->sd_type & 0xFF) == TYPE_SD)
411 #define CHK_SD_HS(sd_card) \
412 (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_HS))
413 #define CHK_SD_SDR50(sd_card) \
414 (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_SDR50))
415 #define CHK_SD_DDR50(sd_card) \
416 (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_DDR50))
417 #define CHK_SD_SDR104(sd_card) \
418 (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_SDR104))
419 #define CHK_SD_HCXC(sd_card) \
420 (CHK_SD(sd_card) && ((sd_card)->sd_type & SD_HCXC))
421 #define CHK_SD30_SPEED(sd_card) \
422 (CHK_SD_SDR50(sd_card) || CHK_SD_DDR50(sd_card) ||\
423 CHK_SD_SDR104(sd_card))
425 #define SET_SD(sd_card) ((sd_card)->sd_type = TYPE_SD)
426 #define SET_SD_HS(sd_card) ((sd_card)->sd_type |= SD_HS)
427 #define SET_SD_SDR50(sd_card) ((sd_card)->sd_type |= SD_SDR50)
428 #define SET_SD_DDR50(sd_card) ((sd_card)->sd_type |= SD_DDR50)
429 #define SET_SD_SDR104(sd_card) ((sd_card)->sd_type |= SD_SDR104)
430 #define SET_SD_HCXC(sd_card) ((sd_card)->sd_type |= SD_HCXC)
432 #define CLR_SD_HS(sd_card) ((sd_card)->sd_type &= ~SD_HS)
433 #define CLR_SD_SDR50(sd_card) ((sd_card)->sd_type &= ~SD_SDR50)
434 #define CLR_SD_DDR50(sd_card) ((sd_card)->sd_type &= ~SD_DDR50)
435 #define CLR_SD_SDR104(sd_card) ((sd_card)->sd_type &= ~SD_SDR104)
436 #define CLR_SD_HCXC(sd_card) ((sd_card)->sd_type &= ~SD_HCXC)
437 #define CLR_SD30_SPEED(sd_card) \
438 ((sd_card)->sd_type &= ~(SD_SDR50|SD_DDR50|SD_SDR104))
441 #define CHK_MMC(sd_card) \
442 (((sd_card)->sd_type & 0xFF) == TYPE_MMC)
443 #define CHK_MMC_26M(sd_card) \
444 (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_26M))
445 #define CHK_MMC_52M(sd_card) \
446 (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_52M))
447 #define CHK_MMC_4BIT(sd_card) \
448 (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_4BIT))
449 #define CHK_MMC_8BIT(sd_card) \
450 (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_8BIT))
451 #define CHK_MMC_SECTOR_MODE(sd_card)\
452 (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_SECTOR_MODE))
453 #define CHK_MMC_DDR52(sd_card) \
454 (CHK_MMC(sd_card) && ((sd_card)->sd_type & MMC_DDR52))
456 #define SET_MMC(sd_card) ((sd_card)->sd_type = TYPE_MMC)
457 #define SET_MMC_26M(sd_card) ((sd_card)->sd_type |= MMC_26M)
458 #define SET_MMC_52M(sd_card) ((sd_card)->sd_type |= MMC_52M)
459 #define SET_MMC_4BIT(sd_card) ((sd_card)->sd_type |= MMC_4BIT)
460 #define SET_MMC_8BIT(sd_card) ((sd_card)->sd_type |= MMC_8BIT)
461 #define SET_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type |= MMC_SECTOR_MODE)
462 #define SET_MMC_DDR52(sd_card) ((sd_card)->sd_type |= MMC_DDR52)
464 #define CLR_MMC_26M(sd_card) ((sd_card)->sd_type &= ~MMC_26M)
465 #define CLR_MMC_52M(sd_card) ((sd_card)->sd_type &= ~MMC_52M)
466 #define CLR_MMC_4BIT(sd_card) ((sd_card)->sd_type &= ~MMC_4BIT)
467 #define CLR_MMC_8BIT(sd_card) ((sd_card)->sd_type &= ~MMC_8BIT)
468 #define CLR_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type &= ~MMC_SECTOR_MODE)
469 #define CLR_MMC_DDR52(sd_card) ((sd_card)->sd_type &= ~MMC_DDR52)
471 #define CHK_MMC_HS(sd_card) \
472 (CHK_MMC_52M(sd_card) && CHK_MMC_26M(sd_card))
473 #define CLR_MMC_HS(sd_card) \
475 CLR_MMC_DDR52(sd_card); \
476 CLR_MMC_52M(sd_card); \
477 CLR_MMC_26M(sd_card); \
480 #define SD_SUPPORT_CLASS_TEN 0x01
481 #define SD_SUPPORT_1V8 0x02
483 #define SD_SET_CLASS_TEN(sd_card) \
484 ((sd_card)->sd_setting |= SD_SUPPORT_CLASS_TEN)
485 #define SD_CHK_CLASS_TEN(sd_card) \
486 ((sd_card)->sd_setting & SD_SUPPORT_CLASS_TEN)
487 #define SD_CLR_CLASS_TEN(sd_card) \
488 ((sd_card)->sd_setting &= ~SD_SUPPORT_CLASS_TEN)
489 #define SD_SET_1V8(sd_card) \
490 ((sd_card)->sd_setting |= SD_SUPPORT_1V8)
491 #define SD_CHK_1V8(sd_card) \
492 ((sd_card)->sd_setting & SD_SUPPORT_1V8)
493 #define SD_CLR_1V8(sd_card) \
494 ((sd_card)->sd_setting &= ~SD_SUPPORT_1V8)
495 #define CLR_RETRY_SD20_MODE(sd_card) \
496 ((sd_card)->retry_SD20_mode = 0)
497 #define SET_RETRY_SD20_MODE(sd_card) \
498 ((sd_card)->retry_SD20_mode = 1)
499 #define CHK_RETRY_SD20_MODE(sd_card) \
500 ((sd_card)->retry_SD20_mode == 1)
542 #define MODE_512_SEQ 0x01
543 #define MODE_2K_SEQ 0x02
545 #define TYPE_MS 0x0000
546 #define TYPE_MSPRO 0x0001
548 #define MS_4BIT 0x0100
549 #define MS_8BIT 0x0200
553 #define HG8BIT (MS_HG | MS_8BIT)
555 #define CHK_MSPRO(ms_card) \
556 (((ms_card)->ms_type & 0xFF) == TYPE_MSPRO)
557 #define CHK_HG8BIT(ms_card) \
558 (CHK_MSPRO(ms_card) && (((ms_card)->ms_type & HG8BIT) == HG8BIT))
559 #define CHK_MSXC(ms_card) \
560 (CHK_MSPRO(ms_card) && ((ms_card)->ms_type & MS_XC))
561 #define CHK_MSHG(ms_card) \
562 (CHK_MSPRO(ms_card) && ((ms_card)->ms_type & MS_HG))
564 #define CHK_MS8BIT(ms_card) (((ms_card)->ms_type & MS_8BIT))
565 #define CHK_MS4BIT(ms_card) (((ms_card)->ms_type & MS_4BIT))
594 #ifdef SUPPORT_PCGL_1P18
614 #ifdef SUPPORT_MAGIC_GATE
621 #define PRO_UNDER_FORMATTING(ms_card) \
622 ((ms_card)->pro_under_formatting)
623 #define SET_FORMAT_STATUS(ms_card, status) \
624 ((ms_card)->format_status = (status))
625 #define CHK_FORMAT_STATUS(ms_card, status) \
626 ((ms_card)->format_status == (status))
723 #define UHS50_EN 0x0001
724 #define UHS50_DIS 0x0000
725 #define SET_UHS50(chip) ((chip)->uhs50_mmc44_en = UHS50_EN)
726 #define CLEAR_UHS50(chip) ((chip)->uhs50_mmc44_en = UHS50_DIS)
727 #define CHECK_UHS50(chip) (((chip)->uhs50_mmc44_en&0xff) == UHS50_EN)
729 #define RTS51X_GET_VID(chip) ((chip)->vendor_id)
730 #define RTS51X_GET_PID(chip) ((chip)->product_id)
732 #define RTS51X_SET_STAT(chip, stat) \
734 if ((stat) != STAT_IDLE) { \
735 (chip)->idle_counter = 0; \
737 (chip)->chip_stat = (enum CHIP_STAT)(stat); \
739 #define RTS51X_CHK_STAT(chip, stat) ((chip)->chip_stat == (stat))
740 #define RTS51X_GET_STAT(chip) ((chip)->chip_stat)
742 #define CHECK_PID(chip, pid) (RTS51X_GET_PID(chip) == (pid))
743 #define CHECK_PKG(chip, pkg) ((chip)->package == (pkg))
744 #define CHECK_USB(chip, speed) ((chip)->usb_speed == (speed))
751 static inline void rts51x_init_cmd(
struct rts51x_chip *chip)
767 u8 *
buf,
int buf_len)
772 static inline u8 *rts51x_get_rsp_data(
struct rts51x_chip *chip)
800 void *
buf,
unsigned int len,
int use_sg,
801 unsigned int *act_len,
int timeout,
u8 stage_flag);
803 #define RTS51X_WRITE_REG(chip, addr, mask, data) \
805 int _retval = rts51x_write_register((chip), \
806 (addr), (mask), (data)); \
807 if (_retval != STATUS_SUCCESS) { \
808 TRACE_RET((chip), _retval); \
812 #define RTS51X_READ_REG(chip, addr, data) \
814 int _retval = rts51x_read_register((chip), \
816 if (_retval != STATUS_SUCCESS) { \
817 TRACE_RET((chip), _retval); \