/* * Set the sleep time for suspend. 0 means infinite sleep time. */ void msm_pm_set_shtimer_sleep_time(int64_t max_sleep_time_ns) { unsigned long flags; KDEBUG_FUNC(); local_irq_save(flags); msm_pm_max_sleep_time = (uint32_t)msm_pm_convert_and_cap_time( max_sleep_time_ns, msm_pm_max_sleep_time); MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND, KERN_INFO, "%s(): Requested %lld ns Giving %u sclk ticks\n", __func__, max_sleep_time_ns, msm_pm_max_sleep_time); local_irq_restore(flags); }
/* * Set the sleep time for suspend. 0 means infinite sleep time. */ void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns) { unsigned long flags; KDEBUG_FUNC(); local_irq_save(flags); if (max_sleep_time_ns == 0) { msm_pm_max_sleep_time = 0; } else { msm_pm_max_sleep_time = (uint32_t)msm_pm_convert_and_cap_time( max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT); if (msm_pm_max_sleep_time == 0) msm_pm_max_sleep_time = 1; } MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND, KERN_INFO, "%s(): Requested %lld ns Giving %u sclk ticks\n", __func__, max_sleep_time_ns, msm_pm_max_sleep_time); local_irq_restore(flags); }
/* * Set the sleep time for suspend. 0 means infinite sleep time. */ void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns) { unsigned long flags; local_irq_save(flags); if (max_sleep_time_ns == 0) { msm_pm_max_sleep_time = 0; } else { msm_pm_max_sleep_time = (uint32_t)msm_pm_convert_and_cap_time( max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT); if (msm_pm_max_sleep_time == 0) msm_pm_max_sleep_time = 1; } MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND, KERN_INFO, "%s(): Requested %lld ns Giving %u sclk ticks\n", __func__, max_sleep_time_ns, msm_pm_max_sleep_time); local_irq_restore(flags); /*Kernel-SC-cpuFreq-none-sync-01-[*/ /*#ifdef CONFIG_SET_MAX_CPUFREQ_BEFORE_SUSPEND { int max_freq = 800000; if (cpu_is_msm7x27aa()) { max_freq = 1008000; } printk(KERN_INFO "%s(): ready to set %d clock rate\n", __func__ , max_freq); if (acpuclk_set_rate(smp_processor_id(), max_freq, SETRATE_CPUFREQ) < 0) { printk(KERN_ERR "%s(): failed to set %d clock rate\n", __func__, max_freq); } } #endif*/ /*Kernel-SC-cpuFreq-none-sync-01-]*/ }
/* * Put CPU in low power mode. */ void arch_idle(void) { bool allow[MSM_PM_SLEEP_MODE_NR]; uint32_t sleep_limit = SLEEP_LIMIT_NONE; int64_t timer_expiration; int latency_qos; int ret; int i; unsigned int cpu; int64_t t1; static DEFINE_PER_CPU(int64_t, t2); int exit_stat; if (!atomic_read(&msm_pm_init_done)) return; cpu = smp_processor_id(); latency_qos = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); /* get the next timer expiration */ timer_expiration = ktime_to_ns(tick_nohz_get_sleep_length()); t1 = ktime_to_ns(ktime_get()); msm_pm_add_stat(MSM_PM_STAT_NOT_IDLE, t1 - __get_cpu_var(t2)); msm_pm_add_stat(MSM_PM_STAT_REQUESTED_IDLE, timer_expiration); exit_stat = MSM_PM_STAT_IDLE_SPIN; for (i = 0; i < ARRAY_SIZE(allow); i++) allow[i] = true; if (num_online_cpus() > 1 || (timer_expiration < msm_pm_idle_sleep_min_time) || !msm_pm_irq_extns->idle_sleep_allowed()) { allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = false; allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] = false; } for (i = 0; i < ARRAY_SIZE(allow); i++) { struct msm_pm_platform_data *mode = &msm_pm_modes[MSM_PM_MODE(cpu, i)]; if (!mode->idle_supported || !mode->idle_enabled || mode->latency >= latency_qos || mode->residency * 1000ULL >= timer_expiration) allow[i] = false; } if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] || allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN]) { uint32_t wait_us = CONFIG_MSM_IDLE_WAIT_ON_MODEM; while (msm_pm_modem_busy() && wait_us) { if (wait_us > 100) { udelay(100); wait_us -= 100; } else { udelay(wait_us); wait_us = 0; } } if (msm_pm_modem_busy()) { allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = false; allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] = false; } } MSM_PM_DPRINTK(MSM_PM_DEBUG_IDLE, KERN_INFO, "%s(): latency qos %d, next timer %lld, sleep limit %u\n", __func__, latency_qos, timer_expiration, sleep_limit); for (i = 0; i < ARRAY_SIZE(allow); i++) MSM_PM_DPRINTK(MSM_PM_DEBUG_IDLE, KERN_INFO, "%s(): allow %s: %d\n", __func__, msm_pm_sleep_mode_labels[i], (int)allow[i]); if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] || allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN]) { /* Sync the timer with SCLK, it is needed only for modem * assissted pollapse case. */ int64_t next_timer_exp = msm_timer_enter_idle(); uint32_t sleep_delay; bool low_power = false; sleep_delay = (uint32_t) msm_pm_convert_and_cap_time( next_timer_exp, MSM_PM_SLEEP_TICK_LIMIT); if (sleep_delay == 0) /* 0 would mean infinite time */ sleep_delay = 1; if (!allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) sleep_limit = SLEEP_LIMIT_NO_TCXO_SHUTDOWN; #if defined(CONFIG_MSM_MEMORY_LOW_POWER_MODE_IDLE_ACTIVE) sleep_limit |= SLEEP_RESOURCE_MEMORY_BIT1; #elif defined(CONFIG_MSM_MEMORY_LOW_POWER_MODE_IDLE_RETENTION) sleep_limit |= SLEEP_RESOURCE_MEMORY_BIT0; #endif ret = msm_pm_power_collapse(true, sleep_delay, sleep_limit); low_power = (ret != -EBUSY && ret != -ETIMEDOUT); msm_timer_exit_idle(low_power); if (ret) exit_stat = MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE; else { exit_stat = MSM_PM_STAT_IDLE_POWER_COLLAPSE; msm_pm_sleep_limit = sleep_limit; } } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) { ret = msm_pm_power_collapse_standalone(true); exit_stat = ret ? MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE : MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE; } else if (allow[MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT]) { ret = msm_pm_swfi(true); if (ret) while (!msm_pm_irq_extns->irq_pending()) udelay(1); exit_stat = ret ? MSM_PM_STAT_IDLE_SPIN : MSM_PM_STAT_IDLE_WFI; } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) { msm_pm_swfi(false); exit_stat = MSM_PM_STAT_IDLE_WFI; } else { while (!msm_pm_irq_extns->irq_pending()) udelay(1); exit_stat = MSM_PM_STAT_IDLE_SPIN; } __get_cpu_var(t2) = ktime_to_ns(ktime_get()); msm_pm_add_stat(exit_stat, __get_cpu_var(t2) - t1); }