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