windfarm: add PowerMac 12,1 support
Subsystems (2)
PATCH 1/1 windfarm: add PowerMac 12,1 support
From: Étienne Bersac <[email protected]>
Implement a new driver named windfarm_pm121 which drive fans on PowerMac 12,1 machine : iMac G5 iSight (rev C) 17" and 20". It's based on windfarm_pm81 driver from Benjamin Herrenschmidt.
---
Implement fan control for PowerMac 12,1 machines. This needs update to windfarm_lm75 and windfarm_max6690 sensors drivers in order to properly match sensors by their location. The code is based on windfarm_pm81 driver, adapted to the complexity of PowerMac 12,1 : 4 system control loops instead of one, per-control target correction and per-model control rubber-banding.
All the data are copied from Darwin 8.10 AppleMacRISC4PE-185.0.0 module as well as correction formula.
arch/powerpc/configs/g5_defconfig +1 -0
@@ -667,6 +667,7 @@ CONFIG_WINDFARM=y CONFIG_WINDFARM_PM81=y CONFIG_WINDFARM_PM91=y CONFIG_WINDFARM_PM112=y +CONFIG_WINDFARM_PM121=y # CONFIG_PMAC_RACKMETER is not set CONFIG_NETDEVICES=y # CONFIG_NETDEVICES_MULTIQUEUE is not set
drivers/macintosh/Kconfig +8 -0
@@ -234,6 +234,14 @@ config WINDFARM_PM112 which are the recent dual and quad G5 machines using the 970MP dual-core processor. +config WINDFARM_PM121 + tristate "Support for thermal management on PowerMac12,1" + depends on WINDFARM && I2C && PMAC_SMU + select I2C_POWERMAC + help + This driver provides thermal control for the PowerMac12,1 + which is the iMac G5 (iSight) 970MP + config ANSLCD tristate "Support for ANS LCD display" depends on ADB_CUDA && PPC_PMAC
drivers/macintosh/Makefile +5 -0
@@ -42,4 +42,9 @@ obj-$(CONFIG_WINDFARM_PM112) += windfarm_pm112.o windfarm_smu_sat.o \ windfarm_smu_sensors.o \ windfarm_max6690_sensor.o \ windfarm_lm75_sensor.o windfarm_pid.o +obj-$(CONFIG_WINDFARM_PM121) += windfarm_pm121.o windfarm_smu_sat.o \ + windfarm_smu_controls.o \ + windfarm_smu_sensors.o \ + windfarm_max6690_sensor.o \ + windfarm_lm75_sensor.o windfarm_pid.o obj-$(CONFIG_PMAC_RACKMETER) += rack-meter.o
drivers/macintosh/windfarm_lm75_sensor.c +6 -0
@@ -127,6 +127,12 @@ static struct wf_lm75_sensor *wf_lm75_create(struct i2c_adapter *adapter,*/ if (!strcmp (loc,"Hard drive" ) || !strcmp (loc,"DRIVE BAY" )) lm->sens.name ="hd-temp" ; +else if (!strcmp (loc,"Incoming Air Temp" )) + lm->sens.name ="incoming-air-temp" ; +else if (!strcmp (loc,"ODD Temp" )) + lm->sens.name ="optical-drive-temp" ; +else if (!strcmp (loc,"HD Temp" )) + lm->sens.name ="hard-drive-temp" ;else goto fail;
drivers/macintosh/windfarm_max6690_sensor.c +14 -6
@@ -77,18 +77,28 @@ static struct wf_sensor_ops wf_max6690_ops = { .owner = THIS_MODULE, }; -static void wf_max6690_create (struct i2c_adapter *adapter,u8 addr) +static void wf_max6690_create (struct i2c_adapter *adapter,u8 addr, +const char *loc) {struct wf_6690_sensor *max; -char *name ="backside-temp" ; +char *name; max =kzalloc (sizeof (struct wf_6690_sensor ),GFP_KERNEL );if (max ==NULL ) {printk (KERN_ERR "windfarm: Couldn't create MAX6690 sensor %s: " -"no memory\n" , name); +"no memory\n" , loc);return ; } +if (!strcmp (loc,"BACKSIDE" )) + name ="backside-temp" ; +else if (!strcmp (loc,"NB Ambient" )) + name ="north-bridge-temp" ; +else if (!strcmp (loc,"GPU Ambient" )) + name ="gpu-temp" ; +else + goto fail; + max->sens.ops = &wf_max6690_ops; max->sens.name = name; max->i2c.addr = addr >>1 ;
@@ -138,9 +148,7 @@ static int wf_max6690_attach(struct i2c_adapter *adapter)if (loc ==NULL || addr ==0 )continue ;printk ("found max6690, loc=%s addr=0x%02x\n" , loc, addr); -if (strcmp (loc,"BACKSIDE" )) -continue ; -wf_max6690_create (adapter, addr); +wf_max6690_create (adapter, addr, loc); }return 0 ;
drivers/macintosh/windfarm_pm121.c new file +1040 -0
1,040 lines not on this page · raw message
drivers/macintosh/windfarm_smu_controls.c +4 -0
@@ -218,6 +218,10 @@ static struct smu_fan_control *smu_fan_create(struct device_node *node, fct->ctrl.name ="cpu-fan" ; else if (!strcmp(l, "Hard Drive") || !strcmp(l, "Hard drive")) fct->ctrl.name ="drive-bay-fan" ; + else if (!strcmp(l, "HDD Fan")) /* seen on iMac G5 iSight */ + fct->ctrl.name ="hard-drive-fan" ; + else if (!strcmp(l, "ODD Fan")) /* same */ + fct->ctrl.name ="optical-drive-fan" ;/* Unrecognized fan, bail out */ if (fct->ctrl.name ==NULL )
Quoted 5 lines · Étienne Bersac
From: Étienne Bersac <[email protected]>
Implement a new driver named
windfarm_pm121which drive fans on PowerMac 12,1 machine : iMac G5 iSight (rev C) 17" and 20". It's based onwindfarm_pm81driver from Benjamin Herrenschmidt.
Is it just coincidence, or does it only seem to stop the fans when I cat /sys/devices/platform/windfarm.0/cpu-temp ?
Signature · 1 line
dwmw2
Quoted 9 lines · David Woodhouse
Quoted 5 lines · Étienne Bersac
From: Étienne Bersac <[email protected]>
Implement a new driver named
windfarm_pm121which drive fans on PowerMac 12,1 machine : iMac G5 iSight (rev C) 17" and 20". It's based onwindfarm_pm81driver from Benjamin Herrenschmidt.Is it just coincidence, or does it only seem to stop the fans when I cat
/sys/devices/platform/windfarm.0/cpu-temp?
Is it actually working ?
If the SMU thinks there is no fan control done by the OS, it will ramp them up ... but bring them back down when it gets ping.
So if for some reason the control loop isn't starting (because it can't find something it wants on this machine), the fans will stay up, but you'll cause such a "ping" when reading the CPU temp.
That may be bogus, just thinking what it could be...
Ben.
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines · David Woodhouse
Quoted 5 lines · Étienne Bersac
From: Étienne Bersac <[email protected]>
Implement a new driver named
windfarm_pm121which drive fans on PowerMac 12,1 machine : iMac G5 iSight (rev C) 17" and 20". It's based onwindfarm_pm81driver from Benjamin Herrenschmidt.Is it just coincidence, or does it only seem to stop the fans when I cat
/sys/devices/platform/windfarm.0/cpu-temp?
Quoted 8 lines
Is it actually working ?
If the SMU thinks there is no fan control done by the OS, it will ramp them up ... but bring them back down when it gets ping.
So if for some reason the control loop isn't starting (because it can't find something it wants on this machine), the fans will stay up, but you'll cause such a "ping" when reading the CPU temp.
Yeah, there's weird shit going on with the sensor/control registration. I think GCC is be miscompiling it -- the sequence of
all = all && pm121_register_control(foo...); all = all && pm121_register_control(bar...);
is bailing out as soon as 'all' gets set to zero. Despite the fact that pm121_register_control() quite blatantly has side-effects.
Signature · 1 line
dwmw2
Quoted 8 lines · David Woodhouse
Yeah, there's weird shit going on with the sensor/control registration.
I think GCC is be miscompiling it -- the sequence ofall = all && pm121_register_control(foo...); all = all && pm121_register_control(bar...);is bailing out as soon as 'all' gets set to zero. Despite the fact that
pm121_register_control()quite blatantly has side-effects.
That's after I fix the names in pm121_new_control() and fix pm121_register_control() to set controls[id] instead of always setting controls[FAN_OD], btw. Without that I don't think it could ever have worked.
But it's still broken. I'll try to cut it down and file a GCC bug...
.pm121_new_control:
.LFB929:
.loc 1 883 0
.LVL44:
mflr 0
.LCFI38:
std 0,16(1)
.LCFI39:
std 30,-16(1)
.LCFI40:
std 31,-8(1)
.LCFI41:
stdu 1,-128(1)
.LCFI42:
ld 30,.LCTOC0@toc(2)
mr 31,3
.loc 1 886 0
ld 9,.LC47-.LCTOC1(30)
lwz 0,48(9)
cmpwi 7,0,0
bne 7,.L31
.LVL45:
.loc 1 889 0
ld 4,.LC49-.LCTOC1(30)
li 5,2
bl .pm121_register_control
cmpdi 7,3,0
beq 7,.L31
.loc 1 890 0
mr 3,31
ld 4,.LC51-.LCTOC1(30)
li 5,1
bl .pm121_register_control
cmpdi 7,3,0
beq 7,.L31
.loc 1 891 0
mr 3,31
ld 4,.LC53-.LCTOC1(30)
li 5,0
bl .pm121_register_control
cmpdi 7,3,0
beq 7,.L31
.loc 1 892 0
mr 3,31
ld 4,.LC55-.LCTOC1(30)
li 5,3
bl .pm121_register_control
cmpdi 7,3,0
beq 7,.L31
.loc 1 895 0
ld 3,.LC57-.LCTOC1(30)
bl .printk
nop
.loc 1 896 0
ld 9,.LC47-.LCTOC1(30)
li 0,1
stw 0,48(9)
.LVL46:
.L31:
.loc 1 898 0
addi 1,1,128
ld 0,16(1)
mtlr 0
ld 30,-16(1)
ld 31,-8(1).LVL47:
blr
Signature · 1 line
dwmw2
Quoted 9 lines · David Woodhouse
Quoted 8 lines · David Woodhouse
Yeah, there's weird shit going on with the sensor/control registration.
I think GCC is be miscompiling it -- the sequence ofall = all && pm121_register_control(foo...); all = all && pm121_register_control(bar...);is bailing out as soon as 'all' gets set to zero. Despite the fact that
pm121_register_control()quite blatantly has side-effects.
And it's just supposed to do that no ?
Ben.
Quoted 77 lines
That's after I fix the names in
pm121_new_control()and fixpm121_register_control()to set controls[id] instead of always setting controls[FAN_OD], btw. Without that I don't think it could ever have worked.But it's still broken. I'll try to cut it down and file a GCC bug...
.pm121_new_control:
.LFB929:.loc 1 883 0 .LVL44: mflr 0 .LCFI38: std 0,16(1) .LCFI39: std 30,-16(1) .LCFI40: std 31,-8(1) .LCFI41: stdu 1,-128(1) .LCFI42: ld 30,.LCTOC0@toc(2) mr 31,3 .loc 1 886 0 ld 9,.LC47-.LCTOC1(30) lwz 0,48(9) cmpwi 7,0,0 bne 7,.L31 .LVL45: .loc 1 889 0 ld 4,.LC49-.LCTOC1(30) li 5,2 bl .pm121_register_control cmpdi 7,3,0 beq 7,.L31 .loc 1 890 0 mr 3,31 ld 4,.LC51-.LCTOC1(30) li 5,1 bl .pm121_register_control cmpdi 7,3,0 beq 7,.L31 .loc 1 891 0 mr 3,31 ld 4,.LC53-.LCTOC1(30) li 5,0 bl .pm121_register_control cmpdi 7,3,0 beq 7,.L31 .loc 1 892 0 mr 3,31 ld 4,.LC55-.LCTOC1(30) li 5,3 bl .pm121_register_control cmpdi 7,3,0 beq 7,.L31 .loc 1 895 0 ld 3,.LC57-.LCTOC1(30) bl .printk nop .loc 1 896 0 ld 9,.LC47-.LCTOC1(30) li 0,1 stw 0,48(9) .LVL46: .L31: .loc 1 898 0 addi 1,1,128 ld 0,16(1) mtlr 0 ld 30,-16(1) ld 31,-8(1).LVL47:
blr
Quoted 7 lines · On Sat, 22 Mar 2008 23:02:46 +0000 David Woodhouse <[email protected]> wrote:
Yeah, there's weird shit going on with the sensor/control registration. I think GCC is be miscompiling it -- the sequence of
all = all && pm121_register_control(foo...); all = all && pm121_register_control(bar...);is bailing out as soon as 'all' gets set to zero. Despite the fact that
pm121_register_control()quite blatantly has side-effects.
Why would you expect otherwise (from the C standard):
"Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares equal to 0, the second operand is not evaluated."
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 6 lines · Stephen Rothwell
Why would you expect otherwise (from the C standard):
"Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares equal to 0, the second operand is not evaluated."
Because it's Saturday night, I wasn't expecting that construct there (because it seems to require that the sensors/controls are detected in the precise order that they're checked for, otherwise it'll never match the ones which are found out of order), and mostly because I'm stupid.
This seems to fix it (note the change of the control names too):
macintosh/windfarm_pm121.c renamed from macintosh/windfarm_pm121.c~ +23 -23
@@ -867,7 +867,7 @@ static struct wf_control* pm121_register {if (controls[id] ==NULL && !strcmp (ct->name, match)) {if (wf_get_control (ct) ==0 ) - controls[FAN_OD ] = ct; + controls[id] = ct; }return controls[id]; }
@@ -879,10 +879,10 @@ static void pm121_new_control(struct wf_if (pm121_all_controls_ok)return ; - all = all &&pm121_register_control (ct,"optical-driver-fan" ,FAN_OD ); - all = all &&pm121_register_control (ct,"hard-driver-fan" ,FAN_HD ); - all = all &&pm121_register_control (ct,"cpu-driver-fan" ,FAN_CPU ); - all = all &&pm121_register_control (ct,"cpufreq-clamp" ,CPUFREQ ); + all =pm121_register_control (ct,"optical-drive-fan" ,FAN_OD ) && all; + all =pm121_register_control (ct,"hard-drive-fan" ,FAN_HD ) && all; + all =pm121_register_control (ct,"cpu-fan" ,FAN_CPU ) && all; + all =pm121_register_control (ct,"cpufreq-clamp" ,CPUFREQ ) && all;if (all) pm121_all_controls_ok =1 ;
@@ -909,24 +909,24 @@ static void pm121_new_sensor(struct wf_sif (pm121_all_sensors_ok)return ; - all = all &&pm121_register_sensor (sr,"cpu-temp" , - &sensor_cpu_temp); - all = all &&pm121_register_sensor (sr,"cpu-current" , - &sensor_cpu_current); - all = all &&pm121_register_sensor (sr,"cpu-voltage" , - &sensor_cpu_voltage); - all = all &&pm121_register_sensor (sr,"cpu-power" , - &sensor_cpu_power); - all = all &&pm121_register_sensor (sr,"hard-drive-temp" , - &sensor_hard_drive_temp); - all = all &&pm121_register_sensor (sr,"optical-drive-temp" , - &sensor_optical_drive_temp); - all = all &&pm121_register_sensor (sr,"incoming-air-temp" , - &sensor_incoming_air_temp); - all = all &&pm121_register_sensor (sr,"north-bridge-temp" , - &sensor_north_bridge_temp); - all = all &&pm121_register_sensor (sr,"gpu-temp" , - &sensor_gpu_temp); + all =pm121_register_sensor (sr,"cpu-temp" , + &sensor_cpu_temp) && all; + all =pm121_register_sensor (sr,"cpu-current" , + &sensor_cpu_current) && all; + all =pm121_register_sensor (sr,"cpu-voltage" , + &sensor_cpu_voltage) && all; + all =pm121_register_sensor (sr,"cpu-power" , + &sensor_cpu_power) && all; + all =pm121_register_sensor (sr,"hard-drive-temp" , + &sensor_hard_drive_temp) && all; + all =pm121_register_sensor (sr,"optical-drive-temp" , + &sensor_optical_drive_temp) && all; + all =pm121_register_sensor (sr,"incoming-air-temp" , + &sensor_incoming_air_temp) && all; + all =pm121_register_sensor (sr,"north-bridge-temp" , + &sensor_north_bridge_temp) && all; + all =pm121_register_sensor (sr,"gpu-temp" , + &sensor_gpu_temp) && all;if (all) pm121_all_sensors_ok =1 ;
Signature · 1 line
dwmw2
macintosh/windfarm_pm121.c static void pm121_new_control(struct wf_ · line 885
Quoted 8 lines · David Woodhouse
macintosh/windfarm_pm121.c renamed from macintosh/windfarm_pm121.c~ +4
-4- all = all &&pm121_register_control (ct,"optical-driver-fan" ,FAN_OD ); - all = all &&pm121_register_control (ct,"hard-driver-fan" ,FAN_HD ); - all = all &&pm121_register_control (ct,"cpu-driver-fan" ,FAN_CPU ); - all = all &&pm121_register_control (ct,"cpufreq-clamp" ,CPUFREQ ); + all =pm121_register_control (ct,"optical-drive-fan" ,FAN_OD ) && all; + all =pm121_register_control (ct,"hard-drive-fan" ,FAN_HD ) && all; + all =pm121_register_control (ct,"cpu-fan" ,FAN_CPU ) && all; + all =pm121_register_control (ct,"cpufreq-clamp" ,CPUFREQ ) && all;
You can also write all &= ... if pm121_register_control always return 0/1 (or make it 0/1 with !!).
Andreas.
Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Hi Dave,
Quoted 10 lines · On Sat, 22 Mar 2008 23:31:13 +0000 David Woodhouse <[email protected]> wrote:
Quoted 6 lines · Stephen Rothwell
Why would you expect otherwise (from the C standard):
"Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation; there is a sequence point after the evaluation of the first operand. If the first operand compares equal to 0, the second operand is not evaluated."
Because it's Saturday night
That seems like all the explanation necessary :-)
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/