* [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:24 ` sashiko-bot
2026-12-02 15:08 ` [PATCH v2 03/22] dt-bindings: phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
` (18 subsequent siblings)
19 siblings, 1 reply; 28+ 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
From: Chintan Vankar <c-vankar@ti.com>
For CPSW5G QSGMII ports, CPSW assumes SERDES to be configured. Since it
may not be always true, add SERDES phys to guarantee it.
Fixes: 496cdc82e05f ("arm64: dts: ti: k3-j7200: Add overlay to enable CPSW5G ports in QSGMII mode")
Signed-off-by: Chintan Vankar <c-vankar@ti.com>
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
arch/arm64/boot/dts/ti/k3-j7200-evm-quad-port-eth-exp.dtso | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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 6432ca08ee8e..4824d53c95bb 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 {
--
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] 28+ messages in thread* Re: [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY
2026-12-02 15:08 ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY Benjamin Robin
@ 2026-12-02 15:24 ` sashiko-bot
0 siblings, 0 replies; 28+ 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] 28+ messages in thread
* [PATCH v2 03/22] dt-bindings: phy: cadence-torrent: make cdns,num-lanes optional again
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants Benjamin Robin
` (17 subsequent siblings)
19 siblings, 0 replies; 28+ 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, stable
Make the cdns,num-lanes property optional again by defaulting to 4 lanes
when it is absent from the PHY node, restoring the behavior before it
was made mandatory in a previous commit.
Fixes: 074e99153594 ("dt-bindings: phy: cadence-torrent: Update Torrent PHY bindings for generic use")
Cc: stable@vger.kernel.org
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml | 1 -
1 file changed, 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml b/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml
index 9af39b33646a..827f76e5edba 100644
--- a/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml
+++ b/Documentation/devicetree/bindings/phy/phy-cadence-torrent.yaml
@@ -129,7 +129,6 @@ patternProperties:
- resets
- "#phy-cells"
- cdns,phy-type
- - cdns,num-lanes
additionalProperties: false
--
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] 28+ messages in thread* [PATCH v2 04/22] dt-bindings: phy: cadence-torrent: add phy-mode constants
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 01/22] arm64: dts: ti: k3-j7200: Fix QSGMII overlay by adding SERDES PHY Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 03/22] dt-bindings: phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 05/22] phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
` (16 subsequent siblings)
19 siblings, 0 replies; 28+ 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] 28+ messages in thread* [PATCH v2 05/22] phy: cadence-torrent: make cdns,num-lanes optional again
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (2 preceding siblings ...)
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:08 ` [PATCH v2 06/22] phy: torrent: fix `RX_DIAG_NQST_CTRL` register address Benjamin Robin
` (15 subsequent siblings)
19 siblings, 0 replies; 28+ 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, stable
Make the cdns,num-lanes property optional again by defaulting to 4 lanes
when it is absent from the PHY node, restoring the behavior before it
was made mandatory in a previous commit.
Fixes: d09945eacad0 ("phy: cadence-torrent: Check total lane count for all subnodes is within limit")
Cc: stable@vger.kernel.org
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 1e178aa2ffd7..42d60102c0f8 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -27,6 +27,7 @@
#define REF_CLK_100MHZ 100000000
#define REF_CLK_156_25MHZ 156250000
+#define DEFAULT_NUM_LANES 4
#define MAX_NUM_LANES 4
#define DEFAULT_MAX_BIT_RATE 8100 /* in Mbps */
@@ -3033,13 +3034,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_child;
}
- if (of_property_read_u32(child, "cdns,num-lanes",
- &cdns_phy->phys[node].num_lanes)) {
- dev_err(dev, "%s: No \"cdns,num-lanes\"-property.\n",
- child->full_name);
- ret = -EINVAL;
- goto put_child;
- }
+ cdns_phy->phys[node].num_lanes = DEFAULT_NUM_LANES;
+ of_property_read_u32(child, "cdns,num-lanes", &cdns_phy->phys[node].num_lanes);
total_num_lanes += cdns_phy->phys[node].num_lanes;
--
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] 28+ messages in thread* [PATCH v2 06/22] phy: torrent: fix `RX_DIAG_NQST_CTRL` register address
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (3 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 05/22] phy: cadence-torrent: make cdns,num-lanes optional again Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 07/22] phy: cadence-torrent: rename symbols to prepare for rewrite Benjamin Robin
` (14 subsequent siblings)
19 siblings, 0 replies; 28+ 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, Dmitry Guzman, stable
From: Dmitry Guzman <Dmitry.Guzman@mobileye.com>
The address of register `RX_DIAG_NQST_CTRL` is defined as 0x01E5.
According to the datasheet, the correct address is 0x01E6.
Fix the register address value by replacing `0x01E5` with `0x01E6`.
Fixes: 6bcf3cb30037 ("phy: cadence-torrent: Add support for PHY multilink configuration")
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Guzman <Dmitry.Guzman@mobileye.com>
[Benjamin: Commit message reformulated]
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 42d60102c0f8..9b3ae73c4d78 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -217,7 +217,7 @@
#define RX_DIAG_DFE_AMP_TUNE_2 0x01E2U
#define RX_DIAG_DFE_AMP_TUNE_3 0x01E3U
#define RX_DIAG_REE_DAC_CTRL 0x01E4U
-#define RX_DIAG_NQST_CTRL 0x01E5U
+#define RX_DIAG_NQST_CTRL 0x01E6U
#define RX_DIAG_SIGDET_TUNE 0x01E8U
#define RX_DIAG_PI_RATE 0x01F4U
#define RX_DIAG_PI_CAP 0x01F5U
--
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] 28+ messages in thread* [PATCH v2 07/22] phy: cadence-torrent: rename symbols to prepare for rewrite
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (4 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 06/22] phy: torrent: fix `RX_DIAG_NQST_CTRL` register address Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 08/22] phy: cadence-torrent: replace regmap with readw/writew Benjamin Robin
` (13 subsequent siblings)
19 siblings, 0 replies; 28+ 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
In preparation for the upcoming rewrite of the driver, rename its
symbols to a shorter, consistent naming scheme and reorganize them into
functional groups.
The cdns_torrent_* function prefix is shortened to `tp_` (for "Torrent
PHY"). The torrent PHY state pointer `cdns_phy` is renamed to `tp_data`,
and the per-link instance pointer `inst` is renamed to `link`.
The clock-provider, reset, power management, port configuration and
DisplayPort helpers are also moved so the following patches have
smaller diffs.
No functional change intended: this commit only renames symbols and
moves functions around.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 1099 ++++++++++++++---------------
1 file changed, 539 insertions(+), 560 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 9b3ae73c4d78..f7ec31a4c417 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -240,7 +240,7 @@
#define CDNS_TORRENT_OUTPUT_CLOCKS 3
-static const char * const clk_names[] = {
+static const char *const tp_clk_names[] = {
[CDNS_TORRENT_REFCLK_DRIVER] = "refclk-driver",
[CDNS_TORRENT_DERIVED_REFCLK] = "refclk-der",
[CDNS_TORRENT_RECEIVED_REFCLK] = "refclk-rec",
@@ -269,13 +269,12 @@ static const struct reg_field phy_pipe_cmn_ctrl1_0 = REG_FIELD(PHY_PIPE_CMN_CTRL
static const struct reg_field cmn_cdiag_refclk_ovrd_4 =
REG_FIELD(CMN_CDIAG_REFCLK_OVRD, 4, 4);
-#define REFCLK_OUT_NUM_CMN_CONFIG 4
-
-enum cdns_torrent_refclk_out_cmn {
+enum tp_refclk_out_cmn {
CMN_CDIAG_REFCLK_DRV0_CTRL_1,
CMN_CDIAG_REFCLK_DRV0_CTRL_4,
CMN_CDIAG_REFCLK_DRV0_CTRL_5,
CMN_CDIAG_REFCLK_DRV0_CTRL_6,
+ TP_REFCLK_OUT_NUM_CMN_CONFIG
};
static const struct reg_field refclk_out_cmn_cfg[] = {
@@ -285,12 +284,41 @@ static const struct reg_field refclk_out_cmn_cfg[] = {
[CMN_CDIAG_REFCLK_DRV0_CTRL_6] = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 6, 6),
};
-static const int refclk_driver_parent_index[] = {
- CDNS_TORRENT_DERIVED_REFCLK,
- CDNS_TORRENT_RECEIVED_REFCLK
+static const int tp_refclk_driver_parent_idx[] = {
+ CDNS_TORRENT_DERIVED_REFCLK, CDNS_TORRENT_RECEIVED_REFCLK
};
-static const u32 cdns_torrent_refclk_driver_mux_table[] = { 1, 0 };
+static const u32 tp_refclk_driver_mux_table[] = { 1, 0 };
+
+struct tp_refclk_driver {
+ struct clk_hw hw;
+ struct regmap_field *cmn_fields[TP_REFCLK_OUT_NUM_CMN_CONFIG];
+ struct clk_init_data clk_data;
+ u8 parent_index;
+};
+
+#define tp_refclk_driver_to_clk_data(_hw) \
+ container_of(_hw, struct tp_refclk_driver, hw)
+
+struct cdns_torrent_derived_refclk {
+ struct clk_hw hw;
+ struct regmap_field *phy_pipe_cmn_ctrl1_0;
+ struct regmap_field *cmn_cdiag_refclk_ovrd_4;
+ struct clk_init_data clk_data;
+};
+
+#define to_cdns_torrent_derived_refclk(_hw) \
+ container_of(_hw, struct cdns_torrent_derived_refclk, hw)
+
+struct cdns_torrent_received_refclk {
+ struct clk_hw hw;
+ struct regmap_field *phy_pipe_cmn_ctrl1_0;
+ struct regmap_field *cmn_cdiag_refclk_ovrd_4;
+ struct clk_init_data clk_data;
+};
+
+#define to_cdns_torrent_received_refclk(_hw) \
+ container_of(_hw, struct cdns_torrent_received_refclk, hw)
enum cdns_torrent_phy_type {
TYPE_NONE,
@@ -344,17 +372,17 @@ enum cdns_torrent_ssc_mode {
CDNS_TORRENT_KEY(CLK_ANY, CLK_ANY, \
(link0), (link1), ANY_SSC)
-struct cdns_torrent_inst {
+struct tp_link {
struct phy *phy;
- u32 mlane;
+ struct reset_control *lnk_rst;
enum cdns_torrent_phy_type phy_type;
+ u32 mlane;
u32 num_lanes;
- struct reset_control *lnk_rst;
enum cdns_torrent_ssc_mode ssc_mode;
};
-struct cdns_torrent_phy {
- void __iomem *base; /* DPTX registers base */
+struct tp_data {
+ void __iomem *base; /* DPTX registers base */
void __iomem *sd_base; /* SD0801 registers base */
u32 max_bit_rate; /* Maximum link bit rate to use (in Mbps) */
u32 dp_pll;
@@ -366,8 +394,8 @@ struct cdns_torrent_phy {
struct clk *clk1;
enum cdns_torrent_ref_clk ref_clk_rate;
enum cdns_torrent_ref_clk ref_clk1_rate;
- struct cdns_torrent_inst phys[MAX_NUM_LANES];
- int nsubnodes;
+ struct tp_link links[MAX_NUM_LANES];
+ int nb_links;
int already_configured;
const struct cdns_torrent_data *init_data;
struct regmap *regmap_common_cdb;
@@ -395,36 +423,6 @@ enum phy_powerstate {
POWERSTATE_A3 = 3,
};
-struct cdns_torrent_refclk_driver {
- struct clk_hw hw;
- struct regmap_field *cmn_fields[REFCLK_OUT_NUM_CMN_CONFIG];
- struct clk_init_data clk_data;
- u8 parent_index;
-};
-
-#define to_cdns_torrent_refclk_driver(_hw) \
- container_of(_hw, struct cdns_torrent_refclk_driver, hw)
-
-struct cdns_torrent_derived_refclk {
- struct clk_hw hw;
- struct regmap_field *phy_pipe_cmn_ctrl1_0;
- struct regmap_field *cmn_cdiag_refclk_ovrd_4;
- struct clk_init_data clk_data;
-};
-
-#define to_cdns_torrent_derived_refclk(_hw) \
- container_of(_hw, struct cdns_torrent_derived_refclk, hw)
-
-struct cdns_torrent_received_refclk {
- struct clk_hw hw;
- struct regmap_field *phy_pipe_cmn_ctrl1_0;
- struct regmap_field *cmn_cdiag_refclk_ovrd_4;
- struct clk_init_data clk_data;
-};
-
-#define to_cdns_torrent_received_refclk(_hw) \
- container_of(_hw, struct cdns_torrent_received_refclk, hw)
-
struct cdns_reg_pairs {
u32 val;
u32 off;
@@ -723,10 +721,10 @@ static const char *cdns_torrent_get_phy_type(enum cdns_torrent_phy_type phy_type
* third register values provided by parameters.
*/
static
-void cdns_torrent_dp_enable_ssc_19_2mhz(struct cdns_torrent_phy *cdns_phy,
+void cdns_torrent_dp_enable_ssc_19_2mhz(struct tp_data *tp_data,
u32 ctrl2_val, u32 ctrl3_val)
{
- struct regmap *regmap = cdns_phy->regmap_common_cdb;
+ struct regmap *regmap = tp_data->regmap_common_cdb;
cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001);
cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
@@ -739,10 +737,10 @@ void cdns_torrent_dp_enable_ssc_19_2mhz(struct cdns_torrent_phy *cdns_phy,
}
static
-void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
+void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct tp_data *tp_data,
u32 rate, bool ssc)
{
- struct regmap *regmap = cdns_phy->regmap_common_cdb;
+ struct regmap *regmap = tp_data->regmap_common_cdb;
/* Assumes 19.2 MHz refclock */
switch (rate) {
@@ -760,7 +758,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00BC);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0012);
if (ssc)
- cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x033A, 0x006A);
+ cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x033A, 0x006A);
break;
/* Setting VCO for 9.72GHz */
case 1620:
@@ -777,7 +775,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0152);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
if (ssc)
- cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x05DD, 0x0069);
+ cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x05DD, 0x0069);
break;
/* Setting VCO for 8.64GHz */
case 2160:
@@ -793,7 +791,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x012C);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
if (ssc)
- cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x0536, 0x0069);
+ cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x0536, 0x0069);
break;
/* Setting VCO for 8.1GHz */
case 8100:
@@ -808,7 +806,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x011A);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
if (ssc)
- cdns_torrent_dp_enable_ssc_19_2mhz(cdns_phy, 0x04D7, 0x006A);
+ cdns_torrent_dp_enable_ssc_19_2mhz(tp_data, 0x04D7, 0x006A);
break;
}
@@ -843,10 +841,10 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct cdns_torrent_phy *cdns_phy,
* Set registers responsible for enabling and configuring SSC, with second
* register value provided by a parameter.
*/
-static void cdns_torrent_dp_enable_ssc_25mhz(struct cdns_torrent_phy *cdns_phy,
+static void cdns_torrent_dp_enable_ssc_25mhz(struct tp_data *tp_data,
u32 ctrl2_val)
{
- struct regmap *regmap = cdns_phy->regmap_common_cdb;
+ struct regmap *regmap = tp_data->regmap_common_cdb;
cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001);
cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
@@ -859,10 +857,10 @@ static void cdns_torrent_dp_enable_ssc_25mhz(struct cdns_torrent_phy *cdns_phy,
}
static
-void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
+void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct tp_data *tp_data,
u32 rate, bool ssc)
{
- struct regmap *regmap = cdns_phy->regmap_common_cdb;
+ struct regmap *regmap = tp_data->regmap_common_cdb;
/* Assumes 25 MHz refclock */
switch (rate) {
@@ -878,7 +876,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0120);
if (ssc)
- cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x0423);
+ cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x0423);
break;
/* Setting VCO for 9.72GHz */
case 1620:
@@ -893,7 +891,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0104);
if (ssc)
- cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x03B9);
+ cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x03B9);
break;
/* Setting VCO for 8.64GHz */
case 2160:
@@ -907,7 +905,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00E7);
if (ssc)
- cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x034F);
+ cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x034F);
break;
/* Setting VCO for 8.1GHz */
case 8100:
@@ -920,7 +918,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00D8);
if (ssc)
- cdns_torrent_dp_enable_ssc_25mhz(cdns_phy, 0x031A);
+ cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x031A);
break;
}
@@ -963,20 +961,20 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct cdns_torrent_phy *cdns_phy,
}
static
-void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
+void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct tp_data *tp_data,
u32 rate, bool ssc)
{
- struct regmap *regmap = cdns_phy->regmap_common_cdb;
+ struct regmap *regmap = tp_data->regmap_common_cdb;
/* Assumes 100 MHz refclock */
switch (rate) {
/* Setting VCO for 10.8GHz */
case 2700:
case 5400:
- if (cdns_phy->dp_pll & DP_PLL0)
+ if (tp_data->dp_pll & DP_PLL0)
cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_FBH_OVRD_M0, 0x0022);
- if (cdns_phy->dp_pll & DP_PLL1) {
+ if (tp_data->dp_pll & DP_PLL1) {
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0028);
cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_FBH_OVRD_M0, 0x0022);
cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_FBL_OVRD_M0, 0x000C);
@@ -986,7 +984,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
case 1620:
case 2430:
case 3240:
- if (cdns_phy->dp_pll & DP_PLL0) {
+ if (tp_data->dp_pll & DP_PLL0) {
cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
@@ -997,7 +995,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0042);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
}
- if (cdns_phy->dp_pll & DP_PLL1) {
+ if (tp_data->dp_pll & DP_PLL1) {
cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
@@ -1012,7 +1010,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
/* Setting VCO for 8.64GHz */
case 2160:
case 4320:
- if (cdns_phy->dp_pll & DP_PLL0) {
+ if (tp_data->dp_pll & DP_PLL0) {
cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
@@ -1023,7 +1021,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x003A);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
}
- if (cdns_phy->dp_pll & DP_PLL1) {
+ if (tp_data->dp_pll & DP_PLL1) {
cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
@@ -1037,7 +1035,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
break;
/* Setting VCO for 8.1GHz */
case 8100:
- if (cdns_phy->dp_pll & DP_PLL0) {
+ if (tp_data->dp_pll & DP_PLL0) {
cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
@@ -1047,7 +1045,7 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0036);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
}
- if (cdns_phy->dp_pll & DP_PLL1) {
+ if (tp_data->dp_pll & DP_PLL1) {
cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
@@ -1062,23 +1060,23 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct cdns_torrent_phy *cdns_phy,
}
/* Set PLL used for DP configuration */
-static int cdns_torrent_dp_get_pll(struct cdns_torrent_phy *cdns_phy,
+static int cdns_torrent_dp_get_pll(struct tp_data *tp_data,
enum cdns_torrent_phy_type phy_t2)
{
switch (phy_t2) {
case TYPE_PCIE:
case TYPE_USB:
- cdns_phy->dp_pll = DP_PLL1;
+ tp_data->dp_pll = DP_PLL1;
break;
case TYPE_SGMII:
case TYPE_QSGMII:
- cdns_phy->dp_pll = DP_PLL0;
+ tp_data->dp_pll = DP_PLL0;
break;
case TYPE_NONE:
- cdns_phy->dp_pll = DP_PLL0 | DP_PLL1;
+ tp_data->dp_pll = DP_PLL0 | DP_PLL1;
break;
default:
- dev_err(cdns_phy->dev, "Unsupported PHY configuration\n");
+ dev_err(tp_data->dev, "Unsupported PHY configuration\n");
return -EINVAL;
}
@@ -1088,12 +1086,10 @@ static int cdns_torrent_dp_get_pll(struct cdns_torrent_phy *cdns_phy,
/*
* Enable or disable PLL for selected lanes.
*/
-static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
- struct phy_configure_opts_dp *dp,
- bool enable)
+static int tp_dptx_set_pll_en(struct tp_data *tp_data, struct tp_link *link,
+ struct phy_configure_opts_dp *dp, bool enable)
{
- struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
+ struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
u32 rd_val, pll_ack_val;
int ret;
@@ -1113,7 +1109,7 @@ static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy,
pll_val |= pll_bits;
pll_ack_val = pll_bits;
} else {
- pll_bits = ((1 << inst->num_lanes) - 1);
+ pll_bits = ((1 << link->num_lanes) - 1);
pll_val &= (~pll_bits);
pll_ack_val = 0;
}
@@ -1130,10 +1126,8 @@ static int cdns_torrent_dp_set_pll_en(struct cdns_torrent_phy *cdns_phy,
return ret;
}
-static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
- u32 num_lanes,
- enum phy_powerstate powerstate)
+static int tp_dptx_set_power_state(struct tp_data *tp_data, struct tp_link *link,
+ u32 num_lanes, enum phy_powerstate powerstate)
{
/* Register value for power state for a single byte. */
u32 value_part, i;
@@ -1141,7 +1135,7 @@ static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy,
u32 mask = 0;
u32 read_val;
int ret;
- struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
+ struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
switch (powerstate) {
case (POWERSTATE_A0):
@@ -1178,12 +1172,28 @@ static int cdns_torrent_dp_set_power_state(struct cdns_torrent_phy *cdns_phy,
return ret;
}
-static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst, u32 num_lanes)
+static int tp_dptx_wait_pma_cmn_ready(struct tp_data *tp_data)
+{
+ unsigned int reg;
+ int ret;
+ struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
+
+ ret = regmap_read_poll_timeout(regmap, PHY_PMA_CMN_READY, reg,
+ reg & 1, 0, POLL_TIMEOUT_US);
+ if (ret == -ETIMEDOUT) {
+ dev_err(tp_data->dev,
+ "timeout waiting for PMA common ready\n");
+ return -ETIMEDOUT;
+ }
+
+ return 0;
+}
+
+static int tp_dp_run(struct tp_data *tp_data, struct tp_link *link, u32 num_lanes)
{
unsigned int read_val;
int ret;
- struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
+ struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
/*
* waiting for ACK of pma_xcvr_pllclk_en_ln_*, only for the
@@ -1193,43 +1203,24 @@ static int cdns_torrent_dp_run(struct cdns_torrent_phy *cdns_phy,
read_val, read_val & 1,
0, POLL_TIMEOUT_US);
if (ret == -ETIMEDOUT) {
- dev_err(cdns_phy->dev,
+ dev_err(tp_data->dev,
"timeout waiting for link PLL clock enable ack\n");
return ret;
}
ndelay(100);
- ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, num_lanes,
- POWERSTATE_A2);
+ ret = tp_dptx_set_power_state(tp_data, link, num_lanes, POWERSTATE_A2);
if (ret)
return ret;
- ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, num_lanes,
- POWERSTATE_A0);
+ ret = tp_dptx_set_power_state(tp_data, link, num_lanes, POWERSTATE_A0);
return ret;
}
-static int cdns_torrent_dp_wait_pma_cmn_ready(struct cdns_torrent_phy *cdns_phy)
-{
- unsigned int reg;
- int ret;
- struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
-
- ret = regmap_read_poll_timeout(regmap, PHY_PMA_CMN_READY, reg,
- reg & 1, 0, POLL_TIMEOUT_US);
- if (ret == -ETIMEDOUT) {
- dev_err(cdns_phy->dev,
- "timeout waiting for PMA common ready\n");
- return -ETIMEDOUT;
- }
-
- return 0;
-}
-
-static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
+static void cdns_torrent_dp_pma_cmn_rate(struct tp_data *tp_data,
+ struct tp_link *link,
u32 rate, u32 num_lanes)
{
unsigned int clk_sel_val = 0;
@@ -1262,17 +1253,17 @@ static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy,
break;
}
- if (cdns_phy->dp_pll & DP_PLL0)
- cdns_torrent_phy_write(cdns_phy->regmap_common_cdb,
+ if (tp_data->dp_pll & DP_PLL0)
+ cdns_torrent_phy_write(tp_data->regmap_common_cdb,
CMN_PDIAG_PLL0_CLK_SEL_M0, clk_sel_val);
- if (cdns_phy->dp_pll & DP_PLL1)
- cdns_torrent_phy_write(cdns_phy->regmap_common_cdb,
+ if (tp_data->dp_pll & DP_PLL1)
+ cdns_torrent_phy_write(tp_data->regmap_common_cdb,
CMN_PDIAG_PLL1_CLK_SEL_M0, clk_sel_val);
/* PMA lane configuration to deal with multi-link operation */
for (i = 0; i < num_lanes; i++)
- cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + i],
+ cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + i],
XCVR_DIAG_HSCLK_DIV, hsclk_div_val);
}
@@ -1280,9 +1271,8 @@ static void cdns_torrent_dp_pma_cmn_rate(struct cdns_torrent_phy *cdns_phy,
* Perform register operations related to setting link rate, once powerstate is
* set and PLL disable request was processed.
*/
-static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
- struct phy_configure_opts_dp *dp)
+static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link,
+ struct phy_configure_opts_dp *dp)
{
u32 read_val, field_val;
int ret;
@@ -1291,19 +1281,19 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
* Disable the associated PLL (cmn_pll0_en or cmn_pll1_en) before
* re-programming the new data rate.
*/
- ret = regmap_field_read(cdns_phy->phy_pma_pll_raw_ctrl, &field_val);
+ ret = regmap_field_read(tp_data->phy_pma_pll_raw_ctrl, &field_val);
if (ret)
return ret;
- field_val &= ~(cdns_phy->dp_pll);
- regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, field_val);
+ field_val &= ~(tp_data->dp_pll);
+ regmap_field_write(tp_data->phy_pma_pll_raw_ctrl, field_val);
/*
* Wait for PLL ready de-assertion.
* For PLL0 - PHY_PMA_CMN_CTRL2[2] == 1
* For PLL1 - PHY_PMA_CMN_CTRL2[3] == 1
*/
- if (cdns_phy->dp_pll & DP_PLL0) {
- ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
+ if (tp_data->dp_pll & DP_PLL0) {
+ ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
read_val,
((read_val >> 2) & 0x01) != 0,
0, POLL_TIMEOUT_US);
@@ -1311,8 +1301,8 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
return ret;
}
- if ((cdns_phy->dp_pll & DP_PLL1) && cdns_phy->nsubnodes != 1) {
- ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
+ if ((tp_data->dp_pll & DP_PLL1) && tp_data->nb_links != 1) {
+ ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
read_val,
((read_val >> 3) & 0x01) != 0,
0, POLL_TIMEOUT_US);
@@ -1322,32 +1312,32 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
ndelay(200);
/* DP Rate Change - VCO Output settings. */
- if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ)
+ if (tp_data->ref_clk_rate == CLK_19_2_MHZ)
/* PMA common configuration 19.2MHz */
- cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy, dp->link_rate, dp->ssc);
- else if (cdns_phy->ref_clk_rate == CLK_25_MHZ)
+ cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data, dp->link_rate, dp->ssc);
+ else if (tp_data->ref_clk_rate == CLK_25_MHZ)
/* PMA common configuration 25MHz */
- cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy, dp->link_rate, dp->ssc);
- else if (cdns_phy->ref_clk_rate == CLK_100_MHZ)
+ cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data, dp->link_rate, dp->ssc);
+ else if (tp_data->ref_clk_rate == CLK_100_MHZ)
/* PMA common configuration 100MHz */
- cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(cdns_phy, dp->link_rate, dp->ssc);
+ cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, dp->link_rate, dp->ssc);
- cdns_torrent_dp_pma_cmn_rate(cdns_phy, inst, dp->link_rate, dp->lanes);
+ cdns_torrent_dp_pma_cmn_rate(tp_data, link, dp->link_rate, dp->lanes);
/* Enable the associated PLL (cmn_pll0_en or cmn_pll1_en) */
- ret = regmap_field_read(cdns_phy->phy_pma_pll_raw_ctrl, &field_val);
+ ret = regmap_field_read(tp_data->phy_pma_pll_raw_ctrl, &field_val);
if (ret)
return ret;
- field_val |= cdns_phy->dp_pll;
- regmap_field_write(cdns_phy->phy_pma_pll_raw_ctrl, field_val);
+ field_val |= tp_data->dp_pll;
+ regmap_field_write(tp_data->phy_pma_pll_raw_ctrl, field_val);
/*
* Wait for PLL ready assertion.
* For PLL0 - PHY_PMA_CMN_CTRL2[0] == 1
* For PLL1 - PHY_PMA_CMN_CTRL2[1] == 1
*/
- if (cdns_phy->dp_pll & DP_PLL0) {
- ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
+ if (tp_data->dp_pll & DP_PLL0) {
+ ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
read_val,
(read_val & 0x01) != 0,
0, POLL_TIMEOUT_US);
@@ -1355,8 +1345,8 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
return ret;
}
- if ((cdns_phy->dp_pll & DP_PLL1) && cdns_phy->nsubnodes != 1)
- ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_2,
+ if ((tp_data->dp_pll & DP_PLL1) && tp_data->nb_links != 1)
+ ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
read_val,
((read_val >> 1) & 0x01) != 0,
0, POLL_TIMEOUT_US);
@@ -1367,8 +1357,7 @@ static int cdns_torrent_dp_configure_rate(struct cdns_torrent_phy *cdns_phy,
/*
* Verify, that parameters to configure PHY with are correct.
*/
-static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst *inst,
- struct phy_configure_opts_dp *dp)
+static int tp_dp_verify_config(struct tp_link *link, struct phy_configure_opts_dp *dp)
{
u8 i;
@@ -1402,7 +1391,7 @@ static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst *inst,
}
/* Check against actual number of PHY's lanes. */
- if (dp->lanes > inst->num_lanes)
+ if (dp->lanes > link->num_lanes)
return -EINVAL;
/*
@@ -1427,11 +1416,11 @@ static int cdns_torrent_dp_verify_config(struct cdns_torrent_inst *inst,
}
/* Set power state A0 and PLL clock enable to 0 on enabled lanes. */
-static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
+static void cdns_torrent_dp_set_a0_pll(struct tp_data *tp_data,
+ struct tp_link *link,
u32 num_lanes)
{
- struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
+ struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
u32 pwr_state = cdns_torrent_dp_read(regmap,
PHY_PMA_XCVR_POWER_STATE_REQ);
u32 pll_clk_en = cdns_torrent_dp_read(regmap,
@@ -1440,9 +1429,9 @@ static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy,
for (i = 0; i < num_lanes; i++) {
pwr_state &= ~(PMA_XCVR_POWER_STATE_REQ_LN_MASK
- << PHY_POWER_STATE_LN(inst->mlane + i));
+ << PHY_POWER_STATE_LN(link->mlane + i));
- pll_clk_en &= ~(0x01U << (inst->mlane + i));
+ pll_clk_en &= ~(0x01U << (link->mlane + i));
}
cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, pwr_state);
@@ -1450,22 +1439,21 @@ static void cdns_torrent_dp_set_a0_pll(struct cdns_torrent_phy *cdns_phy,
}
/* Configure lane count as required. */
-static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
- struct phy_configure_opts_dp *dp)
+static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
+ struct phy_configure_opts_dp *dp)
{
u32 value, i;
int ret;
- struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
+ struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
u8 lane_mask = (1 << dp->lanes) - 1;
u8 pma_tx_elec_idle_mask = 0;
- u32 clane = inst->mlane;
+ u32 clane = link->mlane;
lane_mask <<= clane;
value = cdns_torrent_dp_read(regmap, PHY_RESET);
/* clear pma_tx_elec_idle_ln_* bits. */
- pma_tx_elec_idle_mask = ((1 << inst->num_lanes) - 1) << clane;
+ pma_tx_elec_idle_mask = ((1 << link->num_lanes) - 1) << clane;
pma_tx_elec_idle_mask <<= PMA_TX_ELEC_IDLE_SHIFT;
@@ -1485,27 +1473,27 @@ static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy,
* Assert lane reset on unused lanes and master lane so they remain in reset
* and powered down when re-enabling the link
*/
- for (i = 0; i < inst->num_lanes; i++)
+ for (i = 0; i < link->num_lanes; i++)
value &= (~(1 << (clane + i)));
- for (i = 1; i < inst->num_lanes; i++)
+ for (i = 1; i < link->num_lanes; i++)
value |= ((1 << (clane + i)) & lane_mask);
cdns_torrent_dp_write(regmap, PHY_RESET, value);
- cdns_torrent_dp_set_a0_pll(cdns_phy, inst, dp->lanes);
+ cdns_torrent_dp_set_a0_pll(tp_data, link, dp->lanes);
/* release phy_l0*_reset_n based on used laneCount */
- for (i = 0; i < inst->num_lanes; i++)
+ for (i = 0; i < link->num_lanes; i++)
value &= (~(1 << (clane + i)));
- for (i = 0; i < inst->num_lanes; i++)
+ for (i = 0; i < link->num_lanes; i++)
value |= ((1 << (clane + i)) & lane_mask);
cdns_torrent_dp_write(regmap, PHY_RESET, value);
/* Wait, until PHY gets ready after releasing PHY reset signal. */
- ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy);
+ ret = tp_dptx_wait_pma_cmn_ready(tp_data);
if (ret)
return ret;
@@ -1516,41 +1504,37 @@ static int cdns_torrent_dp_set_lanes(struct cdns_torrent_phy *cdns_phy,
value |= (1 << clane);
cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, value);
- ret = cdns_torrent_dp_run(cdns_phy, inst, dp->lanes);
+ ret = tp_dp_run(tp_data, link, dp->lanes);
return ret;
}
/* Configure link rate as required. */
-static int cdns_torrent_dp_set_rate(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
- struct phy_configure_opts_dp *dp)
+static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
+ struct phy_configure_opts_dp *dp)
{
int ret;
- ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes,
- POWERSTATE_A3);
+ ret = tp_dptx_set_power_state(tp_data, link, dp->lanes, POWERSTATE_A3);
if (ret)
return ret;
- ret = cdns_torrent_dp_set_pll_en(cdns_phy, inst, dp, false);
+ ret = tp_dptx_set_pll_en(tp_data, link, dp, false);
if (ret)
return ret;
ndelay(200);
- ret = cdns_torrent_dp_configure_rate(cdns_phy, inst, dp);
+ ret = tp_dp_configure_rate(tp_data, link, dp);
if (ret)
return ret;
ndelay(200);
- ret = cdns_torrent_dp_set_pll_en(cdns_phy, inst, dp, true);
+ ret = tp_dptx_set_pll_en(tp_data, link, dp, true);
if (ret)
return ret;
- ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes,
- POWERSTATE_A2);
+ ret = tp_dptx_set_power_state(tp_data, link, dp->lanes, POWERSTATE_A2);
if (ret)
return ret;
- ret = cdns_torrent_dp_set_power_state(cdns_phy, inst, dp->lanes,
- POWERSTATE_A0);
+ ret = tp_dptx_set_power_state(tp_data, link, dp->lanes, POWERSTATE_A0);
if (ret)
return ret;
ndelay(900);
@@ -1559,107 +1543,105 @@ static int cdns_torrent_dp_set_rate(struct cdns_torrent_phy *cdns_phy,
}
/* Configure voltage swing and pre-emphasis for all enabled lanes. */
-static void cdns_torrent_dp_set_voltages(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
- struct phy_configure_opts_dp *dp)
+static void tp_dp_set_voltages(struct tp_data *tp_data, struct tp_link *link,
+ struct phy_configure_opts_dp *dp)
{
u8 lane;
u16 val;
for (lane = 0; lane < dp->lanes; lane++) {
- val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ val = cdns_torrent_phy_read(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
TX_DIAG_ACYA);
/*
* Write 1 to register bit TX_DIAG_ACYA[0] to freeze the
* current state of the analog TX driver.
*/
val |= TX_DIAG_ACYA_HBDC_MASK;
- cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
TX_DIAG_ACYA, val);
- cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
TX_TXCC_CTRL, 0x08A4);
val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].diag_tx_drv;
- cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
DRV_DIAG_TX_DRV, val);
val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult;
- cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
TX_TXCC_MGNFS_MULT_000,
val);
val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].cpost_mult;
- cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
TX_TXCC_CPOST_MULT_00,
val);
- val = cdns_torrent_phy_read(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ val = cdns_torrent_phy_read(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
TX_DIAG_ACYA);
/*
* Write 0 to register bit TX_DIAG_ACYA[0] to allow the state of
* analog TX driver to reflect the new programmed one.
*/
val &= ~TX_DIAG_ACYA_HBDC_MASK;
- cdns_torrent_phy_write(cdns_phy->regmap_tx_lane_cdb[inst->mlane + lane],
+ cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
TX_DIAG_ACYA, val);
}
-};
+}
-static int cdns_torrent_dp_configure(struct phy *phy,
- union phy_configure_opts *opts)
+static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
{
- struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
- struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
+ struct tp_link *link = phy_get_drvdata(phy);
+ struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
int ret;
- if (cdns_phy->already_configured)
+ if (tp_data->already_configured)
return 0;
- ret = cdns_torrent_dp_verify_config(inst, &opts->dp);
+ ret = tp_dp_verify_config(link, &opts->dp);
if (ret) {
dev_err(&phy->dev, "invalid params for phy configure\n");
return ret;
}
if (opts->dp.set_lanes) {
- ret = cdns_torrent_dp_set_lanes(cdns_phy, inst, &opts->dp);
+ ret = tp_dp_set_lanes(tp_data, link, &opts->dp);
if (ret) {
- dev_err(&phy->dev, "cdns_torrent_dp_set_lanes failed\n");
+ dev_err(&phy->dev, "tp_dp_set_lanes failed\n");
return ret;
}
}
if (opts->dp.set_rate) {
- ret = cdns_torrent_dp_set_rate(cdns_phy, inst, &opts->dp);
+ ret = tp_dp_set_rate(tp_data, link, &opts->dp);
if (ret) {
- dev_err(&phy->dev, "cdns_torrent_dp_set_rate failed\n");
+ dev_err(&phy->dev, "tp_dp_set_rate failed\n");
return ret;
}
}
if (opts->dp.set_voltages)
- cdns_torrent_dp_set_voltages(cdns_phy, inst, &opts->dp);
+ tp_dp_set_voltages(tp_data, link, &opts->dp);
return ret;
}
-static int cdns_torrent_phy_on(struct phy *phy)
+static int tp_phy_on(struct phy *phy)
{
- struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
- struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
+ struct tp_link *link = phy_get_drvdata(phy);
+ struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
u32 read_val;
int ret;
- if (cdns_phy->already_configured) {
+ if (tp_data->already_configured) {
/* Give 5ms to 10ms delay for the PIPE clock to be stable */
usleep_range(5000, 10000);
return 0;
}
- if (cdns_phy->nsubnodes == 1) {
+ if (tp_data->nb_links == 1) {
/* Take the PHY lane group out of reset */
- reset_control_deassert(inst->lnk_rst);
+ reset_control_deassert(link->lnk_rst);
/* Take the PHY out of reset */
- ret = reset_control_deassert(cdns_phy->phy_rst);
+ ret = reset_control_deassert(tp_data->phy_rst);
if (ret)
return ret;
}
@@ -1668,20 +1650,20 @@ static int cdns_torrent_phy_on(struct phy *phy)
* Wait for cmn_ready assertion
* PHY_PMA_CMN_CTRL1[0] == 1
*/
- ret = regmap_field_read_poll_timeout(cdns_phy->phy_pma_cmn_ctrl_1,
+ ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_1,
read_val, read_val, 1000,
PLL_LOCK_TIMEOUT);
if (ret) {
- dev_err(cdns_phy->dev, "Timeout waiting for CMN ready\n");
+ dev_err(tp_data->dev, "Timeout waiting for CMN ready\n");
return ret;
}
- if (inst->phy_type == TYPE_PCIE || inst->phy_type == TYPE_USB) {
- ret = regmap_field_read_poll_timeout(cdns_phy->phy_pcs_iso_link_ctrl_1[inst->mlane],
+ if (link->phy_type == TYPE_PCIE || link->phy_type == TYPE_USB) {
+ ret = regmap_field_read_poll_timeout(tp_data->phy_pcs_iso_link_ctrl_1[link->mlane],
read_val, !read_val, 1000,
PLL_LOCK_TIMEOUT);
if (ret == -ETIMEDOUT) {
- dev_err(cdns_phy->dev, "Timeout waiting for PHY status ready\n");
+ dev_err(tp_data->dev, "Timeout waiting for PHY status ready\n");
return ret;
}
}
@@ -1689,26 +1671,26 @@ static int cdns_torrent_phy_on(struct phy *phy)
return 0;
}
-static int cdns_torrent_phy_off(struct phy *phy)
+static int tp_phy_off(struct phy *phy)
{
- struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
- struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
+ struct tp_link *link = phy_get_drvdata(phy);
+ struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
int ret;
- if (cdns_phy->nsubnodes != 1)
+ if (tp_data->nb_links != 1)
return 0;
- ret = reset_control_assert(cdns_phy->phy_rst);
+ ret = reset_control_assert(tp_data->phy_rst);
if (ret)
return ret;
- return reset_control_assert(inst->lnk_rst);
+ return reset_control_assert(link->lnk_rst);
}
-static void cdns_torrent_dp_common_init(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst)
+static void cdns_torrent_dp_common_init(struct tp_data *tp_data,
+ struct tp_link *link)
{
- struct regmap *regmap = cdns_phy->regmap_dptx_phy_reg;
+ struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
unsigned char lane_bits;
u32 val;
@@ -1718,13 +1700,13 @@ static void cdns_torrent_dp_common_init(struct cdns_torrent_phy *cdns_phy,
* Set lines power state to A0
* Set lines pll clk enable to 0
*/
- cdns_torrent_dp_set_a0_pll(cdns_phy, inst, inst->num_lanes);
+ cdns_torrent_dp_set_a0_pll(tp_data, link, link->num_lanes);
/*
* release phy_l0*_reset_n and pma_tx_elec_idle_ln_* based on
* used lanes
*/
- lane_bits = (1 << inst->num_lanes) - 1;
+ lane_bits = (1 << link->num_lanes) - 1;
val = cdns_torrent_dp_read(regmap, PHY_RESET);
val |= (0xF & lane_bits);
@@ -1740,86 +1722,84 @@ static void cdns_torrent_dp_common_init(struct cdns_torrent_phy *cdns_phy,
* PHY PMA registers configuration functions
* Initialize PHY with max supported link rate, without SSC.
*/
- if (cdns_phy->ref_clk_rate == CLK_19_2_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(cdns_phy,
- cdns_phy->max_bit_rate,
+ if (tp_data->ref_clk_rate == CLK_19_2_MHZ)
+ cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data,
+ tp_data->max_bit_rate,
false);
- else if (cdns_phy->ref_clk_rate == CLK_25_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(cdns_phy,
- cdns_phy->max_bit_rate,
+ else if (tp_data->ref_clk_rate == CLK_25_MHZ)
+ cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data,
+ tp_data->max_bit_rate,
false);
- else if (cdns_phy->ref_clk_rate == CLK_100_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(cdns_phy,
- cdns_phy->max_bit_rate,
+ else if (tp_data->ref_clk_rate == CLK_100_MHZ)
+ cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data,
+ tp_data->max_bit_rate,
false);
- cdns_torrent_dp_pma_cmn_rate(cdns_phy, inst, cdns_phy->max_bit_rate,
- inst->num_lanes);
+ cdns_torrent_dp_pma_cmn_rate(tp_data, link, tp_data->max_bit_rate,
+ link->num_lanes);
/* take out of reset */
- regmap_field_write(cdns_phy->phy_reset_ctrl, 0x1);
+ regmap_field_write(tp_data->phy_reset_ctrl, 0x1);
}
-static int cdns_torrent_dp_start(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
- struct phy *phy)
+static int cdns_torrent_dp_start(struct tp_data *tp_data, struct tp_link *link, struct phy *phy)
{
int ret;
- ret = cdns_torrent_phy_on(phy);
+ ret = tp_phy_on(phy);
if (ret)
return ret;
- ret = cdns_torrent_dp_wait_pma_cmn_ready(cdns_phy);
+ ret = tp_dptx_wait_pma_cmn_ready(tp_data);
if (ret)
return ret;
- ret = cdns_torrent_dp_run(cdns_phy, inst, inst->num_lanes);
+ ret = tp_dp_run(tp_data, link, link->num_lanes);
return ret;
}
static int cdns_torrent_dp_init(struct phy *phy)
{
- struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
- struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
+ struct tp_link *link = phy_get_drvdata(phy);
+ struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
int ret;
- switch (cdns_phy->ref_clk_rate) {
+ switch (tp_data->ref_clk_rate) {
case CLK_19_2_MHZ:
case CLK_25_MHZ:
case CLK_100_MHZ:
/* Valid Ref Clock Rate */
break;
default:
- dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n");
+ dev_err(tp_data->dev, "Unsupported Ref Clock Rate\n");
return -EINVAL;
}
- ret = cdns_torrent_dp_get_pll(cdns_phy, TYPE_NONE);
+ ret = cdns_torrent_dp_get_pll(tp_data, TYPE_NONE);
if (ret)
return ret;
- cdns_torrent_dp_common_init(cdns_phy, inst);
+ cdns_torrent_dp_common_init(tp_data, link);
- return cdns_torrent_dp_start(cdns_phy, inst, phy);
+ return cdns_torrent_dp_start(tp_data, link, phy);
}
-static int cdns_torrent_dp_multilink_init(struct cdns_torrent_phy *cdns_phy,
- struct cdns_torrent_inst *inst,
+static int cdns_torrent_dp_multilink_init(struct tp_data *tp_data,
+ struct tp_link *link,
struct phy *phy)
{
- if (cdns_phy->ref_clk_rate != CLK_100_MHZ) {
- dev_err(cdns_phy->dev, "Unsupported Ref Clock Rate\n");
+ if (tp_data->ref_clk_rate != CLK_100_MHZ) {
+ dev_err(tp_data->dev, "Unsupported Ref Clock Rate\n");
return -EINVAL;
}
- cdns_torrent_dp_common_init(cdns_phy, inst);
+ cdns_torrent_dp_common_init(tp_data, link);
- return cdns_torrent_dp_start(cdns_phy, inst, phy);
+ return cdns_torrent_dp_start(tp_data, link, phy);
}
-static int cdns_torrent_derived_refclk_enable(struct clk_hw *hw)
+static int tp_derived_refclk_enable(struct clk_hw *hw)
{
struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
@@ -1829,7 +1809,7 @@ static int cdns_torrent_derived_refclk_enable(struct clk_hw *hw)
return 0;
}
-static void cdns_torrent_derived_refclk_disable(struct clk_hw *hw)
+static void tp_derived_refclk_disable(struct clk_hw *hw)
{
struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
@@ -1837,7 +1817,7 @@ static void cdns_torrent_derived_refclk_disable(struct clk_hw *hw)
regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0);
}
-static int cdns_torrent_derived_refclk_is_enabled(struct clk_hw *hw)
+static int tp_derived_refclk_is_enabled(struct clk_hw *hw)
{
struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
int val;
@@ -1847,16 +1827,16 @@ static int cdns_torrent_derived_refclk_is_enabled(struct clk_hw *hw)
return !!val;
}
-static const struct clk_ops cdns_torrent_derived_refclk_ops = {
- .enable = cdns_torrent_derived_refclk_enable,
- .disable = cdns_torrent_derived_refclk_disable,
- .is_enabled = cdns_torrent_derived_refclk_is_enabled,
+static const struct clk_ops tp_derived_refclk_ops = {
+ .enable = tp_derived_refclk_enable,
+ .disable = tp_derived_refclk_disable,
+ .is_enabled = tp_derived_refclk_is_enabled,
};
-static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_phy)
+static int tp_derived_refclk_register(struct tp_data *tp_data)
{
struct cdns_torrent_derived_refclk *derived_refclk;
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
struct clk_init_data *init;
const char *parent_name;
char clk_name[100];
@@ -1869,7 +1849,7 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph
return -ENOMEM;
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
- clk_names[CDNS_TORRENT_DERIVED_REFCLK]);
+ tp_clk_names[CDNS_TORRENT_DERIVED_REFCLK]);
clk = devm_clk_get_optional(dev, "phy_en_refclk");
if (IS_ERR(clk)) {
@@ -1884,12 +1864,12 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph
init->parent_names = &parent_name;
init->num_parents = 1;
}
- init->ops = &cdns_torrent_derived_refclk_ops;
+ init->ops = &tp_derived_refclk_ops;
init->flags = 0;
init->name = clk_name;
- derived_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0;
- derived_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4;
+ derived_refclk->phy_pipe_cmn_ctrl1_0 = tp_data->phy_pipe_cmn_ctrl1_0;
+ derived_refclk->cmn_cdiag_refclk_ovrd_4 = tp_data->cmn_cdiag_refclk_ovrd_4;
derived_refclk->hw.init = init;
@@ -1898,12 +1878,12 @@ static int cdns_torrent_derived_refclk_register(struct cdns_torrent_phy *cdns_ph
if (ret)
return ret;
- cdns_phy->clk_hw_data->hws[CDNS_TORRENT_DERIVED_REFCLK] = hw;
+ tp_data->clk_hw_data->hws[CDNS_TORRENT_DERIVED_REFCLK] = hw;
return 0;
}
-static int cdns_torrent_received_refclk_enable(struct clk_hw *hw)
+static int tp_received_refclk_enable(struct clk_hw *hw)
{
struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
@@ -1912,14 +1892,14 @@ static int cdns_torrent_received_refclk_enable(struct clk_hw *hw)
return 0;
}
-static void cdns_torrent_received_refclk_disable(struct clk_hw *hw)
+static void tp_received_refclk_disable(struct clk_hw *hw)
{
struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0);
}
-static int cdns_torrent_received_refclk_is_enabled(struct clk_hw *hw)
+static int tp_received_refclk_is_enabled(struct clk_hw *hw)
{
struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
int val, cmn_val;
@@ -1930,16 +1910,16 @@ static int cdns_torrent_received_refclk_is_enabled(struct clk_hw *hw)
return val && !cmn_val;
}
-static const struct clk_ops cdns_torrent_received_refclk_ops = {
- .enable = cdns_torrent_received_refclk_enable,
- .disable = cdns_torrent_received_refclk_disable,
- .is_enabled = cdns_torrent_received_refclk_is_enabled,
+static const struct clk_ops tp_received_refclk_ops = {
+ .enable = tp_received_refclk_enable,
+ .disable = tp_received_refclk_disable,
+ .is_enabled = tp_received_refclk_is_enabled,
};
-static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_phy)
+static int tp_received_refclk_register(struct tp_data *tp_data)
{
struct cdns_torrent_received_refclk *received_refclk;
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
struct clk_init_data *init;
const char *parent_name;
char clk_name[100];
@@ -1952,7 +1932,7 @@ static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_p
return -ENOMEM;
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
- clk_names[CDNS_TORRENT_RECEIVED_REFCLK]);
+ tp_clk_names[CDNS_TORRENT_RECEIVED_REFCLK]);
clk = devm_clk_get_optional(dev, "phy_en_refclk");
if (IS_ERR(clk)) {
@@ -1967,12 +1947,12 @@ static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_p
init->parent_names = &parent_name;
init->num_parents = 1;
}
- init->ops = &cdns_torrent_received_refclk_ops;
+ init->ops = &tp_received_refclk_ops;
init->flags = 0;
init->name = clk_name;
- received_refclk->phy_pipe_cmn_ctrl1_0 = cdns_phy->phy_pipe_cmn_ctrl1_0;
- received_refclk->cmn_cdiag_refclk_ovrd_4 = cdns_phy->cmn_cdiag_refclk_ovrd_4;
+ received_refclk->phy_pipe_cmn_ctrl1_0 = tp_data->phy_pipe_cmn_ctrl1_0;
+ received_refclk->cmn_cdiag_refclk_ovrd_4 = tp_data->cmn_cdiag_refclk_ovrd_4;
received_refclk->hw.init = init;
@@ -1981,14 +1961,14 @@ static int cdns_torrent_received_refclk_register(struct cdns_torrent_phy *cdns_p
if (ret)
return ret;
- cdns_phy->clk_hw_data->hws[CDNS_TORRENT_RECEIVED_REFCLK] = hw;
+ tp_data->clk_hw_data->hws[CDNS_TORRENT_RECEIVED_REFCLK] = hw;
return 0;
}
-static int cdns_torrent_refclk_driver_enable(struct clk_hw *hw)
+static int tp_refclk_driver_enable(struct clk_hw *hw)
{
- struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw);
+ struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0);
regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1);
@@ -1997,16 +1977,16 @@ static int cdns_torrent_refclk_driver_enable(struct clk_hw *hw)
return 0;
}
-static void cdns_torrent_refclk_driver_disable(struct clk_hw *hw)
+static void tp_refclk_driver_disable(struct clk_hw *hw)
{
- struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw);
+ struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1);
}
-static int cdns_torrent_refclk_driver_is_enabled(struct clk_hw *hw)
+static int tp_refclk_driver_is_enabled(struct clk_hw *hw)
{
- struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw);
+ struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
int val;
regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], &val);
@@ -2014,37 +1994,37 @@ static int cdns_torrent_refclk_driver_is_enabled(struct clk_hw *hw)
return !val;
}
-static u8 cdns_torrent_refclk_driver_get_parent(struct clk_hw *hw)
+static u8 tp_refclk_driver_get_parent(struct clk_hw *hw)
{
- struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw);
+ struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
unsigned int val;
regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], &val);
- return clk_mux_val_to_index(hw, cdns_torrent_refclk_driver_mux_table, 0, val);
+ return clk_mux_val_to_index(hw, tp_refclk_driver_mux_table, 0, val);
}
-static int cdns_torrent_refclk_driver_set_parent(struct clk_hw *hw, u8 index)
+static int tp_refclk_driver_set_parent(struct clk_hw *hw, u8 index)
{
- struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw);
+ struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
unsigned int val;
- val = cdns_torrent_refclk_driver_mux_table[index];
+ val = tp_refclk_driver_mux_table[index];
return regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val);
}
-static const struct clk_ops cdns_torrent_refclk_driver_ops = {
- .enable = cdns_torrent_refclk_driver_enable,
- .disable = cdns_torrent_refclk_driver_disable,
- .is_enabled = cdns_torrent_refclk_driver_is_enabled,
+static const struct clk_ops tp_refclk_driver_ops = {
+ .enable = tp_refclk_driver_enable,
+ .disable = tp_refclk_driver_disable,
+ .is_enabled = tp_refclk_driver_is_enabled,
.determine_rate = __clk_mux_determine_rate,
- .set_parent = cdns_torrent_refclk_driver_set_parent,
- .get_parent = cdns_torrent_refclk_driver_get_parent,
+ .set_parent = tp_refclk_driver_set_parent,
+ .get_parent = tp_refclk_driver_get_parent,
};
-static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy)
+static int tp_refclk_driver_register(struct tp_data *tp_data)
{
- struct cdns_torrent_refclk_driver *refclk_driver;
- struct device *dev = cdns_phy->dev;
+ struct tp_refclk_driver *refclk_driver;
+ struct device *dev = tp_data->dev;
struct regmap_field *field;
struct clk_init_data *init;
const char **parent_names;
@@ -2058,13 +2038,13 @@ static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy
if (!refclk_driver)
return -ENOMEM;
- num_parents = ARRAY_SIZE(refclk_driver_parent_index);
+ num_parents = ARRAY_SIZE(tp_refclk_driver_parent_idx);
parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL);
if (!parent_names)
return -ENOMEM;
for (i = 0; i < num_parents; i++) {
- hw = cdns_phy->clk_hw_data->hws[refclk_driver_parent_index[i]];
+ hw = tp_data->clk_hw_data->hws[tp_refclk_driver_parent_idx[i]];
if (IS_ERR_OR_NULL(hw)) {
dev_err(dev, "No parent clock for refclk driver clock\n");
return IS_ERR(hw) ? PTR_ERR(hw) : -ENOENT;
@@ -2073,19 +2053,19 @@ static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy
}
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
- clk_names[CDNS_TORRENT_REFCLK_DRIVER]);
+ tp_clk_names[CDNS_TORRENT_REFCLK_DRIVER]);
init = &refclk_driver->clk_data;
- init->ops = &cdns_torrent_refclk_driver_ops;
+ init->ops = &tp_refclk_driver_ops;
init->flags = CLK_SET_RATE_NO_REPARENT;
init->parent_names = parent_names;
init->num_parents = num_parents;
init->name = clk_name;
- regmap = cdns_phy->regmap_common_cdb;
+ regmap = tp_data->regmap_common_cdb;
- for (i = 0; i < REFCLK_OUT_NUM_CMN_CONFIG; i++) {
+ for (i = 0; i < TP_REFCLK_OUT_NUM_CMN_CONFIG; i++) {
field = devm_regmap_field_alloc(dev, regmap, refclk_out_cmn_cfg[i]);
if (IS_ERR(field)) {
dev_err(dev, "Refclk driver CMN reg field init failed\n");
@@ -2104,7 +2084,7 @@ static int cdns_torrent_refclk_driver_register(struct cdns_torrent_phy *cdns_phy
if (ret)
return ret;
- cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER] = hw;
+ tp_data->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER] = hw;
return 0;
}
@@ -2127,100 +2107,100 @@ static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base,
return devm_regmap_init(dev, NULL, ctx, config);
}
-static int cdns_torrent_dp_regfield_init(struct cdns_torrent_phy *cdns_phy)
+static int cdns_torrent_dp_regfield_init(struct tp_data *tp_data)
{
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
struct regmap_field *field;
struct regmap *regmap;
- regmap = cdns_phy->regmap_dptx_phy_reg;
+ regmap = tp_data->regmap_dptx_phy_reg;
field = devm_regmap_field_alloc(dev, regmap, phy_reset_ctrl);
if (IS_ERR(field)) {
dev_err(dev, "PHY_RESET reg field init failed\n");
return PTR_ERR(field);
}
- cdns_phy->phy_reset_ctrl = field;
+ tp_data->phy_reset_ctrl = field;
return 0;
}
-static int cdns_torrent_regfield_init(struct cdns_torrent_phy *cdns_phy)
+static int cdns_torrent_regfield_init(struct tp_data *tp_data)
{
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
struct regmap_field *field;
struct regmap *regmap;
int i;
- regmap = cdns_phy->regmap_phy_pcs_common_cdb;
+ regmap = tp_data->regmap_phy_pcs_common_cdb;
field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg);
if (IS_ERR(field)) {
dev_err(dev, "PHY_PLL_CFG reg field init failed\n");
return PTR_ERR(field);
}
- cdns_phy->phy_pll_cfg = field;
+ tp_data->phy_pll_cfg = field;
- regmap = cdns_phy->regmap_phy_pcs_common_cdb;
+ regmap = tp_data->regmap_phy_pcs_common_cdb;
field = devm_regmap_field_alloc(dev, regmap, phy_pipe_cmn_ctrl1_0);
if (IS_ERR(field)) {
dev_err(dev, "phy_pipe_cmn_ctrl1_0 reg field init failed\n");
return PTR_ERR(field);
}
- cdns_phy->phy_pipe_cmn_ctrl1_0 = field;
+ tp_data->phy_pipe_cmn_ctrl1_0 = field;
- regmap = cdns_phy->regmap_common_cdb;
+ regmap = tp_data->regmap_common_cdb;
field = devm_regmap_field_alloc(dev, regmap, cmn_cdiag_refclk_ovrd_4);
if (IS_ERR(field)) {
dev_err(dev, "cmn_cdiag_refclk_ovrd_4 reg field init failed\n");
return PTR_ERR(field);
}
- cdns_phy->cmn_cdiag_refclk_ovrd_4 = field;
+ tp_data->cmn_cdiag_refclk_ovrd_4 = field;
- regmap = cdns_phy->regmap_phy_pma_common_cdb;
+ regmap = tp_data->regmap_phy_pma_common_cdb;
field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_1);
if (IS_ERR(field)) {
dev_err(dev, "PHY_PMA_CMN_CTRL1 reg field init failed\n");
return PTR_ERR(field);
}
- cdns_phy->phy_pma_cmn_ctrl_1 = field;
+ tp_data->phy_pma_cmn_ctrl_1 = field;
- regmap = cdns_phy->regmap_phy_pma_common_cdb;
+ regmap = tp_data->regmap_phy_pma_common_cdb;
field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_2);
if (IS_ERR(field)) {
dev_err(dev, "PHY_PMA_CMN_CTRL2 reg field init failed\n");
return PTR_ERR(field);
}
- cdns_phy->phy_pma_cmn_ctrl_2 = field;
+ tp_data->phy_pma_cmn_ctrl_2 = field;
- regmap = cdns_phy->regmap_phy_pma_common_cdb;
+ regmap = tp_data->regmap_phy_pma_common_cdb;
field = devm_regmap_field_alloc(dev, regmap, phy_pma_pll_raw_ctrl);
if (IS_ERR(field)) {
dev_err(dev, "PHY_PMA_PLL_RAW_CTRL reg field init failed\n");
return PTR_ERR(field);
}
- cdns_phy->phy_pma_pll_raw_ctrl = field;
+ tp_data->phy_pma_pll_raw_ctrl = field;
for (i = 0; i < MAX_NUM_LANES; i++) {
- regmap = cdns_phy->regmap_phy_pcs_lane_cdb[i];
+ regmap = tp_data->regmap_phy_pcs_lane_cdb[i];
field = devm_regmap_field_alloc(dev, regmap, phy_pcs_iso_link_ctrl_1);
if (IS_ERR(field)) {
dev_err(dev, "PHY_PCS_ISO_LINK_CTRL reg field init for ln %d failed\n", i);
return PTR_ERR(field);
}
- cdns_phy->phy_pcs_iso_link_ctrl_1[i] = field;
+ tp_data->phy_pcs_iso_link_ctrl_1[i] = field;
}
return 0;
}
-static int cdns_torrent_dp_regmap_init(struct cdns_torrent_phy *cdns_phy)
+static int cdns_torrent_dp_regmap_init(struct tp_data *tp_data)
{
- void __iomem *base = cdns_phy->base;
- struct device *dev = cdns_phy->dev;
+ void __iomem *base = tp_data->base;
+ struct device *dev = tp_data->dev;
struct regmap *regmap;
u8 reg_offset_shift;
u32 block_offset;
- reg_offset_shift = cdns_phy->init_data->reg_offset_shift;
+ reg_offset_shift = tp_data->init_data->reg_offset_shift;
block_offset = TORRENT_DPTX_PHY_OFFSET;
regmap = cdns_regmap_init(dev, base, block_offset,
@@ -2230,22 +2210,22 @@ static int cdns_torrent_dp_regmap_init(struct cdns_torrent_phy *cdns_phy)
dev_err(dev, "Failed to init DPTX PHY regmap\n");
return PTR_ERR(regmap);
}
- cdns_phy->regmap_dptx_phy_reg = regmap;
+ tp_data->regmap_dptx_phy_reg = regmap;
return 0;
}
-static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
+static int cdns_torrent_regmap_init(struct tp_data *tp_data)
{
- void __iomem *sd_base = cdns_phy->sd_base;
+ void __iomem *sd_base = tp_data->sd_base;
u8 block_offset_shift, reg_offset_shift;
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
struct regmap *regmap;
u32 block_offset;
int i;
- block_offset_shift = cdns_phy->init_data->block_offset_shift;
- reg_offset_shift = cdns_phy->init_data->reg_offset_shift;
+ block_offset_shift = tp_data->init_data->block_offset_shift;
+ reg_offset_shift = tp_data->init_data->reg_offset_shift;
for (i = 0; i < MAX_NUM_LANES; i++) {
block_offset = TORRENT_TX_LANE_CDB_OFFSET(i, block_offset_shift,
@@ -2257,7 +2237,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
dev_err(dev, "Failed to init tx lane CDB regmap\n");
return PTR_ERR(regmap);
}
- cdns_phy->regmap_tx_lane_cdb[i] = regmap;
+ tp_data->regmap_tx_lane_cdb[i] = regmap;
block_offset = TORRENT_RX_LANE_CDB_OFFSET(i, block_offset_shift,
reg_offset_shift);
@@ -2268,7 +2248,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
dev_err(dev, "Failed to init rx lane CDB regmap\n");
return PTR_ERR(regmap);
}
- cdns_phy->regmap_rx_lane_cdb[i] = regmap;
+ tp_data->regmap_rx_lane_cdb[i] = regmap;
block_offset = TORRENT_PHY_PCS_LANE_CDB_OFFSET(i, block_offset_shift,
reg_offset_shift);
@@ -2279,7 +2259,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
dev_err(dev, "Failed to init PHY PCS lane CDB regmap\n");
return PTR_ERR(regmap);
}
- cdns_phy->regmap_phy_pcs_lane_cdb[i] = regmap;
+ tp_data->regmap_phy_pcs_lane_cdb[i] = regmap;
}
block_offset = TORRENT_COMMON_CDB_OFFSET;
@@ -2290,7 +2270,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
dev_err(dev, "Failed to init common CDB regmap\n");
return PTR_ERR(regmap);
}
- cdns_phy->regmap_common_cdb = regmap;
+ tp_data->regmap_common_cdb = regmap;
block_offset = TORRENT_PHY_PCS_COMMON_OFFSET(block_offset_shift);
regmap = cdns_regmap_init(dev, sd_base, block_offset,
@@ -2300,7 +2280,7 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
dev_err(dev, "Failed to init PHY PCS common CDB regmap\n");
return PTR_ERR(regmap);
}
- cdns_phy->regmap_phy_pcs_common_cdb = regmap;
+ tp_data->regmap_phy_pcs_common_cdb = regmap;
block_offset = TORRENT_PHY_PMA_COMMON_OFFSET(block_offset_shift);
regmap = cdns_regmap_init(dev, sd_base, block_offset,
@@ -2310,34 +2290,34 @@ static int cdns_torrent_regmap_init(struct cdns_torrent_phy *cdns_phy)
dev_err(dev, "Failed to init PHY PMA common CDB regmap\n");
return PTR_ERR(regmap);
}
- cdns_phy->regmap_phy_pma_common_cdb = regmap;
+ tp_data->regmap_phy_pma_common_cdb = regmap;
return 0;
}
-static int cdns_torrent_phy_init(struct phy *phy)
+static int tp_phy_init(struct phy *phy)
{
- struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(phy->dev.parent);
+ struct tp_data *tp_data = dev_get_drvdata(phy->dev.parent);
const struct cdns_torrent_vals *cmn_vals, *tx_ln_vals, *rx_ln_vals;
- const struct cdns_torrent_data *init_data = cdns_phy->init_data;
+ const struct cdns_torrent_data *init_data = tp_data->init_data;
const struct cdns_torrent_vals *link_cmn_vals, *xcvr_diag_vals;
- enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate;
- struct cdns_torrent_inst *inst = phy_get_drvdata(phy);
- enum cdns_torrent_phy_type phy_type = inst->phy_type;
+ enum cdns_torrent_ref_clk ref_clk = tp_data->ref_clk_rate;
+ struct tp_link *link = phy_get_drvdata(phy);
+ enum cdns_torrent_phy_type phy_type = link->phy_type;
const struct cdns_torrent_vals *phy_pma_cmn_vals;
- enum cdns_torrent_ssc_mode ssc = inst->ssc_mode;
+ enum cdns_torrent_ssc_mode ssc = link->ssc_mode;
const struct cdns_torrent_vals *pcs_cmn_vals;
const struct cdns_reg_pairs *reg_pairs;
struct regmap *regmap;
u32 num_regs;
int i, j;
- if (cdns_phy->already_configured)
+ if (tp_data->already_configured)
return 0;
- if (cdns_phy->nsubnodes > 1) {
+ if (tp_data->nb_links > 1) {
if (phy_type == TYPE_DP)
- return cdns_torrent_dp_multilink_init(cdns_phy, inst, phy);
+ return cdns_torrent_dp_multilink_init(tp_data, link, phy);
return 0;
}
@@ -2356,13 +2336,13 @@ static int cdns_torrent_phy_init(struct phy *phy)
if (link_cmn_vals) {
reg_pairs = link_cmn_vals->reg_pairs;
num_regs = link_cmn_vals->num_regs;
- regmap = cdns_phy->regmap_common_cdb;
+ regmap = tp_data->regmap_common_cdb;
/**
* First array value in link_cmn_vals must be of
* PHY_PLL_CFG register
*/
- regmap_field_write(cdns_phy->phy_pll_cfg, reg_pairs[0].val);
+ regmap_field_write(tp_data->phy_pll_cfg, reg_pairs[0].val);
for (i = 1; i < num_regs; i++)
regmap_write(regmap, reg_pairs[i].off,
@@ -2376,8 +2356,8 @@ static int cdns_torrent_phy_init(struct phy *phy)
if (xcvr_diag_vals) {
reg_pairs = xcvr_diag_vals->reg_pairs;
num_regs = xcvr_diag_vals->num_regs;
- for (i = 0; i < inst->num_lanes; i++) {
- regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane];
+ for (i = 0; i < link->num_lanes; i++) {
+ regmap = tp_data->regmap_tx_lane_cdb[i + link->mlane];
for (j = 0; j < num_regs; j++)
regmap_write(regmap, reg_pairs[j].off,
reg_pairs[j].val);
@@ -2392,7 +2372,7 @@ static int cdns_torrent_phy_init(struct phy *phy)
if (pcs_cmn_vals) {
reg_pairs = pcs_cmn_vals->reg_pairs;
num_regs = pcs_cmn_vals->num_regs;
- regmap = cdns_phy->regmap_phy_pcs_common_cdb;
+ regmap = tp_data->regmap_phy_pcs_common_cdb;
for (i = 0; i < num_regs; i++)
regmap_write(regmap, reg_pairs[i].off,
reg_pairs[i].val);
@@ -2406,7 +2386,7 @@ static int cdns_torrent_phy_init(struct phy *phy)
if (phy_pma_cmn_vals) {
reg_pairs = phy_pma_cmn_vals->reg_pairs;
num_regs = phy_pma_cmn_vals->num_regs;
- regmap = cdns_phy->regmap_phy_pma_common_cdb;
+ regmap = tp_data->regmap_phy_pma_common_cdb;
for (i = 0; i < num_regs; i++)
regmap_write(regmap, reg_pairs[i].off,
reg_pairs[i].val);
@@ -2420,7 +2400,7 @@ static int cdns_torrent_phy_init(struct phy *phy)
if (cmn_vals) {
reg_pairs = cmn_vals->reg_pairs;
num_regs = cmn_vals->num_regs;
- regmap = cdns_phy->regmap_common_cdb;
+ regmap = tp_data->regmap_common_cdb;
for (i = 0; i < num_regs; i++)
regmap_write(regmap, reg_pairs[i].off,
reg_pairs[i].val);
@@ -2434,8 +2414,8 @@ static int cdns_torrent_phy_init(struct phy *phy)
if (tx_ln_vals) {
reg_pairs = tx_ln_vals->reg_pairs;
num_regs = tx_ln_vals->num_regs;
- for (i = 0; i < inst->num_lanes; i++) {
- regmap = cdns_phy->regmap_tx_lane_cdb[i + inst->mlane];
+ for (i = 0; i < link->num_lanes; i++) {
+ regmap = tp_data->regmap_tx_lane_cdb[i + link->mlane];
for (j = 0; j < num_regs; j++)
regmap_write(regmap, reg_pairs[j].off,
reg_pairs[j].val);
@@ -2450,8 +2430,8 @@ static int cdns_torrent_phy_init(struct phy *phy)
if (rx_ln_vals) {
reg_pairs = rx_ln_vals->reg_pairs;
num_regs = rx_ln_vals->num_regs;
- for (i = 0; i < inst->num_lanes; i++) {
- regmap = cdns_phy->regmap_rx_lane_cdb[i + inst->mlane];
+ for (i = 0; i < link->num_lanes; i++) {
+ regmap = tp_data->regmap_rx_lane_cdb[i + link->mlane];
for (j = 0; j < num_regs; j++)
regmap_write(regmap, reg_pairs[j].off,
reg_pairs[j].val);
@@ -2465,33 +2445,33 @@ static int cdns_torrent_phy_init(struct phy *phy)
}
static const struct phy_ops cdns_torrent_phy_ops = {
- .init = cdns_torrent_phy_init,
- .configure = cdns_torrent_dp_configure,
- .power_on = cdns_torrent_phy_on,
- .power_off = cdns_torrent_phy_off,
+ .init = tp_phy_init,
+ .configure = tp_phy_configure,
+ .power_on = tp_phy_on,
+ .power_off = tp_phy_off,
.owner = THIS_MODULE,
};
static
-int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
+int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
{
const struct cdns_torrent_vals *cmn_vals, *tx_ln_vals, *rx_ln_vals;
- const struct cdns_torrent_data *init_data = cdns_phy->init_data;
+ const struct cdns_torrent_data *init_data = tp_data->init_data;
const struct cdns_torrent_vals *link_cmn_vals, *xcvr_diag_vals;
- enum cdns_torrent_ref_clk ref_clk1 = cdns_phy->ref_clk1_rate;
- enum cdns_torrent_ref_clk ref_clk = cdns_phy->ref_clk_rate;
+ enum cdns_torrent_ref_clk ref_clk1 = tp_data->ref_clk1_rate;
+ enum cdns_torrent_ref_clk ref_clk = tp_data->ref_clk_rate;
const struct cdns_torrent_vals *phy_pma_cmn_vals;
const struct cdns_torrent_vals *pcs_cmn_vals;
enum cdns_torrent_phy_type phy_t1, phy_t2;
const struct cdns_reg_pairs *reg_pairs;
int i, j, node, mlane, num_lanes, ret;
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
enum cdns_torrent_ssc_mode ssc;
struct regmap *regmap;
u32 num_regs, num_protocols, protocol;
u32 num_pcie_links = 0;
- num_protocols = hweight32(cdns_phy->protocol_bitmask);
+ num_protocols = hweight32(tp_data->protocol_bitmask);
/* Maximum 2 protocols are supported */
if (num_protocols > 2) {
dev_err(dev, "at most 2 protocols are supported\n");
@@ -2504,9 +2484,9 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
* It is possible for phy_t1 to be the same as phy_t2 for special
* configurations such as PCIe Multilink.
*/
- if (cdns_phy->nsubnodes == 2) {
- phy_t1 = cdns_phy->phys[0].phy_type;
- phy_t2 = cdns_phy->phys[1].phy_type;
+ if (tp_data->nb_links == 2) {
+ phy_t1 = tp_data->links[0].phy_type;
+ phy_t2 = tp_data->links[1].phy_type;
} else {
/**
* Both PHY types / protocols should be unique.
@@ -2520,8 +2500,8 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
return -EINVAL;
}
- phy_t1 = fns(cdns_phy->protocol_bitmask, 0);
- phy_t2 = fns(cdns_phy->protocol_bitmask, 1);
+ phy_t1 = fns(tp_data->protocol_bitmask, 0);
+ phy_t2 = fns(tp_data->protocol_bitmask, 1);
/*
* PCIe Multilink configuration can be supported along with a
@@ -2541,8 +2521,8 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
* phy_t1 and phy_t2 are modified in such cases to support the
* PCIe Multilink configuration with a non-PCIe protocol.
*/
- for (node = 0; node < cdns_phy->nsubnodes; node++) {
- if (cdns_phy->phys[node].phy_type == TYPE_PCIE)
+ for (node = 0; node < tp_data->nb_links; node++) {
+ if (tp_data->links[node].phy_type == TYPE_PCIE)
num_pcie_links++;
}
@@ -2552,12 +2532,12 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
return -EINVAL;
} else if (num_pcie_links == 2) {
phy_t1 = TYPE_PCIE_ML;
- for (node = 0; node < cdns_phy->nsubnodes; node++) {
- if (cdns_phy->phys[node].phy_type == TYPE_PCIE) {
- cdns_phy->phys[node].phy_type = TYPE_PCIE_ML;
+ for (node = 0; node < tp_data->nb_links; node++) {
+ if (tp_data->links[node].phy_type == TYPE_PCIE) {
+ tp_data->links[node].phy_type = TYPE_PCIE_ML;
continue;
}
- phy_t2 = cdns_phy->phys[node].phy_type;
+ phy_t2 = tp_data->links[node].phy_type;
}
}
}
@@ -2594,13 +2574,13 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
swap(ref_clk, ref_clk1);
}
- for (node = 0; node < cdns_phy->nsubnodes; node++) {
- if (cdns_phy->phys[node].phy_type != phy_t1)
+ for (node = 0; node < tp_data->nb_links; node++) {
+ if (tp_data->links[node].phy_type != phy_t1)
continue;
- mlane = cdns_phy->phys[node].mlane;
- ssc = cdns_phy->phys[node].ssc_mode;
- num_lanes = cdns_phy->phys[node].num_lanes;
+ mlane = tp_data->links[node].mlane;
+ ssc = tp_data->links[node].ssc_mode;
+ num_lanes = tp_data->links[node].num_lanes;
/**
* PHY configuration specific registers:
@@ -2618,13 +2598,13 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
if (link_cmn_vals) {
reg_pairs = link_cmn_vals->reg_pairs;
num_regs = link_cmn_vals->num_regs;
- regmap = cdns_phy->regmap_common_cdb;
+ regmap = tp_data->regmap_common_cdb;
/**
* First array value in link_cmn_vals must be of
* PHY_PLL_CFG register
*/
- regmap_field_write(cdns_phy->phy_pll_cfg,
+ regmap_field_write(tp_data->phy_pll_cfg,
reg_pairs[0].val);
for (i = 1; i < num_regs; i++)
@@ -2639,7 +2619,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
reg_pairs = xcvr_diag_vals->reg_pairs;
num_regs = xcvr_diag_vals->num_regs;
for (i = 0; i < num_lanes; i++) {
- regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane];
+ regmap = tp_data->regmap_tx_lane_cdb[i + mlane];
for (j = 0; j < num_regs; j++)
regmap_write(regmap, reg_pairs[j].off,
reg_pairs[j].val);
@@ -2653,7 +2633,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
if (pcs_cmn_vals) {
reg_pairs = pcs_cmn_vals->reg_pairs;
num_regs = pcs_cmn_vals->num_regs;
- regmap = cdns_phy->regmap_phy_pcs_common_cdb;
+ regmap = tp_data->regmap_phy_pcs_common_cdb;
for (i = 0; i < num_regs; i++)
regmap_write(regmap, reg_pairs[i].off,
reg_pairs[i].val);
@@ -2667,7 +2647,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
if (phy_pma_cmn_vals) {
reg_pairs = phy_pma_cmn_vals->reg_pairs;
num_regs = phy_pma_cmn_vals->num_regs;
- regmap = cdns_phy->regmap_phy_pma_common_cdb;
+ regmap = tp_data->regmap_phy_pma_common_cdb;
for (i = 0; i < num_regs; i++)
regmap_write(regmap, reg_pairs[i].off,
reg_pairs[i].val);
@@ -2680,7 +2660,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
if (cmn_vals) {
reg_pairs = cmn_vals->reg_pairs;
num_regs = cmn_vals->num_regs;
- regmap = cdns_phy->regmap_common_cdb;
+ regmap = tp_data->regmap_common_cdb;
for (i = 0; i < num_regs; i++)
regmap_write(regmap, reg_pairs[i].off,
reg_pairs[i].val);
@@ -2694,7 +2674,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
reg_pairs = tx_ln_vals->reg_pairs;
num_regs = tx_ln_vals->num_regs;
for (i = 0; i < num_lanes; i++) {
- regmap = cdns_phy->regmap_tx_lane_cdb[i + mlane];
+ regmap = tp_data->regmap_tx_lane_cdb[i + mlane];
for (j = 0; j < num_regs; j++)
regmap_write(regmap, reg_pairs[j].off,
reg_pairs[j].val);
@@ -2709,7 +2689,7 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
reg_pairs = rx_ln_vals->reg_pairs;
num_regs = rx_ln_vals->num_regs;
for (i = 0; i < num_lanes; i++) {
- regmap = cdns_phy->regmap_rx_lane_cdb[i + mlane];
+ regmap = tp_data->regmap_rx_lane_cdb[i + mlane];
for (j = 0; j < num_regs; j++)
regmap_write(regmap, reg_pairs[j].off,
reg_pairs[j].val);
@@ -2717,38 +2697,38 @@ int cdns_torrent_phy_configure_multilink(struct cdns_torrent_phy *cdns_phy)
}
if (phy_t1 == TYPE_DP) {
- ret = cdns_torrent_dp_get_pll(cdns_phy, phy_t2);
+ ret = cdns_torrent_dp_get_pll(tp_data, phy_t2);
if (ret)
return ret;
}
- reset_control_deassert(cdns_phy->phys[node].lnk_rst);
+ reset_control_deassert(tp_data->links[node].lnk_rst);
}
}
/* Restore TYPE_PCIE_ML to TYPE_PCIE to be compatible with suspend-resume */
- for (node = 0; node < cdns_phy->nsubnodes; node++)
- if (cdns_phy->phys[node].phy_type == TYPE_PCIE_ML)
- cdns_phy->phys[node].phy_type = TYPE_PCIE;
+ for (node = 0; node < tp_data->nb_links; node++)
+ if (tp_data->links[node].phy_type == TYPE_PCIE_ML)
+ tp_data->links[node].phy_type = TYPE_PCIE;
/* Take the PHY out of reset */
- ret = reset_control_deassert(cdns_phy->phy_rst);
+ ret = reset_control_deassert(tp_data->phy_rst);
if (ret)
return ret;
return 0;
}
-static void cdns_torrent_clk_cleanup(struct cdns_torrent_phy *cdns_phy)
+static void cdns_torrent_clk_cleanup(struct tp_data *tp_data)
{
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
of_clk_del_provider(dev->of_node);
}
-static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy)
+static int tp_clk_register(struct tp_data *tp_data)
{
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
struct device_node *node = dev->of_node;
struct clk_hw_onecell_data *data;
int ret;
@@ -2758,21 +2738,21 @@ static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy)
return -ENOMEM;
data->num = CDNS_TORRENT_OUTPUT_CLOCKS;
- cdns_phy->clk_hw_data = data;
+ tp_data->clk_hw_data = data;
- ret = cdns_torrent_derived_refclk_register(cdns_phy);
+ ret = tp_derived_refclk_register(tp_data);
if (ret) {
dev_err(dev, "failed to register derived refclk\n");
return ret;
}
- ret = cdns_torrent_received_refclk_register(cdns_phy);
+ ret = tp_received_refclk_register(tp_data);
if (ret) {
dev_err(dev, "failed to register received refclk\n");
return ret;
}
- ret = cdns_torrent_refclk_driver_register(cdns_phy);
+ ret = tp_refclk_driver_register(tp_data);
if (ret) {
dev_err(dev, "failed to register refclk driver\n");
return ret;
@@ -2787,130 +2767,130 @@ static int cdns_torrent_clk_register(struct cdns_torrent_phy *cdns_phy)
return 0;
}
-static int cdns_torrent_of_get_reset(struct cdns_torrent_phy *cdns_phy)
+static int tp_of_get_reset(struct tp_data *tp_data)
{
- struct device *dev = cdns_phy->dev;
+ struct device *dev = tp_data->dev;
- cdns_phy->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0);
- if (IS_ERR(cdns_phy->phy_rst)) {
+ tp_data->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0);
+ if (IS_ERR(tp_data->phy_rst)) {
dev_err(dev, "%s: failed to get reset\n",
dev->of_node->full_name);
- return PTR_ERR(cdns_phy->phy_rst);
+ return PTR_ERR(tp_data->phy_rst);
}
- cdns_phy->apb_rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb");
- if (IS_ERR(cdns_phy->apb_rst)) {
+ tp_data->apb_rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb");
+ if (IS_ERR(tp_data->apb_rst)) {
dev_err(dev, "%s: failed to get apb reset\n",
dev->of_node->full_name);
- return PTR_ERR(cdns_phy->apb_rst);
+ return PTR_ERR(tp_data->apb_rst);
}
return 0;
}
-static int cdns_torrent_of_get_clk(struct cdns_torrent_phy *cdns_phy)
+static int tp_of_get_clk(struct tp_data *tp_data)
{
/* refclk: Input reference clock for PLL0 */
- cdns_phy->clk = devm_clk_get(cdns_phy->dev, "refclk");
- if (IS_ERR(cdns_phy->clk))
- return dev_err_probe(cdns_phy->dev, PTR_ERR(cdns_phy->clk),
+ tp_data->clk = devm_clk_get(tp_data->dev, "refclk");
+ if (IS_ERR(tp_data->clk))
+ return dev_err_probe(tp_data->dev, PTR_ERR(tp_data->clk),
"phy ref clock not found\n");
/* refclk1: Input reference clock for PLL1 */
- cdns_phy->clk1 = devm_clk_get_optional(cdns_phy->dev, "pll1_refclk");
- if (IS_ERR(cdns_phy->clk1))
- return dev_err_probe(cdns_phy->dev, PTR_ERR(cdns_phy->clk1),
+ tp_data->clk1 = devm_clk_get_optional(tp_data->dev, "pll1_refclk");
+ if (IS_ERR(tp_data->clk1))
+ return dev_err_probe(tp_data->dev, PTR_ERR(tp_data->clk1),
"phy PLL1 ref clock not found\n");
return 0;
}
-static int cdns_torrent_clk(struct cdns_torrent_phy *cdns_phy)
+static int cdns_torrent_clk(struct tp_data *tp_data)
{
unsigned long ref_clk1_rate;
unsigned long ref_clk_rate;
int ret;
- ret = clk_prepare_enable(cdns_phy->clk);
+ ret = clk_prepare_enable(tp_data->clk);
if (ret) {
- dev_err(cdns_phy->dev, "Failed to prepare ref clock: %d\n", ret);
+ dev_err(tp_data->dev, "Failed to prepare ref clock: %d\n", ret);
return ret;
}
- ref_clk_rate = clk_get_rate(cdns_phy->clk);
+ ref_clk_rate = clk_get_rate(tp_data->clk);
if (!ref_clk_rate) {
- dev_err(cdns_phy->dev, "Failed to get ref clock rate\n");
+ dev_err(tp_data->dev, "Failed to get ref clock rate\n");
ret = -EINVAL;
goto disable_clk;
}
switch (ref_clk_rate) {
case REF_CLK_19_2MHZ:
- cdns_phy->ref_clk_rate = CLK_19_2_MHZ;
+ tp_data->ref_clk_rate = CLK_19_2_MHZ;
break;
case REF_CLK_25MHZ:
- cdns_phy->ref_clk_rate = CLK_25_MHZ;
+ tp_data->ref_clk_rate = CLK_25_MHZ;
break;
case REF_CLK_100MHZ:
- cdns_phy->ref_clk_rate = CLK_100_MHZ;
+ tp_data->ref_clk_rate = CLK_100_MHZ;
break;
case REF_CLK_156_25MHZ:
- cdns_phy->ref_clk_rate = CLK_156_25_MHZ;
+ tp_data->ref_clk_rate = CLK_156_25_MHZ;
break;
default:
- dev_err(cdns_phy->dev, "Invalid ref clock rate\n");
+ dev_err(tp_data->dev, "Invalid ref clock rate\n");
ret = -EINVAL;
goto disable_clk;
}
- if (cdns_phy->clk1) {
- ret = clk_prepare_enable(cdns_phy->clk1);
+ if (tp_data->clk1) {
+ ret = clk_prepare_enable(tp_data->clk1);
if (ret) {
- dev_err(cdns_phy->dev, "Failed to prepare PLL1 ref clock: %d\n", ret);
+ dev_err(tp_data->dev, "Failed to prepare PLL1 ref clock: %d\n", ret);
goto disable_clk;
}
- ref_clk1_rate = clk_get_rate(cdns_phy->clk1);
+ ref_clk1_rate = clk_get_rate(tp_data->clk1);
if (!ref_clk1_rate) {
- dev_err(cdns_phy->dev, "Failed to get PLL1 ref clock rate\n");
+ dev_err(tp_data->dev, "Failed to get PLL1 ref clock rate\n");
ret = -EINVAL;
goto disable_clk1;
}
switch (ref_clk1_rate) {
case REF_CLK_19_2MHZ:
- cdns_phy->ref_clk1_rate = CLK_19_2_MHZ;
+ tp_data->ref_clk1_rate = CLK_19_2_MHZ;
break;
case REF_CLK_25MHZ:
- cdns_phy->ref_clk1_rate = CLK_25_MHZ;
+ tp_data->ref_clk1_rate = CLK_25_MHZ;
break;
case REF_CLK_100MHZ:
- cdns_phy->ref_clk1_rate = CLK_100_MHZ;
+ tp_data->ref_clk1_rate = CLK_100_MHZ;
break;
case REF_CLK_156_25MHZ:
- cdns_phy->ref_clk1_rate = CLK_156_25_MHZ;
+ tp_data->ref_clk1_rate = CLK_156_25_MHZ;
break;
default:
- dev_err(cdns_phy->dev, "Invalid PLL1 ref clock rate\n");
+ dev_err(tp_data->dev, "Invalid PLL1 ref clock rate\n");
ret = -EINVAL;
goto disable_clk1;
}
} else {
- cdns_phy->ref_clk1_rate = cdns_phy->ref_clk_rate;
+ tp_data->ref_clk1_rate = tp_data->ref_clk_rate;
}
return 0;
disable_clk1:
- clk_disable_unprepare(cdns_phy->clk1);
+ clk_disable_unprepare(tp_data->clk1);
disable_clk:
- clk_disable_unprepare(cdns_phy->clk);
+ clk_disable_unprepare(tp_data->clk);
return ret;
}
static int cdns_torrent_phy_probe(struct platform_device *pdev)
{
- struct cdns_torrent_phy *cdns_phy;
+ struct tp_data *tp_data;
struct device *dev = &pdev->dev;
struct phy_provider *phy_provider;
const struct cdns_torrent_data *data;
@@ -2925,18 +2905,18 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
if (!data)
return -EINVAL;
- cdns_phy = devm_kzalloc_obj(dev, *cdns_phy);
- if (!cdns_phy)
+ tp_data = devm_kzalloc_obj(dev, *tp_data);
+ if (!tp_data)
return -ENOMEM;
- dev_set_drvdata(dev, cdns_phy);
- cdns_phy->dev = dev;
- cdns_phy->init_data = data;
- cdns_phy->protocol_bitmask = 0;
+ dev_set_drvdata(dev, tp_data);
+ tp_data->dev = dev;
+ tp_data->init_data = data;
+ tp_data->protocol_bitmask = 0;
- cdns_phy->sd_base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(cdns_phy->sd_base))
- return PTR_ERR(cdns_phy->sd_base);
+ tp_data->sd_base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(tp_data->sd_base))
+ return PTR_ERR(tp_data->sd_base);
subnodes = of_get_available_child_count(dev->of_node);
if (subnodes == 0) {
@@ -2944,35 +2924,35 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
return -EINVAL;
}
- ret = cdns_torrent_regmap_init(cdns_phy);
+ ret = cdns_torrent_regmap_init(tp_data);
if (ret)
return ret;
- ret = cdns_torrent_regfield_init(cdns_phy);
+ ret = cdns_torrent_regfield_init(tp_data);
if (ret)
return ret;
- ret = cdns_torrent_clk_register(cdns_phy);
+ ret = tp_clk_register(tp_data);
if (ret)
return ret;
- ret = cdns_torrent_of_get_reset(cdns_phy);
+ ret = tp_of_get_reset(tp_data);
if (ret)
goto clk_cleanup;
- ret = cdns_torrent_of_get_clk(cdns_phy);
+ ret = tp_of_get_clk(tp_data);
if (ret)
goto clk_cleanup;
- regmap_field_read(cdns_phy->phy_pma_cmn_ctrl_1, &cdns_phy->already_configured);
+ regmap_field_read(tp_data->phy_pma_cmn_ctrl_1, &tp_data->already_configured);
- if (!cdns_phy->already_configured) {
- ret = cdns_torrent_clk(cdns_phy);
+ if (!tp_data->already_configured) {
+ ret = cdns_torrent_clk(tp_data);
if (ret)
goto clk_cleanup;
/* Enable APB */
- reset_control_deassert(cdns_phy->apb_rst);
+ reset_control_deassert(tp_data->apb_rst);
}
for_each_available_child_of_node(dev->of_node, child) {
@@ -2982,17 +2962,17 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
if (!(of_node_name_eq(child, "phy")))
continue;
- cdns_phy->phys[node].lnk_rst =
+ tp_data->links[node].lnk_rst =
of_reset_control_array_get_exclusive(child);
- if (IS_ERR(cdns_phy->phys[node].lnk_rst)) {
+ if (IS_ERR(tp_data->links[node].lnk_rst)) {
dev_err(dev, "%s: failed to get reset\n",
child->full_name);
- ret = PTR_ERR(cdns_phy->phys[node].lnk_rst);
+ ret = PTR_ERR(tp_data->links[node].lnk_rst);
goto put_lnk_rst;
}
if (of_property_read_u32(child, "reg",
- &cdns_phy->phys[node].mlane)) {
+ &tp_data->links[node].mlane)) {
dev_err(dev, "%s: No \"reg\"-property.\n",
child->full_name);
ret = -EINVAL;
@@ -3008,25 +2988,25 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
switch (phy_type) {
case PHY_TYPE_PCIE:
- cdns_phy->phys[node].phy_type = TYPE_PCIE;
+ tp_data->links[node].phy_type = TYPE_PCIE;
break;
case PHY_TYPE_DP:
- cdns_phy->phys[node].phy_type = TYPE_DP;
+ tp_data->links[node].phy_type = TYPE_DP;
break;
case PHY_TYPE_SGMII:
- cdns_phy->phys[node].phy_type = TYPE_SGMII;
+ tp_data->links[node].phy_type = TYPE_SGMII;
break;
case PHY_TYPE_QSGMII:
- cdns_phy->phys[node].phy_type = TYPE_QSGMII;
+ tp_data->links[node].phy_type = TYPE_QSGMII;
break;
case PHY_TYPE_USB3:
- cdns_phy->phys[node].phy_type = TYPE_USB;
+ tp_data->links[node].phy_type = TYPE_USB;
break;
case PHY_TYPE_USXGMII:
- cdns_phy->phys[node].phy_type = TYPE_USXGMII;
+ tp_data->links[node].phy_type = TYPE_USXGMII;
break;
case PHY_TYPE_XAUI:
- cdns_phy->phys[node].phy_type = TYPE_XAUI;
+ tp_data->links[node].phy_type = TYPE_XAUI;
break;
default:
dev_err(dev, "Unsupported protocol\n");
@@ -3034,15 +3014,15 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_child;
}
- cdns_phy->phys[node].num_lanes = DEFAULT_NUM_LANES;
- of_property_read_u32(child, "cdns,num-lanes", &cdns_phy->phys[node].num_lanes);
+ tp_data->links[node].num_lanes = DEFAULT_NUM_LANES;
+ of_property_read_u32(child, "cdns,num-lanes", &tp_data->links[node].num_lanes);
- total_num_lanes += cdns_phy->phys[node].num_lanes;
+ total_num_lanes += tp_data->links[node].num_lanes;
/* Get SSC mode */
- cdns_phy->phys[node].ssc_mode = NO_SSC;
+ tp_data->links[node].ssc_mode = NO_SSC;
of_property_read_u32(child, "cdns,ssc-mode",
- &cdns_phy->phys[node].ssc_mode);
+ &tp_data->links[node].ssc_mode);
gphy = devm_phy_create(dev, child, &cdns_torrent_phy_ops);
if (IS_ERR(gphy)) {
@@ -3050,8 +3030,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_child;
}
- if (cdns_phy->phys[node].phy_type == TYPE_DP) {
- switch (cdns_phy->phys[node].num_lanes) {
+ if (tp_data->links[node].phy_type == TYPE_DP) {
+ switch (tp_data->links[node].num_lanes) {
case 1:
case 2:
case 4:
@@ -3059,16 +3039,16 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
break;
default:
dev_err(dev, "unsupported number of lanes: %d\n",
- cdns_phy->phys[node].num_lanes);
+ tp_data->links[node].num_lanes);
ret = -EINVAL;
goto put_child;
}
- cdns_phy->max_bit_rate = DEFAULT_MAX_BIT_RATE;
+ tp_data->max_bit_rate = DEFAULT_MAX_BIT_RATE;
of_property_read_u32(child, "cdns,max-bit-rate",
- &cdns_phy->max_bit_rate);
+ &tp_data->max_bit_rate);
- switch (cdns_phy->max_bit_rate) {
+ switch (tp_data->max_bit_rate) {
case 1620:
case 2160:
case 2430:
@@ -3081,24 +3061,24 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
break;
default:
dev_err(dev, "unsupported max bit rate: %dMbps\n",
- cdns_phy->max_bit_rate);
+ tp_data->max_bit_rate);
ret = -EINVAL;
goto put_child;
}
/* DPTX registers */
- cdns_phy->base = devm_platform_ioremap_resource(pdev, 1);
- if (IS_ERR(cdns_phy->base)) {
- ret = PTR_ERR(cdns_phy->base);
+ tp_data->base = devm_platform_ioremap_resource(pdev, 1);
+ if (IS_ERR(tp_data->base)) {
+ ret = PTR_ERR(tp_data->base);
goto put_child;
}
if (!init_dp_regmap) {
- ret = cdns_torrent_dp_regmap_init(cdns_phy);
+ ret = cdns_torrent_dp_regmap_init(tp_data);
if (ret)
goto put_child;
- ret = cdns_torrent_dp_regfield_init(cdns_phy);
+ ret = cdns_torrent_dp_regfield_init(tp_data);
if (ret)
goto put_child;
@@ -3106,21 +3086,21 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
}
dev_dbg(dev, "DP max bit rate %d.%03d Gbps\n",
- cdns_phy->max_bit_rate / 1000,
- cdns_phy->max_bit_rate % 1000);
+ tp_data->max_bit_rate / 1000,
+ tp_data->max_bit_rate % 1000);
- gphy->attrs.bus_width = cdns_phy->phys[node].num_lanes;
- gphy->attrs.max_link_rate = cdns_phy->max_bit_rate;
+ gphy->attrs.bus_width = tp_data->links[node].num_lanes;
+ gphy->attrs.max_link_rate = tp_data->max_bit_rate;
gphy->attrs.mode = PHY_MODE_DP;
}
- cdns_phy->phys[node].phy = gphy;
- cdns_phy->protocol_bitmask |= BIT(cdns_phy->phys[node].phy_type);
- phy_set_drvdata(gphy, &cdns_phy->phys[node]);
+ tp_data->links[node].phy = gphy;
+ tp_data->protocol_bitmask |= BIT(tp_data->links[node].phy_type);
+ phy_set_drvdata(gphy, &tp_data->links[node]);
node++;
}
- cdns_phy->nsubnodes = node;
+ tp_data->nb_links = node;
if (total_num_lanes > MAX_NUM_LANES) {
dev_err(dev, "Invalid lane configuration\n");
@@ -3128,8 +3108,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_lnk_rst;
}
- if (cdns_phy->nsubnodes > 1 && !cdns_phy->already_configured) {
- ret = cdns_torrent_phy_configure_multilink(cdns_phy);
+ if (tp_data->nb_links > 1 && !tp_data->already_configured) {
+ ret = cdns_torrent_phy_configure_multilink(tp_data);
if (ret)
goto put_lnk_rst;
}
@@ -3140,15 +3120,15 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_lnk_rst;
}
- if (cdns_phy->nsubnodes > 1)
+ if (tp_data->nb_links > 1)
dev_dbg(dev, "Multi link configuration:\n");
else
dev_dbg(dev, "Single link configuration:\n");
- for (i = 0; i < cdns_phy->nsubnodes; i++)
+ for (i = 0; i < tp_data->nb_links; i++)
dev_dbg(dev, "%s (%d lanes)",
- cdns_torrent_get_phy_type(cdns_phy->phys[i].phy_type),
- cdns_phy->phys[i].num_lanes);
+ cdns_torrent_get_phy_type(tp_data->links[i].phy_type),
+ tp_data->links[i].num_lanes);
return 0;
@@ -3156,31 +3136,31 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
node++;
put_lnk_rst:
for (i = 0; i < node; i++)
- reset_control_put(cdns_phy->phys[i].lnk_rst);
+ reset_control_put(tp_data->links[i].lnk_rst);
of_node_put(child);
- reset_control_assert(cdns_phy->apb_rst);
- clk_disable_unprepare(cdns_phy->clk1);
- clk_disable_unprepare(cdns_phy->clk);
+ reset_control_assert(tp_data->apb_rst);
+ clk_disable_unprepare(tp_data->clk1);
+ clk_disable_unprepare(tp_data->clk);
clk_cleanup:
- cdns_torrent_clk_cleanup(cdns_phy);
+ cdns_torrent_clk_cleanup(tp_data);
return ret;
}
static void cdns_torrent_phy_remove(struct platform_device *pdev)
{
- struct cdns_torrent_phy *cdns_phy = platform_get_drvdata(pdev);
+ struct tp_data *tp_data = platform_get_drvdata(pdev);
int i;
- reset_control_assert(cdns_phy->phy_rst);
- reset_control_assert(cdns_phy->apb_rst);
- for (i = 0; i < cdns_phy->nsubnodes; i++) {
- reset_control_assert(cdns_phy->phys[i].lnk_rst);
- reset_control_put(cdns_phy->phys[i].lnk_rst);
+ reset_control_assert(tp_data->phy_rst);
+ reset_control_assert(tp_data->apb_rst);
+ for (i = 0; i < tp_data->nb_links; i++) {
+ reset_control_assert(tp_data->links[i].lnk_rst);
+ reset_control_put(tp_data->links[i].lnk_rst);
}
- clk_disable_unprepare(cdns_phy->clk1);
- clk_disable_unprepare(cdns_phy->clk);
- cdns_torrent_clk_cleanup(cdns_phy);
+ clk_disable_unprepare(tp_data->clk1);
+ clk_disable_unprepare(tp_data->clk);
+ cdns_torrent_clk_cleanup(tp_data);
}
/* Multilink PCIe and USB Same SSC link configuration */
@@ -3329,63 +3309,63 @@ static const struct cdns_torrent_vals sgmii_qsgmii_xcvr_diag_ln_vals = {
.num_regs = ARRAY_SIZE(sgmii_qsgmii_xcvr_diag_ln_regs),
};
-static void cdns_torrent_refclk_driver_suspend(struct cdns_torrent_phy *cdns_phy)
+static void tp_refclk_driver_suspend(struct tp_data *tp_data)
{
- struct clk_hw *hw = cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER];
- struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw);
+ struct clk_hw *hw = tp_data->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER];
+ struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
- refclk_driver->parent_index = cdns_torrent_refclk_driver_get_parent(hw);
+ refclk_driver->parent_index = tp_refclk_driver_get_parent(hw);
}
-static int cdns_torrent_refclk_driver_resume(struct cdns_torrent_phy *cdns_phy)
+static int tp_refclk_driver_resume(struct tp_data *tp_data)
{
- struct clk_hw *hw = cdns_phy->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER];
- struct cdns_torrent_refclk_driver *refclk_driver = to_cdns_torrent_refclk_driver(hw);
+ struct clk_hw *hw = tp_data->clk_hw_data->hws[CDNS_TORRENT_REFCLK_DRIVER];
+ struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
- return cdns_torrent_refclk_driver_set_parent(hw, refclk_driver->parent_index);
+ return tp_refclk_driver_set_parent(hw, refclk_driver->parent_index);
}
-static int cdns_torrent_phy_suspend_noirq(struct device *dev)
+static int tp_suspend_noirq(struct device *dev)
{
- struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(dev);
+ struct tp_data *tp_data = dev_get_drvdata(dev);
int i;
- cdns_torrent_refclk_driver_suspend(cdns_phy);
+ tp_refclk_driver_suspend(tp_data);
- reset_control_assert(cdns_phy->phy_rst);
- reset_control_assert(cdns_phy->apb_rst);
- for (i = 0; i < cdns_phy->nsubnodes; i++)
- reset_control_assert(cdns_phy->phys[i].lnk_rst);
+ reset_control_assert(tp_data->phy_rst);
+ reset_control_assert(tp_data->apb_rst);
+ for (i = 0; i < tp_data->nb_links; i++)
+ reset_control_assert(tp_data->links[i].lnk_rst);
- if (cdns_phy->already_configured)
- cdns_phy->already_configured = 0;
+ if (tp_data->already_configured)
+ tp_data->already_configured = 0;
else {
- clk_disable_unprepare(cdns_phy->clk1);
- clk_disable_unprepare(cdns_phy->clk);
+ clk_disable_unprepare(tp_data->clk1);
+ clk_disable_unprepare(tp_data->clk);
}
return 0;
}
-static int cdns_torrent_phy_resume_noirq(struct device *dev)
+static int tp_resume_noirq(struct device *dev)
{
- struct cdns_torrent_phy *cdns_phy = dev_get_drvdata(dev);
- int node = cdns_phy->nsubnodes;
+ struct tp_data *tp_data = dev_get_drvdata(dev);
+ int node = tp_data->nb_links;
int ret, i;
- ret = cdns_torrent_refclk_driver_resume(cdns_phy);
+ ret = tp_refclk_driver_resume(tp_data);
if (ret)
return ret;
- ret = cdns_torrent_clk(cdns_phy);
+ ret = cdns_torrent_clk(tp_data);
if (ret)
return ret;
/* Enable APB */
- reset_control_deassert(cdns_phy->apb_rst);
+ reset_control_deassert(tp_data->apb_rst);
- if (cdns_phy->nsubnodes > 1) {
- ret = cdns_torrent_phy_configure_multilink(cdns_phy);
+ if (tp_data->nb_links > 1) {
+ ret = cdns_torrent_phy_configure_multilink(tp_data);
if (ret)
goto put_lnk_rst;
}
@@ -3394,18 +3374,17 @@ static int cdns_torrent_phy_resume_noirq(struct device *dev)
put_lnk_rst:
for (i = 0; i < node; i++)
- reset_control_assert(cdns_phy->phys[i].lnk_rst);
- reset_control_assert(cdns_phy->apb_rst);
+ reset_control_assert(tp_data->links[i].lnk_rst);
+ reset_control_assert(tp_data->apb_rst);
- clk_disable_unprepare(cdns_phy->clk1);
- clk_disable_unprepare(cdns_phy->clk);
+ clk_disable_unprepare(tp_data->clk1);
+ clk_disable_unprepare(tp_data->clk);
return ret;
}
static DEFINE_NOIRQ_DEV_PM_OPS(cdns_torrent_phy_pm_ops,
- cdns_torrent_phy_suspend_noirq,
- cdns_torrent_phy_resume_noirq);
+ tp_suspend_noirq, tp_resume_noirq);
/* PCIe and XAUI link configuration */
static const struct cdns_reg_pairs pcie_xaui_link_cmn_regs[] = {
--
2.56.1
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 28+ messages in thread* [PATCH v2 08/22] phy: cadence-torrent: replace regmap with readw/writew
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (5 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 07/22] phy: cadence-torrent: rename symbols to prepare for rewrite Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 09/22] phy: cadence-torrent: move refclk clk_init_data to the stack Benjamin Robin
` (12 subsequent siblings)
19 siblings, 0 replies; 28+ 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
Drop the regmap and regmap_field abstractions in favour of direct
memory-mapped access to the PHY registers. The 16-bit CDB register
blocks and the 32-bit DisplayPort PHY registers are all placed at fixed
offsets (initialized from compatible configuration), so the regmap layer,
its configuration tables and the custom read/write callbacks only add
unnecessary indirection.
Introduce two helpers to describe the register map:
- struct tp_reg_base, describing a register block (its __iomem base,
the register-offset shift and the block offset), used for whole
register accesses;
- struct tp_reg_field, describing a single register bit-field (its
address and mask), used for the read-modify-write field accesses.
Add the matching low-level helpers tp_reg_read()/tp_reg_write(),
tp_reg_set_bits()/tp_reg_clear_bits(), tp_reg_field_read()/
tp_reg_field_write() and tp_reg_dptx_read()/tp_reg_dptx_write(), which
use readl()/writel() for the 32-bit DisplayPort registers. Regmap-based
polling (regmap_field_read_poll_timeout) is replaced by
readl_poll_timeout().
Each access is traced with dev_dbg to aid validation of the driver.
Set up the blocks and fields in tp_reg_bases_init() and
tp_reg_fields_init(), replacing the previous devm_regmap_* and
regmap_field_alloc() calls. The refclk clock structures are now embedded
in struct tp_data, removing the need to allocate regmap structures.
No functional change intended.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 1355 +++++++++++------------------
1 file changed, 513 insertions(+), 842 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index f7ec31a4c417..2bdc63caec1e 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -20,7 +20,6 @@
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
#include <linux/reset.h>
-#include <linux/regmap.h>
#define REF_CLK_19_2MHZ 19200000
#define REF_CLK_25MHZ 25000000
@@ -238,6 +237,20 @@
#define PHY_PMA_CMN_CTRL2 0x0001U
#define PHY_PMA_PLL_RAW_CTRL 0x0003U
+struct tp_reg_base {
+ void __iomem *base;
+ u8 reg_offset_shift;
+ u32 block_off;
+ struct device *dev;
+};
+
+struct tp_reg_field {
+ void __iomem *reg_addr;
+ u16 mask;
+ u32 reg_off;
+ struct device *dev;
+};
+
#define CDNS_TORRENT_OUTPUT_CLOCKS 3
static const char *const tp_clk_names[] = {
@@ -246,29 +259,6 @@ static const char *const tp_clk_names[] = {
[CDNS_TORRENT_RECEIVED_REFCLK] = "refclk-rec",
};
-static const struct reg_field phy_pll_cfg =
- REG_FIELD(PHY_PLL_CFG, 0, 1);
-
-static const struct reg_field phy_pma_cmn_ctrl_1 =
- REG_FIELD(PHY_PMA_CMN_CTRL1, 0, 0);
-
-static const struct reg_field phy_pma_cmn_ctrl_2 =
- REG_FIELD(PHY_PMA_CMN_CTRL2, 0, 7);
-
-static const struct reg_field phy_pma_pll_raw_ctrl =
- REG_FIELD(PHY_PMA_PLL_RAW_CTRL, 0, 1);
-
-static const struct reg_field phy_reset_ctrl =
- REG_FIELD(PHY_RESET, 8, 8);
-
-static const struct reg_field phy_pcs_iso_link_ctrl_1 =
- REG_FIELD(PHY_PCS_ISO_LINK_CTRL, 1, 1);
-
-static const struct reg_field phy_pipe_cmn_ctrl1_0 = REG_FIELD(PHY_PIPE_CMN_CTRL1, 0, 0);
-
-static const struct reg_field cmn_cdiag_refclk_ovrd_4 =
- REG_FIELD(CMN_CDIAG_REFCLK_OVRD, 4, 4);
-
enum tp_refclk_out_cmn {
CMN_CDIAG_REFCLK_DRV0_CTRL_1,
CMN_CDIAG_REFCLK_DRV0_CTRL_4,
@@ -277,13 +267,6 @@ enum tp_refclk_out_cmn {
TP_REFCLK_OUT_NUM_CMN_CONFIG
};
-static const struct reg_field refclk_out_cmn_cfg[] = {
- [CMN_CDIAG_REFCLK_DRV0_CTRL_1] = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 1, 1),
- [CMN_CDIAG_REFCLK_DRV0_CTRL_4] = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 4, 4),
- [CMN_CDIAG_REFCLK_DRV0_CTRL_5] = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 5, 5),
- [CMN_CDIAG_REFCLK_DRV0_CTRL_6] = REG_FIELD(CMN_CDIAG_REFCLK_DRV0_CTRL, 6, 6),
-};
-
static const int tp_refclk_driver_parent_idx[] = {
CDNS_TORRENT_DERIVED_REFCLK, CDNS_TORRENT_RECEIVED_REFCLK
};
@@ -292,7 +275,7 @@ static const u32 tp_refclk_driver_mux_table[] = { 1, 0 };
struct tp_refclk_driver {
struct clk_hw hw;
- struct regmap_field *cmn_fields[TP_REFCLK_OUT_NUM_CMN_CONFIG];
+ struct tp_reg_field fields[TP_REFCLK_OUT_NUM_CMN_CONFIG];
struct clk_init_data clk_data;
u8 parent_index;
};
@@ -302,8 +285,8 @@ struct tp_refclk_driver {
struct cdns_torrent_derived_refclk {
struct clk_hw hw;
- struct regmap_field *phy_pipe_cmn_ctrl1_0;
- struct regmap_field *cmn_cdiag_refclk_ovrd_4;
+ struct tp_reg_field *phy_pipe_cmn_ctrl1_0;
+ struct tp_reg_field *cmn_cdiag_refclk_ovrd_4;
struct clk_init_data clk_data;
};
@@ -312,8 +295,8 @@ struct cdns_torrent_derived_refclk {
struct cdns_torrent_received_refclk {
struct clk_hw hw;
- struct regmap_field *phy_pipe_cmn_ctrl1_0;
- struct regmap_field *cmn_cdiag_refclk_ovrd_4;
+ struct tp_reg_field *phy_pipe_cmn_ctrl1_0;
+ struct tp_reg_field *cmn_cdiag_refclk_ovrd_4;
struct clk_init_data clk_data;
};
@@ -398,22 +381,21 @@ struct tp_data {
int nb_links;
int already_configured;
const struct cdns_torrent_data *init_data;
- struct regmap *regmap_common_cdb;
- struct regmap *regmap_phy_pcs_common_cdb;
- struct regmap *regmap_phy_pma_common_cdb;
- struct regmap *regmap_tx_lane_cdb[MAX_NUM_LANES];
- struct regmap *regmap_rx_lane_cdb[MAX_NUM_LANES];
- struct regmap *regmap_phy_pcs_lane_cdb[MAX_NUM_LANES];
- struct regmap *regmap_dptx_phy_reg;
- struct regmap_field *phy_pll_cfg;
- struct regmap_field *phy_pipe_cmn_ctrl1_0;
- struct regmap_field *cmn_cdiag_refclk_ovrd_4;
- struct regmap_field *phy_pma_cmn_ctrl_1;
- struct regmap_field *phy_pma_cmn_ctrl_2;
- struct regmap_field *phy_pma_pll_raw_ctrl;
- struct regmap_field *phy_reset_ctrl;
- struct regmap_field *phy_pcs_iso_link_ctrl_1[MAX_NUM_LANES];
+
+ struct tp_reg_base reg_common_cdb;
+ struct tp_reg_base reg_phy_pcs_common_cdb;
+ struct tp_reg_base reg_phy_pma_common_cdb;
+ struct tp_reg_base reg_tx_lane_cdb[MAX_NUM_LANES];
+ struct tp_reg_base reg_rx_lane_cdb[MAX_NUM_LANES];
+ struct tp_reg_base reg_phy_pcs_lane_cdb[MAX_NUM_LANES];
+ struct tp_reg_field phy_pll_cfg;
+ struct tp_reg_field phy_pipe_cmn_ctrl1_0;
+ struct tp_reg_field cmn_cdiag_refclk_ovrd_4;
+
struct clk_hw_onecell_data *clk_hw_data;
+ struct tp_refclk_driver refclk_driver;
+ struct cdns_torrent_derived_refclk derived_refclk;
+ struct cdns_torrent_received_refclk received_refclk;
};
enum phy_powerstate {
@@ -455,12 +437,6 @@ struct cdns_torrent_data {
struct cdns_torrent_vals_table rx_ln_vals_tbl;
};
-struct cdns_regmap_cdb_context {
- struct device *dev;
- void __iomem *base;
- u8 reg_offset_shift;
-};
-
static const struct cdns_torrent_vals *cdns_torrent_get_tbl_vals(const struct cdns_torrent_vals_table *tbl,
enum cdns_torrent_ref_clk refclk0,
enum cdns_torrent_ref_clk refclk1,
@@ -479,156 +455,6 @@ static const struct cdns_torrent_vals *cdns_torrent_get_tbl_vals(const struct cd
return NULL;
}
-static int cdns_regmap_write(void *context, unsigned int reg, unsigned int val)
-{
- struct cdns_regmap_cdb_context *ctx = context;
- u32 offset = reg << ctx->reg_offset_shift;
-
- writew(val, ctx->base + offset);
-
- return 0;
-}
-
-static int cdns_regmap_read(void *context, unsigned int reg, unsigned int *val)
-{
- struct cdns_regmap_cdb_context *ctx = context;
- u32 offset = reg << ctx->reg_offset_shift;
-
- *val = readw(ctx->base + offset);
- return 0;
-}
-
-static int cdns_regmap_dptx_write(void *context, unsigned int reg,
- unsigned int val)
-{
- struct cdns_regmap_cdb_context *ctx = context;
- u32 offset = reg;
-
- writel(val, ctx->base + offset);
-
- return 0;
-}
-
-static int cdns_regmap_dptx_read(void *context, unsigned int reg,
- unsigned int *val)
-{
- struct cdns_regmap_cdb_context *ctx = context;
- u32 offset = reg;
-
- *val = readl(ctx->base + offset);
- return 0;
-}
-
-#define TORRENT_TX_LANE_CDB_REGMAP_CONF(n) \
-{ \
- .name = "torrent_tx_lane" n "_cdb", \
- .reg_stride = 1, \
- .fast_io = true, \
- .reg_write = cdns_regmap_write, \
- .reg_read = cdns_regmap_read, \
-}
-
-#define TORRENT_RX_LANE_CDB_REGMAP_CONF(n) \
-{ \
- .name = "torrent_rx_lane" n "_cdb", \
- .reg_stride = 1, \
- .fast_io = true, \
- .reg_write = cdns_regmap_write, \
- .reg_read = cdns_regmap_read, \
-}
-
-static const struct regmap_config cdns_torrent_tx_lane_cdb_config[] = {
- TORRENT_TX_LANE_CDB_REGMAP_CONF("0"),
- TORRENT_TX_LANE_CDB_REGMAP_CONF("1"),
- TORRENT_TX_LANE_CDB_REGMAP_CONF("2"),
- TORRENT_TX_LANE_CDB_REGMAP_CONF("3"),
-};
-
-static const struct regmap_config cdns_torrent_rx_lane_cdb_config[] = {
- TORRENT_RX_LANE_CDB_REGMAP_CONF("0"),
- TORRENT_RX_LANE_CDB_REGMAP_CONF("1"),
- TORRENT_RX_LANE_CDB_REGMAP_CONF("2"),
- TORRENT_RX_LANE_CDB_REGMAP_CONF("3"),
-};
-
-static const struct regmap_config cdns_torrent_common_cdb_config = {
- .name = "torrent_common_cdb",
- .reg_stride = 1,
- .fast_io = true,
- .reg_write = cdns_regmap_write,
- .reg_read = cdns_regmap_read,
-};
-
-#define TORRENT_PHY_PCS_LANE_CDB_REGMAP_CONF(n) \
-{ \
- .name = "torrent_phy_pcs_lane" n "_cdb", \
- .reg_stride = 1, \
- .fast_io = true, \
- .reg_write = cdns_regmap_write, \
- .reg_read = cdns_regmap_read, \
-}
-
-static const struct regmap_config cdns_torrent_phy_pcs_lane_cdb_config[] = {
- TORRENT_PHY_PCS_LANE_CDB_REGMAP_CONF("0"),
- TORRENT_PHY_PCS_LANE_CDB_REGMAP_CONF("1"),
- TORRENT_PHY_PCS_LANE_CDB_REGMAP_CONF("2"),
- TORRENT_PHY_PCS_LANE_CDB_REGMAP_CONF("3"),
-};
-
-static const struct regmap_config cdns_torrent_phy_pcs_cmn_cdb_config = {
- .name = "torrent_phy_pcs_cmn_cdb",
- .reg_stride = 1,
- .fast_io = true,
- .reg_write = cdns_regmap_write,
- .reg_read = cdns_regmap_read,
-};
-
-static const struct regmap_config cdns_torrent_phy_pma_cmn_cdb_config = {
- .name = "torrent_phy_pma_cmn_cdb",
- .reg_stride = 1,
- .fast_io = true,
- .reg_write = cdns_regmap_write,
- .reg_read = cdns_regmap_read,
-};
-
-static const struct regmap_config cdns_torrent_dptx_phy_config = {
- .name = "torrent_dptx_phy",
- .reg_stride = 1,
- .fast_io = true,
- .reg_write = cdns_regmap_dptx_write,
- .reg_read = cdns_regmap_dptx_read,
-};
-
-/* PHY mmr access functions */
-
-static void cdns_torrent_phy_write(struct regmap *regmap, u32 offset, u32 val)
-{
- regmap_write(regmap, offset, val);
-}
-
-static u32 cdns_torrent_phy_read(struct regmap *regmap, u32 offset)
-{
- unsigned int val;
-
- regmap_read(regmap, offset, &val);
- return val;
-}
-
-/* DPTX mmr access functions */
-
-static void cdns_torrent_dp_write(struct regmap *regmap, u32 offset, u32 val)
-{
- regmap_write(regmap, offset, val);
-}
-
-static u32 cdns_torrent_dp_read(struct regmap *regmap, u32 offset)
-{
- u32 val;
-
- regmap_read(regmap, offset, &val);
- return val;
-}
-
/*
* Structure used to store values of PHY registers for voltage-related
* coefficients, for particular voltage swing and pre-emphasis level. Values
@@ -693,6 +519,104 @@ static const struct coefficients vltg_coeff[4][4] = {
}
};
+
+static void tp_reg_base_init(const struct tp_data *tp_data, u32 block_offset,
+ struct tp_reg_base *ctx)
+{
+ ctx->base = tp_data->sd_base + block_offset;
+ ctx->reg_offset_shift = tp_data->init_data->reg_offset_shift;
+ ctx->block_off = block_offset;
+ ctx->dev = tp_data->dev;
+}
+
+static void tp_reg_write(const struct tp_reg_base *ctx, u32 reg, u16 val)
+{
+ u32 offset = reg << ctx->reg_offset_shift;
+
+ writew(val, ctx->base + offset);
+ dev_dbg(ctx->dev, "write: 0x%08X = 0x%04X", ctx->block_off + offset, val);
+}
+
+static u16 tp_reg_read(const struct tp_reg_base *ctx, u32 reg)
+{
+ u32 offset = reg << ctx->reg_offset_shift;
+ u16 val = readw(ctx->base + offset);
+
+ dev_dbg(ctx->dev, "read: 0x%08X = 0x%04X", ctx->block_off + offset, val);
+ return val;
+}
+
+static void tp_reg_set_bits(const struct tp_reg_base *ctx, u32 reg, u16 bits)
+{
+ u16 val = tp_reg_read(ctx, reg);
+
+ if ((val & bits) != bits) {
+ val |= bits;
+ tp_reg_write(ctx, reg, val);
+ }
+}
+
+static void tp_reg_clear_bits(const struct tp_reg_base *ctx, u32 reg, u16 bits)
+{
+ u16 val = tp_reg_read(ctx, reg);
+
+ if ((val & bits) != 0) {
+ val &= ~bits;
+ tp_reg_write(ctx, reg, val);
+ }
+}
+
+static void tp_reg_field_init(const struct tp_reg_base *ctx, u32 reg, u16 mask,
+ struct tp_reg_field *field)
+{
+ u32 offset = reg << ctx->reg_offset_shift;
+
+ field->reg_addr = ctx->base + offset;
+ field->mask = mask;
+ field->reg_off = ctx->block_off + offset;
+ field->dev = ctx->dev;
+}
+
+static u16 tp_reg_field_read(const struct tp_reg_field *field)
+{
+ u16 val = readw(field->reg_addr);
+
+ dev_dbg(field->dev, "read (field): 0x%08X = 0x%04X", field->reg_off, val);
+ val &= field->mask;
+ return val >> __ffs(field->mask);
+}
+
+static void tp_reg_field_write(const struct tp_reg_field *field, u16 val)
+{
+ u16 reg_val = readw(field->reg_addr);
+
+ reg_val &= ~field->mask;
+ reg_val |= val << __ffs(field->mask);
+ dev_dbg(field->dev, "write (field): 0x%08X = 0x%04X", field->reg_off, reg_val);
+ writew(reg_val, field->reg_addr);
+}
+
+static void tp_reg_dptx_write(const struct tp_data *tp_data, u32 reg, u32 val)
+{
+ writel(val, tp_data->base + reg);
+ dev_dbg(tp_data->dev, "write (dptx): 0x%08X = 0x%04X", reg, val);
+}
+
+static u32 tp_reg_dptx_read(const struct tp_data *tp_data, u32 reg)
+{
+ u32 val = readl(tp_data->base + reg);
+
+ dev_dbg(tp_data->dev, "read (dptx): 0x%08X = 0x%04X", reg, val);
+ return val;
+}
+
+static void tp_dptx_deassert_phy_reset(const struct tp_data *tp_data)
+{
+ u32 val = tp_reg_dptx_read(tp_data, PHY_RESET);
+
+ tp_reg_dptx_write(tp_data, PHY_RESET, val | 0x0100);
+}
+
static const char *cdns_torrent_get_phy_type(enum cdns_torrent_phy_type phy_type)
{
switch (phy_type) {
@@ -724,39 +648,39 @@ static
void cdns_torrent_dp_enable_ssc_19_2mhz(struct tp_data *tp_data,
u32 ctrl2_val, u32 ctrl3_val)
{
- struct regmap *regmap = tp_data->regmap_common_cdb;
+ const struct tp_reg_base *reg_base = &tp_data->reg_common_cdb;
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl3_val);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL4_M0, 0x0003);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x0001);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, ctrl2_val);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, ctrl3_val);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL4_M0, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, 0x0001);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, ctrl3_val);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL4_M0, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, 0x0001);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, ctrl2_val);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, ctrl3_val);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL4_M0, 0x0003);
}
static
void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct tp_data *tp_data,
u32 rate, bool ssc)
{
- struct regmap *regmap = tp_data->regmap_common_cdb;
+ const struct tp_reg_base *reg_base = &tp_data->reg_common_cdb;
/* Assumes 19.2 MHz refclock */
switch (rate) {
/* Setting VCO for 10.8GHz */
case 2700:
case 5400:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0119);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x4000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x00BC);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0012);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0119);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x4000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00BC);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0012);
+ 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;
@@ -764,77 +688,77 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct tp_data *tp_data,
case 1620:
case 2430:
case 3240:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x01FA);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x4000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0152);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x01FA);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x4000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0152);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
+ 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:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x01C2);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x012C);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x01C2);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x012C);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
+ 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:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x01A5);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0xE000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x011A);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x01A5);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0xE000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x011A);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
+ 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 (ssc) {
- cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_PLLCNT_START, 0x025E);
- cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_PLLCNT_THR, 0x0005);
- cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_PLLCNT_START, 0x025E);
- cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_PLLCNT_THR, 0x0005);
+ 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);
} else {
- cdns_torrent_phy_write(regmap, CMN_PLL0_VCOCAL_PLLCNT_START, 0x0260);
- cdns_torrent_phy_write(regmap, CMN_PLL1_VCOCAL_PLLCNT_START, 0x0260);
+ tp_reg_write(reg_base, CMN_PLL0_VCOCAL_PLLCNT_START, 0x0260);
+ tp_reg_write(reg_base, CMN_PLL1_VCOCAL_PLLCNT_START, 0x0260);
/* Set reset register values to disable SSC */
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL2_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL3_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL4_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_PLLCNT_THR, 0x0003);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL2_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL3_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL4_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_PLLCNT_THR, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL2_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL3_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL4_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL0_LOCK_PLLCNT_THR, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL2_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL3_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL4_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL1_LOCK_PLLCNT_THR, 0x0003);
}
- cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_REFCNT_START, 0x0099);
- cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_PLLCNT_START, 0x0099);
- cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_REFCNT_START, 0x0099);
- cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_PLLCNT_START, 0x0099);
+ tp_reg_write(reg_base, CMN_PLL0_LOCK_REFCNT_START, 0x0099);
+ tp_reg_write(reg_base, CMN_PLL0_LOCK_PLLCNT_START, 0x0099);
+ tp_reg_write(reg_base, CMN_PLL1_LOCK_REFCNT_START, 0x0099);
+ tp_reg_write(reg_base, CMN_PLL1_LOCK_PLLCNT_START, 0x0099);
}
/*
@@ -844,37 +768,37 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(struct tp_data *tp_data,
static void cdns_torrent_dp_enable_ssc_25mhz(struct tp_data *tp_data,
u32 ctrl2_val)
{
- struct regmap *regmap = tp_data->regmap_common_cdb;
+ const struct tp_reg_base *reg_base = &tp_data->reg_common_cdb;
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0001);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x007F);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL4_M0, 0x0003);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x0001);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, ctrl2_val);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x007F);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL4_M0, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, 0x0001);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, ctrl2_val);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, 0x007F);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL4_M0, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, 0x0001);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, ctrl2_val);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, 0x007F);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL4_M0, 0x0003);
}
static
void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct tp_data *tp_data,
u32 rate, bool ssc)
{
- struct regmap *regmap = tp_data->regmap_common_cdb;
+ const struct tp_reg_base *reg_base = &tp_data->reg_common_cdb;
/* Assumes 25 MHz refclock */
switch (rate) {
/* Setting VCO for 10.8GHz */
case 2700:
case 5400:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x01B0);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0120);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x01B0);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0120);
+ tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x01B0);
+ 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, 0x0120);
+ tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x01B0);
+ 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, 0x0120);
if (ssc)
cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x0423);
break;
@@ -882,89 +806,81 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(struct tp_data *tp_data,
case 1620:
case 2430:
case 3240:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0184);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0xCCCD);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0104);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0184);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0xCCCD);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0104);
+ tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x0184);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0xCCCD);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x0104);
+ tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x0184);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0xCCCD);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x0104);
if (ssc)
cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x03B9);
break;
/* Setting VCO for 8.64GHz */
case 2160:
case 4320:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0159);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x999A);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x00E7);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0159);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x999A);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00E7);
+ tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x0159);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0x999A);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x00E7);
+ tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x0159);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0x999A);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x00E7);
if (ssc)
cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x034F);
break;
/* Setting VCO for 8.1GHz */
case 8100:
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0144);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x00D8);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0144);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x00D8);
+ tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x0144);
+ 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, 0x00D8);
+ tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x0144);
+ 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, 0x00D8);
if (ssc)
cdns_torrent_dp_enable_ssc_25mhz(tp_data, 0x031A);
break;
}
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
if (ssc) {
- cdns_torrent_phy_write(regmap,
- CMN_PLL0_VCOCAL_PLLCNT_START, 0x0315);
- cdns_torrent_phy_write(regmap,
- CMN_PLL0_LOCK_PLLCNT_THR, 0x0005);
- cdns_torrent_phy_write(regmap,
- CMN_PLL1_VCOCAL_PLLCNT_START, 0x0315);
- cdns_torrent_phy_write(regmap,
- CMN_PLL1_LOCK_PLLCNT_THR, 0x0005);
+ tp_reg_write(reg_base, CMN_PLL0_VCOCAL_PLLCNT_START, 0x0315);
+ tp_reg_write(reg_base, CMN_PLL0_LOCK_PLLCNT_THR, 0x0005);
+ tp_reg_write(reg_base, CMN_PLL1_VCOCAL_PLLCNT_START, 0x0315);
+ tp_reg_write(reg_base, CMN_PLL1_LOCK_PLLCNT_THR, 0x0005);
} else {
- cdns_torrent_phy_write(regmap,
- CMN_PLL0_VCOCAL_PLLCNT_START, 0x0317);
- cdns_torrent_phy_write(regmap,
- CMN_PLL1_VCOCAL_PLLCNT_START, 0x0317);
+ tp_reg_write(reg_base, CMN_PLL0_VCOCAL_PLLCNT_START, 0x0317);
+ tp_reg_write(reg_base, CMN_PLL1_VCOCAL_PLLCNT_START, 0x0317);
/* Set reset register values to disable SSC */
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL1_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL2_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL3_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL0_SS_CTRL4_M0, 0x0000);
- cdns_torrent_phy_write(regmap,
- CMN_PLL0_LOCK_PLLCNT_THR, 0x0003);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL1_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL2_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL3_M0, 0x0000);
- cdns_torrent_phy_write(regmap, CMN_PLL1_SS_CTRL4_M0, 0x0000);
- cdns_torrent_phy_write(regmap,
- CMN_PLL1_LOCK_PLLCNT_THR, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL1_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL2_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL3_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL0_SS_CTRL4_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL0_LOCK_PLLCNT_THR, 0x0003);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL1_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL2_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL3_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL1_SS_CTRL4_M0, 0x0000);
+ tp_reg_write(reg_base, CMN_PLL1_LOCK_PLLCNT_THR, 0x0003);
}
- cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_REFCNT_START, 0x00C7);
- cdns_torrent_phy_write(regmap, CMN_PLL0_LOCK_PLLCNT_START, 0x00C7);
- cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_REFCNT_START, 0x00C7);
- cdns_torrent_phy_write(regmap, CMN_PLL1_LOCK_PLLCNT_START, 0x00C7);
+ tp_reg_write(reg_base, CMN_PLL0_LOCK_REFCNT_START, 0x00C7);
+ tp_reg_write(reg_base, CMN_PLL0_LOCK_PLLCNT_START, 0x00C7);
+ tp_reg_write(reg_base, CMN_PLL1_LOCK_REFCNT_START, 0x00C7);
+ tp_reg_write(reg_base, CMN_PLL1_LOCK_PLLCNT_START, 0x00C7);
}
static
void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct tp_data *tp_data,
u32 rate, bool ssc)
{
- struct regmap *regmap = tp_data->regmap_common_cdb;
+ const struct tp_reg_base *reg_base = &tp_data->reg_common_cdb;
/* Assumes 100 MHz refclock */
switch (rate) {
@@ -972,12 +888,12 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct tp_data *tp_data,
case 2700:
case 5400:
if (tp_data->dp_pll & DP_PLL0)
- cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_FBH_OVRD_M0, 0x0022);
+ tp_reg_write(reg_base, CMN_PLL0_DSM_FBH_OVRD_M0, 0x0022);
if (tp_data->dp_pll & DP_PLL1) {
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0028);
- cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_FBH_OVRD_M0, 0x0022);
- cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_FBL_OVRD_M0, 0x000C);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0028);
+ tp_reg_write(reg_base, CMN_PLL1_DSM_FBH_OVRD_M0, 0x0022);
+ tp_reg_write(reg_base, CMN_PLL1_DSM_FBL_OVRD_M0, 0x000C);
}
break;
/* Setting VCO for 9.72GHz */
@@ -985,75 +901,75 @@ void cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(struct tp_data *tp_data,
case 2430:
case 3240:
if (tp_data->dp_pll & DP_PLL0) {
- cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0061);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x3333);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0042);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_DSM_DIAG_M0, 0x0004);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
+ tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x0061);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0x3333);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x0042);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
}
if (tp_data->dp_pll & DP_PLL1) {
- cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0061);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x3333);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0042);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_DSM_DIAG_M0, 0x0004);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
+ tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x0061);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0x3333);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x0042);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
}
break;
/* Setting VCO for 8.64GHz */
case 2160:
case 4320:
if (tp_data->dp_pll & DP_PLL0) {
- cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0056);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVL_M0, 0x6666);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x003A);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_DSM_DIAG_M0, 0x0004);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
+ tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x0056);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVL_M0, 0x6666);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x003A);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
}
if (tp_data->dp_pll & DP_PLL1) {
- cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0056);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVL_M0, 0x6666);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x003A);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_DSM_DIAG_M0, 0x0004);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
+ tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x0056);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVL_M0, 0x6666);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x003A);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
}
break;
/* Setting VCO for 8.1GHz */
case 8100:
if (tp_data->dp_pll & DP_PLL0) {
- cdns_torrent_phy_write(regmap, CMN_PLL0_DSM_DIAG_M0, 0x0004);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
- cdns_torrent_phy_write(regmap, CMN_PLL0_INTDIV_M0, 0x0051);
- cdns_torrent_phy_write(regmap, CMN_PLL0_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL0_HIGH_THR_M0, 0x0036);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_DSM_DIAG_M0, 0x0004);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CP_PADJ_M0, 0x0509);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CP_IADJ_M0, 0x0F00);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_FILT_PADJ_M0, 0x0F08);
+ tp_reg_write(reg_base, CMN_PLL0_INTDIV_M0, 0x0051);
+ tp_reg_write(reg_base, CMN_PLL0_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL0_HIGH_THR_M0, 0x0036);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL0_CTRL_M0, 0x0002);
}
if (tp_data->dp_pll & DP_PLL1) {
- cdns_torrent_phy_write(regmap, CMN_PLL1_DSM_DIAG_M0, 0x0004);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
- cdns_torrent_phy_write(regmap, CMN_PLL1_INTDIV_M0, 0x0051);
- cdns_torrent_phy_write(regmap, CMN_PLL1_FRACDIVH_M0, 0x0002);
- cdns_torrent_phy_write(regmap, CMN_PLL1_HIGH_THR_M0, 0x0036);
- cdns_torrent_phy_write(regmap, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_DSM_DIAG_M0, 0x0004);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CP_PADJ_M0, 0x0509);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CP_IADJ_M0, 0x0F00);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_FILT_PADJ_M0, 0x0F08);
+ tp_reg_write(reg_base, CMN_PLL1_INTDIV_M0, 0x0051);
+ tp_reg_write(reg_base, CMN_PLL1_FRACDIVH_M0, 0x0002);
+ tp_reg_write(reg_base, CMN_PLL1_HIGH_THR_M0, 0x0036);
+ tp_reg_write(reg_base, CMN_PDIAG_PLL1_CTRL_M0, 0x0002);
}
break;
}
@@ -1089,7 +1005,7 @@ static int cdns_torrent_dp_get_pll(struct tp_data *tp_data,
static int tp_dptx_set_pll_en(struct tp_data *tp_data, struct tp_link *link,
struct phy_configure_opts_dp *dp, bool enable)
{
- struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
+ void __iomem *addr;
u32 rd_val, pll_ack_val;
int ret;
@@ -1102,7 +1018,7 @@ static int tp_dptx_set_pll_en(struct tp_data *tp_data, struct tp_link *link,
u32 pll_val;
/* Select values of registers and mask, depending on enabled lane count. */
- pll_val = cdns_torrent_dp_read(regmap, PHY_PMA_XCVR_PLLCLK_EN);
+ pll_val = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
if (enable) {
pll_bits = ((1 << dp->lanes) - 1);
@@ -1114,14 +1030,12 @@ static int tp_dptx_set_pll_en(struct tp_data *tp_data, struct tp_link *link,
pll_ack_val = 0;
}
- cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, pll_val);
+ tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, pll_val);
/* Wait for acknowledgment from PHY. */
- ret = regmap_read_poll_timeout(regmap,
- PHY_PMA_XCVR_PLLCLK_EN_ACK,
- rd_val,
- (rd_val & pll_bits) == pll_ack_val,
- 0, POLL_TIMEOUT_US);
+ addr = tp_data->base + PHY_PMA_XCVR_PLLCLK_EN_ACK;
+ ret = readl_poll_timeout(addr, rd_val, (rd_val & pll_bits) == pll_ack_val, 0,
+ POLL_TIMEOUT_US);
ndelay(100);
return ret;
}
@@ -1130,12 +1044,12 @@ static int tp_dptx_set_power_state(struct tp_data *tp_data, struct tp_link *link
u32 num_lanes, enum phy_powerstate powerstate)
{
/* Register value for power state for a single byte. */
+ void __iomem *addr;
u32 value_part, i;
u32 value = 0;
u32 mask = 0;
u32 read_val;
int ret;
- struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
switch (powerstate) {
case (POWERSTATE_A0):
@@ -1158,32 +1072,32 @@ static int tp_dptx_set_power_state(struct tp_data *tp_data, struct tp_link *link
}
/* Set power state A<n>. */
- cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, value);
+ tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_POWER_STATE_REQ, value);
+
/* Wait, until PHY acknowledges power state completion. */
- ret = regmap_read_poll_timeout(regmap, PHY_PMA_XCVR_POWER_STATE_ACK,
- read_val, (read_val & mask) == value, 0,
- POLL_TIMEOUT_US);
+ addr = tp_data->base + PHY_PMA_XCVR_POWER_STATE_ACK;
+ ret = readl_poll_timeout(addr, read_val, (read_val & mask) == value, 0,
+ POLL_TIMEOUT_US);
if (ret)
return ret;
- cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, 0x00000000);
+ tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_POWER_STATE_REQ, 0x00000000);
ndelay(100);
return ret;
}
-static int tp_dptx_wait_pma_cmn_ready(struct tp_data *tp_data)
+static int tp_dptx_wait_pma_cmn_ready(const struct tp_data *tp_data)
{
+ void __iomem *addr;
unsigned int reg;
int ret;
- struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
- ret = regmap_read_poll_timeout(regmap, PHY_PMA_CMN_READY, reg,
- reg & 1, 0, POLL_TIMEOUT_US);
- if (ret == -ETIMEDOUT) {
- dev_err(tp_data->dev,
- "timeout waiting for PMA common ready\n");
- return -ETIMEDOUT;
+ addr = tp_data->base + PHY_PMA_CMN_READY;
+ ret = readl_poll_timeout(addr, reg, reg & 1, 0, POLL_TIMEOUT_US);
+ if (ret < 0) {
+ dev_err(tp_data->dev, "timeout waiting for PMA common ready\n");
+ return ret;
}
return 0;
@@ -1191,20 +1105,18 @@ static int tp_dptx_wait_pma_cmn_ready(struct tp_data *tp_data)
static int tp_dp_run(struct tp_data *tp_data, struct tp_link *link, u32 num_lanes)
{
+ void __iomem *addr;
unsigned int read_val;
int ret;
- struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
/*
* waiting for ACK of pma_xcvr_pllclk_en_ln_*, only for the
* master lane
*/
- ret = regmap_read_poll_timeout(regmap, PHY_PMA_XCVR_PLLCLK_EN_ACK,
- read_val, read_val & 1,
- 0, POLL_TIMEOUT_US);
- if (ret == -ETIMEDOUT) {
- dev_err(tp_data->dev,
- "timeout waiting for link PLL clock enable ack\n");
+ 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");
return ret;
}
@@ -1254,17 +1166,15 @@ static void cdns_torrent_dp_pma_cmn_rate(struct tp_data *tp_data,
}
if (tp_data->dp_pll & DP_PLL0)
- cdns_torrent_phy_write(tp_data->regmap_common_cdb,
- CMN_PDIAG_PLL0_CLK_SEL_M0, clk_sel_val);
+ tp_reg_write(&tp_data->reg_common_cdb, CMN_PDIAG_PLL0_CLK_SEL_M0, clk_sel_val);
if (tp_data->dp_pll & DP_PLL1)
- cdns_torrent_phy_write(tp_data->regmap_common_cdb,
- CMN_PDIAG_PLL1_CLK_SEL_M0, clk_sel_val);
+ tp_reg_write(&tp_data->reg_common_cdb, CMN_PDIAG_PLL1_CLK_SEL_M0, clk_sel_val);
/* PMA lane configuration to deal with multi-link operation */
for (i = 0; i < num_lanes; i++)
- cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + i],
- XCVR_DIAG_HSCLK_DIV, hsclk_div_val);
+ tp_reg_write(&tp_data->reg_tx_lane_cdb[link->mlane + i],
+ XCVR_DIAG_HSCLK_DIV, hsclk_div_val);
}
/*
@@ -1274,41 +1184,29 @@ static void cdns_torrent_dp_pma_cmn_rate(struct tp_data *tp_data,
static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link,
struct phy_configure_opts_dp *dp)
{
- u32 read_val, field_val;
+ struct tp_reg_base *reg_base = &tp_data->reg_phy_pma_common_cdb;
+ u16 pll_mask;
+ u16 val;
int ret;
+ pll_mask = tp_data->dp_pll;
+
/*
* Disable the associated PLL (cmn_pll0_en or cmn_pll1_en) before
* re-programming the new data rate.
*/
- ret = regmap_field_read(tp_data->phy_pma_pll_raw_ctrl, &field_val);
- if (ret)
- return ret;
- field_val &= ~(tp_data->dp_pll);
- regmap_field_write(tp_data->phy_pma_pll_raw_ctrl, field_val);
+ tp_reg_clear_bits(reg_base, PHY_PMA_PLL_RAW_CTRL, pll_mask);
/*
* Wait for PLL ready de-assertion.
* For PLL0 - PHY_PMA_CMN_CTRL2[2] == 1
* For PLL1 - PHY_PMA_CMN_CTRL2[3] == 1
*/
- if (tp_data->dp_pll & DP_PLL0) {
- ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
- read_val,
- ((read_val >> 2) & 0x01) != 0,
- 0, POLL_TIMEOUT_US);
- if (ret)
- return ret;
- }
+ ret = read_poll_timeout(tp_reg_read, val, (val & (pll_mask << 2)) != 0, 0,
+ POLL_TIMEOUT_US, false, reg_base, PHY_PMA_CMN_CTRL2);
+ if (ret)
+ return ret;
- if ((tp_data->dp_pll & DP_PLL1) && tp_data->nb_links != 1) {
- ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
- read_val,
- ((read_val >> 3) & 0x01) != 0,
- 0, POLL_TIMEOUT_US);
- if (ret)
- return ret;
- }
ndelay(200);
/* DP Rate Change - VCO Output settings. */
@@ -1325,33 +1223,15 @@ static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link,
cdns_torrent_dp_pma_cmn_rate(tp_data, link, dp->link_rate, dp->lanes);
/* Enable the associated PLL (cmn_pll0_en or cmn_pll1_en) */
- ret = regmap_field_read(tp_data->phy_pma_pll_raw_ctrl, &field_val);
- if (ret)
- return ret;
- field_val |= tp_data->dp_pll;
- regmap_field_write(tp_data->phy_pma_pll_raw_ctrl, field_val);
+ 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
*/
- if (tp_data->dp_pll & DP_PLL0) {
- ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
- read_val,
- (read_val & 0x01) != 0,
- 0, POLL_TIMEOUT_US);
- if (ret)
- return ret;
- }
-
- if ((tp_data->dp_pll & DP_PLL1) && tp_data->nb_links != 1)
- ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_2,
- read_val,
- ((read_val >> 1) & 0x01) != 0,
- 0, POLL_TIMEOUT_US);
-
- return ret;
+ return read_poll_timeout(tp_reg_read, val, (val & pll_mask) == pll_mask, 0,
+ POLL_TIMEOUT_US, false, reg_base, PHY_PMA_CMN_CTRL2);
}
/*
@@ -1420,11 +1300,8 @@ static void cdns_torrent_dp_set_a0_pll(struct tp_data *tp_data,
struct tp_link *link,
u32 num_lanes)
{
- struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
- u32 pwr_state = cdns_torrent_dp_read(regmap,
- PHY_PMA_XCVR_POWER_STATE_REQ);
- u32 pll_clk_en = cdns_torrent_dp_read(regmap,
- PHY_PMA_XCVR_PLLCLK_EN);
+ 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++) {
@@ -1434,8 +1311,8 @@ static void cdns_torrent_dp_set_a0_pll(struct tp_data *tp_data,
pll_clk_en &= ~(0x01U << (link->mlane + i));
}
- cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_POWER_STATE_REQ, pwr_state);
- cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, pll_clk_en);
+ 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. */
@@ -1444,14 +1321,13 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
{
u32 value, i;
int ret;
- struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
u8 lane_mask = (1 << dp->lanes) - 1;
u8 pma_tx_elec_idle_mask = 0;
u32 clane = link->mlane;
lane_mask <<= clane;
- value = cdns_torrent_dp_read(regmap, PHY_RESET);
+ value = tp_reg_dptx_read(tp_data, PHY_RESET);
/* clear pma_tx_elec_idle_ln_* bits. */
pma_tx_elec_idle_mask = ((1 << link->num_lanes) - 1) << clane;
@@ -1463,10 +1339,10 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
value |= ((~lane_mask) << PMA_TX_ELEC_IDLE_SHIFT) &
pma_tx_elec_idle_mask;
- cdns_torrent_dp_write(regmap, PHY_RESET, value);
+ tp_reg_dptx_write(tp_data, PHY_RESET, value);
/* reset the link by asserting master lane phy_l0*_reset_n low */
- cdns_torrent_dp_write(regmap, PHY_RESET,
+ tp_reg_dptx_write(tp_data, PHY_RESET,
value & (~(1 << clane)));
/*
@@ -1479,7 +1355,7 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
for (i = 1; i < link->num_lanes; i++)
value |= ((1 << (clane + i)) & lane_mask);
- cdns_torrent_dp_write(regmap, PHY_RESET, value);
+ tp_reg_dptx_write(tp_data, PHY_RESET, value);
cdns_torrent_dp_set_a0_pll(tp_data, link, dp->lanes);
@@ -1490,7 +1366,7 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
for (i = 0; i < link->num_lanes; i++)
value |= ((1 << (clane + i)) & lane_mask);
- cdns_torrent_dp_write(regmap, PHY_RESET, value);
+ tp_reg_dptx_write(tp_data, PHY_RESET, value);
/* Wait, until PHY gets ready after releasing PHY reset signal. */
ret = tp_dptx_wait_pma_cmn_ready(tp_data);
@@ -1500,9 +1376,9 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
ndelay(100);
/* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
- value = cdns_torrent_dp_read(regmap, PHY_PMA_XCVR_PLLCLK_EN);
+ value = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
value |= (1 << clane);
- cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, value);
+ tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, value);
ret = tp_dp_run(tp_data, link, dp->lanes);
@@ -1543,46 +1419,34 @@ static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
}
/* Configure voltage swing and pre-emphasis for all enabled lanes. */
-static void tp_dp_set_voltages(struct tp_data *tp_data, struct tp_link *link,
- struct phy_configure_opts_dp *dp)
+static void tp_dp_set_voltages(const struct tp_data *tp_data, const struct tp_link *link,
+ const struct phy_configure_opts_dp *dp)
{
- u8 lane;
- u16 val;
+ for (u32 lane = 0; lane < link->num_lanes; ++lane) {
+ const struct tp_reg_base *reg_base;
+ u16 val;
+
+ reg_base = &tp_data->reg_tx_lane_cdb[link->mlane + lane];
- for (lane = 0; lane < dp->lanes; lane++) {
- val = cdns_torrent_phy_read(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- TX_DIAG_ACYA);
/*
* Write 1 to register bit TX_DIAG_ACYA[0] to freeze the
* current state of the analog TX driver.
*/
- val |= TX_DIAG_ACYA_HBDC_MASK;
- cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- TX_DIAG_ACYA, val);
+ tp_reg_set_bits(reg_base, TX_DIAG_ACYA, TX_DIAG_ACYA_HBDC_MASK);
- cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- TX_TXCC_CTRL, 0x08A4);
+ tp_reg_write(reg_base, TX_TXCC_CTRL, 0x08A4);
val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].diag_tx_drv;
- cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- DRV_DIAG_TX_DRV, val);
+ tp_reg_write(reg_base, DRV_DIAG_TX_DRV, val);
val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult;
- cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- TX_TXCC_MGNFS_MULT_000,
- val);
+ tp_reg_write(reg_base, TX_TXCC_MGNFS_MULT_000, val);
val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].cpost_mult;
- cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- TX_TXCC_CPOST_MULT_00,
- val);
+ tp_reg_write(reg_base, TX_TXCC_CPOST_MULT_00, val);
- val = cdns_torrent_phy_read(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- TX_DIAG_ACYA);
/*
* Write 0 to register bit TX_DIAG_ACYA[0] to allow the state of
* analog TX driver to reflect the new programmed one.
*/
- val &= ~TX_DIAG_ACYA_HBDC_MASK;
- cdns_torrent_phy_write(tp_data->regmap_tx_lane_cdb[link->mlane + lane],
- TX_DIAG_ACYA, val);
+ tp_reg_clear_bits(reg_base, TX_DIAG_ACYA, TX_DIAG_ACYA_HBDC_MASK);
}
}
@@ -1627,7 +1491,7 @@ 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);
- u32 read_val;
+ u16 val;
int ret;
if (tp_data->already_configured) {
@@ -1650,18 +1514,19 @@ static int tp_phy_on(struct phy *phy)
* Wait for cmn_ready assertion
* PHY_PMA_CMN_CTRL1[0] == 1
*/
- ret = regmap_field_read_poll_timeout(tp_data->phy_pma_cmn_ctrl_1,
- read_val, read_val, 1000,
- PLL_LOCK_TIMEOUT);
+ 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) {
dev_err(tp_data->dev, "Timeout waiting for CMN ready\n");
return ret;
}
if (link->phy_type == TYPE_PCIE || link->phy_type == TYPE_USB) {
- ret = regmap_field_read_poll_timeout(tp_data->phy_pcs_iso_link_ctrl_1[link->mlane],
- read_val, !read_val, 1000,
- PLL_LOCK_TIMEOUT);
+ 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) {
dev_err(tp_data->dev, "Timeout waiting for PHY status ready\n");
return ret;
@@ -1690,11 +1555,10 @@ static int tp_phy_off(struct phy *phy)
static void cdns_torrent_dp_common_init(struct tp_data *tp_data,
struct tp_link *link)
{
- struct regmap *regmap = tp_data->regmap_dptx_phy_reg;
unsigned char lane_bits;
u32 val;
- cdns_torrent_dp_write(regmap, PHY_AUX_CTRL, 0x0003); /* enable AUX */
+ tp_reg_dptx_write(tp_data, PHY_AUX_CTRL, 0x0003); /* enable AUX */
/*
* Set lines power state to A0
@@ -1708,15 +1572,15 @@ static void cdns_torrent_dp_common_init(struct tp_data *tp_data,
*/
lane_bits = (1 << link->num_lanes) - 1;
- val = cdns_torrent_dp_read(regmap, PHY_RESET);
+ val = tp_reg_dptx_read(tp_data, PHY_RESET);
val |= (0xF & lane_bits);
val &= ~(lane_bits << 4);
- cdns_torrent_dp_write(regmap, PHY_RESET, val);
+ tp_reg_dptx_write(tp_data, PHY_RESET, val);
/* release pma_xcvr_pllclk_en_ln_*, only for the master lane */
- val = cdns_torrent_dp_read(regmap, PHY_PMA_XCVR_PLLCLK_EN);
+ val = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
val |= 1;
- cdns_torrent_dp_write(regmap, PHY_PMA_XCVR_PLLCLK_EN, val);
+ tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, val);
/*
* PHY PMA registers configuration functions
@@ -1739,7 +1603,7 @@ static void cdns_torrent_dp_common_init(struct tp_data *tp_data,
link->num_lanes);
/* take out of reset */
- regmap_field_write(tp_data->phy_reset_ctrl, 0x1);
+ 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)
@@ -1803,8 +1667,8 @@ static int tp_derived_refclk_enable(struct clk_hw *hw)
{
struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
- regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 1);
- regmap_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 1);
+ tp_reg_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 1);
+ tp_reg_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 1);
return 0;
}
@@ -1813,17 +1677,16 @@ static void tp_derived_refclk_disable(struct clk_hw *hw)
{
struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
- regmap_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 0);
- regmap_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0);
+ tp_reg_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 0);
+ tp_reg_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0);
}
static int tp_derived_refclk_is_enabled(struct clk_hw *hw)
{
struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
- int val;
-
- regmap_field_read(derived_refclk->cmn_cdiag_refclk_ovrd_4, &val);
+ u16 val;
+ val = tp_reg_field_read(derived_refclk->cmn_cdiag_refclk_ovrd_4);
return !!val;
}
@@ -1844,9 +1707,7 @@ static int tp_derived_refclk_register(struct tp_data *tp_data)
struct clk *clk;
int ret;
- derived_refclk = devm_kzalloc_obj(dev, *derived_refclk);
- if (!derived_refclk)
- return -ENOMEM;
+ derived_refclk = &tp_data->derived_refclk;
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
tp_clk_names[CDNS_TORRENT_DERIVED_REFCLK]);
@@ -1868,8 +1729,8 @@ static int tp_derived_refclk_register(struct tp_data *tp_data)
init->flags = 0;
init->name = clk_name;
- derived_refclk->phy_pipe_cmn_ctrl1_0 = tp_data->phy_pipe_cmn_ctrl1_0;
- derived_refclk->cmn_cdiag_refclk_ovrd_4 = tp_data->cmn_cdiag_refclk_ovrd_4;
+ derived_refclk->phy_pipe_cmn_ctrl1_0 = &tp_data->phy_pipe_cmn_ctrl1_0;
+ derived_refclk->cmn_cdiag_refclk_ovrd_4 = &tp_data->cmn_cdiag_refclk_ovrd_4;
derived_refclk->hw.init = init;
@@ -1887,8 +1748,7 @@ static int tp_received_refclk_enable(struct clk_hw *hw)
{
struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
- regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 1);
-
+ tp_reg_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 1);
return 0;
}
@@ -1896,16 +1756,16 @@ static void tp_received_refclk_disable(struct clk_hw *hw)
{
struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
- regmap_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0);
+ tp_reg_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0);
}
static int tp_received_refclk_is_enabled(struct clk_hw *hw)
{
struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
- int val, cmn_val;
+ u16 val, cmn_val;
- regmap_field_read(received_refclk->phy_pipe_cmn_ctrl1_0, &val);
- regmap_field_read(received_refclk->cmn_cdiag_refclk_ovrd_4, &cmn_val);
+ val = tp_reg_field_read(received_refclk->phy_pipe_cmn_ctrl1_0);
+ cmn_val = tp_reg_field_read(received_refclk->cmn_cdiag_refclk_ovrd_4);
return val && !cmn_val;
}
@@ -1927,9 +1787,7 @@ static int tp_received_refclk_register(struct tp_data *tp_data)
struct clk *clk;
int ret;
- received_refclk = devm_kzalloc_obj(dev, *received_refclk);
- if (!received_refclk)
- return -ENOMEM;
+ received_refclk = &tp_data->received_refclk;
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
tp_clk_names[CDNS_TORRENT_RECEIVED_REFCLK]);
@@ -1951,8 +1809,8 @@ static int tp_received_refclk_register(struct tp_data *tp_data)
init->flags = 0;
init->name = clk_name;
- received_refclk->phy_pipe_cmn_ctrl1_0 = tp_data->phy_pipe_cmn_ctrl1_0;
- received_refclk->cmn_cdiag_refclk_ovrd_4 = tp_data->cmn_cdiag_refclk_ovrd_4;
+ received_refclk->phy_pipe_cmn_ctrl1_0 = &tp_data->phy_pipe_cmn_ctrl1_0;
+ received_refclk->cmn_cdiag_refclk_ovrd_4 = &tp_data->cmn_cdiag_refclk_ovrd_4;
received_refclk->hw.init = init;
@@ -1968,48 +1826,48 @@ static int tp_received_refclk_register(struct tp_data *tp_data)
static int tp_refclk_driver_enable(struct clk_hw *hw)
{
- struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
+ struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
- regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6], 0);
- regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5], 1);
- regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 0);
+ 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);
return 0;
}
static void tp_refclk_driver_disable(struct clk_hw *hw)
{
- struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
+ struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
- regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1);
+ tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], 1);
}
static int tp_refclk_driver_is_enabled(struct clk_hw *hw)
{
- struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
- int val;
-
- regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1], &val);
+ struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
+ u16 val;
+ val = tp_reg_field_read(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1]);
return !val;
}
static u8 tp_refclk_driver_get_parent(struct clk_hw *hw)
{
- struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
- unsigned int val;
+ struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
+ u16 val;
- regmap_field_read(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], &val);
+ val = tp_reg_field_read(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4]);
return clk_mux_val_to_index(hw, tp_refclk_driver_mux_table, 0, val);
}
static int tp_refclk_driver_set_parent(struct clk_hw *hw, u8 index)
{
- struct tp_refclk_driver *refclk_driver = tp_refclk_driver_to_clk_data(hw);
- unsigned int val;
+ struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
+ u16 val;
val = tp_refclk_driver_mux_table[index];
- return regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val);
+ tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val);
+ return 0;
}
static const struct clk_ops tp_refclk_driver_ops = {
@@ -2025,18 +1883,14 @@ static int tp_refclk_driver_register(struct tp_data *tp_data)
{
struct tp_refclk_driver *refclk_driver;
struct device *dev = tp_data->dev;
- struct regmap_field *field;
struct clk_init_data *init;
const char **parent_names;
unsigned int num_parents;
- struct regmap *regmap;
char clk_name[100];
struct clk_hw *hw;
int i, ret;
- refclk_driver = devm_kzalloc_obj(dev, *refclk_driver);
- if (!refclk_driver)
- return -ENOMEM;
+ refclk_driver = &tp_data->refclk_driver;
num_parents = ARRAY_SIZE(tp_refclk_driver_parent_idx);
parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL);
@@ -2063,19 +1917,8 @@ static int tp_refclk_driver_register(struct tp_data *tp_data)
init->num_parents = num_parents;
init->name = clk_name;
- regmap = tp_data->regmap_common_cdb;
-
- for (i = 0; i < TP_REFCLK_OUT_NUM_CMN_CONFIG; i++) {
- field = devm_regmap_field_alloc(dev, regmap, refclk_out_cmn_cfg[i]);
- if (IS_ERR(field)) {
- dev_err(dev, "Refclk driver CMN reg field init failed\n");
- return PTR_ERR(field);
- }
- refclk_driver->cmn_fields[i] = field;
- }
-
/* Enable Derived reference clock as default */
- regmap_field_write(refclk_driver->cmn_fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1);
+ tp_reg_field_write(&refclk_driver->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1);
refclk_driver->hw.init = init;
@@ -2089,210 +1932,58 @@ static int tp_refclk_driver_register(struct tp_data *tp_data)
return 0;
}
-static struct regmap *cdns_regmap_init(struct device *dev, void __iomem *base,
- u32 block_offset,
- u8 reg_offset_shift,
- const struct regmap_config *config)
+static void tp_reg_fields_init(struct tp_data *tp_data)
{
- struct cdns_regmap_cdb_context *ctx;
+ tp_reg_field_init(&tp_data->reg_phy_pcs_common_cdb, PHY_PLL_CFG, GENMASK_U16(1, 0),
+ &tp_data->phy_pll_cfg);
- ctx = devm_kzalloc_obj(dev, *ctx);
- if (!ctx)
- return ERR_PTR(-ENOMEM);
+ tp_reg_field_init(&tp_data->reg_phy_pcs_common_cdb, PHY_PIPE_CMN_CTRL1,
+ GENMASK_U16(0, 0), &tp_data->phy_pipe_cmn_ctrl1_0);
- ctx->dev = dev;
- ctx->base = base + block_offset;
- ctx->reg_offset_shift = reg_offset_shift;
+ tp_reg_field_init(&tp_data->reg_common_cdb, CMN_CDIAG_REFCLK_OVRD, GENMASK_U16(4, 4),
+ &tp_data->cmn_cdiag_refclk_ovrd_4);
- return devm_regmap_init(dev, NULL, ctx, config);
-}
-
-static int cdns_torrent_dp_regfield_init(struct tp_data *tp_data)
-{
- struct device *dev = tp_data->dev;
- struct regmap_field *field;
- struct regmap *regmap;
-
- regmap = tp_data->regmap_dptx_phy_reg;
- field = devm_regmap_field_alloc(dev, regmap, phy_reset_ctrl);
- if (IS_ERR(field)) {
- dev_err(dev, "PHY_RESET reg field init failed\n");
- return PTR_ERR(field);
- }
- tp_data->phy_reset_ctrl = field;
-
- return 0;
-}
-
-static int cdns_torrent_regfield_init(struct tp_data *tp_data)
-{
- struct device *dev = tp_data->dev;
- struct regmap_field *field;
- struct regmap *regmap;
- int i;
-
- regmap = tp_data->regmap_phy_pcs_common_cdb;
- field = devm_regmap_field_alloc(dev, regmap, phy_pll_cfg);
- if (IS_ERR(field)) {
- dev_err(dev, "PHY_PLL_CFG reg field init failed\n");
- return PTR_ERR(field);
- }
- tp_data->phy_pll_cfg = field;
-
- regmap = tp_data->regmap_phy_pcs_common_cdb;
- field = devm_regmap_field_alloc(dev, regmap, phy_pipe_cmn_ctrl1_0);
- if (IS_ERR(field)) {
- dev_err(dev, "phy_pipe_cmn_ctrl1_0 reg field init failed\n");
- return PTR_ERR(field);
- }
- tp_data->phy_pipe_cmn_ctrl1_0 = field;
-
- regmap = tp_data->regmap_common_cdb;
- field = devm_regmap_field_alloc(dev, regmap, cmn_cdiag_refclk_ovrd_4);
- if (IS_ERR(field)) {
- dev_err(dev, "cmn_cdiag_refclk_ovrd_4 reg field init failed\n");
- return PTR_ERR(field);
- }
- tp_data->cmn_cdiag_refclk_ovrd_4 = field;
-
- regmap = tp_data->regmap_phy_pma_common_cdb;
- field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_1);
- if (IS_ERR(field)) {
- dev_err(dev, "PHY_PMA_CMN_CTRL1 reg field init failed\n");
- return PTR_ERR(field);
- }
- tp_data->phy_pma_cmn_ctrl_1 = field;
+ tp_reg_field_init(&tp_data->reg_common_cdb, CMN_CDIAG_REFCLK_DRV0_CTRL,
+ GENMASK_U16(1, 1),
+ &tp_data->refclk_driver.fields[CMN_CDIAG_REFCLK_DRV0_CTRL_1]);
- regmap = tp_data->regmap_phy_pma_common_cdb;
- field = devm_regmap_field_alloc(dev, regmap, phy_pma_cmn_ctrl_2);
- if (IS_ERR(field)) {
- dev_err(dev, "PHY_PMA_CMN_CTRL2 reg field init failed\n");
- return PTR_ERR(field);
- }
- tp_data->phy_pma_cmn_ctrl_2 = field;
+ tp_reg_field_init(&tp_data->reg_common_cdb, CMN_CDIAG_REFCLK_DRV0_CTRL,
+ GENMASK_U16(4, 4),
+ &tp_data->refclk_driver.fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4]);
- regmap = tp_data->regmap_phy_pma_common_cdb;
- field = devm_regmap_field_alloc(dev, regmap, phy_pma_pll_raw_ctrl);
- if (IS_ERR(field)) {
- dev_err(dev, "PHY_PMA_PLL_RAW_CTRL reg field init failed\n");
- return PTR_ERR(field);
- }
- tp_data->phy_pma_pll_raw_ctrl = field;
+ tp_reg_field_init(&tp_data->reg_common_cdb, CMN_CDIAG_REFCLK_DRV0_CTRL,
+ GENMASK_U16(5, 5),
+ &tp_data->refclk_driver.fields[CMN_CDIAG_REFCLK_DRV0_CTRL_5]);
- for (i = 0; i < MAX_NUM_LANES; i++) {
- regmap = tp_data->regmap_phy_pcs_lane_cdb[i];
- field = devm_regmap_field_alloc(dev, regmap, phy_pcs_iso_link_ctrl_1);
- if (IS_ERR(field)) {
- dev_err(dev, "PHY_PCS_ISO_LINK_CTRL reg field init for ln %d failed\n", i);
- return PTR_ERR(field);
- }
- tp_data->phy_pcs_iso_link_ctrl_1[i] = field;
- }
-
- return 0;
+ tp_reg_field_init(&tp_data->reg_common_cdb, CMN_CDIAG_REFCLK_DRV0_CTRL,
+ GENMASK_U16(6, 6),
+ &tp_data->refclk_driver.fields[CMN_CDIAG_REFCLK_DRV0_CTRL_6]);
}
-static int cdns_torrent_dp_regmap_init(struct tp_data *tp_data)
+static void tp_reg_bases_init(struct tp_data *tp_data)
{
- void __iomem *base = tp_data->base;
- struct device *dev = tp_data->dev;
- struct regmap *regmap;
- u8 reg_offset_shift;
u32 block_offset;
+ u8 block_shift = tp_data->init_data->block_offset_shift;
+ u8 reg_shift = tp_data->init_data->reg_offset_shift;
- reg_offset_shift = tp_data->init_data->reg_offset_shift;
+ for (u32 i = 0; i < MAX_NUM_LANES; ++i) {
+ block_offset = TORRENT_TX_LANE_CDB_OFFSET(i, block_shift, reg_shift);
+ tp_reg_base_init(tp_data, block_offset, &tp_data->reg_tx_lane_cdb[i]);
- block_offset = TORRENT_DPTX_PHY_OFFSET;
- regmap = cdns_regmap_init(dev, base, block_offset,
- reg_offset_shift,
- &cdns_torrent_dptx_phy_config);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Failed to init DPTX PHY regmap\n");
- return PTR_ERR(regmap);
- }
- tp_data->regmap_dptx_phy_reg = regmap;
+ block_offset = TORRENT_RX_LANE_CDB_OFFSET(i, block_shift, reg_shift);
+ tp_reg_base_init(tp_data, block_offset, &tp_data->reg_rx_lane_cdb[i]);
- return 0;
-}
-
-static int cdns_torrent_regmap_init(struct tp_data *tp_data)
-{
- void __iomem *sd_base = tp_data->sd_base;
- u8 block_offset_shift, reg_offset_shift;
- struct device *dev = tp_data->dev;
- struct regmap *regmap;
- u32 block_offset;
- int i;
-
- block_offset_shift = tp_data->init_data->block_offset_shift;
- reg_offset_shift = tp_data->init_data->reg_offset_shift;
-
- for (i = 0; i < MAX_NUM_LANES; i++) {
- block_offset = TORRENT_TX_LANE_CDB_OFFSET(i, block_offset_shift,
- reg_offset_shift);
- regmap = cdns_regmap_init(dev, sd_base, block_offset,
- reg_offset_shift,
- &cdns_torrent_tx_lane_cdb_config[i]);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Failed to init tx lane CDB regmap\n");
- return PTR_ERR(regmap);
- }
- tp_data->regmap_tx_lane_cdb[i] = regmap;
-
- block_offset = TORRENT_RX_LANE_CDB_OFFSET(i, block_offset_shift,
- reg_offset_shift);
- regmap = cdns_regmap_init(dev, sd_base, block_offset,
- reg_offset_shift,
- &cdns_torrent_rx_lane_cdb_config[i]);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Failed to init rx lane CDB regmap\n");
- return PTR_ERR(regmap);
- }
- tp_data->regmap_rx_lane_cdb[i] = regmap;
-
- block_offset = TORRENT_PHY_PCS_LANE_CDB_OFFSET(i, block_offset_shift,
- reg_offset_shift);
- regmap = cdns_regmap_init(dev, sd_base, block_offset,
- reg_offset_shift,
- &cdns_torrent_phy_pcs_lane_cdb_config[i]);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Failed to init PHY PCS lane CDB regmap\n");
- return PTR_ERR(regmap);
- }
- tp_data->regmap_phy_pcs_lane_cdb[i] = regmap;
+ block_offset = TORRENT_PHY_PCS_LANE_CDB_OFFSET(i, block_shift, reg_shift);
+ tp_reg_base_init(tp_data, block_offset, &tp_data->reg_phy_pcs_lane_cdb[i]);
}
- block_offset = TORRENT_COMMON_CDB_OFFSET;
- regmap = cdns_regmap_init(dev, sd_base, block_offset,
- reg_offset_shift,
- &cdns_torrent_common_cdb_config);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Failed to init common CDB regmap\n");
- return PTR_ERR(regmap);
- }
- tp_data->regmap_common_cdb = regmap;
-
- block_offset = TORRENT_PHY_PCS_COMMON_OFFSET(block_offset_shift);
- regmap = cdns_regmap_init(dev, sd_base, block_offset,
- reg_offset_shift,
- &cdns_torrent_phy_pcs_cmn_cdb_config);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Failed to init PHY PCS common CDB regmap\n");
- return PTR_ERR(regmap);
- }
- tp_data->regmap_phy_pcs_common_cdb = regmap;
+ tp_reg_base_init(tp_data, TORRENT_COMMON_CDB_OFFSET, &tp_data->reg_common_cdb);
- block_offset = TORRENT_PHY_PMA_COMMON_OFFSET(block_offset_shift);
- regmap = cdns_regmap_init(dev, sd_base, block_offset,
- reg_offset_shift,
- &cdns_torrent_phy_pma_cmn_cdb_config);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Failed to init PHY PMA common CDB regmap\n");
- return PTR_ERR(regmap);
- }
- tp_data->regmap_phy_pma_common_cdb = regmap;
+ block_offset = TORRENT_PHY_PCS_COMMON_OFFSET(block_shift);
+ tp_reg_base_init(tp_data, block_offset, &tp_data->reg_phy_pcs_common_cdb);
- return 0;
+ block_offset = TORRENT_PHY_PMA_COMMON_OFFSET(block_shift);
+ tp_reg_base_init(tp_data, block_offset, &tp_data->reg_phy_pma_common_cdb);
}
static int tp_phy_init(struct phy *phy)
@@ -2308,7 +1999,7 @@ static int tp_phy_init(struct phy *phy)
enum cdns_torrent_ssc_mode ssc = link->ssc_mode;
const struct cdns_torrent_vals *pcs_cmn_vals;
const struct cdns_reg_pairs *reg_pairs;
- struct regmap *regmap;
+ struct tp_reg_base *reg_base;
u32 num_regs;
int i, j;
@@ -2336,17 +2027,16 @@ static int tp_phy_init(struct phy *phy)
if (link_cmn_vals) {
reg_pairs = link_cmn_vals->reg_pairs;
num_regs = link_cmn_vals->num_regs;
- regmap = tp_data->regmap_common_cdb;
+ reg_base = &tp_data->reg_common_cdb;
/**
* First array value in link_cmn_vals must be of
* PHY_PLL_CFG register
*/
- regmap_field_write(tp_data->phy_pll_cfg, reg_pairs[0].val);
+ tp_reg_field_write(&tp_data->phy_pll_cfg, reg_pairs[0].val);
for (i = 1; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
- reg_pairs[i].val);
+ tp_reg_write(reg_base, reg_pairs[i].off, reg_pairs[i].val);
}
xcvr_diag_vals = cdns_torrent_get_tbl_vals(&init_data->xcvr_diag_vals_tbl,
@@ -2357,10 +2047,9 @@ static int tp_phy_init(struct phy *phy)
reg_pairs = xcvr_diag_vals->reg_pairs;
num_regs = xcvr_diag_vals->num_regs;
for (i = 0; i < link->num_lanes; i++) {
- regmap = tp_data->regmap_tx_lane_cdb[i + link->mlane];
+ reg_base = &tp_data->reg_tx_lane_cdb[i + link->mlane];
for (j = 0; j < num_regs; j++)
- regmap_write(regmap, reg_pairs[j].off,
- reg_pairs[j].val);
+ tp_reg_write(reg_base, reg_pairs[j].off, reg_pairs[j].val);
}
}
@@ -2372,10 +2061,9 @@ static int tp_phy_init(struct phy *phy)
if (pcs_cmn_vals) {
reg_pairs = pcs_cmn_vals->reg_pairs;
num_regs = pcs_cmn_vals->num_regs;
- regmap = tp_data->regmap_phy_pcs_common_cdb;
+ reg_base = &tp_data->reg_phy_pcs_common_cdb;
for (i = 0; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
- reg_pairs[i].val);
+ tp_reg_write(reg_base, reg_pairs[i].off, reg_pairs[i].val);
}
/* PHY PMA common registers configurations */
@@ -2386,10 +2074,9 @@ static int tp_phy_init(struct phy *phy)
if (phy_pma_cmn_vals) {
reg_pairs = phy_pma_cmn_vals->reg_pairs;
num_regs = phy_pma_cmn_vals->num_regs;
- regmap = tp_data->regmap_phy_pma_common_cdb;
+ reg_base = &tp_data->reg_phy_pma_common_cdb;
for (i = 0; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
- reg_pairs[i].val);
+ tp_reg_write(reg_base, reg_pairs[i].off, reg_pairs[i].val);
}
/* PMA common registers configurations */
@@ -2400,10 +2087,9 @@ static int tp_phy_init(struct phy *phy)
if (cmn_vals) {
reg_pairs = cmn_vals->reg_pairs;
num_regs = cmn_vals->num_regs;
- regmap = tp_data->regmap_common_cdb;
+ reg_base = &tp_data->reg_common_cdb;
for (i = 0; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
- reg_pairs[i].val);
+ tp_reg_write(reg_base, reg_pairs[i].off, reg_pairs[i].val);
}
/* PMA TX lane registers configurations */
@@ -2415,10 +2101,9 @@ static int tp_phy_init(struct phy *phy)
reg_pairs = tx_ln_vals->reg_pairs;
num_regs = tx_ln_vals->num_regs;
for (i = 0; i < link->num_lanes; i++) {
- regmap = tp_data->regmap_tx_lane_cdb[i + link->mlane];
+ reg_base = &tp_data->reg_tx_lane_cdb[i + link->mlane];
for (j = 0; j < num_regs; j++)
- regmap_write(regmap, reg_pairs[j].off,
- reg_pairs[j].val);
+ tp_reg_write(reg_base, reg_pairs[j].off, reg_pairs[j].val);
}
}
@@ -2431,10 +2116,9 @@ static int tp_phy_init(struct phy *phy)
reg_pairs = rx_ln_vals->reg_pairs;
num_regs = rx_ln_vals->num_regs;
for (i = 0; i < link->num_lanes; i++) {
- regmap = tp_data->regmap_rx_lane_cdb[i + link->mlane];
+ reg_base = &tp_data->reg_rx_lane_cdb[i + link->mlane];
for (j = 0; j < num_regs; j++)
- regmap_write(regmap, reg_pairs[j].off,
- reg_pairs[j].val);
+ tp_reg_write(reg_base, reg_pairs[j].off, reg_pairs[j].val);
}
}
@@ -2467,7 +2151,7 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
int i, j, node, mlane, num_lanes, ret;
struct device *dev = tp_data->dev;
enum cdns_torrent_ssc_mode ssc;
- struct regmap *regmap;
+ struct tp_reg_base *reg_base;
u32 num_regs, num_protocols, protocol;
u32 num_pcie_links = 0;
@@ -2598,17 +2282,16 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
if (link_cmn_vals) {
reg_pairs = link_cmn_vals->reg_pairs;
num_regs = link_cmn_vals->num_regs;
- regmap = tp_data->regmap_common_cdb;
+ reg_base = &tp_data->reg_common_cdb;
/**
* First array value in link_cmn_vals must be of
* PHY_PLL_CFG register
*/
- regmap_field_write(tp_data->phy_pll_cfg,
- reg_pairs[0].val);
+ tp_reg_field_write(&tp_data->phy_pll_cfg, reg_pairs[0].val);
for (i = 1; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
+ tp_reg_write(reg_base, reg_pairs[i].off,
reg_pairs[i].val);
}
@@ -2619,9 +2302,9 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
reg_pairs = xcvr_diag_vals->reg_pairs;
num_regs = xcvr_diag_vals->num_regs;
for (i = 0; i < num_lanes; i++) {
- regmap = tp_data->regmap_tx_lane_cdb[i + mlane];
+ reg_base = &tp_data->reg_tx_lane_cdb[i + mlane];
for (j = 0; j < num_regs; j++)
- regmap_write(regmap, reg_pairs[j].off,
+ tp_reg_write(reg_base, reg_pairs[j].off,
reg_pairs[j].val);
}
}
@@ -2633,9 +2316,9 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
if (pcs_cmn_vals) {
reg_pairs = pcs_cmn_vals->reg_pairs;
num_regs = pcs_cmn_vals->num_regs;
- regmap = tp_data->regmap_phy_pcs_common_cdb;
+ reg_base = &tp_data->reg_phy_pcs_common_cdb;
for (i = 0; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
+ tp_reg_write(reg_base, reg_pairs[i].off,
reg_pairs[i].val);
}
@@ -2647,9 +2330,9 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
if (phy_pma_cmn_vals) {
reg_pairs = phy_pma_cmn_vals->reg_pairs;
num_regs = phy_pma_cmn_vals->num_regs;
- regmap = tp_data->regmap_phy_pma_common_cdb;
+ reg_base = &tp_data->reg_phy_pma_common_cdb;
for (i = 0; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
+ tp_reg_write(reg_base, reg_pairs[i].off,
reg_pairs[i].val);
}
@@ -2660,9 +2343,9 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
if (cmn_vals) {
reg_pairs = cmn_vals->reg_pairs;
num_regs = cmn_vals->num_regs;
- regmap = tp_data->regmap_common_cdb;
+ reg_base = &tp_data->reg_common_cdb;
for (i = 0; i < num_regs; i++)
- regmap_write(regmap, reg_pairs[i].off,
+ tp_reg_write(reg_base, reg_pairs[i].off,
reg_pairs[i].val);
}
@@ -2674,9 +2357,9 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
reg_pairs = tx_ln_vals->reg_pairs;
num_regs = tx_ln_vals->num_regs;
for (i = 0; i < num_lanes; i++) {
- regmap = tp_data->regmap_tx_lane_cdb[i + mlane];
+ reg_base = &tp_data->reg_tx_lane_cdb[i + mlane];
for (j = 0; j < num_regs; j++)
- regmap_write(regmap, reg_pairs[j].off,
+ tp_reg_write(reg_base, reg_pairs[j].off,
reg_pairs[j].val);
}
}
@@ -2689,9 +2372,9 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
reg_pairs = rx_ln_vals->reg_pairs;
num_regs = rx_ln_vals->num_regs;
for (i = 0; i < num_lanes; i++) {
- regmap = tp_data->regmap_rx_lane_cdb[i + mlane];
+ reg_base = &tp_data->reg_rx_lane_cdb[i + mlane];
for (j = 0; j < num_regs; j++)
- regmap_write(regmap, reg_pairs[j].off,
+ tp_reg_write(reg_base, reg_pairs[j].off,
reg_pairs[j].val);
}
}
@@ -2888,6 +2571,13 @@ static int cdns_torrent_clk(struct tp_data *tp_data)
return ret;
}
+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);
+
+ return (val & 0x0001) != 0;
+}
+
static int cdns_torrent_phy_probe(struct platform_device *pdev)
{
struct tp_data *tp_data;
@@ -2897,7 +2587,6 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
struct device_node *child;
int ret, subnodes, node = 0, i;
u32 total_num_lanes = 0;
- u8 init_dp_regmap = 0;
u32 phy_type;
/* Get init data for this PHY */
@@ -2924,13 +2613,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
return -EINVAL;
}
- ret = cdns_torrent_regmap_init(tp_data);
- if (ret)
- return ret;
-
- ret = cdns_torrent_regfield_init(tp_data);
- if (ret)
- return ret;
+ tp_reg_bases_init(tp_data);
+ tp_reg_fields_init(tp_data);
ret = tp_clk_register(tp_data);
if (ret)
@@ -2944,8 +2628,7 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
if (ret)
goto clk_cleanup;
- regmap_field_read(tp_data->phy_pma_cmn_ctrl_1, &tp_data->already_configured);
-
+ tp_data->already_configured = tp_is_already_configured(tp_data);
if (!tp_data->already_configured) {
ret = cdns_torrent_clk(tp_data);
if (ret)
@@ -3073,18 +2756,6 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_child;
}
- if (!init_dp_regmap) {
- ret = cdns_torrent_dp_regmap_init(tp_data);
- if (ret)
- goto put_child;
-
- ret = cdns_torrent_dp_regfield_init(tp_data);
- if (ret)
- goto put_child;
-
- init_dp_regmap++;
- }
-
dev_dbg(dev, "DP max bit rate %d.%03d Gbps\n",
tp_data->max_bit_rate / 1000,
tp_data->max_bit_rate % 1000);
--
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] 28+ messages in thread* [PATCH v2 09/22] phy: cadence-torrent: move refclk clk_init_data to the stack
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (6 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 08/22] phy: cadence-torrent: replace regmap with readw/writew Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 10/22] phy: cadence-torrent: drop diag_tx_drv from DP voltage coeff Benjamin Robin
` (11 subsequent siblings)
19 siblings, 0 replies; 28+ 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
Simplify registration of the three refclk-related clocks by building
their struct clk_init_data on the stack instead of keeping a
clk_init_data member in each clock structure. parent_names becomes a
fixed-size stack array, dropping a devm_kzalloc().
struct cdns_torrent_derived_refclk and struct cdns_torrent_received_refclk
are removed; each clock now embeds a plain struct clk_hw in struct tp_data.
The container_of helpers are replaced so the clock ops reach struct
tp_data directly and use the phy_pipe_cmn_ctrl1_0/cmn_cdiag_refclk_ovrd_4
fields already stored there, instead of going through a per-clock wrapper.
No functional change intended.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 144 +++++++++++-------------------
1 file changed, 51 insertions(+), 93 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 2bdc63caec1e..d626e3780cf6 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -276,32 +276,17 @@ static const u32 tp_refclk_driver_mux_table[] = { 1, 0 };
struct tp_refclk_driver {
struct clk_hw hw;
struct tp_reg_field fields[TP_REFCLK_OUT_NUM_CMN_CONFIG];
- struct clk_init_data clk_data;
u8 parent_index;
};
#define tp_refclk_driver_to_clk_data(_hw) \
container_of(_hw, struct tp_refclk_driver, hw)
-struct cdns_torrent_derived_refclk {
- struct clk_hw hw;
- struct tp_reg_field *phy_pipe_cmn_ctrl1_0;
- struct tp_reg_field *cmn_cdiag_refclk_ovrd_4;
- struct clk_init_data clk_data;
-};
+#define tp_derived_refclk_to_tp_data(_hw) \
+ container_of(_hw, struct tp_data, derived_refclk)
-#define to_cdns_torrent_derived_refclk(_hw) \
- container_of(_hw, struct cdns_torrent_derived_refclk, hw)
-
-struct cdns_torrent_received_refclk {
- struct clk_hw hw;
- struct tp_reg_field *phy_pipe_cmn_ctrl1_0;
- struct tp_reg_field *cmn_cdiag_refclk_ovrd_4;
- struct clk_init_data clk_data;
-};
-
-#define to_cdns_torrent_received_refclk(_hw) \
- container_of(_hw, struct cdns_torrent_received_refclk, hw)
+#define tp_received_refclk_to_tp_data(_hw) \
+ container_of(_hw, struct tp_data, received_refclk)
enum cdns_torrent_phy_type {
TYPE_NONE,
@@ -394,8 +379,8 @@ struct tp_data {
struct clk_hw_onecell_data *clk_hw_data;
struct tp_refclk_driver refclk_driver;
- struct cdns_torrent_derived_refclk derived_refclk;
- struct cdns_torrent_received_refclk received_refclk;
+ struct clk_hw derived_refclk;
+ struct clk_hw received_refclk;
};
enum phy_powerstate {
@@ -1665,28 +1650,28 @@ static int cdns_torrent_dp_multilink_init(struct tp_data *tp_data,
static int tp_derived_refclk_enable(struct clk_hw *hw)
{
- struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
+ struct tp_data *tp_data = tp_derived_refclk_to_tp_data(hw);
- tp_reg_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 1);
- tp_reg_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 1);
+ tp_reg_field_write(&tp_data->cmn_cdiag_refclk_ovrd_4, 1);
+ tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 1);
return 0;
}
static void tp_derived_refclk_disable(struct clk_hw *hw)
{
- struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
+ struct tp_data *tp_data = tp_derived_refclk_to_tp_data(hw);
- tp_reg_field_write(derived_refclk->phy_pipe_cmn_ctrl1_0, 0);
- tp_reg_field_write(derived_refclk->cmn_cdiag_refclk_ovrd_4, 0);
+ tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 0);
+ tp_reg_field_write(&tp_data->cmn_cdiag_refclk_ovrd_4, 0);
}
static int tp_derived_refclk_is_enabled(struct clk_hw *hw)
{
- struct cdns_torrent_derived_refclk *derived_refclk = to_cdns_torrent_derived_refclk(hw);
+ struct tp_data *tp_data = tp_derived_refclk_to_tp_data(hw);
u16 val;
- val = tp_reg_field_read(derived_refclk->cmn_cdiag_refclk_ovrd_4);
+ val = tp_reg_field_read(&tp_data->cmn_cdiag_refclk_ovrd_4);
return !!val;
}
@@ -1698,17 +1683,14 @@ static const struct clk_ops tp_derived_refclk_ops = {
static int tp_derived_refclk_register(struct tp_data *tp_data)
{
- struct cdns_torrent_derived_refclk *derived_refclk;
+ struct clk_init_data init_data = { .flags = 0 };
struct device *dev = tp_data->dev;
- struct clk_init_data *init;
const char *parent_name;
char clk_name[100];
struct clk_hw *hw;
struct clk *clk;
int ret;
- derived_refclk = &tp_data->derived_refclk;
-
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
tp_clk_names[CDNS_TORRENT_DERIVED_REFCLK]);
@@ -1718,23 +1700,16 @@ static int tp_derived_refclk_register(struct tp_data *tp_data)
return PTR_ERR(clk);
}
- init = &derived_refclk->clk_data;
-
if (clk) {
parent_name = __clk_get_name(clk);
- init->parent_names = &parent_name;
- init->num_parents = 1;
+ init_data.parent_names = &parent_name;
+ init_data.num_parents = 1;
}
- init->ops = &tp_derived_refclk_ops;
- init->flags = 0;
- init->name = clk_name;
+ init_data.ops = &tp_derived_refclk_ops;
+ init_data.name = clk_name;
- derived_refclk->phy_pipe_cmn_ctrl1_0 = &tp_data->phy_pipe_cmn_ctrl1_0;
- derived_refclk->cmn_cdiag_refclk_ovrd_4 = &tp_data->cmn_cdiag_refclk_ovrd_4;
-
- derived_refclk->hw.init = init;
-
- hw = &derived_refclk->hw;
+ hw = &tp_data->derived_refclk;
+ hw->init = &init_data;
ret = devm_clk_hw_register(dev, hw);
if (ret)
return ret;
@@ -1746,26 +1721,26 @@ static int tp_derived_refclk_register(struct tp_data *tp_data)
static int tp_received_refclk_enable(struct clk_hw *hw)
{
- struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
+ struct tp_data *tp_data = tp_received_refclk_to_tp_data(hw);
- tp_reg_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 1);
+ tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 1);
return 0;
}
static void tp_received_refclk_disable(struct clk_hw *hw)
{
- struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
+ struct tp_data *tp_data = tp_received_refclk_to_tp_data(hw);
- tp_reg_field_write(received_refclk->phy_pipe_cmn_ctrl1_0, 0);
+ tp_reg_field_write(&tp_data->phy_pipe_cmn_ctrl1_0, 0);
}
static int tp_received_refclk_is_enabled(struct clk_hw *hw)
{
- struct cdns_torrent_received_refclk *received_refclk = to_cdns_torrent_received_refclk(hw);
+ struct tp_data *tp_data = tp_received_refclk_to_tp_data(hw);
u16 val, cmn_val;
- val = tp_reg_field_read(received_refclk->phy_pipe_cmn_ctrl1_0);
- cmn_val = tp_reg_field_read(received_refclk->cmn_cdiag_refclk_ovrd_4);
+ val = tp_reg_field_read(&tp_data->phy_pipe_cmn_ctrl1_0);
+ cmn_val = tp_reg_field_read(&tp_data->cmn_cdiag_refclk_ovrd_4);
return val && !cmn_val;
}
@@ -1778,17 +1753,14 @@ static const struct clk_ops tp_received_refclk_ops = {
static int tp_received_refclk_register(struct tp_data *tp_data)
{
- struct cdns_torrent_received_refclk *received_refclk;
+ struct clk_init_data init_data = { .flags = 0 };
struct device *dev = tp_data->dev;
- struct clk_init_data *init;
const char *parent_name;
char clk_name[100];
struct clk_hw *hw;
struct clk *clk;
int ret;
- received_refclk = &tp_data->received_refclk;
-
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
tp_clk_names[CDNS_TORRENT_RECEIVED_REFCLK]);
@@ -1798,23 +1770,16 @@ static int tp_received_refclk_register(struct tp_data *tp_data)
return PTR_ERR(clk);
}
- init = &received_refclk->clk_data;
-
if (clk) {
parent_name = __clk_get_name(clk);
- init->parent_names = &parent_name;
- init->num_parents = 1;
+ init_data.parent_names = &parent_name;
+ init_data.num_parents = 1;
}
- init->ops = &tp_received_refclk_ops;
- init->flags = 0;
- init->name = clk_name;
+ init_data.ops = &tp_received_refclk_ops;
+ init_data.name = clk_name;
- received_refclk->phy_pipe_cmn_ctrl1_0 = &tp_data->phy_pipe_cmn_ctrl1_0;
- received_refclk->cmn_cdiag_refclk_ovrd_4 = &tp_data->cmn_cdiag_refclk_ovrd_4;
-
- received_refclk->hw.init = init;
-
- hw = &received_refclk->hw;
+ hw = &tp_data->received_refclk;
+ hw->init = &init_data;
ret = devm_clk_hw_register(dev, hw);
if (ret)
return ret;
@@ -1865,6 +1830,9 @@ static int tp_refclk_driver_set_parent(struct clk_hw *hw, u8 index)
struct tp_refclk_driver *refclk = tp_refclk_driver_to_clk_data(hw);
u16 val;
+ if (index >= ARRAY_SIZE(tp_refclk_driver_mux_table))
+ return -EINVAL;
+
val = tp_refclk_driver_mux_table[index];
tp_reg_field_write(&refclk->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], val);
return 0;
@@ -1881,23 +1849,16 @@ static const struct clk_ops tp_refclk_driver_ops = {
static int tp_refclk_driver_register(struct tp_data *tp_data)
{
- struct tp_refclk_driver *refclk_driver;
+ struct clk_init_data init_data = { .flags = 0 };
struct device *dev = tp_data->dev;
- struct clk_init_data *init;
- const char **parent_names;
- unsigned int num_parents;
+ const char *parent_names[ARRAY_SIZE(tp_refclk_driver_parent_idx)];
+ u32 num_parents;
char clk_name[100];
struct clk_hw *hw;
- int i, ret;
-
- refclk_driver = &tp_data->refclk_driver;
+ int ret;
num_parents = ARRAY_SIZE(tp_refclk_driver_parent_idx);
- parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), GFP_KERNEL);
- if (!parent_names)
- return -ENOMEM;
-
- for (i = 0; i < num_parents; i++) {
+ for (u32 i = 0; i < num_parents; ++i) {
hw = tp_data->clk_hw_data->hws[tp_refclk_driver_parent_idx[i]];
if (IS_ERR_OR_NULL(hw)) {
dev_err(dev, "No parent clock for refclk driver clock\n");
@@ -1909,20 +1870,17 @@ static int tp_refclk_driver_register(struct tp_data *tp_data)
snprintf(clk_name, sizeof(clk_name), "%s_%s", dev_name(dev),
tp_clk_names[CDNS_TORRENT_REFCLK_DRIVER]);
- init = &refclk_driver->clk_data;
-
- init->ops = &tp_refclk_driver_ops;
- init->flags = CLK_SET_RATE_NO_REPARENT;
- init->parent_names = parent_names;
- init->num_parents = num_parents;
- init->name = clk_name;
+ init_data.ops = &tp_refclk_driver_ops;
+ init_data.flags = CLK_SET_RATE_NO_REPARENT;
+ init_data.parent_names = parent_names;
+ init_data.num_parents = num_parents;
+ init_data.name = clk_name;
/* Enable Derived reference clock as default */
- tp_reg_field_write(&refclk_driver->fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1);
+ tp_reg_field_write(&tp_data->refclk_driver.fields[CMN_CDIAG_REFCLK_DRV0_CTRL_4], 1);
- refclk_driver->hw.init = init;
-
- hw = &refclk_driver->hw;
+ hw = &tp_data->refclk_driver.hw;
+ hw->init = &init_data;
ret = devm_clk_hw_register(dev, hw);
if (ret)
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] 28+ messages in thread* [PATCH v2 10/22] phy: cadence-torrent: drop diag_tx_drv from DP voltage coeff
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (7 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 09/22] phy: cadence-torrent: move refclk clk_init_data to the stack Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config Benjamin Robin
` (10 subsequent siblings)
19 siblings, 0 replies; 28+ 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
The DRV_DIAG_TX_DRV register is always written with the same value
(0x0003) regardless of the voltage swing / pre-emphasis combination, so
the diag_tx_drv member of the DisplayPort voltage coefficient structure
only ever held a single constant and carried no information.
Remove the diag_tx_drv member and write the constant directly at the
call site, which also shrinks the coefficient table. Along the way, the
structure and table are renamed to tp_dp_vltg_coeff and
tp_dp_vltg_coeff_table for consistency with the rest of the driver.
No functional change intended.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 66 ++++++++++++-------------------
1 file changed, 25 insertions(+), 41 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index d626e3780cf6..28627bd23445 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -445,9 +445,7 @@ static const struct cdns_torrent_vals *cdns_torrent_get_tbl_vals(const struct cd
* coefficients, for particular voltage swing and pre-emphasis level. Values
* are shared across all physical lanes.
*/
-struct coefficients {
- /* Value of DRV_DIAG_TX_DRV register to use */
- u16 diag_tx_drv;
+struct tp_dp_vltg_coeff {
/* Value of TX_TXCC_MGNFS_MULT_000 register to use */
u16 mgnfs_mult;
/* Value of TX_TXCC_CPOST_MULT_00 register to use */
@@ -458,53 +456,40 @@ struct coefficients {
* Array consists of values of voltage-related registers for sd0801 PHY. A value
* of 0xFFFF is a placeholder for invalid combination, and will never be used.
*/
-static const struct coefficients vltg_coeff[4][4] = {
+static const struct tp_dp_vltg_coeff tp_dp_vltg_coeff_table[4][4] = {
/* voltage swing 0, pre-emphasis 0->3 */
- { {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x002A,
- .cpost_mult = 0x0000},
- {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x001F,
- .cpost_mult = 0x0014},
- {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0012,
- .cpost_mult = 0x0020},
- {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
- .cpost_mult = 0x002A}
+ {
+ { .mgnfs_mult = 0x002A, .cpost_mult = 0x0000 },
+ { .mgnfs_mult = 0x001F, .cpost_mult = 0x0014 },
+ { .mgnfs_mult = 0x0012, .cpost_mult = 0x0020 },
+ { .mgnfs_mult = 0x0000, .cpost_mult = 0x002A },
},
/* voltage swing 1, pre-emphasis 0->3 */
- { {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x001F,
- .cpost_mult = 0x0000},
- {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0013,
- .cpost_mult = 0x0012},
- {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
- .cpost_mult = 0x001F},
- {.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
- .cpost_mult = 0xFFFF}
+ {
+ { .mgnfs_mult = 0x001F, .cpost_mult = 0x0000 },
+ { .mgnfs_mult = 0x0013, .cpost_mult = 0x0012 },
+ { .mgnfs_mult = 0x0000, .cpost_mult = 0x001F },
+ { .mgnfs_mult = 0xFFFF, .cpost_mult = 0xFFFF },
},
/* voltage swing 2, pre-emphasis 0->3 */
- { {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0013,
- .cpost_mult = 0x0000},
- {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
- .cpost_mult = 0x0013},
- {.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
- .cpost_mult = 0xFFFF},
- {.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
- .cpost_mult = 0xFFFF}
+ {
+ { .mgnfs_mult = 0x0013, .cpost_mult = 0x0000 },
+ { .mgnfs_mult = 0x0000, .cpost_mult = 0x0013 },
+ { .mgnfs_mult = 0xFFFF, .cpost_mult = 0xFFFF },
+ { .mgnfs_mult = 0xFFFF, .cpost_mult = 0xFFFF },
},
/* voltage swing 3, pre-emphasis 0->3 */
- { {.diag_tx_drv = 0x0003, .mgnfs_mult = 0x0000,
- .cpost_mult = 0x0000},
- {.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
- .cpost_mult = 0xFFFF},
- {.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
- .cpost_mult = 0xFFFF},
- {.diag_tx_drv = 0xFFFF, .mgnfs_mult = 0xFFFF,
- .cpost_mult = 0xFFFF}
+ {
+ { .mgnfs_mult = 0x0000, .cpost_mult = 0x0000 },
+ { .mgnfs_mult = 0xFFFF, .cpost_mult = 0xFFFF },
+ { .mgnfs_mult = 0xFFFF, .cpost_mult = 0xFFFF },
+ { .mgnfs_mult = 0xFFFF, .cpost_mult = 0xFFFF },
}
};
-
static void tp_reg_base_init(const struct tp_data *tp_data, u32 block_offset,
struct tp_reg_base *ctx)
{
@@ -1420,11 +1405,10 @@ static void tp_dp_set_voltages(const struct tp_data *tp_data, const struct tp_li
tp_reg_set_bits(reg_base, TX_DIAG_ACYA, TX_DIAG_ACYA_HBDC_MASK);
tp_reg_write(reg_base, TX_TXCC_CTRL, 0x08A4);
- val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].diag_tx_drv;
- tp_reg_write(reg_base, DRV_DIAG_TX_DRV, val);
- val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult;
+ tp_reg_write(reg_base, DRV_DIAG_TX_DRV, 0x0003);
+ val = tp_dp_vltg_coeff_table[dp->voltage[lane]][dp->pre[lane]].mgnfs_mult;
tp_reg_write(reg_base, TX_TXCC_MGNFS_MULT_000, val);
- val = vltg_coeff[dp->voltage[lane]][dp->pre[lane]].cpost_mult;
+ val = tp_dp_vltg_coeff_table[dp->voltage[lane]][dp->pre[lane]].cpost_mult;
tp_reg_write(reg_base, TX_TXCC_CPOST_MULT_00, val);
/*
--
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] 28+ messages in thread* [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (8 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 10/22] phy: cadence-torrent: drop diag_tx_drv from DP voltage coeff Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:28 ` sashiko-bot
2026-12-02 15:08 ` [PATCH v2 12/22] phy: cadence-torrent: use devm_of_clk_add_hw_provider() Benjamin Robin
` (9 subsequent siblings)
19 siblings, 1 reply; 28+ 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
The dp->lanes field of struct phy_configure_opts_dp is only valid when
dp->set_lanes is set, but it was used unconditionally when programming
the PLL clock enable, the PCS lane count, the power-state registers and
the lane-reset bits. A rate-only or voltage-only reconfiguration could be
realized based on an invalid lane count.
Split the link lane count into two fields of struct tp_link:
- max_lanes: the number of lanes available on the link (from
cdns,num-lanes, defaulted to DEFAULT_NUM_LANES);
- num_lanes: the number of lanes currently in use.
tp_dp_verify_config() now validates dp->lanes against max_lanes only
when set_lanes is set, and otherwise keeps the current num_lanes.
tp_dp_set_lanes() receives the requested lane count, updates
link->num_lanes once the lanes are programmed.
All outgoing per-lane register values are also shifted by the link
master lane: the PLL enable bits, the PHY_PMA_XCVR_POWER_STATE_REQ lane
fields, the pma_tx_elec_idle mask and the PHY_RESET lane-reset bits are
now relative to link->mlane instead of lane 0. The per-lane loops in
tp_dp_set_lanes() are replaced with single mask compute/apply steps.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 222 ++++++++++++++++--------------
1 file changed, 115 insertions(+), 107 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 28627bd23445..6e48c315e6b1 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -344,8 +344,9 @@ struct tp_link {
struct phy *phy;
struct reset_control *lnk_rst;
enum cdns_torrent_phy_type phy_type;
- u32 mlane;
- u32 num_lanes;
+ u8 mlane;
+ u8 num_lanes;
+ u8 max_lanes;
enum cdns_torrent_ssc_mode ssc_mode;
};
@@ -610,6 +611,25 @@ static const char *cdns_torrent_get_phy_type(enum cdns_torrent_phy_type phy_type
}
}
+static bool tp_dp_is_valid_bit_rate(u32 bit_rate)
+{
+ switch (bit_rate) {
+ case 1620:
+ case 2430:
+ case 3240:
+ case 2160:
+ case 4320:
+ case 2700:
+ case 5400:
+ case 8100:
+ return true;
+ default:
+ break;
+ }
+
+ return false;
+}
+
/*
* Set registers responsible for enabling and configuring SSC, with second and
* third register values provided by parameters.
@@ -972,30 +992,26 @@ static int cdns_torrent_dp_get_pll(struct tp_data *tp_data,
/*
* Enable or disable PLL for selected lanes.
*/
-static int tp_dptx_set_pll_en(struct tp_data *tp_data, struct tp_link *link,
- struct phy_configure_opts_dp *dp, bool enable)
+static int tp_dptx_set_pll_en(const struct tp_data *tp_data, u32 mlane, u32 num_lanes,
+ bool enable)
{
void __iomem *addr;
- u32 rd_val, pll_ack_val;
+ u32 rd_val;
int ret;
- /*
- * Used to determine, which bits to check for or enable in
- * PHY_PMA_XCVR_PLLCLK_EN register.
- */
- u32 pll_bits;
+ /* Used to determine which bits to check for or enable in PHY_PMA_XCVR_PLLCLK_EN reg */
+ u32 pll_bits = ((1U << num_lanes) - 1) << mlane;
/* Used to enable or disable lanes. */
u32 pll_val;
+ u32 pll_ack_val;
- /* Select values of registers and mask, depending on enabled lane count. */
+ /* Select reg value and mask, depending on enabled lane count. */
pll_val = tp_reg_dptx_read(tp_data, PHY_PMA_XCVR_PLLCLK_EN);
if (enable) {
- pll_bits = ((1 << dp->lanes) - 1);
pll_val |= pll_bits;
pll_ack_val = pll_bits;
} else {
- pll_bits = ((1 << link->num_lanes) - 1);
pll_val &= (~pll_bits);
pll_ack_val = 0;
}
@@ -1006,39 +1022,42 @@ static int tp_dptx_set_pll_en(struct tp_data *tp_data, struct tp_link *link,
addr = tp_data->base + PHY_PMA_XCVR_PLLCLK_EN_ACK;
ret = readl_poll_timeout(addr, rd_val, (rd_val & pll_bits) == pll_ack_val, 0,
POLL_TIMEOUT_US);
+ if (ret < 0) {
+ dev_err(tp_data->dev, "timeout waiting for link PLL clock enable ack\n");
+ return ret;
+ }
+
ndelay(100);
- return ret;
+ return 0;
}
-static int tp_dptx_set_power_state(struct tp_data *tp_data, struct tp_link *link,
- u32 num_lanes, enum phy_powerstate powerstate)
+static int tp_dptx_set_power_state(const struct tp_data *tp_data, u32 mlane, u32 num_lanes,
+ enum phy_powerstate powerstate)
{
- /* Register value for power state for a single byte. */
void __iomem *addr;
- u32 value_part, i;
+ u32 value_part;
u32 value = 0;
u32 mask = 0;
u32 read_val;
int ret;
switch (powerstate) {
- case (POWERSTATE_A0):
+ case POWERSTATE_A0:
value_part = 0x01U;
break;
- case (POWERSTATE_A2):
+ case POWERSTATE_A2:
value_part = 0x04U;
break;
+ case POWERSTATE_A3:
default:
- /* Powerstate A3 */
value_part = 0x08U;
break;
}
/* Select values of registers and mask, depending on enabled lane count. */
-
- for (i = 0; i < num_lanes; i++) {
- value |= (value_part << PHY_POWER_STATE_LN(i));
- mask |= (PMA_XCVR_POWER_STATE_REQ_LN_MASK << PHY_POWER_STATE_LN(i));
+ for (u32 i = 0; i < num_lanes; ++i) {
+ value |= value_part << PHY_POWER_STATE_LN(mlane + i);
+ mask |= PMA_XCVR_POWER_STATE_REQ_LN_MASK << PHY_POWER_STATE_LN(mlane + i);
}
/* Set power state A<n>. */
@@ -1073,7 +1092,7 @@ 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, u32 num_lanes)
+static int tp_dp_run(struct tp_data *tp_data, struct tp_link *link)
{
void __iomem *addr;
unsigned int read_val;
@@ -1092,11 +1111,11 @@ static int tp_dp_run(struct tp_data *tp_data, struct tp_link *link, u32 num_lane
ndelay(100);
- ret = tp_dptx_set_power_state(tp_data, link, num_lanes, POWERSTATE_A2);
+ 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, num_lanes, POWERSTATE_A0);
+ ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, POWERSTATE_A0);
return ret;
}
@@ -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);
@@ -1207,56 +1226,46 @@ static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link,
/*
* Verify, that parameters to configure PHY with are correct.
*/
-static int tp_dp_verify_config(struct tp_link *link, struct phy_configure_opts_dp *dp)
+static int tp_dp_verify_config(const struct tp_link *link,
+ const struct phy_configure_opts_dp *dp)
{
- u8 i;
+ u32 num_lanes;
/* If changing link rate was required, verify it's supported. */
if (dp->set_rate) {
- switch (dp->link_rate) {
- case 1620:
- case 2160:
- case 2430:
- case 2700:
- case 3240:
- case 4320:
- case 5400:
- case 8100:
- /* valid bit rate */
- break;
- default:
+ if (!tp_dp_is_valid_bit_rate(dp->link_rate))
return -EINVAL;
- }
}
/* Verify lane count. */
- switch (dp->lanes) {
- case 1:
- case 2:
- case 4:
- /* valid lane count. */
- break;
- default:
- return -EINVAL;
+ if (dp->set_lanes) {
+ switch (dp->lanes) {
+ case 1:
+ case 2:
+ case 4:
+ /* valid lane count. */
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ /* Check against actual number of PHY's lanes. */
+ if (dp->lanes > link->max_lanes)
+ return -EINVAL;
+
+ num_lanes = dp->lanes;
+ } else {
+ num_lanes = link->num_lanes;
}
- /* Check against actual number of PHY's lanes. */
- if (dp->lanes > link->num_lanes)
- return -EINVAL;
-
- /*
- * If changing voltages is required, check swing and pre-emphasis
- * levels, per-lane.
- */
+ /* If changing voltages is required, check swing and pre-emphasis levels, per-lane. */
if (dp->set_voltages) {
/* Lane count verified previously. */
- for (i = 0; i < dp->lanes; i++) {
+ for (u32 i = 0; i < num_lanes; ++i) {
if (dp->voltage[i] > 3 || dp->pre[i] > 3)
return -EINVAL;
- /* Sum of voltage swing and pre-emphasis levels cannot
- * exceed 3.
- */
+ /* Sum of voltage swing and pre-emphasis levels cannot exceed 3. */
if (dp->voltage[i] + dp->pre[i] > 3)
return -EINVAL;
}
@@ -1286,58 +1295,53 @@ static void cdns_torrent_dp_set_a0_pll(struct tp_data *tp_data,
}
/* Configure lane count as required. */
-static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
- struct phy_configure_opts_dp *dp)
+static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link, u32 num_lanes)
{
- u32 value, i;
+ u32 pma_tx_elec_idle_mask;
+ u32 used_lane_mask;
+ u32 all_lane_mask;
+ u32 value;
+ u32 mlane = link->mlane;
int ret;
- u8 lane_mask = (1 << dp->lanes) - 1;
- u8 pma_tx_elec_idle_mask = 0;
- u32 clane = link->mlane;
- lane_mask <<= clane;
+ used_lane_mask = ((1U << num_lanes) - 1) << mlane;
+ all_lane_mask = ((1U << link->max_lanes) - 1) << mlane;
value = tp_reg_dptx_read(tp_data, PHY_RESET);
+
/* clear pma_tx_elec_idle_ln_* bits. */
- pma_tx_elec_idle_mask = ((1 << link->num_lanes) - 1) << clane;
-
+ pma_tx_elec_idle_mask = ((1U << link->max_lanes) - 1) << mlane;
pma_tx_elec_idle_mask <<= PMA_TX_ELEC_IDLE_SHIFT;
value &= ~pma_tx_elec_idle_mask;
/* Assert pma_tx_elec_idle_ln_* for disabled lanes. */
- value |= ((~lane_mask) << PMA_TX_ELEC_IDLE_SHIFT) &
- pma_tx_elec_idle_mask;
+ value |= ((~used_lane_mask) << PMA_TX_ELEC_IDLE_SHIFT) & pma_tx_elec_idle_mask;
tp_reg_dptx_write(tp_data, PHY_RESET, value);
/* reset the link by asserting master lane phy_l0*_reset_n low */
- tp_reg_dptx_write(tp_data, PHY_RESET,
- value & (~(1 << clane)));
+ value &= ~(1U << mlane);
+ tp_reg_dptx_write(tp_data, PHY_RESET, value);
/*
- * Assert lane reset on unused lanes and master lane so they remain in reset
- * and powered down when re-enabling the link
+ * Assert lane reset on unused lanes and master lane so they remain in
+ * reset and powered down when re-enabling the link
*/
- for (i = 0; i < link->num_lanes; i++)
- value &= (~(1 << (clane + i)));
-
- for (i = 1; i < link->num_lanes; i++)
- value |= ((1 << (clane + i)) & lane_mask);
-
+ value &= ~all_lane_mask;
+ value |= used_lane_mask;
+ value &= ~(1U << mlane);
tp_reg_dptx_write(tp_data, PHY_RESET, value);
- cdns_torrent_dp_set_a0_pll(tp_data, link, dp->lanes);
-
- /* release phy_l0*_reset_n based on used laneCount */
- for (i = 0; i < link->num_lanes; i++)
- value &= (~(1 << (clane + i)));
-
- for (i = 0; i < link->num_lanes; i++)
- value |= ((1 << (clane + i)) & lane_mask);
+ cdns_torrent_dp_set_a0_pll(tp_data, link, link->max_lanes);
+ /* 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);
if (ret)
@@ -1347,10 +1351,10 @@ static int tp_dp_set_lanes(struct tp_data *tp_data, struct tp_link *link,
/* 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 << clane);
+ value |= 1 << mlane;
tp_reg_dptx_write(tp_data, PHY_PMA_XCVR_PLLCLK_EN, value);
- ret = tp_dp_run(tp_data, link, dp->lanes);
+ ret = tp_dp_run(tp_data, link);
return ret;
}
@@ -1361,10 +1365,10 @@ static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
{
int ret;
- ret = tp_dptx_set_power_state(tp_data, link, dp->lanes, POWERSTATE_A3);
+ ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, POWERSTATE_A3);
if (ret)
return ret;
- ret = tp_dptx_set_pll_en(tp_data, link, dp, false);
+ ret = tp_dptx_set_pll_en(tp_data, link->mlane, link->max_lanes, false);
if (ret)
return ret;
ndelay(200);
@@ -1374,13 +1378,13 @@ static int tp_dp_set_rate(struct tp_data *tp_data, struct tp_link *link,
return ret;
ndelay(200);
- ret = tp_dptx_set_pll_en(tp_data, link, dp, true);
+ 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, dp->lanes, POWERSTATE_A2);
+ 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, dp->lanes, POWERSTATE_A0);
+ ret = tp_dptx_set_power_state(tp_data, link->mlane, link->num_lanes, POWERSTATE_A0);
if (ret)
return ret;
ndelay(900);
@@ -1435,7 +1439,7 @@ static int tp_phy_configure(struct phy *phy, union phy_configure_opts *opts)
}
if (opts->dp.set_lanes) {
- ret = tp_dp_set_lanes(tp_data, link, &opts->dp);
+ 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;
@@ -1587,7 +1591,7 @@ static int cdns_torrent_dp_start(struct tp_data *tp_data, struct tp_link *link,
if (ret)
return ret;
- ret = tp_dp_run(tp_data, link, link->num_lanes);
+ ret = tp_dp_run(tp_data, link);
return ret;
}
@@ -2525,6 +2529,7 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
struct tp_data *tp_data;
struct device *dev = &pdev->dev;
struct phy_provider *phy_provider;
+ u32 num_lanes = DEFAULT_NUM_LANES;
const struct cdns_torrent_data *data;
struct device_node *child;
int ret, subnodes, node = 0, i;
@@ -2582,6 +2587,7 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
for_each_available_child_of_node(dev->of_node, child) {
struct phy *gphy;
+ u32 mlane;
/* PHY subnode name must be 'phy'. */
if (!(of_node_name_eq(child, "phy")))
@@ -2596,14 +2602,15 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_lnk_rst;
}
- if (of_property_read_u32(child, "reg",
- &tp_data->links[node].mlane)) {
+ if (of_property_read_u32(child, "reg", &mlane)) {
dev_err(dev, "%s: No \"reg\"-property.\n",
child->full_name);
ret = -EINVAL;
goto put_child;
}
+ tp_data->links[node].mlane = mlane;
+
if (of_property_read_u32(child, "cdns,phy-type", &phy_type)) {
dev_err(dev, "%s: No \"cdns,phy-type\"-property.\n",
child->full_name);
@@ -2639,10 +2646,11 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
goto put_child;
}
- tp_data->links[node].num_lanes = DEFAULT_NUM_LANES;
- of_property_read_u32(child, "cdns,num-lanes", &tp_data->links[node].num_lanes);
+ of_property_read_u32(child, "cdns,num-lanes", &num_lanes);
+ tp_data->links[node].num_lanes = num_lanes;
+ tp_data->links[node].max_lanes = num_lanes;
- total_num_lanes += tp_data->links[node].num_lanes;
+ total_num_lanes += num_lanes;
/* Get SSC mode */
tp_data->links[node].ssc_mode = NO_SSC;
--
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] 28+ messages in thread* Re: [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config
2026-12-02 15:08 ` [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config Benjamin Robin
@ 2026-12-02 15:28 ` sashiko-bot
0 siblings, 0 replies; 28+ 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] 28+ messages in thread
* [PATCH v2 12/22] phy: cadence-torrent: use devm_of_clk_add_hw_provider()
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (9 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 11/22] phy: cadence-torrent: use link lane count and mlane for DP config Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:08 ` [PATCH v2 13/22] phy: cadence-torrent: rework subnode parsing and lane validation Benjamin Robin
` (8 subsequent siblings)
19 siblings, 0 replies; 28+ 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
Use devm_of_clk_add_hw_provider() instead of of_clk_add_hw_provider()
so that the clock provider is unregistered automatically, both on driver
removal and on a late probe failure.
This lets us drop the now-unnecessary cdns_torrent_clk_cleanup() helper.
No functional change intended.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 6e48c315e6b1..59b61dd8e54a 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -2348,17 +2348,9 @@ int cdns_torrent_phy_configure_multilink(struct tp_data *tp_data)
return 0;
}
-static void cdns_torrent_clk_cleanup(struct tp_data *tp_data)
-{
- struct device *dev = tp_data->dev;
-
- of_clk_del_provider(dev->of_node);
-}
-
static int tp_clk_register(struct tp_data *tp_data)
{
struct device *dev = tp_data->dev;
- struct device_node *node = dev->of_node;
struct clk_hw_onecell_data *data;
int ret;
@@ -2387,9 +2379,9 @@ static int tp_clk_register(struct tp_data *tp_data)
return ret;
}
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, data);
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, data);
if (ret) {
- dev_err(dev, "Failed to add clock provider: %s\n", node->name);
+ dev_err(dev, "Failed to add clock provider\n");
return ret;
}
@@ -2763,7 +2755,6 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
clk_disable_unprepare(tp_data->clk1);
clk_disable_unprepare(tp_data->clk);
clk_cleanup:
- cdns_torrent_clk_cleanup(tp_data);
return ret;
}
@@ -2781,7 +2772,6 @@ static void cdns_torrent_phy_remove(struct platform_device *pdev)
clk_disable_unprepare(tp_data->clk1);
clk_disable_unprepare(tp_data->clk);
- cdns_torrent_clk_cleanup(tp_data);
}
/* Multilink PCIe and USB Same SSC link configuration */
--
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] 28+ messages in thread* [PATCH v2 13/22] phy: cadence-torrent: rework subnode parsing and lane validation
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (10 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 12/22] phy: cadence-torrent: use devm_of_clk_add_hw_provider() Benjamin Robin
@ 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)
19 siblings, 0 replies; 28+ 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
Extract the per-subnode handling from the probe function into a new
tp_add_phy_from_of_subnode() helper that fully sets up a single PHY link:
it reads the various properties and validates the lane mapping. The probe
now just iterates over the device-tree children and calls the helper.
Lane assignment is checked by a new tp_set_used_lanes() helper instead
of the previous whole-device lane count. It validates the requested
(mlane, num_lanes) range against the lanes available on the PHY
(mask_available_lanes) and rejects configurations that overlap with
lanes already claimed by another link (mask_used_lanes).
max_bit_rate moves from struct tp_data to struct tp_link: it is a
per-link attribute (parsed from the cdns,max-bit-rate property), not a
Torrent PHY-wide value.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 363 +++++++++++++++++-------------
1 file changed, 201 insertions(+), 162 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 59b61dd8e54a..69e5323b1d68 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -347,13 +347,13 @@ struct tp_link {
u8 mlane;
u8 num_lanes;
u8 max_lanes;
+ u16 max_bit_rate; /* Maximum link bit rate to use (in Mbps) */
enum cdns_torrent_ssc_mode ssc_mode;
};
struct tp_data {
void __iomem *base; /* DPTX registers base */
void __iomem *sd_base; /* SD0801 registers base */
- u32 max_bit_rate; /* Maximum link bit rate to use (in Mbps) */
u32 dp_pll;
u32 protocol_bitmask;
struct reset_control *phy_rst;
@@ -363,6 +363,8 @@ struct tp_data {
struct clk *clk1;
enum cdns_torrent_ref_clk ref_clk_rate;
enum cdns_torrent_ref_clk ref_clk1_rate;
+ u8 mask_used_lanes;
+
struct tp_link links[MAX_NUM_LANES];
int nb_links;
int already_configured;
@@ -414,6 +416,7 @@ struct cdns_torrent_vals_table {
struct cdns_torrent_data {
u8 block_offset_shift;
u8 reg_offset_shift;
+ u8 mask_available_lanes;
struct cdns_torrent_vals_table link_cmn_vals_tbl;
struct cdns_torrent_vals_table xcvr_diag_vals_tbl;
struct cdns_torrent_vals_table pcs_cmn_vals_tbl;
@@ -1560,20 +1563,13 @@ static void cdns_torrent_dp_common_init(struct tp_data *tp_data,
* Initialize PHY with max supported link rate, without SSC.
*/
if (tp_data->ref_clk_rate == CLK_19_2_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data,
- tp_data->max_bit_rate,
- false);
+ cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data, link->max_bit_rate, false);
else if (tp_data->ref_clk_rate == CLK_25_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data,
- tp_data->max_bit_rate,
- false);
+ cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data, link->max_bit_rate, false);
else if (tp_data->ref_clk_rate == CLK_100_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data,
- tp_data->max_bit_rate,
- false);
+ cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, link->max_bit_rate, false);
- cdns_torrent_dp_pma_cmn_rate(tp_data, link, tp_data->max_bit_rate,
- link->num_lanes);
+ cdns_torrent_dp_pma_cmn_rate(tp_data, link, link->max_bit_rate, link->num_lanes);
/* take out of reset */
tp_dptx_deassert_phy_reset(tp_data);
@@ -2509,6 +2505,173 @@ static int cdns_torrent_clk(struct tp_data *tp_data)
return ret;
}
+static int tp_set_used_lanes(struct tp_data *tp_data, u32 mlane, u32 num_lanes)
+{
+ u8 mask_available_lanes;
+ u8 mask_lanes;
+
+ if (((mlane + num_lanes) > MAX_NUM_LANES) || num_lanes == 0)
+ goto invalid_lanes;
+
+ mask_lanes = GENMASK_U8(mlane + num_lanes - 1, mlane);
+ mask_available_lanes = tp_data->init_data->mask_available_lanes;
+
+ if ((mask_lanes & mask_available_lanes) != mask_lanes)
+ goto invalid_lanes;
+
+ if (mask_lanes & tp_data->mask_used_lanes)
+ goto invalid_lanes;
+
+ tp_data->mask_used_lanes |= mask_lanes;
+ return 0;
+
+invalid_lanes:
+ dev_err(tp_data->dev, "Invalid lane configuration\n");
+ return -EINVAL;
+}
+
+static int tp_add_phy_from_of_subnode(struct tp_data *tp_data, struct device_node *child)
+{
+ enum cdns_torrent_phy_type std_type = TYPE_NONE;
+ u32 ssc_mode = CDNS_SERDES_NO_SSC;
+ u32 num_lanes = DEFAULT_NUM_LANES;
+ struct device *dev = tp_data->dev;
+ struct tp_link *link = NULL;
+ struct reset_control *lnk_rst;
+ u32 phy_type = PHY_NONE;
+ int ret = -EINVAL;
+ struct phy *gphy;
+ u32 mlane = 0;
+
+ /* First check the master lane and the number of lanes */
+ if (of_property_read_u32(child, "reg", &mlane)) {
+ dev_err(dev, "%s: No \"reg\"-property.\n", child->full_name);
+ return -EINVAL;
+ }
+
+ of_property_read_u32(child, "cdns,num-lanes", &num_lanes);
+
+ ret = tp_set_used_lanes(tp_data, mlane, num_lanes);
+ if (ret)
+ return ret;
+
+ /* Then retrieve associated standard */
+ if (of_property_read_u32(child, "cdns,phy-type", &phy_type)) {
+ dev_err(dev, "%s: No \"cdns,phy-type\"-property.\n", child->full_name);
+ return -EINVAL;
+ }
+
+ /* Get SSC mode */
+ of_property_read_u32(child, "cdns,ssc-mode", &ssc_mode);
+
+ switch (phy_type) {
+ case PHY_TYPE_PCIE:
+ std_type = TYPE_PCIE;
+ break;
+ case PHY_TYPE_DP:
+ std_type = TYPE_DP;
+ break;
+ case PHY_TYPE_SGMII:
+ std_type = TYPE_SGMII;
+ break;
+ case PHY_TYPE_QSGMII:
+ std_type = TYPE_QSGMII;
+ break;
+ case PHY_TYPE_USB3:
+ std_type = TYPE_USB;
+ break;
+ case PHY_TYPE_USXGMII:
+ std_type = TYPE_USXGMII;
+ break;
+ case PHY_TYPE_XAUI:
+ std_type = TYPE_XAUI;
+ break;
+ default:
+ dev_err(dev, "Unsupported protocol: %u\n", phy_type);
+ return -EINVAL;
+ }
+
+ if (tp_data->nb_links >= MAX_NUM_LANES)
+ return -EINVAL;
+
+ /* Get the PHY link */
+ link = &tp_data->links[tp_data->nb_links];
+ tp_data->nb_links += 1;
+
+ lnk_rst = of_reset_control_array_get_exclusive(child);
+ if (IS_ERR(lnk_rst)) {
+ dev_err(dev, "%s: failed to get reset\n", child->full_name);
+ return PTR_ERR(lnk_rst);
+ }
+
+ link->ssc_mode = ssc_mode;
+ link->lnk_rst = lnk_rst;
+ link->phy_type = std_type;
+ link->mlane = mlane;
+ link->num_lanes = num_lanes;
+ link->max_lanes = num_lanes;
+
+ gphy = devm_phy_create(dev, child, &cdns_torrent_phy_ops);
+ if (IS_ERR(gphy))
+ return PTR_ERR(gphy);
+
+ if (phy_type == PHY_TYPE_DP) {
+ u32 max_bit_rate = DEFAULT_MAX_BIT_RATE;
+
+ switch (num_lanes) {
+ case 1:
+ case 2:
+ case 4:
+ /* valid number of lanes */
+ break;
+ default:
+ dev_err(dev, "unsupported number of lanes: %u\n", num_lanes);
+ return -EINVAL;
+ }
+
+ of_property_read_u32(child, "cdns,max-bit-rate", &max_bit_rate);
+ if (!tp_dp_is_valid_bit_rate(max_bit_rate)) {
+ dev_err(dev, "unsupported max bit rate: %u Mbps\n", max_bit_rate);
+ return -EINVAL;
+ }
+
+ link->max_bit_rate = max_bit_rate;
+ gphy->attrs.bus_width = num_lanes;
+ gphy->attrs.max_link_rate = max_bit_rate;
+ gphy->attrs.mode = PHY_MODE_DP;
+ }
+
+ link->phy = gphy;
+ phy_set_drvdata(gphy, link);
+ tp_data->protocol_bitmask |= BIT(std_type);
+
+ return 0;
+}
+
+static int tp_dp_reg_base_init(struct platform_device *pdev, struct tp_data *tp_data)
+{
+ bool has_dp = false;
+
+ for (u8 i = 0; i < tp_data->nb_links; ++i) {
+ if (tp_data->links[i].phy_type == TYPE_DP) {
+ has_dp = true;
+ break;
+ }
+ }
+
+ if (has_dp) {
+ /* DPTX registers */
+ void __iomem *base = devm_platform_ioremap_resource(pdev, 1);
+
+ if (IS_ERR(base))
+ return PTR_ERR(base);
+
+ tp_data->base = base;
+ }
+
+ return 0;
+}
+
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);
@@ -2521,12 +2684,9 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
struct tp_data *tp_data;
struct device *dev = &pdev->dev;
struct phy_provider *phy_provider;
- u32 num_lanes = DEFAULT_NUM_LANES;
const struct cdns_torrent_data *data;
- struct device_node *child;
- int ret, subnodes, node = 0, i;
- u32 total_num_lanes = 0;
- u32 phy_type;
+ struct device_node *child = NULL;
+ int ret;
/* Get init data for this PHY */
data = of_device_get_match_data(dev);
@@ -2546,8 +2706,8 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
if (IS_ERR(tp_data->sd_base))
return PTR_ERR(tp_data->sd_base);
- subnodes = of_get_available_child_count(dev->of_node);
- if (subnodes == 0) {
+ ret = of_get_available_child_count(dev->of_node);
+ if (ret == 0) {
dev_err(dev, "No available link subnodes found\n");
return -EINVAL;
}
@@ -2561,166 +2721,42 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
ret = tp_of_get_reset(tp_data);
if (ret)
- goto clk_cleanup;
+ return ret;
ret = tp_of_get_clk(tp_data);
if (ret)
- goto clk_cleanup;
+ 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)
- goto clk_cleanup;
+ return ret;
/* Enable APB */
reset_control_deassert(tp_data->apb_rst);
}
for_each_available_child_of_node(dev->of_node, child) {
- struct phy *gphy;
- u32 mlane;
-
/* PHY subnode name must be 'phy'. */
- if (!(of_node_name_eq(child, "phy")))
+ if (!of_node_name_eq(child, "phy"))
continue;
- tp_data->links[node].lnk_rst =
- of_reset_control_array_get_exclusive(child);
- if (IS_ERR(tp_data->links[node].lnk_rst)) {
- dev_err(dev, "%s: failed to get reset\n",
- child->full_name);
- ret = PTR_ERR(tp_data->links[node].lnk_rst);
+ ret = tp_add_phy_from_of_subnode(tp_data, child);
+ if (ret)
goto put_lnk_rst;
- }
-
- if (of_property_read_u32(child, "reg", &mlane)) {
- dev_err(dev, "%s: No \"reg\"-property.\n",
- child->full_name);
- ret = -EINVAL;
- goto put_child;
- }
-
- tp_data->links[node].mlane = mlane;
-
- if (of_property_read_u32(child, "cdns,phy-type", &phy_type)) {
- dev_err(dev, "%s: No \"cdns,phy-type\"-property.\n",
- child->full_name);
- ret = -EINVAL;
- goto put_child;
- }
-
- switch (phy_type) {
- case PHY_TYPE_PCIE:
- tp_data->links[node].phy_type = TYPE_PCIE;
- break;
- case PHY_TYPE_DP:
- tp_data->links[node].phy_type = TYPE_DP;
- break;
- case PHY_TYPE_SGMII:
- tp_data->links[node].phy_type = TYPE_SGMII;
- break;
- case PHY_TYPE_QSGMII:
- tp_data->links[node].phy_type = TYPE_QSGMII;
- break;
- case PHY_TYPE_USB3:
- tp_data->links[node].phy_type = TYPE_USB;
- break;
- case PHY_TYPE_USXGMII:
- tp_data->links[node].phy_type = TYPE_USXGMII;
- break;
- case PHY_TYPE_XAUI:
- tp_data->links[node].phy_type = TYPE_XAUI;
- break;
- default:
- dev_err(dev, "Unsupported protocol\n");
- ret = -EINVAL;
- goto put_child;
- }
-
- of_property_read_u32(child, "cdns,num-lanes", &num_lanes);
- tp_data->links[node].num_lanes = num_lanes;
- tp_data->links[node].max_lanes = num_lanes;
-
- total_num_lanes += num_lanes;
-
- /* Get SSC mode */
- tp_data->links[node].ssc_mode = NO_SSC;
- of_property_read_u32(child, "cdns,ssc-mode",
- &tp_data->links[node].ssc_mode);
-
- gphy = devm_phy_create(dev, child, &cdns_torrent_phy_ops);
- if (IS_ERR(gphy)) {
- ret = PTR_ERR(gphy);
- goto put_child;
- }
-
- if (tp_data->links[node].phy_type == TYPE_DP) {
- switch (tp_data->links[node].num_lanes) {
- case 1:
- case 2:
- case 4:
- /* valid number of lanes */
- break;
- default:
- dev_err(dev, "unsupported number of lanes: %d\n",
- tp_data->links[node].num_lanes);
- ret = -EINVAL;
- goto put_child;
- }
-
- tp_data->max_bit_rate = DEFAULT_MAX_BIT_RATE;
- of_property_read_u32(child, "cdns,max-bit-rate",
- &tp_data->max_bit_rate);
-
- switch (tp_data->max_bit_rate) {
- case 1620:
- case 2160:
- case 2430:
- case 2700:
- case 3240:
- case 4320:
- case 5400:
- case 8100:
- /* valid bit rate */
- break;
- default:
- dev_err(dev, "unsupported max bit rate: %dMbps\n",
- tp_data->max_bit_rate);
- ret = -EINVAL;
- goto put_child;
- }
-
- /* DPTX registers */
- tp_data->base = devm_platform_ioremap_resource(pdev, 1);
- if (IS_ERR(tp_data->base)) {
- ret = PTR_ERR(tp_data->base);
- goto put_child;
- }
-
- dev_dbg(dev, "DP max bit rate %d.%03d Gbps\n",
- tp_data->max_bit_rate / 1000,
- tp_data->max_bit_rate % 1000);
-
- gphy->attrs.bus_width = tp_data->links[node].num_lanes;
- gphy->attrs.max_link_rate = tp_data->max_bit_rate;
- gphy->attrs.mode = PHY_MODE_DP;
- }
-
- tp_data->links[node].phy = gphy;
- tp_data->protocol_bitmask |= BIT(tp_data->links[node].phy_type);
- phy_set_drvdata(gphy, &tp_data->links[node]);
-
- node++;
}
- tp_data->nb_links = node;
+ child = NULL;
- if (total_num_lanes > MAX_NUM_LANES) {
- dev_err(dev, "Invalid lane configuration\n");
- ret = -EINVAL;
+ if (tp_data->nb_links == 0) {
+ ret = -ENODEV;
goto put_lnk_rst;
}
+ ret = tp_dp_reg_base_init(pdev, tp_data);
+ if (ret)
+ goto put_lnk_rst;
+
if (tp_data->nb_links > 1 && !tp_data->already_configured) {
ret = cdns_torrent_phy_configure_multilink(tp_data);
if (ret)
@@ -2738,23 +2774,23 @@ static int cdns_torrent_phy_probe(struct platform_device *pdev)
else
dev_dbg(dev, "Single link configuration:\n");
- for (i = 0; i < tp_data->nb_links; i++)
+ for (u8 i = 0; i < tp_data->nb_links; i++)
dev_dbg(dev, "%s (%d lanes)",
cdns_torrent_get_phy_type(tp_data->links[i].phy_type),
tp_data->links[i].num_lanes);
return 0;
-put_child:
- node++;
put_lnk_rst:
- for (i = 0; i < node; i++)
+ 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);
- of_node_put(child);
+
reset_control_assert(tp_data->apb_rst);
clk_disable_unprepare(tp_data->clk1);
clk_disable_unprepare(tp_data->clk);
-clk_cleanup:
return ret;
}
@@ -4937,6 +4973,7 @@ static const struct cdns_torrent_vals_entry cdns_rx_ln_vals_entries[] = {
static const struct cdns_torrent_data cdns_map_torrent = {
.block_offset_shift = 0x2,
.reg_offset_shift = 0x2,
+ .mask_available_lanes = 0x0F,
.link_cmn_vals_tbl = {
.entries = link_cmn_vals_entries,
.num_entries = ARRAY_SIZE(link_cmn_vals_entries),
@@ -5071,6 +5108,7 @@ static const struct cdns_torrent_vals_entry ti_tx_ln_vals_entries[] = {
static const struct cdns_torrent_data ti_j721e_map_torrent = {
.block_offset_shift = 0x0,
.reg_offset_shift = 0x1,
+ .mask_available_lanes = 0x0F,
.link_cmn_vals_tbl = {
.entries = link_cmn_vals_entries,
.num_entries = ARRAY_SIZE(link_cmn_vals_entries),
@@ -5399,6 +5437,7 @@ static const struct cdns_torrent_vals_entry ti_j7200_rx_ln_vals_entries[] = {
static const struct cdns_torrent_data ti_j7200_map_torrent = {
.block_offset_shift = 0x0,
.reg_offset_shift = 0x1,
+ .mask_available_lanes = 0x0F,
.link_cmn_vals_tbl = {
.entries = link_cmn_vals_entries,
.num_entries = ARRAY_SIZE(link_cmn_vals_entries),
--
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] 28+ messages in thread* [PATCH v2 14/22] phy: cadence-torrent: rework ref clock init and probe cleanup
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (11 preceding siblings ...)
2026-12-02 15:08 ` [PATCH v2 13/22] phy: cadence-torrent: rework subnode parsing and lane validation Benjamin Robin
@ 2026-12-02 15:08 ` Benjamin Robin
2026-12-02 15:24 ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 15/22] phy: cadence-torrent: factor out DP PLL frequency update Benjamin Robin
` (6 subsequent siblings)
19 siblings, 1 reply; 28+ 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] 28+ 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; 28+ 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] 28+ messages in thread
* [PATCH v2 15/22] phy: cadence-torrent: factor out DP PLL frequency update
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (12 preceding siblings ...)
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:09 ` [PATCH v2 16/22] phy: cadence-torrent: store clock and reset handles only on success Benjamin Robin
` (5 subsequent siblings)
19 siblings, 0 replies; 28+ 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
Factor the "DP Rate Change - VCO Output settings" sequence, which was
duplicated at the initial PHY configuration and the link rate-change
paths, into a new tp_dp_update_pll_freq() helper.
No functional change intended.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 40 +++++++++++++++----------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index de4ff3a133ff..8acba13ab827 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -1171,6 +1171,23 @@ static void cdns_torrent_dp_pma_cmn_rate(struct tp_data *tp_data,
XCVR_DIAG_HSCLK_DIV, hsclk_div_val);
}
+static void tp_dp_update_pll_freq(struct tp_data *tp_data, struct tp_link *link,
+ u32 bit_rate, bool ssc)
+{
+ /* DP Rate Change - VCO Output settings. */
+ if (tp_data->ref_clk_rate == CLK_19_2_MHZ)
+ /* PMA common configuration 19.2MHz */
+ cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data, bit_rate, ssc);
+ else if (tp_data->ref_clk_rate == CLK_25_MHZ)
+ /* PMA common configuration 25MHz */
+ cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data, bit_rate, ssc);
+ else if (tp_data->ref_clk_rate == CLK_100_MHZ)
+ /* PMA common configuration 100MHz */
+ cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, bit_rate, ssc);
+
+ cdns_torrent_dp_pma_cmn_rate(tp_data, link, bit_rate, link->num_lanes);
+}
+
/*
* Perform register operations related to setting link rate, once powerstate is
* set and PLL disable request was processed.
@@ -1203,18 +1220,8 @@ static int tp_dp_configure_rate(struct tp_data *tp_data, struct tp_link *link,
ndelay(200);
- /* DP Rate Change - VCO Output settings. */
- if (tp_data->ref_clk_rate == CLK_19_2_MHZ)
- /* PMA common configuration 19.2MHz */
- cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data, dp->link_rate, dp->ssc);
- else if (tp_data->ref_clk_rate == CLK_25_MHZ)
- /* PMA common configuration 25MHz */
- cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data, dp->link_rate, dp->ssc);
- else if (tp_data->ref_clk_rate == CLK_100_MHZ)
- /* PMA common configuration 100MHz */
- cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, dp->link_rate, dp->ssc);
-
- cdns_torrent_dp_pma_cmn_rate(tp_data, link, dp->link_rate, link->num_lanes);
+ /* 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);
@@ -1564,14 +1571,7 @@ static void cdns_torrent_dp_common_init(struct tp_data *tp_data,
* PHY PMA registers configuration functions
* Initialize PHY with max supported link rate, without SSC.
*/
- if (tp_data->ref_clk_rate == CLK_19_2_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_19_2mhz(tp_data, link->max_bit_rate, false);
- else if (tp_data->ref_clk_rate == CLK_25_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_25mhz(tp_data, link->max_bit_rate, false);
- else if (tp_data->ref_clk_rate == CLK_100_MHZ)
- cdns_torrent_dp_pma_cmn_vco_cfg_100mhz(tp_data, link->max_bit_rate, false);
-
- cdns_torrent_dp_pma_cmn_rate(tp_data, link, link->max_bit_rate, link->num_lanes);
+ tp_dp_update_pll_freq(tp_data, link, link->max_bit_rate, false);
/* take out of reset */
tp_dptx_deassert_phy_reset(tp_data);
--
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] 28+ messages in thread* [PATCH v2 16/22] phy: cadence-torrent: store clock and reset handles only on success
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (13 preceding siblings ...)
2026-12-02 15:09 ` [PATCH v2 15/22] phy: cadence-torrent: factor out DP PLL frequency update Benjamin Robin
@ 2026-12-02 15:09 ` Benjamin Robin
2026-12-02 15:09 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
` (4 subsequent siblings)
19 siblings, 0 replies; 28+ 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
In tp_of_get_reset() and tp_of_get_clk(), retrieve the clock and reset
handles into local variables and only store them in the tp_data fields
once the lookup has succeeded. On failure, the struct fields stay NULL,
which makes the error and cleanup paths easier to reason about: the code
never has to deal with a phy_data field carrying an ERR_PTR() value.
No functional change intended.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 42 +++++++++++++++++--------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 8acba13ab827..9a2621fb3ac7 100644
--- a/drivers/phy/cadence/phy-cadence-torrent.c
+++ b/drivers/phy/cadence/phy-cadence-torrent.c
@@ -2389,38 +2389,42 @@ static int tp_clk_register(struct tp_data *tp_data)
static int tp_of_get_reset(struct tp_data *tp_data)
{
struct device *dev = tp_data->dev;
+ struct reset_control *rst;
- tp_data->phy_rst = devm_reset_control_get_exclusive_by_index(dev, 0);
- if (IS_ERR(tp_data->phy_rst)) {
- dev_err(dev, "%s: failed to get reset\n",
- dev->of_node->full_name);
- return PTR_ERR(tp_data->phy_rst);
+ rst = devm_reset_control_get_exclusive_by_index(dev, 0);
+ if (IS_ERR(rst)) {
+ dev_err(dev, "%s: failed to get reset\n", dev->of_node->full_name);
+ return PTR_ERR(rst);
}
+ tp_data->phy_rst = rst;
- tp_data->apb_rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb");
- if (IS_ERR(tp_data->apb_rst)) {
- dev_err(dev, "%s: failed to get apb reset\n",
- dev->of_node->full_name);
- return PTR_ERR(tp_data->apb_rst);
+ rst = devm_reset_control_get_optional_exclusive(dev, "torrent_apb");
+ if (IS_ERR(rst)) {
+ dev_err(dev, "%s: failed to get apb reset\n", dev->of_node->full_name);
+ return PTR_ERR(rst);
}
-
+ tp_data->apb_rst = rst;
return 0;
}
static int tp_of_get_clk(struct tp_data *tp_data)
{
+ struct device *dev = tp_data->dev;
+ struct clk *clk;
+
/* refclk: Input reference clock for PLL0 */
- tp_data->clk = devm_clk_get(tp_data->dev, "refclk");
- if (IS_ERR(tp_data->clk))
- return dev_err_probe(tp_data->dev, PTR_ERR(tp_data->clk),
- "phy ref clock not found\n");
+ clk = devm_clk_get(dev, "refclk");
+ if (IS_ERR(clk))
+ return dev_err_probe(dev, PTR_ERR(clk), "phy ref clock not found\n");
+
+ tp_data->clk = clk;
/* refclk1: Input reference clock for PLL1 */
- tp_data->clk1 = devm_clk_get_optional(tp_data->dev, "pll1_refclk");
- if (IS_ERR(tp_data->clk1))
- return dev_err_probe(tp_data->dev, PTR_ERR(tp_data->clk1),
- "phy PLL1 ref clock not found\n");
+ clk = devm_clk_get_optional(dev, "pll1_refclk");
+ if (IS_ERR(clk))
+ return dev_err_probe(dev, PTR_ERR(clk), "phy PLL1 ref clock not found\n");
+ tp_data->clk1 = clk;
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] 28+ messages in thread* [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (14 preceding siblings ...)
2026-12-02 15:09 ` [PATCH v2 16/22] phy: cadence-torrent: store clock and reset handles only on success Benjamin Robin
@ 2026-12-02 15:09 ` Benjamin Robin
2026-12-02 15:37 ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link Benjamin Robin
` (3 subsequent siblings)
19 siblings, 1 reply; 28+ 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] 28+ 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; 28+ 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] 28+ messages in thread
* [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (15 preceding siblings ...)
2026-12-02 15:09 ` [PATCH v2 17/22] phy: cadence-torrent: unify link configuration in the probe Benjamin Robin
@ 2026-12-02 15:09 ` Benjamin Robin
2026-12-02 15:31 ` sashiko-bot
2026-12-02 15:09 ` [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY Benjamin Robin
` (2 subsequent siblings)
19 siblings, 1 reply; 28+ 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
Allow the DisplayPort link to be configured even when the PHY is already
configured, recovering the number of lanes actually in use from the
hardware in that case. When the probe finds the PHY already configured,
the DP lane count is read from the PHY_RESET register.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 36 ++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 3b4d52ee7a53..0cbbedeefd87 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);
+}
+
/* Configure lane count as required. */
static void tp_dp_set_lanes(const struct tp_data *tp_data, struct tp_link *link, u32 num_lanes)
{
@@ -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;
@@ -1617,6 +1635,16 @@ static const struct phy_ops cdns_torrent_phy_ops = {
.owner = THIS_MODULE,
};
+static void tp_init_already_configured_links_opts(struct tp_data *tp_data)
+{
+ 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_find_used_lanes(tp_data, link);
+ }
+}
+
static int tp_derived_refclk_enable(struct clk_hw *hw)
{
struct tp_data *tp_data = tp_derived_refclk_to_tp_data(hw);
@@ -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);
--
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] 28+ messages in thread* Re: [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link
2026-12-02 15:09 ` [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link Benjamin Robin
@ 2026-12-02 15:31 ` sashiko-bot
0 siblings, 0 replies; 28+ 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] 28+ messages in thread
* [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY
2026-12-02 15:08 [PATCH v2 00/22] phy: cadence-torrent: rewrite Torrent PHY driver Benjamin Robin
` (16 preceding siblings ...)
2026-12-02 15:09 ` [PATCH v2 18/22] phy: cadence-torrent: allow config on an already-configured DP link Benjamin Robin
@ 2026-12-02 15:09 ` Benjamin Robin
2026-12-02 15:30 ` sashiko-bot
[not found] ` <20261202-phy-cadence-torrent-ng-v2-20-0b493387347b@bootlin.com>
[not found] ` <20261202-phy-cadence-torrent-ng-v2-21-0b493387347b@bootlin.com>
19 siblings, 1 reply; 28+ 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
The Cadence Torrent PHY (sd0801) supports up to 8 lanes, but the driver
capped the number of lanes at 4. Raise MAX_NUM_LANES to 8, enlarging the
links array and the per-lane register base arrays (TX/RX lane CDB and PHY
PCS lane CDB) accordingly, so the full 8-lane capability can be used.
Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
drivers/phy/cadence/phy-cadence-torrent.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/phy/cadence/phy-cadence-torrent.c b/drivers/phy/cadence/phy-cadence-torrent.c
index 21ad6c30a3f2..5a3e307f6c96 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
#define DEFAULT_MAX_BIT_RATE 8100 /* in Mbps */
#define POLL_TIMEOUT_US 5000
--
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] 28+ messages in thread* Re: [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY
2026-12-02 15:09 ` [PATCH v2 22/22] phy: cadence-torrent: support 8 lanes on the sd0801 PHY Benjamin Robin
@ 2026-12-02 15:30 ` sashiko-bot
0 siblings, 0 replies; 28+ 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] 28+ messages in thread
[parent not found: <20261202-phy-cadence-torrent-ng-v2-20-0b493387347b@bootlin.com>]
* 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; 28+ 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] 28+ messages in thread
[parent not found: <20261202-phy-cadence-torrent-ng-v2-21-0b493387347b@bootlin.com>]
* 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
2026-12-02 17:18 ` Benjamin Robin
0 siblings, 1 reply; 28+ 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] 28+ messages in thread* Re: [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver
2026-12-02 15:38 ` [PATCH v2 21/22] phy: cadence-torrent: rewrite Torrent PHY driver sashiko-bot
@ 2026-12-02 17:18 ` Benjamin Robin
0 siblings, 0 replies; 28+ messages in thread
From: Benjamin Robin @ 2026-12-02 17:18 UTC (permalink / raw)
To: sashiko-reviews
Cc: devicetree, dri-devel, linux-phy, robh, conor+dt, vkoul,
neil.armstrong, olteanv
On Wednesday, December 2, 2026 at 4:38 PM, sashiko-bot@kernel.org wrote:
> 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)
> > + 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.
This is indeed a bug, and will be fixed in v3.
> [ ... ]
>
> > +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.
This is indeed a bug. Previously the configuration was completely disabled.
In the v3 the rate configuration will only be allowed if the reference clock
was initialized.
> [ ... ]
>
> > +/* 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.
This might be an issue. In v3 for the lanes in reset, do not try to go to
POWERSTATE_A3 (ask 0), so it should fix the issue.
> [ ... ]
>
> > +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.
This might be an issue. In v3 if already_configured then the resets will be
controlled normally from tp_phy_on().
The NULL dereference is indeed a bug. To fix it tp_dp_reg_base_init() will
be called earlier in the probe.
> [ ... ]
>
> > +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).
I largely agree with this remark, but this is the current behavior of the
Cadence "Torrent Programmers Guide" spreadsheet. So for now, keep the same
behavior as documented by Cadence, but that seems a bit strange.
> [ ... ]
>
> > + 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.
This is indeed a bug introduced while refactoring and removing the QSGMII flag
from dt-bindings. This will be fixed in v3.
> [ ... ]
>
> > + 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.
The analysis is correct: this is currently not supported. If a user really
wants to do that, they have to declare the sub-nodes in the "right" order:
PCIe first, then USXGMII, even if the USXGMII reg is 0 (the first lane is
lane 0).
To support this use case, the only solution would be to add a new DTS
property to indicate which PLL to use.
The "old" driver behavior is even more broken in this regard, so the new
code should not introduce any issue.
> [ ... ]
>
> > + 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.
This is indeed a bug, which was already mentioned:
> 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.
To fix it tp_dp_reg_base_init() will be called earlier in the probe.
--
Benjamin Robin, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply [flat|nested] 28+ messages in thread