From d8b7417beaa3ec81e8d2e41bd325949dd901c153 Mon Sep 17 00:00:00 2001 From: William Wu Date: Tue, 31 Aug 2021 16:38:44 +0800 Subject: [PATCH] usb: dwc3: core: allow pm runtime for rockchip platform Most of rockchip platforms support power domain for dwc3. Allow the pm runtime to manage the power domain for dwc3 in the dwc3 runtime PM routine. Signed-off-by: William Wu Change-Id: I49e3fa207db8aea0355a797b69c9c8a791d2eaa3 --- drivers/usb/dwc3/core.c | 9 ++++++++- drivers/usb/dwc3/gadget.c | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 4cea590ca3f6..919090293487 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1642,7 +1642,14 @@ static int dwc3_probe(struct platform_device *pdev) goto err5; dwc3_debugfs_init(dwc); - pm_runtime_put(dev); + + if (of_device_is_compatible(dev->parent->of_node, + "rockchip,rk3399-dwc3")) { + pm_runtime_allow(dev); + pm_runtime_put_sync_suspend(dev); + } else { + pm_runtime_put(dev); + } return 0; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 2b8377dbbab5..01b923cae95c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2581,6 +2581,15 @@ static int __dwc3_gadget_start(struct dwc3 *dwc) int ret = 0; u32 reg; + /* + * If the DWC3 is in runtime suspend, the clocks maybe + * disabled, so avoid enable the DWC3 endpoints here. + * The DWC3 runtime PM resume routine will handle the + * gadget start sequence. + */ + if (pm_runtime_suspended(dwc->dev)) + return ret; + /* * Use IMOD if enabled via dwc->imod_interval. Otherwise, if * the core supports IMOD, disable it.