pm-debug.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 "soc.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. static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
  43. "OFF",
  44. "RET",
  45. "INA",
  46. "ON"
  47. };
  48. void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
  49. {
  50. s64 t;
  51. if (!pm_dbg_init_done)
  52. return ;
  53. /* Update timer for previous state */
  54. t = sched_clock();
  55. pwrdm->state_timer[prev] += t - pwrdm->timer;
  56. pwrdm->timer = t;
  57. }
  58. static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
  59. {
  60. struct seq_file *s = (struct seq_file *)user;
  61. if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
  62. strcmp(clkdm->name, "wkup_clkdm") == 0 ||
  63. strncmp(clkdm->name, "dpll", 4) == 0)
  64. return 0;
  65. seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name,
  66. clkdm->usecount);
  67. return 0;
  68. }
  69. static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
  70. {
  71. struct seq_file *s = (struct seq_file *)user;
  72. int i;
  73. if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
  74. strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
  75. strncmp(pwrdm->name, "dpll", 4) == 0)
  76. return 0;
  77. if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
  78. printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
  79. pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
  80. seq_printf(s, "%s (%s)", pwrdm->name,
  81. pwrdm_state_names[pwrdm->state]);
  82. for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
  83. seq_printf(s, ",%s:%d", pwrdm_state_names[i],
  84. pwrdm->state_counter[i]);
  85. seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
  86. for (i = 0; i < pwrdm->banks; i++)
  87. seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
  88. pwrdm->ret_mem_off_counter[i]);
  89. seq_putc(s, '\n');
  90. return 0;
  91. }
  92. static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
  93. {
  94. struct seq_file *s = (struct seq_file *)user;
  95. int i;
  96. if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
  97. strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
  98. strncmp(pwrdm->name, "dpll", 4) == 0)
  99. return 0;
  100. pwrdm_state_switch(pwrdm);
  101. seq_printf(s, "%s (%s)", pwrdm->name,
  102. pwrdm_state_names[pwrdm->state]);
  103. for (i = 0; i < 4; i++)
  104. seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
  105. pwrdm->state_timer[i]);
  106. seq_putc(s, '\n');
  107. return 0;
  108. }
  109. static int pm_dbg_counters_show(struct seq_file *s, void *unused)
  110. {
  111. pwrdm_for_each(pwrdm_dbg_show_counter, s);
  112. clkdm_for_each(clkdm_dbg_show_counter, s);
  113. return 0;
  114. }
  115. DEFINE_SHOW_ATTRIBUTE(pm_dbg_counters);
  116. static int pm_dbg_timers_show(struct seq_file *s, void *unused)
  117. {
  118. pwrdm_for_each(pwrdm_dbg_show_timer, s);
  119. return 0;
  120. }
  121. DEFINE_SHOW_ATTRIBUTE(pm_dbg_timers);
  122. static int pwrdm_suspend_get(void *data, u64 *val)
  123. {
  124. int ret = -EINVAL;
  125. if (cpu_is_omap34xx())
  126. ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
  127. *val = ret;
  128. if (ret >= 0)
  129. return 0;
  130. return *val;
  131. }
  132. static int pwrdm_suspend_set(void *data, u64 val)
  133. {
  134. if (cpu_is_omap34xx())
  135. return omap3_pm_set_suspend_state(
  136. (struct powerdomain *)data, (int)val);
  137. return -EINVAL;
  138. }
  139. DEFINE_SIMPLE_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
  140. pwrdm_suspend_set, "%llu\n");
  141. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
  142. {
  143. int i;
  144. s64 t;
  145. struct dentry *d;
  146. t = sched_clock();
  147. for (i = 0; i < 4; i++)
  148. pwrdm->state_timer[i] = 0;
  149. pwrdm->timer = t;
  150. if (strncmp(pwrdm->name, "dpll", 4) == 0)
  151. return 0;
  152. d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
  153. if (d)
  154. (void) debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d,
  155. (void *)pwrdm, &pwrdm_suspend_fops);
  156. return 0;
  157. }
  158. static int option_get(void *data, u64 *val)
  159. {
  160. u32 *option = data;
  161. *val = *option;
  162. return 0;
  163. }
  164. static int option_set(void *data, u64 val)
  165. {
  166. u32 *option = data;
  167. *option = val;
  168. if (option == &enable_off_mode) {
  169. if (cpu_is_omap34xx())
  170. omap3_pm_off_mode_enable(val);
  171. }
  172. return 0;
  173. }
  174. DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
  175. static int __init pm_dbg_init(void)
  176. {
  177. struct dentry *d;
  178. if (pm_dbg_init_done)
  179. return 0;
  180. d = debugfs_create_dir("pm_debug", NULL);
  181. if (!d)
  182. return -EINVAL;
  183. (void) debugfs_create_file("count", 0444, d, NULL, &pm_dbg_counters_fops);
  184. (void) debugfs_create_file("time", 0444, d, NULL, &pm_dbg_timers_fops);
  185. pwrdm_for_each(pwrdms_setup, (void *)d);
  186. (void) debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
  187. &enable_off_mode, &pm_dbg_option_fops);
  188. pm_dbg_init_done = 1;
  189. return 0;
  190. }
  191. omap_arch_initcall(pm_dbg_init);
  192. #endif