usb: dwc3: reduce the charger detection dcd poll time to 1.5s

There are some old chargers which have dp/dm floating. Since
that charger are out of spec, usb driver cannot detect charger
type until poll retry end. Previously it took 10 sec.
Reduce the charger detection retry time to 1.5s for quick
abnormal charger detection.

Change-Id: Idf671f23c2372aeed0b279865fa2c4f2088a8d31
Signed-off-by: mohamed.khadri <mohamed.khadri@lge.com>
Signed-off-by: choongryeol.lee <choongryeol.lee@lge.com>
USB: msm_otg: Add support for configuring MPM interrupt for remote wakeup

On some platforms, DP and DM lines are routed to MPM for detecting
data lines transition during VDD minimization. Hence allow VDD
minimization during host bus suspend and depend on MPM for usb remote
wakeup on platforms where detection of peripherals are supported
through MPM interrupt.

Change-Id: I8d72ebf83cab014e3c4839484982c9ae115757a1
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
Revert "USB: dwc3: ep0.c: Disable U1 and U2 low power modes"

Commit 4f1de530f4d5989022d9594413132ea175c2845e disabled U1 and
U2 low power modes to avoid USB reenumeration issue seen during
data transfers in superspeed mode. This USB reenumeration is
resolved by commit Ibd5d8180202b2f877304be3da9d976fe54df3eed
"USB: dwc3: core: Set elastic buffer mode to zero". Hence revert
the commit to reenable U1 and U2 low power modes, otherwise USB3
complaince tests fail.

CRs-Fixed: 483202
Change-Id: I87443c9dc4cac443137f64998ced9fda1e583a44
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
usb: dwc3-msm: replace wakelock with wakeup source

As the wakelock API is now banned, use the underlying
wakeup_source-based implementation directly.

Change-Id: Id6abe00f77b94b4fe82af19def5138e3286ed456
Signed-off-by: Jack Pham <jackp@codeaurora.org>
USB: dwc3: Don't handle USB/Link Status change event for RESUME

USB3 device controller will generate resume wakeup detected event
and also USB/Link status change event when USB Host initiates a
resume condition on the USB bus. Due to this, controller driver
calls gadget_driver->resume two times. This is leading to driver
sending missed disconnect uevent to userspace when it schedules
android_work to send uevent for second resume. As calling resume
from ULSTChng event is reduntant and hence should be removed.

CRs-Fixed: 548429
Change-Id: I8448dd42b20b84eebb68da1a1c83ea2849221f45
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3: Clear USB2PHY_SUSP bit during disconnect

Currently GUSB2PHY_SUSP bit is set in GUSB2PHYCFG(0) register
as part of initialization sequence and not clearing that bit
after that. If this bit is set during charger detection, it is
causing issues with VDP_SRC and IDM_SINK like VDP_SRC is not getting
applied within time, IDM_SINK is not large enough, due to which
battery charging complaince tests are failing with complaince test
device. Hence set this bit during peripheral/host start and clear
the bit while stopping peripheral/host role.

Also reduce the debouncing delay which should be in range [0-120]msec
for VBUS. Otherwise seeing battery charging complaince tests fail
due to bigger delay.

CRs-Fixed: 543926
Change-Id: I9ea87a19b43ce7804748dd3735ac436f77cdf933
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: android: Schedule work only if suspended variable is changed

currently as part of USB link status change event for U3 -> U0,
DWC3 controller driver is not calling driver resume. This results
in not updating suspended status in composite layer due to which
disconnect, configured and then disconnect events are sent to userspace.
This might cause problems for some userspace applications. Hence handle
USB link status event for resume by reverting the commit b217f5007d
("USB: dwc3: Don't handle USB/Link Status change event for RESUME").
Fix actual issue of disconnect sent during suspend/resume in android.c
by scheduling work only if the suspended status is changed to notify
userspace.

CRs-Fixed: 569639
Change-Id: If4fe6f3e8087d3bc972705ff40e4f94f597e2d09
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: msm_otg: Add voting for sleep clock

