rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright Statement: |
| 2 | * |
| 3 | * This software/firmware and related documentation ("MediaTek Software") are |
| 4 | * protected under relevant copyright laws. The information contained herein is |
| 5 | * confidential and proprietary to MediaTek Inc. and/or its licensors. Without |
| 6 | * the prior written permission of MediaTek inc. and/or its licensors, any |
| 7 | * reproduction, modification, use or disclosure of MediaTek Software, and |
| 8 | * information contained herein, in whole or in part, shall be strictly |
| 9 | * prohibited. |
| 10 | * |
| 11 | * MediaTek Inc. (C) 2012. All rights reserved. |
| 12 | * |
| 13 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 14 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 15 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER |
| 16 | * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL |
| 17 | * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR |
| 19 | * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH |
| 20 | * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, |
| 21 | * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES |
| 22 | * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. |
| 23 | * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO |
| 24 | * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK |
| 25 | * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE |
| 26 | * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 27 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S |
| 28 | * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE |
| 29 | * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE |
| 30 | * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE |
| 31 | * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 32 | * |
| 33 | * The following software/firmware and/or related documentation ("MediaTek |
| 34 | * Software") have been modified by MediaTek Inc. All revisions are subject to |
| 35 | * any receiver's applicable license agreements with MediaTek Inc. |
| 36 | */ |
| 37 | |
| 38 | /***************************************************************************** |
| 39 | * |
| 40 | * Filename: |
| 41 | * --------- |
| 42 | * thermal_manager.c |
| 43 | * |
| 44 | * Project: |
| 45 | * -------- |
| 46 | * YuSu |
| 47 | * |
| 48 | * Description: |
| 49 | * ------------ |
| 50 | * Set default values to all thermal zone device drivers and cooling device drivers when |
| 51 | * system init. |
| 52 | * |
| 53 | * Author: |
| 54 | * ------- |
| 55 | * CT Fang (mtk02403) |
| 56 | * |
| 57 | ****************************************************************************/ |
| 58 | #include <stdio.h> |
| 59 | #include <stdlib.h> |
| 60 | #include <string.h> |
| 61 | #include <sys/types.h> |
| 62 | #include <sys/stat.h> |
| 63 | #include <fcntl.h> |
| 64 | #include <unistd.h> |
| 65 | //#include <cutils/properties.h> |
| 66 | //#include <android/log.h> |
| 67 | #include <sys/ioctl.h> |
| 68 | #include <errno.h> |
| 69 | #include <dlfcn.h> |
| 70 | //#include <utils/Log.h> |
| 71 | //#include <cutils/log.h> |
| 72 | |
| 73 | #if 0 |
| 74 | #define MTK_LOG_ENABLE (1) |
| 75 | #define TM_LOG_TAG "thermal_mgr" |
| 76 | |
| 77 | #if MTK_LOG_ENABLE |
| 78 | #define TM_LOG(_priority_, _fmt_, args...) LOG_PRI(_priority_, TM_LOG_TAG, _fmt_, ##args) |
| 79 | static int _tm_debug_on = 1; |
| 80 | #else |
| 81 | #define TM_LOG(_priority_, _fmt_, args...) |
| 82 | #endif |
| 83 | #endif |
| 84 | |
| 85 | int (*loadmtc)(char *) = NULL; |
| 86 | #define LIB_FULL_NAME "libmtcloader.so" |
| 87 | |
| 88 | typedef int (*load)(char *); |
| 89 | |
| 90 | int (*loadchange_policy)(char *, int) = NULL; |
| 91 | typedef int (*load_change_policy)(char *, int); |
| 92 | |
| 93 | int main(int argc, char **argv) |
| 94 | { |
| 95 | int i = 0; |
| 96 | void *handle, *func, *func2; |
| 97 | |
| 98 | printf("[thermal_manager]main\n"); |
| 99 | |
| 100 | for (; i < argc; i++) { |
| 101 | printf("[thermal_manager] argv[%d] %s.\n", i, argv[i]); |
| 102 | } |
| 103 | |
| 104 | handle = dlopen(LIB_FULL_NAME, RTLD_NOW); |
| 105 | |
| 106 | if (handle == NULL) { |
| 107 | printf("[thermal_manager] fails to load lib err: %s.\n", dlerror()); |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | func = dlsym(handle, "loadmtc"); |
| 112 | loadmtc = (load)func; |
| 113 | |
| 114 | if (loadmtc == NULL) { |
| 115 | printf("[thermal_manager] loadmtc err: %s.\n", dlerror()); |
| 116 | dlclose(handle); |
| 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | if (argc - 1 > 0) { |
| 121 | int ret = 0; |
| 122 | |
| 123 | if (argc == 2) { |
| 124 | ret = loadmtc(argv[1]); |
| 125 | } else if (argc == 3) { |
| 126 | func2 = dlsym(handle, "change_policy"); |
| 127 | loadchange_policy = (load_change_policy)func2; |
| 128 | |
| 129 | if (loadchange_policy == NULL) { |
| 130 | dlclose(handle); |
| 131 | return -1; |
| 132 | } |
| 133 | ret = loadchange_policy(argv[1], atoi(argv[2])); |
| 134 | } |
| 135 | dlclose(handle); |
| 136 | return ret; |
| 137 | } else { |
| 138 | //int ret = loadmtc("/vendor/etc/.tp/thermal.conf"); /* default policy */ |
| 139 | int ret = loadmtc("/data/thermal/thermal.conf"); /* default policy */ |
| 140 | dlclose(handle); |
| 141 | return ret; |
| 142 | } |
| 143 | } |
| 144 | |