Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / arm / mach-omap2 / pm-debug.c
blob5c46ea6756d7b1dcbe8e6a6afd9cddc556880e04
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/sched/clock.h>
25 #include <linux/clk.h>
26 #include <linux/err.h>
27 #include <linux/io.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
31 #include "clock.h"
32 #include "powerdomain.h"
33 #include "clockdomain.h"
34 #include "omap-pm.h"
36 #include "soc.h"
37 #include "cm2xxx_3xxx.h"
38 #include "prm2xxx_3xxx.h"
39 #include "pm.h"
41 u32 enable_off_mode;
43 #ifdef CONFIG_DEBUG_FS
44 #include <linux/debugfs.h>
45 #include <linux/seq_file.h>
47 static int pm_dbg_init_done;
49 static int pm_dbg_init(void);
51 enum {
52 DEBUG_FILE_COUNTERS = 0,
53 DEBUG_FILE_TIMERS,
56 static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
57 "OFF",
58 "RET",
59 "INA",
60 "ON"
63 void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
65 s64 t;
67 if (!pm_dbg_init_done)
68 return ;
70 /* Update timer for previous state */
71 t = sched_clock();
73 pwrdm->state_timer[prev] += t - pwrdm->timer;
75 pwrdm->timer = t;
78 static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
80 struct seq_file *s = (struct seq_file *)user;
82 if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
83 strcmp(clkdm->name, "wkup_clkdm") == 0 ||
84 strncmp(clkdm->name, "dpll", 4) == 0)
85 return 0;
87 seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name,
88 clkdm->usecount);
90 return 0;
93 static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
95 struct seq_file *s = (struct seq_file *)user;
96 int i;
98 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
99 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
100 strncmp(pwrdm->name, "dpll", 4) == 0)
101 return 0;
103 if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
104 printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
105 pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
107 seq_printf(s, "%s (%s)", pwrdm->name,
108 pwrdm_state_names[pwrdm->state]);
109 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
110 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
111 pwrdm->state_counter[i]);
113 seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
114 for (i = 0; i < pwrdm->banks; i++)
115 seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
116 pwrdm->ret_mem_off_counter[i]);
118 seq_putc(s, '\n');
119 return 0;
122 static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
124 struct seq_file *s = (struct seq_file *)user;
125 int i;
127 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
128 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
129 strncmp(pwrdm->name, "dpll", 4) == 0)
130 return 0;
132 pwrdm_state_switch(pwrdm);
134 seq_printf(s, "%s (%s)", pwrdm->name,
135 pwrdm_state_names[pwrdm->state]);
137 for (i = 0; i < 4; i++)
138 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
139 pwrdm->state_timer[i]);
141 seq_putc(s, '\n');
142 return 0;
145 static int pm_dbg_show_counters(struct seq_file *s, void *unused)
147 pwrdm_for_each(pwrdm_dbg_show_counter, s);
148 clkdm_for_each(clkdm_dbg_show_counter, s);
150 return 0;
153 static int pm_dbg_show_timers(struct seq_file *s, void *unused)
155 pwrdm_for_each(pwrdm_dbg_show_timer, s);
156 return 0;
159 static int pm_dbg_open(struct inode *inode, struct file *file)
161 switch ((int)inode->i_private) {
162 case DEBUG_FILE_COUNTERS:
163 return single_open(file, pm_dbg_show_counters,
164 &inode->i_private);
165 case DEBUG_FILE_TIMERS:
166 default:
167 return single_open(file, pm_dbg_show_timers,
168 &inode->i_private);
172 static const struct file_operations debug_fops = {
173 .open = pm_dbg_open,
174 .read = seq_read,
175 .llseek = seq_lseek,
176 .release = single_release,
179 static int pwrdm_suspend_get(void *data, u64 *val)
181 int ret = -EINVAL;
183 if (cpu_is_omap34xx())
184 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
185 *val = ret;
187 if (ret >= 0)
188 return 0;
189 return *val;
192 static int pwrdm_suspend_set(void *data, u64 val)
194 if (cpu_is_omap34xx())
195 return omap3_pm_set_suspend_state(
196 (struct powerdomain *)data, (int)val);
197 return -EINVAL;
200 DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
201 pwrdm_suspend_set, "%llu\n");
203 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
205 int i;
206 s64 t;
207 struct dentry *d;
209 t = sched_clock();
211 for (i = 0; i < 4; i++)
212 pwrdm->state_timer[i] = 0;
214 pwrdm->timer = t;
216 if (strncmp(pwrdm->name, "dpll", 4) == 0)
217 return 0;
219 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
220 if (d)
221 (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
222 (void *)pwrdm, &pwrdm_suspend_fops);
224 return 0;
227 static int option_get(void *data, u64 *val)
229 u32 *option = data;
231 *val = *option;
233 return 0;
236 static int option_set(void *data, u64 val)
238 u32 *option = data;
240 *option = val;
242 if (option == &enable_off_mode) {
243 if (val)
244 omap_pm_enable_off_mode();
245 else
246 omap_pm_disable_off_mode();
247 if (cpu_is_omap34xx())
248 omap3_pm_off_mode_enable(val);
251 return 0;
254 DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
256 static int __init pm_dbg_init(void)
258 struct dentry *d;
260 if (pm_dbg_init_done)
261 return 0;
263 d = debugfs_create_dir("pm_debug", NULL);
264 if (!d)
265 return -EINVAL;
267 (void) debugfs_create_file("count", S_IRUGO,
268 d, (void *)DEBUG_FILE_COUNTERS, &debug_fops);
269 (void) debugfs_create_file("time", S_IRUGO,
270 d, (void *)DEBUG_FILE_TIMERS, &debug_fops);
272 pwrdm_for_each(pwrdms_setup, (void *)d);
274 (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
275 &enable_off_mode, &pm_dbg_option_fops);
276 pm_dbg_init_done = 1;
278 return 0;
280 omap_arch_initcall(pm_dbg_init);
282 #endif