diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c b/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c index fa8492b487d7..e3465ab7c80e 100644 --- a/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c +++ b/drivers/phy/qualcomm/phy-qcom-qmp-usbc.c @@ -2003,10 +2003,16 @@ static int qmp_usbc_probe(struct platform_device *pdev) if (ret) goto err_node_put; + /* + * Enable runtime PM before creating the PHYs, phy_create() only enables + * it on the PHY devices if already enabled on the parent. Hold a usage + * reference so callbacks cannot run until the PHY is ready. + */ + pm_runtime_get_noresume(dev); pm_runtime_set_active(dev); ret = devm_pm_runtime_enable(dev); if (ret) - goto err_node_put; + goto err_pm_put; /* * Prevent runtime pm from being ON by default. Users can enable * it using power/control in sysfs. @@ -2015,13 +2021,13 @@ static int qmp_usbc_probe(struct platform_device *pdev) ret = qmp_usbc_register_clocks(qmp, np); if (ret) - goto err_node_put; + goto err_pm_put; qmp->usb_phy = devm_phy_create(dev, np, &qmp_usbc_usb_phy_ops); if (IS_ERR(qmp->usb_phy)) { ret = PTR_ERR(qmp->usb_phy); dev_err(dev, "failed to create PHY: %d\n", ret); - goto err_node_put; + goto err_pm_put; } phy_set_drvdata(qmp->usb_phy, qmp); @@ -2031,17 +2037,25 @@ static int qmp_usbc_probe(struct platform_device *pdev) if (IS_ERR(qmp->dp_phy)) { ret = PTR_ERR(qmp->dp_phy); dev_err(dev, "failed to create PHY: %d\n", ret); - goto err_node_put; + goto err_pm_put; } phy_set_drvdata(qmp->dp_phy, qmp); } + phy_provider = devm_of_phy_provider_register(dev, qmp_usbc_phy_xlate); + if (IS_ERR(phy_provider)) { + ret = PTR_ERR(phy_provider); + goto err_pm_put; + } + of_node_put(np); - phy_provider = devm_of_phy_provider_register(dev, qmp_usbc_phy_xlate); + pm_runtime_put(dev); - return PTR_ERR_OR_ZERO(phy_provider); + return 0; +err_pm_put: + pm_runtime_put_noidle(dev); err_node_put: of_node_put(np); return ret;