10 #include <linux/types.h>
11 #include <linux/errno.h>
12 #include <linux/kernel.h>
13 #include <linux/device.h>
15 #include <linux/reboot.h>
28 #define DBG(args...) printk(args)
30 #define DBG(args...) do { } while(0)
34 #define DBG_LOTS(args...) printk(args)
36 #define DBG_LOTS(args...) do { } while(0)
42 #undef HACKED_OVERTEMP
47 #define NR_CPU_FANS 3 * NR_CHIPS
68 #define CPU_FANS_REQD (NR_CPU_FANS - 2)
73 #define CPU_TEMP_HIST_SIZE 180
92 static int cpu_thist_pt;
93 static s64 cpu_thist_total;
94 static s32 cpu_all_tmax = 100 << 16;
95 static int cpu_last_target;
97 static int backside_tick;
99 static int slots_started;
101 static int drive_bay_tick;
104 static int have_all_controls;
105 static int have_all_sensors;
108 static int failure_state;
109 #define FAILURE_SENSOR 1
110 #define FAILURE_FAN 2
111 #define FAILURE_PERM 4
112 #define FAILURE_LOW_OVERTEMP 8
113 #define FAILURE_HIGH_OVERTEMP 16
116 #define LOW_OVER_AVERAGE 0
117 #define LOW_OVER_IMMEDIATE (10 << 16)
118 #define LOW_OVER_CLEAR ((-10) << 16)
119 #define HIGH_OVER_IMMEDIATE (14 << 16)
120 #define HIGH_OVER_AVERAGE (10 << 16)
121 #define HIGH_OVER_IMMEDIATE (14 << 16)
125 static int create_cpu_loop(
int cpu)
153 if (tmax < cpu_all_tmax)
161 fmin = (nr_cores > 2) ? 750 : 515;
166 pid.
gd = piddata->
gd;
167 pid.
gp = piddata->
gp;
172 pid.
min = main_fan->
ops->get_min(main_fan);
173 pid.
max = main_fan->
ops->get_max(main_fan);
181 static void cpu_max_all_fans(
void)
190 wf_control_set_max(cpufreq_clamp);
193 wf_control_set_max(cpu_fans[i]);
196 static int cpu_check_overtemp(
s32 temp)
212 " immediate CPU temperature !\n");
218 t_old = cpu_thist[cpu_thist_pt];
219 cpu_thist[cpu_thist_pt] =
temp;
221 cpu_thist_total -= t_old;
222 cpu_thist_total +=
temp;
225 DBG_LOTS(
"t_avg = %d.%03d (out: %d.%03d, in: %d.%03d)\n",
239 " average CPU temperature !\n");
250 if ((failure_state & new_state) != new_state)
256 failure_state &= ~FAILURE_LOW_OVERTEMP;
262 static void cpu_fans_tick(
void)
265 s32 greatest_delta = 0;
273 for (cpu = 0; cpu < nr_cores; ++
cpu) {
275 sr = sens_cpu_temp[
cpu];
276 err = sr->
ops->get_value(sr, &temp);
280 "sensor error %d\n", cpu, err);
287 t_max =
max(t_max, temp);
290 sr = sens_cpu_power[
cpu];
291 err = sr->
ops->get_value(sr, &power);
295 "sensor error %d\n", cpu, err);
305 if (cpu == 0 || sp->
last_delta > greatest_delta) {
309 DBG_LOTS(
"[%d] P=%d.%.3d T=%d.%.3d ",
315 if (target < (cpu_last_target - 20))
316 target = cpu_last_target - 20;
318 for (cpu = 0; cpu < nr_cores; ++
cpu)
319 cpu_pid[cpu].target = target;
322 if (cpu_check_overtemp(t_max))
330 err = ct->
ops->set_value(ct, target * cpu_fan_scale[i] / 100);
333 "error %d\n", ct->
name, err);
351 static void backside_fan_tick(
void)
357 if (!backside_fan || !u4_temp)
359 if (!backside_tick) {
362 backside_param.
min = backside_fan->
ops->get_min(backside_fan);
363 backside_param.
max = backside_fan->
ops->get_max(backside_fan);
367 if (--backside_tick > 0)
369 backside_tick = backside_pid.param.interval;
371 err = u4_temp->
ops->get_value(u4_temp, &temp);
376 wf_control_set_max(backside_fan);
380 DBG_LOTS(
"backside PID temp=%d.%.3d speed=%d\n",
383 err = backside_fan->
ops->set_value(backside_fan, speed);
401 static void drive_bay_fan_tick(
void)
407 if (!drive_bay_fan || !hd_temp)
409 if (!drive_bay_tick) {
412 drive_bay_prm.
min = drive_bay_fan->
ops->get_min(drive_bay_fan);
413 drive_bay_prm.
max = drive_bay_fan->
ops->get_max(drive_bay_fan);
417 if (--drive_bay_tick > 0)
419 drive_bay_tick = drive_bay_pid.param.interval;
421 err = hd_temp->
ops->get_value(hd_temp, &temp);
426 wf_control_set_max(drive_bay_fan);
430 DBG_LOTS(
"drive_bay PID temp=%d.%.3d speed=%d\n",
433 err = drive_bay_fan->
ops->set_value(drive_bay_fan, speed);
453 static void slots_fan_tick(
void)
459 if (!slots_fan || !slots_power)
461 if (!slots_started) {
468 err = slots_power->
ops->get_value(slots_power, &power);
473 wf_control_set_max(slots_fan);
477 DBG_LOTS(
"slots PID power=%d.%.3d speed=%d\n",
480 err = slots_fan->
ops->set_value(slots_fan, speed);
487 static void set_fail_state(
void)
492 wf_control_set_max(cpufreq_clamp);
495 wf_control_set_max(cpu_fans[i]);
497 wf_control_set_max(backside_fan);
499 wf_control_set_max(slots_fan);
501 wf_control_set_max(drive_bay_fan);
504 static void pm112_tick(
void)
511 for (i = 0; i < nr_cores; ++
i) {
512 if (create_cpu_loop(i) < 0) {
520 #ifdef HACKED_OVERTEMP
521 cpu_all_tmax = 60 << 16;
531 last_failure = failure_state;
536 drive_bay_fan_tick();
538 DBG_LOTS(
"last_failure: 0x%x, failure_state: %x\n",
539 last_failure, failure_state);
542 if (failure_state && last_failure == 0 && cpufreq_clamp)
543 wf_control_set_max(cpufreq_clamp);
544 if (failure_state == 0 && last_failure && cpufreq_clamp)
545 wf_control_set_min(cpufreq_clamp);
552 static void pm112_new_control(
struct wf_control *ct)
556 if (cpufreq_clamp ==
NULL && !
strcmp(ct->
name,
"cpufreq-clamp")) {
568 if (i >= NR_CPU_FANS) {
576 }
else if (!
strcmp(ct->
name,
"drive-bay-fan")) {
584 if (cpu_fans[i] ==
NULL)
588 max_exhaust = cpu_fans[0]->
ops->get_max(cpu_fans[0]);
590 if ((ct = cpu_fans[i]) !=
NULL)
592 ct->
ops->get_max(ct) * 100 / max_exhaust;
594 have_all_controls = 1;
597 static void pm112_new_sensor(
struct wf_sensor *sr)
602 i = sr->
name[9] -
'0';
605 sens_cpu_temp[
i] =
sr;
608 i = sr->
name[10] -
'0';
611 sens_cpu_power[
i] =
sr;
615 }
else if (!
strcmp(sr->
name,
"slots-power")) {
618 }
else if (!
strcmp(sr->
name,
"backside-temp")) {
625 for (i = 0; i < nr_cores; ++
i)
626 if (sens_cpu_temp[i] ==
NULL || sens_cpu_power[i] ==
NULL)
629 have_all_sensors = 1;
637 pm112_new_sensor(data);
640 pm112_new_control(data);
643 if (have_all_controls && have_all_sensors)
650 .notifier_call = pm112_wf_notify,
667 .probe = wf_pm112_probe,
675 static int __init wf_pm112_init(
void)
690 request_module(
"windfarm_smu_controls");
691 request_module(
"windfarm_smu_sensors");
692 request_module(
"windfarm_smu_sat");
693 request_module(
"windfarm_lm75_sensor");
694 request_module(
"windfarm_max6690_sensor");
695 request_module(
"windfarm_cpufreq_clamp");
703 static void __exit wf_pm112_exit(
void)