17426394fSMagnus Damm /* 27426394fSMagnus Damm * arch/sh/kernel/cpu/shmobile/cpuidle.c 37426394fSMagnus Damm * 47426394fSMagnus Damm * Cpuidle support code for SuperH Mobile 57426394fSMagnus Damm * 67426394fSMagnus Damm * Copyright (C) 2009 Magnus Damm 77426394fSMagnus Damm * 87426394fSMagnus Damm * This file is subject to the terms and conditions of the GNU General Public 97426394fSMagnus Damm * License. See the file "COPYING" in the main directory of this archive 107426394fSMagnus Damm * for more details. 117426394fSMagnus Damm */ 127426394fSMagnus Damm #include <linux/init.h> 137426394fSMagnus Damm #include <linux/kernel.h> 147426394fSMagnus Damm #include <linux/io.h> 157426394fSMagnus Damm #include <linux/suspend.h> 167426394fSMagnus Damm #include <linux/cpuidle.h> 17f7be3455SPaul Gortmaker #include <linux/export.h> 187426394fSMagnus Damm #include <asm/suspend.h> 197426394fSMagnus Damm #include <asm/uaccess.h> 207426394fSMagnus Damm 217426394fSMagnus Damm static unsigned long cpuidle_mode[] = { 227426394fSMagnus Damm SUSP_SH_SLEEP, /* regular sleep mode */ 237426394fSMagnus Damm SUSP_SH_SLEEP | SUSP_SH_SF, /* sleep mode + self refresh */ 2463cd91dfSMagnus Damm SUSP_SH_STANDBY | SUSP_SH_SF, /* software standby mode + self refresh */ 257426394fSMagnus Damm }; 267426394fSMagnus Damm 277426394fSMagnus Damm static int cpuidle_sleep_enter(struct cpuidle_device *dev, 2846bcfad7SDeepthi Dharwar struct cpuidle_driver *drv, 29e978aa7dSDeepthi Dharwar int index) 307426394fSMagnus Damm { 314be88734SPaul Mundt unsigned long allowed_mode = SUSP_SH_SLEEP; 32e978aa7dSDeepthi Dharwar int requested_state = index; 337426394fSMagnus Damm int allowed_state; 347426394fSMagnus Damm int k; 357426394fSMagnus Damm 367426394fSMagnus Damm /* convert allowed mode to allowed state */ 377426394fSMagnus Damm for (k = ARRAY_SIZE(cpuidle_mode) - 1; k > 0; k--) 387426394fSMagnus Damm if (cpuidle_mode[k] == allowed_mode) 397426394fSMagnus Damm break; 407426394fSMagnus Damm 417426394fSMagnus Damm allowed_state = k; 427426394fSMagnus Damm 437426394fSMagnus Damm /* take the following into account for sleep mode selection: 447426394fSMagnus Damm * - allowed_state: best mode allowed by hardware (clock deps) 457426394fSMagnus Damm * - requested_state: best mode allowed by software (latencies) 467426394fSMagnus Damm */ 477426394fSMagnus Damm k = min_t(int, allowed_state, requested_state); 487426394fSMagnus Damm 497426394fSMagnus Damm sh_mobile_call_standby(cpuidle_mode[k]); 50e978aa7dSDeepthi Dharwar 51e978aa7dSDeepthi Dharwar return k; 527426394fSMagnus Damm } 537426394fSMagnus Damm 547426394fSMagnus Damm static struct cpuidle_device cpuidle_dev; 557426394fSMagnus Damm static struct cpuidle_driver cpuidle_driver = { 567426394fSMagnus Damm .name = "sh_idle", 577426394fSMagnus Damm .owner = THIS_MODULE, 585c48c873SRobert Lee .en_core_tk_irqen = 1, 590a4f841eSDaniel Lezcano .states = { 600a4f841eSDaniel Lezcano { 610a4f841eSDaniel Lezcano .exit_latency = 1, 620a4f841eSDaniel Lezcano .target_residency = 1 * 2, 630a4f841eSDaniel Lezcano .power_usage = 3, 640a4f841eSDaniel Lezcano .flags = CPUIDLE_FLAG_TIME_VALID, 650a4f841eSDaniel Lezcano .enter = cpuidle_sleep_enter, 660a4f841eSDaniel Lezcano .name = "C1", 670a4f841eSDaniel Lezcano .desc = "SuperH Sleep Mode", 680a4f841eSDaniel Lezcano }, 690a4f841eSDaniel Lezcano { 700a4f841eSDaniel Lezcano .exit_latency = 100, 710a4f841eSDaniel Lezcano .target_residency = 1 * 2, 720a4f841eSDaniel Lezcano .power_usage = 1, 730a4f841eSDaniel Lezcano .flags = CPUIDLE_FLAG_TIME_VALID, 740a4f841eSDaniel Lezcano .enter = cpuidle_sleep_enter, 750a4f841eSDaniel Lezcano .name = "C2", 760a4f841eSDaniel Lezcano .desc = "SuperH Sleep Mode [SF]", 770a4f841eSDaniel Lezcano .disabled = true, 780a4f841eSDaniel Lezcano }, 790a4f841eSDaniel Lezcano { 800a4f841eSDaniel Lezcano .exit_latency = 2300, 810a4f841eSDaniel Lezcano .target_residency = 1 * 2, 820a4f841eSDaniel Lezcano .power_usage = 1, 830a4f841eSDaniel Lezcano .flags = CPUIDLE_FLAG_TIME_VALID, 840a4f841eSDaniel Lezcano .enter = cpuidle_sleep_enter, 850a4f841eSDaniel Lezcano .name = "C3", 860a4f841eSDaniel Lezcano .desc = "SuperH Mobile Standby Mode [SF]", 870a4f841eSDaniel Lezcano .disabled = true, 880a4f841eSDaniel Lezcano }, 890a4f841eSDaniel Lezcano }, 900a4f841eSDaniel Lezcano .safe_state_index = 0, 910a4f841eSDaniel Lezcano .state_count = 3, 927426394fSMagnus Damm }; 937426394fSMagnus Damm 94*38a94f41SDaniel Lezcano int __init sh_mobile_setup_cpuidle(void) 957426394fSMagnus Damm { 96*38a94f41SDaniel Lezcano int ret; 97*38a94f41SDaniel Lezcano 980a4f841eSDaniel Lezcano if (sh_mobile_sleep_supported & SUSP_SH_SF) 990a4f841eSDaniel Lezcano cpuidle_driver.states[1].disabled = false; 1007426394fSMagnus Damm 1010a4f841eSDaniel Lezcano if (sh_mobile_sleep_supported & SUSP_SH_STANDBY) 1020a4f841eSDaniel Lezcano cpuidle_driver.states[2].disabled = false; 1037426394fSMagnus Damm 104*38a94f41SDaniel Lezcano ret = cpuidle_register_driver(&cpuidle_driver); 105*38a94f41SDaniel Lezcano if (ret) 106*38a94f41SDaniel Lezcano return ret; 107*38a94f41SDaniel Lezcano 108*38a94f41SDaniel Lezcano return cpuidle_register_device(&cpuidle_dev); 1097426394fSMagnus Damm } 110