@@ -125,6 +125,7 @@ struct acpi_thermal {
125125 unsigned long polling_frequency ;
126126 volatile u8 zombie ;
127127 struct acpi_thermal_trips trips ;
128+ struct thermal_trip * trip_table ;
128129 struct acpi_handle_list devices ;
129130 struct thermal_zone_device * thermal_zone ;
130131 int kelvin_offset ; /* in millidegrees */
@@ -178,6 +179,15 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
178179 return 0 ;
179180}
180181
182+ static int acpi_thermal_temp (struct acpi_thermal * tz , int temp_deci_k )
183+ {
184+ if (temp_deci_k == THERMAL_TEMP_INVALID )
185+ return THERMAL_TEMP_INVALID ;
186+
187+ return deci_kelvin_to_millicelsius_with_offset (temp_deci_k ,
188+ tz -> kelvin_offset );
189+ }
190+
181191static void __acpi_thermal_trips_update (struct acpi_thermal * tz , int flag )
182192{
183193 acpi_status status ;
@@ -389,10 +399,30 @@ static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
389399 }
390400}
391401
402+ static int acpi_thermal_adjust_trip (struct thermal_trip * trip , void * data )
403+ {
404+ struct acpi_thermal_trip * acpi_trip = trip -> priv ;
405+ struct acpi_thermal * tz = data ;
406+
407+ if (!acpi_trip )
408+ return 0 ;
409+
410+ if (acpi_trip -> valid )
411+ trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
412+ else
413+ trip -> temperature = THERMAL_TEMP_INVALID ;
414+
415+ return 0 ;
416+ }
417+
392418static void acpi_thermal_adjust_thermal_zone (struct thermal_zone_device * thermal ,
393419 unsigned long data )
394420{
395- __acpi_thermal_trips_update (thermal_zone_device_priv (thermal ), data );
421+ struct acpi_thermal * tz = thermal_zone_device_priv (thermal );
422+
423+ __acpi_thermal_trips_update (tz , data );
424+
425+ for_each_thermal_trip (tz -> thermal_zone , acpi_thermal_adjust_trip , tz );
396426}
397427
398428static void acpi_queue_thermal_check (struct acpi_thermal * tz )
@@ -757,6 +787,8 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
757787
758788static int acpi_thermal_register_thermal_zone (struct acpi_thermal * tz )
759789{
790+ struct acpi_thermal_trip * acpi_trip ;
791+ struct thermal_trip * trip ;
760792 int passive_delay = 0 ;
761793 int trip_count = 0 ;
762794 int result ;
@@ -776,12 +808,56 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
776808 for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE && tz -> trips .active [i ].trip .valid ; i ++ )
777809 trip_count ++ ;
778810
779- tz -> thermal_zone = thermal_zone_device_register ("acpitz" , trip_count , 0 ,
780- tz , & acpi_thermal_zone_ops ,
781- NULL , passive_delay ,
782- tz -> polling_frequency * 100 );
783- if (IS_ERR (tz -> thermal_zone ))
784- return - ENODEV ;
811+ trip = kcalloc (trip_count , sizeof (* trip ), GFP_KERNEL );
812+ if (!trip )
813+ return - ENOMEM ;
814+
815+ tz -> trip_table = trip ;
816+
817+ if (tz -> trips .critical .valid ) {
818+ trip -> type = THERMAL_TRIP_CRITICAL ;
819+ trip -> temperature = acpi_thermal_temp (tz , tz -> trips .critical .temperature );
820+ trip ++ ;
821+ }
822+
823+ if (tz -> trips .hot .valid ) {
824+ trip -> type = THERMAL_TRIP_HOT ;
825+ trip -> temperature = acpi_thermal_temp (tz , tz -> trips .hot .temperature );
826+ trip ++ ;
827+ }
828+
829+ acpi_trip = & tz -> trips .passive .trip ;
830+ if (acpi_trip -> valid ) {
831+ trip -> type = THERMAL_TRIP_PASSIVE ;
832+ trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
833+ trip -> priv = acpi_trip ;
834+ trip ++ ;
835+ }
836+
837+ for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
838+ acpi_trip = & tz -> trips .active [i ].trip ;
839+
840+ if (!acpi_trip -> valid )
841+ break ;
842+
843+ trip -> type = THERMAL_TRIP_ACTIVE ;
844+ trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temperature );
845+ trip -> priv = acpi_trip ;
846+ trip ++ ;
847+ }
848+
849+ tz -> thermal_zone = thermal_zone_device_register_with_trips ("acpitz" ,
850+ tz -> trip_table ,
851+ trip_count ,
852+ 0 , tz ,
853+ & acpi_thermal_zone_ops ,
854+ NULL ,
855+ passive_delay ,
856+ tz -> polling_frequency * 100 );
857+ if (IS_ERR (tz -> thermal_zone )) {
858+ result = PTR_ERR (tz -> thermal_zone );
859+ goto free_trip_table ;
860+ }
785861
786862 result = acpi_thermal_zone_sysfs_add (tz );
787863 if (result )
@@ -800,6 +876,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
800876 acpi_thermal_zone_sysfs_remove (tz );
801877unregister_tzd :
802878 thermal_zone_device_unregister (tz -> thermal_zone );
879+ free_trip_table :
880+ kfree (tz -> trip_table );
803881
804882 return result ;
805883}
@@ -808,6 +886,7 @@ static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
808886{
809887 acpi_thermal_zone_sysfs_remove (tz );
810888 thermal_zone_device_unregister (tz -> thermal_zone );
889+ kfree (tz -> trip_table );
811890 tz -> thermal_zone = NULL ;
812891}
813892
0 commit comments