USB: Allow skipping device resume during system resume

Some buses would like to keep their devices in suspend state during system
resume.  For example HSIC controller driver prevent system suspend when
HSIC device is active.  If this device is resumed, during system resume
HSIC controller acquire wake lock and prevent the subsequent suspend till
HSIC device is auto suspended.

(cherry picked from commit 6f199aa800253a69e5679d1057823039f1bd65c9)

Change-Id: Id9b15a20345423c6f33fd7d8cd2a55372a1e6b4b
CRs-Fixed: 403975
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
Signed-off-by: franciscofranco <franciscofranco.1990@gmail.com>
EHCI: HSIC: Handle wakeup interrupt properly during probe

During HSIC probe driver registers the level triggered interrupt
on wakeup gpio. Wakeup irq line is disabled based on the return
status of interrupt registration. There is a possibility that
wakeup gpio is already pulled high after registering the interrupt
which can cause wakeup interrupts to be fired on continuously
without getting chance to disable the irq line. Hence do not
enable wake up interrupt on request irq.

CRs-Fixed: 394540
Change-Id: I3175cd8710f1d982c33a5392cc49106ee66d0aa6
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
EHCI: HSIC: Add enhancements to debug logging

This change addresses following enhancements to debug
logging:-

1) Add data payload logging which is not currently
supported. This helps to sniff first 32 bytes of data
being sent and received. Data payload logging is
enabled by default. To disable data payload logging:-

echo 0 > /sys/module/ehci_hcd/parameters/enable_payload_log

2) Current urb submission event logging does not cover
root hub submissions, hence move urb submission logging
to hcd driver.

3) Current urb submission event logging does not return
the correct status if submission fails. Hence log the
return status of urb submission.

CRs-Fixed: 393294
Change-Id: Ic7e555e1545ec7d7b0e4042cd35235e0af26fb01
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
usb: ehci-msm-hsic: Fix compilation error

The ehci-msm-hsic driver's bus suspend and resume functions
depend on ehci_hcd's bus_suspend/resume functions, which are
NULL when CONFIG_PM is not defined. Fix the compilation error
by also #defining these sub-driver functions NULL, as they
are effectively no-ops.

Change-Id: Ie250dfae3caccb737ce26bdda17c5b21d358eced
Signed-off-by: Jack Pham <jackp@codeaurora.org>
usb: Add support to set autosuspend delay by controller driver

USB core driver sets the autosuspend delay to 1 sec for root hub and
its children by default. In case if delay needs to be changed for a
particular controller, it requires class driver to explicitly call
PM API to set the new values. Hence add a call back handler to set
autosuspend delay in controller driver. This makes class driver code
generic.

Change-Id: I62121651f0a9648a2909ca7eb4081a6c2567ed01
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
usb: ehci-msm-hsic: Remove usage of MSM_GPIO_TO_INT

MSM_GPIO_TO_INT is a platform-specific macro that should only
be used in board files, not drivers. In this case, we actually
don't need the GPIO number in the driver itself and only need
to manipulate it using the IRQ number it maps to, so perform the
mapping in the device file.

Change-Id: I99eb964f3c7c4e90a4d75d16b2b29c687c3437ca
Signed-off-by: Jack Pham <jackp@codeaurora.org>
usb: Decrease autosuspend delay to 200ms upon usb disconnect

Reduce overall HSIC wakelock active time by decreasing autosuspend
delay for HSIC mdm device from 1 sec to 200ms. However when diag is
active it would send poll events for every 500ms causing frequent
supsend/resume. Avoid this by increasing autosuspend delay to 1 sec
when diag is active. Also, set autosuspend delay for root hub to 0 by
default. These changes reduce time HSIC controller is active when the
bus is idle for better power savings.

CRs-Fixed: 404378
Change-Id: I0500f6b125dff158e6e0c10f3f2023b18ce9dd30
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
usb: ehci-msm-hsic: Add support in device tree to MSM HSIC host

Add support in device tree to MSM HSIC host including support in
GDSC (Global Distributed Switch Controller) for new platforms.

Change-Id: I6b0df0eabb03278b97b2b69f9fcdc2ef3806ba0b
Signed-off-by: Ofir Cohen <ofirc@codeaurora.org>
usb: ehci-msm-hsic: Change HSIC reset sequence

Due to USB HW changes, RST CMD resets CSC/CCS fields in PORTSC
and PCI bit in USBSTS. Therefore HSIC reset sequence should be
changed to avoid case that the device was powered up before the
host and due to a RST CMD the host will miss that the device is
connected.

CRs-Fixed: 417642
Change-Id: I2b1fb2a92658058d70ccc6cb5f73174ce4128b72
Signed-off-by: Ofir Cohen <ofirc@codeaurora.org>
USB: HSIC: Add support for HSIC core and SMSC HUB using DT

Add device tree support in SMSC HUB driver which also registers
platform_device for HSIC as its child. This allows SMSC HUB driver
to turn OFF clocks for power savings after HSIC is suspended.
Also add support for SMSC HUB to use dedicated clock as ref_clk
instead of XO.

Change-Id: I3e8828ddc232936df3e21c8e1158af92b16996a2
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
usb: ehci-msm-hsic: Add asynchronous reset to HSIC

Add support for asynchronous block reset to the HSIC hardware.
In platforms that uses an asynchronous reset methodology,
the HSIC alt_core_clk is not presented.

