rts5249.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /* Driver for Realtek PCI-Express card reader
  2. *
  3. * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2, or (at your option) any
  8. * later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * Author:
  19. * Wei WANG <wei_wang@realsil.com.cn>
  20. */
  21. #include <linux/module.h>
  22. #include <linux/delay.h>
  23. #include <linux/mfd/rtsx_pci.h>
  24. #include "rtsx_pcr.h"
  25. static u8 rts5249_get_ic_version(struct rtsx_pcr *pcr)
  26. {
  27. u8 val;
  28. rtsx_pci_read_register(pcr, DUMMY_REG_RESET_0, &val);
  29. return val & 0x0F;
  30. }
  31. static void rts5249_fill_driving(struct rtsx_pcr *pcr, u8 voltage)
  32. {
  33. u8 driving_3v3[4][3] = {
  34. {0x11, 0x11, 0x18},
  35. {0x55, 0x55, 0x5C},
  36. {0xFF, 0xFF, 0xFF},
  37. {0x96, 0x96, 0x96},
  38. };
  39. u8 driving_1v8[4][3] = {
  40. {0xC4, 0xC4, 0xC4},
  41. {0x3C, 0x3C, 0x3C},
  42. {0xFE, 0xFE, 0xFE},
  43. {0xB3, 0xB3, 0xB3},
  44. };
  45. u8 (*driving)[3], drive_sel;
  46. if (voltage == OUTPUT_3V3) {
  47. driving = driving_3v3;
  48. drive_sel = pcr->sd30_drive_sel_3v3;
  49. } else {
  50. driving = driving_1v8;
  51. drive_sel = pcr->sd30_drive_sel_1v8;
  52. }
  53. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD30_CLK_DRIVE_SEL,
  54. 0xFF, driving[drive_sel][0]);
  55. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD30_CMD_DRIVE_SEL,
  56. 0xFF, driving[drive_sel][1]);
  57. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SD30_DAT_DRIVE_SEL,
  58. 0xFF, driving[drive_sel][2]);
  59. }
  60. static void rtsx_base_fetch_vendor_settings(struct rtsx_pcr *pcr)
  61. {
  62. u32 reg;
  63. rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG1, &reg);
  64. pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG1, reg);
  65. if (!rtsx_vendor_setting_valid(reg)) {
  66. pcr_dbg(pcr, "skip fetch vendor setting\n");
  67. return;
  68. }
  69. pcr->aspm_en = rtsx_reg_to_aspm(reg);
  70. pcr->sd30_drive_sel_1v8 = rtsx_reg_to_sd30_drive_sel_1v8(reg);
  71. pcr->card_drive_sel &= 0x3F;
  72. pcr->card_drive_sel |= rtsx_reg_to_card_drive_sel(reg);
  73. rtsx_pci_read_config_dword(pcr, PCR_SETTING_REG2, &reg);
  74. pcr_dbg(pcr, "Cfg 0x%x: 0x%x\n", PCR_SETTING_REG2, reg);
  75. pcr->sd30_drive_sel_3v3 = rtsx_reg_to_sd30_drive_sel_3v3(reg);
  76. if (rtsx_reg_check_reverse_socket(reg))
  77. pcr->flags |= PCR_REVERSE_SOCKET;
  78. }
  79. static void rtsx_base_force_power_down(struct rtsx_pcr *pcr, u8 pm_state)
  80. {
  81. /* Set relink_time to 0 */
  82. rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 1, 0xFF, 0);
  83. rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 2, 0xFF, 0);
  84. rtsx_pci_write_register(pcr, AUTOLOAD_CFG_BASE + 3, 0x01, 0);
  85. if (pm_state == HOST_ENTER_S3)
  86. rtsx_pci_write_register(pcr, pcr->reg_pm_ctrl3,
  87. D3_DELINK_MODE_EN, D3_DELINK_MODE_EN);
  88. rtsx_pci_write_register(pcr, FPDCTL, 0x03, 0x03);
  89. }
  90. static int rts5249_extra_init_hw(struct rtsx_pcr *pcr)
  91. {
  92. rtsx_pci_init_cmd(pcr);
  93. /* Rest L1SUB Config */
  94. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, L1SUB_CONFIG3, 0xFF, 0x00);
  95. /* Configure GPIO as output */
  96. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, GPIO_CTL, 0x02, 0x02);
  97. /* Reset ASPM state to default value */
  98. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, ASPM_FORCE_CTL, 0x3F, 0);
  99. /* Switch LDO3318 source from DV33 to card_3v3 */
  100. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_PWR_SEL, 0x03, 0x00);
  101. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, LDO_PWR_SEL, 0x03, 0x01);
  102. /* LED shine disabled, set initial shine cycle period */
  103. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, OLT_LED_CTL, 0x0F, 0x02);
  104. /* Configure driving */
  105. rts5249_fill_driving(pcr, OUTPUT_3V3);
  106. if (pcr->flags & PCR_REVERSE_SOCKET)
  107. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0xB0);
  108. else
  109. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PETXCFG, 0xB0, 0x80);
  110. return rtsx_pci_send_cmd(pcr, 100);
  111. }
  112. static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
  113. {
  114. int err;
  115. err = rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
  116. if (err < 0)
  117. return err;
  118. err = rtsx_pci_write_phy_register(pcr, PHY_REV,
  119. PHY_REV_RESV | PHY_REV_RXIDLE_LATCHED |
  120. PHY_REV_P1_EN | PHY_REV_RXIDLE_EN |
  121. PHY_REV_CLKREQ_TX_EN | PHY_REV_RX_PWST |
  122. PHY_REV_CLKREQ_DT_1_0 | PHY_REV_STOP_CLKRD |
  123. PHY_REV_STOP_CLKWR);
  124. if (err < 0)
  125. return err;
  126. msleep(1);
  127. err = rtsx_pci_write_phy_register(pcr, PHY_BPCR,
  128. PHY_BPCR_IBRXSEL | PHY_BPCR_IBTXSEL |
  129. PHY_BPCR_IB_FILTER | PHY_BPCR_CMIRROR_EN);
  130. if (err < 0)
  131. return err;
  132. err = rtsx_pci_write_phy_register(pcr, PHY_PCR,
  133. PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
  134. PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 |
  135. PHY_PCR_RSSI_EN | PHY_PCR_RX10K);
  136. if (err < 0)
  137. return err;
  138. err = rtsx_pci_write_phy_register(pcr, PHY_RCR2,
  139. PHY_RCR2_EMPHASE_EN | PHY_RCR2_NADJR |
  140. PHY_RCR2_CDR_SR_2 | PHY_RCR2_FREQSEL_12 |
  141. PHY_RCR2_CDR_SC_12P | PHY_RCR2_CALIB_LATE);
  142. if (err < 0)
  143. return err;
  144. err = rtsx_pci_write_phy_register(pcr, PHY_FLD4,
  145. PHY_FLD4_FLDEN_SEL | PHY_FLD4_REQ_REF |
  146. PHY_FLD4_RXAMP_OFF | PHY_FLD4_REQ_ADDA |
  147. PHY_FLD4_BER_COUNT | PHY_FLD4_BER_TIMER |
  148. PHY_FLD4_BER_CHK_EN);
  149. if (err < 0)
  150. return err;
  151. err = rtsx_pci_write_phy_register(pcr, PHY_RDR,
  152. PHY_RDR_RXDSEL_1_9 | PHY_SSC_AUTO_PWD);
  153. if (err < 0)
  154. return err;
  155. err = rtsx_pci_write_phy_register(pcr, PHY_RCR1,
  156. PHY_RCR1_ADP_TIME_4 | PHY_RCR1_VCO_COARSE);
  157. if (err < 0)
  158. return err;
  159. err = rtsx_pci_write_phy_register(pcr, PHY_FLD3,
  160. PHY_FLD3_TIMER_4 | PHY_FLD3_TIMER_6 |
  161. PHY_FLD3_RXDELINK);
  162. if (err < 0)
  163. return err;
  164. return rtsx_pci_write_phy_register(pcr, PHY_TUNE,
  165. PHY_TUNE_TUNEREF_1_0 | PHY_TUNE_VBGSEL_1252 |
  166. PHY_TUNE_SDBUS_33 | PHY_TUNE_TUNED18 |
  167. PHY_TUNE_TUNED12 | PHY_TUNE_TUNEA12);
  168. }
  169. static int rtsx_base_turn_on_led(struct rtsx_pcr *pcr)
  170. {
  171. return rtsx_pci_write_register(pcr, GPIO_CTL, 0x02, 0x02);
  172. }
  173. static int rtsx_base_turn_off_led(struct rtsx_pcr *pcr)
  174. {
  175. return rtsx_pci_write_register(pcr, GPIO_CTL, 0x02, 0x00);
  176. }
  177. static int rtsx_base_enable_auto_blink(struct rtsx_pcr *pcr)
  178. {
  179. return rtsx_pci_write_register(pcr, OLT_LED_CTL, 0x08, 0x08);
  180. }
  181. static int rtsx_base_disable_auto_blink(struct rtsx_pcr *pcr)
  182. {
  183. return rtsx_pci_write_register(pcr, OLT_LED_CTL, 0x08, 0x00);
  184. }
  185. static int rtsx_base_card_power_on(struct rtsx_pcr *pcr, int card)
  186. {
  187. int err;
  188. rtsx_pci_init_cmd(pcr);
  189. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_PWR_CTL,
  190. SD_POWER_MASK, SD_VCC_PARTIAL_POWER_ON);
  191. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWR_GATE_CTRL,
  192. LDO3318_PWR_MASK, 0x02);
  193. err = rtsx_pci_send_cmd(pcr, 100);
  194. if (err < 0)
  195. return err;
  196. msleep(5);
  197. rtsx_pci_init_cmd(pcr);
  198. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_PWR_CTL,
  199. SD_POWER_MASK, SD_VCC_POWER_ON);
  200. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWR_GATE_CTRL,
  201. LDO3318_PWR_MASK, 0x06);
  202. return rtsx_pci_send_cmd(pcr, 100);
  203. }
  204. static int rtsx_base_card_power_off(struct rtsx_pcr *pcr, int card)
  205. {
  206. rtsx_pci_init_cmd(pcr);
  207. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_PWR_CTL,
  208. SD_POWER_MASK, SD_POWER_OFF);
  209. rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PWR_GATE_CTRL,
  210. LDO3318_PWR_MASK, 0x00);
  211. return rtsx_pci_send_cmd(pcr, 100);
  212. }
  213. static int rtsx_base_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
  214. {
  215. int err;
  216. u16 append;
  217. switch (voltage) {
  218. case OUTPUT_3V3:
  219. err = rtsx_pci_update_phy(pcr, PHY_TUNE, PHY_TUNE_VOLTAGE_MASK,
  220. PHY_TUNE_VOLTAGE_3V3);
  221. if (err < 0)
  222. return err;
  223. break;
  224. case OUTPUT_1V8:
  225. append = PHY_TUNE_D18_1V8;
  226. if (CHK_PCI_PID(pcr, 0x5249)) {
  227. err = rtsx_pci_update_phy(pcr, PHY_BACR,
  228. PHY_BACR_BASIC_MASK, 0);
  229. if (err < 0)
  230. return err;
  231. append = PHY_TUNE_D18_1V7;
  232. }
  233. err = rtsx_pci_update_phy(pcr, PHY_TUNE, PHY_TUNE_VOLTAGE_MASK,
  234. append);
  235. if (err < 0)
  236. return err;
  237. break;
  238. default:
  239. pcr_dbg(pcr, "unknown output voltage %d\n", voltage);
  240. return -EINVAL;
  241. }
  242. /* set pad drive */
  243. rtsx_pci_init_cmd(pcr);
  244. rts5249_fill_driving(pcr, voltage);
  245. return rtsx_pci_send_cmd(pcr, 100);
  246. }
  247. static const struct pcr_ops rts5249_pcr_ops = {
  248. .fetch_vendor_settings = rtsx_base_fetch_vendor_settings,
  249. .extra_init_hw = rts5249_extra_init_hw,
  250. .optimize_phy = rts5249_optimize_phy,
  251. .turn_on_led = rtsx_base_turn_on_led,
  252. .turn_off_led = rtsx_base_turn_off_led,
  253. .enable_auto_blink = rtsx_base_enable_auto_blink,
  254. .disable_auto_blink = rtsx_base_disable_auto_blink,
  255. .card_power_on = rtsx_base_card_power_on,
  256. .card_power_off = rtsx_base_card_power_off,
  257. .switch_output_voltage = rtsx_base_switch_output_voltage,
  258. .force_power_down = rtsx_base_force_power_down,
  259. };
  260. /* SD Pull Control Enable:
  261. * SD_DAT[3:0] ==> pull up
  262. * SD_CD ==> pull up
  263. * SD_WP ==> pull up
  264. * SD_CMD ==> pull up
  265. * SD_CLK ==> pull down
  266. */
  267. static const u32 rts5249_sd_pull_ctl_enable_tbl[] = {
  268. RTSX_REG_PAIR(CARD_PULL_CTL1, 0x66),
  269. RTSX_REG_PAIR(CARD_PULL_CTL2, 0xAA),
  270. RTSX_REG_PAIR(CARD_PULL_CTL3, 0xE9),
  271. RTSX_REG_PAIR(CARD_PULL_CTL4, 0xAA),
  272. 0,
  273. };
  274. /* SD Pull Control Disable:
  275. * SD_DAT[3:0] ==> pull down
  276. * SD_CD ==> pull up
  277. * SD_WP ==> pull down
  278. * SD_CMD ==> pull down
  279. * SD_CLK ==> pull down
  280. */
  281. static const u32 rts5249_sd_pull_ctl_disable_tbl[] = {
  282. RTSX_REG_PAIR(CARD_PULL_CTL1, 0x66),
  283. RTSX_REG_PAIR(CARD_PULL_CTL2, 0x55),
  284. RTSX_REG_PAIR(CARD_PULL_CTL3, 0xD5),
  285. RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55),
  286. 0,
  287. };
  288. /* MS Pull Control Enable:
  289. * MS CD ==> pull up
  290. * others ==> pull down
  291. */
  292. static const u32 rts5249_ms_pull_ctl_enable_tbl[] = {
  293. RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55),
  294. RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55),
  295. RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15),
  296. 0,
  297. };
  298. /* MS Pull Control Disable:
  299. * MS CD ==> pull up
  300. * others ==> pull down
  301. */
  302. static const u32 rts5249_ms_pull_ctl_disable_tbl[] = {
  303. RTSX_REG_PAIR(CARD_PULL_CTL4, 0x55),
  304. RTSX_REG_PAIR(CARD_PULL_CTL5, 0x55),
  305. RTSX_REG_PAIR(CARD_PULL_CTL6, 0x15),
  306. 0,
  307. };
  308. void rts5249_init_params(struct rtsx_pcr *pcr)
  309. {
  310. pcr->extra_caps = EXTRA_CAPS_SD_SDR50 | EXTRA_CAPS_SD_SDR104;
  311. pcr->num_slots = 2;
  312. pcr->ops = &rts5249_pcr_ops;
  313. pcr->flags = 0;
  314. pcr->card_drive_sel = RTSX_CARD_DRIVE_DEFAULT;
  315. pcr->sd30_drive_sel_1v8 = CFG_DRIVER_TYPE_B;
  316. pcr->sd30_drive_sel_3v3 = CFG_DRIVER_TYPE_B;
  317. pcr->aspm_en = ASPM_L1_EN;
  318. pcr->tx_initial_phase = SET_CLOCK_PHASE(1, 29, 16);
  319. pcr->rx_initial_phase = SET_CLOCK_PHASE(24, 6, 5);
  320. pcr->ic_version = rts5249_get_ic_version(pcr);
  321. pcr->sd_pull_ctl_enable_tbl = rts5249_sd_pull_ctl_enable_tbl;
  322. pcr->sd_pull_ctl_disable_tbl = rts5249_sd_pull_ctl_disable_tbl;
  323. pcr->ms_pull_ctl_enable_tbl = rts5249_ms_pull_ctl_enable_tbl;
  324. pcr->ms_pull_ctl_disable_tbl = rts5249_ms_pull_ctl_disable_tbl;
  325. pcr->reg_pm_ctrl3 = PM_CTRL3;
  326. }
  327. static int rts524a_write_phy(struct rtsx_pcr *pcr, u8 addr, u16 val)
  328. {
  329. addr = addr & 0x80 ? (addr & 0x7F) | 0x40 : addr;
  330. return __rtsx_pci_write_phy_register(pcr, addr, val);
  331. }
  332. static int rts524a_read_phy(struct rtsx_pcr *pcr, u8 addr, u16 *val)
  333. {
  334. addr = addr & 0x80 ? (addr & 0x7F) | 0x40 : addr;
  335. return __rtsx_pci_read_phy_register(pcr, addr, val);
  336. }
  337. static int rts524a_optimize_phy(struct rtsx_pcr *pcr)
  338. {
  339. int err;
  340. err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
  341. D3_DELINK_MODE_EN, 0x00);
  342. if (err < 0)
  343. return err;
  344. rtsx_pci_write_phy_register(pcr, PHY_PCR,
  345. PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
  346. PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 | PHY_PCR_RSSI_EN);
  347. rtsx_pci_write_phy_register(pcr, PHY_SSCCR3,
  348. PHY_SSCCR3_STEP_IN | PHY_SSCCR3_CHECK_DELAY);
  349. if (is_version(pcr, 0x524A, IC_VER_A)) {
  350. rtsx_pci_write_phy_register(pcr, PHY_SSCCR3,
  351. PHY_SSCCR3_STEP_IN | PHY_SSCCR3_CHECK_DELAY);
  352. rtsx_pci_write_phy_register(pcr, PHY_SSCCR2,
  353. PHY_SSCCR2_PLL_NCODE | PHY_SSCCR2_TIME0 |
  354. PHY_SSCCR2_TIME2_WIDTH);
  355. rtsx_pci_write_phy_register(pcr, PHY_ANA1A,
  356. PHY_ANA1A_TXR_LOOPBACK | PHY_ANA1A_RXT_BIST |
  357. PHY_ANA1A_TXR_BIST | PHY_ANA1A_REV);
  358. rtsx_pci_write_phy_register(pcr, PHY_ANA1D,
  359. PHY_ANA1D_DEBUG_ADDR);
  360. rtsx_pci_write_phy_register(pcr, PHY_DIG1E,
  361. PHY_DIG1E_REV | PHY_DIG1E_D0_X_D1 |
  362. PHY_DIG1E_RX_ON_HOST | PHY_DIG1E_RCLK_REF_HOST |
  363. PHY_DIG1E_RCLK_TX_EN_KEEP |
  364. PHY_DIG1E_RCLK_TX_TERM_KEEP |
  365. PHY_DIG1E_RCLK_RX_EIDLE_ON | PHY_DIG1E_TX_TERM_KEEP |
  366. PHY_DIG1E_RX_TERM_KEEP | PHY_DIG1E_TX_EN_KEEP |
  367. PHY_DIG1E_RX_EN_KEEP);
  368. }
  369. rtsx_pci_write_phy_register(pcr, PHY_ANA08,
  370. PHY_ANA08_RX_EQ_DCGAIN | PHY_ANA08_SEL_RX_EN |
  371. PHY_ANA08_RX_EQ_VAL | PHY_ANA08_SCP | PHY_ANA08_SEL_IPI);
  372. return 0;
  373. }
  374. static int rts524a_extra_init_hw(struct rtsx_pcr *pcr)
  375. {
  376. rts5249_extra_init_hw(pcr);
  377. rtsx_pci_write_register(pcr, FUNC_FORCE_CTL,
  378. FORCE_ASPM_L1_EN, FORCE_ASPM_L1_EN);
  379. rtsx_pci_write_register(pcr, PM_EVENT_DEBUG, PME_DEBUG_0, PME_DEBUG_0);
  380. rtsx_pci_write_register(pcr, LDO_VCC_CFG1, LDO_VCC_LMT_EN,
  381. LDO_VCC_LMT_EN);
  382. rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL);
  383. if (is_version(pcr, 0x524A, IC_VER_A)) {
  384. rtsx_pci_write_register(pcr, LDO_DV18_CFG,
  385. LDO_DV18_SR_MASK, LDO_DV18_SR_DF);
  386. rtsx_pci_write_register(pcr, LDO_VCC_CFG1,
  387. LDO_VCC_REF_TUNE_MASK, LDO_VCC_REF_1V2);
  388. rtsx_pci_write_register(pcr, LDO_VIO_CFG,
  389. LDO_VIO_REF_TUNE_MASK, LDO_VIO_REF_1V2);
  390. rtsx_pci_write_register(pcr, LDO_VIO_CFG,
  391. LDO_VIO_SR_MASK, LDO_VIO_SR_DF);
  392. rtsx_pci_write_register(pcr, LDO_DV12S_CFG,
  393. LDO_REF12_TUNE_MASK, LDO_REF12_TUNE_DF);
  394. rtsx_pci_write_register(pcr, SD40_LDO_CTL1,
  395. SD40_VIO_TUNE_MASK, SD40_VIO_TUNE_1V7);
  396. }
  397. return 0;
  398. }
  399. static const struct pcr_ops rts524a_pcr_ops = {
  400. .write_phy = rts524a_write_phy,
  401. .read_phy = rts524a_read_phy,
  402. .fetch_vendor_settings = rtsx_base_fetch_vendor_settings,
  403. .extra_init_hw = rts524a_extra_init_hw,
  404. .optimize_phy = rts524a_optimize_phy,
  405. .turn_on_led = rtsx_base_turn_on_led,
  406. .turn_off_led = rtsx_base_turn_off_led,
  407. .enable_auto_blink = rtsx_base_enable_auto_blink,
  408. .disable_auto_blink = rtsx_base_disable_auto_blink,
  409. .card_power_on = rtsx_base_card_power_on,
  410. .card_power_off = rtsx_base_card_power_off,
  411. .switch_output_voltage = rtsx_base_switch_output_voltage,
  412. .force_power_down = rtsx_base_force_power_down,
  413. };
  414. void rts524a_init_params(struct rtsx_pcr *pcr)
  415. {
  416. rts5249_init_params(pcr);
  417. pcr->reg_pm_ctrl3 = RTS524A_PM_CTRL3;
  418. pcr->ops = &rts524a_pcr_ops;
  419. }
  420. static int rts525a_card_power_on(struct rtsx_pcr *pcr, int card)
  421. {
  422. rtsx_pci_write_register(pcr, LDO_VCC_CFG1,
  423. LDO_VCC_TUNE_MASK, LDO_VCC_3V3);
  424. return rtsx_base_card_power_on(pcr, card);
  425. }
  426. static int rts525a_switch_output_voltage(struct rtsx_pcr *pcr, u8 voltage)
  427. {
  428. switch (voltage) {
  429. case OUTPUT_3V3:
  430. rtsx_pci_write_register(pcr, LDO_CONFIG2,
  431. LDO_D3318_MASK, LDO_D3318_33V);
  432. rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8, 0);
  433. break;
  434. case OUTPUT_1V8:
  435. rtsx_pci_write_register(pcr, LDO_CONFIG2,
  436. LDO_D3318_MASK, LDO_D3318_18V);
  437. rtsx_pci_write_register(pcr, SD_PAD_CTL, SD_IO_USING_1V8,
  438. SD_IO_USING_1V8);
  439. break;
  440. default:
  441. return -EINVAL;
  442. }
  443. rtsx_pci_init_cmd(pcr);
  444. rts5249_fill_driving(pcr, voltage);
  445. return rtsx_pci_send_cmd(pcr, 100);
  446. }
  447. static int rts525a_optimize_phy(struct rtsx_pcr *pcr)
  448. {
  449. int err;
  450. err = rtsx_pci_write_register(pcr, RTS524A_PM_CTRL3,
  451. D3_DELINK_MODE_EN, 0x00);
  452. if (err < 0)
  453. return err;
  454. rtsx_pci_write_phy_register(pcr, _PHY_FLD0,
  455. _PHY_FLD0_CLK_REQ_20C | _PHY_FLD0_RX_IDLE_EN |
  456. _PHY_FLD0_BIT_ERR_RSTN | _PHY_FLD0_BER_COUNT |
  457. _PHY_FLD0_BER_TIMER | _PHY_FLD0_CHECK_EN);
  458. rtsx_pci_write_phy_register(pcr, _PHY_ANA03,
  459. _PHY_ANA03_TIMER_MAX | _PHY_ANA03_OOBS_DEB_EN |
  460. _PHY_CMU_DEBUG_EN);
  461. if (is_version(pcr, 0x525A, IC_VER_A))
  462. rtsx_pci_write_phy_register(pcr, _PHY_REV0,
  463. _PHY_REV0_FILTER_OUT | _PHY_REV0_CDR_BYPASS_PFD |
  464. _PHY_REV0_CDR_RX_IDLE_BYPASS);
  465. return 0;
  466. }
  467. static int rts525a_extra_init_hw(struct rtsx_pcr *pcr)
  468. {
  469. rts5249_extra_init_hw(pcr);
  470. rtsx_pci_write_register(pcr, PCLK_CTL, PCLK_MODE_SEL, PCLK_MODE_SEL);
  471. if (is_version(pcr, 0x525A, IC_VER_A)) {
  472. rtsx_pci_write_register(pcr, L1SUB_CONFIG2,
  473. L1SUB_AUTO_CFG, L1SUB_AUTO_CFG);
  474. rtsx_pci_write_register(pcr, RREF_CFG,
  475. RREF_VBGSEL_MASK, RREF_VBGSEL_1V25);
  476. rtsx_pci_write_register(pcr, LDO_VIO_CFG,
  477. LDO_VIO_TUNE_MASK, LDO_VIO_1V7);
  478. rtsx_pci_write_register(pcr, LDO_DV12S_CFG,
  479. LDO_D12_TUNE_MASK, LDO_D12_TUNE_DF);
  480. rtsx_pci_write_register(pcr, LDO_AV12S_CFG,
  481. LDO_AV12S_TUNE_MASK, LDO_AV12S_TUNE_DF);
  482. rtsx_pci_write_register(pcr, LDO_VCC_CFG0,
  483. LDO_VCC_LMTVTH_MASK, LDO_VCC_LMTVTH_2A);
  484. rtsx_pci_write_register(pcr, OOBS_CONFIG,
  485. OOBS_AUTOK_DIS | OOBS_VAL_MASK, 0x89);
  486. }
  487. return 0;
  488. }
  489. static const struct pcr_ops rts525a_pcr_ops = {
  490. .fetch_vendor_settings = rtsx_base_fetch_vendor_settings,
  491. .extra_init_hw = rts525a_extra_init_hw,
  492. .optimize_phy = rts525a_optimize_phy,
  493. .turn_on_led = rtsx_base_turn_on_led,
  494. .turn_off_led = rtsx_base_turn_off_led,
  495. .enable_auto_blink = rtsx_base_enable_auto_blink,
  496. .disable_auto_blink = rtsx_base_disable_auto_blink,
  497. .card_power_on = rts525a_card_power_on,
  498. .card_power_off = rtsx_base_card_power_off,
  499. .switch_output_voltage = rts525a_switch_output_voltage,
  500. .force_power_down = rtsx_base_force_power_down,
  501. };
  502. void rts525a_init_params(struct rtsx_pcr *pcr)
  503. {
  504. rts5249_init_params(pcr);
  505. pcr->reg_pm_ctrl3 = RTS524A_PM_CTRL3;
  506. pcr->ops = &rts525a_pcr_ops;
  507. }