Move the PHY register programming out of the per-phy init path and into
the probe, and restrict the reset handling to phy_power_on() and
phy_power_off().

Register configuration now happens once in the new tp_configure_links()
helper, called from the probe (and from resume): it dispatches to
cdns_torrent_phy_configure_multilink() for multi-link setups and to the
new tp_configure_single_link() otherwise, and initializes the registers
of each DP link. The previous special-casing -- single-link PHYs
configured in phy_init, multi-link PHYs configured in the probe -- is
therefore removed.

Reset control is now handled solely from phy_power_on()/phy_power_off():
the link reset is deasserted on power_on, the global torrent reset only
when the first link comes up, and phy_power_off() asserts the link reset
and re-asserts the global reset once the last link is down. Guarded by the
driver lock, the `nb_phy_on` counter tracks the number of powered-on links,
telling us when to assert/deassert the torrent reset.

The DisplayPort bring-up is reworked as well: tp_phy_init() only programs
the per-link DP registers and no longer starts the link. The link is
actually brought up from phy_power_on() through tp_dp_run(), which
enables the PLL and drives the power-state sequence (A2/A0). If
phy_configure() reconfigures a link that is already powered on, the link
is restarted after the reconfiguration; otherwise the DP PLL is left
disabled until the link is powered up.

This relies on the DisplayPort controller driver actually calling
phy_power_on()/phy_power_off(), which the cdns-mhdp8546 driver previously
did not; that driver is updated by the series at [1].

[1] https://lore.kernel.org/all/[email protected]/T/

Signed-off-by: Benjamin Robin <[email protected]>
---
 drivers/phy/cadence/phy-cadence-torrent.c | 414 ++++++++++++++----------------
 1 file changed, 198 insertions(+), 216 deletions(-)

diff --git a/drivers/phy/cadence/phy-cadence-torrent.c 
b/drivers/phy/cadence/phy-cadence-torrent.c
index 9a2621fb3ac7..3b4d52ee7a53 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -354,6 +354,9 @@ struct tp_link {
 struct tp_data {
        void __iomem *base; /* DPTX registers base */
        void __iomem *sd_base; /* SD0801 registers base */
+       /* Protect `nb_phy_on` and concurrent register writes */
+       struct mutex lock;
+
        u32 dp_pll;
        u32 protocol_bitmask;
        struct reset_control *phy_rst;
@@ -367,6 +370,7 @@ struct tp_data {
        bool already_configured;
        bool ref_clks_initialized;
        u8 mask_used_lanes;
+       u8 nb_phy_on;
 
        struct tp_link links[MAX_NUM_LANES];
        int nb_links;
@@ -994,6 +998,26 @@ static int cdns_torrent_dp_get_pll(struct tp_data *tp_data,
        return 0;
 }
 
+static int tp_dp_enable_pll(const struct tp_data *tp_data)
+{
+       const struct tp_reg_base *reg_base = &tp_data->reg_phy_pma_common_cdb;
+       u16 pll_mask;
+       u16 val;
+
+       pll_mask = tp_data->dp_pll;
+
+       /* Enable the associated PLL (cmn_pll0_en or cmn_pll1_en) */
+       tp_reg_set_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
+
+       /*
+        * Wait for PLL ready assertion.
+        * For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1
+        * For PLL1 - PHY_PMA_CMN_CTRL2[1] == 1
+        */
+       return read_poll_timeout(tp_reg_read, val, (val & pll_mask) == 
pll_mask, 0,
+                                POLL_TIMEOUT_US, false, reg_base, 
PHY_PMA_CMN_CTRL2);
+}
+
 /*
  * Enable or disable PLL for selected lanes.
  */
@@ -1065,6 +1089,13 @@ static int tp_dptx_set_power_state(const struct tp_data 
*tp_data, u32 mlane, u32
                mask |= PMA_XCVR_POWER_STATE_REQ_LN_MASK << 
PHY_POWER_STATE_LN(mlane + i);
        }
 
+       /* Do not got to power state A3 if already off */
+       if (powerstate == POWERSTATE_A3) {
+               read_val = tp_reg_dptx_read(tp_data, 
PHY_PMA_XCVR_POWER_STATE_ACK);
+               if ((read_val & mask) == 0)
+                       return 0;
+       }
+
        /* Set power state A<n>. */
        tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_POWER_STATE_REQ, value);
 
@@ -1097,34 +1128,37 @@ static int tp_dptx_wait_pma_cmn_ready(const struct 
tp_data *tp_data)
        return 0;
 }
 
-static int tp_dp_run(struct tp_data *tp_data, struct tp_link *link)
+static int tp_dp_run(const struct tp_data *tp_data, const struct tp_link *link)
 {
-       void __iomem *addr;
-       unsigned int read_val;
        int ret;
 
-       /*
-        * waiting for ACK of pma_xcvr_pllclk_en_ln_*, only for the
-        * master lane
-        */
-       addr = tp_data->base + PHY_PMA_XCVR_PLLCLK_EN_ACK;
-       ret = readl_poll_timeout(addr, read_val, read_val & 1, 0, 
POLL_TIMEOUT_US);
-       if (ret < 0) {
-               dev_err(tp_data->dev, "timeout waiting for link PLL clock 
enable ack\n");
+       ret = tp_dp_enable_pll(tp_data);
+       if (ret)
+               return ret;
+
+       ret = tp_dptx_wait_pma_cmn_ready(tp_data);
+       if (ret)
                return ret;
-       }
 
        ndelay(100);
+       ret = tp_dptx_set_pll_en(tp_data, link->mlane, link->num_lanes, true);
+       if (ret)
+               return ret;
 
+       ndelay(100);
        ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, 
POWERSTATE_A2);
        if (ret)
                return ret;
 
        ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, 
POWERSTATE_A0);
+       if (ret)
+               return ret;
 
-       return ret;
+       ndelay(900);
+       return 0;
 }
 
