Skip to content

Commit 520e404

Browse files
JianyuWang0623xiaoxiang781216
authored andcommitted
Thermal: Register pm suspend notifier
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
1 parent 2f285a0 commit 520e404

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

drivers/thermal/thermal_core.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323
****************************************************************************/
2424

2525
#include <nuttx/kmalloc.h>
26+
#ifdef CONFIG_PM
27+
#include <nuttx/power/pm.h>
28+
#endif
2629

30+
#include <assert.h>
2731
#include <debug.h>
2832
#include <stdio.h>
2933
#include <sys/boardctl.h>
3034

35+
#include "sched/sched.h"
3136
#include "thermal_core.h"
3237

3338
/****************************************************************************
@@ -53,6 +58,11 @@ static void device_bind (FAR struct thermal_zone_device_s *zdev,
5358
static void device_unbind (FAR struct thermal_zone_device_s *zdev,
5459
FAR struct thermal_cooling_device_s *cdev);
5560

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+
5666
/****************************************************************************
5767
* Private Data
5868
****************************************************************************/
@@ -70,6 +80,13 @@ static mutex_t g_thermal_lock = NXMUTEX_INITIALIZER;
7080

7181
static FAR struct thermal_governor_s *g_def_governor = NULL;
7282

83+
#ifdef CONFIG_PM
84+
struct pm_callback_s g_thermal_pm_cb =
85+
{
86+
.notify = thermal_pm_notify,
87+
};
88+
#endif
89+
7390
/****************************************************************************
7491
* Private Functions
7592
****************************************************************************/
@@ -264,6 +281,56 @@ find_governor_by_name(FAR const char *name)
264281
return NULL;
265282
}
266283

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+
267334
/****************************************************************************
268335
* Public Functions
269336
****************************************************************************/
@@ -740,6 +807,8 @@ void thermal_zone_device_update(FAR struct thermal_zone_device_s *zdev)
740807
int temp;
741808
int ret;
742809

810+
DEBUGASSERT(!is_idle_task(this_task()));
811+
743812
nxmutex_lock(&g_thermal_lock);
744813

745814
/* Update termerature */
@@ -855,5 +924,14 @@ int thermal_init(void)
855924
}
856925
#endif
857926

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+
858936
return ret;
859937
}

0 commit comments

Comments
 (0)