devfreq-event.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * devfreq-event: a framework to provide raw data and events of devfreq devices
  4. *
  5. * Copyright (C) 2014 Samsung Electronics
  6. * Author: Chanwoo Choi <cw00.choi@samsung.com>
  7. */
  8. #ifndef __LINUX_DEVFREQ_EVENT_H__
  9. #define __LINUX_DEVFREQ_EVENT_H__
  10. #include <linux/device.h>
  11. /**
  12. * struct devfreq_event_dev - the devfreq-event device
  13. *
  14. * @node : Contain the devfreq-event device that have been registered.
  15. * @dev : the device registered by devfreq-event class. dev.parent is
  16. * the device using devfreq-event.
  17. * @lock : a mutex to protect accessing devfreq-event.
  18. * @enable_count: the number of enable function have been called.
  19. * @desc : the description for devfreq-event device.
  20. *
  21. * This structure contains devfreq-event device information.
  22. */
  23. struct devfreq_event_dev {
  24. struct list_head node;
  25. struct device dev;
  26. struct mutex lock;
  27. u32 enable_count;
  28. const struct devfreq_event_desc *desc;
  29. };
  30. /**
  31. * struct devfreq_event_data - the devfreq-event data
  32. *
  33. * @load_count : load count of devfreq-event device for the given period.
  34. * @total_count : total count of devfreq-event device for the given period.
  35. * each count may represent a clock cycle, a time unit
  36. * (ns/us/...), or anything the device driver wants.
  37. * Generally, utilization is load_count / total_count.
  38. *
  39. * This structure contains the data of devfreq-event device for polling period.
  40. */
  41. struct devfreq_event_data {
  42. unsigned long load_count;
  43. unsigned long total_count;
  44. };
  45. /**
  46. * struct devfreq_event_ops - the operations of devfreq-event device
  47. *
  48. * @enable : Enable the devfreq-event device.
  49. * @disable : Disable the devfreq-event device.
  50. * @reset : Reset all setting of the devfreq-event device.
  51. * @set_event : Set the specific event type for the devfreq-event device.
  52. * @get_event : Get the result of the devfreq-event devie with specific
  53. * event type.
  54. *
  55. * This structure contains devfreq-event device operations which can be
  56. * implemented by devfreq-event device drivers.
  57. */
  58. struct devfreq_event_ops {
  59. /* Optional functions */
  60. int (*enable)(struct devfreq_event_dev *edev);
  61. int (*disable)(struct devfreq_event_dev *edev);
  62. int (*reset)(struct devfreq_event_dev *edev);
  63. /* Mandatory functions */
  64. int (*set_event)(struct devfreq_event_dev *edev);
  65. int (*get_event)(struct devfreq_event_dev *edev,
  66. struct devfreq_event_data *edata);
  67. };
  68. /**
  69. * struct devfreq_event_desc - the descriptor of devfreq-event device
  70. *
  71. * @name : the name of devfreq-event device.
  72. * @event_type : the type of the event determined and used by driver
  73. * @driver_data : the private data for devfreq-event driver.
  74. * @ops : the operation to control devfreq-event device.
  75. *
  76. * Each devfreq-event device is described with a this structure.
  77. * This structure contains the various data for devfreq-event device.
  78. * The event_type describes what is going to be counted in the register.
  79. * It might choose to count e.g. read requests, write data in bytes, etc.
  80. * The full supported list of types is present in specyfic header in:
  81. * include/dt-bindings/pmu/.
  82. */
  83. struct devfreq_event_desc {
  84. const char *name;
  85. u32 event_type;
  86. void *driver_data;
  87. const struct devfreq_event_ops *ops;
  88. };
  89. #if defined(CONFIG_PM_DEVFREQ_EVENT)
  90. extern int devfreq_event_enable_edev(struct devfreq_event_dev *edev);
  91. extern int devfreq_event_disable_edev(struct devfreq_event_dev *edev);
  92. extern bool devfreq_event_is_enabled(struct devfreq_event_dev *edev);
  93. extern int devfreq_event_set_event(struct devfreq_event_dev *edev);
  94. extern int devfreq_event_get_event(struct devfreq_event_dev *edev,
  95. struct devfreq_event_data *edata);
  96. extern int devfreq_event_reset_event(struct devfreq_event_dev *edev);
  97. extern struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(
  98. struct device *dev,
  99. const char *phandle_name,
  100. int index);
  101. extern int devfreq_event_get_edev_count(struct device *dev,
  102. const char *phandle_name);
  103. extern struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
  104. struct devfreq_event_desc *desc);
  105. extern int devfreq_event_remove_edev(struct devfreq_event_dev *edev);
  106. extern struct devfreq_event_dev *devm_devfreq_event_add_edev(struct device *dev,
  107. struct devfreq_event_desc *desc);
  108. extern void devm_devfreq_event_remove_edev(struct device *dev,
  109. struct devfreq_event_dev *edev);
  110. static inline void *devfreq_event_get_drvdata(struct devfreq_event_dev *edev)
  111. {
  112. return edev->desc->driver_data;
  113. }
  114. #else
  115. static inline int devfreq_event_enable_edev(struct devfreq_event_dev *edev)
  116. {
  117. return -EINVAL;
  118. }
  119. static inline int devfreq_event_disable_edev(struct devfreq_event_dev *edev)
  120. {
  121. return -EINVAL;
  122. }
  123. static inline bool devfreq_event_is_enabled(struct devfreq_event_dev *edev)
  124. {
  125. return false;
  126. }
  127. static inline int devfreq_event_set_event(struct devfreq_event_dev *edev)
  128. {
  129. return -EINVAL;
  130. }
  131. static inline int devfreq_event_get_event(struct devfreq_event_dev *edev,
  132. struct devfreq_event_data *edata)
  133. {
  134. return -EINVAL;
  135. }
  136. static inline int devfreq_event_reset_event(struct devfreq_event_dev *edev)
  137. {
  138. return -EINVAL;
  139. }
  140. static inline struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(
  141. struct device *dev,
  142. const char *phandle_name,
  143. int index)
  144. {
  145. return ERR_PTR(-EINVAL);
  146. }
  147. static inline int devfreq_event_get_edev_count(struct device *dev,
  148. const char *phandle_name)
  149. {
  150. return -EINVAL;
  151. }
  152. static inline struct devfreq_event_dev *devfreq_event_add_edev(struct device *dev,
  153. struct devfreq_event_desc *desc)
  154. {
  155. return ERR_PTR(-EINVAL);
  156. }
  157. static inline int devfreq_event_remove_edev(struct devfreq_event_dev *edev)
  158. {
  159. return -EINVAL;
  160. }
  161. static inline struct devfreq_event_dev *devm_devfreq_event_add_edev(
  162. struct device *dev,
  163. struct devfreq_event_desc *desc)
  164. {
  165. return ERR_PTR(-EINVAL);
  166. }
  167. static inline void devm_devfreq_event_remove_edev(struct device *dev,
  168. struct devfreq_event_dev *edev)
  169. {
  170. }
  171. static inline void *devfreq_event_get_drvdata(struct devfreq_event_dev *edev)
  172. {
  173. return NULL;
  174. }
  175. #endif /* CONFIG_PM_DEVFREQ_EVENT */
  176. #endif /* __LINUX_DEVFREQ_EVENT_H__ */