power: pm8921-charger: reject vbus calls after checking vbat

Only reject VBUS requests after also checking the VBAT line
to ensure there is actually not other power source present.

Change-Id: Ie846e1d0450e62cddb69bd64a654214215fe2b2b
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-bms: fix fake battery emulation

With the recent split of functions to calculate and report state of
charge, the faking battery feature broke, it remained in the calculate
function.

Move the fake battery feature in the reporting function, where it really
belongs.

Change-Id: Ibc2ecdbca32911b4f35c7e6c2278631a614227fa
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
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>
msm: bms: fix data for palladium battery

The battery data is incorrect and is causing SOC jumps. The SOC is often
inaccurate and would jump from e.g. 40 to 35 in a few seconds due to a bad
battery profile.

Fix the values to use an accurate battery profile that reflects the
battery resistance and voltage versus percent values which help alleviate
the jumps.

Change-Id: I66a9d6eec497829512b001431dde757fed115651
Signed-off-by: Xiaozhe Shi <xiaozhes@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: report DC online for some platforms

Some hardware platforms can supply VPH_PWR without battery
or charger being present.

To avoid shutting down due to no connected power sources
from the perspective of software set a flag that forces
the DC supply to be online for this type of platform.

Change-Id: I325ea00d2103da229bfb7a854ebb7f7fd556c16b
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
msm: 8960/8064/8930: add has_dc_supply property

All CDP platforms are powered by an external DC
supply. Hence set the has_dc_supply flag to
allow the charger driver to handle it accordingly.

Change-Id: Iacdbccbe164823d91ea72cce9d33a0ab5491a45f
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
power: pm8921-charger: adjust vdd max earlier

The charger hardware decides Constant Current VS Constant Voltage based
on the VPH_PWR voltage and not on battery voltage (vbatt) as it should.

The problem is, becuase of IR drop between VPH_PWR and VBATT,  VPH_PWR
reaches the voltage programmed in vdd_max earlier while the VBATT stays
lower causing the charger hardware switch to constant voltage mode
prematurely.

To fix this issue adjust the vdd_max early.

Change-Id: I07638e127e17da9feeb96f316329b8334e7ea031
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>