blob: bee0fbce6a062561e2282330b16f14a63469b225 [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
Bavyasritha Alahari0a344f42023-04-26 17:16:51 -070032/* Changes from Qualcomm Innovation Center are provided under the following license:
33
Priyansh Jainc5ea5602024-08-12 11:18:21 +053034Copyright (c) 2023, 2025 Qualcomm Innovation Center, Inc. All rights reserved.
Bavyasritha Alahari0a344f42023-04-26 17:16:51 -070035SPDX-License-Identifier: BSD-3-Clause-Clear */
36
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070037#ifndef THERMAL_THERMAL_UTILS_H__
38#define THERMAL_THERMAL_UTILS_H__
39
40#include <unordered_map>
41#include <mutex>
Bavyasritha Alahari0a344f42023-04-26 17:16:51 -070042#include <aidl/android/hardware/thermal/BnThermal.h>
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070043#include "thermalConfig.h"
44#include "thermalMonitorNetlink.h"
45#include "thermalCommon.h"
46#include "thermalData.h"
47
Bavyasritha Alahari0a344f42023-04-26 17:16:51 -070048namespace aidl {
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070049namespace android {
50namespace hardware {
51namespace thermal {
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070052
53using ueventCB = std::function<void(Temperature &t)>;
54
55class ThermalUtils {
56 public:
57 ThermalUtils(const ueventCB &inp_cb);
58 ~ThermalUtils() = default;
Priyansh Jainc5ea5602024-08-12 11:18:21 +053059 bool isSensorInitialized();
60 bool isSensorInitialized(TemperatureType type);
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070061 bool isCdevInitialized()
62 {
63 return is_cdev_init;
64 };
Bavyasritha Alahari0a344f42023-04-26 17:16:51 -070065 int readTemperatures(std::vector<Temperature>& temp);
66 int readTemperatures(TemperatureType type,
67 std::vector<Temperature>& temperatures);
68 int readTemperatureThreshold(std::vector<TemperatureThreshold>& thresh);
69 int readTemperatureThreshold(TemperatureType type,
70 std::vector<TemperatureThreshold>& thresh);
71 int readCdevStates(std::vector<CoolingDevice>& cdev);
72 int readCdevStates(cdevType type,
73 std::vector<CoolingDevice>& cdev);
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070074 private:
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070075 bool is_cdev_init;
76 ThermalConfig cfg;
77 ThermalCommon cmnInst;
78 ThermalMonitor monitor;
79 std::unordered_map<int, struct therm_sensor>
80 thermalConfig;
81 std::vector<struct therm_cdev> cdevList;
82 std::mutex sens_cb_mutex;
83 ueventCB cb;
84
85 void eventParse(int tzn, int trip);
86 void sampleParse(int tzn, int temp);
Manaf Meethalavalappu Pallikunhiab1e3c52022-05-14 01:53:29 +053087 void eventCreateParse(int tzn, const char *name);
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070088 void Notify(struct therm_sensor& sens);
89};
90
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070091} // namespace thermal
92} // namespace hardware
93} // namespace android
Bavyasritha Alahari0a344f42023-04-26 17:16:51 -070094} // namespace aidl
Ram Chandrasekar14a48f52021-04-06 13:25:32 -070095
96#endif // THERMAL_THERMAL_UTILS_H__