In preparation for the upcoming rewrite of the driver, rename its symbols to a shorter, consistent naming scheme and reorganize them into functional groups.
The cdns_torrent_* function prefix is shortened to `tp_` (for "Torrent PHY"). The torrent PHY state pointer `cdns_phy` is renamed to `tp_data`, and the per-link instance pointer `inst` is renamed to `link`. The clock-provider, reset, power management, port configuration and DisplayPort helpers are also moved so the following patches have smaller diffs. No functional change intended: this commit only renames symbols and moves functions around. Signed-off-by: Benjamin Robin <[email protected]> --- drivers/phy/cadence/phy-cadence-torrent.c | 1099 ++++++++++++++--------------- 1 file changed, 539 insertions(+), 560 deletions(-) diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c index 9b3ae73c4d78..f7ec31a4c417 100644 --- a/drivers/phy/cadence/phy-cadence-torrent.c +++ b/drivers/phy/cadence/phy-cadence-torrent.c @@ -240,7 +240,7 @@ #define CDNS_TORRENT_OUTPUT_CLOCKS 3 -static const char * const clk_names[] = { +static const char *const tp_clk_names[] = { [CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver", [CDNS_TORRENT_DERIVED_REFCLK] = "refclk-der", [CDNS_TORRENT_RECEIVED_REFCLK] = "refclk-rec", @@ -269,13 +269,12 @@ static const struct reg_field phy_pipe_cmn_ctrl1_0 = REG_FIELD(PHY_PIPE_CMN_CTRL static const struct reg_field cmn_cdiag_refclk_ovrd_4 = REG_FIELD(CMN_CDIAG_REFCLK_OVRD, 4, 4); -#define REFCLK_OUT_NUM_CMN_CONFIG 4 - -enum cdns_torrent_refclk_out_cmn { +enum tp_refclk_out_cmn { CMN_CDIAG_REFCLK_DRV0_CTRL_1, CMN_CDIAG_REFCLK_DRV0_CTRL_4, CMN_CDIAG_REFCLK_DRV0_CTRL_5, CMN_CDIAG_REFCLK_DRV0_CTRL_6, + TP_REFCLK_OUT_NUM_CMN_CONFIG }; static const struct reg_field refclk_out_cmn_cfg[] = { @@ -285,12 +284,41 @@ static const struct reg_field refclk_out_cmn_cfg[] = { [CMN_CDIAG_REFCLK_DRV0_CTRL_6] = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 6, 6), }; -static const int refclk_driver_parent_index[] = { - CDNS_TORRENT_DERIVED_REFCLK, - CDNS_TORRENT_RECEIVED_REFCLK +static const int tp_refclk_driver_parent_idx[] = { + CDNS_TORRENT_DERIVED_REFCLK, CDNS_TORRENT_RECEIVED_REFCLK }; -static const u32 cdns_torrent_refclk_driver_mux_table[] = { 1, 0 }; +static const u32 tp_refclk_driver_mux_table[] = { 1, 0 }; + +struct tp_refclk_driver { + struct clk_hw hw; + struct regmap_field *cmn_fields[TP_REFCLK_OUT_NUM_CMN_CONFIG]; + struct clk_init_data clk_data; + u8 parent_index; +}; + +#define tp_refclk_driver_to_clk_data(_hw) \ + container_of(_hw, struct tp_refclk_driver, hw) + +struct cdns_torrent_derived_refclk { + struct clk_hw hw; + struct regmap_field *phy_pipe_cmn_ctrl1_0; + struct regmap_field *cmn_cdiag_refclk_ovrd_4; + struct clk_init_data clk_data; +}; + +#define to_cdns_torrent_derived_refclk(_hw) \ + container_of(_hw, struct cdns_torrent_derived_refclk, hw) + +struct cdns_torrent_received_refclk { + struct clk_hw hw; + struct regmap_field *phy_pipe_cmn_ctrl1_0; + struct regmap_field *cmn_cdiag_refclk_ovrd_4; + struct clk_init_data clk_data; +}; + +#define to_cdns_torrent_received_refclk(_hw) \ + container_of(_hw, struct cdns_torrent_received_refclk, hw) enum cdns_torrent_phy_type { TYPE_NONE, @@ -344,17 +372,17 @@ enum cdns_torrent_ssc_mode { CDNS_TORRENT_KEY(CLK_ANY, CLK_ANY, \ (link0), (link1), ANY_SSC) -struct cdns_torrent_inst { +struct tp_link { struct phy *phy; - u32 mlane; + struct reset_control *lnk_rst; enum cdns_torrent_phy_type phy_type; + u32 mlane; u32 num_lanes; - struct reset_control *lnk_rst; enum cdns_torrent_ssc_mode ssc_mode; }; -struct cdns_torrent_phy { - void __iomem *base; /* DPTX registers base */ +struct tp_data { + void __iomem *base; /* DPTX registers base */ void __iomem *sd_base; /* SD0801 registers base */ u32 max_bit_rate; /* Maximum link bit rate to use (in Mbps) */ u32 dp_pll; @@ -366,8 +394,8 @@ struct cdns_torrent_phy { struct clk *clk1; enum cdns_torrent_ref_clk ref_clk_rate; enum cdns_torrent_ref_clk ref_clk1_rate; - struct cdns_torrent_inst phys[MAX_NUM_LANES]; - int nsubnodes; + struct tp_link links[MAX_NUM_LANES]; + int nb_links; int already_configured; const struct cdns_torrent_data *init_data; struct regmap *regmap_common_cdb; @@ -395,36 +423,6 @@ enum phy_powerstate { POWERSTATE_A3 = 3, }; -struct cdns_torrent_refclk_driver { - struct clk_hw hw; - struct regmap_field *cmn_fields[REFCLK_OUT_NUM_CMN_CONFIG]; - struct clk_init_data clk_data; - u8 parent_index; -}; - -#define to_cdns_torrent_refclk_driver(_hw) \ - container_of(_hw, struct cdns_torrent_refclk_driver, hw) - -struct cdns_torrent_derived_refclk { - struct clk_hw hw; - struct regmap_field *phy_pipe_cmn_ctrl1_0; - struct regmap_field *cmn_cdiag_refclk_ovrd_4; - struct clk_init_data clk_data; -}; - -#define to_cdns_torrent_derived_refclk(_hw) \ - container_of(_hw, struct cdns_torrent_derived_refclk, hw) - -struct cdns_torrent_received_refclk { - struct clk_hw hw; - struct regmap_field *phy_pipe_cmn_ctrl1_0; - struct regmap_field *cmn_cdiag_refclk_ovrd_4; - struct clk_init_data clk_data; -}; - -#define to_cdns_torrent_received_refclk(_hw) \ - container_of(_hw, struct cdns_torrent_received_refclk, hw) - struct cdns_reg_pairs { u32 val; u32 off; @@ -723,10 +721,10 @@ static const char *cdns_torrent_get_phy_type(enum cdns_torrent_phy_type phy_type * third register values provided by parameters. */ static -void cdns_torrent_dp_enable_ssc_19_2mhz(struct cdns_torrent_phy *cdns_phy, +void cdns_torrent_dp_enable_ssc_19_2mhz(struct tp_data *tp_data, u32 ctrl2_val, u32 ctrl3_val) { - struct regmap *regmap = cdns_phy->regmap_common_cdb; + struct regmap *regmap = tp_data->regmap_common_cdb; cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001); cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val); @@ -739,10 +737,10 @@ void cdns_torrent_dp_enable_ssc_19_2mhz(struct cdns_torrent_phy *cdns_phy, } static -void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy, +void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct tp_data *tp_data, u32 rate, bool ssc) { - struct regmap *regmap = cdns_phy->regmap_common_cdb; + struct regmap *regmap = tp_data->regmap_common_cdb; /* Assumes 19.2 MHz refclock */ switch (rate) { @@ -760,7 +758,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00BC); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0012); if (ssc) - cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x033A, 0x006A); + cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x033A, 0x006A); break; /* Setting VCO for 9.72GHz */ case 1620: @@ -777,7 +775,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0152); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002); if (ssc) - cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x05DD, 0x0069); + cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x05DD, 0x0069); break; /* Setting VCO for 8.64GHz */ case 2160: @@ -793,7 +791,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x012C); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002); if (ssc) - cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x0536, 0x0069); + cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x0536, 0x0069); break; /* Setting VCO for 8.1GHz */ case 8100: @@ -808,7 +806,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x011A); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002); if (ssc) - cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x04D7, 0x006A); + cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x04D7, 0x006A); break; } @@ -843,10 +841,10 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy, * Set registers responsible for enabling and configuring SSC, with second * register value provided by a parameter. */ -static void cdns_torrent_dp_enable_ssc_25mhz(struct cdns_torrent_phy *cdns_phy, +static void cdns_torrent_dp_enable_ssc_25mhz(struct tp_data *tp_data, u32 ctrl2_val) { - struct regmap *regmap = cdns_phy->regmap_common_cdb; + struct regmap *regmap = tp_data->regmap_common_cdb; cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001); cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val); @@ -859,10 +857,10 @@ static void cdns_torrent_dp_enable_ssc_25mhz(struct cdns_torrent_phy *cdns_phy, } static -void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy, +void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct tp_data *tp_data, u32 rate, bool ssc) { - struct regmap *regmap = cdns_phy->regmap_common_cdb; + struct regmap *regmap = tp_data->regmap_common_cdb; /* Assumes 25 MHz refclock */ switch (rate) { @@ -878,7 +876,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002); cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0120); if (ssc) - cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x0423); + cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x0423); break; /* Setting VCO for 9.72GHz */ case 1620: @@ -893,7 +891,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002); cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0104); if (ssc) - cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x03B9); + cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x03B9); break; /* Setting VCO for 8.64GHz */ case 2160: @@ -907,7 +905,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002); cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00E7); if (ssc) - cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x034F); + cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x034F); break; /* Setting VCO for 8.1GHz */ case 8100: @@ -920,7 +918,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002); cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00D8); if (ssc) - cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x031A); + cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x031A); break; } @@ -963,20 +961,20 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy, } static -void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, +void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct tp_data *tp_data, u32 rate, bool ssc) { - struct regmap *regmap = cdns_phy->regmap_common_cdb; + struct regmap *regmap = tp_data->regmap_common_cdb; /* Assumes 100 MHz refclock */ switch (rate) { /* Setting VCO for 10.8GHz */ case 2700: case 5400: - if (cdns_phy->dp_pll & DP_PLL0) + if (tp_data->dp_pll & DP_PLL0) cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_FBH_OVRD_M0, 0x0022); - if (cdns_phy->dp_pll & DP_PLL1) { + if (tp_data->dp_pll & DP_PLL1) { cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0028); cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_FBH_OVRD_M0, 0x0022); cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_FBL_OVRD_M0, 0x000C); @@ -986,7 +984,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, case 1620: case 2430: case 3240: - if (cdns_phy->dp_pll & DP_PLL0) { + if (tp_data->dp_pll & DP_PLL0) { cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00); @@ -997,7 +995,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0042); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002); } - if (cdns_phy->dp_pll & DP_PLL1) { + if (tp_data->dp_pll & DP_PLL1) { cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00); @@ -1012,7 +1010,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, /* Setting VCO for 8.64GHz */ case 2160: case 4320: - if (cdns_phy->dp_pll & DP_PLL0) { + if (tp_data->dp_pll & DP_PLL0) { cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00); @@ -1023,7 +1021,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x003A); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002); } - if (cdns_phy->dp_pll & DP_PLL1) { + if (tp_data->dp_pll & DP_PLL1) { cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00); @@ -1037,7 +1035,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, break; /* Setting VCO for 8.1GHz */ case 8100: - if (cdns_phy->dp_pll & DP_PLL0) { + if (tp_data->dp_pll & DP_PLL0) { cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00); @@ -1047,7 +1045,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0036); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002); } - if (cdns_phy->dp_pll & DP_PLL1) { + if (tp_data->dp_pll & DP_PLL1) { cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509); cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00); @@ -1062,23 +1060,23 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy, } /* Set PLL used for DP configuration */ -static int cdns_torrent_dp_get_pll(struct cdns_torrent_phy *cdns_phy, +static int cdns_torrent_dp_get_pll(struct tp_data *tp_data, enum cdns_torrent_phy_type phy_t2) { switch (phy_t2) { case TYPE_PCIE: case TYPE_USB: - cdns_phy->dp_pll = DP_PLL1; + tp_data->dp_pll = DP_PLL1; break; case TYPE_SGMII: case TYPE_QSGMII: - cdns_phy->dp_pll = DP_PLL0; + tp_data->dp_pll = DP_PLL0; break; case TYPE_NONE: - cdns_phy->dp_pll = DP_PLL0 | DP_PLL1; + tp_data->dp_pll = DP_PLL0 | DP_PLL1; break; default: - dev_err(cdns_phy->dev, "Unsupported PHY configuration\n"); + dev_err(tp_data->dev, "Unsupported PHY configuration\n"); return -EINVAL; } @@ -1088,12 +1086,10 @@ static int cdns_torrent_dp_get_pll(struct cdns_torrent_phy *cdns_phy, /* * Enable or disable PLL for selected lanes. */ -static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, - struct phy_configure_opts_dp *dp, - bool enable) +static int tp_dptx_set_pll_en(struct tp_data *tp_data, struct tp_link *link, + struct phy_configure_opts_dp *dp, bool enable) { - struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; + struct regmap *regmap = tp_data->regmap_dptx_phy_reg; u32 rd_val, pll_ack_val; int ret; @@ -1113,7 +1109,7 @@ static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy, pll_val |= pll_bits; pll_ack_val = pll_bits; } else { - pll_bits = ((1 << inst->num_lanes) - 1); + pll_bits = ((1 << link->num_lanes) - 1); pll_val &= (~pll_bits); pll_ack_val = 0; } @@ -1130,10 +1126,8 @@ static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy, return ret; } -static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, - u32 num_lanes, - enum phy_powerstate powerstate) +static int tp_dptx_set_power_state(struct tp_data *tp_data, struct tp_link *link, + u32 num_lanes, enum phy_powerstate powerstate) { /* Register value for power state for a single byte. */ u32 value_part, i; @@ -1141,7 +1135,7 @@ static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy, u32 mask = 0; u32 read_val; int ret; - struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; + struct regmap *regmap = tp_data->regmap_dptx_phy_reg; switch (powerstate) { case (POWERSTATE_A0): @@ -1178,12 +1172,28 @@ static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy, return ret; } -static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, u32 num_lanes) +static int tp_dptx_wait_pma_cmn_ready(struct tp_data *tp_data) +{ + unsigned int reg; + int ret; + struct regmap *regmap = tp_data->regmap_dptx_phy_reg; + + ret = regmap_read_poll_timeout(regmap, PHY_PMA_CMN_READY, reg, + reg & 1, 0, POLL_TIMEOUT_US); + if (ret == -ETIMEDOUT) { + dev_err(tp_data->dev, + "timeout waiting for PMA common ready\n"); + return -ETIMEDOUT; + } + + return 0; +} + +static int tp_dp_run(struct tp_data *tp_data, struct tp_link *link, u32 num_lanes) { unsigned int read_val; int ret; - struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; + struct regmap *regmap = tp_data->regmap_dptx_phy_reg; /* * waiting for ACK of pma_xcvr_pllclk_en_ln_*, only for the @@ -1193,43 +1203,24 @@ static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy, read_val, read_val & 1, 0, POLL_TIMEOUT_US); if (ret == -ETIMEDOUT) { - dev_err(cdns_phy->dev, + dev_err(tp_data->dev, "timeout waiting for link PLL clock enable ack\n"); return ret; } ndelay(100); - ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, num_lanes, - POWERSTATE_A2); + ret = tp_dptx_set_power_state(tp_data, link, num_lanes, POWERSTATE_A2); if (ret) return ret; - ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, num_lanes, - POWERSTATE_A0); + ret = tp_dptx_set_power_state(tp_data, link, num_lanes, POWERSTATE_A0); return ret; } -static int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy *cdns_phy) -{ - unsigned int reg; - int ret; - struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; - - ret = regmap_read_poll_timeout(regmap, PHY_PMA_CMN_READY, reg, - reg & 1, 0, POLL_TIMEOUT_US); - if (ret == -ETIMEDOUT) { - dev_err(cdns_phy->dev, - "timeout waiting for PMA common ready\n"); - return -ETIMEDOUT; - } - - return 0; -} - -static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, +static void cdns_torrent_dp_pma_cmn_rate(struct tp_data *tp_data, + struct tp_link *link, u32 rate, u32 num_lanes) { unsigned int clk_sel_val = 0; @@ -1262,17 +1253,17 @@ static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy, break; } - if (cdns_phy->dp_pll & DP_PLL0) - cdns_torrent_phy_write(cdns_phy->regmap_common_cdb, + if (tp_data->dp_pll & DP_PLL0) + cdns_torrent_phy_write(tp_data->regmap_common_cdb, CMN_PDIAG_PLL0_CLK_SEL_M0, clk_sel_val); - if (cdns_phy->dp_pll & DP_PLL1) - cdns_torrent_phy_write(cdns_phy->regmap_common_cdb, + if (tp_data->dp_pll & DP_PLL1) + cdns_torrent_phy_write(tp_data->regmap_common_cdb, CMN_PDIAG_PLL1_CLK_SEL_M0, clk_sel_val); /* PMA lane configuration to deal with multi-link operation */ for (i = 0; i < num_lanes; i++) - cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + i], + cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + i], XCVR_DIAG_HSCLK_DIV, hsclk_div_val); } @@ -1280,9 +1271,8 @@ static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy, * Perform register operations related to setting link rate, once powerstate is * set and PLL disable request was processed. */ -static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, - struct phy_configure_opts_dp *dp) +static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link, + struct phy_configure_opts_dp *dp) { u32 read_val, field_val; int ret; @@ -1291,19 +1281,19 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy, * Disable the associated PLL (cmn_pll0_en or cmn_pll1_en) before * re-programming the new data rate. */ - ret = regmap_field_read(cdns_phy->phy_pma_pll_raw_ctrl, &field_val); + ret = regmap_field_read(tp_data->phy_pma_pll_raw_ctrl, &field_val); if (ret) return ret; - field_val &= ~(cdns_phy->dp_pll); - regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, field_val); + field_val &= ~(tp_data->dp_pll); + regmap_field_write(tp_data->phy_pma_pll_raw_ctrl, field_val); /* * Wait for PLL ready de-assertion. * For PLL0 - PHY_PMA_CMN_CTRL2[2] == 1 * For PLL1 - PHY_PMA_CMN_CTRL2[3] == 1 */ - if (cdns_phy->dp_pll & DP_PLL0) { - ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, + if (tp_data->dp_pll & DP_PLL0) { + ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2, read_val, ((read_val >> 2) & 0x01) != 0, 0, POLL_TIMEOUT_US); @@ -1311,8 +1301,8 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy, return ret; } - if ((cdns_phy->dp_pll & DP_PLL1) && cdns_phy->nsubnodes != 1) { - ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, + if ((tp_data->dp_pll & DP_PLL1) && tp_data->nb_links != 1) { + ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2, read_val, ((read_val >> 3) & 0x01) != 0, 0, POLL_TIMEOUT_US); @@ -1322,32 +1312,32 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy, ndelay(200); /* DP Rate Change - VCO Output settings. */ - if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ) + if (tp_data->ref_clk_rate == CLK_19_2_MHZ) /* PMA common configuration 19.2MHz */ - cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy, dp->link_rate, dp->ssc); - else if (cdns_phy->ref_clk_rate == CLK_25_MHZ) + cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data, dp->link_rate, dp->ssc); + else if (tp_data->ref_clk_rate == CLK_25_MHZ) /* PMA common configuration 25MHz */ - cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy, dp->link_rate, dp->ssc); - else if (cdns_phy->ref_clk_rate == CLK_100_MHZ) + cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data, dp->link_rate, dp->ssc); + else if (tp_data->ref_clk_rate == CLK_100_MHZ) /* PMA common configuration 100MHz */ - cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(cdns_phy, dp->link_rate, dp->ssc); + cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, dp->link_rate, dp->ssc); - cdns_torrent_dp_pma_cmn_rate(cdns_phy, inst, dp->link_rate, dp->lanes); + cdns_torrent_dp_pma_cmn_rate(tp_data, link, dp->link_rate, dp->lanes); /* Enable the associated PLL (cmn_pll0_en or cmn_pll1_en) */ - ret = regmap_field_read(cdns_phy->phy_pma_pll_raw_ctrl, &field_val); + ret = regmap_field_read(tp_data->phy_pma_pll_raw_ctrl, &field_val); if (ret) return ret; - field_val |= cdns_phy->dp_pll; - regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, field_val); + field_val |= tp_data->dp_pll; + regmap_field_write(tp_data->phy_pma_pll_raw_ctrl, field_val); /* * Wait for PLL ready assertion. * For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1 * For PLL1 - PHY_PMA_CMN_CTRL2[1] == 1 */ - if (cdns_phy->dp_pll & DP_PLL0) { - ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, + if (tp_data->dp_pll & DP_PLL0) { + ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2, read_val, (read_val & 0x01) != 0, 0, POLL_TIMEOUT_US); @@ -1355,8 +1345,8 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy, return ret; } - if ((cdns_phy->dp_pll & DP_PLL1) && cdns_phy->nsubnodes != 1) - ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2, + if ((tp_data->dp_pll & DP_PLL1) && tp_data->nb_links != 1) + ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2, read_val, ((read_val >> 1) & 0x01) != 0, 0, POLL_TIMEOUT_US); @@ -1367,8 +1357,7 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy, /* * Verify, that parameters to configure PHY with are correct. */ -static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst *inst, - struct phy_configure_opts_dp *dp) +static int tp_dp_verify_config(struct tp_link *link, struct phy_configure_opts_dp *dp) { u8 i; @@ -1402,7 +1391,7 @@ static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst *inst, } /* Check against actual number of PHY's lanes. */ - if (dp->lanes > inst->num_lanes) + if (dp->lanes > link->num_lanes) return -EINVAL; /* @@ -1427,11 +1416,11 @@ static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst *inst, } /* Set power state A0 and PLL clock enable to 0 on enabled lanes. */ -static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, +static void cdns_torrent_dp_set_a0_pll(struct tp_data *tp_data, + struct tp_link *link, u32 num_lanes) { - struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; + struct regmap *regmap = tp_data->regmap_dptx_phy_reg; u32 pwr_state = cdns_torrent_dp_read(regmap, PHY_PMA_XCVR_POWER_STATE_REQ); u32 pll_clk_en = cdns_torrent_dp_read(regmap, @@ -1440,9 +1429,9 @@ static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy, for (i = 0; i < num_lanes; i++) { pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK - << PHY_POWER_STATE_LN(inst->mlane + i)); + << PHY_POWER_STATE_LN(link->mlane + i)); - pll_clk_en &= ~(0x01U << (inst->mlane + i)); + pll_clk_en &= ~(0x01U << (link->mlane + i)); } cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, pwr_state); @@ -1450,22 +1439,21 @@ static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy, } /* Configure lane count as required. */ -static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, - struct phy_configure_opts_dp *dp) +static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link, + struct phy_configure_opts_dp *dp) { u32 value, i; int ret; - struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; + struct regmap *regmap = tp_data->regmap_dptx_phy_reg; u8 lane_mask = (1 << dp->lanes) - 1; u8 pma_tx_elec_idle_mask = 0; - u32 clane = inst->mlane; + u32 clane = link->mlane; lane_mask <<= clane; value = cdns_torrent_dp_read(regmap, PHY_RESET); /* clear pma_tx_elec_idle_ln_* bits. */ - pma_tx_elec_idle_mask = ((1 << inst->num_lanes) - 1) << clane; + pma_tx_elec_idle_mask = ((1 << link->num_lanes) - 1) << clane; pma_tx_elec_idle_mask <<= PMA_TX_ELEC_IDLE_SHIFT; @@ -1485,27 +1473,27 @@ static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy, * Assert lane reset on unused lanes and master lane so they remain in reset * and powered down when re-enabling the link */ - for (i = 0; i < inst->num_lanes; i++) + for (i = 0; i < link->num_lanes; i++) value &= (~(1 << (clane + i))); - for (i = 1; i < inst->num_lanes; i++) + for (i = 1; i < link->num_lanes; i++) value |= ((1 << (clane + i)) & lane_mask); cdns_torrent_dp_write(regmap, PHY_RESET, value); - cdns_torrent_dp_set_a0_pll(cdns_phy, inst, dp->lanes); + cdns_torrent_dp_set_a0_pll(tp_data, link, dp->lanes); /* release phy_l0*_reset_n based on used laneCount */ - for (i = 0; i < inst->num_lanes; i++) + for (i = 0; i < link->num_lanes; i++) value &= (~(1 << (clane + i))); - for (i = 0; i < inst->num_lanes; i++) + for (i = 0; i < link->num_lanes; i++) value |= ((1 << (clane + i)) & lane_mask); cdns_torrent_dp_write(regmap, PHY_RESET, value); /* Wait, until PHY gets ready after releasing PHY reset signal. */ - ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy); + ret = tp_dptx_wait_pma_cmn_ready(tp_data); if (ret) return ret; @@ -1516,41 +1504,37 @@ static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy, value |= (1 << clane); cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, value); - ret = cdns_torrent_dp_run(cdns_phy, inst, dp->lanes); + ret = tp_dp_run(tp_data, link, dp->lanes); return ret; } /* Configure link rate as required. */ -static int cdns_torrent_dp_set_rate(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, - struct phy_configure_opts_dp *dp) +static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link, + struct phy_configure_opts_dp *dp) { int ret; - ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes, - POWERSTATE_A3); + ret = tp_dptx_set_power_state(tp_data, link, dp->lanes, POWERSTATE_A3); if (ret) return ret; - ret = cdns_torrent_dp_set_pll_en(cdns_phy, inst, dp, false); + ret = tp_dptx_set_pll_en(tp_data, link, dp, false); if (ret) return ret; ndelay(200); - ret = cdns_torrent_dp_configure_rate(cdns_phy, inst, dp); + ret = tp_dp_configure_rate(tp_data, link, dp); if (ret) return ret; ndelay(200); - ret = cdns_torrent_dp_set_pll_en(cdns_phy, inst, dp, true); + ret = tp_dptx_set_pll_en(tp_data, link, dp, true); if (ret) return ret; - ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes, - POWERSTATE_A2); + ret = tp_dptx_set_power_state(tp_data, link, dp->lanes, POWERSTATE_A2); if (ret) return ret; - ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes, - POWERSTATE_A0); + ret = tp_dptx_set_power_state(tp_data, link, dp->lanes, POWERSTATE_A0); if (ret) return ret; ndelay(900); @@ -1559,107 +1543,105 @@ static int cdns_torrent_dp_set_rate(struct cdns_torrent_phy *cdns_phy, } /* Configure voltage swing and pre-emphasis for all enabled lanes. */ -static void cdns_torrent_dp_set_voltages(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, - struct phy_configure_opts_dp *dp) +static void tp_dp_set_voltages(struct tp_data *tp_data, struct tp_link *link, + struct phy_configure_opts_dp *dp) { u8 lane; u16 val; for (lane = 0; lane < dp->lanes; lane++) { - val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + val = cdns_torrent_phy_read(tp_data->regmap_tx_lane_cdb[link->mlane + lane], TX_DIAG_ACYA); /* * Write 1 to register bit TX_DIAG_ACYA[0] to freeze the * current state of the analog TX driver. */ val |= TX_DIAG_ACYA_HBDC_MASK; - cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane], TX_DIAG_ACYA, val); - cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane], TX_TXCC_CTRL, 0x08A4); val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].diag_tx_drv; - cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane], DRV_DIAG_TX_DRV, val); val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult; - cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane], TX_TXCC_MGNFS_MULT_000, val); val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].cpost_mult; - cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane], TX_TXCC_CPOST_MULT_00, val); - val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + val = cdns_torrent_phy_read(tp_data->regmap_tx_lane_cdb[link->mlane + lane], TX_DIAG_ACYA); /* * Write 0 to register bit TX_DIAG_ACYA[0] to allow the state of * analog TX driver to reflect the new programmed one. */ val &= ~TX_DIAG_ACYA_HBDC_MASK; - cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane], + cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane], TX_DIAG_ACYA, val); } -}; +} -static int cdns_torrent_dp_configure(struct phy *phy, - union phy_configure_opts *opts) +static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts) { - struct cdns_torrent_inst *inst = phy_get_drvdata(phy); - struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); + struct tp_link *link = phy_get_drvdata(phy); + struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent); int ret; - if (cdns_phy->already_configured) + if (tp_data->already_configured) return 0; - ret = cdns_torrent_dp_verify_config(inst, &opts->dp); + ret = tp_dp_verify_config(link, &opts->dp); if (ret) { dev_err(&phy->dev, "invalid params for phy configure\n"); return ret; } if (opts->dp.set_lanes) { - ret = cdns_torrent_dp_set_lanes(cdns_phy, inst, &opts->dp); + ret = tp_dp_set_lanes(tp_data, link, &opts->dp); if (ret) { - dev_err(&phy->dev, "cdns_torrent_dp_set_lanes failed\n"); + dev_err(&phy->dev, "tp_dp_set_lanes failed\n"); return ret; } } if (opts->dp.set_rate) { - ret = cdns_torrent_dp_set_rate(cdns_phy, inst, &opts->dp); + ret = tp_dp_set_rate(tp_data, link, &opts->dp); if (ret) { - dev_err(&phy->dev, "cdns_torrent_dp_set_rate failed\n"); + dev_err(&phy->dev, "tp_dp_set_rate failed\n"); return ret; } } if (opts->dp.set_voltages) - cdns_torrent_dp_set_voltages(cdns_phy, inst, &opts->dp); + tp_dp_set_voltages(tp_data, link, &opts->dp); return ret; } -static int cdns_torrent_phy_on(struct phy *phy) +static int tp_phy_on(struct phy *phy) { - struct cdns_torrent_inst *inst = phy_get_drvdata(phy); - struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); + struct tp_link *link = phy_get_drvdata(phy); + struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent); u32 read_val; int ret; - if (cdns_phy->already_configured) { + if (tp_data->already_configured) { /* Give 5ms to 10ms delay for the PIPE clock to be stable */ usleep_range(5000, 10000); return 0; } - if (cdns_phy->nsubnodes == 1) { + if (tp_data->nb_links == 1) { /* Take the PHY lane group out of reset */ - reset_control_deassert(inst->lnk_rst); + reset_control_deassert(link->lnk_rst); /* Take the PHY out of reset */ - ret = reset_control_deassert(cdns_phy->phy_rst); + ret = reset_control_deassert(tp_data->phy_rst); if (ret) return ret; } @@ -1668,20 +1650,20 @@ static int cdns_torrent_phy_on(struct phy *phy) * Wait for cmn_ready assertion * PHY_PMA_CMN_CTRL1[0] == 1 */ - ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_1, + ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_1, read_val, read_val, 1000, PLL_LOCK_TIMEOUT); if (ret) { - dev_err(cdns_phy->dev, "Timeout waiting for CMN ready\n"); + dev_err(tp_data->dev, "Timeout waiting for CMN ready\n"); return ret; } - if (inst->phy_type == TYPE_PCIE || inst->phy_type == TYPE_USB) { - ret = regmap_field_read_poll_timeout(cdns_phy->phy_pcs_iso_link_ctrl_1[inst->mlane], + if (link->phy_type == TYPE_PCIE || link->phy_type == TYPE_USB) { + ret = regmap_field_read_poll_timeout(tp_data->phy_pcs_iso_link_ctrl_1[link->mlane], read_val, !read_val, 1000, PLL_LOCK_TIMEOUT); if (ret == -ETIMEDOUT) { - dev_err(cdns_phy->dev, "Timeout waiting for PHY status ready\n"); + dev_err(tp_data->dev, "Timeout waiting for PHY status ready\n"); return ret; } } @@ -1689,26 +1671,26 @@ static int cdns_torrent_phy_on(struct phy *phy) return 0; } -static int cdns_torrent_phy_off(struct phy *phy) +static int tp_phy_off(struct phy *phy) { - struct cdns_torrent_inst *inst = phy_get_drvdata(phy); - struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); + struct tp_link *link = phy_get_drvdata(phy); + struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent); int ret; - if (cdns_phy->nsubnodes != 1) + if (tp_data->nb_links != 1) return 0; - ret = reset_control_assert(cdns_phy->phy_rst); + ret = reset_control_assert(tp_data->phy_rst); if (ret) return ret; - return reset_control_assert(inst->lnk_rst); + return reset_control_assert(link->lnk_rst); } -static void cdns_torrent_dp_common_init(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst) +static void cdns_torrent_dp_common_init(struct tp_data *tp_data, + struct tp_link *link) { - struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg; + struct regmap *regmap = tp_data->regmap_dptx_phy_reg; unsigned char lane_bits; u32 val; @@ -1718,13 +1700,13 @@ static void cdns_torrent_dp_common_init(struct cdns_torrent_phy *cdns_phy, * Set lines power state to A0 * Set lines pll clk enable to 0 */ - cdns_torrent_dp_set_a0_pll(cdns_phy, inst, inst->num_lanes); + cdns_torrent_dp_set_a0_pll(tp_data, link, link->num_lanes); /* * release phy_l0*_reset_n and pma_tx_elec_idle_ln_* based on * used lanes */ - lane_bits = (1 << inst->num_lanes) - 1; + lane_bits = (1 << link->num_lanes) - 1; val = cdns_torrent_dp_read(regmap, PHY_RESET); val |= (0xF & lane_bits); @@ -1740,86 +1722,84 @@ static void cdns_torrent_dp_common_init(struct cdns_torrent_phy *cdns_phy, * PHY PMA registers configuration functions * Initialize PHY with max supported link rate, without SSC. */ - if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ) - cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy, - cdns_phy->max_bit_rate, + if (tp_data->ref_clk_rate == CLK_19_2_MHZ) + cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data, + tp_data->max_bit_rate, false); - else if (cdns_phy->ref_clk_rate == CLK_25_MHZ) - cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy, - cdns_phy->max_bit_rate, + else if (tp_data->ref_clk_rate == CLK_25_MHZ) + cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data, + tp_data->max_bit_rate, false); - else if (cdns_phy->ref_clk_rate == CLK_100_MHZ) - cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(cdns_phy, - cdns_phy->max_bit_rate, + else if (tp_data->ref_clk_rate == CLK_100_MHZ) + cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, + tp_data->max_bit_rate, false); - cdns_torrent_dp_pma_cmn_rate(cdns_phy, inst, cdns_phy->max_bit_rate, - inst->num_lanes); + cdns_torrent_dp_pma_cmn_rate(tp_data, link, tp_data->max_bit_rate, + link->num_lanes); /* take out of reset */ - regmap_field_write(cdns_phy->phy_reset_ctrl, 0x1); + regmap_field_write(tp_data->phy_reset_ctrl, 0x1); } -static int cdns_torrent_dp_start(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, - struct phy *phy) +static int cdns_torrent_dp_start(struct tp_data *tp_data, struct tp_link *link, struct phy *phy) { int ret; - ret = cdns_torrent_phy_on(phy); + ret = tp_phy_on(phy); if (ret) return ret; - ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy); + ret = tp_dptx_wait_pma_cmn_ready(tp_data); if (ret) return ret; - ret = cdns_torrent_dp_run(cdns_phy, inst, inst->num_lanes); + ret = tp_dp_run(tp_data, link, link->num_lanes); return ret; } static int cdns_torrent_dp_init(struct phy *phy) { - struct cdns_torrent_inst *inst = phy_get_drvdata(phy); - struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); + struct tp_link *link = phy_get_drvdata(phy); + struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent); int ret; - switch (cdns_phy->ref_clk_rate) { + switch (tp_data->ref_clk_rate) { case CLK_19_2_MHZ: case CLK_25_MHZ: case CLK_100_MHZ: /* Valid Ref Clock Rate */ break; default: - dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n"); + dev_err(tp_data->dev, "Unsupported Ref Clock Rate\n"); return -EINVAL; } - ret = cdns_torrent_dp_get_pll(cdns_phy, TYPE_NONE); + ret = cdns_torrent_dp_get_pll(tp_data, TYPE_NONE); if (ret) return ret; - cdns_torrent_dp_common_init(cdns_phy, inst); + cdns_torrent_dp_common_init(tp_data, link); - return cdns_torrent_dp_start(cdns_phy, inst, phy); + return cdns_torrent_dp_start(tp_data, link, phy); } -static int cdns_torrent_dp_multilink_init(struct cdns_torrent_phy *cdns_phy, - struct cdns_torrent_inst *inst, +static int cdns_torrent_dp_multilink_init(struct tp_data *tp_data, + struct tp_link *link, struct phy *phy) { - if (cdns_phy->ref_clk_rate != CLK_100_MHZ) { - dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n"); + if (tp_data->ref_clk_rate != CLK_100_MHZ) { + dev_err(tp_data->dev, "Unsupported Ref Clock Rate\n"); return -EINVAL; } - cdns_torrent_dp_common_init(cdns_phy, inst); + cdns_torrent_dp_common_init(tp_data, link); - return cdns_torrent_dp_start(cdns_phy, inst, phy); + return cdns_torrent_dp_start(tp_data, link, phy); } -static int cdns_torrent_derived_refclk_enable(struct clk_hw *hw) +static int tp_derived_refclk_enable(struct clk_hw *hw) { struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw); @@ -1829,7 +1809,7 @@ static int cdns_torrent_derived_refclk_enable(struct clk_hw *hw) return 0; } -static void cdns_torrent_derived_refclk_disable(struct clk_hw *hw) +static void tp_derived_refclk_disable(struct clk_hw *hw) { struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw); @@ -1837,7 +1817,7 @@ static void cdns_torrent_derived_refclk_disable(struct clk_hw *hw) regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0); } -static int cdns_torrent_derived_refclk_is_enabled(struct clk_hw *hw) +static int tp_derived_refclk_is_enabled(struct clk_hw *hw) { struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw); int val; @@ -1847,16 +1827,16 @@ static int cdns_torrent_derived_refclk_is_enabled(struct clk_hw *hw) return !!val; } -static const struct clk_ops cdns_torrent_derived_refclk_ops = { - .enable = cdns_torrent_derived_refclk_enable, - .disable = cdns_torrent_derived_refclk_disable, - .is_enabled = cdns_torrent_derived_refclk_is_enabled, +static const struct clk_ops tp_derived_refclk_ops = { + .enable = tp_derived_refclk_enable, + .disable = tp_derived_refclk_disable, + .is_enabled = tp_derived_refclk_is_enabled, }; -static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_phy) +static int tp_derived_refclk_register(struct tp_data *tp_data) { struct cdns_torrent_derived_refclk *derived_refclk; - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; struct clk_init_data *init; const char *parent_name; char clk_name[100]; @@ -1869,7 +1849,7 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph return -ENOMEM; snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), - clk_names[CDNS_TORRENT_DERIVED_REFCLK]); + tp_clk_names[CDNS_TORRENT_DERIVED_REFCLK]); clk = devm_clk_get_optional(dev, "phy_en_refclk"); if (IS_ERR(clk)) { @@ -1884,12 +1864,12 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph init->parent_names = &parent_name; init->num_parents = 1; } - init->ops = &cdns_torrent_derived_refclk_ops; + init->ops = &tp_derived_refclk_ops; init->flags = 0; init->name = clk_name; - derived_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0; - derived_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4; + derived_refclk->phy_pipe_cmn_ctrl1_0 = tp_data->phy_pipe_cmn_ctrl1_0; + derived_refclk->cmn_cdiag_refclk_ovrd_4 = tp_data->cmn_cdiag_refclk_ovrd_4; derived_refclk->hw.init = init; @@ -1898,12 +1878,12 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph if (ret) return ret; - cdns_phy->clk_hw_data->hws[CDNS_TORRENT_DERIVED_REFCLK] = hw; + tp_data->clk_hw_data->hws[CDNS_TORRENT_DERIVED_REFCLK] = hw; return 0; } -static int cdns_torrent_received_refclk_enable(struct clk_hw *hw) +static int tp_received_refclk_enable(struct clk_hw *hw) { struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw); @@ -1912,14 +1892,14 @@ static int cdns_torrent_received_refclk_enable(struct clk_hw *hw) return 0; } -static void cdns_torrent_received_refclk_disable(struct clk_hw *hw) +static void tp_received_refclk_disable(struct clk_hw *hw) { struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw); regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0); } -static int cdns_torrent_received_refclk_is_enabled(struct clk_hw *hw) +static int tp_received_refclk_is_enabled(struct clk_hw *hw) { struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw); int val, cmn_val; @@ -1930,16 +1910,16 @@ static int cdns_torrent_received_refclk_is_enabled(struct clk_hw *hw) return val && !cmn_val; } -static const struct clk_ops cdns_torrent_received_refclk_ops = { - .enable = cdns_torrent_received_refclk_enable, - .disable = cdns_torrent_received_refclk_disable, - .is_enabled = cdns_torrent_received_refclk_is_enabled, +static const struct clk_ops tp_received_refclk_ops = { + .enable = tp_received_refclk_enable, + .disable = tp_received_refclk_disable, + .is_enabled = tp_received_refclk_is_enabled, }; -static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_phy) +static int tp_received_refclk_register(struct tp_data *tp_data) { struct cdns_torrent_received_refclk *received_refclk; - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; struct clk_init_data *init; const char *parent_name; char clk_name[100]; @@ -1952,7 +1932,7 @@ static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_p return -ENOMEM; snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), - clk_names[CDNS_TORRENT_RECEIVED_REFCLK]); + tp_clk_names[CDNS_TORRENT_RECEIVED_REFCLK]); clk = devm_clk_get_optional(dev, "phy_en_refclk"); if (IS_ERR(clk)) { @@ -1967,12 +1947,12 @@ static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_p init->parent_names = &parent_name; init->num_parents = 1; } - init->ops = &cdns_torrent_received_refclk_ops; + init->ops = &tp_received_refclk_ops; init->flags = 0; init->name = clk_name; - received_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0; - received_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4; + received_refclk->phy_pipe_cmn_ctrl1_0 = tp_data->phy_pipe_cmn_ctrl1_0; + received_refclk->cmn_cdiag_refclk_ovrd_4 = tp_data->cmn_cdiag_refclk_ovrd_4; received_refclk->hw.init = init; @@ -1981,14 +1961,14 @@ static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_p if (ret) return ret; - cdns_phy->clk_hw_data->hws[CDNS_TORRENT_RECEIVED_REFCLK] = hw; + tp_data->clk_hw_data->hws[CDNS_TORRENT_RECEIVED_REFCLK] = hw; return 0; } -static int cdns_torrent_refclk_driver_enable(struct clk_hw *hw) +static int tp_refclk_driver_enable(struct clk_hw *hw) { - struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw); + struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw); regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0); regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1); @@ -1997,16 +1977,16 @@ static int cdns_torrent_refclk_driver_enable(struct clk_hw *hw) return 0; } -static void cdns_torrent_refclk_driver_disable(struct clk_hw *hw) +static void tp_refclk_driver_disable(struct clk_hw *hw) { - struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw); + struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw); regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1); } -static int cdns_torrent_refclk_driver_is_enabled(struct clk_hw *hw) +static int tp_refclk_driver_is_enabled(struct clk_hw *hw) { - struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw); + struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw); int val; regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], &val); @@ -2014,37 +1994,37 @@ static int cdns_torrent_refclk_driver_is_enabled(struct clk_hw *hw) return !val; } -static u8 cdns_torrent_refclk_driver_get_parent(struct clk_hw *hw) +static u8 tp_refclk_driver_get_parent(struct clk_hw *hw) { - struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw); + struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw); unsigned int val; regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], &val); - return clk_mux_val_to_index(hw, cdns_torrent_refclk_driver_mux_table, 0, val); + return clk_mux_val_to_index(hw, tp_refclk_driver_mux_table, 0, val); } -static int cdns_torrent_refclk_driver_set_parent(struct clk_hw *hw, u8 index) +static int tp_refclk_driver_set_parent(struct clk_hw *hw, u8 index) { - struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw); + struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw); unsigned int val; - val = cdns_torrent_refclk_driver_mux_table[index]; + val = tp_refclk_driver_mux_table[index]; return regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val); } -static const struct clk_ops cdns_torrent_refclk_driver_ops = { - .enable = cdns_torrent_refclk_driver_enable, - .disable = cdns_torrent_refclk_driver_disable, - .is_enabled = cdns_torrent_refclk_driver_is_enabled, +static const struct clk_ops tp_refclk_driver_ops = { + .enable = tp_refclk_driver_enable, + .disable = tp_refclk_driver_disable, + .is_enabled = tp_refclk_driver_is_enabled, .determine_rate = __clk_mux_determine_rate, - .set_parent = cdns_torrent_refclk_driver_set_parent, - .get_parent = cdns_torrent_refclk_driver_get_parent, + .set_parent = tp_refclk_driver_set_parent, + .get_parent = tp_refclk_driver_get_parent, }; -static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy) +static int tp_refclk_driver_register(struct tp_data *tp_data) { - struct cdns_torrent_refclk_driver *refclk_driver; - struct device *dev = cdns_phy->dev; + struct tp_refclk_driver *refclk_driver; + struct device *dev = tp_data->dev; struct regmap_field *field; struct clk_init_data *init; const char **parent_names; @@ -2058,13 +2038,13 @@ static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy if (!refclk_driver) return -ENOMEM; - num_parents = ARRAY_SIZE(refclk_driver_parent_index); + num_parents = ARRAY_SIZE(tp_refclk_driver_parent_idx); parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL); if (!parent_names) return -ENOMEM; for (i = 0; i < num_parents; i++) { - hw = cdns_phy->clk_hw_data->hws[refclk_driver_parent_index[i]]; + hw = tp_data->clk_hw_data->hws[tp_refclk_driver_parent_idx[i]]; if (IS_ERR_OR_NULL(hw)) { dev_err(dev, "No parent clock for refclk driver clock\n"); return IS_ERR(hw) ? PTR_ERR(hw) : -ENOENT; @@ -2073,19 +2053,19 @@ static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy } snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev), - clk_names[CDNS_TORRENT_REFCLK_DRIVER]); + tp_clk_names[CDNS_TORRENT_REFCLK_DRIVER]); init = &refclk_driver->clk_data; - init->ops = &cdns_torrent_refclk_driver_ops; + init->ops = &tp_refclk_driver_ops; init->flags = CLK_SET_RATE_NO_REPARENT; init->parent_names = parent_names; init->num_parents = num_parents; init->name = clk_name; - regmap = cdns_phy->regmap_common_cdb; + regmap = tp_data->regmap_common_cdb; - for (i = 0; i < REFCLK_OUT_NUM_CMN_CONFIG; i++) { + for (i = 0; i < TP_REFCLK_OUT_NUM_CMN_CONFIG; i++) { field = devm_regmap_field_alloc(dev, regmap, refclk_out_cmn_cfg[i]); if (IS_ERR(field)) { dev_err(dev, "Refclk driver CMN reg field init failed\n"); @@ -2104,7 +2084,7 @@ static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy if (ret) return ret; - cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER] = hw; + tp_data->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER] = hw; return 0; } @@ -2127,100 +2107,100 @@ static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base, return devm_regmap_init(dev, NULL, ctx, config); } -static int cdns_torrent_dp_regfield_init(struct cdns_torrent_phy *cdns_phy) +static int cdns_torrent_dp_regfield_init(struct tp_data *tp_data) { - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; struct regmap_field *field; struct regmap *regmap; - regmap = cdns_phy->regmap_dptx_phy_reg; + regmap = tp_data->regmap_dptx_phy_reg; field = devm_regmap_field_alloc(dev, regmap, phy_reset_ctrl); if (IS_ERR(field)) { dev_err(dev, "PHY_RESET reg field init failed\n"); return PTR_ERR(field); } - cdns_phy->phy_reset_ctrl = field; + tp_data->phy_reset_ctrl = field; return 0; } -static int cdns_torrent_regfield_init(struct cdns_torrent_phy *cdns_phy) +static int cdns_torrent_regfield_init(struct tp_data *tp_data) { - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; struct regmap_field *field; struct regmap *regmap; int i; - regmap = cdns_phy->regmap_phy_pcs_common_cdb; + regmap = tp_data->regmap_phy_pcs_common_cdb; field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg); if (IS_ERR(field)) { dev_err(dev, "PHY_PLL_CFG reg field init failed\n"); return PTR_ERR(field); } - cdns_phy->phy_pll_cfg = field; + tp_data->phy_pll_cfg = field; - regmap = cdns_phy->regmap_phy_pcs_common_cdb; + regmap = tp_data->regmap_phy_pcs_common_cdb; field = devm_regmap_field_alloc(dev, regmap, phy_pipe_cmn_ctrl1_0); if (IS_ERR(field)) { dev_err(dev, "phy_pipe_cmn_ctrl1_0 reg field init failed\n"); return PTR_ERR(field); } - cdns_phy->phy_pipe_cmn_ctrl1_0 = field; + tp_data->phy_pipe_cmn_ctrl1_0 = field; - regmap = cdns_phy->regmap_common_cdb; + regmap = tp_data->regmap_common_cdb; field = devm_regmap_field_alloc(dev, regmap, cmn_cdiag_refclk_ovrd_4); if (IS_ERR(field)) { dev_err(dev, "cmn_cdiag_refclk_ovrd_4 reg field init failed\n"); return PTR_ERR(field); } - cdns_phy->cmn_cdiag_refclk_ovrd_4 = field; + tp_data->cmn_cdiag_refclk_ovrd_4 = field; - regmap = cdns_phy->regmap_phy_pma_common_cdb; + regmap = tp_data->regmap_phy_pma_common_cdb; field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_1); if (IS_ERR(field)) { dev_err(dev, "PHY_PMA_CMN_CTRL1 reg field init failed\n"); return PTR_ERR(field); } - cdns_phy->phy_pma_cmn_ctrl_1 = field; + tp_data->phy_pma_cmn_ctrl_1 = field; - regmap = cdns_phy->regmap_phy_pma_common_cdb; + regmap = tp_data->regmap_phy_pma_common_cdb; field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_2); if (IS_ERR(field)) { dev_err(dev, "PHY_PMA_CMN_CTRL2 reg field init failed\n"); return PTR_ERR(field); } - cdns_phy->phy_pma_cmn_ctrl_2 = field; + tp_data->phy_pma_cmn_ctrl_2 = field; - regmap = cdns_phy->regmap_phy_pma_common_cdb; + regmap = tp_data->regmap_phy_pma_common_cdb; field = devm_regmap_field_alloc(dev, regmap, phy_pma_pll_raw_ctrl); if (IS_ERR(field)) { dev_err(dev, "PHY_PMA_PLL_RAW_CTRL reg field init failed\n"); return PTR_ERR(field); } - cdns_phy->phy_pma_pll_raw_ctrl = field; + tp_data->phy_pma_pll_raw_ctrl = field; for (i = 0; i < MAX_NUM_LANES; i++) { - regmap = cdns_phy->regmap_phy_pcs_lane_cdb[i]; + regmap = tp_data->regmap_phy_pcs_lane_cdb[i]; field = devm_regmap_field_alloc(dev, regmap, phy_pcs_iso_link_ctrl_1); if (IS_ERR(field)) { dev_err(dev, "PHY_PCS_ISO_LINK_CTRL reg field init for ln %d failed\n", i); return PTR_ERR(field); } - cdns_phy->phy_pcs_iso_link_ctrl_1[i] = field; + tp_data->phy_pcs_iso_link_ctrl_1[i] = field; } return 0; } -static int cdns_torrent_dp_regmap_init(struct cdns_torrent_phy *cdns_phy) +static int cdns_torrent_dp_regmap_init(struct tp_data *tp_data) { - void __iomem *base = cdns_phy->base; - struct device *dev = cdns_phy->dev; + void __iomem *base = tp_data->base; + struct device *dev = tp_data->dev; struct regmap *regmap; u8 reg_offset_shift; u32 block_offset; - reg_offset_shift = cdns_phy->init_data->reg_offset_shift; + reg_offset_shift = tp_data->init_data->reg_offset_shift; block_offset = TORRENT_DPTX_PHY_OFFSET; regmap = cdns_regmap_init(dev, base, block_offset, @@ -2230,22 +2210,22 @@ static int cdns_torrent_dp_regmap_init(struct cdns_torrent_phy *cdns_phy) dev_err(dev, "Failed to init DPTX PHY regmap\n"); return PTR_ERR(regmap); } - cdns_phy->regmap_dptx_phy_reg = regmap; + tp_data->regmap_dptx_phy_reg = regmap; return 0; } -static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy) +static int cdns_torrent_regmap_init(struct tp_data *tp_data) { - void __iomem *sd_base = cdns_phy->sd_base; + void __iomem *sd_base = tp_data->sd_base; u8 block_offset_shift, reg_offset_shift; - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; struct regmap *regmap; u32 block_offset; int i; - block_offset_shift = cdns_phy->init_data->block_offset_shift; - reg_offset_shift = cdns_phy->init_data->reg_offset_shift; + block_offset_shift = tp_data->init_data->block_offset_shift; + reg_offset_shift = tp_data->init_data->reg_offset_shift; for (i = 0; i < MAX_NUM_LANES; i++) { block_offset = TORRENT_TX_LANE_CDB_OFFSET(i, block_offset_shift, @@ -2257,7 +2237,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy) dev_err(dev, "Failed to init tx lane CDB regmap\n"); return PTR_ERR(regmap); } - cdns_phy->regmap_tx_lane_cdb[i] = regmap; + tp_data->regmap_tx_lane_cdb[i] = regmap; block_offset = TORRENT_RX_LANE_CDB_OFFSET(i, block_offset_shift, reg_offset_shift); @@ -2268,7 +2248,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy) dev_err(dev, "Failed to init rx lane CDB regmap\n"); return PTR_ERR(regmap); } - cdns_phy->regmap_rx_lane_cdb[i] = regmap; + tp_data->regmap_rx_lane_cdb[i] = regmap; block_offset = TORRENT_PHY_PCS_LANE_CDB_OFFSET(i, block_offset_shift, reg_offset_shift); @@ -2279,7 +2259,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy) dev_err(dev, "Failed to init PHY PCS lane CDB regmap\n"); return PTR_ERR(regmap); } - cdns_phy->regmap_phy_pcs_lane_cdb[i] = regmap; + tp_data->regmap_phy_pcs_lane_cdb[i] = regmap; } block_offset = TORRENT_COMMON_CDB_OFFSET; @@ -2290,7 +2270,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy) dev_err(dev, "Failed to init common CDB regmap\n"); return PTR_ERR(regmap); } - cdns_phy->regmap_common_cdb = regmap; + tp_data->regmap_common_cdb = regmap; block_offset = TORRENT_PHY_PCS_COMMON_OFFSET(block_offset_shift); regmap = cdns_regmap_init(dev, sd_base, block_offset, @@ -2300,7 +2280,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy) dev_err(dev, "Failed to init PHY PCS common CDB regmap\n"); return PTR_ERR(regmap); } - cdns_phy->regmap_phy_pcs_common_cdb = regmap; + tp_data->regmap_phy_pcs_common_cdb = regmap; block_offset = TORRENT_PHY_PMA_COMMON_OFFSET(block_offset_shift); regmap = cdns_regmap_init(dev, sd_base, block_offset, @@ -2310,34 +2290,34 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy) dev_err(dev, "Failed to init PHY PMA common CDB regmap\n"); return PTR_ERR(regmap); } - cdns_phy->regmap_phy_pma_common_cdb = regmap; + tp_data->regmap_phy_pma_common_cdb = regmap; return 0; } -static int cdns_torrent_phy_init(struct phy *phy) +static int tp_phy_init(struct phy *phy) { - struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent); + struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent); const struct cdns_torrent_vals *cmn_vals, *tx_ln_vals, *rx_ln_vals; - const struct cdns_torrent_data *init_data = cdns_phy->init_data; + const struct cdns_torrent_data *init_data = tp_data->init_data; const struct cdns_torrent_vals *link_cmn_vals, *xcvr_diag_vals; - enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate; - struct cdns_torrent_inst *inst = phy_get_drvdata(phy); - enum cdns_torrent_phy_type phy_type = inst->phy_type; + enum cdns_torrent_ref_clk ref_clk = tp_data->ref_clk_rate; + struct tp_link *link = phy_get_drvdata(phy); + enum cdns_torrent_phy_type phy_type = link->phy_type; const struct cdns_torrent_vals *phy_pma_cmn_vals; - enum cdns_torrent_ssc_mode ssc = inst->ssc_mode; + enum cdns_torrent_ssc_mode ssc = link->ssc_mode; const struct cdns_torrent_vals *pcs_cmn_vals; const struct cdns_reg_pairs *reg_pairs; struct regmap *regmap; u32 num_regs; int i, j; - if (cdns_phy->already_configured) + if (tp_data->already_configured) return 0; - if (cdns_phy->nsubnodes > 1) { + if (tp_data->nb_links > 1) { if (phy_type == TYPE_DP) - return cdns_torrent_dp_multilink_init(cdns_phy, inst, phy); + return cdns_torrent_dp_multilink_init(tp_data, link, phy); return 0; } @@ -2356,13 +2336,13 @@ static int cdns_torrent_phy_init(struct phy *phy) if (link_cmn_vals) { reg_pairs = link_cmn_vals->reg_pairs; num_regs = link_cmn_vals->num_regs; - regmap = cdns_phy->regmap_common_cdb; + regmap = tp_data->regmap_common_cdb; /** * First array value in link_cmn_vals must be of * PHY_PLL_CFG register */ - regmap_field_write(cdns_phy->phy_pll_cfg, reg_pairs[0].val); + regmap_field_write(tp_data->phy_pll_cfg, reg_pairs[0].val); for (i = 1; i < num_regs; i++) regmap_write(regmap, reg_pairs[i].off, @@ -2376,8 +2356,8 @@ static int cdns_torrent_phy_init(struct phy *phy) if (xcvr_diag_vals) { reg_pairs = xcvr_diag_vals->reg_pairs; num_regs = xcvr_diag_vals->num_regs; - for (i = 0; i < inst->num_lanes; i++) { - regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane]; + for (i = 0; i < link->num_lanes; i++) { + regmap = tp_data->regmap_tx_lane_cdb[i + link->mlane]; for (j = 0; j < num_regs; j++) regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); @@ -2392,7 +2372,7 @@ static int cdns_torrent_phy_init(struct phy *phy) if (pcs_cmn_vals) { reg_pairs = pcs_cmn_vals->reg_pairs; num_regs = pcs_cmn_vals->num_regs; - regmap = cdns_phy->regmap_phy_pcs_common_cdb; + regmap = tp_data->regmap_phy_pcs_common_cdb; for (i = 0; i < num_regs; i++) regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); @@ -2406,7 +2386,7 @@ static int cdns_torrent_phy_init(struct phy *phy) if (phy_pma_cmn_vals) { reg_pairs = phy_pma_cmn_vals->reg_pairs; num_regs = phy_pma_cmn_vals->num_regs; - regmap = cdns_phy->regmap_phy_pma_common_cdb; + regmap = tp_data->regmap_phy_pma_common_cdb; for (i = 0; i < num_regs; i++) regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); @@ -2420,7 +2400,7 @@ static int cdns_torrent_phy_init(struct phy *phy) if (cmn_vals) { reg_pairs = cmn_vals->reg_pairs; num_regs = cmn_vals->num_regs; - regmap = cdns_phy->regmap_common_cdb; + regmap = tp_data->regmap_common_cdb; for (i = 0; i < num_regs; i++) regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); @@ -2434,8 +2414,8 @@ static int cdns_torrent_phy_init(struct phy *phy) if (tx_ln_vals) { reg_pairs = tx_ln_vals->reg_pairs; num_regs = tx_ln_vals->num_regs; - for (i = 0; i < inst->num_lanes; i++) { - regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane]; + for (i = 0; i < link->num_lanes; i++) { + regmap = tp_data->regmap_tx_lane_cdb[i + link->mlane]; for (j = 0; j < num_regs; j++) regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); @@ -2450,8 +2430,8 @@ static int cdns_torrent_phy_init(struct phy *phy) if (rx_ln_vals) { reg_pairs = rx_ln_vals->reg_pairs; num_regs = rx_ln_vals->num_regs; - for (i = 0; i < inst->num_lanes; i++) { - regmap = cdns_phy->regmap_rx_lane_cdb[i + inst->mlane]; + for (i = 0; i < link->num_lanes; i++) { + regmap = tp_data->regmap_rx_lane_cdb[i + link->mlane]; for (j = 0; j < num_regs; j++) regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); @@ -2465,33 +2445,33 @@ static int cdns_torrent_phy_init(struct phy *phy) } static const struct phy_ops cdns_torrent_phy_ops = { - .init = cdns_torrent_phy_init, - .configure = cdns_torrent_dp_configure, - .power_on = cdns_torrent_phy_on, - .power_off = cdns_torrent_phy_off, + .init = tp_phy_init, + .configure = tp_phy_configure, + .power_on = tp_phy_on, + .power_off = tp_phy_off, .owner = THIS_MODULE, }; static -int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) +int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data) { const struct cdns_torrent_vals *cmn_vals, *tx_ln_vals, *rx_ln_vals; - const struct cdns_torrent_data *init_data = cdns_phy->init_data; + const struct cdns_torrent_data *init_data = tp_data->init_data; const struct cdns_torrent_vals *link_cmn_vals, *xcvr_diag_vals; - enum cdns_torrent_ref_clk ref_clk1 = cdns_phy->ref_clk1_rate; - enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate; + enum cdns_torrent_ref_clk ref_clk1 = tp_data->ref_clk1_rate; + enum cdns_torrent_ref_clk ref_clk = tp_data->ref_clk_rate; const struct cdns_torrent_vals *phy_pma_cmn_vals; const struct cdns_torrent_vals *pcs_cmn_vals; enum cdns_torrent_phy_type phy_t1, phy_t2; const struct cdns_reg_pairs *reg_pairs; int i, j, node, mlane, num_lanes, ret; - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; enum cdns_torrent_ssc_mode ssc; struct regmap *regmap; u32 num_regs, num_protocols, protocol; u32 num_pcie_links = 0; - num_protocols = hweight32(cdns_phy->protocol_bitmask); + num_protocols = hweight32(tp_data->protocol_bitmask); /* Maximum 2 protocols are supported */ if (num_protocols > 2) { dev_err(dev, "at most 2 protocols are supported\n"); @@ -2504,9 +2484,9 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) * It is possible for phy_t1 to be the same as phy_t2 for special * configurations such as PCIe Multilink. */ - if (cdns_phy->nsubnodes == 2) { - phy_t1 = cdns_phy->phys[0].phy_type; - phy_t2 = cdns_phy->phys[1].phy_type; + if (tp_data->nb_links == 2) { + phy_t1 = tp_data->links[0].phy_type; + phy_t2 = tp_data->links[1].phy_type; } else { /** * Both PHY types / protocols should be unique. @@ -2520,8 +2500,8 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) return -EINVAL; } - phy_t1 = fns(cdns_phy->protocol_bitmask, 0); - phy_t2 = fns(cdns_phy->protocol_bitmask, 1); + phy_t1 = fns(tp_data->protocol_bitmask, 0); + phy_t2 = fns(tp_data->protocol_bitmask, 1); /* * PCIe Multilink configuration can be supported along with a @@ -2541,8 +2521,8 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) * phy_t1 and phy_t2 are modified in such cases to support the * PCIe Multilink configuration with a non-PCIe protocol. */ - for (node = 0; node < cdns_phy->nsubnodes; node++) { - if (cdns_phy->phys[node].phy_type == TYPE_PCIE) + for (node = 0; node < tp_data->nb_links; node++) { + if (tp_data->links[node].phy_type == TYPE_PCIE) num_pcie_links++; } @@ -2552,12 +2532,12 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) return -EINVAL; } else if (num_pcie_links == 2) { phy_t1 = TYPE_PCIE_ML; - for (node = 0; node < cdns_phy->nsubnodes; node++) { - if (cdns_phy->phys[node].phy_type == TYPE_PCIE) { - cdns_phy->phys[node].phy_type = TYPE_PCIE_ML; + for (node = 0; node < tp_data->nb_links; node++) { + if (tp_data->links[node].phy_type == TYPE_PCIE) { + tp_data->links[node].phy_type = TYPE_PCIE_ML; continue; } - phy_t2 = cdns_phy->phys[node].phy_type; + phy_t2 = tp_data->links[node].phy_type; } } } @@ -2594,13 +2574,13 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) swap(ref_clk, ref_clk1); } - for (node = 0; node < cdns_phy->nsubnodes; node++) { - if (cdns_phy->phys[node].phy_type != phy_t1) + for (node = 0; node < tp_data->nb_links; node++) { + if (tp_data->links[node].phy_type != phy_t1) continue; - mlane = cdns_phy->phys[node].mlane; - ssc = cdns_phy->phys[node].ssc_mode; - num_lanes = cdns_phy->phys[node].num_lanes; + mlane = tp_data->links[node].mlane; + ssc = tp_data->links[node].ssc_mode; + num_lanes = tp_data->links[node].num_lanes; /** * PHY configuration specific registers: @@ -2618,13 +2598,13 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) if (link_cmn_vals) { reg_pairs = link_cmn_vals->reg_pairs; num_regs = link_cmn_vals->num_regs; - regmap = cdns_phy->regmap_common_cdb; + regmap = tp_data->regmap_common_cdb; /** * First array value in link_cmn_vals must be of * PHY_PLL_CFG register */ - regmap_field_write(cdns_phy->phy_pll_cfg, + regmap_field_write(tp_data->phy_pll_cfg, reg_pairs[0].val); for (i = 1; i < num_regs; i++) @@ -2639,7 +2619,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) reg_pairs = xcvr_diag_vals->reg_pairs; num_regs = xcvr_diag_vals->num_regs; for (i = 0; i < num_lanes; i++) { - regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane]; + regmap = tp_data->regmap_tx_lane_cdb[i + mlane]; for (j = 0; j < num_regs; j++) regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); @@ -2653,7 +2633,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) if (pcs_cmn_vals) { reg_pairs = pcs_cmn_vals->reg_pairs; num_regs = pcs_cmn_vals->num_regs; - regmap = cdns_phy->regmap_phy_pcs_common_cdb; + regmap = tp_data->regmap_phy_pcs_common_cdb; for (i = 0; i < num_regs; i++) regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); @@ -2667,7 +2647,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) if (phy_pma_cmn_vals) { reg_pairs = phy_pma_cmn_vals->reg_pairs; num_regs = phy_pma_cmn_vals->num_regs; - regmap = cdns_phy->regmap_phy_pma_common_cdb; + regmap = tp_data->regmap_phy_pma_common_cdb; for (i = 0; i < num_regs; i++) regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); @@ -2680,7 +2660,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) if (cmn_vals) { reg_pairs = cmn_vals->reg_pairs; num_regs = cmn_vals->num_regs; - regmap = cdns_phy->regmap_common_cdb; + regmap = tp_data->regmap_common_cdb; for (i = 0; i < num_regs; i++) regmap_write(regmap, reg_pairs[i].off, reg_pairs[i].val); @@ -2694,7 +2674,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) reg_pairs = tx_ln_vals->reg_pairs; num_regs = tx_ln_vals->num_regs; for (i = 0; i < num_lanes; i++) { - regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane]; + regmap = tp_data->regmap_tx_lane_cdb[i + mlane]; for (j = 0; j < num_regs; j++) regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); @@ -2709,7 +2689,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) reg_pairs = rx_ln_vals->reg_pairs; num_regs = rx_ln_vals->num_regs; for (i = 0; i < num_lanes; i++) { - regmap = cdns_phy->regmap_rx_lane_cdb[i + mlane]; + regmap = tp_data->regmap_rx_lane_cdb[i + mlane]; for (j = 0; j < num_regs; j++) regmap_write(regmap, reg_pairs[j].off, reg_pairs[j].val); @@ -2717,38 +2697,38 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy) } if (phy_t1 == TYPE_DP) { - ret = cdns_torrent_dp_get_pll(cdns_phy, phy_t2); + ret = cdns_torrent_dp_get_pll(tp_data, phy_t2); if (ret) return ret; } - reset_control_deassert(cdns_phy->phys[node].lnk_rst); + reset_control_deassert(tp_data->links[node].lnk_rst); } } /* Restore TYPE_PCIE_ML to TYPE_PCIE to be compatible with suspend-resume */ - for (node = 0; node < cdns_phy->nsubnodes; node++) - if (cdns_phy->phys[node].phy_type == TYPE_PCIE_ML) - cdns_phy->phys[node].phy_type = TYPE_PCIE; + for (node = 0; node < tp_data->nb_links; node++) + if (tp_data->links[node].phy_type == TYPE_PCIE_ML) + tp_data->links[node].phy_type = TYPE_PCIE; /* Take the PHY out of reset */ - ret = reset_control_deassert(cdns_phy->phy_rst); + ret = reset_control_deassert(tp_data->phy_rst); if (ret) return ret; return 0; } -static void cdns_torrent_clk_cleanup(struct cdns_torrent_phy *cdns_phy) +static void cdns_torrent_clk_cleanup(struct tp_data *tp_data) { - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; of_clk_del_provider(dev->of_node); } -static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy) +static int tp_clk_register(struct tp_data *tp_data) { - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; struct device_node *node = dev->of_node; struct clk_hw_onecell_data *data; int ret; @@ -2758,21 +2738,21 @@ static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy) return -ENOMEM; data->num = CDNS_TORRENT_OUTPUT_CLOCKS; - cdns_phy->clk_hw_data = data; + tp_data->clk_hw_data = data; - ret = cdns_torrent_derived_refclk_register(cdns_phy); + ret = tp_derived_refclk_register(tp_data); if (ret) { dev_err(dev, "failed to register derived refclk\n"); return ret; } - ret = cdns_torrent_received_refclk_register(cdns_phy); + ret = tp_received_refclk_register(tp_data); if (ret) { dev_err(dev, "failed to register received refclk\n"); return ret; } - ret = cdns_torrent_refclk_driver_register(cdns_phy); + ret = tp_refclk_driver_register(tp_data); if (ret) { dev_err(dev, "failed to register refclk driver\n"); return ret; @@ -2787,130 +2767,130 @@ static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy) return 0; } -static int cdns_torrent_of_get_reset(struct cdns_torrent_phy *cdns_phy) +static int tp_of_get_reset(struct tp_data *tp_data) { - struct device *dev = cdns_phy->dev; + struct device *dev = tp_data->dev; - cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0); - if (IS_ERR(cdns_phy->phy_rst)) { + tp_data->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0); + if (IS_ERR(tp_data->phy_rst)) { dev_err(dev, "%s: failed to get reset\n", dev->of_node->full_name); - return PTR_ERR(cdns_phy->phy_rst); + return PTR_ERR(tp_data->phy_rst); } - cdns_phy->apb_rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb"); - if (IS_ERR(cdns_phy->apb_rst)) { + tp_data->apb_rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb"); + if (IS_ERR(tp_data->apb_rst)) { dev_err(dev, "%s: failed to get apb reset\n", dev->of_node->full_name); - return PTR_ERR(cdns_phy->apb_rst); + return PTR_ERR(tp_data->apb_rst); } return 0; } -static int cdns_torrent_of_get_clk(struct cdns_torrent_phy *cdns_phy) +static int tp_of_get_clk(struct tp_data *tp_data) { /* refclk: Input reference clock for PLL0 */ - cdns_phy->clk = devm_clk_get(cdns_phy->dev, "refclk"); - if (IS_ERR(cdns_phy->clk)) - return dev_err_probe(cdns_phy->dev, PTR_ERR(cdns_phy->clk), + tp_data->clk = devm_clk_get(tp_data->dev, "refclk"); + if (IS_ERR(tp_data->clk)) + return dev_err_probe(tp_data->dev, PTR_ERR(tp_data->clk), "phy ref clock not found\n"); /* refclk1: Input reference clock for PLL1 */ - cdns_phy->clk1 = devm_clk_get_optional(cdns_phy->dev, "pll1_refclk"); - if (IS_ERR(cdns_phy->clk1)) - return dev_err_probe(cdns_phy->dev, PTR_ERR(cdns_phy->clk1), + tp_data->clk1 = devm_clk_get_optional(tp_data->dev, "pll1_refclk"); + if (IS_ERR(tp_data->clk1)) + return dev_err_probe(tp_data->dev, PTR_ERR(tp_data->clk1), "phy PLL1 ref clock not found\n"); return 0; } -static int cdns_torrent_clk(struct cdns_torrent_phy *cdns_phy) +static int cdns_torrent_clk(struct tp_data *tp_data) { unsigned long ref_clk1_rate; unsigned long ref_clk_rate; int ret; - ret = clk_prepare_enable(cdns_phy->clk); + ret = clk_prepare_enable(tp_data->clk); if (ret) { - dev_err(cdns_phy->dev, "Failed to prepare ref clock: %d\n", ret); + dev_err(tp_data->dev, "Failed to prepare ref clock: %d\n", ret); return ret; } - ref_clk_rate = clk_get_rate(cdns_phy->clk); + ref_clk_rate = clk_get_rate(tp_data->clk); if (!ref_clk_rate) { - dev_err(cdns_phy->dev, "Failed to get ref clock rate\n"); + dev_err(tp_data->dev, "Failed to get ref clock rate\n"); ret = -EINVAL; goto disable_clk; } switch (ref_clk_rate) { case REF_CLK_19_2MHZ: - cdns_phy->ref_clk_rate = CLK_19_2_MHZ; + tp_data->ref_clk_rate = CLK_19_2_MHZ; break; case REF_CLK_25MHZ: - cdns_phy->ref_clk_rate = CLK_25_MHZ; + tp_data->ref_clk_rate = CLK_25_MHZ; break; case REF_CLK_100MHZ: - cdns_phy->ref_clk_rate = CLK_100_MHZ; + tp_data->ref_clk_rate = CLK_100_MHZ; break; case REF_CLK_156_25MHZ: - cdns_phy->ref_clk_rate = CLK_156_25_MHZ; + tp_data->ref_clk_rate = CLK_156_25_MHZ; break; default: - dev_err(cdns_phy->dev, "Invalid ref clock rate\n"); + dev_err(tp_data->dev, "Invalid ref clock rate\n"); ret = -EINVAL; goto disable_clk; } - if (cdns_phy->clk1) { - ret = clk_prepare_enable(cdns_phy->clk1); + if (tp_data->clk1) { + ret = clk_prepare_enable(tp_data->clk1); if (ret) { - dev_err(cdns_phy->dev, "Failed to prepare PLL1 ref clock: %d\n", ret); + dev_err(tp_data->dev, "Failed to prepare PLL1 ref clock: %d\n", ret); goto disable_clk; } - ref_clk1_rate = clk_get_rate(cdns_phy->clk1); + ref_clk1_rate = clk_get_rate(tp_data->clk1); if (!ref_clk1_rate) { - dev_err(cdns_phy->dev, "Failed to get PLL1 ref clock rate\n"); + dev_err(tp_data->dev, "Failed to get PLL1 ref clock rate\n"); ret = -EINVAL; goto disable_clk1; } switch (ref_clk1_rate) { case REF_CLK_19_2MHZ: - cdns_phy->ref_clk1_rate = CLK_19_2_MHZ; + tp_data->ref_clk1_rate = CLK_19_2_MHZ; break; case REF_CLK_25MHZ: - cdns_phy->ref_clk1_rate = CLK_25_MHZ; + tp_data->ref_clk1_rate = CLK_25_MHZ; break; case REF_CLK_100MHZ: - cdns_phy->ref_clk1_rate = CLK_100_MHZ; + tp_data->ref_clk1_rate = CLK_100_MHZ; break; case REF_CLK_156_25MHZ: - cdns_phy->ref_clk1_rate = CLK_156_25_MHZ; + tp_data->ref_clk1_rate = CLK_156_25_MHZ; break; default: - dev_err(cdns_phy->dev, "Invalid PLL1 ref clock rate\n"); + dev_err(tp_data->dev, "Invalid PLL1 ref clock rate\n"); ret = -EINVAL; goto disable_clk1; } } else { - cdns_phy->ref_clk1_rate = cdns_phy->ref_clk_rate; + tp_data->ref_clk1_rate = tp_data->ref_clk_rate; } return 0; disable_clk1: - clk_disable_unprepare(cdns_phy->clk1); + clk_disable_unprepare(tp_data->clk1); disable_clk: - clk_disable_unprepare(cdns_phy->clk); + clk_disable_unprepare(tp_data->clk); return ret; } static int cdns_torrent_phy_probe(struct platform_device *pdev) { - struct cdns_torrent_phy *cdns_phy; + struct tp_data *tp_data; struct device *dev = &pdev->dev; struct phy_provider *phy_provider; const struct cdns_torrent_data *data; @@ -2925,18 +2905,18 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) if (!data) return -EINVAL; - cdns_phy = devm_kzalloc_obj(dev, *cdns_phy); - if (!cdns_phy) + tp_data = devm_kzalloc_obj(dev, *tp_data); + if (!tp_data) return -ENOMEM; - dev_set_drvdata(dev, cdns_phy); - cdns_phy->dev = dev; - cdns_phy->init_data = data; - cdns_phy->protocol_bitmask = 0; + dev_set_drvdata(dev, tp_data); + tp_data->dev = dev; + tp_data->init_data = data; + tp_data->protocol_bitmask = 0; - cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(cdns_phy->sd_base)) - return PTR_ERR(cdns_phy->sd_base); + tp_data->sd_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(tp_data->sd_base)) + return PTR_ERR(tp_data->sd_base); subnodes = of_get_available_child_count(dev->of_node); if (subnodes == 0) { @@ -2944,35 +2924,35 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) return -EINVAL; } - ret = cdns_torrent_regmap_init(cdns_phy); + ret = cdns_torrent_regmap_init(tp_data); if (ret) return ret; - ret = cdns_torrent_regfield_init(cdns_phy); + ret = cdns_torrent_regfield_init(tp_data); if (ret) return ret; - ret = cdns_torrent_clk_register(cdns_phy); + ret = tp_clk_register(tp_data); if (ret) return ret; - ret = cdns_torrent_of_get_reset(cdns_phy); + ret = tp_of_get_reset(tp_data); if (ret) goto clk_cleanup; - ret = cdns_torrent_of_get_clk(cdns_phy); + ret = tp_of_get_clk(tp_data); if (ret) goto clk_cleanup; - regmap_field_read(cdns_phy->phy_pma_cmn_ctrl_1, &cdns_phy->already_configured); + regmap_field_read(tp_data->phy_pma_cmn_ctrl_1, &tp_data->already_configured); - if (!cdns_phy->already_configured) { - ret = cdns_torrent_clk(cdns_phy); + if (!tp_data->already_configured) { + ret = cdns_torrent_clk(tp_data); if (ret) goto clk_cleanup; /* Enable APB */ - reset_control_deassert(cdns_phy->apb_rst); + reset_control_deassert(tp_data->apb_rst); } for_each_available_child_of_node(dev->of_node, child) { @@ -2982,17 +2962,17 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) if (!(of_node_name_eq(child, "phy"))) continue; - cdns_phy->phys[node].lnk_rst = + tp_data->links[node].lnk_rst = of_reset_control_array_get_exclusive(child); - if (IS_ERR(cdns_phy->phys[node].lnk_rst)) { + if (IS_ERR(tp_data->links[node].lnk_rst)) { dev_err(dev, "%s: failed to get reset\n", child->full_name); - ret = PTR_ERR(cdns_phy->phys[node].lnk_rst); + ret = PTR_ERR(tp_data->links[node].lnk_rst); goto put_lnk_rst; } if (of_property_read_u32(child, "reg", - &cdns_phy->phys[node].mlane)) { + &tp_data->links[node].mlane)) { dev_err(dev, "%s: No \"reg\"-property.\n", child->full_name); ret = -EINVAL; @@ -3008,25 +2988,25 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) switch (phy_type) { case PHY_TYPE_PCIE: - cdns_phy->phys[node].phy_type = TYPE_PCIE; + tp_data->links[node].phy_type = TYPE_PCIE; break; case PHY_TYPE_DP: - cdns_phy->phys[node].phy_type = TYPE_DP; + tp_data->links[node].phy_type = TYPE_DP; break; case PHY_TYPE_SGMII: - cdns_phy->phys[node].phy_type = TYPE_SGMII; + tp_data->links[node].phy_type = TYPE_SGMII; break; case PHY_TYPE_QSGMII: - cdns_phy->phys[node].phy_type = TYPE_QSGMII; + tp_data->links[node].phy_type = TYPE_QSGMII; break; case PHY_TYPE_USB3: - cdns_phy->phys[node].phy_type = TYPE_USB; + tp_data->links[node].phy_type = TYPE_USB; break; case PHY_TYPE_USXGMII: - cdns_phy->phys[node].phy_type = TYPE_USXGMII; + tp_data->links[node].phy_type = TYPE_USXGMII; break; case PHY_TYPE_XAUI: - cdns_phy->phys[node].phy_type = TYPE_XAUI; + tp_data->links[node].phy_type = TYPE_XAUI; break; default: dev_err(dev, "Unsupported protocol\n"); @@ -3034,15 +3014,15 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) goto put_child; } - cdns_phy->phys[node].num_lanes = DEFAULT_NUM_LANES; - of_property_read_u32(child, "cdns,num-lanes", &cdns_phy->phys[node].num_lanes); + tp_data->links[node].num_lanes = DEFAULT_NUM_LANES; + of_property_read_u32(child, "cdns,num-lanes", &tp_data->links[node].num_lanes); - total_num_lanes += cdns_phy->phys[node].num_lanes; + total_num_lanes += tp_data->links[node].num_lanes; /* Get SSC mode */ - cdns_phy->phys[node].ssc_mode = NO_SSC; + tp_data->links[node].ssc_mode = NO_SSC; of_property_read_u32(child, "cdns,ssc-mode", - &cdns_phy->phys[node].ssc_mode); + &tp_data->links[node].ssc_mode); gphy = devm_phy_create(dev, child, &cdns_torrent_phy_ops); if (IS_ERR(gphy)) { @@ -3050,8 +3030,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) goto put_child; } - if (cdns_phy->phys[node].phy_type == TYPE_DP) { - switch (cdns_phy->phys[node].num_lanes) { + if (tp_data->links[node].phy_type == TYPE_DP) { + switch (tp_data->links[node].num_lanes) { case 1: case 2: case 4: @@ -3059,16 +3039,16 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) break; default: dev_err(dev, "unsupported number of lanes: %d\n", - cdns_phy->phys[node].num_lanes); + tp_data->links[node].num_lanes); ret = -EINVAL; goto put_child; } - cdns_phy->max_bit_rate = DEFAULT_MAX_BIT_RATE; + tp_data->max_bit_rate = DEFAULT_MAX_BIT_RATE; of_property_read_u32(child, "cdns,max-bit-rate", - &cdns_phy->max_bit_rate); + &tp_data->max_bit_rate); - switch (cdns_phy->max_bit_rate) { + switch (tp_data->max_bit_rate) { case 1620: case 2160: case 2430: @@ -3081,24 +3061,24 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) break; default: dev_err(dev, "unsupported max bit rate: %dMbps\n", - cdns_phy->max_bit_rate); + tp_data->max_bit_rate); ret = -EINVAL; goto put_child; } /* DPTX registers */ - cdns_phy->base = devm_platform_ioremap_resource(pdev, 1); - if (IS_ERR(cdns_phy->base)) { - ret = PTR_ERR(cdns_phy->base); + tp_data->base = devm_platform_ioremap_resource(pdev, 1); + if (IS_ERR(tp_data->base)) { + ret = PTR_ERR(tp_data->base); goto put_child; } if (!init_dp_regmap) { - ret = cdns_torrent_dp_regmap_init(cdns_phy); + ret = cdns_torrent_dp_regmap_init(tp_data); if (ret) goto put_child; - ret = cdns_torrent_dp_regfield_init(cdns_phy); + ret = cdns_torrent_dp_regfield_init(tp_data); if (ret) goto put_child; @@ -3106,21 +3086,21 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) } dev_dbg(dev, "DP max bit rate %d.%03d Gbps\n", - cdns_phy->max_bit_rate / 1000, - cdns_phy->max_bit_rate % 1000); + tp_data->max_bit_rate / 1000, + tp_data->max_bit_rate % 1000); - gphy->attrs.bus_width = cdns_phy->phys[node].num_lanes; - gphy->attrs.max_link_rate = cdns_phy->max_bit_rate; + gphy->attrs.bus_width = tp_data->links[node].num_lanes; + gphy->attrs.max_link_rate = tp_data->max_bit_rate; gphy->attrs.mode = PHY_MODE_DP; } - cdns_phy->phys[node].phy = gphy; - cdns_phy->protocol_bitmask |= BIT(cdns_phy->phys[node].phy_type); - phy_set_drvdata(gphy, &cdns_phy->phys[node]); + tp_data->links[node].phy = gphy; + tp_data->protocol_bitmask |= BIT(tp_data->links[node].phy_type); + phy_set_drvdata(gphy, &tp_data->links[node]); node++; } - cdns_phy->nsubnodes = node; + tp_data->nb_links = node; if (total_num_lanes > MAX_NUM_LANES) { dev_err(dev, "Invalid lane configuration\n"); @@ -3128,8 +3108,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) goto put_lnk_rst; } - if (cdns_phy->nsubnodes > 1 && !cdns_phy->already_configured) { - ret = cdns_torrent_phy_configure_multilink(cdns_phy); + if (tp_data->nb_links > 1 && !tp_data->already_configured) { + ret = cdns_torrent_phy_configure_multilink(tp_data); if (ret) goto put_lnk_rst; } @@ -3140,15 +3120,15 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) goto put_lnk_rst; } - if (cdns_phy->nsubnodes > 1) + if (tp_data->nb_links > 1) dev_dbg(dev, "Multi link configuration:\n"); else dev_dbg(dev, "Single link configuration:\n"); - for (i = 0; i < cdns_phy->nsubnodes; i++) + for (i = 0; i < tp_data->nb_links; i++) dev_dbg(dev, "%s (%d lanes)", - cdns_torrent_get_phy_type(cdns_phy->phys[i].phy_type), - cdns_phy->phys[i].num_lanes); + cdns_torrent_get_phy_type(tp_data->links[i].phy_type), + tp_data->links[i].num_lanes); return 0; @@ -3156,31 +3136,31 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev) node++; put_lnk_rst: for (i = 0; i < node; i++) - reset_control_put(cdns_phy->phys[i].lnk_rst); + reset_control_put(tp_data->links[i].lnk_rst); of_node_put(child); - reset_control_assert(cdns_phy->apb_rst); - clk_disable_unprepare(cdns_phy->clk1); - clk_disable_unprepare(cdns_phy->clk); + reset_control_assert(tp_data->apb_rst); + clk_disable_unprepare(tp_data->clk1); + clk_disable_unprepare(tp_data->clk); clk_cleanup: - cdns_torrent_clk_cleanup(cdns_phy); + cdns_torrent_clk_cleanup(tp_data); return ret; } static void cdns_torrent_phy_remove(struct platform_device *pdev) { - struct cdns_torrent_phy *cdns_phy = platform_get_drvdata(pdev); + struct tp_data *tp_data = platform_get_drvdata(pdev); int i; - reset_control_assert(cdns_phy->phy_rst); - reset_control_assert(cdns_phy->apb_rst); - for (i = 0; i < cdns_phy->nsubnodes; i++) { - reset_control_assert(cdns_phy->phys[i].lnk_rst); - reset_control_put(cdns_phy->phys[i].lnk_rst); + reset_control_assert(tp_data->phy_rst); + reset_control_assert(tp_data->apb_rst); + for (i = 0; i < tp_data->nb_links; i++) { + reset_control_assert(tp_data->links[i].lnk_rst); + reset_control_put(tp_data->links[i].lnk_rst); } - clk_disable_unprepare(cdns_phy->clk1); - clk_disable_unprepare(cdns_phy->clk); - cdns_torrent_clk_cleanup(cdns_phy); + clk_disable_unprepare(tp_data->clk1); + clk_disable_unprepare(tp_data->clk); + cdns_torrent_clk_cleanup(tp_data); } /* Multilink PCIe and USB Same SSC link configuration */ @@ -3329,63 +3309,63 @@ static const struct cdns_torrent_vals sgmii_qsgmii_xcvr_diag_ln_vals = { .num_regs = ARRAY_SIZE(sgmii_qsgmii_xcvr_diag_ln_regs), }; -static void cdns_torrent_refclk_driver_suspend(struct cdns_torrent_phy *cdns_phy) +static void tp_refclk_driver_suspend(struct tp_data *tp_data) { - struct clk_hw *hw = cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER]; - struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw); + struct clk_hw *hw = tp_data->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER]; + struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw); - refclk_driver->parent_index = cdns_torrent_refclk_driver_get_parent(hw); + refclk_driver->parent_index = tp_refclk_driver_get_parent(hw); } -static int cdns_torrent_refclk_driver_resume(struct cdns_torrent_phy *cdns_phy) +static int tp_refclk_driver_resume(struct tp_data *tp_data) { - struct clk_hw *hw = cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER]; - struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw); + struct clk_hw *hw = tp_data->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER]; + struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw); - return cdns_torrent_refclk_driver_set_parent(hw, refclk_driver->parent_index); + return tp_refclk_driver_set_parent(hw, refclk_driver->parent_index); } -static int cdns_torrent_phy_suspend_noirq(struct device *dev) +static int tp_suspend_noirq(struct device *dev) { - struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(dev); + struct tp_data *tp_data = dev_get_drvdata(dev); int i; - cdns_torrent_refclk_driver_suspend(cdns_phy); + tp_refclk_driver_suspend(tp_data); - reset_control_assert(cdns_phy->phy_rst); - reset_control_assert(cdns_phy->apb_rst); - for (i = 0; i < cdns_phy->nsubnodes; i++) - reset_control_assert(cdns_phy->phys[i].lnk_rst); + reset_control_assert(tp_data->phy_rst); + reset_control_assert(tp_data->apb_rst); + for (i = 0; i < tp_data->nb_links; i++) + reset_control_assert(tp_data->links[i].lnk_rst); - if (cdns_phy->already_configured) - cdns_phy->already_configured = 0; + if (tp_data->already_configured) + tp_data->already_configured = 0; else { - clk_disable_unprepare(cdns_phy->clk1); - clk_disable_unprepare(cdns_phy->clk); + clk_disable_unprepare(tp_data->clk1); + clk_disable_unprepare(tp_data->clk); } return 0; } -static int cdns_torrent_phy_resume_noirq(struct device *dev) +static int tp_resume_noirq(struct device *dev) { - struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(dev); - int node = cdns_phy->nsubnodes; + struct tp_data *tp_data = dev_get_drvdata(dev); + int node = tp_data->nb_links; int ret, i; - ret = cdns_torrent_refclk_driver_resume(cdns_phy); + ret = tp_refclk_driver_resume(tp_data); if (ret) return ret; - ret = cdns_torrent_clk(cdns_phy); + ret = cdns_torrent_clk(tp_data); if (ret) return ret; /* Enable APB */ - reset_control_deassert(cdns_phy->apb_rst); + reset_control_deassert(tp_data->apb_rst); - if (cdns_phy->nsubnodes > 1) { - ret = cdns_torrent_phy_configure_multilink(cdns_phy); + if (tp_data->nb_links > 1) { + ret = cdns_torrent_phy_configure_multilink(tp_data); if (ret) goto put_lnk_rst; } @@ -3394,18 +3374,17 @@ static int cdns_torrent_phy_resume_noirq(struct device *dev) put_lnk_rst: for (i = 0; i < node; i++) - reset_control_assert(cdns_phy->phys[i].lnk_rst); - reset_control_assert(cdns_phy->apb_rst); + reset_control_assert(tp_data->links[i].lnk_rst); + reset_control_assert(tp_data->apb_rst); - clk_disable_unprepare(cdns_phy->clk1); - clk_disable_unprepare(cdns_phy->clk); + clk_disable_unprepare(tp_data->clk1); + clk_disable_unprepare(tp_data->clk); return ret; } static DEFINE_NOIRQ_DEV_PM_OPS(cdns_torrent_phy_pm_ops, - cdns_torrent_phy_suspend_noirq, - cdns_torrent_phy_resume_noirq); + tp_suspend_noirq, tp_resume_noirq); /* PCIe and XAUI link configuration */ static const struct cdns_reg_pairs pcie_xaui_link_cmn_regs[] = { -- 2.56.1
