opp.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. /*
  27. * Internal data structure organization with the OPP layer library is as
  28. * follows:
  29. * opp_tables (root)
  30. * |- device 1 (represents voltage domain 1)
  31. * | |- opp 1 (availability, freq, voltage)
  32. * | |- opp 2 ..
  33. * ... ...
  34. * | `- opp n ..
  35. * |- device 2 (represents the next voltage domain)
  36. * ...
  37. * `- device m (represents mth voltage domain)
  38. * device 1, 2.. are represented by opp_table structure while each opp
  39. * is represented by the opp structure.
  40. */
  41. /**
  42. * struct dev_pm_opp - Generic OPP description structure
  43. * @node: opp table node. The nodes are maintained throughout the lifetime
  44. * of boot. It is expected only an optimal set of OPPs are
  45. * added to the library by the SoC framework.
  46. * RCU usage: opp table is traversed with RCU locks. node
  47. * modification is possible realtime, hence the modifications
  48. * are protected by the opp_table_lock for integrity.
  49. * IMPORTANT: the opp nodes should be maintained in increasing
  50. * order.
  51. * @available: true/false - marks if this OPP as available or not
  52. * @dynamic: not-created from static DT entries.
  53. * @turbo: true if turbo (boost) OPP
  54. * @suspend: true if suspend OPP
  55. * @rate: Frequency in hertz
  56. * @u_volt: Target voltage in microvolts corresponding to this OPP
  57. * @u_volt_min: Minimum voltage in microvolts corresponding to this OPP
  58. * @u_volt_max: Maximum voltage in microvolts corresponding to this OPP
  59. * @u_amp: Maximum current drawn by the device in microamperes
  60. * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
  61. * frequency from any other OPP's frequency.
  62. * @opp_table: points back to the opp_table struct this opp belongs to
  63. * @rcu_head: RCU callback head used for deferred freeing
  64. * @np: OPP's device node.
  65. * @dentry: debugfs dentry pointer (per opp)
  66. *
  67. * This structure stores the OPP information for a given device.
  68. */
  69. struct dev_pm_opp {
  70. struct list_head node;
  71. bool available;
  72. bool dynamic;
  73. bool turbo;
  74. bool suspend;
  75. unsigned long rate;
  76. unsigned long u_volt;
  77. unsigned long u_volt_min;
  78. unsigned long u_volt_max;
  79. unsigned long u_amp;
  80. unsigned long clock_latency_ns;
  81. struct opp_table *opp_table;
  82. struct rcu_head rcu_head;
  83. struct device_node *np;
  84. #ifdef CONFIG_DEBUG_FS
  85. struct dentry *dentry;
  86. #endif
  87. };
  88. /**
  89. * struct opp_device - devices managed by 'struct opp_table'
  90. * @node: list node
  91. * @dev: device to which the struct object belongs
  92. * @rcu_head: RCU callback head used for deferred freeing
  93. * @dentry: debugfs dentry pointer (per device)
  94. *
  95. * This is an internal data structure maintaining the devices that are managed
  96. * by 'struct opp_table'.
  97. */
  98. struct opp_device {
  99. struct list_head node;
  100. const struct device *dev;
  101. struct rcu_head rcu_head;
  102. #ifdef CONFIG_DEBUG_FS
  103. struct dentry *dentry;
  104. #endif
  105. };
  106. /**
  107. * struct opp_table - Device opp structure
  108. * @node: table node - contains the devices with OPPs that
  109. * have been registered. Nodes once added are not modified in this
  110. * table.
  111. * RCU usage: nodes are not modified in the table of opp_table,
  112. * however addition is possible and is secured by opp_table_lock
  113. * @srcu_head: notifier head to notify the OPP availability changes.
  114. * @rcu_head: RCU callback head used for deferred freeing
  115. * @dev_list: list of devices that share these OPPs
  116. * @opp_list: table of opps
  117. * @np: struct device_node pointer for opp's DT node.
  118. * @clock_latency_ns_max: Max clock latency in nanoseconds.
  119. * @shared_opp: OPP is shared between multiple devices.
  120. * @suspend_opp: Pointer to OPP to be used during device suspend.
  121. * @supported_hw: Array of version number to support.
  122. * @supported_hw_count: Number of elements in supported_hw array.
  123. * @prop_name: A name to postfix to many DT properties, while parsing them.
  124. * @clk: Device's clock handle
  125. * @regulator: Supply regulator
  126. * @dentry: debugfs dentry pointer of the real device directory (not links).
  127. * @dentry_name: Name of the real dentry.
  128. *
  129. * @voltage_tolerance_v1: In percentage, for v1 bindings only.
  130. *
  131. * This is an internal data structure maintaining the link to opps attached to
  132. * a device. This structure is not meant to be shared to users as it is
  133. * meant for book keeping and private to OPP library.
  134. *
  135. * Because the opp structures can be used from both rcu and srcu readers, we
  136. * need to wait for the grace period of both of them before freeing any
  137. * resources. And so we have used kfree_rcu() from within call_srcu() handlers.
  138. */
  139. struct opp_table {
  140. struct list_head node;
  141. struct srcu_notifier_head srcu_head;
  142. struct rcu_head rcu_head;
  143. struct list_head dev_list;
  144. struct list_head opp_list;
  145. struct device_node *np;
  146. unsigned long clock_latency_ns_max;
  147. /* For backward compatibility with v1 bindings */
  148. unsigned int voltage_tolerance_v1;
  149. bool shared_opp;
  150. struct dev_pm_opp *suspend_opp;
  151. unsigned int *supported_hw;
  152. unsigned int supported_hw_count;
  153. const char *prop_name;
  154. struct clk *clk;
  155. struct regulator *regulator;
  156. #ifdef CONFIG_DEBUG_FS
  157. struct dentry *dentry;
  158. char dentry_name[NAME_MAX];
  159. #endif
  160. };
  161. /* Routines internal to opp core */
  162. struct opp_table *_find_opp_table(struct device *dev);
  163. struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table);
  164. struct device_node *_of_get_opp_desc_node(struct device *dev);
  165. #ifdef CONFIG_DEBUG_FS
  166. void opp_debug_remove_one(struct dev_pm_opp *opp);
  167. int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table);
  168. int opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table);
  169. void opp_debug_unregister(struct opp_device *opp_dev, struct opp_table *opp_table);
  170. #else
  171. static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {}
  172. static inline int opp_debug_create_one(struct dev_pm_opp *opp,
  173. struct opp_table *opp_table)
  174. { return 0; }
  175. static inline int opp_debug_register(struct opp_device *opp_dev,
  176. struct opp_table *opp_table)
  177. { return 0; }
  178. static inline void opp_debug_unregister(struct opp_device *opp_dev,
  179. struct opp_table *opp_table)
  180. { }
  181. #endif /* DEBUG_FS */
  182. #endif /* __DRIVER_OPP_H__ */