static void power_supply_changed_work(struct work_struct *work) { unsigned long flags; struct power_supply *psy = container_of(work, struct power_supply, changed_work); dev_dbg(psy->dev, "%s\n", __func__); spin_lock_irqsave(&psy->changed_lock, flags); if (psy->changed) { psy->changed = false; spin_unlock_irqrestore(&psy->changed_lock, flags); class_for_each_device(power_supply_class, NULL, psy, __power_supply_changed_work); power_supply_update_leds(psy); kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); spin_lock_irqsave(&psy->changed_lock, flags); } if (!psy->changed) wake_unlock(&psy->work_wake_lock); spin_unlock_irqrestore(&psy->changed_lock, flags); }
static void bdata_external_power_changed_work(struct work_struct *work) { struct data_info *di = container_of(work, struct data_info, external_change_work); class_for_each_device(power_supply_class, NULL, &di->bdata_ps, get_ext_supplier_data); }
int power_supply_is_system_supplied(void) { int error; error = class_for_each_device(power_supply_class, NULL, NULL, __power_supply_is_system_supplied); return error; }
int power_supply_am_i_supplied(struct power_supply *psy) { int error; error = class_for_each_device(power_supply_class, NULL, psy, __power_supply_am_i_supplied); dev_dbg(psy->dev, "%s %d\n", __func__, error); return error; }
// POWER_SUPPLY_TYPE_BATTERY --- discharge // POWER_SUPPLY_TYPE_USB --- usb_charging // POWER_SUPPLY_TYPE_MAINS --- AC_charging int rk_get_system_battery_status(void) { class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_status); if (ac_status == POWER_SUPPLY_TYPE_MAINS) { return POWER_SUPPLY_TYPE_MAINS; } else if (usb_status == POWER_SUPPLY_TYPE_USB) { return POWER_SUPPLY_TYPE_USB; } return POWER_SUPPLY_TYPE_BATTERY; }
static void power_supply_changed_work(struct work_struct *work) { struct power_supply *psy = container_of(work, struct power_supply, changed_work); dev_dbg(psy->dev, "%s\n", __FUNCTION__); class_for_each_device(power_supply_class, psy, __power_supply_changed_work); power_supply_update_leds(psy); kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); }
void mot_system_power_off(void) { /* If there's external power, let's restart instead ... except for the case when phone was powered on with factory cable and thus has to stay powered off after Turn-Off TCMD INKVSSW-994 */ #ifdef CONFIG_REGULATOR_CPCAP #ifdef CONFIG_BOOTINFO if (cpcap_misc_is_ext_power() && !((bi_powerup_reason() & PWRUP_FACTORY_CABLE) && (bi_powerup_reason() != PWRUP_INVALID)) ) #else if (cpcap_misc_is_ext_power()) #endif { printk("External power detected- rebooting\r\n"); cpcap_misc_clear_power_handoff_info(); tegra_machine_restart(0,""); while(1); } #endif printk(KERN_ERR "%s(): Powering down system\n", __func__); /* Disable RTC alarms to prevent unwanted powerups */ class_for_each_device(rtc_class, NULL, NULL, disable_rtc_alarms); #ifdef CONFIG_REGULATOR_CPCAP /* Disable powercut detection before power off */ cpcap_disable_powercut(); #endif /* We need to set the WDI bit low to power down normally */ if (HWREV_TYPE_IS_PORTABLE(system_rev) && HWREV_REV(system_rev) >= HWREV_REV_1 && HWREV_REV(system_rev) <= HWREV_REV_1C ) { /* Olympus P1 */ gpio_request(TEGRA_GPIO_PT4, "P1 WDI"); gpio_direction_output(TEGRA_GPIO_PT4, 1); gpio_set_value(TEGRA_GPIO_PT4, 0); } else { /* Olympus Mortable, P0, P2 and later */ gpio_request(TEGRA_GPIO_PV7, "P2 WDI"); gpio_direction_output(TEGRA_GPIO_PV7, 1); gpio_set_value(TEGRA_GPIO_PV7, 0); } mdelay(500); printk("Power-off failed (Factory cable inserted?), rebooting\r\n"); tegra_machine_restart(0,""); }
static void update_power_supply_attribute(struct power_supply_attribute * instance) { struct charging_query query={instance->check_type,instance->power_supply_type ,instance->property_enum,{0}} ; if (class_for_each_device(power_supply_class,NULL,&query,_power_supply_get_property)) { instance->last_value= query.value.intval; if (instance->average) { if(instance->property_enum == POWER_SUPPLY_PROP_VOLTAGE_MIN) update_average(instance->average ,instance->last_value / 1000) ; else update_average(instance->average ,instance->last_value) ; } } }
static void find_main_battery(void) { struct find_bat_param bp; int error; memset(&bp, 0, sizeof(struct find_bat_param)); main_battery = NULL; bp.main = main_battery; error = class_for_each_device(power_supply_class, NULL, &bp, __find_main_battery); if (error) { main_battery = bp.main; return; } if ((bp.max_energy_bat && bp.max_charge_bat) && (bp.max_energy_bat != bp.max_charge_bat)) { /* try guess battery with more capacity */ if (!PSY_PROP(bp.max_charge_bat, VOLTAGE_MAX_DESIGN, &bp.full)) { if (bp.max_energy > bp.max_charge * bp.full.intval) main_battery = bp.max_energy_bat; else main_battery = bp.max_charge_bat; } else if (!PSY_PROP(bp.max_energy_bat, VOLTAGE_MAX_DESIGN, &bp.full)) { if (bp.max_charge > bp.max_energy / bp.full.intval) main_battery = bp.max_charge_bat; else main_battery = bp.max_energy_bat; } else { /* give up, choice any */ main_battery = bp.max_energy_bat; } } else if (bp.max_charge_bat) { main_battery = bp.max_charge_bat; } else if (bp.max_energy_bat) { main_battery = bp.max_energy_bat; } else { /* give up, try the last if any */ main_battery = bp.bat; } }
static void bdata_external_power_changed_work(struct work_struct *work) { struct data_info *di = container_of(work, struct data_info, external_change_work); MUTEX_LOCK(&di->lock); di->notify_changed = 0; di->ovp_changed = 0; class_for_each_device(power_supply_class, NULL, &di->bdata_ps, get_ext_supplier_data); MUTEX_UNLOCK(&di->lock); if (di->notify_changed) msm_platform_notify(di); if (di->ovp_changed) msm_set_ovp(di); }
int rk_get_system_battery_capacity(void) { class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_capacity); return battery_capacity.intval; }
void mot_system_power_off(void) { /* If there's external power, let's restart instead ... except for the case when phone was powered on with factory cable and thus has to stay powered off after Turn-Off TCMD INKVSSW-994 */ if (cpcap_misc_is_ext_power() && !((bi_powerup_reason() & PWRUP_FACTORY_CABLE) && (bi_powerup_reason() != PWRUP_INVALID)) ) { printk("External power detected- rebooting\r\n"); cpcap_misc_clear_power_handoff_info(); tegra_machine_restart(0,""); while(1); } printk(KERN_ERR "%s(): Powering down system\n", __func__); /* Disable RTC alarms to prevent unwanted powerups */ class_for_each_device(rtc_class, NULL, NULL, disable_rtc_alarms); /* Disable powercut detection before power off */ cpcap_disable_powercut(); /* We need to set the WDI bit low to power down normally */ if (machine_is_olympus()) { if (HWREV_TYPE_IS_PORTABLE(system_rev) && HWREV_REV(system_rev) >= HWREV_REV_1 && HWREV_REV(system_rev) <= HWREV_REV_1C ) { /* Olympus P1 */ gpio_request(TEGRA_GPIO_PT4, "P1 WDI"); gpio_direction_output(TEGRA_GPIO_PT4, 1); gpio_set_value(TEGRA_GPIO_PT4, 0); } else { /* Olympus Mortable, P0, P2 and later */ gpio_request(TEGRA_GPIO_PV7, "P2 WDI"); gpio_direction_output(TEGRA_GPIO_PV7, 1); gpio_set_value(TEGRA_GPIO_PV7, 0); } } else if (machine_is_etna()) { if ( HWREV_TYPE_IS_BRASSBOARD(system_rev) && HWREV_REV(system_rev) == HWREV_REV_1 ) { // Etna S1 gpio_request(TEGRA_GPIO_PK4, "S1 WDI"); gpio_direction_output(TEGRA_GPIO_PK4, 1); gpio_set_value(TEGRA_GPIO_PK4, 0); } else { // Etna S2, P1 and later gpio_request(TEGRA_GPIO_PT4, "S2 WDI"); gpio_direction_output(TEGRA_GPIO_PT4, 1); gpio_set_value(TEGRA_GPIO_PT4, 0); /* Etna P1B-P3C has a gate on WDI */ if ( machine_is_etna() && ( HWREV_TYPE_IS_PORTABLE(system_rev) && ( HWREV_REV(system_rev) >= HWREV_REV_1B && HWREV_REV(system_rev) < HWREV_REV_4 ))) cpcap_set_wdigate(0); } } else if (machine_is_tegra_daytona()) { gpio_request(TEGRA_GPIO_PV7, "P2 WDI"); gpio_direction_output(TEGRA_GPIO_PV7, 1); gpio_set_value(TEGRA_GPIO_PV7, 0); } else if (machine_is_sunfire()) { gpio_request(TEGRA_GPIO_PT4, "S2 WDI"); gpio_direction_output(TEGRA_GPIO_PT4, 1); gpio_set_value(TEGRA_GPIO_PT4, 0); cpcap_set_wdigate(0); } else { printk(KERN_ERR "Could not poweroff. Unkown hardware revision: 0x%x\n", system_rev); } mdelay(500); printk("Power-off failed (Factory cable inserted?), rebooting\r\n"); tegra_machine_restart(0,""); }