Commit graph

2153 commits

Author SHA1 Message Date
Subbaraman Narayanamurthy
d3aa081876 power: qcom-step-chg: Fix the error return path
Fix the error return path in qcom_step_chg_init() to free up the
allocated memory and registered wake source.

Change-Id: I8f93246d27f79a7c759b3afc4a4544d9ffca7a80
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2017-08-22 15:04:53 -07:00
Linux Build Service Account
da4c2cf3b3 Merge "qcom: smb138x: supsend USBIN and disable OTG before shutdown" 2017-08-21 12:16:28 -07:00
Linux Build Service Account
95b505dfc6 Merge "power: pmic-voter: make debug status more parsable" 2017-08-21 00:19:53 -07:00
Linux Build Service Account
f01c603a50 Merge "power: smb2: Update the charger buck frequencies for PM660" 2017-08-21 00:19:43 -07:00
Linux Build Service Account
fe66215fd0 Merge "power: qpnp-smb2: expose CHARGE_COUNTER prop via batt psy" 2017-08-21 00:19:42 -07:00
Linux Build Service Account
c1650f847c Merge "power: smb-lib: Add USB notification" 2017-08-20 16:13:01 -07:00
Linux Build Service Account
a5a9ec7754 Merge "power_supply: add properties for SDP current and PD voltage" into msm-4.4 2017-08-20 01:17:38 -07:00
Linux Build Service Account
226d13c582 Merge "power: pmic-voter: use force_val in rerun election" into msm-4.4 2017-08-20 01:17:10 -07:00
Linux Build Service Account
c72d0c4cec Merge "qpnp-smb2: use real_type to convey WIPOWER type" into msm-4.4 2017-08-20 01:16:50 -07:00
Nicholas Troast
0092e08d5c power: pmic-voter: make debug status more parsable
The status debug property lists all of the voters, their enable and
value status, and the effective result. Currently the status is
presented on multiple lines which is difficult to parse. Change the
format to be more parsable.

Print each voter in the following format:
VOTABLE: CLIENT: en=1 v=1000

Print a single summary line at the end in the following format:
VOTABLE: effective=EFFECTIVE_CLIENT type=VOTABLE_TYPE v=1000

Change-Id: I0671cdd8e0911450bafe4869cb49cc48bd622a81
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
2017-08-17 16:54:19 -07:00
Abhijeet Dharmapurikar
69e20be0eb qpnp-smb2: use real_type to convey WIPOWER type
Currently we use WIPOWER as the type for dc power supply.
Instead use WIRELESS in the type and use WIPOWER in the
real_type property.

Change-Id: I9081e752e5b3ff725a6ba935d6f6df4e36fec3fa
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-16 18:35:26 -07:00
Ankit Sharma
8cd61d5d11 power: smb-lib: Add USB notification
In designs without the pd-phy interface the usb
insertion/removal and CC_orientation needs to be 
notified to the usb stack by the charger driver. 
Add this notification support via the extcon interface.

CRs-Fixed: 2086422
Change-Id: I22eae3f818859c8fbd08066f690517d4210c7dd3
Signed-off-by: Ankit Sharma <ansharma@codeaurora.org>
2017-08-16 09:41:41 +05:30
Linux Build Service Account
623fc3cf14 Merge "power: qcom: smb-lib: optimize parallel current limiting with PD" 2017-08-10 21:36:38 -07:00
Linux Build Service Account
75f68f1cdb Merge "power: qpnp-fg-gen3: adjust recharge voltage during soft JEITA charge done" 2017-08-10 21:36:32 -07:00
Nicholas Troast
73cfa3e3ef power: qpnp-smb2: expose CHARGE_COUNTER prop via batt psy
CHARGE_COUNTER is a required battery power supply property. Add it.

Change-Id: Ieb9c64447f88213479ce14b738f71fa703ffc194
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
2017-08-10 15:44:56 -07:00
Nicholas Troast
2cc64cac04 power: qpnp-smb2: use correct properties
CURRENT_MAX and VOLTAGE_MAX should be used to show the current values
for the charger. The driver currently uses them to communicate with
the USB and PD drivers.

