omap-pm-noop.c 9.1 KB

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