+
 static void cdns_torrent_dp_pma_cmn_rate(struct tp_data *tp_data,
                                         struct tp_link *link,
                                         u32 rate, u32 num_lanes)
@@ -1193,7 +1227,7 @@ static void tp_dp_update_pll_freq(struct tp_data 
*tp_data, struct tp_link *link,
  * set and PLL disable request was processed.
  */
 static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link,
-                               struct phy_configure_opts_dp *dp)
+                               const struct phy_configure_opts_dp *dp)
 {
        struct tp_reg_base *reg_base = &tp_data->reg_phy_pma_common_cdb;
        u16 pll_mask;
@@ -1222,17 +1256,7 @@ static int tp_dp_configure_rate(struct tp_data *tp_data, 
struct tp_link *link,
 
        /* Reconfigure registers associated with link rate */
        tp_dp_update_pll_freq(tp_data, link, dp->link_rate, dp->ssc);
-
-       /* Enable the associated PLL (cmn_pll0_en or cmn_pll1_en) */
-       tp_reg_set_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
-
-       /*
-        * Wait for PLL ready assertion.
-        * For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1
-        * For PLL1 - PHY_PMA_CMN_CTRL2[1] == 1
-        */
-       return read_poll_timeout(tp_reg_read, val, (val & pll_mask) == 
pll_mask, 0,
-                                POLL_TIMEOUT_US, false, reg_base, 
PHY_PMA_CMN_CTRL2);
+       return 0;
 }
 
 /*
@@ -1286,35 +1310,16 @@ static int tp_dp_verify_config(const struct tp_link 
*link,
        return 0;
 }
 
-/* Set power state A0 and PLL clock enable to 0 on enabled lanes. */
-static void cdns_torrent_dp_set_a0_pll(struct tp_data *tp_data,
-                                      struct tp_link *link,
-                                      u32 num_lanes)
-{
-       u32 pwr_state = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_POWER_STATE_REQ);
-       u32 pll_clk_en = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
-       u32 i;
-
-       for (i = 0; i < num_lanes; i++) {
-               pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK
-                            << PHY_POWER_STATE_LN(link->mlane + i));
-
-               pll_clk_en &= ~(0x01U << (link->mlane + i));
-       }
-
-       tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_POWER_STATE_REQ, pwr_state);
-       tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, pll_clk_en);
-}
-
 /* Configure lane count as required. */
