usb: host: xhci-plat: suspend and resume clocks
authorJustin Chen <justinpopo6@gmail.com>
Wed, 10 Aug 2022 22:27:34 +0000 (15:27 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:35:46 +0000 (12:35 +0200)
[ Upstream commit 8bd954c56197caf5e3a804d989094bc3fe6329aa ]

Introduce XHCI_SUSPEND_RESUME_CLKS quirk as a means to suspend and resume
clocks if the hardware is capable of doing so. We assume that clocks will
be needed if the device may wake.

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Justin Chen <justinpopo6@gmail.com>
Link: https://lore.kernel.org/r/1660170455-15781-2-git-send-email-justinpopo6@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/host/xhci-plat.c
drivers/usb/host/xhci.h

index dc570ce4e8319ad09d6088e3dc2ee557ccba5c78..2687662f26b61cf3d6e84204800e09d7c186097c 100644 (file)
@@ -447,7 +447,16 @@ static int __maybe_unused xhci_plat_suspend(struct device *dev)
         * xhci_suspend() needs `do_wakeup` to know whether host is allowed
         * to do wakeup during suspend.
         */
-       return xhci_suspend(xhci, device_may_wakeup(dev));
+       ret = xhci_suspend(xhci, device_may_wakeup(dev));
+       if (ret)
+               return ret;
+
+       if (!device_may_wakeup(dev) && (xhci->quirks & XHCI_SUSPEND_RESUME_CLKS)) {
+               clk_disable_unprepare(xhci->clk);
+               clk_disable_unprepare(xhci->reg_clk);
+       }
+
+       return 0;
 }
 
 static int __maybe_unused xhci_plat_resume(struct device *dev)
@@ -456,6 +465,11 @@ static int __maybe_unused xhci_plat_resume(struct device *dev)
        struct xhci_hcd *xhci = hcd_to_xhci(hcd);
        int ret;
 
+       if (!device_may_wakeup(dev) && (xhci->quirks & XHCI_SUSPEND_RESUME_CLKS)) {
+               clk_prepare_enable(xhci->clk);
+               clk_prepare_enable(xhci->reg_clk);
+       }
+
        ret = xhci_priv_resume_quirk(hcd);
        if (ret)
                return ret;
index 10a4230d95c37c2c1826ef6626310a557f7ba211..3b39501f26ea9cb96bb0ec7ce4f12c1d400b0b48 100644 (file)
@@ -1903,6 +1903,7 @@ struct xhci_hcd {
 #define XHCI_NO_SOFT_RETRY     BIT_ULL(40)
 #define XHCI_BROKEN_D3COLD     BIT_ULL(41)
 #define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42)
+#define XHCI_SUSPEND_RESUME_CLKS       BIT_ULL(43)
 
        unsigned int            num_active_eps;
        unsigned int            limit_active_eps;