omap-pm-noop.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*
  2. * omap-pm-noop.c - OMAP power management interface - dummy version
  3. *
  4. * This code implements the OMAP power management interface to
  5. * drivers, CPUIdle, CPUFreq, and DSP Bridge. It is strictly for
  6. * debug/demonstration use, as it does nothing but printk() whenever a
  7. * function is called (when DEBUG is defined, below)
  8. *
  9. * Copyright (C) 2008-2009 Texas Instruments, Inc.
  10. * Copyright (C) 2008-2009 Nokia Corporation
  11. * Paul Walmsley
  12. *
  13. * Interface developed by (in alphabetical order):
  14. * Karthik Dasu, Tony Lindgren, Rajendra Nayak, Sakari Poussa, Veeramanikandan
  15. * Raju, Anand Sawant, Igor Stoppa, Paul Walmsley, Richard Woodruff
  16. */
  17. #undef DEBUG
  18. #include <linux/init.h>
  19. #include <linux/cpufreq.h>
  20. #include <linux/device.h>
  21. #include <linux/platform_device.h>
  22. #include "omap_device.h"
  23. #include "omap-pm.h"
  24. static bool off_mode_enabled;
  25. static int dummy_context_loss_counter;
  26. /*
  27. * Device-driver-originated constraints (via board-*.c files)
  28. */
  29. int omap_pm_set_max_mpu_wakeup_lat(struct device *dev, long t)
  30. {
  31. if (!dev || t < -1) {
  32. WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
  33. return -EINVAL;
  34. }
  35. if (t == -1)
  36. pr_debug("OMAP PM: remove max MPU wakeup latency constraint: dev %s\n",
  37. dev_name(dev));
  38. else
  39. pr_debug("OMAP PM: add max MPU wakeup latency constraint: dev %s, t = %ld usec\n",
  40. dev_name(dev), t);
  41. /*
  42. * For current Linux, this needs to map the MPU to a
  43. * powerdomain, then go through the list of current max lat
  44. * constraints on the MPU and find the smallest. If
  45. * the latency constraint has changed, the code should
  46. * recompute the state to enter for the next powerdomain
  47. * state.
  48. *
  49. * TI CDP code can call constraint_set here.
  50. */
  51. return 0;
  52. }
  53. int omap_pm_set_min_bus_tput(struct device *dev, u8 agent_id, unsigned long r)
  54. {
  55. if (!dev || (agent_id != OCP_INITIATOR_AGENT &&
  56. agent_id != OCP_TARGET_AGENT)) {
  57. WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
  58. return -EINVAL;
  59. }
  60. if (r == 0)
  61. pr_debug("OMAP PM: remove min bus tput constraint: dev %s for agent_id %d\n",
  62. dev_name(dev), agent_id);
  63. else
  64. pr_debug("OMAP PM: add min bus tput constraint: dev %s for agent_id %d: rate %ld KiB\n",
  65. dev_name(dev), agent_id, r);
  66. /*
  67. * This code should model the interconnect and compute the
  68. * required clock frequency, convert that to a VDD2 OPP ID, then
  69. * set the VDD2 OPP appropriately.
  70. *
  71. * TI CDP code can call constraint_set here on the VDD2 OPP.
  72. */
  73. return 0;
  74. }
  75. int omap_pm_set_max_dev_wakeup_lat(struct device *req_dev, struct device *dev,
  76. long t)
  77. {
  78. if (!req_dev || !dev || t < -1) {
  79. WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
  80. return -EINVAL;
  81. }
  82. if (t == -1)
  83. pr_debug("OMAP PM: remove max device latency constraint: dev %s\n",
  84. dev_name(dev));
  85. else
  86. pr_debug("OMAP PM: add max device latency constraint: dev %s, t = %ld usec\n",
  87. dev_name(dev), t);
  88. /*
  89. * For current Linux, this needs to map the device to a
  90. * powerdomain, then go through the list of current max lat
  91. * constraints on that powerdomain and find the smallest. If
  92. * the latency constraint has changed, the code should
  93. * recompute the state to enter for the next powerdomain
  94. * state. Conceivably, this code should also determine
  95. * whether to actually disable the device clocks or not,
  96. * depending on how long it takes to re-enable the clocks.
  97. *
  98. * TI CDP code can call constraint_set here.
  99. */
  100. return 0;
  101. }
  102. int omap_pm_set_max_sdma_lat(struct device *dev, long t)
  103. {
  104. if (!dev || t < -1) {
  105. WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
  106. return -EINVAL;
  107. }
  108. if (t == -1)
  109. pr_debug("OMAP PM: remove max DMA latency constraint: dev %s\n",
  110. dev_name(dev));
  111. else
  112. pr_debug("OMAP PM: add max DMA latency constraint: dev %s, t = %ld usec\n",
  113. dev_name(dev), t);
  114. /*
  115. * For current Linux PM QOS params, this code should scan the
  116. * list of maximum CPU and DMA latencies and select the
  117. * smallest, then set cpu_dma_latency pm_qos_param
  118. * accordingly.
  119. *
  120. * For future Linux PM QOS params, with separate CPU and DMA
  121. * latency params, this code should just set the dma_latency param.
  122. *
  123. * TI CDP code can call constraint_set here.
  124. */
  125. return 0;
  126. }
  127. int omap_pm_set_min_clk_rate(struct device *dev, struct clk *c, long r)
  128. {
  129. if (!dev || !c || r < 0) {
  130. WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
  131. return -EINVAL;
  132. }
  133. if (r == 0)
  134. pr_debug("OMAP PM: remove min clk rate constraint: dev %s\n",
  135. dev_name(dev));
  136. else
  137. pr_debug("OMAP PM: add min clk rate constraint: dev %s, rate = %ld Hz\n",
  138. dev_name(dev), r);
  139. /*
  140. * Code in a real implementation should keep track of these
  141. * constraints on the clock, and determine the highest minimum
  142. * clock rate. It should iterate over each OPP and determine
  143. * whether the OPP will result in a clock rate that would
  144. * satisfy this constraint (and any other PM constraint in effect
  145. * at that time). Once it finds the lowest-voltage OPP that
  146. * meets those conditions, it should switch to it, or return
  147. * an error if the code is not capable of doing so.
  148. */
  149. return 0;
  150. }
  151. /*
  152. * DSP Bridge-specific constraints
  153. */
  154. const struct omap_opp *omap_pm_dsp_get_opp_table(void)
  155. {
  156. pr_debug("OMAP PM: DSP request for OPP table\n");
  157. /*
  158. * Return DSP frequency table here: The final item in the
  159. * array should have .rate = .opp_id = 0.
  160. */
  161. return NULL;
  162. }
  163. void omap_pm_dsp_set_min_opp(u8 opp_id)
  164. {
  165. if (opp_id == 0) {
  166. WARN_ON(1);
  167. return;
  168. }
  169. pr_debug("OMAP PM: DSP requests minimum VDD1 OPP to be %d\n", opp_id);
  170. /*
  171. *
  172. * For l-o dev tree, our VDD1 clk is keyed on OPP ID, so we
  173. * can just test to see which is higher, the CPU's desired OPP
  174. * ID or the DSP's desired OPP ID, and use whichever is
  175. * highest.
  176. *
  177. * In CDP12.14+, the VDD1 OPP custom clock that controls the DSP
  178. * rate is keyed on MPU speed, not the OPP ID. So we need to
  179. * map the OPP ID to the MPU speed for use with clk_set_rate()
  180. * if it is higher than the current OPP clock rate.
  181. *
  182. */
  183. }
  184. u8 omap_pm_dsp_get_opp(void)
  185. {
  186. pr_debug("OMAP PM: DSP requests current DSP OPP ID\n");
  187. /*
  188. * For l-o dev tree, call clk_get_rate() on VDD1 OPP clock
  189. *
  190. * CDP12.14+:
  191. * Call clk_get_rate() on the OPP custom clock, map that to an
  192. * OPP ID using the tables defined in board-*.c/chip-*.c files.
  193. */
  194. return 0;
  195. }
  196. /*
  197. * CPUFreq-originated constraint
  198. *
  199. * In the future, this should be handled by custom OPP clocktype
  200. * functions.
  201. */
  202. struct cpufreq_frequency_table **omap_pm_cpu_get_freq_table(void)
  203. {
  204. pr_debug("OMAP PM: CPUFreq request for frequency table\n");
  205. /*
  206. * Return CPUFreq frequency table here: loop over
  207. * all VDD1 clkrates, pull out the mpu_ck frequencies, build
  208. * table
  209. */
  210. return NULL;
  211. }
  212. void omap_pm_cpu_set_freq(unsigned long f)
  213. {
  214. if (f == 0) {
  215. WARN_ON(1);
  216. return;
  217. }
  218. pr_debug("OMAP PM: CPUFreq requests CPU frequency to be set to %lu\n",
  219. f);
  220. /*
  221. * For l-o dev tree, determine whether MPU freq or DSP OPP id
  222. * freq is higher. Find the OPP ID corresponding to the
  223. * higher frequency. Call clk_round_rate() and clk_set_rate()
  224. * on the OPP custom clock.
  225. *
  226. * CDP should just be able to set the VDD1 OPP clock rate here.
  227. */
  228. }
  229. unsigned long omap_pm_cpu_get_freq(void)
  230. {
  231. pr_debug("OMAP PM: CPUFreq requests current CPU frequency\n");
  232. /*
  233. * Call clk_get_rate() on the mpu_ck.
  234. */
  235. return 0;
  236. }
  237. /**
  238. * omap_pm_enable_off_mode - notify OMAP PM that off-mode is enabled
  239. *
  240. * Intended for use only by OMAP PM core code to notify this layer
  241. * that off mode has been enabled.
  242. */
  243. void omap_pm_enable_off_mode(void)
  244. {
  245. off_mode_enabled = true;
  246. }
  247. /**
  248. * omap_pm_disable_off_mode - notify OMAP PM that off-mode is disabled
  249. *
  250. * Intended for use only by OMAP PM core code to notify this layer
  251. * that off mode has been disabled.
  252. */
  253. void omap_pm_disable_off_mode(void)
  254. {
  255. off_mode_enabled = false;
  256. }
  257. /*
  258. * Device context loss tracking
  259. */
  260. #ifdef CONFIG_ARCH_OMAP2PLUS
  261. int omap_pm_get_dev_context_loss_count(struct device *dev)
  262. {
  263. struct platform_device *pdev = to_platform_device(dev);
  264. int count;
  265. if (WARN_ON(!dev))
  266. return -ENODEV;
  267. if (dev->pm_domain == &omap_device_pm_domain) {
  268. count = omap_device_get_context_loss_count(pdev);
  269. } else {
  270. WARN_ONCE(off_mode_enabled, "omap_pm: using dummy context loss counter; device %s should be converted to omap_device",
  271. dev_name(dev));
  272. count = dummy_context_loss_counter;
  273. if (off_mode_enabled) {
  274. count++;
  275. /*
  276. * Context loss count has to be a non-negative value.
  277. * Clear the sign bit to get a value range from 0 to
  278. * INT_MAX.
  279. */
  280. count &= INT_MAX;
  281. dummy_context_loss_counter = count;
  282. }
  283. }
  284. pr_debug("OMAP PM: context loss count for dev %s = %d\n",
  285. dev_name(dev), count);
  286. return count;
  287. }
  288. #else
  289. int omap_pm_get_dev_context_loss_count(struct device *dev)
  290. {
  291. return dummy_context_loss_counter;
  292. }
  293. #endif
  294. /* Should be called before clk framework init */
  295. int __init omap_pm_if_early_init(void)
  296. {
  297. return 0;
  298. }
  299. /* Must be called after clock framework is initialized */
  300. int __init omap_pm_if_init(void)
  301. {
  302. return 0;
  303. }
  304. void omap_pm_if_exit(void)
  305. {
  306. /* Deallocate CPUFreq frequency table here */
  307. }