Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 1 | /* |
| 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 Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 23 | #include <linux/sched.h> |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 24 | #include <linux/clk.h> |
| 25 | #include <linux/err.h> |
| 26 | #include <linux/io.h> |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 27 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 29 | |
Paul Walmsley | a135eaa | 2012-09-27 10:33:34 -0600 | [diff] [blame] | 30 | #include "clock.h" |
Paul Walmsley | 72e06d0 | 2010-12-21 21:05:16 -0700 | [diff] [blame] | 31 | #include "powerdomain.h" |
Paul Walmsley | 1540f214 | 2010-12-21 21:05:15 -0700 | [diff] [blame] | 32 | #include "clockdomain.h" |
Tony Lindgren | 1d5aef4 | 2012-10-03 16:36:40 -0700 | [diff] [blame] | 33 | #include "omap-pm.h" |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 34 | |
Tony Lindgren | e4c060d | 2012-10-05 13:25:59 -0700 | [diff] [blame] | 35 | #include "soc.h" |
Paul Walmsley | 59fb659 | 2010-12-21 15:30:55 -0700 | [diff] [blame] | 36 | #include "cm2xxx_3xxx.h" |
| 37 | #include "prm2xxx_3xxx.h" |
Kevin Hilman | 8bd2294 | 2009-05-28 10:56:16 -0700 | [diff] [blame] | 38 | #include "pm.h" |
| 39 | |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 40 | u32 enable_off_mode; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 41 | |
| 42 | #ifdef CONFIG_DEBUG_FS |
| 43 | #include <linux/debugfs.h> |
| 44 | #include <linux/seq_file.h> |
| 45 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 46 | static int pm_dbg_init_done; |
| 47 | |
Russell King | c8fb13d | 2011-05-27 13:56:12 -0700 | [diff] [blame] | 48 | static int pm_dbg_init(void); |
Sergio Aguirre | 6b34f9d | 2010-01-14 11:01:15 -0600 | [diff] [blame] | 49 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 50 | enum { |
| 51 | DEBUG_FILE_COUNTERS = 0, |
| 52 | DEBUG_FILE_TIMERS, |
| 53 | }; |
| 54 | |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame] | 55 | static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = { |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 56 | "OFF", |
| 57 | "RET", |
| 58 | "INA", |
| 59 | "ON" |
| 60 | }; |
| 61 | |
| 62 | void pm_dbg_update_time(struct powerdomain *pwrdm, int prev) |
| 63 | { |
| 64 | s64 t; |
| 65 | |
| 66 | if (!pm_dbg_init_done) |
| 67 | return ; |
| 68 | |
| 69 | /* Update timer for previous state */ |
| 70 | t = sched_clock(); |
| 71 | |
| 72 | pwrdm->state_timer[prev] += t - pwrdm->timer; |
| 73 | |
| 74 | pwrdm->timer = t; |
| 75 | } |
| 76 | |
| 77 | static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user) |
| 78 | { |
| 79 | struct seq_file *s = (struct seq_file *)user; |
| 80 | |
| 81 | if (strcmp(clkdm->name, "emu_clkdm") == 0 || |
| 82 | strcmp(clkdm->name, "wkup_clkdm") == 0 || |
| 83 | strncmp(clkdm->name, "dpll", 4) == 0) |
| 84 | return 0; |
| 85 | |
| 86 | seq_printf(s, "%s->%s (%d)", clkdm->name, |
| 87 | clkdm->pwrdm.ptr->name, |
| 88 | atomic_read(&clkdm->usecount)); |
| 89 | seq_printf(s, "\n"); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user) |
| 95 | { |
| 96 | struct seq_file *s = (struct seq_file *)user; |
| 97 | int i; |
| 98 | |
| 99 | if (strcmp(pwrdm->name, "emu_pwrdm") == 0 || |
| 100 | strcmp(pwrdm->name, "wkup_pwrdm") == 0 || |
| 101 | strncmp(pwrdm->name, "dpll", 4) == 0) |
| 102 | return 0; |
| 103 | |
| 104 | if (pwrdm->state != pwrdm_read_pwrst(pwrdm)) |
| 105 | printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n", |
| 106 | pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm)); |
| 107 | |
| 108 | seq_printf(s, "%s (%s)", pwrdm->name, |
| 109 | pwrdm_state_names[pwrdm->state]); |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame] | 110 | for (i = 0; i < PWRDM_MAX_PWRSTS; i++) |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 111 | seq_printf(s, ",%s:%d", pwrdm_state_names[i], |
| 112 | pwrdm->state_counter[i]); |
| 113 | |
Thara Gopinath | cde08f8 | 2010-02-24 12:05:50 -0700 | [diff] [blame] | 114 | seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter); |
| 115 | for (i = 0; i < pwrdm->banks; i++) |
| 116 | seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1, |
| 117 | pwrdm->ret_mem_off_counter[i]); |
| 118 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 119 | seq_printf(s, "\n"); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user) |
| 125 | { |
| 126 | struct seq_file *s = (struct seq_file *)user; |
| 127 | int i; |
| 128 | |
| 129 | if (strcmp(pwrdm->name, "emu_pwrdm") == 0 || |
| 130 | strcmp(pwrdm->name, "wkup_pwrdm") == 0 || |
| 131 | strncmp(pwrdm->name, "dpll", 4) == 0) |
| 132 | return 0; |
| 133 | |
| 134 | pwrdm_state_switch(pwrdm); |
| 135 | |
| 136 | seq_printf(s, "%s (%s)", pwrdm->name, |
| 137 | pwrdm_state_names[pwrdm->state]); |
| 138 | |
| 139 | for (i = 0; i < 4; i++) |
| 140 | seq_printf(s, ",%s:%lld", pwrdm_state_names[i], |
| 141 | pwrdm->state_timer[i]); |
| 142 | |
| 143 | seq_printf(s, "\n"); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static int pm_dbg_show_counters(struct seq_file *s, void *unused) |
| 148 | { |
| 149 | pwrdm_for_each(pwrdm_dbg_show_counter, s); |
| 150 | clkdm_for_each(clkdm_dbg_show_counter, s); |
| 151 | |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | static int pm_dbg_show_timers(struct seq_file *s, void *unused) |
| 156 | { |
| 157 | pwrdm_for_each(pwrdm_dbg_show_timer, s); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | static int pm_dbg_open(struct inode *inode, struct file *file) |
| 162 | { |
| 163 | switch ((int)inode->i_private) { |
| 164 | case DEBUG_FILE_COUNTERS: |
| 165 | return single_open(file, pm_dbg_show_counters, |
| 166 | &inode->i_private); |
| 167 | case DEBUG_FILE_TIMERS: |
| 168 | default: |
| 169 | return single_open(file, pm_dbg_show_timers, |
| 170 | &inode->i_private); |
Peter Senna Tschudin | c09fcc43 | 2012-09-18 18:36:11 +0200 | [diff] [blame] | 171 | } |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static const struct file_operations debug_fops = { |
| 175 | .open = pm_dbg_open, |
| 176 | .read = seq_read, |
| 177 | .llseek = seq_lseek, |
| 178 | .release = single_release, |
| 179 | }; |
| 180 | |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 181 | static int pwrdm_suspend_get(void *data, u64 *val) |
| 182 | { |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 183 | int ret = -EINVAL; |
| 184 | |
| 185 | if (cpu_is_omap34xx()) |
| 186 | ret = omap3_pm_get_suspend_state((struct powerdomain *)data); |
Roel Kluin | 61b17d9 | 2009-12-16 17:22:04 +0100 | [diff] [blame] | 187 | *val = ret; |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 188 | |
Roel Kluin | 61b17d9 | 2009-12-16 17:22:04 +0100 | [diff] [blame] | 189 | if (ret >= 0) |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 190 | return 0; |
| 191 | return *val; |
| 192 | } |
| 193 | |
| 194 | static int pwrdm_suspend_set(void *data, u64 val) |
| 195 | { |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 196 | if (cpu_is_omap34xx()) |
| 197 | return omap3_pm_set_suspend_state( |
| 198 | (struct powerdomain *)data, (int)val); |
| 199 | return -EINVAL; |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get, |
| 203 | pwrdm_suspend_set, "%llu\n"); |
| 204 | |
| 205 | static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir) |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 206 | { |
| 207 | int i; |
| 208 | s64 t; |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 209 | struct dentry *d; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 210 | |
| 211 | t = sched_clock(); |
| 212 | |
| 213 | for (i = 0; i < 4; i++) |
| 214 | pwrdm->state_timer[i] = 0; |
| 215 | |
| 216 | pwrdm->timer = t; |
| 217 | |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 218 | if (strncmp(pwrdm->name, "dpll", 4) == 0) |
| 219 | return 0; |
| 220 | |
| 221 | d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir); |
Jean Pihet | 401606f | 2012-02-01 09:37:31 +0100 | [diff] [blame] | 222 | if (!(IS_ERR_OR_NULL(d))) |
| 223 | (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d, |
Tero Kristo | 68d4778 | 2008-11-26 12:26:24 +0200 | [diff] [blame] | 224 | (void *)pwrdm, &pwrdm_suspend_fops); |
| 225 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Kevin Hilman | c40552b | 2009-10-06 14:25:09 -0700 | [diff] [blame] | 229 | static int option_get(void *data, u64 *val) |
| 230 | { |
| 231 | u32 *option = data; |
| 232 | |
| 233 | *val = *option; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static int option_set(void *data, u64 val) |
| 239 | { |
| 240 | u32 *option = data; |
| 241 | |
| 242 | *option = val; |
| 243 | |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 244 | if (option == &enable_off_mode) { |
Kevin Hilman | 6081dc3 | 2010-12-21 21:31:55 -0700 | [diff] [blame] | 245 | if (val) |
| 246 | omap_pm_enable_off_mode(); |
| 247 | else |
| 248 | omap_pm_disable_off_mode(); |
Thara Gopinath | 6cdee91 | 2010-08-12 13:52:25 +0530 | [diff] [blame] | 249 | if (cpu_is_omap34xx()) |
| 250 | omap3_pm_off_mode_enable(val); |
| 251 | } |
Kevin Hilman | c40552b | 2009-10-06 14:25:09 -0700 | [diff] [blame] | 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n"); |
| 257 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 258 | static int __init pm_dbg_init(void) |
| 259 | { |
| 260 | struct dentry *d; |
| 261 | |
Tero Kristo | 2811d6b | 2008-10-29 13:31:24 +0200 | [diff] [blame] | 262 | if (pm_dbg_init_done) |
| 263 | return 0; |
| 264 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 265 | d = debugfs_create_dir("pm_debug", NULL); |
Jean Pihet | 401606f | 2012-02-01 09:37:31 +0100 | [diff] [blame] | 266 | if (IS_ERR_OR_NULL(d)) |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 267 | return PTR_ERR(d); |
| 268 | |
| 269 | (void) debugfs_create_file("count", S_IRUGO, |
| 270 | d, (void *)DEBUG_FILE_COUNTERS, &debug_fops); |
| 271 | (void) debugfs_create_file("time", S_IRUGO, |
| 272 | d, (void *)DEBUG_FILE_TIMERS, &debug_fops); |
| 273 | |
Paul Walmsley | e909d62a8 | 2010-01-26 20:13:00 -0700 | [diff] [blame] | 274 | pwrdm_for_each(pwrdms_setup, (void *)d); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 275 | |
Vasiliy Kulikov | f9fbe47 | 2011-02-04 12:23:16 +0000 | [diff] [blame] | 276 | (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d, |
Kevin Hilman | c40552b | 2009-10-06 14:25:09 -0700 | [diff] [blame] | 277 | &enable_off_mode, &pm_dbg_option_fops); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 278 | pm_dbg_init_done = 1; |
| 279 | |
| 280 | return 0; |
| 281 | } |
Tero Kristo | 2811d6b | 2008-10-29 13:31:24 +0200 | [diff] [blame] | 282 | arch_initcall(pm_dbg_init); |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 283 | |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 284 | #endif |