Skip to contentSkip to conversation

Clock fixes for qcom-snps-femto-v2 PHY driver

RFC PATCH Superseded Adrien Thierry 3 participants 10 messages May 29, 2023 – Jun 1, 2023

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Clock fixes for qcom-snps-femto-v2 PHY driver

This series attempts to fix a few weird clock usages in the qcom-snps-femto-v2 PHY driver:
- ref_clk is never properly enabled
- cfg_ahb_clk is never assigned

Adrien Thierry (2):
phy: qcom-snps-femto-v2: properly enable ref clock
phy: qcom-snps-femto-v2: Remove AHB2PHY interface clock

 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 22 +++++++++----------
 1 file changed, 10 insertions(+), 12 deletions(-)
Signature · 7 lines
2.40.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#1 lore raw

RFC PATCH 1/2 phy: qcom-snps-femto-v2: properly enable ref clock

The driver is not enabling the ref clock, which thus gets disabled by the clk_disable_unused initcall. This leads to the dwc3 controller failing to initialize if probed after clk_disable_unused is called, for instance when the driver is built as a module.

To fix this, add calls to clk_prepare_enable/clk_disable_unprepare at the proper places.

---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +18 -2
index 6c237f3cc66d..8abf482e81a8 100644
@@ -166,6 +166,7 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 	}
 
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
 
@@ -181,6 +182,12 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 		return ret;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -380,10 +387,16 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 		goto poweroff_phy;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
+		goto disable_ahb_clk;
+	}
+
 	ret = reset_control_assert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	usleep_range(100, 150);
@@ -391,7 +404,7 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	ret = reset_control_deassert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
@@ -448,6 +461,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 	return 0;
 
+disable_ref_clk:
+	clk_disable_unprepare(hsphy->ref_clk);
 disable_ahb_clk:
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
@@ -462,6 +477,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 
 	reset_control_assert(hsphy->phy_reset);
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
 
Signature · 7 lines
2.40.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#2 lore raw

Re: [PATCH RFC 1/2] phy: qcom-snps-femto-v2: properly enable ref clock

Quoted 5 lines · Adrien Thierry

The driver is not enabling the ref clock, which thus gets disabled by the clk_disable_unused initcall. This leads to the dwc3 controller failing to initialize if probed after clk_disable_unused is called, for instance when the driver is built as a module.

Good catch!

A side note though, clk_disable_unused() has no way to take kernel modules into consideration today, and it doesn't handle the case where clock drivers are built as modules appropriately.
Work has started to address this, but as of todaybooting the system without clk_ignore_unused is not recommended...

Quoted 3 lines

To fix this, add calls to clk_prepare_enable/clk_disable_unprepare at the proper places.

If I parse the downstream kernel correctly the refclock should be turned off across runtime and system suspend as well.

Regards,
Bjorn

Quoted 77 lines
---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +18 -2
index 6c237f3cc66d..8abf482e81a8 100644
@@ -166,6 +166,7 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 	}
 
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
 
@@ -181,6 +182,12 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 		return ret;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -380,10 +387,16 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 		goto poweroff_phy;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
+		goto disable_ahb_clk;
+	}
+
 	ret = reset_control_assert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	usleep_range(100, 150);
@@ -391,7 +404,7 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	ret = reset_control_deassert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
@@ -448,6 +461,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 	return 0;
 
+disable_ref_clk:
+	clk_disable_unprepare(hsphy->ref_clk);
 disable_ahb_clk:
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
@@ -462,6 +477,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 
 	reset_control_assert(hsphy->phy_reset);
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
 
Signature · 1 line
2.40.1
#3 lore raw

Re: [PATCH RFC 1/2] phy: qcom-snps-femto-v2: properly enable ref clock

Hi Bjorn, thanks for your reply!

Quoted 7 lines · Bjorn Andersson
Quoted 5 lines · Adrien Thierry

