Linux Audio

Check our new training course

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