power: qpnp-bms: prevent shorting input leads for external rsense

The BMS has a feature where when the batfet is open it shorts the
IADC's input leads so that a zero current is read by BMS state
machine.
This feature is very useful when internal Rsense is used, but
may adversely affects current readings if external Rsense is used
and there are components that draw current through it.

Fix this by turning the "shorting input leads" feature off when
external Rsense is in use.

CRs-Fixed: 509620
Change-Id: I643e4df92291a787ba91f6204fc728c26dc80734
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: qpnp-bms: implement workarounds for coupling issue

On certain PMICs there is a coupling issue which causes bad calibration
values that reports a high current value even when the BATFET is open.
This coupling issue happens regardless of an internal/external rsense
configuration.

The suggested workaround is to repeatedly calibrate until we get values
that result in less than 3mA of current.

Expose the BATFET open/closed as battery's ONLINE property. It is
reasonable use of this property since PRESENT suggests a battery is
actually present in the device and ONLINE suggests if it is connected to
the system via BATFET.

The BATFET can open when a charger is present and
* the battery is fully charged
* the battery is hot/cold
(Note that if charger is disabled the buck will not operate
and we don't have coupling issue)
The fully charged notifications trickle down to BMS driver,
since battery psy supplies to "bms", use it to check if the
BATFET has opened.
The hot/cold interrupt is not yet registered to, add it so we can notify
the BMS driver if the battery goes hot or cold. Since the battery can
go hot or cold while the device is sleeping, we need to wakeup for
calibration workaround.

The BATFET can close when
* the charger is removed
* the battery recovers form hot/cold conditions when charger is present
These notifications too trickle down to the BMS driver and can be used to
check if the BATFET has closed.

Also once good calibration values are detected above use them until BATFET
closes i.e. do NOT calibrate until the BATFET closes. Update the code
that periodically calculates SOC to skip calibrations as long as BATFET
is open. On the same lines ask the iadc driver to skip auto calibrations
until BATFET closes.

CRs-Fixed: 509620
Change-Id: I89b521368304d7171d75e462cf15f2f1daa55cdc
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
power: qpnp-bms: use device tree battery profiles

Add in support to autodetect and read battery profiles from the
device tree using of_batterydata.

Change-Id: Iff5cd4ce787412b54eee56d7e4b83676a19ed91c
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: qpnp-bms: Always setup vbat monitoring

Previously, the BMS driver skips adc-tm vbat monitor setup if it
detects that there is no battery. This is incorrect since a battery
could be inserted later. Not setting up the monitor parameters can
lead to issues later when the battery is actually inserted.

Fix this by always setting up the adc-tm vbat monitor parameters
and simply disabling the channel if there is no battery inserted.

Change-Id: I6980d2b67641fe48644970179fa5a04ddbdc479e
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
power: qpnp-bms: remove return in macro

According to the kernel coding styles, returns in macros should be
avoided. Remove the returns in the BMS driver SPMI_PROP_READ macros.

Change-Id: I38c7706801caa4c893bb3f308cf076bf1e84f2b6
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>