blob: 7525022765f3a7b064485367d906d47686b4f47f [file] [log] [blame]
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -07001/*
2 * Copyright (c) 2020, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 *
18 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <unordered_map>
32#include <android-base/logging.h>
33#include <android/hardware/thermal/2.0/IThermal.h>
34
35#include "thermalData.h"
36#include "thermalConfig.h"
37
38namespace android {
39namespace hardware {
40namespace thermal {
41namespace V2_0 {
42namespace implementation {
43 constexpr std::string_view socIDPath("/sys/devices/soc0/soc_id");
44
45 std::vector<std::string> cpu_sensors_lito =
46 {
47 "cpu-0-0-usr",
48 "cpu-0-1-usr",
49 "cpu-0-2-usr",
50 "cpu-0-3-usr",
51 "cpu-0-4-usr",
52 "cpu-0-5-usr",
53 "cpu-1-0-usr",
54 "cpu-1-2-usr",
55 };
56
57 std::vector<struct target_therm_cfg> sensor_cfg_lito =
58 {
59 {
60 TemperatureType::CPU,
61 cpu_sensors_lito,
62 "",
63 95000,
64 115000,
65 95000,
66 true,
67 },
68 {
69 TemperatureType::GPU,
70 { "gpuss-0-usr" },
71 "GPU",
72 95000,
73 115000,
74 95000,
75 true,
76 },
77 {
78 TemperatureType::SKIN,
79 { "xo-therm-usr" },
80 "skin",
81 40000,
82 45000,
83 40000,
84 true,
85 },
86 {
87 TemperatureType::BCL_CURRENT,
88 { "pm7250b-ibat-lvl0" },
89 "ibat",
90 4500,
91 5000,
92 4500,
93 true,
94 },
95 {
96 TemperatureType::BCL_VOLTAGE,
97 { "pm7250b-vbat-lvl0" },
98 "vbat",
99 3200,
100 3000,
101 3200,
102 false,
103 },
104 {
105 TemperatureType::BCL_PERCENTAGE,
106 { "soc" },
107 "soc",
108 10,
109 2,
110 10,
111 false,
112 },
113 };
114
115 std::vector<std::string> cpu_sensors_kona =
116 {
117 "cpu-0-0-usr",
118 "cpu-0-1-usr",
119 "cpu-0-2-usr",
120 "cpu-0-3-usr",
121 "cpu-1-0-usr",
122 "cpu-1-1-usr",
123 "cpu-1-2-usr",
124 "cpu-1-3-usr",
125 };
126
127 std::vector<struct target_therm_cfg> kona_common = {
128 {
129 TemperatureType::CPU,
130 cpu_sensors_kona,
131 "",
132 95000,
133 115000,
134 95000,
135 true,
136 },
137 {
138 TemperatureType::GPU,
139 { "gpuss-0-usr" },
140 "GPU0",
141 95000,
142 115000,
143 95000,
144 true,
145 },
146 {
147 TemperatureType::GPU,
148 { "gpuss-1-usr" },
149 "GPU1",
150 95000,
151 115000,
152 95000,
153 true,
154 },
155 {
156 TemperatureType::SKIN,
157 { "skin-msm-therm-usr" },
158 "skin",
159 40000,
160 95000,
161 40000,
162 true,
163 }
164 };
165
166 std::vector<struct target_therm_cfg> kona_specific = {
167 {
168 TemperatureType::BCL_CURRENT,
169 { "pm8150b-ibat-lvl0" },
170 "ibat",
171 4500,
172 5000,
173 4500,
174 true,
175 },
176 {
177 TemperatureType::BCL_VOLTAGE,
178 { "pm8150b-vbat-lvl0" },
179 "vbat",
180 3200,
181 3000,
182 3200,
183 false,
184 },
185 {
186 TemperatureType::BCL_PERCENTAGE,
187 { "soc" },
188 "soc",
189 10,
190 2,
191 10,
192 false,
193 },
194 {
195 TemperatureType::NPU,
196 { "npu-usr" },
197 "npu",
198 95000,
199 105000,
200 95000,
201 true,
202 },
203 };
204
205 std::vector<struct target_therm_cfg> lahaina_specific = {
206 {
207 TemperatureType::BCL_CURRENT,
208 { "pm8350b-ibat-lvl0" },
209 "ibat",
210 4500,
211 5000,
212 4500,
213 true,
214 },
215 {
216 TemperatureType::NPU,
217 { "nspss-0-usr" },
218 "nsp0",
219 95000,
220 105000,
221 95000,
222 true,
223 },
224 {
225 TemperatureType::NPU,
226 { "nspss-1-usr" },
227 "nsp1",
228 95000,
229 105000,
230 95000,
231 true,
232 },
233 {
234 TemperatureType::NPU,
235 { "nspss-2-usr" },
236 "nsp2",
237 95000,
238 105000,
239 95000,
240 true,
241 },
242 };
243
244 struct target_therm_cfg bat_conf = {
245 TemperatureType::BATTERY,
246 { "battery" },
247 "battery",
248 80000,
249 90000,
250 80000,
251 true,
252 };
253
254 std::vector<struct target_therm_cfg> bcl_conf = {
255 {
256 TemperatureType::BCL_VOLTAGE,
257 { "vbat" },
258 "vbat",
259 3200,
260 3000,
261 3200,
262 false,
263 },
264 {
265 TemperatureType::BCL_PERCENTAGE,
266 { "socd" },
267 "socd",
268 90,
269 99,
270 90,
271 true,
272 },
273 };
274
275 const std::unordered_map<int, std::vector<struct target_therm_cfg>>
276 msm_soc_map = {
277 {400, sensor_cfg_lito}, // lito
278 {440, sensor_cfg_lito},
279 {407, sensor_cfg_lito}, // atoll
280 {434, sensor_cfg_lito}, // lagoon
281 {356, kona_common}, // kona
282 {415, kona_common}, // lahaina
283 };
284
285 const std::unordered_map<int, std::vector<struct target_therm_cfg>>
286 msm_soc_specific = {
287 {356, kona_specific}, // kona
288 {415, lahaina_specific}, // lahaina
289 };
290
291 std::vector<struct target_therm_cfg> add_target_config(
292 int socID,
293 std::vector<struct target_therm_cfg> conf)
294 {
295 std::vector<struct target_therm_cfg> targetConf;
296
297 if (msm_soc_specific.find(socID) == msm_soc_specific.end())
298 return conf;
299 targetConf = (msm_soc_specific.find(socID))->second;
300
301 conf.insert(conf.end(), targetConf.begin(),
302 targetConf.end());
303 return conf;
304 }
305
306 ThermalConfig::ThermalConfig():cmnInst()
307 {
308 std::unordered_map<int, std::vector<struct target_therm_cfg>>::const_iterator it;
309 std::vector<struct target_therm_cfg>::iterator it_vec;
310 bool bcl_defined = false;
311 std::string soc_val;
312
313 if (cmnInst.readFromFile(socIDPath, &soc_val) <= 0) {
314 LOG(ERROR) <<"soc ID fetch error";
315 return;
316 }
317 soc_id = std::stoi(soc_val, nullptr, 0);
318 if (soc_id <= 0) {
319 LOG(ERROR) << "Invalid soc ID: " << soc_id;
320 return;
321 }
322 it = msm_soc_map.find(soc_id);
323 if (it == msm_soc_map.end()) {
324 LOG(ERROR) << "No config for soc ID: " << soc_id;
325 return;
326 }
327 thermalConfig = add_target_config(soc_id, it->second);
328 for (it_vec = thermalConfig.begin();
329 it_vec != thermalConfig.end(); it_vec++) {
330 if (it_vec->type == TemperatureType::BCL_PERCENTAGE)
331 bcl_defined = true;
332 }
333
334 thermalConfig.push_back(bat_conf);
335 if (!bcl_defined)
336 thermalConfig.insert(thermalConfig.end(),
337 bcl_conf.begin(), bcl_conf.end());
338 LOG(DEBUG) << "Total sensors:" << thermalConfig.size();
339 }
340} // namespace implementation
341} // namespace V2_0
342} // namespace thermal
343} // namespace hardware
344} // namespace android
345