2 * OMAP4 CPU idle Routines
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Santosh Shilimkar <santosh.shilimkar@ti.com>
6 * Rajendra Nayak <rnayak@ti.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/sched.h>
14 #include <linux/cpuidle.h>
15 #include <linux/cpu_pm.h>
16 #include <linux/export.h>
17 #include <linux/clockchips.h>
19 #include <asm/proc-fns.h>
25 /* Machine specific information */
26 struct omap4_idle_statedata {
32 static struct omap4_idle_statedata omap4_idle_data[] = {
34 .cpu_state = PWRDM_POWER_ON,
35 .mpu_state = PWRDM_POWER_ON,
36 .mpu_logic_state = PWRDM_POWER_RET,
39 .cpu_state = PWRDM_POWER_OFF,
40 .mpu_state = PWRDM_POWER_RET,
41 .mpu_logic_state = PWRDM_POWER_RET,
44 .cpu_state = PWRDM_POWER_OFF,
45 .mpu_state = PWRDM_POWER_RET,
46 .mpu_logic_state = PWRDM_POWER_OFF,
50 static struct powerdomain *mpu_pd, *cpu0_pd, *cpu1_pd;
53 * omap4_enter_idle - Programs OMAP4 to enter the specified state
54 * @dev: cpuidle device
55 * @drv: cpuidle driver
56 * @index: the index of state to be entered
58 * Called from the CPUidle framework to program the device to the
59 * specified low power state selected by the governor.
60 * Returns the amount of time spent in the low power state.
62 static int omap4_enter_idle(struct cpuidle_device *dev,
63 struct cpuidle_driver *drv,
66 struct omap4_idle_statedata *cx = &omap4_idle_data[index];
68 int cpu_id = smp_processor_id();
73 * CPU0 has to stay ON (i.e in C1) until CPU1 is OFF state.
74 * This is necessary to honour hardware recommondation
75 * of triggeing all the possible low power modes once CPU1 is
76 * out of coherency and in OFF mode.
77 * Update dev->last_state so that governor stats reflects right
80 cpu1_state = pwrdm_read_pwrst(cpu1_pd);
81 if (cpu1_state != PWRDM_POWER_OFF) {
82 index = drv->safe_state_index;
83 cx = &omap4_idle_data[index];
87 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
90 * Call idle CPU PM enter notifier chain so that
91 * VFP and per CPU interrupt context is saved.
93 if (cx->cpu_state == PWRDM_POWER_OFF)
96 pwrdm_set_logic_retst(mpu_pd, cx->mpu_logic_state);
97 omap_set_pwrdm_state(mpu_pd, cx->mpu_state);
100 * Call idle CPU cluster PM enter notifier chain
101 * to save GIC and wakeupgen context.
103 if ((cx->mpu_state == PWRDM_POWER_RET) &&
104 (cx->mpu_logic_state == PWRDM_POWER_OFF))
105 cpu_cluster_pm_enter();
107 omap4_enter_lowpower(dev->cpu, cx->cpu_state);
110 * Call idle CPU PM exit notifier chain to restore
111 * VFP and per CPU IRQ context. Only CPU0 state is
112 * considered since CPU1 is managed by CPU hotplug.
114 if (pwrdm_read_prev_pwrst(cpu0_pd) == PWRDM_POWER_OFF)
118 * Call idle CPU cluster PM exit notifier chain
119 * to restore GIC and wakeupgen context.
121 if (omap4_mpuss_read_prev_context_state())
122 cpu_cluster_pm_exit();
125 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
132 DEFINE_PER_CPU(struct cpuidle_device, omap4_idle_dev);
134 struct cpuidle_driver omap4_idle_driver = {
135 .name = "omap4_idle",
136 .owner = THIS_MODULE,
137 .en_core_tk_irqen = 1,
140 /* C1 - CPU0 ON + CPU1 ON + MPU ON */
141 .exit_latency = 2 + 2,
142 .target_residency = 5,
143 .flags = CPUIDLE_FLAG_TIME_VALID,
144 .enter = omap4_enter_idle,
149 /* C2 - CPU0 OFF + CPU1 OFF + MPU CSWR */
150 .exit_latency = 328 + 440,
151 .target_residency = 960,
152 .flags = CPUIDLE_FLAG_TIME_VALID,
153 .enter = omap4_enter_idle,
155 .desc = "MPUSS CSWR",
158 /* C3 - CPU0 OFF + CPU1 OFF + MPU OSWR */
159 .exit_latency = 460 + 518,
160 .target_residency = 1100,
161 .flags = CPUIDLE_FLAG_TIME_VALID,
162 .enter = omap4_enter_idle,
164 .desc = "MPUSS OSWR",
167 .state_count = ARRAY_SIZE(omap4_idle_data),
168 .safe_state_index = 0,
172 * omap4_idle_init - Init routine for OMAP4 idle
174 * Registers the OMAP4 specific cpuidle driver to the cpuidle
175 * framework with the valid set of states.
177 int __init omap4_idle_init(void)
179 struct cpuidle_device *dev;
180 unsigned int cpu_id = 0;
182 mpu_pd = pwrdm_lookup("mpu_pwrdm");
183 cpu0_pd = pwrdm_lookup("cpu0_pwrdm");
184 cpu1_pd = pwrdm_lookup("cpu1_pwrdm");
185 if ((!mpu_pd) || (!cpu0_pd) || (!cpu1_pd))
188 dev = &per_cpu(omap4_idle_dev, cpu_id);
191 cpuidle_register_driver(&omap4_idle_driver);
193 if (cpuidle_register_device(dev)) {
194 pr_err("%s: CPUidle register device failed\n", __func__);