[DM/FEATURE] Support thermal

Thermal drivers offer a generic mechanism for thermal management.
Usually it's made up of one or more thermal zones and cooling devices.
Each thermal zone contains its own temperature, trip points, and cooling devices.
All platforms with ACPI or OFW thermal support can use this driver.

Signed-off-by: GuEe-GUI <2991707448@qq.com>
This commit is contained in:
GuEe-GUI
2024-12-02 21:17:24 +08:00
committed by Rbb666
parent 8c0a6c934b
commit 429c0c5257
9 changed files with 1266 additions and 0 deletions
+1
View File
@@ -30,6 +30,7 @@ rsource "nvme/Kconfig"
rsource "scsi/Kconfig"
rsource "regulator/Kconfig"
rsource "reset/Kconfig"
rsource "thermal/Kconfig"
rsource "virtio/Kconfig"
rsource "dma/Kconfig"
rsource "mfd/Kconfig"
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __DT_BINDINGS_THERMAL_THERMAL_H__
#define __DT_BINDINGS_THERMAL_THERMAL_H__
/* On cooling devices upper and lower limits */
#define THERMAL_NO_LIMIT (~0)
#endif /* __DT_BINDINGS_THERMAL_THERMAL_H__ */
+4
View File
@@ -104,6 +104,10 @@ extern "C" {
#ifdef RT_MFD_SYSCON
#include "drivers/syscon.h"
#endif /* RT_MFD_SYSCON */
#ifdef RT_USING_THERMAL
#include "drivers/thermal.h"
#endif /* RT_USING_THERMAL */
#endif /* RT_USING_DM */
#ifdef RT_USING_RTC
+20
View File
@@ -0,0 +1,20 @@
menuconfig RT_USING_THERMAL
bool "Using Thermal Management device drivers"
depends on RT_USING_DM
default n
if RT_USING_THERMAL
comment "Thermal Sensors Drivers"
endif
if RT_USING_THERMAL
osource "$(SOC_DM_THERMAL_DIR)/Kconfig"
endif
if RT_USING_THERMAL
comment "Thermal Cool Drivers"
endif
if RT_USING_THERMAL
osource "$(SOC_DM_THERMAL_COOL_DIR)/Kconfig"
endif
+15
View File
@@ -0,0 +1,15 @@
from building import *
group = []
if not GetDepend(['RT_USING_THERMAL']):
Return('group')
cwd = GetCurrentDir()
CPPPATH = [cwd + '/../include']
src = ['thermal.c', 'thermal_dm.c']
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
File diff suppressed because it is too large Load Diff
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/
#define DBG_TAG "rtdm.thermal"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#include "thermal_dm.h"
enum rt_thermal_trip_type thermal_type(const char *type)
{
if (!type)
{
return RT_THERMAL_TRIP_TYPE_MAX;
}
if (!rt_strcmp(type, "active"))
{
return RT_THERMAL_TRIP_ACTIVE;
}
else if (!rt_strcmp(type, "passive"))
{
return RT_THERMAL_TRIP_PASSIVE;
}
else if (!rt_strcmp(type, "hot"))
{
return RT_THERMAL_TRIP_HOT;
}
else if (!rt_strcmp(type, "critical"))
{
return RT_THERMAL_TRIP_CRITICAL;
}
return RT_THERMAL_TRIP_TYPE_MAX;
}
rt_err_t thermal_bind(struct rt_thermal_cooling_device *cdev,
struct rt_thermal_zone_device *zdev)
{
if (cdev->ops->bind)
{
return cdev->ops->bind(cdev, zdev);
}
return RT_EOK;
}
rt_err_t thermal_unbind(struct rt_thermal_cooling_device *cdev,
struct rt_thermal_zone_device *zdev)
{
if (cdev->ops->unbind)
{
return cdev->ops->unbind(cdev, zdev);
}
return RT_EOK;
}
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/
#ifndef __THERMAL_DM_H__
#define __THERMAL_DM_H__
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <drivers/ofw.h>
enum rt_thermal_trip_type thermal_type(const char *type);
rt_err_t thermal_bind(struct rt_thermal_cooling_device *cdev,
struct rt_thermal_zone_device *zdev);
rt_err_t thermal_unbind(struct rt_thermal_cooling_device *cdev,
struct rt_thermal_zone_device *zdev);
#endif /* __THERMAL_DM_H__ */