msm: lpass-8960: Avoid write to lpass wakeup register.

LPASS SSR driver has a write to lpass wakeup register as part of
lpass shutdown process. But wakeup register falls under secure
space which is not accessible by HLOS. To avoid this, the write
has been moved to NMI call now. Hence remove this write to lpass
wake register from ssr driver

CRs-Fixed: 340872
Change-Id: I30f2eae105eeea2ebb543eb57b508c30e4b4b3d0
Signed-off-by: Sriranjan Srikantam <cssrika@codeaurora.org>
(cherry picked from commit 51a43afaaa39543a02f8234e973b462276e64043)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
ASoC: wcd9310: Add plug detection through mechanical switch

Use mechanical switch on the phone jack to detect headset/headphone
insertion and removal.  Mechanical switch is beneficial to avoid fake
button press and high impedance microphone headset detection.

CRs-fixed: 341402
Change-Id: I9eab7285617b9116671e9facb39a878a8ddb464e
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
(cherry picked from commit d7cf2e931cea51c7ff0a40e6b930edf99b320d8e)
(cherry picked from commit 803e1dd6602e789eb1e0da240dc734160f330d39)
ASoC: msm8960: properly protect external mclk control function

Both audio path and MBHC accessory detection logic need master clock
enabled along with bandgap and clock block of CODEC. Clock control
is managed by the machine driver. Calls to clock control function from
audio and MBHC detection paths can be nested. As a result, reference
counter of master clock is incremen/decrement out of order and cause
master clock not enabled when audio path is enabled. Without master clock
CODEC will not consume data and this leads to SLIMBUS overflow error.

Change-Id: Ic29b9740a28256251a8fb2aaf773082562a8fe40
Signed-off-by: Joonwoo Park <joonwoop@codeaurora.org>
(cherry picked from commit 28f49c84acb4e691b630b26c37ab6d206109482f)
(cherry picked from commit 62bceb0052e50013ed6d2e580c125a89493b289a)
cpufreq: Separate speed target revalidate time and initial set time

Allow speed drop after min_sample_time elapses from last time
the current speed was last re-validated as appropriate for
current load / input boost.

Allow speed bump after min_sample_time (or above_hispeed_delay)
elapses from the time the current speed was originally set.

Change-Id: Ic25687a7a53d25e6544c30c47d7ab6f27a47bee8
Signed-off-by: Todd Poynor <toddpoynor@google.com>
power: pm8921-bms: accumulate last_charge_increase

The current code always overwrites last_charger_increase when end
of charging happens. Update the code to add the current percent
increase.

Change-Id: I645554b65de627d26ab01399a6e25a9f5a014fe5
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit 56a5059813b8d95757685cfc5ebec188564408b2)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-bms: fix reporting  bms_end_cc_uah = 0

There is a bug in the driver where the code to fake full battery
causes coulumb counter based charge (bms_end_cc_uah) to be
reported 0mAh. The reason is once the battery is fully charged a 100% OCV
(open circuit voltage) is faked and columb counter value is offset
such that the coulumb reads start from zero. This faking is cleaned up
until a real OCV happens.

Fix the code such that bms_end_cc_uah is updated before the columb counter
is made to read 0.

Change-Id: I14ce494182ac899205fa41ad815a030d573ab793
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit 29f82c8b66f0c70977c7bb101aff1dfecd6b33a3)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: bms: add desay calibration data

Add the calibration data and battery ID information for the
Desay 5200 mAh battery which is used in LiQUID platform
devices.

Change-Id: I19ff1251ee3e71fa71d4fa0c83143d4b7667a80c
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit c00baa96ddc6cf9b0f6dbd0adc490451229d40c6)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: 8960/8064: robust battery detection

To ensure proper battery id dectection on LiQUID and MTP
use machine_is_msm8960/8064_mtp/cdp to determine which
calibration data to use for battery. If platform is
unknown fall back on regular battery id detection.

Conflicts:

	arch/arm/mach-msm/board-8064-pmic.c
	arch/arm/mach-msm/board-8930-pmic.c
