mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-11 07:03:09 -04:00
Add OVP and OCP for battery
Add battery OVP and OCP for battery charging to workaroud the CE certification. Change-Id: I2004e4a280cf2e5e8ce0d19c501e4a338e45d500 Signed-off-by: Yonghua Yan <yanyh2@motorola.com> Reviewed-on: https://gerrit.mot.com/2316155 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Jianqi Yang <yangj@motorola.com> Submit-Approved: Jira Key
This commit is contained in:
parent
9c4e76e7b1
commit
9f61fd6d0e
1 changed files with 38 additions and 0 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include <linux/regulator/driver.h>
|
||||
#include <linux/regulator/of_regulator.h>
|
||||
#include <linux/regulator/machine.h>
|
||||
#include <linux/time64.h>
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/gpio.h>
|
||||
|
|
@ -2267,6 +2268,9 @@ static void sgm4154x_charger_set_constraint(void *data,
|
|||
/* Battery presence detection threshold on battery temperature */
|
||||
#define BPD_TEMP_THRE (-30)
|
||||
#define PANIC_DEB_CNT_MAX (3)
|
||||
#define VBAT_OVP_MV (4600)
|
||||
#define IBAT_OCP_MA (1500)
|
||||
#define PROTECT_DELAY_MS (60000)
|
||||
static void sgm4154x_paired_battery_notify(void *data,
|
||||
struct mmi_battery_info *batt_info)
|
||||
{
|
||||
|
|
@ -2287,6 +2291,10 @@ static void sgm4154x_paired_battery_notify(void *data,
|
|||
static int panic_deb_cnt = 0;
|
||||
static bool prev_high_load_en = false;
|
||||
static bool prev_low_load_en = false;
|
||||
struct timespec64 now;
|
||||
static struct timespec64 start = {0};
|
||||
uint32_t elapsed_ms;
|
||||
static bool batt_protected = false;
|
||||
|
||||
if (!batt_info || batt_info->batt_mv <= 0) {
|
||||
pr_warn("Invalid paired battery info\n");
|
||||
|
|
@ -2386,6 +2394,36 @@ static void sgm4154x_paired_battery_notify(void *data,
|
|||
low_load_en = false;
|
||||
}
|
||||
|
||||
/* Monitor vbat and ibat for OVP and OCP */
|
||||
if (chg->batt_info.batt_mv >= VBAT_OVP_MV) {
|
||||
high_load_en = true;
|
||||
low_load_en = true;
|
||||
batt_protected = true;
|
||||
ktime_get_real_ts64(&start);
|
||||
pr_err("ERROR: vbat OVP is triggered, batt_mv=%dmV\n",
|
||||
chg->batt_info.batt_mv);
|
||||
} else if (chg->batt_info.batt_ma >= IBAT_OCP_MA) {
|
||||
high_load_en = true;
|
||||
low_load_en = true;
|
||||
batt_protected = true;
|
||||
ktime_get_real_ts64(&start);
|
||||
pr_err("ERROR: ibat OCP is triggered, batt_ma=%dmA\n",
|
||||
chg->batt_info.batt_ma);
|
||||
} else if (batt_protected) {
|
||||
ktime_get_real_ts64(&now);
|
||||
elapsed_ms = (now.tv_sec - start.tv_sec) * 1000;
|
||||
elapsed_ms += (now.tv_nsec - start.tv_nsec) / 1000000;
|
||||
if (elapsed_ms < PROTECT_DELAY_MS &&
|
||||
chg->chg_info.chrg_present) {
|
||||
high_load_en = true;
|
||||
low_load_en = true;
|
||||
pr_warn("keep batt protected, elapsed=%dms\n", elapsed_ms);
|
||||
} else {
|
||||
batt_protected = false;
|
||||
pr_warn("recover batt from ovp/ocp protection\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (high_load_en != prev_high_load_en) {
|
||||
if (gpio_is_valid(chg->sgm->high_load_en_gpio)) {
|
||||
gpio_set_value(chg->sgm->high_load_en_gpio,
|
||||
|
|
|
|||
Loading…
Reference in a new issue