blob: ff653f6f32ac6cbb3e77d0e3a8f0336a349d943c [file] [log] [blame]
xf.lia06dd222024-10-14 09:07:20 +00001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "AUTOSUSPEND"
18
19#include <stdbool.h>
20
21#include <log/log.h>
22#include <liblog/lynq_deflog.h>
23
24#include "autosuspend.h"
25
26#include "autosuspend_ops.h"
27
28static struct autosuspend_ops *autosuspend_ops;
29static bool autosuspend_enabled;
30static bool autosuspend_inited;
31
32static int autosuspend_init(void)
33{
34 if (autosuspend_inited) {
35 return 0;
36 }
37
38 autosuspend_ops = autosuspend_wakeup_count_init();
39 if (autosuspend_ops) {
40 goto out;
41 }
42
43 if (!autosuspend_ops) {
44 ALOGI("failed to initialize autosuspend\n");
45 return -1;
46 }
47
48out:
49 autosuspend_inited = true;
50
51 ALOGI("autosuspend initialized\n");
52 return 0;
53}
54
55int autosuspend_enable(void)
56{
57 int ret;
58
59 ret = autosuspend_init();
60 if (ret) {
61 return ret;
62 }
63
64 ALOGI("autosuspend_enable\n");
65
66 if (autosuspend_enabled) {
67 return 0;
68 }
69
70 ret = autosuspend_ops->enable();
71 if (ret) {
72 return ret;
73 }
74
75 autosuspend_enabled = true;
76 return 0;
77}
78
79int autosuspend_disable(void)
80{
81 int ret;
82
83 ret = autosuspend_init();
84 if (ret) {
85 return ret;
86 }
87
88 ALOGI("autosuspend_disable\n");
89
90 if (!autosuspend_enabled) {
91 return 0;
92 }
93
94 ret = autosuspend_ops->disable();
95 if (ret) {
96 return ret;
97 }
98
99 autosuspend_enabled = false;
100 return 0;
101}