18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* Driver for Realtek PCI-Express card reader 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright(c) 2018-2019 Realtek Semiconductor Corp. All rights reserved. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Author: 78c2ecf20Sopenharmony_ci * Rui FENG <rui_feng@realsil.com.cn> 88c2ecf20Sopenharmony_ci * Wei WANG <wei_wang@realsil.com.cn> 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#ifndef RTS5261_H 118c2ecf20Sopenharmony_ci#define RTS5261_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/*New add*/ 148c2ecf20Sopenharmony_ci#define rts5261_vendor_setting_valid(reg) ((reg) & 0x010000) 158c2ecf20Sopenharmony_ci#define rts5261_reg_to_aspm(reg) (((reg) >> 28) ^ 0x03) 168c2ecf20Sopenharmony_ci#define rts5261_reg_check_reverse_socket(reg) ((reg) & 0x04) 178c2ecf20Sopenharmony_ci#define rts5261_reg_to_card_drive_sel(reg) ((((reg) >> 6) & 0x01) << 6) 188c2ecf20Sopenharmony_ci#define rts5261_reg_to_sd30_drive_sel_1v8(reg) (((reg) >> 22) ^ 0x03) 198c2ecf20Sopenharmony_ci#define rts5261_reg_to_sd30_drive_sel_3v3(reg) (((reg) >> 16) ^ 0x03) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define RTS5261_AUTOLOAD_CFG0 0xFF7B 238c2ecf20Sopenharmony_ci#define RTS5261_AUTOLOAD_CFG1 0xFF7C 248c2ecf20Sopenharmony_ci#define RTS5261_AUTOLOAD_CFG2 0xFF7D 258c2ecf20Sopenharmony_ci#define RTS5261_AUTOLOAD_CFG3 0xFF7E 268c2ecf20Sopenharmony_ci#define RTS5261_AUTOLOAD_CFG4 0xFF7F 278c2ecf20Sopenharmony_ci#define RTS5261_FORCE_PRSNT_LOW (1 << 6) 288c2ecf20Sopenharmony_ci#define RTS5261_AUX_CLK_16M_EN (1 << 5) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define RTS5261_REG_VREF 0xFE97 318c2ecf20Sopenharmony_ci#define RTS5261_PWD_SUSPND_EN (1 << 4) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define RTS5261_PAD_H3L1 0xFF79 348c2ecf20Sopenharmony_ci#define PAD_GPIO_H3L1 (1 << 3) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* SSC_CTL2 0xFC12 */ 378c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_MASK 0x07 388c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_DISALBE 0x00 398c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_8M 0x01 408c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_4M 0x02 418c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_2M 0x03 428c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_1M 0x04 438c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_512K 0x05 448c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_256K 0x06 458c2ecf20Sopenharmony_ci#define RTS5261_SSC_DEPTH_128K 0x07 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* efuse control register*/ 488c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_CTL 0xFC30 498c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_ENABLE 0x80 508c2ecf20Sopenharmony_ci/* EFUSE_MODE: 0=READ 1=PROGRAM */ 518c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_MODE_MASK 0x40 528c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_PROGRAM 0x40 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_ADDR 0xFC31 558c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_ADDR_MASK 0x3F 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_WRITE_DATA 0xFC32 588c2ecf20Sopenharmony_ci#define RTS5261_EFUSE_READ_DATA 0xFC34 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* DMACTL 0xFE2C */ 618c2ecf20Sopenharmony_ci#define RTS5261_DMA_PACK_SIZE_MASK 0xF0 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* FW config info register */ 648c2ecf20Sopenharmony_ci#define RTS5261_FW_CFG_INFO0 0xFF50 658c2ecf20Sopenharmony_ci#define RTS5261_FW_EXPRESS_TEST_MASK (0x01<<0) 668c2ecf20Sopenharmony_ci#define RTS5261_FW_EA_MODE_MASK (0x01<<5) 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* FW config register */ 698c2ecf20Sopenharmony_ci#define RTS5261_FW_CFG0 0xFF54 708c2ecf20Sopenharmony_ci#define RTS5261_FW_ENTER_EXPRESS (0x01<<0) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#define RTS5261_FW_CFG1 0xFF55 738c2ecf20Sopenharmony_ci#define RTS5261_SYS_CLK_SEL_MCU_CLK (0x01<<7) 748c2ecf20Sopenharmony_ci#define RTS5261_CRC_CLK_SEL_MCU_CLK (0x01<<6) 758c2ecf20Sopenharmony_ci#define RTS5261_FAKE_MCU_CLOCK_GATING (0x01<<5) 768c2ecf20Sopenharmony_ci/*MCU_bus_mode_sel: 0=real 8051 1=fake mcu*/ 778c2ecf20Sopenharmony_ci#define RTS5261_MCU_BUS_SEL_MASK (0x01<<4) 788c2ecf20Sopenharmony_ci/*MCU_clock_sel:VerA 00=aux16M 01=aux400K 1x=REFCLK100M*/ 798c2ecf20Sopenharmony_ci/*MCU_clock_sel:VerB 00=aux400K 01=aux16M 10=REFCLK100M*/ 808c2ecf20Sopenharmony_ci#define RTS5261_MCU_CLOCK_SEL_MASK (0x03<<2) 818c2ecf20Sopenharmony_ci#define RTS5261_MCU_CLOCK_SEL_16M (0x01<<2) 828c2ecf20Sopenharmony_ci#define RTS5261_MCU_CLOCK_GATING (0x01<<1) 838c2ecf20Sopenharmony_ci#define RTS5261_DRIVER_ENABLE_FW (0x01<<0) 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* FW status register */ 868c2ecf20Sopenharmony_ci#define RTS5261_FW_STATUS 0xFF56 878c2ecf20Sopenharmony_ci#define RTS5261_EXPRESS_LINK_FAIL_MASK (0x01<<7) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* FW control register */ 908c2ecf20Sopenharmony_ci#define RTS5261_FW_CTL 0xFF5F 918c2ecf20Sopenharmony_ci#define RTS5261_INFORM_RTD3_COLD (0x01<<5) 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#define RTS5261_REG_FPDCTL 0xFF60 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define RTS5261_REG_LDO12_CFG 0xFF6E 968c2ecf20Sopenharmony_ci#define RTS5261_LDO12_VO_TUNE_MASK (0x07<<1) 978c2ecf20Sopenharmony_ci#define RTS5261_LDO12_115 (0x03<<1) 988c2ecf20Sopenharmony_ci#define RTS5261_LDO12_120 (0x04<<1) 998c2ecf20Sopenharmony_ci#define RTS5261_LDO12_125 (0x05<<1) 1008c2ecf20Sopenharmony_ci#define RTS5261_LDO12_130 (0x06<<1) 1018c2ecf20Sopenharmony_ci#define RTS5261_LDO12_135 (0x07<<1) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/* LDO control register */ 1048c2ecf20Sopenharmony_ci#define RTS5261_CARD_PWR_CTL 0xFD50 1058c2ecf20Sopenharmony_ci#define RTS5261_SD_CLK_ISO (0x01<<7) 1068c2ecf20Sopenharmony_ci#define RTS5261_PAD_SD_DAT_FW_CTRL (0x01<<6) 1078c2ecf20Sopenharmony_ci#define RTS5261_PUPDC (0x01<<5) 1088c2ecf20Sopenharmony_ci#define RTS5261_SD_CMD_ISO (0x01<<4) 1098c2ecf20Sopenharmony_ci#define RTS5261_SD_DAT_ISO_MASK (0x0F<<0) 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define RTS5261_LDO1233318_POW_CTL 0xFF70 1128c2ecf20Sopenharmony_ci#define RTS5261_LDO3318_POWERON (0x01<<3) 1138c2ecf20Sopenharmony_ci#define RTS5261_LDO3_POWERON (0x01<<2) 1148c2ecf20Sopenharmony_ci#define RTS5261_LDO2_POWERON (0x01<<1) 1158c2ecf20Sopenharmony_ci#define RTS5261_LDO1_POWERON (0x01<<0) 1168c2ecf20Sopenharmony_ci#define RTS5261_LDO_POWERON_MASK (0x0F<<0) 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#define RTS5261_DV3318_CFG 0xFF71 1198c2ecf20Sopenharmony_ci#define RTS5261_DV3318_TUNE_MASK (0x07<<4) 1208c2ecf20Sopenharmony_ci#define RTS5261_DV3318_18 (0x02<<4) 1218c2ecf20Sopenharmony_ci#define RTS5261_DV3318_19 (0x04<<4) 1228c2ecf20Sopenharmony_ci#define RTS5261_DV3318_33 (0x07<<4) 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#define RTS5261_LDO1_CFG0 0xFF72 1258c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_MASK (0x07<<5) 1268c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_EN (0x01<<4) 1278c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_LMT_THD_MASK (0x03<<2) 1288c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_LMT_EN (0x01<<1) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/* CRD6603-433 190319 request changed */ 1318c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_740 (0x00<<5) 1328c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_800 (0x01<<5) 1338c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_860 (0x02<<5) 1348c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_920 (0x03<<5) 1358c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_980 (0x04<<5) 1368c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_1040 (0x05<<5) 1378c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_1100 (0x06<<5) 1388c2ecf20Sopenharmony_ci#define RTS5261_LDO1_OCP_THD_1160 (0x07<<5) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#define RTS5261_LDO1_LMT_THD_450 (0x00<<2) 1418c2ecf20Sopenharmony_ci#define RTS5261_LDO1_LMT_THD_1000 (0x01<<2) 1428c2ecf20Sopenharmony_ci#define RTS5261_LDO1_LMT_THD_1500 (0x02<<2) 1438c2ecf20Sopenharmony_ci#define RTS5261_LDO1_LMT_THD_2000 (0x03<<2) 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#define RTS5261_LDO1_CFG1 0xFF73 1468c2ecf20Sopenharmony_ci#define RTS5261_LDO1_TUNE_MASK (0x07<<1) 1478c2ecf20Sopenharmony_ci#define RTS5261_LDO1_18 (0x05<<1) 1488c2ecf20Sopenharmony_ci#define RTS5261_LDO1_33 (0x07<<1) 1498c2ecf20Sopenharmony_ci#define RTS5261_LDO1_PWD_MASK (0x01<<0) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#define RTS5261_LDO2_CFG0 0xFF74 1528c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_MASK (0x07<<5) 1538c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_EN (0x01<<4) 1548c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_LMT_THD_MASK (0x03<<2) 1558c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_LMT_EN (0x01<<1) 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_620 (0x00<<5) 1588c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_650 (0x01<<5) 1598c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_680 (0x02<<5) 1608c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_720 (0x03<<5) 1618c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_750 (0x04<<5) 1628c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_780 (0x05<<5) 1638c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_810 (0x06<<5) 1648c2ecf20Sopenharmony_ci#define RTS5261_LDO2_OCP_THD_840 (0x07<<5) 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci#define RTS5261_LDO2_CFG1 0xFF75 1678c2ecf20Sopenharmony_ci#define RTS5261_LDO2_TUNE_MASK (0x07<<1) 1688c2ecf20Sopenharmony_ci#define RTS5261_LDO2_18 (0x05<<1) 1698c2ecf20Sopenharmony_ci#define RTS5261_LDO2_33 (0x07<<1) 1708c2ecf20Sopenharmony_ci#define RTS5261_LDO2_PWD_MASK (0x01<<0) 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci#define RTS5261_LDO3_CFG0 0xFF76 1738c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_MASK (0x07<<5) 1748c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_EN (0x01<<4) 1758c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_LMT_THD_MASK (0x03<<2) 1768c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_LMT_EN (0x01<<1) 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_620 (0x00<<5) 1798c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_650 (0x01<<5) 1808c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_680 (0x02<<5) 1818c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_720 (0x03<<5) 1828c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_750 (0x04<<5) 1838c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_780 (0x05<<5) 1848c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_810 (0x06<<5) 1858c2ecf20Sopenharmony_ci#define RTS5261_LDO3_OCP_THD_840 (0x07<<5) 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#define RTS5261_LDO3_CFG1 0xFF77 1888c2ecf20Sopenharmony_ci#define RTS5261_LDO3_TUNE_MASK (0x07<<1) 1898c2ecf20Sopenharmony_ci#define RTS5261_LDO3_18 (0x05<<1) 1908c2ecf20Sopenharmony_ci#define RTS5261_LDO3_33 (0x07<<1) 1918c2ecf20Sopenharmony_ci#define RTS5261_LDO3_PWD_MASK (0x01<<0) 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define RTS5261_REG_PME_FORCE_CTL 0xFF78 1948c2ecf20Sopenharmony_ci#define FORCE_PM_CONTROL 0x20 1958c2ecf20Sopenharmony_ci#define FORCE_PM_VALUE 0x10 1968c2ecf20Sopenharmony_ci#define REG_EFUSE_BYPASS 0x08 1978c2ecf20Sopenharmony_ci#define REG_EFUSE_POR 0x04 1988c2ecf20Sopenharmony_ci#define REG_EFUSE_POWER_MASK 0x03 1998c2ecf20Sopenharmony_ci#define REG_EFUSE_POWERON 0x03 2008c2ecf20Sopenharmony_ci#define REG_EFUSE_POWEROFF 0x00 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/* Single LUN, support SD/SD EXPRESS */ 2048c2ecf20Sopenharmony_ci#define DEFAULT_SINGLE 0 2058c2ecf20Sopenharmony_ci#define SD_LUN 1 2068c2ecf20Sopenharmony_ci#define SD_EXPRESS_LUN 2 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci/* For Change_FPGA_SSCClock Function */ 2098c2ecf20Sopenharmony_ci#define MULTIPLY_BY_1 0x00 2108c2ecf20Sopenharmony_ci#define MULTIPLY_BY_2 0x01 2118c2ecf20Sopenharmony_ci#define MULTIPLY_BY_3 0x02 2128c2ecf20Sopenharmony_ci#define MULTIPLY_BY_4 0x03 2138c2ecf20Sopenharmony_ci#define MULTIPLY_BY_5 0x04 2148c2ecf20Sopenharmony_ci#define MULTIPLY_BY_6 0x05 2158c2ecf20Sopenharmony_ci#define MULTIPLY_BY_7 0x06 2168c2ecf20Sopenharmony_ci#define MULTIPLY_BY_8 0x07 2178c2ecf20Sopenharmony_ci#define MULTIPLY_BY_9 0x08 2188c2ecf20Sopenharmony_ci#define MULTIPLY_BY_10 0x09 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci#define DIVIDE_BY_2 0x01 2218c2ecf20Sopenharmony_ci#define DIVIDE_BY_3 0x02 2228c2ecf20Sopenharmony_ci#define DIVIDE_BY_4 0x03 2238c2ecf20Sopenharmony_ci#define DIVIDE_BY_5 0x04 2248c2ecf20Sopenharmony_ci#define DIVIDE_BY_6 0x05 2258c2ecf20Sopenharmony_ci#define DIVIDE_BY_7 0x06 2268c2ecf20Sopenharmony_ci#define DIVIDE_BY_8 0x07 2278c2ecf20Sopenharmony_ci#define DIVIDE_BY_9 0x08 2288c2ecf20Sopenharmony_ci#define DIVIDE_BY_10 0x09 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ciint rts5261_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock, 2318c2ecf20Sopenharmony_ci u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk); 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci#endif /* RTS5261_H */ 234