-static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link, u32 
num_lanes)
+static void tp_dp_set_lanes(const struct tp_data *tp_data, struct tp_link 
*link, u32 num_lanes)
 {
        u32 pma_tx_elec_idle_mask;
        u32 used_lane_mask;
        u32 all_lane_mask;
+       u32 pll_clk_en;
+       u32 pwr_state;
        u32 value;
        u32 mlane = link->mlane;
-       int ret;
 
        used_lane_mask = ((1U << num_lanes) - 1) << mlane;
        all_lane_mask = ((1U << link->max_lanes) - 1) << mlane;
@@ -1345,7 +1350,17 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, 
struct tp_link *link, u32 nu
        value &= ~(1U << mlane);
        tp_reg_dptx_write(tp_data, PHY_RESET, value);
 
-       cdns_torrent_dp_set_a0_pll(tp_data, link, link->max_lanes);
+       /* Clear requested power state set PLL clock enable to 0 on all used 
lanes. */
+       pwr_state = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_POWER_STATE_REQ);
+       pll_clk_en = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
+
+       for (u32 i = 0; i < link->max_lanes; ++i)
+               pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK << 
PHY_POWER_STATE_LN(mlane + i));
+
+       pll_clk_en &= ~all_lane_mask;
+
+       tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_POWER_STATE_REQ, pwr_state);
+       tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, pll_clk_en);
 
        /* release master lane reset */
        value |= 1 << mlane;
@@ -1353,55 +1368,29 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, 
struct tp_link *link, u32 nu
 
        /* update the number of used lanes */
        link->num_lanes = num_lanes;
-
-       /* Wait, until PHY gets ready after releasing PHY reset signal. */
-       ret = tp_dptx_wait_pma_cmn_ready(tp_data);
-       if (ret)
-               return ret;
-
-       ndelay(100);
-
-       /* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
-       value = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
-       value |= 1 << mlane;
-       tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, value);
-
-       ret = tp_dp_run(tp_data, link);
-
-       return ret;
 }
 
 /* Configure link rate as required. */
 static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
-                         struct phy_configure_opts_dp *dp)
+                         const struct phy_configure_opts_dp *dp)
 {
        int ret;
 
-       ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, 
POWERSTATE_A3);
+       ret = tp_dptx_set_power_state(tp_data, link->mlane, link->max_lanes, 
POWERSTATE_A3);
        if (ret)
                return ret;
+
        ret = tp_dptx_set_pll_en(tp_data, link->mlane, link->max_lanes, false);
        if (ret)
                return ret;
-       ndelay(200);
 
+       ndelay(200);
        ret = tp_dp_configure_rate(tp_data, link, dp);
        if (ret)
                return ret;
+
        ndelay(200);
-
-       ret = tp_dptx_set_pll_en(tp_data, link->mlane, link->num_lanes, true);
-       if (ret)
-               return ret;
-       ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, 
POWERSTATE_A2);
-       if (ret)
-               return ret;
-       ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, 
POWERSTATE_A0);
-       if (ret)
-               return ret;
-       ndelay(900);
-
-       return ret;
+       return 0;
 }
 
 /* Configure voltage swing and pre-emphasis for all enabled lanes. */
