Add thermal framework

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3
2023-10-13 23:10:56 +08:00
committed by Xiang Xiao
parent b78c9a7067
commit d1b87bd021
10 changed files with 1230 additions and 0 deletions
+31
View File
@@ -1936,6 +1936,37 @@ config DEBUG_SPI_INFO
endif # DEBUG_SPI
config DEBUG_THERMAL
bool "Thermal Debug Features"
default n
---help---
Enable thermal debug features.
if DEBUG_THERMAL
config DEBUG_THERMAL_ERROR
bool "Thermal Error Output"
default n
depends on DEBUG_ERROR
---help---
Enable thermal error output to SYSLOG.
config DEBUG_THERMAL_WARN
bool "Thermal Warnings Output"
default n
depends on DEBUG_WARN
---help---
Enable thermal warning output to SYSLOG.
config DEBUG_THERMAL_INFO
bool "Thermal Informational Output"
default n
depends on DEBUG_INFO
---help---
Enable thermal informational output to SYSLOG.
endif # DEBUG_THERMAL
config DEBUG_TIMER
bool "Timer Debug Features"
default n
+1
View File
@@ -42,6 +42,7 @@ source "drivers/rpmsg/Kconfig"
source "drivers/rptun/Kconfig"
source "drivers/sensors/Kconfig"
source "drivers/serial/Kconfig"
source "drivers/thermal/Kconfig"
source "drivers/usbdev/Kconfig"
source "drivers/usbhost/Kconfig"
source "drivers/usbmisc/Kconfig"
+1
View File
@@ -63,6 +63,7 @@ include sensors/Make.defs
include serial/Make.defs
include spi/Make.defs
include syslog/Make.defs
include thermal/Make.defs
include timers/Make.defs
include usbdev/Make.defs
include usbhost/Make.defs
+5
View File
@@ -46,6 +46,7 @@
#include <nuttx/serial/uart_ram.h>
#include <nuttx/syslog/syslog.h>
#include <nuttx/syslog/syslog_console.h>
#include <nuttx/thermal.h>
#include <nuttx/trace.h>
#include <nuttx/usrsock/usrsock_rpmsg.h>
#include <nuttx/virtio/virtio.h>
@@ -271,5 +272,9 @@ void drivers_initialize(void)
optee_register();
#endif
#ifdef CONFIG_THERMAL
thermal_init();
#endif
drivers_trace_end();
}
+20
View File
@@ -0,0 +1,20 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
menuconfig THERMAL
bool "Thermal framework"
default n
---help---
Enable thermal framework.
if THERMAL
config THERMAL_DEFAULT_GOVERNOR
string "Thermal default governor name"
default "step_wise"
---help---
Default governor name.
endif # THERMAL
+30
View File
@@ -0,0 +1,30 @@
############################################################################
# drivers/thermal/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Include thermal sources
ifeq ($(CONFIG_THERMAL),y)
CSRCS += thermal_core.c
DEPPATH += --dep-path thermal
VPATH += thermal
endif
File diff suppressed because it is too large Load Diff
+76
View File
@@ -0,0 +1,76 @@
/****************************************************************************
* drivers/thermal/thermal_core.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __DRIVERS_THERMAL_THERMAL_CORE_H
#define __DRIVERS_THERMAL_THERMAL_CORE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/thermal.h>
/****************************************************************************
* Public Types
****************************************************************************/
struct thermal_instance_s
{
FAR struct thermal_cooling_device_s *cdev;
FAR struct thermal_zone_device_s *zdev;
int trip;
/* Cooling State */
unsigned int target; /* Expected Cooling State */
unsigned int upper; /* The Maximum cooling state for this trip point */
unsigned int lower; /* Minimum cooling state */
unsigned int weight;
struct list_node cdev_node;
struct list_node zdev_node;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* Cooling Device */
void
thermal_cooling_device_update (FAR struct thermal_cooling_device_s *cdev);
/* Zone Device */
int thermal_zone_enable (FAR struct thermal_zone_device_s *zdev,
bool enabled);
int thermal_zone_get_trend (FAR struct thermal_zone_device_s *zdev);
int thermal_zone_get_trip_temp(FAR struct thermal_zone_device_s *zdev,
int trip,
FAR int *temp);
int thermal_zone_get_trip_type(FAR struct thermal_zone_device_s *zdev,
int trip,
FAR enum thermal_trip_type_e *type);
int thermal_zone_get_trip_hyst(FAR struct thermal_zone_device_s *zdev,
int trip,
FAR int *hyst);
#endif /* __DRIVERS_THERMAL_THERMAL_CORE_H */
+18
View File
@@ -758,6 +758,24 @@
# define spiinfo _none
#endif
#ifdef CONFIG_DEBUG_THERMAL_ERROR
# define therr _err
#else
# define therr _none
#endif
#ifdef CONFIG_DEBUG_THERMAL_WARN
# define thwarn _warn
#else
# define thwarn _none
#endif
#ifdef CONFIG_DEBUG_THERMAL_INFO
# define thinfo _info
#else
# define thinfo _none
#endif
#ifdef CONFIG_DEBUG_TIMER_ERROR
# define tmrerr _err
#else
+205
View File
@@ -0,0 +1,205 @@
/****************************************************************************
* include/nuttx/thermal.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_THERMAL_H
#define __INCLUDE_NUTTX_THERMAL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/list.h>
#include <nuttx/mutex.h>
#include <nuttx/wqueue.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Generic */
#define THERMAL_NAME_LEN 32
/* Trips */
#define THERMAL_NO_LIMIT 0
/* Temperature */
#define THERMAL_INVALID_TEMP INT_MIN
/* Cooling State */
#define THERMAL_TARGET_MIN 0
#define THERMAL_TARGET_MAX (UINT_MAX - 1)
#define THERMAL_NO_TARGET UINT_MAX
/****************************************************************************
* Public Types
****************************************************************************/
struct thermal_cooling_device_ops_s;
struct thermal_zone_device_ops_s;
struct thermal_zone_device_s;
struct thermal_zone_params_s;
enum thermal_trend_e
{
THERMAL_TREND_RAISING,
THERMAL_TREND_DROPPING,
THERMAL_TREND_STABLE,
};
enum thermal_trip_type_e
{
THERMAL_COLD,
THERMAL_NORMAL,
THERMAL_HOT,
THERMAL_CRITICAL,
};
struct thermal_governor_s
{
struct list_node node;
FAR const char *name;
CODE int (*bind_to_tz) (FAR struct thermal_zone_device_s *zdev);
CODE int (*throttle) (FAR struct thermal_zone_device_s *zdev,
int trip);
CODE void (*unbind_from_tz)(FAR struct thermal_zone_device_s *zdev);
};
struct thermal_cooling_device_s
{
struct list_node node;
char name[THERMAL_NAME_LEN];
FAR void *devdata;
FAR const struct thermal_cooling_device_ops_s *ops;
struct list_node instance_list;
};
struct thermal_zone_device_s
{
struct list_node node;
char name[THERMAL_NAME_LEN];
bool enabled;
FAR void *devdata;
int last_temperature;
int temperature;
FAR const struct thermal_zone_device_ops_s *ops;
FAR struct thermal_governor_s *governor;
FAR const struct thermal_zone_params_s *params;
struct work_s monitor;
struct list_node instance_list;
};
struct thermal_cooling_device_ops_s
{
CODE int (*set_state) (FAR struct thermal_cooling_device_s *cdev,
unsigned int state);
CODE int (*get_state) (FAR struct thermal_cooling_device_s *cdev,
FAR unsigned int *state);
CODE int (*get_max_state)(FAR struct thermal_cooling_device_s *cdev,
FAR unsigned int *state);
};
struct thermal_zone_device_ops_s
{
CODE int (*get_temp) (FAR struct thermal_zone_device_s *zdev,
FAR int *temp);
CODE int (*get_trend) (FAR struct thermal_zone_device_s *zdev,
FAR enum thermal_trend_e *trend);
CODE int (*set_trips) (FAR struct thermal_zone_device_s *zdev,
int low, int high);
};
struct thermal_zone_map_s
{
FAR const char *trip_name;
FAR const char *cdev_name;
unsigned int low;
unsigned int high;
unsigned int weight;
};
struct thermal_zone_trip_s
{
FAR const char *name;
unsigned int temp;
unsigned int hyst;
enum thermal_trip_type_e type;
};
struct thermal_zone_params_s
{
FAR const char *gov_name;
int polling_delay;
FAR const struct thermal_zone_trip_s *trips;
int num_trips;
FAR const struct thermal_zone_map_s *maps;
int num_maps;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* Governor */
int thermal_register_governor (FAR struct thermal_governor_s *gov);
void thermal_unregister_governor(FAR struct thermal_governor_s *gov);
/* Cooling Device */
FAR struct thermal_cooling_device_s *
thermal_cooling_device_register(FAR const char *name, void *devdata,
FAR const struct thermal_cooling_device_ops_s *ops);
void
thermal_cooling_device_unregister(
FAR struct thermal_cooling_device_s *cdev);
/* Zone Device */
FAR struct thermal_zone_device_s *
thermal_zone_device_register(FAR const char *name, FAR void *devdata,
FAR const struct thermal_zone_device_ops_s *ops,
FAR const struct thermal_zone_params_s *params);
void
thermal_zone_device_unregister(
FAR struct thermal_zone_device_s *zdev);
void
thermal_zone_device_update (FAR struct thermal_zone_device_s *zdev);
/* Thermal Framework initialization */
int thermal_init(void);
#endif /* __INCLUDE_NUTTX_THERMAL_H */