Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Windfarm PowerMac thermal control.
0004  * Control loops for RackMack3,1 (Xserve G5)
0005  *
0006  * Copyright (C) 2012 Benjamin Herrenschmidt, IBM Corp.
0007  */
0008 #include <linux/types.h>
0009 #include <linux/errno.h>
0010 #include <linux/kernel.h>
0011 #include <linux/device.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/reboot.h>
0014 
0015 #include <asm/smu.h>
0016 
0017 #include "windfarm.h"
0018 #include "windfarm_pid.h"
0019 #include "windfarm_mpu.h"
0020 
0021 #define VERSION "1.0"
0022 
0023 #undef DEBUG
0024 #undef LOTSA_DEBUG
0025 
0026 #ifdef DEBUG
0027 #define DBG(args...)    printk(args)
0028 #else
0029 #define DBG(args...)    do { } while(0)
0030 #endif
0031 
0032 #ifdef LOTSA_DEBUG
0033 #define DBG_LOTS(args...)   printk(args)
0034 #else
0035 #define DBG_LOTS(args...)   do { } while(0)
0036 #endif
0037 
0038 /* define this to force CPU overtemp to 60 degree, useful for testing
0039  * the overtemp code
0040  */
0041 #undef HACKED_OVERTEMP
0042 
0043 /* We currently only handle 2 chips */
0044 #define NR_CHIPS    2
0045 #define NR_CPU_FANS 3 * NR_CHIPS
0046 
0047 /* Controls and sensors */
0048 static struct wf_sensor *sens_cpu_temp[NR_CHIPS];
0049 static struct wf_sensor *sens_cpu_volts[NR_CHIPS];
0050 static struct wf_sensor *sens_cpu_amps[NR_CHIPS];
0051 static struct wf_sensor *backside_temp;
0052 static struct wf_sensor *slots_temp;
0053 static struct wf_sensor *dimms_temp;
0054 
0055 static struct wf_control *cpu_fans[NR_CHIPS][3];
0056 static struct wf_control *backside_fan;
0057 static struct wf_control *slots_fan;
0058 static struct wf_control *cpufreq_clamp;
0059 
0060 /* We keep a temperature history for average calculation of 180s */
0061 #define CPU_TEMP_HIST_SIZE  180
0062 
0063 /* PID loop state */
0064 static const struct mpu_data *cpu_mpu_data[NR_CHIPS];
0065 static struct wf_cpu_pid_state cpu_pid[NR_CHIPS];
0066 static u32 cpu_thist[CPU_TEMP_HIST_SIZE];
0067 static int cpu_thist_pt;
0068 static s64 cpu_thist_total;
0069 static s32 cpu_all_tmax = 100 << 16;
0070 static struct wf_pid_state backside_pid;
0071 static int backside_tick;
0072 static struct wf_pid_state slots_pid;
0073 static int slots_tick;
0074 static int slots_speed;
0075 static struct wf_pid_state dimms_pid;
0076 static int dimms_output_clamp;
0077 
0078 static int nr_chips;
0079 static bool have_all_controls;
0080 static bool have_all_sensors;
0081 static bool started;
0082 
0083 static int failure_state;
0084 #define FAILURE_SENSOR      1
0085 #define FAILURE_FAN     2
0086 #define FAILURE_PERM        4
0087 #define FAILURE_LOW_OVERTEMP    8
0088 #define FAILURE_HIGH_OVERTEMP   16
0089 
0090 /* Overtemp values */
0091 #define LOW_OVER_AVERAGE    0
0092 #define LOW_OVER_IMMEDIATE  (10 << 16)
0093 #define LOW_OVER_CLEAR      ((-10) << 16)
0094 #define HIGH_OVER_IMMEDIATE (14 << 16)
0095 #define HIGH_OVER_AVERAGE   (10 << 16)
0096 #define HIGH_OVER_IMMEDIATE (14 << 16)
0097 
0098 
0099 static void cpu_max_all_fans(void)
0100 {
0101     int i;
0102 
0103     /* We max all CPU fans in case of a sensor error. We also do the
0104      * cpufreq clamping now, even if it's supposedly done later by the
0105      * generic code anyway, we do it earlier here to react faster
0106      */
0107     if (cpufreq_clamp)
0108         wf_control_set_max(cpufreq_clamp);
0109     for (i = 0; i < nr_chips; i++) {
0110         if (cpu_fans[i][0])
0111             wf_control_set_max(cpu_fans[i][0]);
0112         if (cpu_fans[i][1])
0113             wf_control_set_max(cpu_fans[i][1]);
0114         if (cpu_fans[i][2])
0115             wf_control_set_max(cpu_fans[i][2]);
0116     }
0117 }
0118 
0119 static int cpu_check_overtemp(s32 temp)
0120 {
0121     int new_state = 0;
0122     s32 t_avg, t_old;
0123     static bool first = true;
0124 
0125     /* First check for immediate overtemps */
0126     if (temp >= (cpu_all_tmax + LOW_OVER_IMMEDIATE)) {
0127         new_state |= FAILURE_LOW_OVERTEMP;
0128         if ((failure_state & FAILURE_LOW_OVERTEMP) == 0)
0129             printk(KERN_ERR "windfarm: Overtemp due to immediate CPU"
0130                    " temperature !\n");
0131     }
0132     if (temp >= (cpu_all_tmax + HIGH_OVER_IMMEDIATE)) {
0133         new_state |= FAILURE_HIGH_OVERTEMP;
0134         if ((failure_state & FAILURE_HIGH_OVERTEMP) == 0)
0135             printk(KERN_ERR "windfarm: Critical overtemp due to"
0136                    " immediate CPU temperature !\n");
0137     }
0138 
0139     /*
0140      * The first time around, initialize the array with the first
0141      * temperature reading
0142      */
0143     if (first) {
0144         int i;
0145 
0146         cpu_thist_total = 0;
0147         for (i = 0; i < CPU_TEMP_HIST_SIZE; i++) {
0148             cpu_thist[i] = temp;
0149             cpu_thist_total += temp;
0150         }
0151         first = false;
0152     }
0153 
0154     /*
0155      * We calculate a history of max temperatures and use that for the
0156      * overtemp management
0157      */
0158     t_old = cpu_thist[cpu_thist_pt];
0159     cpu_thist[cpu_thist_pt] = temp;
0160     cpu_thist_pt = (cpu_thist_pt + 1) % CPU_TEMP_HIST_SIZE;
0161     cpu_thist_total -= t_old;
0162     cpu_thist_total += temp;
0163     t_avg = cpu_thist_total / CPU_TEMP_HIST_SIZE;
0164 
0165     DBG_LOTS("  t_avg = %d.%03d (out: %d.%03d, in: %d.%03d)\n",
0166          FIX32TOPRINT(t_avg), FIX32TOPRINT(t_old), FIX32TOPRINT(temp));
0167 
0168     /* Now check for average overtemps */
0169     if (t_avg >= (cpu_all_tmax + LOW_OVER_AVERAGE)) {
0170         new_state |= FAILURE_LOW_OVERTEMP;
0171         if ((failure_state & FAILURE_LOW_OVERTEMP) == 0)
0172             printk(KERN_ERR "windfarm: Overtemp due to average CPU"
0173                    " temperature !\n");
0174     }
0175     if (t_avg >= (cpu_all_tmax + HIGH_OVER_AVERAGE)) {
0176         new_state |= FAILURE_HIGH_OVERTEMP;
0177         if ((failure_state & FAILURE_HIGH_OVERTEMP) == 0)
0178             printk(KERN_ERR "windfarm: Critical overtemp due to"
0179                    " average CPU temperature !\n");
0180     }
0181 
0182     /* Now handle overtemp conditions. We don't currently use the windfarm
0183      * overtemp handling core as it's not fully suited to the needs of those
0184      * new machine. This will be fixed later.
0185      */
0186     if (new_state) {
0187         /* High overtemp -> immediate shutdown */
0188         if (new_state & FAILURE_HIGH_OVERTEMP)
0189             machine_power_off();
0190         if ((failure_state & new_state) != new_state)
0191             cpu_max_all_fans();
0192         failure_state |= new_state;
0193     } else if ((failure_state & FAILURE_LOW_OVERTEMP) &&
0194            (temp < (cpu_all_tmax + LOW_OVER_CLEAR))) {
0195         printk(KERN_ERR "windfarm: Overtemp condition cleared !\n");
0196         failure_state &= ~FAILURE_LOW_OVERTEMP;
0197     }
0198 
0199     return failure_state & (FAILURE_LOW_OVERTEMP | FAILURE_HIGH_OVERTEMP);
0200 }
0201 
0202 static int read_one_cpu_vals(int cpu, s32 *temp, s32 *power)
0203 {
0204     s32 dtemp, volts, amps;
0205     int rc;
0206 
0207     /* Get diode temperature */
0208     rc = wf_sensor_get(sens_cpu_temp[cpu], &dtemp);
0209     if (rc) {
0210         DBG("  CPU%d: temp reading error !\n", cpu);
0211         return -EIO;
0212     }
0213     DBG_LOTS("  CPU%d: temp   = %d.%03d\n", cpu, FIX32TOPRINT((dtemp)));
0214     *temp = dtemp;
0215 
0216     /* Get voltage */
0217     rc = wf_sensor_get(sens_cpu_volts[cpu], &volts);
0218     if (rc) {
0219         DBG("  CPU%d, volts reading error !\n", cpu);
0220         return -EIO;
0221     }
0222     DBG_LOTS("  CPU%d: volts  = %d.%03d\n", cpu, FIX32TOPRINT((volts)));
0223 
0224     /* Get current */
0225     rc = wf_sensor_get(sens_cpu_amps[cpu], &amps);
0226     if (rc) {
0227         DBG("  CPU%d, current reading error !\n", cpu);
0228         return -EIO;
0229     }
0230     DBG_LOTS("  CPU%d: amps   = %d.%03d\n", cpu, FIX32TOPRINT((amps)));
0231 
0232     /* Calculate power */
0233 
0234     /* Scale voltage and current raw sensor values according to fixed scales
0235      * obtained in Darwin and calculate power from I and V
0236      */
0237     *power = (((u64)volts) * ((u64)amps)) >> 16;
0238 
0239     DBG_LOTS("  CPU%d: power  = %d.%03d\n", cpu, FIX32TOPRINT((*power)));
0240 
0241     return 0;
0242 
0243 }
0244 
0245 static void cpu_fans_tick(void)
0246 {
0247     int err, cpu, i;
0248     s32 speed, temp, power, t_max = 0;
0249 
0250     DBG_LOTS("* cpu fans_tick_split()\n");
0251 
0252     for (cpu = 0; cpu < nr_chips; ++cpu) {
0253         struct wf_cpu_pid_state *sp = &cpu_pid[cpu];
0254 
0255         /* Read current speed */
0256         wf_control_get(cpu_fans[cpu][0], &sp->target);
0257 
0258         err = read_one_cpu_vals(cpu, &temp, &power);
0259         if (err) {
0260             failure_state |= FAILURE_SENSOR;
0261             cpu_max_all_fans();
0262             return;
0263         }
0264 
0265         /* Keep track of highest temp */
0266         t_max = max(t_max, temp);
0267 
0268         /* Handle possible overtemps */
0269         if (cpu_check_overtemp(t_max))
0270             return;
0271 
0272         /* Run PID */
0273         wf_cpu_pid_run(sp, power, temp);
0274 
0275         DBG_LOTS("  CPU%d: target = %d RPM\n", cpu, sp->target);
0276 
0277         /* Apply DIMMs clamp */
0278         speed = max(sp->target, dimms_output_clamp);
0279 
0280         /* Apply result to all cpu fans */
0281         for (i = 0; i < 3; i++) {
0282             err = wf_control_set(cpu_fans[cpu][i], speed);
0283             if (err) {
0284                 pr_warn("wf_rm31: Fan %s reports error %d\n",
0285                     cpu_fans[cpu][i]->name, err);
0286                 failure_state |= FAILURE_FAN;
0287             }
0288         }
0289     }
0290 }
0291 
0292 /* Implementation... */
0293 static int cpu_setup_pid(int cpu)
0294 {
0295     struct wf_cpu_pid_param pid;
0296     const struct mpu_data *mpu = cpu_mpu_data[cpu];
0297     s32 tmax, ttarget, ptarget;
0298     int fmin, fmax, hsize;
0299 
0300     /* Get PID params from the appropriate MPU EEPROM */
0301     tmax = mpu->tmax << 16;
0302     ttarget = mpu->ttarget << 16;
0303     ptarget = ((s32)(mpu->pmaxh - mpu->padjmax)) << 16;
0304 
0305     DBG("wf_72: CPU%d ttarget = %d.%03d, tmax = %d.%03d\n",
0306         cpu, FIX32TOPRINT(ttarget), FIX32TOPRINT(tmax));
0307 
0308     /* We keep a global tmax for overtemp calculations */
0309     if (tmax < cpu_all_tmax)
0310         cpu_all_tmax = tmax;
0311 
0312     /* Set PID min/max by using the rear fan min/max */
0313     fmin = wf_control_get_min(cpu_fans[cpu][0]);
0314     fmax = wf_control_get_max(cpu_fans[cpu][0]);
0315     DBG("wf_72: CPU%d max RPM range = [%d..%d]\n", cpu, fmin, fmax);
0316 
0317     /* History size */
0318     hsize = min_t(int, mpu->tguardband, WF_PID_MAX_HISTORY);
0319     DBG("wf_72: CPU%d history size = %d\n", cpu, hsize);
0320 
0321     /* Initialize PID loop */
0322     pid.interval    = 1;    /* seconds */
0323     pid.history_len = hsize;
0324     pid.gd      = mpu->pid_gd;
0325     pid.gp      = mpu->pid_gp;
0326     pid.gr      = mpu->pid_gr;
0327     pid.tmax    = tmax;
0328     pid.ttarget = ttarget;
0329     pid.pmaxadj = ptarget;
0330     pid.min     = fmin;
0331     pid.max     = fmax;
0332 
0333     wf_cpu_pid_init(&cpu_pid[cpu], &pid);
0334     cpu_pid[cpu].target = 4000;
0335     
0336     return 0;
0337 }
0338 
0339 /* Backside/U3 fan */
0340 static const struct wf_pid_param backside_param = {
0341     .interval   = 1,
0342     .history_len    = 2,
0343     .gd     = 0x00500000,
0344     .gp     = 0x0004cccc,
0345     .gr     = 0,
0346     .itarget    = 70 << 16,
0347     .additive   = 0,
0348     .min        = 20,
0349     .max        = 100,
0350 };
0351 
0352 /* DIMMs temperature (clamp the backside fan) */
0353 static const struct wf_pid_param dimms_param = {
0354     .interval   = 1,
0355     .history_len    = 20,
0356     .gd     = 0,
0357     .gp     = 0,
0358     .gr     = 0x06553600,
0359     .itarget    = 50 << 16,
0360     .additive   = 0,
0361     .min        = 4000,
0362     .max        = 14000,
0363 };
0364 
0365 static void backside_fan_tick(void)
0366 {
0367     s32 temp, dtemp;
0368     int speed, dspeed, fan_min;
0369     int err;
0370 
0371     if (!backside_fan || !backside_temp || !dimms_temp || !backside_tick)
0372         return;
0373     if (--backside_tick > 0)
0374         return;
0375     backside_tick = backside_pid.param.interval;
0376 
0377     DBG_LOTS("* backside fans tick\n");
0378 
0379     /* Update fan speed from actual fans */
0380     err = wf_control_get(backside_fan, &speed);
0381     if (!err)
0382         backside_pid.target = speed;
0383 
0384     err = wf_sensor_get(backside_temp, &temp);
0385     if (err) {
0386         printk(KERN_WARNING "windfarm: U3 temp sensor error %d\n",
0387                err);
0388         failure_state |= FAILURE_SENSOR;
0389         wf_control_set_max(backside_fan);
0390         return;
0391     }
0392     speed = wf_pid_run(&backside_pid, temp);
0393 
0394     DBG_LOTS("backside PID temp=%d.%.3d speed=%d\n",
0395          FIX32TOPRINT(temp), speed);
0396 
0397     err = wf_sensor_get(dimms_temp, &dtemp);
0398     if (err) {
0399         printk(KERN_WARNING "windfarm: DIMMs temp sensor error %d\n",
0400                err);
0401         failure_state |= FAILURE_SENSOR;
0402         wf_control_set_max(backside_fan);
0403         return;
0404     }
0405     dspeed = wf_pid_run(&dimms_pid, dtemp);
0406     dimms_output_clamp = dspeed;
0407 
0408     fan_min = (dspeed * 100) / 14000;
0409     fan_min = max(fan_min, backside_param.min);
0410     speed = max(speed, fan_min);
0411 
0412     err = wf_control_set(backside_fan, speed);
0413     if (err) {
0414         printk(KERN_WARNING "windfarm: backside fan error %d\n", err);
0415         failure_state |= FAILURE_FAN;
0416     }
0417 }
0418 
0419 static void backside_setup_pid(void)
0420 {
0421     /* first time initialize things */
0422     s32 fmin = wf_control_get_min(backside_fan);
0423     s32 fmax = wf_control_get_max(backside_fan);
0424     struct wf_pid_param param;
0425 
0426     param = backside_param;
0427     param.min = max(param.min, fmin);
0428     param.max = min(param.max, fmax);
0429     wf_pid_init(&backside_pid, &param);
0430 
0431     param = dimms_param;
0432     wf_pid_init(&dimms_pid, &param);
0433 
0434     backside_tick = 1;
0435 
0436     pr_info("wf_rm31: Backside control loop started.\n");
0437 }
0438 
0439 /* Slots fan */
0440 static const struct wf_pid_param slots_param = {
0441     .interval   = 1,
0442     .history_len    = 20,
0443     .gd     = 0,
0444     .gp     = 0,
0445     .gr     = 0x00100000,
0446     .itarget    = 3200000,
0447     .additive   = 0,
0448     .min        = 20,
0449     .max        = 100,
0450 };
0451 
0452 static void slots_fan_tick(void)
0453 {
0454     s32 temp;
0455     int speed;
0456     int err;
0457 
0458     if (!slots_fan || !slots_temp || !slots_tick)
0459         return;
0460     if (--slots_tick > 0)
0461         return;
0462     slots_tick = slots_pid.param.interval;
0463 
0464     DBG_LOTS("* slots fans tick\n");
0465 
0466     err = wf_sensor_get(slots_temp, &temp);
0467     if (err) {
0468         pr_warn("wf_rm31: slots temp sensor error %d\n", err);
0469         failure_state |= FAILURE_SENSOR;
0470         wf_control_set_max(slots_fan);
0471         return;
0472     }
0473     speed = wf_pid_run(&slots_pid, temp);
0474 
0475     DBG_LOTS("slots PID temp=%d.%.3d speed=%d\n",
0476          FIX32TOPRINT(temp), speed);
0477 
0478     slots_speed = speed;
0479     err = wf_control_set(slots_fan, speed);
0480     if (err) {
0481         printk(KERN_WARNING "windfarm: slots bay fan error %d\n", err);
0482         failure_state |= FAILURE_FAN;
0483     }
0484 }
0485 
0486 static void slots_setup_pid(void)
0487 {
0488     /* first time initialize things */
0489     s32 fmin = wf_control_get_min(slots_fan);
0490     s32 fmax = wf_control_get_max(slots_fan);
0491     struct wf_pid_param param = slots_param;
0492 
0493     param.min = max(param.min, fmin);
0494     param.max = min(param.max, fmax);
0495     wf_pid_init(&slots_pid, &param);
0496     slots_tick = 1;
0497 
0498     pr_info("wf_rm31: Slots control loop started.\n");
0499 }
0500 
0501 static void set_fail_state(void)
0502 {
0503     cpu_max_all_fans();
0504 
0505     if (backside_fan)
0506         wf_control_set_max(backside_fan);
0507     if (slots_fan)
0508         wf_control_set_max(slots_fan);
0509 }
0510 
0511 static void rm31_tick(void)
0512 {
0513     int i, last_failure;
0514 
0515     if (!started) {
0516         started = true;
0517         printk(KERN_INFO "windfarm: CPUs control loops started.\n");
0518         for (i = 0; i < nr_chips; ++i) {
0519             if (cpu_setup_pid(i) < 0) {
0520                 failure_state = FAILURE_PERM;
0521                 set_fail_state();
0522                 break;
0523             }
0524         }
0525         DBG_LOTS("cpu_all_tmax=%d.%03d\n", FIX32TOPRINT(cpu_all_tmax));
0526 
0527         backside_setup_pid();
0528         slots_setup_pid();
0529 
0530 #ifdef HACKED_OVERTEMP
0531         cpu_all_tmax = 60 << 16;
0532 #endif
0533     }
0534 
0535     /* Permanent failure, bail out */
0536     if (failure_state & FAILURE_PERM)
0537         return;
0538 
0539     /*
0540      * Clear all failure bits except low overtemp which will be eventually
0541      * cleared by the control loop itself
0542      */
0543     last_failure = failure_state;
0544     failure_state &= FAILURE_LOW_OVERTEMP;
0545     backside_fan_tick();
0546     slots_fan_tick();
0547 
0548     /* We do CPUs last because they can be clamped high by
0549      * DIMM temperature
0550      */
0551     cpu_fans_tick();
0552 
0553     DBG_LOTS("  last_failure: 0x%x, failure_state: %x\n",
0554          last_failure, failure_state);
0555 
0556     /* Check for failures. Any failure causes cpufreq clamping */
0557     if (failure_state && last_failure == 0 && cpufreq_clamp)
0558         wf_control_set_max(cpufreq_clamp);
0559     if (failure_state == 0 && last_failure && cpufreq_clamp)
0560         wf_control_set_min(cpufreq_clamp);
0561 
0562     /* That's it for now, we might want to deal with other failures
0563      * differently in the future though
0564      */
0565 }
0566 
0567 static void rm31_new_control(struct wf_control *ct)
0568 {
0569     bool all_controls;
0570 
0571     if (!strcmp(ct->name, "cpu-fan-a-0"))
0572         cpu_fans[0][0] = ct;
0573     else if (!strcmp(ct->name, "cpu-fan-b-0"))
0574         cpu_fans[0][1] = ct;
0575     else if (!strcmp(ct->name, "cpu-fan-c-0"))
0576         cpu_fans[0][2] = ct;
0577     else if (!strcmp(ct->name, "cpu-fan-a-1"))
0578         cpu_fans[1][0] = ct;
0579     else if (!strcmp(ct->name, "cpu-fan-b-1"))
0580         cpu_fans[1][1] = ct;
0581     else if (!strcmp(ct->name, "cpu-fan-c-1"))
0582         cpu_fans[1][2] = ct;
0583     else if (!strcmp(ct->name, "backside-fan"))
0584         backside_fan = ct;
0585     else if (!strcmp(ct->name, "slots-fan"))
0586         slots_fan = ct;
0587     else if (!strcmp(ct->name, "cpufreq-clamp"))
0588         cpufreq_clamp = ct;
0589 
0590     all_controls =
0591         cpu_fans[0][0] &&
0592         cpu_fans[0][1] &&
0593         cpu_fans[0][2] &&
0594         backside_fan &&
0595         slots_fan;
0596     if (nr_chips > 1)
0597         all_controls &=
0598             cpu_fans[1][0] &&
0599             cpu_fans[1][1] &&
0600             cpu_fans[1][2];
0601     have_all_controls = all_controls;
0602 }
0603 
0604 
0605 static void rm31_new_sensor(struct wf_sensor *sr)
0606 {
0607     bool all_sensors;
0608 
0609     if (!strcmp(sr->name, "cpu-diode-temp-0"))
0610         sens_cpu_temp[0] = sr;
0611     else if (!strcmp(sr->name, "cpu-diode-temp-1"))
0612         sens_cpu_temp[1] = sr;
0613     else if (!strcmp(sr->name, "cpu-voltage-0"))
0614         sens_cpu_volts[0] = sr;
0615     else if (!strcmp(sr->name, "cpu-voltage-1"))
0616         sens_cpu_volts[1] = sr;
0617     else if (!strcmp(sr->name, "cpu-current-0"))
0618         sens_cpu_amps[0] = sr;
0619     else if (!strcmp(sr->name, "cpu-current-1"))
0620         sens_cpu_amps[1] = sr;
0621     else if (!strcmp(sr->name, "backside-temp"))
0622         backside_temp = sr;
0623     else if (!strcmp(sr->name, "slots-temp"))
0624         slots_temp = sr;
0625     else if (!strcmp(sr->name, "dimms-temp"))
0626         dimms_temp = sr;
0627 
0628     all_sensors =
0629         sens_cpu_temp[0] &&
0630         sens_cpu_volts[0] &&
0631         sens_cpu_amps[0] &&
0632         backside_temp &&
0633         slots_temp &&
0634         dimms_temp;
0635     if (nr_chips > 1)
0636         all_sensors &=
0637             sens_cpu_temp[1] &&
0638             sens_cpu_volts[1] &&
0639             sens_cpu_amps[1];
0640 
0641     have_all_sensors = all_sensors;
0642 }
0643 
0644 static int rm31_wf_notify(struct notifier_block *self,
0645               unsigned long event, void *data)
0646 {
0647     switch (event) {
0648     case WF_EVENT_NEW_SENSOR:
0649         rm31_new_sensor(data);
0650         break;
0651     case WF_EVENT_NEW_CONTROL:
0652         rm31_new_control(data);
0653         break;
0654     case WF_EVENT_TICK:
0655         if (have_all_controls && have_all_sensors)
0656             rm31_tick();
0657     }
0658     return 0;
0659 }
0660 
0661 static struct notifier_block rm31_events = {
0662     .notifier_call = rm31_wf_notify,
0663 };
0664 
0665 static int wf_rm31_probe(struct platform_device *dev)
0666 {
0667     wf_register_client(&rm31_events);
0668     return 0;
0669 }
0670 
0671 static int wf_rm31_remove(struct platform_device *dev)
0672 {
0673     wf_unregister_client(&rm31_events);
0674 
0675     /* should release all sensors and controls */
0676     return 0;
0677 }
0678 
0679 static struct platform_driver wf_rm31_driver = {
0680     .probe  = wf_rm31_probe,
0681     .remove = wf_rm31_remove,
0682     .driver = {
0683         .name = "windfarm",
0684     },
0685 };
0686 
0687 static int __init wf_rm31_init(void)
0688 {
0689     struct device_node *cpu;
0690     int i;
0691 
0692     if (!of_machine_is_compatible("RackMac3,1"))
0693         return -ENODEV;
0694 
0695     /* Count the number of CPU cores */
0696     nr_chips = 0;
0697     for_each_node_by_type(cpu, "cpu")
0698         ++nr_chips;
0699     if (nr_chips > NR_CHIPS)
0700         nr_chips = NR_CHIPS;
0701 
0702     pr_info("windfarm: Initializing for desktop G5 with %d chips\n",
0703         nr_chips);
0704 
0705     /* Get MPU data for each CPU */
0706     for (i = 0; i < nr_chips; i++) {
0707         cpu_mpu_data[i] = wf_get_mpu(i);
0708         if (!cpu_mpu_data[i]) {
0709             pr_err("wf_rm31: Failed to find MPU data for CPU %d\n", i);
0710             return -ENXIO;
0711         }
0712     }
0713 
0714 #ifdef MODULE
0715     request_module("windfarm_fcu_controls");
0716     request_module("windfarm_lm75_sensor");
0717     request_module("windfarm_lm87_sensor");
0718     request_module("windfarm_ad7417_sensor");
0719     request_module("windfarm_max6690_sensor");
0720     request_module("windfarm_cpufreq_clamp");
0721 #endif /* MODULE */
0722 
0723     platform_driver_register(&wf_rm31_driver);
0724     return 0;
0725 }
0726 
0727 static void __exit wf_rm31_exit(void)
0728 {
0729     platform_driver_unregister(&wf_rm31_driver);
0730 }
0731 
0732 module_init(wf_rm31_init);
0733 module_exit(wf_rm31_exit);
0734 
0735 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
0736 MODULE_DESCRIPTION("Thermal control for Xserve G5");
0737 MODULE_LICENSE("GPL");
0738 MODULE_ALIAS("platform:windfarm");