@@ -708,6 +708,40 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal,
708708 return - EINVAL ;
709709}
710710
711+ static int thermal_get_trend (struct thermal_zone_device * thermal ,
712+ int trip , enum thermal_trend * trend )
713+ {
714+ struct acpi_thermal * tz = thermal -> devdata ;
715+ enum thermal_trip_type type ;
716+ int i ;
717+
718+ if (thermal_get_trip_type (thermal , trip , & type ))
719+ return - EINVAL ;
720+
721+ if (type == THERMAL_TRIP_ACTIVE ) {
722+ /* aggressive active cooling */
723+ * trend = THERMAL_TREND_RAISING ;
724+ return 0 ;
725+ }
726+
727+ /*
728+ * tz->temperature has already been updated by generic thermal layer,
729+ * before this callback being invoked
730+ */
731+ i = (tz -> trips .passive .tc1 * (tz -> temperature - tz -> last_temperature ))
732+ + (tz -> trips .passive .tc2
733+ * (tz -> temperature - tz -> trips .passive .temperature ));
734+
735+ if (i > 0 )
736+ * trend = THERMAL_TREND_RAISING ;
737+ else if (i < 0 )
738+ * trend = THERMAL_TREND_DROPPING ;
739+ else
740+ * trend = THERMAL_TREND_STABLE ;
741+ return 0 ;
742+ }
743+
744+
711745static int thermal_notify (struct thermal_zone_device * thermal , int trip ,
712746 enum thermal_trip_type trip_type )
713747{
@@ -731,11 +765,9 @@ static int thermal_notify(struct thermal_zone_device *thermal, int trip,
731765 return 0 ;
732766}
733767
734- typedef int (* cb )(struct thermal_zone_device * , int ,
735- struct thermal_cooling_device * );
736768static int acpi_thermal_cooling_device_cb (struct thermal_zone_device * thermal ,
737769 struct thermal_cooling_device * cdev ,
738- cb action )
770+ bool bind )
739771{
740772 struct acpi_device * device = cdev -> devdata ;
741773 struct acpi_thermal * tz = thermal -> devdata ;
@@ -759,11 +791,19 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
759791 i ++ ) {
760792 handle = tz -> trips .passive .devices .handles [i ];
761793 status = acpi_bus_get_device (handle , & dev );
762- if (ACPI_SUCCESS (status ) && (dev == device )) {
763- result = action (thermal , trip , cdev );
764- if (result )
765- goto failed ;
766- }
794+ if (ACPI_FAILURE (status ) || dev != device )
795+ continue ;
796+ if (bind )
797+ result =
798+ thermal_zone_bind_cooling_device
799+ (thermal , trip , cdev ,
800+ THERMAL_NO_LIMIT , THERMAL_NO_LIMIT );
801+ else
802+ result =
803+ thermal_zone_unbind_cooling_device
804+ (thermal , trip , cdev );
805+ if (result )
806+ goto failed ;
767807 }
768808 }
769809
@@ -776,19 +816,32 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
776816 j ++ ) {
777817 handle = tz -> trips .active [i ].devices .handles [j ];
778818 status = acpi_bus_get_device (handle , & dev );
779- if (ACPI_SUCCESS (status ) && (dev == device )) {
780- result = action (thermal , trip , cdev );
781- if (result )
782- goto failed ;
783- }
819+ if (ACPI_FAILURE (status ) || dev != device )
820+ continue ;
821+ if (bind )
822+ result = thermal_zone_bind_cooling_device
823+ (thermal , trip , cdev ,
824+ THERMAL_NO_LIMIT , THERMAL_NO_LIMIT );
825+ else
826+ result = thermal_zone_unbind_cooling_device
827+ (thermal , trip , cdev );
828+ if (result )
829+ goto failed ;
784830 }
785831 }
786832
787833 for (i = 0 ; i < tz -> devices .count ; i ++ ) {
788834 handle = tz -> devices .handles [i ];
789835 status = acpi_bus_get_device (handle , & dev );
790836 if (ACPI_SUCCESS (status ) && (dev == device )) {
791- result = action (thermal , -1 , cdev );
837+ if (bind )
838+ result = thermal_zone_bind_cooling_device
839+ (thermal , -1 , cdev ,
840+ THERMAL_NO_LIMIT ,
841+ THERMAL_NO_LIMIT );
842+ else
843+ result = thermal_zone_unbind_cooling_device
844+ (thermal , -1 , cdev );
792845 if (result )
793846 goto failed ;
794847 }
@@ -802,16 +855,14 @@ static int
802855acpi_thermal_bind_cooling_device (struct thermal_zone_device * thermal ,
803856 struct thermal_cooling_device * cdev )
804857{
805- return acpi_thermal_cooling_device_cb (thermal , cdev ,
806- thermal_zone_bind_cooling_device );
858+ return acpi_thermal_cooling_device_cb (thermal , cdev , true);
807859}
808860
809861static int
810862acpi_thermal_unbind_cooling_device (struct thermal_zone_device * thermal ,
811863 struct thermal_cooling_device * cdev )
812864{
813- return acpi_thermal_cooling_device_cb (thermal , cdev ,
814- thermal_zone_unbind_cooling_device );
865+ return acpi_thermal_cooling_device_cb (thermal , cdev , false);
815866}
816867
817868static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
@@ -823,6 +874,7 @@ static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
823874 .get_trip_type = thermal_get_trip_type ,
824875 .get_trip_temp = thermal_get_trip_temp ,
825876 .get_crit_temp = thermal_get_crit_temp ,
877+ .get_trend = thermal_get_trend ,
826878 .notify = thermal_notify ,
827879};
828880
@@ -849,15 +901,12 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
849901 tz -> thermal_zone =
850902 thermal_zone_device_register ("acpitz" , trips , 0 , tz ,
851903 & acpi_thermal_zone_ops ,
852- tz -> trips .passive .tc1 ,
853- tz -> trips .passive .tc2 ,
854904 tz -> trips .passive .tsp * 100 ,
855905 tz -> polling_frequency * 100 );
856906 else
857907 tz -> thermal_zone =
858908 thermal_zone_device_register ("acpitz" , trips , 0 , tz ,
859- & acpi_thermal_zone_ops ,
860- 0 , 0 , 0 ,
909+ & acpi_thermal_zone_ops , 0 ,
861910 tz -> polling_frequency * 100 );
862911 if (IS_ERR (tz -> thermal_zone ))
863912 return - ENODEV ;
0 commit comments