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 <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"
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
)
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);
71 DEBUG_FILE_COUNTERS
= 0,
75 static const char pwrdm_state_names
[][PWRDM_MAX_PWRSTS
] = {
82 void pm_dbg_update_time(struct powerdomain
*pwrdm
, int prev
)
86 if (!pm_dbg_init_done
)
89 /* Update timer for previous state */
92 pwrdm
->state_timer
[prev
] += t
- pwrdm
->timer
;
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)
106 seq_printf(s
, "%s->%s (%d)", clkdm
->name
,
107 clkdm
->pwrdm
.ptr
->name
,
108 atomic_read(&clkdm
->usecount
));
114 static int pwrdm_dbg_show_counter(struct powerdomain
*pwrdm
, void *user
)
116 struct seq_file
*s
= (struct seq_file
*)user
;
119 if (strcmp(pwrdm
->name
, "emu_pwrdm") == 0 ||
120 strcmp(pwrdm
->name
, "wkup_pwrdm") == 0 ||
121 strncmp(pwrdm
->name
, "dpll", 4) == 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
]);
144 static int pwrdm_dbg_show_timer(struct powerdomain
*pwrdm
, void *user
)
146 struct seq_file
*s
= (struct seq_file
*)user
;
149 if (strcmp(pwrdm
->name
, "emu_pwrdm") == 0 ||
150 strcmp(pwrdm
->name
, "wkup_pwrdm") == 0 ||
151 strncmp(pwrdm
->name
, "dpll", 4) == 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
]);
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
);
175 static int pm_dbg_show_timers(struct seq_file
*s
, void *unused
)
177 pwrdm_for_each(pwrdm_dbg_show_timer
, s
);
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
,
187 case DEBUG_FILE_TIMERS
:
189 return single_open(file
, pm_dbg_show_timers
,
194 static const struct file_operations debug_fops
= {
198 .release
= single_release
,
201 static int pwrdm_suspend_get(void *data
, u64
*val
)
205 if (cpu_is_omap34xx())
206 ret
= omap3_pm_get_suspend_state((struct powerdomain
*)data
);
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
);
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
)
233 for (i
= 0; i
< 4; i
++)
234 pwrdm
->state_timer
[i
] = 0;
238 if (strncmp(pwrdm
->name
, "dpll", 4) == 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
);
249 static int option_get(void *data
, u64
*val
)
258 static int option_set(void *data
, u64 val
)
262 if (option
== &wakeup_timer_milliseconds
&& val
>= 1000)
267 if (option
== &enable_off_mode
) {
269 omap_pm_enable_off_mode();
271 omap_pm_disable_off_mode();
272 if (cpu_is_omap34xx())
273 omap3_pm_off_mode_enable(val
);
279 DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops
, option_get
, option_set
, "%llu\n");
281 static int __init
pm_dbg_init(void)
285 if (pm_dbg_init_done
)
288 d
= debugfs_create_dir("pm_debug", NULL
);
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;
310 arch_initcall(pm_dbg_init
);