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>
power: pm8921-bms: add delta param to bms

The master band gap (MBG) drifts when usb is inserted - a known
problem with the hardware. This drifts in the MBG cause errors
in adc readings - in particular the open circuit voltage of the
battery.

Use the driver to measure how much the 0.625V channel drifts when
a usb is inserted and compensate adc readings using that delta.

Also changed the unsigned nature of the calculations done for
adjusting the battery voltage, it was found doing incorrect
adjustments at very low battery voltages.

Change-Id: I15ea0e8ec0cf7ddd679fda1a7fc864f1ba1b46c2
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit acca418a196d1d4b17f27bb49c8db9ebbc460cf6)
(cherry picked from commit a7a6fdfd0510f15c9ba9b4a917c41aa23124dbaa)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: reset chg failed bit regularly

The charger was observed to freeze for unknown reasons. Clear the failed
bit upon insertion/removal of usb. Also clear that bit in eoc check worker
and the heartbeat worker.

Change-Id: I6419b7ecbfc4d9b73537285357be1e810efa0411
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit e451f3463b1f57384275bcb9a6867d49759fa81c)
(cherry picked from commit 7f90748c171a251061b72c6dd2177e9d7610439c)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: do not report usb present while in otg

When a usb slave device is being powered by the pmic, the charger
sees a valid voltage on the usb_in line incorrectly reporting that
a valid charger source is present.

It is expected that when a slave device is present the charger is
asked to not draw any current from usb. Use this setting as a flag
to indicate if a valid charger source is present.

Also clean up the implementation by splitting the get property function
in to two - one for usb charger and other for the dc charger.

CRs-Fixed: 339000
Change-Id: I5665f7b2364c61a6f618f4725facf32b209e0249
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 9da392dc3c8c1632e26981b572a7fb4553cdb2d6)
(cherry picked from commit 4d01a5b6e6e827636e7fb5aca00dc208189f02db)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: implement ir compensation

The charger hardware has a +/-30mv error for vdd_max settings. This
means that when vdd_max is set to 4200mV the actual voltage on vph_pwr
line could range from 4170mV to 4230mV. This further means that when
constant current to constant voltage transition happens, the battery
may not be charged up to 4200mV - leading to an premature end of charge.

Fix this by implementing periodic IR compensation. On a device measure the
resistance from the vbat terminal to the ground by shorting the +ve and
-ve of the battery terminals (without a battery), this will be referred to
as rconn in the description. In the code it is rconn_mohm to reflect the
units.

The voltage at battery terminal will be
Vbat(terminal) = Vbat(xoadc) + Ibat * rconn
where Ibat is the current flowing out of (or into if -ve) of the battery.

Vbat(xoadc) and Ibat can be obtained by using the override mode of the
bms. So Vbat(terminal) can be deduced and compensated by increasing
vdd_max. This also helps in increasing constant current mode thereby
decreasing constant voltage mode and decreasing the overall charging time.

The value of rconn will be specific to a PCB layout, it is
passed in from platform_data.

Change-Id: If8df93333ca6b0bad35505895a4fc5577562fadd
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 40491ce8d0543bb0d81d855b7742f078a404d85f)
(cherry picked from commit ad94d0a91b3de263243990752d09b59f8a012194)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: calibrate hkadc upon insertion/removal

The hkadc should 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.

Call the bms api to calibrate hkadc.

Change-Id: I89564dcc3ef32af2c3abe422b901c499e91fd2d5
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit c9ba27184eb2f8117397242366011cdfe8b08fd0)
(cherry picked from commit 5bbb916aadf3ea10173102ff3fa20d306e1792fe)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: remove obsolete wakelock

Remove an obsolete wakelock which used to be part of
the reverse boost fix. The wakelock is not required
because the reverse boost fix relies on the loop
change interrupt when the device is suspended.

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

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-bms: calculate rbatt only at resume

