pm-debug.c 6.8 KB

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