aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2006-07-06 04:03:06 -0400
committerPaul Mackerras <paulus@samba.org>2006-07-07 06:19:16 -0400
commit861fa7737db889ae1701ba58c083d4a7bd8705d3 (patch)
treef2398f760279de2169a2c61b0a4034d1a0c0c2c1 /drivers/macintosh
parente7c1f69d4fa4da47dc995b5de64b6cb76ae32081 (diff)
[POWERPC] Xserve G5 thermal control fixes
The thermal control for the Xserve G5s had a few issues. For one, the way to program the RPM fans speeds into the FCU is different between it and the desktop models, which I didn't figure out until recently, and it was missing a control loop for the slots fan, running it too fast. Both of those problems were causing the machine to be much more noisy than necessary. This patch also changes the fixed value of the slots fan for desktop G5s to 40% instead of 50%. It seems to still have a pretty good airflow that way and is much less noisy. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r--drivers/macintosh/therm_pm72.c218
-rw-r--r--drivers/macintosh/therm_pm72.h33
2 files changed, 234 insertions, 17 deletions
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index c1fe0b368f76..20bf67244e2c 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -95,6 +95,17 @@
95 * - Use min/max macros here or there 95 * - Use min/max macros here or there
96 * - Latest darwin updated U3H min fan speed to 20% PWM 96 * - Latest darwin updated U3H min fan speed to 20% PWM
97 * 97 *
98 * July. 06, 2006 : 1.3
99 * - Fix setting of RPM fans on Xserve G5 (they were going too fast)
100 * - Add missing slots fan control loop for Xserve G5
101 * - Lower fixed slots fan speed from 50% to 40% on desktop G5s. We
102 * still can't properly implement the control loop for these, so let's
103 * reduce the noise a little bit, it appears that 40% still gives us
104 * a pretty good air flow
105 * - Add code to "tickle" the FCU regulary so it doesn't think that
106 * we are gone while in fact, the machine just didn't need any fan
107 * speed change lately
108 *
98 */ 109 */
99 110
100#include <linux/types.h> 111#include <linux/types.h>
@@ -121,7 +132,7 @@
121 132
122#include "therm_pm72.h" 133#include "therm_pm72.h"
123 134
124#define VERSION "1.2b2" 135#define VERSION "1.3"
125 136
126#undef DEBUG 137#undef DEBUG
127 138
@@ -146,6 +157,7 @@ static struct basckside_pid_params backside_params;
146static struct backside_pid_state backside_state; 157static struct backside_pid_state backside_state;
147static struct drives_pid_state drives_state; 158static struct drives_pid_state drives_state;
148static struct dimm_pid_state dimms_state; 159static struct dimm_pid_state dimms_state;
160static struct slots_pid_state slots_state;
149static int state; 161static int state;
150static int cpu_count; 162static int cpu_count;
151static int cpu_pid_type; 163static int cpu_pid_type;
@@ -154,7 +166,8 @@ static struct completion ctrl_complete;
154static int critical_state; 166static int critical_state;
155static int rackmac; 167static int rackmac;
156static s32 dimm_output_clamp; 168static s32 dimm_output_clamp;
157 169static int fcu_rpm_shift;
170static int fcu_tickle_ticks;
158static DECLARE_MUTEX(driver_lock); 171static DECLARE_MUTEX(driver_lock);
159 172
160/* 173/*
@@ -495,13 +508,20 @@ static int start_fcu(void)
495 rc = fan_write_reg(0x2e, &buf, 1); 508 rc = fan_write_reg(0x2e, &buf, 1);
496 if (rc < 0) 509 if (rc < 0)
497 return -EIO; 510 return -EIO;
511 rc = fan_read_reg(0, &buf, 1);
512 if (rc < 0)
513 return -EIO;
514 fcu_rpm_shift = (buf == 1) ? 2 : 3;
515 printk(KERN_DEBUG "FCU Initialized, RPM fan shift is %d\n",
516 fcu_rpm_shift);
517
498 return 0; 518 return 0;
499} 519}
500 520
501static int set_rpm_fan(int fan_index, int rpm) 521static int set_rpm_fan(int fan_index, int rpm)
502{ 522{
503 unsigned char buf[2]; 523 unsigned char buf[2];
504 int rc, id; 524 int rc, id, min, max;
505 525
506 if (fcu_fans[fan_index].type != FCU_FAN_RPM) 526 if (fcu_fans[fan_index].type != FCU_FAN_RPM)
507 return -EINVAL; 527 return -EINVAL;
@@ -509,12 +529,15 @@ static int set_rpm_fan(int fan_index, int rpm)
509 if (id == FCU_FAN_ABSENT_ID) 529 if (id == FCU_FAN_ABSENT_ID)
510 return -EINVAL; 530 return -EINVAL;
511 531
512 if (rpm < 300) 532 min = 2400 >> fcu_rpm_shift;
513 rpm = 300; 533 max = 56000 >> fcu_rpm_shift;
514 else if (rpm > 8191) 534
515 rpm = 8191; 535 if (rpm < min)
516 buf[0] = rpm >> 5; 536 rpm = min;
517 buf[1] = rpm << 3; 537 else if (rpm > max)
538 rpm = max;
539 buf[0] = rpm >> (8 - fcu_rpm_shift);
540 buf[1] = rpm << fcu_rpm_shift;
518 rc = fan_write_reg(0x10 + (id * 2), buf, 2); 541 rc = fan_write_reg(0x10 + (id * 2), buf, 2);
519 if (rc < 0) 542 if (rc < 0)
520 return -EIO; 543 return -EIO;
@@ -551,7 +574,7 @@ static int get_rpm_fan(int fan_index, int programmed)
551 if (rc != 2) 574 if (rc != 2)
552 return -EIO; 575 return -EIO;
553 576
554 return (buf[0] << 5) | buf[1] >> 3; 577 return (buf[0] << (8 - fcu_rpm_shift)) | buf[1] >> fcu_rpm_shift;
555} 578}
556 579
557static int set_pwm_fan(int fan_index, int pwm) 580static int set_pwm_fan(int fan_index, int pwm)
@@ -609,6 +632,26 @@ static int get_pwm_fan(int fan_index)
609 return (buf[0] * 1000) / 2559; 632 return (buf[0] * 1000) / 2559;
610} 633}
611 634
635static void tickle_fcu(void)
636{
637 int pwm;
638
639 pwm = get_pwm_fan(SLOTS_FAN_PWM_INDEX);
640
641 DBG("FCU Tickle, slots fan is: %d\n", pwm);
642 if (pwm < 0)
643 pwm = 100;
644
645 if (!rackmac) {
646 pwm = SLOTS_FAN_DEFAULT_PWM;
647 } else if (pwm < SLOTS_PID_OUTPUT_MIN)
648 pwm = SLOTS_PID_OUTPUT_MIN;
649
650 /* That is hopefully enough to make the FCU happy */
651 set_pwm_fan(SLOTS_FAN_PWM_INDEX, pwm);
652}
653
654
612/* 655/*
613 * Utility routine to read the CPU calibration EEPROM data 656 * Utility routine to read the CPU calibration EEPROM data
614 * from the device-tree 657 * from the device-tree
@@ -715,6 +758,9 @@ BUILD_SHOW_FUNC_INT(backside_fan_pwm, backside_state.pwm)
715BUILD_SHOW_FUNC_FIX(drives_temperature, drives_state.last_temp) 758BUILD_SHOW_FUNC_FIX(drives_temperature, drives_state.last_temp)
716BUILD_SHOW_FUNC_INT(drives_fan_rpm, drives_state.rpm) 759BUILD_SHOW_FUNC_INT(drives_fan_rpm, drives_state.rpm)
717 760
761BUILD_SHOW_FUNC_FIX(slots_temperature, slots_state.last_temp)
762BUILD_SHOW_FUNC_INT(slots_fan_pwm, slots_state.pwm)
763
718BUILD_SHOW_FUNC_FIX(dimms_temperature, dimms_state.last_temp) 764BUILD_SHOW_FUNC_FIX(dimms_temperature, dimms_state.last_temp)
719 765
720static DEVICE_ATTR(cpu0_temperature,S_IRUGO,show_cpu0_temperature,NULL); 766static DEVICE_ATTR(cpu0_temperature,S_IRUGO,show_cpu0_temperature,NULL);
@@ -735,6 +781,9 @@ static DEVICE_ATTR(backside_fan_pwm,S_IRUGO,show_backside_fan_pwm,NULL);
735static DEVICE_ATTR(drives_temperature,S_IRUGO,show_drives_temperature,NULL); 781static DEVICE_ATTR(drives_temperature,S_IRUGO,show_drives_temperature,NULL);
736static DEVICE_ATTR(drives_fan_rpm,S_IRUGO,show_drives_fan_rpm,NULL); 782static DEVICE_ATTR(drives_fan_rpm,S_IRUGO,show_drives_fan_rpm,NULL);
737 783
784static DEVICE_ATTR(slots_temperature,S_IRUGO,show_slots_temperature,NULL);
785static DEVICE_ATTR(slots_fan_pwm,S_IRUGO,show_slots_fan_pwm,NULL);
786
738static DEVICE_ATTR(dimms_temperature,S_IRUGO,show_dimms_temperature,NULL); 787static DEVICE_ATTR(dimms_temperature,S_IRUGO,show_dimms_temperature,NULL);
739 788
740/* 789/*
@@ -1076,6 +1125,9 @@ static void do_monitor_cpu_rack(struct cpu_pid_state *state)
1076 fan_min = dimm_output_clamp; 1125 fan_min = dimm_output_clamp;
1077 fan_min = max(fan_min, (int)state->mpu.rminn_intake_fan); 1126 fan_min = max(fan_min, (int)state->mpu.rminn_intake_fan);
1078 1127
1128 DBG(" CPU min mpu = %d, min dimm = %d\n",
1129 state->mpu.rminn_intake_fan, dimm_output_clamp);
1130
1079 state->rpm = max(state->rpm, (int)fan_min); 1131 state->rpm = max(state->rpm, (int)fan_min);
1080 state->rpm = min(state->rpm, (int)state->mpu.rmaxn_intake_fan); 1132 state->rpm = min(state->rpm, (int)state->mpu.rmaxn_intake_fan);
1081 state->intake_rpm = state->rpm; 1133 state->intake_rpm = state->rpm;
@@ -1374,7 +1426,8 @@ static void do_monitor_drives(struct drives_pid_state *state)
1374 DBG(" current rpm: %d\n", state->rpm); 1426 DBG(" current rpm: %d\n", state->rpm);
1375 1427
1376 /* Get some sensor readings */ 1428 /* Get some sensor readings */
1377 temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor, DS1775_TEMP)) << 8; 1429 temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor,
1430 DS1775_TEMP)) << 8;
1378 state->last_temp = temp; 1431 state->last_temp = temp;
1379 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp), 1432 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
1380 FIX32TOPRINT(DRIVES_PID_INPUT_TARGET)); 1433 FIX32TOPRINT(DRIVES_PID_INPUT_TARGET));
@@ -1575,7 +1628,7 @@ static int init_dimms_state(struct dimm_pid_state *state)
1575} 1628}
1576 1629
1577/* 1630/*
1578 * Dispose of the state data for the drives control loop 1631 * Dispose of the state data for the DIMM control loop
1579 */ 1632 */
1580static void dispose_dimms_state(struct dimm_pid_state *state) 1633static void dispose_dimms_state(struct dimm_pid_state *state)
1581{ 1634{
@@ -1588,6 +1641,127 @@ static void dispose_dimms_state(struct dimm_pid_state *state)
1588 state->monitor = NULL; 1641 state->monitor = NULL;
1589} 1642}
1590 1643
1644/*
1645 * Slots fan control loop
1646 */
1647static void do_monitor_slots(struct slots_pid_state *state)
1648{
1649 s32 temp, integral, derivative;
1650 s64 integ_p, deriv_p, prop_p, sum;
1651 int i, rc;
1652
1653 if (--state->ticks != 0)
1654 return;
1655 state->ticks = SLOTS_PID_INTERVAL;
1656
1657 DBG("slots:\n");
1658
1659 /* Check fan status */
1660 rc = get_pwm_fan(SLOTS_FAN_PWM_INDEX);
1661 if (rc < 0) {
1662 printk(KERN_WARNING "Error %d reading slots fan !\n", rc);
1663 /* XXX What do we do now ? */
1664 } else
1665 state->pwm = rc;
1666 DBG(" current pwm: %d\n", state->pwm);
1667
1668 /* Get some sensor readings */
1669 temp = le16_to_cpu(i2c_smbus_read_word_data(state->monitor,
1670 DS1775_TEMP)) << 8;
1671 state->last_temp = temp;
1672 DBG(" temp: %d.%03d, target: %d.%03d\n", FIX32TOPRINT(temp),
1673 FIX32TOPRINT(SLOTS_PID_INPUT_TARGET));
1674
1675 /* Store temperature and error in history array */
1676 state->cur_sample = (state->cur_sample + 1) % SLOTS_PID_HISTORY_SIZE;
1677 state->sample_history[state->cur_sample] = temp;
1678 state->error_history[state->cur_sample] = temp - SLOTS_PID_INPUT_TARGET;
1679
1680 /* If first loop, fill the history table */
1681 if (state->first) {
1682 for (i = 0; i < (SLOTS_PID_HISTORY_SIZE - 1); i++) {
1683 state->cur_sample = (state->cur_sample + 1) %
1684 SLOTS_PID_HISTORY_SIZE;
1685 state->sample_history[state->cur_sample] = temp;
1686 state->error_history[state->cur_sample] =
1687 temp - SLOTS_PID_INPUT_TARGET;
1688 }
1689 state->first = 0;
1690 }
1691
1692 /* Calculate the integral term */
1693 sum = 0;
1694 integral = 0;
1695 for (i = 0; i < SLOTS_PID_HISTORY_SIZE; i++)
1696 integral += state->error_history[i];
1697 integral *= SLOTS_PID_INTERVAL;
1698 DBG(" integral: %08x\n", integral);
1699 integ_p = ((s64)SLOTS_PID_G_r) * (s64)integral;
1700 DBG(" integ_p: %d\n", (int)(integ_p >> 36));
1701 sum += integ_p;
1702
1703 /* Calculate the derivative term */
1704 derivative = state->error_history[state->cur_sample] -
1705 state->error_history[(state->cur_sample + SLOTS_PID_HISTORY_SIZE - 1)
1706 % SLOTS_PID_HISTORY_SIZE];
1707 derivative /= SLOTS_PID_INTERVAL;
1708 deriv_p = ((s64)SLOTS_PID_G_d) * (s64)derivative;
1709 DBG(" deriv_p: %d\n", (int)(deriv_p >> 36));
1710 sum += deriv_p;
1711
1712 /* Calculate the proportional term */
1713 prop_p = ((s64)SLOTS_PID_G_p) * (s64)(state->error_history[state->cur_sample]);
1714 DBG(" prop_p: %d\n", (int)(prop_p >> 36));
1715 sum += prop_p;
1716
1717 /* Scale sum */
1718 sum >>= 36;
1719
1720 DBG(" sum: %d\n", (int)sum);
1721 state->pwm = (s32)sum;
1722
1723 state->pwm = max(state->pwm, SLOTS_PID_OUTPUT_MIN);
1724 state->pwm = min(state->pwm, SLOTS_PID_OUTPUT_MAX);
1725
1726 DBG("** DRIVES PWM: %d\n", (int)state->pwm);
1727 set_pwm_fan(SLOTS_FAN_PWM_INDEX, state->pwm);
1728}
1729
1730/*
1731 * Initialize the state structure for the slots bay fan control loop
1732 */
1733static int init_slots_state(struct slots_pid_state *state)
1734{
1735 state->ticks = 1;
1736 state->first = 1;
1737 state->pwm = 50;
1738
1739 state->monitor = attach_i2c_chip(XSERVE_SLOTS_LM75, "slots_temp");
1740 if (state->monitor == NULL)
1741 return -ENODEV;
1742
1743 device_create_file(&of_dev->dev, &dev_attr_slots_temperature);
1744 device_create_file(&of_dev->dev, &dev_attr_slots_fan_pwm);
1745
1746 return 0;
1747}
1748
1749/*
1750 * Dispose of the state data for the slots control loop
1751 */
1752static void dispose_slots_state(struct slots_pid_state *state)
1753{
1754 if (state->monitor == NULL)
1755 return;
1756
1757 device_remove_file(&of_dev->dev, &dev_attr_slots_temperature);
1758 device_remove_file(&of_dev->dev, &dev_attr_slots_fan_pwm);
1759
1760 detach_i2c_chip(state->monitor);
1761 state->monitor = NULL;
1762}
1763
1764
1591static int call_critical_overtemp(void) 1765static int call_critical_overtemp(void)
1592{ 1766{
1593 char *argv[] = { critical_overtemp_path, NULL }; 1767 char *argv[] = { critical_overtemp_path, NULL };
@@ -1617,14 +1791,17 @@ static int main_control_loop(void *x)
1617 goto out; 1791 goto out;
1618 } 1792 }
1619 1793
1620 /* Set the PCI fan once for now */ 1794 /* Set the PCI fan once for now on non-RackMac */
1621 set_pwm_fan(SLOTS_FAN_PWM_INDEX, SLOTS_FAN_DEFAULT_PWM); 1795 if (!rackmac)
1796 set_pwm_fan(SLOTS_FAN_PWM_INDEX, SLOTS_FAN_DEFAULT_PWM);
1622 1797
1623 /* Initialize ADCs */ 1798 /* Initialize ADCs */
1624 initialize_adc(&cpu_state[0]); 1799 initialize_adc(&cpu_state[0]);
1625 if (cpu_state[1].monitor != NULL) 1800 if (cpu_state[1].monitor != NULL)
1626 initialize_adc(&cpu_state[1]); 1801 initialize_adc(&cpu_state[1]);
1627 1802
1803 fcu_tickle_ticks = FCU_TICKLE_TICKS;
1804
1628 up(&driver_lock); 1805 up(&driver_lock);
1629 1806
1630 while (state == state_attached) { 1807 while (state == state_attached) {
@@ -1634,6 +1811,12 @@ static int main_control_loop(void *x)
1634 1811
1635 down(&driver_lock); 1812 down(&driver_lock);
1636 1813
1814 /* Tickle the FCU just in case */
1815 if (--fcu_tickle_ticks < 0) {
1816 fcu_tickle_ticks = FCU_TICKLE_TICKS;
1817 tickle_fcu();
1818 }
1819
1637 /* First, we always calculate the new DIMMs state on an Xserve */ 1820 /* First, we always calculate the new DIMMs state on an Xserve */
1638 if (rackmac) 1821 if (rackmac)
1639 do_monitor_dimms(&dimms_state); 1822 do_monitor_dimms(&dimms_state);
@@ -1654,7 +1837,9 @@ static int main_control_loop(void *x)
1654 } 1837 }
1655 /* Then, the rest */ 1838 /* Then, the rest */
1656 do_monitor_backside(&backside_state); 1839 do_monitor_backside(&backside_state);
1657 if (!rackmac) 1840 if (rackmac)
1841 do_monitor_slots(&slots_state);
1842 else
1658 do_monitor_drives(&drives_state); 1843 do_monitor_drives(&drives_state);
1659 up(&driver_lock); 1844 up(&driver_lock);
1660 1845
@@ -1696,6 +1881,7 @@ static void dispose_control_loops(void)
1696 dispose_cpu_state(&cpu_state[1]); 1881 dispose_cpu_state(&cpu_state[1]);
1697 dispose_backside_state(&backside_state); 1882 dispose_backside_state(&backside_state);
1698 dispose_drives_state(&drives_state); 1883 dispose_drives_state(&drives_state);
1884 dispose_slots_state(&slots_state);
1699 dispose_dimms_state(&dimms_state); 1885 dispose_dimms_state(&dimms_state);
1700} 1886}
1701 1887
@@ -1745,6 +1931,8 @@ static int create_control_loops(void)
1745 goto fail; 1931 goto fail;
1746 if (rackmac && init_dimms_state(&dimms_state)) 1932 if (rackmac && init_dimms_state(&dimms_state))
1747 goto fail; 1933 goto fail;
1934 if (rackmac && init_slots_state(&slots_state))
1935 goto fail;
1748 if (!rackmac && init_drives_state(&drives_state)) 1936 if (!rackmac && init_drives_state(&drives_state))
1749 goto fail; 1937 goto fail;
1750 1938
diff --git a/drivers/macintosh/therm_pm72.h b/drivers/macintosh/therm_pm72.h
index fc7e9b7ecaf2..393cc9df94e1 100644
--- a/drivers/macintosh/therm_pm72.h
+++ b/drivers/macintosh/therm_pm72.h
@@ -105,6 +105,7 @@ static char * critical_overtemp_path = "/sbin/critical_overtemp";
105#define DRIVES_DALLAS_ID 0x94 105#define DRIVES_DALLAS_ID 0x94
106#define BACKSIDE_MAX_ID 0x98 106#define BACKSIDE_MAX_ID 0x98
107#define XSERVE_DIMMS_LM87 0x25a 107#define XSERVE_DIMMS_LM87 0x25a
108#define XSERVE_SLOTS_LM75 0x290
108 109
109/* 110/*
110 * Some MAX6690, DS1775, LM87 register definitions 111 * Some MAX6690, DS1775, LM87 register definitions
@@ -198,7 +199,7 @@ struct drives_pid_state
198 199
199#define SLOTS_FAN_PWM_DEFAULT_ID 2 200#define SLOTS_FAN_PWM_DEFAULT_ID 2
200#define SLOTS_FAN_PWM_INDEX 2 201#define SLOTS_FAN_PWM_INDEX 2
201#define SLOTS_FAN_DEFAULT_PWM 50 /* Do better here ! */ 202#define SLOTS_FAN_DEFAULT_PWM 40 /* Do better here ! */
202 203
203 204
204/* 205/*
@@ -206,7 +207,7 @@ struct drives_pid_state
206 */ 207 */
207#define DIMM_PID_G_d 0 208#define DIMM_PID_G_d 0
208#define DIMM_PID_G_p 0 209#define DIMM_PID_G_p 0
209#define DIMM_PID_G_r 0x6553600 210#define DIMM_PID_G_r 0x06553600
210#define DIMM_PID_INPUT_TARGET 3276800 211#define DIMM_PID_INPUT_TARGET 3276800
211#define DIMM_PID_INTERVAL 1 212#define DIMM_PID_INTERVAL 1
212#define DIMM_PID_OUTPUT_MAX 14000 213#define DIMM_PID_OUTPUT_MAX 14000
@@ -226,6 +227,31 @@ struct dimm_pid_state
226}; 227};
227 228
228 229
230/*
231 * PID factors for the Xserve Slots control loop
232 */
233#define SLOTS_PID_G_d 0
234#define SLOTS_PID_G_p 0
235#define SLOTS_PID_G_r 0x00100000
236#define SLOTS_PID_INPUT_TARGET 3200000
237#define SLOTS_PID_INTERVAL 1
238#define SLOTS_PID_OUTPUT_MAX 100
239#define SLOTS_PID_OUTPUT_MIN 20
240#define SLOTS_PID_HISTORY_SIZE 20
241
242struct slots_pid_state
243{
244 int ticks;
245 struct i2c_client * monitor;
246 s32 sample_history[SLOTS_PID_HISTORY_SIZE];
247 s32 error_history[SLOTS_PID_HISTORY_SIZE];
248 int cur_sample;
249 s32 last_temp;
250 int first;
251 int pwm;
252};
253
254
229 255
230/* Desktops */ 256/* Desktops */
231 257
@@ -283,6 +309,9 @@ struct cpu_pid_state
283 s32 pump_max; 309 s32 pump_max;
284}; 310};
285 311
312/* Tickle FCU every 10 seconds */
313#define FCU_TICKLE_TICKS 10
314
286/* 315/*
287 * Driver state 316 * Driver state
288 */ 317 */