static int mc13892_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct mc13892_dev_info *di = to_mc13892_dev_info(psy); switch (psp) { case POWER_SUPPLY_PROP_STATUS: if (di->battery_status == POWER_SUPPLY_STATUS_UNKNOWN) { #ifdef CONFIG_MACH_MX51_ERDOS mc13892_charger_update_status(di); /* first call */ mc13892_battery_update_status(di); #else mc13892_battery_update_status(di); mc13892_charger_update_status(di); #endif /* CONFIG_MACH_MX51_ERDOS */ } val->intval = di->battery_status; return 0; default: break; } mc13892_battery_read_status(di); switch (psp) { case POWER_SUPPLY_PROP_VOLTAGE_NOW: val->intval = di->voltage_uV; break; #ifndef CONFIG_MACH_MX51_ERDOS case POWER_SUPPLY_PROP_CURRENT_NOW: val->intval = di->current_uA; break; case POWER_SUPPLY_PROP_CHARGE_NOW: val->intval = di->accum_current_uAh; break; #endif /* CONFIG_MACH_MX51_ERDOS */ default: return -EINVAL; } return 0; }
static int mc13892_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct mc13892_dev_info *di = to_mc13892_dev_info(psy); switch (psp) { case POWER_SUPPLY_PROP_STATUS: if (di->battery_status == POWER_SUPPLY_STATUS_UNKNOWN) { mc13892_charger_update_status(di); mc13892_battery_update_status(di); } val->intval = di->battery_status; return 0; default: break; } mc13892_battery_read_status(di); switch (psp) { case POWER_SUPPLY_PROP_VOLTAGE_NOW: val->intval = di->voltage_uV; break; case POWER_SUPPLY_PROP_CURRENT_NOW: val->intval = di->current_uA; break; case POWER_SUPPLY_PROP_CHARGE_NOW: val->intval = di->accum_current_uAh; break; case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: val->intval = 3800000; break; case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: val->intval = 3300000; break; default: return -EINVAL; } return 0; }
static int mc13892_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct mc13892_dev_info *di = to_mc13892_dev_info(psy); unsigned int online=0; static int lowBattaryCount =0; //bool bInLowBattaryState = false; online = get_charger_state(); switch (psp) { case POWER_SUPPLY_PROP_STATUS: if (di->battery_status == POWER_SUPPLY_STATUS_UNKNOWN) { mc13892_charger_update_status(di); mc13892_battery_update_status(di); } val->intval = di->battery_status; return 0; default: break; } mc13892_battery_read_status(di); switch (psp) { case POWER_SUPPLY_PROP_VOLTAGE_NOW: val->intval = di->voltage_uV; break; case POWER_SUPPLY_PROP_CURRENT_NOW: val->intval = di->current_uA; break; case POWER_SUPPLY_PROP_CHARGE_NOW: val->intval = di->accum_current_uAh; break; case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: val->intval = PMIC_VOLTAGE_MAX_WORK; break; case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: val->intval = PMIC_VOLTAGE_MIN_WORK; break; case POWER_SUPPLY_PROP_CAPACITY: val->intval = di->capacity; break; case POWER_SUPPLY_PROP_VOLTAGE_MAX: val->intval = PMIC_VOLTAGE_MAX_WORK; break; case POWER_SUPPLY_PROP_VOLTAGE_MIN: val->intval = PMIC_VOLTAGE_MIN_WORK; break; case POWER_SUPPLY_PROP_HEALTH: val->intval = POWER_SUPPLY_HEALTH_GOOD; break; default: return -EINVAL; } return 0; }
static int mc13892_compute_battery_capacity_from_CC(struct work_struct *work) { int v=0; static int old_state = -1; //static int old_init_charge = 0; int CurVolts =0; int iCount=0; int CurRangeNextC =0; int CurRangeC =0; int CurCountNext = 0; int CurCountPre = 0; static int old_CurRangeC = 0; long cc = 0; struct mc13892_dev_info *di = container_of(work, struct mc13892_dev_info, calc_capacity.work); if (di->charger_online != old_state) { //pmic_calibrate_coulomb_counter(); pmic_stop_coulomb_counter(); di->init_charge = -1; } if (di->init_charge == -1) { /*first entry - init */ //pmic_set_chg_current(0); mc13892_battery_read_status(di); //printk("[%s] di->voltage_uV = %i; %i\n",__func__,di->voltage_uV,di->voltage_uV/1000); di->init_charge = mc13892_compute_battery_charge_from_V(di->voltage_uV / 1000); pmic_start_coulomb_counter(); //mc13892_battery_read_status(di); } old_state = di->charger_online; pmic_get_charger_coulomb_raw(&cc); if (di->charger_online) { v = (di->init_charge + ((long)abs(cc) * 10 / 36)) * 100 / BAT_CAP_MAH; } else { v = (di->init_charge - ((long)abs(0xffff - cc ? cc : 0xffff) * 10 / 36)) * 100 / BAT_CAP_MAH; } if(bUsbstateChanged) { bUsbstateChanged = false; capacityOffset = v - di->capacity; } v=v -capacityOffset; ///Bootup with DC-DC,sometimes the capacity read error,so we ///need reread again. if((di->charger_online) && bBootupWithCharger){ CurVolts =(di->voltage_uV / 1000) ; while (CurVolts < charge[iCount].v) { CurCountNext = iCount+1; CurRangeNextC = charge[CurCountNext].c; CurRangeC = charge[iCount].c; iCount++; } if(( v > CurRangeC ) || (v< CurRangeNextC) ) { di->init_charge = -1; if (di->monitor_wqueue) queue_delayed_work(di->monitor_wqueue, &di->calc_capacity, msecs_to_jiffies(50)); else schedule_delayed_work(&di->calc_capacity, msecs_to_jiffies(50)); } if(v< old_CurRangeC){ v= old_CurRangeC; }else{ old_CurRangeC =v; } } if (v > 100) v = 100; if (v < 0) v = 0; di->capacity = v; ////sometimes when the voltage is low 3600, ///the capacity will be read error. it as 100,so we use the ///follow funtions to avoid it. if(!(di->charger_online)){ if(((di->voltage_uV / 1000) < 3550) && ((di->voltage_uV / 1000) > 3525)) { if(di->capacity > 5) di->capacity = 4; }else if (((di->voltage_uV / 1000) < 3525) && ((di->voltage_uV / 1000) > 3500)) { if(di->capacity > 2) di->capacity = 2; }else if ((di->voltage_uV / 1000) < 3500) { di->capacity = 0; } } if (di->monitor_wqueue) queue_delayed_work(di->monitor_wqueue, &di->calc_capacity, msecs_to_jiffies(5000)); else schedule_delayed_work(&di->calc_capacity, msecs_to_jiffies(5000)); return 0; }