OMAP2+: PM: fix section mismatch in pm_dbg_init()
[linux-2.6/kvm.git] / arch / arm / mach-omap2 / pm-debug.c
blob3feb475bd14d17192f71bf9b1d924228c162cff4
1 /*
2 * OMAP Power Management debug routines
4 * Copyright (C) 2005 Texas Instruments, Inc.
5 * Copyright (C) 2006-2008 Nokia Corporation
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
15 * Based on pm.c for omap2
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.
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>
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>
37 #include "cm2xxx_3xxx.h"
38 #include "prm2xxx_3xxx.h"
39 #include "pm.h"
41 u32 enable_off_mode;
42 u32 wakeup_timer_seconds;
43 u32 wakeup_timer_milliseconds;
45 void omap2_pm_wakeup_on_timer(u32 seconds, u32 milliseconds)
47 u32 tick_rate, cycles;
49 if (!seconds && !milliseconds)
50 return;
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);
57 pr_info("PM: Resume timer in %u.%03u secs"
58 " (%d ticks at %d ticks/sec.)\n",
59 seconds, milliseconds, cycles, tick_rate);
62 #ifdef CONFIG_DEBUG_FS
63 #include <linux/debugfs.h>
64 #include <linux/seq_file.h>
66 static int pm_dbg_init_done;
68 static int pm_dbg_init(void);
70 enum {
71 DEBUG_FILE_COUNTERS = 0,
72 DEBUG_FILE_TIMERS,
75 static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
76 "OFF",
77 "RET",
78 "INA",
79 "ON"
82 void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
84 s64 t;
86 if (!pm_dbg_init_done)
87 return ;
89 /* Update timer for previous state */
90 t = sched_clock();
92 pwrdm->state_timer[prev] += t - pwrdm->timer;
94 pwrdm->timer = t;
97 static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
99 struct seq_file *s = (struct seq_file *)user;
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;
106 seq_printf(s, "%s->%s (%d)", clkdm->name,
107 clkdm->pwrdm.ptr->name,
108 atomic_read(&clkdm->usecount));
109 seq_printf(s, "\n");
111 return 0;
114 static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
116 struct seq_file *s = (struct seq_file *)user;
117 int i;
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;
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));
128 seq_printf(s, "%s (%s)", pwrdm->name,
129 pwrdm_state_names[pwrdm->state]);
130 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
131 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
132 pwrdm->state_counter[i]);
134 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]);
139 seq_printf(s, "\n");
141 return 0;
144 static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
146 struct seq_file *s = (struct seq_file *)user;
147 int i;
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;
154 pwrdm_state_switch(pwrdm);
156 seq_printf(s, "%s (%s)", pwrdm->name,
157 pwrdm_state_names[pwrdm->state]);
159 for (i = 0; i < 4; i++)
160 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
161 pwrdm->state_timer[i]);
163 seq_printf(s, "\n");
164 return 0;
167 static int pm_dbg_show_counters(struct seq_file *s, void *unused)
169 pwrdm_for_each(pwrdm_dbg_show_counter, s);
170 clkdm_for_each(clkdm_dbg_show_counter, s);
172 return 0;
175 static int pm_dbg_show_timers(struct seq_file *s, void *unused)
177 pwrdm_for_each(pwrdm_dbg_show_timer, s);
178 return 0;
181 static int pm_dbg_open(struct inode *inode, struct file *file)
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);
194 static const struct file_operations debug_fops = {
195 .open = pm_dbg_open,
196 .read = seq_read,
197 .llseek = seq_lseek,
198 .release = single_release,
201 static int pwrdm_suspend_get(void *data, u64 *val)
203 int ret = -EINVAL;
205 if (cpu_is_omap34xx())
206 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
207 *val = ret;
209 if (ret >= 0)
210 return 0;
211 return *val;
214 static int pwrdm_suspend_set(void *data, u64 val)
216 if (cpu_is_omap34xx())
217 return omap3_pm_set_suspend_state(
218 (struct powerdomain *)data, (int)val);
219 return -EINVAL;
222 DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
223 pwrdm_suspend_set, "%llu\n");
225 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
227 int i;
228 s64 t;
229 struct dentry *d;
231 t = sched_clock();
233 for (i = 0; i < 4; i++)
234 pwrdm->state_timer[i] = 0;
236 pwrdm->timer = t;
238 if (strncmp(pwrdm->name, "dpll", 4) == 0)
239 return 0;
241 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
243 (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
244 (void *)pwrdm, &pwrdm_suspend_fops);
246 return 0;
249 static int option_get(void *data, u64 *val)
251 u32 *option = data;
253 *val = *option;
255 return 0;
258 static int option_set(void *data, u64 val)
260 u32 *option = data;
262 if (option == &wakeup_timer_milliseconds && val >= 1000)
263 return -EINVAL;
265 *option = val;
267 if (option == &enable_off_mode) {
268 if (val)
269 omap_pm_enable_off_mode();
270 else
271 omap_pm_disable_off_mode();
272 if (cpu_is_omap34xx())
273 omap3_pm_off_mode_enable(val);
276 return 0;
279 DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
281 static int __init pm_dbg_init(void)
283 struct dentry *d;
285 if (pm_dbg_init_done)
286 return 0;
288 d = debugfs_create_dir("pm_debug", NULL);
289 if (IS_ERR(d))
290 return PTR_ERR(d);
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);
297 pwrdm_for_each(pwrdms_setup, (void *)d);
299 (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
300 &enable_off_mode, &pm_dbg_option_fops);
301 (void) debugfs_create_file("wakeup_timer_seconds", S_IRUGO | S_IWUSR, d,
302 &wakeup_timer_seconds, &pm_dbg_option_fops);
303 (void) debugfs_create_file("wakeup_timer_milliseconds",
304 S_IRUGO | S_IWUSR, d, &wakeup_timer_milliseconds,
305 &pm_dbg_option_fops);
306 pm_dbg_init_done = 1;
308 return 0;
310 arch_initcall(pm_dbg_init);
312 #endif