opp.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. * @supplies: Power supplies voltage/current values
  58. * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
  59. * frequency from any other OPP's frequency.
  60. * @opp_table: points back to the opp_table struct this opp belongs to
  61. * @rcu_head: RCU callback head used for deferred freeing
  62. * @np: OPP's device node.
  63. * @dentry: debugfs dentry pointer (per opp)
  64. *
  65. * This structure stores the OPP information for a given device.
  66. */
  67. struct dev_pm_opp {
  68. struct list_head node;
  69. bool available;
  70. bool dynamic;
  71. bool turbo;
  72. bool suspend;
  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 rcu_head rcu_head;
  78. struct device_node *np;
  79. #ifdef CONFIG_DEBUG_FS
  80. struct dentry *dentry;
  81. #endif
  82. };
  83. /**
  84. * struct opp_device - devices managed by 'struct opp_table'
  85. * @node: list node
  86. * @dev: device to which the struct object belongs
  87. * @rcu_head: RCU callback head used for deferred freeing
  88. * @dentry: debugfs dentry pointer (per device)
  89. *
  90. * This is an internal data structure maintaining the devices that are managed
  91. * by 'struct opp_table'.
  92. */
  93. struct opp_device {
  94. struct list_head node;
  95. const struct device *dev;
  96. struct rcu_head rcu_head;
  97. #ifdef CONFIG_DEBUG_FS
  98. struct dentry *dentry;
  99. #endif
  100. };
  101. enum opp_table_access {
  102. OPP_TABLE_ACCESS_UNKNOWN = 0,
  103. OPP_TABLE_ACCESS_EXCLUSIVE = 1,
  104. OPP_TABLE_ACCESS_SHARED = 2,
  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. * @regulators: Supply regulators
  126. * @regulator_count: Number of power supply regulators
  127. * @set_opp: Platform specific set_opp callback
  128. * @set_opp_data: Data to be passed to set_opp callback
  129. * @dentry: debugfs dentry pointer of the real device directory (not links).
  130. * @dentry_name: Name of the real dentry.
  131. *
  132. * @voltage_tolerance_v1: In percentage, for v1 bindings only.
  133. *
  134. * This is an internal data structure maintaining the link to opps attached to
  135. * a device. This structure is not meant to be shared to users as it is
  136. * meant for book keeping and private to OPP library.
  137. *
  138. * Because the opp structures can be used from both rcu and srcu readers, we
  139. * need to wait for the grace period of both of them before freeing any
  140. * resources. And so we have used kfree_rcu() from within call_srcu() handlers.
  141. */
  142. struct opp_table {
  143. struct list_head node;
  144. struct srcu_notifier_head srcu_head;
  145. struct rcu_head rcu_head;
  146. struct list_head dev_list;
  147. struct list_head opp_list;
  148. struct device_node *np;
  149. unsigned long clock_latency_ns_max;
  150. /* For backward compatibility with v1 bindings */
  151. unsigned int voltage_tolerance_v1;
  152. enum opp_table_access shared_opp;
  153. struct dev_pm_opp *suspend_opp;
  154. unsigned int *supported_hw;
  155. unsigned int supported_hw_count;
  156. const char *prop_name;
  157. struct clk *clk;
  158. struct regulator **regulators;
  159. unsigned int regulator_count;
  160. int (*set_opp)(struct dev_pm_set_opp_data *data);
  161. struct dev_pm_set_opp_data *set_opp_data;
  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. void _dev_pm_opp_remove_table(struct device *dev, bool remove_all);
  171. struct dev_pm_opp *_allocate_opp(struct device *dev, struct opp_table **opp_table);
  172. int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table);
  173. void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp, bool notify);
  174. int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, bool dynamic);
  175. void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of);
  176. #ifdef CONFIG_OF
  177. void _of_init_opp_table(struct opp_table *opp_table, struct device *dev);
  178. #else
  179. static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {}
  180. #endif
  181. #ifdef CONFIG_DEBUG_FS
  182. void opp_debug_remove_one(struct dev_pm_opp *opp);
  183. int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table);
  184. int opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table);
  185. void opp_debug_unregister(struct opp_device *opp_dev, struct opp_table *opp_table);
  186. #else
  187. static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {}
  188. static inline int opp_debug_create_one(struct dev_pm_opp *opp,
  189. struct opp_table *opp_table)
  190. { return 0; }
  191. static inline int opp_debug_register(struct opp_device *opp_dev,
  192. struct opp_table *opp_table)
  193. { return 0; }
  194. static inline void opp_debug_unregister(struct opp_device *opp_dev,
  195. struct opp_table *opp_table)
  196. { }
  197. #endif /* DEBUG_FS */
  198. #endif /* __DRIVER_OPP_H__ */