blob: dc72f5c3317b9c645547248bc079cde6e6551b6e [file] [log] [blame]
Ram Chandrasekar14a48f52021-04-06 13:25:32 -07001/*
2 * Copyright (c) 2021, The Linux Foundation. All rights reserved.
Manaf Meethalavalappu Pallikunhiab1e3c52022-05-14 01:53:29 +05303 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Ram Chandrasekar14a48f52021-04-06 13:25:32 -07004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * * Neither the name of The Linux Foundation nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 *
19 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef THERMAL_THERMAL_UTILS_H__
33#define THERMAL_THERMAL_UTILS_H__
34
35#include <unordered_map>
36#include <mutex>
37#include <android/hardware/thermal/2.0/IThermal.h>
38#include "thermalConfig.h"
39#include "thermalMonitorNetlink.h"
40#include "thermalCommon.h"
41#include "thermalData.h"
42
43namespace android {
44namespace hardware {
45namespace thermal {
46namespace V2_0 {
47namespace implementation {
48
49using ueventCB = std::function<void(Temperature &t)>;
50
51class ThermalUtils {
52 public:
53 ThermalUtils(const ueventCB &inp_cb);
54 ~ThermalUtils() = default;
55 bool isSensorInitialized()
56 {
57 return is_sensor_init;
58 };
59 bool isCdevInitialized()
60 {
61 return is_cdev_init;
62 };
63 int readTemperatures(hidl_vec<Temperature_1_0>& temp);
64 int readTemperatures(bool filterType, TemperatureType type,
65 hidl_vec<Temperature>& temperatures);
66 int readTemperatureThreshold(bool filterType, TemperatureType type,
67 hidl_vec<TemperatureThreshold>& thresh);
68 int readCdevStates(bool filterType, cdevType type,
69 hidl_vec<CoolingDevice>& cdev);
70 int fetchCpuUsages(hidl_vec<CpuUsage>& cpu_usages);
71 private:
72 bool is_sensor_init;
73 bool is_cdev_init;
74 ThermalConfig cfg;
75 ThermalCommon cmnInst;
76 ThermalMonitor monitor;
77 std::unordered_map<int, struct therm_sensor>
78 thermalConfig;
79 std::vector<struct therm_cdev> cdevList;
80 std::mutex sens_cb_mutex;
81 ueventCB cb;
82
83 void eventParse(int tzn, int trip);
84 void sampleParse(int tzn, int temp);
Manaf Meethalavalappu Pallikunhiab1e3c52022-05-14 01:53:29 +053085 void eventCreateParse(int tzn, const char *name);
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070086 void Notify(struct therm_sensor& sens);
87};
88
89} // namespace implementation
90} // namespace V2_0
91} // namespace thermal
92} // namespace hardware
93} // namespace android
94
95#endif // THERMAL_THERMAL_UTILS_H__