Merge changes I8a8e36a0,I5b01b0dc into ics_chocolate

* changes:
  radio-tavarua: Queue only the FM Shutdown work during FM Off
  radio: radio-tavarua: Re-org code for workqueue
Merge "msm_fb: hdmi: CEC Message queue flush" into ics_chocolate
Merge changes I1a5670e1,I0fe0a4e1 into ics_chocolate

* changes:
  msm_fb: display: Enable mixer1 writeback for video downscale use cases
  board-msm8x60: display: Fix writeback memory size
Merge "USB: android: Fix missing USB DISCONNECT uevent" into ics_chocolate
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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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: Sudhir Sharma <sudsha@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)

Conflicts:

	drivers/usb/otg/msm_otg.c

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
(cherry picked from commit 50420469d474d7d0c1cee9d0e74edb07e7cb91c6)

Signed-off-by: Sudhir Sharma <sudsha@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)

Conflicts:

	drivers/usb/otg/msm_otg.c

Signed-off-by: Zhoulu Luo <zluo@codeaurora.org>
(cherry picked from commit 1a6f8ee6227558dc142e31d886ea9cb08a972d93)

Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
msm: vidc: Downloads firmware using pil_get.

Downloads video codec firmware using pil_get
for secure sessions only. Firmware is not
downloaded using pil_get for non-secure
sessions.

Signed-off-by: Vinay Kalia <vkalia@codeaurora.org>
Signed-off-by: Ramakrishna Prasad N <crpn@codeaurora.org>
(cherry picked from commit 38d3329309c936d9ecf3b51b07245e85eb53f7b6)

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