The driver is not enabling the ref clock, which thus gets disabled by the clk_disable_unused initcall. This leads to the dwc3 controller failing to initialize if probed after clk_disable_unused is called, for instance when the driver is built as a module.

Quoted 8 lines

Good catch!

A side note though, clk_disable_unused() has no way to take kernel modules into consideration today, and it doesn't handle the case where clock drivers are built as modules appropriately.
Work has started to address this, but as of todaybooting the system without clk_ignore_unused is not recommended...

For my understanding, do you have an example of a situation that would fail with modules when not using clk_ignore_unused?

Quoted 7 lines
Quoted 3 lines

To fix this, add calls to clk_prepare_enable/clk_disable_unprepare at the proper places.

If I parse the downstream kernel correctly the refclock should be turned off across runtime and system suspend as well.

Which downstream kernel are you using? I'm not seing a system suspend callback in mine [1]. refclock should be turned off on runtime suspend in my patch, in qcom_snps_hsphy_suspend, which is called by qcom_snps_hsphy_runtime_suspend.

[1] https://git.codelinaro.org/clo/la/kernel/ark-5.14/-/blob/kernel.lnx.5.14.r2-rel/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c

Quoted 77 lines

Regards,
Bjorn

Quoted 74 lines
---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +18 -2
index 6c237f3cc66d..8abf482e81a8 100644
@@ -166,6 +166,7 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 	}
 
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
 
@@ -181,6 +182,12 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 		return ret;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -380,10 +387,16 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 		goto poweroff_phy;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
+		goto disable_ahb_clk;
+	}
+
 	ret = reset_control_assert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	usleep_range(100, 150);
@@ -391,7 +404,7 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	ret = reset_control_deassert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
@@ -448,6 +461,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 	return 0;
 
+disable_ref_clk:
+	clk_disable_unprepare(hsphy->ref_clk);
 disable_ahb_clk:
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
@@ -462,6 +477,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 
 	reset_control_assert(hsphy->phy_reset);
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
 
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.40.1

Best,
Adrien

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#4 lore raw

Re: [PATCH RFC 1/2] phy: qcom-snps-femto-v2: properly enable ref clock

Quoted 19 lines · Adrien Thierry

Hi Bjorn, thanks for your reply!

Quoted 7 lines · Bjorn Andersson
Quoted 5 lines · Adrien Thierry

The driver is not enabling the ref clock, which thus gets disabled by the clk_disable_unused initcall. This leads to the dwc3 controller failing to initialize if probed after clk_disable_unused is called, for instance when the driver is built as a module.

Quoted 8 lines

Good catch!

A side note though, clk_disable_unused() has no way to take kernel modules into consideration today, and it doesn't handle the case where clock drivers are built as modules appropriately.
Work has started to address this, but as of todaybooting the system without clk_ignore_unused is not recommended...

Quoted 3 lines

For my understanding, do you have an example of a situation that would fail with modules when not using clk_ignore_unused?

The prime example relates to the display clocks, where the bootloader typically leave clocks on and at lateinit we haven't yet loaded enough modules to bring up the display. And to make matters worse, the code ends up disabling the PLL feeding the clock tree without first disabling some of the muxes - which has side effects...

Another case, although much less concerning in the short run, is when you have any of the clock drivers built as modules. clk_disable_unused() will be invoked before they are loaded, so your expectation that unused clocks are turned off is just not fulfilled.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

To fix this, add calls to clk_prepare_enable/clk_disable_unprepare at the proper places.

Quoted 9 lines
Quoted 3 lines

If I parse the downstream kernel correctly the refclock should be turned off across runtime and system suspend as well.

Which downstream kernel are you using? I'm not seing a system suspend callback in mine [1]. refclock should be turned off on runtime suspend in my patch, in qcom_snps_hsphy_suspend, which is called by qcom_snps_hsphy_runtime_suspend.

Forgive me, but isn't [1] the driver you're modifying?

I'm looking at [2], with set_suspend() being invoked from the runtime and system suspend/resume handlers.

Quoted 1 line

