pm-debug.c 5.9 KB

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