blob: 38ecd270a4a8f6be890c503cbf17f09c123093c0 [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
Daniel Lezcano4e0a64f2012-04-24 16:05:24 +020034#define OMAP4_NUM_STATES 3
Santosh Shilimkar982726602011-08-16 17:31:40 +053035
Daniel Lezcanocc6ae022012-04-24 16:05:25 +020036static struct omap4_idle_statedata omap4_idle_data[OMAP4_NUM_STATES];
Santosh Shilimkar982726602011-08-16 17:31:40 +053037static struct powerdomain *mpu_pd, *cpu0_pd, *cpu1_pd;
38
39/**
40 * omap4_enter_idle - Programs OMAP4 to enter the specified state
41 * @dev: cpuidle device
42 * @drv: cpuidle driver
43 * @index: the index of state to be entered
44 *
45 * Called from the CPUidle framework to program the device to the
46 * specified low power state selected by the governor.
47 * Returns the amount of time spent in the low power state.
48 */
49static int omap4_enter_idle(struct cpuidle_device *dev,
50 struct cpuidle_driver *drv,
51 int index)
52{
53 struct omap4_idle_statedata *cx =
54 cpuidle_get_statedata(&dev->states_usage[index]);
Santosh Shilimkar982726602011-08-16 17:31:40 +053055 u32 cpu1_state;
Santosh Shilimkar98be0dd2011-01-16 00:42:31 +053056 int cpu_id = smp_processor_id();
Santosh Shilimkar982726602011-08-16 17:31:40 +053057
Santosh Shilimkar982726602011-08-16 17:31:40 +053058 local_fiq_disable();
59
60 /*
61 * CPU0 has to stay ON (i.e in C1) until CPU1 is OFF state.
62 * This is necessary to honour hardware recommondation
63 * of triggeing all the possible low power modes once CPU1 is
64 * out of coherency and in OFF mode.
65 * Update dev->last_state so that governor stats reflects right
66 * data.
67 */
68 cpu1_state = pwrdm_read_pwrst(cpu1_pd);
69 if (cpu1_state != PWRDM_POWER_OFF) {
Santosh Shilimkar03e4fd62012-02-05 13:18:44 +053070 index = drv->safe_state_index;
71 cx = cpuidle_get_statedata(&dev->states_usage[index]);
Santosh Shilimkar982726602011-08-16 17:31:40 +053072 }
73
Santosh Shilimkar98be0dd2011-01-16 00:42:31 +053074 if (index > 0)
75 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
76
Santosh Shilimkar982726602011-08-16 17:31:40 +053077 /*
78 * Call idle CPU PM enter notifier chain so that
79 * VFP and per CPU interrupt context is saved.
80 */
81 if (cx->cpu_state == PWRDM_POWER_OFF)
82 cpu_pm_enter();
83
84 pwrdm_set_logic_retst(mpu_pd, cx->mpu_logic_state);
85 omap_set_pwrdm_state(mpu_pd, cx->mpu_state);
86
87 /*
88 * Call idle CPU cluster PM enter notifier chain
89 * to save GIC and wakeupgen context.
90 */
91 if ((cx->mpu_state == PWRDM_POWER_RET) &&
92 (cx->mpu_logic_state == PWRDM_POWER_OFF))
93 cpu_cluster_pm_enter();
94
95 omap4_enter_lowpower(dev->cpu, cx->cpu_state);
96
97 /*
98 * Call idle CPU PM exit notifier chain to restore
99 * VFP and per CPU IRQ context. Only CPU0 state is
100 * considered since CPU1 is managed by CPU hotplug.
101 */
102 if (pwrdm_read_prev_pwrst(cpu0_pd) == PWRDM_POWER_OFF)
103 cpu_pm_exit();
104
105 /*
106 * Call idle CPU cluster PM exit notifier chain
107 * to restore GIC and wakeupgen context.
108 */
109 if (omap4_mpuss_read_prev_context_state())
110 cpu_cluster_pm_exit();
111
Santosh Shilimkar98be0dd2011-01-16 00:42:31 +0530112 if (index > 0)
113 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
114
Santosh Shilimkar982726602011-08-16 17:31:40 +0530115 local_fiq_enable();
116
Santosh Shilimkar982726602011-08-16 17:31:40 +0530117 return index;
118}
119
120DEFINE_PER_CPU(struct cpuidle_device, omap4_idle_dev);
121
122struct cpuidle_driver omap4_idle_driver = {
Robert Leed13e9262012-03-20 15:22:47 -0500123 .name = "omap4_idle",
124 .owner = THIS_MODULE,
125 .en_core_tk_irqen = 1,
Daniel Lezcano78e90162012-04-24 16:05:23 +0200126 .states = {
127 {
128 /* C1 - CPU0 ON + CPU1 ON + MPU ON */
129 .exit_latency = 2 + 2,
130 .target_residency = 5,
131 .flags = CPUIDLE_FLAG_TIME_VALID,
132 .enter = omap4_enter_idle,
133 .name = "C1",
134 .desc = "MPUSS ON"
135 },
136 {
137 /* C2 - CPU0 OFF + CPU1 OFF + MPU CSWR */
138 .exit_latency = 328 + 440,
139 .target_residency = 960,
140 .flags = CPUIDLE_FLAG_TIME_VALID,
141 .enter = omap4_enter_idle,
142 .name = "C2",
143 .desc = "MPUSS CSWR",
144 },
145 {
146 /* C3 - CPU0 OFF + CPU1 OFF + MPU OSWR */
147 .exit_latency = 460 + 518,
148 .target_residency = 1100,
149 .flags = CPUIDLE_FLAG_TIME_VALID,
150 .enter = omap4_enter_idle,
151 .name = "C3",
152 .desc = "MPUSS OSWR",
153 },
154 },
155 .state_count = OMAP4_NUM_STATES,
156 .safe_state_index = 0,
Santosh Shilimkar982726602011-08-16 17:31:40 +0530157};
158
Santosh Shilimkar982726602011-08-16 17:31:40 +0530159static inline struct omap4_idle_statedata *_fill_cstate_usage(
160 struct cpuidle_device *dev,
161 int idx)
162{
163 struct omap4_idle_statedata *cx = &omap4_idle_data[idx];
164 struct cpuidle_state_usage *state_usage = &dev->states_usage[idx];
165
Santosh Shilimkar982726602011-08-16 17:31:40 +0530166 cpuidle_set_statedata(state_usage, cx);
167
168 return cx;
169}
170
171
172
173/**
174 * omap4_idle_init - Init routine for OMAP4 idle
175 *
176 * Registers the OMAP4 specific cpuidle driver to the cpuidle
177 * framework with the valid set of states.
178 */
179int __init omap4_idle_init(void)
180{
181 struct omap4_idle_statedata *cx;
182 struct cpuidle_device *dev;
Santosh Shilimkar982726602011-08-16 17:31:40 +0530183 unsigned int cpu_id = 0;
184
185 mpu_pd = pwrdm_lookup("mpu_pwrdm");
186 cpu0_pd = pwrdm_lookup("cpu0_pwrdm");
187 cpu1_pd = pwrdm_lookup("cpu1_pwrdm");
188 if ((!mpu_pd) || (!cpu0_pd) || (!cpu1_pd))
189 return -ENODEV;
190
Santosh Shilimkar982726602011-08-16 17:31:40 +0530191 dev = &per_cpu(omap4_idle_dev, cpu_id);
192 dev->cpu = cpu_id;
193
Santosh Shilimkar982726602011-08-16 17:31:40 +0530194 cx = _fill_cstate_usage(dev, 0);
Santosh Shilimkar982726602011-08-16 17:31:40 +0530195 cx->cpu_state = PWRDM_POWER_ON;
196 cx->mpu_state = PWRDM_POWER_ON;
197 cx->mpu_logic_state = PWRDM_POWER_RET;
198
Santosh Shilimkar982726602011-08-16 17:31:40 +0530199 cx = _fill_cstate_usage(dev, 1);
200 cx->cpu_state = PWRDM_POWER_OFF;
201 cx->mpu_state = PWRDM_POWER_RET;
202 cx->mpu_logic_state = PWRDM_POWER_RET;
203
Santosh Shilimkar982726602011-08-16 17:31:40 +0530204 cx = _fill_cstate_usage(dev, 2);
205 cx->cpu_state = PWRDM_POWER_OFF;
206 cx->mpu_state = PWRDM_POWER_RET;
207 cx->mpu_logic_state = PWRDM_POWER_OFF;
208
Santosh Shilimkar982726602011-08-16 17:31:40 +0530209 cpuidle_register_driver(&omap4_idle_driver);
210
Santosh Shilimkar982726602011-08-16 17:31:40 +0530211 if (cpuidle_register_device(dev)) {
212 pr_err("%s: CPUidle register device failed\n", __func__);
Daniel Lezcano78e90162012-04-24 16:05:23 +0200213 return -EIO;
214 }
Santosh Shilimkar982726602011-08-16 17:31:40 +0530215
216 return 0;
217}
218#else
219int __init omap4_idle_init(void)
220{
221 return 0;
222}
223#endif /* CONFIG_CPU_IDLE */