USB PHY is provided sleep clock on few platform which is
required to enable for USB PHY functionality. Hence add
support to vote sleep clock if it exists.

CRs-Fixed: 518353
Change-Id: I67006bfe3fbe9b3ad3e1d1e2ddb0e8e060437bd7
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
USB: msm_otg: Host: Allow XO shutdown only if no session is active

Currently msm_otg driver allows VDD minimization during host bus
suspend and depends on MPM for USB remote wakeup on platforms,
where D+ and D- lines are routed to MPM. As part of VDD minimization,
PHY will be put into retention state in which pull down resistors
are disabled. This scenario could cause issues without HW rework of
connecting pull down resistors on data lines. Hence don't allow
XO shutdown during host bus suspend if session is active.

Change-Id: Ic7274072cc4f266574cf45030bcadc469091c333
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
usb: msm_otg: Fix null ref pointer crash for some targets

Adding a check to ensure bus_scale_table exists in the platform data
before accessing it. This fix is good for targets which do not have
the bus_scale_table defined in the platform data.

Change-Id: I4ec1ce53b4b7cf545e8aae207e611fb8402ab491
Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
USB: gadget: f_mtp: Fix bug in receive_file work

If cable is disconnected while receive_file work is in progress,
there is a case where mtp driver returns -ECANCELLED instead of
-EIO. This results in mtp server thread not getting disconnect
notification and mtp release will not be called. Due to this, mtp
server will not start mtp connection after next USB connection.

CRs-Fixed: 590055
Change-Id: I909bebe0d22c19329cebb0a4a76424e08c82328c
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: u_serial: Don't free usb_requests in gs_close and reuse them

Commit: 950a3a3 "USB: Gadget: u_serial: Freeing usb requests as a
part of gs_close" results in freeing requests and flushing the EP
on every port close even if USB connection is present. These requests
are allocated again on port open. Also, EP flush call may result in
unclocked access of USB hardware if USB BUS state was suspended at
the time of port_close. This patch fixes that and also addresses the
original issue of gs_open allocating usb requests on every port_open
by adding a condition to allocate USB requests in port open only if
they are not already allocated.

CRs-fixed: 591617
Change-Id: If2ab31fa1d36ea6119dc0ced13ade5ed93d85d86
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
usb: xhci: Add support for SINGLE_STEP_SET_FEATURE test of EHSET

The Embedded High-speed Host Electrical Test (EHSET) procedure defines
the SINGLE_STEP_SET_FEATURE test for an embedded USB Host port. Upon
activating this test mode, the SETUP stage of a GetDescriptor request
is sent and followed by a delay of 15 seconds before finishing with
the DATA and STATUS stages. The idea is that this delay will give the
test operator sufficient time to configure the oscilloscope to perform
a measurement of the response time delay between the latter two stages.

This test is not implemented by the EHCI/xHCI host controller itself but
can be implemented in software. Similar to commit 75e845f64 ("usb: ehci:
Add support for SINGLE_STEP_SET_FEATURE test of EHSET"), this patch adds
such support to the xHCI driver.

CRs-fixed: 461710
Change-Id: I69aad8b068e40c13a58a66be917c185492615bfb
Signed-off-by: Jack Pham <jackp@codeaurora.org>
usb: xhci: Fix uninitialized variable compiler warning

Fix the following compiler warning:

drivers/usb/host/xhci-hub.c: In function 'xhci_hub_control':
drivers/usb/host/xhci-hub.c:544:6: warning: 'retval' may be used
uninitialized in this function error, forbidden warning: xhci-hub.c:544
make[7]: *** [drivers/usb/host/xhci-hub.o] Error 1

Change-Id: I4f7ab5fcfeaa3de9b9acc48571a92771935bc0be
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Revert "usb: dwc3: read charging current from slimport driver"

This reverts commit fae6a17d85882ea308761cbb5e1f3c35faae8aba.