mmc: omap_hsmmc: use spinlock IRQ safe variant

Prevent possible races between HSMMC/DMA IRQs and next requests.

Signed-off-by: Venkatraman S <svenkatr@ti.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
mmc: remove MMC bus legacy suspend/resume method

MMC bus is using legacy suspend/resume method, which is not compatible if
runtime pm callbacks are used. In this scenario, MMC bus suspend/resume
callbacks cannot be called when system entering S3. So change to use the
new defined dev_pm_ops for system sleeping mode.

Tested on AM335x Platform. Solves major issue/crash reported at
http://www.mail-archive.com/linux-omap@vger.kernel.org/msg65425.html

Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.com>
Tested-by: Hebbar, Gururaja <gururaja.hebbar@ti.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Ulf Hansson <ulf.hansson@stericsson.com>
Signed-off-by: Chris Ball <cjb@laptop.org>

Conflicts:
	drivers/mmc/core/bus.c
Fix compiling.
Using IRQ save spin lock routines.
Using IRQ save spin lock functions.
mmc: omap_hsmmc: fix timeout for cmd and data soft reset

With HSMMC_HAS_UPDATED_RESET reset of cmd/data (SRC/SRD) can be to
quick and can be missed resulting in wait for software timeout.
With cpu_relax timeout can be long and unpredictable. Use udelay
instead for timeout implementation.

Reported-by: Yuzheng Ma <mayuzheng@kedacom.com>
Tested-by: Yuzheng Ma <mayuzheng@kedacom.com>
Reviewed-by: Hein Tibosch <hein_tibosch@yahoo.es>
Signed-off-by: Jianpeng Ma <majianpeng@gmail.com>
Signed-off-by: Balaji T K <balajitk@ti.com>
Signed-off-by: Chris Ball <cjb@laptop.org>

Conflicts:
	drivers/mmc/host/omap_hsmmc.c
MMC CSD info can specify very large, ridiculous timeouts, big enough to
overflow timeout_ns. This can result in the card timing out on every
operation because the wrapped timeout value is far too small.

Fix the overflow by capping the result at UINT_MAX.  Cards specifying
longer timeouts are almost certainly insane, and host controllers
generally cannot support timeouts that long in any case.

Signed-off-by: Torne (Richard Coles) <torne@google.com>
Signed-off-by: Quallenauge <Hamsi2k@freenet.de>
mmc: core: new discard feature support at Samsung eMMC v4.41+.

Support discard feature if MID field in the CID register is 0x15, EXT.CSD[192]
(device version) is 5 and Bit 0 in the EXT.CSD[64] is 1. Also removed REQ_SECURE flag
check to avoid kernel hang.

This patch is released from samsung.

Change-Id: I6531b9301c956ca0b65e6dde9468e08459ee09ca

Conflicts:
	drivers/mmc/card/block.c
Backport low memory killer from 3.4.
(Left cma logic out.)

Conflicts:
	drivers/staging/android/lowmemorykiller.c
    Backport alarmtimer/alarm-dev from google kernel 3.10 fork to support newly introduced clocks such as
    - CLOCK_BOOTTIME_ALARM
    - CLOCK_REALTIME_ALARM
    which where used by the android healthd daemon.

Conflicts:
	drivers/power/twl6030_bci_battery.c
	drivers/rtc/alarm-dev.c
	drivers/rtc/alarm.c
	fs/fcntl.c
fix: Backport alarmtimer/alarm-dev. Deleted abandoned files
USB: MUSB: Fix L3 error when USB-OTG plug/unplug to PC many times during Kernel boot.

L3 CUSTOM SRESP error appears on early stage of kernel boot and USB OTG repeating  plug/unplug  to PC.
Source:
[    2.258453] Master 0x0        MPU
[    2.258453] L4CFG OPCODE  0x00000002

Root cause is MUSB-OMAP2430 runtime suspending during PHY power on.

Fix:
pm_runtime_get_sync() is used.

modified:   drivers/usb/musb/omap2430.c

Change-Id: I59fa9db641caba811123f3724fbc17333f1458b1
Signed-off-by: x0169938 <vasyl.yushchyshen@ti.com>
usb: musb: Fix memory corruption

rx_count, the number of bytes in the rx fifo, may be larger than the
size of the transfer buffer. Make sure we don't overflow the transfer
buffer in that case.

Bug: 6497399
Change-Id: I5bcf6dd543f9da4ee22944aa6c41673f2cca4c1f
Signed-off-by: Benoit Goby <benoit@android.com>
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
usb: musb: Fix crash when dma is nuked while irq handler is pending

It appears possible for the dma to get nuked while the irq handler
is pending/about to run.  The dma is cancelled by nuke() but the
irq handler will still run and wind up dereferencing NULL, so add
a check.

Crash log:

