1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Windfarm PowerMac thermal control. SMU based 1 CPU desktop control loops
4 *
5 * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
6 * <benh@kernel.crashing.org>
7 *
8 * The algorithm used is the PID control algorithm, used the same
9 * way the published Darwin code does, using the same values that
10 * are present in the Darwin 8.2 snapshot property lists (note however
11 * that none of the code has been re-used, it's a complete re-implementation
12 *
13 * The various control loops found in Darwin config file are:
14 *
15 * PowerMac9,1
16 * ===========
17 *
18 * Has 3 control loops: CPU fans is similar to PowerMac8,1 (though it doesn't
19 * try to play with other control loops fans). Drive bay is rather basic PID
20 * with one sensor and one fan. Slots area is a bit different as the Darwin
21 * driver is supposed to be capable of working in a special "AGP" mode which
22 * involves the presence of an AGP sensor and an AGP fan (possibly on the
23 * AGP card itself). I can't deal with that special mode as I don't have
24 * access to those additional sensor/fans for now (though ultimately, it would
25 * be possible to add sensor objects for them) so I'm only implementing the
26 * basic PCI slot control loop
27 */
28
29 #include <linux/types.h>
30 #include <linux/errno.h>
31 #include <linux/kernel.h>
32 #include <linux/delay.h>
33 #include <linux/slab.h>
34 #include <linux/init.h>
35 #include <linux/spinlock.h>
36 #include <linux/wait.h>
37 #include <linux/kmod.h>
38 #include <linux/device.h>
39 #include <linux/platform_device.h>
40 #include <linux/of.h>
41
42 #include <asm/machdep.h>
43 #include <asm/io.h>
44 #include <asm/sections.h>
45 #include <asm/smu.h>
46
47 #include "windfarm.h"
48 #include "windfarm_pid.h"
49
50 #define VERSION "0.4"
51
52 #undef DEBUG
53
54 #ifdef DEBUG
55 #define DBG(args...) printk(args)
56 #else
57 #define DBG(args...) do { } while(0)
58 #endif
59
60 /* define this to force CPU overtemp to 74 degree, useful for testing
61 * the overtemp code
62 */
63 #undef HACKED_OVERTEMP
64
65 /* Controls & sensors */
66 static struct wf_sensor *sensor_cpu_power;
67 static struct wf_sensor *sensor_cpu_temp;
68 static struct wf_sensor *sensor_hd_temp;
69 static struct wf_sensor *sensor_slots_power;
70 static struct wf_control *fan_cpu_main;
71 static struct wf_control *fan_cpu_second;
72 static struct wf_control *fan_cpu_third;
73 static struct wf_control *fan_hd;
74 static struct wf_control *fan_slots;
75 static struct wf_control *cpufreq_clamp;
76
77 /* Set to kick the control loop into life */
78 static int wf_smu_all_controls_ok, wf_smu_all_sensors_ok;
79 static bool wf_smu_started;
80 static bool wf_smu_overtemp;
81
82 /* Failure handling.. could be nicer */
83 #define FAILURE_FAN 0x01
84 #define FAILURE_SENSOR 0x02
85 #define FAILURE_OVERTEMP 0x04
86
87 static unsigned int wf_smu_failure_state;
88 static int wf_smu_readjust, wf_smu_skipping;
89
90 /*
91 * ****** CPU Fans Control Loop ******
92 *
93 */
94
95
96 #define WF_SMU_CPU_FANS_INTERVAL 1
97 #define WF_SMU_CPU_FANS_MAX_HISTORY 16
98
99 /* State data used by the cpu fans control loop
100 */
101 struct wf_smu_cpu_fans_state {
102 int ticks;
103 s32 cpu_setpoint;
104 struct wf_cpu_pid_state pid;
105 };
106
107 static struct wf_smu_cpu_fans_state *wf_smu_cpu_fans;
108
109
110
111 /*
112 * ****** Drive Fan Control Loop ******
113 *
114 */
115
116 struct wf_smu_drive_fans_state {
117 int ticks;
118 s32 setpoint;
119 struct wf_pid_state pid;
120 };
121
122 static struct wf_smu_drive_fans_state *wf_smu_drive_fans;
123
124 /*
125 * ****** Slots Fan Control Loop ******
126 *
127 */
128
129 struct wf_smu_slots_fans_state {
130 int ticks;
131 s32 setpoint;
132 struct wf_pid_state pid;
133 };
134
135 static struct wf_smu_slots_fans_state *wf_smu_slots_fans;
136
137 /*
138 * ***** Implementation *****
139 *
140 */
141
142
wf_smu_create_cpu_fans(void)143 static void wf_smu_create_cpu_fans(void)
144 {
145 struct wf_cpu_pid_param pid_param;
146 const struct smu_sdbp_header *hdr;
147 struct smu_sdbp_cpupiddata *piddata;
148 struct smu_sdbp_fvt *fvt;
149 s32 tmax, tdelta, maxpow, powadj;
150
151 /* First, locate the PID params in SMU SBD */
152 hdr = smu_get_sdb_partition(SMU_SDB_CPUPIDDATA_ID, NULL);
153 if (!hdr) {
154 printk(KERN_WARNING "windfarm: CPU PID fan config not found "
155 "max fan speed\n");
156 goto fail;
157 }
158 piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];
159
160 /* Get the FVT params for operating point 0 (the only supported one
161 * for now) in order to get tmax
162 */
163 hdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL);
164 if (hdr) {
165 fvt = (struct smu_sdbp_fvt *)&hdr[1];
166 tmax = ((s32)fvt->maxtemp) << 16;
167 } else
168 tmax = 0x5e0000; /* 94 degree default */
169
170 /* Alloc & initialize state */
171 wf_smu_cpu_fans = kmalloc_obj(struct wf_smu_cpu_fans_state);
172 if (wf_smu_cpu_fans == NULL)
173 goto fail;
174 wf_smu_cpu_fans->ticks = 1;
175
176 /* Fill PID params */
177 pid_param.interval = WF_SMU_CPU_FANS_INTERVAL;
178 pid_param.history_len = piddata->history_len;
179 if (pid_param.history_len > WF_CPU_PID_MAX_HISTORY) {
180 printk(KERN_WARNING "windfarm: History size overflow on "
181 "CPU control loop (%d)\n", piddata->history_len);
182 pid_param.history_len = WF_CPU_PID_MAX_HISTORY;
183 }
184 pid_param.gd = piddata->gd;
185 pid_param.gp = piddata->gp;
186 pid_param.gr = piddata->gr / pid_param.history_len;
187
188 tdelta = ((s32)piddata->target_temp_delta) << 16;
189 maxpow = ((s32)piddata->max_power) << 16;
190 powadj = ((s32)piddata->power_adj) << 16;
191
192 pid_param.tmax = tmax;
193 pid_param.ttarget = tmax - tdelta;
194 pid_param.pmaxadj = maxpow - powadj;
195
196 pid_param.min = wf_control_get_min(fan_cpu_main);
197 pid_param.max = wf_control_get_max(fan_cpu_main);
198
199 wf_cpu_pid_init(&wf_smu_cpu_fans->pid, &pid_param);
200
201 DBG("wf: CPU Fan control initialized.\n");
202 DBG(" ttarget=%d.%03d, tmax=%d.%03d, min=%d RPM, max=%d RPM\n",
203 FIX32TOPRINT(pid_param.ttarget), FIX32TOPRINT(pid_param.tmax),
204 pid_param.min, pid_param.max);
205
206 return;
207
208 fail:
209 printk(KERN_WARNING "windfarm: CPU fan config not found\n"
210 "for this machine model, max fan speed\n");
211
212 if (cpufreq_clamp)
213 wf_control_set_max(cpufreq_clamp);
214 if (fan_cpu_main)
215 wf_control_set_max(fan_cpu_main);
216 }
217
wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state * st)218 static void wf_smu_cpu_fans_tick(struct wf_smu_cpu_fans_state *st)
219 {
220 s32 new_setpoint, temp, power;
221 int rc;
222
223 if (--st->ticks != 0) {
224 if (wf_smu_readjust)
225 goto readjust;
226 return;
227 }
228 st->ticks = WF_SMU_CPU_FANS_INTERVAL;
229
230 rc = wf_sensor_get(sensor_cpu_temp, &temp);
231 if (rc) {
232 printk(KERN_WARNING "windfarm: CPU temp sensor error %d\n",
233 rc);
234 wf_smu_failure_state |= FAILURE_SENSOR;
235 return;
236 }
237
238 rc = wf_sensor_get(sensor_cpu_power, &power);
239 if (rc) {
240 printk(KERN_WARNING "windfarm: CPU power sensor error %d\n",
241 rc);
242 wf_smu_failure_state |= FAILURE_SENSOR;
243 return;
244 }
245
246 DBG("wf_smu: CPU Fans tick ! CPU temp: %d.%03d, power: %d.%03d\n",
247 FIX32TOPRINT(temp), FIX32TOPRINT(power));
248
249 #ifdef HACKED_OVERTEMP
250 if (temp > 0x4a0000)
251 wf_smu_failure_state |= FAILURE_OVERTEMP;
252 #else
253 if (temp > st->pid.param.tmax)
254 wf_smu_failure_state |= FAILURE_OVERTEMP;
255 #endif
256 new_setpoint = wf_cpu_pid_run(&st->pid, power, temp);
257
258 DBG("wf_smu: new_setpoint: %d RPM\n", (int)new_setpoint);
259
260 if (st->cpu_setpoint == new_setpoint)
261 return;
262 st->cpu_setpoint = new_setpoint;
263 readjust:
264 if (fan_cpu_main && wf_smu_failure_state == 0) {
265 rc = wf_control_set(fan_cpu_main, st->cpu_setpoint);
266 if (rc) {
267 printk(KERN_WARNING "windfarm: CPU main fan"
268 " error %d\n", rc);
269 wf_smu_failure_state |= FAILURE_FAN;
270 }
271 }
272 if (fan_cpu_second && wf_smu_failure_state == 0) {
273 rc = wf_control_set(fan_cpu_second, st->cpu_setpoint);
274 if (rc) {
275 printk(KERN_WARNING "windfarm: CPU second fan"
276 " error %d\n", rc);
277 wf_smu_failure_state |= FAILURE_FAN;
278 }
279 }
280 if (fan_cpu_third && wf_smu_failure_state == 0) {
281 rc = wf_control_set(fan_cpu_third, st->cpu_setpoint);
282 if (rc) {
283 printk(KERN_WARNING "windfarm: CPU third fan"
284 " error %d\n", rc);
285 wf_smu_failure_state |= FAILURE_FAN;
286 }
287 }
288 }
289
wf_smu_create_drive_fans(void)290 static void wf_smu_create_drive_fans(void)
291 {
292 struct wf_pid_param param = {
293 .interval = 5,
294 .history_len = 2,
295 .gd = 0x01e00000,
296 .gp = 0x00500000,
297 .gr = 0x00000000,
298 .itarget = 0x00200000,
299 };
300
301 /* Alloc & initialize state */
302 wf_smu_drive_fans = kmalloc_obj(struct wf_smu_drive_fans_state);
303 if (wf_smu_drive_fans == NULL) {
304 printk(KERN_WARNING "windfarm: Memory allocation error"
305 " max fan speed\n");
306 goto fail;
307 }
308 wf_smu_drive_fans->ticks = 1;
309
310 /* Fill PID params */
311 param.additive = (fan_hd->type == WF_CONTROL_RPM_FAN);
312 param.min = wf_control_get_min(fan_hd);
313 param.max = wf_control_get_max(fan_hd);
314 wf_pid_init(&wf_smu_drive_fans->pid, ¶m);
315
316 DBG("wf: Drive Fan control initialized.\n");
317 DBG(" itarged=%d.%03d, min=%d RPM, max=%d RPM\n",
318 FIX32TOPRINT(param.itarget), param.min, param.max);
319 return;
320
321 fail:
322 if (fan_hd)
323 wf_control_set_max(fan_hd);
324 }
325
wf_smu_drive_fans_tick(struct wf_smu_drive_fans_state * st)326 static void wf_smu_drive_fans_tick(struct wf_smu_drive_fans_state *st)
327 {
328 s32 new_setpoint, temp;
329 int rc;
330
331 if (--st->ticks != 0) {
332 if (wf_smu_readjust)
333 goto readjust;
334 return;
335 }
336 st->ticks = st->pid.param.interval;
337
338 rc = wf_sensor_get(sensor_hd_temp, &temp);
339 if (rc) {
340 printk(KERN_WARNING "windfarm: HD temp sensor error %d\n",
341 rc);
342 wf_smu_failure_state |= FAILURE_SENSOR;
343 return;
344 }
345
346 DBG("wf_smu: Drive Fans tick ! HD temp: %d.%03d\n",
347 FIX32TOPRINT(temp));
348
349 if (temp > (st->pid.param.itarget + 0x50000))
350 wf_smu_failure_state |= FAILURE_OVERTEMP;
351
352 new_setpoint = wf_pid_run(&st->pid, temp);
353
354 DBG("wf_smu: new_setpoint: %d\n", (int)new_setpoint);
355
356 if (st->setpoint == new_setpoint)
357 return;
358 st->setpoint = new_setpoint;
359 readjust:
360 if (fan_hd && wf_smu_failure_state == 0) {
361 rc = wf_control_set(fan_hd, st->setpoint);
362 if (rc) {
363 printk(KERN_WARNING "windfarm: HD fan error %d\n",
364 rc);
365 wf_smu_failure_state |= FAILURE_FAN;
366 }
367 }
368 }
369
wf_smu_create_slots_fans(void)370 static void wf_smu_create_slots_fans(void)
371 {
372 struct wf_pid_param param = {
373 .interval = 1,
374 .history_len = 8,
375 .gd = 0x00000000,
376 .gp = 0x00000000,
377 .gr = 0x00020000,
378 .itarget = 0x00000000
379 };
380
381 /* Alloc & initialize state */
382 wf_smu_slots_fans = kmalloc_obj(struct wf_smu_slots_fans_state);
383 if (wf_smu_slots_fans == NULL) {
384 printk(KERN_WARNING "windfarm: Memory allocation error"
385 " max fan speed\n");
386 goto fail;
387 }
388 wf_smu_slots_fans->ticks = 1;
389
390 /* Fill PID params */
391 param.additive = (fan_slots->type == WF_CONTROL_RPM_FAN);
392 param.min = wf_control_get_min(fan_slots);
393 param.max = wf_control_get_max(fan_slots);
394 wf_pid_init(&wf_smu_slots_fans->pid, ¶m);
395
396 DBG("wf: Slots Fan control initialized.\n");
397 DBG(" itarged=%d.%03d, min=%d RPM, max=%d RPM\n",
398 FIX32TOPRINT(param.itarget), param.min, param.max);
399 return;
400
401 fail:
402 if (fan_slots)
403 wf_control_set_max(fan_slots);
404 }
405
wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state * st)406 static void wf_smu_slots_fans_tick(struct wf_smu_slots_fans_state *st)
407 {
408 s32 new_setpoint, power;
409 int rc;
410
411 if (--st->ticks != 0) {
412 if (wf_smu_readjust)
413 goto readjust;
414 return;
415 }
416 st->ticks = st->pid.param.interval;
417
418 rc = wf_sensor_get(sensor_slots_power, &power);
419 if (rc) {
420 printk(KERN_WARNING "windfarm: Slots power sensor error %d\n",
421 rc);
422 wf_smu_failure_state |= FAILURE_SENSOR;
423 return;
424 }
425
426 DBG("wf_smu: Slots Fans tick ! Slots power: %d.%03d\n",
427 FIX32TOPRINT(power));
428
429 #if 0 /* Check what makes a good overtemp condition */
430 if (power > (st->pid.param.itarget + 0x50000))
431 wf_smu_failure_state |= FAILURE_OVERTEMP;
432 #endif
433
434 new_setpoint = wf_pid_run(&st->pid, power);
435
436 DBG("wf_smu: new_setpoint: %d\n", (int)new_setpoint);
437
438 if (st->setpoint == new_setpoint)
439 return;
440 st->setpoint = new_setpoint;
441 readjust:
442 if (fan_slots && wf_smu_failure_state == 0) {
443 rc = wf_control_set(fan_slots, st->setpoint);
444 if (rc) {
445 printk(KERN_WARNING "windfarm: Slots fan error %d\n",
446 rc);
447 wf_smu_failure_state |= FAILURE_FAN;
448 }
449 }
450 }
451
452
453 /*
454 * ****** Setup / Init / Misc ... ******
455 *
456 */
457
wf_smu_tick(void)458 static void wf_smu_tick(void)
459 {
460 unsigned int last_failure = wf_smu_failure_state;
461 unsigned int new_failure;
462
463 if (!wf_smu_started) {
464 DBG("wf: creating control loops !\n");
465 wf_smu_create_drive_fans();
466 wf_smu_create_slots_fans();
467 wf_smu_create_cpu_fans();
468 wf_smu_started = true;
469 }
470
471 /* Skipping ticks */
472 if (wf_smu_skipping && --wf_smu_skipping)
473 return;
474
475 wf_smu_failure_state = 0;
476 if (wf_smu_drive_fans)
477 wf_smu_drive_fans_tick(wf_smu_drive_fans);
478 if (wf_smu_slots_fans)
479 wf_smu_slots_fans_tick(wf_smu_slots_fans);
480 if (wf_smu_cpu_fans)
481 wf_smu_cpu_fans_tick(wf_smu_cpu_fans);
482
483 wf_smu_readjust = 0;
484 new_failure = wf_smu_failure_state & ~last_failure;
485
486 /* If entering failure mode, clamp cpufreq and ramp all
487 * fans to full speed.
488 */
489 if (wf_smu_failure_state && !last_failure) {
490 if (cpufreq_clamp)
491 wf_control_set_max(cpufreq_clamp);
492 if (fan_cpu_main)
493 wf_control_set_max(fan_cpu_main);
494 if (fan_cpu_second)
495 wf_control_set_max(fan_cpu_second);
496 if (fan_cpu_third)
497 wf_control_set_max(fan_cpu_third);
498 if (fan_hd)
499 wf_control_set_max(fan_hd);
500 if (fan_slots)
501 wf_control_set_max(fan_slots);
502 }
503
504 /* If leaving failure mode, unclamp cpufreq and readjust
505 * all fans on next iteration
506 */
507 if (!wf_smu_failure_state && last_failure) {
508 if (cpufreq_clamp)
509 wf_control_set_min(cpufreq_clamp);
510 wf_smu_readjust = 1;
511 }
512
513 /* Overtemp condition detected, notify and start skipping a couple
514 * ticks to let the temperature go down
515 */
516 if (new_failure & FAILURE_OVERTEMP) {
517 wf_set_overtemp();
518 wf_smu_skipping = 2;
519 wf_smu_overtemp = true;
520 }
521
522 /* We only clear the overtemp condition if overtemp is cleared
523 * _and_ no other failure is present. Since a sensor error will
524 * clear the overtemp condition (can't measure temperature) at
525 * the control loop levels, but we don't want to keep it clear
526 * here in this case
527 */
528 if (!wf_smu_failure_state && wf_smu_overtemp) {
529 wf_clear_overtemp();
530 wf_smu_overtemp = false;
531 }
532 }
533
534
wf_smu_new_control(struct wf_control * ct)535 static void wf_smu_new_control(struct wf_control *ct)
536 {
537 if (wf_smu_all_controls_ok)
538 return;
539
540 if (fan_cpu_main == NULL && !strcmp(ct->name, "cpu-rear-fan-0")) {
541 if (wf_get_control(ct) == 0)
542 fan_cpu_main = ct;
543 }
544
545 if (fan_cpu_second == NULL && !strcmp(ct->name, "cpu-rear-fan-1")) {
546 if (wf_get_control(ct) == 0)
547 fan_cpu_second = ct;
548 }
549
550 if (fan_cpu_third == NULL && !strcmp(ct->name, "cpu-front-fan-0")) {
551 if (wf_get_control(ct) == 0)
552 fan_cpu_third = ct;
553 }
554
555 if (cpufreq_clamp == NULL && !strcmp(ct->name, "cpufreq-clamp")) {
556 if (wf_get_control(ct) == 0)
557 cpufreq_clamp = ct;
558 }
559
560 if (fan_hd == NULL && !strcmp(ct->name, "drive-bay-fan")) {
561 if (wf_get_control(ct) == 0)
562 fan_hd = ct;
563 }
564
565 if (fan_slots == NULL && !strcmp(ct->name, "slots-fan")) {
566 if (wf_get_control(ct) == 0)
567 fan_slots = ct;
568 }
569
570 if (fan_cpu_main && (fan_cpu_second || fan_cpu_third) && fan_hd &&
571 fan_slots && cpufreq_clamp)
572 wf_smu_all_controls_ok = 1;
573 }
574
wf_smu_new_sensor(struct wf_sensor * sr)575 static void wf_smu_new_sensor(struct wf_sensor *sr)
576 {
577 if (wf_smu_all_sensors_ok)
578 return;
579
580 if (sensor_cpu_power == NULL && !strcmp(sr->name, "cpu-power")) {
581 if (wf_get_sensor(sr) == 0)
582 sensor_cpu_power = sr;
583 }
584
585 if (sensor_cpu_temp == NULL && !strcmp(sr->name, "cpu-temp")) {
586 if (wf_get_sensor(sr) == 0)
587 sensor_cpu_temp = sr;
588 }
589
590 if (sensor_hd_temp == NULL && !strcmp(sr->name, "hd-temp")) {
591 if (wf_get_sensor(sr) == 0)
592 sensor_hd_temp = sr;
593 }
594
595 if (sensor_slots_power == NULL && !strcmp(sr->name, "slots-power")) {
596 if (wf_get_sensor(sr) == 0)
597 sensor_slots_power = sr;
598 }
599
600 if (sensor_cpu_power && sensor_cpu_temp &&
601 sensor_hd_temp && sensor_slots_power)
602 wf_smu_all_sensors_ok = 1;
603 }
604
605
wf_smu_notify(struct notifier_block * self,unsigned long event,void * data)606 static int wf_smu_notify(struct notifier_block *self,
607 unsigned long event, void *data)
608 {
609 switch(event) {
610 case WF_EVENT_NEW_CONTROL:
611 DBG("wf: new control %s detected\n",
612 ((struct wf_control *)data)->name);
613 wf_smu_new_control(data);
614 wf_smu_readjust = 1;
615 break;
616 case WF_EVENT_NEW_SENSOR:
617 DBG("wf: new sensor %s detected\n",
618 ((struct wf_sensor *)data)->name);
619 wf_smu_new_sensor(data);
620 break;
621 case WF_EVENT_TICK:
622 if (wf_smu_all_controls_ok && wf_smu_all_sensors_ok)
623 wf_smu_tick();
624 }
625
626 return 0;
627 }
628
629 static struct notifier_block wf_smu_events = {
630 .notifier_call = wf_smu_notify,
631 };
632
wf_init_pm(void)633 static int wf_init_pm(void)
634 {
635 printk(KERN_INFO "windfarm: Initializing for Desktop G5 model\n");
636
637 return 0;
638 }
639
wf_smu_probe(struct platform_device * ddev)640 static int wf_smu_probe(struct platform_device *ddev)
641 {
642 wf_register_client(&wf_smu_events);
643
644 return 0;
645 }
646
wf_smu_remove(struct platform_device * ddev)647 static void wf_smu_remove(struct platform_device *ddev)
648 {
649 wf_unregister_client(&wf_smu_events);
650
651 /* XXX We don't have yet a guarantee that our callback isn't
652 * in progress when returning from wf_unregister_client, so
653 * we add an arbitrary delay. I'll have to fix that in the core
654 */
655 msleep(1000);
656
657 /* Release all sensors */
658 /* One more crappy race: I don't think we have any guarantee here
659 * that the attribute callback won't race with the sensor beeing
660 * disposed of, and I'm not 100% certain what best way to deal
661 * with that except by adding locks all over... I'll do that
662 * eventually but heh, who ever rmmod this module anyway ?
663 */
664 if (sensor_cpu_power)
665 wf_put_sensor(sensor_cpu_power);
666 if (sensor_cpu_temp)
667 wf_put_sensor(sensor_cpu_temp);
668 if (sensor_hd_temp)
669 wf_put_sensor(sensor_hd_temp);
670 if (sensor_slots_power)
671 wf_put_sensor(sensor_slots_power);
672
673 /* Release all controls */
674 if (fan_cpu_main)
675 wf_put_control(fan_cpu_main);
676 if (fan_cpu_second)
677 wf_put_control(fan_cpu_second);
678 if (fan_cpu_third)
679 wf_put_control(fan_cpu_third);
680 if (fan_hd)
681 wf_put_control(fan_hd);
682 if (fan_slots)
683 wf_put_control(fan_slots);
684 if (cpufreq_clamp)
685 wf_put_control(cpufreq_clamp);
686
687 /* Destroy control loops state structures */
688 kfree(wf_smu_slots_fans);
689 kfree(wf_smu_drive_fans);
690 kfree(wf_smu_cpu_fans);
691 }
692
693 static struct platform_driver wf_smu_driver = {
694 .probe = wf_smu_probe,
695 .remove = wf_smu_remove,
696 .driver = {
697 .name = "windfarm",
698 },
699 };
700
701
wf_smu_init(void)702 static int __init wf_smu_init(void)
703 {
704 int rc = -ENODEV;
705
706 if (of_machine_is_compatible("PowerMac9,1"))
707 rc = wf_init_pm();
708
709 if (rc == 0) {
710 #ifdef MODULE
711 request_module("windfarm_smu_controls");
712 request_module("windfarm_smu_sensors");
713 request_module("windfarm_lm75_sensor");
714 request_module("windfarm_cpufreq_clamp");
715
716 #endif /* MODULE */
717 platform_driver_register(&wf_smu_driver);
718 }
719
720 return rc;
721 }
722
wf_smu_exit(void)723 static void __exit wf_smu_exit(void)
724 {
725
726 platform_driver_unregister(&wf_smu_driver);
727 }
728
729
730 module_init(wf_smu_init);
731 module_exit(wf_smu_exit);
732
733 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
734 MODULE_DESCRIPTION("Thermal control logic for PowerMac9,1");
735 MODULE_LICENSE("GPL");
736
737 MODULE_ALIAS("platform:windfarm");
738