Skip to content

Commit a1fe1ec

Browse files
floatiousvinodkoul
authored andcommitted
phy: rockchip-snps-pcie3: add support for rockchip,rx-common-refclk-mode
>From the RK3588 Technical Reference Manual, Part1, section 6.19 PCIe3PHY_GRF Register Description: "rxX_cmn_refclk_mode" RX common reference clock mode for lane X. This mode should be enabled only when the far-end and near-end devices are running with a common reference clock. The hardware reset value for this field is 0x1 (enabled). Note that this register field is only available on RK3588, not on RK3568. The link training either fails or is highly unstable (link state will jump continuously between L0 and recovery) when this mode is enabled while using an endpoint running in Separate Reference Clock with No SSC (SRNS) mode or Separate Reference Clock with SSC (SRIS) mode. (Which is usually the case when using a real SoC as endpoint, e.g. the RK3588 PCIe controller can run in both Root Complex and Endpoint mode.) Add support for the device tree property rockchip,rx-common-refclk-mode, such that the PCIe PHY can be used in configurations where the Root Complex and Endpoint are not using a common reference clock. Signed-off-by: Niklas Cassel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 46492d1 commit a1fe1ec

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

drivers/phy/rockchip/phy-rockchip-snps-pcie3.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@
3535
#define RK3588_PCIE3PHY_GRF_CMN_CON0 0x0
3636
#define RK3588_PCIE3PHY_GRF_PHY0_STATUS1 0x904
3737
#define RK3588_PCIE3PHY_GRF_PHY1_STATUS1 0xa04
38+
#define RK3588_PCIE3PHY_GRF_PHY0_LN0_CON1 0x1004
39+
#define RK3588_PCIE3PHY_GRF_PHY0_LN1_CON1 0x1104
40+
#define RK3588_PCIE3PHY_GRF_PHY1_LN0_CON1 0x2004
41+
#define RK3588_PCIE3PHY_GRF_PHY1_LN1_CON1 0x2104
3842
#define RK3588_SRAM_INIT_DONE(reg) (reg & BIT(0))
3943

4044
#define RK3588_BIFURCATION_LANE_0_1 BIT(0)
4145
#define RK3588_BIFURCATION_LANE_2_3 BIT(1)
4246
#define RK3588_LANE_AGGREGATION BIT(2)
47+
#define RK3588_RX_CMN_REFCLK_MODE_EN ((BIT(7) << 16) | BIT(7))
48+
#define RK3588_RX_CMN_REFCLK_MODE_DIS (BIT(7) << 16)
4349
#define RK3588_PCIE1LN_SEL_EN (GENMASK(1, 0) << 16)
4450
#define RK3588_PCIE30_PHY_MODE_EN (GENMASK(2, 0) << 16)
4551

@@ -60,6 +66,7 @@ struct rockchip_p3phy_priv {
6066
int num_clks;
6167
int num_lanes;
6268
u32 lanes[4];
69+
u32 rx_cmn_refclk_mode[4];
6370
};
6471

6572
struct rockchip_p3phy_ops {
@@ -137,6 +144,19 @@ static int rockchip_p3phy_rk3588_init(struct rockchip_p3phy_priv *priv)
137144
u8 mode = RK3588_LANE_AGGREGATION; /* default */
138145
int ret;
139146

147+
regmap_write(priv->phy_grf, RK3588_PCIE3PHY_GRF_PHY0_LN0_CON1,
148+
priv->rx_cmn_refclk_mode[0] ? RK3588_RX_CMN_REFCLK_MODE_EN :
149+
RK3588_RX_CMN_REFCLK_MODE_DIS);
150+
regmap_write(priv->phy_grf, RK3588_PCIE3PHY_GRF_PHY0_LN1_CON1,
151+
priv->rx_cmn_refclk_mode[1] ? RK3588_RX_CMN_REFCLK_MODE_EN :
152+
RK3588_RX_CMN_REFCLK_MODE_DIS);
153+
regmap_write(priv->phy_grf, RK3588_PCIE3PHY_GRF_PHY1_LN0_CON1,
154+
priv->rx_cmn_refclk_mode[2] ? RK3588_RX_CMN_REFCLK_MODE_EN :
155+
RK3588_RX_CMN_REFCLK_MODE_DIS);
156+
regmap_write(priv->phy_grf, RK3588_PCIE3PHY_GRF_PHY1_LN1_CON1,
157+
priv->rx_cmn_refclk_mode[3] ? RK3588_RX_CMN_REFCLK_MODE_EN :
158+
RK3588_RX_CMN_REFCLK_MODE_DIS);
159+
140160
/* Deassert PCIe PMA output clamp mode */
141161
regmap_write(priv->phy_grf, RK3588_PCIE3PHY_GRF_CMN_CON0, BIT(8) | BIT(24));
142162

@@ -275,6 +295,23 @@ static int rockchip_p3phy_probe(struct platform_device *pdev)
275295
return priv->num_lanes;
276296
}
277297

298+
ret = of_property_read_variable_u32_array(dev->of_node,
299+
"rockchip,rx-common-refclk-mode",
300+
priv->rx_cmn_refclk_mode, 1,
301+
ARRAY_SIZE(priv->rx_cmn_refclk_mode));
302+
/*
303+
* if no rockchip,rx-common-refclk-mode, assume enabled for all lanes in
304+
* order to be DT backwards compatible. (Since HW reset val is enabled.)
305+
*/
306+
if (ret == -EINVAL) {
307+
for (int i = 0; i < ARRAY_SIZE(priv->rx_cmn_refclk_mode); i++)
308+
priv->rx_cmn_refclk_mode[i] = 1;
309+
} else if (ret < 0) {
310+
dev_err(dev, "failed to read rockchip,rx-common-refclk-mode property %d\n",
311+
ret);
312+
return ret;
313+
}
314+
278315
priv->phy = devm_phy_create(dev, NULL, &rockchip_p3phy_ops);
279316
if (IS_ERR(priv->phy)) {
280317
dev_err(dev, "failed to create combphy\n");

0 commit comments

Comments
 (0)