forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/tools/thermal/tmon/tmon.c
....@@ -1,19 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * tmon.c Thermal Monitor (TMON) main function and entry point
34 *
45 * Copyright (C) 2012 Intel Corporation. All rights reserved.
56 *
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
- *
157 * Author: Jacob Pan <jacob.jun.pan@linux.intel.com>
16
- *
178 */
189
1910 #include <getopt.h>
....@@ -55,7 +46,7 @@
5546
5647 pthread_t event_tid;
5748 pthread_mutex_t input_lock;
58
-void usage()
49
+void usage(void)
5950 {
6051 printf("Usage: tmon [OPTION...]\n");
6152 printf(" -c, --control cooling device in control\n");
....@@ -71,7 +62,7 @@
7162 exit(0);
7263 }
7364
74
-void version()
65
+void version(void)
7566 {
7667 printf("TMON version %s\n", VERSION);
7768 exit(EXIT_SUCCESS);
....@@ -79,7 +70,6 @@
7970
8071 static void tmon_cleanup(void)
8172 {
82
-
8373 syslog(LOG_INFO, "TMON exit cleanup\n");
8474 fflush(stdout);
8575 refresh();
....@@ -105,7 +95,6 @@
10595 exit(1);
10696 }
10797
108
-
10998 static void tmon_sig_handler(int sig)
11099 {
111100 syslog(LOG_INFO, "TMON caught signal %d\n", sig);
....@@ -128,7 +117,6 @@
128117 }
129118 tmon_exit = true;
130119 }
131
-
132120
133121 static void start_syslog(void)
134122 {
....@@ -176,7 +164,6 @@
176164 return;
177165 }
178166
179
-
180167 fprintf(tmon_log, "#----------- THERMAL SYSTEM CONFIG -------------\n");
181168 for (i = 0; i < ptdata.nr_tz_sensor; i++) {
182169 char binding_str[33]; /* size of long + 1 */
....@@ -184,7 +171,7 @@
184171
185172 memset(binding_str, 0, sizeof(binding_str));
186173 for (j = 0; j < 32; j++)
187
- binding_str[j] = (ptdata.tzi[i].cdev_binding & 1<<j) ?
174
+ binding_str[j] = (ptdata.tzi[i].cdev_binding & (1 << j)) ?
188175 '1' : '0';
189176
190177 fprintf(tmon_log, "#thermal zone %s%02d cdevs binding: %32s\n",
....@@ -196,7 +183,6 @@
196183 trip_type_name[ptdata.tzi[i].tp[j].type],
197184 ptdata.tzi[i].tp[j].temp);
198185 }
199
-
200186 }
201187
202188 for (i = 0; i < ptdata.nr_cooling_dev; i++)
....@@ -227,7 +213,6 @@
227213 { "debug", 0, NULL, 'g' },
228214 { 0, 0, NULL, 0 }
229215 };
230
-
231216
232217 int main(int argc, char **argv)
233218 {
....@@ -292,7 +277,7 @@
292277 if (signal(SIGINT, tmon_sig_handler) == SIG_ERR)
293278 syslog(LOG_DEBUG, "Cannot handle SIGINT\n");
294279 if (signal(SIGTERM, tmon_sig_handler) == SIG_ERR)
295
- syslog(LOG_DEBUG, "Cannot handle SIGINT\n");
280
+ syslog(LOG_DEBUG, "Cannot handle SIGTERM\n");
296281
297282 if (probe_thermal_sysfs()) {
298283 pthread_mutex_destroy(&input_lock);
....@@ -337,8 +322,7 @@
337322 show_cooling_device();
338323 }
339324 time_elapsed += ticktime;
340
- controller_handler(trec[0].temp[target_tz_index] / 1000,
341
- &yk);
325
+ controller_handler(trec[0].temp[target_tz_index] / 1000, &yk);
342326 trec[0].pid_out_pct = yk;
343327 if (!dialogue_on)
344328 show_control_w();
....@@ -349,14 +333,15 @@
349333 return 0;
350334 }
351335
352
-static void start_daemon_mode()
336
+static void start_daemon_mode(void)
353337 {
354338 daemon_mode = 1;
355339 /* fork */
356340 pid_t sid, pid = fork();
357
- if (pid < 0) {
341
+
342
+ if (pid < 0)
358343 exit(EXIT_FAILURE);
359
- } else if (pid > 0)
344
+ else if (pid > 0)
360345 /* kill parent */
361346 exit(EXIT_SUCCESS);
362347
....@@ -375,11 +360,9 @@
375360 if ((chdir("/")) < 0)
376361 exit(EXIT_FAILURE);
377362
378
-
379363 sleep(10);
380364
381365 close(STDIN_FILENO);
382366 close(STDOUT_FILENO);
383367 close(STDERR_FILENO);
384
-
385368 }