Update the code such that USB uses SDP_CURRENT_MAX to set 500mA/900mA
current limits after enumeration and PD uses PD_VOLTAGE_MIN/MAX to set
the adapter voltage limits.

CURRENT_MAX now shows the max current that can be drawn from the charger
and VOLTAGE_MAX shows the max voltage that the charger can negotiate up
to.

CURRENT_MAX and VOLTAGE_MAX can no longer be set.

Change-Id: I660e39effc1862051cff8b9babc885d8de3f9c84
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
2017-08-10 15:44:47 -07:00
Nicholas Troast
dcdf2ac6c1 power_supply: add properties for SDP current and PD voltage
SDP_CURRENT_MAX is used to communicate the maximum current negotiated by
the USB phy. PD_VOLTAGE_MAX is used to communicate the maximum voltage
negotiated by the PD phy. PD_VOLTAGE_MIN is used to communicate the
minimum voltage negotiated by the PD phy.

Change-Id: I8332f7072c99c2c4e009607d92ccfb47534cc23b
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
2017-08-10 15:42:12 -07:00
Linux Build Service Account
bb7cc76a8f Merge "qpnp-smb2: enable/disable sw jeita using a property" 2017-08-09 03:18:21 -07:00
Linux Build Service Account
772f98746e Merge "power: power_supply: add property for sw based JEITA" 2017-08-09 03:18:21 -07:00
Abhijeet Dharmapurikar
713a3c923a qpnp-smb2: enable/disable sw jeita using a property
Provide support to enable/disable sw jeita using a power supply
property.

Change-Id: Id1c2a4bcd8caece5ed7591dc5ab5bf3ac2207cba
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-09 09:55:38 +05:30
Ashay Jaiswal
04e88147af power: power_supply: add property for sw based JEITA
Add power_supply property to enable/disable software based
JEITA charging.

Change-Id: I9fca73c1de524e78c3df83b02a9f5a64488eaae0
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-09 09:47:17 +05:30
Anirudh Ghayal
5a343c279b power: qpnp-fg-gen3: Get the raw MSOC directly from FG register
Use the MSOC raw value directly from the register instead of
extrapolating it from MSOC value to avoid any rounding-off
errors.

CRs-Fixed: 2080211
Change-Id: I91d98c6aa8a63344ff79b5414c45d0f5a5b52b81
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
2017-08-09 09:21:12 +05:30
Linux Build Service Account
603df3f744 Merge "power: qpnp-fg-gen3: add support for skew in capacity learning algorithm" 2017-08-08 16:24:56 -07:00
Subbaraman Narayanamurthy
65cbdb062d power: qpnp-fg-gen3: adjust recharge voltage during soft JEITA charge done
When there is an early charge termination because of soft JEITA
(warm and cool) conditions, float voltage would have been reduced
by the charger based on the compensation configuration (e.g. by
105 mV). This can be close to the recharge voltage threshold
(e.g. 4.25 V) when the recharge is configured to be based off
Vbatt. Adjust the recharge voltage threshold dynamically by
lowering it by 200 mV during soft JEITA and charge termination.
Reset it back to the original value when the condition clears
i.e. either it is out of soft JEITA or the charger is removed.

Change-Id: If4d293c10e84e414c81204784f2e7062140264b1
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
2017-08-07 16:27:13 -07:00
Linux Build Service Account
d843c02a78 Merge "power: qpnp-fg-gen3: improve cycle counter algorithm" 2017-08-06 20:32:57 -07:00
Linux Build Service Account
ca652b3d74 Merge "power: qcom-step-chg: Add temperature based step-charging" 2017-08-05 05:27:02 -07:00
Abhijeet Dharmapurikar
fbd4949949 qpnp-qnovo: skip taking ESR measurement when disabled
Currently when ptrain_done interrupt is handled, the driver invariably
issues a ESR measurement. This is not required if qnovo is disabled.

