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