25 #include <linux/types.h>
26 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
33 #include <linux/reboot.h>
34 #include <linux/device.h>
48 #define DBG(args...) printk(args)
50 #define DBG(args...) do { } while(0)
57 static int wf_client_count;
58 static unsigned int wf_overtemp;
59 static unsigned int wf_overtemp_counter;
70 static inline void wf_notify(
int event,
void *
param)
77 static char * critical_overtemp_path =
"/sbin/critical_overtemp";
78 char *argv[] = { critical_overtemp_path,
NULL };
79 static char *envp[] = {
"HOME=/",
81 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
84 return call_usermodehelper(critical_overtemp_path,
89 static int wf_thread_func(
void *
data)
95 DBG(
"wf: thread started\n");
104 wf_overtemp_counter++;
106 if (wf_overtemp_counter > 10)
109 if (wf_overtemp_counter > 30) {
112 " seconds, shutting down\n");
124 DBG(
"wf: thread stopped\n");
129 static void wf_start_thread(
void)
132 if (IS_ERR(wf_thread)) {
140 static void wf_stop_thread(
void)
151 static void wf_control_release(
struct kref *
kref)
155 DBG(
"wf: Deleting control %s\n", ct->
name);
157 if (ct->
ops && ct->
ops->release)
158 ct->
ops->release(ct);
171 err = ctrl->
ops->get_value(ctrl, &val);
174 return sprintf(buf,
"<HW FAULT>\n");
187 return sprintf(buf,
"%d%s\n", val, typestr);
193 const char *buf,
size_t count)
201 while (endp < buf + count && (*endp ==
' ' || *endp ==
'\n'))
203 if (endp - buf < count)
205 err = ctrl->
ops->set_value(ctrl, val);
219 " duplicate control %s\n", ct->
name);
224 kref_init(&new_ct->
ref);
225 list_add(&new_ct->
link, &wf_controls);
228 new_ct->
attr.attr.name = new_ct->
name;
229 new_ct->
attr.attr.mode = 0644;
230 new_ct->
attr.show = wf_show_control;
231 new_ct->
attr.store = wf_store_control;
234 " for %s\n", new_ct->
name);
237 DBG(
"wf: Registered control %s\n", new_ct->
name);
252 DBG(
"wf: Unregistered control %s\n", ct->
name);
254 kref_put(&ct->
ref, wf_control_release);
278 if (!try_module_get(ct->
ops->owner))
288 kref_put(&ct->
ref, wf_control_release);
299 static void wf_sensor_release(
struct kref *kref)
303 DBG(
"wf: Deleting sensor %s\n", sr->
name);
305 if (sr->
ops && sr->
ops->release)
306 sr->
ops->release(sr);
318 err = sens->
ops->get_value(sens, &val);
332 " duplicate sensor %s\n", sr->
name);
337 kref_init(&new_sr->
ref);
338 list_add(&new_sr->
link, &wf_sensors);
341 new_sr->
attr.attr.name = new_sr->
name;
342 new_sr->
attr.attr.mode = 0444;
343 new_sr->
attr.show = wf_show_sensor;
347 " for %s\n", new_sr->
name);
350 DBG(
"wf: Registered sensor %s\n", new_sr->
name);
365 DBG(
"wf: Unregistered sensor %s\n", sr->
name);
391 if (!try_module_get(sr->
ops->owner))
401 kref_put(&sr->
ref, wf_sensor_release);
426 if (wf_client_count == 1)
439 if (wf_client_count == 0)
451 if (wf_overtemp == 1) {
453 wf_overtemp_counter = 0;
464 if (wf_overtemp == 0) {
469 if (wf_overtemp == 0) {
479 return (wf_overtemp != 0);
483 static int __init windfarm_core_init(
void)
485 DBG(
"wf: core loaded\n");
491 static void __exit windfarm_core_exit(
void)
493 BUG_ON(wf_client_count != 0);
495 DBG(
"wf: core unloaded\n");