static int bq27541_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { int ret = 0; struct bq27541_device_info *di = to_bq27541_device_info(psy); DBG("Enter:%s %d psp= %d\n",__FUNCTION__,__LINE__,psp); switch (psp) { case POWER_SUPPLY_PROP_STATUS: ret = bq27541_battery_status(di, val); break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: case POWER_SUPPLY_PROP_PRESENT: val->intval = bq27541_battery_voltage(di); if (psp == POWER_SUPPLY_PROP_PRESENT){ val->intval = val->intval <= 0 ? 0 : 1; } break; case POWER_SUPPLY_PROP_CURRENT_NOW: val->intval = bq27541_battery_current(di); break; case POWER_SUPPLY_PROP_CAPACITY: if (di->power_down == 1){ // < 3.4V power down ,capacity = 0; val->intval = 0; }else { val->intval = bq27541_battery_rsoc(di); } break; case POWER_SUPPLY_PROP_TEMP: val->intval = bq27541_battery_temperature(di); break; case POWER_SUPPLY_PROP_TECHNOLOGY: val->intval = POWER_SUPPLY_TECHNOLOGY_LION; break; case POWER_SUPPLY_PROP_HEALTH: ret = bq27541_health_status(di, val); break; case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: ret = bq27541_battery_time(di, BQ27x00_REG_TTE, val); break; case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: ret = bq27541_battery_time(di, BQ27x00_REG_TTECP, val); break; case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: ret = bq27541_battery_time(di, BQ27x00_REG_TTF, val); break; default: return -EINVAL; } return ret; }
/********************** Boot threshold voltage limit is set in the ADC driver,judge here only to prevent 0% capacity but voltage is more than 3.5V leading to shut down immediately after boot ***********************/ static void battery_capacity_check(struct bq27541_device_info *di) { int rsoc; rsoc = bq27541_battery_rsoc(di); if(rsoc <= 0){ if(is_usbcharging()){ printk("usb charging and capacity less than 0%,continue charging\n"); low_usb_charge = true; return; }else if(!is_accharging()){ printk("no charging and capacity less than 0%,power off\n"); kernel_power_off(); } } #if defined(CONFIG_REBOOT_TO_POWER_OFF) if ((board_boot_mode() == BOOT_MODE_REBOOT) ) if((0 == charge_status_now) && (rsoc <= 5)) kernel_power_off(); #endif return; }
static int bq27541_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { int ret = 0; struct bq27541_device_info *di = to_bq27541_device_info(psy); DBG("Enter:%s %d psp= %d\n",__FUNCTION__,__LINE__,psp); switch (psp) { case POWER_SUPPLY_PROP_STATUS: ret = bq27541_battery_status(di, val); break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: val->intval = bq27541_battery_voltage(di); break; case POWER_SUPPLY_PROP_PRESENT: #if 0 val->intval = bq27541_battery_voltage(di); if (psp == POWER_SUPPLY_PROP_PRESENT){ val->intval = val->intval <= 0 ? 0 : 1; } #else val->intval = 1; #endif break; case POWER_SUPPLY_PROP_CURRENT_NOW: val->intval = bq27541_battery_current(di); break; case POWER_SUPPLY_PROP_CAPACITY: val->intval = bq27541_battery_rsoc(di); break; case POWER_SUPPLY_PROP_TEMP: val->intval = bq27541_battery_temperature(di); #if defined(CONFIG_CHARGER_LIMITED_BY_TEMP) if(1 == charge_en_flags) temp_val = val->intval; #endif break; case POWER_SUPPLY_PROP_TECHNOLOGY: val->intval = POWER_SUPPLY_TECHNOLOGY_LION; break; case POWER_SUPPLY_PROP_HEALTH: ret = bq27541_health_status(di, val); break; case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW: ret = bq27541_battery_time(di, BQ27x00_REG_TTE, val); break; case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG: ret = bq27541_battery_time(di, BQ27x00_REG_TTECP, val); break; case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW: ret = bq27541_battery_time(di, BQ27x00_REG_TTF, val); break; default: return -EINVAL; } return ret; }