pm-debug.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. #include <linux/kernel.h>
  22. #include <linux/sched.h>
  23. #include <linux/sched/clock.h>
  24. #include <linux/clk.h>
  25. #include <linux/err.h>
  26. #include <linux/io.h>
  27. #include <linux/module.h>
  28. #include <linux/slab.h>
  29. #include "clock.h"
  30. #include "powerdomain.h"
  31. #include "clockdomain.h"
  32. #include "omap-pm.h"
  33. #include "soc.h"
  34. #include "cm2xxx_3xxx.h"
  35. #include "prm2xxx_3xxx.h"
  36. #include "pm.h"
  37. u32 enable_off_mode;
  38. #ifdef CONFIG_DEBUG_FS
  39. #include <linux/debugfs.h>
  40. #include <linux/seq_file.h>
  41. static int pm_dbg_init_done;
  42. static int pm_dbg_init(void);
  43. enum {
  44. DEBUG_FILE_COUNTERS = 0,
  45. DEBUG_FILE_TIMERS,
  46. };
  47. static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
  48. "OFF",
  49. "RET",
  50. "INA",
  51. "ON"
  52. };
  53. void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
  54. {
  55. s64 t;
  56. if (!pm_dbg_init_done)
  57. return ;
  58. /* Update timer for previous state */
  59. t = sched_clock();
  60. pwrdm->state_timer[prev] += t - pwrdm->timer;
  61. pwrdm->timer = t;
  62. }
  63. static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
  64. {
  65. struct seq_file *s = (struct seq_file *)user;
  66. if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
  67. strcmp(clkdm->name, "wkup_clkdm") == 0 ||
  68. strncmp(clkdm->name, "dpll", 4) == 0)
  69. return 0;
  70. seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name,
  71. clkdm->usecount);
  72. return 0;
  73. }
  74. static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
  75. {
  76. struct seq_file *s = (struct seq_file *)user;
  77. int i;
  78. if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
  79. strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
  80. strncmp(pwrdm->name, "dpll", 4) == 0)
  81. return 0;
  82. if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
  83. printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
  84. pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
  85. seq_printf(s, "%s (%s)", pwrdm->name,
  86. pwrdm_state_names[pwrdm->state]);
  87. for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
  88. seq_printf(s, ",%s:%d", pwrdm_state_names[i],
  89. pwrdm->state_counter[i]);
  90. seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
  91. for (i = 0; i < pwrdm->banks; i++)
  92. seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
  93. pwrdm->ret_mem_off_counter[i]);
  94. seq_putc(s, '\n');
  95. return 0;
  96. }
  97. static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
  98. {
  99. struct seq_file *s = (struct seq_file *)user;
  100. int i;
  101. if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
  102. strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
  103. strncmp(pwrdm->name, "dpll", 4) == 0)
  104. return 0;
  105. pwrdm_state_switch(pwrdm);
  106. seq_printf(s, "%s (%s)", pwrdm->name,
  107. pwrdm_state_names[pwrdm->state]);
  108. for (i = 0; i < 4; i++)
  109. seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
  110. pwrdm->state_timer[i]);
  111. seq_putc(s, '\n');
  112. return 0;
  113. }
  114. static int pm_dbg_show_counters(struct seq_file *s, void *unused)
  115. {
  116. pwrdm_for_each(pwrdm_dbg_show_counter, s);
  117. clkdm_for_each(clkdm_dbg_show_counter, s);
  118. return 0;
  119. }
  120. static int pm_dbg_show_timers(struct seq_file *s, void *unused)
  121. {
  122. pwrdm_for_each(pwrdm_dbg_show_timer, s);
  123. return 0;
  124. }
  125. static int pm_dbg_open(struct inode *inode, struct file *file)
  126. {
  127. switch ((int)inode->i_private) {
  128. case DEBUG_FILE_COUNTERS:
  129. return single_open(file, pm_dbg_show_counters,
  130. &inode->i_private);
  131. case DEBUG_FILE_TIMERS:
  132. default:
  133. return single_open(file, pm_dbg_show_timers,
  134. &inode->i_private);
  135. }
  136. }
  137. static const struct file_operations debug_fops = {
  138. .open = pm_dbg_open,
  139. .read = seq_read,
  140. .llseek = seq_lseek,
  141. .release = single_release,
  142. };
  143. static int pwrdm_suspend_get(void *data, u64 *val)
  144. {
  145. int ret = -EINVAL;
  146. if (cpu_is_omap34xx())
  147. ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
  148. *val = ret;
  149. if (ret >= 0)
  150. return 0;
  151. return *val;
  152. }
  153. static int pwrdm_suspend_set(void *data, u64 val)
  154. {
  155. if (cpu_is_omap34xx())
  156. return omap3_pm_set_suspend_state(
  157. (struct powerdomain *)data, (int)val);
  158. return -EINVAL;
  159. }
  160. DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
  161. pwrdm_suspend_set, "%llu\n");
  162. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
  163. {
  164. int i;
  165. s64 t;
  166. struct dentry *d;
  167. t = sched_clock();
  168. for (i = 0; i < 4; i++)
  169. pwrdm->state_timer[i] = 0;
  170. pwrdm->timer = t;
  171. if (strncmp(pwrdm->name, "dpll", 4) == 0)
  172. return 0;
  173. d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
  174. if (d)
  175. (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
  176. (void *)pwrdm, &pwrdm_suspend_fops);
  177. return 0;
  178. }
  179. static int option_get(void *data, u64 *val)
  180. {
  181. u32 *option = data;
  182. *val = *option;
  183. return 0;
  184. }
  185. static int option_set(void *data, u64 val)
  186. {
  187. u32 *option = data;
  188. *option = val;
  189. if (option == &enable_off_mode) {
  190. if (val)
  191. omap_pm_enable_off_mode();
  192. else
  193. omap_pm_disable_off_mode();
  194. if (cpu_is_omap34xx())
  195. omap3_pm_off_mode_enable(val);
  196. }
  197. return 0;
  198. }
  199. DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
  200. static int __init pm_dbg_init(void)
  201. {
  202. struct dentry *d;
  203. if (pm_dbg_init_done)
  204. return 0;
  205. d = debugfs_create_dir("pm_debug", NULL);
  206. if (!d)
  207. return -EINVAL;
  208. (void) debugfs_create_file("count", S_IRUGO,
  209. d, (void *)DEBUG_FILE_COUNTERS, &debug_fops);
  210. (void) debugfs_create_file("time", S_IRUGO,
  211. d, (void *)DEBUG_FILE_TIMERS, &debug_fops);
  212. pwrdm_for_each(pwrdms_setup, (void *)d);
  213. (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
  214. &enable_off_mode, &pm_dbg_option_fops);
  215. pm_dbg_init_done = 1;
  216. return 0;
  217. }
  218. omap_arch_initcall(pm_dbg_init);
  219. #endif