Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: rtsx: Add support new chip rts5228 mmc: rtsx: Add support MMC_CAP2_NO_MMC

In order to support new chip rts5228, the definitions of some internal
registers and workflow have to be modified.
Added rts5228.c rts5228.h for independent functions of the new chip rts5228

Signed-off-by: Ricky Wu <ricky_wu@realtek.com>
Link: https://lore.kernel.org/r/20200706070259.32565-1-ricky_wu@realtek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ricky Wu and committed by
Greg Kroah-Hartman
849a9366 f31a03b1

+985 -32
+1 -1
drivers/misc/cardreader/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 obj-$(CONFIG_MISC_ALCOR_PCI) += alcor_pci.o 3 3 obj-$(CONFIG_MISC_RTSX_PCI) += rtsx_pci.o 4 - rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o rts5260.o rts5261.o 4 + rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o rts5260.o rts5261.o rts5228.o 5 5 obj-$(CONFIG_MISC_RTSX_USB) += rtsx_usb.o
+740
drivers/misc/cardreader/rts5228.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* Driver for Realtek PCI-Express card reader 3 + * 4 + * Copyright(c) 2018-2019 Realtek Semiconductor Corp. All rights reserved. 5 + * 6 + * Author: 7 + * Ricky WU <ricky_wu@realtek.com> 8 + * Rui FENG <rui_feng@realsil.com.cn> 9 + * Wei WANG <wei_wang@realsil.com.cn> 10 + */ 11 + 12 + #include <linux/module.h> 13 + #include <linux/delay.h> 14 + #include <linux/rtsx_pci.h> 15 + 16 + #include "rts5228.h" 17 + #include "rtsx_pcr.h" 18 + 19 + static u8 rts5228_get_ic_version(struct rtsx_pcr *pcr) 20 + { 21 + u8 val; 22 + 23 + rtsx_pci_read_register(pcr, DUMMY_REG_RESET_0, &val); 24 + return val & IC_VERSION_MASK; 25 + } 26 + 27 + static void rts5228_fill_driving(struct rtsx_pcr *pcr, u8 voltage) 28 + { 29 + u8 driving_3v3[4][3] = { 30 + {0x13, 0x13, 0x13}, 31 + {0x96, 0x96, 0x96}, 32 + {0x7F, 0x7F, 0x7F}, 33 + {0x96, 0x96, 0x96}, 34 + }; 35 + u8 driving_1v8[4][3] = { 36 + {0x99, 0x99, 0x99}, 37 + {0xB5, 0xB5, 0xB5}, 38 + {0xE6, 0x7E, 0xFE}, 39 + {0x6B, 0x6B, 0x6B}, 40 + }; 41 + u8 (*driving)[3], drive_sel; 42 + 43 + if (voltage == OUTPUT_3V3) { 44 + driving = driving_3v3; 45 + drive_sel = pcr->sd30_drive_sel_3v3; 46 + } else { 47 + driving = driving_1v8; 48 + drive_sel = pcr->sd30_drive_sel_1v8; 49 + } 50 + 51 + rtsx_pci_write_register(pcr, SD30_CLK_DRIVE_SEL, 52 + 0xFF, driving[drive_sel][0]); 53 + 54 + rtsx_pci_write_register(pcr, SD30_CMD_DRIVE_SEL, 55 + 0xFF, driving[drive_sel][1]); 56 + 57 + rtsx_pci_write_register(pcr, SD30_DAT_DRIVE_SEL, 58 + 0xFF, driving[drive_sel][2]); 59 + } 60 + 61 + static void rtsx5228_fetch_vendor_settings(struct rtsx_pcr *pcr) 62 + { 63 + u32 reg; 64 + /* 0x724~0x727 */ 65 + rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg); 66 + pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg); 67 + 68 + if (!rtsx_vendor_setting_valid(reg)) { 69 + pcr_dbg(pcr, "skip fetch vendor setting\n"); 70 + return; 71 + } 72 + pcr->sd30_drive_sel_1v8 = rtsx_reg_to_sd30_drive_sel_1v8(reg); 73 + pcr->aspm_en = rtsx_reg_to_aspm(reg); 74 + 75 + /* 0x814~0x817 */ 76 + rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG2, &reg); 77 + pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg); 78 + 79 + pcr->rtd3_en = rtsx_reg_to_rtd3(reg); 80 + if (rtsx_check_mmc_support(reg)) 81 + pcr->extra_caps |= EXTRA_CAPS_NO_MMC; 82 + pcr->sd30_drive_sel_3v3 = rtsx_reg_to_sd30_drive_sel_3v3(reg); 83 + if (rtsx_reg_check_reverse_socket(reg)) 84 + pcr->flags |= PCR_REVERSE_SOCKET; 85 + } 86 + 87 + static int rts5228_optimize_phy(struct rtsx_pcr *pcr) 88 + { 89 + return rtsx_pci_write_phy_register(pcr, 0x07, 0x8F40); 90 + } 91 + 92 + static void rts5228_force_power_down(struct rtsx_pcr *pcr, u8 pm_state) 93 + { 94 + /* Set relink_time to 0 */ 95 + rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 1, MASK_8_BIT_DEF, 0); 96 + rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 2, MASK_8_BIT_DEF, 0); 97 + rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 98 + RELINK_TIME_MASK, 0); 99 + 100 + if (pm_state == HOST_ENTER_S3) 101 + rtsx_pci_write_register(pcr, pcr->reg_pm_ctrl3, 102 + D3_DELINK_MODE_EN, D3_DELINK_MODE_EN); 103 + 104 + rtsx_pci_write_register(pcr, FPDCTL, 105 + SSC_POWER_DOWN, SSC_POWER_DOWN); 106 + } 107 + 108 + static int rts5228_enable_auto_blink(struct rtsx_pcr *pcr) 109 + { 110 + return rtsx_pci_write_register(pcr, OLT_LED_CTL, 111 + LED_SHINE_MASK, LED_SHINE_EN); 112 + } 113 + 114 + static int rts5228_disable_auto_blink(struct rtsx_pcr *pcr) 115 + { 116 + return rtsx_pci_write_register(pcr, OLT_LED_CTL, 117 + LED_SHINE_MASK, LED_SHINE_DISABLE); 118 + } 119 + 120 + static int rts5228_turn_on_led(struct rtsx_pcr *pcr) 121 + { 122 + return rtsx_pci_write_register(pcr, GPIO_CTL, 123 + 0x02, 0x02); 124 + } 125 + 126 + static int rts5228_turn_off_led(struct rtsx_pcr *pcr) 127 + { 128 + return rtsx_pci_write_register(pcr, GPIO_CTL, 129 + 0x02, 0x00); 130 + } 131 + 132 + /* SD Pull Control Enable: 133 + * SD_DAT[3:0] ==> pull up 134 + * SD_CD ==> pull up 135 + * SD_WP ==> pull up 136 + * SD_CMD ==> pull up 137 + * SD_CLK ==> pull down 138 + */ 139 + static const u32 rts5228_sd_pull_ctl_enable_tbl[] = { 140 + RTSX_REG_PAIR(CARD_PULL_CTL2, 0xAA), 141 + RTSX_REG_PAIR(CARD_PULL_CTL3, 0xE9), 142 + 0, 143 + }; 144 + 145 + /* SD Pull Control Disable: 146 + * SD_DAT[3:0] ==> pull down 147 + * SD_CD ==> pull up 148 + * SD_WP ==> pull down 149 + * SD_CMD ==> pull down 150 + * SD_CLK ==> pull down 151 + */ 152 + static const u32 rts5228_sd_pull_ctl_disable_tbl[] = { 153 + RTSX_REG_PAIR(CARD_PULL_CTL2, 0x55), 154 + RTSX_REG_PAIR(CARD_PULL_CTL3, 0xD5), 155 + 0, 156 + }; 157 + 158 + static int rts5228_sd_set_sample_push_timing_sd30(struct rtsx_pcr *pcr) 159 + { 160 + rtsx_pci_write_register(pcr, SD_CFG1, SD_MODE_SELECT_MASK 161 + | SD_ASYNC_FIFO_NOT_RST, SD_30_MODE | SD_ASYNC_FIFO_NOT_RST); 162 + rtsx_pci_write_register(pcr, CLK_CTL, CLK_LOW_FREQ, CLK_LOW_FREQ); 163 + rtsx_pci_write_register(pcr, CARD_CLK_SOURCE, 0xFF, 164 + CRC_VAR_CLK0 | SD30_FIX_CLK | SAMPLE_VAR_CLK1); 165 + rtsx_pci_write_register(pcr, CLK_CTL, CLK_LOW_FREQ, 0); 166 + 167 + return 0; 168 + } 169 + 170 + static int rts5228_card_power_on(struct rtsx_pcr *pcr, int card) 171 + { 172 + struct rtsx_cr_option *option = &pcr->option; 173 + 174 + if (option->ocp_en) 175 + rtsx_pci_enable_ocp(pcr); 176 + 177 + rtsx_pci_write_register(pcr, REG_CRC_DUMMY_0, 178 + CFG_SD_POW_AUTO_PD, CFG_SD_POW_AUTO_PD); 179 + 180 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG1, 181 + RTS5228_LDO1_TUNE_MASK, RTS5228_LDO1_33); 182 + 183 + rtsx_pci_write_register(pcr, RTS5228_LDO1233318_POW_CTL, 184 + RTS5228_LDO1_POWERON_MASK, RTS5228_LDO1_SOFTSTART); 185 + mdelay(2); 186 + rtsx_pci_write_register(pcr, RTS5228_LDO1233318_POW_CTL, 187 + RTS5228_LDO1_POWERON_MASK, RTS5228_LDO1_FULLON); 188 + 189 + 190 + rtsx_pci_write_register(pcr, RTS5228_LDO1233318_POW_CTL, 191 + RTS5228_LDO3318_POWERON, RTS5228_LDO3318_POWERON); 192 + 193 + msleep(20); 194 + 195 + rtsx_pci_write_register(pcr, CARD_OE, SD_OUTPUT_EN, SD_OUTPUT_EN); 196 + 197 + /* Initialize SD_CFG1 register */ 198 + rtsx_pci_write_register(pcr, SD_CFG1, 0xFF, 199 + SD_CLK_DIVIDE_128 | SD_20_MODE | SD_BUS_WIDTH_1BIT); 200 + 201 + rtsx_pci_write_register(pcr, SD_SAMPLE_POINT_CTL, 202 + 0xFF, SD20_RX_POS_EDGE); 203 + rtsx_pci_write_register(pcr, SD_PUSH_POINT_CTL, 0xFF, 0); 204 + rtsx_pci_write_register(pcr, CARD_STOP, SD_STOP | SD_CLR_ERR, 205 + SD_STOP | SD_CLR_ERR); 206 + 207 + /* Reset SD_CFG3 register */ 208 + rtsx_pci_write_register(pcr, SD_CFG3, SD30_CLK_END_EN, 0); 209 + rtsx_pci_write_register(pcr, REG_SD_STOP_SDCLK_CFG, 210 + SD30_CLK_STOP_CFG_EN | SD30_CLK_STOP_CFG1 | 211 + SD30_CLK_STOP_CFG0, 0); 212 + 213 + if (pcr->extra_caps & EXTRA_CAPS_SD_SDR50 || 214 + pcr->extra_caps & EXTRA_CAPS_SD_SDR104) 215 + rts5228_sd_set_sample_push_timing_sd30(pcr); 216 + 217 + return 0; 218 + } 219 + 220 + static int rts5228_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage) 221 + { 222 + int err; 223 + u16 val = 0; 224 + 225 + rtsx_pci_write_register(pcr, RTS5228_CARD_PWR_CTL, 226 + RTS5228_PUPDC, RTS5228_PUPDC); 227 + 228 + switch (voltage) { 229 + case OUTPUT_3V3: 230 + rtsx_pci_read_phy_register(pcr, PHY_TUNE, &val); 231 + val |= PHY_TUNE_SDBUS_33; 232 + err = rtsx_pci_write_phy_register(pcr, PHY_TUNE, val); 233 + if (err < 0) 234 + return err; 235 + 236 + rtsx_pci_write_register(pcr, RTS5228_DV3318_CFG, 237 + RTS5228_DV3318_TUNE_MASK, RTS5228_DV3318_33); 238 + rtsx_pci_write_register(pcr, SD_PAD_CTL, 239 + SD_IO_USING_1V8, 0); 240 + break; 241 + case OUTPUT_1V8: 242 + rtsx_pci_read_phy_register(pcr, PHY_TUNE, &val); 243 + val &= ~PHY_TUNE_SDBUS_33; 244 + err = rtsx_pci_write_phy_register(pcr, PHY_TUNE, val); 245 + if (err < 0) 246 + return err; 247 + 248 + rtsx_pci_write_register(pcr, RTS5228_DV3318_CFG, 249 + RTS5228_DV3318_TUNE_MASK, RTS5228_DV3318_18); 250 + rtsx_pci_write_register(pcr, SD_PAD_CTL, 251 + SD_IO_USING_1V8, SD_IO_USING_1V8); 252 + break; 253 + default: 254 + return -EINVAL; 255 + } 256 + 257 + /* set pad drive */ 258 + rts5228_fill_driving(pcr, voltage); 259 + 260 + return 0; 261 + } 262 + 263 + static void rts5228_stop_cmd(struct rtsx_pcr *pcr) 264 + { 265 + rtsx_pci_writel(pcr, RTSX_HCBCTLR, STOP_CMD); 266 + rtsx_pci_writel(pcr, RTSX_HDBCTLR, STOP_DMA); 267 + rtsx_pci_write_register(pcr, RTS5260_DMA_RST_CTL_0, 268 + RTS5260_DMA_RST | RTS5260_ADMA3_RST, 269 + RTS5260_DMA_RST | RTS5260_ADMA3_RST); 270 + rtsx_pci_write_register(pcr, RBCTL, RB_FLUSH, RB_FLUSH); 271 + } 272 + 273 + static void rts5228_card_before_power_off(struct rtsx_pcr *pcr) 274 + { 275 + rts5228_stop_cmd(pcr); 276 + rts5228_switch_output_voltage(pcr, OUTPUT_3V3); 277 + } 278 + 279 + static void rts5228_enable_ocp(struct rtsx_pcr *pcr) 280 + { 281 + u8 val = 0; 282 + 283 + val = SD_OCP_INT_EN | SD_DETECT_EN; 284 + rtsx_pci_write_register(pcr, REG_OCPCTL, 0xFF, val); 285 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG0, 286 + RTS5228_LDO1_OCP_EN | RTS5228_LDO1_OCP_LMT_EN, 287 + RTS5228_LDO1_OCP_EN | RTS5228_LDO1_OCP_LMT_EN); 288 + } 289 + 290 + static void rts5228_disable_ocp(struct rtsx_pcr *pcr) 291 + { 292 + u8 mask = 0; 293 + 294 + mask = SD_OCP_INT_EN | SD_DETECT_EN; 295 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); 296 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG0, 297 + RTS5228_LDO1_OCP_EN | RTS5228_LDO1_OCP_LMT_EN, 0); 298 + } 299 + 300 + static int rts5228_card_power_off(struct rtsx_pcr *pcr, int card) 301 + { 302 + int err = 0; 303 + 304 + rts5228_card_before_power_off(pcr); 305 + err = rtsx_pci_write_register(pcr, RTS5228_LDO1233318_POW_CTL, 306 + RTS5228_LDO_POWERON_MASK, 0); 307 + rtsx_pci_write_register(pcr, REG_CRC_DUMMY_0, CFG_SD_POW_AUTO_PD, 0); 308 + 309 + if (pcr->option.ocp_en) 310 + rtsx_pci_disable_ocp(pcr); 311 + 312 + return err; 313 + } 314 + 315 + static void rts5228_init_ocp(struct rtsx_pcr *pcr) 316 + { 317 + struct rtsx_cr_option *option = &pcr->option; 318 + 319 + if (option->ocp_en) { 320 + u8 mask, val; 321 + 322 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG0, 323 + RTS5228_LDO1_OCP_EN | RTS5228_LDO1_OCP_LMT_EN, 324 + RTS5228_LDO1_OCP_EN | RTS5228_LDO1_OCP_LMT_EN); 325 + 326 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG0, 327 + RTS5228_LDO1_OCP_THD_MASK, option->sd_800mA_ocp_thd); 328 + 329 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG0, 330 + RTS5228_LDO1_OCP_LMT_THD_MASK, 331 + RTS5228_LDO1_LMT_THD_1500); 332 + 333 + rtsx_pci_read_register(pcr, RTS5228_LDO1_CFG0, &val); 334 + 335 + mask = SD_OCP_GLITCH_MASK; 336 + val = pcr->hw_param.ocp_glitch; 337 + rtsx_pci_write_register(pcr, REG_OCPGLITCH, mask, val); 338 + 339 + rts5228_enable_ocp(pcr); 340 + 341 + } else { 342 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG0, 343 + RTS5228_LDO1_OCP_EN | RTS5228_LDO1_OCP_LMT_EN, 0); 344 + } 345 + } 346 + 347 + static void rts5228_clear_ocpstat(struct rtsx_pcr *pcr) 348 + { 349 + u8 mask = 0; 350 + u8 val = 0; 351 + 352 + mask = SD_OCP_INT_CLR | SD_OC_CLR; 353 + val = SD_OCP_INT_CLR | SD_OC_CLR; 354 + 355 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, val); 356 + 357 + udelay(1000); 358 + rtsx_pci_write_register(pcr, REG_OCPCTL, mask, 0); 359 + 360 + } 361 + 362 + static void rts5228_process_ocp(struct rtsx_pcr *pcr) 363 + { 364 + if (!pcr->option.ocp_en) 365 + return; 366 + 367 + rtsx_pci_get_ocpstat(pcr, &pcr->ocp_stat); 368 + 369 + if (pcr->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) { 370 + rts5228_clear_ocpstat(pcr); 371 + rts5228_card_power_off(pcr, RTSX_SD_CARD); 372 + rtsx_pci_write_register(pcr, CARD_OE, SD_OUTPUT_EN, 0); 373 + pcr->ocp_stat = 0; 374 + } 375 + 376 + } 377 + 378 + static void rts5228_init_from_cfg(struct rtsx_pcr *pcr) 379 + { 380 + u32 lval; 381 + struct rtsx_cr_option *option = &pcr->option; 382 + 383 + rtsx_pci_read_config_dword(pcr, PCR_ASPM_SETTING_REG1, &lval); 384 + 385 + 386 + if (0 == (lval & 0x0F)) 387 + rtsx_pci_enable_oobs_polling(pcr); 388 + else 389 + rtsx_pci_disable_oobs_polling(pcr); 390 + 391 + if (lval & ASPM_L1_1_EN_MASK) 392 + rtsx_set_dev_flag(pcr, ASPM_L1_1_EN); 393 + else 394 + rtsx_clear_dev_flag(pcr, ASPM_L1_1_EN); 395 + 396 + if (lval & ASPM_L1_2_EN_MASK) 397 + rtsx_set_dev_flag(pcr, ASPM_L1_2_EN); 398 + else 399 + rtsx_clear_dev_flag(pcr, ASPM_L1_2_EN); 400 + 401 + if (lval & PM_L1_1_EN_MASK) 402 + rtsx_set_dev_flag(pcr, PM_L1_1_EN); 403 + else 404 + rtsx_clear_dev_flag(pcr, PM_L1_1_EN); 405 + 406 + if (lval & PM_L1_2_EN_MASK) 407 + rtsx_set_dev_flag(pcr, PM_L1_2_EN); 408 + else 409 + rtsx_clear_dev_flag(pcr, PM_L1_2_EN); 410 + 411 + rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, 0xFF, 0); 412 + if (option->ltr_en) { 413 + u16 val; 414 + 415 + pcie_capability_read_word(pcr->pci, PCI_EXP_DEVCTL2, &val); 416 + if (val & PCI_EXP_DEVCTL2_LTR_EN) { 417 + option->ltr_enabled = true; 418 + option->ltr_active = true; 419 + rtsx_set_ltr_latency(pcr, option->ltr_active_latency); 420 + } else { 421 + option->ltr_enabled = false; 422 + } 423 + } 424 + 425 + if (rtsx_check_dev_flag(pcr, ASPM_L1_1_EN | ASPM_L1_2_EN 426 + | PM_L1_1_EN | PM_L1_2_EN)) 427 + option->force_clkreq_0 = false; 428 + else 429 + option->force_clkreq_0 = true; 430 + } 431 + 432 + static int rts5228_extra_init_hw(struct rtsx_pcr *pcr) 433 + { 434 + struct rtsx_cr_option *option = &pcr->option; 435 + 436 + rtsx_pci_write_register(pcr, RTS5228_AUTOLOAD_CFG1, 437 + CD_RESUME_EN_MASK, CD_RESUME_EN_MASK); 438 + 439 + rts5228_init_from_cfg(pcr); 440 + 441 + rtsx_pci_write_register(pcr, L1SUB_CONFIG1, 442 + AUX_CLK_ACTIVE_SEL_MASK, MAC_CKSW_DONE); 443 + rtsx_pci_write_register(pcr, L1SUB_CONFIG3, 0xFF, 0); 444 + 445 + rtsx_pci_write_register(pcr, FUNC_FORCE_CTL, 446 + FUNC_FORCE_UPME_XMT_DBG, FUNC_FORCE_UPME_XMT_DBG); 447 + 448 + rtsx_pci_write_register(pcr, PCLK_CTL, 449 + PCLK_MODE_SEL, PCLK_MODE_SEL); 450 + 451 + rtsx_pci_write_register(pcr, PM_EVENT_DEBUG, PME_DEBUG_0, PME_DEBUG_0); 452 + rtsx_pci_write_register(pcr, PM_CLK_FORCE_CTL, CLK_PM_EN, CLK_PM_EN); 453 + 454 + /* LED shine disabled, set initial shine cycle period */ 455 + rtsx_pci_write_register(pcr, OLT_LED_CTL, 0x0F, 0x02); 456 + 457 + /* Configure driving */ 458 + rts5228_fill_driving(pcr, OUTPUT_3V3); 459 + 460 + if (pcr->flags & PCR_REVERSE_SOCKET) 461 + rtsx_pci_write_register(pcr, PETXCFG, 0x30, 0x30); 462 + else 463 + rtsx_pci_write_register(pcr, PETXCFG, 0x30, 0x00); 464 + 465 + /* 466 + * If u_force_clkreq_0 is enabled, CLKREQ# PIN will be forced 467 + * to drive low, and we forcibly request clock. 468 + */ 469 + if (option->force_clkreq_0) 470 + rtsx_pci_write_register(pcr, PETXCFG, 471 + FORCE_CLKREQ_DELINK_MASK, FORCE_CLKREQ_LOW); 472 + else 473 + rtsx_pci_write_register(pcr, PETXCFG, 474 + FORCE_CLKREQ_DELINK_MASK, FORCE_CLKREQ_HIGH); 475 + 476 + rtsx_pci_write_register(pcr, PWD_SUSPEND_EN, 0xFF, 0xFB); 477 + rtsx_pci_write_register(pcr, pcr->reg_pm_ctrl3, 0x10, 0x00); 478 + rtsx_pci_write_register(pcr, RTS5228_REG_PME_FORCE_CTL, 479 + FORCE_PM_CONTROL | FORCE_PM_VALUE, FORCE_PM_CONTROL); 480 + 481 + return 0; 482 + } 483 + 484 + static void rts5228_enable_aspm(struct rtsx_pcr *pcr, bool enable) 485 + { 486 + u8 mask, val; 487 + 488 + if (pcr->aspm_enabled == enable) 489 + return; 490 + 491 + mask = FORCE_ASPM_VAL_MASK | FORCE_ASPM_CTL0 | FORCE_ASPM_CTL1; 492 + val = FORCE_ASPM_CTL0 | FORCE_ASPM_CTL1; 493 + val |= (pcr->aspm_en & 0x02); 494 + rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, mask, val); 495 + pcie_capability_clear_and_set_word(pcr->pci, PCI_EXP_LNKCTL, 496 + PCI_EXP_LNKCTL_ASPMC, pcr->aspm_en); 497 + pcr->aspm_enabled = enable; 498 + } 499 + 500 + static void rts5228_disable_aspm(struct rtsx_pcr *pcr, bool enable) 501 + { 502 + u8 mask, val; 503 + 504 + if (pcr->aspm_enabled == enable) 505 + return; 506 + 507 + pcie_capability_clear_and_set_word(pcr->pci, PCI_EXP_LNKCTL, 508 + PCI_EXP_LNKCTL_ASPMC, 0); 509 + mask = FORCE_ASPM_VAL_MASK | FORCE_ASPM_CTL0 | FORCE_ASPM_CTL1; 510 + val = FORCE_ASPM_CTL0 | FORCE_ASPM_CTL1; 511 + rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, mask, val); 512 + rtsx_pci_write_register(pcr, SD_CFG1, SD_ASYNC_FIFO_NOT_RST, 0); 513 + mdelay(10); 514 + pcr->aspm_enabled = enable; 515 + } 516 + 517 + static void rts5228_set_aspm(struct rtsx_pcr *pcr, bool enable) 518 + { 519 + if (enable) 520 + rts5228_enable_aspm(pcr, true); 521 + else 522 + rts5228_disable_aspm(pcr, false); 523 + } 524 + 525 + static void rts5228_set_l1off_cfg_sub_d0(struct rtsx_pcr *pcr, int active) 526 + { 527 + struct rtsx_cr_option *option = &pcr->option; 528 + int aspm_L1_1, aspm_L1_2; 529 + u8 val = 0; 530 + 531 + aspm_L1_1 = rtsx_check_dev_flag(pcr, ASPM_L1_1_EN); 532 + aspm_L1_2 = rtsx_check_dev_flag(pcr, ASPM_L1_2_EN); 533 + 534 + if (active) { 535 + /* run, latency: 60us */ 536 + if (aspm_L1_1) 537 + val = option->ltr_l1off_snooze_sspwrgate; 538 + } else { 539 + /* l1off, latency: 300us */ 540 + if (aspm_L1_2) 541 + val = option->ltr_l1off_sspwrgate; 542 + } 543 + 544 + rtsx_set_l1off_sub(pcr, val); 545 + } 546 + 547 + static const struct pcr_ops rts5228_pcr_ops = { 548 + .fetch_vendor_settings = rtsx5228_fetch_vendor_settings, 549 + .turn_on_led = rts5228_turn_on_led, 550 + .turn_off_led = rts5228_turn_off_led, 551 + .extra_init_hw = rts5228_extra_init_hw, 552 + .enable_auto_blink = rts5228_enable_auto_blink, 553 + .disable_auto_blink = rts5228_disable_auto_blink, 554 + .card_power_on = rts5228_card_power_on, 555 + .card_power_off = rts5228_card_power_off, 556 + .switch_output_voltage = rts5228_switch_output_voltage, 557 + .force_power_down = rts5228_force_power_down, 558 + .stop_cmd = rts5228_stop_cmd, 559 + .set_aspm = rts5228_set_aspm, 560 + .set_l1off_cfg_sub_d0 = rts5228_set_l1off_cfg_sub_d0, 561 + .enable_ocp = rts5228_enable_ocp, 562 + .disable_ocp = rts5228_disable_ocp, 563 + .init_ocp = rts5228_init_ocp, 564 + .process_ocp = rts5228_process_ocp, 565 + .clear_ocpstat = rts5228_clear_ocpstat, 566 + .optimize_phy = rts5228_optimize_phy, 567 + }; 568 + 569 + 570 + static inline u8 double_ssc_depth(u8 depth) 571 + { 572 + return ((depth > 1) ? (depth - 1) : depth); 573 + } 574 + 575 + int rts5228_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, 576 + u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk) 577 + { 578 + int err, clk; 579 + u16 n; 580 + u8 clk_divider, mcu_cnt, div; 581 + static const u8 depth[] = { 582 + [RTSX_SSC_DEPTH_4M] = RTS5228_SSC_DEPTH_4M, 583 + [RTSX_SSC_DEPTH_2M] = RTS5228_SSC_DEPTH_2M, 584 + [RTSX_SSC_DEPTH_1M] = RTS5228_SSC_DEPTH_1M, 585 + [RTSX_SSC_DEPTH_500K] = RTS5228_SSC_DEPTH_512K, 586 + }; 587 + 588 + if (initial_mode) { 589 + /* We use 250k(around) here, in initial stage */ 590 + clk_divider = SD_CLK_DIVIDE_128; 591 + card_clock = 30000000; 592 + } else { 593 + clk_divider = SD_CLK_DIVIDE_0; 594 + } 595 + err = rtsx_pci_write_register(pcr, SD_CFG1, 596 + SD_CLK_DIVIDE_MASK, clk_divider); 597 + if (err < 0) 598 + return err; 599 + 600 + card_clock /= 1000000; 601 + pcr_dbg(pcr, "Switch card clock to %dMHz\n", card_clock); 602 + 603 + clk = card_clock; 604 + if (!initial_mode && double_clk) 605 + clk = card_clock * 2; 606 + pcr_dbg(pcr, "Internal SSC clock: %dMHz (cur_clock = %d)\n", 607 + clk, pcr->cur_clock); 608 + 609 + if (clk == pcr->cur_clock) 610 + return 0; 611 + 612 + if (pcr->ops->conv_clk_and_div_n) 613 + n = pcr->ops->conv_clk_and_div_n(clk, CLK_TO_DIV_N); 614 + else 615 + n = clk - 4; 616 + if ((clk <= 4) || (n > 396)) 617 + return -EINVAL; 618 + 619 + mcu_cnt = 125/clk + 3; 620 + if (mcu_cnt > 15) 621 + mcu_cnt = 15; 622 + 623 + div = CLK_DIV_1; 624 + while ((n < MIN_DIV_N_PCR - 4) && (div < CLK_DIV_8)) { 625 + if (pcr->ops->conv_clk_and_div_n) { 626 + int dbl_clk = pcr->ops->conv_clk_and_div_n(n, 627 + DIV_N_TO_CLK) * 2; 628 + n = pcr->ops->conv_clk_and_div_n(dbl_clk, 629 + CLK_TO_DIV_N); 630 + } else { 631 + n = (n + 4) * 2 - 4; 632 + } 633 + div++; 634 + } 635 + 636 + n = (n / 2) - 1; 637 + pcr_dbg(pcr, "n = %d, div = %d\n", n, div); 638 + 639 + ssc_depth = depth[ssc_depth]; 640 + if (double_clk) 641 + ssc_depth = double_ssc_depth(ssc_depth); 642 + 643 + if (ssc_depth) { 644 + if (div == CLK_DIV_2) { 645 + if (ssc_depth > 1) 646 + ssc_depth -= 1; 647 + else 648 + ssc_depth = RTS5228_SSC_DEPTH_8M; 649 + } else if (div == CLK_DIV_4) { 650 + if (ssc_depth > 2) 651 + ssc_depth -= 2; 652 + else 653 + ssc_depth = RTS5228_SSC_DEPTH_8M; 654 + } else if (div == CLK_DIV_8) { 655 + if (ssc_depth > 3) 656 + ssc_depth -= 3; 657 + else 658 + ssc_depth = RTS5228_SSC_DEPTH_8M; 659 + } 660 + } else { 661 + ssc_depth = 0; 662 + } 663 + pcr_dbg(pcr, "ssc_depth = %d\n", ssc_depth); 664 + 665 + rtsx_pci_init_cmd(pcr); 666 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CLK_CTL, 667 + CLK_LOW_FREQ, CLK_LOW_FREQ); 668 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CLK_DIV, 669 + 0xFF, (div << 4) | mcu_cnt); 670 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL1, SSC_RSTB, 0); 671 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 672 + SSC_DEPTH_MASK, ssc_depth); 673 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_DIV_N_0, 0xFF, n); 674 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL1, SSC_RSTB, SSC_RSTB); 675 + if (vpclk) { 676 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD_VPCLK0_CTL, 677 + PHASE_NOT_RESET, 0); 678 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD_VPCLK1_CTL, 679 + PHASE_NOT_RESET, 0); 680 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD_VPCLK0_CTL, 681 + PHASE_NOT_RESET, PHASE_NOT_RESET); 682 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD_VPCLK1_CTL, 683 + PHASE_NOT_RESET, PHASE_NOT_RESET); 684 + } 685 + 686 + err = rtsx_pci_send_cmd(pcr, 2000); 687 + if (err < 0) 688 + return err; 689 + 690 + /* Wait SSC clock stable */ 691 + udelay(SSC_CLOCK_STABLE_WAIT); 692 + err = rtsx_pci_write_register(pcr, CLK_CTL, CLK_LOW_FREQ, 0); 693 + if (err < 0) 694 + return err; 695 + 696 + pcr->cur_clock = clk; 697 + return 0; 698 + 699 + } 700 + 701 + void rts5228_init_params(struct rtsx_pcr *pcr) 702 + { 703 + struct rtsx_cr_option *option = &pcr->option; 704 + struct rtsx_hw_param *hw_param = &pcr->hw_param; 705 + 706 + pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104; 707 + pcr->num_slots = 1; 708 + pcr->ops = &rts5228_pcr_ops; 709 + 710 + pcr->flags = 0; 711 + pcr->card_drive_sel = RTSX_CARD_DRIVE_DEFAULT; 712 + pcr->sd30_drive_sel_1v8 = CFG_DRIVER_TYPE_B; 713 + pcr->sd30_drive_sel_3v3 = CFG_DRIVER_TYPE_B; 714 + pcr->aspm_en = ASPM_L1_EN; 715 + pcr->tx_initial_phase = SET_CLOCK_PHASE(28, 27, 11); 716 + pcr->rx_initial_phase = SET_CLOCK_PHASE(24, 6, 5); 717 + 718 + pcr->ic_version = rts5228_get_ic_version(pcr); 719 + pcr->sd_pull_ctl_enable_tbl = rts5228_sd_pull_ctl_enable_tbl; 720 + pcr->sd_pull_ctl_disable_tbl = rts5228_sd_pull_ctl_disable_tbl; 721 + 722 + pcr->reg_pm_ctrl3 = RTS5228_AUTOLOAD_CFG3; 723 + 724 + option->dev_flags = (LTR_L1SS_PWR_GATE_CHECK_CARD_EN 725 + | LTR_L1SS_PWR_GATE_EN); 726 + option->ltr_en = true; 727 + 728 + /* init latency of active, idle, L1OFF to 60us, 300us, 3ms */ 729 + option->ltr_active_latency = LTR_ACTIVE_LATENCY_DEF; 730 + option->ltr_idle_latency = LTR_IDLE_LATENCY_DEF; 731 + option->ltr_l1off_latency = LTR_L1OFF_LATENCY_DEF; 732 + option->l1_snooze_delay = L1_SNOOZE_DELAY_DEF; 733 + option->ltr_l1off_sspwrgate = 0x7F; 734 + option->ltr_l1off_snooze_sspwrgate = 0x78; 735 + 736 + option->ocp_en = 1; 737 + hw_param->interrupt_en |= SD_OC_INT_EN; 738 + hw_param->ocp_glitch = SD_OCP_GLITCH_800U; 739 + option->sd_800mA_ocp_thd = RTS5228_LDO1_OCP_THD_930; 740 + }
+168
drivers/misc/cardreader/rts5228.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* Driver for Realtek PCI-Express card reader 3 + * 4 + * Copyright(c) 2018-2019 Realtek Semiconductor Corp. All rights reserved. 5 + * 6 + * Author: 7 + * Ricky WU <ricky_wu@realtek.com> 8 + * Rui FENG <rui_feng@realsil.com.cn> 9 + * Wei WANG <wei_wang@realsil.com.cn> 10 + */ 11 + #ifndef RTS5228_H 12 + #define RTS5228_H 13 + 14 + 15 + #define RTS5228_AUTOLOAD_CFG0 0xFF7B 16 + #define RTS5228_AUTOLOAD_CFG1 0xFF7C 17 + #define RTS5228_AUTOLOAD_CFG2 0xFF7D 18 + #define RTS5228_AUTOLOAD_CFG3 0xFF7E 19 + #define RTS5228_AUTOLOAD_CFG4 0xFF7F 20 + 21 + #define RTS5228_REG_VREF 0xFE97 22 + #define RTS5228_PWD_SUSPND_EN (1 << 4) 23 + 24 + #define RTS5228_PAD_H3L1 0xFF79 25 + #define PAD_GPIO_H3L1 (1 << 3) 26 + 27 + /* SSC_CTL2 0xFC12 */ 28 + #define RTS5228_SSC_DEPTH_MASK 0x07 29 + #define RTS5228_SSC_DEPTH_DISALBE 0x00 30 + #define RTS5228_SSC_DEPTH_8M 0x01 31 + #define RTS5228_SSC_DEPTH_4M 0x02 32 + #define RTS5228_SSC_DEPTH_2M 0x03 33 + #define RTS5228_SSC_DEPTH_1M 0x04 34 + #define RTS5228_SSC_DEPTH_512K 0x05 35 + #define RTS5228_SSC_DEPTH_256K 0x06 36 + #define RTS5228_SSC_DEPTH_128K 0x07 37 + 38 + /* DMACTL 0xFE2C */ 39 + #define RTS5228_DMA_PACK_SIZE_MASK 0xF0 40 + 41 + #define RTS5228_REG_LDO12_CFG 0xFF6E 42 + #define RTS5228_LDO12_VO_TUNE_MASK (0x07<<1) 43 + #define RTS5228_LDO12_100 (0x00<<1) 44 + #define RTS5228_LDO12_105 (0x01<<1) 45 + #define RTS5228_LDO12_110 (0x02<<1) 46 + #define RTS5228_LDO12_115 (0x03<<1) 47 + #define RTS5228_LDO12_120 (0x04<<1) 48 + #define RTS5228_LDO12_125 (0x05<<1) 49 + #define RTS5228_LDO12_130 (0x06<<1) 50 + #define RTS5228_LDO12_135 (0x07<<1) 51 + #define RTS5228_REG_PWD_LDO12 (0x01<<0) 52 + 53 + #define RTS5228_REG_LDO12_L12 0xFF6F 54 + #define RTS5228_LDO12_L12_MASK (0x07<<4) 55 + #define RTS5228_LDO12_L12_120 (0x04<<4) 56 + 57 + /* LDO control register */ 58 + #define RTS5228_CARD_PWR_CTL 0xFD50 59 + #define RTS5228_PUPDC (0x01<<5) 60 + 61 + #define RTS5228_LDO1233318_POW_CTL 0xFF70 62 + #define RTS5228_LDO3318_POWERON (0x01<<3) 63 + #define RTS5228_LDO1_POWEROFF (0x00<<0) 64 + #define RTS5228_LDO1_SOFTSTART (0x01<<0) 65 + #define RTS5228_LDO1_FULLON (0x03<<0) 66 + #define RTS5228_LDO1_POWERON_MASK (0x03<<0) 67 + #define RTS5228_LDO_POWERON_MASK (0x0F<<0) 68 + 69 + #define RTS5228_DV3318_CFG 0xFF71 70 + #define RTS5228_DV3318_TUNE_MASK (0x07<<4) 71 + #define RTS5228_DV3318_17 (0x00<<4) 72 + #define RTS5228_DV3318_1V75 (0x01<<4) 73 + #define RTS5228_DV3318_18 (0x02<<4) 74 + #define RTS5228_DV3318_1V85 (0x03<<4) 75 + #define RTS5228_DV3318_19 (0x04<<4) 76 + #define RTS5228_DV3318_33 (0x07<<4) 77 + #define RTS5228_DV3318_SR_MASK (0x03<<2) 78 + #define RTS5228_DV3318_SR_0 (0x00<<2) 79 + #define RTS5228_DV3318_SR_250 (0x01<<2) 80 + #define RTS5228_DV3318_SR_500 (0x02<<2) 81 + #define RTS5228_DV3318_SR_1000 (0x03<<2) 82 + 83 + #define RTS5228_LDO1_CFG0 0xFF72 84 + #define RTS5228_LDO1_OCP_THD_MASK (0x07<<5) 85 + #define RTS5228_LDO1_OCP_EN (0x01<<4) 86 + #define RTS5228_LDO1_OCP_LMT_THD_MASK (0x03<<2) 87 + #define RTS5228_LDO1_OCP_LMT_EN (0x01<<1) 88 + 89 + #define RTS5228_LDO1_OCP_THD_730 (0x00<<5) 90 + #define RTS5228_LDO1_OCP_THD_780 (0x01<<5) 91 + #define RTS5228_LDO1_OCP_THD_860 (0x02<<5) 92 + #define RTS5228_LDO1_OCP_THD_930 (0x03<<5) 93 + #define RTS5228_LDO1_OCP_THD_1000 (0x04<<5) 94 + #define RTS5228_LDO1_OCP_THD_1070 (0x05<<5) 95 + #define RTS5228_LDO1_OCP_THD_1140 (0x06<<5) 96 + #define RTS5228_LDO1_OCP_THD_1220 (0x07<<5) 97 + 98 + #define RTS5228_LDO1_LMT_THD_450 (0x00<<2) 99 + #define RTS5228_LDO1_LMT_THD_1000 (0x01<<2) 100 + #define RTS5228_LDO1_LMT_THD_1500 (0x02<<2) 101 + #define RTS5228_LDO1_LMT_THD_2000 (0x03<<2) 102 + 103 + #define RTS5228_LDO1_CFG1 0xFF73 104 + #define RTS5228_LDO1_SR_TIME_MASK (0x03<<6) 105 + #define RTS5228_LDO1_SR_0_0 (0x00<<6) 106 + #define RTS5228_LDO1_SR_0_25 (0x01<<6) 107 + #define RTS5228_LDO1_SR_0_5 (0x02<<6) 108 + #define RTS5228_LDO1_SR_1_0 (0x03<<6) 109 + #define RTS5228_LDO1_TUNE_MASK (0x07<<1) 110 + #define RTS5228_LDO1_18 (0x05<<1) 111 + #define RTS5228_LDO1_33 (0x07<<1) 112 + #define RTS5228_LDO1_PWD_MASK (0x01<<0) 113 + 114 + #define RTS5228_AUXCLK_GAT_CTL 0xFF74 115 + 116 + #define RTS5228_REG_RREF_CTL_0 0xFF75 117 + #define RTS5228_FORCE_RREF_EXTL (0x01<<7) 118 + #define RTS5228_REG_BG33_MASK (0x07<<0) 119 + #define RTS5228_RREF_12_1V (0x04<<0) 120 + #define RTS5228_RREF_12_3V (0x05<<0) 121 + 122 + #define RTS5228_REG_RREF_CTL_1 0xFF76 123 + 124 + #define RTS5228_REG_RREF_CTL_2 0xFF77 125 + #define RTS5228_TEST_INTL_RREF (0x01<<7) 126 + #define RTS5228_DGLCH_TIME_MASK (0x03<<5) 127 + #define RTS5228_DGLCH_TIME_50 (0x00<<5) 128 + #define RTS5228_DGLCH_TIME_75 (0x01<<5) 129 + #define RTS5228_DGLCH_TIME_100 (0x02<<5) 130 + #define RTS5228_DGLCH_TIME_125 (0x03<<5) 131 + #define RTS5228_REG_REXT_TUNE_MASK (0x1F<<0) 132 + 133 + #define RTS5228_REG_PME_FORCE_CTL 0xFF78 134 + #define FORCE_PM_CONTROL 0x20 135 + #define FORCE_PM_VALUE 0x10 136 + 137 + 138 + /* Single LUN, support SD */ 139 + #define DEFAULT_SINGLE 0 140 + #define SD_LUN 1 141 + 142 + 143 + /* For Change_FPGA_SSCClock Function */ 144 + #define MULTIPLY_BY_1 0x00 145 + #define MULTIPLY_BY_2 0x01 146 + #define MULTIPLY_BY_3 0x02 147 + #define MULTIPLY_BY_4 0x03 148 + #define MULTIPLY_BY_5 0x04 149 + #define MULTIPLY_BY_6 0x05 150 + #define MULTIPLY_BY_7 0x06 151 + #define MULTIPLY_BY_8 0x07 152 + #define MULTIPLY_BY_9 0x08 153 + #define MULTIPLY_BY_10 0x09 154 + 155 + #define DIVIDE_BY_2 0x01 156 + #define DIVIDE_BY_3 0x02 157 + #define DIVIDE_BY_4 0x03 158 + #define DIVIDE_BY_5 0x04 159 + #define DIVIDE_BY_6 0x05 160 + #define DIVIDE_BY_7 0x06 161 + #define DIVIDE_BY_8 0x07 162 + #define DIVIDE_BY_9 0x08 163 + #define DIVIDE_BY_10 0x09 164 + 165 + int rts5228_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, 166 + u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk); 167 + 168 + #endif /* RTS5228_H */
+58 -31
drivers/misc/cardreader/rtsx_pcr.c
··· 23 23 24 24 #include "rtsx_pcr.h" 25 25 #include "rts5261.h" 26 + #include "rts5228.h" 26 27 27 28 static bool msi_en = true; 28 29 module_param(msi_en, bool, S_IRUGO | S_IWUSR); ··· 51 50 { PCI_DEVICE(0x10EC, 0x525A), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 52 51 { PCI_DEVICE(0x10EC, 0x5260), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 53 52 { PCI_DEVICE(0x10EC, 0x5261), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 53 + { PCI_DEVICE(0x10EC, 0x5228), PCI_CLASS_OTHERS << 16, 0xFF0000 }, 54 54 { 0, } 55 55 }; 56 56 ··· 208 206 int err, i, finished = 0; 209 207 u8 tmp; 210 208 211 - rtsx_pci_init_cmd(pcr); 212 - 213 - rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYDATA0, 0xFF, (u8)val); 214 - rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYDATA1, 0xFF, (u8)(val >> 8)); 215 - rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYADDR, 0xFF, addr); 216 - rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYRWCTL, 0xFF, 0x81); 217 - 218 - err = rtsx_pci_send_cmd(pcr, 100); 219 - if (err < 0) 220 - return err; 209 + rtsx_pci_write_register(pcr, PHYDATA0, 0xFF, (u8)val); 210 + rtsx_pci_write_register(pcr, PHYDATA1, 0xFF, (u8)(val >> 8)); 211 + rtsx_pci_write_register(pcr, PHYADDR, 0xFF, addr); 212 + rtsx_pci_write_register(pcr, PHYRWCTL, 0xFF, 0x81); 221 213 222 214 for (i = 0; i < 100000; i++) { 223 215 err = rtsx_pci_read_register(pcr, PHYRWCTL, &tmp); ··· 243 247 { 244 248 int err, i, finished = 0; 245 249 u16 data; 246 - u8 *ptr, tmp; 250 + u8 tmp, val1, val2; 247 251 248 - rtsx_pci_init_cmd(pcr); 249 - 250 - rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYADDR, 0xFF, addr); 251 - rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYRWCTL, 0xFF, 0x80); 252 - 253 - err = rtsx_pci_send_cmd(pcr, 100); 254 - if (err < 0) 255 - return err; 252 + rtsx_pci_write_register(pcr, PHYADDR, 0xFF, addr); 253 + rtsx_pci_write_register(pcr, PHYRWCTL, 0xFF, 0x80); 256 254 257 255 for (i = 0; i < 100000; i++) { 258 256 err = rtsx_pci_read_register(pcr, PHYRWCTL, &tmp); ··· 262 272 if (!finished) 263 273 return -ETIMEDOUT; 264 274 265 - rtsx_pci_init_cmd(pcr); 266 - 267 - rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA0, 0, 0); 268 - rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA1, 0, 0); 269 - 270 - err = rtsx_pci_send_cmd(pcr, 100); 271 - if (err < 0) 272 - return err; 273 - 274 - ptr = rtsx_pci_get_cmd_data(pcr); 275 - data = ((u16)ptr[1] << 8) | ptr[0]; 275 + rtsx_pci_read_register(pcr, PHYDATA0, &val1); 276 + rtsx_pci_read_register(pcr, PHYDATA1, &val2); 277 + data = val1 | (val2 << 8); 276 278 277 279 if (val) 278 280 *val = data; ··· 399 417 if (end) 400 418 option |= RTSX_SG_END; 401 419 402 - if (PCI_PID(pcr) == PID_5261) { 420 + if ((PCI_PID(pcr) == PID_5261) || (PCI_PID(pcr) == PID_5228)) { 403 421 if (len > 0xFFFF) 404 422 val = ((u64)addr << 32) | (((u64)len & 0xFFFF) << 16) 405 423 | (((u64)len >> 16) << 6) | option; ··· 704 722 705 723 if (PCI_PID(pcr) == PID_5261) 706 724 return rts5261_pci_switch_clock(pcr, card_clock, 725 + ssc_depth, initial_mode, double_clk, vpclk); 726 + if (PCI_PID(pcr) == PID_5228) 727 + return rts5228_pci_switch_clock(pcr, card_clock, 707 728 ssc_depth, initial_mode, double_clk, vpclk); 708 729 709 730 if (initial_mode) { ··· 1187 1202 } 1188 1203 } 1189 1204 1205 + void rtsx_pci_enable_oobs_polling(struct rtsx_pcr *pcr) 1206 + { 1207 + u16 val; 1208 + 1209 + if ((PCI_PID(pcr) != PID_525A) && (PCI_PID(pcr) != PID_5260)) { 1210 + rtsx_pci_read_phy_register(pcr, 0x01, &val); 1211 + val |= 1<<9; 1212 + rtsx_pci_write_phy_register(pcr, 0x01, val); 1213 + } 1214 + rtsx_pci_write_register(pcr, REG_CFG_OOBS_OFF_TIMER, 0xFF, 0x32); 1215 + rtsx_pci_write_register(pcr, REG_CFG_OOBS_ON_TIMER, 0xFF, 0x05); 1216 + rtsx_pci_write_register(pcr, REG_CFG_VCM_ON_TIMER, 0xFF, 0x83); 1217 + rtsx_pci_write_register(pcr, REG_CFG_OOBS_POLLING, 0xFF, 0xDE); 1218 + 1219 + } 1220 + 1221 + void rtsx_pci_disable_oobs_polling(struct rtsx_pcr *pcr) 1222 + { 1223 + u16 val; 1224 + 1225 + if ((PCI_PID(pcr) != PID_525A) && (PCI_PID(pcr) != PID_5260)) { 1226 + rtsx_pci_read_phy_register(pcr, 0x01, &val); 1227 + val &= ~(1<<9); 1228 + rtsx_pci_write_phy_register(pcr, 0x01, val); 1229 + } 1230 + rtsx_pci_write_register(pcr, REG_CFG_VCM_ON_TIMER, 0xFF, 0x03); 1231 + rtsx_pci_write_register(pcr, REG_CFG_OOBS_POLLING, 0xFF, 0x00); 1232 + 1233 + } 1234 + 1190 1235 int rtsx_sd_power_off_card3v3(struct rtsx_pcr *pcr) 1191 1236 { 1192 1237 rtsx_pci_write_register(pcr, CARD_CLK_EN, SD_CLK_EN | ··· 1247 1232 static int rtsx_pci_init_hw(struct rtsx_pcr *pcr) 1248 1233 { 1249 1234 int err; 1235 + 1236 + if (PCI_PID(pcr) == PID_5228) 1237 + rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG1, RTS5228_LDO1_SR_TIME_MASK, 1238 + RTS5228_LDO1_SR_0_5); 1250 1239 1251 1240 pcr->pcie_cap = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP); 1252 1241 rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr); ··· 1299 1280 if (PCI_PID(pcr) == PID_5261) 1300 1281 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 0xFF, 1301 1282 RTS5261_SSC_DEPTH_2M); 1283 + else if (PCI_PID(pcr) == PID_5228) 1284 + rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 0xFF, 1285 + RTS5228_SSC_DEPTH_2M); 1302 1286 else 1303 1287 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 0xFF, 0x12); 1304 1288 ··· 1336 1314 case PID_525A: 1337 1315 case PID_5260: 1338 1316 case PID_5261: 1317 + case PID_5228: 1339 1318 rtsx_pci_write_register(pcr, PM_CLK_FORCE_CTL, 1, 1); 1340 1319 break; 1341 1320 default: ··· 1423 1400 1424 1401 case 0x5261: 1425 1402 rts5261_init_params(pcr); 1403 + break; 1404 + 1405 + case 0x5228: 1406 + rts5228_init_params(pcr); 1426 1407 break; 1427 1408 } 1428 1409
+5
drivers/misc/cardreader/rtsx_pcr.h
··· 53 53 void rtl8411b_init_params(struct rtsx_pcr *pcr); 54 54 void rts5260_init_params(struct rtsx_pcr *pcr); 55 55 void rts5261_init_params(struct rtsx_pcr *pcr); 56 + void rts5228_init_params(struct rtsx_pcr *pcr); 56 57 57 58 static inline u8 map_sd_drive(int idx) 58 59 { ··· 71 70 #define rts5209_vendor_setting1_valid(reg) (!((reg) & 0x80)) 72 71 #define rts5209_vendor_setting2_valid(reg) ((reg) & 0x80) 73 72 73 + #define rtsx_check_mmc_support(reg) ((reg) & 0x10) 74 + #define rtsx_reg_to_rtd3(reg) ((reg) & 0x02) 74 75 #define rtsx_reg_to_aspm(reg) (((reg) >> 28) & 0x03) 75 76 #define rtsx_reg_to_sd30_drive_sel_1v8(reg) (((reg) >> 26) & 0x03) 76 77 #define rtsx_reg_to_sd30_drive_sel_3v3(reg) (((reg) >> 5) & 0x03) ··· 103 100 void rtsx_pci_enable_ocp(struct rtsx_pcr *pcr); 104 101 int rtsx_pci_get_ocpstat(struct rtsx_pcr *pcr, u8 *val); 105 102 void rtsx_pci_clear_ocpstat(struct rtsx_pcr *pcr); 103 + void rtsx_pci_enable_oobs_polling(struct rtsx_pcr *pcr); 104 + void rtsx_pci_disable_oobs_polling(struct rtsx_pcr *pcr); 106 105 int rtsx_sd_power_off_card3v3(struct rtsx_pcr *pcr); 107 106 int rtsx_ms_power_off_card3v3(struct rtsx_pcr *pcr); 108 107
+2
drivers/mmc/host/rtsx_pci_sdmmc.c
··· 1336 1336 mmc->caps |= MMC_CAP_1_8V_DDR; 1337 1337 if (pcr->extra_caps & EXTRA_CAPS_MMC_8BIT) 1338 1338 mmc->caps |= MMC_CAP_8_BIT_DATA; 1339 + if (pcr->extra_caps & EXTRA_CAPS_NO_MMC) 1340 + mmc->caps2 |= MMC_CAP2_NO_MMC; 1339 1341 } 1340 1342 1341 1343 static void realtek_init_host(struct realtek_pci_sdmmc *host)
+11
include/linux/rtsx_pci.h
··· 305 305 #define SD30_CLK_STOP_CFG0 0x01 306 306 #define REG_PRE_RW_MODE 0xFD70 307 307 #define EN_INFINITE_MODE 0x01 308 + #define REG_CRC_DUMMY_0 0xFD71 309 + #define CFG_SD_POW_AUTO_PD (1<<0) 308 310 309 311 #define SRCTL 0xFC13 310 312 ··· 601 599 602 600 #define ASPM_FORCE_CTL 0xFE57 603 601 #define FORCE_ASPM_CTL0 0x10 602 + #define FORCE_ASPM_CTL1 0x20 604 603 #define FORCE_ASPM_VAL_MASK 0x03 605 604 #define FORCE_ASPM_L1_EN 0x02 606 605 #define FORCE_ASPM_L0_EN 0x01 ··· 669 666 #define RESET_PIN_WAKE 0x02 670 667 #define PM_WAKE_EN 0x01 671 668 #define PM_CTRL4 0xFF47 669 + 670 + #define REG_CFG_OOBS_OFF_TIMER 0xFEA6 671 + #define REG_CFG_OOBS_ON_TIMER 0xFEA7 672 + #define REG_CFG_VCM_ON_TIMER 0xFEA8 673 + #define REG_CFG_OOBS_POLLING 0xFEA9 672 674 673 675 /* Memory mapping */ 674 676 #define SRAM_BASE 0xE600 ··· 1212 1204 #define EXTRA_CAPS_MMC_HSDDR (1 << 3) 1213 1205 #define EXTRA_CAPS_MMC_HS200 (1 << 4) 1214 1206 #define EXTRA_CAPS_MMC_8BIT (1 << 5) 1207 + #define EXTRA_CAPS_NO_MMC (1 << 7) 1215 1208 u32 extra_caps; 1216 1209 1217 1210 #define IC_VER_A 0 ··· 1251 1242 u8 dma_error_count; 1252 1243 u8 ocp_stat; 1253 1244 u8 ocp_stat2; 1245 + u8 rtd3_en; 1254 1246 }; 1255 1247 1256 1248 #define PID_524A 0x524A ··· 1260 1250 #define PID_525A 0x525A 1261 1251 #define PID_5260 0x5260 1262 1252 #define PID_5261 0x5261 1253 + #define PID_5228 0x5228 1263 1254 1264 1255 #define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid)) 1265 1256 #define PCI_VID(pcr) ((pcr)->pci->vendor)