[ 7629.098815] Unable to handle kernel NULL pointer dereference at virtual address 00000004
[ 7629.099273] pgd = c0004000
[ 7629.099456] [00000004] *pgd=00000000
[ 7629.099761] Internal error: Oops: 17 [#1] PREEMPT SMP
[ 7629.100067] Modules linked in:
[ 7629.100402] CPU: 0    Not tainted  (3.0.8-gcb25bf2 #1)
[ 7629.100585] PC is at txstate+0x74/0x1ec
[ 7629.100891] LR is at musb_g_tx+0x138/0x1d8
[ 7629.101074] pc : [<c033f1cc>]    lr : [<c033fc9c>]    psr: 20000193
[ 7629.101074] sp : c06efd60  ip : c06efd98  fp : c06efd94
[ 7629.101531] r10: 00000018  r9 : 00000000  r8 : 00000200
[ 7629.101684] r7 : 00000000  r6 : fc0ab110  r5 : c7852448  r4 : c7125c00
[ 7629.101867] r3 : 00000000  r2 : 00000000  r1 : 00000002  r0 : c78520e4
...
[ 7629.228668] [<c033f158>] (txstate+0x0/0x1ec) from [<c033fc9c>] (musb_g_tx+0x138/0x1d8)
[ 7629.229003] [<c033fb64>] (musb_g_tx+0x0/0x1d8) from [<c033d35c>] (musb_interrupt+0x104/0x8cc)
[ 7629.229187] [<c033d258>] (musb_interrupt+0x0/0x8cc) from [<c033db7c>] (generic_interrupt+0x58/0x8c)
[ 7629.229522] [<c033db24>] (generic_interrupt+0x0/0x8c) from [<c00da008>] (handle_irq_event_percpu+0x54/0x188)
[ 7629.229827]  r6:00000000 r5:c06f3f4c r4:c78f49c0 r3:c033db24

Change-Id: I305c80a246f5161f2d3d20839c5603376d5b746c
Signed-off-by: Mike J. Chen <mjchen@google.com>
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
usb: gadget: android: Honor CONFIG_USB_GADGET_VBUS_DRAW

The maximum current draw was hard coded to 500 mA.  composite.c
has code that uses CONFIG_USB_GADGET_VBUS_DRAW to set the
bMaxPower and to set whether or not the device is self-powered if
they haven't been set.  This change removes the code in android.c
to allow composite.c to set them.

Change-Id: I9db37922e91ee86e9e5c0e14519e119e5c41ca48
Signed-off-by: Scott Anderson <saa@google.com>
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
usb: musb: host: do not use (un)map_urb_for_dma hooks if DMA is not used

There is no any sense in using (un)map_urb_for_dma
for non-DMA mode (such as PIO). Do not use these
hooks if CONFIG_MUSB_PIO_ONLY mode selected

Change-Id: I913af2cc0a208a660308124c79007e05365618a4
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
OMAP4: USB: remove unused function twl6030_set_phy_clk

This function is redundant and not used anywhere.
Remove it and change associated code accordingly

Change-Id: I06ba222429cfe89a401b426a211d1752e646450a
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
OMAP4: USBTLL: Off mode disconnect workaround (Errata i754)

When resuming from OFF mode, the EHCI controller was performing a
reset resume for ports using the TLL interface because the port
status was being cleared. This was caused by the host controller
not restoring the state of the ID pin in the TLL module correctly.
This issue is workarounded by enabling the ID pin pull-up in the TLL
(because the EHCI controller is always the host) and disabling ID
pin events as these are not required for the TLL connection.

Change-Id: Ibc22d77606e05e4dd138819079028ebcf254039e
Signed-off-by: Jon Hunter <jon-hunter@ti.com>
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
Revert "HACK: fix ehci suspend/resume failure"

This reverts commit 4288c066b40204f8b3b09e5b8c9c2754ce92c5d9.

Conflicts:

	drivers/usb/host/ehci-hub.c

Revert this hack for implementing new SW WA in correct place

Change-Id: I958271dfb454801437065299977228be76d0b956
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
usb: ehci-omap: reimplement workaround for errata i693

The OMAP4 EHCI controller has the following defect (errata ID i693):

Title:
	USB HOST EHCI - Port Resume Fails On Second Resume Iteration

Description:
	When entering USB suspend mode, the EHCI will automatically
	ask the PHY to enter low power mode (PHY function control
	register bit suspendM is reset).
	The PHY will then cut the ULPI_CLK after a minimum of 5
	clock cycles.(no maximum specified). On the other hand,
	the EHCI embeds a counter counting up to 18 before cutting
	the internal clock after suspend signal is asserted. Since
	the PHY cuts the clock prematurely, the counter is not
	reaching 18. However, the first suspend and resume will work
	correctly. At the second suspend sequence, since the counter
	has maintained the value (thanks to retention flops),
	the counter reaches 18 and cuts the clock internally.
	As a consequence, the internal state machine does not
	transition to the correct state causing the next resume to fail.
	Both host initiated resume and remote wakeup are impacted
	by this issue.

Workaround
	After setting the suspend bit, switch the internal clock
	supply from the external ULPI_CLK provided by the PHY to
	the internal 60 MHz clock. This will allow the internal
	counter to reach 18. Then after 1ms, switch back to
	the external ULPI_CLK. This switch can be done thanks
	to the CM_L3INIT_HSUSBHOST_CLKCTRL[25:24]:CLKSEL_UTMI_P1/2 bits.
	During the application of the WA, the
	CM_L3INIT_HSUSBHOST_CLKCTRL[9:8]OPTFCLKEN_UTMI_P1/2_CLK
	optional clocks need to be enabled.

All OMAP4430 devices are impacted.

Change-Id: Ifb127cf86a8aeaa10a996403cf8f4e2a68d1ab23
Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>