omap-pm-noop.c 9.0 KB

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