diff options
author | Paul Mundt <lethal@linux-sh.org> | 2009-04-13 17:29:07 -0400 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2009-04-13 17:29:07 -0400 |
commit | f499cae1e59d75d5eb24c23d47cf8986e6032c6d (patch) | |
tree | 1af6235c18391212c40116eb90b01eae8938efee /drivers/acpi/thermal.c | |
parent | fc3f55e672e1ed917dd9e215af81939cd3d717da (diff) | |
parent | 80a04d3f2f94fb68b5df05e3ac6697130bc3467a (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers/acpi/thermal.c')
-rw-r--r-- | drivers/acpi/thermal.c | 68 |
1 files changed, 38 insertions, 30 deletions
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index e8c143caf0fd..9cd15e8c8932 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c | |||
@@ -98,6 +98,7 @@ MODULE_PARM_DESC(psv, "Disable or override all passive trip points."); | |||
98 | static int acpi_thermal_add(struct acpi_device *device); | 98 | static int acpi_thermal_add(struct acpi_device *device); |
99 | static int acpi_thermal_remove(struct acpi_device *device, int type); | 99 | static int acpi_thermal_remove(struct acpi_device *device, int type); |
100 | static int acpi_thermal_resume(struct acpi_device *device); | 100 | static int acpi_thermal_resume(struct acpi_device *device); |
101 | static void acpi_thermal_notify(struct acpi_device *device, u32 event); | ||
101 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); | 102 | static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); |
102 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); | 103 | static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); |
103 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); | 104 | static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); |
@@ -123,6 +124,7 @@ static struct acpi_driver acpi_thermal_driver = { | |||
123 | .add = acpi_thermal_add, | 124 | .add = acpi_thermal_add, |
124 | .remove = acpi_thermal_remove, | 125 | .remove = acpi_thermal_remove, |
125 | .resume = acpi_thermal_resume, | 126 | .resume = acpi_thermal_resume, |
127 | .notify = acpi_thermal_notify, | ||
126 | }, | 128 | }, |
127 | }; | 129 | }; |
128 | 130 | ||
@@ -192,6 +194,7 @@ struct acpi_thermal { | |||
192 | struct acpi_handle_list devices; | 194 | struct acpi_handle_list devices; |
193 | struct thermal_zone_device *thermal_zone; | 195 | struct thermal_zone_device *thermal_zone; |
194 | int tz_enabled; | 196 | int tz_enabled; |
197 | int kelvin_offset; | ||
195 | struct mutex lock; | 198 | struct mutex lock; |
196 | }; | 199 | }; |
197 | 200 | ||
@@ -581,7 +584,7 @@ static void acpi_thermal_check(void *data) | |||
581 | } | 584 | } |
582 | 585 | ||
583 | /* sys I/F for generic thermal sysfs support */ | 586 | /* sys I/F for generic thermal sysfs support */ |
584 | #define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200) | 587 | #define KELVIN_TO_MILLICELSIUS(t, off) (((t) - (off)) * 100) |
585 | 588 | ||
586 | static int thermal_get_temp(struct thermal_zone_device *thermal, | 589 | static int thermal_get_temp(struct thermal_zone_device *thermal, |
587 | unsigned long *temp) | 590 | unsigned long *temp) |
@@ -596,7 +599,7 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, | |||
596 | if (result) | 599 | if (result) |
597 | return result; | 600 | return result; |
598 | 601 | ||
599 | *temp = KELVIN_TO_MILLICELSIUS(tz->temperature); | 602 | *temp = KELVIN_TO_MILLICELSIUS(tz->temperature, tz->kelvin_offset); |
600 | return 0; | 603 | return 0; |
601 | } | 604 | } |
602 | 605 | ||
@@ -702,7 +705,8 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, | |||
702 | if (tz->trips.critical.flags.valid) { | 705 | if (tz->trips.critical.flags.valid) { |
703 | if (!trip) { | 706 | if (!trip) { |
704 | *temp = KELVIN_TO_MILLICELSIUS( | 707 | *temp = KELVIN_TO_MILLICELSIUS( |
705 | tz->trips.critical.temperature); | 708 | tz->trips.critical.temperature, |
709 | tz->kelvin_offset); | ||
706 | return 0; | 710 | return 0; |
707 | } | 711 | } |
708 | trip--; | 712 | trip--; |
@@ -711,7 +715,8 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, | |||
711 | if (tz->trips.hot.flags.valid) { | 715 | if (tz->trips.hot.flags.valid) { |
712 | if (!trip) { | 716 | if (!trip) { |
713 | *temp = KELVIN_TO_MILLICELSIUS( | 717 | *temp = KELVIN_TO_MILLICELSIUS( |
714 | tz->trips.hot.temperature); | 718 | tz->trips.hot.temperature, |
719 | tz->kelvin_offset); | ||
715 | return 0; | 720 | return 0; |
716 | } | 721 | } |
717 | trip--; | 722 | trip--; |
@@ -720,7 +725,8 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, | |||
720 | if (tz->trips.passive.flags.valid) { | 725 | if (tz->trips.passive.flags.valid) { |
721 | if (!trip) { | 726 | if (!trip) { |
722 | *temp = KELVIN_TO_MILLICELSIUS( | 727 | *temp = KELVIN_TO_MILLICELSIUS( |
723 | tz->trips.passive.temperature); | 728 | tz->trips.passive.temperature, |
729 | tz->kelvin_offset); | ||
724 | return 0; | 730 | return 0; |
725 | } | 731 | } |
726 | trip--; | 732 | trip--; |
@@ -730,7 +736,8 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, | |||
730 | tz->trips.active[i].flags.valid; i++) { | 736 | tz->trips.active[i].flags.valid; i++) { |
731 | if (!trip) { | 737 | if (!trip) { |
732 | *temp = KELVIN_TO_MILLICELSIUS( | 738 | *temp = KELVIN_TO_MILLICELSIUS( |
733 | tz->trips.active[i].temperature); | 739 | tz->trips.active[i].temperature, |
740 | tz->kelvin_offset); | ||
734 | return 0; | 741 | return 0; |
735 | } | 742 | } |
736 | trip--; | 743 | trip--; |
@@ -745,7 +752,8 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal, | |||
745 | 752 | ||
746 | if (tz->trips.critical.flags.valid) { | 753 | if (tz->trips.critical.flags.valid) { |
747 | *temperature = KELVIN_TO_MILLICELSIUS( | 754 | *temperature = KELVIN_TO_MILLICELSIUS( |
748 | tz->trips.critical.temperature); | 755 | tz->trips.critical.temperature, |
756 | tz->kelvin_offset); | ||
749 | return 0; | 757 | return 0; |
750 | } else | 758 | } else |
751 | return -EINVAL; | 759 | return -EINVAL; |
@@ -1264,17 +1272,14 @@ static int acpi_thermal_remove_fs(struct acpi_device *device) | |||
1264 | Driver Interface | 1272 | Driver Interface |
1265 | -------------------------------------------------------------------------- */ | 1273 | -------------------------------------------------------------------------- */ |
1266 | 1274 | ||
1267 | static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) | 1275 | static void acpi_thermal_notify(struct acpi_device *device, u32 event) |
1268 | { | 1276 | { |
1269 | struct acpi_thermal *tz = data; | 1277 | struct acpi_thermal *tz = acpi_driver_data(device); |
1270 | struct acpi_device *device = NULL; | ||
1271 | 1278 | ||
1272 | 1279 | ||
1273 | if (!tz) | 1280 | if (!tz) |
1274 | return; | 1281 | return; |
1275 | 1282 | ||
1276 | device = tz->device; | ||
1277 | |||
1278 | switch (event) { | 1283 | switch (event) { |
1279 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: | 1284 | case ACPI_THERMAL_NOTIFY_TEMPERATURE: |
1280 | acpi_thermal_check(tz); | 1285 | acpi_thermal_check(tz); |
@@ -1298,8 +1303,6 @@ static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) | |||
1298 | "Unsupported event [0x%x]\n", event)); | 1303 | "Unsupported event [0x%x]\n", event)); |
1299 | break; | 1304 | break; |
1300 | } | 1305 | } |
1301 | |||
1302 | return; | ||
1303 | } | 1306 | } |
1304 | 1307 | ||
1305 | static int acpi_thermal_get_info(struct acpi_thermal *tz) | 1308 | static int acpi_thermal_get_info(struct acpi_thermal *tz) |
@@ -1334,10 +1337,28 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz) | |||
1334 | return 0; | 1337 | return 0; |
1335 | } | 1338 | } |
1336 | 1339 | ||
1340 | /* | ||
1341 | * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI | ||
1342 | * handles temperature values with a single decimal place. As a consequence, | ||
1343 | * some implementations use an offset of 273.1 and others use an offset of | ||
1344 | * 273.2. Try to find out which one is being used, to present the most | ||
1345 | * accurate and visually appealing number. | ||
1346 | * | ||
1347 | * The heuristic below should work for all ACPI thermal zones which have a | ||
1348 | * critical trip point with a value being a multiple of 0.5 degree Celsius. | ||
1349 | */ | ||
1350 | static void acpi_thermal_guess_offset(struct acpi_thermal *tz) | ||
1351 | { | ||
1352 | if (tz->trips.critical.flags.valid && | ||
1353 | (tz->trips.critical.temperature % 5) == 1) | ||
1354 | tz->kelvin_offset = 2731; | ||
1355 | else | ||
1356 | tz->kelvin_offset = 2732; | ||
1357 | } | ||
1358 | |||
1337 | static int acpi_thermal_add(struct acpi_device *device) | 1359 | static int acpi_thermal_add(struct acpi_device *device) |
1338 | { | 1360 | { |
1339 | int result = 0; | 1361 | int result = 0; |
1340 | acpi_status status = AE_OK; | ||
1341 | struct acpi_thermal *tz = NULL; | 1362 | struct acpi_thermal *tz = NULL; |
1342 | 1363 | ||
1343 | 1364 | ||
@@ -1360,6 +1381,8 @@ static int acpi_thermal_add(struct acpi_device *device) | |||
1360 | if (result) | 1381 | if (result) |
1361 | goto free_memory; | 1382 | goto free_memory; |
1362 | 1383 | ||
1384 | acpi_thermal_guess_offset(tz); | ||
1385 | |||
1363 | result = acpi_thermal_register_thermal_zone(tz); | 1386 | result = acpi_thermal_register_thermal_zone(tz); |
1364 | if (result) | 1387 | if (result) |
1365 | goto free_memory; | 1388 | goto free_memory; |
@@ -1368,21 +1391,11 @@ static int acpi_thermal_add(struct acpi_device *device) | |||
1368 | if (result) | 1391 | if (result) |
1369 | goto unregister_thermal_zone; | 1392 | goto unregister_thermal_zone; |
1370 | 1393 | ||
1371 | status = acpi_install_notify_handler(device->handle, | ||
1372 | ACPI_DEVICE_NOTIFY, | ||
1373 | acpi_thermal_notify, tz); | ||
1374 | if (ACPI_FAILURE(status)) { | ||
1375 | result = -ENODEV; | ||
1376 | goto remove_fs; | ||
1377 | } | ||
1378 | |||
1379 | printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", | 1394 | printk(KERN_INFO PREFIX "%s [%s] (%ld C)\n", |
1380 | acpi_device_name(device), acpi_device_bid(device), | 1395 | acpi_device_name(device), acpi_device_bid(device), |
1381 | KELVIN_TO_CELSIUS(tz->temperature)); | 1396 | KELVIN_TO_CELSIUS(tz->temperature)); |
1382 | goto end; | 1397 | goto end; |
1383 | 1398 | ||
1384 | remove_fs: | ||
1385 | acpi_thermal_remove_fs(device); | ||
1386 | unregister_thermal_zone: | 1399 | unregister_thermal_zone: |
1387 | thermal_zone_device_unregister(tz->thermal_zone); | 1400 | thermal_zone_device_unregister(tz->thermal_zone); |
1388 | free_memory: | 1401 | free_memory: |
@@ -1393,7 +1406,6 @@ end: | |||
1393 | 1406 | ||
1394 | static int acpi_thermal_remove(struct acpi_device *device, int type) | 1407 | static int acpi_thermal_remove(struct acpi_device *device, int type) |
1395 | { | 1408 | { |
1396 | acpi_status status = AE_OK; | ||
1397 | struct acpi_thermal *tz = NULL; | 1409 | struct acpi_thermal *tz = NULL; |
1398 | 1410 | ||
1399 | if (!device || !acpi_driver_data(device)) | 1411 | if (!device || !acpi_driver_data(device)) |
@@ -1401,10 +1413,6 @@ static int acpi_thermal_remove(struct acpi_device *device, int type) | |||
1401 | 1413 | ||
1402 | tz = acpi_driver_data(device); | 1414 | tz = acpi_driver_data(device); |
1403 | 1415 | ||
1404 | status = acpi_remove_notify_handler(device->handle, | ||
1405 | ACPI_DEVICE_NOTIFY, | ||
1406 | acpi_thermal_notify); | ||
1407 | |||
1408 | acpi_thermal_remove_fs(device); | 1416 | acpi_thermal_remove_fs(device); |
1409 | acpi_thermal_unregister_thermal_zone(tz); | 1417 | acpi_thermal_unregister_thermal_zone(tz); |
1410 | mutex_destroy(&tz->lock); | 1418 | mutex_destroy(&tz->lock); |