QList<QAction*> PowerManager::availableActions() { QList<QAction*> ret; QAction * act; // TODO/FIXME: icons act = new QAction(XdgIcon::fromTheme("system-suspend-hibernate"), tr("Hibernate"), this); connect(act, SIGNAL(triggered()), this, SLOT(hibernate())); ret.append(act); act = new QAction(XdgIcon::fromTheme("system-suspend"), tr("Suspend"), this); connect(act, SIGNAL(triggered()), this, SLOT(suspend())); ret.append(act); act = new QAction(XdgIcon::fromTheme("system-reboot"), tr("Reboot"), this); connect(act, SIGNAL(triggered()), this, SLOT(reboot())); ret.append(act); act = new QAction(XdgIcon::fromTheme("system-shutdown"), tr("Shutdown"), this); connect(act, SIGNAL(triggered()), this, SLOT(halt())); ret.append(act); act = new QAction(XdgIcon::fromTheme("system-log-out"), tr("Logout"), this); connect(act, SIGNAL(triggered()), this, SLOT(logout())); ret.append(act); return ret; }
bool SensorProcess::execute() { if(!SCMProcess::execute()) return false; // Tell the scheduler we'll want to sleep 1mS from this point of time. // While the clock is ticking, we'll actually be processing sensors. // What this does is it makes the delay at least 1mS rather than // 1mS + the amount of processing time. hibernate(10); if(!sensors->ReadAndNormalize()) { int errorValue = -(int)sensors->StatusCode(); readings->blue.raw = errorValue; readings->blue.normalized = errorValue; readings->red.raw = errorValue; readings->red.normalized = errorValue; readings->yellow.raw = errorValue; readings->yellow.normalized = errorValue; readings->green.raw = errorValue; readings->green.normalized = errorValue; return true; } // Cache readings readings->blue.raw = sensors->Values[blueIndex]; readings->blue.normalized = sensors->Normalized[blueIndex]; readings->red.raw = sensors->Values[redIndex]; readings->red.normalized = sensors->Normalized[redIndex]; readings->yellow.raw = sensors->Values[yellowIndex]; readings->yellow.normalized = sensors->Normalized[yellowIndex]; readings->green.raw = sensors->Values[greenIndex]; readings->green.normalized = sensors->Normalized[greenIndex]; return true; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { suspend_state_t state; int error; error = pm_autosleep_lock(); if (error) return error; if (pm_autosleep_state() > PM_SUSPEND_ON) { error = -EBUSY; goto out; } state = decode_state(buf, n); if (state < PM_SUSPEND_MAX) error = pm_suspend(state); else if (state == PM_SUSPEND_MAX) error = hibernate(); else error = -EINVAL; out: pm_autosleep_unlock(); return error ? error : n; }
static void try_to_suspend(struct work_struct *work) { unsigned int initial_count, final_count; if (!pm_get_wakeup_count(&initial_count, true)) { #ifdef CONFIG_HTC_POWER_DEBUG pr_info("[P] suspend abort, wakeup event nonzero\n"); htc_print_active_wakeup_sources(); #endif goto out; } mutex_lock(&autosleep_lock); if (!pm_save_wakeup_count(initial_count)) { #ifdef CONFIG_HTC_POWER_DEBUG pr_info("[P] suspend abort, events not matched or being processed\n"); #endif mutex_unlock(&autosleep_lock); goto out; } if (autosleep_state == PM_SUSPEND_ON) { #ifdef CONFIG_HTC_POWER_DEBUG pr_info("[P] suspend abort, autosleep_state is ON\n"); #endif mutex_unlock(&autosleep_lock); return; } if (autosleep_state >= PM_SUSPEND_MAX) hibernate(); else { #ifdef CONFIG_HTC_POWER_DEBUG pr_info("[R] suspend start\n"); #endif pm_suspend(autosleep_state); } mutex_unlock(&autosleep_lock); if (!pm_get_wakeup_count(&final_count, false)) { #ifdef CONFIG_HTC_POWER_DEBUG pr_info("[R] resume end\n"); #endif goto out; } if (final_count == initial_count) { #ifdef CONFIG_HTC_POWER_DEBUG pr_info("[P] wakeup occured for an unknown reason, wait HZ/2\n"); #endif schedule_timeout_uninterruptible(HZ / 2); } #ifdef CONFIG_HTC_POWER_DEBUG pr_info("[R] resume end\n"); #endif out: queue_up_suspend_work(); }
static ssize_t acpi_system_write_sleep(struct file *file, const char __user * buffer, size_t count, loff_t * ppos) { char str[12]; u32 state = 0; int error = 0; if (count > sizeof(str) - 1) goto Done; memset(str, 0, sizeof(str)); if (copy_from_user(str, buffer, count)) return -EFAULT; /* Check for S4 bios request */ if (!strcmp(str, "4b")) { error = acpi_suspend(4); goto Done; } state = simple_strtoul(str, NULL, 0); #ifdef CONFIG_HIBERNATION if (state == 4) { error = hibernate(); goto Done; } #endif error = acpi_suspend(state); Done: return error ? error : count; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND suspend_state_t state = PM_SUSPEND_STANDBY; const char * const *s; #endif char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } if (state < PM_SUSPEND_MAX && *s) error = enter_state(state); #endif Exit: return error ? error : n; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } if (state < PM_SUSPEND_MAX && *s) #ifdef CONFIG_EARLYSUSPEND && CONFIG_HAS_WAKELOCK if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); } #elif defined CONFIG_HAS_WAKELOCK wake_unlock(&main_wake_lock); //Release main lock in the hope of going to sleep if (!has_wake_lock(WAKE_LOCK_SUSPEND)) { wake_timer.data = current; mod_timer(&wake_timer, jiffies + HZ * 5); //To prevent us from freezing indefinitely set_freeze_flag(current); try_to_freeze(); del_timer(&wake_timer); } wake_lock(&main_wake_lock); //Re-grab the main lock so that we do not go into sleep again #else error = enter_state(state); #endif #endif Exit: return error ? error : n; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_MIN; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } #ifdef CONFIG_FAST_BOOT if (len == 4 && !strncmp(buf, "dmem", len)) { pr_info("%s: fake shut down!!!\n", __func__); fake_shut_down = true; state = PM_SUSPEND_MEM; } #endif if (state < PM_SUSPEND_MAX && *s) { #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); } #ifdef CONFIG_FAST_BOOT if (fake_shut_down) wakelock_force_suspend(); #endif #else error = enter_state(state); #endif } #endif Exit: return error ? error : n; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { do_hibernation = 1; //B090162 do_hibernation_codec = 1; //B090162 //sensor driver to early suspend #ifdef CONFIG_TCC_SENSOR_DRV tcc_sensor_early_suspend(); #endif error = hibernate(); #ifdef CONFIG_TCC_SENSOR_DRV tcc_sensor_late_resume(); #endif goto Exit; } else if (len == 5 && !strncmp(buf, "reset", len)) { tcc_usb_notification(); } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } if (state < PM_SUSPEND_MAX && *s) #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); } #else error = enter_state(state); #endif #endif Exit: return error ? error : n; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #if defined(CONFIG_MP_MSTAR_STR_BASE) // for mstar str, we skip wakelock // and earlysuspend/lateresume to speedup suspend if (len == 4 && !strncmp(buf, "mstr", len)) { state = PM_SUSPEND_MEM; pm_is_mstar_str = 1; error = enter_state(state); pm_is_mstar_str = 0; goto Exit; } #endif #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } if (state < PM_SUSPEND_MAX && *s) #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); } #else error = enter_state(state); #endif #endif Exit: return error ? error : n; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { suspend_state_t state; struct timespec ts_entry, ts_exit; u64 elapsed_msecs64; u32 elapsed_msecs32; int error; error = pm_autosleep_lock(); if (error) return error; if (pm_autosleep_state() > PM_SUSPEND_ON) { error = -EBUSY; goto out; } state = decode_state(buf, n); if (state < PM_SUSPEND_MAX) { /* * We want to prevent system from frequent periodic wake-ups * when sleeping time is less or equival certain interval. * It's done in order to save power in certain cases, one of * the examples is GPS tracking, but not only. */ getnstimeofday(&ts_entry); error = pm_suspend(state); getnstimeofday(&ts_exit); elapsed_msecs64 = timespec_to_ns(&ts_exit) - timespec_to_ns(&ts_entry); do_div(elapsed_msecs64, NSEC_PER_MSEC); elapsed_msecs32 = elapsed_msecs64; if (elapsed_msecs32 <= SBO_SLEEP_MSEC) { if (suspend_short_count == SBO_CNT) suspend_backoff(); else suspend_short_count++; } else { suspend_short_count = 0; } } else if (state == PM_SUSPEND_MAX) error = hibernate(); else error = -EINVAL; out: pm_autosleep_unlock(); return error ? error : n; }
static void try_to_suspend(struct work_struct *work) { unsigned int initial_count, final_count; int error = 0; if (!pm_get_wakeup_count(&initial_count, true)) goto out; mutex_lock(&autosleep_lock); if (!pm_save_wakeup_count(initial_count) || system_state != SYSTEM_RUNNING) { mutex_unlock(&autosleep_lock); goto out; } if (autosleep_state == PM_SUSPEND_ON) { mutex_unlock(&autosleep_lock); return; } if (autosleep_state >= PM_SUSPEND_MAX) hibernate(); else error = pm_suspend(autosleep_state); mutex_unlock(&autosleep_lock); #ifdef CONFIG_SEC_PM if (error) goto out; #endif if (!pm_get_wakeup_count(&final_count, false)) goto out; /* * If the wakeup occured for an unknown reason, wait to prevent the * system from trying to suspend and waking up in a tight loop. */ if (final_count == initial_count) schedule_timeout_uninterruptible(HZ / 2); out: #ifdef CONFIG_SEC_PM if (error) { pr_info("PM: suspend returned(%d)\n", error); schedule_timeout_uninterruptible(HZ / 2); } #endif queue_up_suspend_work(); }
/* NOTICE: this function MUST be called under autosleep_lock (in autosleep.c) is locked!! */ int mtk_hibernate_via_autosleep(suspend_state_t *autosleep_state) { int err = 0; hib_log("entering hibernation state(%d)\n", *autosleep_state); err = hibernate(); if (err) { hib_warn ("@@@@@@@@@@@@@@@@@@@@@@@@@\n@@_Hibernation Failed_@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@\n"); /* enhanced error handling */ #ifdef CONFIG_TOI_ENHANCE if (toi_hibernate_fatalerror()) { kernel_power_off(); kernel_halt(); BUG(); } #endif if (hibernation_failed_action == HIB_FAILED_TO_SHUTDOWN) { kernel_power_off(); kernel_halt(); BUG(); } else if (hibernation_failed_action == HIB_FAILED_TO_S2RAM) { hib_warn("hibernation failed: so changing state(%d->%d) err(%d)\n", *autosleep_state, PM_SUSPEND_MEM, err); if (++hib_failed_cnt >= MAX_HIB_FAILED_CNT) hibernation_failed_action = HIB_FAILED_TO_SHUTDOWN; hibernate_recover(); *autosleep_state = PM_SUSPEND_MEM; pm_wake_lock("IPOD_HIB_WAKELOCK"); system_is_hibernating = false; } else { hib_err("@@@@@@@@@@@@@@@@@@\n@_FATAL ERROR !!!_\n@@@@@@@@@@@@@@@@@@@\n"); BUG(); } } else { if (hybrid_sleep_mode()) { hib_warn("hybrid sleep mode so changing state(%d->%d)\n", *autosleep_state, PM_SUSPEND_MEM); *autosleep_state = PM_SUSPEND_MEM; /* continue suspend to ram if hybrid sleep mode */ } else { hib_warn("hibernation succeeded: so changing state(%d->%d) err(%d)\n", *autosleep_state, PM_SUSPEND_ON, err); hibernate_restore(); *autosleep_state = PM_SUSPEND_ON; /* if this is not set, it will recursively do hibernating!! */ } hib_failed_cnt = 0; pm_wake_lock("IPOD_HIB_WAKELOCK"); system_is_hibernating = false; } return err; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { printk(KERN_ERR "entering hibernate"); error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } printk(KERN_ERR "entering sleep state = %d\n", state); if (state < PM_SUSPEND_MAX && *s) { #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); } else { printk(KERN_ERR "not valid state with state = %d", state); } #else error = enter_state(state); #endif } #endif Exit: return error ? error : n; }
int warp_boot(int saveno) { int ret; int (*hibernate) (void); if ((ret = warp_checkboot(saveno)) != 0) return ret; warp_fix(); hibernate = (void *)(warp_drv_addr + WARP_HEADER_HIBERNATE); ret = hibernate(); printf("Warp!! error can not boot %d\n", ret); return ret; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; if (factory_mode == 0) { p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) { #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); break; } #else error = pm_suspend(state); #endif } } #endif Exit: return error ? error : n; } else { return 0; } }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } if (state < PM_SUSPEND_MAX && *s) { /*LGE_CHANGE : [email protected] fix bug in suspend statics update*/ #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); } #else error = enter_state(state); if (error) { suspend_stats.fail++; dpm_save_failed_errno(error); } else suspend_stats.success++; #endif } #endif Exit: return error ? error : n; }
int main() { unsigned int i=0; unsigned int num_pages; // Initial state: flash is insactive, and the big guy just pulled down the // MISO pin. last_f = 1; if (READ_MISO_PIN()) last_b = 0; else last_b = 1; if (last_b == 0) { CLR_BIG_GUY_RESET_PIN(); MAKE_BIG_GUY_RESET_OUTPUT(); spi_init(); CLR_SCK_PIN(); MAKE_BIG_GUY_RESET_OUTPUT(); pulse_flash_cs(); wait_ms(20); // read the program legth num_pages = read_params(); //num_pages=575; num_pages += 0xff; num_pages >>= 8; error_code(num_pages); if (program_enable()) { program_erase(); } else { error_code(0x10); hibernate(); } // wait a little bit wait_ms(120); pulse_flash_cs(); // pulse the reset pin //wait_ms(20); // upload the program if (program_enable()) { for (i=0; i < num_pages; i++) { program_page(i); wait_ms(56); } } else { error_code(0x20); } }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; pr_info("%s\n",__func__); p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } if (state < PM_SUSPEND_MAX && *s) #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; pr_info("%s invoking request_suspend_state - state = %d\n",__func__,state); request_suspend_state(state); } #else error = enter_state(state); #endif #endif Exit: return error ? error : n; }
/* called by echo "disk" > /sys/power/state */ int mtk_hibernate(void) { int err = 0; hib_log("entering hibernation\n"); err = hibernate(); if (err) { hib_warn ("@@@@@@@@@@@@@@@@@@@@@@@@@\n@@_Hibernation Failed_@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@\n"); /* enhanced error handling */ #ifdef CONFIG_TOI_ENHANCE if (toi_hibernate_fatalerror()) { kernel_power_off(); kernel_halt(); BUG(); } #endif if (hibernation_failed_action == HIB_FAILED_TO_SHUTDOWN) { kernel_power_off(); kernel_halt(); BUG(); } else if (hibernation_failed_action == HIB_FAILED_TO_S2RAM) { hib_warn("hibernation failed, suspend to ram instead!\n"); if (++hib_failed_cnt >= MAX_HIB_FAILED_CNT) hibernation_failed_action = HIB_FAILED_TO_SHUTDOWN; hibernate_recover(); pm_wake_lock("IPOD_HIB_WAKELOCK"); system_is_hibernating = false; } else { hib_err("@@@@@@@@@@@@@@@@@@\n@_FATAL ERROR !!!_\n@@@@@@@@@@@@@@@@@@@\n"); BUG(); } } else { if (!hybrid_sleep_mode()) { hibernate_restore(); } hib_failed_cnt = 0; pm_wake_lock("IPOD_HIB_WAKELOCK"); system_is_hibernating = false; } return err; }
// NOTICE: this function MUST be called under autosleep_lock (in autosleep.c) is locked!! int mtk_hibernate_via_autosleep(suspend_state_t *autosleep_state) { int err = 0; hib_log("entering hibernation state(%d)\n", *autosleep_state); err = hibernate(); if (err) { hib_warn("@@@@@@@@@@@@@@@@@@@@@@@@@\n@@_Hibernation Failed_@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@\n"); if (hibernation_failed_action == HIB_FAILED_TO_SHUTDOWN) { kernel_power_off(); kernel_halt(); BUG(); } else if (hibernation_failed_action == HIB_FAILED_TO_S2RAM) { hib_warn("hibernation failed: so changing state(%d->%d) err(%d)\n", *autosleep_state, PM_SUSPEND_MEM, err); if (++hib_failed_cnt >= MAX_HIB_FAILED_CNT) hibernation_failed_action = HIB_FAILED_TO_SHUTDOWN; // userspace recover if hibernation failed usr_recover_func(NULL); *autosleep_state = PM_SUSPEND_MEM; system_is_hibernating = false; } else { hib_err("@@@@@@@@@@@@@@@@@@\n@_FATAL ERROR !!!_\n@@@@@@@@@@@@@@@@@@@\n"); BUG(); } } else { if (hybrid_sleep_mode()) { hib_warn("hybrid sleep mode so changing state(%d->%d)\n", *autosleep_state, PM_SUSPEND_MEM); *autosleep_state = PM_SUSPEND_MEM; //continue suspend to ram if hybrid sleep mode } else { hib_warn("hibernation succeeded: so changing state(%d->%d) err(%d) \n", *autosleep_state, PM_SUSPEND_ON, err); hib_warn("start trigger ipod\n"); //usr_bootanim_start(NULL); //schedule_delayed_work(&usr_restore_work, HZ*0.05); usr_restore_func(NULL); *autosleep_state = PM_SUSPEND_ON; // if this is not set, it will recursively do hibernating!! } hib_failed_cnt = 0; pm_wake_lock("IPOD_HIB_WAKELOCK"); system_is_hibernating = false; } return err; }
static void try_to_suspend(struct work_struct *work) { unsigned int initial_count, final_count; if (!pm_get_wakeup_count(&initial_count, true)) goto out; mutex_lock(&autosleep_lock); if (!pm_save_wakeup_count(initial_count)) { mutex_unlock(&autosleep_lock); goto out; } if (autosleep_state == PM_SUSPEND_ON) { mutex_unlock(&autosleep_lock); return; } if (autosleep_state >= PM_SUSPEND_MAX) hibernate(); else pm_suspend(autosleep_state); mutex_unlock(&autosleep_lock); if (!pm_get_wakeup_count(&final_count, false)) goto out; /* * If the wakeup occured for an unknown reason, wait to prevent the * system from trying to suspend and waking up in a tight loop. */ if (final_count == initial_count) schedule_timeout_uninterruptible(HZ / 2); out: queue_up_suspend_work(); }
// called by echo "disk" > /sys/power/state int mtk_hibernate(void) { int err = 0; hib_log("entering hibernation\n"); err = hibernate(); if (err) { hib_warn("@@@@@@@@@@@@@@@@@@@@@@@@@\n@@_Hibernation Failed_@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@\n"); if (hibernation_failed_action == HIB_FAILED_TO_SHUTDOWN) { kernel_power_off(); kernel_halt(); BUG(); } else if (hibernation_failed_action == HIB_FAILED_TO_S2RAM) { hib_warn("hibernation failed, suspend to ram instead!\n"); if (++hib_failed_cnt >= MAX_HIB_FAILED_CNT) hibernation_failed_action = HIB_FAILED_TO_SHUTDOWN; // userspace recover if hibernation failed usr_recover_func(NULL); system_is_hibernating = false; } else { hib_err("@@@@@@@@@@@@@@@@@@\n@_FATAL ERROR !!!_\n@@@@@@@@@@@@@@@@@@@\n"); BUG(); } } else { if (!hybrid_sleep_mode()) { hib_warn("start trigger ipod\n"); //schedule_delayed_work(&usr_bootanim_start_work, HZ*1.0); //schedule_delayed_work(&usr_restore_work, HZ*0.05); //usr_bootanim_start(NULL); usr_restore_func(NULL); } hib_failed_cnt = 0; pm_wake_lock("IPOD_HIB_WAKELOCK"); system_is_hibernating = false; } return err; }
Dialog::Dialog(QWidget *parent) : QDialog(parent, Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint), ui(new Ui::Dialog) { ui->setupUi(this); connect(ui->hibernateButton, SIGNAL(clicked()), this, SLOT(hibernate())); ui->hibernateButton->setVisible(mPower.canAction(RazorPower::PowerHibernate)); connect(ui->logoutButton, SIGNAL(clicked()), this, SLOT(logout())); ui->logoutButton->setVisible(mPower.canAction(RazorPower::PowerLogout)); connect(ui->rebootButton, SIGNAL(clicked()), this, SLOT(reboot())); ui->rebootButton->setVisible(mPower.canAction(RazorPower::PowerReboot)); connect(ui->shutdownButton, SIGNAL(clicked()), this, SLOT(shutdown())); ui->shutdownButton->setVisible(mPower.canAction(RazorPower::PowerShutdown)); connect(ui->suspendButton, SIGNAL(clicked()), this, SLOT(suspend())); ui->suspendButton->setVisible(mPower.canAction(RazorPower::PowerSuspend)); connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(close())); }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif char *p; int len; int error = -EINVAL; #ifdef CONFIG_PM_DEEPSLEEP char temp[20]; #endif p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_PM_DEEPSLEEP if (sizeof(temp) - 1 < len) { len = sizeof(temp)-1; printk(KERN_ERR "pm states is invalid\n"); } memset(temp, 0, sizeof(temp)); strncpy(temp, buf, len); if (len == 9 && !strncmp(temp, "deepsleep", len)) { s = &pm_states[PM_SUSPEND_MEM]; if (strlen(*s) > sizeof(temp) - 1) { printk(KERN_ERR "pm states overflow\n"); } else { memset(temp, 0, sizeof(temp)); strncpy(temp, *s, strlen(*s)); pm_deepsleep_enabled = 1; } } else if (pm_deepsleep_enabled == 1 && len == 2 && !strncmp(temp, "on", len)) { pm_deepsleep_enabled = 0; } #endif #ifdef CONFIG_SUSPEND #ifdef CONFIG_PM_DEEPSLEEP for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(temp, *s, len)) break; } #else for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } #endif if (state < PM_SUSPEND_MAX && *s) { #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { error = 0; request_suspend_state(state); } #else error = enter_state(state); #endif } #endif Exit: return error ? error : n; }
static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n) { #ifdef CONFIG_SUSPEND #ifdef CONFIG_EARLYSUSPEND suspend_state_t state = PM_SUSPEND_ON; #else suspend_state_t state = PM_SUSPEND_STANDBY; #endif const char * const *s; #endif /* CONFIG_SUSPEND */ char *p; int len; int error = -EINVAL; p = memchr(buf, '\n', n); len = p ? p - buf : n; /* First, check if we are requested to hibernate */ if (len == 4 && !strncmp(buf, "disk", len)) { error = hibernate(); goto Exit; } #ifdef CONFIG_SUSPEND for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) { if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) break; } if (state < PM_SUSPEND_MAX && *s) { printk(KERN_ERR "%s: state:%d (%s)\n", __func__, state, *s); #ifdef CONFIG_EARLYSUSPEND if (state == PM_SUSPEND_ON || valid_state(state)) { if(state == PM_SUSPEND_ON) { #ifdef FEATURE_FTM_SLEEP if (ftm_sleep == 1) { pr_info("%s: wake lock for FTM\n", __func__); ftm_sleep = 0; wake_lock_timeout(&ftm_wake_lock, 60 * HZ); if (ftm_enable_usb_sw) ftm_enable_usb_sw(1); } #endif /* FEATURE_FTM_SLEEP */ global_state = PM_SUSPEND_ON; } else { #ifdef FEATURE_FTM_SLEEP if (ftm_sleep == 1) { // when ftm sleep cmd if (ftm_enable_usb_sw) ftm_enable_usb_sw(0); } #endif /* FEATURE_FTM_SLEEP */ global_state = PM_SUSPEND_MEM; } error = 0; request_suspend_state(state); #ifdef FEATURE_FTM_SLEEP if (ftm_sleep && global_state == PM_SUSPEND_MEM) { wakelock_force_suspend(); } #endif /* FEATURE_FTM_SLEEP */ } #else error = enter_state(state); #endif } #endif /* CONFIG_SUSPEND */ Exit: return error ? error : n; }
void AVisitor<C>::walk(Y& obj) { hibernate(*this, obj, static_cast<const unsigned int>(0)); }
/* * Reboot system call: for obvious reasons only root may call it, * and even root needs to set up some magic numbers in the registers * so that some mistake won't make this reboot the whole machine. * You can also set the meaning of the ctrl-alt-del-key here. * * reboot doesn't sync: do that yourself before calling this. */ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user * arg) { char buffer[256]; /* We only trust the superuser with rebooting the system. */ if (!capable(CAP_SYS_BOOT)) return -EPERM; /* For safety, we require "magic" arguments. */ if (magic1 != LINUX_REBOOT_MAGIC1 || (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A && magic2 != LINUX_REBOOT_MAGIC2B && magic2 != LINUX_REBOOT_MAGIC2C)) return -EINVAL; /* Instead of trying to make the power_off code look like * halt when pm_power_off is not set do it the easy way. */ if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off) cmd = LINUX_REBOOT_CMD_HALT; lock_kernel(); switch (cmd) { case LINUX_REBOOT_CMD_RESTART: kernel_restart(NULL); break; case LINUX_REBOOT_CMD_CAD_ON: C_A_D = 1; break; case LINUX_REBOOT_CMD_CAD_OFF: C_A_D = 0; break; case LINUX_REBOOT_CMD_HALT: kernel_halt(); unlock_kernel(); do_exit(0); break; case LINUX_REBOOT_CMD_POWER_OFF: kernel_power_off(); unlock_kernel(); do_exit(0); break; case LINUX_REBOOT_CMD_RESTART2: if (strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1) < 0) { unlock_kernel(); return -EFAULT; } buffer[sizeof(buffer) - 1] = '\0'; kernel_restart(buffer); break; case LINUX_REBOOT_CMD_KEXEC: kernel_kexec(); unlock_kernel(); return -EINVAL; #ifdef CONFIG_HIBERNATION case LINUX_REBOOT_CMD_SW_SUSPEND: { int ret = hibernate(); unlock_kernel(); return ret; } #endif default: unlock_kernel(); return -EINVAL; } unlock_kernel(); return 0; }
/* * Reboot system call: for obvious reasons only root may call it, * and even root needs to set up some magic numbers in the registers * so that some mistake won't make this reboot the whole machine. * You can also set the meaning of the ctrl-alt-del-key here. * * reboot doesn't sync: do that yourself before calling this. */ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, void __user *, arg) { struct pid_namespace *pid_ns = task_active_pid_ns(current); char buffer[256]; int ret = 0; /* We only trust the superuser with rebooting the system. */ if (!ns_capable(pid_ns->user_ns, CAP_SYS_BOOT)) return -EPERM; /* For safety, we require "magic" arguments. */ if (magic1 != LINUX_REBOOT_MAGIC1 || (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A && magic2 != LINUX_REBOOT_MAGIC2B && magic2 != LINUX_REBOOT_MAGIC2C)) return -EINVAL; /* * If pid namespaces are enabled and the current task is in a child * pid_namespace, the command is handled by reboot_pid_ns() which will * call do_exit(). */ ret = reboot_pid_ns(pid_ns, cmd); if (ret) return ret; /* Instead of trying to make the power_off code look like * halt when pm_power_off is not set do it the easy way. */ if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off) cmd = LINUX_REBOOT_CMD_HALT; mutex_lock(&reboot_mutex); switch (cmd) { case LINUX_REBOOT_CMD_RESTART: kernel_restart(NULL); break; case LINUX_REBOOT_CMD_CAD_ON: C_A_D = 1; break; case LINUX_REBOOT_CMD_CAD_OFF: C_A_D = 0; break; case LINUX_REBOOT_CMD_HALT: kernel_halt(); do_exit(0); panic("cannot halt"); case LINUX_REBOOT_CMD_POWER_OFF: kernel_power_off(); do_exit(0); break; case LINUX_REBOOT_CMD_RESTART2: ret = strncpy_from_user(&buffer[0], arg, sizeof(buffer) - 1); if (ret < 0) { ret = -EFAULT; break; } buffer[sizeof(buffer) - 1] = '\0'; kernel_restart(buffer); break; #ifdef CONFIG_KEXEC_CORE case LINUX_REBOOT_CMD_KEXEC: ret = kernel_kexec(); break; #endif #ifdef CONFIG_HIBERNATION case LINUX_REBOOT_CMD_SW_SUSPEND: ret = hibernate(); break; #endif default: ret = -EINVAL; break; } mutex_unlock(&reboot_mutex); return ret; }
int main(int argc, char *argv[]) { const char *fname = apmdev; int ctl_fd, sock_fd, ch, suspends, standbys, resumes; int statonly = 0; int powerstatus = 0, powerbak = 0, powerchange = 0; int noacsleep = 0; struct timespec ts = {TIMO, 0}, sts = {0, 0}; struct apm_power_info pinfo; time_t apmtimeout = 0; const char *sockname = sockfile; int kq, nchanges; struct kevent ev[2]; int ncpu_mib[2] = { CTL_HW, HW_NCPU }; int ncpu; size_t ncpu_sz = sizeof(ncpu); while ((ch = getopt(argc, argv, "aACdHLsf:t:S:")) != -1) switch(ch) { case 'a': noacsleep = 1; break; case 'd': debug = 1; break; case 'f': fname = optarg; break; case 'S': sockname = optarg; break; case 't': ts.tv_sec = strtoul(optarg, NULL, 0); if (ts.tv_sec == 0) usage(); break; case 's': /* status only */ statonly = 1; break; case 'A': if (doperf != PERF_NONE) usage(); doperf = PERF_AUTO; break; case 'C': if (doperf != PERF_NONE) usage(); doperf = PERF_COOL; break; case 'L': if (doperf != PERF_NONE) usage(); doperf = PERF_MANUAL; setperf(PERFMIN); break; case 'H': if (doperf != PERF_NONE) usage(); doperf = PERF_MANUAL; setperf(PERFMAX); break; case '?': default: usage(); } argc -= optind; argv += optind; if (argc != 0) usage(); if (doperf == PERF_NONE) doperf = PERF_MANUAL; if (debug) openlog(__progname, LOG_CONS, LOG_LOCAL1); else { if (daemon(0, 0) < 0) error("failed to daemonize", NULL); openlog(__progname, LOG_CONS, LOG_DAEMON); setlogmask(LOG_UPTO(LOG_NOTICE)); } (void) signal(SIGTERM, sigexit); (void) signal(SIGHUP, sigexit); (void) signal(SIGINT, sigexit); if ((ctl_fd = open(fname, O_RDWR)) == -1) { if (errno != ENXIO && errno != ENOENT) error("cannot open device file `%s'", fname); } else if (fcntl(ctl_fd, F_SETFD, FD_CLOEXEC) == -1) error("cannot set close-on-exec for `%s'", fname); sock_fd = bind_socket(sockname); if (fcntl(sock_fd, F_SETFD, FD_CLOEXEC) == -1) error("cannot set close-on-exec for the socket", NULL); power_status(ctl_fd, 1, &pinfo); if (statonly) exit(0); set_driver_messages(ctl_fd, APM_PRINT_OFF); kq = kqueue(); if (kq <= 0) error("kqueue", NULL); EV_SET(&ev[0], sock_fd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, NULL); if (ctl_fd == -1) nchanges = 1; else { EV_SET(&ev[1], ctl_fd, EVFILT_READ, EV_ADD | EV_ENABLE | EV_CLEAR, 0, 0, NULL); nchanges = 2; } if (kevent(kq, ev, nchanges, NULL, 0, &sts) < 0) error("kevent", NULL); if (sysctl(ncpu_mib, 2, &ncpu, &ncpu_sz, NULL, 0) < 0) error("cannot read hw.ncpu", NULL); if (doperf == PERF_AUTO || doperf == PERF_COOL) { setperf(0); setperf(100); } for (;;) { int rv; sts = ts; if (doperf == PERF_AUTO || doperf == PERF_COOL) { sts.tv_sec = 1; perf_status(&pinfo, ncpu); } apmtimeout += sts.tv_sec; if ((rv = kevent(kq, NULL, 0, ev, 1, &sts)) < 0) break; if (apmtimeout >= ts.tv_sec) { apmtimeout = 0; /* wakeup for timeout: take status */ powerbak = power_status(ctl_fd, 0, &pinfo); if (powerstatus != powerbak) { powerstatus = powerbak; powerchange = 1; } } if (!rv) continue; if (ev->ident == ctl_fd) { suspends = standbys = resumes = 0; syslog(LOG_DEBUG, "apmevent %04x index %d", (int)APM_EVENT_TYPE(ev->data), (int)APM_EVENT_INDEX(ev->data)); switch (APM_EVENT_TYPE(ev->data)) { case APM_SUSPEND_REQ: case APM_USER_SUSPEND_REQ: case APM_CRIT_SUSPEND_REQ: case APM_BATTERY_LOW: suspends++; break; case APM_USER_STANDBY_REQ: case APM_STANDBY_REQ: standbys++; break; #if 0 case APM_CANCEL: suspends = standbys = 0; break; #endif case APM_NORMAL_RESUME: case APM_CRIT_RESUME: case APM_SYS_STANDBY_RESUME: powerbak = power_status(ctl_fd, 0, &pinfo); if (powerstatus != powerbak) { powerstatus = powerbak; powerchange = 1; } resumes++; break; case APM_POWER_CHANGE: powerbak = power_status(ctl_fd, 0, &pinfo); if (powerstatus != powerbak) { powerstatus = powerbak; powerchange = 1; } break; default: ; } if ((standbys || suspends) && noacsleep && power_status(ctl_fd, 0, &pinfo)) syslog(LOG_DEBUG, "no! sleep! till brooklyn!"); else if (suspends) suspend(ctl_fd); else if (standbys) stand_by(ctl_fd); else if (resumes) { do_etc_file(_PATH_APM_ETC_RESUME); syslog(LOG_NOTICE, "system resumed from sleep"); } if (powerchange) { if (powerstatus) do_etc_file(_PATH_APM_ETC_POWERUP); else do_etc_file(_PATH_APM_ETC_POWERDOWN); powerchange = 0; } } else if (ev->ident == sock_fd) switch (handle_client(sock_fd, ctl_fd)) { case NORMAL: break; case SUSPENDING: suspend(ctl_fd); break; case STANDING_BY: stand_by(ctl_fd); break; case HIBERNATING: hibernate(ctl_fd); break; } } error("kevent loop", NULL); return 1; }