MLK-10102-7 usb: chipidea: otg: fix deadlock of usb host removal after system resume
This is to fix possible deadlock of usb host with mass storage removal after
system resume, by waiting host finish device disconnection and then stop host
This is a patch merge for ideas from below 2 patches:
ENGR00308442-2 usb: chipidea: otg: wait devices disconnected before stop host.
ENGR00310498 usb: chipidea: otg: fix otg role switch from host to device failure
How to reproduce:
Failure case 1:
- Enable console wakeup:
echo enabled > /sys/class/tty/ttymxc0/power/wakeup
- Connect a udisk with ID cable to OTG port.
- Suspend the system:
ehco mem > /sys/power/state
- Remove ID cable together with udisk.
- Wakeup the system by console.
- OTG port cannot switch to device role.
Failure case 2:
- Connect a udisk with ID cable to OTG port.
- Enable usb wakeup by ./low_power_usb.sh
- Suspend the system:
ehco mem > /sys/power/state
- Remove ID cable together with udisk.
- System wakeup but OTG port cannot switch to device role.
Root cause:
In this case, ID change interrupt generates before port change interrupt,
so with irq disabled, ci_handle_id_switch() will find there is usb device
still connected and wait it to disconnect by sleep, but disconnect will not
happen since usb irq still disabled so port change irq has no chance to be
handled.
How this patch is fixing this issue:
This patch waits host finish handle usb device disconnection before stop host,
and enables irq before sleep and disables irq after, thus port change
rq can be handled and usb device disconnection can timely happen, then
ci_handle_id_switch() can stop host and switch to device role correctly.
Signed-off-by: Li Jun <b47624@freescale.com>
(cherry picked from commit
56d79fbaa4bea3670542a96354ee7034239a1c1f)
(cherry picked from commit
d5350035b22cfa1cef15956612a4eec36b4dc0de)