@@ -125,6 +125,7 @@ struct acpi_thermal {
125
125
unsigned long polling_frequency ;
126
126
volatile u8 zombie ;
127
127
struct acpi_thermal_trips trips ;
128
+ struct thermal_trip * trip_table ;
128
129
struct acpi_handle_list devices ;
129
130
struct thermal_zone_device * thermal_zone ;
130
131
int kelvin_offset ; /* in millidegrees */
@@ -178,6 +179,15 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
178
179
return 0 ;
179
180
}
180
181
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
+
181
191
static void __acpi_thermal_trips_update (struct acpi_thermal * tz , int flag )
182
192
{
183
193
acpi_status status ;
@@ -389,10 +399,30 @@ static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
389
399
}
390
400
}
391
401
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
+
392
418
static void acpi_thermal_adjust_thermal_zone (struct thermal_zone_device * thermal ,
393
419
unsigned long data )
394
420
{
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 );
396
426
}
397
427
398
428
static void acpi_queue_thermal_check (struct acpi_thermal * tz )
@@ -757,6 +787,8 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz)
757
787
758
788
static int acpi_thermal_register_thermal_zone (struct acpi_thermal * tz )
759
789
{
790
+ struct acpi_thermal_trip * acpi_trip ;
791
+ struct thermal_trip * trip ;
760
792
int passive_delay = 0 ;
761
793
int trip_count = 0 ;
762
794
int result ;
@@ -776,12 +808,56 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
776
808
for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE && tz -> trips .active [i ].trip .valid ; i ++ )
777
809
trip_count ++ ;
778
810
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
+ }
785
861
786
862
result = acpi_thermal_zone_sysfs_add (tz );
787
863
if (result )
@@ -800,6 +876,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
800
876
acpi_thermal_zone_sysfs_remove (tz );
801
877
unregister_tzd :
802
878
thermal_zone_device_unregister (tz -> thermal_zone );
879
+ free_trip_table :
880
+ kfree (tz -> trip_table );
803
881
804
882
return result ;
805
883
}
@@ -808,6 +886,7 @@ static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
808
886
{
809
887
acpi_thermal_zone_sysfs_remove (tz );
810
888
thermal_zone_device_unregister (tz -> thermal_zone );
889
+ kfree (tz -> trip_table );
811
890
tz -> thermal_zone = NULL ;
812
891
}
813
892
0 commit comments