windfarm.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Windfarm PowerMac thermal control.
  3. *
  4. * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
  5. * <benh@kernel.crashing.org>
  6. *
  7. * Released under the term of the GNU GPL v2.
  8. */
  9. #ifndef __WINDFARM_H__
  10. #define __WINDFARM_H__
  11. #include <linux/kref.h>
  12. #include <linux/list.h>
  13. #include <linux/module.h>
  14. #include <linux/notifier.h>
  15. #include <linux/device.h>
  16. /* Display a 16.16 fixed point value */
  17. #define FIX32TOPRINT(f) (((s32)(f)) >> 16),(((((s32)(f)) & 0xffff) * 1000) >> 16)
  18. /*
  19. * Control objects
  20. */
  21. struct wf_control;
  22. struct wf_control_ops {
  23. int (*set_value)(struct wf_control *ct, s32 val);
  24. int (*get_value)(struct wf_control *ct, s32 *val);
  25. s32 (*get_min)(struct wf_control *ct);
  26. s32 (*get_max)(struct wf_control *ct);
  27. void (*release)(struct wf_control *ct);
  28. struct module *owner;
  29. };
  30. struct wf_control {
  31. struct list_head link;
  32. const struct wf_control_ops *ops;
  33. const char *name;
  34. int type;
  35. struct kref ref;
  36. struct device_attribute attr;
  37. void *priv;
  38. };
  39. #define WF_CONTROL_TYPE_GENERIC 0
  40. #define WF_CONTROL_RPM_FAN 1
  41. #define WF_CONTROL_PWM_FAN 2
  42. /* Note about lifetime rules: wf_register_control() will initialize
  43. * the kref and wf_unregister_control will decrement it, thus the
  44. * object creating/disposing a given control shouldn't assume it
  45. * still exists after wf_unregister_control has been called.
  46. * wf_find_control will inc the refcount for you
  47. */
  48. extern int wf_register_control(struct wf_control *ct);
  49. extern void wf_unregister_control(struct wf_control *ct);
  50. extern struct wf_control * wf_find_control(const char *name);
  51. extern int wf_get_control(struct wf_control *ct);
  52. extern void wf_put_control(struct wf_control *ct);
  53. static inline int wf_control_set_max(struct wf_control *ct)
  54. {
  55. s32 vmax = ct->ops->get_max(ct);
  56. return ct->ops->set_value(ct, vmax);
  57. }
  58. static inline int wf_control_set_min(struct wf_control *ct)
  59. {
  60. s32 vmin = ct->ops->get_min(ct);
  61. return ct->ops->set_value(ct, vmin);
  62. }
  63. static inline int wf_control_set(struct wf_control *ct, s32 val)
  64. {
  65. return ct->ops->set_value(ct, val);
  66. }
  67. static inline int wf_control_get(struct wf_control *ct, s32 *val)
  68. {
  69. return ct->ops->get_value(ct, val);
  70. }
  71. static inline s32 wf_control_get_min(struct wf_control *ct)
  72. {
  73. return ct->ops->get_min(ct);
  74. }
  75. static inline s32 wf_control_get_max(struct wf_control *ct)
  76. {
  77. return ct->ops->get_max(ct);
  78. }
  79. /*
  80. * Sensor objects
  81. */
  82. struct wf_sensor;
  83. struct wf_sensor_ops {
  84. int (*get_value)(struct wf_sensor *sr, s32 *val);
  85. void (*release)(struct wf_sensor *sr);
  86. struct module *owner;
  87. };
  88. struct wf_sensor {
  89. struct list_head link;
  90. const struct wf_sensor_ops *ops;
  91. const char *name;
  92. struct kref ref;
  93. struct device_attribute attr;
  94. void *priv;
  95. };
  96. /* Same lifetime rules as controls */
  97. extern int wf_register_sensor(struct wf_sensor *sr);
  98. extern void wf_unregister_sensor(struct wf_sensor *sr);
  99. extern struct wf_sensor * wf_find_sensor(const char *name);
  100. extern int wf_get_sensor(struct wf_sensor *sr);
  101. extern void wf_put_sensor(struct wf_sensor *sr);
  102. static inline int wf_sensor_get(struct wf_sensor *sr, s32 *val)
  103. {
  104. return sr->ops->get_value(sr, val);
  105. }
  106. /* For use by clients. Note that we are a bit racy here since
  107. * notifier_block doesn't have a module owner field. I may fix
  108. * it one day ...
  109. *
  110. * LOCKING NOTE !
  111. *
  112. * All "events" except WF_EVENT_TICK are called with an internal mutex
  113. * held which will deadlock if you call basically any core routine.
  114. * So don't ! Just take note of the event and do your actual operations
  115. * from the ticker.
  116. *
  117. */
  118. extern int wf_register_client(struct notifier_block *nb);
  119. extern int wf_unregister_client(struct notifier_block *nb);
  120. /* Overtemp conditions. Those are refcounted */
  121. extern void wf_set_overtemp(void);
  122. extern void wf_clear_overtemp(void);
  123. extern int wf_is_overtemp(void);
  124. #define WF_EVENT_NEW_CONTROL 0 /* param is wf_control * */
  125. #define WF_EVENT_NEW_SENSOR 1 /* param is wf_sensor * */
  126. #define WF_EVENT_OVERTEMP 2 /* no param */
  127. #define WF_EVENT_NORMALTEMP 3 /* overtemp condition cleared */
  128. #define WF_EVENT_TICK 4 /* 1 second tick */
  129. /* Note: If that driver gets more broad use, we could replace the
  130. * simplistic overtemp bits with "environmental conditions". That
  131. * could then be used to also notify of things like fan failure,
  132. * case open, battery conditions, ...
  133. */
  134. #endif /* __WINDFARM_H__ */