opp.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. * @rate: Frequency in hertz
  55. * @supplies: Power supplies voltage/current values
  56. * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
  57. * frequency from any other OPP's frequency.
  58. * @opp_table: points back to the opp_table struct this opp belongs to
  59. * @np: OPP's device node.
  60. * @dentry: debugfs dentry pointer (per opp)
  61. *
  62. * This structure stores the OPP information for a given device.
  63. */
  64. struct dev_pm_opp {
  65. struct list_head node;
  66. struct kref kref;
  67. bool available;
  68. bool dynamic;
  69. bool turbo;
  70. bool suspend;
  71. unsigned long rate;
  72. struct dev_pm_opp_supply *supplies;
  73. unsigned long clock_latency_ns;
  74. struct opp_table *opp_table;
  75. struct device_node *np;
  76. #ifdef CONFIG_DEBUG_FS
  77. struct dentry *dentry;
  78. #endif
  79. };
  80. /**
  81. * struct opp_device - devices managed by 'struct opp_table'
  82. * @node: list node
  83. * @dev: device to which the struct object belongs
  84. * @dentry: debugfs dentry pointer (per device)
  85. *
  86. * This is an internal data structure maintaining the devices that are managed
  87. * by 'struct opp_table'.
  88. */
  89. struct opp_device {
  90. struct list_head node;
  91. const struct device *dev;
  92. #ifdef CONFIG_DEBUG_FS
  93. struct dentry *dentry;
  94. #endif
  95. };
  96. enum opp_table_access {
  97. OPP_TABLE_ACCESS_UNKNOWN = 0,
  98. OPP_TABLE_ACCESS_EXCLUSIVE = 1,
  99. OPP_TABLE_ACCESS_SHARED = 2,
  100. };
  101. /**
  102. * struct opp_table - Device opp structure
  103. * @node: table node - contains the devices with OPPs that
  104. * have been registered. Nodes once added are not modified in this
  105. * table.
  106. * @head: notifier head to notify the OPP availability changes.
  107. * @dev_list: list of devices that share these OPPs
  108. * @opp_list: table of opps
  109. * @kref: for reference count of the table.
  110. * @lock: mutex protecting the opp_list.
  111. * @np: struct device_node pointer for opp's DT node.
  112. * @clock_latency_ns_max: Max clock latency in nanoseconds.
  113. * @shared_opp: OPP is shared between multiple devices.
  114. * @suspend_opp: Pointer to OPP to be used during device suspend.
  115. * @supported_hw: Array of version number to support.
  116. * @supported_hw_count: Number of elements in supported_hw array.
  117. * @prop_name: A name to postfix to many DT properties, while parsing them.
  118. * @clk: Device's clock handle
  119. * @regulators: Supply regulators
  120. * @regulator_count: Number of power supply regulators
  121. * @set_opp: Platform specific set_opp callback
  122. * @set_opp_data: Data to be passed to set_opp callback
  123. * @dentry: debugfs dentry pointer of the real device directory (not links).
  124. * @dentry_name: Name of the real dentry.
  125. *
  126. * @voltage_tolerance_v1: In percentage, for v1 bindings only.
  127. *
  128. * This is an internal data structure maintaining the link to opps attached to
  129. * a device. This structure is not meant to be shared to users as it is
  130. * meant for book keeping and private to OPP library.
  131. */
  132. struct opp_table {
  133. struct list_head node;
  134. struct blocking_notifier_head head;
  135. struct list_head dev_list;
  136. struct list_head opp_list;
  137. struct kref kref;
  138. struct mutex lock;
  139. struct device_node *np;
  140. unsigned long clock_latency_ns_max;
  141. /* For backward compatibility with v1 bindings */
  142. unsigned int voltage_tolerance_v1;
  143. enum opp_table_access shared_opp;
  144. struct dev_pm_opp *suspend_opp;
  145. unsigned int *supported_hw;
  146. unsigned int supported_hw_count;
  147. const char *prop_name;
  148. struct clk *clk;
  149. struct regulator **regulators;
  150. unsigned int regulator_count;
  151. int (*set_opp)(struct dev_pm_set_opp_data *data);
  152. struct dev_pm_set_opp_data *set_opp_data;
  153. #ifdef CONFIG_DEBUG_FS
  154. struct dentry *dentry;
  155. char dentry_name[NAME_MAX];
  156. #endif
  157. };
  158. /* Routines internal to opp core */
  159. void _get_opp_table_kref(struct opp_table *opp_table);
  160. struct opp_table *_find_opp_table(struct device *dev);
  161. struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table);
  162. void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, bool remove_all);
  163. void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all);
  164. struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table);
  165. void _opp_free(struct dev_pm_opp *opp);
  166. int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table);
  167. int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic);
  168. void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of);
  169. struct opp_table *_add_opp_table(struct device *dev);
  170. #ifdef CONFIG_OF
  171. void _of_init_opp_table(struct opp_table *opp_table, struct device *dev);
  172. #else
  173. static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {}
  174. #endif
  175. #ifdef CONFIG_DEBUG_FS
  176. void opp_debug_remove_one(struct dev_pm_opp *opp);
  177. int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table);
  178. int opp_debug_register(struct opp_device *opp_dev, struct opp_table *opp_table);
  179. void opp_debug_unregister(struct opp_device *opp_dev, struct opp_table *opp_table);
  180. #else
  181. static inline void opp_debug_remove_one(struct dev_pm_opp *opp) {}
  182. static inline int opp_debug_create_one(struct dev_pm_opp *opp,
  183. struct opp_table *opp_table)
  184. { return 0; }
  185. static inline int opp_debug_register(struct opp_device *opp_dev,
  186. struct opp_table *opp_table)
  187. { return 0; }
  188. static inline void opp_debug_unregister(struct opp_device *opp_dev,
  189. struct opp_table *opp_table)
  190. { }
  191. #endif /* DEBUG_FS */
  192. #endif /* __DRIVER_OPP_H__ */