3 #include <linux/types.h>
4 #include <linux/module.h>
5 #include <linux/errno.h>
6 #include <linux/kernel.h>
7 #include <linux/delay.h>
8 #include <linux/sched.h>
9 #include <linux/init.h>
10 #include <linux/spinlock.h>
11 #include <linux/wait.h>
12 #include <linux/reboot.h>
13 #include <linux/kmod.h>
14 #include <linux/i2c.h>
15 #include <linux/kthread.h>
16 #include <linux/mutex.h>
17 #include <linux/of_device.h>
18 #include <linux/of_platform.h>
20 #include <asm/machdep.h>
22 #include <asm/system.h>
23 #include <asm/sections.h>
24 #include <asm/macio.h>
26 #include "therm_pm72.h"
33 #define DBG(args...) printk(args)
35 #define DBG(args...) do { } while(0)
43 static struct platform_device
* of_dev
;
44 static struct i2c_adapter
* u3_0
;
45 static struct i2c_adapter
* u3_1
;
46 static struct i2c_adapter
* k2
;
47 static struct i2c_client
* fcu
;
48 static struct cpu_pid_state cpu_state
[2];
49 static struct basckside_pid_params backside_params
;
50 static struct backside_pid_state backside_state
;
51 static struct drives_pid_state drives_state
;
52 static struct dimm_pid_state dimms_state
;
53 static struct slots_pid_state slots_state
;
56 static int cpu_pid_type
;
57 static struct task_struct
*ctrl_task
;
58 static struct completion ctrl_complete
;
59 static int critical_state
;
61 static s32 dimm_output_clamp
;
62 static int fcu_rpm_shift
;
63 static int fcu_tickle_ticks
;
64 static DEFINE_MUTEX(driver_lock
);
67 * We have 3 types of CPU PID control. One is "split" old style control
68 * for intake & exhaust fans, the other is "combined" control for both
69 * CPUs that also deals with the pumps when present. To be "compatible"
70 * with OS X at this point, we only use "COMBINED" on the machines that
71 * are identified as having the pumps (though that identification is at
72 * least dodgy). Ultimately, we could probably switch completely to this
73 * algorithm provided we hack it to deal with the UP case
75 #define CPU_PID_TYPE_SPLIT 0
76 #define CPU_PID_TYPE_COMBINED 1
77 #define CPU_PID_TYPE_RACKMAC 2
80 * This table describes all fans in the FCU. The "id" and "type" values
81 * are defaults valid for all earlier machines. Newer machines will
82 * eventually override the table content based on the device-tree
86 char* loc
; /* location code */
87 int type
; /* 0 = rpm, 1 = pwm, 2 = pump */
88 int id
; /* id or -1 */
94 #define FCU_FAN_ABSENT_ID -1
96 #define FCU_FAN_COUNT ARRAY_SIZE(fcu_fans)
98 struct fcu_fan_table fcu_fans
[] = {
99 [BACKSIDE_FAN_PWM_INDEX
] = {
100 .loc
= "BACKSIDE,SYS CTRLR FAN",
102 .id
= BACKSIDE_FAN_PWM_DEFAULT_ID
,
104 [DRIVES_FAN_RPM_INDEX
] = {
107 .id
= DRIVES_FAN_RPM_DEFAULT_ID
,
109 [SLOTS_FAN_PWM_INDEX
] = {
110 .loc
= "SLOT,PCI FAN",
112 .id
= SLOTS_FAN_PWM_DEFAULT_ID
,
114 [CPUA_INTAKE_FAN_RPM_INDEX
] = {
115 .loc
= "CPU A INTAKE",
117 .id
= CPUA_INTAKE_FAN_RPM_DEFAULT_ID
,
119 [CPUA_EXHAUST_FAN_RPM_INDEX
] = {
120 .loc
= "CPU A EXHAUST",
122 .id
= CPUA_EXHAUST_FAN_RPM_DEFAULT_ID
,
124 [CPUB_INTAKE_FAN_RPM_INDEX
] = {
125 .loc
= "CPU B INTAKE",
127 .id
= CPUB_INTAKE_FAN_RPM_DEFAULT_ID
,
129 [CPUB_EXHAUST_FAN_RPM_INDEX
] = {
130 .loc
= "CPU B EXHAUST",
132 .id
= CPUB_EXHAUST_FAN_RPM_DEFAULT_ID
,
134 /* pumps aren't present by default, have to be looked up in the
137 [CPUA_PUMP_RPM_INDEX
] = {
140 .id
= FCU_FAN_ABSENT_ID
,
142 [CPUB_PUMP_RPM_INDEX
] = {
145 .id
= FCU_FAN_ABSENT_ID
,
148 [CPU_A1_FAN_RPM_INDEX
] = {
151 .id
= FCU_FAN_ABSENT_ID
,
153 [CPU_A2_FAN_RPM_INDEX
] = {
156 .id
= FCU_FAN_ABSENT_ID
,
158 [CPU_A3_FAN_RPM_INDEX
] = {
161 .id
= FCU_FAN_ABSENT_ID
,
163 [CPU_B1_FAN_RPM_INDEX
] = {
166 .id
= FCU_FAN_ABSENT_ID
,
168 [CPU_B2_FAN_RPM_INDEX
] = {
171 .id
= FCU_FAN_ABSENT_ID
,
173 [CPU_B3_FAN_RPM_INDEX
] = {
176 .id
= FCU_FAN_ABSENT_ID
,
180 static struct i2c_driver therm_pm72_driver
;
183 * Utility function to create an i2c_client structure and
184 * attach it to one of u3 adapters
186 static struct i2c_client
*attach_i2c_chip(int id
, const char *name
)
188 struct i2c_client
*clt
;
189 struct i2c_adapter
*adap
;
190 struct i2c_board_info info
;
201 memset(&info
, 0, sizeof(struct i2c_board_info
));
202 info
.addr
= (id
>> 1) & 0x7f;
203 strlcpy(info
.type
, "therm_pm72", I2C_NAME_SIZE
);
204 clt
= i2c_new_device(adap
, &info
);
206 printk(KERN_ERR
"therm_pm72: Failed to attach to i2c ID 0x%x\n", id
);
211 * Let i2c-core delete that device on driver removal.
212 * This is safe because i2c-core holds the core_lock mutex for us.
214 list_add_tail(&clt
->detected
, &therm_pm72_driver
.clients
);
219 * Here are the i2c chip access wrappers
222 static void initialize_adc(struct cpu_pid_state
*state
)
227 /* Read ADC the configuration register and cache it. We
228 * also make sure Config2 contains proper values, I've seen
229 * cases where we got stale grabage in there, thus preventing
230 * proper reading of conv. values
236 i2c_master_send(state
->monitor
, buf
, 2);
238 /* Read & cache Config1 */
240 rc
= i2c_master_send(state
->monitor
, buf
, 1);
242 rc
= i2c_master_recv(state
->monitor
, buf
, 1);
244 state
->adc_config
= buf
[0];
245 DBG("ADC config reg: %02x\n", state
->adc_config
);
246 /* Disable shutdown mode */
247 state
->adc_config
&= 0xfe;
249 buf
[1] = state
->adc_config
;
250 rc
= i2c_master_send(state
->monitor
, buf
, 2);
254 printk(KERN_ERR
"therm_pm72: Error reading ADC config"
258 static int read_smon_adc(struct cpu_pid_state
*state
, int chan
)
260 int rc
, data
, tries
= 0;
266 buf
[1] = (state
->adc_config
& 0x1f) | (chan
<< 5);
267 rc
= i2c_master_send(state
->monitor
, buf
, 2);
270 /* Wait for convertion */
272 /* Switch to data register */
274 rc
= i2c_master_send(state
->monitor
, buf
, 1);
278 rc
= i2c_master_recv(state
->monitor
, buf
, 2);
281 data
= ((u16
)buf
[0]) << 8 | (u16
)buf
[1];
284 DBG("Error reading ADC, retrying...\n");
286 printk(KERN_ERR
"therm_pm72: Error reading ADC !\n");
293 static int read_lm87_reg(struct i2c_client
* chip
, int reg
)
301 rc
= i2c_master_send(chip
, &buf
, 1);
304 rc
= i2c_master_recv(chip
, &buf
, 1);
309 DBG("Error reading LM87, retrying...\n");
311 printk(KERN_ERR
"therm_pm72: Error reading LM87 !\n");
318 static int fan_read_reg(int reg
, unsigned char *buf
, int nb
)
325 nw
= i2c_master_send(fcu
, buf
, 1);
326 if (nw
> 0 || (nw
< 0 && nw
!= -EIO
) || tries
>= 100)
332 printk(KERN_ERR
"Failure writing address to FCU: %d", nw
);
337 nr
= i2c_master_recv(fcu
, buf
, nb
);
338 if (nr
> 0 || (nr
< 0 && nr
!= ENODEV
) || tries
>= 100)
344 printk(KERN_ERR
"Failure reading data from FCU: %d", nw
);
348 static int fan_write_reg(int reg
, const unsigned char *ptr
, int nb
)
351 unsigned char buf
[16];
354 memcpy(buf
+1, ptr
, nb
);
358 nw
= i2c_master_send(fcu
, buf
, nb
);
359 if (nw
> 0 || (nw
< 0 && nw
!= EIO
) || tries
>= 100)
365 printk(KERN_ERR
"Failure writing to FCU: %d", nw
);
369 static int start_fcu(void)
371 unsigned char buf
= 0xff;
374 rc
= fan_write_reg(0xe, &buf
, 1);
377 rc
= fan_write_reg(0x2e, &buf
, 1);
380 rc
= fan_read_reg(0, &buf
, 1);
383 fcu_rpm_shift
= (buf
== 1) ? 2 : 3;
384 printk(KERN_DEBUG
"FCU Initialized, RPM fan shift is %d\n",
390 static int set_rpm_fan(int fan_index
, int rpm
)
392 unsigned char buf
[2];
393 int rc
, id
, min
, max
;
395 if (fcu_fans
[fan_index
].type
!= FCU_FAN_RPM
)
397 id
= fcu_fans
[fan_index
].id
;
398 if (id
== FCU_FAN_ABSENT_ID
)
401 min
= 2400 >> fcu_rpm_shift
;
402 max
= 56000 >> fcu_rpm_shift
;
408 buf
[0] = rpm
>> (8 - fcu_rpm_shift
);
409 buf
[1] = rpm
<< fcu_rpm_shift
;
410 rc
= fan_write_reg(0x10 + (id
* 2), buf
, 2);
416 static int get_rpm_fan(int fan_index
, int programmed
)
418 unsigned char failure
;
419 unsigned char active
;
420 unsigned char buf
[2];
421 int rc
, id
, reg_base
;
423 if (fcu_fans
[fan_index
].type
!= FCU_FAN_RPM
)
425 id
= fcu_fans
[fan_index
].id
;
426 if (id
== FCU_FAN_ABSENT_ID
)
429 rc
= fan_read_reg(0xb, &failure
, 1);
432 if ((failure
& (1 << id
)) != 0)
434 rc
= fan_read_reg(0xd, &active
, 1);
437 if ((active
& (1 << id
)) == 0)
440 /* Programmed value or real current speed */
441 reg_base
= programmed
? 0x10 : 0x11;
442 rc
= fan_read_reg(reg_base
+ (id
* 2), buf
, 2);
446 return (buf
[0] << (8 - fcu_rpm_shift
)) | buf
[1] >> fcu_rpm_shift
;
449 static int set_pwm_fan(int fan_index
, int pwm
)
451 unsigned char buf
[2];
454 if (fcu_fans
[fan_index
].type
!= FCU_FAN_PWM
)
456 id
= fcu_fans
[fan_index
].id
;
457 if (id
== FCU_FAN_ABSENT_ID
)
464 pwm
= (pwm
* 2559) / 1000;
466 rc
= fan_write_reg(0x30 + (id
* 2), buf
, 1);
472 static int get_pwm_fan(int fan_index
)
474 unsigned char failure
;
475 unsigned char active
;
476 unsigned char buf
[2];
479 if (fcu_fans
[fan_index
].type
!= FCU_FAN_PWM
)
481 id
= fcu_fans
[fan_index
].id
;
482 if (id
== FCU_FAN_ABSENT_ID
)
485 rc
= fan_read_reg(0x2b, &failure
, 1);
488 if ((failure
& (1 << id
)) != 0)
490 rc
= fan_read_reg(0x2d, &active
, 1);
493 if ((active
& (1 << id
)) == 0)
496 /* Programmed value or real current speed */
497 rc
= fan_read_reg(0x30 + (id
* 2), buf
, 1);
501 return (buf
[0] * 1000) / 2559;
504 static void tickle_fcu(void)
508 pwm
= get_pwm_fan(SLOTS_FAN_PWM_INDEX
);
510 DBG("FCU Tickle, slots fan is: %d\n", pwm
);
515 pwm
= SLOTS_FAN_DEFAULT_PWM
;
516 } else if (pwm
< SLOTS_PID_OUTPUT_MIN
)
517 pwm
= SLOTS_PID_OUTPUT_MIN
;
519 /* That is hopefully enough to make the FCU happy */
520 set_pwm_fan(SLOTS_FAN_PWM_INDEX
, pwm
);
525 * Utility routine to read the CPU calibration EEPROM data
526 * from the device-tree
528 static int read_eeprom(int cpu
, struct mpu_data
*out
)
530 struct device_node
*np
;
535 sprintf(nodename
, "/u3@0,f8000000/i2c@f8001000/cpuid@a%d", cpu
? 2 : 0);
536 np
= of_find_node_by_path(nodename
);
538 printk(KERN_ERR
"therm_pm72: Failed to retrieve cpuid node from device-tree\n");
541 data
= of_get_property(np
, "cpuid", &len
);
543 printk(KERN_ERR
"therm_pm72: Failed to retrieve cpuid property from device-tree\n");
547 memcpy(out
, data
, sizeof(struct mpu_data
));
553 static void fetch_cpu_pumps_minmax(void)
555 struct cpu_pid_state
*state0
= &cpu_state
[0];
556 struct cpu_pid_state
*state1
= &cpu_state
[1];
557 u16 pump_min
= 0, pump_max
= 0xffff;
560 /* Try to fetch pumps min/max infos from eeprom */
562 memcpy(&tmp
, &state0
->mpu
.processor_part_num
, 8);
563 if (tmp
[0] != 0xffff && tmp
[1] != 0xffff) {
564 pump_min
= max(pump_min
, tmp
[0]);
565 pump_max
= min(pump_max
, tmp
[1]);
567 if (tmp
[2] != 0xffff && tmp
[3] != 0xffff) {
568 pump_min
= max(pump_min
, tmp
[2]);
569 pump_max
= min(pump_max
, tmp
[3]);
572 /* Double check the values, this _IS_ needed as the EEPROM on
573 * some dual 2.5Ghz G5s seem, at least, to have both min & max
574 * same to the same value ... (grrrr)
576 if (pump_min
== pump_max
|| pump_min
== 0 || pump_max
== 0xffff) {
577 pump_min
= CPU_PUMP_OUTPUT_MIN
;
578 pump_max
= CPU_PUMP_OUTPUT_MAX
;
581 state0
->pump_min
= state1
->pump_min
= pump_min
;
582 state0
->pump_max
= state1
->pump_max
= pump_max
;
586 * Now, unfortunately, sysfs doesn't give us a nice void * we could
587 * pass around to the attribute functions, so we don't really have
588 * choice but implement a bunch of them...
590 * That sucks a bit, we take the lock because FIX32TOPRINT evaluates
591 * the input twice... I accept patches :)
593 #define BUILD_SHOW_FUNC_FIX(name, data) \
594 static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
597 mutex_lock(&driver_lock); \
598 r = sprintf(buf, "%d.%03d", FIX32TOPRINT(data)); \
599 mutex_unlock(&driver_lock); \
602 #define BUILD_SHOW_FUNC_INT(name, data) \
603 static ssize_t show_##name(struct device *dev, struct device_attribute *attr, char *buf) \
605 return sprintf(buf, "%d", data); \
608 BUILD_SHOW_FUNC_FIX(cpu0_temperature
, cpu_state
[0].last_temp
)
609 BUILD_SHOW_FUNC_FIX(cpu0_voltage
, cpu_state
[0].voltage
)
610 BUILD_SHOW_FUNC_FIX(cpu0_current
, cpu_state
[0].current_a
)
611 BUILD_SHOW_FUNC_INT(cpu0_exhaust_fan_rpm
, cpu_state
[0].rpm
)
612 BUILD_SHOW_FUNC_INT(cpu0_intake_fan_rpm
, cpu_state
[0].intake_rpm
)
614 BUILD_SHOW_FUNC_FIX(cpu1_temperature
, cpu_state
[1].last_temp
)
615 BUILD_SHOW_FUNC_FIX(cpu1_voltage
, cpu_state
[1].voltage
)
616 BUILD_SHOW_FUNC_FIX(cpu1_current
, cpu_state
[1].current_a
)
617 BUILD_SHOW_FUNC_INT(cpu1_exhaust_fan_rpm
, cpu_state
[1].rpm
)
618 BUILD_SHOW_FUNC_INT(cpu1_intake_fan_rpm
, cpu_state
[1].intake_rpm
)
620 BUILD_SHOW_FUNC_FIX(backside_temperature
, backside_state
.last_temp
)
621 BUILD_SHOW_FUNC_INT(backside_fan_pwm
, backside_state
.pwm
)
623 BUILD_SHOW_FUNC_FIX(drives_temperature
, drives_state
.last_temp
)
624 BUILD_SHOW_FUNC_INT(drives_fan_rpm
, drives_state
.rpm
)
626 BUILD_SHOW_FUNC_FIX(slots_temperature
, slots_state
.last_temp
)
627 BUILD_SHOW_FUNC_INT(slots_fan_pwm
, slots_state
.pwm
)
629 BUILD_SHOW_FUNC_FIX(dimms_temperature
, dimms_state
.last_temp
)
631 static DEVICE_ATTR(cpu0_temperature
,S_IRUGO
,show_cpu0_temperature
,NULL
);
632 static DEVICE_ATTR(cpu0_voltage
,S_IRUGO
,show_cpu0_voltage
,NULL
);
633 static DEVICE_ATTR(cpu0_current
,S_IRUGO
,show_cpu0_current
,NULL
);
634 static DEVICE_ATTR(cpu0_exhaust_fan_rpm
,S_IRUGO
,show_cpu0_exhaust_fan_rpm
,NULL
);
635 static DEVICE_ATTR(cpu0_intake_fan_rpm
,S_IRUGO
,show_cpu0_intake_fan_rpm
,NULL
);
637 static DEVICE_ATTR(cpu1_temperature
,S_IRUGO
,show_cpu1_temperature
,NULL
);
638 static DEVICE_ATTR(cpu1_voltage
,S_IRUGO
,show_cpu1_voltage
,NULL
);
639 static DEVICE_ATTR(cpu1_current
,S_IRUGO
,show_cpu1_current
,NULL
);
640 static DEVICE_ATTR(cpu1_exhaust_fan_rpm
,S_IRUGO
,show_cpu1_exhaust_fan_rpm
,NULL
);
641 static DEVICE_ATTR(cpu1_intake_fan_rpm
,S_IRUGO
,show_cpu1_intake_fan_rpm
,NULL
);
643 static DEVICE_ATTR(backside_temperature
,S_IRUGO
,show_backside_temperature
,NULL
);
644 static DEVICE_ATTR(backside_fan_pwm
,S_IRUGO
,show_backside_fan_pwm
,NULL
);
646 static DEVICE_ATTR(drives_temperature
,S_IRUGO
,show_drives_temperature
,NULL
);
647 static DEVICE_ATTR(drives_fan_rpm
,S_IRUGO
,show_drives_fan_rpm
,NULL
);
649 static DEVICE_ATTR(slots_temperature
,S_IRUGO
,show_slots_temperature
,NULL
);
650 static DEVICE_ATTR(slots_fan_pwm
,S_IRUGO
,show_slots_fan_pwm
,NULL
);
652 static DEVICE_ATTR(dimms_temperature
,S_IRUGO
,show_dimms_temperature
,NULL
);
655 * CPUs fans control loop
658 static int do_read_one_cpu_values(struct cpu_pid_state
*state
, s32
*temp
, s32
*power
)
660 s32 ltemp
, volts
, amps
;
663 /* Default (in case of error) */
664 *temp
= state
->cur_temp
;
665 *power
= state
->cur_power
;
667 if (cpu_pid_type
== CPU_PID_TYPE_RACKMAC
)
668 index
= (state
->index
== 0) ?
669 CPU_A1_FAN_RPM_INDEX
: CPU_B1_FAN_RPM_INDEX
;
671 index
= (state
->index
== 0) ?
672 CPUA_EXHAUST_FAN_RPM_INDEX
: CPUB_EXHAUST_FAN_RPM_INDEX
;
674 /* Read current fan status */
675 rc
= get_rpm_fan(index
, !RPM_PID_USE_ACTUAL_SPEED
);
677 DBG(" cpu %d, fan reading error !\n", state
->index
);
680 DBG(" cpu %d, exhaust RPM: %d\n", state
->index
, state
->rpm
);
683 /* Get some sensor readings and scale it */
684 ltemp
= read_smon_adc(state
, 1);
689 DBG(" cpu %d, temp reading error !\n", state
->index
);
691 /* Fixup temperature according to diode calibration
693 DBG(" cpu %d, temp raw: %04x, m_diode: %04x, b_diode: %04x\n",
695 ltemp
, state
->mpu
.mdiode
, state
->mpu
.bdiode
);
696 *temp
= ((s32
)ltemp
* (s32
)state
->mpu
.mdiode
+ ((s32
)state
->mpu
.bdiode
<< 12)) >> 2;
697 state
->last_temp
= *temp
;
698 DBG(" temp: %d.%03d\n", FIX32TOPRINT((*temp
)));
702 * Read voltage & current and calculate power
704 volts
= read_smon_adc(state
, 3);
705 amps
= read_smon_adc(state
, 4);
707 /* Scale voltage and current raw sensor values according to fixed scales
708 * obtained in Darwin and calculate power from I and V
710 volts
*= ADC_CPU_VOLTAGE_SCALE
;
711 amps
*= ADC_CPU_CURRENT_SCALE
;
712 *power
= (((u64
)volts
) * ((u64
)amps
)) >> 16;
713 state
->voltage
= volts
;
714 state
->current_a
= amps
;
715 state
->last_power
= *power
;
717 DBG(" cpu %d, current: %d.%03d, voltage: %d.%03d, power: %d.%03d W\n",
718 state
->index
, FIX32TOPRINT(state
->current_a
),
719 FIX32TOPRINT(state
->voltage
), FIX32TOPRINT(*power
));
724 static void do_cpu_pid(struct cpu_pid_state
*state
, s32 temp
, s32 power
)
726 s32 power_target
, integral
, derivative
, proportional
, adj_in_target
, sval
;
727 s64 integ_p
, deriv_p
, prop_p
, sum
;
730 /* Calculate power target value (could be done once for all)
731 * and convert to a 16.16 fp number
733 power_target
= ((u32
)(state
->mpu
.pmaxh
- state
->mpu
.padjmax
)) << 16;
734 DBG(" power target: %d.%03d, error: %d.%03d\n",
735 FIX32TOPRINT(power_target
), FIX32TOPRINT(power_target
- power
));
737 /* Store temperature and power in history array */
738 state
->cur_temp
= (state
->cur_temp
+ 1) % CPU_TEMP_HISTORY_SIZE
;
739 state
->temp_history
[state
->cur_temp
] = temp
;
740 state
->cur_power
= (state
->cur_power
+ 1) % state
->count_power
;
741 state
->power_history
[state
->cur_power
] = power
;
742 state
->error_history
[state
->cur_power
] = power_target
- power
;
744 /* If first loop, fill the history table */
746 for (i
= 0; i
< (state
->count_power
- 1); i
++) {
747 state
->cur_power
= (state
->cur_power
+ 1) % state
->count_power
;
748 state
->power_history
[state
->cur_power
] = power
;
749 state
->error_history
[state
->cur_power
] = power_target
- power
;
751 for (i
= 0; i
< (CPU_TEMP_HISTORY_SIZE
- 1); i
++) {
752 state
->cur_temp
= (state
->cur_temp
+ 1) % CPU_TEMP_HISTORY_SIZE
;
753 state
->temp_history
[state
->cur_temp
] = temp
;
758 /* Calculate the integral term normally based on the "power" values */
761 for (i
= 0; i
< state
->count_power
; i
++)
762 integral
+= state
->error_history
[i
];
763 integral
*= CPU_PID_INTERVAL
;
764 DBG(" integral: %08x\n", integral
);
766 /* Calculate the adjusted input (sense value).
769 * so the result is 28.36
771 * input target is mpu.ttarget, input max is mpu.tmax
773 integ_p
= ((s64
)state
->mpu
.pid_gr
) * (s64
)integral
;
774 DBG(" integ_p: %d\n", (int)(integ_p
>> 36));
775 sval
= (state
->mpu
.tmax
<< 16) - ((integ_p
>> 20) & 0xffffffff);
776 adj_in_target
= (state
->mpu
.ttarget
<< 16);
777 if (adj_in_target
> sval
)
778 adj_in_target
= sval
;
779 DBG(" adj_in_target: %d.%03d, ttarget: %d\n", FIX32TOPRINT(adj_in_target
),
782 /* Calculate the derivative term */
783 derivative
= state
->temp_history
[state
->cur_temp
] -
784 state
->temp_history
[(state
->cur_temp
+ CPU_TEMP_HISTORY_SIZE
- 1)
785 % CPU_TEMP_HISTORY_SIZE
];
786 derivative
/= CPU_PID_INTERVAL
;
787 deriv_p
= ((s64
)state
->mpu
.pid_gd
) * (s64
)derivative
;
788 DBG(" deriv_p: %d\n", (int)(deriv_p
>> 36));
791 /* Calculate the proportional term */
792 proportional
= temp
- adj_in_target
;
793 prop_p
= ((s64
)state
->mpu
.pid_gp
) * (s64
)proportional
;
794 DBG(" prop_p: %d\n", (int)(prop_p
>> 36));
800 DBG(" sum: %d\n", (int)sum
);
801 state
->rpm
+= (s32
)sum
;
804 static void do_monitor_cpu_combined(void)
806 struct cpu_pid_state
*state0
= &cpu_state
[0];
807 struct cpu_pid_state
*state1
= &cpu_state
[1];
808 s32 temp0
, power0
, temp1
, power1
;
809 s32 temp_combi
, power_combi
;
810 int rc
, intake
, pump
;
812 rc
= do_read_one_cpu_values(state0
, &temp0
, &power0
);
815 state1
->overtemp
= 0;
816 rc
= do_read_one_cpu_values(state1
, &temp1
, &power1
);
819 if (state1
->overtemp
)
822 temp_combi
= max(temp0
, temp1
);
823 power_combi
= max(power0
, power1
);
825 /* Check tmax, increment overtemp if we are there. At tmax+8, we go
826 * full blown immediately and try to trigger a shutdown
828 if (temp_combi
>= ((state0
->mpu
.tmax
+ 8) << 16)) {
829 printk(KERN_WARNING
"Warning ! Temperature way above maximum (%d) !\n",
831 state0
->overtemp
+= CPU_MAX_OVERTEMP
/ 4;
832 } else if (temp_combi
> (state0
->mpu
.tmax
<< 16)) {
834 printk(KERN_WARNING
"Temperature %d above max %d. overtemp %d\n",
835 temp_combi
>> 16, state0
->mpu
.tmax
, state0
->overtemp
);
837 if (state0
->overtemp
)
838 printk(KERN_WARNING
"Temperature back down to %d\n",
840 state0
->overtemp
= 0;
842 if (state0
->overtemp
>= CPU_MAX_OVERTEMP
)
844 if (state0
->overtemp
> 0) {
845 state0
->rpm
= state0
->mpu
.rmaxn_exhaust_fan
;
846 state0
->intake_rpm
= intake
= state0
->mpu
.rmaxn_intake_fan
;
847 pump
= state0
->pump_max
;
852 do_cpu_pid(state0
, temp_combi
, power_combi
);
855 state0
->rpm
= max(state0
->rpm
, (int)state0
->mpu
.rminn_exhaust_fan
);
856 state0
->rpm
= min(state0
->rpm
, (int)state0
->mpu
.rmaxn_exhaust_fan
);
858 /* Calculate intake fan speed */
859 intake
= (state0
->rpm
* CPU_INTAKE_SCALE
) >> 16;
860 intake
= max(intake
, (int)state0
->mpu
.rminn_intake_fan
);
861 intake
= min(intake
, (int)state0
->mpu
.rmaxn_intake_fan
);
862 state0
->intake_rpm
= intake
;
864 /* Calculate pump speed */
865 pump
= (state0
->rpm
* state0
->pump_max
) /
866 state0
->mpu
.rmaxn_exhaust_fan
;
867 pump
= min(pump
, state0
->pump_max
);
868 pump
= max(pump
, state0
->pump_min
);
871 /* We copy values from state 0 to state 1 for /sysfs */
872 state1
->rpm
= state0
->rpm
;
873 state1
->intake_rpm
= state0
->intake_rpm
;
875 DBG("** CPU %d RPM: %d Ex, %d, Pump: %d, In, overtemp: %d\n",
876 state1
->index
, (int)state1
->rpm
, intake
, pump
, state1
->overtemp
);
878 /* We should check for errors, shouldn't we ? But then, what
879 * do we do once the error occurs ? For FCU notified fan
880 * failures (-EFAULT) we probably want to notify userland
883 set_rpm_fan(CPUA_INTAKE_FAN_RPM_INDEX
, intake
);
884 set_rpm_fan(CPUA_EXHAUST_FAN_RPM_INDEX
, state0
->rpm
);
885 set_rpm_fan(CPUB_INTAKE_FAN_RPM_INDEX
, intake
);
886 set_rpm_fan(CPUB_EXHAUST_FAN_RPM_INDEX
, state0
->rpm
);
888 if (fcu_fans
[CPUA_PUMP_RPM_INDEX
].id
!= FCU_FAN_ABSENT_ID
)
889 set_rpm_fan(CPUA_PUMP_RPM_INDEX
, pump
);
890 if (fcu_fans
[CPUB_PUMP_RPM_INDEX
].id
!= FCU_FAN_ABSENT_ID
)
891 set_rpm_fan(CPUB_PUMP_RPM_INDEX
, pump
);
894 static void do_monitor_cpu_split(struct cpu_pid_state
*state
)
899 /* Read current fan status */
900 rc
= do_read_one_cpu_values(state
, &temp
, &power
);
904 /* Check tmax, increment overtemp if we are there. At tmax+8, we go
905 * full blown immediately and try to trigger a shutdown
907 if (temp
>= ((state
->mpu
.tmax
+ 8) << 16)) {
908 printk(KERN_WARNING
"Warning ! CPU %d temperature way above maximum"
910 state
->index
, temp
>> 16);
911 state
->overtemp
+= CPU_MAX_OVERTEMP
/ 4;
912 } else if (temp
> (state
->mpu
.tmax
<< 16)) {
914 printk(KERN_WARNING
"CPU %d temperature %d above max %d. overtemp %d\n",
915 state
->index
, temp
>> 16, state
->mpu
.tmax
, state
->overtemp
);
918 printk(KERN_WARNING
"CPU %d temperature back down to %d\n",
919 state
->index
, temp
>> 16);
922 if (state
->overtemp
>= CPU_MAX_OVERTEMP
)
924 if (state
->overtemp
> 0) {
925 state
->rpm
= state
->mpu
.rmaxn_exhaust_fan
;
926 state
->intake_rpm
= intake
= state
->mpu
.rmaxn_intake_fan
;
931 do_cpu_pid(state
, temp
, power
);
934 state
->rpm
= max(state
->rpm
, (int)state
->mpu
.rminn_exhaust_fan
);
935 state
->rpm
= min(state
->rpm
, (int)state
->mpu
.rmaxn_exhaust_fan
);
937 /* Calculate intake fan */
938 intake
= (state
->rpm
* CPU_INTAKE_SCALE
) >> 16;
939 intake
= max(intake
, (int)state
->mpu
.rminn_intake_fan
);
940 intake
= min(intake
, (int)state
->mpu
.rmaxn_intake_fan
);
941 state
->intake_rpm
= intake
;
944 DBG("** CPU %d RPM: %d Ex, %d In, overtemp: %d\n",
945 state
->index
, (int)state
->rpm
, intake
, state
->overtemp
);
947 /* We should check for errors, shouldn't we ? But then, what
948 * do we do once the error occurs ? For FCU notified fan
949 * failures (-EFAULT) we probably want to notify userland
952 if (state
->index
== 0) {
953 set_rpm_fan(CPUA_INTAKE_FAN_RPM_INDEX
, intake
);
954 set_rpm_fan(CPUA_EXHAUST_FAN_RPM_INDEX
, state
->rpm
);
956 set_rpm_fan(CPUB_INTAKE_FAN_RPM_INDEX
, intake
);
957 set_rpm_fan(CPUB_EXHAUST_FAN_RPM_INDEX
, state
->rpm
);
961 static void do_monitor_cpu_rack(struct cpu_pid_state
*state
)
963 s32 temp
, power
, fan_min
;
966 /* Read current fan status */
967 rc
= do_read_one_cpu_values(state
, &temp
, &power
);
971 /* Check tmax, increment overtemp if we are there. At tmax+8, we go
972 * full blown immediately and try to trigger a shutdown
974 if (temp
>= ((state
->mpu
.tmax
+ 8) << 16)) {
975 printk(KERN_WARNING
"Warning ! CPU %d temperature way above maximum"
977 state
->index
, temp
>> 16);
978 state
->overtemp
= CPU_MAX_OVERTEMP
/ 4;
979 } else if (temp
> (state
->mpu
.tmax
<< 16)) {
981 printk(KERN_WARNING
"CPU %d temperature %d above max %d. overtemp %d\n",
982 state
->index
, temp
>> 16, state
->mpu
.tmax
, state
->overtemp
);
985 printk(KERN_WARNING
"CPU %d temperature back down to %d\n",
986 state
->index
, temp
>> 16);
989 if (state
->overtemp
>= CPU_MAX_OVERTEMP
)
991 if (state
->overtemp
> 0) {
992 state
->rpm
= state
->intake_rpm
= state
->mpu
.rmaxn_intake_fan
;
997 do_cpu_pid(state
, temp
, power
);
999 /* Check clamp from dimms */
1000 fan_min
= dimm_output_clamp
;
1001 fan_min
= max(fan_min
, (int)state
->mpu
.rminn_intake_fan
);
1003 DBG(" CPU min mpu = %d, min dimm = %d\n",
1004 state
->mpu
.rminn_intake_fan
, dimm_output_clamp
);
1006 state
->rpm
= max(state
->rpm
, (int)fan_min
);
1007 state
->rpm
= min(state
->rpm
, (int)state
->mpu
.rmaxn_intake_fan
);
1008 state
->intake_rpm
= state
->rpm
;
1011 DBG("** CPU %d RPM: %d overtemp: %d\n",
1012 state
->index
, (int)state
->rpm
, state
->overtemp
);
1014 /* We should check for errors, shouldn't we ? But then, what
1015 * do we do once the error occurs ? For FCU notified fan
1016 * failures (-EFAULT) we probably want to notify userland
1019 if (state
->index
== 0) {
1020 set_rpm_fan(CPU_A1_FAN_RPM_INDEX
, state
->rpm
);
1021 set_rpm_fan(CPU_A2_FAN_RPM_INDEX
, state
->rpm
);
1022 set_rpm_fan(CPU_A3_FAN_RPM_INDEX
, state
->rpm
);
1024 set_rpm_fan(CPU_B1_FAN_RPM_INDEX
, state
->rpm
);
1025 set_rpm_fan(CPU_B2_FAN_RPM_INDEX
, state
->rpm
);
1026 set_rpm_fan(CPU_B3_FAN_RPM_INDEX
, state
->rpm
);
1031 * Initialize the state structure for one CPU control loop
1033 static int init_cpu_state(struct cpu_pid_state
*state
, int index
)
1037 state
->index
= index
;
1039 state
->rpm
= (cpu_pid_type
== CPU_PID_TYPE_RACKMAC
) ? 4000 : 1000;
1040 state
->overtemp
= 0;
1041 state
->adc_config
= 0x00;
1045 state
->monitor
= attach_i2c_chip(SUPPLY_MONITOR_ID
, "CPU0_monitor");
1046 else if (index
== 1)
1047 state
->monitor
= attach_i2c_chip(SUPPLY_MONITORB_ID
, "CPU1_monitor");
1048 if (state
->monitor
== NULL
)
1051 if (read_eeprom(index
, &state
->mpu
))
1054 state
->count_power
= state
->mpu
.tguardband
;
1055 if (state
->count_power
> CPU_POWER_HISTORY_SIZE
) {
1056 printk(KERN_WARNING
"Warning ! too many power history slots\n");
1057 state
->count_power
= CPU_POWER_HISTORY_SIZE
;
1059 DBG("CPU %d Using %d power history entries\n", index
, state
->count_power
);
1062 err
= device_create_file(&of_dev
->dev
, &dev_attr_cpu0_temperature
);
1063 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu0_voltage
);
1064 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu0_current
);
1065 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu0_exhaust_fan_rpm
);
1066 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu0_intake_fan_rpm
);
1068 err
= device_create_file(&of_dev
->dev
, &dev_attr_cpu1_temperature
);
1069 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu1_voltage
);
1070 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu1_current
);
1071 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu1_exhaust_fan_rpm
);
1072 err
|= device_create_file(&of_dev
->dev
, &dev_attr_cpu1_intake_fan_rpm
);
1075 printk(KERN_WARNING
"Failed to create some of the atribute"
1076 "files for CPU %d\n", index
);
1080 state
->monitor
= NULL
;
1086 * Dispose of the state data for one CPU control loop
1088 static void dispose_cpu_state(struct cpu_pid_state
*state
)
1090 if (state
->monitor
== NULL
)
1093 if (state
->index
== 0) {
1094 device_remove_file(&of_dev
->dev
, &dev_attr_cpu0_temperature
);
1095 device_remove_file(&of_dev
->dev
, &dev_attr_cpu0_voltage
);
1096 device_remove_file(&of_dev
->dev
, &dev_attr_cpu0_current
);
1097 device_remove_file(&of_dev
->dev
, &dev_attr_cpu0_exhaust_fan_rpm
);
1098 device_remove_file(&of_dev
->dev
, &dev_attr_cpu0_intake_fan_rpm
);
1100 device_remove_file(&of_dev
->dev
, &dev_attr_cpu1_temperature
);
1101 device_remove_file(&of_dev
->dev
, &dev_attr_cpu1_voltage
);
1102 device_remove_file(&of_dev
->dev
, &dev_attr_cpu1_current
);
1103 device_remove_file(&of_dev
->dev
, &dev_attr_cpu1_exhaust_fan_rpm
);
1104 device_remove_file(&of_dev
->dev
, &dev_attr_cpu1_intake_fan_rpm
);
1107 state
->monitor
= NULL
;
1111 * Motherboard backside & U3 heatsink fan control loop
1113 static void do_monitor_backside(struct backside_pid_state
*state
)
1115 s32 temp
, integral
, derivative
, fan_min
;
1116 s64 integ_p
, deriv_p
, prop_p
, sum
;
1119 if (--state
->ticks
!= 0)
1121 state
->ticks
= backside_params
.interval
;
1125 /* Check fan status */
1126 rc
= get_pwm_fan(BACKSIDE_FAN_PWM_INDEX
);
1128 printk(KERN_WARNING
"Error %d reading backside fan !\n", rc
);
1131 DBG(" current pwm: %d\n", state
->pwm
);
1133 /* Get some sensor readings */
1134 temp
= i2c_smbus_read_byte_data(state
->monitor
, MAX6690_EXT_TEMP
) << 16;
1135 state
->last_temp
= temp
;
1136 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp
),
1137 FIX32TOPRINT(backside_params
.input_target
));
1139 /* Store temperature and error in history array */
1140 state
->cur_sample
= (state
->cur_sample
+ 1) % BACKSIDE_PID_HISTORY_SIZE
;
1141 state
->sample_history
[state
->cur_sample
] = temp
;
1142 state
->error_history
[state
->cur_sample
] = temp
- backside_params
.input_target
;
1144 /* If first loop, fill the history table */
1146 for (i
= 0; i
< (BACKSIDE_PID_HISTORY_SIZE
- 1); i
++) {
1147 state
->cur_sample
= (state
->cur_sample
+ 1) %
1148 BACKSIDE_PID_HISTORY_SIZE
;
1149 state
->sample_history
[state
->cur_sample
] = temp
;
1150 state
->error_history
[state
->cur_sample
] =
1151 temp
- backside_params
.input_target
;
1156 /* Calculate the integral term */
1159 for (i
= 0; i
< BACKSIDE_PID_HISTORY_SIZE
; i
++)
1160 integral
+= state
->error_history
[i
];
1161 integral
*= backside_params
.interval
;
1162 DBG(" integral: %08x\n", integral
);
1163 integ_p
= ((s64
)backside_params
.G_r
) * (s64
)integral
;
1164 DBG(" integ_p: %d\n", (int)(integ_p
>> 36));
1167 /* Calculate the derivative term */
1168 derivative
= state
->error_history
[state
->cur_sample
] -
1169 state
->error_history
[(state
->cur_sample
+ BACKSIDE_PID_HISTORY_SIZE
- 1)
1170 % BACKSIDE_PID_HISTORY_SIZE
];
1171 derivative
/= backside_params
.interval
;
1172 deriv_p
= ((s64
)backside_params
.G_d
) * (s64
)derivative
;
1173 DBG(" deriv_p: %d\n", (int)(deriv_p
>> 36));
1176 /* Calculate the proportional term */
1177 prop_p
= ((s64
)backside_params
.G_p
) * (s64
)(state
->error_history
[state
->cur_sample
]);
1178 DBG(" prop_p: %d\n", (int)(prop_p
>> 36));
1184 DBG(" sum: %d\n", (int)sum
);
1185 if (backside_params
.additive
)
1186 state
->pwm
+= (s32
)sum
;
1190 /* Check for clamp */
1191 fan_min
= (dimm_output_clamp
* 100) / 14000;
1192 fan_min
= max(fan_min
, backside_params
.output_min
);
1194 state
->pwm
= max(state
->pwm
, fan_min
);
1195 state
->pwm
= min(state
->pwm
, backside_params
.output_max
);
1197 DBG("** BACKSIDE PWM: %d\n", (int)state
->pwm
);
1198 set_pwm_fan(BACKSIDE_FAN_PWM_INDEX
, state
->pwm
);
1202 * Initialize the state structure for the backside fan control loop
1204 static int init_backside_state(struct backside_pid_state
*state
)
1206 struct device_node
*u3
;
1207 int u3h
= 1; /* conservative by default */
1211 * There are different PID params for machines with U3 and machines
1212 * with U3H, pick the right ones now
1214 u3
= of_find_node_by_path("/u3@0,f8000000");
1216 const u32
*vers
= of_get_property(u3
, "device-rev", NULL
);
1218 if (((*vers
) & 0x3f) < 0x34)
1224 backside_params
.G_d
= BACKSIDE_PID_RACK_G_d
;
1225 backside_params
.input_target
= BACKSIDE_PID_RACK_INPUT_TARGET
;
1226 backside_params
.output_min
= BACKSIDE_PID_U3H_OUTPUT_MIN
;
1227 backside_params
.interval
= BACKSIDE_PID_RACK_INTERVAL
;
1228 backside_params
.G_p
= BACKSIDE_PID_RACK_G_p
;
1229 backside_params
.G_r
= BACKSIDE_PID_G_r
;
1230 backside_params
.output_max
= BACKSIDE_PID_OUTPUT_MAX
;
1231 backside_params
.additive
= 0;
1233 backside_params
.G_d
= BACKSIDE_PID_U3H_G_d
;
1234 backside_params
.input_target
= BACKSIDE_PID_U3H_INPUT_TARGET
;
1235 backside_params
.output_min
= BACKSIDE_PID_U3H_OUTPUT_MIN
;
1236 backside_params
.interval
= BACKSIDE_PID_INTERVAL
;
1237 backside_params
.G_p
= BACKSIDE_PID_G_p
;
1238 backside_params
.G_r
= BACKSIDE_PID_G_r
;
1239 backside_params
.output_max
= BACKSIDE_PID_OUTPUT_MAX
;
1240 backside_params
.additive
= 1;
1242 backside_params
.G_d
= BACKSIDE_PID_U3_G_d
;
1243 backside_params
.input_target
= BACKSIDE_PID_U3_INPUT_TARGET
;
1244 backside_params
.output_min
= BACKSIDE_PID_U3_OUTPUT_MIN
;
1245 backside_params
.interval
= BACKSIDE_PID_INTERVAL
;
1246 backside_params
.G_p
= BACKSIDE_PID_G_p
;
1247 backside_params
.G_r
= BACKSIDE_PID_G_r
;
1248 backside_params
.output_max
= BACKSIDE_PID_OUTPUT_MAX
;
1249 backside_params
.additive
= 1;
1256 state
->monitor
= attach_i2c_chip(BACKSIDE_MAX_ID
, "backside_temp");
1257 if (state
->monitor
== NULL
)
1260 err
= device_create_file(&of_dev
->dev
, &dev_attr_backside_temperature
);
1261 err
|= device_create_file(&of_dev
->dev
, &dev_attr_backside_fan_pwm
);
1263 printk(KERN_WARNING
"Failed to create attribute file(s)"
1264 " for backside fan\n");
1270 * Dispose of the state data for the backside control loop
1272 static void dispose_backside_state(struct backside_pid_state
*state
)
1274 if (state
->monitor
== NULL
)
1277 device_remove_file(&of_dev
->dev
, &dev_attr_backside_temperature
);
1278 device_remove_file(&of_dev
->dev
, &dev_attr_backside_fan_pwm
);
1280 state
->monitor
= NULL
;
1284 * Drives bay fan control loop
1286 static void do_monitor_drives(struct drives_pid_state
*state
)
1288 s32 temp
, integral
, derivative
;
1289 s64 integ_p
, deriv_p
, prop_p
, sum
;
1292 if (--state
->ticks
!= 0)
1294 state
->ticks
= DRIVES_PID_INTERVAL
;
1298 /* Check fan status */
1299 rc
= get_rpm_fan(DRIVES_FAN_RPM_INDEX
, !RPM_PID_USE_ACTUAL_SPEED
);
1301 printk(KERN_WARNING
"Error %d reading drives fan !\n", rc
);
1304 DBG(" current rpm: %d\n", state
->rpm
);
1306 /* Get some sensor readings */
1307 temp
= le16_to_cpu(i2c_smbus_read_word_data(state
->monitor
,
1309 state
->last_temp
= temp
;
1310 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp
),
1311 FIX32TOPRINT(DRIVES_PID_INPUT_TARGET
));
1313 /* Store temperature and error in history array */
1314 state
->cur_sample
= (state
->cur_sample
+ 1) % DRIVES_PID_HISTORY_SIZE
;
1315 state
->sample_history
[state
->cur_sample
] = temp
;
1316 state
->error_history
[state
->cur_sample
] = temp
- DRIVES_PID_INPUT_TARGET
;
1318 /* If first loop, fill the history table */
1320 for (i
= 0; i
< (DRIVES_PID_HISTORY_SIZE
- 1); i
++) {
1321 state
->cur_sample
= (state
->cur_sample
+ 1) %
1322 DRIVES_PID_HISTORY_SIZE
;
1323 state
->sample_history
[state
->cur_sample
] = temp
;
1324 state
->error_history
[state
->cur_sample
] =
1325 temp
- DRIVES_PID_INPUT_TARGET
;
1330 /* Calculate the integral term */
1333 for (i
= 0; i
< DRIVES_PID_HISTORY_SIZE
; i
++)
1334 integral
+= state
->error_history
[i
];
1335 integral
*= DRIVES_PID_INTERVAL
;
1336 DBG(" integral: %08x\n", integral
);
1337 integ_p
= ((s64
)DRIVES_PID_G_r
) * (s64
)integral
;
1338 DBG(" integ_p: %d\n", (int)(integ_p
>> 36));
1341 /* Calculate the derivative term */
1342 derivative
= state
->error_history
[state
->cur_sample
] -
1343 state
->error_history
[(state
->cur_sample
+ DRIVES_PID_HISTORY_SIZE
- 1)
1344 % DRIVES_PID_HISTORY_SIZE
];
1345 derivative
/= DRIVES_PID_INTERVAL
;
1346 deriv_p
= ((s64
)DRIVES_PID_G_d
) * (s64
)derivative
;
1347 DBG(" deriv_p: %d\n", (int)(deriv_p
>> 36));
1350 /* Calculate the proportional term */
1351 prop_p
= ((s64
)DRIVES_PID_G_p
) * (s64
)(state
->error_history
[state
->cur_sample
]);
1352 DBG(" prop_p: %d\n", (int)(prop_p
>> 36));
1358 DBG(" sum: %d\n", (int)sum
);
1359 state
->rpm
+= (s32
)sum
;
1361 state
->rpm
= max(state
->rpm
, DRIVES_PID_OUTPUT_MIN
);
1362 state
->rpm
= min(state
->rpm
, DRIVES_PID_OUTPUT_MAX
);
1364 DBG("** DRIVES RPM: %d\n", (int)state
->rpm
);
1365 set_rpm_fan(DRIVES_FAN_RPM_INDEX
, state
->rpm
);
1369 * Initialize the state structure for the drives bay fan control loop
1371 static int init_drives_state(struct drives_pid_state
*state
)
1379 state
->monitor
= attach_i2c_chip(DRIVES_DALLAS_ID
, "drives_temp");
1380 if (state
->monitor
== NULL
)
1383 err
= device_create_file(&of_dev
->dev
, &dev_attr_drives_temperature
);
1384 err
|= device_create_file(&of_dev
->dev
, &dev_attr_drives_fan_rpm
);
1386 printk(KERN_WARNING
"Failed to create attribute file(s)"
1387 " for drives bay fan\n");
1393 * Dispose of the state data for the drives control loop
1395 static void dispose_drives_state(struct drives_pid_state
*state
)
1397 if (state
->monitor
== NULL
)
1400 device_remove_file(&of_dev
->dev
, &dev_attr_drives_temperature
);
1401 device_remove_file(&of_dev
->dev
, &dev_attr_drives_fan_rpm
);
1403 state
->monitor
= NULL
;
1407 * DIMMs temp control loop
1409 static void do_monitor_dimms(struct dimm_pid_state
*state
)
1411 s32 temp
, integral
, derivative
, fan_min
;
1412 s64 integ_p
, deriv_p
, prop_p
, sum
;
1415 if (--state
->ticks
!= 0)
1417 state
->ticks
= DIMM_PID_INTERVAL
;
1421 DBG(" current value: %d\n", state
->output
);
1423 temp
= read_lm87_reg(state
->monitor
, LM87_INT_TEMP
);
1427 state
->last_temp
= temp
;
1428 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp
),
1429 FIX32TOPRINT(DIMM_PID_INPUT_TARGET
));
1431 /* Store temperature and error in history array */
1432 state
->cur_sample
= (state
->cur_sample
+ 1) % DIMM_PID_HISTORY_SIZE
;
1433 state
->sample_history
[state
->cur_sample
] = temp
;
1434 state
->error_history
[state
->cur_sample
] = temp
- DIMM_PID_INPUT_TARGET
;
1436 /* If first loop, fill the history table */
1438 for (i
= 0; i
< (DIMM_PID_HISTORY_SIZE
- 1); i
++) {
1439 state
->cur_sample
= (state
->cur_sample
+ 1) %
1440 DIMM_PID_HISTORY_SIZE
;
1441 state
->sample_history
[state
->cur_sample
] = temp
;
1442 state
->error_history
[state
->cur_sample
] =
1443 temp
- DIMM_PID_INPUT_TARGET
;
1448 /* Calculate the integral term */
1451 for (i
= 0; i
< DIMM_PID_HISTORY_SIZE
; i
++)
1452 integral
+= state
->error_history
[i
];
1453 integral
*= DIMM_PID_INTERVAL
;
1454 DBG(" integral: %08x\n", integral
);
1455 integ_p
= ((s64
)DIMM_PID_G_r
) * (s64
)integral
;
1456 DBG(" integ_p: %d\n", (int)(integ_p
>> 36));
1459 /* Calculate the derivative term */
1460 derivative
= state
->error_history
[state
->cur_sample
] -
1461 state
->error_history
[(state
->cur_sample
+ DIMM_PID_HISTORY_SIZE
- 1)
1462 % DIMM_PID_HISTORY_SIZE
];
1463 derivative
/= DIMM_PID_INTERVAL
;
1464 deriv_p
= ((s64
)DIMM_PID_G_d
) * (s64
)derivative
;
1465 DBG(" deriv_p: %d\n", (int)(deriv_p
>> 36));
1468 /* Calculate the proportional term */
1469 prop_p
= ((s64
)DIMM_PID_G_p
) * (s64
)(state
->error_history
[state
->cur_sample
]);
1470 DBG(" prop_p: %d\n", (int)(prop_p
>> 36));
1476 DBG(" sum: %d\n", (int)sum
);
1477 state
->output
= (s32
)sum
;
1478 state
->output
= max(state
->output
, DIMM_PID_OUTPUT_MIN
);
1479 state
->output
= min(state
->output
, DIMM_PID_OUTPUT_MAX
);
1480 dimm_output_clamp
= state
->output
;
1482 DBG("** DIMM clamp value: %d\n", (int)state
->output
);
1484 /* Backside PID is only every 5 seconds, force backside fan clamping now */
1485 fan_min
= (dimm_output_clamp
* 100) / 14000;
1486 fan_min
= max(fan_min
, backside_params
.output_min
);
1487 if (backside_state
.pwm
< fan_min
) {
1488 backside_state
.pwm
= fan_min
;
1489 DBG(" -> applying clamp to backside fan now: %d !\n", fan_min
);
1490 set_pwm_fan(BACKSIDE_FAN_PWM_INDEX
, fan_min
);
1495 * Initialize the state structure for the DIMM temp control loop
1497 static int init_dimms_state(struct dimm_pid_state
*state
)
1501 state
->output
= 4000;
1503 state
->monitor
= attach_i2c_chip(XSERVE_DIMMS_LM87
, "dimms_temp");
1504 if (state
->monitor
== NULL
)
1507 if (device_create_file(&of_dev
->dev
, &dev_attr_dimms_temperature
))
1508 printk(KERN_WARNING
"Failed to create attribute file"
1509 " for DIMM temperature\n");
1515 * Dispose of the state data for the DIMM control loop
1517 static void dispose_dimms_state(struct dimm_pid_state
*state
)
1519 if (state
->monitor
== NULL
)
1522 device_remove_file(&of_dev
->dev
, &dev_attr_dimms_temperature
);
1524 state
->monitor
= NULL
;
1528 * Slots fan control loop
1530 static void do_monitor_slots(struct slots_pid_state
*state
)
1532 s32 temp
, integral
, derivative
;
1533 s64 integ_p
, deriv_p
, prop_p
, sum
;
1536 if (--state
->ticks
!= 0)
1538 state
->ticks
= SLOTS_PID_INTERVAL
;
1542 /* Check fan status */
1543 rc
= get_pwm_fan(SLOTS_FAN_PWM_INDEX
);
1545 printk(KERN_WARNING
"Error %d reading slots fan !\n", rc
);
1548 DBG(" current pwm: %d\n", state
->pwm
);
1550 /* Get some sensor readings */
1551 temp
= le16_to_cpu(i2c_smbus_read_word_data(state
->monitor
,
1553 state
->last_temp
= temp
;
1554 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp
),
1555 FIX32TOPRINT(SLOTS_PID_INPUT_TARGET
));
1557 /* Store temperature and error in history array */
1558 state
->cur_sample
= (state
->cur_sample
+ 1) % SLOTS_PID_HISTORY_SIZE
;
1559 state
->sample_history
[state
->cur_sample
] = temp
;
1560 state
->error_history
[state
->cur_sample
] = temp
- SLOTS_PID_INPUT_TARGET
;
1562 /* If first loop, fill the history table */
1564 for (i
= 0; i
< (SLOTS_PID_HISTORY_SIZE
- 1); i
++) {
1565 state
->cur_sample
= (state
->cur_sample
+ 1) %
1566 SLOTS_PID_HISTORY_SIZE
;
1567 state
->sample_history
[state
->cur_sample
] = temp
;
1568 state
->error_history
[state
->cur_sample
] =
1569 temp
- SLOTS_PID_INPUT_TARGET
;
1574 /* Calculate the integral term */
1577 for (i
= 0; i
< SLOTS_PID_HISTORY_SIZE
; i
++)
1578 integral
+= state
->error_history
[i
];
1579 integral
*= SLOTS_PID_INTERVAL
;
1580 DBG(" integral: %08x\n", integral
);
1581 integ_p
= ((s64
)SLOTS_PID_G_r
) * (s64
)integral
;
1582 DBG(" integ_p: %d\n", (int)(integ_p
>> 36));
1585 /* Calculate the derivative term */
1586 derivative
= state
->error_history
[state
->cur_sample
] -
1587 state
->error_history
[(state
->cur_sample
+ SLOTS_PID_HISTORY_SIZE
- 1)
1588 % SLOTS_PID_HISTORY_SIZE
];
1589 derivative
/= SLOTS_PID_INTERVAL
;
1590 deriv_p
= ((s64
)SLOTS_PID_G_d
) * (s64
)derivative
;
1591 DBG(" deriv_p: %d\n", (int)(deriv_p
>> 36));
1594 /* Calculate the proportional term */
1595 prop_p
= ((s64
)SLOTS_PID_G_p
) * (s64
)(state
->error_history
[state
->cur_sample
]);
1596 DBG(" prop_p: %d\n", (int)(prop_p
>> 36));
1602 DBG(" sum: %d\n", (int)sum
);
1603 state
->pwm
= (s32
)sum
;
1605 state
->pwm
= max(state
->pwm
, SLOTS_PID_OUTPUT_MIN
);
1606 state
->pwm
= min(state
->pwm
, SLOTS_PID_OUTPUT_MAX
);
1608 DBG("** DRIVES PWM: %d\n", (int)state
->pwm
);
1609 set_pwm_fan(SLOTS_FAN_PWM_INDEX
, state
->pwm
);
1613 * Initialize the state structure for the slots bay fan control loop
1615 static int init_slots_state(struct slots_pid_state
*state
)
1623 state
->monitor
= attach_i2c_chip(XSERVE_SLOTS_LM75
, "slots_temp");
1624 if (state
->monitor
== NULL
)
1627 err
= device_create_file(&of_dev
->dev
, &dev_attr_slots_temperature
);
1628 err
|= device_create_file(&of_dev
->dev
, &dev_attr_slots_fan_pwm
);
1630 printk(KERN_WARNING
"Failed to create attribute file(s)"
1631 " for slots bay fan\n");
1637 * Dispose of the state data for the slots control loop
1639 static void dispose_slots_state(struct slots_pid_state
*state
)
1641 if (state
->monitor
== NULL
)
1644 device_remove_file(&of_dev
->dev
, &dev_attr_slots_temperature
);
1645 device_remove_file(&of_dev
->dev
, &dev_attr_slots_fan_pwm
);
1647 state
->monitor
= NULL
;
1651 static int call_critical_overtemp(void)
1653 char *argv
[] = { critical_overtemp_path
, NULL
};
1654 static char *envp
[] = { "HOME=/",
1656 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
1659 return call_usermodehelper(critical_overtemp_path
,
1660 argv
, envp
, UMH_WAIT_EXEC
);
1665 * Here's the kernel thread that calls the various control loops
1667 static int main_control_loop(void *x
)
1669 DBG("main_control_loop started\n");
1671 mutex_lock(&driver_lock
);
1673 if (start_fcu() < 0) {
1674 printk(KERN_ERR
"kfand: failed to start FCU\n");
1675 mutex_unlock(&driver_lock
);
1679 /* Set the PCI fan once for now on non-RackMac */
1681 set_pwm_fan(SLOTS_FAN_PWM_INDEX
, SLOTS_FAN_DEFAULT_PWM
);
1683 /* Initialize ADCs */
1684 initialize_adc(&cpu_state
[0]);
1685 if (cpu_state
[1].monitor
!= NULL
)
1686 initialize_adc(&cpu_state
[1]);
1688 fcu_tickle_ticks
= FCU_TICKLE_TICKS
;
1690 mutex_unlock(&driver_lock
);
1692 while (state
== state_attached
) {
1693 unsigned long elapsed
, start
;
1697 mutex_lock(&driver_lock
);
1699 /* Tickle the FCU just in case */
1700 if (--fcu_tickle_ticks
< 0) {
1701 fcu_tickle_ticks
= FCU_TICKLE_TICKS
;
1705 /* First, we always calculate the new DIMMs state on an Xserve */
1707 do_monitor_dimms(&dimms_state
);
1709 /* Then, the CPUs */
1710 if (cpu_pid_type
== CPU_PID_TYPE_COMBINED
)
1711 do_monitor_cpu_combined();
1712 else if (cpu_pid_type
== CPU_PID_TYPE_RACKMAC
) {
1713 do_monitor_cpu_rack(&cpu_state
[0]);
1714 if (cpu_state
[1].monitor
!= NULL
)
1715 do_monitor_cpu_rack(&cpu_state
[1]);
1716 // better deal with UP
1718 do_monitor_cpu_split(&cpu_state
[0]);
1719 if (cpu_state
[1].monitor
!= NULL
)
1720 do_monitor_cpu_split(&cpu_state
[1]);
1721 // better deal with UP
1723 /* Then, the rest */
1724 do_monitor_backside(&backside_state
);
1726 do_monitor_slots(&slots_state
);
1728 do_monitor_drives(&drives_state
);
1729 mutex_unlock(&driver_lock
);
1731 if (critical_state
== 1) {
1732 printk(KERN_WARNING
"Temperature control detected a critical condition\n");
1733 printk(KERN_WARNING
"Attempting to shut down...\n");
1734 if (call_critical_overtemp()) {
1735 printk(KERN_WARNING
"Can't call %s, power off now!\n",
1736 critical_overtemp_path
);
1737 machine_power_off();
1740 if (critical_state
> 0)
1742 if (critical_state
> MAX_CRITICAL_STATE
) {
1743 printk(KERN_WARNING
"Shutdown timed out, power off now !\n");
1744 machine_power_off();
1747 elapsed
= jiffies
- start
;
1749 schedule_timeout_interruptible(HZ
- elapsed
);
1753 DBG("main_control_loop ended\n");
1756 complete_and_exit(&ctrl_complete
, 0);
1760 * Dispose the control loops when tearing down
1762 static void dispose_control_loops(void)
1764 dispose_cpu_state(&cpu_state
[0]);
1765 dispose_cpu_state(&cpu_state
[1]);
1766 dispose_backside_state(&backside_state
);
1767 dispose_drives_state(&drives_state
);
1768 dispose_slots_state(&slots_state
);
1769 dispose_dimms_state(&dimms_state
);
1773 * Create the control loops. U3-0 i2c bus is up, so we can now
1774 * get to the various sensors
1776 static int create_control_loops(void)
1778 struct device_node
*np
;
1780 /* Count CPUs from the device-tree, we don't care how many are
1781 * actually used by Linux
1784 for (np
= NULL
; NULL
!= (np
= of_find_node_by_type(np
, "cpu"));)
1787 DBG("counted %d CPUs in the device-tree\n", cpu_count
);
1789 /* Decide the type of PID algorithm to use based on the presence of
1790 * the pumps, though that may not be the best way, that is good enough
1794 cpu_pid_type
= CPU_PID_TYPE_RACKMAC
;
1795 else if (of_machine_is_compatible("PowerMac7,3")
1797 && fcu_fans
[CPUA_PUMP_RPM_INDEX
].id
!= FCU_FAN_ABSENT_ID
1798 && fcu_fans
[CPUB_PUMP_RPM_INDEX
].id
!= FCU_FAN_ABSENT_ID
) {
1799 printk(KERN_INFO
"Liquid cooling pumps detected, using new algorithm !\n");
1800 cpu_pid_type
= CPU_PID_TYPE_COMBINED
;
1802 cpu_pid_type
= CPU_PID_TYPE_SPLIT
;
1804 /* Create control loops for everything. If any fail, everything
1807 if (init_cpu_state(&cpu_state
[0], 0))
1809 if (cpu_pid_type
== CPU_PID_TYPE_COMBINED
)
1810 fetch_cpu_pumps_minmax();
1812 if (cpu_count
> 1 && init_cpu_state(&cpu_state
[1], 1))
1814 if (init_backside_state(&backside_state
))
1816 if (rackmac
&& init_dimms_state(&dimms_state
))
1818 if (rackmac
&& init_slots_state(&slots_state
))
1820 if (!rackmac
&& init_drives_state(&drives_state
))
1823 DBG("all control loops up !\n");
1828 DBG("failure creating control loops, disposing\n");
1830 dispose_control_loops();
1836 * Start the control loops after everything is up, that is create
1837 * the thread that will make them run
1839 static void start_control_loops(void)
1841 init_completion(&ctrl_complete
);
1843 ctrl_task
= kthread_run(main_control_loop
, NULL
, "kfand");
1847 * Stop the control loops when tearing down
1849 static void stop_control_loops(void)
1852 wait_for_completion(&ctrl_complete
);
1856 * Attach to the i2c FCU after detecting U3-1 bus
1858 static int attach_fcu(void)
1860 fcu
= attach_i2c_chip(FAN_CTRLER_ID
, "fcu");
1864 DBG("FCU attached\n");
1870 * Detach from the i2c FCU when tearing down
1872 static void detach_fcu(void)
1878 * Attach to the i2c controller. We probe the various chips based
1879 * on the device-tree nodes and build everything for the driver to
1880 * run, we then kick the driver monitoring thread
1882 static int therm_pm72_attach(struct i2c_adapter
*adapter
)
1884 mutex_lock(&driver_lock
);
1887 if (state
== state_detached
)
1888 state
= state_attaching
;
1889 if (state
!= state_attaching
) {
1890 mutex_unlock(&driver_lock
);
1894 /* Check if we are looking for one of these */
1895 if (u3_0
== NULL
&& !strcmp(adapter
->name
, "u3 0")) {
1897 DBG("found U3-0\n");
1899 if (create_control_loops())
1901 } else if (u3_1
== NULL
&& !strcmp(adapter
->name
, "u3 1")) {
1903 DBG("found U3-1, attaching FCU\n");
1906 } else if (k2
== NULL
&& !strcmp(adapter
->name
, "mac-io 0")) {
1909 if (u3_0
&& rackmac
)
1910 if (create_control_loops())
1913 /* We got all we need, start control loops */
1914 if (u3_0
!= NULL
&& u3_1
!= NULL
&& (k2
|| !rackmac
)) {
1915 DBG("everything up, starting control loops\n");
1916 state
= state_attached
;
1917 start_control_loops();
1919 mutex_unlock(&driver_lock
);
1924 static int therm_pm72_probe(struct i2c_client
*client
,
1925 const struct i2c_device_id
*id
)
1927 /* Always succeed, the real work was done in therm_pm72_attach() */
1932 * Called when any of the devices which participates into thermal management
1935 static int therm_pm72_remove(struct i2c_client
*client
)
1937 struct i2c_adapter
*adapter
= client
->adapter
;
1939 mutex_lock(&driver_lock
);
1941 if (state
!= state_detached
)
1942 state
= state_detaching
;
1944 /* Stop control loops if any */
1945 DBG("stopping control loops\n");
1946 mutex_unlock(&driver_lock
);
1947 stop_control_loops();
1948 mutex_lock(&driver_lock
);
1950 if (u3_0
!= NULL
&& !strcmp(adapter
->name
, "u3 0")) {
1951 DBG("lost U3-0, disposing control loops\n");
1952 dispose_control_loops();
1956 if (u3_1
!= NULL
&& !strcmp(adapter
->name
, "u3 1")) {
1957 DBG("lost U3-1, detaching FCU\n");
1961 if (u3_0
== NULL
&& u3_1
== NULL
)
1962 state
= state_detached
;
1964 mutex_unlock(&driver_lock
);
1970 * i2c_driver structure to attach to the host i2c controller
1973 static const struct i2c_device_id therm_pm72_id
[] = {
1975 * Fake device name, thermal management is done by several
1976 * chips but we don't need to differentiate between them at
1979 { "therm_pm72", 0 },
1983 static struct i2c_driver therm_pm72_driver
= {
1985 .name
= "therm_pm72",
1987 .attach_adapter
= therm_pm72_attach
,
1988 .probe
= therm_pm72_probe
,
1989 .remove
= therm_pm72_remove
,
1990 .id_table
= therm_pm72_id
,
1993 static int fan_check_loc_match(const char *loc
, int fan
)
1998 strlcpy(tmp
, fcu_fans
[fan
].loc
, 64);
2005 if (strcmp(loc
, c
) == 0)
2014 static void fcu_lookup_fans(struct device_node
*fcu_node
)
2016 struct device_node
*np
= NULL
;
2019 /* The table is filled by default with values that are suitable
2020 * for the old machines without device-tree informations. We scan
2021 * the device-tree and override those values with whatever is
2025 DBG("Looking up FCU controls in device-tree...\n");
2027 while ((np
= of_get_next_child(fcu_node
, np
)) != NULL
) {
2032 DBG(" control: %s, type: %s\n", np
->name
, np
->type
);
2034 /* Detect control type */
2035 if (!strcmp(np
->type
, "fan-rpm-control") ||
2036 !strcmp(np
->type
, "fan-rpm"))
2038 if (!strcmp(np
->type
, "fan-pwm-control") ||
2039 !strcmp(np
->type
, "fan-pwm"))
2041 /* Only care about fans for now */
2045 /* Lookup for a matching location */
2046 loc
= of_get_property(np
, "location", NULL
);
2047 reg
= of_get_property(np
, "reg", NULL
);
2048 if (loc
== NULL
|| reg
== NULL
)
2050 DBG(" matching location: %s, reg: 0x%08x\n", loc
, *reg
);
2052 for (i
= 0; i
< FCU_FAN_COUNT
; i
++) {
2055 if (!fan_check_loc_match(loc
, i
))
2057 DBG(" location match, index: %d\n", i
);
2058 fcu_fans
[i
].id
= FCU_FAN_ABSENT_ID
;
2059 if (type
!= fcu_fans
[i
].type
) {
2060 printk(KERN_WARNING
"therm_pm72: Fan type mismatch "
2061 "in device-tree for %s\n", np
->full_name
);
2064 if (type
== FCU_FAN_RPM
)
2065 fan_id
= ((*reg
) - 0x10) / 2;
2067 fan_id
= ((*reg
) - 0x30) / 2;
2069 printk(KERN_WARNING
"therm_pm72: Can't parse "
2070 "fan ID in device-tree for %s\n", np
->full_name
);
2073 DBG(" fan id -> %d, type -> %d\n", fan_id
, type
);
2074 fcu_fans
[i
].id
= fan_id
;
2078 /* Now dump the array */
2079 printk(KERN_INFO
"Detected fan controls:\n");
2080 for (i
= 0; i
< FCU_FAN_COUNT
; i
++) {
2081 if (fcu_fans
[i
].id
== FCU_FAN_ABSENT_ID
)
2083 printk(KERN_INFO
" %d: %s fan, id %d, location: %s\n", i
,
2084 fcu_fans
[i
].type
== FCU_FAN_RPM
? "RPM" : "PWM",
2085 fcu_fans
[i
].id
, fcu_fans
[i
].loc
);
2089 static int fcu_of_probe(struct platform_device
* dev
, const struct of_device_id
*match
)
2091 state
= state_detached
;
2093 /* Lookup the fans in the device tree */
2094 fcu_lookup_fans(dev
->dev
.of_node
);
2096 /* Add the driver */
2097 return i2c_add_driver(&therm_pm72_driver
);
2100 static int fcu_of_remove(struct platform_device
* dev
)
2102 i2c_del_driver(&therm_pm72_driver
);
2107 static const struct of_device_id fcu_match
[] =
2115 static struct of_platform_driver fcu_of_platform_driver
=
2118 .name
= "temperature",
2119 .owner
= THIS_MODULE
,
2120 .of_match_table
= fcu_match
,
2122 .probe
= fcu_of_probe
,
2123 .remove
= fcu_of_remove
2127 * Check machine type, attach to i2c controller
2129 static int __init
therm_pm72_init(void)
2131 struct device_node
*np
;
2133 rackmac
= of_machine_is_compatible("RackMac3,1");
2135 if (!of_machine_is_compatible("PowerMac7,2") &&
2136 !of_machine_is_compatible("PowerMac7,3") &&
2140 printk(KERN_INFO
"PowerMac G5 Thermal control driver %s\n", VERSION
);
2142 np
= of_find_node_by_type(NULL
, "fcu");
2144 /* Some machines have strangely broken device-tree */
2145 np
= of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");
2147 printk(KERN_ERR
"Can't find FCU in device-tree !\n");
2151 of_dev
= of_platform_device_create(np
, "temperature", NULL
);
2152 if (of_dev
== NULL
) {
2153 printk(KERN_ERR
"Can't register FCU platform device !\n");
2157 of_register_platform_driver(&fcu_of_platform_driver
);
2162 static void __exit
therm_pm72_exit(void)
2164 of_unregister_platform_driver(&fcu_of_platform_driver
);
2167 of_device_unregister(of_dev
);
2170 module_init(therm_pm72_init
);
2171 module_exit(therm_pm72_exit
);
2173 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
2174 MODULE_DESCRIPTION("Driver for Apple's PowerMac G5 thermal control");
2175 MODULE_LICENSE("GPL");