There are situations when we observe that charging is in progress
but the end of charge (EOC) worker is not running. This leads to
problems like
-never detecting end of charge
-not adjusting vddmax
-not preventing suspend while charging.
The reason is that the bootloader could have started charging already,
causing a fastchg interrupt to not happen. If the fastchg interrupt is
missed the driver will never start EOC worker.
Check the real time status of the fastchg interrupt and if it is fast
charging invoke the handler so that the eoc worker could be
started.
(cherry picked from commit 7f1d97fd69c3afe66577e731105207e5db544ab2)
CRs-Fixed: 393301
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Change-Id: I5c0ba3b8f0653c5f9d64f35346601763c059505a
Signed-off-by: Neha Pandey <nehap@codeaurora.org>
Toggle the CHG_USB_SUSPEND bit when utilizing the VBUS boost.
This bit controls ensures that no current is being drawn from
a USB device and the charger runs off the battery.
This makes sure that when pm8921_disable_source_current is called
the correct setting is written to the suspend bit depending
on the disable flag.
(cherry picked from commit d8878596b9b19668fd1f1b226a333d955f2218c4)
CRs-Fixed: 393498
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
Change-Id: Iae390fd10e59d6ba1fe85743c1015eea35b06f7a
Signed-off-by: Neha Pandey <nehap@codeaurora.org>
In the usb_ma_table there exist two consecutive values
that have IUSB_FINE_RES bit set. Some functions
incorrectly assume that this does not happen.
Fix this by checking for consecutive values having
IUSB_FINE_IRES bit set.
(cherry picked from commit 67ebde08e12d246302d133b4510d59c8f96325d1)
CRs-Fixed: 404348
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
Change-Id: I6b6ca96b92ec4b9765e4812352057a0ac8cff380
Signed-off-by: Neha Pandey <nehap@codeaurora.org>
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.
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
(cherry picked from commit a3cf943ef8c91435e2cb94b8e8bcc482dc65cb27)
Conflicts:
drivers/power/pm8921-charger.c
Change-Id: I565edb1ab797384481ce5e37aee73ee0a8e80428
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
Using stored average ibat(shutdown ibat_avg) which came from
previous boot sometimes cause SoC sudden drop in boot up time.
So this patch use fixed ibat_avg value instead of shutdown ibat_avg
during 1st SoC calculation.
Change-Id: I9675652c3b4918529be40a8d6f8ee29b6dee1359
Signed-off-by: Iliyan Malchev <malchev@google.com>
For accurate SoC calculation, bms need to know if target
was booted from reset or power down. Previously, minimum
CC value check was used to detect power on reason.
But this minimum CC value check is useless when charger is
connected. So, this patch use pmic power on reason to know
the exact power on reason.
Signed-off-by: Iliyan Malchev <malchev@google.com>
There are situation when the system undergoes a restart but the
pmic does not execute its power on sequence. In such case the OCV
value is not updated and the CC value is not cleared. Since OCV
and CC values came from the previous boot, we don't have to use
shutdown soc in this case. The use of shutdown soc without reset
of CC increase error of soc. So this patch remove use of shutdown
soc in restart case.
b/7327066
Change-Id: I2c5c5974a4c8ace076c1f8c56c856718b7140fb8
usb_psy type should be POWER_SUPPLY_TYPE_USB. Do not change the type.
Otherwise, if you boot up with DC, userspace might recognize usb_psy
as DC, not USB charger. After that, device might not detect the USB charger.
Change-Id: I73f743e77fbfee0cb5847be1fc6747fd48e41790
Signed-off-by: Iliyan Malchev <malchev@google.com>
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>
Since WLC(wireless charger) supply power to battery without PM8921 charger,
the SoC value is not accurate. This patch adjust OCV(open circuit voltage)
and max CV(constant voltage) value to compensate difference between
WLC and pm8921-charger.
Change-Id: I8fa368f706866d93451c2f663da69c010f9b2a35
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>
Calculated SoC could be fluctuated by system load. This patch
remove these fluctuation by using previous SoC if calculated Soc
is higher than previous value during discharging.
Change-Id: I1d144207125ed3c55030004fee1eb4b2489a298c
There is adjustment to prevent discontinuous SoC change when
calculated SoC is reported. This adjustment is performed while
device is charged only. In current implementation, the
determination of charging is not accurate. So in some case,
the adjustment is performed even device is not charged. This cause
unintended difference between reported SoC and calculated Soc.
This patch change the method of charging determination for
reported Soc adjustment.
Change-Id: I7caedf7d696be57c96d5f777e44f8ddecbdbc7f2
When battery is forced to stop charging by overheat, re-charging
should not be initiated even if re-charging condition is satisfied.
Change-Id: I0070039a186ccf3f12c0e79a8696a7aa3c61e538
When usb mode is changed from MTP to Tethering, chg_gone_irq_handler is called
and then disconnect tethering by turning off ovpfet from unplug_ovp_fet_open.
So we add under threshold to protect this error while usb is being connected.
Change-Id: Id66a3db0822c291ba348cf93d2e7a72f6ae857ae
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.
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Signed-off-by: Iliyan Malchev <malchev@google.com>
For some platforms disabling the input voltage
regulation is not sufficent to prevent unplug events
from going unnoticed.
Fix this by making sure the unplug_check_worker
is also running when a PC USB connection with
a current limit of 500 mA is set.
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Current pm8921 charger code doesn't consider the SoC % to determine
end of charging and recharging state. This can cause weird UI display
on SoC % and charging state.
For example, charging is completed when SoC % is not reached 100% or
charging is not completed even if SoC % is already 100%.
So this patch change how to determine end of charging and recharging.
Change-Id: Ice658488744d71117fedb64e0fa0eb7ad34c6573
In some case, USBIN voltage doesn't drop for a while when
usb cable is unplugged. Due to this error, charger cannot
be detected correctly. This patch introduce OVP_FET
off method to drop USBIN volatge in error case.
Change-Id: I8d279cc8b4e7a489e8bfdc86b2015ff45704f832
When batt temp state is changed to normal state in
battery temperature control, the charging current
is not restored. So this patch fix this bug.
Change-Id: I5ae69d1f4f9b3edba7973efe0d6d8d5dd61d1647
commit 8126554cf049d13f4dd2d815d86ea289efdc6f3a has fluctuation issue
between charging and not charging. It fixes this issue.
Change-Id: I1cc2f3b51b5c1077b5d317ce324e0ce05a616977
usb_otg is able to know what kind of charger is connected like as
USB, TA and Slimport. And we can decide the max charging current
by cable type. pm8921-charger is able to use this information.
And unplug_check_worker has some problem. Wrong charging current
might set as 100mA even thought USB charger can be set by max 500mA.
It cause very slow charging.
msg_otg didn't use power supply api properly due to not supported
some POWER_SUPPLY_PROPs in pm8921-charger.c. It's also fixed.
Change-Id: I86661fbe38e3db5522caab6ff316c0100f87fe0d
The thermal mitigation and battery temp control can overwrite
the ibat max value each other. So this patch remove the possibility
of overwrite ibat max value by mitigation and battery temp control.
Change-Id: Ib0f7bf2b8bd2e474d1d9c76bd5100b05310cb048
We need to monitor the battery status periodically.So change the message
level and simplify the information.
Change-Id: Ia010ad220875f6863b3cdf1835cf6a4afc555935
There is a problem when is_active_chg_plugged_in API check active_chg_plugged_in
with active_path for TA in unplug_check_worker. So we used the_chip->usb_present
for TA detection correctly due to the same usb port.(USB_IN->USB_OUT->DC_IN->DC_OUT).
Change-Id: If51923ba12e6496bf63123104a158d34cad377b0
This is expected to prevent missing wireless charger state.
The bms needs to know if anything is connected to the wireless charging.
Change-Id: Ie97130cc515d19ab17b67267d9aca7588c1fff72
The battery temperature should be controlled for safty.
So this patch indroduce battery temperature control.
Change-Id: Ia00e7ce5bf697591be2da94f9a7c2960738642d5
During UVLO events the charger hardware may lock up
if it is in hardware clock switching mode.
To fix this add a battery alarm with a lower threshold
that disables hardware clock switching.
When the system is awake the resume callback ensures
that the charger is running off of the 19.2 MhZ clock
which does not allow the charger to lock up. Therefore
if the battery alarm wakes up the device before hitting
UVLO the charger hardware will not be in hardware clock
switching mode.
CRs-Fixed: 374607
Signed-off-by: David Keitel <dkeitel@codeaurora.org>
Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Change-Id: I1bb20b2e7ff1a11f032b12b4abd4804ed130fe4a
lk should support battery check to enable this feature.
if you want to use it, set CONFIG_LGE_PM_BATTERY_ID_CHECKER=y
in defconfig
Change-Id: Ie92c612e197aeede39b8da526332add3fab15a19
When the device is started with a charger inserted, it reports 0% soc.
This is because a variable "soc_at_cv" is not initialized correctly in
the probe function.
Fix this by initializing it appropriately to -EINVAL.
Change-Id: I106f36e204c5cc4f16a8f52b9fa7a2a012282e35
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Forcing to return shutdown soc for the first 30 seconds was added so
that we show consistent soc right after bootup.
However with the recent changes to the algorithm viz. using termination
resistance for UUC, restricting UUC changes at most 1% and limiting the
OCV corrections, this forcing is not required. The soc stays within
limits of the shutdown soc.
Remove this forcing of shutdown soc.
Change-Id: Ie74e9318cca29ab60436df6ddec286917fbd0cd7
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
A drop in state of charge (soc) was observed right after End Of Charge
(EOC) happens. This was because calculated soc was still low, while the
scaling algorithm increased the SOC to 100%. There was a situation
where SOC was calculated right when charging finished but charger did not
send the EOC to bms - the charging adjustments algorithm does not scale
since it sees charging is stopped and falls back to the calculated soc
which was lower than the scaled soc.
Fix this by changing the calculated OCV(open circuit voltage) of the
battery so that the calculated soc is same as the scaled soc.
Change-Id: Ieb409721da6fc70d673ccbf4334f94a1793dfe7e
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
It was observed that while charging the reported soc sometimes reaches
100% before end of charging happens. At other times it does not reach
100% at end of charge and a abrupt jump to 100% soc happens.
Fix this by linearly increasing soc based on battery charge current
after constant voltage phase is reached. Constant voltage phase is
reached when battery voltage reaches the max value.
Also once constant voltage phase is reached and the voltage or charge
current decreases keep reporting the earlier soc. This could be because
of a transient system load.
Change-Id: I14c2f42d7897041db038ce85ce1124cf1ef261af
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
It was observed that the battery was charged at voltage less than the
max voltage. This was because the vdd max algorithm rounded down the
voltage.
Use voltage rounding up instead.
Change-Id: Ifb5e9c265b8f616e82abbb979ecfac5e6604b25d
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
Unusable Charge(UUC) is based on battery resistance and average load. Since
battery resistance is based on temperature and state of charge, UUC
is essentially based on temperature, state of charge and the load.
The purpose of UUC is to prevent the battery from falling below the
cutoff voltage. In the current implementation, since UUC is dependent
on SOC, it is small when SOC is high and gets bigger as SOC approaches
zero. This increase however is not linear which causes huge jumps in
SOC.
Remove the dependence of UUC on SOC. Simply use the resistance value
which would have been used when SOC = 0.
To find this resistance value, loop from SOC = 0 towards 100 and at each
step calculate/interpolate open circuit voltage, resistance and the
corresponding unusable voltage. The interpolated resistance value where
unusable voltage equals open circuit voltage is the termination
resistance. Use this resistance value for calculation of UUC. Note that
this resistance value is not dependent on the current SOC and will be
constant as long as the load and temperature remain the same.
Change-Id: I3ba91f8b1cb831e257f72363058a6e3a04ffc39b
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>