Earlier the charger status worker will be active only when a fault occurs and we used to monitor the Battery/charger until fault is cleared. In this patch the charger status worker will run continuously at different intervals depending on the Platform state(idle, active) and battery state(normal, fault) conditions. During idle conditions(no audio, video etc..) platform is drawing less than 500mA. If the Ibatt is more Than the idle current then the platform is in active mode. After finding the platform state and battery state we will schedule (possibly 60s, 10s, 5s, 1s) the status monitoring worker.
Signed-off-by: Ramakrishna Pallala <[email protected]> --- drivers/power/intel_mdf_battery.c | 50 ++++++++++++++++++++++++++---------- 1 files changed, 36 insertions(+), 14 deletions(-) diff --git a/drivers/power/intel_mdf_battery.c b/drivers/power/intel_mdf_battery.c index 431d190..dcc8b1b 100644 --- a/drivers/power/intel_mdf_battery.c +++ b/drivers/power/intel_mdf_battery.c @@ -223,6 +223,7 @@ #define CHARGE_FULL_IN_MAH 1500 /* 1500 mAh */ #define MSIC_CHRG_RBATT_VAL 180 /* 180 mOhms */ #define COLMB_TO_MAHRS_CONV_FCTR 3600 +#define IDLE_STATE_CUR_LMT -500 /* -500mA */ #define MSIC_BATT_TEMP_MAX 60000 /* 60000 milli degrees */ #define MSIC_BATT_TEMP_MIN 0 @@ -238,7 +239,7 @@ #define IPCCMD_CC_READ 0x01 #define TEMP_CHARGE_DELAY_JIFFIES (HZ * 30) /*30 sec */ -#define CHARGE_STATUS_DELAY_JIFFIES (HZ * 10) /*10 sec */ +#define CHARGE_STATUS_DELAY_JIFFIES (HZ * 60) /*60 sec */ #define IRQ_FIFO_MAX 16 #define THERM_CURVE_MAX_SAMPLES 7 @@ -1995,10 +1996,20 @@ 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, chr_mode, chr_event; + int retval, val, volt, temp, ibatt_avg, is_active = 0, is_fault = 0; + int chr_mode, chr_event; + unsigned int delay = CHARGE_STATUS_DELAY_JIFFIES; struct msic_power_module_info *mbi = container_of(work, struct msic_power_module_info, chr_status_monitor.work); + /* If battery is not charging Ibatt value will be in -ve + * direction and if platfrom is idle then the current drawn + * by board is around 500mA + */ + ibatt_avg = read_avg_ibatt(mbi); + if (ibatt_avg < IDLE_STATE_CUR_LMT) + is_active = 1; + retval = intel_scu_ipc_ioread8(CHR_STATUS_FLULT_REG, &data); if (retval) { dev_warn(msic_dev, "%s:ipc read failed\n", __func__); @@ -2009,14 +2020,14 @@ static void msic_status_monitor(struct work_struct *work) val = (data & CHR_STATUS_BIT_MASK) >> 4; if (val == CHR_STATUS_BIT_FAULT) { dev_dbg(msic_dev, "chr status regisrer:%x\n", data); - schedule_delayed_work(&mbi->chr_status_monitor, - CHARGE_STATUS_DELAY_JIFFIES); - return ; + is_fault = 1; + goto fault_detected; } /* Compute Charger health */ mutex_lock(&mbi->usb_chrg_lock); - if (mbi->usb_chrg_props.charger_health != POWER_SUPPLY_HEALTH_GOOD) + if (mbi->usb_chrg_props.charger_health != POWER_SUPPLY_HEALTH_UNKNOWN && + mbi->usb_chrg_props.charger_health != POWER_SUPPLY_HEALTH_GOOD) mbi->usb_chrg_props.charger_health = POWER_SUPPLY_HEALTH_GOOD; mutex_unlock(&mbi->usb_chrg_lock); @@ -2038,10 +2049,9 @@ static void msic_status_monitor(struct work_struct *work) */ if (temp >= (MSIC_BATT_TEMP_MAX - MSIC_TEMP_HYST_ERR) || temp <= (MSIC_BATT_TEMP_MIN + MSIC_TEMP_HYST_ERR)) { - schedule_delayed_work(&mbi->chr_status_monitor, - CHARGE_STATUS_DELAY_JIFFIES); mutex_unlock(&mbi->batt_lock); - return ; + is_fault = 1; + goto fault_detected; } } @@ -2058,14 +2068,26 @@ static void msic_status_monitor(struct work_struct *work) volt = mdf_read_adc_regs(MSIC_ADC_VOL_IDX, mbi); dev_dbg(msic_dev, "low vol in mV :%d\n", volt); if (volt < BATT_LOWBATT_CUTOFF_VOLT) { - schedule_delayed_work(&mbi->chr_status_monitor, - CHARGE_STATUS_DELAY_JIFFIES); mutex_unlock(&mbi->batt_lock); - return ; + if (volt < BATT_DEAD_CUTOFF_VOLT) + power_supply_changed(&mbi->batt); + is_fault = 1; + goto fault_detected; } } mbi->batt_props.health = POWER_SUPPLY_HEALTH_GOOD; mutex_unlock(&mbi->batt_lock); + +fault_detected: + if (is_fault && is_active) + delay = delay / 60; /* 1 Sec delay */ + else if (is_fault && !is_active) + delay = delay / 12; /* 5 Sec delay */ + else if (!is_fault && is_active) + delay = delay / 6; /* 10 Sec delay */ + + schedule_delayed_work(&mbi->chr_status_monitor, delay); + } /** * msic_battery_interrupt_handler - msic battery interrupt handler @@ -2165,8 +2187,6 @@ static irqreturn_t msic_battery_thread_handler(int id, void *dev) msic_handle_exception(mbi, data[0], data[1]); power_supply_changed(&mbi->batt); power_supply_changed(&mbi->usb); - schedule_delayed_work(&mbi->chr_status_monitor, - CHARGE_STATUS_DELAY_JIFFIES); } return IRQ_HANDLED; @@ -2575,6 +2595,8 @@ static int msic_battery_probe(struct platform_device *pdev) } + /* Start the status monitoring worker */ + schedule_delayed_work(&mbi->chr_status_monitor, 0); return retval; requestirq_failed: -- 1.7.2.3
0006-Adaptive-monitoring-support.patch
Description: 0006-Adaptive-monitoring-support.patch
_______________________________________________ MeeGo-kernel mailing list [email protected] http://lists.meego.com/listinfo/meego-kernel
