2
* thd_zone_therm_sys_fs.cpp: thermal zone class implementation
4
* Copyright (C) 2012 Intel Corporation. All rights reserved.
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.
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.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
* Author Name <Srinivas.Pandruvada@linux.intel.com>
25
#include "thd_zone_therm_sys_fs.h"
26
#include "thd_engine.h"
29
cthd_sysfs_zone::cthd_sysfs_zone(int count, std::string path) :
30
cthd_zone(count, path), trip_point_cnt(0), zone(NULL) {
32
std::stringstream tc_type_dev;
33
tc_type_dev << index << "/type";
35
thd_log_debug("Thermal Zone look for %s\n", tc_type_dev.str().c_str());
37
if (zone_sysfs.exists(tc_type_dev.str())) {
38
zone_sysfs.read(tc_type_dev.str(), type_str);
41
thd_log_debug("Thermal Zone %d:%s\n", index, type_str.c_str());
44
int cthd_sysfs_zone::zone_bind_sensors() {
47
sensor = thd_engine->search_sensor(type_str);
56
int cthd_sysfs_zone::read_trip_points() {
58
// Gather all trip points
59
std::stringstream trip_sysfs;
60
trip_sysfs << index << "/" << "trip_point_";
61
for (int i = 0; i < max_trip_points; ++i) {
62
std::stringstream type_stream;
63
std::stringstream temp_stream;
64
std::stringstream hist_stream;
65
std::string _type_str;
66
std::string _temp_str;
67
std::string _hist_str;
68
trip_point_type_t trip_type;
69
unsigned int temp = 0, hyst = 1;
71
type_stream << trip_sysfs.str() << i << "_type";
72
if (zone_sysfs.exists(type_stream.str())) {
73
zone_sysfs.read(type_stream.str(), _type_str);
74
thd_log_debug("read_trip_points %s:%s \n",
75
type_stream.str().c_str(), _type_str.c_str());
77
temp_stream << trip_sysfs.str() << i << "_temp";
78
if (zone_sysfs.exists(temp_stream.str())) {
79
zone_sysfs.read(temp_stream.str(), _temp_str);
80
std::istringstream(_temp_str) >> temp;
81
thd_log_debug("read_trip_points %s:%s \n",
82
temp_stream.str().c_str(), _temp_str.c_str());
85
hist_stream << trip_sysfs.str() << i << "_hyst";
86
if (zone_sysfs.exists(hist_stream.str())) {
87
zone_sysfs.read(hist_stream.str(), _hist_str);
88
std::istringstream(_hist_str) >> hyst;
89
thd_log_debug("read_trip_points %s:%s \n",
90
hist_stream.str().c_str(), _hist_str.c_str());
93
if (_type_str == "critical")
95
else if (_type_str == "hot")
97
else if (_type_str == "active")
99
else if (_type_str == "passive")
102
trip_type = INVALID_TRIP_TYPE;
103
if (temp > 0 && trip_type != INVALID_TRIP_TYPE) {
106
sensor = thd_engine->search_sensor(type_str);
108
cthd_trip_point trip_pt(trip_point_cnt, trip_type, temp, hyst,
109
index, sensor->get_index());
110
trip_points.push_back(trip_pt);
115
thd_log_debug("read_trip_points Added %d trips \n", trip_point_cnt);
116
if (trip_point_cnt == 0)
122
int cthd_sysfs_zone::read_cdev_trip_points() {
123
thd_log_debug(" >> read_cdev_trip_points for \n");
126
// Gather all trip points
127
std::stringstream cdev_sysfs;
128
cdev_sysfs << index << "/" << "cdev";
129
for (int i = 0; i < max_cool_devs; ++i) {
130
std::stringstream trip_pt_stream, cdev_stream;
131
std::string trip_pt_str;
134
trip_pt_stream << cdev_sysfs.str() << i << "_trip_point";
136
if (zone_sysfs.exists(trip_pt_stream.str())) {
137
zone_sysfs.read(trip_pt_stream.str(), trip_pt_str);
138
std::istringstream(trip_pt_str) >> trip_cnt;
141
thd_log_debug("cdev trip point: %s contains %d\n", trip_pt_str.c_str(),
143
cdev_stream << cdev_sysfs.str() << i;
144
if (zone_sysfs.exists(cdev_stream.str())) {
145
thd_log_debug("cdev%d present\n", i);
146
int ret = zone_sysfs.read_symbolic_link_value(cdev_stream.str(),
149
ptr = strstr(buf, "cooling_device");
151
ptr += strlen("cooling_device");
152
thd_log_debug("symbolic name %s:%s\n", buf, ptr);
154
trip_points[trip_cnt].thd_trip_point_add_cdev_index(
155
atoi(ptr), cthd_trip_point::default_influence);
156
zone_cdev_binded_status = true;
163
"cthd_sysfs_zone::read_cdev_trip_points: ZONE bound to CDEV status %d \n",
164
zone_cdev_binded_status);