Change-Id: I8c81dadc38da69ba7248905af2d772f7ce918239
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-04 11:17:06 -07:00
Subbaraman Narayanamurthy
c4205fe6be power: qpnp-fg-gen3: add support for skew in capacity learning algorithm
In some cases, a skew needs to be applied on the learnt capacity
to counter the error. Add support for it.

Change-Id: I7f80088e7db4e3414d86983722c92e4fc14323e0
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-04 11:17:05 -07:00
Subbaraman Narayanamurthy
183bc63f12 power: qpnp-fg-gen3: improve cycle counter algorithm
Currently, when the charging status transitions to a state other
than charging, cycle counter algorithm stores the cycle count for
all the buckets for which the counting had started. This is fine
with respect to the algorithm.

However with qnovo enabled charging, this can cause issues when
charging status can go to not charging intermittently causing the
cycle count to be stored multiple times for a bucket. Modify the
logic to check for the charge termination or the presence of
input to go through all the buckets for storing the count. Also,
increment and store the counter only if battery SOC had increased
more than 2 LSBs for that SOC bucket.

While at it, run cycle_counter algorithm as a function instead
of a work. Also, keep the usage of cycle counter feature enable
flag inside the cycle counter APIs.

Change-Id: I62a92964ccbc6b965af09696deddc6fa8366a841
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-04 11:17:04 -07:00
Nicholas Troast
96168e19d4 power: qpnp-fg-gen3: make TTF monotonic by limiting slope
Currently if there is a spike in system load or a thermal event which
causes the battery current to change dramatically then the TTF can jump.

While a battery is charging the TTF should be monotonically decreasing.

Track the TTF starting with the first estimate and set hard bounds of -2
and -0.1 on the slope. The negative slope ensures the TTF is
monotonically decreasing and the hard bounds on the slope smooth out
significant changes in the TTF.

Change-Id: I68a934599ff25bc5a9eb67b372b28a723532a540
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-04 11:17:03 -07:00
Nicholas Troast
811a8bd2ef power: qpnp-fg-gen3: optimize TTF for QNOVO
QNOVO provides a table of expected charge current settings across the
charge cycle. Use this table to calculate the time it will take to
charge in each step. The sum of these steps is the total time it will
take to fully charge a battery.

Change-Id: I0ed48a2a63886531e761e7ce1d175a600060eaf8
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-04 11:17:02 -07:00
Nicholas Troast
e55198f9ef power: qpnp-fg-gen3: prepare for QNOVO TTF
Micro resolution and 64-bit division is unnecessary; use milli
resolution instead. Measuring the IBATT and VBATT periodically during
sleep is necessary for accuracy. Don't clear the IBATT and VBATT buffers
on suspend to account for the higher charge current during suspend.
Prime the IBATT and VBATT buffers with 10 samples to get a more accurate
first estimate. Introduce a ttf mode to separate the differences in the
QNOVO version of TTF.

Change-Id: Ibc591dd5d38d4bbb712d8906755040d59181f008
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-08-04 11:16:53 -07:00
Linux Build Service Account
0e4e7eab42 Merge "power: fg-util: add median filter for circular buffer" 2017-08-03 10:07:58 -07:00
Nicholas Troast
175907d3d2 power: fg-util: add median filter for circular buffer
A median filter is useful for filtering out outliers. Add it.

Change-Id: I21f97a870c262e5fb3d33b8250a2bf074f519b58
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:28:02 -07:00
Abhijeet Dharmapurikar
3c21390e3c power: qpnp-fg-gen3: use the CC_STEP and CC_STEP_SEL properties
Add support for the CC_STEP and CC_STEP_SEL properties in the BMS power
supply. These properties will be used to communicate the future charge
currents for time to full calculations.

Change-Id: I44087b42b31800d1885bdaf1f38815c8756bc9a8
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:28:02 -07:00
Nicholas Troast
eb8700f685 power_supply: add CC_STEP and CC_STEP_SEL properties
There are several algorithms which modify the charge current in steps
across the charge cycle. CC_STEP is used to notify of all the upcoming
charge currents.

The CC_STEP_SEL property is used to select the index of the CC_STEP to
read or modify using the CC_STEP property.

