1 /* Driver for Realtek PCI-Express card reader
4 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, see <http://www.gnu.org/licenses/>.
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
35 /* Hardware switch bus_ctl and cd_ctl automatically */
36 #define HW_AUTO_SWITCH_SD_BUS
37 /* Enable hardware interrupt write clear */
38 #define HW_INT_WRITE_CLR
39 /* #define LED_AUTO_BLINK */
40 /* #define DISABLE_CARD_INT */
42 #ifdef SUPPORT_MAGIC_GATE
43 /* Using NORMAL_WRITE instead of AUTO_WRITE to set ICV */
44 #define MG_SET_ICV_SLOW
45 /* HW may miss ERR/CMDNK signal when sampling INT status. */
46 #define MS_SAMPLE_INT_ERR
48 * HW DO NOT support Wait_INT function
49 * during READ_BYTES transfer mode
51 #define READ_BYTES_WAIT_INT
56 #define SUPPORT_PCGL_1P18
59 #ifndef LED_AUTO_BLINK
63 #define LED_BLINK_SPEED 5
64 #define LED_TOGGLE_INTERVAL 6
65 #define GPIO_TOGGLE_THRESHOLD 1024
68 #define POLLING_INTERVAL 30
70 #define TRACE_ITEM_CNT 64
72 #ifndef STATUS_SUCCESS
73 #define STATUS_SUCCESS 0
78 #ifndef STATUS_TIMEDOUT
79 #define STATUS_TIMEDOUT 2
82 #define STATUS_NOMEM 3
84 #ifndef STATUS_READ_FAIL
85 #define STATUS_READ_FAIL 4
87 #ifndef STATUS_WRITE_FAIL
88 #define STATUS_WRITE_FAIL 5
91 #define STATUS_ERROR 10
98 * Transport return codes
101 #define TRANSPORT_GOOD 0 /* Transport good, command good */
102 #define TRANSPORT_FAILED 1 /* Transport good, command failed */
103 #define TRANSPORT_NO_SENSE 2 /* Command failed, no auto-sense */
104 #define TRANSPORT_ERROR 3 /* Transport bad (i.e. device dead) */
109 #define STOP_MEDIUM 0x00 /* access disable */
110 #define MAKE_MEDIUM_READY 0x01 /* access enable */
111 #define UNLOAD_MEDIUM 0x02 /* unload */
112 #define LOAD_MEDIUM 0x03 /* load */
117 #define QULIFIRE 0x00
118 #define AENC_FNC 0x00
119 #define TRML_IOP 0x00
128 #define VEN_ID_LEN 8 /* Vendor ID Length */
129 #define PRDCT_ID_LEN 16 /* Product ID Length */
130 #define PRDCT_REV_LEN 4 /* Product LOT Length */
132 /* Dynamic flag definitions: used in set_bit() etc. */
133 /* 0x00040000 transfer is active */
134 #define RTSX_FLIDX_TRANS_ACTIVE 18
135 /* 0x00100000 abort is in progress */
136 #define RTSX_FLIDX_ABORTING 20
137 /* 0x00200000 disconnect in progress */
138 #define RTSX_FLIDX_DISCONNECTING 21
140 #define ABORTING_OR_DISCONNECTING ((1UL << US_FLIDX_ABORTING) | \
141 (1UL << US_FLIDX_DISCONNECTING))
143 /* 0x00400000 device reset in progress */
144 #define RTSX_FLIDX_RESETTING 22
145 /* 0x00800000 SCSI midlayer timed out */
146 #define RTSX_FLIDX_TIMED_OUT 23
147 #define DRCT_ACCESS_DEV 0x00 /* Direct Access Device */
148 #define RMB_DISC 0x80 /* The Device is Removable */
149 #define ANSI_SCSI2 0x02 /* Based on ANSI-SCSI2 */
151 #define SCSI 0x00 /* Interface ID */
153 #define WRITE_PROTECTED_MEDIA 0x07
155 /*---- sense key ----*/
156 #define ILI 0x20 /* ILI bit is on */
158 #define NO_SENSE 0x00 /* not exist sense key */
159 #define RECOVER_ERR 0x01 /* Target/Logical unit is recoverd */
160 #define NOT_READY 0x02 /* Logical unit is not ready */
161 #define MEDIA_ERR 0x03 /* medium/data error */
162 #define HARDWARE_ERR 0x04 /* hardware error */
163 #define ILGAL_REQ 0x05 /* CDB/parameter/identify msg error */
164 #define UNIT_ATTENTION 0x06 /* unit attention condition occur */
165 #define DAT_PRTCT 0x07 /* read/write is desable */
166 #define BLNC_CHK 0x08 /* find blank/DOF in read */
167 /* write to unblank area */
168 #define CPY_ABRT 0x0a /* Copy/Compare/Copy&Verify illgal */
169 #define ABRT_CMD 0x0b /* Target make the command in error */
170 #define EQUAL 0x0c /* Search Data end with Equal */
171 #define VLM_OVRFLW 0x0d /* Some data are left in buffer */
172 #define MISCMP 0x0e /* find inequality */
177 #define FIRST_RESET 0x01
178 #define USED_EXIST 0x02
184 #define SENSE_VALID 0x80 /* Sense data is valid as SCSI2 */
185 #define SENSE_INVALID 0x00 /* Sense data is invalid as SCSI2 */
187 /*---- error code ----*/
188 #define CUR_ERR 0x70 /* current error */
189 #define DEF_ERR 0x71 /* specific command error */
191 /*---- sense key Information ----*/
192 #define SNSKEYINFO_LEN 3 /* length of sense key information */
195 #define CDB_ILLEGAL 0x40
196 #define DAT_ILLEGAL 0x00
198 #define BIT_ILLEGAL0 0 /* bit0 is illegal */
199 #define BIT_ILLEGAL1 1 /* bit1 is illegal */
200 #define BIT_ILLEGAL2 2 /* bit2 is illegal */
201 #define BIT_ILLEGAL3 3 /* bit3 is illegal */
202 #define BIT_ILLEGAL4 4 /* bit4 is illegal */
203 #define BIT_ILLEGAL5 5 /* bit5 is illegal */
204 #define BIT_ILLEGAL6 6 /* bit6 is illegal */
205 #define BIT_ILLEGAL7 7 /* bit7 is illegal */
208 #define ASC_NO_INFO 0x00
209 #define ASC_MISCMP 0x1d
210 #define ASC_INVLD_CDB 0x24
211 #define ASC_INVLD_PARA 0x26
212 #define ASC_LU_NOT_READY 0x04
213 #define ASC_WRITE_ERR 0x0c
214 #define ASC_READ_ERR 0x11
215 #define ASC_LOAD_EJCT_ERR 0x53
216 #define ASC_MEDIA_NOT_PRESENT 0x3A
217 #define ASC_MEDIA_CHANGED 0x28
218 #define ASC_MEDIA_IN_PROCESS 0x04
219 #define ASC_WRITE_PROTECT 0x27
220 #define ASC_LUN_NOT_SUPPORTED 0x25
223 #define ASCQ_NO_INFO 0x00
224 #define ASCQ_MEDIA_IN_PROCESS 0x01
225 #define ASCQ_MISCMP 0x00
226 #define ASCQ_INVLD_CDB 0x00
227 #define ASCQ_INVLD_PARA 0x02
228 #define ASCQ_LU_NOT_READY 0x02
229 #define ASCQ_WRITE_ERR 0x02
230 #define ASCQ_READ_ERR 0x00
231 #define ASCQ_LOAD_EJCT_ERR 0x00
232 #define ASCQ_WRITE_PROTECT 0x00
234 struct sense_data_t {
235 unsigned char err_code; /* error code */
238 /* (0 : Vendor * specific) */
239 /* bit6-0 : error * code */
240 /* (0x70 : current * error) */
241 /* (0x71 : specific command error) */
242 unsigned char seg_no; /* segment No. */
243 unsigned char sense_key; /* byte5 : ILI */
244 /* bit3-0 : sense key */
245 unsigned char info[4]; /* information */
246 unsigned char ad_sense_len; /* additional sense data length */
247 unsigned char cmd_info[4]; /* command specific information */
248 unsigned char asc; /* ASC */
249 unsigned char ascq; /* ASCQ */
250 unsigned char rfu; /* FRU */
251 unsigned char sns_key_info[3];/* sense key specific information */
254 /* PCI Operation Register Address */
255 #define RTSX_HCBAR 0x00
256 #define RTSX_HCBCTLR 0x04
257 #define RTSX_HDBAR 0x08
258 #define RTSX_HDBCTLR 0x0C
259 #define RTSX_HAIMR 0x10
260 #define RTSX_BIPR 0x14
261 #define RTSX_BIER 0x18
263 /* Host command buffer control register */
264 #define STOP_CMD (0x01 << 28)
266 /* Host data buffer control register */
267 #define SDMA_MODE 0x00
268 #define ADMA_MODE (0x02 << 26)
269 #define STOP_DMA (0x01 << 28)
270 #define TRIG_DMA (0x01 << 31)
272 /* Bus interrupt pending register */
273 #define CMD_DONE_INT BIT(31)
274 #define DATA_DONE_INT BIT(30)
275 #define TRANS_OK_INT BIT(29)
276 #define TRANS_FAIL_INT BIT(28)
277 #define XD_INT BIT(27)
278 #define MS_INT BIT(26)
279 #define SD_INT BIT(25)
280 #define GPIO0_INT BIT(24)
281 #define OC_INT BIT(23)
282 #define SD_WRITE_PROTECT BIT(19)
283 #define XD_EXIST BIT(18)
284 #define MS_EXIST BIT(17)
285 #define SD_EXIST BIT(16)
286 #define DELINK_INT GPIO0_INT
287 #define MS_OC_INT BIT(23)
288 #define SD_OC_INT BIT(22)
290 #define CARD_INT (XD_INT | MS_INT | SD_INT)
291 #define NEED_COMPLETE_INT (DATA_DONE_INT | TRANS_OK_INT | TRANS_FAIL_INT)
292 #define RTSX_INT (CMD_DONE_INT | NEED_COMPLETE_INT | CARD_INT | \
295 #define CARD_EXIST (XD_EXIST | MS_EXIST | SD_EXIST)
297 /* Bus interrupt enable register */
298 #define CMD_DONE_INT_EN BIT(31)
299 #define DATA_DONE_INT_EN BIT(30)
300 #define TRANS_OK_INT_EN BIT(29)
301 #define TRANS_FAIL_INT_EN BIT(28)
302 #define XD_INT_EN BIT(27)
303 #define MS_INT_EN BIT(26)
304 #define SD_INT_EN BIT(25)
305 #define GPIO0_INT_EN BIT(24)
306 #define OC_INT_EN BIT(23)
307 #define DELINK_INT_EN GPIO0_INT_EN
308 #define MS_OC_INT_EN BIT(23)
309 #define SD_OC_INT_EN BIT(22)
311 #define READ_REG_CMD 0
312 #define WRITE_REG_CMD 1
313 #define CHECK_REG_CMD 2
315 #define HOST_TO_DEVICE 0
316 #define DEVICE_TO_HOST 1
318 #define RTSX_RESV_BUF_LEN 4096
319 #define HOST_CMDS_BUF_LEN 1024
320 #define HOST_SG_TBL_BUF_LEN (RTSX_RESV_BUF_LEN - HOST_CMDS_BUF_LEN)
326 #define SD_CARD BIT(SD_NR)
327 #define MS_CARD BIT(MS_NR)
328 #define XD_CARD BIT(XD_NR)
329 #define SPI_CARD BIT(SPI_NR)
331 #define MAX_ALLOWED_LUN_CNT 8
333 #define XD_FREE_TABLE_CNT 1200
334 #define MS_FREE_TABLE_CNT 512
337 #define SET_BIT(data, idx) ((data) |= 1 << (idx))
338 #define CLR_BIT(data, idx) ((data) &= ~(1 << (idx)))
339 #define CHK_BIT(data, idx) ((data) & (1 << (idx)))
342 #define RTSX_SG_INT 0x04
343 #define RTSX_SG_END 0x02
344 #define RTSX_SG_VALID 0x01
346 #define RTSX_SG_NO_OP 0x00
347 #define RTSX_SG_TRANS_DATA (0x02 << 4)
348 #define RTSX_SG_LINK_DESC (0x03 << 4)
352 typedef int (*card_rw_func)(struct scsi_cmnd *srb, struct rtsx_chip *chip,
353 u32 sec_addr, u16 sec_cnt);
355 /* Supported Clock */
356 enum card_clock {CLK_20 = 1, CLK_30, CLK_40, CLK_50, CLK_60,
357 CLK_80, CLK_100, CLK_120, CLK_150, CLK_200};
359 enum RTSX_STAT {RTSX_STAT_INIT, RTSX_STAT_IDLE, RTSX_STAT_RUN, RTSX_STAT_SS,
360 RTSX_STAT_DELINK, RTSX_STAT_SUSPEND,
361 RTSX_STAT_ABORT, RTSX_STAT_DISCONNECT};
362 enum IC_VER {IC_VER_AB, IC_VER_C = 2, IC_VER_D = 3};
364 #define MAX_RESET_CNT 3
367 #define MAX_DEFECTIVE_BLOCK 10
372 u16 defect_list[MAX_DEFECTIVE_BLOCK]; /* For MS card only */
377 /* To indicate whether the L2P table of this zone has been built. */
381 #define TYPE_SD 0x0000
382 #define TYPE_MMC 0x0001
386 #define SD_SDR50 0x0200
387 #define SD_DDR50 0x0400
388 #define SD_SDR104 0x0800
389 #define SD_HCXC 0x1000
392 #define MMC_26M 0x0100
393 #define MMC_52M 0x0200
394 #define MMC_4BIT 0x0400
395 #define MMC_8BIT 0x0800
396 #define MMC_SECTOR_MODE 0x1000
397 #define MMC_DDR52 0x2000
400 #define CHK_SD(sd_card) (((sd_card)->sd_type & 0xFF) == TYPE_SD)
401 #define CHK_SD_HS(sd_card) (CHK_SD(sd_card) && \
402 ((sd_card)->sd_type & SD_HS))
403 #define CHK_SD_SDR50(sd_card) (CHK_SD(sd_card) && \
404 ((sd_card)->sd_type & SD_SDR50))
405 #define CHK_SD_DDR50(sd_card) (CHK_SD(sd_card) && \
406 ((sd_card)->sd_type & SD_DDR50))
407 #define CHK_SD_SDR104(sd_card) (CHK_SD(sd_card) && \
408 ((sd_card)->sd_type & SD_SDR104))
409 #define CHK_SD_HCXC(sd_card) (CHK_SD(sd_card) && \
410 ((sd_card)->sd_type & SD_HCXC))
411 #define CHK_SD_HC(sd_card) (CHK_SD_HCXC(sd_card) && \
412 ((sd_card)->capacity <= 0x4000000))
413 #define CHK_SD_XC(sd_card) (CHK_SD_HCXC(sd_card) && \
414 ((sd_card)->capacity > 0x4000000))
415 #define CHK_SD30_SPEED(sd_card) (CHK_SD_SDR50(sd_card) || \
416 CHK_SD_DDR50(sd_card) || \
417 CHK_SD_SDR104(sd_card))
419 #define SET_SD(sd_card) ((sd_card)->sd_type = TYPE_SD)
420 #define SET_SD_HS(sd_card) ((sd_card)->sd_type |= SD_HS)
421 #define SET_SD_SDR50(sd_card) ((sd_card)->sd_type |= SD_SDR50)
422 #define SET_SD_DDR50(sd_card) ((sd_card)->sd_type |= SD_DDR50)
423 #define SET_SD_SDR104(sd_card) ((sd_card)->sd_type |= SD_SDR104)
424 #define SET_SD_HCXC(sd_card) ((sd_card)->sd_type |= SD_HCXC)
426 #define CLR_SD_HS(sd_card) ((sd_card)->sd_type &= ~SD_HS)
427 #define CLR_SD_SDR50(sd_card) ((sd_card)->sd_type &= ~SD_SDR50)
428 #define CLR_SD_DDR50(sd_card) ((sd_card)->sd_type &= ~SD_DDR50)
429 #define CLR_SD_SDR104(sd_card) ((sd_card)->sd_type &= ~SD_SDR104)
430 #define CLR_SD_HCXC(sd_card) ((sd_card)->sd_type &= ~SD_HCXC)
433 #define CHK_MMC(sd_card) (((sd_card)->sd_type & 0xFF) == \
435 #define CHK_MMC_26M(sd_card) (CHK_MMC(sd_card) && \
436 ((sd_card)->sd_type & MMC_26M))
437 #define CHK_MMC_52M(sd_card) (CHK_MMC(sd_card) && \
438 ((sd_card)->sd_type & MMC_52M))
439 #define CHK_MMC_4BIT(sd_card) (CHK_MMC(sd_card) && \
440 ((sd_card)->sd_type & MMC_4BIT))
441 #define CHK_MMC_8BIT(sd_card) (CHK_MMC(sd_card) && \
442 ((sd_card)->sd_type & MMC_8BIT))
443 #define CHK_MMC_SECTOR_MODE(sd_card) (CHK_MMC(sd_card) && \
444 ((sd_card)->sd_type & MMC_SECTOR_MODE))
445 #define CHK_MMC_DDR52(sd_card) (CHK_MMC(sd_card) && \
446 ((sd_card)->sd_type & MMC_DDR52))
448 #define SET_MMC(sd_card) ((sd_card)->sd_type = TYPE_MMC)
449 #define SET_MMC_26M(sd_card) ((sd_card)->sd_type |= MMC_26M)
450 #define SET_MMC_52M(sd_card) ((sd_card)->sd_type |= MMC_52M)
451 #define SET_MMC_4BIT(sd_card) ((sd_card)->sd_type |= MMC_4BIT)
452 #define SET_MMC_8BIT(sd_card) ((sd_card)->sd_type |= MMC_8BIT)
453 #define SET_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type |= MMC_SECTOR_MODE)
454 #define SET_MMC_DDR52(sd_card) ((sd_card)->sd_type |= MMC_DDR52)
456 #define CLR_MMC_26M(sd_card) ((sd_card)->sd_type &= ~MMC_26M)
457 #define CLR_MMC_52M(sd_card) ((sd_card)->sd_type &= ~MMC_52M)
458 #define CLR_MMC_4BIT(sd_card) ((sd_card)->sd_type &= ~MMC_4BIT)
459 #define CLR_MMC_8BIT(sd_card) ((sd_card)->sd_type &= ~MMC_8BIT)
460 #define CLR_MMC_SECTOR_MODE(sd_card) ((sd_card)->sd_type &= ~MMC_SECTOR_MODE)
461 #define CLR_MMC_DDR52(sd_card) ((sd_card)->sd_type &= ~MMC_DDR52)
463 #define CHK_MMC_HS(sd_card) (CHK_MMC_52M(sd_card) && \
464 CHK_MMC_26M(sd_card))
465 #define CLR_MMC_HS(sd_card) \
467 CLR_MMC_DDR52(sd_card); \
468 CLR_MMC_52M(sd_card); \
469 CLR_MMC_26M(sd_card); \
472 #define SD_SUPPORT_CLASS_TEN 0x01
473 #define SD_SUPPORT_1V8 0x02
475 #define SD_SET_CLASS_TEN(sd_card) ((sd_card)->sd_setting |= \
476 SD_SUPPORT_CLASS_TEN)
477 #define SD_CHK_CLASS_TEN(sd_card) ((sd_card)->sd_setting & \
478 SD_SUPPORT_CLASS_TEN)
479 #define SD_CLR_CLASS_TEN(sd_card) ((sd_card)->sd_setting &= \
480 ~SD_SUPPORT_CLASS_TEN)
481 #define SD_SET_1V8(sd_card) ((sd_card)->sd_setting |= \
483 #define SD_CHK_1V8(sd_card) ((sd_card)->sd_setting & \
485 #define SD_CLR_1V8(sd_card) ((sd_card)->sd_setting &= \
491 u8 sd_data_buf_ready;
500 enum dma_data_direction pre_dir;
508 int mmc_dont_switch_bus;
525 #ifdef SUPPORT_SD_LOCK
533 struct xd_delay_write_tag {
552 struct zone_entry *zone;
555 struct xd_delay_write_tag delay_write;
561 #define MODE_512_SEQ 0x01
562 #define MODE_2K_SEQ 0x02
564 #define TYPE_MS 0x0000
565 #define TYPE_MSPRO 0x0001
567 #define MS_4BIT 0x0100
568 #define MS_8BIT 0x0200
572 #define HG8BIT (MS_HG | MS_8BIT)
574 #define CHK_MSPRO(ms_card) (((ms_card)->ms_type & 0xFF) == TYPE_MSPRO)
575 #define CHK_HG8BIT(ms_card) (CHK_MSPRO(ms_card) && \
576 (((ms_card)->ms_type & HG8BIT) == HG8BIT))
577 #define CHK_MSXC(ms_card) (CHK_MSPRO(ms_card) && \
578 ((ms_card)->ms_type & MS_XC))
579 #define CHK_MSHG(ms_card) (CHK_MSPRO(ms_card) && \
580 ((ms_card)->ms_type & MS_HG))
582 #define CHK_MS8BIT(ms_card) (((ms_card)->ms_type & MS_8BIT))
583 #define CHK_MS4BIT(ms_card) (((ms_card)->ms_type & MS_4BIT))
585 struct ms_delay_write_tag {
605 struct zone_entry *segment;
608 int pro_under_formatting;
612 #ifdef SUPPORT_PCGL_1P18
613 u8 raw_model_name[48];
620 enum dma_data_direction pre_dir;
625 struct ms_delay_write_tag delay_write;
631 #ifdef SUPPORT_MAGIC_GATE
632 u8 magic_gate_id[16];
634 int mg_auth; /* flag to indicate authentication process */
650 #define MSG_FUNC_LEN 64
651 char func[MSG_FUNC_LEN];
652 #define MSG_FILE_LEN 32
653 char file[MSG_FILE_LEN];
654 #define TIME_VAL_LEN 16
655 u8 timeval_buf[TIME_VAL_LEN];
663 /* Single LUN, support xD/SD/MS */
664 #define DEFAULT_SINGLE 0
665 /* 2 LUN mode, support SD/MS */
667 /* Single LUN, but only support SD/MS, for Barossa LQFP */
670 #define LAST_LUN_MODE 2
672 /* Barossa package */
679 /* SD push point control, bit 0, 1 */
680 #define SD_PUSH_POINT_CTL_MASK 0x03
681 #define SD_PUSH_POINT_DELAY 0x01
682 #define SD_PUSH_POINT_AUTO 0x02
683 /* SD sample point control, bit 2, 3 */
684 #define SD_SAMPLE_POINT_CTL_MASK 0x0C
685 #define SD_SAMPLE_POINT_DELAY 0x04
686 #define SD_SAMPLE_POINT_AUTO 0x08
687 /* SD DDR Tx phase set by user, bit 4 */
688 #define SD_DDR_TX_PHASE_SET_BY_USER 0x10
689 /* MMC DDR Tx phase set by user, bit 5 */
690 #define MMC_DDR_TX_PHASE_SET_BY_USER 0x20
691 /* Support MMC DDR mode, bit 6 */
692 #define SUPPORT_MMC_DDR_MODE 0x40
693 /* Reset MMC at first */
694 #define RESET_MMC_FIRST 0x80
696 #define SEQ_START_CRITERIA 0x20
698 /* MS Power Class En */
699 #define POWER_CLASS_2_EN 0x02
700 #define POWER_CLASS_1_EN 0x01
702 #define MAX_SHOW_CNT 10
703 #define MAX_RESET_CNT 3
705 #define SDIO_EXIST 0x01
706 #define SDIO_IGNORED 0x02
708 #define CHK_SDIO_EXIST(chip) ((chip)->sdio_func_exist & SDIO_EXIST)
709 #define SET_SDIO_EXIST(chip) ((chip)->sdio_func_exist |= SDIO_EXIST)
710 #define CLR_SDIO_EXIST(chip) ((chip)->sdio_func_exist &= ~SDIO_EXIST)
712 #define CHK_SDIO_IGNORED(chip) ((chip)->sdio_func_exist & SDIO_IGNORED)
713 #define SET_SDIO_IGNORED(chip) ((chip)->sdio_func_exist |= \
715 #define CLR_SDIO_IGNORED(chip) ((chip)->sdio_func_exist &= \
719 struct rtsx_dev *rtsx;
721 u32 int_reg; /* Bus interrupt pending register */
725 void *host_cmds_ptr; /* host commands buffer pointer */
726 dma_addr_t host_cmds_addr;
727 int ci; /* Command Index */
729 void *host_sg_tbl_ptr; /* SG descriptor table */
730 dma_addr_t host_sg_tbl_addr;
731 int sgi; /* SG entry index */
733 struct scsi_cmnd *srb; /* current srb */
734 struct sense_data_t sense_buffer[MAX_ALLOWED_LUN_CNT];
736 int cur_clk; /* current card clock */
738 /* Current accessed card */
741 unsigned long need_release; /* need release bit map */
742 unsigned long need_reset; /* need reset bit map */
744 * Flag to indicate that this card is just resumed from SS state,
745 * and need released before being resetted
747 unsigned long need_reinit;
756 u8 card_exist; /* card exist bit map (physical exist) */
757 u8 card_ready; /* card ready bit map (reset successfully) */
758 u8 card_fail; /* card reset fail bit map */
759 u8 card_ejected; /* card ejected bit map */
760 u8 card_wp; /* card write protected bit map */
763 * flag to indicate whether to answer
767 #ifndef LED_AUTO_BLINK
768 int led_toggle_counter;
771 int sd_reset_counter;
772 int xd_reset_counter;
773 int ms_reset_counter;
776 u8 card_bus_width[MAX_ALLOWED_LUN_CNT];
778 u32 capacity[MAX_ALLOWED_LUN_CNT];
779 /* read/write card function pointer */
780 card_rw_func rw_card[MAX_ALLOWED_LUN_CNT];
781 /* read/write capacity, used for GPIO Toggle */
782 u32 rw_cap[MAX_ALLOWED_LUN_CNT];
783 /* card to lun mapping table */
785 /* lun to card mapping table */
786 u8 lun2card[MAX_ALLOWED_LUN_CNT];
788 int rw_fail_cnt[MAX_ALLOWED_LUN_CNT];
794 /* card information */
795 struct sd_info sd_card;
796 struct xd_info xd_card;
797 struct ms_info ms_card;
802 struct trace_msg_t trace_msg[TRACE_ITEM_CNT];
807 int auto_delink_allowed;
814 u8 sdio_raw_data[12];
823 enum RTSX_STAT rtsx_stat;
829 int driver_first_load;
831 #ifdef HW_AUTO_SWITCH_SD_BUS
837 int chip_insert_with_sdio;
848 int power_down_in_ss;
861 u8 ms_power_class_en;
863 int mspro_formatter_enable;
865 int remote_wakeup_en;
874 int fpga_sd_sdr104_clk;
875 int fpga_sd_ddr50_clk;
876 int fpga_sd_sdr50_clk;
878 int fpga_mmc_52m_clk;
880 int fpga_ms_4bit_clk;
881 int fpga_ms_1bit_clk;
883 int asic_sd_sdr104_clk;
884 int asic_sd_ddr50_clk;
885 int asic_sd_sdr50_clk;
887 int asic_mmc_52m_clk;
889 int asic_ms_4bit_clk;
890 int asic_ms_1bit_clk;
892 u8 ssc_depth_sd_sdr104;
893 u8 ssc_depth_sd_ddr50;
894 u8 ssc_depth_sd_sdr50;
896 u8 ssc_depth_mmc_52m;
898 u8 ssc_depth_ms_4bit;
899 u8 ssc_depth_low_speed;
902 u8 sd30_drive_sel_1v8;
903 u8 sd30_drive_sel_3v3;
920 int mmc_ddr_tx_phase;
921 int sd_default_tx_phase;
922 int sd_default_rx_phase;
924 int pmos_pwr_on_interval;
925 int sd_voltage_switch_delay;
926 int s3_pwr_off_delay;
931 int do_delink_before_power_down;
935 int delink_stage1_step;
936 int delink_stage2_step;
937 int delink_stage3_step;
939 int auto_delink_in_L1;
940 int hp_watch_bios_hotplug;
948 u32 sd_current_prior;
952 static inline struct device *rtsx_dev(const struct rtsx_chip *chip)
954 return &chip->rtsx->pci->dev;
957 #define rtsx_set_stat(chip, stat) \
959 if ((stat) != RTSX_STAT_IDLE) { \
960 (chip)->idle_counter = 0; \
962 (chip)->rtsx_stat = (enum RTSX_STAT)(stat); \
964 #define rtsx_get_stat(chip) ((chip)->rtsx_stat)
965 #define rtsx_chk_stat(chip, stat) ((chip)->rtsx_stat == (stat))
967 #define RTSX_SET_DELINK(chip) ((chip)->rtsx_flag |= 0x01)
968 #define RTSX_CLR_DELINK(chip) ((chip)->rtsx_flag &= 0xFE)
969 #define RTSX_TST_DELINK(chip) ((chip)->rtsx_flag & 0x01)
971 #define CHECK_PID(chip, pid) ((chip)->product_id == (pid))
972 #define CHECK_BARO_PKG(chip, pkg) ((chip)->baro_pkg == (pkg))
973 #define CHECK_LUN_MODE(chip, mode) ((chip)->lun_mode == (mode))
975 /* Power down control */
976 #define SSC_PDCTL 0x01
977 #define OC_PDCTL 0x02
979 int rtsx_force_power_on(struct rtsx_chip *chip, u8 ctl);
980 int rtsx_force_power_down(struct rtsx_chip *chip, u8 ctl);
982 void rtsx_enable_card_int(struct rtsx_chip *chip);
983 void rtsx_enable_bus_int(struct rtsx_chip *chip);
984 void rtsx_disable_bus_int(struct rtsx_chip *chip);
985 int rtsx_reset_chip(struct rtsx_chip *chip);
986 int rtsx_init_chip(struct rtsx_chip *chip);
987 void rtsx_release_chip(struct rtsx_chip *chip);
988 void rtsx_polling_func(struct rtsx_chip *chip);
989 void rtsx_stop_cmd(struct rtsx_chip *chip, int card);
990 int rtsx_write_register(struct rtsx_chip *chip, u16 addr, u8 mask, u8 data);
991 int rtsx_read_register(struct rtsx_chip *chip, u16 addr, u8 *data);
992 int rtsx_write_cfg_dw(struct rtsx_chip *chip,
993 u8 func_no, u16 addr, u32 mask, u32 val);
994 int rtsx_read_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 *val);
995 int rtsx_write_cfg_seq(struct rtsx_chip *chip,
996 u8 func, u16 addr, u8 *buf, int len);
997 int rtsx_read_cfg_seq(struct rtsx_chip *chip,
998 u8 func, u16 addr, u8 *buf, int len);
999 int rtsx_write_phy_register(struct rtsx_chip *chip, u8 addr, u16 val);
1000 int rtsx_read_phy_register(struct rtsx_chip *chip, u8 addr, u16 *val);
1001 int rtsx_read_efuse(struct rtsx_chip *chip, u8 addr, u8 *val);
1002 int rtsx_write_efuse(struct rtsx_chip *chip, u8 addr, u8 val);
1003 int rtsx_clr_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit);
1004 int rtsx_set_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit);
1005 void rtsx_enter_ss(struct rtsx_chip *chip);
1006 void rtsx_exit_ss(struct rtsx_chip *chip);
1007 int rtsx_pre_handle_interrupt(struct rtsx_chip *chip);
1008 void rtsx_enter_L1(struct rtsx_chip *chip);
1009 void rtsx_exit_L1(struct rtsx_chip *chip);
1010 void rtsx_do_before_power_down(struct rtsx_chip *chip, int pm_stat);
1011 void rtsx_enable_aspm(struct rtsx_chip *chip);
1012 void rtsx_disable_aspm(struct rtsx_chip *chip);
1013 int rtsx_read_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len);
1014 int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len);
1015 int rtsx_check_chip_exist(struct rtsx_chip *chip);
1017 #endif /* __REALTEK_RTSX_CHIP_H */