Path: blob/master/drivers/macintosh/windfarm_pm121.c
15109 views
/*1* Windfarm PowerMac thermal control. iMac G5 iSight2*3* (c) Copyright 2007 Étienne Bersac <[email protected]>4*5* Bits & pieces from windfarm_pm81.c by (c) Copyright 2005 Benjamin6* Herrenschmidt, IBM Corp. <[email protected]>7*8* Released under the term of the GNU GPL v2.9*10*11*12* PowerMac12,113* ============14*15*16* The algorithm used is the PID control algorithm, used the same way17* the published Darwin code does, using the same values that are18* present in the Darwin 8.10 snapshot property lists (note however19* that none of the code has been re-used, it's a complete20* re-implementation21*22* There is two models using PowerMac12,1. Model 2 is iMac G5 iSight23* 17" while Model 3 is iMac G5 20". They do have both the same24* controls with a tiny difference. The control-ids of hard-drive-fan25* and cpu-fan is swapped.26*27*28* Target Correction :29*30* controls have a target correction calculated as :31*32* new_min = ((((average_power * slope) >> 16) + offset) >> 16) + min_value33* new_value = max(new_value, max(new_min, 0))34*35* OD Fan control correction.36*37* # model_id: 238* offset : -1956315239* slope : 195631540*41* # model_id: 342* offset : -1565065243* slope : 156506544*45* HD Fan control correction.46*47* # model_id: 248* offset : -1565065249* slope : 156506550*51* # model_id: 352* offset : -1956315253* slope : 195631554*55* CPU Fan control correction.56*57* # model_id: 258* offset : -2543190059* slope : 254319060*61* # model_id: 362* offset : -1565065263* slope : 156506564*65*66* Target rubber-banding :67*68* Some controls have a target correction which depends on another69* control value. The correction is computed in the following way :70*71* new_min = ref_value * slope + offset72*73* ref_value is the value of the reference control. If new_min is74* greater than 0, then we correct the target value using :75*76* new_target = max (new_target, new_min >> 16)77*78*79* # model_id : 280* control : cpu-fan81* ref : optical-drive-fan82* offset : -1565065283* slope : 156506584*85* # model_id : 386* control : optical-drive-fan87* ref : hard-drive-fan88* offset : -3276800089* slope : 6553690*91*92* In order to have the moste efficient correction with those93* dependencies, we must trigger HD loop before OD loop before CPU94* loop.95*96*97* The various control loops found in Darwin config file are:98*99* HD Fan control loop.100*101* # model_id: 2102* control : hard-drive-fan103* sensor : hard-drive-temp104* PID params : G_d = 0x00000000105* G_p = 0x002D70A3106* G_r = 0x00019999107* History = 2 entries108* Input target = 0x370000109* Interval = 5s110*111* # model_id: 3112* control : hard-drive-fan113* sensor : hard-drive-temp114* PID params : G_d = 0x00000000115* G_p = 0x002170A3116* G_r = 0x00019999117* History = 2 entries118* Input target = 0x370000119* Interval = 5s120*121* OD Fan control loop.122*123* # model_id: 2124* control : optical-drive-fan125* sensor : optical-drive-temp126* PID params : G_d = 0x00000000127* G_p = 0x001FAE14128* G_r = 0x00019999129* History = 2 entries130* Input target = 0x320000131* Interval = 5s132*133* # model_id: 3134* control : optical-drive-fan135* sensor : optical-drive-temp136* PID params : G_d = 0x00000000137* G_p = 0x001FAE14138* G_r = 0x00019999139* History = 2 entries140* Input target = 0x320000141* Interval = 5s142*143* GPU Fan control loop.144*145* # model_id: 2146* control : hard-drive-fan147* sensor : gpu-temp148* PID params : G_d = 0x00000000149* G_p = 0x002A6666150* G_r = 0x00019999151* History = 2 entries152* Input target = 0x5A0000153* Interval = 5s154*155* # model_id: 3156* control : cpu-fan157* sensor : gpu-temp158* PID params : G_d = 0x00000000159* G_p = 0x0010CCCC160* G_r = 0x00019999161* History = 2 entries162* Input target = 0x500000163* Interval = 5s164*165* KODIAK (aka northbridge) Fan control loop.166*167* # model_id: 2168* control : optical-drive-fan169* sensor : north-bridge-temp170* PID params : G_d = 0x00000000171* G_p = 0x003BD70A172* G_r = 0x00019999173* History = 2 entries174* Input target = 0x550000175* Interval = 5s176*177* # model_id: 3178* control : hard-drive-fan179* sensor : north-bridge-temp180* PID params : G_d = 0x00000000181* G_p = 0x0030F5C2182* G_r = 0x00019999183* History = 2 entries184* Input target = 0x550000185* Interval = 5s186*187* CPU Fan control loop.188*189* control : cpu-fan190* sensors : cpu-temp, cpu-power191* PID params : from SDB partition192*193*194* CPU Slew control loop.195*196* control : cpufreq-clamp197* sensor : cpu-temp198*199*/200201#undef DEBUG202203#include <linux/types.h>204#include <linux/errno.h>205#include <linux/kernel.h>206#include <linux/delay.h>207#include <linux/slab.h>208#include <linux/init.h>209#include <linux/spinlock.h>210#include <linux/wait.h>211#include <linux/kmod.h>212#include <linux/device.h>213#include <linux/platform_device.h>214#include <asm/prom.h>215#include <asm/machdep.h>216#include <asm/io.h>217#include <asm/system.h>218#include <asm/sections.h>219#include <asm/smu.h>220221#include "windfarm.h"222#include "windfarm_pid.h"223224#define VERSION "0.3"225226static int pm121_mach_model; /* machine model id */227228/* Controls & sensors */229static struct wf_sensor *sensor_cpu_power;230static struct wf_sensor *sensor_cpu_temp;231static struct wf_sensor *sensor_cpu_voltage;232static struct wf_sensor *sensor_cpu_current;233static struct wf_sensor *sensor_gpu_temp;234static struct wf_sensor *sensor_north_bridge_temp;235static struct wf_sensor *sensor_hard_drive_temp;236static struct wf_sensor *sensor_optical_drive_temp;237static struct wf_sensor *sensor_incoming_air_temp; /* unused ! */238239enum {240FAN_CPU,241FAN_HD,242FAN_OD,243CPUFREQ,244N_CONTROLS245};246static struct wf_control *controls[N_CONTROLS] = {};247248/* Set to kick the control loop into life */249static int pm121_all_controls_ok, pm121_all_sensors_ok, pm121_started;250251enum {252FAILURE_FAN = 1 << 0,253FAILURE_SENSOR = 1 << 1,254FAILURE_OVERTEMP = 1 << 2255};256257/* All sys loops. Note the HD before the OD loop in order to have it258run before. */259enum {260LOOP_GPU, /* control = hd or cpu, but luckily,261it doesn't matter */262LOOP_HD, /* control = hd */263LOOP_KODIAK, /* control = hd or od */264LOOP_OD, /* control = od */265N_LOOPS266};267268static const char *loop_names[N_LOOPS] = {269"GPU",270"HD",271"KODIAK",272"OD",273};274275#define PM121_NUM_CONFIGS 2276277static unsigned int pm121_failure_state;278static int pm121_readjust, pm121_skipping;279static s32 average_power;280281struct pm121_correction {282int offset;283int slope;284};285286static struct pm121_correction corrections[N_CONTROLS][PM121_NUM_CONFIGS] = {287/* FAN_OD */288{289/* MODEL 2 */290{ .offset = -19563152,291.slope = 1956315292},293/* MODEL 3 */294{ .offset = -15650652,295.slope = 1565065296},297},298/* FAN_HD */299{300/* MODEL 2 */301{ .offset = -15650652,302.slope = 1565065303},304/* MODEL 3 */305{ .offset = -19563152,306.slope = 1956315307},308},309/* FAN_CPU */310{311/* MODEL 2 */312{ .offset = -25431900,313.slope = 2543190314},315/* MODEL 3 */316{ .offset = -15650652,317.slope = 1565065318},319},320/* CPUFREQ has no correction (and is not implemented at all) */321};322323struct pm121_connection {324unsigned int control_id;325unsigned int ref_id;326struct pm121_correction correction;327};328329static struct pm121_connection pm121_connections[] = {330/* MODEL 2 */331{ .control_id = FAN_CPU,332.ref_id = FAN_OD,333{ .offset = -32768000,334.slope = 65536335}336},337/* MODEL 3 */338{ .control_id = FAN_OD,339.ref_id = FAN_HD,340{ .offset = -32768000,341.slope = 65536342}343},344};345346/* pointer to the current model connection */347static struct pm121_connection *pm121_connection;348349/*350* ****** System Fans Control Loop ******351*352*/353354/* Since each loop handles only one control and we want to avoid355* writing virtual control, we store the control correction with the356* loop params. Some data are not set, there are common to all loop357* and thus, hardcoded.358*/359struct pm121_sys_param {360/* purely informative since we use mach_model-2 as index */361int model_id;362struct wf_sensor **sensor; /* use sensor_id instead ? */363s32 gp, itarget;364unsigned int control_id;365};366367static struct pm121_sys_param368pm121_sys_all_params[N_LOOPS][PM121_NUM_CONFIGS] = {369/* GPU Fan control loop */370{371{ .model_id = 2,372.sensor = &sensor_gpu_temp,373.gp = 0x002A6666,374.itarget = 0x5A0000,375.control_id = FAN_HD,376},377{ .model_id = 3,378.sensor = &sensor_gpu_temp,379.gp = 0x0010CCCC,380.itarget = 0x500000,381.control_id = FAN_CPU,382},383},384/* HD Fan control loop */385{386{ .model_id = 2,387.sensor = &sensor_hard_drive_temp,388.gp = 0x002D70A3,389.itarget = 0x370000,390.control_id = FAN_HD,391},392{ .model_id = 3,393.sensor = &sensor_hard_drive_temp,394.gp = 0x002170A3,395.itarget = 0x370000,396.control_id = FAN_HD,397},398},399/* KODIAK Fan control loop */400{401{ .model_id = 2,402.sensor = &sensor_north_bridge_temp,403.gp = 0x003BD70A,404.itarget = 0x550000,405.control_id = FAN_OD,406},407{ .model_id = 3,408.sensor = &sensor_north_bridge_temp,409.gp = 0x0030F5C2,410.itarget = 0x550000,411.control_id = FAN_HD,412},413},414/* OD Fan control loop */415{416{ .model_id = 2,417.sensor = &sensor_optical_drive_temp,418.gp = 0x001FAE14,419.itarget = 0x320000,420.control_id = FAN_OD,421},422{ .model_id = 3,423.sensor = &sensor_optical_drive_temp,424.gp = 0x001FAE14,425.itarget = 0x320000,426.control_id = FAN_OD,427},428},429};430431/* the hardcoded values */432#define PM121_SYS_GD 0x00000000433#define PM121_SYS_GR 0x00019999434#define PM121_SYS_HISTORY_SIZE 2435#define PM121_SYS_INTERVAL 5436437/* State data used by the system fans control loop438*/439struct pm121_sys_state {440int ticks;441s32 setpoint;442struct wf_pid_state pid;443};444445struct pm121_sys_state *pm121_sys_state[N_LOOPS] = {};446447/*448* ****** CPU Fans Control Loop ******449*450*/451452#define PM121_CPU_INTERVAL 1453454/* State data used by the cpu fans control loop455*/456struct pm121_cpu_state {457int ticks;458s32 setpoint;459struct wf_cpu_pid_state pid;460};461462static struct pm121_cpu_state *pm121_cpu_state;463464465466/*467* ***** Implementation *****468*469*/470471/* correction the value using the output-low-bound correction algo */472static s32 pm121_correct(s32 new_setpoint,473unsigned int control_id,474s32 min)475{476s32 new_min;477struct pm121_correction *correction;478correction = &corrections[control_id][pm121_mach_model - 2];479480new_min = (average_power * correction->slope) >> 16;481new_min += correction->offset;482new_min = (new_min >> 16) + min;483484return max3(new_setpoint, new_min, 0);485}486487static s32 pm121_connect(unsigned int control_id, s32 setpoint)488{489s32 new_min, value, new_setpoint;490491if (pm121_connection->control_id == control_id) {492controls[control_id]->ops->get_value(controls[control_id],493&value);494new_min = value * pm121_connection->correction.slope;495new_min += pm121_connection->correction.offset;496if (new_min > 0) {497new_setpoint = max(setpoint, (new_min >> 16));498if (new_setpoint != setpoint) {499pr_debug("pm121: %s depending on %s, "500"corrected from %d to %d RPM\n",501controls[control_id]->name,502controls[pm121_connection->ref_id]->name,503(int) setpoint, (int) new_setpoint);504}505} else506new_setpoint = setpoint;507}508/* no connection */509else510new_setpoint = setpoint;511512return new_setpoint;513}514515/* FAN LOOPS */516static void pm121_create_sys_fans(int loop_id)517{518struct pm121_sys_param *param = NULL;519struct wf_pid_param pid_param;520struct wf_control *control = NULL;521int i;522523/* First, locate the params for this model */524for (i = 0; i < PM121_NUM_CONFIGS; i++) {525if (pm121_sys_all_params[loop_id][i].model_id == pm121_mach_model) {526param = &(pm121_sys_all_params[loop_id][i]);527break;528}529}530531/* No params found, put fans to max */532if (param == NULL) {533printk(KERN_WARNING "pm121: %s fan config not found "534" for this machine model\n",535loop_names[loop_id]);536goto fail;537}538539control = controls[param->control_id];540541/* Alloc & initialize state */542pm121_sys_state[loop_id] = kmalloc(sizeof(struct pm121_sys_state),543GFP_KERNEL);544if (pm121_sys_state[loop_id] == NULL) {545printk(KERN_WARNING "pm121: Memory allocation error\n");546goto fail;547}548pm121_sys_state[loop_id]->ticks = 1;549550/* Fill PID params */551pid_param.gd = PM121_SYS_GD;552pid_param.gp = param->gp;553pid_param.gr = PM121_SYS_GR;554pid_param.interval = PM121_SYS_INTERVAL;555pid_param.history_len = PM121_SYS_HISTORY_SIZE;556pid_param.itarget = param->itarget;557pid_param.min = control->ops->get_min(control);558pid_param.max = control->ops->get_max(control);559560wf_pid_init(&pm121_sys_state[loop_id]->pid, &pid_param);561562pr_debug("pm121: %s Fan control loop initialized.\n"563" itarged=%d.%03d, min=%d RPM, max=%d RPM\n",564loop_names[loop_id], FIX32TOPRINT(pid_param.itarget),565pid_param.min, pid_param.max);566return;567568fail:569/* note that this is not optimal since another loop may still570control the same control */571printk(KERN_WARNING "pm121: failed to set up %s loop "572"setting \"%s\" to max speed.\n",573loop_names[loop_id], control->name);574575if (control)576wf_control_set_max(control);577}578579static void pm121_sys_fans_tick(int loop_id)580{581struct pm121_sys_param *param;582struct pm121_sys_state *st;583struct wf_sensor *sensor;584struct wf_control *control;585s32 temp, new_setpoint;586int rc;587588param = &(pm121_sys_all_params[loop_id][pm121_mach_model-2]);589st = pm121_sys_state[loop_id];590sensor = *(param->sensor);591control = controls[param->control_id];592593if (--st->ticks != 0) {594if (pm121_readjust)595goto readjust;596return;597}598st->ticks = PM121_SYS_INTERVAL;599600rc = sensor->ops->get_value(sensor, &temp);601if (rc) {602printk(KERN_WARNING "windfarm: %s sensor error %d\n",603sensor->name, rc);604pm121_failure_state |= FAILURE_SENSOR;605return;606}607608pr_debug("pm121: %s Fan tick ! %s: %d.%03d\n",609loop_names[loop_id], sensor->name,610FIX32TOPRINT(temp));611612new_setpoint = wf_pid_run(&st->pid, temp);613614/* correction */615new_setpoint = pm121_correct(new_setpoint,616param->control_id,617st->pid.param.min);618/* linked corretion */619new_setpoint = pm121_connect(param->control_id, new_setpoint);620621if (new_setpoint == st->setpoint)622return;623st->setpoint = new_setpoint;624pr_debug("pm121: %s corrected setpoint: %d RPM\n",625control->name, (int)new_setpoint);626readjust:627if (control && pm121_failure_state == 0) {628rc = control->ops->set_value(control, st->setpoint);629if (rc) {630printk(KERN_WARNING "windfarm: %s fan error %d\n",631control->name, rc);632pm121_failure_state |= FAILURE_FAN;633}634}635}636637638/* CPU LOOP */639static void pm121_create_cpu_fans(void)640{641struct wf_cpu_pid_param pid_param;642const struct smu_sdbp_header *hdr;643struct smu_sdbp_cpupiddata *piddata;644struct smu_sdbp_fvt *fvt;645struct wf_control *fan_cpu;646s32 tmax, tdelta, maxpow, powadj;647648fan_cpu = controls[FAN_CPU];649650/* First, locate the PID params in SMU SBD */651hdr = smu_get_sdb_partition(SMU_SDB_CPUPIDDATA_ID, NULL);652if (hdr == 0) {653printk(KERN_WARNING "pm121: CPU PID fan config not found.\n");654goto fail;655}656piddata = (struct smu_sdbp_cpupiddata *)&hdr[1];657658/* Get the FVT params for operating point 0 (the only supported one659* for now) in order to get tmax660*/661hdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL);662if (hdr) {663fvt = (struct smu_sdbp_fvt *)&hdr[1];664tmax = ((s32)fvt->maxtemp) << 16;665} else666tmax = 0x5e0000; /* 94 degree default */667668/* Alloc & initialize state */669pm121_cpu_state = kmalloc(sizeof(struct pm121_cpu_state),670GFP_KERNEL);671if (pm121_cpu_state == NULL)672goto fail;673pm121_cpu_state->ticks = 1;674675/* Fill PID params */676pid_param.interval = PM121_CPU_INTERVAL;677pid_param.history_len = piddata->history_len;678if (pid_param.history_len > WF_CPU_PID_MAX_HISTORY) {679printk(KERN_WARNING "pm121: History size overflow on "680"CPU control loop (%d)\n", piddata->history_len);681pid_param.history_len = WF_CPU_PID_MAX_HISTORY;682}683pid_param.gd = piddata->gd;684pid_param.gp = piddata->gp;685pid_param.gr = piddata->gr / pid_param.history_len;686687tdelta = ((s32)piddata->target_temp_delta) << 16;688maxpow = ((s32)piddata->max_power) << 16;689powadj = ((s32)piddata->power_adj) << 16;690691pid_param.tmax = tmax;692pid_param.ttarget = tmax - tdelta;693pid_param.pmaxadj = maxpow - powadj;694695pid_param.min = fan_cpu->ops->get_min(fan_cpu);696pid_param.max = fan_cpu->ops->get_max(fan_cpu);697698wf_cpu_pid_init(&pm121_cpu_state->pid, &pid_param);699700pr_debug("pm121: CPU Fan control initialized.\n");701pr_debug(" ttarged=%d.%03d, tmax=%d.%03d, min=%d RPM, max=%d RPM,\n",702FIX32TOPRINT(pid_param.ttarget), FIX32TOPRINT(pid_param.tmax),703pid_param.min, pid_param.max);704705return;706707fail:708printk(KERN_WARNING "pm121: CPU fan config not found, max fan speed\n");709710if (controls[CPUFREQ])711wf_control_set_max(controls[CPUFREQ]);712if (fan_cpu)713wf_control_set_max(fan_cpu);714}715716717static void pm121_cpu_fans_tick(struct pm121_cpu_state *st)718{719s32 new_setpoint, temp, power;720struct wf_control *fan_cpu = NULL;721int rc;722723if (--st->ticks != 0) {724if (pm121_readjust)725goto readjust;726return;727}728st->ticks = PM121_CPU_INTERVAL;729730fan_cpu = controls[FAN_CPU];731732rc = sensor_cpu_temp->ops->get_value(sensor_cpu_temp, &temp);733if (rc) {734printk(KERN_WARNING "pm121: CPU temp sensor error %d\n",735rc);736pm121_failure_state |= FAILURE_SENSOR;737return;738}739740rc = sensor_cpu_power->ops->get_value(sensor_cpu_power, &power);741if (rc) {742printk(KERN_WARNING "pm121: CPU power sensor error %d\n",743rc);744pm121_failure_state |= FAILURE_SENSOR;745return;746}747748pr_debug("pm121: CPU Fans tick ! CPU temp: %d.%03d°C, power: %d.%03d\n",749FIX32TOPRINT(temp), FIX32TOPRINT(power));750751if (temp > st->pid.param.tmax)752pm121_failure_state |= FAILURE_OVERTEMP;753754new_setpoint = wf_cpu_pid_run(&st->pid, power, temp);755756/* correction */757new_setpoint = pm121_correct(new_setpoint,758FAN_CPU,759st->pid.param.min);760761/* connected correction */762new_setpoint = pm121_connect(FAN_CPU, new_setpoint);763764if (st->setpoint == new_setpoint)765return;766st->setpoint = new_setpoint;767pr_debug("pm121: CPU corrected setpoint: %d RPM\n", (int)new_setpoint);768769readjust:770if (fan_cpu && pm121_failure_state == 0) {771rc = fan_cpu->ops->set_value(fan_cpu, st->setpoint);772if (rc) {773printk(KERN_WARNING "pm121: %s fan error %d\n",774fan_cpu->name, rc);775pm121_failure_state |= FAILURE_FAN;776}777}778}779780/*781* ****** Common ******782*783*/784785static void pm121_tick(void)786{787unsigned int last_failure = pm121_failure_state;788unsigned int new_failure;789s32 total_power;790int i;791792if (!pm121_started) {793pr_debug("pm121: creating control loops !\n");794for (i = 0; i < N_LOOPS; i++)795pm121_create_sys_fans(i);796797pm121_create_cpu_fans();798pm121_started = 1;799}800801/* skipping ticks */802if (pm121_skipping && --pm121_skipping)803return;804805/* compute average power */806total_power = 0;807for (i = 0; i < pm121_cpu_state->pid.param.history_len; i++)808total_power += pm121_cpu_state->pid.powers[i];809810average_power = total_power / pm121_cpu_state->pid.param.history_len;811812813pm121_failure_state = 0;814for (i = 0 ; i < N_LOOPS; i++) {815if (pm121_sys_state[i])816pm121_sys_fans_tick(i);817}818819if (pm121_cpu_state)820pm121_cpu_fans_tick(pm121_cpu_state);821822pm121_readjust = 0;823new_failure = pm121_failure_state & ~last_failure;824825/* If entering failure mode, clamp cpufreq and ramp all826* fans to full speed.827*/828if (pm121_failure_state && !last_failure) {829for (i = 0; i < N_CONTROLS; i++) {830if (controls[i])831wf_control_set_max(controls[i]);832}833}834835/* If leaving failure mode, unclamp cpufreq and readjust836* all fans on next iteration837*/838if (!pm121_failure_state && last_failure) {839if (controls[CPUFREQ])840wf_control_set_min(controls[CPUFREQ]);841pm121_readjust = 1;842}843844/* Overtemp condition detected, notify and start skipping a couple845* ticks to let the temperature go down846*/847if (new_failure & FAILURE_OVERTEMP) {848wf_set_overtemp();849pm121_skipping = 2;850}851852/* We only clear the overtemp condition if overtemp is cleared853* _and_ no other failure is present. Since a sensor error will854* clear the overtemp condition (can't measure temperature) at855* the control loop levels, but we don't want to keep it clear856* here in this case857*/858if (new_failure == 0 && last_failure & FAILURE_OVERTEMP)859wf_clear_overtemp();860}861862863static struct wf_control* pm121_register_control(struct wf_control *ct,864const char *match,865unsigned int id)866{867if (controls[id] == NULL && !strcmp(ct->name, match)) {868if (wf_get_control(ct) == 0)869controls[id] = ct;870}871return controls[id];872}873874static void pm121_new_control(struct wf_control *ct)875{876int all = 1;877878if (pm121_all_controls_ok)879return;880881all = pm121_register_control(ct, "optical-drive-fan", FAN_OD) && all;882all = pm121_register_control(ct, "hard-drive-fan", FAN_HD) && all;883all = pm121_register_control(ct, "cpu-fan", FAN_CPU) && all;884all = pm121_register_control(ct, "cpufreq-clamp", CPUFREQ) && all;885886if (all)887pm121_all_controls_ok = 1;888}889890891892893static struct wf_sensor* pm121_register_sensor(struct wf_sensor *sensor,894const char *match,895struct wf_sensor **var)896{897if (*var == NULL && !strcmp(sensor->name, match)) {898if (wf_get_sensor(sensor) == 0)899*var = sensor;900}901return *var;902}903904static void pm121_new_sensor(struct wf_sensor *sr)905{906int all = 1;907908if (pm121_all_sensors_ok)909return;910911all = pm121_register_sensor(sr, "cpu-temp",912&sensor_cpu_temp) && all;913all = pm121_register_sensor(sr, "cpu-current",914&sensor_cpu_current) && all;915all = pm121_register_sensor(sr, "cpu-voltage",916&sensor_cpu_voltage) && all;917all = pm121_register_sensor(sr, "cpu-power",918&sensor_cpu_power) && all;919all = pm121_register_sensor(sr, "hard-drive-temp",920&sensor_hard_drive_temp) && all;921all = pm121_register_sensor(sr, "optical-drive-temp",922&sensor_optical_drive_temp) && all;923all = pm121_register_sensor(sr, "incoming-air-temp",924&sensor_incoming_air_temp) && all;925all = pm121_register_sensor(sr, "north-bridge-temp",926&sensor_north_bridge_temp) && all;927all = pm121_register_sensor(sr, "gpu-temp",928&sensor_gpu_temp) && all;929930if (all)931pm121_all_sensors_ok = 1;932}933934935936static int pm121_notify(struct notifier_block *self,937unsigned long event, void *data)938{939switch (event) {940case WF_EVENT_NEW_CONTROL:941pr_debug("pm121: new control %s detected\n",942((struct wf_control *)data)->name);943pm121_new_control(data);944break;945case WF_EVENT_NEW_SENSOR:946pr_debug("pm121: new sensor %s detected\n",947((struct wf_sensor *)data)->name);948pm121_new_sensor(data);949break;950case WF_EVENT_TICK:951if (pm121_all_controls_ok && pm121_all_sensors_ok)952pm121_tick();953break;954}955956return 0;957}958959static struct notifier_block pm121_events = {960.notifier_call = pm121_notify,961};962963static int pm121_init_pm(void)964{965const struct smu_sdbp_header *hdr;966967hdr = smu_get_sdb_partition(SMU_SDB_SENSORTREE_ID, NULL);968if (hdr != 0) {969struct smu_sdbp_sensortree *st =970(struct smu_sdbp_sensortree *)&hdr[1];971pm121_mach_model = st->model_id;972}973974pm121_connection = &pm121_connections[pm121_mach_model - 2];975976printk(KERN_INFO "pm121: Initializing for iMac G5 iSight model ID %d\n",977pm121_mach_model);978979return 0;980}981982983static int pm121_probe(struct platform_device *ddev)984{985wf_register_client(&pm121_events);986987return 0;988}989990static int __devexit pm121_remove(struct platform_device *ddev)991{992wf_unregister_client(&pm121_events);993return 0;994}995996static struct platform_driver pm121_driver = {997.probe = pm121_probe,998.remove = __devexit_p(pm121_remove),999.driver = {1000.name = "windfarm",1001.bus = &platform_bus_type,1002},1003};100410051006static int __init pm121_init(void)1007{1008int rc = -ENODEV;10091010if (of_machine_is_compatible("PowerMac12,1"))1011rc = pm121_init_pm();10121013if (rc == 0) {1014request_module("windfarm_smu_controls");1015request_module("windfarm_smu_sensors");1016request_module("windfarm_smu_sat");1017request_module("windfarm_lm75_sensor");1018request_module("windfarm_max6690_sensor");1019request_module("windfarm_cpufreq_clamp");1020platform_driver_register(&pm121_driver);1021}10221023return rc;1024}10251026static void __exit pm121_exit(void)1027{10281029platform_driver_unregister(&pm121_driver);1030}103110321033module_init(pm121_init);1034module_exit(pm121_exit);10351036MODULE_AUTHOR("Étienne Bersac <[email protected]>");1037MODULE_DESCRIPTION("Thermal control logic for iMac G5 (iSight)");1038MODULE_LICENSE("GPL");1039104010411042