Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * tmon.h contains data structures and constants used by TMON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2012 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author Name Jacob Pan <jacob.jun.pan@linux.intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifndef TMON_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define TMON_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define MAX_DISP_TEMP 125
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define MAX_CTRL_TEMP 105
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define MIN_CTRL_TEMP 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define MAX_NR_TZONE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define MAX_NR_CDEV 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define MAX_NR_TRIP 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define MAX_NR_CDEV_TRIP 12 /* number of cooling devices that can bind
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 			     * to a thermal zone trip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 			     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define MAX_TEMP_KC 140000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /* starting char position to draw sensor data, such as tz names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * trip point list, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DATA_LEFT_ALIGN 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define NR_LINES_TZDATA 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define TMON_LOG_FILE "/var/tmp/tmon.log"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) extern unsigned long ticktime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) extern double time_elapsed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) extern unsigned long target_temp_user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) extern int dialogue_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) extern char ctrl_cdev[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) extern pthread_mutex_t input_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) extern int tmon_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) extern int target_thermal_zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) /* use fixed size record to simplify data processing and transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * TBD: more info to be added, e.g. programmable trip point data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) struct thermal_data_record {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct timeval tv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned long temp[MAX_NR_TZONE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	double pid_out_pct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) struct cdev_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	char type[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	unsigned long max_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	unsigned long cur_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned long flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) enum trip_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	THERMAL_TRIP_CRITICAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	THERMAL_TRIP_HOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	THERMAL_TRIP_PASSIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	THERMAL_TRIP_ACTIVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	NR_THERMAL_TRIP_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct trip_point {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	enum trip_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	unsigned long temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned long hysteresis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int attribute; /* programmability etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /* thermal zone configuration information, binding with cooling devices could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * change at runtime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) struct tz_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	char type[256]; /* e.g. acpitz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int passive; /* active zone has passive node to force passive mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	int nr_cdev; /* number of cooling device binded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int nr_trip_pts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct trip_point tp[MAX_NR_TRIP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	unsigned long cdev_binding; /* bitmap for attached cdevs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	/* cdev bind trip points, allow one cdev bind to multiple trips */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	unsigned long trip_binding[MAX_NR_CDEV];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) struct tmon_platform_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	int nr_tz_sensor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int nr_cooling_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	/* keep track of instance ids since there might be gaps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int max_tz_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int max_cdev_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct tz_info *tzi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct cdev_info *cdi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) struct control_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	void (*set_ratio)(unsigned long ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	unsigned long (*get_ratio)(unsigned long ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) enum cdev_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	CDEV_TYPE_PROC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	CDEV_TYPE_FAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	CDEV_TYPE_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	CDEV_TYPE_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* REVISIT: the idea is to group sensors if possible, e.g. on intel mid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * we have "skin0", "skin1", "sys", "msicdie"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * on DPTF enabled systems, we might have PCH, TSKN, TAMB, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) enum tzone_types {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	TZONE_TYPE_ACPI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	TZONE_TYPE_PCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	TZONE_TYPE_NR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* limit the output of PID controller adjustment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define LIMIT_HIGH (95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define LIMIT_LOW  (2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct pid_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	double kp;  /* Controller gain from Dialog Box */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	double ki;  /* Time-constant for I action from Dialog Box */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	double kd;  /* Time-constant for D action from Dialog Box */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	double ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	double k_lpf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	double t_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	double y_k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) extern int init_thermal_controller(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) extern void controller_handler(const double xk, double *yk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) extern struct tmon_platform_data ptdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) extern struct pid_params p_param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) extern FILE *tmon_log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) extern int cur_thermal_record; /* index to the trec array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) extern struct thermal_data_record trec[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) extern const char *trip_type_name[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) extern unsigned long no_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) extern void initialize_curses(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) extern void show_controller_stats(char *line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) extern void show_title_bar(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) extern void setup_windows(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) extern void disable_tui(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) extern void show_sensors_w(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) extern void show_data_w(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) extern void write_status_bar(int x, char *line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) extern void show_control_w();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) extern void show_cooling_device(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) extern void show_dialogue(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) extern int update_thermal_data(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) extern int probe_thermal_sysfs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) extern void free_thermal_data(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) extern	void resize_handler(int sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) extern void set_ctrl_state(unsigned long state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) extern void get_ctrl_state(unsigned long *state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) extern void *handle_tui_events(void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) extern int sysfs_set_ulong(char *path, char *filename, unsigned long val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) extern int zone_instance_to_index(int zone_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) extern void close_windows(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define PT_COLOR_DEFAULT    1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define PT_COLOR_HEADER_BAR 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #define PT_COLOR_ERROR      3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #define PT_COLOR_RED        4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #define PT_COLOR_YELLOW     5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #define PT_COLOR_GREEN      6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #define PT_COLOR_BRIGHT     7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define PT_COLOR_BLUE	    8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* each thermal zone uses 12 chars, 8 for name, 2 for instance, 2 space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * also used to list trip points in forms of AAAC, which represents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * A: Active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * C: Critical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define TZONE_RECORD_SIZE 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define TZ_LEFT_ALIGN 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define CDEV_NAME_SIZE 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #define CDEV_FLAG_IN_CONTROL (1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* dialogue box starts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #define DIAG_X 48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #define DIAG_Y 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #define THERMAL_SYSFS "/sys/class/thermal"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define CDEV "cooling_device"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define TZONE "thermal_zone"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #define TDATA_LEFT 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #endif /* TMON_H */