devfreq-event.h 5.6 KB

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