Fixes for qcom-snps-femto-v2 PHY driver
Subsystems (2)
v4 cover Fixes for qcom-snps-femto-v2 PHY driver
This series contains a few fixes for the qcom-snps-femto-v2 driver, mostly clock-related.
v3 -> v4
- remove commit that added system sleep PM ops
- add commit "phy: qcom-snps-femto-v2: keep cfg_ahb_clk enabled during runtime suspend"
- "phy: qcom-snps-femto-v2: properly enable ref clock"
- dropped "HACK:" comment (Bjorn Andersson)
- check for IS_ERR() for the optional cfg_ahb clock (Bjorn Andersson)
- don't print an error message in case clk_bulk_prepare() fails (Bjorn Andersson)
v2 -> v3
- "phy: qcom-snps-femto-v2: add system sleep PM ops" - add link to downstream driver used as reference (Andrew Halaney)
- add commit "phy: qcom-snps-femto-v2: use qcom_snps_hsphy_do_suspend/resume error code" to make sure PM ops don't always return 0 (Andrew Halaney)
v1 -> v2
- keep cfg_ahb clock and use clk_bulk API to handle both cfg_ahb and ref clocks (Bjorn Andersson)
- add system sleep PM callbacks (Bjorn Andersson)
- add Link: and Fixes: tag (Andrew Halaney)
Adrien Thierry (3):
phy: qcom-snps-femto-v2: keep cfg_ahb_clk enabled during runtime
suspend
phy: qcom-snps-femto-v2: properly enable ref clock
phy: qcom-snps-femto-v2: use qcom_snps_hsphy_suspend/resume error code
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 78 ++++++++++++------- 1 file changed, 50 insertions(+), 28 deletions(-)
Signature · 7 lines
2.40.1 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
PATCH v4 1/3 phy: qcom-snps-femto-v2: keep cfg_ahb_clk enabled during runtime suspend
In the dwc3 core, both system and runtime suspend end up calling dwc3_suspend_common(). From there, what happens for the PHYs depends on the USB mode and whether the controller is entering system or runtime suspend.
HOST mode:
(1) system suspend on a non-wakeup-capable controller
The [1] if branch is taken. dwc3_core_exit() is called, which ends up calling phy_power_off() and phy_exit(). Those two functions decrease the PM runtime count at some point, so they will trigger the PHY runtime sleep (assuming the count is right).
(2) runtime suspend / system suspend on a wakeup-capable controller
The [1] branch is not taken. dwc3_suspend_common() calls phy_pm_runtime_put_sync(). Assuming the ref count is right, the PHY runtime suspend op is called.
DEVICE mode:
dwc3_core_exit() is called on both runtime and system sleep unless the controller is already runtime suspended.
OTG mode:
(1) system suspend : dwc3_core_exit() is called
(2) runtime suspend : do nothing
In host mode, the code seems to make a distinction between 1) runtime sleep / system sleep for wakeup-capable controller, and 2) system sleep for non-wakeup-capable controller, where phy_power_off() and phy_exit() are only called for the latter. This suggests the PHY is not supposed to be in a fully powered-off state for runtime sleep and system sleep for wakeup-capable controller.
Moreover, downstream, cfg_ahb_clk only gets disabled for system suspend. The clocks are disabled by phy->set_suspend() [2] which is only called in the system sleep path through dwc3_core_exit() [3].
With that in mind, don't disable the clocks during the femto PHY runtime suspend callback. The clocks will only be disabled during system suspend for non-wakeup-capable controllers, through dwc3_core_exit().
[1] https://elixir.bootlin.com/linux/v6.4/source/drivers/usb/dwc3/core.c#L1988
[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#L524
[3] https://git.codelinaro.org/clo/la/kernel/msm-5.4/-/blob/LV.AU.1.2.1.r2-05300-gen3meta.0/drivers/usb/dwc3/core.c#L1915
--- drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +0 -9
@@ -165,22 +165,13 @@ static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy) 0, USB2_AUTO_RESUME); } -clk_disable_unprepare (hsphy->cfg_ahb_clk);return 0 ; }static int qcom_snps_hsphy_resume (struct qcom_snps_hsphy *hsphy) { -int ret; -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; - } -return 0 ; }
Signature · 7 lines
2.40.1 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
PATCH v4 2/3 phy: qcom-snps-femto-v2: properly enable ref clock
In reply to Adrien ThierryThe 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, switch to the clk_bulk API to handle both cfg_ahb and ref clocks at the proper places.
Note that the cfg_ahb clock is currently not used by any device tree instantiation of the PHY. Work needs to be done separately to fix this.
--- drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 63 ++++++++++++++----- 1 file changed, 48 insertions(+), 15 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +48 -15
@@ -110,11 +110,13 @@ struct phy_override_seq {/** * struct qcom_snps_hsphy - snps hs phy attributes * +* @dev: device structure +* * @phy: generic phy * @base: iomapped memory space for snps hs phy * -* @cfg_ahb_clk: AHB2PHY interface clock -* @ref_clk: phy reference clock +* @num_clks: number of clocks +* @clks: array of clocks * @phy_reset: phy reset control * @vregs: regulator supplies bulk data * @phy_initialized: if PHY has been initialized correctly
@@ -122,11 +124,13 @@ struct phy_override_seq {* @update_seq_cfg: tuning parameters for phy init */ struct qcom_snps_hsphy { +struct device *dev; +struct phy *phy;void __iomem *base; -struct clk *cfg_ahb_clk; -struct clk *ref_clk; +int num_clks; +struct clk_bulk_data *clks;struct reset_control *phy_reset;struct regulator_bulk_data vregs[SNPS_HS_NUM_VREGS ];
@@ -135,6 +139,34 @@ struct qcom_snps_hsphy {struct phy_override_seq update_seq_cfg[NUM_HSPHY_TUNING_PARAMS ]; }; +static int qcom_snps_hsphy_clk_init (struct qcom_snps_hsphy *hsphy) +{ +struct device *dev = hsphy->dev; + + hsphy->num_clks =2 ; + hsphy->clks =devm_kcalloc (dev, hsphy->num_clks,sizeof (*hsphy->clks),GFP_KERNEL ); +if (!hsphy->clks) +return -ENOMEM ; + +/* +* TODO: Currently no device tree instantiation of the PHY is using the clock. +* This needs to be fixed in order for this code to be able to use devm_clk_bulk_get(). +*/ + hsphy->clks[0 ].id ="cfg_ahb" ; + hsphy->clks[0 ].clk =devm_clk_get_optional (dev,"cfg_ahb" ); +if (IS_ERR (hsphy->clks[0 ].clk)) +return dev_err_probe (dev,PTR_ERR (hsphy->clks[0 ].clk), +"failed to get cfg_ahb clk\n" ); + + hsphy->clks[1 ].id ="ref" ; + hsphy->clks[1 ].clk =devm_clk_get (dev,"ref" ); +if (IS_ERR (hsphy->clks[1 ].clk)) +return dev_err_probe (dev,PTR_ERR (hsphy->clks[1 ].clk), +"failed to get ref clk\n" ); + +return 0 ; +} +static inline void qcom_snps_hsphy_write_mask (void __iomem *base,u32 offset,u32 mask,u32 val) {
@@ -365,16 +397,16 @@ static int qcom_snps_hsphy_init(struct phy *phy)if (ret)return ret; - ret =clk_prepare_enable (hsphy->cfg_ahb_clk); + ret =clk_bulk_prepare_enable (hsphy->num_clks, hsphy->clks);if (ret) { -dev_err (&phy->dev,"failed to enable cfg ahb clock, %d\n" , ret); +dev_err (&phy->dev,"failed to enable clocks, %d\n" , ret); goto poweroff_phy; } 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_clks; }usleep_range (100 ,150 );
@@ -382,7 +414,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_clks; } qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
@@ -439,8 +471,8 @@ static int qcom_snps_hsphy_init(struct phy *phy)return 0 ; -disable_ahb_clk: -clk_disable_unprepare (hsphy->cfg_ahb_clk); +disable_clks: +clk_bulk_disable_unprepare (hsphy->num_clks, hsphy->clks); poweroff_phy:regulator_bulk_disable (ARRAY_SIZE (hsphy->vregs), hsphy->vregs);
@@ -452,7 +484,7 @@ 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_bulk_disable_unprepare (hsphy->num_clks, hsphy->clks);regulator_bulk_disable (ARRAY_SIZE (hsphy->vregs), hsphy->vregs); hsphy->phy_initialized = false;
@@ -545,14 +577,15 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)if (!hsphy)return -ENOMEM ; + hsphy->dev = dev; + hsphy->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (hsphy->base))return PTR_ERR (hsphy->base); - hsphy->ref_clk =devm_clk_get (dev,"ref" ); -if (IS_ERR (hsphy->ref_clk)) -return dev_err_probe (dev,PTR_ERR (hsphy->ref_clk), -"failed to get ref clk\n" ); + ret =qcom_snps_hsphy_clk_init (hsphy); +if (ret) +return dev_err_probe (dev, ret,"failed to initialize clocks\n" ); hsphy->phy_reset =devm_reset_control_get_exclusive (&pdev->dev,NULL );if (IS_ERR (hsphy->phy_reset)) {
Signature · 7 lines
2.40.1 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
PATCH v4 3/3 phy: qcom-snps-femto-v2: use qcom_snps_hsphy_suspend/resume error code
In reply to Adrien ThierryThe return value from qcom_snps_hsphy_suspend/resume is not used. Make sure qcom_snps_hsphy_runtime_suspend/resume return this value as well.
--- drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +2 -4
@@ -214,8 +214,7 @@ static int __maybe_unused qcom_snps_hsphy_runtime_suspend(struct device *dev)if (!hsphy->phy_initialized)return 0 ; -qcom_snps_hsphy_suspend (hsphy); -return 0 ; +return qcom_snps_hsphy_suspend (hsphy); }static int __maybe_unused qcom_snps_hsphy_runtime_resume (struct device *dev)
@@ -225,8 +224,7 @@ static int __maybe_unused qcom_snps_hsphy_runtime_resume(struct device *dev)if (!hsphy->phy_initialized)return 0 ; -qcom_snps_hsphy_resume (hsphy); -return 0 ; +return qcom_snps_hsphy_resume (hsphy); } static int qcom_snps_hsphy_set_mode(struct phy *phy, enum phy_mode mode,
Signature · 7 lines
2.40.1 -- linux-phy mailing list [email protected] https://lists.infradead.org/mailman/listinfo/linux-phy
Quoted 13 lines · Adrien Thierry
This series contains a few fixes for the qcom-snps-femto-v2 driver, mostly clock-related.
v3 -> v4
- remove commit that added system sleep PM ops
- add commit "phy: qcom-snps-femto-v2: keepcfg_ahb_clkenabled during runtime suspend"
- "phy: qcom-snps-femto-v2: properly enable ref clock"
- dropped "HACK:" comment (Bjorn Andersson)
- check forIS_ERR()for the optionalcfg_ahbclock (Bjorn Andersson)
- don't print an error message in caseclk_bulk_prepare()fails (Bjorn Andersson)
Quoted 1 line
[...]
Applied, thanks!
[1/3] phy: qcom-snps-femto-v2: keep cfg_ahb_clk enabled during runtime suspend
commit: 825c6d29f129e3e74dc2b4a7435bc64ff34ab5f6
[2/3] phy: qcom-snps-femto-v2: properly enable ref clock
commit: d621660a1d5bba54494367a2fa8c5bb294ad002b
[3/3] phy: qcom-snps-femto-v2: use qcom_snps_hsphy_suspend/resume error code
commit: 0383f66b80733c90fd841836ca541ad4c1fc203fBest regards,
Signature · 1 line
~Vinod