[1] https://git.codelinaro.org/clo/la/kernel/ark-5.14/-/blob/kernel.lnx.5.14.r2-rel/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c

[2] https://git.codelinaro.org/clo/la/kernel/msm-5.4/-/blob/LV.AU.1.2.1.r2-05300-gen3meta.0/drivers/usb/phy/phy-msm-snps-hs.c#L908

Regards,
Bjorn

Quoted 85 lines
Quoted 78 lines

Regards,
Bjorn

Quoted 74 lines
---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +18 -2
index 6c237f3cc66d..8abf482e81a8 100644
@@ -166,6 +166,7 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 	}
 
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
 
@@ -181,6 +182,12 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 		return ret;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -380,10 +387,16 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 		goto poweroff_phy;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
+		goto disable_ahb_clk;
+	}
+
 	ret = reset_control_assert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	usleep_range(100, 150);
@@ -391,7 +404,7 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	ret = reset_control_deassert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
@@ -448,6 +461,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 	return 0;
 
+disable_ref_clk:
+	clk_disable_unprepare(hsphy->ref_clk);
 disable_ahb_clk:
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
@@ -462,6 +477,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 
 	reset_control_assert(hsphy->phy_reset);
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
 
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.40.1

Best,
Adrien

#5 lore raw

Re: [PATCH RFC 1/2] phy: qcom-snps-femto-v2: properly enable ref clock

Quoted 30 lines · Bjorn Andersson
Quoted 19 lines · Adrien Thierry

Hi Bjorn, thanks for your reply!

Quoted 7 lines · Bjorn Andersson
Quoted 5 lines · Adrien Thierry

The driver is not enabling the ref clock, which thus gets disabled by the clk_disable_unused initcall. This leads to the dwc3 controller failing to initialize if probed after clk_disable_unused is called, for instance when the driver is built as a module.

Quoted 8 lines

Good catch!

A side note though, clk_disable_unused() has no way to take kernel modules into consideration today, and it doesn't handle the case where clock drivers are built as modules appropriately.
Work has started to address this, but as of todaybooting the system without clk_ignore_unused is not recommended...

Quoted 3 lines

For my understanding, do you have an example of a situation that would fail with modules when not using clk_ignore_unused?

The prime example relates to the display clocks, where the bootloader typically leave clocks on and at lateinit we haven't yet loaded enough modules to bring up the display. And to make matters worse, the code ends up disabling the PLL feeding the clock tree without first disabling some of the muxes - which has side effects...

Quoted 5 lines

Another case, although much less concerning in the short run, is when you have any of the clock drivers built as modules. clk_disable_unused() will be invoked before they are loaded, so your expectation that unused clocks are turned off is just not fulfilled.

Thanks for the explanation!

Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

To fix this, add calls to clk_prepare_enable/clk_disable_unprepare at the proper places.

Quoted 9 lines
Quoted 3 lines

If I parse the downstream kernel correctly the refclock should be turned off across runtime and system suspend as well.

Which downstream kernel are you using? I'm not seing a system suspend callback in mine [1]. refclock should be turned off on runtime suspend in my patch, in qcom_snps_hsphy_suspend, which is called by qcom_snps_hsphy_runtime_suspend.

Quoted 9 lines

Forgive me, but isn't [1] the driver you're modifying?

I'm looking at [2], with set_suspend() being invoked from the runtime and system suspend/resume handlers.

Quoted 1 line

[1] https://git.codelinaro.org/clo/la/kernel/ark-5.14/-/blob/kernel.lnx.5.14.r2-rel/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c

[2] https://git.codelinaro.org/clo/la/kernel/msm-5.4/-/blob/LV.AU.1.2.1.r2-05300-gen3meta.0/drivers/usb/phy/phy-msm-snps-hs.c#L908

Thank you. The femto PHY driver is not using set_suspend(), but has runtime PM ops. Is it ok if I add the system sleep PM ops as well with SET_SYSTEM_SLEEP_PM_OPS() ?

