提交 849a9366 编写于 作者: R Ricky Wu 提交者: Greg Kroah-Hartman

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: NRicky Wu <ricky_wu@realtek.com>
Link: https://lore.kernel.org/r/20200706070259.32565-1-ricky_wu@realtek.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 f31a03b1
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_MISC_ALCOR_PCI) += alcor_pci.o
obj-$(CONFIG_MISC_RTSX_PCI) += rtsx_pci.o
rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o rts5260.o rts5261.o
rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o rts5260.o rts5261.o rts5228.o
obj-$(CONFIG_MISC_RTSX_USB) += rtsx_usb.o
此差异已折叠。
/* SPDX-License-Identifier: GPL-2.0-only */
/* Driver for Realtek PCI-Express card reader
*
* Copyright(c) 2018-2019 Realtek Semiconductor Corp. All rights reserved.
*
* Author:
* Ricky WU <ricky_wu@realtek.com>
* Rui FENG <rui_feng@realsil.com.cn>
* Wei WANG <wei_wang@realsil.com.cn>
*/
#ifndef RTS5228_H
#define RTS5228_H
#define RTS5228_AUTOLOAD_CFG0 0xFF7B
#define RTS5228_AUTOLOAD_CFG1 0xFF7C
#define RTS5228_AUTOLOAD_CFG2 0xFF7D
#define RTS5228_AUTOLOAD_CFG3 0xFF7E
#define RTS5228_AUTOLOAD_CFG4 0xFF7F
#define RTS5228_REG_VREF 0xFE97
#define RTS5228_PWD_SUSPND_EN (1 << 4)
#define RTS5228_PAD_H3L1 0xFF79
#define PAD_GPIO_H3L1 (1 << 3)
/* SSC_CTL2 0xFC12 */
#define RTS5228_SSC_DEPTH_MASK 0x07
#define RTS5228_SSC_DEPTH_DISALBE 0x00
#define RTS5228_SSC_DEPTH_8M 0x01
#define RTS5228_SSC_DEPTH_4M 0x02
#define RTS5228_SSC_DEPTH_2M 0x03
#define RTS5228_SSC_DEPTH_1M 0x04
#define RTS5228_SSC_DEPTH_512K 0x05
#define RTS5228_SSC_DEPTH_256K 0x06
#define RTS5228_SSC_DEPTH_128K 0x07
/* DMACTL 0xFE2C */
#define RTS5228_DMA_PACK_SIZE_MASK 0xF0
#define RTS5228_REG_LDO12_CFG 0xFF6E
#define RTS5228_LDO12_VO_TUNE_MASK (0x07<<1)
#define RTS5228_LDO12_100 (0x00<<1)
#define RTS5228_LDO12_105 (0x01<<1)
#define RTS5228_LDO12_110 (0x02<<1)
#define RTS5228_LDO12_115 (0x03<<1)
#define RTS5228_LDO12_120 (0x04<<1)
#define RTS5228_LDO12_125 (0x05<<1)
#define RTS5228_LDO12_130 (0x06<<1)
#define RTS5228_LDO12_135 (0x07<<1)
#define RTS5228_REG_PWD_LDO12 (0x01<<0)
#define RTS5228_REG_LDO12_L12 0xFF6F
#define RTS5228_LDO12_L12_MASK (0x07<<4)
#define RTS5228_LDO12_L12_120 (0x04<<4)
/* LDO control register */
#define RTS5228_CARD_PWR_CTL 0xFD50
#define RTS5228_PUPDC (0x01<<5)
#define RTS5228_LDO1233318_POW_CTL 0xFF70
#define RTS5228_LDO3318_POWERON (0x01<<3)
#define RTS5228_LDO1_POWEROFF (0x00<<0)
#define RTS5228_LDO1_SOFTSTART (0x01<<0)
#define RTS5228_LDO1_FULLON (0x03<<0)
#define RTS5228_LDO1_POWERON_MASK (0x03<<0)
#define RTS5228_LDO_POWERON_MASK (0x0F<<0)
#define RTS5228_DV3318_CFG 0xFF71
#define RTS5228_DV3318_TUNE_MASK (0x07<<4)
#define RTS5228_DV3318_17 (0x00<<4)
#define RTS5228_DV3318_1V75 (0x01<<4)
#define RTS5228_DV3318_18 (0x02<<4)
#define RTS5228_DV3318_1V85 (0x03<<4)
#define RTS5228_DV3318_19 (0x04<<4)
#define RTS5228_DV3318_33 (0x07<<4)
#define RTS5228_DV3318_SR_MASK (0x03<<2)
#define RTS5228_DV3318_SR_0 (0x00<<2)
#define RTS5228_DV3318_SR_250 (0x01<<2)
#define RTS5228_DV3318_SR_500 (0x02<<2)
#define RTS5228_DV3318_SR_1000 (0x03<<2)
#define RTS5228_LDO1_CFG0 0xFF72
#define RTS5228_LDO1_OCP_THD_MASK (0x07<<5)
#define RTS5228_LDO1_OCP_EN (0x01<<4)
#define RTS5228_LDO1_OCP_LMT_THD_MASK (0x03<<2)
#define RTS5228_LDO1_OCP_LMT_EN (0x01<<1)
#define RTS5228_LDO1_OCP_THD_730 (0x00<<5)
#define RTS5228_LDO1_OCP_THD_780 (0x01<<5)
#define RTS5228_LDO1_OCP_THD_860 (0x02<<5)
#define RTS5228_LDO1_OCP_THD_930 (0x03<<5)
#define RTS5228_LDO1_OCP_THD_1000 (0x04<<5)
#define RTS5228_LDO1_OCP_THD_1070 (0x05<<5)
#define RTS5228_LDO1_OCP_THD_1140 (0x06<<5)
#define RTS5228_LDO1_OCP_THD_1220 (0x07<<5)
#define RTS5228_LDO1_LMT_THD_450 (0x00<<2)
#define RTS5228_LDO1_LMT_THD_1000 (0x01<<2)
#define RTS5228_LDO1_LMT_THD_1500 (0x02<<2)
#define RTS5228_LDO1_LMT_THD_2000 (0x03<<2)
#define RTS5228_LDO1_CFG1 0xFF73
#define RTS5228_LDO1_SR_TIME_MASK (0x03<<6)
#define RTS5228_LDO1_SR_0_0 (0x00<<6)
#define RTS5228_LDO1_SR_0_25 (0x01<<6)
#define RTS5228_LDO1_SR_0_5 (0x02<<6)
#define RTS5228_LDO1_SR_1_0 (0x03<<6)
#define RTS5228_LDO1_TUNE_MASK (0x07<<1)
#define RTS5228_LDO1_18 (0x05<<1)
#define RTS5228_LDO1_33 (0x07<<1)
#define RTS5228_LDO1_PWD_MASK (0x01<<0)
#define RTS5228_AUXCLK_GAT_CTL 0xFF74
#define RTS5228_REG_RREF_CTL_0 0xFF75
#define RTS5228_FORCE_RREF_EXTL (0x01<<7)
#define RTS5228_REG_BG33_MASK (0x07<<0)
#define RTS5228_RREF_12_1V (0x04<<0)
#define RTS5228_RREF_12_3V (0x05<<0)
#define RTS5228_REG_RREF_CTL_1 0xFF76
#define RTS5228_REG_RREF_CTL_2 0xFF77
#define RTS5228_TEST_INTL_RREF (0x01<<7)
#define RTS5228_DGLCH_TIME_MASK (0x03<<5)
#define RTS5228_DGLCH_TIME_50 (0x00<<5)
#define RTS5228_DGLCH_TIME_75 (0x01<<5)
#define RTS5228_DGLCH_TIME_100 (0x02<<5)
#define RTS5228_DGLCH_TIME_125 (0x03<<5)
#define RTS5228_REG_REXT_TUNE_MASK (0x1F<<0)
#define RTS5228_REG_PME_FORCE_CTL 0xFF78
#define FORCE_PM_CONTROL 0x20
#define FORCE_PM_VALUE 0x10
/* Single LUN, support SD */
#define DEFAULT_SINGLE 0
#define SD_LUN 1
/* For Change_FPGA_SSCClock Function */
#define MULTIPLY_BY_1 0x00
#define MULTIPLY_BY_2 0x01
#define MULTIPLY_BY_3 0x02
#define MULTIPLY_BY_4 0x03
#define MULTIPLY_BY_5 0x04
#define MULTIPLY_BY_6 0x05
#define MULTIPLY_BY_7 0x06
#define MULTIPLY_BY_8 0x07
#define MULTIPLY_BY_9 0x08
#define MULTIPLY_BY_10 0x09
#define DIVIDE_BY_2 0x01
#define DIVIDE_BY_3 0x02
#define DIVIDE_BY_4 0x03
#define DIVIDE_BY_5 0x04
#define DIVIDE_BY_6 0x05
#define DIVIDE_BY_7 0x06
#define DIVIDE_BY_8 0x07
#define DIVIDE_BY_9 0x08
#define DIVIDE_BY_10 0x09
int rts5228_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
u8 ssc_depth, bool initial_mode, bool double_clk, bool vpclk);
#endif /* RTS5228_H */
......@@ -23,6 +23,7 @@
#include "rtsx_pcr.h"
#include "rts5261.h"
#include "rts5228.h"
static bool msi_en = true;
module_param(msi_en, bool, S_IRUGO | S_IWUSR);
......@@ -50,6 +51,7 @@ static const struct pci_device_id rtsx_pci_ids[] = {
{ PCI_DEVICE(0x10EC, 0x525A), PCI_CLASS_OTHERS << 16, 0xFF0000 },
{ PCI_DEVICE(0x10EC, 0x5260), PCI_CLASS_OTHERS << 16, 0xFF0000 },
{ PCI_DEVICE(0x10EC, 0x5261), PCI_CLASS_OTHERS << 16, 0xFF0000 },
{ PCI_DEVICE(0x10EC, 0x5228), PCI_CLASS_OTHERS << 16, 0xFF0000 },
{ 0, }
};
......@@ -206,16 +208,10 @@ int __rtsx_pci_write_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 val)
int err, i, finished = 0;
u8 tmp;
rtsx_pci_init_cmd(pcr);
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYDATA0, 0xFF, (u8)val);
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYDATA1, 0xFF, (u8)(val >> 8));
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYADDR, 0xFF, addr);
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYRWCTL, 0xFF, 0x81);
err = rtsx_pci_send_cmd(pcr, 100);
if (err < 0)
return err;
rtsx_pci_write_register(pcr, PHYDATA0, 0xFF, (u8)val);
rtsx_pci_write_register(pcr, PHYDATA1, 0xFF, (u8)(val >> 8));
rtsx_pci_write_register(pcr, PHYADDR, 0xFF, addr);
rtsx_pci_write_register(pcr, PHYRWCTL, 0xFF, 0x81);
for (i = 0; i < 100000; i++) {
err = rtsx_pci_read_register(pcr, PHYRWCTL, &tmp);
......@@ -247,16 +243,10 @@ int __rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
{
int err, i, finished = 0;
u16 data;
u8 *ptr, tmp;
rtsx_pci_init_cmd(pcr);
u8 tmp, val1, val2;
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYADDR, 0xFF, addr);
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, PHYRWCTL, 0xFF, 0x80);
err = rtsx_pci_send_cmd(pcr, 100);
if (err < 0)
return err;
rtsx_pci_write_register(pcr, PHYADDR, 0xFF, addr);
rtsx_pci_write_register(pcr, PHYRWCTL, 0xFF, 0x80);
for (i = 0; i < 100000; i++) {
err = rtsx_pci_read_register(pcr, PHYRWCTL, &tmp);
......@@ -272,17 +262,9 @@ int __rtsx_pci_read_phy_register(struct rtsx_pcr *pcr, u8 addr, u16 *val)
if (!finished)
return -ETIMEDOUT;
rtsx_pci_init_cmd(pcr);
rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA0, 0, 0);
rtsx_pci_add_cmd(pcr, READ_REG_CMD, PHYDATA1, 0, 0);
err = rtsx_pci_send_cmd(pcr, 100);
if (err < 0)
return err;
ptr = rtsx_pci_get_cmd_data(pcr);
data = ((u16)ptr[1] << 8) | ptr[0];
rtsx_pci_read_register(pcr, PHYDATA0, &val1);
rtsx_pci_read_register(pcr, PHYDATA1, &val2);
data = val1 | (val2 << 8);
if (val)
*val = data;
......@@ -417,7 +399,7 @@ static void rtsx_pci_add_sg_tbl(struct rtsx_pcr *pcr,
if (end)
option |= RTSX_SG_END;
if (PCI_PID(pcr) == PID_5261) {
if ((PCI_PID(pcr) == PID_5261) || (PCI_PID(pcr) == PID_5228)) {
if (len > 0xFFFF)
val = ((u64)addr << 32) | (((u64)len & 0xFFFF) << 16)
| (((u64)len >> 16) << 6) | option;
......@@ -723,6 +705,9 @@ int rtsx_pci_switch_clock(struct rtsx_pcr *pcr, unsigned int card_clock,
if (PCI_PID(pcr) == PID_5261)
return rts5261_pci_switch_clock(pcr, card_clock,
ssc_depth, initial_mode, double_clk, vpclk);
if (PCI_PID(pcr) == PID_5228)
return rts5228_pci_switch_clock(pcr, card_clock,
ssc_depth, initial_mode, double_clk, vpclk);
if (initial_mode) {
/* We use 250k(around) here, in initial stage */
......@@ -1202,6 +1187,36 @@ void rtsx_pci_clear_ocpstat(struct rtsx_pcr *pcr)
}
}
void rtsx_pci_enable_oobs_polling(struct rtsx_pcr *pcr)
{
u16 val;
if ((PCI_PID(pcr) != PID_525A) && (PCI_PID(pcr) != PID_5260)) {
rtsx_pci_read_phy_register(pcr, 0x01, &val);
val |= 1<<9;
rtsx_pci_write_phy_register(pcr, 0x01, val);
}
rtsx_pci_write_register(pcr, REG_CFG_OOBS_OFF_TIMER, 0xFF, 0x32);
rtsx_pci_write_register(pcr, REG_CFG_OOBS_ON_TIMER, 0xFF, 0x05);
rtsx_pci_write_register(pcr, REG_CFG_VCM_ON_TIMER, 0xFF, 0x83);
rtsx_pci_write_register(pcr, REG_CFG_OOBS_POLLING, 0xFF, 0xDE);
}
void rtsx_pci_disable_oobs_polling(struct rtsx_pcr *pcr)
{
u16 val;
if ((PCI_PID(pcr) != PID_525A) && (PCI_PID(pcr) != PID_5260)) {
rtsx_pci_read_phy_register(pcr, 0x01, &val);
val &= ~(1<<9);
rtsx_pci_write_phy_register(pcr, 0x01, val);
}
rtsx_pci_write_register(pcr, REG_CFG_VCM_ON_TIMER, 0xFF, 0x03);
rtsx_pci_write_register(pcr, REG_CFG_OOBS_POLLING, 0xFF, 0x00);
}
int rtsx_sd_power_off_card3v3(struct rtsx_pcr *pcr)
{
rtsx_pci_write_register(pcr, CARD_CLK_EN, SD_CLK_EN |
......@@ -1233,6 +1248,10 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
{
int err;
if (PCI_PID(pcr) == PID_5228)
rtsx_pci_write_register(pcr, RTS5228_LDO1_CFG1, RTS5228_LDO1_SR_TIME_MASK,
RTS5228_LDO1_SR_0_5);
pcr->pcie_cap = pci_find_capability(pcr->pci, PCI_CAP_ID_EXP);
rtsx_pci_writel(pcr, RTSX_HCBAR, pcr->host_cmds_addr);
......@@ -1280,6 +1299,9 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
if (PCI_PID(pcr) == PID_5261)
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 0xFF,
RTS5261_SSC_DEPTH_2M);
else if (PCI_PID(pcr) == PID_5228)
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 0xFF,
RTS5228_SSC_DEPTH_2M);
else
rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, SSC_CTL2, 0xFF, 0x12);
......@@ -1314,6 +1336,7 @@ static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
case PID_525A:
case PID_5260:
case PID_5261:
case PID_5228:
rtsx_pci_write_register(pcr, PM_CLK_FORCE_CTL, 1, 1);
break;
default:
......@@ -1401,6 +1424,10 @@ static int rtsx_pci_init_chip(struct rtsx_pcr *pcr)
case 0x5261:
rts5261_init_params(pcr);
break;
case 0x5228:
rts5228_init_params(pcr);
break;
}
pcr_dbg(pcr, "PID: 0x%04x, IC version: 0x%02x\n",
......
......@@ -53,6 +53,7 @@ void rts525a_init_params(struct rtsx_pcr *pcr);
void rtl8411b_init_params(struct rtsx_pcr *pcr);
void rts5260_init_params(struct rtsx_pcr *pcr);
void rts5261_init_params(struct rtsx_pcr *pcr);
void rts5228_init_params(struct rtsx_pcr *pcr);
static inline u8 map_sd_drive(int idx)
{
......@@ -70,6 +71,8 @@ static inline u8 map_sd_drive(int idx)
#define rts5209_vendor_setting1_valid(reg) (!((reg) & 0x80))
#define rts5209_vendor_setting2_valid(reg) ((reg) & 0x80)
#define rtsx_check_mmc_support(reg) ((reg) & 0x10)
#define rtsx_reg_to_rtd3(reg) ((reg) & 0x02)
#define rtsx_reg_to_aspm(reg) (((reg) >> 28) & 0x03)
#define rtsx_reg_to_sd30_drive_sel_1v8(reg) (((reg) >> 26) & 0x03)
#define rtsx_reg_to_sd30_drive_sel_3v3(reg) (((reg) >> 5) & 0x03)
......@@ -100,6 +103,8 @@ void rtsx_pci_disable_ocp(struct rtsx_pcr *pcr);
void rtsx_pci_enable_ocp(struct rtsx_pcr *pcr);
int rtsx_pci_get_ocpstat(struct rtsx_pcr *pcr, u8 *val);
void rtsx_pci_clear_ocpstat(struct rtsx_pcr *pcr);
void rtsx_pci_enable_oobs_polling(struct rtsx_pcr *pcr);
void rtsx_pci_disable_oobs_polling(struct rtsx_pcr *pcr);
int rtsx_sd_power_off_card3v3(struct rtsx_pcr *pcr);
int rtsx_ms_power_off_card3v3(struct rtsx_pcr *pcr);
......
......@@ -1336,6 +1336,8 @@ static void init_extra_caps(struct realtek_pci_sdmmc *host)
mmc->caps |= MMC_CAP_1_8V_DDR;
if (pcr->extra_caps & EXTRA_CAPS_MMC_8BIT)
mmc->caps |= MMC_CAP_8_BIT_DATA;
if (pcr->extra_caps & EXTRA_CAPS_NO_MMC)
mmc->caps2 |= MMC_CAP2_NO_MMC;
}
static void realtek_init_host(struct realtek_pci_sdmmc *host)
......
......@@ -305,6 +305,8 @@
#define SD30_CLK_STOP_CFG0 0x01
#define REG_PRE_RW_MODE 0xFD70
#define EN_INFINITE_MODE 0x01
#define REG_CRC_DUMMY_0 0xFD71
#define CFG_SD_POW_AUTO_PD (1<<0)
#define SRCTL 0xFC13
......@@ -599,6 +601,7 @@
#define ASPM_FORCE_CTL 0xFE57
#define FORCE_ASPM_CTL0 0x10
#define FORCE_ASPM_CTL1 0x20
#define FORCE_ASPM_VAL_MASK 0x03
#define FORCE_ASPM_L1_EN 0x02
#define FORCE_ASPM_L0_EN 0x01
......@@ -667,6 +670,11 @@
#define PM_WAKE_EN 0x01
#define PM_CTRL4 0xFF47
#define REG_CFG_OOBS_OFF_TIMER 0xFEA6
#define REG_CFG_OOBS_ON_TIMER 0xFEA7
#define REG_CFG_VCM_ON_TIMER 0xFEA8
#define REG_CFG_OOBS_POLLING 0xFEA9
/* Memory mapping */
#define SRAM_BASE 0xE600
#define RBUF_BASE 0xF400
......@@ -1204,6 +1212,7 @@ struct rtsx_pcr {
#define EXTRA_CAPS_MMC_HSDDR (1 << 3)
#define EXTRA_CAPS_MMC_HS200 (1 << 4)
#define EXTRA_CAPS_MMC_8BIT (1 << 5)
#define EXTRA_CAPS_NO_MMC (1 << 7)
u32 extra_caps;
#define IC_VER_A 0
......@@ -1242,6 +1251,7 @@ struct rtsx_pcr {
u8 dma_error_count;
u8 ocp_stat;
u8 ocp_stat2;
u8 rtd3_en;
};
#define PID_524A 0x524A
......@@ -1250,6 +1260,7 @@ struct rtsx_pcr {
#define PID_525A 0x525A
#define PID_5260 0x5260
#define PID_5261 0x5261
#define PID_5228 0x5228
#define CHK_PCI_PID(pcr, pid) ((pcr)->pci->device == (pid))
#define PCI_VID(pcr) ((pcr)->pci->vendor)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册