2 * Copyright (C) 2011 Google, Inc.
5 * Colin Cross <ccross@android.com>
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #include <linux/kernel.h>
19 #include <linux/cpu_pm.h>
20 #include <linux/module.h>
21 #include <linux/notifier.h>
22 #include <linux/spinlock.h>
24 static DEFINE_RWLOCK(cpu_pm_notifier_lock);
25 static RAW_NOTIFIER_HEAD(cpu_pm_notifier_chain);
27 static int cpu_pm_notify(enum cpu_pm_event event, int nr_to_call, int *nr_calls)
31 ret = __raw_notifier_call_chain(&cpu_pm_notifier_chain, event, NULL,
32 nr_to_call, nr_calls);
34 return notifier_to_errno(ret);
38 * cpu_pm_register_notifier - register a driver with cpu_pm
39 * @nb: notifier block to register
41 * Add a driver to a list of drivers that are notified about
42 * CPU and CPU cluster low power entry and exit.
44 * This function may sleep, and has the same return conditions as
45 * raw_notifier_chain_register.
47 int cpu_pm_register_notifier(struct notifier_block *nb)
52 write_lock_irqsave(&cpu_pm_notifier_lock, flags);
53 ret = raw_notifier_chain_register(&cpu_pm_notifier_chain, nb);
54 write_unlock_irqrestore(&cpu_pm_notifier_lock, flags);
58 EXPORT_SYMBOL_GPL(cpu_pm_register_notifier);
61 * cpu_pm_unregister_notifier - unregister a driver with cpu_pm
62 * @nb: notifier block to be unregistered
64 * Remove a driver from the CPU PM notifier list.
66 * This function may sleep, and has the same return conditions as
67 * raw_notifier_chain_unregister.
69 int cpu_pm_unregister_notifier(struct notifier_block *nb)
74 write_lock_irqsave(&cpu_pm_notifier_lock, flags);
75 ret = raw_notifier_chain_unregister(&cpu_pm_notifier_chain, nb);
76 write_unlock_irqrestore(&cpu_pm_notifier_lock, flags);
80 EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
83 * cpm_pm_enter - CPU low power entry notifier
85 * Notifies listeners that a single CPU is entering a low power state that may
86 * cause some blocks in the same power domain as the cpu to reset.
88 * Must be called on the affected CPU with interrupts disabled. Platform is
89 * responsible for ensuring that cpu_pm_enter is not called twice on the same
90 * CPU before cpu_pm_exit is called. Notified drivers can include VFP
91 * co-processor, interrupt controller and it's PM extensions, local CPU
92 * timers context save/restore which shouldn't be interrupted. Hence it
93 * must be called with interrupts disabled.
95 * Return conditions are same as __raw_notifier_call_chain.
97 int cpu_pm_enter(void)
102 read_lock(&cpu_pm_notifier_lock);
103 ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls);
106 * Inform listeners (nr_calls - 1) about failure of CPU PM
107 * PM entry who are notified earlier to prepare for it.
109 cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL);
110 read_unlock(&cpu_pm_notifier_lock);
114 EXPORT_SYMBOL_GPL(cpu_pm_enter);
117 * cpm_pm_exit - CPU low power exit notifier
119 * Notifies listeners that a single CPU is exiting a low power state that may
120 * have caused some blocks in the same power domain as the cpu to reset.
122 * Notified drivers can include VFP co-processor, interrupt controller
123 * and it's PM extensions, local CPU timers context save/restore which
124 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
126 * Return conditions are same as __raw_notifier_call_chain.
128 int cpu_pm_exit(void)
132 read_lock(&cpu_pm_notifier_lock);
133 ret = cpu_pm_notify(CPU_PM_EXIT, -1, NULL);
134 read_unlock(&cpu_pm_notifier_lock);
138 EXPORT_SYMBOL_GPL(cpu_pm_exit);
141 * cpm_cluster_pm_enter - CPU cluster low power entry notifier
143 * Notifies listeners that all cpus in a power domain are entering a low power
144 * state that may cause some blocks in the same power domain to reset.
146 * Must be called after cpu_pm_enter has been called on all cpus in the power
147 * domain, and before cpu_pm_exit has been called on any cpu in the power
148 * domain. Notified drivers can include VFP co-processor, interrupt controller
149 * and it's PM extensions, local CPU timers context save/restore which
150 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
152 * Must be called with interrupts disabled.
154 * Return conditions are same as __raw_notifier_call_chain.
156 int cpu_cluster_pm_enter(void)
161 read_lock(&cpu_pm_notifier_lock);
162 ret = cpu_pm_notify(CPU_CLUSTER_PM_ENTER, -1, &nr_calls);
165 * Inform listeners (nr_calls - 1) about failure of CPU cluster
166 * PM entry who are notified earlier to prepare for it.
168 cpu_pm_notify(CPU_CLUSTER_PM_ENTER_FAILED, nr_calls - 1, NULL);
169 read_unlock(&cpu_pm_notifier_lock);
173 EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
176 * cpm_cluster_pm_exit - CPU cluster low power exit notifier
178 * Notifies listeners that all cpus in a power domain are exiting form a
179 * low power state that may have caused some blocks in the same power domain
182 * Must be called after cpu_pm_exit has been called on all cpus in the power
183 * domain, and before cpu_pm_exit has been called on any cpu in the power
184 * domain. Notified drivers can include VFP co-processor, interrupt controller
185 * and it's PM extensions, local CPU timers context save/restore which
186 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
188 * Return conditions are same as __raw_notifier_call_chain.
190 int cpu_cluster_pm_exit(void)
194 read_lock(&cpu_pm_notifier_lock);
195 ret = cpu_pm_notify(CPU_CLUSTER_PM_EXIT, -1, NULL);
196 read_unlock(&cpu_pm_notifier_lock);
200 EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);