Path: blob/master/arch/sh/kernel/cpu/shmobile/cpuidle.c
26495 views
// SPDX-License-Identifier: GPL-2.01/*2* arch/sh/kernel/cpu/shmobile/cpuidle.c3*4* Cpuidle support code for SuperH Mobile5*6* Copyright (C) 2009 Magnus Damm7*/8#include <linux/init.h>9#include <linux/kernel.h>10#include <linux/io.h>11#include <linux/suspend.h>12#include <linux/cpuidle.h>13#include <linux/export.h>14#include <asm/suspend.h>15#include <linux/uaccess.h>1617static unsigned long cpuidle_mode[] = {18SUSP_SH_SLEEP, /* regular sleep mode */19SUSP_SH_SLEEP | SUSP_SH_SF, /* sleep mode + self refresh */20SUSP_SH_STANDBY | SUSP_SH_SF, /* software standby mode + self refresh */21};2223static int cpuidle_sleep_enter(struct cpuidle_device *dev,24struct cpuidle_driver *drv,25int index)26{27unsigned long allowed_mode = SUSP_SH_SLEEP;28int requested_state = index;29int allowed_state;30int k;3132/* convert allowed mode to allowed state */33for (k = ARRAY_SIZE(cpuidle_mode) - 1; k > 0; k--)34if (cpuidle_mode[k] == allowed_mode)35break;3637allowed_state = k;3839/* take the following into account for sleep mode selection:40* - allowed_state: best mode allowed by hardware (clock deps)41* - requested_state: best mode allowed by software (latencies)42*/43k = min_t(int, allowed_state, requested_state);4445sh_mobile_call_standby(cpuidle_mode[k]);4647return k;48}4950static struct cpuidle_driver cpuidle_driver = {51.name = "sh_idle",52.owner = THIS_MODULE,53.states = {54{55.exit_latency = 1,56.target_residency = 1 * 2,57.power_usage = 3,58.enter = cpuidle_sleep_enter,59.name = "C1",60.desc = "SuperH Sleep Mode",61},62{63.exit_latency = 100,64.target_residency = 1 * 2,65.power_usage = 1,66.enter = cpuidle_sleep_enter,67.name = "C2",68.desc = "SuperH Sleep Mode [SF]",69.flags = CPUIDLE_FLAG_UNUSABLE,70},71{72.exit_latency = 2300,73.target_residency = 1 * 2,74.power_usage = 1,75.enter = cpuidle_sleep_enter,76.name = "C3",77.desc = "SuperH Mobile Standby Mode [SF]",78.flags = CPUIDLE_FLAG_UNUSABLE,79},80},81.safe_state_index = 0,82.state_count = 3,83};8485int __init sh_mobile_setup_cpuidle(void)86{87if (sh_mobile_sleep_supported & SUSP_SH_SF)88cpuidle_driver.states[1].flags = CPUIDLE_FLAG_NONE;8990if (sh_mobile_sleep_supported & SUSP_SH_STANDBY)91cpuidle_driver.states[2].flags = CPUIDLE_FLAG_NONE;9293return cpuidle_register(&cpuidle_driver, NULL);94}959697