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