pm_opp.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. void dev_pm_opp_put(struct dev_pm_opp *opp);
  89. int dev_pm_opp_add(struct device *dev, unsigned long freq,
  90. unsigned long u_volt);
  91. void dev_pm_opp_remove(struct device *dev, unsigned long freq);
  92. int dev_pm_opp_enable(struct device *dev, unsigned long freq);
  93. int dev_pm_opp_disable(struct device *dev, unsigned long freq);
  94. int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
  95. int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
  96. struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
  97. void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
  98. struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
  99. void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
  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. struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
  103. void dev_pm_opp_put_clkname(struct opp_table *opp_table);
  104. struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
  105. void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
  106. int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
  107. int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
  108. int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
  109. void dev_pm_opp_remove_table(struct device *dev);
  110. void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
  111. #else
  112. static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
  113. {
  114. return ERR_PTR(-ENOTSUPP);
  115. }
  116. static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
  117. static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
  118. {
  119. return 0;
  120. }
  121. static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
  122. {
  123. return 0;
  124. }
  125. static inline bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp)
  126. {
  127. return false;
  128. }
  129. static inline int dev_pm_opp_get_opp_count(struct device *dev)
  130. {
  131. return 0;
  132. }
  133. static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
  134. {
  135. return 0;
  136. }
  137. static inline unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev)
  138. {
  139. return 0;
  140. }
  141. static inline unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev)
  142. {
  143. return 0;
  144. }
  145. static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
  146. {
  147. return 0;
  148. }
  149. static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
  150. unsigned long freq, bool available)
  151. {
  152. return ERR_PTR(-ENOTSUPP);
  153. }
  154. static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
  155. unsigned long *freq)
  156. {
  157. return ERR_PTR(-ENOTSUPP);
  158. }
  159. static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
  160. unsigned long *freq)
  161. {
  162. return ERR_PTR(-ENOTSUPP);
  163. }
  164. static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
  165. static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
  166. unsigned long u_volt)
  167. {
  168. return -ENOTSUPP;
  169. }
  170. static inline void dev_pm_opp_remove(struct device *dev, unsigned long freq)
  171. {
  172. }
  173. static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
  174. {
  175. return 0;
  176. }
  177. static inline int dev_pm_opp_disable(struct device *dev, unsigned long freq)
  178. {
  179. return 0;
  180. }
  181. static inline int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
  182. {
  183. return -ENOTSUPP;
  184. }
  185. static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb)
  186. {
  187. return -ENOTSUPP;
  188. }
  189. static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
  190. const u32 *versions,
  191. unsigned int count)
  192. {
  193. return ERR_PTR(-ENOTSUPP);
  194. }
  195. static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
  196. static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
  197. int (*set_opp)(struct dev_pm_set_opp_data *data))
  198. {
  199. return ERR_PTR(-ENOTSUPP);
  200. }
  201. static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
  202. static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
  203. {
  204. return ERR_PTR(-ENOTSUPP);
  205. }
  206. static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
  207. static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count)
  208. {
  209. return ERR_PTR(-ENOTSUPP);
  210. }
  211. static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
  212. static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name)
  213. {
  214. return ERR_PTR(-ENOTSUPP);
  215. }
  216. static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
  217. static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
  218. {
  219. return -ENOTSUPP;
  220. }
  221. static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask)
  222. {
  223. return -ENOTSUPP;
  224. }
  225. static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
  226. {
  227. return -EINVAL;
  228. }
  229. static inline void dev_pm_opp_remove_table(struct device *dev)
  230. {
  231. }
  232. static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask)
  233. {
  234. }
  235. #endif /* CONFIG_PM_OPP */
  236. #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
  237. int dev_pm_opp_of_add_table(struct device *dev);
  238. int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
  239. void dev_pm_opp_of_remove_table(struct device *dev);
  240. int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
  241. void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
  242. int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
  243. struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
  244. struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np);
  245. struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
  246. #else
  247. static inline int dev_pm_opp_of_add_table(struct device *dev)
  248. {
  249. return -ENOTSUPP;
  250. }
  251. static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
  252. {
  253. return -ENOTSUPP;
  254. }
  255. static inline void dev_pm_opp_of_remove_table(struct device *dev)
  256. {
  257. }
  258. static inline int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
  259. {
  260. return -ENOTSUPP;
  261. }
  262. static inline void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
  263. {
  264. }
  265. static inline int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
  266. {
  267. return -ENOTSUPP;
  268. }
  269. static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
  270. {
  271. return NULL;
  272. }
  273. static inline struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np)
  274. {
  275. return NULL;
  276. }
  277. static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
  278. {
  279. return NULL;
  280. }
  281. #endif
  282. #endif /* __LINUX_OPP_H__ */