Change-Id: I2f5629572d1e5fcac0a2feb114947b91a96f3bf0
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit 08e614cd89252e9bb83ffbc9bc5fd5db2c539170)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: bms: split battery data for different battery

Use different files for different battery profiles. This makes updating
the profiles easy as more data is collected.

Change-Id: Iafa369f4629f4e797ea55f6f81df08c54b57ad1d
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit b0353eb58bdab4d7ee67320be500313261f7b626)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
pm8xxx-adc: fix missing interrupts

There exists situations when an adc conversion is requested very
early in the resume sequence. These requests fail to complete
because of missing interrupts and eventually cause lockups.

When an interrupt is enabled during system resume the kernel rejects
enabling these interrupts. This keeps the interrupt disabled and causes
missed interrupt. Get around this problem by not needing to enable the
interrupt. IOW, do not call disable_irq and enable_irq, only request
the irq which leaves it in enabled state.

There is a bug in the pmic where if an interrupt is masked/unmasked
it clears the pending status. This causes a nonwakeup interrupt to
be missed as it is unmasked while resuming. Mostly this is okay but
if a adc request is made early in the suspend, it causes it to miss
interrupts. Make the adc interrupt a wakeup interrupt.

The driver initializes its completion only at probe time. This may cause
incorrect end of conversions with out of sync (spurious) interrupts.
Update the code to init a completion just before issuing a conversion.

Another issue was observed where the interrupt's unmask_irq was delayed,
causing another cpu to initiate the next conversion as soon as complete was
called. This lead to a situation where the interrupt for the next request
was triggered and the unmask happened later. Call complete within a
workqueue which guarantees that unmask would have completed and
it is safe to start the next conversion.

CRs-Fixed: 350768
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit f5285a2ed7918b941ac260e078c64c534a1d0e8d)

Change-Id: I09398655caed85a8a1b3af1cd5128b8dd2470c8c
Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
dm-crypt: fix possible mempool deadlock

This patch fixes a possible deadlock in mempool in dm-crypt.

Currently, dm-crypt reserves a mempool of MIN_BIO_PAGES reserved
pages. It allocates first MIN_BIO_PAGES with non-failing allocation
(the allocation cannot fail and waits until the mempool is refilled).
Further pages are allocated with different gfp flags that allow
failing.

Because allocations may be done in parallel, this code can deadlock.
Example:
There are two processes, each tries to allocate MIN_BIO_PAGES and
the processes run simultaneously.
It may end up in a situation where each process allocates
(MIN_BIO_PAGES / 2) pages. The mempool is exhausted. Each process
waits for more pages to be freed to the mempool, which never happens.

To avoid this deadlock scenario, this patch changes the code so that
only the first page is allocated with non-failing gfp mask. Allocation
of further pages may fail.

(cherry picked from commit 71b41c32bc4dc0be468435fc62e9285ee862e805)

Change-Id: I56b934a16f3056b494bdea732676debde47219c1
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Shashank Mittal <mittals@codeaurora.org>
(cherry picked from commit dca62667dfdee13709698769bb5af4a58ce5fc83)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
dm-crypt: add missing error handling

There were cases where error code would be used only if we finish
processing the last sector. If there were other encryption operations
in flight, error would be ignored and bio would be returned with
success as if no error happened.

This bug is present in kcryptd_crypt_write_convert,
kcryptd_crypt_read_convert and kcryptd_async_done.

This patch fixes it, setting io->error to -EIO always when an
error happens.

(cherry picked from commit 8bfc015229efd9f2e2eb18f03176d1a9d058e3a4)

Change-Id: I384100803d46630343e4777f807e062cf686dfd7
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Shashank Mittal <mittals@codeaurora.org>
(cherry picked from commit 7f7f17e8c5d0cd1aa7cc8f2b33e1d9afda1c9c45)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
dm-crypt: Rename pending

There are two structures that have "pending" field.
This patch renames it to "cc_pending" and "io_pending" to reduce confusion
and ease searching the code.

