Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 2 | /* |
| 3 | * OMAP Power Management debug routines |
| 4 | * |
| 5 | * Copyright (C) 2005 Texas Instruments, Inc. |
| 6 | * Copyright (C) 2006-2008 Nokia Corporation |
| 7 | * |
| 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 |
| 15 | * |
| 16 | * Based on pm.c for omap2 |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/kernel.h> |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 20 | #include <linux/sched.h> |
Ingo Molnar | e601757 | 2017-02-01 16:36:40 +0100 | [diff] [blame] | 21 | #include <linux/sched/clock.h> |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 22 | #include <linux/clk.h> |
| 23 | #include <linux/err.h> |
| 24 | #include <linux/io.h> |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 25 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 27 | |
Paul Walmsley | a135eaa | 2012-09-27 10:33:34 -0600 | [diff] [blame] | 28 | #include "clock.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 29 | #include "powerdomain.h" |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 30 | #include "clockdomain.h" |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 31 | |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame] | 32 | #include "soc.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 33 | #include "cm2xxx_3xxx.h" |
| 34 | #include "prm2xxx_3xxx.h" |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 35 | #include "pm.h" |
| 36 | |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 37 | u32 enable_off_mode; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 38 | |
| 39 | #ifdef CONFIG_DEBUG_FS |
| 40 | #include <linux/debugfs.h> |
| 41 | #include <linux/seq_file.h> |
| 42 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 43 | static int pm_dbg_init_done; |
| 44 | |
Russell King | c8fb13d | 2011-05-27 13:56:12 -0700 | [diff] [blame] | 45 | static int pm_dbg_init(void); |
Sergio Aguirre | 6b34f9d | 2010-01-14 11:01:15 -0600 | [diff] [blame] | 46 | |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame] | 47 | static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = { |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 48 | "OFF", |
| 49 | "RET", |
| 50 | "INA", |
| 51 | "ON" |
| 52 | }; |
| 53 | |
| 54 | void pm_dbg_update_time(struct powerdomain *pwrdm, int prev) |
| 55 | { |
| 56 | s64 t; |
| 57 | |
| 58 | if (!pm_dbg_init_done) |
| 59 | return ; |
| 60 | |
| 61 | /* Update timer for previous state */ |
| 62 | t = sched_clock(); |
| 63 | |
| 64 | pwrdm->state_timer[prev] += t - pwrdm->timer; |
| 65 | |
| 66 | pwrdm->timer = t; |
| 67 | } |
| 68 | |
| 69 | static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user) |
| 70 | { |
| 71 | struct seq_file *s = (struct seq_file *)user; |
| 72 | |
| 73 | if (strcmp(clkdm->name, "emu_clkdm") == 0 || |
| 74 | strcmp(clkdm->name, "wkup_clkdm") == 0 || |
| 75 | strncmp(clkdm->name, "dpll", 4) == 0) |
| 76 | return 0; |
| 77 | |
Paul Walmsley | 9249387 | 2013-01-26 00:58:17 -0700 | [diff] [blame] | 78 | seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name, |
| 79 | clkdm->usecount); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user) |
| 85 | { |
| 86 | struct seq_file *s = (struct seq_file *)user; |
| 87 | int i; |
| 88 | |
| 89 | if (strcmp(pwrdm->name, "emu_pwrdm") == 0 || |
| 90 | strcmp(pwrdm->name, "wkup_pwrdm") == 0 || |
| 91 | strncmp(pwrdm->name, "dpll", 4) == 0) |
| 92 | return 0; |
| 93 | |
| 94 | if (pwrdm->state != pwrdm_read_pwrst(pwrdm)) |
| 95 | printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n", |
| 96 | pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm)); |
| 97 | |
| 98 | seq_printf(s, "%s (%s)", pwrdm->name, |
| 99 | pwrdm_state_names[pwrdm->state]); |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame] | 100 | for (i = 0; i < PWRDM_MAX_PWRSTS; i++) |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 101 | seq_printf(s, ",%s:%d", pwrdm_state_names[i], |
| 102 | pwrdm->state_counter[i]); |
| 103 | |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 104 | seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter); |
| 105 | for (i = 0; i < pwrdm->banks; i++) |
| 106 | seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1, |
| 107 | pwrdm->ret_mem_off_counter[i]); |
| 108 | |
Markus Elfring | 5c02b01 | 2016-10-15 22:30:44 +0200 | [diff] [blame] | 109 | seq_putc(s, '\n'); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user) |
| 114 | { |
| 115 | struct seq_file *s = (struct seq_file *)user; |
| 116 | int i; |
| 117 | |
| 118 | if (strcmp(pwrdm->name, "emu_pwrdm") == 0 || |
| 119 | strcmp(pwrdm->name, "wkup_pwrdm") == 0 || |
| 120 | strncmp(pwrdm->name, "dpll", 4) == 0) |
| 121 | return 0; |
| 122 | |
| 123 | pwrdm_state_switch(pwrdm); |
| 124 | |
| 125 | seq_printf(s, "%s (%s)", pwrdm->name, |
| 126 | pwrdm_state_names[pwrdm->state]); |
| 127 | |
| 128 | for (i = 0; i < 4; i++) |
| 129 | seq_printf(s, ",%s:%lld", pwrdm_state_names[i], |
| 130 | pwrdm->state_timer[i]); |
| 131 | |
Markus Elfring | 5c02b01 | 2016-10-15 22:30:44 +0200 | [diff] [blame] | 132 | seq_putc(s, '\n'); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
Andy Shevchenko | eb07fe9 | 2018-07-09 10:23:41 +0300 | [diff] [blame] | 136 | static int pm_dbg_counters_show(struct seq_file *s, void *unused) |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 137 | { |
| 138 | pwrdm_for_each(pwrdm_dbg_show_counter, s); |
| 139 | clkdm_for_each(clkdm_dbg_show_counter, s); |
| 140 | |
| 141 | return 0; |
| 142 | } |
Andy Shevchenko | eb07fe9 | 2018-07-09 10:23:41 +0300 | [diff] [blame] | 143 | DEFINE_SHOW_ATTRIBUTE(pm_dbg_counters); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 144 | |
Andy Shevchenko | eb07fe9 | 2018-07-09 10:23:41 +0300 | [diff] [blame] | 145 | static int pm_dbg_timers_show(struct seq_file *s, void *unused) |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 146 | { |
| 147 | pwrdm_for_each(pwrdm_dbg_show_timer, s); |
| 148 | return 0; |
| 149 | } |
Andy Shevchenko | eb07fe9 | 2018-07-09 10:23:41 +0300 | [diff] [blame] | 150 | DEFINE_SHOW_ATTRIBUTE(pm_dbg_timers); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 151 | |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 152 | static int pwrdm_suspend_get(void *data, u64 *val) |
| 153 | { |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 154 | int ret = -EINVAL; |
| 155 | |
| 156 | if (cpu_is_omap34xx()) |
| 157 | ret = omap3_pm_get_suspend_state((struct powerdomain *)data); |
Roel Kluin | 61b17d9 | 2009-12-16 17:22:04 +0100 | [diff] [blame] | 158 | *val = ret; |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 159 | |
Roel Kluin | 61b17d9 | 2009-12-16 17:22:04 +0100 | [diff] [blame] | 160 | if (ret >= 0) |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 161 | return 0; |
| 162 | return *val; |
| 163 | } |
| 164 | |
| 165 | static int pwrdm_suspend_set(void *data, u64 val) |
| 166 | { |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 167 | if (cpu_is_omap34xx()) |
| 168 | return omap3_pm_set_suspend_state( |
| 169 | (struct powerdomain *)data, (int)val); |
| 170 | return -EINVAL; |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get, |
| 174 | pwrdm_suspend_set, "%llu\n"); |
| 175 | |
| 176 | static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir) |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 177 | { |
| 178 | int i; |
| 179 | s64 t; |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 180 | struct dentry *d; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 181 | |
| 182 | t = sched_clock(); |
| 183 | |
| 184 | for (i = 0; i < 4; i++) |
| 185 | pwrdm->state_timer[i] = 0; |
| 186 | |
| 187 | pwrdm->timer = t; |
| 188 | |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 189 | if (strncmp(pwrdm->name, "dpll", 4) == 0) |
| 190 | return 0; |
| 191 | |
| 192 | d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir); |
Greg Kroah-Hartman | 30ed997 | 2019-01-22 15:41:14 +0100 | [diff] [blame] | 193 | debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d, pwrdm, |
| 194 | &pwrdm_suspend_fops); |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 195 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
Kevin Hilman | c40552b | 2009-10-06 14:25:09 -0700 | [diff] [blame] | 199 | static int option_get(void *data, u64 *val) |
| 200 | { |
| 201 | u32 *option = data; |
| 202 | |
| 203 | *val = *option; |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static int option_set(void *data, u64 val) |
| 209 | { |
| 210 | u32 *option = data; |
| 211 | |
| 212 | *option = val; |
| 213 | |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 214 | if (option == &enable_off_mode) { |
| 215 | if (cpu_is_omap34xx()) |
| 216 | omap3_pm_off_mode_enable(val); |
| 217 | } |
Kevin Hilman | c40552b | 2009-10-06 14:25:09 -0700 | [diff] [blame] | 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n"); |
| 223 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 224 | static int __init pm_dbg_init(void) |
| 225 | { |
| 226 | struct dentry *d; |
| 227 | |
Tero Kristo | 2811d6b | 2008-10-29 13:31:24 +0200 | [diff] [blame] | 228 | if (pm_dbg_init_done) |
| 229 | return 0; |
| 230 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 231 | d = debugfs_create_dir("pm_debug", NULL); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 232 | |
Greg Kroah-Hartman | 30ed997 | 2019-01-22 15:41:14 +0100 | [diff] [blame] | 233 | debugfs_create_file("count", 0444, d, NULL, &pm_dbg_counters_fops); |
| 234 | debugfs_create_file("time", 0444, d, NULL, &pm_dbg_timers_fops); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 235 | |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 236 | pwrdm_for_each(pwrdms_setup, (void *)d); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 237 | |
Greg Kroah-Hartman | 30ed997 | 2019-01-22 15:41:14 +0100 | [diff] [blame] | 238 | debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d, |
| 239 | &enable_off_mode, &pm_dbg_option_fops); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 240 | pm_dbg_init_done = 1; |
| 241 | |
| 242 | return 0; |
| 243 | } |
Tony Lindgren | b76c8b19 | 2013-01-11 11:24:18 -0800 | [diff] [blame] | 244 | omap_arch_initcall(pm_dbg_init); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 245 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 246 | #endif |