aboutsummaryrefslogtreecommitdiff
path: root/kernel/power/quickwakeup.c
blob: 69b7c1eb05fbc15c4715ebfeea619662fb8acdef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* kernel/power/quickwakeup.c
 *
 * Copyright (C) 2013 Motorola.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#include <linux/slab.h>
#include <linux/quickwakeup.h>

static LIST_HEAD(qw_head);
static DEFINE_MUTEX(list_lock);

int quickwakeup_register(struct quickwakeup_ops *ops)
{
	mutex_lock(&list_lock);
	list_add(&ops->list, &qw_head);
	mutex_unlock(&list_lock);

	return 0;
}

void quickwakeup_unregister(struct quickwakeup_ops *ops)
{
	mutex_lock(&list_lock);
	list_del(&ops->list);
	mutex_unlock(&list_lock);
}

int quickwakeup_check(void)
{
	int check = 0;
	struct quickwakeup_ops *index;

	mutex_lock(&list_lock);

	list_for_each_entry(index, &qw_head, list) {
		int ret = index->qw_check(index->data);
		index->execute = ret;
		check |= ret;
		pr_debug("%s: %s votes for %s\n", __func__, index->name,
			ret ? "execute" : "dont care");
	}

	mutex_unlock(&list_lock);

	return check;
}

/* return 1 => suspend again
   return 0 => continue wakeup
 */
int quickwakeup_execute(void)
{
	int suspend_again = 0;
	int final_vote = 1;
	struct quickwakeup_ops *index;

	mutex_lock(&list_lock);

	list_for_each_entry(index, &qw_head, list) {
		if (index->execute) {
			int ret = index->qw_execute(index->data);
			index->execute = 0;
			final_vote &= ret;
			suspend_again = final_vote;
			pr_debug("%s: %s votes for %s\n", __func__, index->name,
				ret ? "suspend again" : "wakeup");
		}
	}

	mutex_unlock(&list_lock);

	pr_debug("%s: %s\n", __func__,
		suspend_again ? "suspend again" : "wakeup");

	return suspend_again;
}