blob: 7072c9e63a8fe91d29ffa8d62300b12916371535 [file] [log] [blame]
Santosh Shilimkar982726602011-08-16 17:31:40 +05301/*
2 * OMAP4 CPU idle Routines
3 *
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Santosh Shilimkar <santosh.shilimkar@ti.com>
6 * Rajendra Nayak <rnayak@ti.com>
7 *
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.
11 */
12
13#include <linux/sched.h>
14#include <linux/cpuidle.h>
15#include <linux/cpu_pm.h>
16#include <linux/export.h>
Santosh Shilimkar98be0dd2011-01-16 00:42:31 +053017#include <linux/clockchips.h>
Santosh Shilimkar982726602011-08-16 17:31:40 +053018
19#include <asm/proc-fns.h>
20
21#include "common.h"
22#include "pm.h"
23#include "prm.h"
24
25#ifdef CONFIG_CPU_IDLE
26
27/* Machine specific information to be recorded in the C-state driver_data */
28struct omap4_idle_statedata {
29 u32 cpu_state;
30 u32 mpu_logic_state;
31 u32 mpu_state;
Santosh Shilimkar982726602011-08-16 17:31:40 +053032};
33
34static struct cpuidle_params cpuidle_params_table[] = {
35 /* C1 - CPU0 ON + CPU1 ON + MPU ON */
Daniel Lezcano65d284d2012-04-24 16:05:22 +020036 {.exit_latency = 2 + 2 , .target_residency = 5 },
Santosh Shilimkar982726602011-08-16 17:31:40 +053037 /* C2- CPU0 OFF + CPU1 OFF + MPU CSWR */
Daniel Lezcano65d284d2012-04-24 16:05:22 +020038 {.exit_latency = 328 + 440 , .target_residency = 960 },
Santosh Shilimkar982726602011-08-16 17:31:40 +053039 /* C3 - CPU0 OFF + CPU1 OFF + MPU OSWR */
Daniel Lezcano65d284d2012-04-24 16:05:22 +020040 {.exit_latency = 460 + 518 , .target_residency = 1100 },
Santosh Shilimkar982726602011-08-16 17:31:40 +053041};
42
43#define OMAP4_NUM_STATES ARRAY_SIZE(cpuidle_params_table)
44
45struct omap4_idle_statedata omap4_idle_data[OMAP4_NUM_STATES];
46static struct powerdomain *mpu_pd, *cpu0_pd, *cpu1_pd;
47
48/**
49 * omap4_enter_idle - Programs OMAP4 to enter the specified state
50 * @dev: cpuidle device
51 * @drv: cpuidle driver
52 * @index: the index of state to be entered
53 *
54 * Called from the CPUidle framework to program the device to the
55 * specified low power state selected by the governor.
56 * Returns the amount of time spent in the low power state.
57 */
58static int omap4_enter_idle(struct cpuidle_device *dev,
59 struct cpuidle_driver *drv,
60 int index)
61{
62 struct omap4_idle_statedata *cx =
63 cpuidle_get_statedata(&dev->states_usage[index]);
Santosh Shilimkar982726602011-08-16 17:31:40 +053064 u32 cpu1_state;
Santosh Shilimkar98be0dd2011-01-16 00:42:31 +053065 int cpu_id = smp_processor_id();
Santosh Shilimkar982726602011-08-16 17:31:40 +053066
Santosh Shilimkar982726602011-08-16 17:31:40 +053067 local_fiq_disable();
68
69 /*
70 * CPU0 has to stay ON (i.e in C1) until CPU1 is OFF state.
71 * This is necessary to honour hardware recommondation
72 * of triggeing all the possible low power modes once CPU1 is
73 * out of coherency and in OFF mode.
74 * Update dev->last_state so that governor stats reflects right
75 * data.
76 */
77 cpu1_state = pwrdm_read_pwrst(cpu1_pd);
78 if (cpu1_state != PWRDM_POWER_OFF) {
Santosh Shilimkar03e4fd62012-02-05 13:18:44 +053079 index = drv->safe_state_index;
80 cx = cpuidle_get_statedata(&dev->states_usage[index]);
Santosh Shilimkar982726602011-08-16 17:31:40 +053081 }
82
Santosh Shilimkar98be0dd2011-01-16 00:42:31 +053083 if (index > 0)
84 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
85
Santosh Shilimkar982726602011-08-16 17:31:40 +053086 /*
87 * Call idle CPU PM enter notifier chain so that
88 * VFP and per CPU interrupt context is saved.
89 */
90 if (cx->cpu_state == PWRDM_POWER_OFF)
91 cpu_pm_enter();
92
93 pwrdm_set_logic_retst(mpu_pd, cx->mpu_logic_state);
94 omap_set_pwrdm_state(mpu_pd, cx->mpu_state);
95
96 /*
97 * Call idle CPU cluster PM enter notifier chain
98 * to save GIC and wakeupgen context.
99 */
100 if ((cx->mpu_state == PWRDM_POWER_RET) &&
101 (cx->mpu_logic_state == PWRDM_POWER_OFF))
102 cpu_cluster_pm_enter();
103
104 omap4_enter_lowpower(dev->cpu, cx->cpu_state);
105
106 /*
107 * Call idle CPU PM exit notifier chain to restore
108 * VFP and per CPU IRQ context. Only CPU0 state is
109 * considered since CPU1 is managed by CPU hotplug.
110 */
111 if (pwrdm_read_prev_pwrst(cpu0_pd) == PWRDM_POWER_OFF)
112 cpu_pm_exit();
113
114 /*
115 * Call idle CPU cluster PM exit notifier chain
116 * to restore GIC and wakeupgen context.
117 */
118 if (omap4_mpuss_read_prev_context_state())
119 cpu_cluster_pm_exit();
120
Santosh Shilimkar98be0dd2011-01-16 00:42:31 +0530121 if (index > 0)
122 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
123
Santosh Shilimkar982726602011-08-16 17:31:40 +0530124 local_fiq_enable();
125
Santosh Shilimkar982726602011-08-16 17:31:40 +0530126 return index;
127}
128
129DEFINE_PER_CPU(struct cpuidle_device, omap4_idle_dev);
130
131struct cpuidle_driver omap4_idle_driver = {
Robert Leed13e9262012-03-20 15:22:47 -0500132 .name = "omap4_idle",
133 .owner = THIS_MODULE,
134 .en_core_tk_irqen = 1,
Daniel Lezcano78e90162012-04-24 16:05:23 +0200135 .states = {
136 {
137 /* C1 - CPU0 ON + CPU1 ON + MPU ON */
138 .exit_latency = 2 + 2,
139 .target_residency = 5,
140 .flags = CPUIDLE_FLAG_TIME_VALID,
141 .enter = omap4_enter_idle,
142 .name = "C1",
143 .desc = "MPUSS ON"
144 },
145 {
146 /* C2 - CPU0 OFF + CPU1 OFF + MPU CSWR */
147 .exit_latency = 328 + 440,
148 .target_residency = 960,
149 .flags = CPUIDLE_FLAG_TIME_VALID,
150 .enter = omap4_enter_idle,
151 .name = "C2",
152 .desc = "MPUSS CSWR",
153 },
154 {
155 /* C3 - CPU0 OFF + CPU1 OFF + MPU OSWR */
156 .exit_latency = 460 + 518,
157 .target_residency = 1100,
158 .flags = CPUIDLE_FLAG_TIME_VALID,
159 .enter = omap4_enter_idle,
160 .name = "C3",
161 .desc = "MPUSS OSWR",
162 },
163 },
164 .state_count = OMAP4_NUM_STATES,
165 .safe_state_index = 0,
Santosh Shilimkar982726602011-08-16 17:31:40 +0530166};
167
Santosh Shilimkar982726602011-08-16 17:31:40 +0530168static inline struct omap4_idle_statedata *_fill_cstate_usage(
169 struct cpuidle_device *dev,
170 int idx)
171{
172 struct omap4_idle_statedata *cx = &omap4_idle_data[idx];
173 struct cpuidle_state_usage *state_usage = &dev->states_usage[idx];
174
Santosh Shilimkar982726602011-08-16 17:31:40 +0530175 cpuidle_set_statedata(state_usage, cx);
176
177 return cx;
178}
179
180
181
182/**
183 * omap4_idle_init - Init routine for OMAP4 idle
184 *
185 * Registers the OMAP4 specific cpuidle driver to the cpuidle
186 * framework with the valid set of states.
187 */
188int __init omap4_idle_init(void)
189{
190 struct omap4_idle_statedata *cx;
191 struct cpuidle_device *dev;
Santosh Shilimkar982726602011-08-16 17:31:40 +0530192 unsigned int cpu_id = 0;
193
194 mpu_pd = pwrdm_lookup("mpu_pwrdm");
195 cpu0_pd = pwrdm_lookup("cpu0_pwrdm");
196 cpu1_pd = pwrdm_lookup("cpu1_pwrdm");
197 if ((!mpu_pd) || (!cpu0_pd) || (!cpu1_pd))
198 return -ENODEV;
199
Santosh Shilimkar982726602011-08-16 17:31:40 +0530200 dev = &per_cpu(omap4_idle_dev, cpu_id);
201 dev->cpu = cpu_id;
202
Santosh Shilimkar982726602011-08-16 17:31:40 +0530203 cx = _fill_cstate_usage(dev, 0);
Santosh Shilimkar982726602011-08-16 17:31:40 +0530204 cx->cpu_state = PWRDM_POWER_ON;
205 cx->mpu_state = PWRDM_POWER_ON;
206 cx->mpu_logic_state = PWRDM_POWER_RET;
207
Santosh Shilimkar982726602011-08-16 17:31:40 +0530208 cx = _fill_cstate_usage(dev, 1);
209 cx->cpu_state = PWRDM_POWER_OFF;
210 cx->mpu_state = PWRDM_POWER_RET;
211 cx->mpu_logic_state = PWRDM_POWER_RET;
212
Santosh Shilimkar982726602011-08-16 17:31:40 +0530213 cx = _fill_cstate_usage(dev, 2);
214 cx->cpu_state = PWRDM_POWER_OFF;
215 cx->mpu_state = PWRDM_POWER_RET;
216 cx->mpu_logic_state = PWRDM_POWER_OFF;
217
Santosh Shilimkar982726602011-08-16 17:31:40 +0530218 cpuidle_register_driver(&omap4_idle_driver);
219
Santosh Shilimkar982726602011-08-16 17:31:40 +0530220 if (cpuidle_register_device(dev)) {
221 pr_err("%s: CPUidle register device failed\n", __func__);
Daniel Lezcano78e90162012-04-24 16:05:23 +0200222 return -EIO;
223 }
Santosh Shilimkar982726602011-08-16 17:31:40 +0530224
225 return 0;
226}
227#else
228int __init omap4_idle_init(void)
229{
230 return 0;
231}
232#endif /* CONFIG_CPU_IDLE */