OMAP2: PM debug: always compile
[pandora-kernel.git] / arch / arm / mach-omap2 / pm-debug.c
1 /*
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>
23 #include <linux/sched.h>
24 #include <linux/clk.h>
25 #include <linux/err.h>
26 #include <linux/io.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
29
30 #include <plat/clock.h>
31 #include <plat/board.h>
32 #include "powerdomain.h"
33 #include "clockdomain.h"
34 #include <plat/dmtimer.h>
35 #include <plat/omap-pm.h>
36
37 #include "cm2xxx_3xxx.h"
38 #include "prm2xxx_3xxx.h"
39 #include "pm.h"
40
41 u32 enable_off_mode;
42
43 #ifdef CONFIG_DEBUG_FS
44 #include <linux/debugfs.h>
45 #include <linux/seq_file.h>
46
47 static int pm_dbg_init_done;
48
49 static int pm_dbg_init(void);
50
51 enum {
52         DEBUG_FILE_COUNTERS = 0,
53         DEBUG_FILE_TIMERS,
54 };
55
56 static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
57         "OFF",
58         "RET",
59         "INA",
60         "ON"
61 };
62
63 #ifdef CONFIG_PM_DEBUG
64 void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
65 {
66         s64 t;
67
68         if (!pm_dbg_init_done)
69                 return ;
70
71         /* Update timer for previous state */
72         t = sched_clock();
73
74         pwrdm->state_timer[prev] += t - pwrdm->timer;
75
76         pwrdm->timer = t;
77 }
78 #endif
79
80 static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
81 {
82         struct seq_file *s = (struct seq_file *)user;
83
84         if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
85                 strcmp(clkdm->name, "wkup_clkdm") == 0 ||
86                 strncmp(clkdm->name, "dpll", 4) == 0)
87                 return 0;
88
89         seq_printf(s, "%s->%s (%d)", clkdm->name,
90                         clkdm->pwrdm.ptr->name,
91                         atomic_read(&clkdm->usecount));
92         seq_printf(s, "\n");
93
94         return 0;
95 }
96
97 static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
98 {
99         struct seq_file *s = (struct seq_file *)user;
100         int i;
101
102         if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
103                 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
104                 strncmp(pwrdm->name, "dpll", 4) == 0)
105                 return 0;
106
107         if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
108                 printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
109                         pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
110
111         seq_printf(s, "%s (%s)", pwrdm->name,
112                         pwrdm_state_names[pwrdm->state]);
113         for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
114                 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
115                         pwrdm->state_counter[i]);
116
117         seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
118         for (i = 0; i < pwrdm->banks; i++)
119                 seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
120                                 pwrdm->ret_mem_off_counter[i]);
121
122         seq_printf(s, "\n");
123
124         return 0;
125 }
126
127 static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
128 {
129 #ifdef CONFIG_PM_DEBUG
130         struct seq_file *s = (struct seq_file *)user;
131         int i;
132
133         if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
134                 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
135                 strncmp(pwrdm->name, "dpll", 4) == 0)
136                 return 0;
137
138         pwrdm_state_switch(pwrdm);
139
140         seq_printf(s, "%s (%s)", pwrdm->name,
141                 pwrdm_state_names[pwrdm->state]);
142
143         for (i = 0; i < 4; i++)
144                 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
145                         pwrdm->state_timer[i]);
146
147         seq_printf(s, "\n");
148 #endif
149         return 0;
150 }
151
152 static int pm_dbg_show_counters(struct seq_file *s, void *unused)
153 {
154         pwrdm_for_each(pwrdm_dbg_show_counter, s);
155         clkdm_for_each(clkdm_dbg_show_counter, s);
156
157         return 0;
158 }
159
160 static int pm_dbg_show_timers(struct seq_file *s, void *unused)
161 {
162         pwrdm_for_each(pwrdm_dbg_show_timer, s);
163         return 0;
164 }
165
166 static int pm_dbg_open(struct inode *inode, struct file *file)
167 {
168         switch ((int)inode->i_private) {
169         case DEBUG_FILE_COUNTERS:
170                 return single_open(file, pm_dbg_show_counters,
171                         &inode->i_private);
172         case DEBUG_FILE_TIMERS:
173         default:
174                 return single_open(file, pm_dbg_show_timers,
175                         &inode->i_private);
176         };
177 }
178
179 static const struct file_operations debug_fops = {
180         .open           = pm_dbg_open,
181         .read           = seq_read,
182         .llseek         = seq_lseek,
183         .release        = single_release,
184 };
185
186 static int pwrdm_suspend_get(void *data, u64 *val)
187 {
188         int ret = -EINVAL;
189
190         if (cpu_is_omap34xx())
191                 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
192         *val = ret;
193
194         if (ret >= 0)
195                 return 0;
196         return *val;
197 }
198
199 static int pwrdm_suspend_set(void *data, u64 val)
200 {
201         if (cpu_is_omap34xx())
202                 return omap3_pm_set_suspend_state(
203                         (struct powerdomain *)data, (int)val);
204         return -EINVAL;
205 }
206
207 DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
208                         pwrdm_suspend_set, "%llu\n");
209
210 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
211 {
212         struct dentry *d;
213
214 #ifdef CONFIG_PM_DEBUG
215         int i;
216         s64 t;
217
218         t = sched_clock();
219
220         for (i = 0; i < 4; i++)
221                 pwrdm->state_timer[i] = 0;
222
223         pwrdm->timer = t;
224 #endif
225
226         if (strncmp(pwrdm->name, "dpll", 4) == 0)
227                 return 0;
228
229         d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
230         if (!(IS_ERR_OR_NULL(d)))
231                 (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
232                         (void *)pwrdm, &pwrdm_suspend_fops);
233
234         return 0;
235 }
236
237 static int option_get(void *data, u64 *val)
238 {
239         u32 *option = data;
240
241         *val = *option;
242
243         return 0;
244 }
245
246 static int option_set(void *data, u64 val)
247 {
248         u32 *option = data;
249
250         *option = val;
251
252         if (option == &enable_off_mode) {
253                 if (val)
254                         omap_pm_enable_off_mode();
255                 else
256                         omap_pm_disable_off_mode();
257                 if (cpu_is_omap34xx())
258                         omap3_pm_off_mode_enable(val);
259         }
260
261         return 0;
262 }
263
264 DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
265
266 static int __init pm_dbg_init(void)
267 {
268         struct dentry *d;
269
270         if (pm_dbg_init_done)
271                 return 0;
272
273         d = debugfs_create_dir("pm_debug", NULL);
274         if (IS_ERR_OR_NULL(d))
275                 return PTR_ERR(d);
276
277         (void) debugfs_create_file("count", S_IRUGO,
278                 d, (void *)DEBUG_FILE_COUNTERS, &debug_fops);
279         (void) debugfs_create_file("time", S_IRUGO,
280                 d, (void *)DEBUG_FILE_TIMERS, &debug_fops);
281
282         pwrdm_for_each(pwrdms_setup, (void *)d);
283
284         (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
285                                    &enable_off_mode, &pm_dbg_option_fops);
286         pm_dbg_init_done = 1;
287
288         return 0;
289 }
290 arch_initcall(pm_dbg_init);
291
292 #endif