1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Driver for Realtek PCI-Express card reader
5 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
12 #ifndef __REALTEK_RTSX_CHIP_H
13 #define __REALTEK_RTSX_CHIP_H
19 #define SUPPORT_SDIO_ASPM
20 #define SUPPORT_MAGIC_GATE
22 #define SUPPORT_SD_LOCK
23 /* Hardware switch bus_ctl and cd_ctl automatically */
24 #define HW_AUTO_SWITCH_SD_BUS
25 /* Enable hardware interrupt write clear */
26 #define HW_INT_WRITE_CLR
27 /* #define LED_AUTO_BLINK */
28 /* #define DISABLE_CARD_INT */
30 #ifdef SUPPORT_MAGIC_GATE
31 /* Using NORMAL_WRITE instead of AUTO_WRITE to set ICV */
32 #define MG_SET_ICV_SLOW
33 /* HW may miss ERR/CMDNK signal when sampling INT status. */
34 #define MS_SAMPLE_INT_ERR
36 * HW DO NOT support Wait_INT function
37 * during READ_BYTES transfer mode
39 #define READ_BYTES_WAIT_INT
44 #define SUPPORT_PCGL_1P18
47 #ifndef LED_AUTO_BLINK
51 #define LED_BLINK_SPEED 5
52 #define LED_TOGGLE_INTERVAL 6
53 #define GPIO_TOGGLE_THRESHOLD 1024
56 #define POLLING_INTERVAL 30
58 #define TRACE_ITEM_CNT 64
60 #ifndef STATUS_SUCCESS
61 #define STATUS_SUCCESS 0
66 #ifndef STATUS_TIMEDOUT
67 #define STATUS_TIMEDOUT 2
70 #define STATUS_NOMEM 3
72 #ifndef STATUS_READ_FAIL
73 #define STATUS_READ_FAIL 4
75 #ifndef STATUS_WRITE_FAIL
76 #define STATUS_WRITE_FAIL 5
79 #define STATUS_ERROR 10
86 * Transport return codes
89 #define TRANSPORT_GOOD 0 /* Transport good, command good */
90 #define TRANSPORT_FAILED 1 /* Transport good, command failed */
91 #define TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */
92 #define TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */
97 #define STOP_MEDIUM 0x00 /* access disable */
98 #define MAKE_MEDIUM_READY 0x01 /* access enable */
99 #define UNLOAD_MEDIUM 0x02 /* unload */
100 #define LOAD_MEDIUM 0x03 /* load */
105 #define QULIFIRE 0x00
106 #define AENC_FNC 0x00
107 #define TRML_IOP 0x00
116 #define VEN_ID_LEN 8 /* Vendor ID Length */
117 #define PRDCT_ID_LEN 16 /* Product ID Length */
118 #define PRDCT_REV_LEN 4 /* Product LOT Length */
120 /* Dynamic flag definitions: used in set_bit() etc. */
121 /* 0x00040000 transfer is active */
122 #define RTSX_FLIDX_TRANS_ACTIVE 18
123 /* 0x00100000 abort is in progress */
124 #define RTSX_FLIDX_ABORTING 20
125 /* 0x00200000 disconnect in progress */
126 #define RTSX_FLIDX_DISCONNECTING 21
128 #define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
129 (1UL << US_FLIDX_DISCONNECTING))
131 /* 0x00400000 device reset in progress */
132 #define RTSX_FLIDX_RESETTING 22
133 /* 0x00800000 SCSI midlayer timed out */
134 #define RTSX_FLIDX_TIMED_OUT 23
135 #define DRCT_ACCESS_DEV 0x00 /* Direct Access Device */
136 #define RMB_DISC 0x80 /* The Device is Removable */
137 #define ANSI_SCSI2 0x02 /* Based on ANSI-SCSI2 */
139 #define SCSI 0x00 /* Interface ID */
141 #define WRITE_PROTECTED_MEDIA 0x07
143 /*---- sense key ----*/
144 #define ILI 0x20 /* ILI bit is on */
146 #define NO_SENSE 0x00 /* not exist sense key */
147 #define RECOVER_ERR 0x01 /* Target/Logical unit is recoverd */
148 #define NOT_READY 0x02 /* Logical unit is not ready */
149 #define MEDIA_ERR 0x03 /* medium/data error */
150 #define HARDWARE_ERR 0x04 /* hardware error */
151 #define ILGAL_REQ 0x05 /* CDB/parameter/identify msg error */
152 #define UNIT_ATTENTION 0x06 /* unit attention condition occur */
153 #define DAT_PRTCT 0x07 /* read/write is desable */
154 #define BLNC_CHK 0x08 /* find blank/DOF in read */
155 /* write to unblank area */
156 #define CPY_ABRT 0x0a /* Copy/Compare/Copy&Verify illegal */
157 #define ABRT_CMD 0x0b /* Target make the command in error */
158 #define EQUAL 0x0c /* Search Data end with Equal */
159 #define VLM_OVRFLW 0x0d /* Some data are left in buffer */
160 #define MISCMP 0x0e /* find inequality */
165 #define FIRST_RESET 0x01
166 #define USED_EXIST 0x02
172 #define SENSE_VALID 0x80 /* Sense data is valid as SCSI2 */
173 #define SENSE_INVALID 0x00 /* Sense data is invalid as SCSI2 */
175 /*---- error code ----*/
176 #define CUR_ERR 0x70 /* current error */
177 #define DEF_ERR 0x71 /* specific command error */
179 /*---- sense key Information ----*/
180 #define SNSKEYINFO_LEN 3 /* length of sense key information */
183 #define CDB_ILLEGAL 0x40
184 #define DAT_ILLEGAL 0x00
186 #define BIT_ILLEGAL0 0 /* bit0 is illegal */
187 #define BIT_ILLEGAL1 1 /* bit1 is illegal */
188 #define BIT_ILLEGAL2 2 /* bit2 is illegal */
189 #define BIT_ILLEGAL3 3 /* bit3 is illegal */
190 #define BIT_ILLEGAL4 4 /* bit4 is illegal */
191 #define BIT_ILLEGAL5 5 /* bit5 is illegal */
192 #define BIT_ILLEGAL6 6 /* bit6 is illegal */
193 #define BIT_ILLEGAL7 7 /* bit7 is illegal */
196 #define ASC_NO_INFO 0x00
197 #define ASC_MISCMP 0x1d
198 #define ASC_INVLD_CDB 0x24
199 #define ASC_INVLD_PARA 0x26
200 #define ASC_LU_NOT_READY 0x04
201 #define ASC_WRITE_ERR 0x0c
202 #define ASC_READ_ERR 0x11
203 #define ASC_LOAD_EJCT_ERR 0x53
204 #define ASC_MEDIA_NOT_PRESENT 0x3A
205 #define ASC_MEDIA_CHANGED 0x28
206 #define ASC_MEDIA_IN_PROCESS 0x04
207 #define ASC_WRITE_PROTECT 0x27
208 #define ASC_LUN_NOT_SUPPORTED 0x25
211 #define ASCQ_NO_INFO 0x00
212 #define ASCQ_MEDIA_IN_PROCESS 0x01
213 #define ASCQ_MISCMP 0x00
214 #define ASCQ_INVLD_CDB 0x00
215 #define ASCQ_INVLD_PARA 0x02
216 #define ASCQ_LU_NOT_READY 0x02
217 #define ASCQ_WRITE_ERR 0x02
218 #define ASCQ_READ_ERR 0x00
219 #define ASCQ_LOAD_EJCT_ERR 0x00
220 #define ASCQ_WRITE_PROTECT 0x00
222 struct sense_data_t {
223 unsigned char err_code; /* error code */
226 /* (0 : Vendor * specific) */
227 /* bit6-0 : error * code */
228 /* (0x70 : current * error) */
229 /* (0x71 : specific command error) */
230 unsigned char seg_no; /* segment No. */
231 unsigned char sense_key; /* byte5 : ILI */
232 /* bit3-0 : sense key */
233 unsigned char info[4]; /* information */
234 unsigned char ad_sense_len; /* additional sense data length */
235 unsigned char cmd_info[4]; /* command specific information */
236 unsigned char asc; /* ASC */
237 unsigned char ascq; /* ASCQ */
238 unsigned char rfu; /* FRU */
239 unsigned char sns_key_info[3];/* sense key specific information */
242 /* PCI Operation Register Address */
243 #define RTSX_HCBAR 0x00
244 #define RTSX_HCBCTLR 0x04
245 #define RTSX_HDBAR 0x08
246 #define RTSX_HDBCTLR 0x0C
247 #define RTSX_HAIMR 0x10
248 #define RTSX_BIPR 0x14
249 #define RTSX_BIER 0x18
251 /* Host command buffer control register */
252 #define STOP_CMD (0x01 << 28)
254 /* Host data buffer control register */
255 #define SDMA_MODE 0x00
256 #define ADMA_MODE (0x02 << 26)
257 #define STOP_DMA (0x01 << 28)
258 #define TRIG_DMA (0x01 << 31)
260 /* Bus interrupt pending register */
261 #define CMD_DONE_INT BIT(31)
262 #define DATA_DONE_INT BIT(30)
263 #define TRANS_OK_INT BIT(29)
264 #define TRANS_FAIL_INT BIT(28)
265 #define XD_INT BIT(27)
266 #define MS_INT BIT(26)
267 #define SD_INT BIT(25)
268 #define GPIO0_INT BIT(24)
269 #define OC_INT BIT(23)
270 #define SD_WRITE_PROTECT BIT(19)
271 #define XD_EXIST BIT(18)
272 #define MS_EXIST BIT(17)
273 #define SD_EXIST BIT(16)
274 #define DELINK_INT GPIO0_INT
275 #define MS_OC_INT BIT(23)
276 #define SD_OC_INT BIT(22)
278 #define CARD_INT (XD_INT | MS_INT | SD_INT)
279 #define NEED_COMPLETE_INT (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
280 #define RTSX_INT (CMD_DONE_INT | NEED_COMPLETE_INT | CARD_INT | \
283 #define CARD_EXIST (XD_EXIST | MS_EXIST | SD_EXIST)
285 /* Bus interrupt enable register */
286 #define CMD_DONE_INT_EN BIT(31)
287 #define DATA_DONE_INT_EN BIT(30)
288 #define TRANS_OK_INT_EN BIT(29)
289 #define TRANS_FAIL_INT_EN BIT(28)
290 #define XD_INT_EN BIT(27)
291 #define MS_INT_EN BIT(26)
292 #define SD_INT_EN BIT(25)
293 #define GPIO0_INT_EN BIT(24)
294 #define OC_INT_EN BIT(23)
295 #define DELINK_INT_EN GPIO0_INT_EN
296 #define MS_OC_INT_EN BIT(23)
297 #define SD_OC_INT_EN BIT(22)
299 #define READ_REG_CMD 0
300 #define WRITE_REG_CMD 1
301 #define CHECK_REG_CMD 2
303 #define HOST_TO_DEVICE 0
304 #define DEVICE_TO_HOST 1
306 #define RTSX_RESV_BUF_LEN 4096
307 #define HOST_CMDS_BUF_LEN 1024
308 #define HOST_SG_TBL_BUF_LEN (RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
314 #define SD_CARD BIT(SD_NR)
315 #define MS_CARD BIT(MS_NR)
316 #define XD_CARD BIT(XD_NR)
317 #define SPI_CARD BIT(SPI_NR)
319 #define MAX_ALLOWED_LUN_CNT 8
321 #define XD_FREE_TABLE_CNT 1200
322 #define MS_FREE_TABLE_CNT 512
325 #define SET_BIT(data, idx) ((data) |= 1 << (idx))
326 #define CLR_BIT(data, idx) ((data) &= ~(1 << (idx)))
327 #define CHK_BIT(data, idx) ((data) & (1 << (idx)))
330 #define RTSX_SG_INT 0x04
331 #define RTSX_SG_END 0x02
332 #define RTSX_SG_VALID 0x01
334 #define RTSX_SG_NO_OP 0x00
335 #define RTSX_SG_TRANS_DATA (0x02 << 4)
336 #define RTSX_SG_LINK_DESC (0x03 << 4)
340 typedef int (*card_rw_func)(struct scsi_cmnd *srb, struct rtsx_chip *chip,
341 u32 sec_addr, u16 sec_cnt);
343 /* Supported Clock */
344 enum card_clock {CLK_20 = 1, CLK_30, CLK_40, CLK_50, CLK_60,
345 CLK_80, CLK_100, CLK_120, CLK_150, CLK_200};
347 enum RTSX_STAT {RTSX_STAT_INIT, RTSX_STAT_IDLE, RTSX_STAT_RUN, RTSX_STAT_SS,
348 RTSX_STAT_DELINK, RTSX_STAT_SUSPEND,
349 RTSX_STAT_ABORT, RTSX_STAT_DISCONNECT};
350 enum IC_VER {IC_VER_AB, IC_VER_C = 2, IC_VER_D = 3};
352 #define MAX_RESET_CNT 3
355 #define MAX_DEFECTIVE_BLOCK 10
360 u16 defect_list[MAX_DEFECTIVE_BLOCK]; /* For MS card only */
365 /* To indicate whether the L2P table of this zone has been built. */
369 #define TYPE_SD 0x0000
370 #define TYPE_MMC 0x0001
374 #define SD_SDR50 0x0200
375 #define SD_DDR50 0x0400
376 #define SD_SDR104 0x0800
377 #define SD_HCXC 0x1000
380 #define MMC_26M 0x0100
381 #define MMC_52M 0x0200
382 #define MMC_4BIT 0x0400
383 #define MMC_8BIT 0x0800
384 #define MMC_SECTOR_MODE 0x1000
385 #define MMC_DDR52 0x2000
388 #define CHK_SD(sd_card) (((sd_card)->sd_type & 0xFF) == TYPE_SD)
389 #define CHK_SD_HS(sd_card) (CHK_SD(sd_card) && \
390 ((sd_card)->sd_type & SD_HS))
391 #define CHK_SD_SDR50(sd_card) (CHK_SD(sd_card) && \
392 ((sd_card)->sd_type & SD_SDR50))
393 #define CHK_SD_DDR50(sd_card) (CHK_SD(sd_card) && \
394 ((sd_card)->sd_type & SD_DDR50))
395 #define CHK_SD_SDR104(sd_card) (CHK_SD(sd_card) && \
396 ((sd_card)->sd_type & SD_SDR104))
397 #define CHK_SD_HCXC(sd_card) (CHK_SD(sd_card) && \
398 ((sd_card)->sd_type & SD_HCXC))
399 #define CHK_SD_HC(sd_card) (CHK_SD_HCXC(sd_card) && \
400 ((sd_card)->capacity <= 0x4000000))
401 #define CHK_SD_XC(sd_card) (CHK_SD_HCXC(sd_card) && \
402 ((sd_card)->capacity > 0x4000000))
403 #define CHK_SD30_SPEED(sd_card) (CHK_SD_SDR50(sd_card) || \
404 CHK_SD_DDR50(sd_card) || \
405 CHK_SD_SDR104(sd_card))
407 #define SET_SD(sd_card) ((sd_card)->sd_type = TYPE_SD)
408 #define SET_SD_HS(sd_card) ((sd_card)->sd_type |= SD_HS)
409 #define SET_SD_SDR50(sd_card) ((sd_card)->sd_type |= SD_SDR50)
410 #define SET_SD_DDR50(sd_card) ((sd_card)->sd_type |= SD_DDR50)
411 #define SET_SD_SDR104(sd_card) ((sd_card)->sd_type |= SD_SDR104)
412 #define SET_SD_HCXC(sd_card) ((sd_card)->sd_type |= SD_HCXC)
414 #define CLR_SD_HS(sd_card) ((sd_card)->sd_type &= ~SD_HS)
415 #define CLR_SD_SDR50(sd_card) ((sd_card)->sd_type &= ~SD_SDR50)
416 #define CLR_SD_DDR50(sd_card) ((sd_card)->sd_type &= ~SD_DDR50)
417 #define CLR_SD_SDR104(sd_card) ((sd_card)->sd_type &= ~SD_SDR104)
418 #define CLR_SD_HCXC(sd_card) ((sd_card)->sd_type &= ~SD_HCXC)
421 #define CHK_MMC(sd_card) (((sd_card)->sd_type & 0xFF) == \
423 #define CHK_MMC_26M(sd_card) (CHK_MMC(sd_card) && \
424 ((sd_card)->sd_type & MMC_26M))
425 #define CHK_MMC_52M(sd_card) (CHK_MMC(sd_card) && \
426 ((sd_card)->sd_type & MMC_52M))
427 #define CHK_MMC_4BIT(sd_card) (CHK_MMC(sd_card) && \
428 ((sd_card)->sd_type & MMC_4BIT))
429 #define CHK_MMC_8BIT(sd_card) (CHK_MMC(sd_card) && \
430 ((sd_card)->sd_type & MMC_8BIT))
431 #define CHK_MMC_SECTOR_MODE(sd_card) (CHK_MMC(sd_card) && \
432 ((sd_card)->sd_type & MMC_SECTOR_MODE))
433 #define CHK_MMC_DDR52(sd_card) (CHK_MMC(sd_card) && \
434 ((sd_card)->sd_type & MMC_DDR52))
436 #define SET_MMC(sd_card) ((sd_card)->sd_type = TYPE_MMC)
437 #define SET_MMC_26M(sd_card) ((sd_card)->sd_type |= MMC_26M)
438 #define SET_MMC_52M(sd_card) ((sd_card)->sd_type |= MMC_52M)
439 #define SET_MMC_4BIT(sd_card) ((sd_card)->sd_type |= MMC_4BIT)
440 #define SET_MMC_8BIT(sd_card) ((sd_card)->sd_type |= MMC_8BIT)
441 #define SET_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type |= MMC_SECTOR_MODE)
442 #define SET_MMC_DDR52(sd_card) ((sd_card)->sd_type |= MMC_DDR52)
444 #define CLR_MMC_26M(sd_card) ((sd_card)->sd_type &= ~MMC_26M)
445 #define CLR_MMC_52M(sd_card) ((sd_card)->sd_type &= ~MMC_52M)
446 #define CLR_MMC_4BIT(sd_card) ((sd_card)->sd_type &= ~MMC_4BIT)
447 #define CLR_MMC_8BIT(sd_card) ((sd_card)->sd_type &= ~MMC_8BIT)
448 #define CLR_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type &= ~MMC_SECTOR_MODE)
449 #define CLR_MMC_DDR52(sd_card) ((sd_card)->sd_type &= ~MMC_DDR52)
451 #define CHK_MMC_HS(sd_card) (CHK_MMC_52M(sd_card) && \
452 CHK_MMC_26M(sd_card))
453 #define CLR_MMC_HS(sd_card) \
455 CLR_MMC_DDR52(sd_card); \
456 CLR_MMC_52M(sd_card); \
457 CLR_MMC_26M(sd_card); \
460 #define SD_SUPPORT_CLASS_TEN 0x01
461 #define SD_SUPPORT_1V8 0x02
463 #define SD_SET_CLASS_TEN(sd_card) ((sd_card)->sd_setting |= \
464 SD_SUPPORT_CLASS_TEN)
465 #define SD_CHK_CLASS_TEN(sd_card) ((sd_card)->sd_setting & \
466 SD_SUPPORT_CLASS_TEN)
467 #define SD_CLR_CLASS_TEN(sd_card) ((sd_card)->sd_setting &= \
468 ~SD_SUPPORT_CLASS_TEN)
469 #define SD_SET_1V8(sd_card) ((sd_card)->sd_setting |= \
471 #define SD_CHK_1V8(sd_card) ((sd_card)->sd_setting & \
473 #define SD_CLR_1V8(sd_card) ((sd_card)->sd_setting &= \
479 u8 sd_data_buf_ready;
488 enum dma_data_direction pre_dir;
496 int mmc_dont_switch_bus;
513 #ifdef SUPPORT_SD_LOCK
521 struct xd_delay_write_tag {
540 struct zone_entry *zone;
543 struct xd_delay_write_tag delay_write;
549 #define MODE_512_SEQ 0x01
550 #define MODE_2K_SEQ 0x02
552 #define TYPE_MS 0x0000
553 #define TYPE_MSPRO 0x0001
555 #define MS_4BIT 0x0100
556 #define MS_8BIT 0x0200
560 #define HG8BIT (MS_HG | MS_8BIT)
562 #define CHK_MSPRO(ms_card) (((ms_card)->ms_type & 0xFF) == TYPE_MSPRO)
563 #define CHK_HG8BIT(ms_card) (CHK_MSPRO(ms_card) && \
564 (((ms_card)->ms_type & HG8BIT) == HG8BIT))
565 #define CHK_MSXC(ms_card) (CHK_MSPRO(ms_card) && \
566 ((ms_card)->ms_type & MS_XC))
567 #define CHK_MSHG(ms_card) (CHK_MSPRO(ms_card) && \
568 ((ms_card)->ms_type & MS_HG))
570 #define CHK_MS8BIT(ms_card) (((ms_card)->ms_type & MS_8BIT))
571 #define CHK_MS4BIT(ms_card) (((ms_card)->ms_type & MS_4BIT))
573 struct ms_delay_write_tag {
593 struct zone_entry *segment;
596 int pro_under_formatting;
600 #ifdef SUPPORT_PCGL_1P18
601 u8 raw_model_name[48];
608 enum dma_data_direction pre_dir;
613 struct ms_delay_write_tag delay_write;
619 #ifdef SUPPORT_MAGIC_GATE
620 u8 magic_gate_id[16];
622 int mg_auth; /* flag to indicate authentication process */
638 /* Single LUN, support xD/SD/MS */
639 #define DEFAULT_SINGLE 0
640 /* 2 LUN mode, support SD/MS */
642 /* Single LUN, but only support SD/MS, for Barossa LQFP */
645 #define LAST_LUN_MODE 2
647 /* Barossa package */
654 /* SD push point control, bit 0, 1 */
655 #define SD_PUSH_POINT_CTL_MASK 0x03
656 #define SD_PUSH_POINT_DELAY 0x01
657 #define SD_PUSH_POINT_AUTO 0x02
658 /* SD sample point control, bit 2, 3 */
659 #define SD_SAMPLE_POINT_CTL_MASK 0x0C
660 #define SD_SAMPLE_POINT_DELAY 0x04
661 #define SD_SAMPLE_POINT_AUTO 0x08
662 /* SD DDR Tx phase set by user, bit 4 */
663 #define SD_DDR_TX_PHASE_SET_BY_USER 0x10
664 /* MMC DDR Tx phase set by user, bit 5 */
665 #define MMC_DDR_TX_PHASE_SET_BY_USER 0x20
666 /* Support MMC DDR mode, bit 6 */
667 #define SUPPORT_MMC_DDR_MODE 0x40
668 /* Reset MMC at first */
669 #define RESET_MMC_FIRST 0x80
671 #define SEQ_START_CRITERIA 0x20
673 /* MS Power Class En */
674 #define POWER_CLASS_2_EN 0x02
675 #define POWER_CLASS_1_EN 0x01
677 #define MAX_SHOW_CNT 10
678 #define MAX_RESET_CNT 3
680 #define SDIO_EXIST 0x01
681 #define SDIO_IGNORED 0x02
683 #define CHK_SDIO_EXIST(chip) ((chip)->sdio_func_exist & SDIO_EXIST)
684 #define SET_SDIO_EXIST(chip) ((chip)->sdio_func_exist |= SDIO_EXIST)
685 #define CLR_SDIO_EXIST(chip) ((chip)->sdio_func_exist &= ~SDIO_EXIST)
687 #define CHK_SDIO_IGNORED(chip) ((chip)->sdio_func_exist & SDIO_IGNORED)
688 #define SET_SDIO_IGNORED(chip) ((chip)->sdio_func_exist |= \
690 #define CLR_SDIO_IGNORED(chip) ((chip)->sdio_func_exist &= \
694 struct rtsx_dev *rtsx;
696 u32 int_reg; /* Bus interrupt pending register */
700 void *host_cmds_ptr; /* host commands buffer pointer */
701 dma_addr_t host_cmds_addr;
702 int ci; /* Command Index */
704 void *host_sg_tbl_ptr; /* SG descriptor table */
705 dma_addr_t host_sg_tbl_addr;
706 int sgi; /* SG entry index */
708 struct scsi_cmnd *srb; /* current srb */
709 struct sense_data_t sense_buffer[MAX_ALLOWED_LUN_CNT];
711 int cur_clk; /* current card clock */
713 /* Current accessed card */
716 unsigned long need_release; /* need release bit map */
717 unsigned long need_reset; /* need reset bit map */
719 * Flag to indicate that this card is just resumed from SS state,
720 * and need released before being resetted
722 unsigned long need_reinit;
731 u8 card_exist; /* card exist bit map (physical exist) */
732 u8 card_ready; /* card ready bit map (reset successfully) */
733 u8 card_fail; /* card reset fail bit map */
734 u8 card_ejected; /* card ejected bit map */
735 u8 card_wp; /* card write protected bit map */
738 * flag to indicate whether to answer
742 #ifndef LED_AUTO_BLINK
743 int led_toggle_counter;
746 int sd_reset_counter;
747 int xd_reset_counter;
748 int ms_reset_counter;
751 u8 card_bus_width[MAX_ALLOWED_LUN_CNT];
753 u32 capacity[MAX_ALLOWED_LUN_CNT];
754 /* read/write card function pointer */
755 card_rw_func rw_card[MAX_ALLOWED_LUN_CNT];
756 /* read/write capacity, used for GPIO Toggle */
757 u32 rw_cap[MAX_ALLOWED_LUN_CNT];
758 /* card to lun mapping table */
760 /* lun to card mapping table */
761 u8 lun2card[MAX_ALLOWED_LUN_CNT];
763 int rw_fail_cnt[MAX_ALLOWED_LUN_CNT];
769 /* card information */
770 struct sd_info sd_card;
771 struct xd_info xd_card;
772 struct ms_info ms_card;
777 int auto_delink_allowed;
784 u8 sdio_raw_data[12];
793 enum RTSX_STAT rtsx_stat;
799 int driver_first_load;
801 #ifdef HW_AUTO_SWITCH_SD_BUS
807 int chip_insert_with_sdio;
818 int power_down_in_ss;
831 u8 ms_power_class_en;
833 int mspro_formatter_enable;
835 int remote_wakeup_en;
844 int fpga_sd_sdr104_clk;
845 int fpga_sd_ddr50_clk;
846 int fpga_sd_sdr50_clk;
848 int fpga_mmc_52m_clk;
850 int fpga_ms_4bit_clk;
851 int fpga_ms_1bit_clk;
853 int asic_sd_sdr104_clk;
854 int asic_sd_ddr50_clk;
855 int asic_sd_sdr50_clk;
857 int asic_mmc_52m_clk;
859 int asic_ms_4bit_clk;
860 int asic_ms_1bit_clk;
862 u8 ssc_depth_sd_sdr104;
863 u8 ssc_depth_sd_ddr50;
864 u8 ssc_depth_sd_sdr50;
866 u8 ssc_depth_mmc_52m;
868 u8 ssc_depth_ms_4bit;
869 u8 ssc_depth_low_speed;
872 u8 sd30_drive_sel_1v8;
873 u8 sd30_drive_sel_3v3;
890 int mmc_ddr_tx_phase;
891 int sd_default_tx_phase;
892 int sd_default_rx_phase;
894 int pmos_pwr_on_interval;
895 int sd_voltage_switch_delay;
896 int s3_pwr_off_delay;
901 int do_delink_before_power_down;
905 int delink_stage1_step;
906 int delink_stage2_step;
907 int delink_stage3_step;
909 int auto_delink_in_L1;
910 int hp_watch_bios_hotplug;
918 u32 sd_current_prior;
922 static inline struct device *rtsx_dev(const struct rtsx_chip *chip)
924 return &chip->rtsx->pci->dev;
927 #define rtsx_set_stat(chip, stat) \
929 if ((stat) != RTSX_STAT_IDLE) { \
930 (chip)->idle_counter = 0; \
932 (chip)->rtsx_stat = (enum RTSX_STAT)(stat); \
934 #define rtsx_get_stat(chip) ((chip)->rtsx_stat)
935 #define rtsx_chk_stat(chip, stat) ((chip)->rtsx_stat == (stat))
937 #define RTSX_SET_DELINK(chip) ((chip)->rtsx_flag |= 0x01)
938 #define RTSX_CLR_DELINK(chip) ((chip)->rtsx_flag &= 0xFE)
939 #define RTSX_TST_DELINK(chip) ((chip)->rtsx_flag & 0x01)
941 #define CHECK_PID(chip, pid) ((chip)->product_id == (pid))
942 #define CHECK_BARO_PKG(chip, pkg) ((chip)->baro_pkg == (pkg))
943 #define CHECK_LUN_MODE(chip, mode) ((chip)->lun_mode == (mode))
945 /* Power down control */
946 #define SSC_PDCTL 0x01
947 #define OC_PDCTL 0x02
949 int rtsx_force_power_on(struct rtsx_chip *chip, u8 ctl);
950 int rtsx_force_power_down(struct rtsx_chip *chip, u8 ctl);
952 void rtsx_enable_card_int(struct rtsx_chip *chip);
953 void rtsx_enable_bus_int(struct rtsx_chip *chip);
954 void rtsx_disable_bus_int(struct rtsx_chip *chip);
955 int rtsx_reset_chip(struct rtsx_chip *chip);
956 int rtsx_init_chip(struct rtsx_chip *chip);
957 void rtsx_release_chip(struct rtsx_chip *chip);
958 void rtsx_polling_func(struct rtsx_chip *chip);
959 void rtsx_stop_cmd(struct rtsx_chip *chip, int card);
960 int rtsx_write_register(struct rtsx_chip *chip, u16 addr, u8 mask, u8 data);
961 int rtsx_read_register(struct rtsx_chip *chip, u16 addr, u8 *data);
962 int rtsx_write_cfg_dw(struct rtsx_chip *chip,
963 u8 func_no, u16 addr, u32 mask, u32 val);
964 int rtsx_read_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 *val);
965 int rtsx_write_cfg_seq(struct rtsx_chip *chip,
966 u8 func, u16 addr, u8 *buf, int len);
967 int rtsx_read_cfg_seq(struct rtsx_chip *chip,
968 u8 func, u16 addr, u8 *buf, int len);
969 int rtsx_write_phy_register(struct rtsx_chip *chip, u8 addr, u16 val);
970 int rtsx_read_phy_register(struct rtsx_chip *chip, u8 addr, u16 *val);
971 int rtsx_read_efuse(struct rtsx_chip *chip, u8 addr, u8 *val);
972 int rtsx_write_efuse(struct rtsx_chip *chip, u8 addr, u8 val);
973 int rtsx_clr_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit);
974 int rtsx_set_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit);
975 void rtsx_enter_ss(struct rtsx_chip *chip);
976 void rtsx_exit_ss(struct rtsx_chip *chip);
977 int rtsx_pre_handle_interrupt(struct rtsx_chip *chip);
978 void rtsx_enter_L1(struct rtsx_chip *chip);
979 void rtsx_exit_L1(struct rtsx_chip *chip);
980 void rtsx_do_before_power_down(struct rtsx_chip *chip, int pm_stat);
981 void rtsx_enable_aspm(struct rtsx_chip *chip);
982 void rtsx_disable_aspm(struct rtsx_chip *chip);
983 int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len);
984 int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len);
985 int rtsx_check_chip_exist(struct rtsx_chip *chip);
987 #endif /* __REALTEK_RTSX_CHIP_H */