blob: 5c46ea6756d7b1dcbe8e6a6afd9cddc556880e04 [file] [log] [blame]
Kevin Hilman8bd22942009-05-28 10:56:16 -07001/*
2 * OMAP Power Management debug routines
3 *
4 * Copyright (C) 2005 Texas Instruments, Inc.
5 * Copyright (C) 2006-2008 Nokia Corporation
6 *
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
14 *
15 * Based on pm.c for omap2
16 *
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.
20 */
21
22#include <linux/kernel.h>
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030023#include <linux/sched.h>
Ingo Molnare6017572017-02-01 16:36:40 +010024#include <linux/sched/clock.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070025#include <linux/clk.h>
26#include <linux/err.h>
27#include <linux/io.h>
Tero Kristo68d47782008-11-26 12:26:24 +020028#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Kevin Hilman8bd22942009-05-28 10:56:16 -070030
Paul Walmsleya135eaa2012-09-27 10:33:34 -060031#include "clock.h"
Paul Walmsley72e06d02010-12-21 21:05:16 -070032#include "powerdomain.h"
Paul Walmsley1540f2142010-12-21 21:05:15 -070033#include "clockdomain.h"
Tony Lindgren1d5aef42012-10-03 16:36:40 -070034#include "omap-pm.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070035
Tony Lindgrene4c060d2012-10-05 13:25:59 -070036#include "soc.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070037#include "cm2xxx_3xxx.h"
38#include "prm2xxx_3xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070039#include "pm.h"
40
Thara Gopinath6cdee912010-08-12 13:52:25 +053041u32 enable_off_mode;
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030042
43#ifdef CONFIG_DEBUG_FS
44#include <linux/debugfs.h>
45#include <linux/seq_file.h>
46
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030047static int pm_dbg_init_done;
48
Russell Kingc8fb13d2011-05-27 13:56:12 -070049static int pm_dbg_init(void);
Sergio Aguirre6b34f9d2010-01-14 11:01:15 -060050
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030051enum {
52 DEBUG_FILE_COUNTERS = 0,
53 DEBUG_FILE_TIMERS,
54};
55
Paul Walmsley2354eb52009-12-08 16:33:12 -070056static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030057 "OFF",
58 "RET",
59 "INA",
60 "ON"
61};
62
63void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
64{
65 s64 t;
66
67 if (!pm_dbg_init_done)
68 return ;
69
70 /* Update timer for previous state */
71 t = sched_clock();
72
73 pwrdm->state_timer[prev] += t - pwrdm->timer;
74
75 pwrdm->timer = t;
76}
77
78static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
79{
80 struct seq_file *s = (struct seq_file *)user;
81
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;
86
Paul Walmsley92493872013-01-26 00:58:17 -070087 seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name,
88 clkdm->usecount);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030089
90 return 0;
91}
92
93static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
94{
95 struct seq_file *s = (struct seq_file *)user;
96 int i;
97
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;
102
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));
106
107 seq_printf(s, "%s (%s)", pwrdm->name,
108 pwrdm_state_names[pwrdm->state]);
Paul Walmsley2354eb52009-12-08 16:33:12 -0700109 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300110 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
111 pwrdm->state_counter[i]);
112
Thara Gopinathcde08f82010-02-24 12:05:50 -0700113 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]);
117
Markus Elfring5c02b012016-10-15 22:30:44 +0200118 seq_putc(s, '\n');
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300119 return 0;
120}
121
122static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
123{
124 struct seq_file *s = (struct seq_file *)user;
125 int i;
126
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;
131
132 pwrdm_state_switch(pwrdm);
133
134 seq_printf(s, "%s (%s)", pwrdm->name,
135 pwrdm_state_names[pwrdm->state]);
136
137 for (i = 0; i < 4; i++)
138 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
139 pwrdm->state_timer[i]);
140
Markus Elfring5c02b012016-10-15 22:30:44 +0200141 seq_putc(s, '\n');
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300142 return 0;
143}
144
145static int pm_dbg_show_counters(struct seq_file *s, void *unused)
146{
147 pwrdm_for_each(pwrdm_dbg_show_counter, s);
148 clkdm_for_each(clkdm_dbg_show_counter, s);
149
150 return 0;
151}
152
153static int pm_dbg_show_timers(struct seq_file *s, void *unused)
154{
155 pwrdm_for_each(pwrdm_dbg_show_timer, s);
156 return 0;
157}
158
159static int pm_dbg_open(struct inode *inode, struct file *file)
160{
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);
Peter Senna Tschudinc09fcc432012-09-18 18:36:11 +0200169 }
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300170}
171
172static const struct file_operations debug_fops = {
173 .open = pm_dbg_open,
174 .read = seq_read,
175 .llseek = seq_lseek,
176 .release = single_release,
177};
178
Tero Kristo68d47782008-11-26 12:26:24 +0200179static int pwrdm_suspend_get(void *data, u64 *val)
180{
Thara Gopinath6cdee912010-08-12 13:52:25 +0530181 int ret = -EINVAL;
182
183 if (cpu_is_omap34xx())
184 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
Roel Kluin61b17d92009-12-16 17:22:04 +0100185 *val = ret;
Tero Kristo68d47782008-11-26 12:26:24 +0200186
Roel Kluin61b17d92009-12-16 17:22:04 +0100187 if (ret >= 0)
Tero Kristo68d47782008-11-26 12:26:24 +0200188 return 0;
189 return *val;
190}
191
192static int pwrdm_suspend_set(void *data, u64 val)
193{
Thara Gopinath6cdee912010-08-12 13:52:25 +0530194 if (cpu_is_omap34xx())
195 return omap3_pm_set_suspend_state(
196 (struct powerdomain *)data, (int)val);
197 return -EINVAL;
Tero Kristo68d47782008-11-26 12:26:24 +0200198}
199
200DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
201 pwrdm_suspend_set, "%llu\n");
202
203static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300204{
205 int i;
206 s64 t;
Tero Kristo68d47782008-11-26 12:26:24 +0200207 struct dentry *d;
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300208
209 t = sched_clock();
210
211 for (i = 0; i < 4; i++)
212 pwrdm->state_timer[i] = 0;
213
214 pwrdm->timer = t;
215
Tero Kristo68d47782008-11-26 12:26:24 +0200216 if (strncmp(pwrdm->name, "dpll", 4) == 0)
217 return 0;
218
219 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
Russell Kingd808aa62013-02-24 10:52:18 +0000220 if (d)
Jean Pihet401606f2012-02-01 09:37:31 +0100221 (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
Tero Kristo68d47782008-11-26 12:26:24 +0200222 (void *)pwrdm, &pwrdm_suspend_fops);
223
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300224 return 0;
225}
226
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700227static int option_get(void *data, u64 *val)
228{
229 u32 *option = data;
230
231 *val = *option;
232
233 return 0;
234}
235
236static int option_set(void *data, u64 val)
237{
238 u32 *option = data;
239
240 *option = val;
241
Thara Gopinath6cdee912010-08-12 13:52:25 +0530242 if (option == &enable_off_mode) {
Kevin Hilman6081dc32010-12-21 21:31:55 -0700243 if (val)
244 omap_pm_enable_off_mode();
245 else
246 omap_pm_disable_off_mode();
Thara Gopinath6cdee912010-08-12 13:52:25 +0530247 if (cpu_is_omap34xx())
248 omap3_pm_off_mode_enable(val);
249 }
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700250
251 return 0;
252}
253
254DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
255
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300256static int __init pm_dbg_init(void)
257{
258 struct dentry *d;
259
Tero Kristo2811d6b2008-10-29 13:31:24 +0200260 if (pm_dbg_init_done)
261 return 0;
262
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300263 d = debugfs_create_dir("pm_debug", NULL);
Russell Kingd808aa62013-02-24 10:52:18 +0000264 if (!d)
265 return -EINVAL;
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300266
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);
271
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700272 pwrdm_for_each(pwrdms_setup, (void *)d);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300273
Vasiliy Kulikovf9fbe472011-02-04 12:23:16 +0000274 (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700275 &enable_off_mode, &pm_dbg_option_fops);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300276 pm_dbg_init_done = 1;
277
278 return 0;
279}
Tony Lindgrenb76c8b192013-01-11 11:24:18 -0800280omap_arch_initcall(pm_dbg_init);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300281
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300282#endif