USB: msm_otg: Fix race between PM resume and charger detection
When device is in system suspend and USB charger is disconnected,
then due to VBUS clear IRQ from PMIC, the device will be PM resumed.
Now shortly if PMIC driver detects valid VBUS it will handle VBUS
set condition,notifies to msm_otg and msm_otg will kick in charger
detection mechanism. During PM resume, in dmp_complete() it will
call a pm_runtime_put_sync(), which will immediately kick off the
PM runtime idle and suspend routines.
dpm_complete()
->device_complete()
->pm_runtime_put_sync()
->rpm_idle()
->rpm_suspend()
The PM resume also runs in a separate worker queue, so it is not
guaranteed that it will finish executing before we finish the charger
detection stage. During this case there is a race if dpm_complete()
returns before charger detection starts. Return of dmp_cpmplete()
before charger detection will make USB to enter LPM. As USB will be
in LPM now and if charger detection starts then it will lead to
unclocked access.
Fixing the issue by handling the pm usage count using the variable
pm_done in msm_otg. When USB charger is disconnected and msm_otg
processes the disconnect event it marks the pm_done to true. Later
when USB charger is connected , mark the pm_done to false in
msm_otg_runtime_resume(). If pm_done is true increment the pm counter
using pm_runtime_get_sync. This handles the race case when PM resume
thread returns before the charger detection starts.
CRs-Fixed: 599143
Change-Id: I6de19fe850e24efa03ea71c7d14e388c15cf2f97
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
2 files changed