(cherry picked from commit 815bc97ac977a0cbccbd141f373a730374cd7882)

Change-Id: I831085b44d8910a14379e8140349bbd5747db4eb
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Shashank Mittal <mittals@codeaurora.org>
(cherry picked from commit 6a82453e13fc7f65cd706649cf37e1cb06dd1874)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
dm-crypt: move static cipher data out of per-cpu structure

Cipher information is static, so it does not have to be in a per-cpu
structure.

This is a preparation for further patches that remove per-cpu structure
altogether.

(cherry picked from commit fbd06f976a4f69bde837f7307c6ac62d0e8f8704)

Change-Id: Id717d197a894e5c05eb9d2b4c9f56982899ccdc2
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Shashank Mittal <mittals@codeaurora.org>
(cherry picked from commit d3c9a8845f3086b9adf4579180654f5a1b147ddb)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
dm-crypt: remove per-cpu structure

Remove per-cpu structure and make it per-convert_context instead.
This allows moving requests between different cpus.

CRs-Fixed: 339113

(cherry picked from commit 30c273a77c02ed9db52bd51027c812ebf513771e)

Change-Id: Icbd465144e17b51710901b1cca88577e7bcfc9c7
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Shashank Mittal <mittals@codeaurora.org>
(cherry picked from commit b463d1e1f24833d3b667f2f36f86e43adbaae88c)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: camera: Fix msm_camera_i2c_poll function call

Change-Id: Ie99e61811332054b2b7e4b0f3a05a932e988729c
Signed-off-by: Rajakumar Govindaram <rajakuma@codeaurora.org>
CRs-Fixed: 348564
(cherry picked from commit e14cb2fd294c6dc2a3a825255bfafe2ce4fe4386)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: fix 10mv error on vdd_max

It was observed that the charging voltage is off by 10mV. The root
cause was the 10mV bit in the vdd_max register adds 10mV to the voltage
instead of reducing the voltage by 10mV.

The current driver thinks it subtracts 10mV. Fix this.

Change-Id: I37949113cb4c25642c873ce0cf39ac9fdeb276e1
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 08e7e0a792f32189bd0dadddc880065da9bdab44)
(cherry picked from commit ad83bbf9c99ae01e37ce37be76f8442629be65e7)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-bms: add protection against divide by zero

There is a unprotected divide by zero in the driver- when full charge
capacity of the battery and unusable charge of the battery are calculated
equal.

In such a case set state of charge to 0% without the actual division.

Change-Id: I57f3333e780396de29435d29c30e54940c657d4e
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit bbae8831f407d2d701e5ac74be3104fb86f8ccfe)
(cherry picked from commit f40455e7a3936072ef69aa14ceb84f380238bc9a)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-bms: calibrate xoadc more often

Improve the values of the battery voltage read from xoadc by periodically
calibrating the xoadc.

The xoadc needs to be calibrated every time a charger is plugged in
or plugged out. This is because the reference voltage shifts a bit
when a charger is plugged in.

Provide an api to calibrate xoadc. This api will be used by the charger
driver.

CRs-Fixed: 334825
Change-Id: I09735f6e5c5d4ab8be379fe001fff81c25c95397
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 1b8e8293b691f873f4c47b3184c153510ef894b5)
(cherry picked from commit e8221f4a6228e0fa8b7d3ba9a1bf2a45b7e20ebb)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-bms: add api to simultaneously read vbatt and ibatt

The compensation algorithms need simultaneous readings of the battery
voltage (vbatt) and the current flowing through it (ibatt).

One needs to put the BMS in override mode to get simultaneous vbatt
and ibatt readings.

Note that since one would need to sleep for 20 milliseconds after the
BMS is put in override mode the spin_lock is changed to mutex in the bms
driver.

Change-Id: I1bfdc1f4e84d5d3c2cd6502dd66afdfba650cc0d
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit c9857ca398776beaba55ebe9be64f4019760d645)
(cherry picked from commit 73771bc0b5c5c7ccfedf28f56bcfefb41dfdd171)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>