blob: 3feb475bd14d17192f71bf9b1d924228c162cff4 [file] [log] [blame]
Kevin Hilman8bd22942009-05-28 10:56:16 -07001/*
2 * OMAP Power Management debug routines
3 *
4 * Copyright (C) 2005 Texas Instruments, Inc.
5 * Copyright (C) 2006-2008 Nokia Corporation
6 *
7 * Written by:
8 * Richard Woodruff <r-woodruff2@ti.com>
9 * Tony Lindgren
10 * Juha Yrjola
11 * Amit Kucheria <amit.kucheria@nokia.com>
12 * Igor Stoppa <igor.stoppa@nokia.com>
13 * Jouni Hogander
14 *
15 * Based on pm.c for omap2
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
20 */
21
22#include <linux/kernel.h>
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030023#include <linux/sched.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070024#include <linux/clk.h>
25#include <linux/err.h>
26#include <linux/io.h>
Tero Kristo68d47782008-11-26 12:26:24 +020027#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070029
Tony Lindgrence491cf2009-10-20 09:40:47 -070030#include <plat/clock.h>
31#include <plat/board.h>
Paul Walmsley72e06d02010-12-21 21:05:16 -070032#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070033#include "clockdomain.h"
Santosh Shilimkar86b0c1e2010-09-15 01:03:59 +053034#include <plat/dmtimer.h>
Kevin Hilman6081dc32010-12-21 21:31:55 -070035#include <plat/omap-pm.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070036
Paul Walmsley59fb6592010-12-21 15:30:55 -070037#include "cm2xxx_3xxx.h"
38#include "prm2xxx_3xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070039#include "pm.h"
40
Thara Gopinath6cdee912010-08-12 13:52:25 +053041u32 enable_off_mode;
Thara Gopinath6cdee912010-08-12 13:52:25 +053042u32 wakeup_timer_seconds;
43u32 wakeup_timer_milliseconds;
Kevin Hilman8bd22942009-05-28 10:56:16 -070044
Kevin Hilman9f5ead72010-12-01 10:55:46 +000045void omap2_pm_wakeup_on_timer(u32 seconds, u32 milliseconds)
46{
47 u32 tick_rate, cycles;
48
49 if (!seconds && !milliseconds)
50 return;
51
52 tick_rate = clk_get_rate(omap_dm_timer_get_fclk(gptimer_wakeup));
53 cycles = tick_rate * seconds + tick_rate * milliseconds / 1000;
54 omap_dm_timer_stop(gptimer_wakeup);
55 omap_dm_timer_set_load_start(gptimer_wakeup, 0, 0xffffffff - cycles);
56
57 pr_info("PM: Resume timer in %u.%03u secs"
58 " (%d ticks at %d ticks/sec.)\n",
59 seconds, milliseconds, cycles, tick_rate);
60}
61
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030062#ifdef CONFIG_DEBUG_FS
63#include <linux/debugfs.h>
64#include <linux/seq_file.h>
65
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030066static int pm_dbg_init_done;
67
Russell Kingc8fb13d2011-05-27 13:56:12 -070068static int pm_dbg_init(void);
Sergio Aguirre6b34f9d2010-01-14 11:01:15 -060069
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030070enum {
71 DEBUG_FILE_COUNTERS = 0,
72 DEBUG_FILE_TIMERS,
73};
74
Paul Walmsley2354eb52009-12-08 16:33:12 -070075static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030076 "OFF",
77 "RET",
78 "INA",
79 "ON"
80};
81
82void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
83{
84 s64 t;
85
86 if (!pm_dbg_init_done)
87 return ;
88
89 /* Update timer for previous state */
90 t = sched_clock();
91
92 pwrdm->state_timer[prev] += t - pwrdm->timer;
93
94 pwrdm->timer = t;
95}
96
97static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
98{
99 struct seq_file *s = (struct seq_file *)user;
100
101 if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
102 strcmp(clkdm->name, "wkup_clkdm") == 0 ||
103 strncmp(clkdm->name, "dpll", 4) == 0)
104 return 0;
105
106 seq_printf(s, "%s->%s (%d)", clkdm->name,
107 clkdm->pwrdm.ptr->name,
108 atomic_read(&clkdm->usecount));
109 seq_printf(s, "\n");
110
111 return 0;
112}
113
114static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
115{
116 struct seq_file *s = (struct seq_file *)user;
117 int i;
118
119 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
120 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
121 strncmp(pwrdm->name, "dpll", 4) == 0)
122 return 0;
123
124 if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
125 printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
126 pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
127
128 seq_printf(s, "%s (%s)", pwrdm->name,
129 pwrdm_state_names[pwrdm->state]);
Paul Walmsley2354eb52009-12-08 16:33:12 -0700130 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300131 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
132 pwrdm->state_counter[i]);
133
Thara Gopinathcde08f82010-02-24 12:05:50 -0700134 seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
135 for (i = 0; i < pwrdm->banks; i++)
136 seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
137 pwrdm->ret_mem_off_counter[i]);
138
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300139 seq_printf(s, "\n");
140
141 return 0;
142}
143
144static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
145{
146 struct seq_file *s = (struct seq_file *)user;
147 int i;
148
149 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
150 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
151 strncmp(pwrdm->name, "dpll", 4) == 0)
152 return 0;
153
154 pwrdm_state_switch(pwrdm);
155
156 seq_printf(s, "%s (%s)", pwrdm->name,
157 pwrdm_state_names[pwrdm->state]);
158
159 for (i = 0; i < 4; i++)
160 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
161 pwrdm->state_timer[i]);
162
163 seq_printf(s, "\n");
164 return 0;
165}
166
167static int pm_dbg_show_counters(struct seq_file *s, void *unused)
168{
169 pwrdm_for_each(pwrdm_dbg_show_counter, s);
170 clkdm_for_each(clkdm_dbg_show_counter, s);
171
172 return 0;
173}
174
175static int pm_dbg_show_timers(struct seq_file *s, void *unused)
176{
177 pwrdm_for_each(pwrdm_dbg_show_timer, s);
178 return 0;
179}
180
181static int pm_dbg_open(struct inode *inode, struct file *file)
182{
183 switch ((int)inode->i_private) {
184 case DEBUG_FILE_COUNTERS:
185 return single_open(file, pm_dbg_show_counters,
186 &inode->i_private);
187 case DEBUG_FILE_TIMERS:
188 default:
189 return single_open(file, pm_dbg_show_timers,
190 &inode->i_private);
191 };
192}
193
194static const struct file_operations debug_fops = {
195 .open = pm_dbg_open,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
199};
200
Tero Kristo68d47782008-11-26 12:26:24 +0200201static int pwrdm_suspend_get(void *data, u64 *val)
202{
Thara Gopinath6cdee912010-08-12 13:52:25 +0530203 int ret = -EINVAL;
204
205 if (cpu_is_omap34xx())
206 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
Roel Kluin61b17d92009-12-16 17:22:04 +0100207 *val = ret;
Tero Kristo68d47782008-11-26 12:26:24 +0200208
Roel Kluin61b17d92009-12-16 17:22:04 +0100209 if (ret >= 0)
Tero Kristo68d47782008-11-26 12:26:24 +0200210 return 0;
211 return *val;
212}
213
214static int pwrdm_suspend_set(void *data, u64 val)
215{
Thara Gopinath6cdee912010-08-12 13:52:25 +0530216 if (cpu_is_omap34xx())
217 return omap3_pm_set_suspend_state(
218 (struct powerdomain *)data, (int)val);
219 return -EINVAL;
Tero Kristo68d47782008-11-26 12:26:24 +0200220}
221
222DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
223 pwrdm_suspend_set, "%llu\n");
224
225static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300226{
227 int i;
228 s64 t;
Tero Kristo68d47782008-11-26 12:26:24 +0200229 struct dentry *d;
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300230
231 t = sched_clock();
232
233 for (i = 0; i < 4; i++)
234 pwrdm->state_timer[i] = 0;
235
236 pwrdm->timer = t;
237
Tero Kristo68d47782008-11-26 12:26:24 +0200238 if (strncmp(pwrdm->name, "dpll", 4) == 0)
239 return 0;
240
241 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
242
243 (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
244 (void *)pwrdm, &pwrdm_suspend_fops);
245
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300246 return 0;
247}
248
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700249static int option_get(void *data, u64 *val)
250{
251 u32 *option = data;
252
253 *val = *option;
254
255 return 0;
256}
257
258static int option_set(void *data, u64 val)
259{
260 u32 *option = data;
261
Ari Kauppi8e2efde2010-03-23 09:04:59 +0200262 if (option == &wakeup_timer_milliseconds && val >= 1000)
263 return -EINVAL;
264
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700265 *option = val;
266
Thara Gopinath6cdee912010-08-12 13:52:25 +0530267 if (option == &enable_off_mode) {
Kevin Hilman6081dc32010-12-21 21:31:55 -0700268 if (val)
269 omap_pm_enable_off_mode();
270 else
271 omap_pm_disable_off_mode();
Thara Gopinath6cdee912010-08-12 13:52:25 +0530272 if (cpu_is_omap34xx())
273 omap3_pm_off_mode_enable(val);
274 }
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700275
276 return 0;
277}
278
279DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
280
Sanjeev Premiec3cdb52011-06-17 02:01:00 +0530281static int __init pm_dbg_init(void)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300282{
283 struct dentry *d;
284
Tero Kristo2811d6b2008-10-29 13:31:24 +0200285 if (pm_dbg_init_done)
286 return 0;
287
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300288 d = debugfs_create_dir("pm_debug", NULL);
289 if (IS_ERR(d))
290 return PTR_ERR(d);
291
292 (void) debugfs_create_file("count", S_IRUGO,
293 d, (void *)DEBUG_FILE_COUNTERS, &debug_fops);
294 (void) debugfs_create_file("time", S_IRUGO,
295 d, (void *)DEBUG_FILE_TIMERS, &debug_fops);
296
Paul Walmsleye909d622010-01-26 20:13:00 -0700297 pwrdm_for_each(pwrdms_setup, (void *)d);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300298
Vasiliy Kulikovf9fbe472011-02-04 12:23:16 +0000299 (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700300 &enable_off_mode, &pm_dbg_option_fops);
Vasiliy Kulikovf9fbe472011-02-04 12:23:16 +0000301 (void) debugfs_create_file("wakeup_timer_seconds", S_IRUGO | S_IWUSR, d,
Kevin Hilmand7814e42009-10-06 14:30:23 -0700302 &wakeup_timer_seconds, &pm_dbg_option_fops);
Santosh Shilimkar315e2552010-09-15 01:04:00 +0530303 (void) debugfs_create_file("wakeup_timer_milliseconds",
Vasiliy Kulikovf9fbe472011-02-04 12:23:16 +0000304 S_IRUGO | S_IWUSR, d, &wakeup_timer_milliseconds,
Santosh Shilimkar315e2552010-09-15 01:04:00 +0530305 &pm_dbg_option_fops);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300306 pm_dbg_init_done = 1;
307
308 return 0;
309}
Tero Kristo2811d6b2008-10-29 13:31:24 +0200310arch_initcall(pm_dbg_init);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300311
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300312#endif