blob: 1f9334a3d61163525e8365b58448bd385d8efcc3 [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"
Kevin Hilman8bd22942009-05-28 10:56:16 -070034
Tony Lindgrene4c060d2012-10-05 13:25:59 -070035#include "soc.h"
Paul Walmsley59fb6592010-12-21 15:30:55 -070036#include "cm2xxx_3xxx.h"
37#include "prm2xxx_3xxx.h"
Kevin Hilman8bd22942009-05-28 10:56:16 -070038#include "pm.h"
39
Thara Gopinath6cdee912010-08-12 13:52:25 +053040u32 enable_off_mode;
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030041
42#ifdef CONFIG_DEBUG_FS
43#include <linux/debugfs.h>
44#include <linux/seq_file.h>
45
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030046static int pm_dbg_init_done;
47
Russell Kingc8fb13d2011-05-27 13:56:12 -070048static int pm_dbg_init(void);
Sergio Aguirre6b34f9d2010-01-14 11:01:15 -060049
Paul Walmsley2354eb52009-12-08 16:33:12 -070050static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030051 "OFF",
52 "RET",
53 "INA",
54 "ON"
55};
56
57void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
58{
59 s64 t;
60
61 if (!pm_dbg_init_done)
62 return ;
63
64 /* Update timer for previous state */
65 t = sched_clock();
66
67 pwrdm->state_timer[prev] += t - pwrdm->timer;
68
69 pwrdm->timer = t;
70}
71
72static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
73{
74 struct seq_file *s = (struct seq_file *)user;
75
76 if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
77 strcmp(clkdm->name, "wkup_clkdm") == 0 ||
78 strncmp(clkdm->name, "dpll", 4) == 0)
79 return 0;
80
Paul Walmsley92493872013-01-26 00:58:17 -070081 seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name,
82 clkdm->usecount);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +030083
84 return 0;
85}
86
87static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
88{
89 struct seq_file *s = (struct seq_file *)user;
90 int i;
91
92 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
93 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
94 strncmp(pwrdm->name, "dpll", 4) == 0)
95 return 0;
96
97 if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
98 printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
99 pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
100
101 seq_printf(s, "%s (%s)", pwrdm->name,
102 pwrdm_state_names[pwrdm->state]);
Paul Walmsley2354eb52009-12-08 16:33:12 -0700103 for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300104 seq_printf(s, ",%s:%d", pwrdm_state_names[i],
105 pwrdm->state_counter[i]);
106
Thara Gopinathcde08f82010-02-24 12:05:50 -0700107 seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
108 for (i = 0; i < pwrdm->banks; i++)
109 seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
110 pwrdm->ret_mem_off_counter[i]);
111
Markus Elfring5c02b012016-10-15 22:30:44 +0200112 seq_putc(s, '\n');
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300113 return 0;
114}
115
116static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
117{
118 struct seq_file *s = (struct seq_file *)user;
119 int i;
120
121 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
122 strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
123 strncmp(pwrdm->name, "dpll", 4) == 0)
124 return 0;
125
126 pwrdm_state_switch(pwrdm);
127
128 seq_printf(s, "%s (%s)", pwrdm->name,
129 pwrdm_state_names[pwrdm->state]);
130
131 for (i = 0; i < 4; i++)
132 seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
133 pwrdm->state_timer[i]);
134
Markus Elfring5c02b012016-10-15 22:30:44 +0200135 seq_putc(s, '\n');
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300136 return 0;
137}
138
Andy Shevchenkoeb07fe92018-07-09 10:23:41 +0300139static int pm_dbg_counters_show(struct seq_file *s, void *unused)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300140{
141 pwrdm_for_each(pwrdm_dbg_show_counter, s);
142 clkdm_for_each(clkdm_dbg_show_counter, s);
143
144 return 0;
145}
Andy Shevchenkoeb07fe92018-07-09 10:23:41 +0300146DEFINE_SHOW_ATTRIBUTE(pm_dbg_counters);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300147
Andy Shevchenkoeb07fe92018-07-09 10:23:41 +0300148static int pm_dbg_timers_show(struct seq_file *s, void *unused)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300149{
150 pwrdm_for_each(pwrdm_dbg_show_timer, s);
151 return 0;
152}
Andy Shevchenkoeb07fe92018-07-09 10:23:41 +0300153DEFINE_SHOW_ATTRIBUTE(pm_dbg_timers);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300154
Tero Kristo68d47782008-11-26 12:26:24 +0200155static int pwrdm_suspend_get(void *data, u64 *val)
156{
Thara Gopinath6cdee912010-08-12 13:52:25 +0530157 int ret = -EINVAL;
158
159 if (cpu_is_omap34xx())
160 ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
Roel Kluin61b17d92009-12-16 17:22:04 +0100161 *val = ret;
Tero Kristo68d47782008-11-26 12:26:24 +0200162
Roel Kluin61b17d92009-12-16 17:22:04 +0100163 if (ret >= 0)
Tero Kristo68d47782008-11-26 12:26:24 +0200164 return 0;
165 return *val;
166}
167
168static int pwrdm_suspend_set(void *data, u64 val)
169{
Thara Gopinath6cdee912010-08-12 13:52:25 +0530170 if (cpu_is_omap34xx())
171 return omap3_pm_set_suspend_state(
172 (struct powerdomain *)data, (int)val);
173 return -EINVAL;
Tero Kristo68d47782008-11-26 12:26:24 +0200174}
175
176DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
177 pwrdm_suspend_set, "%llu\n");
178
179static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300180{
181 int i;
182 s64 t;
Tero Kristo68d47782008-11-26 12:26:24 +0200183 struct dentry *d;
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300184
185 t = sched_clock();
186
187 for (i = 0; i < 4; i++)
188 pwrdm->state_timer[i] = 0;
189
190 pwrdm->timer = t;
191
Tero Kristo68d47782008-11-26 12:26:24 +0200192 if (strncmp(pwrdm->name, "dpll", 4) == 0)
193 return 0;
194
195 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
Greg Kroah-Hartman30ed9972019-01-22 15:41:14 +0100196 debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d, pwrdm,
197 &pwrdm_suspend_fops);
Tero Kristo68d47782008-11-26 12:26:24 +0200198
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300199 return 0;
200}
201
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700202static int option_get(void *data, u64 *val)
203{
204 u32 *option = data;
205
206 *val = *option;
207
208 return 0;
209}
210
211static int option_set(void *data, u64 val)
212{
213 u32 *option = data;
214
215 *option = val;
216
Thara Gopinath6cdee912010-08-12 13:52:25 +0530217 if (option == &enable_off_mode) {
218 if (cpu_is_omap34xx())
219 omap3_pm_off_mode_enable(val);
220 }
Kevin Hilmanc40552b2009-10-06 14:25:09 -0700221
222 return 0;
223}
224
225DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
226
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300227static int __init pm_dbg_init(void)
228{
229 struct dentry *d;
230
Tero Kristo2811d6b2008-10-29 13:31:24 +0200231 if (pm_dbg_init_done)
232 return 0;
233
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300234 d = debugfs_create_dir("pm_debug", NULL);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300235
Greg Kroah-Hartman30ed9972019-01-22 15:41:14 +0100236 debugfs_create_file("count", 0444, d, NULL, &pm_dbg_counters_fops);
237 debugfs_create_file("time", 0444, d, NULL, &pm_dbg_timers_fops);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300238
Paul Walmsleye909d62a82010-01-26 20:13:00 -0700239 pwrdm_for_each(pwrdms_setup, (void *)d);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300240
Greg Kroah-Hartman30ed9972019-01-22 15:41:14 +0100241 debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
242 &enable_off_mode, &pm_dbg_option_fops);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300243 pm_dbg_init_done = 1;
244
245 return 0;
246}
Tony Lindgrenb76c8b192013-01-11 11:24:18 -0800247omap_arch_initcall(pm_dbg_init);
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300248
Peter 'p2' De Schrijver331b93f2008-10-15 18:13:48 +0300249#endif