@@ -1437,38 +1426,46 @@ static void tp_dp_set_voltages(const struct tp_data 
*tp_data, const struct tp_li
 
 static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
 {
-       struct tp_link *link = phy_get_drvdata(phy);
        struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
+       struct tp_link *link = phy_get_drvdata(phy);
+       bool run_needed = false;
        int ret;
 
+       guard(mutex)(&tp_data->lock);
+
        if (tp_data->already_configured)
                return 0;
 
+       if (link->phy_type != TYPE_DP)
+               return -EINVAL;
+
        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 = tp_dp_set_lanes(tp_data, link, opts->dp.lanes);
-               if (ret) {
-                       dev_err(&phy->dev, "tp_dp_set_lanes failed\n");
-                       return ret;
-               }
+       if (opts->dp.set_lanes && opts->dp.lanes != link->num_lanes) {
+               tp_dp_set_lanes(tp_data, link, opts->dp.lanes);
+               run_needed = true;
        }
 
        if (opts->dp.set_rate) {
                ret = tp_dp_set_rate(tp_data, link, &opts->dp);
                if (ret) {
-                       dev_err(&phy->dev, "tp_dp_set_rate failed\n");
+                       dev_err(&phy->dev, "Set rate failed\n");
                        return ret;
                }
+               run_needed = true;
        }
 
        if (opts->dp.set_voltages)
                tp_dp_set_voltages(tp_data, link, &opts->dp);
 
+       /* Restart the link after reconfiguration if it was already running */
+       if (phy->power_count && run_needed)
+               ret = tp_dp_run(tp_data, link);
+
        return ret;
 }
 
@@ -1479,46 +1476,65 @@ static int tp_phy_on(struct phy *phy)
        u16 val;
        int ret;
 
+       guard(mutex)(&tp_data->lock);
+
        if (tp_data->already_configured) {
                /* Give 5ms to 10ms delay for the PIPE clock to be stable */
                usleep_range(5000, 10000);
+               tp_data->nb_phy_on++;
                return 0;
        }
 
-       if (tp_data->nb_links == 1) {
-               /* Take the PHY lane group out of reset */
-               reset_control_deassert(link->lnk_rst);
-
+       if (tp_data->nb_phy_on == 0) {
                /* Take the PHY out of reset */
                ret = reset_control_deassert(tp_data->phy_rst);
                if (ret)
                        return ret;
        }
 
+       /* Take the PHY lane group out of reset */
+       ret = reset_control_deassert(link->lnk_rst);
+       if (ret)
+               goto failed;
+
        /*
         * Wait for cmn_ready assertion
         * PHY_PMA_CMN_CTRL1[0] == 1
         */
        ret = read_poll_timeout(tp_reg_read, val, val & 1, 1000, 
PLL_LOCK_TIMEOUT, false,
                                &tp_data->reg_phy_pma_common_cdb, 
PHY_PMA_CMN_CTRL1);
-       if (ret) {
+       if (ret < 0) {
                dev_err(tp_data->dev, "Timeout waiting for CMN ready\n");
-               return ret;
+               goto failed;
        }
 
-       if (link->phy_type == TYPE_PCIE || link->phy_type == TYPE_USB) {
+       if (link->phy_type == TYPE_DP) {
+               ret = tp_dp_run(tp_data, link);
+               if (ret < 0) {
+                       dev_err(tp_data->dev, "Failed to start DisplayPort 
link\n");
+                       goto failed;
+               }
+       } else if (link->phy_type == TYPE_PCIE || link->phy_type == TYPE_USB) {
                struct tp_reg_base *reg_base = 
&tp_data->reg_phy_pcs_lane_cdb[link->mlane];
 
                ret = read_poll_timeout(tp_reg_read, val, (val & 2) == 0, 1000,
                                        PLL_LOCK_TIMEOUT, false, reg_base,
                                        PHY_PCS_ISO_LINK_CTRL);
-               if (ret == -ETIMEDOUT) {
+               if (ret < 0) {
                        dev_err(tp_data->dev, "Timeout waiting for PHY status 
ready\n");
-                       return ret;
+                       goto failed;
                }
        }
 
+       tp_data->nb_phy_on++;
        return 0;
+
+failed:
+       reset_control_assert(link->lnk_rst);
+       if (tp_data->nb_phy_on == 0)
+               reset_control_assert(tp_data->phy_rst);
+
+       return ret;
 }
 
 static int tp_phy_off(struct phy *phy)
@@ -1527,112 +1543,79 @@ static int tp_phy_off(struct phy *phy)
        struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
        int ret;
 
-       if (tp_data->nb_links != 1)
-               return 0;
+       guard(mutex)(&tp_data->lock);
 
-       ret = reset_control_assert(tp_data->phy_rst);
+       ret = reset_control_assert(link->lnk_rst);
        if (ret)
                return ret;
 
-       return reset_control_assert(link->lnk_rst);
+       if (tp_data->nb_phy_on == 1) {
+               ret = reset_control_assert(tp_data->phy_rst);
+               if (ret)
+                       return ret;
+       }
+
+       tp_data->nb_phy_on--;
+       return 0;
 }
 
-static void cdns_torrent_dp_common_init(struct tp_data *tp_data,
-                                       struct tp_link *link)
+static int tp_dp_phy_init(struct tp_data *tp_data, struct tp_link *link)
 {
-       unsigned char lane_bits;
-       u32 val;
+       /* check reference clock */
+       if (tp_data->nb_links > 1) {
+               if (tp_data->ref_clk_rate != CLK_100_MHZ) {
+                       dev_err(tp_data->dev, "Unsupported Ref Clock Rate\n");
+                       return -EINVAL;
+               }
+       } else {
+               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(tp_data->dev, "Unsupported Ref Clock Rate\n");
+                       return -EINVAL;
+               }
+       }
 
-       tp_reg_dptx_write(tp_data, PHY_AUX_CTRL, 0x0003); /* enable AUX */
+       /* enable AUX */
+       tp_reg_dptx_write(tp_data, PHY_AUX_CTRL, 0x0003);
 
-       /*
-        * Set lines power state to A0
-        * Set lines pll clk enable to 0
-        */
-       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 << link->num_lanes) - 1;
-
-       val = tp_reg_dptx_read(tp_data, PHY_RESET);
-       val |= (0xF & lane_bits);
-       val &= ~(lane_bits << 4);
-       tp_reg_dptx_write(tp_data, PHY_RESET, val);
-
-       /* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
-       val = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
-       val |= 1;
-       tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, val);
-
-       /*
-        * PHY PMA registers configuration functions
-        * Initialize PHY with max supported link rate, without SSC.
-        */
-       tp_dp_update_pll_freq(tp_data, link, link->max_bit_rate, false);
+       /* configure the number of lanes */
+       tp_dp_set_lanes(tp_data, link, link->num_lanes);
 
        /* take out of reset */
        tp_dptx_deassert_phy_reset(tp_data);
-}
-
-static int cdns_torrent_dp_start(struct tp_data *tp_data, struct tp_link 
*link, struct phy *phy)
-{
-       int ret;
-
-       ret = tp_phy_on(phy);
-       if (ret)
-               return ret;
-
-       ret = tp_dptx_wait_pma_cmn_ready(tp_data);
-       if (ret)
-               return ret;
-
-       ret = tp_dp_run(tp_data, link);
 
-       return ret;
+       return 0;
 }
 
-static int cdns_torrent_dp_init(struct phy *phy)
+static int tp_phy_init(struct phy *phy)
 {
-       struct tp_link *link = phy_get_drvdata(phy);
        struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
-       int ret;
+       struct tp_link *link = phy_get_drvdata(phy);
+       int ret = 0;
 
-       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(tp_data->dev, "Unsupported Ref Clock Rate\n");
-               return -EINVAL;
-       }
+       guard(mutex)(&tp_data->lock);
 
-       ret = cdns_torrent_dp_get_pll(tp_data, TYPE_NONE);
-       if (ret)
-               return ret;
+       if (tp_data->already_configured)
+               return 0;
 
-       cdns_torrent_dp_common_init(tp_data, link);
+       if (link->phy_type == TYPE_DP)
+               ret = tp_dp_phy_init(tp_data, link);
 
-       return cdns_torrent_dp_start(tp_data, link, phy);
+       return ret;
 }
 
-static int cdns_torrent_dp_multilink_init(struct tp_data *tp_data,
-                                         struct tp_link *link,
-                                         struct phy *phy)
-{
-       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(tp_data, link);
-
-       return cdns_torrent_dp_start(tp_data, link, phy);
-}
+static const struct phy_ops cdns_torrent_phy_ops = {
+       .init           = tp_phy_init,
+       .configure      = tp_phy_configure,
+       .power_on       = tp_phy_on,
+       .power_off      = tp_phy_off,
+       .owner          = THIS_MODULE,
+};
 
 static int tp_derived_refclk_enable(struct clk_hw *hw)
 {
@@ -1930,14 +1913,12 @@ static void tp_reg_bases_init(struct tp_data *tp_data)
        tp_reg_base_init(tp_data, block_offset, 
&tp_data->reg_phy_pma_common_cdb);
 }
 
-static int tp_phy_init(struct phy *phy)
+static int tp_configure_single_link(struct tp_data *tp_data, struct tp_link 
*link)
 {
-       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 = tp_data->init_data;
        const struct cdns_torrent_vals *link_cmn_vals, *xcvr_diag_vals;
        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 = link->ssc_mode;
@@ -1945,16 +1926,7 @@ static int tp_phy_init(struct phy *phy)
        const struct cdns_reg_pairs *reg_pairs;
        struct tp_reg_base *reg_base;
        u32 num_regs;
-       int i, j;
-
-       if (tp_data->already_configured)
-               return 0;
-
-       if (tp_data->nb_links > 1) {
-               if (phy_type == TYPE_DP)
-                       return cdns_torrent_dp_multilink_init(tp_data, link, 
phy);
-               return 0;
-       }
+       int i, j, ret;
 
        /**
         * Spread spectrum generation is not required or supported
@@ -2066,20 +2038,15 @@ static int tp_phy_init(struct phy *phy)
                }
        }
 
-       if (phy_type == TYPE_DP)
-               return cdns_torrent_dp_init(phy);
+       if (phy_type == TYPE_DP) {
+               ret = cdns_torrent_dp_get_pll(tp_data, TYPE_NONE);
+               if (ret)
+                       return ret;
+       }
 
        return 0;
 }
 
-static const struct phy_ops cdns_torrent_phy_ops = {
-       .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 tp_data *tp_data)
 {
@@ -2106,7 +2073,6 @@ int cdns_torrent_phy_configure_multilink(struct tp_data 
*tp_data)
                return -EINVAL;
        }
 
-
        /**
         * Get PHY types directly from subnodes if only 2 subnodes exist.
         * It is possible for phy_t1 to be the same as phy_t2 for special
@@ -2328,8 +2294,6 @@ int cdns_torrent_phy_configure_multilink(struct tp_data 
*tp_data)
                                if (ret)
                                        return ret;
                        }
-
-                       reset_control_deassert(tp_data->links[node].lnk_rst);
                }
        }
 
@@ -2338,12 +2302,31 @@ int cdns_torrent_phy_configure_multilink(struct tp_data 
*tp_data)
                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(tp_data->phy_rst);
+       return 0;
+}
+
+static int tp_configure_links(struct tp_data *tp_data)
+{
+       int ret;
+
+       if (tp_data->nb_links > 1)
+               ret = cdns_torrent_phy_configure_multilink(tp_data);
+       else
+               ret = tp_configure_single_link(tp_data, &tp_data->links[0]);
+
        if (ret)
                return ret;
 
-       return 0;
+       /*
+        * PHY PMA registers configuration functions
+        * Initialize PHY with max supported link rate, without SSC.
+        */
+       for (u8 i = 0; i < tp_data->nb_links; ++i) {
+               struct tp_link *link = &tp_data->links[i];
+
+               if (link->phy_type == TYPE_DP)
+                       tp_dp_update_pll_freq(tp_data, link, 
link->max_bit_rate, false);
+       }
 }
 
 static int tp_clk_register(struct tp_data *tp_data)
@@ -2713,6 +2696,7 @@ static int cdns_torrent_phy_probe(struct platform_device 
*pdev)
                return -ENOMEM;
 
        dev_set_drvdata(dev, tp_data);
+       mutex_init(&tp_data->lock);
        tp_data->dev = dev;
        tp_data->init_data = data;
        tp_data->protocol_bitmask = 0;
@@ -2772,8 +2756,8 @@ static int cdns_torrent_phy_probe(struct platform_device 
*pdev)
        if (ret)
                goto cleanup;
 
-       if (tp_data->nb_links > 1 && !tp_data->already_configured) {
-               ret = cdns_torrent_phy_configure_multilink(tp_data);
+       if (!tp_data->already_configured) {
+               ret = tp_configure_links(tp_data);
                if (ret)
                        goto cleanup;
        }
@@ -3008,11 +2992,9 @@ static int tp_resume_noirq(struct device *dev)
        /* Enable APB */
        reset_control_deassert(tp_data->apb_rst);
 
-       if (tp_data->nb_links > 1) {
-               ret = cdns_torrent_phy_configure_multilink(tp_data);
-               if (ret)
-                       goto put_lnk_rst;
-       }
+       ret = tp_configure_links(tp_data);
+       if (ret)
+               goto put_lnk_rst;
 
        return 0;
 

-- 
2.56.1

Reply via email to