23
23
****************************************************************************/
24
24
25
25
#include <nuttx/kmalloc.h>
26
+ #ifdef CONFIG_PM
27
+ #include <nuttx/power/pm.h>
28
+ #endif
26
29
30
+ #include <assert.h>
27
31
#include <debug.h>
28
32
#include <stdio.h>
29
33
#include <sys/boardctl.h>
30
34
35
+ #include "sched/sched.h"
31
36
#include "thermal_core.h"
32
37
33
38
/****************************************************************************
@@ -53,6 +58,11 @@ static void device_bind (FAR struct thermal_zone_device_s *zdev,
53
58
static void device_unbind (FAR struct thermal_zone_device_s * zdev ,
54
59
FAR struct thermal_cooling_device_s * cdev );
55
60
61
+ #ifdef CONFIG_PM
62
+ static void thermal_pm_notify (FAR struct pm_callback_s * cb , int domain ,
63
+ enum pm_state_e pmstate );
64
+ #endif
65
+
56
66
/****************************************************************************
57
67
* Private Data
58
68
****************************************************************************/
@@ -70,6 +80,13 @@ static mutex_t g_thermal_lock = NXMUTEX_INITIALIZER;
70
80
71
81
static FAR struct thermal_governor_s * g_def_governor = NULL ;
72
82
83
+ #ifdef CONFIG_PM
84
+ struct pm_callback_s g_thermal_pm_cb =
85
+ {
86
+ .notify = thermal_pm_notify ,
87
+ };
88
+ #endif
89
+
73
90
/****************************************************************************
74
91
* Private Functions
75
92
****************************************************************************/
@@ -264,6 +281,56 @@ find_governor_by_name(FAR const char *name)
264
281
return NULL ;
265
282
}
266
283
284
+ #ifdef CONFIG_PM
285
+ static void thermal_pm_notify (FAR struct pm_callback_s * cb , int domain ,
286
+ enum pm_state_e pmstate )
287
+ {
288
+ FAR struct thermal_zone_device_s * zdev ;
289
+
290
+ switch (pmstate )
291
+ {
292
+ case PM_SLEEP :
293
+ {
294
+ nxmutex_lock (& g_thermal_lock );
295
+
296
+ list_for_every_entry (& g_zone_dev_list , zdev ,
297
+ struct thermal_zone_device_s , node )
298
+ {
299
+ work_cancel (LPWORK , & zdev -> monitor );
300
+ }
301
+
302
+ nxmutex_unlock (& g_thermal_lock );
303
+ }
304
+ break ;
305
+ case PM_RESTORE :
306
+ case PM_NORMAL :
307
+ case PM_IDLE :
308
+ case PM_STANDBY :
309
+ {
310
+ nxmutex_lock (& g_thermal_lock );
311
+
312
+ list_for_every_entry (& g_zone_dev_list , zdev ,
313
+ struct thermal_zone_device_s , node )
314
+ {
315
+ if (zdev -> enabled && work_available (& zdev -> monitor ))
316
+ {
317
+ work_queue (LPWORK , & zdev -> monitor ,
318
+ (worker_t )thermal_zone_device_update , zdev ,
319
+ zdev -> params -> polling_delay );
320
+ }
321
+ }
322
+
323
+ nxmutex_unlock (& g_thermal_lock );
324
+ }
325
+ break ;
326
+ default :
327
+ break ;
328
+ }
329
+
330
+ return ;
331
+ }
332
+ #endif
333
+
267
334
/****************************************************************************
268
335
* Public Functions
269
336
****************************************************************************/
@@ -740,6 +807,8 @@ void thermal_zone_device_update(FAR struct thermal_zone_device_s *zdev)
740
807
int temp ;
741
808
int ret ;
742
809
810
+ DEBUGASSERT (!is_idle_task (this_task ()));
811
+
743
812
nxmutex_lock (& g_thermal_lock );
744
813
745
814
/* Update termerature */
@@ -855,5 +924,14 @@ int thermal_init(void)
855
924
}
856
925
#endif
857
926
927
+ #ifdef CONFIG_PM
928
+ ret = pm_register (& g_thermal_pm_cb );
929
+ if (ret < 0 )
930
+ {
931
+ therr ("Register suspend notifier failed!\n" );
932
+ return ret ;
933
+ }
934
+ #endif
935
+
858
936
return ret ;
859
937
}
0 commit comments