opp.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 __DRIVER_OPP_H__
  14. #define __DRIVER_OPP_H__
  15. #include <linux/device.h>
  16. #include <linux/kernel.h>
  17. #include <linux/kref.h>
  18. #include <linux/list.h>
  19. #include <linux/limits.h>
  20. #include <linux/pm_opp.h>
  21. #include <linux/notifier.h>
  22. struct clk;
  23. struct regulator;
  24. /* Lock to allow exclusive modification to the device and opp lists */
  25. extern struct mutex opp_table_lock;
  26. extern struct list_head opp_tables;
  27. /*
  28. * Internal data structure organization with the OPP layer library is as
  29. * follows:
  30. * opp_tables (root)
  31. * |- device 1 (represents voltage domain 1)
  32. * | |- opp 1 (availability, freq, voltage)
  33. * | |- opp 2 ..
  34. * ... ...
  35. * | `- opp n ..
  36. * |- device 2 (represents the next voltage domain)
  37. * ...
  38. * `- device m (represents mth voltage domain)
  39. * device 1, 2.. are represented by opp_table structure while each opp
  40. * is represented by the opp structure.
  41. */
  42. /**
  43. * struct dev_pm_opp - Generic OPP description structure
  44. * @node: opp table node. The nodes are maintained throughout the lifetime
  45. * of boot. It is expected only an optimal set of OPPs are
  46. * added to the library by the SoC framework.
  47. * IMPORTANT: the opp nodes should be maintained in increasing
  48. * order.
  49. * @kref: for reference count of the OPP.
  50. * @available: true/false - marks if this OPP as available or not
  51. * @dynamic: not-created from static DT entries.
  52. * @turbo: true if turbo (boost) OPP
  53. * @suspend: true if suspend OPP
  54. * @pstate: Device's power domain's performance state.
  55. * @rate: Frequency in hertz
  56. * @supplies: Power supplies voltage/current values
  57. * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
  58. * frequency from any other OPP's frequency.
  59. * @opp_table: points back to the opp_table struct this opp belongs to
  60. * @np: OPP's device node.
  61. * @dentry: debugfs dentry pointer (per opp)
  62. *
  63. * This structure stores the OPP information for a given device.
  64. */
  65. struct dev_pm_opp {
  66. struct list_head node;
  67. struct kref kref;
  68. bool available;
  69. bool dynamic;
  70. bool turbo;
  71. bool suspend;
  72. unsigned int pstate;
  73. unsigned long rate;
  74. struct dev_pm_opp_supply *supplies;
  75. unsigned long clock_latency_ns;
  76. struct opp_table *opp_table;
  77. struct device_node *np;
  78. #ifdef CONFIG_DEBUG_FS
  79. struct dentry *dentry;
  80. #endif
  81. };
  82. /**
  83. * struct opp_device - devices managed by 'struct opp_table'
  84. * @node: list node
  85. * @dev: device to which the struct object belongs
  86. * @dentry: debugfs dentry pointer (per device)
  87. *
  88. * This is an internal data structure maintaining the devices that are managed
  89. * by 'struct opp_table'.
  90. */
  91. struct opp_device {
  92. struct list_head node;
  93. const struct device *dev;
  94. #ifdef CONFIG_DEBUG_FS
  95. struct dentry *dentry;
  96. #endif
  97. };
  98. enum opp_table_access {
  99. OPP_TABLE_ACCESS_UNKNOWN = 0,
  100. OPP_TABLE_ACCESS_EXCLUSIVE = 1,
  101. OPP_TABLE_ACCESS_SHARED = 2,
  102. };
  103. /**
  104. * struct opp_table - Device opp structure
  105. * @node: table node - contains the devices with OPPs that
  106. * have been registered. Nodes once added are not modified in this
  107. * table.
  108. * @head: notifier head to notify the OPP availability changes.
  109. * @dev_list: list of devices that share these OPPs
  110. * @opp_list: table of opps
  111. * @kref: for reference count of the table.
  112. * @lock: mutex protecting the opp_list.
  113. * @np: struct device_node pointer for opp's DT node.
  114. * @clock_latency_ns_max: Max clock latency in nanoseconds.
  115. * @shared_opp: OPP is shared between multiple devices.
  116. * @suspend_opp: Pointer to OPP to be used during device suspend.
  117. * @supported_hw: Array of version number to support.
  118. * @supported_hw_count: Number of elements in supported_hw array.
  119. * @prop_name: A name to postfix to many DT properties, while parsing them.
  120. * @clk: Device's clock handle
  121. * @regulators: Supply regulators
  122. * @regulator_count: Number of power supply regulators. Its value can be -1
  123. * (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt
  124. * property).
  125. * @genpd_performance_state: Device's power domain support performance state.
  126. * @set_opp: Platform specific set_opp callback
  127. * @set_opp_data: Data to be passed to set_opp callback
  128. * @dentry: debugfs dentry pointer of the real device directory (not links).
  129. * @dentry_name: Name of the real dentry.
  130. *
  131. * @voltage_tolerance_v1: In percentage, for v1 bindings only.
  132. *
  133. * This is an internal data structure maintaining the link to opps attached to
  134. * a device. This structure is not meant to be shared to users as it is
  135. * meant for book keeping and private to OPP library.
  136. */
  137. struct opp_table {
  138. struct list_head node;
  139. struct blocking_notifier_head head;
  140. struct list_head dev_list;
  141. struct list_head opp_list;
  142. struct kref kref;
  143. struct mutex lock;
  144. struct device_node *np;
  145. unsigned long clock_latency_ns_max;
  146. /* For backward compatibility with v1 bindings */
  147. unsigned int voltage_tolerance_v1;
  148. enum opp_table_access shared_opp;
  149. struct dev_pm_opp *suspend_opp;
  150. unsigned int *supported_hw;
  151. unsigned int supported_hw_count;
  152. const char *prop_name;
  153. struct clk *clk;
  154. struct regulator **regulators;
  155. int regulator_count;
  156. bool genpd_performance_state;
  157. int (*set_opp)(struct dev_pm_set_opp_data *data);
  158. struct dev_pm_set_opp_data *set_opp_data;
  159. #ifdef CONFIG_DEBUG_FS
  160. struct dentry *dentry;
  161. char dentry_name[NAME_MAX];
  162. #endif
  163. };
  164. /* Routines internal to opp core */
  165. void dev_pm_opp_get(struct dev_pm_opp *opp);
  166. void _get_opp_table_kref(struct opp_table *opp_table);
  167. int _get_opp_count(struct opp_table *opp_table);
  168. struct opp_table *_find_opp_table(struct device *dev);
  169. struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table);
  170. void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, bool remove_all);
  171. void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all);
  172. struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table);
  173. void _opp_free(struct dev_pm_opp *opp);
  174. int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available);
  175. int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic);
  176. void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of);
  177. struct opp_table *_add_opp_table(struct device *dev);
  178. #ifdef CONFIG_OF
  179. void _of_init_opp_table(struct opp_table *opp_table, struct device *dev);
  180. #else
  181. static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {}
  182. #endif
  183. #ifdef CONFIG_DEBUG_FS
  184. void opp_debug_remove_one(struct dev_pm_opp *opp);
  185. int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table);
  186. int opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table);
  187. void opp_debug_unregister(struct opp_device *opp_dev, struct opp_table *opp_table);
  188. #else
  189. static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {}
  190. static inline int opp_debug_create_one(struct dev_pm_opp *opp,
  191. struct opp_table *opp_table)
  192. { return 0; }
  193. static inline int opp_debug_register(struct opp_device *opp_dev,
  194. struct opp_table *opp_table)
  195. { return 0; }
  196. static inline void opp_debug_unregister(struct opp_device *opp_dev,
  197. struct opp_table *opp_table)
  198. { }
  199. #endif /* DEBUG_FS */
  200. #endif /* __DRIVER_OPP_H__ */