pm_opp.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
  72. unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
  73. bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
  74. int dev_pm_opp_get_opp_count(struct device *dev);
  75. unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
  76. unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev);
  77. unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev);
  78. struct dev_pm_opp *dev_pm_opp_get_suspend_opp(struct device *dev);
  79. struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
  80. unsigned long freq,
  81. bool available);
  82. struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
  83. unsigned long *freq);
  84. struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
  85. unsigned long *freq);
  86. int dev_pm_opp_add(struct device *dev, unsigned long freq,
  87. unsigned long u_volt);
  88. void dev_pm_opp_remove(struct device *dev, unsigned long freq);
  89. int dev_pm_opp_enable(struct device *dev, unsigned long freq);
  90. int dev_pm_opp_disable(struct device *dev, unsigned long freq);
  91. struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev);
  92. int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
  93. unsigned int count);
  94. void dev_pm_opp_put_supported_hw(struct device *dev);
  95. int dev_pm_opp_set_prop_name(struct device *dev, const char *name);
  96. void dev_pm_opp_put_prop_name(struct device *dev);
  97. struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
  98. void dev_pm_opp_put_regulators(struct opp_table *opp_table);
  99. int dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
  100. void dev_pm_opp_register_put_opp_helper(struct device *dev);
  101. int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
  102. int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
  103. int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
  104. void dev_pm_opp_remove_table(struct device *dev);
  105. void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
  106. #else
  107. static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
  108. {
  109. return 0;
  110. }
  111. static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
  112. {
  113. return 0;
  114. }
  115. static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
  116. {
  117. return false;
  118. }
  119. static inline int dev_pm_opp_get_opp_count(struct device *dev)
  120. {
  121. return 0;
  122. }
  123. static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
  124. {
  125. return 0;
  126. }
  127. static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
  128. {
  129. return 0;
  130. }
  131. static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
  132. {
  133. return 0;
  134. }
  135. static inline struct dev_pm_opp *dev_pm_opp_get_suspend_opp(struct device *dev)
  136. {
  137. return NULL;
  138. }
  139. static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
  140. unsigned long freq, bool available)
  141. {
  142. return ERR_PTR(-ENOTSUPP);
  143. }
  144. static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
  145. unsigned long *freq)
  146. {
  147. return ERR_PTR(-ENOTSUPP);
  148. }
  149. static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
  150. unsigned long *freq)
  151. {
  152. return ERR_PTR(-ENOTSUPP);
  153. }
  154. static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
  155. unsigned long u_volt)
  156. {
  157. return -ENOTSUPP;
  158. }
  159. static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
  160. {
  161. }
  162. static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
  163. {
  164. return 0;
  165. }
  166. static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
  167. {
  168. return 0;
  169. }
  170. static inline struct srcu_notifier_head *dev_pm_opp_get_notifier(
  171. struct device *dev)
  172. {
  173. return ERR_PTR(-ENOTSUPP);
  174. }
  175. static inline int dev_pm_opp_set_supported_hw(struct device *dev,
  176. const u32 *versions,
  177. unsigned int count)
  178. {
  179. return -ENOTSUPP;
  180. }
  181. static inline void dev_pm_opp_put_supported_hw(struct device *dev) {}
  182. static inline int dev_pm_opp_register_set_opp_helper(struct device *dev,
  183. int (*set_opp)(struct dev_pm_set_opp_data *data))
  184. {
  185. return -ENOTSUPP;
  186. }
  187. static inline void dev_pm_opp_register_put_opp_helper(struct device *dev) {}
  188. static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
  189. {
  190. return -ENOTSUPP;
  191. }
  192. static inline void dev_pm_opp_put_prop_name(struct device *dev) {}
  193. static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
  194. {
  195. return ERR_PTR(-ENOTSUPP);
  196. }
  197. static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
  198. static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
  199. {
  200. return -ENOTSUPP;
  201. }
  202. static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
  203. {
  204. return -ENOTSUPP;
  205. }
  206. static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
  207. {
  208. return -EINVAL;
  209. }
  210. static inline void dev_pm_opp_remove_table(struct device *dev)
  211. {
  212. }
  213. static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
  214. {
  215. }
  216. #endif /* CONFIG_PM_OPP */
  217. #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
  218. int dev_pm_opp_of_add_table(struct device *dev);
  219. void dev_pm_opp_of_remove_table(struct device *dev);
  220. int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
  221. void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
  222. int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
  223. struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
  224. #else
  225. static inline int dev_pm_opp_of_add_table(struct device *dev)
  226. {
  227. return -ENOTSUPP;
  228. }
  229. static inline void dev_pm_opp_of_remove_table(struct device *dev)
  230. {
  231. }
  232. static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
  233. {
  234. return -ENOTSUPP;
  235. }
  236. static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
  237. {
  238. }
  239. static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
  240. {
  241. return -ENOTSUPP;
  242. }
  243. static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
  244. {
  245. return NULL;
  246. }
  247. #endif
  248. #endif /* __LINUX_OPP_H__ */