aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/thermal.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/thermal.c')
-rw-r--r--drivers/acpi/thermal.c539
1 files changed, 99 insertions, 440 deletions
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 99e6f1f8ea45..6b959976b7a4 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -37,11 +37,11 @@
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/types.h> 38#include <linux/types.h>
39#include <linux/proc_fs.h> 39#include <linux/proc_fs.h>
40#include <linux/timer.h>
41#include <linux/jiffies.h> 40#include <linux/jiffies.h>
42#include <linux/kmod.h> 41#include <linux/kmod.h>
43#include <linux/seq_file.h> 42#include <linux/seq_file.h>
44#include <linux/reboot.h> 43#include <linux/reboot.h>
44#include <linux/device.h>
45#include <asm/uaccess.h> 45#include <asm/uaccess.h>
46#include <linux/thermal.h> 46#include <linux/thermal.h>
47#include <acpi/acpi_bus.h> 47#include <acpi/acpi_bus.h>
@@ -190,7 +190,6 @@ struct acpi_thermal {
190 struct acpi_thermal_state state; 190 struct acpi_thermal_state state;
191 struct acpi_thermal_trips trips; 191 struct acpi_thermal_trips trips;
192 struct acpi_handle_list devices; 192 struct acpi_handle_list devices;
193 struct timer_list timer;
194 struct thermal_zone_device *thermal_zone; 193 struct thermal_zone_device *thermal_zone;
195 int tz_enabled; 194 int tz_enabled;
196 struct mutex lock; 195 struct mutex lock;
@@ -290,6 +289,11 @@ static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
290 289
291 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */ 290 tz->polling_frequency = seconds * 10; /* Convert value to deci-seconds */
292 291
292 tz->thermal_zone->polling_delay = seconds * 1000;
293
294 if (tz->tz_enabled)
295 thermal_zone_device_update(tz->thermal_zone);
296
293 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 297 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
294 "Polling frequency set to %lu seconds\n", 298 "Polling frequency set to %lu seconds\n",
295 tz->polling_frequency/10)); 299 tz->polling_frequency/10));
@@ -569,392 +573,18 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
569 return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); 573 return acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
570} 574}
571 575
572static int acpi_thermal_critical(struct acpi_thermal *tz)
573{
574 if (!tz || !tz->trips.critical.flags.valid)
575 return -EINVAL;
576
577 if (tz->temperature >= tz->trips.critical.temperature) {
578 printk(KERN_WARNING PREFIX "Critical trip point\n");
579 tz->trips.critical.flags.enabled = 1;
580 } else if (tz->trips.critical.flags.enabled)
581 tz->trips.critical.flags.enabled = 0;
582
583 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_CRITICAL,
584 tz->trips.critical.flags.enabled);
585 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
586 dev_name(&tz->device->dev),
587 ACPI_THERMAL_NOTIFY_CRITICAL,
588 tz->trips.critical.flags.enabled);
589
590 /* take no action if nocrt is set */
591 if(!nocrt) {
592 printk(KERN_EMERG
593 "Critical temperature reached (%ld C), shutting down.\n",
594 KELVIN_TO_CELSIUS(tz->temperature));
595 orderly_poweroff(true);
596 }
597
598 return 0;
599}
600
601static int acpi_thermal_hot(struct acpi_thermal *tz)
602{
603 if (!tz || !tz->trips.hot.flags.valid)
604 return -EINVAL;
605
606 if (tz->temperature >= tz->trips.hot.temperature) {
607 printk(KERN_WARNING PREFIX "Hot trip point\n");
608 tz->trips.hot.flags.enabled = 1;
609 } else if (tz->trips.hot.flags.enabled)
610 tz->trips.hot.flags.enabled = 0;
611
612 acpi_bus_generate_proc_event(tz->device, ACPI_THERMAL_NOTIFY_HOT,
613 tz->trips.hot.flags.enabled);
614 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
615 dev_name(&tz->device->dev),
616 ACPI_THERMAL_NOTIFY_HOT,
617 tz->trips.hot.flags.enabled);
618
619 /* TBD: Call user-mode "sleep(S4)" function if nocrt is cleared */
620
621 return 0;
622}
623
624static void acpi_thermal_passive(struct acpi_thermal *tz)
625{
626 int result = 1;
627 struct acpi_thermal_passive *passive = NULL;
628 int trend = 0;
629 int i = 0;
630
631
632 if (!tz || !tz->trips.passive.flags.valid)
633 return;
634
635 passive = &(tz->trips.passive);
636
637 /*
638 * Above Trip?
639 * -----------
640 * Calculate the thermal trend (using the passive cooling equation)
641 * and modify the performance limit for all passive cooling devices
642 * accordingly. Note that we assume symmetry.
643 */
644 if (tz->temperature >= passive->temperature) {
645 trend =
646 (passive->tc1 * (tz->temperature - tz->last_temperature)) +
647 (passive->tc2 * (tz->temperature - passive->temperature));
648 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
649 "trend[%d]=(tc1[%lu]*(tmp[%lu]-last[%lu]))+(tc2[%lu]*(tmp[%lu]-psv[%lu]))\n",
650 trend, passive->tc1, tz->temperature,
651 tz->last_temperature, passive->tc2,
652 tz->temperature, passive->temperature));
653 passive->flags.enabled = 1;
654 /* Heating up? */
655 if (trend > 0)
656 for (i = 0; i < passive->devices.count; i++)
657 acpi_processor_set_thermal_limit(passive->
658 devices.
659 handles[i],
660 ACPI_PROCESSOR_LIMIT_INCREMENT);
661 /* Cooling off? */
662 else if (trend < 0) {
663 for (i = 0; i < passive->devices.count; i++)
664 /*
665 * assume that we are on highest
666 * freq/lowest thrott and can leave
667 * passive mode, even in error case
668 */
669 if (!acpi_processor_set_thermal_limit
670 (passive->devices.handles[i],
671 ACPI_PROCESSOR_LIMIT_DECREMENT))
672 result = 0;
673 /*
674 * Leave cooling mode, even if the temp might
675 * higher than trip point This is because some
676 * machines might have long thermal polling
677 * frequencies (tsp) defined. We will fall back
678 * into passive mode in next cycle (probably quicker)
679 */
680 if (result) {
681 passive->flags.enabled = 0;
682 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
683 "Disabling passive cooling, still above threshold,"
684 " but we are cooling down\n"));
685 }
686 }
687 return;
688 }
689
690 /*
691 * Below Trip?
692 * -----------
693 * Implement passive cooling hysteresis to slowly increase performance
694 * and avoid thrashing around the passive trip point. Note that we
695 * assume symmetry.
696 */
697 if (!passive->flags.enabled)
698 return;
699 for (i = 0; i < passive->devices.count; i++)
700 if (!acpi_processor_set_thermal_limit
701 (passive->devices.handles[i],
702 ACPI_PROCESSOR_LIMIT_DECREMENT))
703 result = 0;
704 if (result) {
705 passive->flags.enabled = 0;
706 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
707 "Disabling passive cooling (zone is cool)\n"));
708 }
709}
710
711static void acpi_thermal_active(struct acpi_thermal *tz)
712{
713 int result = 0;
714 struct acpi_thermal_active *active = NULL;
715 int i = 0;
716 int j = 0;
717 unsigned long maxtemp = 0;
718
719
720 if (!tz)
721 return;
722
723 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
724 active = &(tz->trips.active[i]);
725 if (!active || !active->flags.valid)
726 break;
727 if (tz->temperature >= active->temperature) {
728 /*
729 * Above Threshold?
730 * ----------------
731 * If not already enabled, turn ON all cooling devices
732 * associated with this active threshold.
733 */
734 if (active->temperature > maxtemp)
735 tz->state.active_index = i;
736 maxtemp = active->temperature;
737 if (active->flags.enabled)
738 continue;
739 for (j = 0; j < active->devices.count; j++) {
740 result =
741 acpi_bus_set_power(active->devices.
742 handles[j],
743 ACPI_STATE_D0);
744 if (result) {
745 printk(KERN_WARNING PREFIX
746 "Unable to turn cooling device [%p] 'on'\n",
747 active->devices.
748 handles[j]);
749 continue;
750 }
751 active->flags.enabled = 1;
752 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
753 "Cooling device [%p] now 'on'\n",
754 active->devices.handles[j]));
755 }
756 continue;
757 }
758 if (!active->flags.enabled)
759 continue;
760 /*
761 * Below Threshold?
762 * ----------------
763 * Turn OFF all cooling devices associated with this
764 * threshold.
765 */
766 for (j = 0; j < active->devices.count; j++) {
767 result = acpi_bus_set_power(active->devices.handles[j],
768 ACPI_STATE_D3);
769 if (result) {
770 printk(KERN_WARNING PREFIX
771 "Unable to turn cooling device [%p] 'off'\n",
772 active->devices.handles[j]);
773 continue;
774 }
775 active->flags.enabled = 0;
776 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
777 "Cooling device [%p] now 'off'\n",
778 active->devices.handles[j]));
779 }
780 }
781}
782
783static void acpi_thermal_check(void *context);
784
785static void acpi_thermal_run(unsigned long data)
786{
787 struct acpi_thermal *tz = (struct acpi_thermal *)data;
788 if (!tz->zombie)
789 acpi_os_execute(OSL_GPE_HANDLER, acpi_thermal_check, (void *)data);
790}
791
792static void acpi_thermal_active_off(void *data)
793{
794 int result = 0;
795 struct acpi_thermal *tz = data;
796 int i = 0;
797 int j = 0;
798 struct acpi_thermal_active *active = NULL;
799
800 if (!tz) {
801 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
802 return;
803 }
804
805 result = acpi_thermal_get_temperature(tz);
806 if (result)
807 return;
808
809 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
810 active = &(tz->trips.active[i]);
811 if (!active || !active->flags.valid)
812 break;
813 if (tz->temperature >= active->temperature) {
814 /*
815 * If the thermal temperature is greater than the
816 * active threshod, unnecessary to turn off the
817 * the active cooling device.
818 */
819 continue;
820 }
821 /*
822 * Below Threshold?
823 * ----------------
824 * Turn OFF all cooling devices associated with this
825 * threshold.
826 */
827 for (j = 0; j < active->devices.count; j++)
828 result = acpi_bus_set_power(active->devices.handles[j],
829 ACPI_STATE_D3);
830 }
831}
832
833static void acpi_thermal_check(void *data) 576static void acpi_thermal_check(void *data)
834{ 577{
835 int result = 0;
836 struct acpi_thermal *tz = data; 578 struct acpi_thermal *tz = data;
837 unsigned long sleep_time = 0;
838 unsigned long timeout_jiffies = 0;
839 int i = 0;
840 struct acpi_thermal_state state;
841
842
843 if (!tz) {
844 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
845 return;
846 }
847
848 /* Check if someone else is already running */
849 if (!mutex_trylock(&tz->lock))
850 return;
851
852 state = tz->state;
853
854 result = acpi_thermal_get_temperature(tz);
855 if (result)
856 goto unlock;
857
858 if (!tz->tz_enabled)
859 goto unlock;
860
861 memset(&tz->state, 0, sizeof(tz->state));
862
863 /*
864 * Check Trip Points
865 * -----------------
866 * Compare the current temperature to the trip point values to see
867 * if we've entered one of the thermal policy states. Note that
868 * this function determines when a state is entered, but the
869 * individual policy decides when it is exited (e.g. hysteresis).
870 */
871 if (tz->trips.critical.flags.valid)
872 state.critical |=
873 (tz->temperature >= tz->trips.critical.temperature);
874 if (tz->trips.hot.flags.valid)
875 state.hot |= (tz->temperature >= tz->trips.hot.temperature);
876 if (tz->trips.passive.flags.valid)
877 state.passive |=
878 (tz->temperature >= tz->trips.passive.temperature);
879 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
880 if (tz->trips.active[i].flags.valid)
881 state.active |=
882 (tz->temperature >=
883 tz->trips.active[i].temperature);
884
885 /*
886 * Invoke Policy
887 * -------------
888 * Separated from the above check to allow individual policy to
889 * determine when to exit a given state.
890 */
891 if (state.critical)
892 acpi_thermal_critical(tz);
893 if (state.hot)
894 acpi_thermal_hot(tz);
895 if (state.passive)
896 acpi_thermal_passive(tz);
897 if (state.active)
898 acpi_thermal_active(tz);
899
900 /*
901 * Calculate State
902 * ---------------
903 * Again, separated from the above two to allow independent policy
904 * decisions.
905 */
906 tz->state.critical = tz->trips.critical.flags.enabled;
907 tz->state.hot = tz->trips.hot.flags.enabled;
908 tz->state.passive = tz->trips.passive.flags.enabled;
909 tz->state.active = 0;
910 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
911 tz->state.active |= tz->trips.active[i].flags.enabled;
912
913 /*
914 * Calculate Sleep Time
915 * --------------------
916 * If we're in the passive state, use _TSP's value. Otherwise
917 * use the default polling frequency (e.g. _TZP). If no polling
918 * frequency is specified then we'll wait forever (at least until
919 * a thermal event occurs). Note that _TSP and _TZD values are
920 * given in 1/10th seconds (we must covert to milliseconds).
921 */
922 if (tz->state.passive) {
923 sleep_time = tz->trips.passive.tsp * 100;
924 timeout_jiffies = jiffies + (HZ * sleep_time) / 1000;
925 } else if (tz->polling_frequency > 0) {
926 sleep_time = tz->polling_frequency * 100;
927 timeout_jiffies = round_jiffies(jiffies + (HZ * sleep_time) / 1000);
928 }
929 579
930 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s: temperature[%lu] sleep[%lu]\n", 580 thermal_zone_device_update(tz->thermal_zone);
931 tz->name, tz->temperature, sleep_time));
932
933 /*
934 * Schedule Next Poll
935 * ------------------
936 */
937 if (!sleep_time) {
938 if (timer_pending(&(tz->timer)))
939 del_timer(&(tz->timer));
940 } else {
941 if (timer_pending(&(tz->timer)))
942 mod_timer(&(tz->timer), timeout_jiffies);
943 else {
944 tz->timer.data = (unsigned long)tz;
945 tz->timer.function = acpi_thermal_run;
946 tz->timer.expires = timeout_jiffies;
947 add_timer(&(tz->timer));
948 }
949 }
950 unlock:
951 mutex_unlock(&tz->lock);
952} 581}
953 582
954/* sys I/F for generic thermal sysfs support */ 583/* sys I/F for generic thermal sysfs support */
955#define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200) 584#define KELVIN_TO_MILLICELSIUS(t) (t * 100 - 273200)
956 585
957static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf) 586static int thermal_get_temp(struct thermal_zone_device *thermal,
587 unsigned long *temp)
958{ 588{
959 struct acpi_thermal *tz = thermal->devdata; 589 struct acpi_thermal *tz = thermal->devdata;
960 int result; 590 int result;
@@ -966,25 +596,28 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, char *buf)
966 if (result) 596 if (result)
967 return result; 597 return result;
968 598
969 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS(tz->temperature)); 599 *temp = KELVIN_TO_MILLICELSIUS(tz->temperature);
600 return 0;
970} 601}
971 602
972static const char enabled[] = "kernel"; 603static const char enabled[] = "kernel";
973static const char disabled[] = "user"; 604static const char disabled[] = "user";
974static int thermal_get_mode(struct thermal_zone_device *thermal, 605static int thermal_get_mode(struct thermal_zone_device *thermal,
975 char *buf) 606 enum thermal_device_mode *mode)
976{ 607{
977 struct acpi_thermal *tz = thermal->devdata; 608 struct acpi_thermal *tz = thermal->devdata;
978 609
979 if (!tz) 610 if (!tz)
980 return -EINVAL; 611 return -EINVAL;
981 612
982 return sprintf(buf, "%s\n", tz->tz_enabled ? 613 *mode = tz->tz_enabled ? THERMAL_DEVICE_ENABLED :
983 enabled : disabled); 614 THERMAL_DEVICE_DISABLED;
615
616 return 0;
984} 617}
985 618
986static int thermal_set_mode(struct thermal_zone_device *thermal, 619static int thermal_set_mode(struct thermal_zone_device *thermal,
987 const char *buf) 620 enum thermal_device_mode mode)
988{ 621{
989 struct acpi_thermal *tz = thermal->devdata; 622 struct acpi_thermal *tz = thermal->devdata;
990 int enable; 623 int enable;
@@ -995,9 +628,9 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
995 /* 628 /*
996 * enable/disable thermal management from ACPI thermal driver 629 * enable/disable thermal management from ACPI thermal driver
997 */ 630 */
998 if (!strncmp(buf, enabled, sizeof enabled - 1)) 631 if (mode == THERMAL_DEVICE_ENABLED)
999 enable = 1; 632 enable = 1;
1000 else if (!strncmp(buf, disabled, sizeof disabled - 1)) 633 else if (mode == THERMAL_DEVICE_DISABLED)
1001 enable = 0; 634 enable = 0;
1002 else 635 else
1003 return -EINVAL; 636 return -EINVAL;
@@ -1013,7 +646,7 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
1013} 646}
1014 647
1015static int thermal_get_trip_type(struct thermal_zone_device *thermal, 648static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1016 int trip, char *buf) 649 int trip, enum thermal_trip_type *type)
1017{ 650{
1018 struct acpi_thermal *tz = thermal->devdata; 651 struct acpi_thermal *tz = thermal->devdata;
1019 int i; 652 int i;
@@ -1022,27 +655,35 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1022 return -EINVAL; 655 return -EINVAL;
1023 656
1024 if (tz->trips.critical.flags.valid) { 657 if (tz->trips.critical.flags.valid) {
1025 if (!trip) 658 if (!trip) {
1026 return sprintf(buf, "critical\n"); 659 *type = THERMAL_TRIP_CRITICAL;
660 return 0;
661 }
1027 trip--; 662 trip--;
1028 } 663 }
1029 664
1030 if (tz->trips.hot.flags.valid) { 665 if (tz->trips.hot.flags.valid) {
1031 if (!trip) 666 if (!trip) {
1032 return sprintf(buf, "hot\n"); 667 *type = THERMAL_TRIP_HOT;
668 return 0;
669 }
1033 trip--; 670 trip--;
1034 } 671 }
1035 672
1036 if (tz->trips.passive.flags.valid) { 673 if (tz->trips.passive.flags.valid) {
1037 if (!trip) 674 if (!trip) {
1038 return sprintf(buf, "passive\n"); 675 *type = THERMAL_TRIP_PASSIVE;
676 return 0;
677 }
1039 trip--; 678 trip--;
1040 } 679 }
1041 680
1042 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 681 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1043 tz->trips.active[i].flags.valid; i++) { 682 tz->trips.active[i].flags.valid; i++) {
1044 if (!trip) 683 if (!trip) {
1045 return sprintf(buf, "active%d\n", i); 684 *type = THERMAL_TRIP_ACTIVE;
685 return 0;
686 }
1046 trip--; 687 trip--;
1047 } 688 }
1048 689
@@ -1050,7 +691,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal,
1050} 691}
1051 692
1052static int thermal_get_trip_temp(struct thermal_zone_device *thermal, 693static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
1053 int trip, char *buf) 694 int trip, unsigned long *temp)
1054{ 695{
1055 struct acpi_thermal *tz = thermal->devdata; 696 struct acpi_thermal *tz = thermal->devdata;
1056 int i; 697 int i;
@@ -1059,31 +700,39 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal,
1059 return -EINVAL; 700 return -EINVAL;
1060 701
1061 if (tz->trips.critical.flags.valid) { 702 if (tz->trips.critical.flags.valid) {
1062 if (!trip) 703 if (!trip) {
1063 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 704 *temp = KELVIN_TO_MILLICELSIUS(
1064 tz->trips.critical.temperature)); 705 tz->trips.critical.temperature);
706 return 0;
707 }
1065 trip--; 708 trip--;
1066 } 709 }
1067 710
1068 if (tz->trips.hot.flags.valid) { 711 if (tz->trips.hot.flags.valid) {
1069 if (!trip) 712 if (!trip) {
1070 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 713 *temp = KELVIN_TO_MILLICELSIUS(
1071 tz->trips.hot.temperature)); 714 tz->trips.hot.temperature);
715 return 0;
716 }
1072 trip--; 717 trip--;
1073 } 718 }
1074 719
1075 if (tz->trips.passive.flags.valid) { 720 if (tz->trips.passive.flags.valid) {
1076 if (!trip) 721 if (!trip) {
1077 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 722 *temp = KELVIN_TO_MILLICELSIUS(
1078 tz->trips.passive.temperature)); 723 tz->trips.passive.temperature);
724 return 0;
725 }
1079 trip--; 726 trip--;
1080 } 727 }
1081 728
1082 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 729 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1083 tz->trips.active[i].flags.valid; i++) { 730 tz->trips.active[i].flags.valid; i++) {
1084 if (!trip) 731 if (!trip) {
1085 return sprintf(buf, "%ld\n", KELVIN_TO_MILLICELSIUS( 732 *temp = KELVIN_TO_MILLICELSIUS(
1086 tz->trips.active[i].temperature)); 733 tz->trips.active[i].temperature);
734 return 0;
735 }
1087 trip--; 736 trip--;
1088 } 737 }
1089 738
@@ -1102,6 +751,29 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
1102 return -EINVAL; 751 return -EINVAL;
1103} 752}
1104 753
754static int thermal_notify(struct thermal_zone_device *thermal, int trip,
755 enum thermal_trip_type trip_type)
756{
757 u8 type = 0;
758 struct acpi_thermal *tz = thermal->devdata;
759
760 if (trip_type == THERMAL_TRIP_CRITICAL)
761 type = ACPI_THERMAL_NOTIFY_CRITICAL;
762 else if (trip_type == THERMAL_TRIP_HOT)
763 type = ACPI_THERMAL_NOTIFY_HOT;
764 else
765 return 0;
766
767 acpi_bus_generate_proc_event(tz->device, type, 1);
768 acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
769 dev_name(&tz->device->dev), type, 1);
770
771 if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
772 return 1;
773
774 return 0;
775}
776
1105typedef int (*cb)(struct thermal_zone_device *, int, 777typedef int (*cb)(struct thermal_zone_device *, int,
1106 struct thermal_cooling_device *); 778 struct thermal_cooling_device *);
1107static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, 779static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
@@ -1194,6 +866,7 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
1194 .get_trip_type = thermal_get_trip_type, 866 .get_trip_type = thermal_get_trip_type,
1195 .get_trip_temp = thermal_get_trip_temp, 867 .get_trip_temp = thermal_get_trip_temp,
1196 .get_crit_temp = thermal_get_crit_temp, 868 .get_crit_temp = thermal_get_crit_temp,
869 .notify = thermal_notify,
1197}; 870};
1198 871
1199static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) 872static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
@@ -1214,8 +887,21 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
1214 887
1215 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && 888 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
1216 tz->trips.active[i].flags.valid; i++, trips++); 889 tz->trips.active[i].flags.valid; i++, trips++);
1217 tz->thermal_zone = thermal_zone_device_register("acpitz", 890
1218 trips, tz, &acpi_thermal_zone_ops); 891 if (tz->trips.passive.flags.valid)
892 tz->thermal_zone =
893 thermal_zone_device_register("acpitz", trips, tz,
894 &acpi_thermal_zone_ops,
895 tz->trips.passive.tc1,
896 tz->trips.passive.tc2,
897 tz->trips.passive.tsp*100,
898 tz->polling_frequency*100);
899 else
900 tz->thermal_zone =
901 thermal_zone_device_register("acpitz", trips, tz,
902 &acpi_thermal_zone_ops,
903 0, 0, 0,
904 tz->polling_frequency);
1219 if (IS_ERR(tz->thermal_zone)) 905 if (IS_ERR(tz->thermal_zone))
1220 return -ENODEV; 906 return -ENODEV;
1221 907
@@ -1447,13 +1133,13 @@ static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1447 if (!tz) 1133 if (!tz)
1448 goto end; 1134 goto end;
1449 1135
1450 if (!tz->polling_frequency) { 1136 if (!tz->thermal_zone->polling_delay) {
1451 seq_puts(seq, "<polling disabled>\n"); 1137 seq_puts(seq, "<polling disabled>\n");
1452 goto end; 1138 goto end;
1453 } 1139 }
1454 1140
1455 seq_printf(seq, "polling frequency: %lu seconds\n", 1141 seq_printf(seq, "polling frequency: %d seconds\n",
1456 (tz->polling_frequency / 10)); 1142 (tz->thermal_zone->polling_delay / 1000));
1457 1143
1458 end: 1144 end:
1459 return 0; 1145 return 0;
@@ -1683,12 +1369,6 @@ static int acpi_thermal_add(struct acpi_device *device)
1683 if (result) 1369 if (result)
1684 goto unregister_thermal_zone; 1370 goto unregister_thermal_zone;
1685 1371
1686 init_timer(&tz->timer);
1687
1688 acpi_thermal_active_off(tz);
1689
1690 acpi_thermal_check(tz);
1691
1692 status = acpi_install_notify_handler(device->handle, 1372 status = acpi_install_notify_handler(device->handle,
1693 ACPI_DEVICE_NOTIFY, 1373 ACPI_DEVICE_NOTIFY,
1694 acpi_thermal_notify, tz); 1374 acpi_thermal_notify, tz);
@@ -1717,36 +1397,15 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1717 acpi_status status = AE_OK; 1397 acpi_status status = AE_OK;
1718 struct acpi_thermal *tz = NULL; 1398 struct acpi_thermal *tz = NULL;
1719 1399
1720
1721 if (!device || !acpi_driver_data(device)) 1400 if (!device || !acpi_driver_data(device))
1722 return -EINVAL; 1401 return -EINVAL;
1723 1402
1724 tz = acpi_driver_data(device); 1403 tz = acpi_driver_data(device);
1725 1404
1726 /* avoid timer adding new defer task */
1727 tz->zombie = 1;
1728 /* wait for running timer (on other CPUs) finish */
1729 del_timer_sync(&(tz->timer));
1730 /* synchronize deferred task */
1731 acpi_os_wait_events_complete(NULL);
1732 /* deferred task may reinsert timer */
1733 del_timer_sync(&(tz->timer));
1734
1735 status = acpi_remove_notify_handler(device->handle, 1405 status = acpi_remove_notify_handler(device->handle,
1736 ACPI_DEVICE_NOTIFY, 1406 ACPI_DEVICE_NOTIFY,
1737 acpi_thermal_notify); 1407 acpi_thermal_notify);
1738 1408
1739 /* Terminate policy */
1740 if (tz->trips.passive.flags.valid && tz->trips.passive.flags.enabled) {
1741 tz->trips.passive.flags.enabled = 0;
1742 acpi_thermal_passive(tz);
1743 }
1744 if (tz->trips.active[0].flags.valid
1745 && tz->trips.active[0].flags.enabled) {
1746 tz->trips.active[0].flags.enabled = 0;
1747 acpi_thermal_active(tz);
1748 }
1749
1750 acpi_thermal_remove_fs(device); 1409 acpi_thermal_remove_fs(device);
1751 acpi_thermal_unregister_thermal_zone(tz); 1410 acpi_thermal_unregister_thermal_zone(tz);
1752 mutex_destroy(&tz->lock); 1411 mutex_destroy(&tz->lock);