1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Driver for Realtek PCI-Express card reader
4 * Copyright(c) 2016-2017 Realtek Semiconductor Corp. All rights reserved.
7 * Steven FENG <steven_feng@realsil.com.cn>
8 * Rui FENG <rui_feng@realsil.com.cn>
9 * Wei WANG <wei_wang@realsil.com.cn>
12 #include <linux/module.h>
13 #include <linux/delay.h>
14 #include <linux/rtsx_pci.h>
19 static u8
rts5260_get_ic_version(struct rtsx_pcr
*pcr
)
23 rtsx_pci_read_register(pcr
, DUMMY_REG_RESET_0
, &val
);
24 return val
& IC_VERSION_MASK
;
27 static void rts5260_fill_driving(struct rtsx_pcr
*pcr
, u8 voltage
)
29 u8 driving_3v3
[4][3] = {
35 u8 driving_1v8
[4][3] = {
41 u8 (*driving
)[3], drive_sel
;
43 if (voltage
== OUTPUT_3V3
) {
44 driving
= driving_3v3
;
45 drive_sel
= pcr
->sd30_drive_sel_3v3
;
47 driving
= driving_1v8
;
48 drive_sel
= pcr
->sd30_drive_sel_1v8
;
51 rtsx_pci_write_register(pcr
, SD30_CLK_DRIVE_SEL
,
52 0xFF, driving
[drive_sel
][0]);
54 rtsx_pci_write_register(pcr
, SD30_CMD_DRIVE_SEL
,
55 0xFF, driving
[drive_sel
][1]);
57 rtsx_pci_write_register(pcr
, SD30_DAT_DRIVE_SEL
,
58 0xFF, driving
[drive_sel
][2]);
61 static void rtsx_base_fetch_vendor_settings(struct rtsx_pcr
*pcr
)
63 struct pci_dev
*pdev
= pcr
->pci
;
66 pci_read_config_dword(pdev
, PCR_SETTING_REG1
, ®
);
67 pcr_dbg(pcr
, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1
, reg
);
69 if (!rtsx_vendor_setting_valid(reg
)) {
70 pcr_dbg(pcr
, "skip fetch vendor setting\n");
74 pcr
->aspm_en
= rtsx_reg_to_aspm(reg
);
75 pcr
->sd30_drive_sel_1v8
= rtsx_reg_to_sd30_drive_sel_1v8(reg
);
76 pcr
->card_drive_sel
&= 0x3F;
77 pcr
->card_drive_sel
|= rtsx_reg_to_card_drive_sel(reg
);
79 pci_read_config_dword(pdev
, PCR_SETTING_REG2
, ®
);
80 pcr_dbg(pcr
, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2
, reg
);
81 if (rtsx_check_mmc_support(reg
))
82 pcr
->extra_caps
|= EXTRA_CAPS_NO_MMC
;
83 pcr
->sd30_drive_sel_3v3
= rtsx_reg_to_sd30_drive_sel_3v3(reg
);
84 if (rtsx_reg_check_reverse_socket(reg
))
85 pcr
->flags
|= PCR_REVERSE_SOCKET
;
88 static int rtsx_base_enable_auto_blink(struct rtsx_pcr
*pcr
)
90 return rtsx_pci_write_register(pcr
, OLT_LED_CTL
,
91 LED_SHINE_MASK
, LED_SHINE_EN
);
94 static int rtsx_base_disable_auto_blink(struct rtsx_pcr
*pcr
)
96 return rtsx_pci_write_register(pcr
, OLT_LED_CTL
,
97 LED_SHINE_MASK
, LED_SHINE_DISABLE
);
100 static int rts5260_turn_on_led(struct rtsx_pcr
*pcr
)
102 return rtsx_pci_write_register(pcr
, RTS5260_REG_GPIO_CTL0
,
103 RTS5260_REG_GPIO_MASK
, RTS5260_REG_GPIO_ON
);
106 static int rts5260_turn_off_led(struct rtsx_pcr
*pcr
)
108 return rtsx_pci_write_register(pcr
, RTS5260_REG_GPIO_CTL0
,
109 RTS5260_REG_GPIO_MASK
, RTS5260_REG_GPIO_OFF
);
112 /* SD Pull Control Enable:
113 * SD_DAT[3:0] ==> pull up
117 * SD_CLK ==> pull down
119 static const u32 rts5260_sd_pull_ctl_enable_tbl
[] = {
120 RTSX_REG_PAIR(CARD_PULL_CTL1
, 0x66),
121 RTSX_REG_PAIR(CARD_PULL_CTL2
, 0xAA),
122 RTSX_REG_PAIR(CARD_PULL_CTL3
, 0xE9),
123 RTSX_REG_PAIR(CARD_PULL_CTL4
, 0xAA),
127 /* SD Pull Control Disable:
128 * SD_DAT[3:0] ==> pull down
130 * SD_WP ==> pull down
131 * SD_CMD ==> pull down
132 * SD_CLK ==> pull down
134 static const u32 rts5260_sd_pull_ctl_disable_tbl
[] = {
135 RTSX_REG_PAIR(CARD_PULL_CTL1
, 0x66),
136 RTSX_REG_PAIR(CARD_PULL_CTL2
, 0x55),
137 RTSX_REG_PAIR(CARD_PULL_CTL3
, 0xD5),
138 RTSX_REG_PAIR(CARD_PULL_CTL4
, 0x55),
142 /* MS Pull Control Enable:
144 * others ==> pull down
146 static const u32 rts5260_ms_pull_ctl_enable_tbl
[] = {
147 RTSX_REG_PAIR(CARD_PULL_CTL4
, 0x55),
148 RTSX_REG_PAIR(CARD_PULL_CTL5
, 0x55),
149 RTSX_REG_PAIR(CARD_PULL_CTL6
, 0x15),
153 /* MS Pull Control Disable:
155 * others ==> pull down
157 static const u32 rts5260_ms_pull_ctl_disable_tbl
[] = {
158 RTSX_REG_PAIR(CARD_PULL_CTL4
, 0x55),
159 RTSX_REG_PAIR(CARD_PULL_CTL5
, 0x55),
160 RTSX_REG_PAIR(CARD_PULL_CTL6
, 0x15),
164 static int sd_set_sample_push_timing_sd30(struct rtsx_pcr
*pcr
)
166 rtsx_pci_write_register(pcr
, SD_CFG1
, SD_MODE_SELECT_MASK
167 | SD_ASYNC_FIFO_NOT_RST
, SD_30_MODE
| SD_ASYNC_FIFO_NOT_RST
);
168 rtsx_pci_write_register(pcr
, CLK_CTL
, CLK_LOW_FREQ
, CLK_LOW_FREQ
);
169 rtsx_pci_write_register(pcr
, CARD_CLK_SOURCE
, 0xFF,
170 CRC_VAR_CLK0
| SD30_FIX_CLK
| SAMPLE_VAR_CLK1
);
171 rtsx_pci_write_register(pcr
, CLK_CTL
, CLK_LOW_FREQ
, 0);
176 static int rts5260_card_power_on(struct rtsx_pcr
*pcr
, int card
)
178 struct rtsx_cr_option
*option
= &pcr
->option
;
181 rtsx_pci_enable_ocp(pcr
);
184 rtsx_pci_write_register(pcr
, LDO_CONFIG2
, DV331812_VDD1
, DV331812_VDD1
);
185 rtsx_pci_write_register(pcr
, LDO_VCC_CFG0
,
186 RTS5260_DVCC_TUNE_MASK
, RTS5260_DVCC_33
);
188 rtsx_pci_write_register(pcr
, LDO_VCC_CFG1
, LDO_POW_SDVDD1_MASK
,
191 rtsx_pci_write_register(pcr
, LDO_CONFIG2
,
192 DV331812_POWERON
, DV331812_POWERON
);
195 if (pcr
->extra_caps
& EXTRA_CAPS_SD_SDR50
||
196 pcr
->extra_caps
& EXTRA_CAPS_SD_SDR104
)
197 sd_set_sample_push_timing_sd30(pcr
);
199 /* Initialize SD_CFG1 register */
200 rtsx_pci_write_register(pcr
, SD_CFG1
, 0xFF,
201 SD_CLK_DIVIDE_128
| SD_20_MODE
);
203 rtsx_pci_write_register(pcr
, SD_SAMPLE_POINT_CTL
,
204 0xFF, SD20_RX_POS_EDGE
);
205 rtsx_pci_write_register(pcr
, SD_PUSH_POINT_CTL
, 0xFF, 0);
206 rtsx_pci_write_register(pcr
, CARD_STOP
, SD_STOP
| SD_CLR_ERR
,
207 SD_STOP
| SD_CLR_ERR
);
209 /* Reset SD_CFG3 register */
210 rtsx_pci_write_register(pcr
, SD_CFG3
, SD30_CLK_END_EN
, 0);
211 rtsx_pci_write_register(pcr
, REG_SD_STOP_SDCLK_CFG
,
212 SD30_CLK_STOP_CFG_EN
| SD30_CLK_STOP_CFG1
|
213 SD30_CLK_STOP_CFG0
, 0);
215 rtsx_pci_write_register(pcr
, REG_PRE_RW_MODE
, EN_INFINITE_MODE
, 0);
220 static int rts5260_switch_output_voltage(struct rtsx_pcr
*pcr
, u8 voltage
)
224 rtsx_pci_write_register(pcr
, LDO_CONFIG2
,
225 DV331812_VDD1
, DV331812_VDD1
);
226 rtsx_pci_write_register(pcr
, LDO_DV18_CFG
,
227 DV331812_MASK
, DV331812_33
);
228 rtsx_pci_write_register(pcr
, SD_PAD_CTL
, SD_IO_USING_1V8
, 0);
231 rtsx_pci_write_register(pcr
, LDO_CONFIG2
,
232 DV331812_VDD1
, DV331812_VDD1
);
233 rtsx_pci_write_register(pcr
, LDO_DV18_CFG
,
234 DV331812_MASK
, DV331812_17
);
235 rtsx_pci_write_register(pcr
, SD_PAD_CTL
, SD_IO_USING_1V8
,
243 rts5260_fill_driving(pcr
, voltage
);
248 static void rts5260_stop_cmd(struct rtsx_pcr
*pcr
)
250 rtsx_pci_writel(pcr
, RTSX_HCBCTLR
, STOP_CMD
);
251 rtsx_pci_writel(pcr
, RTSX_HDBCTLR
, STOP_DMA
);
252 rtsx_pci_write_register(pcr
, RTS5260_DMA_RST_CTL_0
,
253 RTS5260_DMA_RST
| RTS5260_ADMA3_RST
,
254 RTS5260_DMA_RST
| RTS5260_ADMA3_RST
);
255 rtsx_pci_write_register(pcr
, RBCTL
, RB_FLUSH
, RB_FLUSH
);
258 static void rts5260_card_before_power_off(struct rtsx_pcr
*pcr
)
260 rts5260_stop_cmd(pcr
);
261 rts5260_switch_output_voltage(pcr
, OUTPUT_3V3
);
265 static int rts5260_card_power_off(struct rtsx_pcr
*pcr
, int card
)
269 rts5260_card_before_power_off(pcr
);
270 err
= rtsx_pci_write_register(pcr
, LDO_VCC_CFG1
,
271 LDO_POW_SDVDD1_MASK
, LDO_POW_SDVDD1_OFF
);
272 err
= rtsx_pci_write_register(pcr
, LDO_CONFIG2
,
273 DV331812_POWERON
, DV331812_POWEROFF
);
274 if (pcr
->option
.ocp_en
)
275 rtsx_pci_disable_ocp(pcr
);
280 static void rts5260_init_ocp(struct rtsx_pcr
*pcr
)
282 struct rtsx_cr_option
*option
= &pcr
->option
;
284 if (option
->ocp_en
) {
288 rtsx_pci_write_register(pcr
, RTS5260_DVCC_CTRL
,
289 RTS5260_DVCC_OCP_THD_MASK
,
290 option
->sd_800mA_ocp_thd
);
292 rtsx_pci_write_register(pcr
, RTS5260_DV331812_CFG
,
293 RTS5260_DV331812_OCP_THD_MASK
,
294 RTS5260_DV331812_OCP_THD_270
);
296 mask
= SD_OCP_GLITCH_MASK
;
297 val
= pcr
->hw_param
.ocp_glitch
;
298 rtsx_pci_write_register(pcr
, REG_OCPGLITCH
, mask
, val
);
299 rtsx_pci_write_register(pcr
, RTS5260_DVCC_CTRL
,
300 RTS5260_DVCC_OCP_EN
|
301 RTS5260_DVCC_OCP_CL_EN
,
302 RTS5260_DVCC_OCP_EN
|
303 RTS5260_DVCC_OCP_CL_EN
);
305 rtsx_pci_enable_ocp(pcr
);
307 rtsx_pci_write_register(pcr
, RTS5260_DVCC_CTRL
,
308 RTS5260_DVCC_OCP_EN
|
309 RTS5260_DVCC_OCP_CL_EN
, 0);
313 static void rts5260_enable_ocp(struct rtsx_pcr
*pcr
)
317 val
= SD_OCP_INT_EN
| SD_DETECT_EN
;
318 rtsx_pci_write_register(pcr
, REG_OCPCTL
, 0xFF, val
);
322 static void rts5260_disable_ocp(struct rtsx_pcr
*pcr
)
326 mask
= SD_OCP_INT_EN
| SD_DETECT_EN
;
327 rtsx_pci_write_register(pcr
, REG_OCPCTL
, mask
, 0);
332 static int rts5260_get_ocpstat(struct rtsx_pcr
*pcr
, u8
*val
)
334 return rtsx_pci_read_register(pcr
, REG_OCPSTAT
, val
);
337 static int rts5260_get_ocpstat2(struct rtsx_pcr
*pcr
, u8
*val
)
339 return rtsx_pci_read_register(pcr
, REG_DV3318_OCPSTAT
, val
);
342 static void rts5260_clear_ocpstat(struct rtsx_pcr
*pcr
)
347 mask
= SD_OCP_INT_CLR
| SD_OC_CLR
;
348 val
= SD_OCP_INT_CLR
| SD_OC_CLR
;
350 rtsx_pci_write_register(pcr
, REG_OCPCTL
, mask
, val
);
351 rtsx_pci_write_register(pcr
, REG_DV3318_OCPCTL
,
352 DV3318_OCP_INT_CLR
| DV3318_OCP_CLR
,
353 DV3318_OCP_INT_CLR
| DV3318_OCP_CLR
);
355 rtsx_pci_write_register(pcr
, REG_OCPCTL
, mask
, 0);
356 rtsx_pci_write_register(pcr
, REG_DV3318_OCPCTL
,
357 DV3318_OCP_INT_CLR
| DV3318_OCP_CLR
, 0);
360 static void rts5260_process_ocp(struct rtsx_pcr
*pcr
)
362 if (!pcr
->option
.ocp_en
)
365 rtsx_pci_get_ocpstat(pcr
, &pcr
->ocp_stat
);
366 rts5260_get_ocpstat2(pcr
, &pcr
->ocp_stat2
);
368 if ((pcr
->ocp_stat
& (SD_OC_NOW
| SD_OC_EVER
)) ||
369 (pcr
->ocp_stat2
& (DV3318_OCP_NOW
| DV3318_OCP_EVER
))) {
370 rtsx_pci_card_power_off(pcr
, RTSX_SD_CARD
);
371 rtsx_pci_write_register(pcr
, CARD_OE
, SD_OUTPUT_EN
, 0);
372 rtsx_pci_clear_ocpstat(pcr
);
379 static int rts5260_init_hw(struct rtsx_pcr
*pcr
)
383 rtsx_pci_init_cmd(pcr
);
385 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, L1SUB_CONFIG1
,
386 AUX_CLK_ACTIVE_SEL_MASK
, MAC_CKSW_DONE
);
387 /* Rest L1SUB Config */
388 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, L1SUB_CONFIG3
, 0xFF, 0x00);
389 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PM_CLK_FORCE_CTL
,
390 CLK_PM_EN
, CLK_PM_EN
);
391 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PWD_SUSPEND_EN
, 0xFF, 0xFF);
392 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PWR_GATE_CTRL
,
393 PWR_GATE_EN
, PWR_GATE_EN
);
394 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, REG_VREF
,
395 PWD_SUSPND_EN
, PWD_SUSPND_EN
);
396 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, RBCTL
,
397 U_AUTO_DMA_EN_MASK
, U_AUTO_DMA_DISABLE
);
399 if (pcr
->flags
& PCR_REVERSE_SOCKET
)
400 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PETXCFG
, 0xB0, 0xB0);
402 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, PETXCFG
, 0xB0, 0x80);
404 rtsx_pci_add_cmd(pcr
, WRITE_REG_CMD
, OBFF_CFG
,
405 OBFF_EN_MASK
, OBFF_DISABLE
);
407 err
= rtsx_pci_send_cmd(pcr
, CMD_TIMEOUT_DEF
);
411 rtsx_pci_init_ocp(pcr
);
416 static void rts5260_pwr_saving_setting(struct rtsx_pcr
*pcr
)
418 int lss_l1_1
, lss_l1_2
;
420 lss_l1_1
= rtsx_check_dev_flag(pcr
, ASPM_L1_1_EN
)
421 | rtsx_check_dev_flag(pcr
, PM_L1_1_EN
);
422 lss_l1_2
= rtsx_check_dev_flag(pcr
, ASPM_L1_2_EN
)
423 | rtsx_check_dev_flag(pcr
, PM_L1_2_EN
);
425 rtsx_pci_write_register(pcr
, ASPM_FORCE_CTL
, 0xFF, 0);
427 pcr_dbg(pcr
, "Set parameters for L1.2.");
428 rtsx_pci_write_register(pcr
, PWR_GLOBAL_CTRL
,
430 rtsx_pci_write_register(pcr
, RTS5260_DVCC_CTRL
,
431 RTS5260_DVCC_OCP_EN
|
432 RTS5260_DVCC_OCP_CL_EN
,
433 RTS5260_DVCC_OCP_EN
|
434 RTS5260_DVCC_OCP_CL_EN
);
436 rtsx_pci_write_register(pcr
, PWR_FE_CTL
,
437 0xFF, PCIE_L1_2_PD_FE_EN
);
438 } else if (lss_l1_1
) {
439 pcr_dbg(pcr
, "Set parameters for L1.1.");
440 rtsx_pci_write_register(pcr
, PWR_GLOBAL_CTRL
,
442 rtsx_pci_write_register(pcr
, PWR_FE_CTL
,
443 0xFF, PCIE_L1_1_PD_FE_EN
);
445 pcr_dbg(pcr
, "Set parameters for L1.");
446 rtsx_pci_write_register(pcr
, PWR_GLOBAL_CTRL
,
448 rtsx_pci_write_register(pcr
, PWR_FE_CTL
,
449 0xFF, PCIE_L1_0_PD_FE_EN
);
452 rtsx_pci_write_register(pcr
, CFG_L1_0_PCIE_DPHY_RET_VALUE
,
453 0xFF, CFG_L1_0_RET_VALUE_DEFAULT
);
454 rtsx_pci_write_register(pcr
, CFG_L1_0_PCIE_MAC_RET_VALUE
,
455 0xFF, CFG_L1_0_RET_VALUE_DEFAULT
);
456 rtsx_pci_write_register(pcr
, CFG_L1_0_CRC_SD30_RET_VALUE
,
457 0xFF, CFG_L1_0_RET_VALUE_DEFAULT
);
458 rtsx_pci_write_register(pcr
, CFG_L1_0_CRC_SD40_RET_VALUE
,
459 0xFF, CFG_L1_0_RET_VALUE_DEFAULT
);
460 rtsx_pci_write_register(pcr
, CFG_L1_0_SYS_RET_VALUE
,
461 0xFF, CFG_L1_0_RET_VALUE_DEFAULT
);
463 rtsx_pci_write_register(pcr
, CFG_PCIE_APHY_OFF_0
,
464 0xFF, CFG_PCIE_APHY_OFF_0_DEFAULT
);
465 rtsx_pci_write_register(pcr
, CFG_PCIE_APHY_OFF_1
,
466 0xFF, CFG_PCIE_APHY_OFF_1_DEFAULT
);
467 rtsx_pci_write_register(pcr
, CFG_PCIE_APHY_OFF_2
,
468 0xFF, CFG_PCIE_APHY_OFF_2_DEFAULT
);
469 rtsx_pci_write_register(pcr
, CFG_PCIE_APHY_OFF_3
,
470 0xFF, CFG_PCIE_APHY_OFF_3_DEFAULT
);
472 rtsx_pci_write_register(pcr
, PWC_CDR
, 0xFF, PWC_CDR_DEFAULT
);
474 rtsx_pci_write_register(pcr
, CFG_LP_FPWM_VALUE
,
475 0xFF, CFG_LP_FPWM_VALUE_DEFAULT
);
476 /*No Power Saving WA*/
477 rtsx_pci_write_register(pcr
, CFG_L1_0_CRC_MISC_RET_VALUE
,
478 0xFF, CFG_L1_0_CRC_MISC_RET_VALUE_DEFAULT
);
481 static void rts5260_init_from_cfg(struct rtsx_pcr
*pcr
)
483 struct pci_dev
*pdev
= pcr
->pci
;
485 struct rtsx_cr_option
*option
= &pcr
->option
;
488 l1ss
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_L1SS
);
492 pci_read_config_dword(pdev
, l1ss
+ PCI_L1SS_CTL1
, &lval
);
494 if (lval
& PCI_L1SS_CTL1_ASPM_L1_1
)
495 rtsx_set_dev_flag(pcr
, ASPM_L1_1_EN
);
497 if (lval
& PCI_L1SS_CTL1_ASPM_L1_2
)
498 rtsx_set_dev_flag(pcr
, ASPM_L1_2_EN
);
500 if (lval
& PCI_L1SS_CTL1_PCIPM_L1_1
)
501 rtsx_set_dev_flag(pcr
, PM_L1_1_EN
);
503 if (lval
& PCI_L1SS_CTL1_PCIPM_L1_2
)
504 rtsx_set_dev_flag(pcr
, PM_L1_2_EN
);
506 rts5260_pwr_saving_setting(pcr
);
508 if (option
->ltr_en
) {
511 pcie_capability_read_word(pdev
, PCI_EXP_DEVCTL2
, &val
);
512 if (val
& PCI_EXP_DEVCTL2_LTR_EN
) {
513 option
->ltr_enabled
= true;
514 option
->ltr_active
= true;
515 rtsx_set_ltr_latency(pcr
, option
->ltr_active_latency
);
517 option
->ltr_enabled
= false;
521 if (rtsx_check_dev_flag(pcr
, ASPM_L1_1_EN
| ASPM_L1_2_EN
522 | PM_L1_1_EN
| PM_L1_2_EN
))
523 option
->force_clkreq_0
= false;
525 option
->force_clkreq_0
= true;
528 static int rts5260_extra_init_hw(struct rtsx_pcr
*pcr
)
530 struct rtsx_cr_option
*option
= &pcr
->option
;
532 /* Set mcu_cnt to 7 to ensure data can be sampled properly */
533 rtsx_pci_write_register(pcr
, 0xFC03, 0x7F, 0x07);
534 rtsx_pci_write_register(pcr
, SSC_DIV_N_0
, 0xFF, 0x5D);
536 rts5260_init_from_cfg(pcr
);
539 rtsx_pci_write_register(pcr
, RTS5260_AUTOLOAD_CFG4
,
540 0xFF, RTS5260_MIMO_DISABLE
);
541 /*Modify SDVCC Tune Default Parameters!*/
542 rtsx_pci_write_register(pcr
, LDO_VCC_CFG0
,
543 RTS5260_DVCC_TUNE_MASK
, RTS5260_DVCC_33
);
545 rtsx_pci_write_register(pcr
, PCLK_CTL
, PCLK_MODE_SEL
, PCLK_MODE_SEL
);
547 rts5260_init_hw(pcr
);
550 * If u_force_clkreq_0 is enabled, CLKREQ# PIN will be forced
551 * to drive low, and we forcibly request clock.
553 if (option
->force_clkreq_0
)
554 rtsx_pci_write_register(pcr
, PETXCFG
,
555 FORCE_CLKREQ_DELINK_MASK
, FORCE_CLKREQ_LOW
);
557 rtsx_pci_write_register(pcr
, PETXCFG
,
558 FORCE_CLKREQ_DELINK_MASK
, FORCE_CLKREQ_HIGH
);
560 rtsx_pci_write_register(pcr
, pcr
->reg_pm_ctrl3
, 0x10, 0x00);
565 static void rts5260_set_l1off_cfg_sub_d0(struct rtsx_pcr
*pcr
, int active
)
567 struct rtsx_cr_option
*option
= &pcr
->option
;
568 u32 interrupt
= rtsx_pci_readl(pcr
, RTSX_BIPR
);
569 int card_exist
= (interrupt
& SD_EXIST
) | (interrupt
& MS_EXIST
);
570 int aspm_L1_1
, aspm_L1_2
;
573 aspm_L1_1
= rtsx_check_dev_flag(pcr
, ASPM_L1_1_EN
);
574 aspm_L1_2
= rtsx_check_dev_flag(pcr
, ASPM_L1_2_EN
);
577 /* run, latency: 60us */
579 val
= option
->ltr_l1off_snooze_sspwrgate
;
581 /* l1off, latency: 300us */
583 val
= option
->ltr_l1off_sspwrgate
;
586 if (aspm_L1_1
|| aspm_L1_2
) {
587 if (rtsx_check_dev_flag(pcr
,
588 LTR_L1SS_PWR_GATE_CHECK_CARD_EN
)) {
590 val
&= ~L1OFF_MBIAS2_EN_5250
;
592 val
|= L1OFF_MBIAS2_EN_5250
;
595 rtsx_set_l1off_sub(pcr
, val
);
598 static const struct pcr_ops rts5260_pcr_ops
= {
599 .fetch_vendor_settings
= rtsx_base_fetch_vendor_settings
,
600 .turn_on_led
= rts5260_turn_on_led
,
601 .turn_off_led
= rts5260_turn_off_led
,
602 .extra_init_hw
= rts5260_extra_init_hw
,
603 .enable_auto_blink
= rtsx_base_enable_auto_blink
,
604 .disable_auto_blink
= rtsx_base_disable_auto_blink
,
605 .card_power_on
= rts5260_card_power_on
,
606 .card_power_off
= rts5260_card_power_off
,
607 .switch_output_voltage
= rts5260_switch_output_voltage
,
608 .stop_cmd
= rts5260_stop_cmd
,
609 .set_l1off_cfg_sub_d0
= rts5260_set_l1off_cfg_sub_d0
,
610 .enable_ocp
= rts5260_enable_ocp
,
611 .disable_ocp
= rts5260_disable_ocp
,
612 .init_ocp
= rts5260_init_ocp
,
613 .process_ocp
= rts5260_process_ocp
,
614 .get_ocpstat
= rts5260_get_ocpstat
,
615 .clear_ocpstat
= rts5260_clear_ocpstat
,
618 void rts5260_init_params(struct rtsx_pcr
*pcr
)
620 struct rtsx_cr_option
*option
= &pcr
->option
;
621 struct rtsx_hw_param
*hw_param
= &pcr
->hw_param
;
623 pcr
->extra_caps
= EXTRA_CAPS_SD_SDR50
| EXTRA_CAPS_SD_SDR104
;
627 pcr
->card_drive_sel
= RTSX_CARD_DRIVE_DEFAULT
;
628 pcr
->sd30_drive_sel_1v8
= CFG_DRIVER_TYPE_B
;
629 pcr
->sd30_drive_sel_3v3
= CFG_DRIVER_TYPE_B
;
630 pcr
->aspm_en
= ASPM_L1_EN
;
631 pcr
->tx_initial_phase
= SET_CLOCK_PHASE(27, 29, 11);
632 pcr
->rx_initial_phase
= SET_CLOCK_PHASE(24, 6, 5);
634 pcr
->ic_version
= rts5260_get_ic_version(pcr
);
635 pcr
->sd_pull_ctl_enable_tbl
= rts5260_sd_pull_ctl_enable_tbl
;
636 pcr
->sd_pull_ctl_disable_tbl
= rts5260_sd_pull_ctl_disable_tbl
;
637 pcr
->ms_pull_ctl_enable_tbl
= rts5260_ms_pull_ctl_enable_tbl
;
638 pcr
->ms_pull_ctl_disable_tbl
= rts5260_ms_pull_ctl_disable_tbl
;
640 pcr
->reg_pm_ctrl3
= RTS524A_PM_CTRL3
;
642 pcr
->ops
= &rts5260_pcr_ops
;
644 option
->dev_flags
= (LTR_L1SS_PWR_GATE_CHECK_CARD_EN
645 | LTR_L1SS_PWR_GATE_EN
);
646 option
->ltr_en
= true;
648 /* init latency of active, idle, L1OFF to 60us, 300us, 3ms */
649 option
->ltr_active_latency
= LTR_ACTIVE_LATENCY_DEF
;
650 option
->ltr_idle_latency
= LTR_IDLE_LATENCY_DEF
;
651 option
->ltr_l1off_latency
= LTR_L1OFF_LATENCY_DEF
;
652 option
->l1_snooze_delay
= L1_SNOOZE_DELAY_DEF
;
653 option
->ltr_l1off_sspwrgate
= LTR_L1OFF_SSPWRGATE_5250_DEF
;
654 option
->ltr_l1off_snooze_sspwrgate
=
655 LTR_L1OFF_SNOOZE_SSPWRGATE_5250_DEF
;
659 hw_param
->interrupt_en
|= SD_OC_INT_EN
;
660 hw_param
->ocp_glitch
= SD_OCP_GLITCH_100U
| SDVIO_OCP_GLITCH_800U
;
661 option
->sd_400mA_ocp_thd
= RTS5260_DVCC_OCP_THD_550
;
662 option
->sd_800mA_ocp_thd
= RTS5260_DVCC_OCP_THD_970
;