blob: b6682d8184c0034fd9659ea135f154a481ad5a2d [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
254 std::vector<struct target_therm_cfg> lahaina_specific = {
255 {
256 TemperatureType::BCL_CURRENT,
257 { "pm8350b-ibat-lvl0" },
258 "ibat",
259 4500,
260 5000,
261 4500,
262 true,
263 },
264 {
265 TemperatureType::NPU,
266 { "nspss-0-usr" },
267 "nsp0",
268 95000,
Ram Chandrasekarc49329d2020-08-25 14:28:02 -0700269 115000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700270 95000,
271 true,
272 },
273 {
274 TemperatureType::NPU,
275 { "nspss-1-usr" },
276 "nsp1",
277 95000,
Ram Chandrasekarc49329d2020-08-25 14:28:02 -0700278 115000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700279 95000,
280 true,
281 },
282 {
283 TemperatureType::NPU,
284 { "nspss-2-usr" },
285 "nsp2",
286 95000,
Ram Chandrasekarc49329d2020-08-25 14:28:02 -0700287 115000,
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700288 95000,
289 true,
290 },
291 };
292
293 struct target_therm_cfg bat_conf = {
294 TemperatureType::BATTERY,
295 { "battery" },
296 "battery",
297 80000,
298 90000,
299 80000,
300 true,
301 };
302
303 std::vector<struct target_therm_cfg> bcl_conf = {
304 {
305 TemperatureType::BCL_VOLTAGE,
306 { "vbat" },
307 "vbat",
308 3200,
309 3000,
310 3200,
311 false,
312 },
313 {
314 TemperatureType::BCL_PERCENTAGE,
315 { "socd" },
316 "socd",
317 90,
318 99,
319 90,
320 true,
321 },
322 };
323
324 const std::unordered_map<int, std::vector<struct target_therm_cfg>>
325 msm_soc_map = {
326 {400, sensor_cfg_lito}, // lito
327 {440, sensor_cfg_lito},
328 {407, sensor_cfg_lito}, // atoll
329 {434, sensor_cfg_lito}, // lagoon
330 {356, kona_common}, // kona
331 {415, kona_common}, // lahaina
Manaf Meethalavalappu Pallikunhi8c2153e2020-09-04 00:46:47 +0530332 {454, sensor_cfg_holi}, // holi
Ram Chandrasekardac8f7d2020-06-10 12:23:28 -0700333 };
334
335 const std::unordered_map<int, std::vector<struct target_therm_cfg>>
336 msm_soc_specific = {
337 {356, kona_specific}, // kona
338 {415, lahaina_specific}, // lahaina
339 };
340
341 std::vector<struct target_therm_cfg> add_target_config(
342 int socID,
343 std::vector<struct target_therm_cfg> conf)
344 {
345 std::vector<struct target_therm_cfg> targetConf;
346
347 if (msm_soc_specific.find(socID) == msm_soc_specific.end())
348 return conf;
349 targetConf = (msm_soc_specific.find(socID))->second;
350
351 conf.insert(conf.end(), targetConf.begin(),
352 targetConf.end());
353 return conf;
354 }
355
356 ThermalConfig::ThermalConfig():cmnInst()
357 {
358 std::unordered_map<int, std::vector<struct target_therm_cfg>>::const_iterator it;
359 std::vector<struct target_therm_cfg>::iterator it_vec;
360 bool bcl_defined = false;
361 std::string soc_val;
362
363 if (cmnInst.readFromFile(socIDPath, &soc_val) <= 0) {
364 LOG(ERROR) <<"soc ID fetch error";
365 return;
366 }
367 soc_id = std::stoi(soc_val, nullptr, 0);
368 if (soc_id <= 0) {
369 LOG(ERROR) << "Invalid soc ID: " << soc_id;
370 return;
371 }
372 it = msm_soc_map.find(soc_id);
373 if (it == msm_soc_map.end()) {
374 LOG(ERROR) << "No config for soc ID: " << soc_id;
375 return;
376 }
377 thermalConfig = add_target_config(soc_id, it->second);
378 for (it_vec = thermalConfig.begin();
379 it_vec != thermalConfig.end(); it_vec++) {
380 if (it_vec->type == TemperatureType::BCL_PERCENTAGE)
381 bcl_defined = true;
382 }
383
384 thermalConfig.push_back(bat_conf);
385 if (!bcl_defined)
386 thermalConfig.insert(thermalConfig.end(),
387 bcl_conf.begin(), bcl_conf.end());
388 LOG(DEBUG) << "Total sensors:" << thermalConfig.size();
389 }
390} // namespace implementation
391} // namespace V2_0
392} // namespace thermal
393} // namespace hardware
394} // namespace android
395