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>
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>
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>
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>
CHARGE_COUNTER is a required battery power supply property. Add it.
Change-Id: Ieb9c64447f88213479ce14b738f71fa703ffc194
Signed-off-by: Nicholas Troast <ntroast@codeaurora.org>
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>
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>
Provide support to enable/disable sw jeita using a power supply
property.
Change-Id: Id1c2a4bcd8caece5ed7591dc5ab5bf3ac2207cba
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>