Quoted 88 lines

Regards,
Bjorn

Quoted 85 lines
Quoted 78 lines

Regards,
Bjorn

Quoted 74 lines
---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +18 -2
index 6c237f3cc66d..8abf482e81a8 100644
@@ -166,6 +166,7 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 	}
 
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
 
@@ -181,6 +182,12 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 		return ret;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -380,10 +387,16 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 		goto poweroff_phy;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
+		goto disable_ahb_clk;
+	}
+
 	ret = reset_control_assert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	usleep_range(100, 150);
@@ -391,7 +404,7 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	ret = reset_control_deassert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
@@ -448,6 +461,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 	return 0;
 
+disable_ref_clk:
+	clk_disable_unprepare(hsphy->ref_clk);
 disable_ahb_clk:
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
@@ -462,6 +477,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 
 	reset_control_assert(hsphy->phy_reset);
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
 
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.40.1

Best,
Adrien

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#6 lore raw

Re: [PATCH RFC 1/2] phy: qcom-snps-femto-v2: properly enable ref clock

In reply to Adrien Thierry
Quoted 8 lines · Adrien Thierry

The driver is not enabling the ref clock, which thus gets disabled by the clk_disable_unused initcall. This leads to the dwc3 controller failing to initialize if probed after clk_disable_unused is called, for instance when the driver is built as a module.

To fix this, add calls to clk_prepare_enable/clk_disable_unprepare at the proper places.

I'm a sucker for a good paper trail, maybe add:

Fixes 51e8114f80d0 ("phy: qcom-snps: Add SNPS USB PHY driver for QCOM based SOCs")

good work!

Quoted 77 lines
---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +18 -2
index 6c237f3cc66d..8abf482e81a8 100644
@@ -166,6 +166,7 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 	}
 
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
 
@@ -181,6 +182,12 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 		return ret;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -380,10 +387,16 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 		goto poweroff_phy;
 	}
 
+	ret = clk_prepare_enable(hsphy->ref_clk);
+	if (ret) {
+		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
+		goto disable_ahb_clk;
+	}
+
 	ret = reset_control_assert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	usleep_range(100, 150);
@@ -391,7 +404,7 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	ret = reset_control_deassert(hsphy->phy_reset);
 	if (ret) {
 		dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
-		goto disable_ahb_clk;
+		goto disable_ref_clk;
 	}
 
 	qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
@@ -448,6 +461,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 	return 0;
 
+disable_ref_clk:
+	clk_disable_unprepare(hsphy->ref_clk);
 disable_ahb_clk:
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
@@ -462,6 +477,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 
 	reset_control_assert(hsphy->phy_reset);
 	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
 
Signature · 1 line
2.40.1
#7 lore raw

RFC PATCH 2/2 phy: qcom-snps-femto-v2: Remove AHB2PHY interface clock

In reply to Adrien Thierry

The AHB2PHY interface clock cfg_ahb_clk is not assigned anywhere in the driver. Moreover, it's not used by any device tree, nor is present in the qcom,usb-snps-femto-v2 bindings. Remove it.

---
I'm not 100% sure if the clock should be removed, or if it should be added to bindings and device trees that use this PHY. Better informed opinions on the topic are highly welcome.

 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -19
index 8abf482e81a8..2d9c1105e28c 100644
@@ -113,7 +113,6 @@ struct phy_override_seq {
  * @phy: generic phy
  * @base: iomapped memory space for snps hs phy
  *
- * @cfg_ahb_clk: AHB2PHY interface clock
  * @ref_clk: phy reference clock
  * @phy_reset: phy reset control
  * @vregs: regulator supplies bulk data
@@ -125,7 +124,6 @@ struct qcom_snps_hsphy {
 	struct phy *phy;
 	void __iomem *base;
 
-	struct clk *cfg_ahb_clk;
 	struct clk *ref_clk;
 	struct reset_control *phy_reset;
 	struct regulator_bulk_data vregs[SNPS_HS_NUM_VREGS];
@@ -165,7 +163,6 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 					   0, USB2_AUTO_RESUME);
 	}
 
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
@@ -176,12 +173,6 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 
 	dev_dbg(&hsphy->phy->dev, "Resume QCOM SNPS PHY, mode\n");
 