The battery resistance (rbatt) measurement can only happen when the
current consumption of the device goes very low. This implies that
rbatt should be checked for only while resuming.

Update the driver to check and measure for rbatt only during resume.
As a result separate the functions that read state of charge (soc)
parameters from rbatt parameters. Also note the battery temperature
right before suspend. This will be used for adjusting the rbatt based
on temperature.

Change-Id: I254833f437605d6d64dcd6159edb8440d08383db
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 1a7561a47a8058297e4434eaf3993e0ce5a2cc2a)
(cherry picked from commit 8b1939ddc95accdff7166364b4f00c99b171721a)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: add adaptive current limiting

Adaptive current limiting is a method which tries to
maximize the available usb current by slowly stepping
up the allowed maximum usb current and verifying that
the connected wall-charger is collapsing.

If the USB driver determines that 1500 mA are available
the starting current on usb is 500 mA slowly stepping up
unless

* VIN_MIN is reached (charger is reaching its capacity)
* USBIN goes low for less than 50 ms (charger collapsed)

If one of the two conditions apply then reduce the target
maximum current to the current maximum usb current and
stop trying to stepping up. If the conditions occur again
decrease both the target and current usb maximum setting.

CRs-Fixed: 339022
Change-Id: Icdb46e6346b6b871d81bbacbffe70831dd62d93c
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit acf57c86caa0fbc79e29cf64508b05dee75fecb2)
(cherry picked from commit 17eb847eb0ab0c418c6093def20afa3fbabb7fb5)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
power: pm8921-charger: remove set_usb_power_supply_type

This custom API is no longer required since AC charging
reporting to userspace is solely dependent on the maximum
current supplied by the USB rather than the connector
type.

CRs-Fixed: 339841
Change-Id: Id542b083dd4f0ba5679d64f9e20d3b04cf14d972
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit 70f6cdc262dc3e2bb3fb8ac1c56a216f0600d441)
(cherry picked from commit 44b37d92b98c3eaf2fbcf08c1d1b2418cae0a3e8)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
usb: otg: Add support for power supply API for USB charging

With this commit, USB Driver will start using Power Supply
API rather than calling direct pmxxx driver API for USB charging.
This will allow hiding specific charger model (such as
external LTC4088 charger used for MDM9x15) from USB driver.

In case the power supply API is not support, fallback to legacy
API which uses pm8921 driver.

Change-Id: Ic0f302e3aa8aa60f6483a0fdeec9389a0ded1fac
Signed-off-by: Amit Blay <ablay@codeaurora.org>
(cherry picked from commit 0f7edf7796c170f8dc4d87e71dcd77c24c93c39a)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
USB: OTG: remove pm8921_set_usb_power_supply_type

This custom notifier is no longer required to determine
wether a wall charger is connected to the PM8921 charger
or not.

The pm8921-charger driver determines AC charging solely
dependent upon maximum input current from the charging
device.

CRs-Fixed: 339841
Change-Id: I564fa01c61286d013be6b263d038e87568a297f2
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit 34b874562012c3453da20059094992140ca1ea61)

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
msm: rmnet_bam: Handle Network TX Queue Race Condition

The netif TX queue is started and stopped based upon the watermark state
maintained by BAM DMUX.  The queue is checked after TX-enqueue
operations to disable the queue if the high watermark is hit and after
TX-dequeue operations to enable the queue if the low watermark is hit.

Without locking, this opens a race condition where the TX-dequeue check
and the call to stop the queue can happen after the write-done
completion has occurred which would restart the queue.  This results in
the queue being stopped indefinitely which results in a permanent data
stall.

(cherry picked from commit ed3ca0ab07bf58816be2e24e9710511ee0c63c78)

Change-Id: Ib2780ba372c935852a347b77888568a2a3070d86
CRs-Fixed: 347174
Signed-off-by: Eric Holmberg <eholmber@codeaurora.org>
(cherry picked from commit ee21be22a59b5bb782a1cce170233e74ff86bd46)

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