diff options
Diffstat (limited to 'drivers/macintosh/therm_pm72.c')
-rw-r--r-- | drivers/macintosh/therm_pm72.c | 110 |
1 files changed, 45 insertions, 65 deletions
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c index 44549272333c..0ff92c208005 100644 --- a/drivers/macintosh/therm_pm72.c +++ b/drivers/macintosh/therm_pm72.c | |||
@@ -44,11 +44,11 @@ | |||
44 | * TODO: - Check MPU structure version/signature | 44 | * TODO: - Check MPU structure version/signature |
45 | * - Add things like /sbin/overtemp for non-critical | 45 | * - Add things like /sbin/overtemp for non-critical |
46 | * overtemp conditions so userland can take some policy | 46 | * overtemp conditions so userland can take some policy |
47 | * decisions, like slewing down CPUs | 47 | * decisions, like slowing down CPUs |
48 | * - Deal with fan and i2c failures in a better way | 48 | * - Deal with fan and i2c failures in a better way |
49 | * - Maybe do a generic PID based on params used for | 49 | * - Maybe do a generic PID based on params used for |
50 | * U3 and Drives ? Definitely need to factor code a bit | 50 | * U3 and Drives ? Definitely need to factor code a bit |
51 | * bettter... also make sensor detection more robust using | 51 | * better... also make sensor detection more robust using |
52 | * the device-tree to probe for them | 52 | * the device-tree to probe for them |
53 | * - Figure out how to get the slots consumption and set the | 53 | * - Figure out how to get the slots consumption and set the |
54 | * slots fan accordingly | 54 | * slots fan accordingly |
@@ -91,7 +91,7 @@ | |||
91 | * | 91 | * |
92 | * Mar. 10, 2005 : 1.2 | 92 | * Mar. 10, 2005 : 1.2 |
93 | * - Add basic support for Xserve G5 | 93 | * - Add basic support for Xserve G5 |
94 | * - Retreive pumps min/max from EEPROM image in device-tree (broken) | 94 | * - Retrieve pumps min/max from EEPROM image in device-tree (broken) |
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 | * |
@@ -153,7 +153,7 @@ static struct i2c_adapter * u3_0; | |||
153 | static struct i2c_adapter * u3_1; | 153 | static struct i2c_adapter * u3_1; |
154 | static struct i2c_adapter * k2; | 154 | static struct i2c_adapter * k2; |
155 | static struct i2c_client * fcu; | 155 | static struct i2c_client * fcu; |
156 | static struct cpu_pid_state cpu_state[2]; | 156 | static struct cpu_pid_state processor_state[2]; |
157 | static struct basckside_pid_params backside_params; | 157 | static struct basckside_pid_params backside_params; |
158 | static struct backside_pid_state backside_state; | 158 | static struct backside_pid_state backside_state; |
159 | static struct drives_pid_state drives_state; | 159 | static struct drives_pid_state drives_state; |
@@ -375,7 +375,7 @@ static int read_smon_adc(struct cpu_pid_state *state, int chan) | |||
375 | rc = i2c_master_send(state->monitor, buf, 2); | 375 | rc = i2c_master_send(state->monitor, buf, 2); |
376 | if (rc <= 0) | 376 | if (rc <= 0) |
377 | goto error; | 377 | goto error; |
378 | /* Wait for convertion */ | 378 | /* Wait for conversion */ |
379 | msleep(1); | 379 | msleep(1); |
380 | /* Switch to data register */ | 380 | /* Switch to data register */ |
381 | buf[0] = 4; | 381 | buf[0] = 4; |
@@ -443,7 +443,7 @@ static int fan_read_reg(int reg, unsigned char *buf, int nb) | |||
443 | tries = 0; | 443 | tries = 0; |
444 | for (;;) { | 444 | for (;;) { |
445 | nr = i2c_master_recv(fcu, buf, nb); | 445 | nr = i2c_master_recv(fcu, buf, nb); |
446 | if (nr > 0 || (nr < 0 && nr != ENODEV) || tries >= 100) | 446 | if (nr > 0 || (nr < 0 && nr != -ENODEV) || tries >= 100) |
447 | break; | 447 | break; |
448 | msleep(10); | 448 | msleep(10); |
449 | ++tries; | 449 | ++tries; |
@@ -464,7 +464,7 @@ static int fan_write_reg(int reg, const unsigned char *ptr, int nb) | |||
464 | tries = 0; | 464 | tries = 0; |
465 | for (;;) { | 465 | for (;;) { |
466 | nw = i2c_master_send(fcu, buf, nb); | 466 | nw = i2c_master_send(fcu, buf, nb); |
467 | if (nw > 0 || (nw < 0 && nw != EIO) || tries >= 100) | 467 | if (nw > 0 || (nw < 0 && nw != -EIO) || tries >= 100) |
468 | break; | 468 | break; |
469 | msleep(10); | 469 | msleep(10); |
470 | ++tries; | 470 | ++tries; |
@@ -664,8 +664,8 @@ static int read_eeprom(int cpu, struct mpu_data *out) | |||
664 | 664 | ||
665 | static void fetch_cpu_pumps_minmax(void) | 665 | static void fetch_cpu_pumps_minmax(void) |
666 | { | 666 | { |
667 | struct cpu_pid_state *state0 = &cpu_state[0]; | 667 | struct cpu_pid_state *state0 = &processor_state[0]; |
668 | struct cpu_pid_state *state1 = &cpu_state[1]; | 668 | struct cpu_pid_state *state1 = &processor_state[1]; |
669 | u16 pump_min = 0, pump_max = 0xffff; | 669 | u16 pump_min = 0, pump_max = 0xffff; |
670 | u16 tmp[4]; | 670 | u16 tmp[4]; |
671 | 671 | ||
@@ -717,17 +717,17 @@ static ssize_t show_##name(struct device *dev, struct device_attribute *attr, ch | |||
717 | return sprintf(buf, "%d", data); \ | 717 | return sprintf(buf, "%d", data); \ |
718 | } | 718 | } |
719 | 719 | ||
720 | BUILD_SHOW_FUNC_FIX(cpu0_temperature, cpu_state[0].last_temp) | 720 | BUILD_SHOW_FUNC_FIX(cpu0_temperature, processor_state[0].last_temp) |
721 | BUILD_SHOW_FUNC_FIX(cpu0_voltage, cpu_state[0].voltage) | 721 | BUILD_SHOW_FUNC_FIX(cpu0_voltage, processor_state[0].voltage) |
722 | BUILD_SHOW_FUNC_FIX(cpu0_current, cpu_state[0].current_a) | 722 | BUILD_SHOW_FUNC_FIX(cpu0_current, processor_state[0].current_a) |
723 | BUILD_SHOW_FUNC_INT(cpu0_exhaust_fan_rpm, cpu_state[0].rpm) | 723 | BUILD_SHOW_FUNC_INT(cpu0_exhaust_fan_rpm, processor_state[0].rpm) |
724 | BUILD_SHOW_FUNC_INT(cpu0_intake_fan_rpm, cpu_state[0].intake_rpm) | 724 | BUILD_SHOW_FUNC_INT(cpu0_intake_fan_rpm, processor_state[0].intake_rpm) |
725 | 725 | ||
726 | BUILD_SHOW_FUNC_FIX(cpu1_temperature, cpu_state[1].last_temp) | 726 | BUILD_SHOW_FUNC_FIX(cpu1_temperature, processor_state[1].last_temp) |
727 | BUILD_SHOW_FUNC_FIX(cpu1_voltage, cpu_state[1].voltage) | 727 | BUILD_SHOW_FUNC_FIX(cpu1_voltage, processor_state[1].voltage) |
728 | BUILD_SHOW_FUNC_FIX(cpu1_current, cpu_state[1].current_a) | 728 | BUILD_SHOW_FUNC_FIX(cpu1_current, processor_state[1].current_a) |
729 | BUILD_SHOW_FUNC_INT(cpu1_exhaust_fan_rpm, cpu_state[1].rpm) | 729 | BUILD_SHOW_FUNC_INT(cpu1_exhaust_fan_rpm, processor_state[1].rpm) |
730 | BUILD_SHOW_FUNC_INT(cpu1_intake_fan_rpm, cpu_state[1].intake_rpm) | 730 | BUILD_SHOW_FUNC_INT(cpu1_intake_fan_rpm, processor_state[1].intake_rpm) |
731 | 731 | ||
732 | BUILD_SHOW_FUNC_FIX(backside_temperature, backside_state.last_temp) | 732 | BUILD_SHOW_FUNC_FIX(backside_temperature, backside_state.last_temp) |
733 | BUILD_SHOW_FUNC_INT(backside_fan_pwm, backside_state.pwm) | 733 | BUILD_SHOW_FUNC_INT(backside_fan_pwm, backside_state.pwm) |
@@ -919,8 +919,8 @@ static void do_cpu_pid(struct cpu_pid_state *state, s32 temp, s32 power) | |||
919 | 919 | ||
920 | static void do_monitor_cpu_combined(void) | 920 | static void do_monitor_cpu_combined(void) |
921 | { | 921 | { |
922 | struct cpu_pid_state *state0 = &cpu_state[0]; | 922 | struct cpu_pid_state *state0 = &processor_state[0]; |
923 | struct cpu_pid_state *state1 = &cpu_state[1]; | 923 | struct cpu_pid_state *state1 = &processor_state[1]; |
924 | s32 temp0, power0, temp1, power1; | 924 | s32 temp0, power0, temp1, power1; |
925 | s32 temp_combi, power_combi; | 925 | s32 temp_combi, power_combi; |
926 | int rc, intake, pump; | 926 | int rc, intake, pump; |
@@ -1150,7 +1150,7 @@ static void do_monitor_cpu_rack(struct cpu_pid_state *state) | |||
1150 | /* | 1150 | /* |
1151 | * Initialize the state structure for one CPU control loop | 1151 | * Initialize the state structure for one CPU control loop |
1152 | */ | 1152 | */ |
1153 | static int init_cpu_state(struct cpu_pid_state *state, int index) | 1153 | static int init_processor_state(struct cpu_pid_state *state, int index) |
1154 | { | 1154 | { |
1155 | int err; | 1155 | int err; |
1156 | 1156 | ||
@@ -1192,7 +1192,7 @@ static int init_cpu_state(struct cpu_pid_state *state, int index) | |||
1192 | err |= device_create_file(&of_dev->dev, &dev_attr_cpu1_intake_fan_rpm); | 1192 | err |= device_create_file(&of_dev->dev, &dev_attr_cpu1_intake_fan_rpm); |
1193 | } | 1193 | } |
1194 | if (err) | 1194 | if (err) |
1195 | printk(KERN_WARNING "Failed to create some of the atribute" | 1195 | printk(KERN_WARNING "Failed to create some of the attribute" |
1196 | "files for CPU %d\n", index); | 1196 | "files for CPU %d\n", index); |
1197 | 1197 | ||
1198 | return 0; | 1198 | return 0; |
@@ -1205,7 +1205,7 @@ static int init_cpu_state(struct cpu_pid_state *state, int index) | |||
1205 | /* | 1205 | /* |
1206 | * Dispose of the state data for one CPU control loop | 1206 | * Dispose of the state data for one CPU control loop |
1207 | */ | 1207 | */ |
1208 | static void dispose_cpu_state(struct cpu_pid_state *state) | 1208 | static void dispose_processor_state(struct cpu_pid_state *state) |
1209 | { | 1209 | { |
1210 | if (state->monitor == NULL) | 1210 | if (state->monitor == NULL) |
1211 | return; | 1211 | return; |
@@ -1804,9 +1804,9 @@ static int main_control_loop(void *x) | |||
1804 | set_pwm_fan(SLOTS_FAN_PWM_INDEX, SLOTS_FAN_DEFAULT_PWM); | 1804 | set_pwm_fan(SLOTS_FAN_PWM_INDEX, SLOTS_FAN_DEFAULT_PWM); |
1805 | 1805 | ||
1806 | /* Initialize ADCs */ | 1806 | /* Initialize ADCs */ |
1807 | initialize_adc(&cpu_state[0]); | 1807 | initialize_adc(&processor_state[0]); |
1808 | if (cpu_state[1].monitor != NULL) | 1808 | if (processor_state[1].monitor != NULL) |
1809 | initialize_adc(&cpu_state[1]); | 1809 | initialize_adc(&processor_state[1]); |
1810 | 1810 | ||
1811 | fcu_tickle_ticks = FCU_TICKLE_TICKS; | 1811 | fcu_tickle_ticks = FCU_TICKLE_TICKS; |
1812 | 1812 | ||
@@ -1833,14 +1833,14 @@ static int main_control_loop(void *x) | |||
1833 | if (cpu_pid_type == CPU_PID_TYPE_COMBINED) | 1833 | if (cpu_pid_type == CPU_PID_TYPE_COMBINED) |
1834 | do_monitor_cpu_combined(); | 1834 | do_monitor_cpu_combined(); |
1835 | else if (cpu_pid_type == CPU_PID_TYPE_RACKMAC) { | 1835 | else if (cpu_pid_type == CPU_PID_TYPE_RACKMAC) { |
1836 | do_monitor_cpu_rack(&cpu_state[0]); | 1836 | do_monitor_cpu_rack(&processor_state[0]); |
1837 | if (cpu_state[1].monitor != NULL) | 1837 | if (processor_state[1].monitor != NULL) |
1838 | do_monitor_cpu_rack(&cpu_state[1]); | 1838 | do_monitor_cpu_rack(&processor_state[1]); |
1839 | // better deal with UP | 1839 | // better deal with UP |
1840 | } else { | 1840 | } else { |
1841 | do_monitor_cpu_split(&cpu_state[0]); | 1841 | do_monitor_cpu_split(&processor_state[0]); |
1842 | if (cpu_state[1].monitor != NULL) | 1842 | if (processor_state[1].monitor != NULL) |
1843 | do_monitor_cpu_split(&cpu_state[1]); | 1843 | do_monitor_cpu_split(&processor_state[1]); |
1844 | // better deal with UP | 1844 | // better deal with UP |
1845 | } | 1845 | } |
1846 | /* Then, the rest */ | 1846 | /* Then, the rest */ |
@@ -1885,8 +1885,8 @@ static int main_control_loop(void *x) | |||
1885 | */ | 1885 | */ |
1886 | static void dispose_control_loops(void) | 1886 | static void dispose_control_loops(void) |
1887 | { | 1887 | { |
1888 | dispose_cpu_state(&cpu_state[0]); | 1888 | dispose_processor_state(&processor_state[0]); |
1889 | dispose_cpu_state(&cpu_state[1]); | 1889 | dispose_processor_state(&processor_state[1]); |
1890 | dispose_backside_state(&backside_state); | 1890 | dispose_backside_state(&backside_state); |
1891 | dispose_drives_state(&drives_state); | 1891 | dispose_drives_state(&drives_state); |
1892 | dispose_slots_state(&slots_state); | 1892 | dispose_slots_state(&slots_state); |
@@ -1928,12 +1928,12 @@ static int create_control_loops(void) | |||
1928 | /* Create control loops for everything. If any fail, everything | 1928 | /* Create control loops for everything. If any fail, everything |
1929 | * fails | 1929 | * fails |
1930 | */ | 1930 | */ |
1931 | if (init_cpu_state(&cpu_state[0], 0)) | 1931 | if (init_processor_state(&processor_state[0], 0)) |
1932 | goto fail; | 1932 | goto fail; |
1933 | if (cpu_pid_type == CPU_PID_TYPE_COMBINED) | 1933 | if (cpu_pid_type == CPU_PID_TYPE_COMBINED) |
1934 | fetch_cpu_pumps_minmax(); | 1934 | fetch_cpu_pumps_minmax(); |
1935 | 1935 | ||
1936 | if (cpu_count > 1 && init_cpu_state(&cpu_state[1], 1)) | 1936 | if (cpu_count > 1 && init_processor_state(&processor_state[1], 1)) |
1937 | goto fail; | 1937 | goto fail; |
1938 | if (init_backside_state(&backside_state)) | 1938 | if (init_backside_state(&backside_state)) |
1939 | goto fail; | 1939 | goto fail; |
@@ -2210,9 +2210,12 @@ static void fcu_lookup_fans(struct device_node *fcu_node) | |||
2210 | } | 2210 | } |
2211 | } | 2211 | } |
2212 | 2212 | ||
2213 | static int fcu_of_probe(struct platform_device* dev, const struct of_device_id *match) | 2213 | static int fcu_of_probe(struct platform_device* dev) |
2214 | { | 2214 | { |
2215 | state = state_detached; | 2215 | state = state_detached; |
2216 | of_dev = dev; | ||
2217 | |||
2218 | dev_info(&dev->dev, "PowerMac G5 Thermal control driver %s\n", VERSION); | ||
2216 | 2219 | ||
2217 | /* Lookup the fans in the device tree */ | 2220 | /* Lookup the fans in the device tree */ |
2218 | fcu_lookup_fans(dev->dev.of_node); | 2221 | fcu_lookup_fans(dev->dev.of_node); |
@@ -2235,8 +2238,9 @@ static const struct of_device_id fcu_match[] = | |||
2235 | }, | 2238 | }, |
2236 | {}, | 2239 | {}, |
2237 | }; | 2240 | }; |
2241 | MODULE_DEVICE_TABLE(of, fcu_match); | ||
2238 | 2242 | ||
2239 | static struct of_platform_driver fcu_of_platform_driver = | 2243 | static struct platform_driver fcu_of_platform_driver = |
2240 | { | 2244 | { |
2241 | .driver = { | 2245 | .driver = { |
2242 | .name = "temperature", | 2246 | .name = "temperature", |
@@ -2252,8 +2256,6 @@ static struct of_platform_driver fcu_of_platform_driver = | |||
2252 | */ | 2256 | */ |
2253 | static int __init therm_pm72_init(void) | 2257 | static int __init therm_pm72_init(void) |
2254 | { | 2258 | { |
2255 | struct device_node *np; | ||
2256 | |||
2257 | rackmac = of_machine_is_compatible("RackMac3,1"); | 2259 | rackmac = of_machine_is_compatible("RackMac3,1"); |
2258 | 2260 | ||
2259 | if (!of_machine_is_compatible("PowerMac7,2") && | 2261 | if (!of_machine_is_compatible("PowerMac7,2") && |
@@ -2261,34 +2263,12 @@ static int __init therm_pm72_init(void) | |||
2261 | !rackmac) | 2263 | !rackmac) |
2262 | return -ENODEV; | 2264 | return -ENODEV; |
2263 | 2265 | ||
2264 | printk(KERN_INFO "PowerMac G5 Thermal control driver %s\n", VERSION); | 2266 | return platform_driver_register(&fcu_of_platform_driver); |
2265 | |||
2266 | np = of_find_node_by_type(NULL, "fcu"); | ||
2267 | if (np == NULL) { | ||
2268 | /* Some machines have strangely broken device-tree */ | ||
2269 | np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e"); | ||
2270 | if (np == NULL) { | ||
2271 | printk(KERN_ERR "Can't find FCU in device-tree !\n"); | ||
2272 | return -ENODEV; | ||
2273 | } | ||
2274 | } | ||
2275 | of_dev = of_platform_device_create(np, "temperature", NULL); | ||
2276 | if (of_dev == NULL) { | ||
2277 | printk(KERN_ERR "Can't register FCU platform device !\n"); | ||
2278 | return -ENODEV; | ||
2279 | } | ||
2280 | |||
2281 | of_register_platform_driver(&fcu_of_platform_driver); | ||
2282 | |||
2283 | return 0; | ||
2284 | } | 2267 | } |
2285 | 2268 | ||
2286 | static void __exit therm_pm72_exit(void) | 2269 | static void __exit therm_pm72_exit(void) |
2287 | { | 2270 | { |
2288 | of_unregister_platform_driver(&fcu_of_platform_driver); | 2271 | platform_driver_unregister(&fcu_of_platform_driver); |
2289 | |||
2290 | if (of_dev) | ||
2291 | of_device_unregister(of_dev); | ||
2292 | } | 2272 | } |
2293 | 2273 | ||
2294 | module_init(therm_pm72_init); | 2274 | module_init(therm_pm72_init); |