msm: 8064: Add connector resistance

The adjust vdd max algorithm in the charger driver needs connector
resistance to set the battery voltage appropriately.

Set the connector resistance value from the board file.

Change-Id: If934783e2910c8456090c8926e934138abb75222
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: pm8921-charger: remove old workarounds

PMIC8921 revision 1.0 and 1.1 are no longer supported by software.

Remove the applicable workarounds from the driver.

Change-Id: I8c99fcbbf2f7229728236ae1059f4c9cb8dbb065
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-bms: use consistent temperature units

There is bug in the code where interpolate_pc is passed temperature in
DegC at one call site vs deciDegCelcius at other.

Use degC consistently.

Change-Id: I3e5e92e39adf904e62d4c5ffcb6d370c0655f7cf
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: report higher soc even when called within a second

The current code puts a restriction in the charger scaling algorithm
that state of charge (soc) should be called after a second. If it is
called earlier, simply report the previous soc.

There are user space applications that call soc every few milliseconds.
The soc appears stuck for such applications.

Remove that restriction.

Change-Id: I22d2dbdae5c9c859d4baca2bdb7bea71da09b85b
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-charger: PMIC version check for workarounds

Since the revision registers across different PMIC chips
may match up some workarounds may be applied to chips
that do not require them and cause issues.

Fix this by adding version checks to these workarounds
to make sure that the workarounds are applied to the correct
PMIC version.

Change-Id: I8af031570466a88656c89ee7764f78c5ec14d247
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
mfd: pm8xxx: provide api to read restart reason

The BMS driver needs to know the restart reason of the pmic. Add
an api in the pm8xxx design to provide the restart reason.

Change-Id: I0bbad22c5fed8c32dd7de387194e94c8d4b9ad75
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: use restart reason for usb detection

When the charger is not initialized it returns -EINVAL when asked
whether usb charger is plugged in. Use the restart reason to check
if we started with a charger insertion.

Change-Id: I2e8fcb4a15af3a66331a921d378bfd5d2dfe4533
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-bms: update power supply class if soc changes

There is a hearbeat loop that queries the state of charge
(soc) every few seconds. If the soc changes multiple times in
that period, we miss updating the userspace of those changes.

The userspace will notice a big step in soc, which is undesirable.
Update the userspace when the calculated SOC changes.

Change-Id: I2c149e6edd7c194e7f31ece95e2003ffde935806
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921-charger: workaround for active charger path

The active path bits in PBL_ACCESS1 register don't reflect the actual
status until some delay. This delay varies from few millisecond to
three seconds.

The unplug detection loop relies on these bits reflecting the correct
status for proper operation. Due to this bug the unplug worker wont
run when a charger is plugged in.

Update the code such that if it sees nothing set in the active path,
it still reschedules the unplug detection worker.

Change-Id: Ib99cd49623698d0295bc3c3cf880225495d530cb
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: pm8921 and ltc4088-charger: add pm_power_set_property

Add pm_power_set_property_usb API to support the power
supply framework APIs which allow changing the type of
a given power supply.

This is required to avoid the use of PMIC specific APIs
in the USB driver and encourage the use of the power
supply framework.

Change-Id: Ifba2bd1248e8bb47a0700dec4d321d32db4f2066
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power_supply: add BMS for a new power supply type

Add POWER_SUPPLY_TYPE_BMS for the hardware chip or module which
monitors battery for state of charge and other properties.

BMS will register itself as a separate power supply of type BMS.
The charger will register the battery power supply and pull BMS data
from the BMS power supply if it exists.

Change-Id: I071f0d958a4b2b6af5f51460d201f6970aed595f
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: pm8921-charger: fix TTRKL_MAX_MASK

The PM8921_CHG_TTRKL_MAX_MASK should range from
bits 0 to 5.

Fix this by changing the mask to 0x3F.

Change-Id: I8e3e9068e7b9a3bfd24c07a00bb3953180ce0741
CRs-Fixed: 394246
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: disable AICL when charging is disabled

If charging is disabled the VCHG line will see a drop in input
voltage regulation and the VIN_ACTIVE bit will be set.

To avoid incorrectly changing the USB input current limit disable the
adjustments made by the AICL algorithms if charging is disabled.

CRs-Fixed: 380478
Change-Id: I2bf31a23199f942a9ac843b9940a0f7377256238
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: distinguish between PMIC 3.0.1 and 3.0

