USB: msm_otg: Process HOST disconnect only after system RESUME

If Host Cable (ID_GND) is disconnected in system suspend then
it results in race between device removal and device pm_resume.
PM core does't handle this correctly and sometimes frees up
parent device before children are resumed. To avoid this race
make sure that system has resumed completely before handling
ID_FLOAT (or host cable disconnect) event.

CRs-fixed: 652870, 651561
Change-Id: Id0956a9677d819d3fa3f17f54965cae38f2ee31d
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
USB: msm: Add support for MSM_USB_EXT_CHG_TYPE ioctl

Add support for MSM_USB_EXT_CHG_TYPE ioctl in driver for userspace to
notify kernel whether charger connected is external charger or not.

CRs-Fixed: 652965
Change-Id: I13095b4183efe3cfc690b7a9cb4f3c2d3cb4ee73
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: Fix bug in ext_chg_active flag handling

The ext_chg_active flag is set to true when the external charger
processing is pending. It is set to true when DCP is detected and
set to false when the user space notifies that it is done with
the charger detection. The user space may unblock the low power mode
any time to access the hardware to request a new voltage setting.
The current code does not set ext_chg_active flag in this case due to
which USB enters low power mode while external charger processing
is pending. This results in unclocked register access.
Fix the issue by setting ext_chg_active to true every time the
userspace calls the block LPM.

CRs-Fixed: 663301
Change-Id: If18f762d7fc0b4eaba297e27bbd7382b161fbcde
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>
usb: msm_otg: Fix bug with hvdcp connect and disconnect processing

The HVDCP charger is detected as a DCP charger by the USB driver. When a
DCP is detected, ext_chg_active flag is set to true and low power mode is
deferred by 3 seconds. When the user space receives the DCP connect uevent,
it kicks the charger detection algorithm. The charger detection procedure
involves reading and writing to the USB hardware registers and it makes an
ioctl call to block the low power mode by incrementing the pmruntime usage
counter. The user space calls the ioctl to unblock low power mode once
hvdcp detection is done by decrementing the pmruntime usage counter .

Consider the scenario where DCP detection is done and userspace makes
ioctl call to block low power mode. Next usb cable is disconnected and then
userspace makes ioctl call to unblock the low power mode by decrementing
the pmruntime usage counter. Due to this runtime suspend gets called and
USB clocks are turned off which later leads to unclocked access in
disconnnect processing. As part of USB disconnect, phy reset is done which
also involves ulpi register access. As clocks are turned off, it leads to
crash.

Fix the issue by making sure otg_sm work for usb disconnect is processed
first followed by decrementing the pmruntime usage counter in the ioctl
call made by userspace for unblocking the low power mode.

CRs-Fixed: 668648
Change-Id: I91db5f2e1084ae8f65dd8ec51c4314acc764c9c5
Signed-off-by: Saket Saurabh <ssaurabh@codeaurora.org>