Change-Id: Ieeb533b758035c1c408cdfd68f001374bf0987a5
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:28:01 -07:00
Abhijeet Dharmapurikar
3fcbb078c8 qpnp-smb2: Ignore status 7 register while qnovo is enabled
status7 register will indicate all the charger bits are cleared during
the rest or discharge phase of a Qnovo pulse. Moreover those bits remain
cleared after a pulse train is done and before a new pulse train is
issued.

Hence when Qnovo is active ignore status 7 register bits.

Change-Id: Ice61f8a49625081ffbf1aacaac844b929715e818
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:28:01 -07:00
Harry Yang
2aced65bf8 qcom: qnovo: restart pulse train in stall state
There are a couple of cases where qnovo charging fails,

1. pulse train enable command register fails to write through, or
2. pulse engine fails to start and pulse train timer PTTIME does
   not start counting.

In either case, qnovo charging will stop. Here is the fix,

Write register twice when enabling pulse train, and
restart pulse train if PTTIME does not increase.

Change-Id: Ic235f8f2bc67fe577e42848ef623870c25b68256
Signed-off-by: Harry Yang <harryy@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:28:00 -07:00
Abhijeet Dharmapurikar
cbff20cc9a qpnp-qnovo: add debounce for charger
The request is to delay ok_to_qnovo for 15 seconds after a charger is
inserted.

To achive that:
Make ok_to_qnovo variable as a votable that can be voted on by
A. HW error conditions
B. Charger is ready  after debounce

Moreover since there could be two chargers -usb and dc, create another
votable to track their individual debounce states. The result of this
votable will feed in to ok_to_qnovo votable as branch B above.

Also since we need to stay awake for the debounce time, create an
awake_votable and vote on it while debounce on either usb or dc is in
progress.

Change-Id: I32dc07ba16ef0515a9683f2702d317c39baa2eba
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:28:00 -07:00
Abhijeet Dharmapurikar
354e7f16bd qpnp-qnovo: prevent pulse train while esr is in progress
At the end of pulse train ESR measurement is forced. It is expected
that when ESR is being measured, which takes about 1.5 seconds, the
next pulse train does not start.

However we see that a uevent is sent to userspace and it enables pulse
train within 100mS.

To prevent that put the pulse train enabling bit under a votable
control. And make QNI_VOTER (the userspace voter) and ESR_VOTER vote
on it.

Moreover, the current pulse train enabling path checks if qnovo was
enabled, make a QNOVO_OVERALL_ENABLE voter to this new voter to reflect
it.

Change-Id: I6d2177250cc47f5aeb6591c532ee18d37e3b02c6
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:27:56 -07:00
Abhijeet Dharmapurikar
18cb81a94f qpnp-fg-gen3: qnovo ESR/IADC workarounds
When FG IADC measurement period coincides with qnovo discharge pulses
it reads incorrect IADC values. That causes issues with SOC accuracy
and capacity learning amongst others.

The fix to IADC inaccuracy is to set a bit in the FG
peripheral while Qnovo is active.

A side effect of IADC inaccuracy fix is that the ESR
measurement goes haywire. To overcome that, disable ESR when
Qnovo is active and force an esr measurement when its between pulses.

Realize this by disabling ESR and enabling the bit when
Qnovo becomes active. The qnovo driver will set CHARGE_QNOVO_ENABLE
property on the bms psy when its active. Also provide code to
force an ESR measurement via a write to RESISTANCE property in
bms psy.

Change-Id: I7160ad6288362c17d28d67b38ec09332d9a6cbd2
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:26:29 -07:00
Abhijeet Dharmapurikar
7b5b0b5914 qpnp-qnovo: IADC/ESR workarounds
When FG IADC measurement period coincides with qnovo discharge pulses
it reads incorrect IADC values. That causes issues with SOC accuracy
and capacity learning amongst others.

The fix to IADC inaccuracy is to set a bit in the FG peripheral while
Qnovo is active.

A side effect of IADC inaccuracy fix is that the ESR measurement goes
haywire. To overcome that, disable ESR when Qnovo is active and force
an esr measurement when its between pulses.

