phy: rockchip: snps-pcie3: Updating the driver from the kernel repository
Subsystems (2)
PATCH 1/1 phy: rockchip: snps-pcie3: Updating the driver from the kernel repository
This patch replaces the driver code from the Linux kernel repository, specifically to handle the new device tree binding "rockchip,rx-common-refclk-mode".
Signed-off-by Alexander Shiyan <[email protected]>
--- .../phy/rockchip/phy-rockchip-snps-pcie3.c | 92 ++++++++++++------- 1 file changed, 57 insertions(+), 35 deletions(-)
drivers/phy/rockchip/phy-rockchip-snps-pcie3.c +57 -35
@@ -11,7 +11,6 @@#include <linux/io.h> #include <linux/iopoll.h> #include <linux/kernel.h> -//#include <linux/phy/pcie.h> #include <mfd/syscon.h> #include <linux/phy/phy.h> #include <linux/regmap.h>
@@ -33,11 +32,19 @@#define RK3588_PCIE3PHY_GRF_CMN_CON0 0x0#define RK3588_PCIE3PHY_GRF_PHY0_STATUS1 0x904#define RK3588_PCIE3PHY_GRF_PHY1_STATUS1 0xa04 +#define RK3588_PCIE3PHY_GRF_PHY0_LN0_CON1 0x1004 +#define RK3588_PCIE3PHY_GRF_PHY0_LN1_CON1 0x1104 +#define RK3588_PCIE3PHY_GRF_PHY1_LN0_CON1 0x2004 +#define RK3588_PCIE3PHY_GRF_PHY1_LN1_CON1 0x2104#define RK3588_SRAM_INIT_DONE (reg) (reg & BIT(0))#define RK3588_BIFURCATION_LANE_0_1 BIT(0)#define RK3588_BIFURCATION_LANE_2_3 BIT(1)#define RK3588_LANE_AGGREGATION BIT(2) +#define RK3588_RX_CMN_REFCLK_MODE_EN ((BIT(7) << 16) | BIT(7)) +#define RK3588_RX_CMN_REFCLK_MODE_DIS (BIT(7) << 16) +#define RK3588_PCIE1LN_SEL_EN (GENMASK(1, 0) << 16) +#define RK3588_PCIE30_PHY_MODE_EN (GENMASK(2, 0) << 16)struct rockchip_p3phy_ops ;
@@ -56,6 +63,7 @@ struct rockchip_p3phy_priv {int num_clks;int num_lanes;u32 lanes[4 ]; +u32 rx_cmn_refclk_mode[4 ]; };struct rockchip_p3phy_ops {
@@ -115,39 +123,45 @@ static const struct rockchip_p3phy_ops rk3568_ops = {static int rockchip_p3phy_rk3588_init (struct rockchip_p3phy_priv *priv) {u32 reg =0 ; -u8 mode =0 ; +u8 mode =RK3588_LANE_AGGREGATION ;/* default */ int ret; +regmap_write (priv->phy_grf,RK3588_PCIE3PHY_GRF_PHY0_LN0_CON1 , + priv->rx_cmn_refclk_mode[0 ] ?RK3588_RX_CMN_REFCLK_MODE_EN : +RK3588_RX_CMN_REFCLK_MODE_DIS ); +regmap_write (priv->phy_grf,RK3588_PCIE3PHY_GRF_PHY0_LN1_CON1 , + priv->rx_cmn_refclk_mode[1 ] ?RK3588_RX_CMN_REFCLK_MODE_EN : +RK3588_RX_CMN_REFCLK_MODE_DIS ); +regmap_write (priv->phy_grf,RK3588_PCIE3PHY_GRF_PHY1_LN0_CON1 , + priv->rx_cmn_refclk_mode[2 ] ?RK3588_RX_CMN_REFCLK_MODE_EN : +RK3588_RX_CMN_REFCLK_MODE_DIS ); +regmap_write (priv->phy_grf,RK3588_PCIE3PHY_GRF_PHY1_LN1_CON1 , + priv->rx_cmn_refclk_mode[3 ] ?RK3588_RX_CMN_REFCLK_MODE_EN : +RK3588_RX_CMN_REFCLK_MODE_DIS ); +/* Deassert PCIe PMA output clamp mode */ regmap_write (priv->phy_grf,RK3588_PCIE3PHY_GRF_CMN_CON0 ,BIT (8 ) |BIT (24 ));/* Set bifurcation if needed */ for (int i =0 ; i < priv->num_lanes; i++) { -if (!priv->lanes[i]) - mode |= (BIT (i) <<3 ); -if (priv->lanes[i] >1 ) - mode |= (BIT (i) >>1 ); + mode &= ~RK3588_LANE_AGGREGATION ; +if (priv->lanes[i] ==3 ) + mode |=RK3588_BIFURCATION_LANE_0_1 ; +if (priv->lanes[i] ==4 ) + mode |=RK3588_BIFURCATION_LANE_2_3 ; } -if (!mode) - reg =RK3588_LANE_AGGREGATION ; -else { -if (mode & (BIT (0 ) |BIT (1 ))) - reg |=RK3588_BIFURCATION_LANE_0_1 ; - -if (mode & (BIT (2 ) |BIT (3 ))) - reg |=RK3588_BIFURCATION_LANE_2_3 ; - } - -regmap_write (priv->phy_grf,RK3588_PCIE3PHY_GRF_CMN_CON0 , (0x7 <<16 ) | reg); + reg = mode; +regmap_write (priv->phy_grf,RK3588_PCIE3PHY_GRF_CMN_CON0 , +RK3588_PCIE30_PHY_MODE_EN | reg);/* Set pcie1ln_sel in PHP_GRF_PCIESEL_CON */ if (!IS_ERR (priv->pipe_grf)) { - reg = (mode & (BIT (6 ) |BIT (7 ))) >>6 ; + reg = mode & (RK3588_BIFURCATION_LANE_0_1 |RK3588_BIFURCATION_LANE_2_3 );if (reg)regmap_write (priv->pipe_grf,PHP_GRF_PCIESEL_CON , - (reg <<16 ) | reg); +RK3588_PCIE1LN_SEL_EN | reg); }reset_control_deassert (priv->p30phy);
@@ -170,7 +184,7 @@ static const struct rockchip_p3phy_ops rk3588_ops = { .phy_init = rockchip_p3phy_rk3588_init, }; -static int rochchip_p3phy_init (struct phy *phy) +static int rockchip_p3phy_init (struct phy *phy) {struct rockchip_p3phy_priv *priv =phy_get_drvdata (phy);int ret;
@@ -193,7 +207,7 @@ static int rochchip_p3phy_init(struct phy *phy)return ret; } -static int rochchip_p3phy_exit (struct phy *phy) +static int rockchip_p3phy_exit (struct phy *phy) {struct rockchip_p3phy_priv *priv =phy_get_drvdata (phy);
@@ -202,20 +216,12 @@ static int rochchip_p3phy_exit(struct phy *phy)return 0 ; } -static const struct phy_ops rochchip_p3phy_ops = { - .init = rochchip_p3phy_init, - .exit = rochchip_p3phy_exit, +static const struct phy_ops rockchip_p3phy_ops = { + .init = rockchip_p3phy_init, + .exit = rockchip_p3phy_exit, .set_mode = rockchip_p3phy_set_mode, }; -static struct phy *rockchip_p3phy_xlate (struct device *dev, -const struct of_phandle_args *args) -{ -struct rockchip_p3phy_priv *priv = dev->priv; - -return priv->phy; -} -static int rockchip_p3phy_probe (struct device *dev) {struct phy_provider *phy_provider;
@@ -274,7 +280,24 @@ static int rockchip_p3phy_probe(struct device *dev)return priv->num_lanes; } - priv->phy =phy_create (dev,NULL , &rochchip_p3phy_ops); + ret =of_property_read_variable_u32_array (dev->of_node, +"rockchip,rx-common-refclk-mode" , + priv->rx_cmn_refclk_mode,1 , +ARRAY_SIZE (priv->rx_cmn_refclk_mode)); +/* +* if no rockchip,rx-common-refclk-mode, assume enabled for all lanes in +* order to be DT backwards compatible. (Since HW reset val is enabled.) +*/ +if (ret == -EINVAL ) { +for (int i =0 ; i <ARRAY_SIZE (priv->rx_cmn_refclk_mode); i++) + priv->rx_cmn_refclk_mode[i] =1 ; + }else if (ret <0 ) { +dev_err (dev,"failed to read rockchip,rx-common-refclk-mode property %d\n" , + ret); +return ret; + } + + priv->phy =phy_create (dev,NULL , &rockchip_p3phy_ops);if (IS_ERR (priv->phy)) {dev_err (dev,"failed to create combphy\n" );return PTR_ERR (priv->phy);
@@ -294,8 +317,7 @@ static int rockchip_p3phy_probe(struct device *dev) dev->priv = priv;phy_set_drvdata (priv->phy, priv); - phy_provider =of_phy_provider_register (dev, rockchip_p3phy_xlate); - + phy_provider =of_phy_provider_register (dev, of_phy_simple_xlate);return PTR_ERR_OR_ZERO (phy_provider); }
Signature · 1 line
2.38.2
Sascha Hauer
AppliedQuoted 5 lines · Alexander Shiyan
This patch replaces the driver code from the Linux kernel repository, specifically to handle the new device tree binding "rockchip,rx-common-refclk-mode".
Applied, thanks!
[1/1] phy: rockchip: snps-pcie3: Updating the driver from the kernel repository
https://git.pengutronix.de/cgit/barebox/commit/?id=0b4a1567cef7 (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>