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> 23 #include <linux/sched.h> 24 #include <linux/sched/clock.h> 25 #include <linux/clk.h> 26 #include <linux/err.h> 27 #include <linux/io.h> 28 #include <linux/module.h> 29 #include <linux/slab.h> 30 31 #include "clock.h" 32 #include "powerdomain.h" 33 #include "clockdomain.h" 34 35 #include "soc.h" 36 #include "cm2xxx_3xxx.h" 37 #include "prm2xxx_3xxx.h" 38 #include "pm.h" 39 40 u32 enable_off_mode; 41 42 #ifdef CONFIG_DEBUG_FS 43 #include <linux/debugfs.h> 44 #include <linux/seq_file.h> 45 46 static int pm_dbg_init_done; 47 48 static int pm_dbg_init(void); 49 50 enum { 51 DEBUG_FILE_COUNTERS = 0, 52 DEBUG_FILE_TIMERS, 53 }; 54 55 static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = { 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)\n", clkdm->name, clkdm->pwrdm.ptr->name, 87 clkdm->usecount); 88 89 return 0; 90 } 91 92 static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user) 93 { 94 struct seq_file *s = (struct seq_file *)user; 95 int i; 96 97 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 || 98 strcmp(pwrdm->name, "wkup_pwrdm") == 0 || 99 strncmp(pwrdm->name, "dpll", 4) == 0) 100 return 0; 101 102 if (pwrdm->state != pwrdm_read_pwrst(pwrdm)) 103 printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n", 104 pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm)); 105 106 seq_printf(s, "%s (%s)", pwrdm->name, 107 pwrdm_state_names[pwrdm->state]); 108 for (i = 0; i < PWRDM_MAX_PWRSTS; i++) 109 seq_printf(s, ",%s:%d", pwrdm_state_names[i], 110 pwrdm->state_counter[i]); 111 112 seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter); 113 for (i = 0; i < pwrdm->banks; i++) 114 seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1, 115 pwrdm->ret_mem_off_counter[i]); 116 117 seq_putc(s, '\n'); 118 return 0; 119 } 120 121 static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user) 122 { 123 struct seq_file *s = (struct seq_file *)user; 124 int i; 125 126 if (strcmp(pwrdm->name, "emu_pwrdm") == 0 || 127 strcmp(pwrdm->name, "wkup_pwrdm") == 0 || 128 strncmp(pwrdm->name, "dpll", 4) == 0) 129 return 0; 130 131 pwrdm_state_switch(pwrdm); 132 133 seq_printf(s, "%s (%s)", pwrdm->name, 134 pwrdm_state_names[pwrdm->state]); 135 136 for (i = 0; i < 4; i++) 137 seq_printf(s, ",%s:%lld", pwrdm_state_names[i], 138 pwrdm->state_timer[i]); 139 140 seq_putc(s, '\n'); 141 return 0; 142 } 143 144 static int pm_dbg_show_counters(struct seq_file *s, void *unused) 145 { 146 pwrdm_for_each(pwrdm_dbg_show_counter, s); 147 clkdm_for_each(clkdm_dbg_show_counter, s); 148 149 return 0; 150 } 151 152 static int pm_dbg_show_timers(struct seq_file *s, void *unused) 153 { 154 pwrdm_for_each(pwrdm_dbg_show_timer, s); 155 return 0; 156 } 157 158 static int pm_dbg_open(struct inode *inode, struct file *file) 159 { 160 switch ((int)inode->i_private) { 161 case DEBUG_FILE_COUNTERS: 162 return single_open(file, pm_dbg_show_counters, 163 &inode->i_private); 164 case DEBUG_FILE_TIMERS: 165 default: 166 return single_open(file, pm_dbg_show_timers, 167 &inode->i_private); 168 } 169 } 170 171 static const struct file_operations debug_fops = { 172 .open = pm_dbg_open, 173 .read = seq_read, 174 .llseek = seq_lseek, 175 .release = single_release, 176 }; 177 178 static int pwrdm_suspend_get(void *data, u64 *val) 179 { 180 int ret = -EINVAL; 181 182 if (cpu_is_omap34xx()) 183 ret = omap3_pm_get_suspend_state((struct powerdomain *)data); 184 *val = ret; 185 186 if (ret >= 0) 187 return 0; 188 return *val; 189 } 190 191 static int pwrdm_suspend_set(void *data, u64 val) 192 { 193 if (cpu_is_omap34xx()) 194 return omap3_pm_set_suspend_state( 195 (struct powerdomain *)data, (int)val); 196 return -EINVAL; 197 } 198 199 DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get, 200 pwrdm_suspend_set, "%llu\n"); 201 202 static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir) 203 { 204 int i; 205 s64 t; 206 struct dentry *d; 207 208 t = sched_clock(); 209 210 for (i = 0; i < 4; i++) 211 pwrdm->state_timer[i] = 0; 212 213 pwrdm->timer = t; 214 215 if (strncmp(pwrdm->name, "dpll", 4) == 0) 216 return 0; 217 218 d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir); 219 if (d) 220 (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d, 221 (void *)pwrdm, &pwrdm_suspend_fops); 222 223 return 0; 224 } 225 226 static int option_get(void *data, u64 *val) 227 { 228 u32 *option = data; 229 230 *val = *option; 231 232 return 0; 233 } 234 235 static int option_set(void *data, u64 val) 236 { 237 u32 *option = data; 238 239 *option = val; 240 241 if (option == &enable_off_mode) { 242 if (cpu_is_omap34xx()) 243 omap3_pm_off_mode_enable(val); 244 } 245 246 return 0; 247 } 248 249 DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n"); 250 251 static int __init pm_dbg_init(void) 252 { 253 struct dentry *d; 254 255 if (pm_dbg_init_done) 256 return 0; 257 258 d = debugfs_create_dir("pm_debug", NULL); 259 if (!d) 260 return -EINVAL; 261 262 (void) debugfs_create_file("count", S_IRUGO, 263 d, (void *)DEBUG_FILE_COUNTERS, &debug_fops); 264 (void) debugfs_create_file("time", S_IRUGO, 265 d, (void *)DEBUG_FILE_TIMERS, &debug_fops); 266 267 pwrdm_for_each(pwrdms_setup, (void *)d); 268 269 (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d, 270 &enable_off_mode, &pm_dbg_option_fops); 271 pm_dbg_init_done = 1; 272 273 return 0; 274 } 275 omap_arch_initcall(pm_dbg_init); 276 277 #endif 278