aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/power/intel_mdf_battery.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/drivers/power/intel_mdf_battery.c b/drivers/power/intel_mdf_battery.c
index 45f8e8ed4ac..5371bc5f040 100644
--- a/drivers/power/intel_mdf_battery.c
+++ b/drivers/power/intel_mdf_battery.c
@@ -1476,10 +1476,10 @@ static int msic_batt_stop_charging(struct msic_power_module_info *mbi)
* capabilities connected to the platform.
*/
static int msic_batt_do_charging(struct msic_power_module_info *mbi,
- struct charge_params *params)
+ struct charge_params *params, int is_maint_mode)
{
int retval;
- static u8 data[8] = {
+ static u8 data[] = {
WDTWRITE_UNLOCK_VALUE, 0,
WDTWRITE_UNLOCK_VALUE, 0,
WDTWRITE_UNLOCK_VALUE, 0,
@@ -1508,12 +1508,10 @@ static int msic_batt_do_charging(struct msic_power_module_info *mbi,
dev_dbg(msic_dev, "Charger Enabled\n");
mutex_lock(&mbi->batt_lock);
- spin_lock(&mbi->event_lock);
- if (mbi->charging_mode == BATT_CHARGING_MODE_MAINTAINENCE)
+ if (is_maint_mode)
mbi->batt_props.status = POWER_SUPPLY_STATUS_FULL;
else
mbi->batt_props.status = POWER_SUPPLY_STATUS_CHARGING;
- spin_unlock(&mbi->event_lock);
mbi->batt_props.health = POWER_SUPPLY_HEALTH_GOOD;
mutex_unlock(&mbi->batt_lock);
@@ -1714,7 +1712,7 @@ static void calculate_charge_cycles(struct msic_power_module_info *mbi,
*/
static void msic_batt_temp_charging(struct work_struct *work)
{
- int ret, i, charge_now, is_maint_chrg = false;
+ int ret, i, charge_now, is_maint_chrg = false, is_lowchrg_enbl;
static int iprev = -1, is_chrg_enbl;
short int cv = 0, cc = 0, vinlimit = 0, cvref;
int adc_temp, adc_vol;
@@ -1787,13 +1785,17 @@ static void msic_batt_temp_charging(struct work_struct *work)
cvref = sfi_table->temp_mon_range[i].maint_chrg_vol_ul;
is_maint_chrg = true;
}
+ spin_unlock(&mbi->event_lock);
+
ret = check_charge_full(mbi, cvref);
if (ret) {
is_chrg_enbl = false;
- if (mbi->charging_mode != BATT_CHARGING_MODE_MAINTAINENCE) {
+ if (!is_maint_chrg) {
dev_dbg(msic_dev, "Going to Maintenence CHRG Mode\n");
+
+ spin_lock(&mbi->event_lock);
mbi->charging_mode = BATT_CHARGING_MODE_MAINTAINENCE;
- is_maint_chrg = true;
+ spin_unlock(&mbi->event_lock);
mutex_lock(&mbi->batt_lock);
charge_now = msic_read_coloumb_ctr();
@@ -1801,9 +1803,11 @@ static void msic_batt_temp_charging(struct work_struct *work)
cc_to_coloumbs(charge_now);
mbi->batt_props.status = POWER_SUPPLY_STATUS_FULL;
mutex_unlock(&mbi->batt_lock);
+
+ is_maint_chrg = true;
+ power_supply_set_battery_charged(&mbi->batt);
}
}
- spin_unlock(&mbi->event_lock);
/*
* If we are in same Temparature range check for check for the
@@ -1860,19 +1864,20 @@ static void msic_batt_temp_charging(struct work_struct *work)
* allow the charging as set in charge current register
*/
spin_lock(&mbi->event_lock);
- if (!mbi->emrg_chrg_enbl && (i == sfi_table->temp_mon_ranges)) {
+ if (!mbi->emrg_chrg_enbl && (adc_temp < 0)) {
dev_dbg(msic_dev, "Emeregency Charging Enabled\n");
- ipc_read_modify_chr_param_reg(mbi, MSIC_BATT_CHR_SPCHARGER_ADDR,
- CHR_SPCHRGER_LOWCHR_ENABLE, BIT_SET);
+ is_lowchrg_enbl = BIT_SET;
} else {
dev_dbg(msic_dev, "Emeregency Charging Not Enabled\n");
- ipc_read_modify_chr_param_reg(mbi, MSIC_BATT_CHR_SPCHARGER_ADDR,
- CHR_SPCHRGER_LOWCHR_ENABLE, BIT_RESET);
+ is_lowchrg_enbl = BIT_RESET;
}
spin_unlock(&mbi->event_lock);
+ ipc_read_modify_chr_param_reg(mbi, MSIC_BATT_CHR_SPCHARGER_ADDR,
+ CHR_SPCHRGER_LOWCHR_ENABLE, is_lowchrg_enbl);
+
/* enable charging here */
- ret = msic_batt_do_charging(mbi, &charge_param);
+ ret = msic_batt_do_charging(mbi, &charge_param, is_maint_chrg);
if (ret) {
dev_warn(msic_dev, "msic_batt_do_charging failed\n");
goto lbl_sched_work;
@@ -1887,7 +1892,6 @@ lbl_sched_work:
schedule_delayed_work(&mbi->connect_handler, TEMP_CHARGE_DELAY_JIFFIES);
}
-
static void msic_batt_disconn(struct work_struct *work)
{
int ret;
@@ -1989,7 +1993,7 @@ static int msic_charger_callback(void *arg, int event, struct otg_bc_cap *cap)
static void msic_status_monitor(struct work_struct *work)
{
uint8_t data;
- int retval, val, volt, temp;
+ int retval, val, volt, temp, chr_mode, chr_event;
struct msic_power_module_info *mbi = container_of(work,
struct msic_power_module_info, chr_status_monitor.work);
@@ -2014,6 +2018,11 @@ static void msic_status_monitor(struct work_struct *work)
mbi->usb_chrg_props.charger_health = POWER_SUPPLY_HEALTH_GOOD;
mutex_unlock(&mbi->usb_chrg_lock);
+ spin_lock(&mbi->event_lock);
+ chr_mode = mbi->charging_mode;
+ chr_event = mbi->batt_event;
+ spin_unlock(&mbi->event_lock);
+
/* Compute Battery health */
mutex_lock(&mbi->batt_lock);
if (mbi->batt_props.health == POWER_SUPPLY_HEALTH_OVERHEAT) {
@@ -2034,16 +2043,14 @@ static void msic_status_monitor(struct work_struct *work)
}
}
- spin_lock(&mbi->event_lock);
- if (mbi->charging_mode == BATT_CHARGING_MODE_MAINTAINENCE)
+ if (chr_mode == BATT_CHARGING_MODE_MAINTAINENCE)
mbi->batt_props.status = POWER_SUPPLY_STATUS_FULL;
- else if (mbi->charging_mode == BATT_CHARGING_MODE_NORMAL)
+ else if (chr_mode == BATT_CHARGING_MODE_NORMAL)
mbi->batt_props.status = POWER_SUPPLY_STATUS_CHARGING;
- else if (mbi->batt_event == USBCHRG_EVENT_SUSPEND)
+ else if (chr_event == USBCHRG_EVENT_SUSPEND)
mbi->batt_props.status = POWER_SUPPLY_STATUS_NOT_CHARGING;
else
mbi->batt_props.status = POWER_SUPPLY_STATUS_DISCHARGING;
- spin_unlock(&mbi->event_lock);
if (mbi->batt_props.health == POWER_SUPPLY_HEALTH_DEAD) {
volt = mdf_read_adc_regs(MSIC_ADC_VOL_IDX, mbi);