sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / kernel / cpu_pm.c
blob009cc9a17d95d601e4f6bf38f13d0f810ebbdb34
1 /*
2 * Copyright (C) 2011 Google, Inc.
4 * Author:
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>
23 #include <linux/syscore_ops.h>
25 static DEFINE_RWLOCK(cpu_pm_notifier_lock);
26 static RAW_NOTIFIER_HEAD(cpu_pm_notifier_chain);
28 static int cpu_pm_notify(enum cpu_pm_event event, int nr_to_call, int *nr_calls)
30 int ret;
32 ret = __raw_notifier_call_chain(&cpu_pm_notifier_chain, event, NULL,
33 nr_to_call, nr_calls);
35 return notifier_to_errno(ret);
38 /**
39 * cpu_pm_register_notifier - register a driver with cpu_pm
40 * @nb: notifier block to register
42 * Add a driver to a list of drivers that are notified about
43 * CPU and CPU cluster low power entry and exit.
45 * This function may sleep, and has the same return conditions as
46 * raw_notifier_chain_register.
48 int cpu_pm_register_notifier(struct notifier_block *nb)
50 unsigned long flags;
51 int ret;
53 write_lock_irqsave(&cpu_pm_notifier_lock, flags);
54 ret = raw_notifier_chain_register(&cpu_pm_notifier_chain, nb);
55 write_unlock_irqrestore(&cpu_pm_notifier_lock, flags);
57 return ret;
59 EXPORT_SYMBOL_GPL(cpu_pm_register_notifier);
61 /**
62 * cpu_pm_unregister_notifier - unregister a driver with cpu_pm
63 * @nb: notifier block to be unregistered
65 * Remove a driver from the CPU PM notifier list.
67 * This function may sleep, and has the same return conditions as
68 * raw_notifier_chain_unregister.
70 int cpu_pm_unregister_notifier(struct notifier_block *nb)
72 unsigned long flags;
73 int ret;
75 write_lock_irqsave(&cpu_pm_notifier_lock, flags);
76 ret = raw_notifier_chain_unregister(&cpu_pm_notifier_chain, nb);
77 write_unlock_irqrestore(&cpu_pm_notifier_lock, flags);
79 return ret;
81 EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
83 /**
84 * cpu_pm_enter - CPU low power entry notifier
86 * Notifies listeners that a single CPU is entering a low power state that may
87 * cause some blocks in the same power domain as the cpu to reset.
89 * Must be called on the affected CPU with interrupts disabled. Platform is
90 * responsible for ensuring that cpu_pm_enter is not called twice on the same
91 * CPU before cpu_pm_exit is called. Notified drivers can include VFP
92 * co-processor, interrupt controller and its PM extensions, local CPU
93 * timers context save/restore which shouldn't be interrupted. Hence it
94 * must be called with interrupts disabled.
96 * Return conditions are same as __raw_notifier_call_chain.
98 int cpu_pm_enter(void)
100 int nr_calls;
101 int ret = 0;
103 read_lock(&cpu_pm_notifier_lock);
104 ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls);
105 if (ret)
107 * Inform listeners (nr_calls - 1) about failure of CPU PM
108 * PM entry who are notified earlier to prepare for it.
110 cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL);
111 read_unlock(&cpu_pm_notifier_lock);
113 return ret;
115 EXPORT_SYMBOL_GPL(cpu_pm_enter);
118 * cpu_pm_exit - CPU low power exit notifier
120 * Notifies listeners that a single CPU is exiting a low power state that may
121 * have caused some blocks in the same power domain as the cpu to reset.
123 * Notified drivers can include VFP co-processor, interrupt controller
124 * and its PM extensions, local CPU timers context save/restore which
125 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
127 * Return conditions are same as __raw_notifier_call_chain.
129 int cpu_pm_exit(void)
131 int ret;
133 read_lock(&cpu_pm_notifier_lock);
134 ret = cpu_pm_notify(CPU_PM_EXIT, -1, NULL);
135 read_unlock(&cpu_pm_notifier_lock);
137 return ret;
139 EXPORT_SYMBOL_GPL(cpu_pm_exit);
142 * cpu_cluster_pm_enter - CPU cluster low power entry notifier
144 * Notifies listeners that all cpus in a power domain are entering a low power
145 * state that may cause some blocks in the same power domain to reset.
147 * Must be called after cpu_pm_enter has been called on all cpus in the power
148 * domain, and before cpu_pm_exit has been called on any cpu in the power
149 * domain. Notified drivers can include VFP co-processor, interrupt controller
150 * and its PM extensions, local CPU timers context save/restore which
151 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
153 * Must be called with interrupts disabled.
155 * Return conditions are same as __raw_notifier_call_chain.
157 int cpu_cluster_pm_enter(void)
159 int nr_calls;
160 int ret = 0;
162 read_lock(&cpu_pm_notifier_lock);
163 ret = cpu_pm_notify(CPU_CLUSTER_PM_ENTER, -1, &nr_calls);
164 if (ret)
166 * Inform listeners (nr_calls - 1) about failure of CPU cluster
167 * PM entry who are notified earlier to prepare for it.
169 cpu_pm_notify(CPU_CLUSTER_PM_ENTER_FAILED, nr_calls - 1, NULL);
170 read_unlock(&cpu_pm_notifier_lock);
172 return ret;
174 EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
177 * cpu_cluster_pm_exit - CPU cluster low power exit notifier
179 * Notifies listeners that all cpus in a power domain are exiting form a
180 * low power state that may have caused some blocks in the same power domain
181 * to reset.
183 * Must be called after cpu_cluster_pm_enter has been called for the power
184 * domain, and before cpu_pm_exit has been called on any cpu in the power
185 * domain. Notified drivers can include VFP co-processor, interrupt controller
186 * and its PM extensions, local CPU timers context save/restore which
187 * shouldn't be interrupted. Hence it must be called with interrupts disabled.
189 * Return conditions are same as __raw_notifier_call_chain.
191 int cpu_cluster_pm_exit(void)
193 int ret;
195 read_lock(&cpu_pm_notifier_lock);
196 ret = cpu_pm_notify(CPU_CLUSTER_PM_EXIT, -1, NULL);
197 read_unlock(&cpu_pm_notifier_lock);
199 return ret;
201 EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);
203 #ifdef CONFIG_PM
204 static int cpu_pm_suspend(void)
206 int ret;
208 ret = cpu_pm_enter();
209 if (ret)
210 return ret;
212 ret = cpu_cluster_pm_enter();
213 return ret;
216 static void cpu_pm_resume(void)
218 cpu_cluster_pm_exit();
219 cpu_pm_exit();
222 static struct syscore_ops cpu_pm_syscore_ops = {
223 .suspend = cpu_pm_suspend,
224 .resume = cpu_pm_resume,
227 static int cpu_pm_init(void)
229 register_syscore_ops(&cpu_pm_syscore_ops);
230 return 0;
232 core_initcall(cpu_pm_init);
233 #endif