blob: 93d1dafdd0cbfbe9b6e63ea3bb0b23b47af3f6d4 [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
Manaf Meethalavalappu Pallikunhi8c2153e2020-09-04 00:46:47 +0530115 std::vector<struct target_therm_cfg> sensor_cfg_holi =
116 {
117 {
118 TemperatureType::CPU,
119 cpu_sensors_lito,
120 "",
121 95000,
122 115000,
123 95000,
124 true,
125 },
126 {
127 TemperatureType::GPU,
128 { "gpuss-0-usr" },
129 "gpu0",
130 95000,
131 115000,
132 95000,
133 true,
134 },
135 {
136 TemperatureType::GPU,
137 { "gpuss-1-usr" },
138 "gpu1",
139 95000,
140 115000,
141 95000,
142 true,
143 },
144 {
145 TemperatureType::SKIN,
146 { "quiet-therm-usr" },
147 "skin",
148 40000,
149 95000,
150 40000,
151 true,
152 },
153 {
154 TemperatureType::BCL_CURRENT,
155 { "pm7250b-ibat-lvl0" },
156 "ibat",
157 5500,
158 6000,
159 5500,
160 true,
161 },
162 };
163
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700164 std::vector<std::string> cpu_sensors_kona =
165 {
166 "cpu-0-0-usr",
167 "cpu-0-1-usr",
168 "cpu-0-2-usr",
169 "cpu-0-3-usr",
170 "cpu-1-0-usr",
171 "cpu-1-1-usr",
172 "cpu-1-2-usr",
173 "cpu-1-3-usr",
174 };
175
176 std::vector<struct target_therm_cfg> kona_common = {
177 {
178 TemperatureType::CPU,
179 cpu_sensors_kona,
180 "",
181 95000,
182 115000,
183 95000,
184 true,
185 },
186 {
187 TemperatureType::GPU,
188 { "gpuss-0-usr" },
189 "GPU0",
190 95000,
191 115000,
192 95000,
193 true,
194 },
195 {
196 TemperatureType::GPU,
197 { "gpuss-1-usr" },
198 "GPU1",
199 95000,
200 115000,
201 95000,
202 true,
203 },
204 {
205 TemperatureType::SKIN,
206 { "skin-msm-therm-usr" },
207 "skin",
208 40000,
209 95000,
210 40000,
211 true,
212 }
213 };
214
215 std::vector<struct target_therm_cfg> kona_specific = {
216 {
217 TemperatureType::BCL_CURRENT,
218 { "pm8150b-ibat-lvl0" },
219 "ibat",
220 4500,
221 5000,
222 4500,
223 true,
224 },
225 {
226 TemperatureType::BCL_VOLTAGE,
227 { "pm8150b-vbat-lvl0" },
228 "vbat",
229 3200,
230 3000,
231 3200,
232 false,
233 },
234 {
235 TemperatureType::BCL_PERCENTAGE,
236 { "soc" },
237 "soc",
238 10,
239 2,
240 10,
241 false,
242 },
243 {
244 TemperatureType::NPU,
245 { "npu-usr" },
246 "npu",
247 95000,
Ram Chandrasekarc49329d2020-08-25 14:28:02 -0700248 115000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700249 95000,
250 true,
251 },
252 };
253
Manaf Meethalavalappu Pallikunhi9dd647c2020-09-09 01:20:40 +0530254 std::vector<std::string> cpu_sensors_lahaina =
255 {
256 "cpu-0-0-usr",
257 "cpu-0-1-usr",
258 "cpu-0-2-usr",
259 "cpu-0-3-usr",
260 "cpu-1-0-usr",
261 "cpu-1-2-usr",
262 "cpu-1-4-usr",
263 "cpu-1-6-usr",
264 };
265
266 std::vector<struct target_therm_cfg> lahaina_common = {
267 {
268 TemperatureType::CPU,
269 cpu_sensors_lahaina,
270 "",
271 95000,
272 115000,
273 95000,
274 true,
275 },
276 {
277 TemperatureType::GPU,
278 { "gpuss-0-usr" },
279 "GPU0",
280 95000,
281 115000,
282 95000,
283 true,
284 },
285 {
286 TemperatureType::GPU,
287 { "gpuss-1-usr" },
288 "GPU1",
289 95000,
290 115000,
291 95000,
292 true,
293 },
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700294 {
295 TemperatureType::BCL_CURRENT,
296 { "pm8350b-ibat-lvl0" },
297 "ibat",
Manaf Meethalavalappu Pallikunhi9dd647c2020-09-09 01:20:40 +0530298 6000,
299 7500,
300 6000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700301 true,
302 },
303 {
304 TemperatureType::NPU,
305 { "nspss-0-usr" },
306 "nsp0",
307 95000,
Ram Chandrasekarc49329d2020-08-25 14:28:02 -0700308 115000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700309 95000,
310 true,
311 },
312 {
313 TemperatureType::NPU,
314 { "nspss-1-usr" },
315 "nsp1",
316 95000,
Ram Chandrasekarc49329d2020-08-25 14:28:02 -0700317 115000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700318 95000,
319 true,
320 },
321 {
322 TemperatureType::NPU,
323 { "nspss-2-usr" },
324 "nsp2",
325 95000,
Ram Chandrasekarc49329d2020-08-25 14:28:02 -0700326 115000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700327 95000,
328 true,
329 },
330 };
331
Manaf Meethalavalappu Pallikunhi9dd647c2020-09-09 01:20:40 +0530332 std::vector<struct target_therm_cfg> lahaina_specific = {
333 {
334 TemperatureType::SKIN,
335 { "skin-msm-therm-usr" },
336 "skin",
337 40000,
338 95000,
339 40000,
340 true,
341 },
342 };
343
344 std::vector<struct target_therm_cfg> shima_specific = {
345 {
346 TemperatureType::SKIN,
347 { "quiet-therm-usr" },
348 "skin",
349 40000,
350 95000,
351 40000,
352 true,
353 },
354 };
355
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700356 struct target_therm_cfg bat_conf = {
357 TemperatureType::BATTERY,
358 { "battery" },
359 "battery",
360 80000,
361 90000,
362 80000,
363 true,
364 };
365
366 std::vector<struct target_therm_cfg> bcl_conf = {
367 {
368 TemperatureType::BCL_VOLTAGE,
369 { "vbat" },
370 "vbat",
371 3200,
372 3000,
373 3200,
374 false,
375 },
376 {
377 TemperatureType::BCL_PERCENTAGE,
378 { "socd" },
379 "socd",
380 90,
381 99,
382 90,
383 true,
384 },
385 };
386
387 const std::unordered_map<int, std::vector<struct target_therm_cfg>>
388 msm_soc_map = {
389 {400, sensor_cfg_lito}, // lito
390 {440, sensor_cfg_lito},
391 {407, sensor_cfg_lito}, // atoll
392 {434, sensor_cfg_lito}, // lagoon
393 {356, kona_common}, // kona
Manaf Meethalavalappu Pallikunhi9dd647c2020-09-09 01:20:40 +0530394 {415, lahaina_common}, // lahaina
395 {439, lahaina_common}, // lahainap
396 {456, lahaina_common}, // lahaina-atp
397 {450, lahaina_common}, // shima
Manaf Meethalavalappu Pallikunhi8c2153e2020-09-04 00:46:47 +0530398 {454, sensor_cfg_holi}, // holi
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700399 };
400
401 const std::unordered_map<int, std::vector<struct target_therm_cfg>>
402 msm_soc_specific = {
403 {356, kona_specific}, // kona
404 {415, lahaina_specific}, // lahaina
Manaf Meethalavalappu Pallikunhi9dd647c2020-09-09 01:20:40 +0530405 {439, lahaina_specific}, // lahainap
406 {456, lahaina_specific}, // lahaina-atp
407 {450, shima_specific}, // shima
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700408 };
409
410 std::vector<struct target_therm_cfg> add_target_config(
411 int socID,
412 std::vector<struct target_therm_cfg> conf)
413 {
414 std::vector<struct target_therm_cfg> targetConf;
415
416 if (msm_soc_specific.find(socID) == msm_soc_specific.end())
417 return conf;
418 targetConf = (msm_soc_specific.find(socID))->second;
419
420 conf.insert(conf.end(), targetConf.begin(),
421 targetConf.end());
422 return conf;
423 }
424
425 ThermalConfig::ThermalConfig():cmnInst()
426 {
427 std::unordered_map<int, std::vector<struct target_therm_cfg>>::const_iterator it;
428 std::vector<struct target_therm_cfg>::iterator it_vec;
429 bool bcl_defined = false;
430 std::string soc_val;
431
432 if (cmnInst.readFromFile(socIDPath, &soc_val) <= 0) {
433 LOG(ERROR) <<"soc ID fetch error";
434 return;
435 }
436 soc_id = std::stoi(soc_val, nullptr, 0);
437 if (soc_id <= 0) {
438 LOG(ERROR) << "Invalid soc ID: " << soc_id;
439 return;
440 }
441 it = msm_soc_map.find(soc_id);
442 if (it == msm_soc_map.end()) {
443 LOG(ERROR) << "No config for soc ID: " << soc_id;
444 return;
445 }
446 thermalConfig = add_target_config(soc_id, it->second);
447 for (it_vec = thermalConfig.begin();
448 it_vec != thermalConfig.end(); it_vec++) {
449 if (it_vec->type == TemperatureType::BCL_PERCENTAGE)
450 bcl_defined = true;
451 }
452
453 thermalConfig.push_back(bat_conf);
454 if (!bcl_defined)
455 thermalConfig.insert(thermalConfig.end(),
456 bcl_conf.begin(), bcl_conf.end());
457 LOG(DEBUG) << "Total sensors:" << thermalConfig.size();
458 }
459} // namespace implementation
460} // namespace V2_0
461} // namespace thermal
462} // namespace hardware
463} // namespace android
464