msm: camera: Fix msm_camera_i2c_poll function call

Change-Id: Ie99e61811332054b2b7e4b0f3a05a932e988729c
Signed-off-by: Rajakumar Govindaram <rajakuma@codeaurora.org>
CRs-Fixed: 348564
Asoc: msm: Remove the condition check before sending FENS command

If FENS is disabled before starting voice call, FENS disable
command is not sent to CVD.
Remove the condition check, fens disable and enable command will
send to CVD when starting voice call.

Change-Id: I0cfa21db428cd9cc635442c34321f5482d3b3018
CRs-fixed: 349234
Signed-off-by: Helen Zeng <xiaoyunz@codeaurora.org>
diag: Edit mask update algorithm

DIAG sends mask updates to peripherals over SMD control channel.
Such updates are sent when a peripehral boots up or any mask change
request is sent to target. Several automation failures were seen
with this mechanism. This change edits the mechanism in following
way:

1) Sometimes during automation, such updates are sent at a very high
speed and hence SMD layer cannot process them at the same time. This
change adds a delay in case of SMD write failure and re-tries. Such
re-tries cannot be done indefinitley, as it risks QPST timeout.

2) The SMD channel is written to when any mask update is received and
also if a peripheral comes up. Thus, there could be a race condition.
Adding a spinlock to avoid corruption due to race conditions.

3) Changes the way F3 mask updates are stored in apps table. Earlier these
masks were recorded as they are received. Now QXDM sends masks in an
orderly fashion and thus the masks were recorded in a pre-determined
manner. However, automation sends them in a random manner. This throws
off mask table parsing logic on applications processor. This change
creates the mask table at initialization time and updates them on
receiving further updates. Thus, the mask table is always parsed in
a known manner.

4) Some updates were done on a work queue earlier to avoid QPST timeouts.
This has been re-written to prevent potential race conditions. It has
been tested that QPST still does not timeout. Hence, this change safely
cleans up the work functions as well.

5) Added some debug statements to enable faster debugs in future.

Change-Id: I516e4e30a5a12757615887f5dfedad600245c9a1
CRs-Fixed: 349347
Signed-off-by: Shalabh Jain <shalabhj@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: 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_fb: display: Call footswitch control from overlay dtv on/off

Instead of dtv on and off, call footswitch control during
overlay dtv timing generator on and off calls

Change-Id: Iffe47e12ce99e1fc7a080daef7b220c4f010ccda
Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>
msm: display: Add proper flags for secure/non-secure writeback buffers

For MDP writeback buffer allocations, use appropriate heap id flags
for secure and non-secure sessions

Change-Id: I05e897d5d90ab03b17ccddbda764f39b963192ef
Signed-off-by: Ravishangar Kalyanam <rkalya@codeaurora.org>