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>

Conflicts:

	drivers/usb/host/ehci-msm-hsic.c
msm: hsic: Retry port RESUME if unable to send SOFs within 3ms

Due to h/w bug in hsic controller, interrupts are disabled during
resume signalling (~20ms), commit: e404049ae, which may result in
below issues
1. Delayed MDP interrupts causing display stutters
2. Since default workqueue disables preemption for 20ms, the kernel
   scheduler schedules out the worker thread for long time. It results
   in MDM crash due to delayed response
To avoid busy loop, port resume is performed without disabling the
interrupts. Due to this if resume time constraint is not met then
don't start SOF and retry RESUME after some time. This delay (w/o SOF)
lets the device to enter SUSPEND state (after issuing remote wakeup)
and followed by RESUME after sometime. Also, Move the resume code to
hsic controller driver to avoid changes to ehci upstream code.

CRs-Fixed: 383752
Change-Id: Ic4768587bbb9a00d8cf495065ec9e14c46a5c1d4
Signed-off-by: Vamsi Krishna <vskrishn@codeaurora.org>
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>

Conflicts:

	drivers/usb/host/ehci-msm-hsic.c
EHCI: HSIC: Prevent disabling wakeup irq twice

If PM resume and Wakeup irq happen at same time
its possible to disable wakeup irq twice. Prevent
the same by protecting with spinlock

CRs-Fixed: 396895
Change-Id: I3320478d6c770787bc571964f4a38dce6927af63
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
msm: hsic: Disallow processor idle sleep while driving resume signal

HSIC controller should send SOF with in 3 msec after completing
the resume signal.  If processor is in idle sleep state, the timer
interrupt generated by HSIC controller to indicate resume completion
gets delayed.  If the interrupt handler is not run with in 3msec
after resume, the resume sequence is repeated.  Disallow processor
idle sleep to avoid multiple resume cycles.

CRs-Fixed: 397154
Change-Id: Ibc8965ad8bcd94e0b1b1d39b5b2ad8f39cf51095
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
EHCI: HSIC: Fail root hub bus suspend when port is not enabled.

HSIC controller can not detect HSIC device in low power mode.  Hence
controller suspend is allowed only when port is enabled.  But this
check is done in controller suspend routine.  Controller suspend is
attempted after root hub bus is suspended.  Even if we fail, controller
suspend, root hub bus remains in suspend state.  This would delay
the enumeration of HSIC device as root hub bus resume takes some time.

CRs-Fixed: 396444
Change-Id: I9cfdfb4beb458651fc81a3d22ad9ac79207514fd
Signed-off-by: Pavankumar Kondeti <pkondeti@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>

Conflicts:

	drivers/usb/host/ehci-msm-hsic.c
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: 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: 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>
EHCI: HSIC: Allow standalone power collapse when HSIC is active

HSIC generates interrupt at 4ms interval. If idle power collapse
is enabled when HSIC is active, krait keeps on going into idle
power collapse requesting RPM to handle the sleep set requirement.
If HSIC interrupt comes after 4ms interval, krait comes out of idle
power collapse and it again ask RPM to handle this request therefore
keeps RPM busy handling requests due to frequent idle power collapse.
This has a power impact. Hence only allow standalone power collapse
when HSIC is active to avoid RPM involvement in assisting kraits to
power collapse. Vote for idle power collapse when HSIC goes to low
power mode.

Change-Id: Iee8bc1fa180499f2d26fbac955a6a6ed767fdeb4
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>

Conflicts:

	arch/arm/mach-msm/board-8064.c
EHCI: HSIC: Add support to vote for SVS digital voltage

HSIC HW can operate at SVS digital voltage when it is active.
Currently HSIC is voting for 120Mhz SFAB and 64Mhz DFAB clock
frequencies. Clock frequencies are directly proportional to SVS
voltage. If DFAB is running at 64Mhz or SFAB is running at 120Mhz
or higher SVS is not possible even though HSIC votes for it. Hence
do not vote for SFAB clock frequency and only vote for 32Mhz for
DFAB in order to allow SVS to happen. Voting for SVS voltage reduces
current consumption by 3mA in HSDPA network.

Change-Id: I8a6844efbbe90a8ea118be8450f8210717c2641b
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>
EHCI: HSIC: Fix GPT timer count values used for resume sequence

The counter value to be loaded into GPT timer represents the time
in micro seconds minus 1 for the timer duration.  The current code
incorrectly programs the timer.  Fix it.

Change-Id: Ief8039b4e75910001d31a7c05b3b274e6e66c2da
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
EHCI: HSIC: Handle asynchronous interrupt properly

Runtime PM resume and asynchronous interrupt can run in parallel. When
this happens, there is a possibility of PM usage counter mismatch.
Fix this by checking the return value of pm_runtime_get() and by
disabling the USB interrupt while resuming the HSIC.

Consider asynchronous interrupt case when resuming HSIC during system
resume.

CRs-Fixed: 444883
Change-Id: I315fb6cecffcea83c03037be899e3ff840791c21
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>

Conflicts:

	drivers/usb/host/ehci-msm-hsic.c
EHCI: HSIC: Disable asynchronous interrupt when wakeup gpio is present

Controller can generate interrupt asynchronously in low power mode (LPM).
Enable this interrupt in USBCMD register only when wakeup gpio IRQ is
not available.

CRs-Fixed: 444883
Change-Id: I8f68fa63c1c086990ff429cd1224e14a1d34654b
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
msm: msm_bus: Add device tree support for bus scaling clients

This patch enables clients to specify vectors in device tree
format. Clients will no longer need to specify vectors in
the boards file. Instead, they can add the bus-scaling
related data to their own device-nodes.
The clients can then call an API exposed by the bus driver
which will build the pdata out of those strings.
The registration process using pdata remains unchanged.

Change-Id: I1bba645d031e2cd822f16d8edcdf926a0418618c
Signed-off-by: Gagan Mac <gmac@codeaurora.org>