17160820dSYifeng Zhao // SPDX-License-Identifier: GPL-2.0 27160820dSYifeng Zhao /* 37160820dSYifeng Zhao * Rockchip PIPE USB3.0 PCIE SATA Combo Phy driver 47160820dSYifeng Zhao * 57160820dSYifeng Zhao * Copyright (C) 2021 Rockchip Electronics Co., Ltd. 67160820dSYifeng Zhao */ 77160820dSYifeng Zhao 87160820dSYifeng Zhao #include <dt-bindings/phy/phy.h> 97160820dSYifeng Zhao #include <linux/clk.h> 107160820dSYifeng Zhao #include <linux/mfd/syscon.h> 117559e757SRob Herring #include <linux/of.h> 127160820dSYifeng Zhao #include <linux/phy/phy.h> 137559e757SRob Herring #include <linux/platform_device.h> 147160820dSYifeng Zhao #include <linux/regmap.h> 157160820dSYifeng Zhao #include <linux/reset.h> 167160820dSYifeng Zhao #include <linux/units.h> 177160820dSYifeng Zhao 187160820dSYifeng Zhao #define BIT_WRITEABLE_SHIFT 16 197160820dSYifeng Zhao #define REF_CLOCK_24MHz (24 * HZ_PER_MHZ) 207160820dSYifeng Zhao #define REF_CLOCK_25MHz (25 * HZ_PER_MHZ) 217160820dSYifeng Zhao #define REF_CLOCK_100MHz (100 * HZ_PER_MHZ) 227160820dSYifeng Zhao 237160820dSYifeng Zhao /* COMBO PHY REG */ 247160820dSYifeng Zhao #define PHYREG6 0x14 257160820dSYifeng Zhao #define PHYREG6_PLL_DIV_MASK GENMASK(7, 6) 267160820dSYifeng Zhao #define PHYREG6_PLL_DIV_SHIFT 6 277160820dSYifeng Zhao #define PHYREG6_PLL_DIV_2 1 287160820dSYifeng Zhao 297160820dSYifeng Zhao #define PHYREG7 0x18 307160820dSYifeng Zhao #define PHYREG7_TX_RTERM_MASK GENMASK(7, 4) 317160820dSYifeng Zhao #define PHYREG7_TX_RTERM_SHIFT 4 327160820dSYifeng Zhao #define PHYREG7_TX_RTERM_50OHM 8 337160820dSYifeng Zhao #define PHYREG7_RX_RTERM_MASK GENMASK(3, 0) 347160820dSYifeng Zhao #define PHYREG7_RX_RTERM_SHIFT 0 357160820dSYifeng Zhao #define PHYREG7_RX_RTERM_44OHM 15 367160820dSYifeng Zhao 377160820dSYifeng Zhao #define PHYREG8 0x1C 387160820dSYifeng Zhao #define PHYREG8_SSC_EN BIT(4) 397160820dSYifeng Zhao 407160820dSYifeng Zhao #define PHYREG11 0x28 417160820dSYifeng Zhao #define PHYREG11_SU_TRIM_0_7 0xF0 427160820dSYifeng Zhao 437160820dSYifeng Zhao #define PHYREG12 0x2C 447160820dSYifeng Zhao #define PHYREG12_PLL_LPF_ADJ_VALUE 4 457160820dSYifeng Zhao 467160820dSYifeng Zhao #define PHYREG13 0x30 477160820dSYifeng Zhao #define PHYREG13_RESISTER_MASK GENMASK(5, 4) 487160820dSYifeng Zhao #define PHYREG13_RESISTER_SHIFT 0x4 497160820dSYifeng Zhao #define PHYREG13_RESISTER_HIGH_Z 3 507160820dSYifeng Zhao #define PHYREG13_CKRCV_AMP0 BIT(7) 517160820dSYifeng Zhao 527160820dSYifeng Zhao #define PHYREG14 0x34 537160820dSYifeng Zhao #define PHYREG14_CKRCV_AMP1 BIT(0) 547160820dSYifeng Zhao 557160820dSYifeng Zhao #define PHYREG15 0x38 567160820dSYifeng Zhao #define PHYREG15_CTLE_EN BIT(0) 577160820dSYifeng Zhao #define PHYREG15_SSC_CNT_MASK GENMASK(7, 6) 587160820dSYifeng Zhao #define PHYREG15_SSC_CNT_SHIFT 6 597160820dSYifeng Zhao #define PHYREG15_SSC_CNT_VALUE 1 607160820dSYifeng Zhao 617160820dSYifeng Zhao #define PHYREG16 0x3C 627160820dSYifeng Zhao #define PHYREG16_SSC_CNT_VALUE 0x5f 637160820dSYifeng Zhao 647160820dSYifeng Zhao #define PHYREG18 0x44 657160820dSYifeng Zhao #define PHYREG18_PLL_LOOP 0x32 667160820dSYifeng Zhao 67a03c4427SLucas Tanure #define PHYREG27 0x6C 68a03c4427SLucas Tanure #define PHYREG27_RX_TRIM_RK3588 0x4C 69a03c4427SLucas Tanure 707160820dSYifeng Zhao #define PHYREG32 0x7C 717160820dSYifeng Zhao #define PHYREG32_SSC_MASK GENMASK(7, 4) 727160820dSYifeng Zhao #define PHYREG32_SSC_DIR_SHIFT 4 737160820dSYifeng Zhao #define PHYREG32_SSC_UPWARD 0 747160820dSYifeng Zhao #define PHYREG32_SSC_DOWNWARD 1 757160820dSYifeng Zhao #define PHYREG32_SSC_OFFSET_SHIFT 6 767160820dSYifeng Zhao #define PHYREG32_SSC_OFFSET_500PPM 1 777160820dSYifeng Zhao 787160820dSYifeng Zhao #define PHYREG33 0x80 797160820dSYifeng Zhao #define PHYREG33_PLL_KVCO_MASK GENMASK(4, 2) 807160820dSYifeng Zhao #define PHYREG33_PLL_KVCO_SHIFT 2 817160820dSYifeng Zhao #define PHYREG33_PLL_KVCO_VALUE 2 827160820dSYifeng Zhao 837160820dSYifeng Zhao struct rockchip_combphy_priv; 847160820dSYifeng Zhao 857160820dSYifeng Zhao struct combphy_reg { 867160820dSYifeng Zhao u16 offset; 877160820dSYifeng Zhao u16 bitend; 887160820dSYifeng Zhao u16 bitstart; 897160820dSYifeng Zhao u16 disable; 907160820dSYifeng Zhao u16 enable; 917160820dSYifeng Zhao }; 927160820dSYifeng Zhao 937160820dSYifeng Zhao struct rockchip_combphy_grfcfg { 947160820dSYifeng Zhao struct combphy_reg pcie_mode_set; 957160820dSYifeng Zhao struct combphy_reg usb_mode_set; 967160820dSYifeng Zhao struct combphy_reg sgmii_mode_set; 977160820dSYifeng Zhao struct combphy_reg qsgmii_mode_set; 987160820dSYifeng Zhao struct combphy_reg pipe_rxterm_set; 997160820dSYifeng Zhao struct combphy_reg pipe_txelec_set; 1007160820dSYifeng Zhao struct combphy_reg pipe_txcomp_set; 1017160820dSYifeng Zhao struct combphy_reg pipe_clk_25m; 1027160820dSYifeng Zhao struct combphy_reg pipe_clk_100m; 1037160820dSYifeng Zhao struct combphy_reg pipe_phymode_sel; 1047160820dSYifeng Zhao struct combphy_reg pipe_rate_sel; 1057160820dSYifeng Zhao struct combphy_reg pipe_rxterm_sel; 1067160820dSYifeng Zhao struct combphy_reg pipe_txelec_sel; 1077160820dSYifeng Zhao struct combphy_reg pipe_txcomp_sel; 1087160820dSYifeng Zhao struct combphy_reg pipe_clk_ext; 1097160820dSYifeng Zhao struct combphy_reg pipe_sel_usb; 1107160820dSYifeng Zhao struct combphy_reg pipe_sel_qsgmii; 1117160820dSYifeng Zhao struct combphy_reg pipe_phy_status; 1127160820dSYifeng Zhao struct combphy_reg con0_for_pcie; 1137160820dSYifeng Zhao struct combphy_reg con1_for_pcie; 1147160820dSYifeng Zhao struct combphy_reg con2_for_pcie; 1157160820dSYifeng Zhao struct combphy_reg con3_for_pcie; 1167160820dSYifeng Zhao struct combphy_reg con0_for_sata; 1177160820dSYifeng Zhao struct combphy_reg con1_for_sata; 1187160820dSYifeng Zhao struct combphy_reg con2_for_sata; 1197160820dSYifeng Zhao struct combphy_reg con3_for_sata; 1207160820dSYifeng Zhao struct combphy_reg pipe_con0_for_sata; 121a03c4427SLucas Tanure struct combphy_reg pipe_con1_for_sata; 1227160820dSYifeng Zhao struct combphy_reg pipe_xpcs_phy_ready; 123a03c4427SLucas Tanure struct combphy_reg pipe_pcie1l0_sel; 124a03c4427SLucas Tanure struct combphy_reg pipe_pcie1l1_sel; 1257160820dSYifeng Zhao }; 1267160820dSYifeng Zhao 1277160820dSYifeng Zhao struct rockchip_combphy_cfg { 1287160820dSYifeng Zhao const struct rockchip_combphy_grfcfg *grfcfg; 1297160820dSYifeng Zhao int (*combphy_cfg)(struct rockchip_combphy_priv *priv); 1307160820dSYifeng Zhao }; 1317160820dSYifeng Zhao 1327160820dSYifeng Zhao struct rockchip_combphy_priv { 1337160820dSYifeng Zhao u8 type; 1347160820dSYifeng Zhao void __iomem *mmio; 1357160820dSYifeng Zhao int num_clks; 1367160820dSYifeng Zhao struct clk_bulk_data *clks; 1377160820dSYifeng Zhao struct device *dev; 1387160820dSYifeng Zhao struct regmap *pipe_grf; 1397160820dSYifeng Zhao struct regmap *phy_grf; 1407160820dSYifeng Zhao struct phy *phy; 1417160820dSYifeng Zhao struct reset_control *phy_rst; 1427160820dSYifeng Zhao const struct rockchip_combphy_cfg *cfg; 1437160820dSYifeng Zhao bool enable_ssc; 1447160820dSYifeng Zhao bool ext_refclk; 1457160820dSYifeng Zhao struct clk *refclk; 1467160820dSYifeng Zhao }; 1477160820dSYifeng Zhao 1487160820dSYifeng Zhao static void rockchip_combphy_updatel(struct rockchip_combphy_priv *priv, 1497160820dSYifeng Zhao int mask, int val, int reg) 1507160820dSYifeng Zhao { 1517160820dSYifeng Zhao unsigned int temp; 1527160820dSYifeng Zhao 1537160820dSYifeng Zhao temp = readl(priv->mmio + reg); 1547160820dSYifeng Zhao temp = (temp & ~(mask)) | val; 1557160820dSYifeng Zhao writel(temp, priv->mmio + reg); 1567160820dSYifeng Zhao } 1577160820dSYifeng Zhao 1587160820dSYifeng Zhao static int rockchip_combphy_param_write(struct regmap *base, 1597160820dSYifeng Zhao const struct combphy_reg *reg, bool en) 1607160820dSYifeng Zhao { 1617160820dSYifeng Zhao u32 val, mask, tmp; 1627160820dSYifeng Zhao 1637160820dSYifeng Zhao tmp = en ? reg->enable : reg->disable; 1647160820dSYifeng Zhao mask = GENMASK(reg->bitend, reg->bitstart); 1657160820dSYifeng Zhao val = (tmp << reg->bitstart) | (mask << BIT_WRITEABLE_SHIFT); 1667160820dSYifeng Zhao 1677160820dSYifeng Zhao return regmap_write(base, reg->offset, val); 1687160820dSYifeng Zhao } 1697160820dSYifeng Zhao 1707160820dSYifeng Zhao static u32 rockchip_combphy_is_ready(struct rockchip_combphy_priv *priv) 1717160820dSYifeng Zhao { 1727160820dSYifeng Zhao const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; 1737160820dSYifeng Zhao u32 mask, val; 1747160820dSYifeng Zhao 1757160820dSYifeng Zhao mask = GENMASK(cfg->pipe_phy_status.bitend, 1767160820dSYifeng Zhao cfg->pipe_phy_status.bitstart); 1777160820dSYifeng Zhao 1787160820dSYifeng Zhao regmap_read(priv->phy_grf, cfg->pipe_phy_status.offset, &val); 1797160820dSYifeng Zhao val = (val & mask) >> cfg->pipe_phy_status.bitstart; 1807160820dSYifeng Zhao 1817160820dSYifeng Zhao return val; 1827160820dSYifeng Zhao } 1837160820dSYifeng Zhao 1847160820dSYifeng Zhao static int rockchip_combphy_init(struct phy *phy) 1857160820dSYifeng Zhao { 1867160820dSYifeng Zhao struct rockchip_combphy_priv *priv = phy_get_drvdata(phy); 1877160820dSYifeng Zhao const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; 1887160820dSYifeng Zhao u32 val; 1897160820dSYifeng Zhao int ret; 1907160820dSYifeng Zhao 1917160820dSYifeng Zhao ret = clk_bulk_prepare_enable(priv->num_clks, priv->clks); 1927160820dSYifeng Zhao if (ret) { 1937160820dSYifeng Zhao dev_err(priv->dev, "failed to enable clks\n"); 1947160820dSYifeng Zhao return ret; 1957160820dSYifeng Zhao } 1967160820dSYifeng Zhao 1977160820dSYifeng Zhao switch (priv->type) { 1987160820dSYifeng Zhao case PHY_TYPE_PCIE: 1997160820dSYifeng Zhao case PHY_TYPE_USB3: 2007160820dSYifeng Zhao case PHY_TYPE_SATA: 2017160820dSYifeng Zhao case PHY_TYPE_SGMII: 2027160820dSYifeng Zhao case PHY_TYPE_QSGMII: 2037160820dSYifeng Zhao if (priv->cfg->combphy_cfg) 2047160820dSYifeng Zhao ret = priv->cfg->combphy_cfg(priv); 2057160820dSYifeng Zhao break; 2067160820dSYifeng Zhao default: 2077160820dSYifeng Zhao dev_err(priv->dev, "incompatible PHY type\n"); 2087160820dSYifeng Zhao ret = -EINVAL; 2097160820dSYifeng Zhao break; 2107160820dSYifeng Zhao } 2117160820dSYifeng Zhao 2127160820dSYifeng Zhao if (ret) { 2137160820dSYifeng Zhao dev_err(priv->dev, "failed to init phy for phy type %x\n", priv->type); 2147160820dSYifeng Zhao goto err_clk; 2157160820dSYifeng Zhao } 2167160820dSYifeng Zhao 2177160820dSYifeng Zhao ret = reset_control_deassert(priv->phy_rst); 2187160820dSYifeng Zhao if (ret) 2197160820dSYifeng Zhao goto err_clk; 2207160820dSYifeng Zhao 2217160820dSYifeng Zhao if (priv->type == PHY_TYPE_USB3) { 2227160820dSYifeng Zhao ret = readx_poll_timeout_atomic(rockchip_combphy_is_ready, 2237160820dSYifeng Zhao priv, val, 2247160820dSYifeng Zhao val == cfg->pipe_phy_status.enable, 2257160820dSYifeng Zhao 10, 1000); 2267160820dSYifeng Zhao if (ret) 2277160820dSYifeng Zhao dev_warn(priv->dev, "wait phy status ready timeout\n"); 2287160820dSYifeng Zhao } 2297160820dSYifeng Zhao 2307160820dSYifeng Zhao return 0; 2317160820dSYifeng Zhao 2327160820dSYifeng Zhao err_clk: 2337160820dSYifeng Zhao clk_bulk_disable_unprepare(priv->num_clks, priv->clks); 2347160820dSYifeng Zhao 2357160820dSYifeng Zhao return ret; 2367160820dSYifeng Zhao } 2377160820dSYifeng Zhao 2387160820dSYifeng Zhao static int rockchip_combphy_exit(struct phy *phy) 2397160820dSYifeng Zhao { 2407160820dSYifeng Zhao struct rockchip_combphy_priv *priv = phy_get_drvdata(phy); 2417160820dSYifeng Zhao 2427160820dSYifeng Zhao clk_bulk_disable_unprepare(priv->num_clks, priv->clks); 2437160820dSYifeng Zhao reset_control_assert(priv->phy_rst); 2447160820dSYifeng Zhao 2457160820dSYifeng Zhao return 0; 2467160820dSYifeng Zhao } 2477160820dSYifeng Zhao 2487160820dSYifeng Zhao static const struct phy_ops rochchip_combphy_ops = { 2497160820dSYifeng Zhao .init = rockchip_combphy_init, 2507160820dSYifeng Zhao .exit = rockchip_combphy_exit, 2517160820dSYifeng Zhao .owner = THIS_MODULE, 2527160820dSYifeng Zhao }; 2537160820dSYifeng Zhao 254*00ca8a15SKrzysztof Kozlowski static struct phy *rockchip_combphy_xlate(struct device *dev, const struct of_phandle_args *args) 2557160820dSYifeng Zhao { 2567160820dSYifeng Zhao struct rockchip_combphy_priv *priv = dev_get_drvdata(dev); 2577160820dSYifeng Zhao 2587160820dSYifeng Zhao if (args->args_count != 1) { 2597160820dSYifeng Zhao dev_err(dev, "invalid number of arguments\n"); 2607160820dSYifeng Zhao return ERR_PTR(-EINVAL); 2617160820dSYifeng Zhao } 2627160820dSYifeng Zhao 2637160820dSYifeng Zhao if (priv->type != PHY_NONE && priv->type != args->args[0]) 2647160820dSYifeng Zhao dev_warn(dev, "phy type select %d overwriting type %d\n", 2657160820dSYifeng Zhao args->args[0], priv->type); 2667160820dSYifeng Zhao 2677160820dSYifeng Zhao priv->type = args->args[0]; 2687160820dSYifeng Zhao 2697160820dSYifeng Zhao return priv->phy; 2707160820dSYifeng Zhao } 2717160820dSYifeng Zhao 2727160820dSYifeng Zhao static int rockchip_combphy_parse_dt(struct device *dev, struct rockchip_combphy_priv *priv) 2737160820dSYifeng Zhao { 2747160820dSYifeng Zhao int i; 2757160820dSYifeng Zhao 2767160820dSYifeng Zhao priv->num_clks = devm_clk_bulk_get_all(dev, &priv->clks); 2777160820dSYifeng Zhao if (priv->num_clks < 1) 2787160820dSYifeng Zhao return -EINVAL; 2797160820dSYifeng Zhao 2807160820dSYifeng Zhao priv->refclk = NULL; 2817160820dSYifeng Zhao for (i = 0; i < priv->num_clks; i++) { 2827160820dSYifeng Zhao if (!strncmp(priv->clks[i].id, "ref", 3)) { 2837160820dSYifeng Zhao priv->refclk = priv->clks[i].clk; 2847160820dSYifeng Zhao break; 2857160820dSYifeng Zhao } 2867160820dSYifeng Zhao } 2877160820dSYifeng Zhao 2887160820dSYifeng Zhao if (!priv->refclk) { 2897160820dSYifeng Zhao dev_err(dev, "no refclk found\n"); 2907160820dSYifeng Zhao return -EINVAL; 2917160820dSYifeng Zhao } 2927160820dSYifeng Zhao 2937160820dSYifeng Zhao priv->pipe_grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pipe-grf"); 2947160820dSYifeng Zhao if (IS_ERR(priv->pipe_grf)) { 2957160820dSYifeng Zhao dev_err(dev, "failed to find peri_ctrl pipe-grf regmap\n"); 2967160820dSYifeng Zhao return PTR_ERR(priv->pipe_grf); 2977160820dSYifeng Zhao } 2987160820dSYifeng Zhao 2997160820dSYifeng Zhao priv->phy_grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pipe-phy-grf"); 3007160820dSYifeng Zhao if (IS_ERR(priv->phy_grf)) { 3017160820dSYifeng Zhao dev_err(dev, "failed to find peri_ctrl pipe-phy-grf regmap\n"); 3027160820dSYifeng Zhao return PTR_ERR(priv->phy_grf); 3037160820dSYifeng Zhao } 3047160820dSYifeng Zhao 3057160820dSYifeng Zhao priv->enable_ssc = device_property_present(dev, "rockchip,enable-ssc"); 3067160820dSYifeng Zhao 3077160820dSYifeng Zhao priv->ext_refclk = device_property_present(dev, "rockchip,ext-refclk"); 3087160820dSYifeng Zhao 3097160820dSYifeng Zhao priv->phy_rst = devm_reset_control_array_get_exclusive(dev); 3107160820dSYifeng Zhao if (IS_ERR(priv->phy_rst)) 3117160820dSYifeng Zhao return dev_err_probe(dev, PTR_ERR(priv->phy_rst), "failed to get phy reset\n"); 3127160820dSYifeng Zhao 3137160820dSYifeng Zhao return 0; 3147160820dSYifeng Zhao } 3157160820dSYifeng Zhao 3167160820dSYifeng Zhao static int rockchip_combphy_probe(struct platform_device *pdev) 3177160820dSYifeng Zhao { 3187160820dSYifeng Zhao struct phy_provider *phy_provider; 3197160820dSYifeng Zhao struct device *dev = &pdev->dev; 3207160820dSYifeng Zhao struct rockchip_combphy_priv *priv; 3217160820dSYifeng Zhao const struct rockchip_combphy_cfg *phy_cfg; 3227160820dSYifeng Zhao struct resource *res; 3237160820dSYifeng Zhao int ret; 3247160820dSYifeng Zhao 3257160820dSYifeng Zhao phy_cfg = of_device_get_match_data(dev); 3267160820dSYifeng Zhao if (!phy_cfg) { 3277160820dSYifeng Zhao dev_err(dev, "no OF match data provided\n"); 3287160820dSYifeng Zhao return -EINVAL; 3297160820dSYifeng Zhao } 3307160820dSYifeng Zhao 3317160820dSYifeng Zhao priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 3327160820dSYifeng Zhao if (!priv) 3337160820dSYifeng Zhao return -ENOMEM; 3347160820dSYifeng Zhao 3357160820dSYifeng Zhao priv->mmio = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 3367160820dSYifeng Zhao if (IS_ERR(priv->mmio)) { 3377160820dSYifeng Zhao ret = PTR_ERR(priv->mmio); 3387160820dSYifeng Zhao return ret; 3397160820dSYifeng Zhao } 3407160820dSYifeng Zhao 3417160820dSYifeng Zhao priv->dev = dev; 3427160820dSYifeng Zhao priv->type = PHY_NONE; 3437160820dSYifeng Zhao priv->cfg = phy_cfg; 3447160820dSYifeng Zhao 3457160820dSYifeng Zhao ret = rockchip_combphy_parse_dt(dev, priv); 3467160820dSYifeng Zhao if (ret) 3477160820dSYifeng Zhao return ret; 3487160820dSYifeng Zhao 3497160820dSYifeng Zhao ret = reset_control_assert(priv->phy_rst); 3507160820dSYifeng Zhao if (ret) { 3517160820dSYifeng Zhao dev_err(dev, "failed to reset phy\n"); 3527160820dSYifeng Zhao return ret; 3537160820dSYifeng Zhao } 3547160820dSYifeng Zhao 3557160820dSYifeng Zhao priv->phy = devm_phy_create(dev, NULL, &rochchip_combphy_ops); 3567160820dSYifeng Zhao if (IS_ERR(priv->phy)) { 3577160820dSYifeng Zhao dev_err(dev, "failed to create combphy\n"); 3587160820dSYifeng Zhao return PTR_ERR(priv->phy); 3597160820dSYifeng Zhao } 3607160820dSYifeng Zhao 3617160820dSYifeng Zhao dev_set_drvdata(dev, priv); 3627160820dSYifeng Zhao phy_set_drvdata(priv->phy, priv); 3637160820dSYifeng Zhao 3647160820dSYifeng Zhao phy_provider = devm_of_phy_provider_register(dev, rockchip_combphy_xlate); 3657160820dSYifeng Zhao 3667160820dSYifeng Zhao return PTR_ERR_OR_ZERO(phy_provider); 3677160820dSYifeng Zhao } 3687160820dSYifeng Zhao 3697160820dSYifeng Zhao static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv) 3707160820dSYifeng Zhao { 3717160820dSYifeng Zhao const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; 3727160820dSYifeng Zhao unsigned long rate; 3737160820dSYifeng Zhao u32 val; 3747160820dSYifeng Zhao 3757160820dSYifeng Zhao switch (priv->type) { 3767160820dSYifeng Zhao case PHY_TYPE_PCIE: 3777160820dSYifeng Zhao /* Set SSC downward spread spectrum. */ 3787160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, 3797160820dSYifeng Zhao PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT, 3807160820dSYifeng Zhao PHYREG32); 3817160820dSYifeng Zhao 3827160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_pcie, true); 3837160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_pcie, true); 3847160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_pcie, true); 3857160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_pcie, true); 3867160820dSYifeng Zhao break; 3877160820dSYifeng Zhao 3887160820dSYifeng Zhao case PHY_TYPE_USB3: 3897160820dSYifeng Zhao /* Set SSC downward spread spectrum. */ 3907160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, 3917160820dSYifeng Zhao PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT, 3927160820dSYifeng Zhao PHYREG32); 3937160820dSYifeng Zhao 3947160820dSYifeng Zhao /* Enable adaptive CTLE for USB3.0 Rx. */ 3957160820dSYifeng Zhao val = readl(priv->mmio + PHYREG15); 3967160820dSYifeng Zhao val |= PHYREG15_CTLE_EN; 3977160820dSYifeng Zhao writel(val, priv->mmio + PHYREG15); 3987160820dSYifeng Zhao 3997160820dSYifeng Zhao /* Set PLL KVCO fine tuning signals. */ 4007160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK, 4017160820dSYifeng Zhao PHYREG33_PLL_KVCO_VALUE << PHYREG33_PLL_KVCO_SHIFT, 4027160820dSYifeng Zhao PHYREG33); 4037160820dSYifeng Zhao 4047160820dSYifeng Zhao /* Enable controlling random jitter. */ 4057160820dSYifeng Zhao writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12); 4067160820dSYifeng Zhao 4077160820dSYifeng Zhao /* Set PLL input clock divider 1/2. */ 4087160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG6_PLL_DIV_MASK, 4097160820dSYifeng Zhao PHYREG6_PLL_DIV_2 << PHYREG6_PLL_DIV_SHIFT, 4107160820dSYifeng Zhao PHYREG6); 4117160820dSYifeng Zhao 4127160820dSYifeng Zhao writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18); 4137160820dSYifeng Zhao writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11); 4147160820dSYifeng Zhao 4157160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_sel_usb, true); 4167160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false); 4177160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false); 4187160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->usb_mode_set, true); 4197160820dSYifeng Zhao break; 4207160820dSYifeng Zhao 4217160820dSYifeng Zhao case PHY_TYPE_SATA: 4227160820dSYifeng Zhao /* Enable adaptive CTLE for SATA Rx. */ 4237160820dSYifeng Zhao val = readl(priv->mmio + PHYREG15); 4247160820dSYifeng Zhao val |= PHYREG15_CTLE_EN; 4257160820dSYifeng Zhao writel(val, priv->mmio + PHYREG15); 4267160820dSYifeng Zhao /* 4277160820dSYifeng Zhao * Set tx_rterm=50ohm and rx_rterm=44ohm for SATA. 4287160820dSYifeng Zhao * 0: 60ohm, 8: 50ohm 15: 44ohm (by step abort 1ohm) 4297160820dSYifeng Zhao */ 4307160820dSYifeng Zhao val = PHYREG7_TX_RTERM_50OHM << PHYREG7_TX_RTERM_SHIFT; 4317160820dSYifeng Zhao val |= PHYREG7_RX_RTERM_44OHM << PHYREG7_RX_RTERM_SHIFT; 4327160820dSYifeng Zhao writel(val, priv->mmio + PHYREG7); 4337160820dSYifeng Zhao 4347160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_sata, true); 4357160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_sata, true); 4367160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_sata, true); 4377160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_sata, true); 4387160820dSYifeng Zhao rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true); 4397160820dSYifeng Zhao break; 4407160820dSYifeng Zhao 4417160820dSYifeng Zhao case PHY_TYPE_SGMII: 4427160820dSYifeng Zhao rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true); 4437160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true); 4447160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true); 4457160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->sgmii_mode_set, true); 4467160820dSYifeng Zhao break; 4477160820dSYifeng Zhao 4487160820dSYifeng Zhao case PHY_TYPE_QSGMII: 4497160820dSYifeng Zhao rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_xpcs_phy_ready, true); 4507160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_phymode_sel, true); 4517160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_rate_sel, true); 4527160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_sel_qsgmii, true); 4537160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->qsgmii_mode_set, true); 4547160820dSYifeng Zhao break; 4557160820dSYifeng Zhao 4567160820dSYifeng Zhao default: 4577160820dSYifeng Zhao dev_err(priv->dev, "incompatible PHY type\n"); 4587160820dSYifeng Zhao return -EINVAL; 4597160820dSYifeng Zhao } 4607160820dSYifeng Zhao 4617160820dSYifeng Zhao rate = clk_get_rate(priv->refclk); 4627160820dSYifeng Zhao 4637160820dSYifeng Zhao switch (rate) { 4647160820dSYifeng Zhao case REF_CLOCK_24MHz: 4657160820dSYifeng Zhao if (priv->type == PHY_TYPE_USB3 || priv->type == PHY_TYPE_SATA) { 4667160820dSYifeng Zhao /* Set ssc_cnt[9:0]=0101111101 & 31.5KHz. */ 4677160820dSYifeng Zhao val = PHYREG15_SSC_CNT_VALUE << PHYREG15_SSC_CNT_SHIFT; 4687160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG15_SSC_CNT_MASK, 4697160820dSYifeng Zhao val, PHYREG15); 4707160820dSYifeng Zhao 4717160820dSYifeng Zhao writel(PHYREG16_SSC_CNT_VALUE, priv->mmio + PHYREG16); 4727160820dSYifeng Zhao } 4737160820dSYifeng Zhao break; 4747160820dSYifeng Zhao 4757160820dSYifeng Zhao case REF_CLOCK_25MHz: 4767160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_25m, true); 4777160820dSYifeng Zhao break; 4787160820dSYifeng Zhao 4797160820dSYifeng Zhao case REF_CLOCK_100MHz: 4807160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_100m, true); 4817160820dSYifeng Zhao if (priv->type == PHY_TYPE_PCIE) { 4827160820dSYifeng Zhao /* PLL KVCO fine tuning. */ 4837160820dSYifeng Zhao val = PHYREG33_PLL_KVCO_VALUE << PHYREG33_PLL_KVCO_SHIFT; 4847160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK, 4857160820dSYifeng Zhao val, PHYREG33); 4867160820dSYifeng Zhao 4877160820dSYifeng Zhao /* Enable controlling random jitter. */ 4887160820dSYifeng Zhao writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12); 4897160820dSYifeng Zhao 4907160820dSYifeng Zhao val = PHYREG6_PLL_DIV_2 << PHYREG6_PLL_DIV_SHIFT; 4917160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG6_PLL_DIV_MASK, 4927160820dSYifeng Zhao val, PHYREG6); 4937160820dSYifeng Zhao 4947160820dSYifeng Zhao writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18); 4957160820dSYifeng Zhao writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11); 4967160820dSYifeng Zhao } else if (priv->type == PHY_TYPE_SATA) { 4977160820dSYifeng Zhao /* downward spread spectrum +500ppm */ 4987160820dSYifeng Zhao val = PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT; 4997160820dSYifeng Zhao val |= PHYREG32_SSC_OFFSET_500PPM << PHYREG32_SSC_OFFSET_SHIFT; 5007160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, val, PHYREG32); 5017160820dSYifeng Zhao } 5027160820dSYifeng Zhao break; 5037160820dSYifeng Zhao 5047160820dSYifeng Zhao default: 5057160820dSYifeng Zhao dev_err(priv->dev, "unsupported rate: %lu\n", rate); 5067160820dSYifeng Zhao return -EINVAL; 5077160820dSYifeng Zhao } 5087160820dSYifeng Zhao 5097160820dSYifeng Zhao if (priv->ext_refclk) { 5107160820dSYifeng Zhao rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_ext, true); 5117160820dSYifeng Zhao if (priv->type == PHY_TYPE_PCIE && rate == REF_CLOCK_100MHz) { 5127160820dSYifeng Zhao val = PHYREG13_RESISTER_HIGH_Z << PHYREG13_RESISTER_SHIFT; 5137160820dSYifeng Zhao val |= PHYREG13_CKRCV_AMP0; 5147160820dSYifeng Zhao rockchip_combphy_updatel(priv, PHYREG13_RESISTER_MASK, val, PHYREG13); 5157160820dSYifeng Zhao 5167160820dSYifeng Zhao val = readl(priv->mmio + PHYREG14); 5177160820dSYifeng Zhao val |= PHYREG14_CKRCV_AMP1; 5187160820dSYifeng Zhao writel(val, priv->mmio + PHYREG14); 5197160820dSYifeng Zhao } 5207160820dSYifeng Zhao } 5217160820dSYifeng Zhao 5227160820dSYifeng Zhao if (priv->enable_ssc) { 5237160820dSYifeng Zhao val = readl(priv->mmio + PHYREG8); 5247160820dSYifeng Zhao val |= PHYREG8_SSC_EN; 5257160820dSYifeng Zhao writel(val, priv->mmio + PHYREG8); 5267160820dSYifeng Zhao } 5277160820dSYifeng Zhao 5287160820dSYifeng Zhao return 0; 5297160820dSYifeng Zhao } 5307160820dSYifeng Zhao 5317160820dSYifeng Zhao static const struct rockchip_combphy_grfcfg rk3568_combphy_grfcfgs = { 5327160820dSYifeng Zhao /* pipe-phy-grf */ 5337160820dSYifeng Zhao .pcie_mode_set = { 0x0000, 5, 0, 0x00, 0x11 }, 5347160820dSYifeng Zhao .usb_mode_set = { 0x0000, 5, 0, 0x00, 0x04 }, 5357160820dSYifeng Zhao .sgmii_mode_set = { 0x0000, 5, 0, 0x00, 0x01 }, 5367160820dSYifeng Zhao .qsgmii_mode_set = { 0x0000, 5, 0, 0x00, 0x21 }, 5377160820dSYifeng Zhao .pipe_rxterm_set = { 0x0000, 12, 12, 0x00, 0x01 }, 5387160820dSYifeng Zhao .pipe_txelec_set = { 0x0004, 1, 1, 0x00, 0x01 }, 5397160820dSYifeng Zhao .pipe_txcomp_set = { 0x0004, 4, 4, 0x00, 0x01 }, 5407160820dSYifeng Zhao .pipe_clk_25m = { 0x0004, 14, 13, 0x00, 0x01 }, 5417160820dSYifeng Zhao .pipe_clk_100m = { 0x0004, 14, 13, 0x00, 0x02 }, 5427160820dSYifeng Zhao .pipe_phymode_sel = { 0x0008, 1, 1, 0x00, 0x01 }, 5437160820dSYifeng Zhao .pipe_rate_sel = { 0x0008, 2, 2, 0x00, 0x01 }, 5447160820dSYifeng Zhao .pipe_rxterm_sel = { 0x0008, 8, 8, 0x00, 0x01 }, 5457160820dSYifeng Zhao .pipe_txelec_sel = { 0x0008, 12, 12, 0x00, 0x01 }, 5467160820dSYifeng Zhao .pipe_txcomp_sel = { 0x0008, 15, 15, 0x00, 0x01 }, 5477160820dSYifeng Zhao .pipe_clk_ext = { 0x000c, 9, 8, 0x02, 0x01 }, 5487160820dSYifeng Zhao .pipe_sel_usb = { 0x000c, 14, 13, 0x00, 0x01 }, 5497160820dSYifeng Zhao .pipe_sel_qsgmii = { 0x000c, 15, 13, 0x00, 0x07 }, 5507160820dSYifeng Zhao .pipe_phy_status = { 0x0034, 6, 6, 0x01, 0x00 }, 5517160820dSYifeng Zhao .con0_for_pcie = { 0x0000, 15, 0, 0x00, 0x1000 }, 5527160820dSYifeng Zhao .con1_for_pcie = { 0x0004, 15, 0, 0x00, 0x0000 }, 5537160820dSYifeng Zhao .con2_for_pcie = { 0x0008, 15, 0, 0x00, 0x0101 }, 5547160820dSYifeng Zhao .con3_for_pcie = { 0x000c, 15, 0, 0x00, 0x0200 }, 5557160820dSYifeng Zhao .con0_for_sata = { 0x0000, 15, 0, 0x00, 0x0119 }, 5567160820dSYifeng Zhao .con1_for_sata = { 0x0004, 15, 0, 0x00, 0x0040 }, 5577160820dSYifeng Zhao .con2_for_sata = { 0x0008, 15, 0, 0x00, 0x80c3 }, 5587160820dSYifeng Zhao .con3_for_sata = { 0x000c, 15, 0, 0x00, 0x4407 }, 5597160820dSYifeng Zhao /* pipe-grf */ 5607160820dSYifeng Zhao .pipe_con0_for_sata = { 0x0000, 15, 0, 0x00, 0x2220 }, 5617160820dSYifeng Zhao .pipe_xpcs_phy_ready = { 0x0040, 2, 2, 0x00, 0x01 }, 5627160820dSYifeng Zhao }; 5637160820dSYifeng Zhao 5647160820dSYifeng Zhao static const struct rockchip_combphy_cfg rk3568_combphy_cfgs = { 5657160820dSYifeng Zhao .grfcfg = &rk3568_combphy_grfcfgs, 5667160820dSYifeng Zhao .combphy_cfg = rk3568_combphy_cfg, 5677160820dSYifeng Zhao }; 5687160820dSYifeng Zhao 569a03c4427SLucas Tanure static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv) 570a03c4427SLucas Tanure { 571a03c4427SLucas Tanure const struct rockchip_combphy_grfcfg *cfg = priv->cfg->grfcfg; 572a03c4427SLucas Tanure unsigned long rate; 573a03c4427SLucas Tanure u32 val; 574a03c4427SLucas Tanure 575a03c4427SLucas Tanure switch (priv->type) { 576a03c4427SLucas Tanure case PHY_TYPE_PCIE: 577a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_pcie, true); 578a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_pcie, true); 579a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_pcie, true); 580a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_pcie, true); 581a03c4427SLucas Tanure rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_pcie1l0_sel, true); 582a03c4427SLucas Tanure rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_pcie1l1_sel, true); 583a03c4427SLucas Tanure break; 584a03c4427SLucas Tanure case PHY_TYPE_USB3: 585a03c4427SLucas Tanure /* Set SSC downward spread spectrum */ 586a03c4427SLucas Tanure rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, 587a03c4427SLucas Tanure PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT, 588a03c4427SLucas Tanure PHYREG32); 589a03c4427SLucas Tanure 590a03c4427SLucas Tanure /* Enable adaptive CTLE for USB3.0 Rx. */ 591a03c4427SLucas Tanure val = readl(priv->mmio + PHYREG15); 592a03c4427SLucas Tanure val |= PHYREG15_CTLE_EN; 593a03c4427SLucas Tanure writel(val, priv->mmio + PHYREG15); 594a03c4427SLucas Tanure 595a03c4427SLucas Tanure /* Set PLL KVCO fine tuning signals. */ 596a03c4427SLucas Tanure rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK, 597a03c4427SLucas Tanure PHYREG33_PLL_KVCO_VALUE << PHYREG33_PLL_KVCO_SHIFT, 598a03c4427SLucas Tanure PHYREG33); 599a03c4427SLucas Tanure 600a03c4427SLucas Tanure /* Enable controlling random jitter. */ 601a03c4427SLucas Tanure writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12); 602a03c4427SLucas Tanure 603a03c4427SLucas Tanure /* Set PLL input clock divider 1/2. */ 604a03c4427SLucas Tanure rockchip_combphy_updatel(priv, PHYREG6_PLL_DIV_MASK, 605a03c4427SLucas Tanure PHYREG6_PLL_DIV_2 << PHYREG6_PLL_DIV_SHIFT, 606a03c4427SLucas Tanure PHYREG6); 607a03c4427SLucas Tanure 608a03c4427SLucas Tanure writel(PHYREG18_PLL_LOOP, priv->mmio + PHYREG18); 609a03c4427SLucas Tanure writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11); 610a03c4427SLucas Tanure 611a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txcomp_sel, false); 612a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_txelec_sel, false); 613a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->usb_mode_set, true); 614a03c4427SLucas Tanure break; 615a03c4427SLucas Tanure case PHY_TYPE_SATA: 616a03c4427SLucas Tanure /* Enable adaptive CTLE for SATA Rx. */ 617a03c4427SLucas Tanure val = readl(priv->mmio + PHYREG15); 618a03c4427SLucas Tanure val |= PHYREG15_CTLE_EN; 619a03c4427SLucas Tanure writel(val, priv->mmio + PHYREG15); 620a03c4427SLucas Tanure /* 621a03c4427SLucas Tanure * Set tx_rterm=50ohm and rx_rterm=44ohm for SATA. 622a03c4427SLucas Tanure * 0: 60ohm, 8: 50ohm 15: 44ohm (by step abort 1ohm) 623a03c4427SLucas Tanure */ 624a03c4427SLucas Tanure val = PHYREG7_TX_RTERM_50OHM << PHYREG7_TX_RTERM_SHIFT; 625a03c4427SLucas Tanure val |= PHYREG7_RX_RTERM_44OHM << PHYREG7_RX_RTERM_SHIFT; 626a03c4427SLucas Tanure writel(val, priv->mmio + PHYREG7); 627a03c4427SLucas Tanure 628a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con0_for_sata, true); 629a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con1_for_sata, true); 630a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con2_for_sata, true); 631a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->con3_for_sata, true); 632a03c4427SLucas Tanure rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con0_for_sata, true); 633a03c4427SLucas Tanure rockchip_combphy_param_write(priv->pipe_grf, &cfg->pipe_con1_for_sata, true); 634a03c4427SLucas Tanure break; 635a03c4427SLucas Tanure case PHY_TYPE_SGMII: 636a03c4427SLucas Tanure case PHY_TYPE_QSGMII: 637a03c4427SLucas Tanure default: 638a03c4427SLucas Tanure dev_err(priv->dev, "incompatible PHY type\n"); 639a03c4427SLucas Tanure return -EINVAL; 640a03c4427SLucas Tanure } 641a03c4427SLucas Tanure 642a03c4427SLucas Tanure rate = clk_get_rate(priv->refclk); 643a03c4427SLucas Tanure 644a03c4427SLucas Tanure switch (rate) { 645a03c4427SLucas Tanure case REF_CLOCK_24MHz: 646a03c4427SLucas Tanure if (priv->type == PHY_TYPE_USB3 || priv->type == PHY_TYPE_SATA) { 647a03c4427SLucas Tanure /* Set ssc_cnt[9:0]=0101111101 & 31.5KHz. */ 648a03c4427SLucas Tanure val = PHYREG15_SSC_CNT_VALUE << PHYREG15_SSC_CNT_SHIFT; 649a03c4427SLucas Tanure rockchip_combphy_updatel(priv, PHYREG15_SSC_CNT_MASK, 650a03c4427SLucas Tanure val, PHYREG15); 651a03c4427SLucas Tanure 652a03c4427SLucas Tanure writel(PHYREG16_SSC_CNT_VALUE, priv->mmio + PHYREG16); 653a03c4427SLucas Tanure } 654a03c4427SLucas Tanure break; 655a03c4427SLucas Tanure 656a03c4427SLucas Tanure case REF_CLOCK_25MHz: 657a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_25m, true); 658a03c4427SLucas Tanure break; 659a03c4427SLucas Tanure case REF_CLOCK_100MHz: 660a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_100m, true); 661a03c4427SLucas Tanure if (priv->type == PHY_TYPE_PCIE) { 662a03c4427SLucas Tanure /* PLL KVCO fine tuning. */ 663a03c4427SLucas Tanure val = 4 << PHYREG33_PLL_KVCO_SHIFT; 664a03c4427SLucas Tanure rockchip_combphy_updatel(priv, PHYREG33_PLL_KVCO_MASK, 665a03c4427SLucas Tanure val, PHYREG33); 666a03c4427SLucas Tanure 667a03c4427SLucas Tanure /* Enable controlling random jitter. */ 668a03c4427SLucas Tanure writel(PHYREG12_PLL_LPF_ADJ_VALUE, priv->mmio + PHYREG12); 669a03c4427SLucas Tanure 670a03c4427SLucas Tanure /* Set up rx_trim: PLL LPF C1 85pf R1 1.25kohm */ 671a03c4427SLucas Tanure writel(PHYREG27_RX_TRIM_RK3588, priv->mmio + PHYREG27); 672a03c4427SLucas Tanure 673a03c4427SLucas Tanure /* Set up su_trim: */ 674a03c4427SLucas Tanure writel(PHYREG11_SU_TRIM_0_7, priv->mmio + PHYREG11); 675a03c4427SLucas Tanure } else if (priv->type == PHY_TYPE_SATA) { 676a03c4427SLucas Tanure /* downward spread spectrum +500ppm */ 677a03c4427SLucas Tanure val = PHYREG32_SSC_DOWNWARD << PHYREG32_SSC_DIR_SHIFT; 678a03c4427SLucas Tanure val |= PHYREG32_SSC_OFFSET_500PPM << PHYREG32_SSC_OFFSET_SHIFT; 679a03c4427SLucas Tanure rockchip_combphy_updatel(priv, PHYREG32_SSC_MASK, val, PHYREG32); 680a03c4427SLucas Tanure } 681a03c4427SLucas Tanure break; 682a03c4427SLucas Tanure default: 683a03c4427SLucas Tanure dev_err(priv->dev, "Unsupported rate: %lu\n", rate); 684a03c4427SLucas Tanure return -EINVAL; 685a03c4427SLucas Tanure } 686a03c4427SLucas Tanure 687a03c4427SLucas Tanure if (priv->ext_refclk) { 688a03c4427SLucas Tanure rockchip_combphy_param_write(priv->phy_grf, &cfg->pipe_clk_ext, true); 689a03c4427SLucas Tanure if (priv->type == PHY_TYPE_PCIE && rate == REF_CLOCK_100MHz) { 690a03c4427SLucas Tanure val = PHYREG13_RESISTER_HIGH_Z << PHYREG13_RESISTER_SHIFT; 691a03c4427SLucas Tanure val |= PHYREG13_CKRCV_AMP0; 692a03c4427SLucas Tanure rockchip_combphy_updatel(priv, PHYREG13_RESISTER_MASK, val, PHYREG13); 693a03c4427SLucas Tanure 694a03c4427SLucas Tanure val = readl(priv->mmio + PHYREG14); 695a03c4427SLucas Tanure val |= PHYREG14_CKRCV_AMP1; 696a03c4427SLucas Tanure writel(val, priv->mmio + PHYREG14); 697a03c4427SLucas Tanure } 698a03c4427SLucas Tanure } 699a03c4427SLucas Tanure 700a03c4427SLucas Tanure if (priv->enable_ssc) { 701a03c4427SLucas Tanure val = readl(priv->mmio + PHYREG8); 702a03c4427SLucas Tanure val |= PHYREG8_SSC_EN; 703a03c4427SLucas Tanure writel(val, priv->mmio + PHYREG8); 704a03c4427SLucas Tanure } 705a03c4427SLucas Tanure 706a03c4427SLucas Tanure return 0; 707a03c4427SLucas Tanure } 708a03c4427SLucas Tanure 709a03c4427SLucas Tanure static const struct rockchip_combphy_grfcfg rk3588_combphy_grfcfgs = { 710a03c4427SLucas Tanure /* pipe-phy-grf */ 711a03c4427SLucas Tanure .pcie_mode_set = { 0x0000, 5, 0, 0x00, 0x11 }, 712a03c4427SLucas Tanure .usb_mode_set = { 0x0000, 5, 0, 0x00, 0x04 }, 713a03c4427SLucas Tanure .pipe_rxterm_set = { 0x0000, 12, 12, 0x00, 0x01 }, 714a03c4427SLucas Tanure .pipe_txelec_set = { 0x0004, 1, 1, 0x00, 0x01 }, 715a03c4427SLucas Tanure .pipe_txcomp_set = { 0x0004, 4, 4, 0x00, 0x01 }, 716a03c4427SLucas Tanure .pipe_clk_25m = { 0x0004, 14, 13, 0x00, 0x01 }, 717a03c4427SLucas Tanure .pipe_clk_100m = { 0x0004, 14, 13, 0x00, 0x02 }, 718a03c4427SLucas Tanure .pipe_rxterm_sel = { 0x0008, 8, 8, 0x00, 0x01 }, 719a03c4427SLucas Tanure .pipe_txelec_sel = { 0x0008, 12, 12, 0x00, 0x01 }, 720a03c4427SLucas Tanure .pipe_txcomp_sel = { 0x0008, 15, 15, 0x00, 0x01 }, 721a03c4427SLucas Tanure .pipe_clk_ext = { 0x000c, 9, 8, 0x02, 0x01 }, 722a03c4427SLucas Tanure .pipe_phy_status = { 0x0034, 6, 6, 0x01, 0x00 }, 723a03c4427SLucas Tanure .con0_for_pcie = { 0x0000, 15, 0, 0x00, 0x1000 }, 724a03c4427SLucas Tanure .con1_for_pcie = { 0x0004, 15, 0, 0x00, 0x0000 }, 725a03c4427SLucas Tanure .con2_for_pcie = { 0x0008, 15, 0, 0x00, 0x0101 }, 726a03c4427SLucas Tanure .con3_for_pcie = { 0x000c, 15, 0, 0x00, 0x0200 }, 727a03c4427SLucas Tanure .con0_for_sata = { 0x0000, 15, 0, 0x00, 0x0129 }, 728a03c4427SLucas Tanure .con1_for_sata = { 0x0004, 15, 0, 0x00, 0x0000 }, 729a03c4427SLucas Tanure .con2_for_sata = { 0x0008, 15, 0, 0x00, 0x80c1 }, 730a03c4427SLucas Tanure .con3_for_sata = { 0x000c, 15, 0, 0x00, 0x0407 }, 731a03c4427SLucas Tanure /* pipe-grf */ 732a03c4427SLucas Tanure .pipe_con0_for_sata = { 0x0000, 11, 5, 0x00, 0x22 }, 733a03c4427SLucas Tanure .pipe_con1_for_sata = { 0x0000, 2, 0, 0x00, 0x2 }, 734a03c4427SLucas Tanure .pipe_pcie1l0_sel = { 0x0100, 0, 0, 0x01, 0x0 }, 735a03c4427SLucas Tanure .pipe_pcie1l1_sel = { 0x0100, 1, 1, 0x01, 0x0 }, 736a03c4427SLucas Tanure }; 737a03c4427SLucas Tanure 738a03c4427SLucas Tanure static const struct rockchip_combphy_cfg rk3588_combphy_cfgs = { 739a03c4427SLucas Tanure .grfcfg = &rk3588_combphy_grfcfgs, 740a03c4427SLucas Tanure .combphy_cfg = rk3588_combphy_cfg, 741a03c4427SLucas Tanure }; 742a03c4427SLucas Tanure 7437160820dSYifeng Zhao static const struct of_device_id rockchip_combphy_of_match[] = { 7447160820dSYifeng Zhao { 7457160820dSYifeng Zhao .compatible = "rockchip,rk3568-naneng-combphy", 7467160820dSYifeng Zhao .data = &rk3568_combphy_cfgs, 7477160820dSYifeng Zhao }, 748a03c4427SLucas Tanure { 749a03c4427SLucas Tanure .compatible = "rockchip,rk3588-naneng-combphy", 750a03c4427SLucas Tanure .data = &rk3588_combphy_cfgs, 751a03c4427SLucas Tanure }, 7527160820dSYifeng Zhao { }, 7537160820dSYifeng Zhao }; 7547160820dSYifeng Zhao MODULE_DEVICE_TABLE(of, rockchip_combphy_of_match); 7557160820dSYifeng Zhao 7567160820dSYifeng Zhao static struct platform_driver rockchip_combphy_driver = { 7577160820dSYifeng Zhao .probe = rockchip_combphy_probe, 7587160820dSYifeng Zhao .driver = { 7597160820dSYifeng Zhao .name = "rockchip-naneng-combphy", 7607160820dSYifeng Zhao .of_match_table = rockchip_combphy_of_match, 7617160820dSYifeng Zhao }, 7627160820dSYifeng Zhao }; 7637160820dSYifeng Zhao module_platform_driver(rockchip_combphy_driver); 7647160820dSYifeng Zhao 7657160820dSYifeng Zhao MODULE_DESCRIPTION("Rockchip NANENG COMBPHY driver"); 7667160820dSYifeng Zhao MODULE_LICENSE("GPL v2"); 767