[PATCH v2 20/22] phy: cadence-torrent: rework suspend/resume to restore link config
Benjamin Robin
benjamin.robin at bootlin.com
Wed Dec 2 07:09:05 PST 2026
Rework the suspend/resume paths so the ref clocks are only torn down
when needed, and the PHY configuration is restored on resume if it was
lost.
On suspend, the ref clocks are now unprepared and the APB reset asserted
only when no link is still powered on (nb_phy_on == 0), i.e. when every
link went through phy_power_off() first. The per-link and global reset
states are left to the power transitions; previously the ref clocks were
unconditionally unprepared and all the resets forced.
On resume, after enabling the APB and re-initializing the ref clocks if
needed, the driver checks whether the PHY kept its configuration using
tp_is_already_configured(). If no link was powered on, or the
configuration was lost while links are still powered, all the links and
the PHY are put in reset, tp_configure_links() re-programs the PHY, and
the resets are restored to their previous state.
To track that state, struct tp_link gains an rst_asserted flag, updated
by the new tp_control_link_reset() helper that every link-reset
transition (power_on, power_off, cleanup, resume) goes through.
Signed-off-by: Benjamin Robin <benjamin.robin at bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 99 ++++++++++++++++++++++---------
1 file changed, 72 insertions(+), 27 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 02e3c91316d5..7c4c20b005a9 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -348,6 +348,7 @@ struct tp_link {
u8 num_lanes;
u8 max_lanes;
u16 bit_rate; /* in Mb/s */
+ bool rst_asserted;
enum cdns_torrent_ssc_mode ssc_mode;
};
@@ -1492,6 +1493,21 @@ static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
return ret;
}
+static int tp_control_link_reset(struct tp_link *link, bool assert_reset)
+{
+ int ret;
+
+ if (assert_reset)
+ ret = reset_control_assert(link->lnk_rst);
+ else
+ ret = reset_control_deassert(link->lnk_rst);
+
+ if (!ret)
+ link->rst_asserted = assert_reset;
+
+ return ret;
+}
+
static int tp_phy_on(struct phy *phy)
{
struct tp_link *link = phy_get_drvdata(phy);
@@ -1516,7 +1532,7 @@ static int tp_phy_on(struct phy *phy)
}
/* Take the PHY lane group out of reset */
- ret = reset_control_deassert(link->lnk_rst);
+ ret = tp_control_link_reset(link, false);
if (ret)
goto failed;
@@ -1553,7 +1569,7 @@ static int tp_phy_on(struct phy *phy)
return 0;
failed:
- reset_control_assert(link->lnk_rst);
+ tp_control_link_reset(link, true);
if (tp_data->nb_phy_on == 0)
reset_control_assert(tp_data->phy_rst);
@@ -1568,7 +1584,7 @@ static int tp_phy_off(struct phy *phy)
guard(mutex)(&tp_data->lock);
- ret = reset_control_assert(link->lnk_rst);
+ ret = tp_control_link_reset(link, true);
if (ret)
return ret;
@@ -2694,7 +2710,7 @@ static int tp_dp_reg_base_init(struct platform_device *pdev, struct tp_data *tp_
static void tp_cleanup_remove(struct tp_data *tp_data)
{
for (u8 i = 0; i < tp_data->nb_links; ++i) {
- reset_control_assert(tp_data->links[i].lnk_rst);
+ tp_control_link_reset(&tp_data->links[i], true);
reset_control_put(tp_data->links[i].lnk_rst);
}
@@ -2984,7 +3000,7 @@ static void tp_refclk_driver_suspend(struct tp_data *tp_data)
refclk_driver->parent_index = tp_refclk_driver_get_parent(hw);
}
-static int tp_refclk_driver_resume(struct tp_data *tp_data)
+static int tp_refclk_driver_resume(const struct tp_data *tp_data)
{
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);
@@ -2994,51 +3010,80 @@ static int tp_refclk_driver_resume(struct tp_data *tp_data)
static int tp_suspend_noirq(struct device *dev)
{
+ int ret = 0;
struct tp_data *tp_data = dev_get_drvdata(dev);
- int i;
tp_refclk_driver_suspend(tp_data);
- 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);
-
tp_data->already_configured = false;
- tp_ref_clks_uninit(tp_data);
+ if (!tp_data->nb_phy_on) {
+ tp_ref_clks_uninit(tp_data);
+ ret = reset_control_assert(tp_data->apb_rst);
+ }
- return 0;
+ return ret;
}
static int tp_resume_noirq(struct device *dev)
{
+ int ret;
+ bool config_needed = false;
+ bool restore_resets = false;
struct tp_data *tp_data = dev_get_drvdata(dev);
- int node = tp_data->nb_links;
- int ret, i;
+
+ /* Enable APB unconditionally */
+ ret = reset_control_deassert(tp_data->apb_rst);
+ if (ret)
+ return ret;
ret = tp_refclk_driver_resume(tp_data);
if (ret)
- return ret;
+ goto failed;
ret = tp_ref_clks_init(tp_data);
if (ret)
- return ret;
+ goto failed;
- /* Enable APB */
- reset_control_deassert(tp_data->apb_rst);
+ /* Check if we have lost the configuration */
+ if (!tp_data->nb_phy_on) {
+ /* All the links are in reset, and the torrent PHY is in reset */
+ config_needed = true;
- ret = tp_configure_links(tp_data);
- if (ret)
- goto put_lnk_rst;
+ } else if (!tp_is_already_configured(tp_data)) {
+ /* First put all the links in reset, and the PHY in reset */
+ for (u8 i = 0; i < tp_data->nb_links; ++i)
+ reset_control_assert(tp_data->links[i].lnk_rst);
+
+ reset_control_assert(tp_data->phy_rst);
+ config_needed = true;
+ restore_resets = true;
+ }
+
+ if (config_needed) {
+ ret = tp_configure_links(tp_data);
+ if (ret)
+ goto failed;
+ }
+
+ if (restore_resets) {
+ /* Restore resets in previous state */
+ reset_control_deassert(tp_data->phy_rst);
+
+ for (u8 i = 0; i < tp_data->nb_links; ++i) {
+ struct tp_link *link = &tp_data->links[i];
+
+ if (!link->rst_asserted)
+ reset_control_deassert(link->lnk_rst);
+ }
+ }
return 0;
-put_lnk_rst:
- for (i = 0; i < node; i++)
- reset_control_assert(tp_data->links[i].lnk_rst);
- reset_control_assert(tp_data->apb_rst);
+failed:
+ for (u8 i = 0; i < tp_data->nb_links; ++i)
+ tp_control_link_reset(&tp_data->links[i], true);
- tp_ref_clks_uninit(tp_data);
+ reset_control_assert(tp_data->phy_rst);
return ret;
}
--
2.56.1
More information about the linux-arm-kernel
mailing list