Realize this by setting CHARGE_QNOVO_ENABLE and RESISTANCE property on
the bms psy at appropriate times in the driver.

Change-Id: I5b37083c843ec6bc052c4d344347b9a80554e226
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-31 19:23:19 -07:00
Linux Build Service Account
2552d0a834 Merge "power: smb-lib: enable DPDM regulator at CC attach" 2017-07-31 09:52:17 -07:00
Nicholas Troast
95f429cba2 power: pmic-voter: use force_val in rerun election
If force_val is used it can be overwritten by rerun election. Fix this
by getting the effective result which takes the force_val into
consideration.

Change-Id: I2d52d0b2cad1d515efaa103187e7197fe78cc106
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
2017-07-31 09:35:04 -07:00
Anirudh Ghayal
0934c154fd power: qpnp-fg-gen3: Use msoc for recharge-soc comparison
The recharge SOC is based off the monotonic SOC (msoc). Hence, use
the msoc to determine if the hold-soc-while-full logic needs
to be applied.

CRs-Fixed: 2080211
Change-Id: I52b02adc4d97cbed42b0c8034a5a48dba1e343d3
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
2017-07-30 21:12:15 +05:30
Harry Yang
4e6b3d37f5 qcom: smb138x: supsend USBIN and disable OTG before shutdown
SMB138X does not get reset when device restarts, so USBIN and OTG settings
will not be cleared. Reset them on PMIC shutdown, and restore in probe.

Disable OTG in early driver probe, because device may restart from WDOG
bite with OTG enabled.

CRs-Fixed: 2083638
Change-Id: I451d3e861ea28f89029fe8759599ac0e133baf11
Signed-off-by: Harry Yang <harryy@codeaurora.org>
2017-07-28 16:32:53 -07:00
Ashay Jaiswal
2cf2aaf54c power: smb-lib: enable DPDM regulator at CC attach
In case of quick back-to-back  insertion/removal of USB
there is a possibility that VBUS does not fall below the
1V usb-plugout threshold and hence the subsequent insertion
does not generate a plug-in event. This keeps the DPDM
regulator disabled at insertion thus impacting the APSD result.

Fix this by voting to enable the DPDM regulator in the cc-attach
handler.

CRs-Fixed: 2042071
Change-Id: I37a32081f0847965e34eb1c4114602ec61e9a005
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
2017-07-28 16:41:08 +05:30
Ashay Jaiswal
95e05ba592 power: qcom-step-chg: Add temperature based step-charging
It supports for temperature (JEITA) based step charging.
The solution samples the battery temperature periodically and
applies the FCC from a static look-up table.

There is a provision for timed hysteresis which is achieved using
a 5 second delayed work.

Change-Id: Ica18f2c812232d6938799dab16fb9f18bc14b48f
Signed-off-by: Ashay Jaiswal <ashayj@codeaurora.org>
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
2017-07-26 15:20:44 -07:00
Anirudh Ghayal
3abd7de15e power: smb-lib: Update the FLOAT detection logic
An SDP may get detected as a FLOAT charger by PMIC APSD.
To handle this case do the following steps when a FLOAT
charger is detected -

1. Limit the ICL to 100mA and start USB enumeration
2. If enumeration succeeds, USB notifies a valid
   ICL and the charger updates ICL and charger-type to SDP.
3. If enumeration fails, USB notifies -ETIMEDOUT and
   charger applies ICL based on the Rp value.

CRs-Fixed: 2081457
Change-Id: I2747a42ed9f9531e83c53d781a8ae9baa9aa74d0
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
2017-07-26 22:52:45 +05:30
Anirudh Ghayal
476954d0e7 power: smb2: Update the charger buck frequencies for PM660
Update the charger buck frequencies for 5V and 6V_8V
VBUS voltages as per design recommendation.

Change-Id: I3c4007cff1f3d7dcb5d5e64d93c887441dc6ea5a
Signed-off-by: Anirudh Ghayal <aghayal@codeaurora.org>
2017-07-26 09:20:24 +05:30