pm-debug.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP Power Management debug routines
  4. *
  5. * Copyright (C) 2005 Texas Instruments, Inc.
  6. * Copyright (C) 2006-2008 Nokia Corporation
  7. *
  8. * Written by:
  9. * Richard Woodruff <[email protected]>
  10. * Tony Lindgren
  11. * Juha Yrjola
  12. * Amit Kucheria <[email protected]>
  13. * Igor Stoppa <[email protected]>
  14. * Jouni Hogander
  15. *
  16. * Based on pm.c for omap2
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/sched.h>
  20. #include <linux/sched/clock.h>
  21. #include <linux/clk.h>
  22. #include <linux/err.h>
  23. #include <linux/io.h>
  24. #include <linux/module.h>
  25. #include <linux/slab.h>
  26. #include "clock.h"
  27. #include "powerdomain.h"
  28. #include "clockdomain.h"
  29. #include "soc.h"
  30. #include "cm2xxx_3xxx.h"
  31. #include "prm2xxx_3xxx.h"
  32. #include "pm.h"
  33. #ifdef CONFIG_DEBUG_FS
  34. #include <linux/debugfs.h>
  35. #include <linux/seq_file.h>
  36. static int pm_dbg_init_done;
  37. static int pm_dbg_init(void);
  38. static const char pwrdm_state_names[][PWRDM_MAX_PWRSTS] = {
  39. "OFF",
  40. "RET",
  41. "INA",
  42. "ON"
  43. };
  44. void pm_dbg_update_time(struct powerdomain *pwrdm, int prev)
  45. {
  46. s64 t;
  47. if (!pm_dbg_init_done)
  48. return ;
  49. /* Update timer for previous state */
  50. t = sched_clock();
  51. pwrdm->state_timer[prev] += t - pwrdm->timer;
  52. pwrdm->timer = t;
  53. }
  54. static int clkdm_dbg_show_counter(struct clockdomain *clkdm, void *user)
  55. {
  56. struct seq_file *s = (struct seq_file *)user;
  57. if (strcmp(clkdm->name, "emu_clkdm") == 0 ||
  58. strcmp(clkdm->name, "wkup_clkdm") == 0 ||
  59. strncmp(clkdm->name, "dpll", 4) == 0)
  60. return 0;
  61. seq_printf(s, "%s->%s (%d)\n", clkdm->name, clkdm->pwrdm.ptr->name,
  62. clkdm->usecount);
  63. return 0;
  64. }
  65. static int pwrdm_dbg_show_counter(struct powerdomain *pwrdm, void *user)
  66. {
  67. struct seq_file *s = (struct seq_file *)user;
  68. int i;
  69. if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
  70. strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
  71. strncmp(pwrdm->name, "dpll", 4) == 0)
  72. return 0;
  73. if (pwrdm->state != pwrdm_read_pwrst(pwrdm))
  74. printk(KERN_ERR "pwrdm state mismatch(%s) %d != %d\n",
  75. pwrdm->name, pwrdm->state, pwrdm_read_pwrst(pwrdm));
  76. seq_printf(s, "%s (%s)", pwrdm->name,
  77. pwrdm_state_names[pwrdm->state]);
  78. for (i = 0; i < PWRDM_MAX_PWRSTS; i++)
  79. seq_printf(s, ",%s:%d", pwrdm_state_names[i],
  80. pwrdm->state_counter[i]);
  81. seq_printf(s, ",RET-LOGIC-OFF:%d", pwrdm->ret_logic_off_counter);
  82. for (i = 0; i < pwrdm->banks; i++)
  83. seq_printf(s, ",RET-MEMBANK%d-OFF:%d", i + 1,
  84. pwrdm->ret_mem_off_counter[i]);
  85. seq_putc(s, '\n');
  86. return 0;
  87. }
  88. static int pwrdm_dbg_show_timer(struct powerdomain *pwrdm, void *user)
  89. {
  90. struct seq_file *s = (struct seq_file *)user;
  91. int i;
  92. if (strcmp(pwrdm->name, "emu_pwrdm") == 0 ||
  93. strcmp(pwrdm->name, "wkup_pwrdm") == 0 ||
  94. strncmp(pwrdm->name, "dpll", 4) == 0)
  95. return 0;
  96. pwrdm_state_switch(pwrdm);
  97. seq_printf(s, "%s (%s)", pwrdm->name,
  98. pwrdm_state_names[pwrdm->state]);
  99. for (i = 0; i < 4; i++)
  100. seq_printf(s, ",%s:%lld", pwrdm_state_names[i],
  101. pwrdm->state_timer[i]);
  102. seq_putc(s, '\n');
  103. return 0;
  104. }
  105. static int pm_dbg_counters_show(struct seq_file *s, void *unused)
  106. {
  107. pwrdm_for_each(pwrdm_dbg_show_counter, s);
  108. clkdm_for_each(clkdm_dbg_show_counter, s);
  109. return 0;
  110. }
  111. DEFINE_SHOW_ATTRIBUTE(pm_dbg_counters);
  112. static int pm_dbg_timers_show(struct seq_file *s, void *unused)
  113. {
  114. pwrdm_for_each(pwrdm_dbg_show_timer, s);
  115. return 0;
  116. }
  117. DEFINE_SHOW_ATTRIBUTE(pm_dbg_timers);
  118. static int pwrdm_suspend_get(void *data, u64 *val)
  119. {
  120. int ret = -EINVAL;
  121. if (cpu_is_omap34xx())
  122. ret = omap3_pm_get_suspend_state((struct powerdomain *)data);
  123. *val = ret;
  124. if (ret >= 0)
  125. return 0;
  126. return *val;
  127. }
  128. static int pwrdm_suspend_set(void *data, u64 val)
  129. {
  130. if (cpu_is_omap34xx())
  131. return omap3_pm_set_suspend_state(
  132. (struct powerdomain *)data, (int)val);
  133. return -EINVAL;
  134. }
  135. DEFINE_DEBUGFS_ATTRIBUTE(pwrdm_suspend_fops, pwrdm_suspend_get,
  136. pwrdm_suspend_set, "%llu\n");
  137. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *dir)
  138. {
  139. int i;
  140. s64 t;
  141. struct dentry *d;
  142. t = sched_clock();
  143. for (i = 0; i < 4; i++)
  144. pwrdm->state_timer[i] = 0;
  145. pwrdm->timer = t;
  146. if (strncmp(pwrdm->name, "dpll", 4) == 0)
  147. return 0;
  148. d = debugfs_create_dir(pwrdm->name, (struct dentry *)dir);
  149. debugfs_create_file("suspend", S_IRUGO|S_IWUSR, d, pwrdm,
  150. &pwrdm_suspend_fops);
  151. return 0;
  152. }
  153. static int option_get(void *data, u64 *val)
  154. {
  155. u32 *option = data;
  156. *val = *option;
  157. return 0;
  158. }
  159. static int option_set(void *data, u64 val)
  160. {
  161. u32 *option = data;
  162. *option = val;
  163. if (option == &enable_off_mode) {
  164. if (cpu_is_omap34xx())
  165. omap3_pm_off_mode_enable(val);
  166. }
  167. return 0;
  168. }
  169. DEFINE_SIMPLE_ATTRIBUTE(pm_dbg_option_fops, option_get, option_set, "%llu\n");
  170. static int __init pm_dbg_init(void)
  171. {
  172. struct dentry *d;
  173. if (pm_dbg_init_done)
  174. return 0;
  175. d = debugfs_create_dir("pm_debug", NULL);
  176. debugfs_create_file("count", 0444, d, NULL, &pm_dbg_counters_fops);
  177. debugfs_create_file("time", 0444, d, NULL, &pm_dbg_timers_fops);
  178. pwrdm_for_each(pwrdms_setup, (void *)d);
  179. debugfs_create_file("enable_off_mode", S_IRUGO | S_IWUSR, d,
  180. &enable_off_mode, &pm_dbg_option_fops);
  181. pm_dbg_init_done = 1;
  182. return 0;
  183. }
  184. omap_arch_initcall(pm_dbg_init);
  185. #endif