WIP FPC-III support
[linux/fpc-iii.git] / arch / arm / mach-omap2 / pm-debug.c
blob919d35d5b325ddce3c59d25fa1a4b246bd894186
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * OMAP Power Management debug routines
5 * Copyright (C) 2005 Texas Instruments, Inc.
6 * Copyright (C) 2006-2008 Nokia Corporation
8 * Written by:
9 * Richard Woodruff <r-woodruff2@ti.com>
10 * Tony Lindgren
11 * Juha Yrjola
12 * Amit Kucheria <amit.kucheria@nokia.com>
13 * Igor Stoppa <igor.stoppa@nokia.com>
14 * Jouni Hogander
16 * Based on pm.c for omap2
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/sched/clock.h>
22 #include <linux/clk.h>
23 #include <linux/err.h>
24 #include <linux/io.h>
25 #include <linux/module.h>
26 #include <linux/slab.h>
28 #include "clock.h"
29 #include "powerdomain.h"
30 #include "clockdomain.h"
32 #include "soc.h"
33 #include "cm2xxx_3xxx.h"
34 #include "prm2xxx_3xxx.h"
35 #include "pm.h"
37 #ifdef CONFIG_DEBUG_FS
38 #include <linux/debugfs.h>
39 #include <linux/seq_file.h>
41 static int pm_dbg_init_done;
43 static int pm_dbg_init(void);
45 static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
46 "OFF",
47 "RET",
48 "INA",
49 "ON"
52 void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
54 s64 t;
56 if (!pm_dbg_init_done)
57 return ;
59 /* Update timer for previous state */
60 t = sched_clock();
62 pwrdm->state_timer[prev] += t - pwrdm->timer;
64 pwrdm->timer = t;
67 static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
69 struct seq_file *s = (struct seq_file *)user;
71 if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
72 strcmp(clkdm->name, "wkup_clkdm") == 0 ||
73 strncmp(clkdm->name, "dpll", 4) == 0)
74 return 0;
76 seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name,
77 clkdm->usecount);
79 return 0;
82 static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
84 struct seq_file *s = (struct seq_file *)user;
85 int i;
87 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
88 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
89 strncmp(pwrdm->name, "dpll", 4) == 0)
90 return 0;
92 if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
93 printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
94 pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
96 seq_printf(s, "%s (%s)", pwrdm->name,
97 pwrdm_state_names[pwrdm->state]);
98 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
99 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
100 pwrdm->state_counter[i]);
102 seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
103 for (i = 0; i < pwrdm->banks; i++)
104 seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
105 pwrdm->ret_mem_off_counter[i]);
107 seq_putc(s, '\n');
108 return 0;
111 static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
113 struct seq_file *s = (struct seq_file *)user;
114 int i;
116 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
117 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
118 strncmp(pwrdm->name, "dpll", 4) == 0)
119 return 0;
121 pwrdm_state_switch(pwrdm);
123 seq_printf(s, "%s (%s)", pwrdm->name,
124 pwrdm_state_names[pwrdm->state]);
126 for (i = 0; i < 4; i++)
127 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
128 pwrdm->state_timer[i]);
130 seq_putc(s, '\n');
131 return 0;
134 static int pm_dbg_counters_show(struct seq_file *s, void *unused)
136 pwrdm_for_each(pwrdm_dbg_show_counter, s);
137 clkdm_for_each(clkdm_dbg_show_counter, s);
139 return 0;
141 DEFINE_SHOW_ATTRIBUTE(pm_dbg_counters);
143 static int pm_dbg_timers_show(struct seq_file *s, void *unused)
145 pwrdm_for_each(pwrdm_dbg_show_timer, s);
146 return 0;
148 DEFINE_SHOW_ATTRIBUTE(pm_dbg_timers);
150 static int pwrdm_suspend_get(void *data, u64 *val)
152 int ret = -EINVAL;
154 if (cpu_is_omap34xx())
155 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
156 *val = ret;
158 if (ret >= 0)
159 return 0;
160 return *val;
163 static int pwrdm_suspend_set(void *data, u64 val)
165 if (cpu_is_omap34xx())
166 return omap3_pm_set_suspend_state(
167 (struct powerdomain *)data, (int)val);
168 return -EINVAL;
171 DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
172 pwrdm_suspend_set, "%llu\n");
174 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
176 int i;
177 s64 t;
178 struct dentry *d;
180 t = sched_clock();
182 for (i = 0; i < 4; i++)
183 pwrdm->state_timer[i] = 0;
185 pwrdm->timer = t;
187 if (strncmp(pwrdm->name, "dpll", 4) == 0)
188 return 0;
190 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
191 debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d, pwrdm,
192 &pwrdm_suspend_fops);
194 return 0;
197 static int option_get(void *data, u64 *val)
199 u32 *option = data;
201 *val = *option;
203 return 0;
206 static int option_set(void *data, u64 val)
208 u32 *option = data;
210 *option = val;
212 if (option == &enable_off_mode) {
213 if (cpu_is_omap34xx())
214 omap3_pm_off_mode_enable(val);
217 return 0;
220 DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
222 static int __init pm_dbg_init(void)
224 struct dentry *d;
226 if (pm_dbg_init_done)
227 return 0;
229 d = debugfs_create_dir("pm_debug", NULL);
231 debugfs_create_file("count", 0444, d, NULL, &pm_dbg_counters_fops);
232 debugfs_create_file("time", 0444, d, NULL, &pm_dbg_timers_fops);
234 pwrdm_for_each(pwrdms_setup, (void *)d);
236 debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
237 &enable_off_mode, &pm_dbg_option_fops);
238 pm_dbg_init_done = 1;
240 return 0;
242 omap_arch_initcall(pm_dbg_init);
244 #endif