pm_opp.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * Generic OPP Interface
  3. *
  4. * Copyright (C) 2009-2010 Texas Instruments Incorporated.
  5. * Nishanth Menon
  6. * Romit Dasgupta
  7. * Kevin Hilman
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #ifndef __LINUX_OPP_H__
  14. #define __LINUX_OPP_H__
  15. #include <linux/err.h>
  16. #include <linux/notifier.h>
  17. struct clk;
  18. struct regulator;
  19. struct dev_pm_opp;
  20. struct device;
  21. struct opp_table;
  22. enum dev_pm_opp_event {
  23. OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
  24. };
  25. /**
  26. * struct dev_pm_opp_supply - Power supply voltage/current values
  27. * @u_volt: Target voltage in microvolts corresponding to this OPP
  28. * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
  29. * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
  30. * @u_amp: Maximum current drawn by the device in microamperes
  31. *
  32. * This structure stores the voltage/current values for a single power supply.
  33. */
  34. struct dev_pm_opp_supply {
  35. unsigned long u_volt;
  36. unsigned long u_volt_min;
  37. unsigned long u_volt_max;
  38. unsigned long u_amp;
  39. };
  40. /**
  41. * struct dev_pm_opp_info - OPP freq/voltage/current values
  42. * @rate: Target clk rate in hz
  43. * @supplies: Array of voltage/current values for all power supplies
  44. *
  45. * This structure stores the freq/voltage/current values for a single OPP.
  46. */
  47. struct dev_pm_opp_info {
  48. unsigned long rate;
  49. struct dev_pm_opp_supply *supplies;
  50. };
  51. /**
  52. * struct dev_pm_set_opp_data - Set OPP data
  53. * @old_opp: Old OPP info
  54. * @new_opp: New OPP info
  55. * @regulators: Array of regulator pointers
  56. * @regulator_count: Number of regulators
  57. * @clk: Pointer to clk
  58. * @dev: Pointer to the struct device
  59. *
  60. * This structure contains all information required for setting an OPP.
  61. */
  62. struct dev_pm_set_opp_data {
  63. struct dev_pm_opp_info old_opp;
  64. struct dev_pm_opp_info new_opp;
  65. struct regulator **regulators;
  66. unsigned int regulator_count;
  67. struct clk *clk;
  68. struct device *dev;
  69. };
  70. #if defined(CONFIG_PM_OPP)
  71. struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
  72. void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
  73. unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
  74. unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
  75. bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
  76. int dev_pm_opp_get_opp_count(struct device *dev);
  77. unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
  78. unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
  79. unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
  80. unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev);
  81. struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
  82. unsigned long freq,
  83. bool available);
  84. struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
  85. unsigned long *freq);
  86. struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
  87. unsigned long *freq);
  88. int dev_pm_opp_add(struct device *dev, unsigned long freq,
  89. unsigned long u_volt);
  90. void dev_pm_opp_remove(struct device *dev, unsigned long freq);
  91. int dev_pm_opp_enable(struct device *dev, unsigned long freq);
  92. int dev_pm_opp_disable(struct device *dev, unsigned long freq);
  93. int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
  94. int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
  95. int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
  96. unsigned int count);
  97. void dev_pm_opp_put_supported_hw(struct device *dev);
  98. int dev_pm_opp_set_prop_name(struct device *dev, const char *name);
  99. void dev_pm_opp_put_prop_name(struct device *dev);
  100. struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
  101. void dev_pm_opp_put_regulators(struct opp_table *opp_table);
  102. int dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
  103. void dev_pm_opp_register_put_opp_helper(struct device *dev);
  104. int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
  105. int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
  106. int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
  107. void dev_pm_opp_remove_table(struct device *dev);
  108. void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
  109. #else
  110. static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
  111. {
  112. return ERR_PTR(-ENOTSUPP);
  113. }
  114. static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
  115. static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
  116. {
  117. return 0;
  118. }
  119. static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
  120. {
  121. return 0;
  122. }
  123. static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
  124. {
  125. return false;
  126. }
  127. static inline int dev_pm_opp_get_opp_count(struct device *dev)
  128. {
  129. return 0;
  130. }
  131. static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
  132. {
  133. return 0;
  134. }
  135. static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
  136. {
  137. return 0;
  138. }
  139. static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
  140. {
  141. return 0;
  142. }
  143. static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
  144. {
  145. return 0;
  146. }
  147. static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
  148. unsigned long freq, bool available)
  149. {
  150. return ERR_PTR(-ENOTSUPP);
  151. }
  152. static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
  153. unsigned long *freq)
  154. {
  155. return ERR_PTR(-ENOTSUPP);
  156. }
  157. static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
  158. unsigned long *freq)
  159. {
  160. return ERR_PTR(-ENOTSUPP);
  161. }
  162. static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
  163. unsigned long u_volt)
  164. {
  165. return -ENOTSUPP;
  166. }
  167. static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
  168. {
  169. }
  170. static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
  171. {
  172. return 0;
  173. }
  174. static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
  175. {
  176. return 0;
  177. }
  178. static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
  179. {
  180. return -ENOTSUPP;
  181. }
  182. static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
  183. {
  184. return -ENOTSUPP;
  185. }
  186. static inline int dev_pm_opp_set_supported_hw(struct device *dev,
  187. const u32 *versions,
  188. unsigned int count)
  189. {
  190. return -ENOTSUPP;
  191. }
  192. static inline void dev_pm_opp_put_supported_hw(struct device *dev) {}
  193. static inline int dev_pm_opp_register_set_opp_helper(struct device *dev,
  194. int (*set_opp)(struct dev_pm_set_opp_data *data))
  195. {
  196. return -ENOTSUPP;
  197. }
  198. static inline void dev_pm_opp_register_put_opp_helper(struct device *dev) {}
  199. static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
  200. {
  201. return -ENOTSUPP;
  202. }
  203. static inline void dev_pm_opp_put_prop_name(struct device *dev) {}
  204. static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
  205. {
  206. return ERR_PTR(-ENOTSUPP);
  207. }
  208. static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
  209. static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
  210. {
  211. return -ENOTSUPP;
  212. }
  213. static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
  214. {
  215. return -ENOTSUPP;
  216. }
  217. static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
  218. {
  219. return -EINVAL;
  220. }
  221. static inline void dev_pm_opp_remove_table(struct device *dev)
  222. {
  223. }
  224. static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
  225. {
  226. }
  227. #endif /* CONFIG_PM_OPP */
  228. #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
  229. int dev_pm_opp_of_add_table(struct device *dev);
  230. void dev_pm_opp_of_remove_table(struct device *dev);
  231. int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
  232. void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
  233. int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
  234. #else
  235. static inline int dev_pm_opp_of_add_table(struct device *dev)
  236. {
  237. return -ENOTSUPP;
  238. }
  239. static inline void dev_pm_opp_of_remove_table(struct device *dev)
  240. {
  241. }
  242. static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
  243. {
  244. return -ENOTSUPP;
  245. }
  246. static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
  247. {
  248. }
  249. static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
  250. {
  251. return -ENOTSUPP;
  252. }
  253. #endif
  254. #endif /* __LINUX_OPP_H__ */