usb: gadget: tegra-xudc: Fix idle suspend/resume
authorThierry Reding <treding@nvidia.com>
Fri, 17 Apr 2020 17:05:37 +0000 (19:05 +0200)
committerFelipe Balbi <balbi@kernel.org>
Sat, 9 May 2020 08:05:08 +0000 (11:05 +0300)
When the XUDC device is idle (i.e. powergated), care must be taken not
to access any registers because that would lead to a crash.

Move the call to tegra_xudc_device_mode_off() into the same conditional
as the tegra_xudc_powergate() call to make sure we only force device
mode off if the XUDC is actually powered up.

Fixes: 49db427232fe ("usb: gadget: Add UDC driver for tegra XUSB device mode controller")
Acked-by: Jon Hunter <jonathanh@nvidia.com>
Tested-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
drivers/usb/gadget/udc/tegra-xudc.c

index 52a6add..dfabc54 100644 (file)
@@ -3840,11 +3840,11 @@ static int __maybe_unused tegra_xudc_suspend(struct device *dev)
 
        flush_work(&xudc->usb_role_sw_work);
 
-       /* Forcibly disconnect before powergating. */
-       tegra_xudc_device_mode_off(xudc);
-
-       if (!pm_runtime_status_suspended(dev))
+       if (!pm_runtime_status_suspended(dev)) {
+               /* Forcibly disconnect before powergating. */
+               tegra_xudc_device_mode_off(xudc);
                tegra_xudc_powergate(xudc);
+       }
 
        pm_runtime_disable(dev);