[PATCH] therm_adt746x: show correct sensor locations

This patch shows the correct locations of the heat sensors present in iBook
and PowerBooks G4, instead of displaying them as being on CPU and GPU
(which is not always the case).

Signed-off-by: Colin Leroy <colin@colino.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Colin Leroy and committed by Linus Torvalds d20c507f a8bacec0

+77 -42
+77 -42
drivers/macintosh/therm_adt746x.c
··· 39 39 #define MANUAL_MASK 0xe0 40 40 #define AUTO_MASK 0x20 41 41 42 - static u8 TEMP_REG[3] = {0x26, 0x25, 0x27}; /* local, cpu, gpu */ 43 - static u8 LIMIT_REG[3] = {0x6b, 0x6a, 0x6c}; /* local, cpu, gpu */ 42 + static u8 TEMP_REG[3] = {0x26, 0x25, 0x27}; /* local, sensor1, sensor2 */ 43 + static u8 LIMIT_REG[3] = {0x6b, 0x6a, 0x6c}; /* local, sensor1, sensor2 */ 44 44 static u8 MANUAL_MODE[2] = {0x5c, 0x5d}; 45 45 static u8 REM_CONTROL[2] = {0x00, 0x40}; 46 46 static u8 FAN_SPEED[2] = {0x28, 0x2a}; 47 47 static u8 FAN_SPD_SET[2] = {0x30, 0x31}; 48 48 49 - static u8 default_limits_local[3] = {70, 50, 70}; /* local, cpu, gpu */ 50 - static u8 default_limits_chip[3] = {80, 65, 80}; /* local, cpu, gpu */ 49 + static u8 default_limits_local[3] = {70, 50, 70}; /* local, sensor1, sensor2 */ 50 + static u8 default_limits_chip[3] = {80, 65, 80}; /* local, sensor1, sensor2 */ 51 + static char *sensor_location[3] = {NULL, NULL, NULL}; 51 52 52 53 static int limit_adjust = 0; 53 54 static int fan_speed = -1; ··· 59 58 MODULE_LICENSE("GPL"); 60 59 61 60 module_param(limit_adjust, int, 0644); 62 - MODULE_PARM_DESC(limit_adjust,"Adjust maximum temperatures (50 cpu, 70 gpu) " 61 + MODULE_PARM_DESC(limit_adjust,"Adjust maximum temperatures (50 sensor1, 70 sensor2) " 63 62 "by N degrees."); 64 63 65 64 module_param(fan_speed, int, 0644); ··· 214 213 if (th->last_speed[fan] != speed) { 215 214 if (speed == -1) 216 215 printk(KERN_DEBUG "adt746x: Setting speed to automatic " 217 - "for %s fan.\n", fan?"GPU":"CPU"); 216 + "for %s fan.\n", sensor_location[fan+1]); 218 217 else 219 218 printk(KERN_DEBUG "adt746x: Setting speed to %d " 220 - "for %s fan.\n", speed, fan?"GPU":"CPU"); 219 + "for %s fan.\n", speed, sensor_location[fan+1]); 221 220 } else 222 221 return; 223 222 ··· 301 300 printk(KERN_DEBUG "adt746x: setting fans speed to %d " 302 301 "(limit exceeded by %d on %s) \n", 303 302 new_speed, var, 304 - fan_number?"GPU/pwr":"CPU"); 303 + sensor_location[fan_number+1]); 305 304 write_both_fan_speed(th, new_speed); 306 305 th->last_var[fan_number] = var; 307 306 } else if (var < -2) { 308 - /* don't stop fan if GPU/power is cold and CPU is not 307 + /* don't stop fan if sensor2 is cold and sensor1 is not 309 308 * so cold (lastvar >= -1) */ 310 309 if (i == 2 && lastvar < -1) { 311 310 if (th->last_speed[fan_number] != 0) ··· 319 318 320 319 if (started) 321 320 return; /* we don't want to re-stop the fan 322 - * if CPU is heating and GPU/power is not */ 321 + * if sensor1 is heating and sensor2 is not */ 323 322 } 324 323 } 325 324 ··· 354 353 355 354 static void set_limit(struct thermostat *th, int i) 356 355 { 357 - /* Set CPU limit higher to avoid powerdowns */ 356 + /* Set sensor1 limit higher to avoid powerdowns */ 358 357 th->limits[i] = default_limits_chip[i] + limit_adjust; 359 358 write_reg(th, LIMIT_REG[i], th->limits[i]); 360 359 ··· 462 461 return sprintf(buf, "%d\n", data); \ 463 462 } 464 463 464 + #define BUILD_SHOW_FUNC_STR(name, data) \ 465 + static ssize_t show_##name(struct device *dev, char *buf) \ 466 + { \ 467 + return sprintf(buf, "%s\n", data); \ 468 + } 469 + 465 470 #define BUILD_SHOW_FUNC_FAN(name, data) \ 466 471 static ssize_t show_##name(struct device *dev, char *buf) \ 467 472 { \ ··· 483 476 int val; \ 484 477 int i; \ 485 478 val = simple_strtol(buf, NULL, 10); \ 486 - printk(KERN_INFO "Adjusting limits by %d�C\n", val); \ 479 + printk(KERN_INFO "Adjusting limits by %d degrees\n", val); \ 487 480 limit_adjust = val; \ 488 481 for (i=0; i < 3; i++) \ 489 482 set_limit(thermostat, i); \ ··· 502 495 return n; \ 503 496 } 504 497 505 - BUILD_SHOW_FUNC_INT(cpu_temperature, (read_reg(thermostat, TEMP_REG[1]))) 506 - BUILD_SHOW_FUNC_INT(gpu_temperature, (read_reg(thermostat, TEMP_REG[2]))) 507 - BUILD_SHOW_FUNC_INT(cpu_limit, thermostat->limits[1]) 508 - BUILD_SHOW_FUNC_INT(gpu_limit, thermostat->limits[2]) 498 + BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(thermostat, TEMP_REG[1]))) 499 + BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(thermostat, TEMP_REG[2]))) 500 + BUILD_SHOW_FUNC_INT(sensor1_limit, thermostat->limits[1]) 501 + BUILD_SHOW_FUNC_INT(sensor2_limit, thermostat->limits[2]) 502 + BUILD_SHOW_FUNC_STR(sensor1_location, sensor_location[1]) 503 + BUILD_SHOW_FUNC_STR(sensor2_location, sensor_location[2]) 509 504 510 505 BUILD_SHOW_FUNC_INT(specified_fan_speed, fan_speed) 511 - BUILD_SHOW_FUNC_FAN(cpu_fan_speed, 0) 512 - BUILD_SHOW_FUNC_FAN(gpu_fan_speed, 1) 506 + BUILD_SHOW_FUNC_FAN(sensor1_fan_speed, 0) 507 + BUILD_SHOW_FUNC_FAN(sensor2_fan_speed, 1) 513 508 514 509 BUILD_STORE_FUNC_INT(specified_fan_speed,fan_speed) 515 510 BUILD_SHOW_FUNC_INT(limit_adjust, limit_adjust) 516 511 BUILD_STORE_FUNC_DEG(limit_adjust, thermostat) 517 512 518 - static DEVICE_ATTR(cpu_temperature, S_IRUGO, 519 - show_cpu_temperature,NULL); 520 - static DEVICE_ATTR(gpu_temperature, S_IRUGO, 521 - show_gpu_temperature,NULL); 522 - static DEVICE_ATTR(cpu_limit, S_IRUGO, 523 - show_cpu_limit, NULL); 524 - static DEVICE_ATTR(gpu_limit, S_IRUGO, 525 - show_gpu_limit, NULL); 513 + static DEVICE_ATTR(sensor1_temperature, S_IRUGO, 514 + show_sensor1_temperature,NULL); 515 + static DEVICE_ATTR(sensor2_temperature, S_IRUGO, 516 + show_sensor2_temperature,NULL); 517 + static DEVICE_ATTR(sensor1_limit, S_IRUGO, 518 + show_sensor1_limit, NULL); 519 + static DEVICE_ATTR(sensor2_limit, S_IRUGO, 520 + show_sensor2_limit, NULL); 521 + static DEVICE_ATTR(sensor1_location, S_IRUGO, 522 + show_sensor1_location, NULL); 523 + static DEVICE_ATTR(sensor2_location, S_IRUGO, 524 + show_sensor2_location, NULL); 526 525 527 526 static DEVICE_ATTR(specified_fan_speed, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, 528 527 show_specified_fan_speed,store_specified_fan_speed); 529 528 530 - static DEVICE_ATTR(cpu_fan_speed, S_IRUGO, 531 - show_cpu_fan_speed, NULL); 532 - static DEVICE_ATTR(gpu_fan_speed, S_IRUGO, 533 - show_gpu_fan_speed, NULL); 529 + static DEVICE_ATTR(sensor1_fan_speed, S_IRUGO, 530 + show_sensor1_fan_speed, NULL); 531 + static DEVICE_ATTR(sensor2_fan_speed, S_IRUGO, 532 + show_sensor2_fan_speed, NULL); 534 533 535 534 static DEVICE_ATTR(limit_adjust, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, 536 535 show_limit_adjust, store_limit_adjust); ··· 547 534 { 548 535 struct device_node* np; 549 536 u32 *prop; 537 + int i = 0, offset = 0; 550 538 551 539 np = of_find_node_by_name(NULL, "fan"); 552 540 if (!np) ··· 583 569 "limit_adjust: %d, fan_speed: %d\n", 584 570 therm_bus, therm_address, limit_adjust, fan_speed); 585 571 572 + if (get_property(np, "hwsensor-location", NULL)) { 573 + for (i = 0; i < 3; i++) { 574 + sensor_location[i] = get_property(np, 575 + "hwsensor-location", NULL) + offset; 576 + 577 + if (sensor_location[i] == NULL) 578 + sensor_location[i] = ""; 579 + 580 + printk(KERN_INFO "sensor %d: %s\n", i, sensor_location[i]); 581 + offset += strlen(sensor_location[i]) + 1; 582 + } 583 + } else { 584 + sensor_location[0] = "?"; 585 + sensor_location[1] = "?"; 586 + sensor_location[2] = "?"; 587 + } 588 + 586 589 of_dev = of_platform_device_create(np, "temperatures"); 587 590 588 591 if (of_dev == NULL) { ··· 607 576 return -ENODEV; 608 577 } 609 578 610 - device_create_file(&of_dev->dev, &dev_attr_cpu_temperature); 611 - device_create_file(&of_dev->dev, &dev_attr_gpu_temperature); 612 - device_create_file(&of_dev->dev, &dev_attr_cpu_limit); 613 - device_create_file(&of_dev->dev, &dev_attr_gpu_limit); 579 + device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature); 580 + device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature); 581 + device_create_file(&of_dev->dev, &dev_attr_sensor1_limit); 582 + device_create_file(&of_dev->dev, &dev_attr_sensor2_limit); 583 + device_create_file(&of_dev->dev, &dev_attr_sensor1_location); 584 + device_create_file(&of_dev->dev, &dev_attr_sensor2_location); 614 585 device_create_file(&of_dev->dev, &dev_attr_limit_adjust); 615 586 device_create_file(&of_dev->dev, &dev_attr_specified_fan_speed); 616 - device_create_file(&of_dev->dev, &dev_attr_cpu_fan_speed); 587 + device_create_file(&of_dev->dev, &dev_attr_sensor1_fan_speed); 617 588 if(therm_type == ADT7460) 618 - device_create_file(&of_dev->dev, &dev_attr_gpu_fan_speed); 589 + device_create_file(&of_dev->dev, &dev_attr_sensor2_fan_speed); 619 590 620 591 #ifndef CONFIG_I2C_KEYWEST 621 592 request_module("i2c-keywest"); ··· 630 597 thermostat_exit(void) 631 598 { 632 599 if (of_dev) { 633 - device_remove_file(&of_dev->dev, &dev_attr_cpu_temperature); 634 - device_remove_file(&of_dev->dev, &dev_attr_gpu_temperature); 635 - device_remove_file(&of_dev->dev, &dev_attr_cpu_limit); 636 - device_remove_file(&of_dev->dev, &dev_attr_gpu_limit); 600 + device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature); 601 + device_remove_file(&of_dev->dev, &dev_attr_sensor2_temperature); 602 + device_remove_file(&of_dev->dev, &dev_attr_sensor1_limit); 603 + device_remove_file(&of_dev->dev, &dev_attr_sensor2_limit); 604 + device_remove_file(&of_dev->dev, &dev_attr_sensor1_location); 605 + device_remove_file(&of_dev->dev, &dev_attr_sensor2_location); 637 606 device_remove_file(&of_dev->dev, &dev_attr_limit_adjust); 638 607 device_remove_file(&of_dev->dev, &dev_attr_specified_fan_speed); 639 - device_remove_file(&of_dev->dev, &dev_attr_cpu_fan_speed); 608 + device_remove_file(&of_dev->dev, &dev_attr_sensor1_fan_speed); 640 609 641 610 if(therm_type == ADT7460) 642 611 device_remove_file(&of_dev->dev, 643 - &dev_attr_gpu_fan_speed); 612 + &dev_attr_sensor2_fan_speed); 644 613 645 614 of_device_unregister(of_dev); 646 615 }