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>
29 #include <mach/clock.h>
30 #include <mach/board.h>
31 #include <mach/powerdomain.h>
32 #include <mach/clockdomain.h>
40 #define DUMP_PRM_MOD_REG(mod, reg) \
41 regs[reg_count].name = #mod "." #reg; \
42 regs[reg_count++].val = prm_read_mod_reg(mod, reg)
43 #define DUMP_CM_MOD_REG(mod, reg) \
44 regs[reg_count].name = #mod "." #reg; \
45 regs[reg_count++].val = cm_read_mod_reg(mod, reg)
46 #define DUMP_PRM_REG(reg) \
47 regs[reg_count].name = #reg; \
48 regs[reg_count++].val = __raw_readl(reg)
49 #define DUMP_CM_REG(reg) \
50 regs[reg_count].name = #reg; \
51 regs[reg_count++].val = __raw_readl(reg)
52 #define DUMP_INTC_REG(reg, off) \
53 regs[reg_count].name = #reg; \
54 regs[reg_count++].val = __raw_readl(OMAP2_IO_ADDRESS(0x480fe000 + (off)))
56 static int __init
pm_dbg_init(void);
58 void omap2_pm_dump(int mode
, int resume
, unsigned int us
)
65 const char *s1
= NULL
, *s2
= NULL
;
70 DUMP_PRM_MOD_REG(OCP_MOD
, OMAP2_PRM_IRQENABLE_MPU_OFFSET
);
71 DUMP_CM_MOD_REG(MPU_MOD
, CM_CLKSTCTRL
);
72 DUMP_PRM_MOD_REG(MPU_MOD
, PM_PWSTCTRL
);
73 DUMP_PRM_MOD_REG(MPU_MOD
, PM_PWSTST
);
74 DUMP_PRM_MOD_REG(MPU_MOD
, PM_WKDEP
);
78 DUMP_INTC_REG(INTC_MIR0
, 0x0084);
79 DUMP_INTC_REG(INTC_MIR1
, 0x00a4);
80 DUMP_INTC_REG(INTC_MIR2
, 0x00c4);
83 DUMP_CM_MOD_REG(CORE_MOD
, CM_FCLKEN1
);
84 if (cpu_is_omap24xx()) {
85 DUMP_CM_MOD_REG(CORE_MOD
, OMAP24XX_CM_FCLKEN2
);
86 DUMP_PRM_MOD_REG(OMAP24XX_GR_MOD
,
87 OMAP2_PRCM_CLKEMUL_CTRL_OFFSET
);
88 DUMP_PRM_MOD_REG(OMAP24XX_GR_MOD
,
89 OMAP2_PRCM_CLKSRC_CTRL_OFFSET
);
91 DUMP_CM_MOD_REG(WKUP_MOD
, CM_FCLKEN
);
92 DUMP_CM_MOD_REG(CORE_MOD
, CM_ICLKEN1
);
93 DUMP_CM_MOD_REG(CORE_MOD
, CM_ICLKEN2
);
94 DUMP_CM_MOD_REG(WKUP_MOD
, CM_ICLKEN
);
95 DUMP_CM_MOD_REG(PLL_MOD
, CM_CLKEN
);
96 DUMP_CM_MOD_REG(PLL_MOD
, CM_AUTOIDLE
);
97 DUMP_PRM_MOD_REG(CORE_MOD
, PM_PWSTST
);
101 if (cpu_is_omap24xx()) {
102 DUMP_CM_MOD_REG(OMAP24XX_DSP_MOD
, CM_FCLKEN
);
103 DUMP_CM_MOD_REG(OMAP24XX_DSP_MOD
, CM_ICLKEN
);
104 DUMP_CM_MOD_REG(OMAP24XX_DSP_MOD
, CM_IDLEST
);
105 DUMP_CM_MOD_REG(OMAP24XX_DSP_MOD
, CM_AUTOIDLE
);
106 DUMP_CM_MOD_REG(OMAP24XX_DSP_MOD
, CM_CLKSEL
);
107 DUMP_CM_MOD_REG(OMAP24XX_DSP_MOD
, CM_CLKSTCTRL
);
108 DUMP_PRM_MOD_REG(OMAP24XX_DSP_MOD
, RM_RSTCTRL
);
109 DUMP_PRM_MOD_REG(OMAP24XX_DSP_MOD
, RM_RSTST
);
110 DUMP_PRM_MOD_REG(OMAP24XX_DSP_MOD
, PM_PWSTCTRL
);
111 DUMP_PRM_MOD_REG(OMAP24XX_DSP_MOD
, PM_PWSTST
);
115 DUMP_PRM_MOD_REG(CORE_MOD
, PM_WKST1
);
116 if (cpu_is_omap24xx())
117 DUMP_PRM_MOD_REG(CORE_MOD
, OMAP24XX_PM_WKST2
);
118 DUMP_PRM_MOD_REG(WKUP_MOD
, PM_WKST
);
119 DUMP_PRM_MOD_REG(OCP_MOD
, OMAP2_PRCM_IRQSTATUS_MPU_OFFSET
);
121 DUMP_INTC_REG(INTC_PENDING_IRQ0
, 0x0098);
122 DUMP_INTC_REG(INTC_PENDING_IRQ1
, 0x00b8);
123 DUMP_INTC_REG(INTC_PENDING_IRQ2
, 0x00d8);
145 "--- Going to %s %s (next timer after %u ms)\n", s1
, s2
,
146 jiffies_to_msecs(get_next_timer_interrupt(jiffies
) -
149 printk(KERN_INFO
"--- Going to %s %s\n", s1
, s2
);
152 printk(KERN_INFO
"--- Woke up (slept for %u.%03u ms)\n",
153 us
/ 1000, us
% 1000);
155 for (i
= 0; i
< reg_count
; i
++)
156 printk(KERN_INFO
"%-20s: 0x%08x\n", regs
[i
].name
, regs
[i
].val
);
159 #ifdef CONFIG_DEBUG_FS
160 #include <linux/debugfs.h>
161 #include <linux/seq_file.h>
163 static void pm_dbg_regset_store(u32
*ptr
);
165 struct dentry
*pm_dbg_dir
;
167 static int pm_dbg_init_done
;
170 DEBUG_FILE_COUNTERS
= 0,
174 struct pm_module_def
{
175 char name
[8]; /* Name of the module */
176 short type
; /* CM or PRM */
177 unsigned short offset
;
178 int low
; /* First register address on this module */
179 int high
; /* Last register address on this module */
185 static const struct pm_module_def
*pm_dbg_reg_modules
;
186 static const struct pm_module_def omap3_pm_reg_modules
[] = {
187 { "IVA2", MOD_CM
, OMAP3430_IVA2_MOD
, 0, 0x4c },
188 { "OCP", MOD_CM
, OCP_MOD
, 0, 0x10 },
189 { "MPU", MOD_CM
, MPU_MOD
, 4, 0x4c },
190 { "CORE", MOD_CM
, CORE_MOD
, 0, 0x4c },
191 { "SGX", MOD_CM
, OMAP3430ES2_SGX_MOD
, 0, 0x4c },
192 { "WKUP", MOD_CM
, WKUP_MOD
, 0, 0x40 },
193 { "CCR", MOD_CM
, PLL_MOD
, 0, 0x70 },
194 { "DSS", MOD_CM
, OMAP3430_DSS_MOD
, 0, 0x4c },
195 { "CAM", MOD_CM
, OMAP3430_CAM_MOD
, 0, 0x4c },
196 { "PER", MOD_CM
, OMAP3430_PER_MOD
, 0, 0x4c },
197 { "EMU", MOD_CM
, OMAP3430_EMU_MOD
, 0x40, 0x54 },
198 { "NEON", MOD_CM
, OMAP3430_NEON_MOD
, 0x20, 0x48 },
199 { "USB", MOD_CM
, OMAP3430ES2_USBHOST_MOD
, 0, 0x4c },
201 { "IVA2", MOD_PRM
, OMAP3430_IVA2_MOD
, 0x50, 0xfc },
202 { "OCP", MOD_PRM
, OCP_MOD
, 4, 0x1c },
203 { "MPU", MOD_PRM
, MPU_MOD
, 0x58, 0xe8 },
204 { "CORE", MOD_PRM
, CORE_MOD
, 0x58, 0xf8 },
205 { "SGX", MOD_PRM
, OMAP3430ES2_SGX_MOD
, 0x58, 0xe8 },
206 { "WKUP", MOD_PRM
, WKUP_MOD
, 0xa0, 0xb0 },
207 { "CCR", MOD_PRM
, PLL_MOD
, 0x40, 0x70 },
208 { "DSS", MOD_PRM
, OMAP3430_DSS_MOD
, 0x58, 0xe8 },
209 { "CAM", MOD_PRM
, OMAP3430_CAM_MOD
, 0x58, 0xe8 },
210 { "PER", MOD_PRM
, OMAP3430_PER_MOD
, 0x58, 0xe8 },
211 { "EMU", MOD_PRM
, OMAP3430_EMU_MOD
, 0x58, 0xe4 },
212 { "GLBL", MOD_PRM
, OMAP3430_GR_MOD
, 0x20, 0xe4 },
213 { "NEON", MOD_PRM
, OMAP3430_NEON_MOD
, 0x58, 0xe8 },
214 { "USB", MOD_PRM
, OMAP3430ES2_USBHOST_MOD
, 0x58, 0xe8 },
218 #define PM_DBG_MAX_REG_SETS 4
220 static void *pm_dbg_reg_set
[PM_DBG_MAX_REG_SETS
];
222 static int pm_dbg_get_regset_size(void)
224 static int regset_size
;
226 if (regset_size
== 0) {
229 while (pm_dbg_reg_modules
[i
].name
[0] != 0) {
230 regset_size
+= pm_dbg_reg_modules
[i
].high
+
231 4 - pm_dbg_reg_modules
[i
].low
;
238 static int pm_dbg_show_regs(struct seq_file
*s
, void *unused
)
242 int reg_set
= (int)s
->private;
249 store
= kmalloc(pm_dbg_get_regset_size(), GFP_KERNEL
);
251 pm_dbg_regset_store(ptr
);
253 ptr
= pm_dbg_reg_set
[reg_set
- 1];
258 while (pm_dbg_reg_modules
[i
].name
[0] != 0) {
261 if (pm_dbg_reg_modules
[i
].type
== MOD_CM
)
262 seq_printf(s
, "MOD: CM_%s (%08x)\n",
263 pm_dbg_reg_modules
[i
].name
,
264 (u32
)(OMAP3430_CM_BASE
+
265 pm_dbg_reg_modules
[i
].offset
));
267 seq_printf(s
, "MOD: PRM_%s (%08x)\n",
268 pm_dbg_reg_modules
[i
].name
,
269 (u32
)(OMAP3430_PRM_BASE
+
270 pm_dbg_reg_modules
[i
].offset
));
272 for (j
= pm_dbg_reg_modules
[i
].low
;
273 j
<= pm_dbg_reg_modules
[i
].high
; j
+= 4) {
281 seq_printf(s
, " %02x => %08lx", j
, val
);
296 static void pm_dbg_regset_store(u32
*ptr
)
303 while (pm_dbg_reg_modules
[i
].name
[0] != 0) {
304 for (j
= pm_dbg_reg_modules
[i
].low
;
305 j
<= pm_dbg_reg_modules
[i
].high
; j
+= 4) {
306 if (pm_dbg_reg_modules
[i
].type
== MOD_CM
)
307 val
= cm_read_mod_reg(
308 pm_dbg_reg_modules
[i
].offset
, j
);
310 val
= prm_read_mod_reg(
311 pm_dbg_reg_modules
[i
].offset
, j
);
318 int pm_dbg_regset_save(int reg_set
)
320 if (pm_dbg_reg_set
[reg_set
-1] == NULL
)
323 pm_dbg_regset_store(pm_dbg_reg_set
[reg_set
-1]);
328 static const char pwrdm_state_names
[][4] = {
335 void pm_dbg_update_time(struct powerdomain
*pwrdm
, int prev
)
339 if (!pm_dbg_init_done
)
342 /* Update timer for previous state */
345 pwrdm
->state_timer
[prev
] += t
- pwrdm
->timer
;
350 static int clkdm_dbg_show_counter(struct clockdomain
*clkdm
, void *user
)
352 struct seq_file
*s
= (struct seq_file
*)user
;
354 if (strcmp(clkdm
->name
, "emu_clkdm") == 0 ||
355 strcmp(clkdm
->name
, "wkup_clkdm") == 0 ||
356 strncmp(clkdm
->name
, "dpll", 4) == 0)
359 seq_printf(s
, "%s->%s (%d)", clkdm
->name
,
360 clkdm
->pwrdm
.ptr
->name
,
361 atomic_read(&clkdm
->usecount
));
367 static int pwrdm_dbg_show_counter(struct powerdomain
*pwrdm
, void *user
)
369 struct seq_file
*s
= (struct seq_file
*)user
;
372 if (strcmp(pwrdm
->name
, "emu_pwrdm") == 0 ||
373 strcmp(pwrdm
->name
, "wkup_pwrdm") == 0 ||
374 strncmp(pwrdm
->name
, "dpll", 4) == 0)
377 if (pwrdm
->state
!= pwrdm_read_pwrst(pwrdm
))
378 printk(KERN_ERR
"pwrdm state mismatch(%s) %d != %d\n",
379 pwrdm
->name
, pwrdm
->state
, pwrdm_read_pwrst(pwrdm
));
381 seq_printf(s
, "%s (%s)", pwrdm
->name
,
382 pwrdm_state_names
[pwrdm
->state
]);
383 for (i
= 0; i
< 4; i
++)
384 seq_printf(s
, ",%s:%d", pwrdm_state_names
[i
],
385 pwrdm
->state_counter
[i
]);
392 static int pwrdm_dbg_show_timer(struct powerdomain
*pwrdm
, void *user
)
394 struct seq_file
*s
= (struct seq_file
*)user
;
397 if (strcmp(pwrdm
->name
, "emu_pwrdm") == 0 ||
398 strcmp(pwrdm
->name
, "wkup_pwrdm") == 0 ||
399 strncmp(pwrdm
->name
, "dpll", 4) == 0)
402 pwrdm_state_switch(pwrdm
);
404 seq_printf(s
, "%s (%s)", pwrdm
->name
,
405 pwrdm_state_names
[pwrdm
->state
]);
407 for (i
= 0; i
< 4; i
++)
408 seq_printf(s
, ",%s:%lld", pwrdm_state_names
[i
],
409 pwrdm
->state_timer
[i
]);
415 static int pm_dbg_show_counters(struct seq_file
*s
, void *unused
)
417 pwrdm_for_each(pwrdm_dbg_show_counter
, s
);
418 clkdm_for_each(clkdm_dbg_show_counter
, s
);
423 static int pm_dbg_show_timers(struct seq_file
*s
, void *unused
)
425 pwrdm_for_each(pwrdm_dbg_show_timer
, s
);
429 static int pm_dbg_open(struct inode
*inode
, struct file
*file
)
431 switch ((int)inode
->i_private
) {
432 case DEBUG_FILE_COUNTERS
:
433 return single_open(file
, pm_dbg_show_counters
,
435 case DEBUG_FILE_TIMERS
:
437 return single_open(file
, pm_dbg_show_timers
,
442 static int pm_dbg_reg_open(struct inode
*inode
, struct file
*file
)
444 return single_open(file
, pm_dbg_show_regs
, inode
->i_private
);
447 static const struct file_operations debug_fops
= {
451 .release
= single_release
,
454 static const struct file_operations debug_reg_fops
= {
455 .open
= pm_dbg_reg_open
,
458 .release
= single_release
,
461 int pm_dbg_regset_init(int reg_set
)
465 if (!pm_dbg_init_done
)
468 if (reg_set
< 1 || reg_set
> PM_DBG_MAX_REG_SETS
||
469 pm_dbg_reg_set
[reg_set
-1] != NULL
)
472 pm_dbg_reg_set
[reg_set
-1] =
473 kmalloc(pm_dbg_get_regset_size(), GFP_KERNEL
);
475 if (pm_dbg_reg_set
[reg_set
-1] == NULL
)
478 if (pm_dbg_dir
!= NULL
) {
479 sprintf(name
, "%d", reg_set
);
481 (void) debugfs_create_file(name
, S_IRUGO
,
482 pm_dbg_dir
, (void *)reg_set
, &debug_reg_fops
);
488 static int pwrdm_suspend_get(void *data
, u64
*val
)
490 *val
= omap3_pm_get_suspend_state((struct powerdomain
*)data
);
497 static int pwrdm_suspend_set(void *data
, u64 val
)
499 return omap3_pm_set_suspend_state((struct powerdomain
*)data
, (int)val
);
502 DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops
, pwrdm_suspend_get
,
503 pwrdm_suspend_set
, "%llu\n");
505 static int __init
pwrdms_setup(struct powerdomain
*pwrdm
, void *dir
)
513 for (i
= 0; i
< 4; i
++)
514 pwrdm
->state_timer
[i
] = 0;
518 if (strncmp(pwrdm
->name
, "dpll", 4) == 0)
521 d
= debugfs_create_dir(pwrdm
->name
, (struct dentry
*)dir
);
523 (void) debugfs_create_file("suspend", S_IRUGO
|S_IWUSR
, d
,
524 (void *)pwrdm
, &pwrdm_suspend_fops
);
529 static int __init
pm_dbg_init(void)
535 if (pm_dbg_init_done
)
538 if (cpu_is_omap34xx())
539 pm_dbg_reg_modules
= omap3_pm_reg_modules
;
541 printk(KERN_ERR
"%s: only OMAP3 supported\n", __func__
);
545 d
= debugfs_create_dir("pm_debug", NULL
);
549 (void) debugfs_create_file("count", S_IRUGO
,
550 d
, (void *)DEBUG_FILE_COUNTERS
, &debug_fops
);
551 (void) debugfs_create_file("time", S_IRUGO
,
552 d
, (void *)DEBUG_FILE_TIMERS
, &debug_fops
);
554 pwrdm_for_each_nolock(pwrdms_setup
, (void *)d
);
556 pm_dbg_dir
= debugfs_create_dir("registers", d
);
557 if (IS_ERR(pm_dbg_dir
))
558 return PTR_ERR(pm_dbg_dir
);
560 (void) debugfs_create_file("current", S_IRUGO
,
561 pm_dbg_dir
, (void *)0, &debug_reg_fops
);
563 for (i
= 0; i
< PM_DBG_MAX_REG_SETS
; i
++)
564 if (pm_dbg_reg_set
[i
] != NULL
) {
565 sprintf(name
, "%d", i
+1);
566 (void) debugfs_create_file(name
, S_IRUGO
,
567 pm_dbg_dir
, (void *)(i
+1), &debug_reg_fops
);
571 pm_dbg_init_done
= 1;
575 arch_initcall(pm_dbg_init
);
578 void pm_dbg_update_time(struct powerdomain
*pwrdm
, int prev
) {}