-	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
-	if (ret) {
-		dev_err(&hsphy->phy->dev, "failed to enable cfg ahb clock\n");
-		return ret;
-	}
-
 	ret = clk_prepare_enable(hsphy->ref_clk);
 	if (ret) {
 		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
@@ -381,16 +372,10 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
-	if (ret) {
-		dev_err(&phy->dev, "failed to enable cfg ahb clock, %d\n", ret);
-		goto poweroff_phy;
-	}
-
 	ret = clk_prepare_enable(hsphy->ref_clk);
 	if (ret) {
 		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
-		goto disable_ahb_clk;
+		goto poweroff_phy;
 	}
 
 	ret = reset_control_assert(hsphy->phy_reset);
@@ -463,8 +448,6 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 disable_ref_clk:
 	clk_disable_unprepare(hsphy->ref_clk);
-disable_ahb_clk:
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 
@@ -476,7 +459,6 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
 
 	reset_control_assert(hsphy->phy_reset);
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
Signature · 7 lines
2.40.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#8 lore raw

Re: [PATCH RFC 2/2] phy: qcom-snps-femto-v2: Remove AHB2PHY interface clock

Quoted 4 lines · Adrien Thierry

The AHB2PHY interface clock cfg_ahb_clk is not assigned anywhere in the driver. Moreover, it's not used by any device tree, nor is present in the qcom,usb-snps-femto-v2 bindings. Remove it.

The downstream driver deals with cfg_ahb as well, so I think it would be more appropriate to ensure that it's actually wired up.

And in that case, I would find it preferable to switch to use the clk_bulk API for the introduction of the ref clk - to clean up the error paths if nothing else.

Regards,
Bjorn

Quoted 88 lines

---
I'm not 100% sure if the clock should be removed, or if it should be added to bindings and device trees that use this PHY. Better informed opinions on the topic are highly welcome.

 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -19
index 8abf482e81a8..2d9c1105e28c 100644
@@ -113,7 +113,6 @@ struct phy_override_seq {
  * @phy: generic phy
  * @base: iomapped memory space for snps hs phy
  *
- * @cfg_ahb_clk: AHB2PHY interface clock
  * @ref_clk: phy reference clock
  * @phy_reset: phy reset control
  * @vregs: regulator supplies bulk data
@@ -125,7 +124,6 @@ struct qcom_snps_hsphy {
 	struct phy *phy;
 	void __iomem *base;
 
-	struct clk *cfg_ahb_clk;
 	struct clk *ref_clk;
 	struct reset_control *phy_reset;
 	struct regulator_bulk_data vregs[SNPS_HS_NUM_VREGS];
@@ -165,7 +163,6 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 					   0, USB2_AUTO_RESUME);
 	}
 
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
@@ -176,12 +173,6 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 
 	dev_dbg(&hsphy->phy->dev, "Resume QCOM SNPS PHY, mode\n");
 
-	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
-	if (ret) {
-		dev_err(&hsphy->phy->dev, "failed to enable cfg ahb clock\n");
-		return ret;
-	}
-
 	ret = clk_prepare_enable(hsphy->ref_clk);
 	if (ret) {
 		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
@@ -381,16 +372,10 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
-	if (ret) {
-		dev_err(&phy->dev, "failed to enable cfg ahb clock, %d\n", ret);
-		goto poweroff_phy;
-	}
-
 	ret = clk_prepare_enable(hsphy->ref_clk);
 	if (ret) {
 		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
-		goto disable_ahb_clk;
+		goto poweroff_phy;
 	}
 
 	ret = reset_control_assert(hsphy->phy_reset);
@@ -463,8 +448,6 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 disable_ref_clk:
 	clk_disable_unprepare(hsphy->ref_clk);
-disable_ahb_clk:
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 
@@ -476,7 +459,6 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
 
 	reset_control_assert(hsphy->phy_reset);
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
Signature · 1 line
2.40.1
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#9 lore raw

Re: [PATCH RFC 2/2] phy: qcom-snps-femto-v2: Remove AHB2PHY interface clock

Hi Bjorn,

Quoted 6 lines · Bjorn Andersson
Quoted 4 lines · Adrien Thierry

The AHB2PHY interface clock cfg_ahb_clk is not assigned anywhere in the driver. Moreover, it's not used by any device tree, nor is present in the qcom,usb-snps-femto-v2 bindings. Remove it.

Quoted 7 lines

The downstream driver deals with cfg_ahb as well, so I think it would be more appropriate to ensure that it's actually wired up.

And in that case, I would find it preferable to switch to use the clk_bulk API for the introduction of the ref clk - to clean up the error paths if nothing else.

I won't be able to properly wire the cfg_ahb clock in the device trees because I've got no way of knowing which clock to use for cfg_ahb in the various SoCs, but I can at least try to clean the code by using the clk_bulk API.

Quoted 91 lines

Regards,
Bjorn

Quoted 88 lines

---
I'm not 100% sure if the clock should be removed, or if it should be added to bindings and device trees that use this PHY. Better informed opinions on the topic are highly welcome.

 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 20 +------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -19
index 8abf482e81a8..2d9c1105e28c 100644
@@ -113,7 +113,6 @@ struct phy_override_seq {
  * @phy: generic phy
  * @base: iomapped memory space for snps hs phy
  *
- * @cfg_ahb_clk: AHB2PHY interface clock
  * @ref_clk: phy reference clock
  * @phy_reset: phy reset control
  * @vregs: regulator supplies bulk data
@@ -125,7 +124,6 @@ struct qcom_snps_hsphy {
 	struct phy *phy;
 	void __iomem *base;
 
-	struct clk *cfg_ahb_clk;
 	struct clk *ref_clk;
 	struct reset_control *phy_reset;
 	struct regulator_bulk_data vregs[SNPS_HS_NUM_VREGS];
@@ -165,7 +163,6 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
 					   0, USB2_AUTO_RESUME);
 	}
 
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 	clk_disable_unprepare(hsphy->ref_clk);
 	return 0;
 }
@@ -176,12 +173,6 @@ static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
 
 	dev_dbg(&hsphy->phy->dev, "Resume QCOM SNPS PHY, mode\n");
 
-	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
-	if (ret) {
-		dev_err(&hsphy->phy->dev, "failed to enable cfg ahb clock\n");
-		return ret;
-	}
-
 	ret = clk_prepare_enable(hsphy->ref_clk);
 	if (ret) {
 		dev_err(&hsphy->phy->dev, "failed to enable ref clock\n");
@@ -381,16 +372,10 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
-	if (ret) {
-		dev_err(&phy->dev, "failed to enable cfg ahb clock, %d\n", ret);
-		goto poweroff_phy;
-	}
-
 	ret = clk_prepare_enable(hsphy->ref_clk);
 	if (ret) {
 		dev_err(&phy->dev, "failed to enable ref clock, %d\n", ret);
-		goto disable_ahb_clk;
+		goto poweroff_phy;
 	}
 
 	ret = reset_control_assert(hsphy->phy_reset);
@@ -463,8 +448,6 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
 disable_ref_clk:
 	clk_disable_unprepare(hsphy->ref_clk);
-disable_ahb_clk:
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 poweroff_phy:
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 
@@ -476,7 +459,6 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
 
 	reset_control_assert(hsphy->phy_reset);
-	clk_disable_unprepare(hsphy->cfg_ahb_clk);
 	clk_disable_unprepare(hsphy->ref_clk);
 	regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
 	hsphy->phy_initialized = false;
Signature · 1 line
2.40.1
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy