Bluetooth : Ignore incomming events when the hci device is down

In error conditions Adapter state machine via Bluez tries to reset
the hci device, during that in some rare scenario if some pending event
comes from riva, the command complete apis tries to access some already
freed memory in reset sequence.

CRs-fixed: 369658
Signed-off-by: Bhasker Neti <bneti@codeaurora.org>
(cherry picked from commit 6f4ceb1f8588aec11b4d9380cd328d0008c8d167)

Change-Id: I7d72cc12ef98f15cc21bd5954c5ba9c810246716
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
cpufreq: Fix sysfs deadlock with concurrent hotplug/frequency switch

Running one program that continuously hotplugs and replugs a cpu
concurrently with another program that continuously writes to the
scaling_set_speed node eventually deadlocks with:

=============================================
[ INFO: possible recursive locking detected ]
3.4.0 #37 Tainted: G        W
---------------------------------------------
filemonkey/122 is trying to acquire lock:
 (s_active#13){++++.+}, at: [<c01a3d28>] sysfs_remove_dir+0x9c/0xb4

but task is already holding lock:
 (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(s_active#13);
  lock(s_active#13);

 *** DEADLOCK ***

 May be due to missing lock nesting notation

2 locks held by filemonkey/122:
 #0:  (&buffer->mutex){+.+.+.}, at: [<c01a2230>] sysfs_write_file+0x28/0x140
 #1:  (s_active#13){++++.+}, at: [<c01a22f0>] sysfs_write_file+0xe8/0x140

stack backtrace:
[<c0014fcc>] (unwind_backtrace+0x0/0x120) from [<c00ca600>] (validate_chain+0x6f8/0x1054)
[<c00ca600>] (validate_chain+0x6f8/0x1054) from [<c00cb778>] (__lock_acquire+0x81c/0x8d8)
[<c00cb778>] (__lock_acquire+0x81c/0x8d8) from [<c00cb9c0>] (lock_acquire+0x18c/0x1e8)
[<c00cb9c0>] (lock_acquire+0x18c/0x1e8) from [<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180)
[<c01a3ba8>] (sysfs_addrm_finish+0xd0/0x180) from [<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4)
[<c01a3d28>] (sysfs_remove_dir+0x9c/0xb4) from [<c02d0e5c>] (kobject_del+0x10/0x38)
[<c02d0e5c>] (kobject_del+0x10/0x38) from [<c02d0f74>] (kobject_release+0xf0/0x194)
[<c02d0f74>] (kobject_release+0xf0/0x194) from [<c0565a98>] (cpufreq_cpu_put+0xc/0x24)
[<c0565a98>] (cpufreq_cpu_put+0xc/0x24) from [<c05683f0>] (store+0x6c/0x74)
[<c05683f0>] (store+0x6c/0x74) from [<c01a2314>] (sysfs_write_file+0x10c/0x140)
[<c01a2314>] (sysfs_write_file+0x10c/0x140) from [<c014af44>] (vfs_write+0xb0/0x128)
[<c014af44>] (vfs_write+0xb0/0x128) from [<c014b06c>] (sys_write+0x3c/0x68)
[<c014b06c>] (sys_write+0x3c/0x68) from [<c000e0e0>] (ret_fast_syscall+0x0/0x3c)

This is because store() in cpufreq.c indirectly grabs a kobject
with kobject_get() and is the last one to call kobject_put()
indirectly via cpufreq_cpu_put().

Fix this deadlock by introducing two new functions,
cpufreq_cpu_get_sysfs() and cpufreq_cpu_put_sysfs() which do the
same thing as cpufreq_cpu_{get,put}() but don't grab the kobject.

CRs-fixed: 366560
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
(cherry picked from commit f82ef51be26b44b83d86afa56b3cd9c743023470)

Change-Id: Ia692e64dc3ce40f0ff3e209025a346f7d9b569da
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
msm_fb: display: Add pre-multiplied alpha support for MDP4.

MDP4 blend logic differs from GPU blend implementation as MDP4
does not differentiate between layers with pre-multiplied alpha
with that to non pre-multiplied alpha layers. Check layers for
pre-multiplied alpha and change blend logic accordingly.

CRs-Fixed: 355755
CRs-Fixed: 361729
CRs-Fixed: 366441
Change-Id: Idf3fef57bc3cc31a221b83027f5f3fa64dee5ae7
Signed-off-by: Mayank Chopra <makchopra@codeaurora.org>
Revert "msm: bam_dmux: Add locking around platform device calls"

This reverts commit 4dae83360bae84c6df12c53c995f772cb068eedb.

Change-Id: Ida541fefa769cd0a1692d3357c58f0556ee754e0
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
USB: ci13xxx_udc: Flush ep0IN and ep0OUT endpoint from ep_dequeue

Flush control endpoints from ep_dequeue and set request completion
to NULL once calling completion handler of function driver. This will
make sure that all control endpoint requests are flushed in disconnect.

CRs-Fixed: 373672
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
(cherry picked from commit 0c1b8b2174f85c4437a197c2e58350bd6f6c3d02)

Change-Id: I3fef1c2b464db6a8ef283c0a02a87b5b48ab26ad
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
arm: Make the WFE macro unconditional

Remove the condition argument from the WFE macro in the
spinlock code so it can support a WFE fixup needed on
certain Krait CPUs.

Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
(cherry picked from commit 470d134db676e23982676061971a3a201f32b4a6)

Change-Id: I66a4ab60f2f26081630f79c95402f3494d00f664
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
arm: Convert spinlocks to new inline assembly style

Refactor the inline assembly code in spinlock.h in
preparation for supporting the Krait safe WFE sequence.

Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
(cherry picked from commit 68e1d7476e66911f9722a5dd82554e883cdb35ba)

Change-Id: If0b93f9f7dedbd81fd5473dfb1dd937cf5191f15
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
arm: Support the safe WFE sequence for Krait CPUs

Certain version of the Krait processor require a specific
code sequence to be executed prior to executing a WFE
instruction to permit that instruction to place the
processor into a low-power state.

Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
(cherry picked from commit 196f86e88fac14963de15bcd4413d306d777c1fe)

Conflicts:

	arch/arm/mach-msm/Kconfig

Change-Id: I48557c8c1efdde1aa0686dba2c6fd24e33f4e149
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
mmc: msm_sdcc: Add sysfs attribute to update idle timeout value

Add a sysfs attribute to configure the runtime PM idle timer value

In some cases (eg. audio playback) the power consumption drops if
runtime idle PM timeout is set to 10sec. So this sysfs attribute
should be used to configure the idle timeout for SDCC per target.

The value must be greater than 5secs or else will have a major
performance hit.

CRs-fixed: 381494
Signed-off-by: Pratibhasagar V <pratibha@codeaurora.org>
(cherry picked from commit 13d1d039ddc39ccbfa9f5eef52d6c47bb743acad)

Conflicts:

	drivers/mmc/host/msm_sdcc.c
	drivers/mmc/host/msm_sdcc.h

Change-Id: I80080f5016d399cb412823bf5645d60abcd37241
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
mmc: msm_sdcc: Enable AUTO_PROG_DONE for CMD25

With commit (d5d59dc) setting AUTO_PROG_DONE bit for Multi
block write command (CMD25) is broken. Fix this by setting
wait_for_auto_prog_done flag for CMD25 preceded with CMD23.

Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
(cherry picked from commit b8e8369371e351dcc7708ac63cac26dede3a543f)

CRs-Fixed: 383088
Change-Id: Ie71b2c8f40d74dd2042bd00e1e5f47a71a8637e6
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Bluetooth: Prevents update of Low Energy connection parameters

The start encryption command fails when the LE update
connection parameters request is pending.
Hence, prevent the update of LE connection parameters during the
bonding process. The update of connection parameters is
not necessary during bonding process.

CRs-fixed: 380257
Signed-off-by: Subramanian Srinivasan <subrsrin@codeaurora.org>
(cherry picked from commit 923e3e66d32f7071fcf8eea87b073aa1966e4e9b)

Change-Id: I9e9607423aae2a0bb2e7469d7cdbebefc3fc664b
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
Revert "Revert "msm: gpio-v2: Fix spurious interrupts when gpio-irq is unmasked""

This reverts commit 7dde3a1d9af53f8f25597c2b1ca743c56b80a3ec.

Change-Id: I671ae95eb9c39881fbe415840d9b248b3adb33bb
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
msm: gpio-v2: Re-arrange the write to RAW_STATUS_EN

Move enabling the RAW_STATUS_EN at the very beginning.
Hardware team clarified that it is better to write to
RAW_STATUS_EN before writing to any other INTR_CFG bits
in order to prevent spurious interrupts.
Removing writing to the GPIO_INTR_CFG_SU register
during every mask/unmask as it could cause spurious
interrupts as well.

Change-Id: Ifbd991364216ef5f163e5211bc35f7f145c75916
CRs-Fixed: 346861
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
msm: gpio-v2: Clear the interrupt status before unmasking

After the change to keep the RAW_STATUS_EN always on, the
interrupt status bit was latched and could be set during
other (non-interrupt) activity on the GPIO line. This would
end up triggering the interrupt as soon as it was unmasked.
Hence, clear the interrupt status before unmasking the gpio
interrupt.
This keeps the behavior and expectations same as when the
RAW_STATUS_EN was toggled and it prevented the interrupt
status from being updated while the interrupt was masked.

Change-Id: I2bbfa36e4ec0f4a961f05047f4061d7d8fc9fd2f
CRs-Fixed: 346861
Signed-off-by: Rohit Vaswani <rvaswani@codeaurora.org>
msm: bam_dmux: enable disconnect ack feature support by default

The disconnect ack feature is normally turned on by a handshaking
mechanism between bam_dmux and A2, but on some 9615 variants that
mechanism will not exist.  A2 will still expect the disconnect ack to
be active and might crash if it encounters that it is not active.
Enable the disconnect ack feature by default to prevent this.

CRs-Fixed: 372958 382037
Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
(cherry picked from commit b1e7c58c8f7e1495360784929245d30fcd32127e)

Change-Id: I208b55317b8ffe9dc988597b99b855fc9528d341
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: bam_dmux: update SSR handling to reflect disconnect ack on by default

When subsystem restart of the modem is triggered, the SSR handling function
disables the disconnect ack feature.  Later, when the modem reboots, it
expects the disconnect ack feature to be enabled by default as it was when
the modem first booted.  This causes a problem when the modem times out
waiting for the disconnect ack and asserts.

Fix the issue by changing the SSR code in bam_dmux to reenable the
disconnect ack feature instead of disabling it.

CRs-Fixed: 377493 382037
Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
(cherry picked from commit f62029d1c902342470816ad4920b08ea805a52d6)

Change-Id: I4073885a0148e938966ab5c246bb689063e5840b
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
msm: bam_dmux: add missing parameter to bam_dmux_log() call

bam_dmux_log() takes a formatted string and a variable argument list
similar to printf() and creates printf() style output to a private kfifo
log.  This change fixes a particular invocation of bam_dmux_log() which has
an invalid variable argument list for the formatted string used.  Depending
on system timing, this invocation could succeed as expected, or it could
cause a null pointer exception.

To prevent further issues, add the __printf() function attribute so that
the gcc compiler will check at compile time the arguments to bam_dmux_log()
for proper number and types according to printf() usage.

CRs-Fixed: 382037
Signed-off-by: Jeffrey Hugo <jhugo@codeaurora.org>
(cherry picked from commit d7d2b0698912348c464e126fe85fa4aca9da0bd5)

Change-Id: Id3c678317412a348f7a1067f5a4fc975af2675a5
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
USB: ci13xxx_udc: Convert ATDTW loop into finite one

Currently while queueing requests to HW, waiting in infinite
loop till ATDTW bit set for HW semaphore to be released by HW
to avoid race conditions between HW and SW. This could lead to
watchdog timer expiry if bus infrastructure is stuck. Hence
convert this loop into finite loop of 100msec which is atmost
required for USB HW to release HW semaphore as per HW team.

CRs-Fixed: 368769
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
(cherry picked from commit 397a453ef048dde980b321c637d86662adbe077c)

Conflicts:

	drivers/usb/gadget/ci13xxx_udc.c

Change-Id: I7c4a7e16ebbb8d5d0c196674708c72a306098279
Signed-off-by: Srivalli Oguri <oguri@codeaurora.org>
wcnss: cancel any pending APPS votes from coldboot before SSR

APPS vote from coldboot may be still pending when SSR is invoked;
so make sure that the APPS votes from coldboot are cancelled before
SSR votes for these Riva regulators.

CRs-fixed: 380434
Signed-off-by: Sameer Thalappil <sameert@codeaurora.org>
(cherry picked from commit 13f45182fcd1756df8526e1be19c1cf4717dec09)

Change-Id: I4b06d8445c9036078c1962280047990621dcdbbb
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
wcnss: fix incomplete ramdump for wcnss

SSR3 ramdump API only specifies 3MB wcnss RAM segments. Increase
this to 5MB to specify the complete wcnss RAM segments.

CRs-fixed: 377178
Signed-off-by: Sameer Thalappil <sameert@codeaurora.org>
(cherry picked from commit 84bc89aa4e4ff5508b0b774c74d39f2b4b658bb8)

Change-Id: I9c2139400c6dcec7cfc240ec7822bf30aac4789c
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>