2 * OMAP Power Management debug routines
4 * Copyright (C) 2005 Texas Instruments, Inc.
5 * Copyright (C) 2006-2008 Nokia Corporation
8 * Richard Woodruff <r-woodruff2@ti.com>
11 * Amit Kucheria <amit.kucheria@nokia.com>
12 * Igor Stoppa <igor.stoppa@nokia.com>
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>
27 #include <linux/module.h>
28 #include <linux/slab.h>
30 #include <plat/clock.h>
31 #include "powerdomain.h"
32 #include "clockdomain.h"
33 #include <plat/dmtimer.h>
34 #include <plat/omap-pm.h>
36 #include "cm2xxx_3xxx.h"
37 #include "prm2xxx_3xxx.h"
42 #ifdef CONFIG_DEBUG_FS
43 #include <linux/debugfs.h>
44 #include <linux/seq_file.h>
46 static int pm_dbg_init_done;
48 static int pm_dbg_init(void);
51 DEBUG_FILE_COUNTERS = 0,
55 static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
62 void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
66 if (!pm_dbg_init_done)
69 /* Update timer for previous state */
72 pwrdm->state_timer[prev] += t - pwrdm->timer;
77 static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
79 struct seq_file *s = (struct seq_file *)user;
81 if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
82 strcmp(clkdm->name, "wkup_clkdm") == 0 ||
83 strncmp(clkdm->name, "dpll", 4) == 0)
86 seq_printf(s, "%s->%s (%d)", clkdm->name,
87 clkdm->pwrdm.ptr->name,
88 atomic_read(&clkdm->usecount));
94 static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
96 struct seq_file *s = (struct seq_file *)user;
99 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
100 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
101 strncmp(pwrdm->name, "dpll", 4) == 0)
104 if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
105 printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
106 pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
108 seq_printf(s, "%s (%s)", pwrdm->name,
109 pwrdm_state_names[pwrdm->state]);
110 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
111 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
112 pwrdm->state_counter[i]);
114 seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
115 for (i = 0; i < pwrdm->banks; i++)
116 seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
117 pwrdm->ret_mem_off_counter[i]);
124 static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
126 struct seq_file *s = (struct seq_file *)user;
129 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
130 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
131 strncmp(pwrdm->name, "dpll", 4) == 0)
134 pwrdm_state_switch(pwrdm);
136 seq_printf(s, "%s (%s)", pwrdm->name,
137 pwrdm_state_names[pwrdm->state]);
139 for (i = 0; i < 4; i++)
140 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
141 pwrdm->state_timer[i]);
147 static int pm_dbg_show_counters(struct seq_file *s, void *unused)
149 pwrdm_for_each(pwrdm_dbg_show_counter, s);
150 clkdm_for_each(clkdm_dbg_show_counter, s);
155 static int pm_dbg_show_timers(struct seq_file *s, void *unused)
157 pwrdm_for_each(pwrdm_dbg_show_timer, s);
161 static int pm_dbg_open(struct inode *inode, struct file *file)
163 switch ((int)inode->i_private) {
164 case DEBUG_FILE_COUNTERS:
165 return single_open(file, pm_dbg_show_counters,
167 case DEBUG_FILE_TIMERS:
169 return single_open(file, pm_dbg_show_timers,
174 static const struct file_operations debug_fops = {
178 .release = single_release,
181 static int pwrdm_suspend_get(void *data, u64 *val)
185 if (cpu_is_omap34xx())
186 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
194 static int pwrdm_suspend_set(void *data, u64 val)
196 if (cpu_is_omap34xx())
197 return omap3_pm_set_suspend_state(
198 (struct powerdomain *)data, (int)val);
202 DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
203 pwrdm_suspend_set, "%llu\n");
205 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
213 for (i = 0; i < 4; i++)
214 pwrdm->state_timer[i] = 0;
218 if (strncmp(pwrdm->name, "dpll", 4) == 0)
221 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
222 if (!(IS_ERR_OR_NULL(d)))
223 (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
224 (void *)pwrdm, &pwrdm_suspend_fops);
229 static int option_get(void *data, u64 *val)
238 static int option_set(void *data, u64 val)
244 if (option == &enable_off_mode) {
246 omap_pm_enable_off_mode();
248 omap_pm_disable_off_mode();
249 if (cpu_is_omap34xx())
250 omap3_pm_off_mode_enable(val);
256 DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
258 static int __init pm_dbg_init(void)
262 if (pm_dbg_init_done)
265 d = debugfs_create_dir("pm_debug", NULL);
266 if (IS_ERR_OR_NULL(d))
269 (void) debugfs_create_file("count", S_IRUGO,
270 d, (void *)DEBUG_FILE_COUNTERS, &debug_fops);
271 (void) debugfs_create_file("time", S_IRUGO,
272 d, (void *)DEBUG_FILE_TIMERS, &debug_fops);
274 pwrdm_for_each(pwrdms_setup, (void *)d);
276 (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
277 &enable_off_mode, &pm_dbg_option_fops);
278 pm_dbg_init_done = 1;
282 arch_initcall(pm_dbg_init);