Skip to content

Commit a94f018

Browse files
Artur Petrosyangregkh
authored andcommitted
usb: dwc2: Add exit hibernation mode before removing drive
When dwc2 core is in hibernation mode loading driver again causes driver fail. Because in that mode registers are not accessible. In order to exit from hibernation checking dwc2 core power saving state in "dwc2_driver_remove()" function. If core is in hibernation, then checking the operational mode of the driver. To check whether dwc2 core is operating in host mode or device mode there is one way which is retrieving the backup value of "gotgctl" and compare the "CurMod" value. If previously core entered hibernation in host mode then the exit is performed for host if not then exit is performed for device mode. The introduced checking is because in hibernation state all registers are not accessible. Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Acked-by: Minas Harutyunyan <[email protected]> Signed-off-by: Artur Petrosyan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ae0da4f commit a94f018

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/usb/dwc2/platform.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,23 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
316316
static int dwc2_driver_remove(struct platform_device *dev)
317317
{
318318
struct dwc2_hsotg *hsotg = platform_get_drvdata(dev);
319+
struct dwc2_gregs_backup *gr;
319320
int ret = 0;
320321

322+
gr = &hsotg->gr_backup;
323+
324+
/* Exit Hibernation when driver is removed. */
325+
if (hsotg->hibernated) {
326+
if (gr->gotgctl & GOTGCTL_CURMODE_HOST)
327+
ret = dwc2_exit_hibernation(hsotg, 0, 0, 1);
328+
else
329+
ret = dwc2_exit_hibernation(hsotg, 0, 0, 0);
330+
331+
if (ret)
332+
dev_err(hsotg->dev,
333+
"exit hibernation failed.\n");
334+
}
335+
321336
/* Exit Partial Power Down when driver is removed. */
322337
if (hsotg->in_ppd) {
323338
ret = dwc2_exit_partial_power_down(hsotg, 0, true);

0 commit comments

Comments
 (0)