GNU Linux-libre 4.19.286-gnu1
[releases.git] / tools / thermal / tmon / tmon.h
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
39 #include <sys/time.h>
40 #include <pthread.h>
41
42 extern unsigned long ticktime;
43 extern double time_elapsed;
44 extern unsigned long target_temp_user;
45 extern int dialogue_on;
46 extern char ctrl_cdev[];
47 extern pthread_mutex_t input_lock;
48 extern int tmon_exit;
49 extern int target_thermal_zone;
50 /* use fixed size record to simplify data processing and transfer
51  * TBD: more info to be added, e.g. programmable trip point data.
52 */
53 struct thermal_data_record {
54         struct timeval tv;
55         unsigned long temp[MAX_NR_TZONE];
56         double pid_out_pct;
57 };
58
59 struct cdev_info {
60         char type[64];
61         int instance;
62         unsigned long max_state;
63         unsigned long cur_state;
64         unsigned long flag;
65 };
66
67 enum trip_type {
68         THERMAL_TRIP_CRITICAL,
69         THERMAL_TRIP_HOT,
70         THERMAL_TRIP_PASSIVE,
71         THERMAL_TRIP_ACTIVE,
72         NR_THERMAL_TRIP_TYPE,
73 };
74
75 struct trip_point {
76         enum trip_type type;
77         unsigned long temp;
78         unsigned long hysteresis;
79         int attribute; /* programmability etc. */
80 };
81
82 /* thermal zone configuration information, binding with cooling devices could
83  * change at runtime.
84  */
85 struct tz_info {
86         char type[256]; /* e.g. acpitz */
87         int instance;
88         int passive; /* active zone has passive node to force passive mode */
89         int nr_cdev; /* number of cooling device binded */
90         int nr_trip_pts;
91         struct trip_point tp[MAX_NR_TRIP];
92         unsigned long cdev_binding; /* bitmap for attached cdevs */
93         /* cdev bind trip points, allow one cdev bind to multiple trips */
94         unsigned long trip_binding[MAX_NR_CDEV];
95 };
96
97 struct tmon_platform_data {
98         int nr_tz_sensor;
99         int nr_cooling_dev;
100         /* keep track of instance ids since there might be gaps */
101         int max_tz_instance;
102         int max_cdev_instance;
103         struct tz_info *tzi;
104         struct cdev_info *cdi;
105 };
106
107 struct control_ops {
108         void (*set_ratio)(unsigned long ratio);
109         unsigned long (*get_ratio)(unsigned long ratio);
110
111 };
112
113 enum cdev_types {
114         CDEV_TYPE_PROC,
115         CDEV_TYPE_FAN,
116         CDEV_TYPE_MEM,
117         CDEV_TYPE_NR,
118 };
119
120 /* REVISIT: the idea is to group sensors if possible, e.g. on intel mid
121  * we have "skin0", "skin1", "sys", "msicdie"
122  * on DPTF enabled systems, we might have PCH, TSKN, TAMB, etc.
123  */
124 enum tzone_types {
125         TZONE_TYPE_ACPI,
126         TZONE_TYPE_PCH,
127         TZONE_TYPE_NR,
128 };
129
130 /* limit the output of PID controller adjustment */
131 #define LIMIT_HIGH (95)
132 #define LIMIT_LOW  (2)
133
134 struct pid_params {
135         double kp;  /* Controller gain from Dialog Box */
136         double ki;  /* Time-constant for I action from Dialog Box */
137         double kd;  /* Time-constant for D action from Dialog Box */
138         double ts;
139         double k_lpf;
140
141         double t_target;
142         double y_k;
143 };
144
145 extern int init_thermal_controller(void);
146 extern void controller_handler(const double xk, double *yk);
147
148 extern struct tmon_platform_data ptdata;
149 extern struct pid_params p_param;
150
151 extern FILE *tmon_log;
152 extern int cur_thermal_record; /* index to the trec array */
153 extern struct thermal_data_record trec[];
154 extern const char *trip_type_name[];
155 extern unsigned long no_control;
156
157 extern void initialize_curses(void);
158 extern void show_controller_stats(char *line);
159 extern void show_title_bar(void);
160 extern void setup_windows(void);
161 extern void disable_tui(void);
162 extern void show_sensors_w(void);
163 extern void show_data_w(void);
164 extern void write_status_bar(int x, char *line);
165 extern void show_control_w();
166
167 extern void show_cooling_device(void);
168 extern void show_dialogue(void);
169 extern int update_thermal_data(void);
170
171 extern int probe_thermal_sysfs(void);
172 extern void free_thermal_data(void);
173 extern  void resize_handler(int sig);
174 extern void set_ctrl_state(unsigned long state);
175 extern void get_ctrl_state(unsigned long *state);
176 extern void *handle_tui_events(void *arg);
177 extern int sysfs_set_ulong(char *path, char *filename, unsigned long val);
178 extern int zone_instance_to_index(int zone_inst);
179 extern void close_windows(void);
180
181 #define PT_COLOR_DEFAULT    1
182 #define PT_COLOR_HEADER_BAR 2
183 #define PT_COLOR_ERROR      3
184 #define PT_COLOR_RED        4
185 #define PT_COLOR_YELLOW     5
186 #define PT_COLOR_GREEN      6
187 #define PT_COLOR_BRIGHT     7
188 #define PT_COLOR_BLUE       8
189
190 /* each thermal zone uses 12 chars, 8 for name, 2 for instance, 2 space
191  * also used to list trip points in forms of AAAC, which represents
192  * A: Active
193  * C: Critical
194  */
195 #define TZONE_RECORD_SIZE 12
196 #define TZ_LEFT_ALIGN 32
197 #define CDEV_NAME_SIZE 20
198 #define CDEV_FLAG_IN_CONTROL (1 << 0)
199
200 /* dialogue box starts */
201 #define DIAG_X 48
202 #define DIAG_Y 8
203 #define THERMAL_SYSFS "/sys/class/thermal"
204 #define CDEV "cooling_device"
205 #define TZONE "thermal_zone"
206 #define TDATA_LEFT 16
207 #endif /* TMON_H */