Some workarounds that are required for PMIC die version 3.0
differ slightly for die version 3.0.1.

Fix this by checking the PMIC subversion register to distinguish
between 3.0 and 3.0.1.

CRs-Fixed: 403150
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit 913c55e2706c36132fd42f90c05530b8e55a26ed)

Conflicts:

	drivers/power/pm8921-charger.c

Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
(cherry picked from commit be353f74c5e90535a7fcf11f2c3d708b20ca542b)

Conflicts:

	drivers/power/pm8921-charger.c

Change-Id: I7b55405b3186cb55312ef74ca7abf5ec76bc48fd
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
power: pm8921-charger: resume charging based on SOC

At EOC, the battery is disconnected from the charger and starts
discharging. This can result in SOC dropping to around 93% before
charging starts again.

Manually set the CHG_VBAT_DET threshold high to restart charging once SOC
drops below keep_charge_percent.

CRs-Fixed: 404909
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
(cherry picked from commit 14e8fa1e42c02ea643d16d3f833b5d8e1b5753e6)

Conflicts:

	arch/arm/mach-msm/board-8064-pmic.c
	arch/arm/mach-msm/board-8930-pmic.c
	arch/arm/mach-msm/board-8960-pmic.c
	drivers/power/pm8921-charger.c

Change-Id: Ic54ff2c14866c43b13edee03ad3c8084c1e1791d
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
(cherry picked from commit 1437c79c48893ca2883d99871c7fd9f10604ee42)

Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
power: pm8921-charger: make usb_max_current configurable

Allow the module parameter to be configurable through the board
files. This gives another option to set the usb_max_current
setting if userspace is not able to set this during
bootup.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit 8e67275cb440be560830089fabc0201eb5830c9e)

Conflicts:

	drivers/power/pm8921-charger.c

Change-Id: I0a8ea4ed5d97cdbadeba55fe3c489eefc2290f86
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
power: pm8921-charger: add USB soft trim procedure

To improve accuracy of USB input current limits add
a soft trim procedure. This procedure subtracts codes
from the original trim value in the USB_OVP_TRIM
register based on the selected USB input current limit.

Note that the USB_OVP_TRIM is not reset if there is
a watchdog restart. In such cases we don't want to
overwrite a already corrected trim value. The trick
is to update the boot loader to save the original trim
value in register 0x10A and 0x09C and the kernel driver
to use that as the starting point instead of the
USB_OVP_TRIM.

Also note that we choose the value of 0xFF to indicate that
the driver has not yet read the trim value. The trim value
is only 6 bits and so 0xFF serves as an uninitialized value.

CRs-Fixed: 389937
CRs-Fixed: 418033
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit 1e3a82fb0a651fdef1e76ca36dd4ca5f5628b92d)

Change-Id: I3ee33df6119f6385a8cfc21acc13441d2eb928ab
Signed-off-by: Sivasri Kumar Vanka <sivasri@codeaurora.org>
power: pm8921-charger: fix resume SOC check problem

The current code assumes that the battery state of charge (SOC)
increases or decreases by one percent. This is not so. The check
for resume charging could fail and we might enter a condition when
the SOC is lower and we might not resume charging.

Fix it by checking whether we have crossed resume SOC threshold.

While at it there is also an issue where we might not resume
charging if the charger was plugged out before end of charge but
above vbatdet threshold, if the charger is inserted back again
it might not resume because the current algorithm seeks for a
drop in SOC. Update the check to only lookout for a SOC less
than resume percent and if the charging is not in progress.

Change-Id: I8cac84296ddb1e323f28e2476f78d0190f4a1b73
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
msm: board-8930-pmic: Disable pmic noise gate.

The noise gate is resulting in intermittent audio issue,
hence disable it.

(cherry picked from commit 53c87b04d0282af18fa57b1d99d2b6b13149b3e4)

Change-Id: Ia932394af33120d1cbffc12bb79fbc7225bcce1a
CRs-Fixed: 428933
Signed-off-by: Asish Bhattacharya <asishb@codeaurora.org>
power: pm8921-charger: Support multiple vbus requests

ACA chargers can generate multiple vbus current draw requests
based on the number of USB peripherals connected to the dock.
Handle this by allowing runtime modification to the max target
current limit.

CRs-Fixed: 427933
Change-Id: Ie508a85bbbe129d77af48c05235376779d799128
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>