@@ -38,6 +38,14 @@ struct thermal_data {
3838 struct thermal_handler * th ;
3939};
4040
41+ static int show_threshold (struct thermal_threshold * th , __maybe_unused void * arg )
42+ {
43+ INFO ("threshold temp=%d, direction=%d\n" ,
44+ th -> temperature , th -> direction );
45+
46+ return 0 ;
47+ }
48+
4149static int show_trip (struct thermal_trip * tt , __maybe_unused void * arg )
4250{
4351 INFO ("trip id=%d, type=%d, temp=%d, hyst=%d\n" ,
@@ -70,13 +78,39 @@ static int show_tz(struct thermal_zone *tz, __maybe_unused void *arg)
7078
7179 for_each_thermal_trip (tz -> trip , show_trip , NULL );
7280
81+ for_each_thermal_threshold (tz -> thresholds , show_threshold , NULL );
82+
7383 show_temp (tz , arg );
7484
7585 show_governor (tz , arg );
7686
7787 return 0 ;
7888}
7989
90+ static int set_threshold (struct thermal_zone * tz , __maybe_unused void * arg )
91+ {
92+ struct thermal_handler * th = arg ;
93+ int thresholds [] = { 43000 , 65000 , 49000 , 55000 , 57000 };
94+ size_t i ;
95+
96+ INFO ("Setting threshold for thermal zone '%s', id=%d\n" , tz -> name , tz -> id );
97+
98+ if (thermal_cmd_threshold_flush (th , tz )) {
99+ ERROR ("Failed to flush all previous thresholds\n" );
100+ return -1 ;
101+ }
102+
103+ for (i = 0 ; i < sizeof (thresholds ) / sizeof (thresholds [0 ]); i ++ )
104+ if (thermal_cmd_threshold_add (th , tz , thresholds [i ],
105+ THERMAL_THRESHOLD_WAY_UP |
106+ THERMAL_THRESHOLD_WAY_DOWN )) {
107+ ERROR ("Failed to set threshold\n" );
108+ return -1 ;
109+ }
110+
111+ return 0 ;
112+ }
113+
80114static int tz_create (const char * name , int tz_id , __maybe_unused void * arg )
81115{
82116 INFO ("Thermal zone '%s'/%d created\n" , name , tz_id );
@@ -197,20 +231,62 @@ static int gov_change(int tz_id, const char *name, __maybe_unused void *arg)
197231 return 0 ;
198232}
199233
234+ static int threshold_add (int tz_id , int temp , int direction , __maybe_unused void * arg )
235+ {
236+ INFO ("Threshold added tz_id=%d: temp=%d, direction=%d\n" , tz_id , temp , direction );
237+
238+ return 0 ;
239+ }
240+
241+ static int threshold_delete (int tz_id , int temp , int direction , __maybe_unused void * arg )
242+ {
243+ INFO ("Threshold deleted tz_id=%d: temp=%d, direction=%d\n" , tz_id , temp , direction );
244+
245+ return 0 ;
246+ }
247+
248+ static int threshold_flush (int tz_id , __maybe_unused void * arg )
249+ {
250+ INFO ("Thresholds flushed tz_id=%d\n" , tz_id );
251+
252+ return 0 ;
253+ }
254+
255+ static int threshold_up (int tz_id , int temp , int prev_temp , __maybe_unused void * arg )
256+ {
257+ INFO ("Threshold crossed way up tz_id=%d: temp=%d, prev_temp=%d\n" ,
258+ tz_id , temp , prev_temp );
259+
260+ return 0 ;
261+ }
262+
263+ static int threshold_down (int tz_id , int temp , int prev_temp , __maybe_unused void * arg )
264+ {
265+ INFO ("Threshold crossed way down tz_id=%d: temp=%d, prev_temp=%d\n" ,
266+ tz_id , temp , prev_temp );
267+
268+ return 0 ;
269+ }
270+
200271static struct thermal_ops ops = {
201- .events .tz_create = tz_create ,
202- .events .tz_delete = tz_delete ,
203- .events .tz_disable = tz_disable ,
204- .events .tz_enable = tz_enable ,
205- .events .trip_high = trip_high ,
206- .events .trip_low = trip_low ,
207- .events .trip_add = trip_add ,
208- .events .trip_delete = trip_delete ,
209- .events .trip_change = trip_change ,
210- .events .cdev_add = cdev_add ,
211- .events .cdev_delete = cdev_delete ,
212- .events .cdev_update = cdev_update ,
213- .events .gov_change = gov_change
272+ .events .tz_create = tz_create ,
273+ .events .tz_delete = tz_delete ,
274+ .events .tz_disable = tz_disable ,
275+ .events .tz_enable = tz_enable ,
276+ .events .trip_high = trip_high ,
277+ .events .trip_low = trip_low ,
278+ .events .trip_add = trip_add ,
279+ .events .trip_delete = trip_delete ,
280+ .events .trip_change = trip_change ,
281+ .events .cdev_add = cdev_add ,
282+ .events .cdev_delete = cdev_delete ,
283+ .events .cdev_update = cdev_update ,
284+ .events .gov_change = gov_change ,
285+ .events .threshold_add = threshold_add ,
286+ .events .threshold_delete = threshold_delete ,
287+ .events .threshold_flush = threshold_flush ,
288+ .events .threshold_up = threshold_up ,
289+ .events .threshold_down = threshold_down ,
214290};
215291
216292static int thermal_event (__maybe_unused int fd , __maybe_unused void * arg )
@@ -280,6 +356,7 @@ enum {
280356 THERMAL_ENGINE_DAEMON_ERROR ,
281357 THERMAL_ENGINE_LOG_ERROR ,
282358 THERMAL_ENGINE_THERMAL_ERROR ,
359+ THERMAL_ENGINE_THRESHOLD_ERROR ,
283360 THERMAL_ENGINE_MAINLOOP_ERROR ,
284361};
285362
@@ -318,6 +395,8 @@ int main(int argc, char *argv[])
318395 return THERMAL_ENGINE_THERMAL_ERROR ;
319396 }
320397
398+ for_each_thermal_zone (td .tz , set_threshold , td .th );
399+
321400 for_each_thermal_zone (td .tz , show_tz , td .th );
322401
323402 if (mainloop_init ()) {
0 commit comments