opp.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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/list.h>
  18. #include <linux/limits.h>
  19. #include <linux/pm_opp.h>
  20. #include <linux/rculist.h>
  21. #include <linux/rcupdate.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. * RCU usage: opp table is traversed with RCU locks. node
  48. * modification is possible realtime, hence the modifications
  49. * are protected by the opp_table_lock for integrity.
  50. * IMPORTANT: the opp nodes should be maintained in increasing
  51. * order.
  52. * @available: true/false - marks if this OPP as available or not
  53. * @dynamic: not-created from static DT entries.
  54. * @turbo: true if turbo (boost) OPP
  55. * @suspend: true if suspend OPP
  56. * @rate: Frequency in hertz
  57. * @u_volt: Target voltage in microvolts corresponding to this OPP
  58. * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
  59. * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
  60. * @u_amp: Maximum current drawn by the device in microamperes
  61. * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
  62. * frequency from any other OPP's frequency.
  63. * @opp_table: points back to the opp_table struct this opp belongs to
  64. * @rcu_head: RCU callback head used for deferred freeing
  65. * @np: OPP's device node.
  66. * @dentry: debugfs dentry pointer (per opp)
  67. *
  68. * This structure stores the OPP information for a given device.
  69. */
  70. struct dev_pm_opp {
  71. struct list_head node;
  72. bool available;
  73. bool dynamic;
  74. bool turbo;
  75. bool suspend;
  76. unsigned long rate;
  77. unsigned long u_volt;
  78. unsigned long u_volt_min;
  79. unsigned long u_volt_max;
  80. unsigned long u_amp;
  81. unsigned long clock_latency_ns;
  82. struct opp_table *opp_table;
  83. struct rcu_head rcu_head;
  84. struct device_node *np;
  85. #ifdef CONFIG_DEBUG_FS
  86. struct dentry *dentry;
  87. #endif
  88. };
  89. /**
  90. * struct opp_device - devices managed by 'struct opp_table'
  91. * @node: list node
  92. * @dev: device to which the struct object belongs
  93. * @rcu_head: RCU callback head used for deferred freeing
  94. * @dentry: debugfs dentry pointer (per device)
  95. *
  96. * This is an internal data structure maintaining the devices that are managed
  97. * by 'struct opp_table'.
  98. */
  99. struct opp_device {
  100. struct list_head node;
  101. const struct device *dev;
  102. struct rcu_head rcu_head;
  103. #ifdef CONFIG_DEBUG_FS
  104. struct dentry *dentry;
  105. #endif
  106. };
  107. enum opp_table_access {
  108. OPP_TABLE_ACCESS_UNKNOWN = 0,
  109. OPP_TABLE_ACCESS_EXCLUSIVE = 1,
  110. OPP_TABLE_ACCESS_SHARED = 2,
  111. };
  112. /**
  113. * struct opp_table - Device opp structure
  114. * @node: table node - contains the devices with OPPs that
  115. * have been registered. Nodes once added are not modified in this
  116. * table.
  117. * RCU usage: nodes are not modified in the table of opp_table,
  118. * however addition is possible and is secured by opp_table_lock
  119. * @srcu_head: notifier head to notify the OPP availability changes.
  120. * @rcu_head: RCU callback head used for deferred freeing
  121. * @dev_list: list of devices that share these OPPs
  122. * @opp_list: table of opps
  123. * @np: struct device_node pointer for opp's DT node.
  124. * @clock_latency_ns_max: Max clock latency in nanoseconds.
  125. * @shared_opp: OPP is shared between multiple devices.
  126. * @suspend_opp: Pointer to OPP to be used during device suspend.
  127. * @supported_hw: Array of version number to support.
  128. * @supported_hw_count: Number of elements in supported_hw array.
  129. * @prop_name: A name to postfix to many DT properties, while parsing them.
  130. * @clk: Device's clock handle
  131. * @regulator: Supply regulator
  132. * @dentry: debugfs dentry pointer of the real device directory (not links).
  133. * @dentry_name: Name of the real dentry.
  134. *
  135. * @voltage_tolerance_v1: In percentage, for v1 bindings only.
  136. *
  137. * This is an internal data structure maintaining the link to opps attached to
  138. * a device. This structure is not meant to be shared to users as it is
  139. * meant for book keeping and private to OPP library.
  140. *
  141. * Because the opp structures can be used from both rcu and srcu readers, we
  142. * need to wait for the grace period of both of them before freeing any
  143. * resources. And so we have used kfree_rcu() from within call_srcu() handlers.
  144. */
  145. struct opp_table {
  146. struct list_head node;
  147. struct srcu_notifier_head srcu_head;
  148. struct rcu_head rcu_head;
  149. struct list_head dev_list;
  150. struct list_head opp_list;
  151. struct device_node *np;
  152. unsigned long clock_latency_ns_max;
  153. /* For backward compatibility with v1 bindings */
  154. unsigned int voltage_tolerance_v1;
  155. enum opp_table_access shared_opp;
  156. struct dev_pm_opp *suspend_opp;
  157. unsigned int *supported_hw;
  158. unsigned int supported_hw_count;
  159. const char *prop_name;
  160. struct clk *clk;
  161. struct regulator *regulator;
  162. #ifdef CONFIG_DEBUG_FS
  163. struct dentry *dentry;
  164. char dentry_name[NAME_MAX];
  165. #endif
  166. };
  167. /* Routines internal to opp core */
  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. struct device_node *_of_get_opp_desc_node(struct device *dev);
  171. void _dev_pm_opp_remove_table(struct device *dev, bool remove_all);
  172. struct dev_pm_opp *_allocate_opp(struct device *dev, struct opp_table **opp_table);
  173. int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table);
  174. void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp, bool notify);
  175. int _opp_add_v1(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. #ifdef CONFIG_OF
  178. void _of_init_opp_table(struct opp_table *opp_table, struct device *dev);
  179. #else
  180. static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {}
  181. #endif
  182. #ifdef CONFIG_DEBUG_FS
  183. void opp_debug_remove_one(struct dev_pm_opp *opp);
  184. int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table);
  185. int opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table);
  186. void opp_debug_unregister(struct opp_device *opp_dev, struct opp_table *opp_table);
  187. #else
  188. static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {}
  189. static inline int opp_debug_create_one(struct dev_pm_opp *opp,
  190. struct opp_table *opp_table)
  191. { return 0; }
  192. static inline int opp_debug_register(struct opp_device *opp_dev,
  193. struct opp_table *opp_table)
  194. { return 0; }
  195. static inline void opp_debug_unregister(struct opp_device *opp_dev,
  196. struct opp_table *opp_table)
  197. { }
  198. #endif /* DEBUG_FS */
  199. #endif /* __DRIVER_OPP_H__ */