2
* Copyright 2013 Canonical Ltd.
4
* This file is part of powerd.
6
* powerd is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* powerd is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
static const char state_path[] = "/sys/power/state";
24
static const char wakelock_path[] = "/sys/power/wake_lock";
25
static const char autosleep_path[] = "/sys/power/autosleep";
27
static const char mem_str[] = "mem";
28
static const char on_str[] = "on";
30
static int earlysuspend_enter(void)
32
int ret = sysfs_write(state_path, mem_str, ARRAY_SIZE(mem_str) - 1);
33
return ret < 0 ? ret : 0;
36
static int earlysuspend_exit(void)
38
int ret = sysfs_write(state_path, on_str, ARRAY_SIZE(on_str) - 1);
39
return ret < 0 ? ret : 0;
42
static const struct suspend_handler earlysuspend_handler = {
43
.enter = earlysuspend_enter,
44
.exit = earlysuspend_exit,
47
const struct suspend_handler *earlysuspend_detect(void)
49
if (!sysfs_file_exists(autosleep_path) &&
50
sysfs_file_exists(wakelock_path) &&
51
sysfs_file_exists(state_path))
52
return &earlysuspend_handler;