Change-Id: I0dc0e1bf294260a5530e01660d970cc939a9dbec
Signed-off-by: Ofir Cohen <ofirc@codeaurora.org>
USB: HSIC: Fix setting of strobe and data gpios for HSIC host

Since the following commit I3e8828ddc232936df3e21c8e1158af92b16996a2
the ehci msm hsic host driver read device tree settings as the strobe
and the data gpios. In case that these gpios not exists in the device
tree the return value is negative. The return value was assigned to
unsigned variables, therefore the driver assumes that there are
such gpios.
This fix handles correctly the return value of the of_get_named_gpio.

Change-Id: Ia5dde57cc36438b977791df658375e0946123096
Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
usb: host: ehci: allow ehci_bus_resume symbol to be unused

All the platforms may not use ehci_bus_resume symbol in their
hc_driver structure. This may result in below warning:

drivers/usb/host/ehci-hub.c: warning: 'ehci_bus_resume' \
    defined but not used

In order to remove this warning add '__maybe_unused' annotation
to ehci_bus_resume function.

Change-Id: I3c97eed7555688d99d68618f3810197e574499cb
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
USB: ci13xxx_udc: Fix ENDPOINT PRIME failure issue

while queueing requests to USB HW, waiting till EP PRIME bit
get cleared after setting it leads to wathdog timeout. Fix
this by implementing timer based solution instead of infinite
PRIME check loop.

CRs-Fixed: 397907
Change-Id: I74e9acbfdfcd2030896d1fa813e66803ece7d5bd
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: ci13xxx_udc: Add timeout of 100ms for endpoint flush loop

Currently completion of endpoint flush operation is checked after
setting that endpoint bit with ENDPTFLUSH register and polling the
same to get it clear. It has been observed that sometime this flush
operation takes huge amount of time which results into watchdog
timeout issue due to this busy loop without any time-out. Hence add
time-out of 100ms for endpoint flush operation completion and also
add 100us delay before checking ENDPTFLUSH register for endpoint bit
clear or not.

Also print important usb status register and flushed endpoint dtds
at the time of issue.

CRs-Fixed: 409382
Change-Id: I7ae57cc436077f8a03051b92750bdca9a571da2b
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
usb: gadget: ci13xxx_msm: Allow BAM enable and disable

There are scenarios where the USB BAM has to be reset.
For example, when the peer BAM is being reset, the USB BAM
must be reset as well, otherwise the BAM-BAM connection will
go out of sync.

In order to reset the USB BAM, the USB controller has to disable
the BAM first. After the USB BAM reset is completed, the USB
controller has to re-enable the USB BAM.

So this change adds the support for USB BAM enable/disable.
This is done by adding an API to ci13xxx_msm. A function driver can
ask for BAM enable/disable by calling this API.

This change doesn't add the support for the USB BAM reset sequence.

CRs-Fixed: 424867
Change-Id: Ib5518fafe3765f86bb09d1ce10723ec733543b35
Signed-off-by: Amit Blay <ablay@codeaurora.org>

Conflicts:
	include/linux/usb/msm_hsusb.h
net: usb: Prevent suspend if response available notification received

There is a possibility of interface suspend after receiving response
available notification from mdm device. In this case driver unlinks
the rx urb and do not send GET_ENCAPSULATED_RESPONSE setup packet to
mdm. Response to mdm gets delayed up until interface resumes and mdm
sends response available notification again. Hence resume interface
after receiving response available notification if it is suspended.
Allow interface suspend only after completing
GET_ENCAPSULATED_RESPONSE.

Change-Id: Ib52e64b1cc7b6d5edfe3ada9651ec56526cf4852
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
net: usb: Abort suspend if get_encap response is not sent

After receiving response available notification driver queues
a work to send get_encap response. pm state is set to
RPM_SUSPENDING before interface suspend is initiated. If
interface suspend happens after queuing the work then work
will be executed and blocked until it is done. Work tries to
resume the interface synchronously by calling rpm_resume().
This causes rpm_resume() to wait indefinitely for the pm state
to change from RPM_SUSPENDED to RPM_RESUME which will not
happen until interface suspend returns EBUSY. Hence avoid this
situation by aborting interface suspend if work is pending
or running.

CRs-Fixed: 415208
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Change-Id: Ib2a079a7107d994f760c0a876736ede3add07ea2
net: usb: Handle interface suspend properly

Upon interface suspend driver performs suspend on data channel
first and then on control channel. In case if suspend aborts
due to pending transfer on control channel, driver is not
undoing data channel suspend. This causes stall on data channel.
Fix the problem by performing suspend check on control channel
first. In this case if suspend aborts on control channel, driver
does not have to undo anything to abort interface suspend. Once
data channel suspend succeeds driver performs suspend on control
channel.

Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
Change-Id: I405b4797740e1b2aa67c6c28a2f3dcee0c196391
net: usb: Define waitqueue head as static global variable

usbnet_terminate_urbs() defines waitqueue head as local variable.
There is a possibility that wake_up is called on this queue head
in workqueue context and usbnet_terminate_urbs() already returned
or dev->wait pointer becomes NULL while calling wake_up() from
workqueue context. Hence call wake_up() using waitqueue head
defined as static global variable.

CRs-Fixed: 388724
Change-Id: Ib7e6c3023b9d780af0466496b25e68113b2d3fd3
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>