* [PATCH v2] phy: qualcomm: qmp-combo: Differentiate clocks related to the USB block
@ 2026-11-17 23:02 Wesley Cheng
2026-11-17 23:15 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Wesley Cheng @ 2026-11-17 23:02 UTC (permalink / raw)
To: Vinod Koul, Neil Armstrong, Manivannan Sadhasivam
Cc: linux-arm-msm, linux-phy, linux-kernel, jason.pettit,
konrad.dybcio, Wesley Cheng
The Qualcomm QMP combo PHY has a USB and Displayport block that is
sourced with different clocks. In situations where the USB path is not
utilized, and only Displayport is active, unnecessary clocks are enabled
and not used. Split the current clock list into USB specific clocks,
which will be enabled whenever the USB initialization routine is
executed.
In addition, move autonomous mode control specifically when USB is
active, as its primary purpose is to detect RX detection and LFPS
signals, which occurs only when USB is active.
Signed-off-by: Wesley Cheng <wesley.cheng@oss.qualcomm.com>
---
Changes in v2:
- Added proper error path cleanup with the introduction of a new set of
clocks.
- Enable/disable usb_clks accoridngly with the usb4 path.
- Link to v1: https://patch.msgid.link/20260930-qmp_phy_usb_clks_v1-v1-1-d4dccc9eb263@oss.qualcomm.com
---
drivers/phy/qualcomm/phy-qcom-qmp-combo.c | 76 ++++++++++++++++++++++++++-----
1 file changed, 64 insertions(+), 12 deletions(-)
diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
index 187f0cd11f6c..bb9eee2f3f0b 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
@@ -2619,8 +2619,10 @@ struct qmp_combo {
struct clk *pipe_clk;
struct clk_bulk_data *clks;
- struct clk *p2rr2p_pipe_clk;
int num_clks;
+ struct clk_bulk_data *usb_clks;
+ int num_usb_clks;
+ struct clk *p2rr2p_pipe_clk;
struct reset_control_bulk_data *resets;
struct regulator_bulk_data *vregs;
@@ -2668,7 +2670,11 @@ static int qmp_v8_configure_dp_phy(struct qmp_combo *qmp);
/* list of clocks required by phy */
static const char * const qmp_combo_phy_clk_l[] = {
- "aux", "cfg_ahb", "ref", "com_aux",
+ "cfg_ahb", "ref",
+};
+
+static const char * const qmp_combo_usb_phy_clk_l[] = {
+ "aux", "com_aux",
};
/* list of resets */
@@ -4455,13 +4461,20 @@ static int qmp_combo_usb_init(struct phy *phy)
return 0;
}
- ret = qmp_combo_com_init(qmp, false);
+ ret = clk_bulk_prepare_enable(qmp->num_usb_clks, qmp->usb_clks);
if (ret)
return ret;
+ ret = qmp_combo_com_init(qmp, false);
+ if (ret) {
+ clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
+ return ret;
+ }
+
ret = qmp_combo_usb_power_on(phy);
if (ret) {
qmp_combo_com_exit(qmp, false);
+ clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
return ret;
}
@@ -4492,6 +4505,8 @@ static int qmp_combo_usb_exit(struct phy *phy)
if (ret)
return ret;
+ clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
+
qmp->usb_init_count--;
return 0;
@@ -4547,6 +4562,10 @@ static int qmp_combo_usb4_init(struct phy *phy)
return -EINVAL;
}
+ ret = clk_bulk_prepare_enable(qmp->num_usb_clks, qmp->usb_clks);
+ if (ret)
+ return ret;
+
ret = clk_prepare_enable(qmp->p2rr2p_pipe_clk);
if (ret) {
dev_err(qmp->dev, "p2rr2p_pipe enable failed: %d\n", ret);
@@ -4606,6 +4625,7 @@ static int qmp_combo_usb4_exit(struct phy *phy)
qmp->usb4_init_count--;
clk_disable_unprepare(qmp->p2rr2p_pipe_clk);
+ clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
return 0;
}
@@ -4722,7 +4742,10 @@ static int __maybe_unused qmp_combo_runtime_suspend(struct device *dev)
return 0;
}
- qmp_combo_enable_autonomous_mode(qmp);
+ if (qmp->usb_init_count) {
+ qmp_combo_enable_autonomous_mode(qmp);
+ clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
+ }
clk_disable_unprepare(qmp->pipe_clk);
clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
@@ -4749,13 +4772,27 @@ static int __maybe_unused qmp_combo_runtime_resume(struct device *dev)
ret = clk_prepare_enable(qmp->pipe_clk);
if (ret) {
dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
- clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
- return ret;
+ goto disable_clks;
}
- qmp_combo_disable_autonomous_mode(qmp);
+ if (qmp->usb_init_count) {
+ ret = clk_bulk_prepare_enable(qmp->num_usb_clks, qmp->usb_clks);
+ if (ret) {
+ dev_err(dev, "usb_clks enable failed, err=%d\n", ret);
+ goto disable_pipe_clk;
+ }
+
+ qmp_combo_disable_autonomous_mode(qmp);
+ }
return 0;
+
+disable_pipe_clk:
+ clk_disable_unprepare(qmp->pipe_clk);
+disable_clks:
+ clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+
+ return ret;
}
static const struct dev_pm_ops qmp_combo_pm_ops = {
@@ -4788,19 +4825,34 @@ static int qmp_combo_reset_init(struct qmp_combo *qmp)
static int qmp_combo_clk_init(struct qmp_combo *qmp)
{
struct device *dev = qmp->dev;
- int num = ARRAY_SIZE(qmp_combo_phy_clk_l);
+ int num_clks = ARRAY_SIZE(qmp_combo_phy_clk_l);
+ int num_usb_clks = ARRAY_SIZE(qmp_combo_usb_phy_clk_l);
int i;
+ int ret;
- qmp->clks = devm_kcalloc(dev, num, sizeof(*qmp->clks), GFP_KERNEL);
+ qmp->clks = devm_kcalloc(dev, num_clks, sizeof(*qmp->clks), GFP_KERNEL);
if (!qmp->clks)
return -ENOMEM;
- for (i = 0; i < num; i++)
+ for (i = 0; i < num_clks; i++)
qmp->clks[i].id = qmp_combo_phy_clk_l[i];
- qmp->num_clks = num;
+ qmp->num_clks = num_clks;
+
+ qmp->usb_clks = devm_kcalloc(dev, num_usb_clks, sizeof(*qmp->usb_clks), GFP_KERNEL);
+ if (!qmp->usb_clks)
+ return -ENOMEM;
+
+ for (i = 0; i < num_usb_clks; i++)
+ qmp->usb_clks[i].id = qmp_combo_usb_phy_clk_l[i];
+
+ qmp->num_usb_clks = num_usb_clks;
+
+ ret = devm_clk_bulk_get_optional(dev, num_clks, qmp->clks);
+ if (ret)
+ return ret;
- return devm_clk_bulk_get_optional(dev, num, qmp->clks);
+ return devm_clk_bulk_get_optional(dev, num_usb_clks, qmp->usb_clks);
}
static void phy_clk_release_provider(void *res)
---
base-commit: 6bdfbe223ed4735073c299a6645ebd3faac3f51f
change-id: 20260930-qmp_phy_usb_clks_v1-25b9374086b2
Best regards,
--
Wesley Cheng <wesley.cheng@oss.qualcomm.com>
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] phy: qualcomm: qmp-combo: Differentiate clocks related to the USB block
2026-11-17 23:02 [PATCH v2] phy: qualcomm: qmp-combo: Differentiate clocks related to the USB block Wesley Cheng
@ 2026-11-17 23:15 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-17 23:15 UTC (permalink / raw)
To: Wesley Cheng; +Cc: linux-phy, vkoul, neil.armstrong, olteanv
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] phy: qcom-qmp-combo: unbalanced usb_clks across USB3 and USB4
init/exit
- [Medium] phy: qcom-qmp-combo: leak of usb_clks on
qmp_combo_usb4_init() error paths
- [Medium] phy: qcom-qmp-combo: missing usb4_init_count check in runtime
PM callbacks
--
commit b7cf67f2e40df5f2b187b7358099c33b24201c9f
Author: Wesley Cheng <wesley.cheng@oss.qualcomm.com>
phy: qualcomm: qmp-combo: Differentiate clocks related to the USB block
This commit splits the USB-specific clocks ("aux" and "com_aux") into a
separate clock bulk array so they are only enabled when the USB or USB4
paths are active, and gates autonomous mode transitions on USB activity.
> diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> index 187f0cd11f6c3..bb9eee2f3f0b8 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qmp-combo.c
[ ... ]
> @@ -4455,13 +4461,20 @@ static int qmp_combo_usb_init(struct phy *phy)
> return 0;
> }
>
> - ret = qmp_combo_com_init(qmp, false);
> + ret = clk_bulk_prepare_enable(qmp->num_usb_clks, qmp->usb_clks);
> if (ret)
> return ret;
>
> + ret = qmp_combo_com_init(qmp, false);
> + if (ret) {
> + clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
> + return ret;
> + }
> +
> ret = qmp_combo_usb_power_on(phy);
> if (ret) {
> qmp_combo_com_exit(qmp, false);
> + clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
> return ret;
> }
>
> @@ -4492,6 +4505,8 @@ static int qmp_combo_usb_exit(struct phy *phy)
> if (ret)
> return ret;
>
> + clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
> +
> qmp->usb_init_count--;
>
> return 0;
> @@ -4547,6 +4562,10 @@ static int qmp_combo_usb4_init(struct phy *phy)
> return -EINVAL;
> }
>
> + ret = clk_bulk_prepare_enable(qmp->num_usb_clks, qmp->usb_clks);
> + if (ret)
> + return ret;
> +
> ret = clk_prepare_enable(qmp->p2rr2p_pipe_clk);
> if (ret) {
> dev_err(qmp->dev, "p2rr2p_pipe enable failed: %d\n", ret);
[Severity: Medium]
Does qmp_combo_usb4_init() leak qmp->usb_clks on failure? If
clk_prepare_enable(qmp->p2rr2p_pipe_clk), qmp_combo_com_init(),
qmp_combo_reconfigure_phy(), or qmp_combo_usb_power_on() fails, none of
their error paths call clk_bulk_disable_unprepare(qmp->num_usb_clks,
qmp->usb_clks), leaving the USB clocks permanently prepared and enabled.
> @@ -4606,6 +4625,7 @@ static int qmp_combo_usb4_exit(struct phy *phy)
> qmp->usb4_init_count--;
>
> clk_disable_unprepare(qmp->p2rr2p_pipe_clk);
> + clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
>
> return 0;
> }
[Severity: High]
As reported by Konrad Dybcio on v1 [1], can qmp->usb_clks become
unbalanced when USB3 and USB4 init/exit overlap?
In qmp_combo_usb_init() and qmp_combo_usb_exit(), when qmp->usb4_init_count
is non-zero, both functions update qmp->usb_init_count and return early
before touching qmp->usb_clks:
drivers/phy/qualcomm/phy-qcom-qmp-combo.c:qmp_combo_usb_init() {
/* USB4 mode takes precedence, do not reprogram the PHY in that case */
if (qmp->usb4_init_count) {
qmp->init_count++;
qmp->usb_init_count++;
return 0;
}
ret = clk_bulk_prepare_enable(qmp->num_usb_clks, qmp->usb_clks);
If qmp_combo_usb4_init() runs first (enabling qmp->usb_clks once),
qmp_combo_usb_init() runs next (skipping clk_bulk_prepare_enable()), and
qmp_combo_usb4_exit() then runs, qmp_combo_usb4_exit() disables
qmp->usb_clks down to zero while qmp->usb_init_count is still 1. Any
subsequent USB3 register access in qmp_combo_typec_mux_set(),
qmp_combo_runtime_suspend(), or qmp_combo_usb_exit() happens with
qmp->usb_clks disabled, and qmp_combo_usb_exit() then calls
clk_bulk_disable_unprepare() a second time on already-disabled clocks.
Conversely, if qmp_combo_usb_init() runs before qmp_combo_usb4_init() (so
both enable qmp->usb_clks) and qmp_combo_usb_exit() is called while
qmp->usb4_init_count is still non-zero, qmp_combo_usb_exit() returns early
without disabling qmp->usb_clks, leaking a clock reference.
> @@ -4722,7 +4742,10 @@ static int __maybe_unused qmp_combo_runtime_suspend(struct device *dev)
> return 0;
> }
>
> - qmp_combo_enable_autonomous_mode(qmp);
> + if (qmp->usb_init_count) {
> + qmp_combo_enable_autonomous_mode(qmp);
> + clk_bulk_disable_unprepare(qmp->num_usb_clks, qmp->usb_clks);
> + }
>
> clk_disable_unprepare(qmp->pipe_clk);
> clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
> @@ -4749,13 +4772,27 @@ static int __maybe_unused qmp_combo_runtime_resume(struct device *dev)
> ret = clk_prepare_enable(qmp->pipe_clk);
> if (ret) {
> dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
> - clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
> - return ret;
> + goto disable_clks;
> }
>
> - qmp_combo_disable_autonomous_mode(qmp);
> + if (qmp->usb_init_count) {
> + ret = clk_bulk_prepare_enable(qmp->num_usb_clks, qmp->usb_clks);
> + if (ret) {
> + dev_err(dev, "usb_clks enable failed, err=%d\n", ret);
> + goto disable_pipe_clk;
> + }
> +
> + qmp_combo_disable_autonomous_mode(qmp);
> + }
>
> return 0;
> +
> +disable_pipe_clk:
> + clk_disable_unprepare(qmp->pipe_clk);
> +disable_clks:
> + clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
> +
> + return ret;
> }
[Severity: Medium]
Should qmp_combo_runtime_suspend() and qmp_combo_runtime_resume() also
account for qmp->usb4_init_count?
qmp_combo_usb4_init() enables qmp->usb_clks and increments
qmp->usb4_init_count without incrementing qmp->usb_init_count, and
qmp_combo_enable_autonomous_mode() / qmp_combo_disable_autonomous_mode()
explicitly handle QMPPHY_MODE_USB4 via QPHY_PCS_USB4_CLAMP_ENABLE.
Checking only qmp->usb_init_count skips autonomous mode and leaves
qmp->usb_clks enabled during runtime suspend when only USB4 is initialized.
[1] https://lore.kernel.org/r/c1abd9d4-98ef-4469-b4f3-94a8dcad9d0b@oss.qualcomm.com
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-qmp_phy_usb_clks_v1-v2-1-6e960853aa69@oss.qualcomm.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] 2+ messages in thread
end of thread, other threads:[~2026-11-17 23:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 23:02 [PATCH v2] phy: qualcomm: qmp-combo: Differentiate clocks related to the USB block Wesley Cheng
2026-11-17 23:15 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox