* [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants
[not found] <20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com>
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup Benjamin Robin
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Benjamin Robin @ 2026-12-02 15:08 UTC (permalink / raw)
To: Nishanth Menon, Vignesh Raghavendra, Tero Kristo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Siddharth Vadapalli,
Andrew Davis, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Vinod Koul, Manivannan Sadhasivam, Swapnil Jakhade,
Yuti Amonkar, Philipp Zabel
Cc: thomas.petazzoni, Chintan Vankar, Abhash Kumar Jha,
Thomas Richard, Gregory CLEMENT, Théo Lebrun, Tawfik Bayouk,
Vladimir Kondratiev, linux-arm-kernel, devicetree, linux-kernel,
dri-devel, linux-phy, Benjamin Robin
Add the CDNS_TORRENT_MODE_* constants to
`include/dt-bindings/phy/phy-cadence.h`. They are used by the Cadence
Torrent PHY driver and referenced by the "cdns,phy-mode" property to
select an optional configuration for a given PHY standard.
The Torrent PHY supports multiple standards (PCIe, USB, SATA, XAUI,
SGMII, ...). Some of them expose additional configuration options,
each encoded as a bit in "cdns,phy-mode":
- USB:
CDNS_TORRENT_MODE_USB_IO_11V selects the 1.1 V I/O supply voltage
(instead of 1.2 V), which affects the TX full-swing magnitude
multiplier configuration for the USB TX/RX pad supply.
CDNS_TORRENT_MODE_USB_G1 limits the link to SuperSpeed Gen 1 (5 Gb/s)
instead of Gen 2 (10 Gb/s, SuperSpeed+) to reduce power.
- SATA:
CDNS_TORRENT_MODE_SATA_LP limits the link to SATA Gen 2 (3 Gb/s)
instead of allowing Gen 3 (6 Gb/s), to reduce power.
- XAUI:
CDNS_TORRENT_MODE_XAUI_LP restricts the link to 1X operation
(3.125 Gb/s lane rate), dropping the 2X rate (6.25 Gb/s), again to
reduce power.
- SGMII:
CDNS_TORRENT_MODE_2500_BASEX overclocks the link to 2500BASE-X
(called "SGMII+" in the user guide) instead of 1 Gb/s.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml | 8 ++++++++
include/dt-bindings/phy/phy-cadence.h | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml b/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml
index 827f76e5edba..b91a957ef422 100644
--- a/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml
+++ b/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml
@@ -101,6 +101,14 @@ patternProperties:
$ref: /schemas/types.yaml#/definitions/uint32
enum: [1, 2, 3, 4, 5, 6, 7, 8, 9, 12]
+ cdns,phy-mode:
+ description:
+ Specifies an optional mode of PHY for which the group of PHY lanes is used.
+ Refer include/dt-bindings/phy/phy-cadence.h for the constants to be used.
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [0, 1, 2, 3, 4, 8, 16]
+ default: 0
+
cdns,num-lanes:
description:
Number of lanes.
diff --git a/include/dt-bindings/phy/phy-cadence.h b/include/dt-bindings/phy/phy-cadence.h
index 0671991208fc..ed2c11b3150d 100644
--- a/include/dt-bindings/phy/phy-cadence.h
+++ b/include/dt-bindings/phy/phy-cadence.h
@@ -15,6 +15,13 @@
#define CDNS_TORRENT_DERIVED_REFCLK 1
#define CDNS_TORRENT_RECEIVED_REFCLK 2
+#define CDNS_TORRENT_MODE_NONE 0x00
+#define CDNS_TORRENT_MODE_USB_G1 0x01
+#define CDNS_TORRENT_MODE_USB_IO_11V 0x02
+#define CDNS_TORRENT_MODE_XAUI_LP 0x04
+#define CDNS_TORRENT_MODE_SATA_LP 0x08
+#define CDNS_TORRENT_MODE_2500_BASEX 0x10
+
/* Sierra */
#define CDNS_SIERRA_PLL_CMNLC 0
#define CDNS_SIERRA_PLL_CMNLC1 1
--
2.56.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup
[not found] <20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com>
2026-12-02 15:08 ` [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:24 ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
` (6 subsequent siblings)
8 siblings, 1 reply; 11+ messages in thread
From: Benjamin Robin @ 2026-12-02 15:08 UTC (permalink / raw)
To: Nishanth Menon, Vignesh Raghavendra, Tero Kristo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Siddharth Vadapalli,
Andrew Davis, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Vinod Koul, Manivannan Sadhasivam, Swapnil Jakhade,
Yuti Amonkar, Philipp Zabel
Cc: thomas.petazzoni, Chintan Vankar, Abhash Kumar Jha,
Thomas Richard, Gregory CLEMENT, Théo Lebrun, Tawfik Bayouk,
Vladimir Kondratiev, linux-arm-kernel, devicetree, linux-kernel,
dri-devel, linux-phy, Benjamin Robin
Rework the reference clock setup and simplify the probe error handling.
Reference clock initialization is factored into tp_ref_clk_init(),
which enables a single ref clock and validates its rate, called twice
from tp_ref_clks_init(). The helper takes the clock name ("main" or
"PLL1") so it can be reported in error messages. A ref_clks_initialized
flag tracks whether the clocks are currently enabled, letting
tp_ref_clks_uninit() disable them only when they were previously set up.
The ref clocks are now initialized only after the phy subnodes have been
parsed successfully, since they are not needed when no subnode is
present. This also sets up a later step, since the set of allowed
reference clock frequencies will depend on the selected standards.
All the probe error paths are folded into a single cleanup label that
calls tp_cleanup_remove(), which asserts the APB reset and uninitializes
the ref clocks. cdns_torrent_phy_remove() reuses the same helper.
Finally, the APB reset is now deasserted before tp_is_already_configured()
reads the registers, so the check runs on a block that is not held in
reset.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 182 ++++++++++++++----------------
1 file changed, 87 insertions(+), 95 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 69e5323b1d68..de4ff3a133ff 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -363,11 +363,13 @@ struct tp_data {
struct clk *clk1;
enum cdns_torrent_ref_clk ref_clk_rate;
enum cdns_torrent_ref_clk ref_clk1_rate;
+
+ bool already_configured;
+ bool ref_clks_initialized;
u8 mask_used_lanes;
struct tp_link links[MAX_NUM_LANES];
int nb_links;
- int already_configured;
const struct cdns_torrent_data *init_data;
struct tp_reg_base reg_common_cdb;
@@ -2422,89 +2424,86 @@ static int tp_of_get_clk(struct tp_data *tp_data)
return 0;
}
-static int cdns_torrent_clk(struct tp_data *tp_data)
+static int tp_ref_clk_init(const struct tp_data *tp_data, struct clk *clk, const char *name,
+ enum cdns_torrent_ref_clk *p_ref_clk_rate)
{
- unsigned long ref_clk1_rate;
- unsigned long ref_clk_rate;
+ struct device *dev = tp_data->dev;
+ u32 ref_clk_rate;
int ret;
- ret = clk_prepare_enable(tp_data->clk);
+ ret = clk_prepare_enable(clk);
if (ret) {
- dev_err(tp_data->dev, "Failed to prepare ref clock: %d\n", ret);
+ dev_err(dev, "Failed to prepare %s ref clock: %d\n", name, ret);
return ret;
}
- ref_clk_rate = clk_get_rate(tp_data->clk);
+ ref_clk_rate = clk_get_rate(clk);
if (!ref_clk_rate) {
- dev_err(tp_data->dev, "Failed to get ref clock rate\n");
+ dev_err(dev, "Failed to get %s ref clock rate\n", name);
ret = -EINVAL;
goto disable_clk;
}
switch (ref_clk_rate) {
case REF_CLK_19_2MHZ:
- tp_data->ref_clk_rate = CLK_19_2_MHZ;
+ *p_ref_clk_rate = CLK_19_2_MHZ;
break;
case REF_CLK_25MHZ:
- tp_data->ref_clk_rate = CLK_25_MHZ;
+ *p_ref_clk_rate = CLK_25_MHZ;
break;
case REF_CLK_100MHZ:
- tp_data->ref_clk_rate = CLK_100_MHZ;
+ *p_ref_clk_rate = CLK_100_MHZ;
break;
case REF_CLK_156_25MHZ:
- tp_data->ref_clk_rate = CLK_156_25_MHZ;
+ *p_ref_clk_rate = CLK_156_25_MHZ;
break;
default:
- dev_err(tp_data->dev, "Invalid ref clock rate\n");
+ dev_err(dev, "Invalid ref clock rate: %u Hz\n", ref_clk_rate);
ret = -EINVAL;
goto disable_clk;
}
- if (tp_data->clk1) {
- ret = clk_prepare_enable(tp_data->clk1);
- if (ret) {
- dev_err(tp_data->dev, "Failed to prepare PLL1 ref clock: %d\n", ret);
- goto disable_clk;
- }
-
- ref_clk1_rate = clk_get_rate(tp_data->clk1);
- if (!ref_clk1_rate) {
- 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:
- tp_data->ref_clk1_rate = CLK_19_2_MHZ;
- break;
- case REF_CLK_25MHZ:
- tp_data->ref_clk1_rate = CLK_25_MHZ;
- break;
- case REF_CLK_100MHZ:
- tp_data->ref_clk1_rate = CLK_100_MHZ;
- break;
- case REF_CLK_156_25MHZ:
- tp_data->ref_clk1_rate = CLK_156_25_MHZ;
- break;
- default:
- dev_err(tp_data->dev, "Invalid PLL1 ref clock rate\n");
- ret = -EINVAL;
- goto disable_clk1;
- }
- } else {
- tp_data->ref_clk1_rate = tp_data->ref_clk_rate;
- }
-
return 0;
-disable_clk1:
- clk_disable_unprepare(tp_data->clk1);
disable_clk:
- clk_disable_unprepare(tp_data->clk);
+ clk_disable_unprepare(clk);
return ret;
}
+static int tp_ref_clks_init(struct tp_data *tp_data)
+{
+ int ret;
+
+ if (tp_data->ref_clks_initialized)
+ return 0;
+
+ ret = tp_ref_clk_init(tp_data, tp_data->clk, "main", &tp_data->ref_clk_rate);
+ if (ret)
+ return ret;
+
+ if (!tp_data->clk1) {
+ tp_data->ref_clk1_rate = tp_data->ref_clk_rate;
+ } else {
+ ret = tp_ref_clk_init(tp_data, tp_data->clk1, "PLL1", &tp_data->ref_clk1_rate);
+ if (ret) {
+ clk_disable_unprepare(tp_data->clk);
+ return ret;
+ }
+ }
+
+ tp_data->ref_clks_initialized = true;
+ return 0;
+}
+
+static void tp_ref_clks_uninit(struct tp_data *tp_data)
+{
+ if (tp_data->ref_clks_initialized) {
+ clk_disable_unprepare(tp_data->clk1);
+ clk_disable_unprepare(tp_data->clk);
+ tp_data->ref_clks_initialized = false;
+ }
+}
+
static int tp_set_used_lanes(struct tp_data *tp_data, u32 mlane, u32 num_lanes)
{
u8 mask_available_lanes;
@@ -2672,6 +2671,18 @@ static int tp_dp_reg_base_init(struct platform_device *pdev, struct tp_data *tp_
return 0;
}
+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);
+ reset_control_put(tp_data->links[i].lnk_rst);
+ }
+
+ reset_control_assert(tp_data->phy_rst);
+ reset_control_assert(tp_data->apb_rst);
+ tp_ref_clks_uninit(tp_data);
+}
+
static bool tp_is_already_configured(const struct tp_data *tp_data)
{
u16 val = tp_reg_read(&tp_data->reg_phy_pma_common_cdb, PHY_PMA_CMN_CTRL1);
@@ -2721,21 +2732,11 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
ret = tp_of_get_reset(tp_data);
if (ret)
- return ret;
+ goto cleanup;
ret = tp_of_get_clk(tp_data);
if (ret)
- return ret;
-
- tp_data->already_configured = tp_is_already_configured(tp_data);
- if (!tp_data->already_configured) {
- ret = cdns_torrent_clk(tp_data);
- if (ret)
- return ret;
-
- /* Enable APB */
- reset_control_deassert(tp_data->apb_rst);
- }
+ goto cleanup;
for_each_available_child_of_node(dev->of_node, child) {
/* PHY subnode name must be 'phy'. */
@@ -2744,29 +2745,39 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
ret = tp_add_phy_from_of_subnode(tp_data, child);
if (ret)
- goto put_lnk_rst;
+ goto cleanup;
}
child = NULL;
if (tp_data->nb_links == 0) {
ret = -ENODEV;
- goto put_lnk_rst;
+ goto cleanup;
+ }
+
+ /* Enable APB */
+ reset_control_deassert(tp_data->apb_rst);
+
+ tp_data->already_configured = tp_is_already_configured(tp_data);
+ if (!tp_data->already_configured) {
+ ret = tp_ref_clks_init(tp_data);
+ if (ret)
+ goto cleanup;
}
ret = tp_dp_reg_base_init(pdev, tp_data);
if (ret)
- goto put_lnk_rst;
+ goto cleanup;
if (tp_data->nb_links > 1 && !tp_data->already_configured) {
ret = cdns_torrent_phy_configure_multilink(tp_data);
if (ret)
- goto put_lnk_rst;
+ goto cleanup;
}
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
if (IS_ERR(phy_provider)) {
ret = PTR_ERR(phy_provider);
- goto put_lnk_rst;
+ goto cleanup;
}
if (tp_data->nb_links > 1)
@@ -2781,33 +2792,19 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
return 0;
-put_lnk_rst:
+cleanup:
if (child)
of_node_put(child);
- for (u8 i = 0; i < tp_data->nb_links; i++)
- reset_control_put(tp_data->links[i].lnk_rst);
-
- reset_control_assert(tp_data->apb_rst);
- clk_disable_unprepare(tp_data->clk1);
- clk_disable_unprepare(tp_data->clk);
+ tp_cleanup_remove(tp_data);
return ret;
}
static void cdns_torrent_phy_remove(struct platform_device *pdev)
{
struct tp_data *tp_data = platform_get_drvdata(pdev);
- int i;
- 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(tp_data->clk1);
- clk_disable_unprepare(tp_data->clk);
+ tp_cleanup_remove(tp_data);
}
/* Multilink PCIe and USB Same SSC link configuration */
@@ -2984,12 +2981,8 @@ static int tp_suspend_noirq(struct device *dev)
for (i = 0; i < tp_data->nb_links; i++)
reset_control_assert(tp_data->links[i].lnk_rst);
- if (tp_data->already_configured)
- tp_data->already_configured = 0;
- else {
- clk_disable_unprepare(tp_data->clk1);
- clk_disable_unprepare(tp_data->clk);
- }
+ tp_data->already_configured = false;
+ tp_ref_clks_uninit(tp_data);
return 0;
}
@@ -3004,7 +2997,7 @@ static int tp_resume_noirq(struct device *dev)
if (ret)
return ret;
- ret = cdns_torrent_clk(tp_data);
+ ret = tp_ref_clks_init(tp_data);
if (ret)
return ret;
@@ -3024,8 +3017,7 @@ static int tp_resume_noirq(struct device *dev)
reset_control_assert(tp_data->links[i].lnk_rst);
reset_control_assert(tp_data->apb_rst);
- clk_disable_unprepare(tp_data->clk1);
- clk_disable_unprepare(tp_data->clk);
+ tp_ref_clks_uninit(tp_data);
return ret;
}
--
2.56.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe
[not found] <20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com>
2026-12-02 15:08 ` [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup Benjamin Robin
@ 2026-12-02 15:09 ` Benjamin Robin
2026-12-02 15:37 ` sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-1-0b493387347b@bootlin.com>
` (5 subsequent siblings)
8 siblings, 1 reply; 11+ messages in thread
From: Benjamin Robin @ 2026-12-02 15:09 UTC (permalink / raw)
To: Nishanth Menon, Vignesh Raghavendra, Tero Kristo, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Siddharth Vadapalli,
Andrew Davis, Andrzej Hajda, Neil Armstrong, Robert Foss,
Laurent Pinchart, Jonas Karlman, Jernej Skrabec, Luca Ceresoli,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
Simona Vetter, Vinod Koul, Manivannan Sadhasivam, Swapnil Jakhade,
Yuti Amonkar, Philipp Zabel
Cc: thomas.petazzoni, Chintan Vankar, Abhash Kumar Jha,
Thomas Richard, Gregory CLEMENT, Théo Lebrun, Tawfik Bayouk,
Vladimir Kondratiev, linux-arm-kernel, devicetree, linux-kernel,
dri-devel, linux-phy, Benjamin Robin
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/20261124101747.2432344-1-a-kumar2@ti.com/T/
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
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
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY
[not found] ` <20261202-phy-cadence-torrent-ng-v2-1-0b493387347b@bootlin.com>
@ 2026-12-02 15:24 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:24 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] arm64: dts: ti: missing SERDES PHY on cpsw0_port2..4 in J7200
QSGMII overlay
--
commit 9308aaccf0ec64c66667e093bd8f8f0c3d7d8571
Author: Chintan Vankar <c-vankar@ti.com>
arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY
This commit adds the serdes0_qsgmii_link PHY phandle and phy-names to
cpsw0_port1 in the J7200 QSGMII quad-port Ethernet expansion overlay.
> diff --git a/arch/arm64/boot/dts/ti/k3-j7200-evm-quad-port-eth-exp.dtso b/arch/arm64/boot/dts/ti/k3-j7200-evm-quad-port-eth-exp.dtso
> index 6432ca08ee8e4..4824d53c95bb3 100644
> --- a/arch/arm64/boot/dts/ti/k3-j7200-evm-quad-port-eth-exp.dtso
> +++ b/arch/arm64/boot/dts/ti/k3-j7200-evm-quad-port-eth-exp.dtso
> @@ -32,7 +32,8 @@ &cpsw0_port1 {
> phy-handle = <&cpsw5g_phy0>;
> phy-mode = "qsgmii";
> mac-address = [00 00 00 00 00 00];
> - phys = <&cpsw0_phy_gmii_sel 1>;
> + phys = <&cpsw0_phy_gmii_sel 1>, <&serdes0_qsgmii_link>;
> + phy-names = "mac", "serdes";
> };
>
> &cpsw0_port2 {
[Severity: Medium]
Should cpsw0_port2, cpsw0_port3, and cpsw0_port4 also reference
<&serdes0_qsgmii_link> with phy-names = "mac", "serdes"?
am65_cpsw_nuss_init_slave_ports() skips disabled ports and calls
am65_cpsw_init_serdes_phy() on each enabled port. If cpsw0_port1 is
disabled while any of cpsw0_port2..4 remain enabled, serdes0_qsgmii_link
is never initialized or powered on and QSGMII link fails on the remaining
ports. In k3-j784s4-evm-quad-port-eth-exp1.dtso, all four QSGMII ports
specify both the gmii_sel PHY and the shared QSGMII SERDES link PHY.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup
2026-12-02 15:08 ` [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup Benjamin Robin
@ 2026-12-02 15:24 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:24 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] phy: cadence-torrent: invalid reset_control_assert() calls on
probe error
--
commit d8ca83553938e7b813b4701d8d1a0be332d25133
Author: Benjamin Robin <benjamin.robin@bootlin.com>
phy: cadence-torrent: rework ref clock init and probe cleanup
This commit refactors reference clock initialization into helper functions
and consolidates probe error handling and driver removal into a shared
tp_cleanup_remove() helper.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 69e5323b1d689..de4ff3a133ffa 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
[ ... ]
> @@ -2672,6 +2671,18 @@ static int tp_dp_reg_base_init(struct platform_device *pdev, struct tp_data *tp_
> return 0;
> }
>
> +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);
> + reset_control_put(tp_data->links[i].lnk_rst);
> + }
> +
> + reset_control_assert(tp_data->phy_rst);
> + reset_control_assert(tp_data->apb_rst);
> + tp_ref_clks_uninit(tp_data);
> +}
> +
> static bool tp_is_already_configured(const struct tp_data *tp_data)
> {
> u16 val = tp_reg_read(&tp_data->reg_phy_pma_common_cdb, PHY_PMA_CMN_CTRL1);
> @@ -2721,21 +2732,11 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
>
> ret = tp_of_get_reset(tp_data);
> if (ret)
> - return ret;
> + goto cleanup;
>
> ret = tp_of_get_clk(tp_data);
> if (ret)
> - return ret;
> -
> - tp_data->already_configured = tp_is_already_configured(tp_data);
> - if (!tp_data->already_configured) {
> - ret = cdns_torrent_clk(tp_data);
> - if (ret)
> - return ret;
> -
> - /* Enable APB */
> - reset_control_deassert(tp_data->apb_rst);
> - }
> + goto cleanup;
>
> for_each_available_child_of_node(dev->of_node, child) {
> /* PHY subnode name must be 'phy'. */
> @@ -2744,29 +2745,39 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
>
> ret = tp_add_phy_from_of_subnode(tp_data, child);
> if (ret)
> - goto put_lnk_rst;
> + goto cleanup;
> }
> child = NULL;
>
> if (tp_data->nb_links == 0) {
> ret = -ENODEV;
> - goto put_lnk_rst;
> + goto cleanup;
> + }
> +
> + /* Enable APB */
> + reset_control_deassert(tp_data->apb_rst);
> +
> + tp_data->already_configured = tp_is_already_configured(tp_data);
> + if (!tp_data->already_configured) {
> + ret = tp_ref_clks_init(tp_data);
> + if (ret)
> + goto cleanup;
> }
>
> ret = tp_dp_reg_base_init(pdev, tp_data);
> if (ret)
> - goto put_lnk_rst;
> + goto cleanup;
>
> if (tp_data->nb_links > 1 && !tp_data->already_configured) {
> ret = cdns_torrent_phy_configure_multilink(tp_data);
> if (ret)
> - goto put_lnk_rst;
> + goto cleanup;
> }
>
> phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> if (IS_ERR(phy_provider)) {
> ret = PTR_ERR(phy_provider);
> - goto put_lnk_rst;
> + goto cleanup;
> }
>
> if (tp_data->nb_links > 1)
> @@ -2781,33 +2792,19 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
>
> return 0;
>
> -put_lnk_rst:
> +cleanup:
> if (child)
> of_node_put(child);
>
> - for (u8 i = 0; i < tp_data->nb_links; i++)
> - reset_control_put(tp_data->links[i].lnk_rst);
> -
> - reset_control_assert(tp_data->apb_rst);
> - clk_disable_unprepare(tp_data->clk1);
> - clk_disable_unprepare(tp_data->clk);
> + tp_cleanup_remove(tp_data);
> return ret;
> }
[Severity: Medium]
Can jumping to cleanup from cdns_torrent_phy_probe() trigger a WARN_ON()
in reset_control_assert() or reset a SERDES that was already configured by
the bootloader?
If tp_of_get_reset() fails (for example with -EPROBE_DEFER),
tp_data->phy_rst or tp_data->apb_rst holds an ERR_PTR, which
tp_cleanup_remove() passes to reset_control_assert(), hitting
WARN_ON(IS_ERR(rstc)):
drivers/phy/cadence/phy-cadence-torrent.c:tp_of_get_reset() {
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(tp_data->phy_rst);
}
...
}
Although commit "phy: cadence-torrent: store clock and reset handles only
on success" later in this series avoids storing the ERR_PTR, ordering that
change before this one would avoid breaking bisection.
In addition, calling tp_cleanup_remove() on probe failure after
tp_of_get_reset() (such as -EPROBE_DEFER in tp_of_get_clk() or
tp_add_phy_from_of_subnode(), or any failure when
tp_data->already_configured is true) unconditionally asserts
links[i].lnk_rst, phy_rst, and apb_rst. Previously, probe failure never
asserted phy_rst or links[i].lnk_rst, and asserting these resets on probe
deferral resets an already-configured SERDES and clears PHY_PMA_CMN_CTRL1,
so subsequent probe retries no longer detect already_configured.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=14
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config
[not found] ` <20261202-phy-cadence-torrent-ng-v2-11-0b493387347b@bootlin.com>
@ 2026-12-02 15:28 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:28 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] phy: cadence-torrent: per-lane CDB init uses num_lanes
instead of max_lanes
--
commit a7bb6d81b805f076baf2e912724f7f59b580f8d8
Author: Benjamin Robin <benjamin.robin@bootlin.com>
phy: cadence-torrent: use link lane count and mlane for DP config
This commit splits the link lane count into max_lanes and num_lanes in
struct tp_link so DisplayPort reconfiguration uses the active lane count
when set_lanes is not set, and shifts per-lane register masks by
link->mlane.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 28627bd234458..6e48c315e6b1a 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
[ ... ]
> @@ -1190,7 +1209,7 @@ static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link,
> /* PMA common configuration 100MHz */
> cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, dp->link_rate, dp->ssc);
>
> - cdns_torrent_dp_pma_cmn_rate(tp_data, link, dp->link_rate, dp->lanes);
> + cdns_torrent_dp_pma_cmn_rate(tp_data, link, dp->link_rate, link->num_lanes);
>
> /* Enable the associated PLL (cmn_pll0_en or cmn_pll1_en) */
> tp_reg_set_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
[ ... ]
> @@ -1286,58 +1295,53 @@ static void cdns_torrent_dp_set_a0_pll(struct tp_data *tp_data,
[ ... ]
> + /* release master lane reset */
> + value |= 1 << mlane;
> tp_reg_dptx_write(tp_data, PHY_RESET, value);
>
> + /* 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);
[Severity: Medium]
Does updating link->num_lanes to the active DisplayPort lane count leave
upper physical lanes unconfigured when the lane count is later increased?
After tp_dp_set_lanes() reduces link->num_lanes below link->max_lanes (for
example from 4 lanes to 1 or 2), cdns_torrent_phy_configure_multilink()
(called on system resume by tp_resume_noirq() after reset assertion) and
tp_phy_init() still loop up to link->num_lanes instead of link->max_lanes
when programming per-lane CDB tables (xcvr_diag_vals, tx_ln_vals,
rx_ln_vals):
drivers/phy/cadence/phy-cadence-torrent.c:cdns_torrent_phy_configure_multilink() {
...
mlane = tp_data->links[node].mlane;
ssc = tp_data->links[node].ssc_mode;
num_lanes = tp_data->links[node].num_lanes;
...
if (xcvr_diag_vals) {
reg_pairs = xcvr_diag_vals->reg_pairs;
num_regs = xcvr_diag_vals->num_regs;
for (i = 0; i < num_lanes; i++) {
...
}
If the system suspends and resumes while fewer than max_lanes are active
and a later phy_configure() increases dp->lanes back to 4,
tp_dp_set_lanes() releases the upper lanes from reset without their
per-lane CDB registers initialized (which also remains the case in
tp_configure_links() after commit "phy: cadence-torrent: rewrite Torrent
PHY driver").
Similarly, tp_dp_configure_rate() passes link->num_lanes to
cdns_torrent_dp_pma_cmn_rate(), which only writes XCVR_DIAG_HSCLK_DIV for
0 .. link->num_lanes - 1; if a rate change happens at 1 or 2 lanes and a
subsequent phy_configure() increases the lane count via set_lanes without
set_rate, the newly enabled lanes keep stale XCVR_DIAG_HSCLK_DIV values
(though commit "phy: cadence-torrent: rewrite Torrent PHY driver" later
updates the XCVR_DIAG_HSCLK_DIV write to use link->max_lanes).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=11
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY
[not found] ` <20261202-phy-cadence-torrent-ng-v2-22-0b493387347b@bootlin.com>
@ 2026-12-02 15:30 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:30 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] phy: cadence-torrent: mask_available_lanes 0x0F blocks 8-lane
support
--
commit 4cd07b2392984febe0d7ed29322fdd4014b9aee3
Author: Benjamin Robin <benjamin.robin@bootlin.com>
phy: cadence-torrent: support 8 lanes on the sd0801 PHY
This commit raises MAX_NUM_LANES from 4 to 8 to support up to 8 lanes on
the Cadence Torrent SD0801 PHY.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 21ad6c30a3f20..5a3e307f6c969 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> @@ -22,7 +22,7 @@
> #include <linux/reset.h>
>
> #define DEFAULT_NUM_LANES 4
> -#define MAX_NUM_LANES 4
> +#define MAX_NUM_LANES 8
[Severity: High]
Does cdns_map_torrent.mask_available_lanes also need to be updated from
0x0F to 0xFF?
tp_set_used_lanes() checks mask_lanes against
tp_data->init_data->mask_available_lanes, which is still 0x0F in
cdns_map_torrent, so probing any subnode that uses lanes 4..7 will fail
with -EINVAL.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=22
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link
[not found] ` <20261202-phy-cadence-torrent-ng-v2-18-0b493387347b@bootlin.com>
@ 2026-12-02 15:31 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:31 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] phy: cadence-torrent: NULL pointer dereference in
tp_dp_find_used_lanes()
- [High] phy: cadence-torrent: uninitialized dp_pll and ref_clk in
tp_phy_configure()
- [Medium] phy: cadence-torrent: link->num_lanes set to 0 in
tp_dp_find_used_lanes()
--
commit 26b8eac666ec602cc77dee851e18adb2e17e76e7
Author: Benjamin Robin <benjamin.robin@bootlin.com>
phy: cadence-torrent: allow config on an already-configured DP link
This commit removes the early return for already-configured PHYs in
tp_phy_configure() and reads the active DisplayPort lane count from the
PHY_RESET register during probe when the PHY is already configured.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 3b4d52ee7a531..0cbbedeefd87a 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
> @@ -1310,6 +1310,27 @@ static int tp_dp_verify_config(const struct tp_link *link,
> return 0;
> }
>
> +static void tp_dp_find_used_lanes(const struct tp_data *tp_data, struct tp_link *link)
> +{
> + u32 mlane = link->mlane;
> + u32 used_lanes_mask;
> + u32 all_lane_mask;
> + u32 value;
> +
> + all_lane_mask = ((1U << link->max_lanes) - 1) << mlane;
> + value = tp_reg_dptx_read(tp_data, PHY_RESET);
> +
> + /* only keep the lanes not in reset */
> + used_lanes_mask = value & all_lane_mask;
> +
> + /* only keep the lanes with Tx differential output not into electrical idle */
> + used_lanes_mask &= (~(value >> PMA_TX_ELEC_IDLE_SHIFT)) & all_lane_mask;
> +
> + /* update the number of used lanes */
> + used_lanes_mask >>= mlane;
> + link->num_lanes = __ffs(~used_lanes_mask);
> +}
[Severity: Medium]
Can tp_dp_find_used_lanes() overwrite link->num_lanes with 0 when all
DisplayPort lanes are held in reset or electrical idle at probe time?
In a multi-link setup where the bootloader only configured the non-DP link,
tp_is_already_configured() still returns true because the shared
PHY_PMA_CMN_CTRL1 bit 0 is set, while the DP lanes in PHY_RESET have
used_lanes_mask == 0 and __ffs(~used_lanes_mask) == 0. If the system
suspends and resumes before DP link training updates link->num_lanes,
tp_resume_noirq() -> tp_configure_links() loops over 0 .. link->num_lanes - 1
and skips programming the per-lane PMA TX/RX CDB registers for the DP link.
> @@ -1433,9 +1454,6 @@ static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
>
> guard(mutex)(&tp_data->lock);
>
> - if (tp_data->already_configured)
> - return 0;
> -
> if (link->phy_type != TYPE_DP)
> return -EINVAL;
[Severity: High]
Will tp_phy_configure() fail with -ETIMEDOUT when opts->dp.set_rate is set
on an already-configured PHY because tp_data->dp_pll and
tp_data->ref_clk_rate were never initialized?
When tp_data->already_configured is true, cdns_torrent_phy_probe() skips
both tp_ref_clks_init() and tp_configure_links() (which calls
cdns_torrent_dp_get_pll()), leaving tp_data->dp_pll and
tp_data->ref_clk_rate at 0. When tp_phy_configure() calls
tp_dp_set_rate() -> tp_dp_configure_rate(), pll_mask is 0 after the lanes
have already been put into POWERSTATE_A3:
drivers/phy/cadence/phy-cadence-torrent.c:tp_dp_configure_rate() {
...
pll_mask = tp_data->dp_pll;
...
tp_reg_clear_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
...
ret = read_poll_timeout(tp_reg_read, val, (val & (pll_mask << 2)) != 0, 0,
POLL_TIMEOUT_US, false, reg_base, PHY_PMA_CMN_CTRL2);
...
}
Because (val & (pll_mask << 2)) != 0 is always false, tp_dp_configure_rate()
times out and leaves the DisplayPort lanes powered down. Later in the
series, commit "phy: cadence-torrent: rewrite Torrent PHY driver" replaces
dp_pll with 1U << link->std_idx, but tp_ref_clks_init() and
tp_init_plls_data() are still skipped when tp_data->already_configured is
true, leaving pll->ref_clk_khz at 0 in tp_write_pll_regs().
[ ... ]
> @@ -2750,6 +2778,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
> ret = tp_ref_clks_init(tp_data);
> if (ret)
> goto cleanup;
> + } else {
> + tp_init_already_configured_links_opts(tp_data);
> }
>
> ret = tp_dp_reg_base_init(pdev, tp_data);
[Severity: High]
Does calling tp_init_already_configured_links_opts() before
tp_dp_reg_base_init() cause a NULL pointer dereference on tp_data->base?
When tp_data->already_configured is true and a TYPE_DP link is present,
tp_init_already_configured_links_opts() -> tp_dp_find_used_lanes() ->
tp_reg_dptx_read() reads from tp_data->base + PHY_RESET, but tp_data->base
is only ioremapped in tp_dp_reg_base_init() immediately afterwards.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=18
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 20/22] phy: cadence-torrent: rework suspend/resume to restore link config
[not found] ` <20261202-phy-cadence-torrent-ng-v2-20-0b493387347b@bootlin.com>
@ 2026-12-02 15:34 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:34 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] phy: cadence-torrent: uninitialized rst_asserted breaks
resume reset state
- [Medium] phy: cadence-torrent: incomplete reset and link restoration
in tp_resume_noirq()
--
commit a2bcc09aba1dcb8fcf52a6ca3d4a6b96ba68afa6
Author: Benjamin Robin <benjamin.robin@bootlin.com>
phy: cadence-torrent: rework suspend/resume to restore link config
This commit reworks suspend and resume to track per-link reset state, keep
reference clocks enabled across suspend when links remain powered on, and
re-program the PHY on resume when its configuration was lost.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 02e3c91316d56..7c4c20b005a95 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;
> };
[Severity: Medium]
Should link->rst_asserted be initialized when each link is set up at probe
time?
cdns_torrent_phy_probe() zero-allocates tp_data via devm_kzalloc_obj(), so
link->rst_asserted starts as false for all links even though unpowered
links remain in reset until tp_phy_on() is called. In a multi-link setup
where one link is powered on (nb_phy_on > 0) and another link has never
been powered on, a state-losing suspend and resume takes the
restore_resets path in tp_resume_noirq() and sees !link->rst_asserted on
the never-powered link, deasserting link->lnk_rst on an unpowered link.
Also, if link->rst_asserted is initialized to true at probe time when
!tp_data->already_configured, note that the tp_data->already_configured
early return in tp_phy_on() increments nb_phy_on without calling
tp_control_link_reset(link, false), so rst_asserted needs to reflect
whether the link was already out of reset.
[ ... ]
> @@ -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;
>
> - ret = tp_refclk_driver_resume(tp_data);
> + /* Enable APB unconditionally */
> + ret = reset_control_deassert(tp_data->apb_rst);
> if (ret)
> return ret;
>
> + ret = tp_refclk_driver_resume(tp_data);
> + if (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);
> + }
> + }
[Severity: Medium]
Does the restore_resets path in tp_resume_noirq() leave active links
uninitialized after deasserting phy_rst and lnk_rst?
When nb_phy_on > 0 and the PHY lost its configuration during suspend,
restore_resets only deasserts phy_rst and link->lnk_rst. Unlike
tp_phy_init() and tp_phy_on(), it does not wait for PHY_PMA_CMN_CTRL1[0]
(CMN ready), re-run tp_dp_phy_init() and tp_dp_run() for active TYPE_DP
links, or poll PHY_PCS_ISO_LINK_CTRL for active TYPE_PCIE and TYPE_USB
links, leaving consumers that keep the PHY powered across suspend (such as
cdns-mhdp8546) with an unstarted link.
In addition, when the PHY was pre-configured by the bootloader at probe
time (tp_data->already_configured == true) and nb_phy_on == 0 at suspend,
tp_suspend_noirq() clears already_configured without asserting phy_rst or
lnk_rst. On resume, the !tp_data->nb_phy_on branch assumes all links and
the PHY are already in reset and runs tp_configure_links() while the
resets are still deasserted.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=20
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe
2026-12-02 15:09 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
@ 2026-12-02 15:37 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:37 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] phy: cadence-torrent: missing return statement in
tp_configure_links()
- [High] phy: cadence-torrent: A3 power-state timeout in
tp_dp_set_rate()
- [Medium] phy: cadence-torrent: tp_phy_off() leaves PHY in reset when
already_configured
--
commit d9682d304dc8f77ceb7780c5aacc3465f1589265
Author: Benjamin Robin <benjamin.robin@bootlin.com>
phy: cadence-torrent: unify link configuration in the probe
This commit moves PHY register configuration for both single-link and
multi-link setups into probe and resume, and moves reset and DisplayPort
link startup handling into the PHY power_on and power_off callbacks.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 9a2621fb3ac74..3b4d52ee7a531 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
[ ... ]
> @@ -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);
[ ... ]
> @@ -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;
[ ... ]
> }
>
> /* 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;
[Severity: High]
Will tp_dptx_set_power_state() time out waiting for POWERSTATE_A3 when a
running DisplayPort link uses fewer than link->max_lanes lanes?
tp_dp_set_lanes() holds unused lanes (link->num_lanes .. link->max_lanes - 1)
in reset with PHY_PMA_XCVR_PLLCLK_EN cleared, and tp_dp_run() only brings
up link->num_lanes lanes to POWERSTATE_A0. When tp_dp_set_rate() passes
link->max_lanes on an active link, the active lanes have non-zero bits in
PHY_PMA_XCVR_POWER_STATE_ACK, so the early return in
tp_dptx_set_power_state() is not taken. readl_poll_timeout() then waits
for all link->max_lanes lanes to acknowledge POWERSTATE_A3 (0x08), which
unused lanes held in reset never do, failing link rate changes for 1-lane
or 2-lane configs on a 4-lane PHY with -ETIMEDOUT.
Also, when tp_phy_configure() is called on a running link with both
set_lanes and set_rate set, tp_dp_set_lanes() runs first and clears
PHY_PMA_XCVR_PLLCLK_EN on all lanes and puts newly disabled lanes into
reset before tp_dp_set_rate() requests POWERSTATE_A3.
[ ... ]
> @@ -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;
> }
[ ... ]
> 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;
> }
[Severity: Medium]
If tp_data->already_configured is true, does a runtime phy_power_off()
followed by phy_power_on() leave the PHY held in reset?
tp_phy_off() unconditionally asserts link->lnk_rst and tp_data->phy_rst,
but tp_phy_on() returns early when tp_data->already_configured is set
without deasserting either reset (and probe skipped tp_ref_clks_init() and
tp_configure_links()).
[ ... ]
> +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);
> + }
> }
[Severity: High]
Does tp_configure_links() fall off the end without returning 0 on the
success path?
This breaks bisection by failing the build with -Werror=return-type until
commit "phy: cadence-torrent: rewrite Torrent PHY driver" later in the
series adds the return statement.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=17
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver
[not found] ` <20261202-phy-cadence-torrent-ng-v2-21-0b493387347b@bootlin.com>
@ 2026-12-02 15:38 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-12-02 15:38 UTC (permalink / raw)
To: Benjamin Robin
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] phy: cadence-torrent: broken QSGMII mode check in
tp_add_phy_from_of_subnode()
- [High] phy: cadence-torrent: divide-by-zero in tp_dp_update_pll_freq()
- [High] phy: cadence-torrent: NULL dereference of base in
tp_dp_find_used_lanes()
- [High] phy: cadence-torrent: A3 timeout on unused DP lanes and partial
lane config
- [High] phy: cadence-torrent: NULL deref, div-by-zero, and reset bug if
preconfigured
- [Medium] phy: cadence-torrent: wrong std1 initialization in
tp_calc_pll_fb_div_modes()
- [Medium] phy: cadence-torrent: broken dual-refclk validation in
tp_ref_clk_init()
- [Medium] phy: cadence-torrent: rejected standard swap with clk1 in
tp_find_link_cfg()
--
commit 107a7c6a980951f00c775c6427a095f0f4912099
Author: Benjamin Robin <benjamin.robin@bootlin.com>
phy: cadence-torrent: rewrite Torrent PHY driver
This commit rewrites the Cadence Torrent PHY driver to compute reference
clock and PLL register values at run time and select protocol, revision,
and process-node settings from compact configuration tables instead of
hard-coded register arrays.
> diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
> index 7c4c20b005a95..21ad6c30a3f20 100644
> --- a/drivers/phy/cadence/phy-cadence-torrent.c
> +++ b/drivers/phy/cadence/phy-cadence-torrent.c
[ ... ]
> +static void tp_calc_pll_fb_div_modes(struct tp_data *tp_data)
> +{
> + enum tp_pll_fb_div_mode div_mode;
> + const struct tp_standard *std0 = &tp_data->standards[0];
> + const struct tp_standard *std1 = &tp_data->standards[0];
>
> - /* Assumes 19.2 MHz refclock */
> - switch (rate) {
> - /* Setting VCO for 10.8GHz */
> - case 2700:
> - case 5400:
> - tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x0119);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0x4000);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x00BC);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0012);
> - tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x0119);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0x4000);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x00BC);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0012);
> - if (ssc)
> - cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x033A, 0x006A);
> - break;
> - /* Setting VCO for 9.72GHz */
> - case 1620:
> - case 2430:
> - case 3240:
> - tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x01FA);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0x4000);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x0152);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x01FA);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0x4000);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x0152);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
> - if (ssc)
> - cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x05DD, 0x0069);
> - break;
> - /* Setting VCO for 8.64GHz */
> - case 2160:
> - case 4320:
> - tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x01C2);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0x0000);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x012C);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x01C2);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0x0000);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x012C);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
> - if (ssc)
> - cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x0536, 0x0069);
> - break;
> - /* Setting VCO for 8.1GHz */
> - case 8100:
> - tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x01A5);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0xE000);
> - tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x011A);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x01A5);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0xE000);
> - tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
> - tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x011A);
> - tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
> - if (ssc)
> - cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x04D7, 0x006A);
> - break;
> - }
> + if (std0->type == STD_TYPE_PCIE) {
> + div_mode = tp_calc_pcie_pll_fb_div_mode(tp_data);
> +
> + tp_data->plls[PLL0_MODE0].fb_div_mode = div_mode;
> + tp_data->plls[PLL0_MODE1].fb_div_mode = div_mode;
>
> - if (ssc) {
> - tp_reg_write(reg_base, CMN_PLL0_VCOCAL_PLLCNT_START, 0x025E);
> - tp_reg_write(reg_base, CMN_PLL0_LOCK_PLLCNT_THR, 0x0005);
> - tp_reg_write(reg_base, CMN_PLL1_VCOCAL_PLLCNT_START, 0x025E);
> - tp_reg_write(reg_base, CMN_PLL1_LOCK_PLLCNT_THR, 0x0005);
> + if ((std0->flags & STD_FLAG_PCIE_ML) || std1->type == STD_TYPE_NONE)
> + tp_data->plls[PLL1_MODE0].fb_div_mode = div_mode;
> + else
> + tp_data->plls[PLL1_MODE0].fb_div_mode = PLL_FB_DIV_MODE_FBR;
[Severity: Medium]
Should std1 be initialized to &tp_data->standards[1] instead of
&tp_data->standards[0]?
Because std1 points to standards[0], std1->type == STD_TYPE_NONE is always
false inside the std0->type == STD_TYPE_PCIE branch, so single-link PCIe
configurations set plls[PLL1_MODE0].fb_div_mode to PLL_FB_DIV_MODE_FBR
instead of div_mode.
[ ... ]
> +static int tp_dp_update_pll_freq(struct tp_data *tp_data, const struct tp_link *link,
> + enum tp_pll_id pll_id, u32 bit_rate, bool ssc)
> {
> - struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> -
> - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0);
> - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1);
> - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 0);
> + const struct tp_link_cfg *link_cfg = tp_data->link_cfg;
> + struct tp_pll_data *pll = &tp_data->plls[pll_id];
> + u32 pll_freq_khz = 0;
> + u16 val;
>
> - return 0;
> -}
> + if (link_cfg->pll_freq[pll_id] != PLL_DP)
> + return -EINVAL;
>
> -static void tp_refclk_driver_disable(struct clk_hw *hw)
> -{
> - struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> + pll_freq_khz = tp_dp_pll_freq_from_bit_rate(bit_rate);
> + if (pll_freq_khz == 0)
> + return -EINVAL;
>
> - tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1);
> -}
> + pll->freq_khz = pll_freq_khz;
> + pll->ssc = ssc;
> + pll->fractional_mode = tp_is_pll_fractional_mode_required(pll);
>
> -static int tp_refclk_driver_is_enabled(struct clk_hw *hw)
> -{
> - struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> - u16 val;
> + val = tp_dp_pll_clk_sel_from_bit_rate(bit_rate);
> + tp_reg_write(&tp_data->reg_common_cdb, CMN_PDIAG_PLLx_CLK_SEL_Mx(pll_id), val);
>
> - val = tp_reg_field_read(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1]);
> - return !val;
> -}
> + val = tp_dp_xcvr_diag_hsclk_div_from_bit_rate(bit_rate);
> + tp_write_lanes_reg(tp_data->reg_tx_lane_cdb, link->mlane, link->max_lanes,
> + XCVR_DIAG_HSCLK_DIV, val);
>
> -static u8 tp_refclk_driver_get_parent(struct clk_hw *hw)
> -{
> - struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
> - u16 val;
> + tp_write_pll_lock_tmr(tp_data, pll_id);
> + tp_write_pll_regs(tp_data, pll_id);
[Severity: High]
Can tp_dp_update_pll_freq() divide by zero when tp_data->already_configured
was true at probe time?
When tp_data->already_configured is true, cdns_torrent_phy_probe() skips
both tp_ref_clks_init() and tp_configure_links() (and tp_resume_noirq()
also skips tp_configure_links() -> tp_init_plls_data() if nb_phy_on > 0 and
the PHY remained configured), leaving tp_data->ref_clk_khz and
pll->ref_clk_khz at 0. Calling phy_configure() with opts->dp.set_rate set
then reaches tp_dp_update_pll_freq(), where
tp_is_pll_fractional_mode_required() and tp_write_pll_regs() divide by
pll->ref_clk_khz.
[ ... ]
> +/* Configure link rate as required. */
> +static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
> + const struct phy_configure_opts_dp *dp)
> +{
> + int ret;
>
> -static const struct cdns_torrent_vals usb_sgmii_xcvr_diag_ln_vals = {
> - .reg_pairs = usb_sgmii_xcvr_diag_ln_regs,
> - .num_regs = ARRAY_SIZE(usb_sgmii_xcvr_diag_ln_regs),
> -};
> + ret = tp_dptx_set_power_state(tp_data, link->mlane, link->max_lanes, POWERSTATE_A3);
> + if (ret)
> + return ret;
[Severity: High]
Does tp_dptx_set_power_state() time out here when reconfiguring the link
rate while link->num_lanes < link->max_lanes?
When fewer than link->max_lanes lanes are active (for example 1 or 2 lanes
on a 4-lane DP link) and phy_configure() updates the link rate without
changing the lane count, the active lanes are in POWERSTATE_A0 while unused
lanes are held in reset with PHY_PMA_XCVR_PLLCLK_EN cleared. Passing
link->max_lanes to tp_dptx_set_power_state() causes (read_val & mask) to be
non-zero, and readl_poll_timeout() then waits for the reset lanes to
acknowledge POWERSTATE_A3 in PHY_PMA_XCVR_POWER_STATE_ACK and fails with
-ETIMEDOUT.
In addition, tp_configure_links() programs per-lane CDB registers only up
to link->num_lanes instead of link->max_lanes, which leaves upper lanes
unconfigured after a suspend/resume cycle if the lane count is later
increased.
[ ... ]
> +static int tp_phy_on(struct phy *phy)
> +{
> + struct tp_link *link = phy_get_drvdata(phy);
> + struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
> + u16 val;
> + int ret;
>
> -static const struct cdns_torrent_vals pcie_sgmii_xcvr_diag_ln_vals = {
> - .reg_pairs = pcie_sgmii_xcvr_diag_ln_regs,
> - .num_regs = ARRAY_SIZE(pcie_sgmii_xcvr_diag_ln_regs),
> -};
> + guard(mutex)(&tp_data->lock);
>
> -static const struct cdns_torrent_vals sgmii_pcie_xcvr_diag_ln_vals = {
> - .reg_pairs = sgmii_pcie_xcvr_diag_ln_regs,
> - .num_regs = ARRAY_SIZE(sgmii_pcie_xcvr_diag_ln_regs),
> -};
> + 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;
> + }
[ ... ]
> +static int tp_phy_off(struct phy *phy)
> +{
> + struct tp_link *link = phy_get_drvdata(phy);
> + struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
> + int ret;
>
> -static const struct cdns_torrent_vals qsgmii_100_no_ssc_cmn_vals = {
> - .reg_pairs = qsgmii_100_no_ssc_cmn_regs,
> - .num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_cmn_regs),
> -};
> + guard(mutex)(&tp_data->lock);
>
> -static const struct cdns_torrent_vals qsgmii_100_no_ssc_tx_ln_vals = {
> - .reg_pairs = qsgmii_100_no_ssc_tx_ln_regs,
> - .num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_tx_ln_regs),
> -};
> + ret = tp_control_link_reset(link, true);
> + if (ret)
> + return ret;
>
> -static const struct cdns_torrent_vals ti_qsgmii_100_no_ssc_tx_ln_vals = {
> - .reg_pairs = ti_qsgmii_100_no_ssc_tx_ln_regs,
> - .num_regs = ARRAY_SIZE(ti_qsgmii_100_no_ssc_tx_ln_regs),
> -};
> + if (tp_data->nb_phy_on == 1) {
> + ret = reset_control_assert(tp_data->phy_rst);
> + if (ret)
> + return ret;
> + }
>
> -static const struct cdns_torrent_vals qsgmii_100_no_ssc_rx_ln_vals = {
> - .reg_pairs = qsgmii_100_no_ssc_rx_ln_regs,
> - .num_regs = ARRAY_SIZE(qsgmii_100_no_ssc_rx_ln_regs),
> -};
> + tp_data->nb_phy_on--;
> + return 0;
> +}
[Severity: High]
What happens if a pre-configured PHY (tp_data->already_configured == true)
is powered off and then powered back on?
tp_phy_off() asserts link->lnk_rst and tp_data->phy_rst without clearing
tp_data->already_configured, so a subsequent tp_phy_on() takes the early
already_configured return and leaves both resets asserted and the PHY
unconfigured. In addition, when tp_data->already_configured is true at
probe time, tp_dp_find_used_lanes() dereferences tp_data->base while it is
still NULL and tp_dp_update_pll_freq() divides by zero because
ref_clk_khz is never initialized.
[ ... ]
> +static int tp_ref_clk_init(const struct tp_data *tp_data, struct clk *clk, const char *name,
> + u32 *p_ref_clk_khz)
> +{
> + struct device *dev = tp_data->dev;
> + u32 ref_clk_rate;
> + int ret;
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_SGMII, NO_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> + ret = clk_prepare_enable(clk);
> + if (ret) {
> + dev_err(dev, "Failed to prepare %s ref clock: %d\n", name, ret);
> + return ret;
> + }
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, NO_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, EXTERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_QSGMII, TYPE_USB, INTERNAL_SSC), &qsgmii_100_no_ssc_rx_ln_vals},
> + ref_clk_rate = clk_get_rate(clk);
> + if (!ref_clk_rate) {
> + dev_err(dev, "Failed to get %s ref clock rate\n", name);
> + ret = -EINVAL;
> + goto disable_clk;
> + }
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, NO_SSC), &usb_100_no_ssc_rx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, EXTERNAL_SSC), &usb_100_no_ssc_rx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_NONE, INTERNAL_SSC), &usb_100_no_ssc_rx_ln_vals},
> + for (u8 i = 0; i < tp_data->nb_links; ++i) {
> + if (!tp_is_ref_freq_supported(tp_data->links[i].type, ref_clk_rate)) {
> + dev_err(dev, "Invalid ref clock rate: %u Hz\n", ref_clk_rate);
> + ret = -EINVAL;
> + goto disable_clk;
> + }
> + }
[Severity: Medium]
Does validating ref_clk_rate against all links in tp_data->links[] reject
valid dual-reference-clock configurations?
When both refclk (PLL0) and pll1_refclk (PLL1) are provided,
tp_ref_clks_init() calls tp_ref_clk_init() for each clock, and this loop
requires both frequencies to be supported by every link's standard. A
setup such as SATA at 100 MHz on PLL0 with USXGMII at 156.25 MHz on PLL1
fails probe with -EINVAL because 156.25 MHz is not in SATA's supported
frequency list (freq_set4).
[ ... ]
> + switch (phy_type) {
> + case PHY_TYPE_PCIE:
> + std_type = STD_TYPE_PCIE;
> + break;
> + case PHY_TYPE_USB3:
> + std_type = STD_TYPE_USB_TXRX;
> + supported_flags = CDNS_TORRENT_MODE_USB_G1 | CDNS_TORRENT_MODE_USB_IO_11V;
> + break;
> + case PHY_TYPE_DP:
> + std_type = STD_TYPE_DP;
> + break;
> + case PHY_TYPE_XAUI:
> + std_type = STD_TYPE_XAUI;
> + supported_flags = CDNS_TORRENT_MODE_XAUI_LP;
> + break;
> + case PHY_TYPE_SGMII:
> + std_type = STD_TYPE_SGMII;
> + supported_flags = CDNS_TORRENT_MODE_2500_BASEX;
> + break;
> + case PHY_TYPE_QSGMII:
> + std_type = STD_TYPE_SGMII;
> + link_flags |= STD_FLAG_QSGMII;
> + break;
> + case PHY_TYPE_SATA:
> + std_type = STD_TYPE_SATA;
> + supported_flags = CDNS_TORRENT_MODE_SATA_LP;
> + break;
> + case PHY_TYPE_USXGMII:
> + std_type = STD_TYPE_USXGMII;
> + break;
> + default:
> + dev_err(dev, "Unsupported protocol: %u\n", phy_type);
> + return -EINVAL;
> + }
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, EXTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE, INTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> + if (link_flags & ~supported_flags) {
> + dev_err(dev, "Unsupported modes 0x%X for this PHY type %u\n",
> + link_flags, std_type);
> + return -EINVAL;
> + }
[Severity: High]
Does PHY_TYPE_QSGMII always fail this check with -EINVAL?
The PHY_TYPE_QSGMII case sets STD_FLAG_QSGMII in link_flags while leaving
supported_flags at 0, so (link_flags & ~supported_flags) is always
non-zero.
[ ... ]
> + link_cfg = tp_find_link_cfg_from_standards(std0, std1);
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, NO_SSC), &usb_100_no_ssc_cmn_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, EXTERNAL_SSC), &usb_100_no_ssc_cmn_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_PCIE_ML, INTERNAL_SSC), &usb_100_no_ssc_cmn_vals},
> + /* Only swap the two standards if PLL1 has no dedicated reference clock. If
> + * there are two DTS PHY nodes and the `pll1_refclk` reference clock is
> + * specified, the user assumes the PLL1 reference clock will be used for the
> + * second DTS PHY node. If the standards are swapped, this clock would be used
> + * for the first DTS PHY node instead, which could be a problem, for example
> + * with USXGMII, which prefers a 156.25 MHz reference clock.
> + */
> + if (!link_cfg && !tp_data->clk1) {
> + link_cfg = tp_find_link_cfg_from_standards(std1, std0);
> + if (link_cfg) {
> + /* Swap the 2 standards */
> + swap(tp_data->standards[0], tp_data->standards[1]);
> +
> + for (u8 i = 0; i < tp_data->nb_links; ++i)
> + tp_data->links[i].std_idx ^= 1;
> + }
> + }
[Severity: Medium]
Does gating the (std1, std0) fallback lookup on !tp_data->clk1 break dual
reference clock setups where the first DT subnode uses the protocol routed
to PLL1?
tp_add_phy_from_of_subnode() populates standards[0] and standards[1] in DT
subnode order (typically ascending lane address, such as phy@0 then phy@2),
whereas in tp_link_cfgs[] std0 is always clocked by PLL0 (refclk) and std1
by PLL1 (pll1_refclk), and most protocol pairs only exist in one PLL
assignment order (for example, PCIe must be std0 on PLL0). If phy@0 is
USXGMII (clocked by pll1_refclk on PLL1) and phy@2 is PCIe (clocked by
refclk on PLL0), tp_find_link_cfg_from_standards(std0, std1) returns NULL
and !tp_data->clk1 prevents swapping them to match their required PLL0 and
PLL1 assignment, failing probe with -EINVAL.
[ ... ]
> + tp_data->already_configured = tp_is_already_configured(tp_data);
> + if (!tp_data->already_configured) {
> + ret = tp_ref_clks_init(tp_data);
> + if (ret)
> + goto cleanup;
> + } else {
> + tp_init_already_configured_links_opts(tp_data);
> + }
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, EXTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_QSGMII, INTERNAL_SSC), &usb_100_no_ssc_tx_ln_vals},
> + ret = tp_read_techno_revision(tp_data);
> + if (ret)
> + goto cleanup;
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_USB, TYPE_DP, NO_SSC), &usb_100_no_ssc_tx_ln_vals},
> + tp_check_multiple_pcie_links(tp_data);
>
> - {CDNS_TORRENT_KEY(CLK_100_MHZ, CLK_100_MHZ, TYPE_XAUI, TYPE_PCIE, NO_SSC), &ti_xaui_100_no_ssc_tx_ln_vals},
> + ret = tp_find_link_cfg(tp_data);
> + if (ret)
> + goto cleanup;
>
> - {CDNS_TORRENT_KEY(CLK_156_25_MHZ, CLK_156_25_MHZ, TYPE_USXGMII, TYPE_NONE, NO_SSC), &usxgmii_156_25_no_ssc_tx_ln_vals},
> + ret = tp_dp_reg_base_init(pdev, tp_data);
> + if (ret)
> + goto cleanup;
[Severity: High]
Does tp_init_already_configured_links_opts() dereference a NULL
tp_data->base when a DisplayPort link is present?
For DisplayPort links, tp_init_already_configured_links_opts() calls
tp_dp_find_used_lanes() -> tp_reg_dptx_read(tp_data, PHY_RESET), which
reads from tp_data->base before tp_dp_reg_base_init() maps the DPTX
registers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com?part=21
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-02 15:38 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261202-phy-cadence-torrent-ng-v2-0-0b493387347b@bootlin.com>
2026-12-02 15:08 ` [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup Benjamin Robin
2026-12-02 15:24 ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
2026-12-02 15:37 ` sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-1-0b493387347b@bootlin.com>
2026-12-02 15:24 ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-11-0b493387347b@bootlin.com>
2026-12-02 15:28 ` [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-22-0b493387347b@bootlin.com>
2026-12-02 15:30 ` [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-18-0b493387347b@bootlin.com>
2026-12-02 15:31 ` [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-20-0b493387347b@bootlin.com>
2026-12-02 15:34 ` [PATCH v2 20/22] phy: cadence-torrent: rework suspend/resume to restore link config sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-21-0b493387347b@bootlin.com>
2026-12-02 15:38 ` [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox