blob: 85df5387bc61f2c1b5ff15e9807b8d0484421e72 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/cpufreq/cpufreq.c
3 *
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 *
Ashok Rajc32b6b82005-10-30 14:59:54 -08007 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
Dave Jones32ee8c32006-02-28 00:43:23 -05008 * Added handling for CPU hotplug
Dave Jones8ff69732006-03-05 03:37:23 -05009 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
10 * Fix handling for CPU hotplug -- affected CPUs
Ashok Rajc32b6b82005-10-30 14:59:54 -080011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 *
16 */
17
Viresh Kumardb701152012-10-23 01:29:03 +020018#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/init.h>
23#include <linux/notifier.h>
24#include <linux/cpufreq.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/spinlock.h>
28#include <linux/device.h>
29#include <linux/slab.h>
30#include <linux/cpu.h>
31#include <linux/completion.h>
akpm@osdl.org3fc54d32006-01-13 15:54:22 -080032#include <linux/mutex.h>
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +010033#include <linux/syscore_ops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Thomas Renninger6f4f2722010-04-20 13:17:36 +020035#include <trace/events/power.h>
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/**
Dave Jonescd878472006-08-11 17:59:28 -040038 * The "cpufreq driver" - the arch- or hardware-dependent low
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * level driver of CPUFreq support, and its spinlock. This lock
40 * also protects the cpufreq_cpu_data array.
41 */
Dave Jones7d5e3502006-02-02 17:03:42 -050042static struct cpufreq_driver *cpufreq_driver;
Mike Travis7a6aedf2008-03-25 15:06:53 -070043static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
Thomas Renninger084f3492007-07-09 11:35:28 -070044#ifdef CONFIG_HOTPLUG_CPU
45/* This one keeps track of the previously set governor of a removed CPU */
Dmitry Monakhove77b89f2009-10-05 00:38:55 +040046static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor);
Thomas Renninger084f3492007-07-09 11:35:28 -070047#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static DEFINE_SPINLOCK(cpufreq_driver_lock);
49
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080050/*
51 * cpu_policy_rwsem is a per CPU reader-writer semaphore designed to cure
52 * all cpufreq/hotplug/workqueue/etc related lock issues.
53 *
54 * The rules for this semaphore:
55 * - Any routine that wants to read from the policy structure will
56 * do a down_read on this semaphore.
57 * - Any routine that will write to the policy structure and/or may take away
58 * the policy altogether (eg. CPU hotplug), will hold this lock in write
59 * mode before doing so.
60 *
61 * Additional rules:
62 * - All holders of the lock should check to make sure that the CPU they
63 * are concerned with are online after they get the lock.
64 * - Governor routines that can be called in cpufreq hotplug path should not
65 * take this sem as top level hotplug notifier handler takes this.
Mathieu Desnoyers395913d2009-06-08 13:17:31 -040066 * - Lock should not be held across
67 * __cpufreq_governor(data, CPUFREQ_GOV_STOP);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080068 */
Tejun Heof1625062009-10-29 22:34:13 +090069static DEFINE_PER_CPU(int, cpufreq_policy_cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080070static DEFINE_PER_CPU(struct rw_semaphore, cpu_policy_rwsem);
71
72#define lock_policy_rwsem(mode, cpu) \
Amerigo Wang226528c2010-03-04 03:23:36 -050073static int lock_policy_rwsem_##mode \
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080074(int cpu) \
75{ \
Tejun Heof1625062009-10-29 22:34:13 +090076 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080077 BUG_ON(policy_cpu == -1); \
78 down_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \
79 if (unlikely(!cpu_online(cpu))) { \
80 up_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \
81 return -1; \
82 } \
83 \
84 return 0; \
85}
86
87lock_policy_rwsem(read, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080088
89lock_policy_rwsem(write, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080090
Amerigo Wang226528c2010-03-04 03:23:36 -050091static void unlock_policy_rwsem_read(int cpu)
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080092{
Tejun Heof1625062009-10-29 22:34:13 +090093 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080094 BUG_ON(policy_cpu == -1);
95 up_read(&per_cpu(cpu_policy_rwsem, policy_cpu));
96}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080097
Amerigo Wang226528c2010-03-04 03:23:36 -050098static void unlock_policy_rwsem_write(int cpu)
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080099{
Tejun Heof1625062009-10-29 22:34:13 +0900100 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800101 BUG_ON(policy_cpu == -1);
102 up_write(&per_cpu(cpu_policy_rwsem, policy_cpu));
103}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800104
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/* internal prototypes */
Dave Jones29464f22009-01-18 01:37:11 -0500107static int __cpufreq_governor(struct cpufreq_policy *policy,
108 unsigned int event);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800109static unsigned int __cpufreq_get(unsigned int cpu);
David Howells65f27f32006-11-22 14:55:48 +0000110static void handle_update(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112/**
Dave Jones32ee8c32006-02-28 00:43:23 -0500113 * Two notifier lists: the "policy" list is involved in the
114 * validation process for a new CPU frequency policy; the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 * "transition" list for kernel code that needs to handle
116 * changes to devices when the CPU clock speed changes.
117 * The mutex locks both lists.
118 */
Alan Sterne041c682006-03-27 01:16:30 -0800119static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700120static struct srcu_notifier_head cpufreq_transition_notifier_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Cesar Eduardo Barros74212ca2008-02-16 08:41:24 -0200122static bool init_cpufreq_transition_notifier_list_called;
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700123static int __init init_cpufreq_transition_notifier_list(void)
124{
125 srcu_init_notifier_head(&cpufreq_transition_notifier_list);
Cesar Eduardo Barros74212ca2008-02-16 08:41:24 -0200126 init_cpufreq_transition_notifier_list_called = true;
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700127 return 0;
128}
Linus Torvaldsb3438f82006-11-20 11:47:18 -0800129pure_initcall(init_cpufreq_transition_notifier_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -0400131static int off __read_mostly;
132int cpufreq_disabled(void)
133{
134 return off;
135}
136void disable_cpufreq(void)
137{
138 off = 1;
139}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static LIST_HEAD(cpufreq_governor_list);
Dave Jones29464f22009-01-18 01:37:11 -0500141static DEFINE_MUTEX(cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Stephen Boyda9144432012-07-20 18:14:38 +0000143static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 struct cpufreq_policy *data;
146 unsigned long flags;
147
Mike Travis7a6aedf2008-03-25 15:06:53 -0700148 if (cpu >= nr_cpu_ids)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 goto err_out;
150
151 /* get the cpufreq driver */
152 spin_lock_irqsave(&cpufreq_driver_lock, flags);
153
154 if (!cpufreq_driver)
155 goto err_out_unlock;
156
157 if (!try_module_get(cpufreq_driver->owner))
158 goto err_out_unlock;
159
160
161 /* get the CPU */
Mike Travis7a6aedf2008-03-25 15:06:53 -0700162 data = per_cpu(cpufreq_cpu_data, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 if (!data)
165 goto err_out_put_module;
166
Stephen Boyda9144432012-07-20 18:14:38 +0000167 if (!sysfs && !kobject_get(&data->kobj))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 goto err_out_put_module;
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return data;
172
Dave Jones7d5e3502006-02-02 17:03:42 -0500173err_out_put_module:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 module_put(cpufreq_driver->owner);
Dave Jones7d5e3502006-02-02 17:03:42 -0500175err_out_unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Dave Jones7d5e3502006-02-02 17:03:42 -0500177err_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return NULL;
179}
Stephen Boyda9144432012-07-20 18:14:38 +0000180
181struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
182{
183 return __cpufreq_cpu_get(cpu, false);
184}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
186
Stephen Boyda9144432012-07-20 18:14:38 +0000187static struct cpufreq_policy *cpufreq_cpu_get_sysfs(unsigned int cpu)
188{
189 return __cpufreq_cpu_get(cpu, true);
190}
191
192static void __cpufreq_cpu_put(struct cpufreq_policy *data, bool sysfs)
193{
194 if (!sysfs)
195 kobject_put(&data->kobj);
196 module_put(cpufreq_driver->owner);
197}
Dave Jones7d5e3502006-02-02 17:03:42 -0500198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199void cpufreq_cpu_put(struct cpufreq_policy *data)
200{
Stephen Boyda9144432012-07-20 18:14:38 +0000201 __cpufreq_cpu_put(data, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202}
203EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
204
Stephen Boyda9144432012-07-20 18:14:38 +0000205static void cpufreq_cpu_put_sysfs(struct cpufreq_policy *data)
206{
207 __cpufreq_cpu_put(data, true);
208}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210/*********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
212 *********************************************************************/
213
214/**
215 * adjust_jiffies - adjust the system "loops_per_jiffy"
216 *
217 * This function alters the system "loops_per_jiffy" for the clock
218 * speed change. Note that loops_per_jiffy cannot be updated on SMP
Dave Jones32ee8c32006-02-28 00:43:23 -0500219 * systems as each CPU might be scaled differently. So, use the arch
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 * per-CPU loops_per_jiffy value wherever possible.
221 */
222#ifndef CONFIG_SMP
223static unsigned long l_p_j_ref;
224static unsigned int l_p_j_ref_freq;
225
Arjan van de Ven858119e2006-01-14 13:20:43 -0800226static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227{
228 if (ci->flags & CPUFREQ_CONST_LOOPS)
229 return;
230
231 if (!l_p_j_ref_freq) {
232 l_p_j_ref = loops_per_jiffy;
233 l_p_j_ref_freq = ci->old;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200234 pr_debug("saving %lu as reference value for loops_per_jiffy; "
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530235 "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
Afzal Mohammedd08de0c12012-01-04 10:52:46 +0530237 if ((val == CPUFREQ_POSTCHANGE && ci->old != ci->new) ||
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -0700238 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530239 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
240 ci->new);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200241 pr_debug("scaling loops_per_jiffy to %lu "
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530242 "for frequency %u kHz\n", loops_per_jiffy, ci->new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 }
244}
245#else
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530246static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
247{
248 return;
249}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250#endif
251
252
253/**
Dave Jonese4472cb2006-01-31 15:53:55 -0800254 * cpufreq_notify_transition - call notifier chain and adjust_jiffies
255 * on frequency transition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 *
Dave Jonese4472cb2006-01-31 15:53:55 -0800257 * This function calls the transition notifiers and the "adjust_jiffies"
258 * function. It is called twice on all CPU frequency changes that have
Dave Jones32ee8c32006-02-28 00:43:23 -0500259 * external effects.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 */
261void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
262{
Dave Jonese4472cb2006-01-31 15:53:55 -0800263 struct cpufreq_policy *policy;
264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 BUG_ON(irqs_disabled());
266
267 freqs->flags = cpufreq_driver->flags;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200268 pr_debug("notification %u of frequency transition to %u kHz\n",
Dave Jonese4472cb2006-01-31 15:53:55 -0800269 state, freqs->new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Mike Travis7a6aedf2008-03-25 15:06:53 -0700271 policy = per_cpu(cpufreq_cpu_data, freqs->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 switch (state) {
Dave Jonese4472cb2006-01-31 15:53:55 -0800273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 case CPUFREQ_PRECHANGE:
Dave Jones32ee8c32006-02-28 00:43:23 -0500275 /* detect if the driver reported a value as "old frequency"
Dave Jonese4472cb2006-01-31 15:53:55 -0800276 * which is not equal to what the cpufreq core thinks is
277 * "old frequency".
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 */
279 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
Dave Jonese4472cb2006-01-31 15:53:55 -0800280 if ((policy) && (policy->cpu == freqs->cpu) &&
281 (policy->cur) && (policy->cur != freqs->old)) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200282 pr_debug("Warning: CPU frequency is"
Dave Jonese4472cb2006-01-31 15:53:55 -0800283 " %u, cpufreq assumed %u kHz.\n",
284 freqs->old, policy->cur);
285 freqs->old = policy->cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 }
287 }
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700288 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
Alan Sterne041c682006-03-27 01:16:30 -0800289 CPUFREQ_PRECHANGE, freqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
291 break;
Dave Jonese4472cb2006-01-31 15:53:55 -0800292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 case CPUFREQ_POSTCHANGE:
294 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200295 pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new,
Thomas Renninger6f4f2722010-04-20 13:17:36 +0200296 (unsigned long)freqs->cpu);
297 trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu);
Thomas Renninger25e41932011-01-03 17:50:44 +0100298 trace_cpu_frequency(freqs->new, freqs->cpu);
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700299 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
Alan Sterne041c682006-03-27 01:16:30 -0800300 CPUFREQ_POSTCHANGE, freqs);
Dave Jonese4472cb2006-01-31 15:53:55 -0800301 if (likely(policy) && likely(policy->cpu == freqs->cpu))
302 policy->cur = freqs->new;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 break;
304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
307
308
309
310/*********************************************************************
311 * SYSFS INTERFACE *
312 *********************************************************************/
313
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700314static struct cpufreq_governor *__find_governor(const char *str_governor)
315{
316 struct cpufreq_governor *t;
317
318 list_for_each_entry(t, &cpufreq_governor_list, governor_list)
Dave Jones29464f22009-01-18 01:37:11 -0500319 if (!strnicmp(str_governor, t->name, CPUFREQ_NAME_LEN))
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700320 return t;
321
322 return NULL;
323}
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325/**
326 * cpufreq_parse_governor - parse a governor string
327 */
Dave Jones905d77c2008-03-05 14:28:32 -0500328static int cpufreq_parse_governor(char *str_governor, unsigned int *policy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 struct cpufreq_governor **governor)
330{
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700331 int err = -EINVAL;
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 if (!cpufreq_driver)
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700334 goto out;
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (cpufreq_driver->setpolicy) {
337 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
338 *policy = CPUFREQ_POLICY_PERFORMANCE;
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700339 err = 0;
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530340 } else if (!strnicmp(str_governor, "powersave",
341 CPUFREQ_NAME_LEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *policy = CPUFREQ_POLICY_POWERSAVE;
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700343 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700345 } else if (cpufreq_driver->target) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 struct cpufreq_governor *t;
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700347
akpm@osdl.org3fc54d32006-01-13 15:54:22 -0800348 mutex_lock(&cpufreq_governor_mutex);
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700349
350 t = __find_governor(str_governor);
351
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700352 if (t == NULL) {
Kees Cook1a8e1462011-05-04 08:38:56 -0700353 int ret;
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700354
Kees Cook1a8e1462011-05-04 08:38:56 -0700355 mutex_unlock(&cpufreq_governor_mutex);
356 ret = request_module("cpufreq_%s", str_governor);
357 mutex_lock(&cpufreq_governor_mutex);
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700358
Kees Cook1a8e1462011-05-04 08:38:56 -0700359 if (ret == 0)
360 t = __find_governor(str_governor);
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700361 }
362
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700363 if (t != NULL) {
364 *governor = t;
365 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700367
akpm@osdl.org3fc54d32006-01-13 15:54:22 -0800368 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
Dave Jones29464f22009-01-18 01:37:11 -0500370out:
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700371 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/**
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530376 * cpufreq_per_cpu_attr_read() / show_##file_name() -
377 * print out cpufreq information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 *
379 * Write out information from cpufreq_driver->policy[cpu]; object must be
380 * "unsigned int".
381 */
382
Dave Jones32ee8c32006-02-28 00:43:23 -0500383#define show_one(file_name, object) \
384static ssize_t show_##file_name \
Dave Jones905d77c2008-03-05 14:28:32 -0500385(struct cpufreq_policy *policy, char *buf) \
Dave Jones32ee8c32006-02-28 00:43:23 -0500386{ \
Dave Jones29464f22009-01-18 01:37:11 -0500387 return sprintf(buf, "%u\n", policy->object); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388}
389
390show_one(cpuinfo_min_freq, cpuinfo.min_freq);
391show_one(cpuinfo_max_freq, cpuinfo.max_freq);
Thomas Renningered129782009-02-04 01:17:41 +0100392show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393show_one(scaling_min_freq, min);
394show_one(scaling_max_freq, max);
395show_one(scaling_cur_freq, cur);
396
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530397static int __cpufreq_set_policy(struct cpufreq_policy *data,
398 struct cpufreq_policy *policy);
Thomas Renninger7970e082006-04-13 15:14:04 +0200399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400/**
401 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
402 */
403#define store_one(file_name, object) \
404static ssize_t store_##file_name \
Dave Jones905d77c2008-03-05 14:28:32 -0500405(struct cpufreq_policy *policy, const char *buf, size_t count) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{ \
407 unsigned int ret = -EINVAL; \
408 struct cpufreq_policy new_policy; \
409 \
410 ret = cpufreq_get_policy(&new_policy, policy->cpu); \
411 if (ret) \
412 return -EINVAL; \
413 \
Dave Jones29464f22009-01-18 01:37:11 -0500414 ret = sscanf(buf, "%u", &new_policy.object); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 if (ret != 1) \
416 return -EINVAL; \
417 \
Thomas Renninger7970e082006-04-13 15:14:04 +0200418 ret = __cpufreq_set_policy(policy, &new_policy); \
419 policy->user_policy.object = policy->object; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 \
421 return ret ? ret : count; \
422}
423
Dave Jones29464f22009-01-18 01:37:11 -0500424store_one(scaling_min_freq, min);
425store_one(scaling_max_freq, max);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427/**
428 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
429 */
Dave Jones905d77c2008-03-05 14:28:32 -0500430static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
431 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800433 unsigned int cur_freq = __cpufreq_get(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 if (!cur_freq)
435 return sprintf(buf, "<unknown>");
436 return sprintf(buf, "%u\n", cur_freq);
437}
438
439
440/**
441 * show_scaling_governor - show the current policy for the specified CPU
442 */
Dave Jones905d77c2008-03-05 14:28:32 -0500443static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Dave Jones29464f22009-01-18 01:37:11 -0500445 if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return sprintf(buf, "powersave\n");
447 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
448 return sprintf(buf, "performance\n");
449 else if (policy->governor)
viresh kumar4b972f02012-10-23 01:23:43 +0200450 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n",
Dave Jones29464f22009-01-18 01:37:11 -0500451 policy->governor->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return -EINVAL;
453}
454
455
456/**
457 * store_scaling_governor - store policy for the specified CPU
458 */
Dave Jones905d77c2008-03-05 14:28:32 -0500459static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
460 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 unsigned int ret = -EINVAL;
463 char str_governor[16];
464 struct cpufreq_policy new_policy;
465
466 ret = cpufreq_get_policy(&new_policy, policy->cpu);
467 if (ret)
468 return ret;
469
Dave Jones29464f22009-01-18 01:37:11 -0500470 ret = sscanf(buf, "%15s", str_governor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (ret != 1)
472 return -EINVAL;
473
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530474 if (cpufreq_parse_governor(str_governor, &new_policy.policy,
475 &new_policy.governor))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return -EINVAL;
477
Thomas Renninger7970e082006-04-13 15:14:04 +0200478 /* Do not use cpufreq_set_policy here or the user_policy.max
479 will be wrongly overridden */
Thomas Renninger7970e082006-04-13 15:14:04 +0200480 ret = __cpufreq_set_policy(policy, &new_policy);
481
482 policy->user_policy.policy = policy->policy;
483 policy->user_policy.governor = policy->governor;
Thomas Renninger7970e082006-04-13 15:14:04 +0200484
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530485 if (ret)
486 return ret;
487 else
488 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
491/**
492 * show_scaling_driver - show the cpufreq driver currently loaded
493 */
Dave Jones905d77c2008-03-05 14:28:32 -0500494static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
viresh kumar4b972f02012-10-23 01:23:43 +0200496 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499/**
500 * show_scaling_available_governors - show the available CPUfreq governors
501 */
Dave Jones905d77c2008-03-05 14:28:32 -0500502static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
503 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
505 ssize_t i = 0;
506 struct cpufreq_governor *t;
507
508 if (!cpufreq_driver->target) {
509 i += sprintf(buf, "performance powersave");
510 goto out;
511 }
512
513 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
Dave Jones29464f22009-01-18 01:37:11 -0500514 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
515 - (CPUFREQ_NAME_LEN + 2)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 goto out;
viresh kumar4b972f02012-10-23 01:23:43 +0200517 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
Dave Jones7d5e3502006-02-02 17:03:42 -0500519out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 i += sprintf(&buf[i], "\n");
521 return i;
522}
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700523
Rusty Russell835481d2009-01-04 05:18:06 -0800524static ssize_t show_cpus(const struct cpumask *mask, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
526 ssize_t i = 0;
527 unsigned int cpu;
528
Rusty Russell835481d2009-01-04 05:18:06 -0800529 for_each_cpu(cpu, mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (i)
531 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
532 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
533 if (i >= (PAGE_SIZE - 5))
Dave Jones29464f22009-01-18 01:37:11 -0500534 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
536 i += sprintf(&buf[i], "\n");
537 return i;
538}
539
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700540/**
541 * show_related_cpus - show the CPUs affected by each transition even if
542 * hw coordination is in use
543 */
544static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
545{
Rusty Russell835481d2009-01-04 05:18:06 -0800546 if (cpumask_empty(policy->related_cpus))
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700547 return show_cpus(policy->cpus, buf);
548 return show_cpus(policy->related_cpus, buf);
549}
550
551/**
552 * show_affected_cpus - show the CPUs affected by each transition
553 */
554static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
555{
556 return show_cpus(policy->cpus, buf);
557}
558
Venki Pallipadi9e769882007-10-26 10:18:21 -0700559static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
Dave Jones905d77c2008-03-05 14:28:32 -0500560 const char *buf, size_t count)
Venki Pallipadi9e769882007-10-26 10:18:21 -0700561{
562 unsigned int freq = 0;
563 unsigned int ret;
564
CHIKAMA masaki879000f2008-06-05 22:46:33 -0700565 if (!policy->governor || !policy->governor->store_setspeed)
Venki Pallipadi9e769882007-10-26 10:18:21 -0700566 return -EINVAL;
567
568 ret = sscanf(buf, "%u", &freq);
569 if (ret != 1)
570 return -EINVAL;
571
572 policy->governor->store_setspeed(policy, freq);
573
574 return count;
575}
576
577static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
578{
CHIKAMA masaki879000f2008-06-05 22:46:33 -0700579 if (!policy->governor || !policy->governor->show_setspeed)
Venki Pallipadi9e769882007-10-26 10:18:21 -0700580 return sprintf(buf, "<unsupported>\n");
581
582 return policy->governor->show_setspeed(policy, buf);
583}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Thomas Renningere2f74f32009-11-19 12:31:01 +0100585/**
viresh kumar8bf1ac72012-10-23 01:23:33 +0200586 * show_bios_limit - show the current cpufreq HW/BIOS limitation
Thomas Renningere2f74f32009-11-19 12:31:01 +0100587 */
588static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
589{
590 unsigned int limit;
591 int ret;
592 if (cpufreq_driver->bios_limit) {
593 ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
594 if (!ret)
595 return sprintf(buf, "%u\n", limit);
596 }
597 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
598}
599
Borislav Petkov6dad2a22010-03-31 21:56:46 +0200600cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
601cpufreq_freq_attr_ro(cpuinfo_min_freq);
602cpufreq_freq_attr_ro(cpuinfo_max_freq);
603cpufreq_freq_attr_ro(cpuinfo_transition_latency);
604cpufreq_freq_attr_ro(scaling_available_governors);
605cpufreq_freq_attr_ro(scaling_driver);
606cpufreq_freq_attr_ro(scaling_cur_freq);
607cpufreq_freq_attr_ro(bios_limit);
608cpufreq_freq_attr_ro(related_cpus);
609cpufreq_freq_attr_ro(affected_cpus);
610cpufreq_freq_attr_rw(scaling_min_freq);
611cpufreq_freq_attr_rw(scaling_max_freq);
612cpufreq_freq_attr_rw(scaling_governor);
613cpufreq_freq_attr_rw(scaling_setspeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Dave Jones905d77c2008-03-05 14:28:32 -0500615static struct attribute *default_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 &cpuinfo_min_freq.attr,
617 &cpuinfo_max_freq.attr,
Thomas Renningered129782009-02-04 01:17:41 +0100618 &cpuinfo_transition_latency.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 &scaling_min_freq.attr,
620 &scaling_max_freq.attr,
621 &affected_cpus.attr,
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700622 &related_cpus.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 &scaling_governor.attr,
624 &scaling_driver.attr,
625 &scaling_available_governors.attr,
Venki Pallipadi9e769882007-10-26 10:18:21 -0700626 &scaling_setspeed.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 NULL
628};
629
Thomas Renninger8aa84ad2009-07-24 15:25:05 +0200630struct kobject *cpufreq_global_kobject;
631EXPORT_SYMBOL(cpufreq_global_kobject);
632
Dave Jones29464f22009-01-18 01:37:11 -0500633#define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
634#define to_attr(a) container_of(a, struct freq_attr, attr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Dave Jones29464f22009-01-18 01:37:11 -0500636static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Dave Jones905d77c2008-03-05 14:28:32 -0500638 struct cpufreq_policy *policy = to_policy(kobj);
639 struct freq_attr *fattr = to_attr(attr);
Dave Jones0db4a8a2008-03-05 14:20:57 -0500640 ssize_t ret = -EINVAL;
Stephen Boyda9144432012-07-20 18:14:38 +0000641 policy = cpufreq_cpu_get_sysfs(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if (!policy)
Dave Jones0db4a8a2008-03-05 14:20:57 -0500643 goto no_policy;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800644
645 if (lock_policy_rwsem_read(policy->cpu) < 0)
Dave Jones0db4a8a2008-03-05 14:20:57 -0500646 goto fail;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800647
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530648 if (fattr->show)
649 ret = fattr->show(policy, buf);
650 else
651 ret = -EIO;
652
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800653 unlock_policy_rwsem_read(policy->cpu);
Dave Jones0db4a8a2008-03-05 14:20:57 -0500654fail:
Stephen Boyda9144432012-07-20 18:14:38 +0000655 cpufreq_cpu_put_sysfs(policy);
Dave Jones0db4a8a2008-03-05 14:20:57 -0500656no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 return ret;
658}
659
Dave Jones905d77c2008-03-05 14:28:32 -0500660static ssize_t store(struct kobject *kobj, struct attribute *attr,
661 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Dave Jones905d77c2008-03-05 14:28:32 -0500663 struct cpufreq_policy *policy = to_policy(kobj);
664 struct freq_attr *fattr = to_attr(attr);
Dave Jonesa07530b2008-03-05 14:22:25 -0500665 ssize_t ret = -EINVAL;
Stephen Boyda9144432012-07-20 18:14:38 +0000666 policy = cpufreq_cpu_get_sysfs(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if (!policy)
Dave Jonesa07530b2008-03-05 14:22:25 -0500668 goto no_policy;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800669
670 if (lock_policy_rwsem_write(policy->cpu) < 0)
Dave Jonesa07530b2008-03-05 14:22:25 -0500671 goto fail;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800672
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530673 if (fattr->store)
674 ret = fattr->store(policy, buf, count);
675 else
676 ret = -EIO;
677
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800678 unlock_policy_rwsem_write(policy->cpu);
Dave Jonesa07530b2008-03-05 14:22:25 -0500679fail:
Stephen Boyda9144432012-07-20 18:14:38 +0000680 cpufreq_cpu_put_sysfs(policy);
Dave Jonesa07530b2008-03-05 14:22:25 -0500681no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 return ret;
683}
684
Dave Jones905d77c2008-03-05 14:28:32 -0500685static void cpufreq_sysfs_release(struct kobject *kobj)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Dave Jones905d77c2008-03-05 14:28:32 -0500687 struct cpufreq_policy *policy = to_policy(kobj);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200688 pr_debug("last reference is dropped\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 complete(&policy->kobj_unregister);
690}
691
Emese Revfy52cf25d2010-01-19 02:58:23 +0100692static const struct sysfs_ops sysfs_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .show = show,
694 .store = store,
695};
696
697static struct kobj_type ktype_cpufreq = {
698 .sysfs_ops = &sysfs_ops,
699 .default_attrs = default_attrs,
700 .release = cpufreq_sysfs_release,
701};
702
Thomas Renninger4bfa0422009-07-24 15:25:03 +0200703/*
704 * Returns:
705 * Negative: Failure
706 * 0: Success
707 * Positive: When we have a managed CPU and the sysfs got symlinked
708 */
Alex Chiangcf3289d02009-11-17 20:27:08 -0700709static int cpufreq_add_dev_policy(unsigned int cpu,
710 struct cpufreq_policy *policy,
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800711 struct device *dev)
Dave Jonesecf7e462009-07-08 18:48:47 -0400712{
713 int ret = 0;
714#ifdef CONFIG_SMP
715 unsigned long flags;
716 unsigned int j;
Dave Jonesecf7e462009-07-08 18:48:47 -0400717#ifdef CONFIG_HOTPLUG_CPU
Dmitry Monakhove77b89f2009-10-05 00:38:55 +0400718 struct cpufreq_governor *gov;
719
720 gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu));
721 if (gov) {
722 policy->governor = gov;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200723 pr_debug("Restoring governor %s for cpu %d\n",
Dave Jonesecf7e462009-07-08 18:48:47 -0400724 policy->governor->name, cpu);
725 }
726#endif
727
728 for_each_cpu(j, policy->cpus) {
729 struct cpufreq_policy *managed_policy;
730
731 if (cpu == j)
732 continue;
733
734 /* Check for existing affected CPUs.
735 * They may not be aware of it due to CPU Hotplug.
736 * cpufreq_cpu_put is called when the device is removed
737 * in __cpufreq_remove_dev()
738 */
739 managed_policy = cpufreq_cpu_get(j);
740 if (unlikely(managed_policy)) {
741
742 /* Set proper policy_cpu */
743 unlock_policy_rwsem_write(cpu);
Tejun Heof1625062009-10-29 22:34:13 +0900744 per_cpu(cpufreq_policy_cpu, cpu) = managed_policy->cpu;
Dave Jonesecf7e462009-07-08 18:48:47 -0400745
746 if (lock_policy_rwsem_write(cpu) < 0) {
747 /* Should not go through policy unlock path */
748 if (cpufreq_driver->exit)
749 cpufreq_driver->exit(policy);
750 cpufreq_cpu_put(managed_policy);
751 return -EBUSY;
752 }
753
754 spin_lock_irqsave(&cpufreq_driver_lock, flags);
755 cpumask_copy(managed_policy->cpus, policy->cpus);
756 per_cpu(cpufreq_cpu_data, cpu) = managed_policy;
757 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
758
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200759 pr_debug("CPU already managed, adding link\n");
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800760 ret = sysfs_create_link(&dev->kobj,
Dave Jonesecf7e462009-07-08 18:48:47 -0400761 &managed_policy->kobj,
762 "cpufreq");
763 if (ret)
764 cpufreq_cpu_put(managed_policy);
765 /*
766 * Success. We only needed to be added to the mask.
767 * Call driver->exit() because only the cpu parent of
768 * the kobj needed to call init().
769 */
770 if (cpufreq_driver->exit)
771 cpufreq_driver->exit(policy);
Thomas Renninger4bfa0422009-07-24 15:25:03 +0200772
773 if (!ret)
774 return 1;
775 else
776 return ret;
Dave Jonesecf7e462009-07-08 18:48:47 -0400777 }
778 }
779#endif
780 return ret;
781}
782
783
Dave Jones19d6f7e2009-07-08 17:35:39 -0400784/* symlink affected CPUs */
Alex Chiangcf3289d02009-11-17 20:27:08 -0700785static int cpufreq_add_dev_symlink(unsigned int cpu,
786 struct cpufreq_policy *policy)
Dave Jones19d6f7e2009-07-08 17:35:39 -0400787{
788 unsigned int j;
789 int ret = 0;
790
791 for_each_cpu(j, policy->cpus) {
792 struct cpufreq_policy *managed_policy;
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800793 struct device *cpu_dev;
Dave Jones19d6f7e2009-07-08 17:35:39 -0400794
795 if (j == cpu)
796 continue;
797 if (!cpu_online(j))
798 continue;
799
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200800 pr_debug("CPU %u already managed, adding link\n", j);
Dave Jones19d6f7e2009-07-08 17:35:39 -0400801 managed_policy = cpufreq_cpu_get(cpu);
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800802 cpu_dev = get_cpu_device(j);
803 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
Dave Jones19d6f7e2009-07-08 17:35:39 -0400804 "cpufreq");
805 if (ret) {
806 cpufreq_cpu_put(managed_policy);
807 return ret;
808 }
809 }
810 return ret;
811}
812
Alex Chiangcf3289d02009-11-17 20:27:08 -0700813static int cpufreq_add_dev_interface(unsigned int cpu,
814 struct cpufreq_policy *policy,
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800815 struct device *dev)
Dave Jones909a6942009-07-08 18:05:42 -0400816{
Dave Jonesecf7e462009-07-08 18:48:47 -0400817 struct cpufreq_policy new_policy;
Dave Jones909a6942009-07-08 18:05:42 -0400818 struct freq_attr **drv_attr;
819 unsigned long flags;
820 int ret = 0;
821 unsigned int j;
822
823 /* prepare interface data */
824 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800825 &dev->kobj, "cpufreq");
Dave Jones909a6942009-07-08 18:05:42 -0400826 if (ret)
827 return ret;
828
829 /* set up files for this cpu device */
830 drv_attr = cpufreq_driver->attr;
831 while ((drv_attr) && (*drv_attr)) {
832 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
833 if (ret)
834 goto err_out_kobj_put;
835 drv_attr++;
836 }
837 if (cpufreq_driver->get) {
838 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
839 if (ret)
840 goto err_out_kobj_put;
841 }
842 if (cpufreq_driver->target) {
843 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
844 if (ret)
845 goto err_out_kobj_put;
846 }
Thomas Renningere2f74f32009-11-19 12:31:01 +0100847 if (cpufreq_driver->bios_limit) {
848 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
849 if (ret)
850 goto err_out_kobj_put;
851 }
Dave Jones909a6942009-07-08 18:05:42 -0400852
853 spin_lock_irqsave(&cpufreq_driver_lock, flags);
854 for_each_cpu(j, policy->cpus) {
Julia Lawallbec037a2010-08-05 22:23:00 +0200855 if (!cpu_online(j))
856 continue;
Dave Jones909a6942009-07-08 18:05:42 -0400857 per_cpu(cpufreq_cpu_data, j) = policy;
Tejun Heof1625062009-10-29 22:34:13 +0900858 per_cpu(cpufreq_policy_cpu, j) = policy->cpu;
Dave Jones909a6942009-07-08 18:05:42 -0400859 }
860 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
861
862 ret = cpufreq_add_dev_symlink(cpu, policy);
Dave Jonesecf7e462009-07-08 18:48:47 -0400863 if (ret)
864 goto err_out_kobj_put;
865
866 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
867 /* assure that the starting sequence is run in __cpufreq_set_policy */
868 policy->governor = NULL;
869
870 /* set default policy */
871 ret = __cpufreq_set_policy(policy, &new_policy);
872 policy->user_policy.policy = policy->policy;
873 policy->user_policy.governor = policy->governor;
874
875 if (ret) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200876 pr_debug("setting policy failed\n");
Dave Jonesecf7e462009-07-08 18:48:47 -0400877 if (cpufreq_driver->exit)
878 cpufreq_driver->exit(policy);
879 }
Dave Jones909a6942009-07-08 18:05:42 -0400880 return ret;
881
882err_out_kobj_put:
883 kobject_put(&policy->kobj);
884 wait_for_completion(&policy->kobj_unregister);
885 return ret;
886}
887
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
889/**
890 * cpufreq_add_dev - add a CPU device
891 *
Dave Jones32ee8c32006-02-28 00:43:23 -0500892 * Adds the cpufreq interface for a CPU device.
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400893 *
894 * The Oracle says: try running cpufreq registration/unregistration concurrently
895 * with with cpu hotplugging and all hell will break loose. Tried to clean this
896 * mess up, but more thorough testing is needed. - Mathieu
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 */
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800898static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800900 unsigned int cpu = dev->id;
Prarit Bhargava90e41ba2009-11-12 09:18:46 -0500901 int ret = 0, found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 struct cpufreq_policy *policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 unsigned long flags;
904 unsigned int j;
Prarit Bhargava90e41ba2009-11-12 09:18:46 -0500905#ifdef CONFIG_HOTPLUG_CPU
906 int sibling;
907#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Ashok Rajc32b6b82005-10-30 14:59:54 -0800909 if (cpu_is_offline(cpu))
910 return 0;
911
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200912 pr_debug("adding CPU %u\n", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914#ifdef CONFIG_SMP
915 /* check whether a different CPU already registered this
916 * CPU because it is in the same boat. */
917 policy = cpufreq_cpu_get(cpu);
918 if (unlikely(policy)) {
Dave Jones8ff69732006-03-05 03:37:23 -0500919 cpufreq_cpu_put(policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 return 0;
921 }
922#endif
923
924 if (!try_module_get(cpufreq_driver->owner)) {
925 ret = -EINVAL;
926 goto module_out;
927 }
928
Dave Jones059019a2009-07-08 16:30:03 -0400929 ret = -ENOMEM;
Dave Jonese98df502005-10-20 15:17:43 -0700930 policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL);
Dave Jones059019a2009-07-08 16:30:03 -0400931 if (!policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 goto nomem_out;
Dave Jones059019a2009-07-08 16:30:03 -0400933
934 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400935 goto err_free_policy;
Dave Jones059019a2009-07-08 16:30:03 -0400936
937 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400938 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 policy->cpu = cpu;
Rusty Russell835481d2009-01-04 05:18:06 -0800941 cpumask_copy(policy->cpus, cpumask_of(cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800943 /* Initially set CPU itself as the policy_cpu */
Tejun Heof1625062009-10-29 22:34:13 +0900944 per_cpu(cpufreq_policy_cpu, cpu) = cpu;
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400945 ret = (lock_policy_rwsem_write(cpu) < 0);
946 WARN_ON(ret);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 init_completion(&policy->kobj_unregister);
David Howells65f27f32006-11-22 14:55:48 +0000949 INIT_WORK(&policy->update, handle_update);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Thomas Renninger8122c6c2007-10-02 13:28:09 -0700951 /* Set governor before ->init, so that driver could check it */
Prarit Bhargava90e41ba2009-11-12 09:18:46 -0500952#ifdef CONFIG_HOTPLUG_CPU
953 for_each_online_cpu(sibling) {
954 struct cpufreq_policy *cp = per_cpu(cpufreq_cpu_data, sibling);
955 if (cp && cp->governor &&
956 (cpumask_test_cpu(cpu, cp->related_cpus))) {
957 policy->governor = cp->governor;
958 found = 1;
959 break;
960 }
961 }
962#endif
963 if (!found)
964 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 /* call driver. From then on the cpufreq must be able
966 * to accept all calls to ->verify and ->setpolicy for this CPU
967 */
968 ret = cpufreq_driver->init(policy);
969 if (ret) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200970 pr_debug("initialization failed\n");
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400971 goto err_unlock_policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 }
Mike Chan187d9f42008-12-04 12:19:17 -0800973 policy->user_policy.min = policy->min;
974 policy->user_policy.max = policy->max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Thomas Renningera1531ac2008-07-29 22:32:58 -0700976 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
977 CPUFREQ_START, policy);
978
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800979 ret = cpufreq_add_dev_policy(cpu, policy, dev);
Thomas Renninger4bfa0422009-07-24 15:25:03 +0200980 if (ret) {
981 if (ret > 0)
982 /* This is a managed cpu, symlink created,
983 exit with 0 */
984 ret = 0;
Dave Jonesecf7e462009-07-08 18:48:47 -0400985 goto err_unlock_policy;
Thomas Renninger4bfa0422009-07-24 15:25:03 +0200986 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800988 ret = cpufreq_add_dev_interface(cpu, policy, dev);
Dave Jones19d6f7e2009-07-08 17:35:39 -0400989 if (ret)
990 goto err_out_unregister;
Dave Jones8ff69732006-03-05 03:37:23 -0500991
Lothar Waßmanndca02612008-05-29 17:54:52 +0200992 unlock_policy_rwsem_write(cpu);
993
Greg Kroah-Hartman038c5b32007-12-17 15:54:39 -0400994 kobject_uevent(&policy->kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 module_put(cpufreq_driver->owner);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200996 pr_debug("initialization complete\n");
Dave Jones87c32272006-03-29 01:48:37 -0500997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 return 0;
999
1000
1001err_out_unregister:
1002 spin_lock_irqsave(&cpufreq_driver_lock, flags);
Rusty Russell835481d2009-01-04 05:18:06 -08001003 for_each_cpu(j, policy->cpus)
Mike Travis7a6aedf2008-03-25 15:06:53 -07001004 per_cpu(cpufreq_cpu_data, j) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1006
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -08001007 kobject_put(&policy->kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 wait_for_completion(&policy->kobj_unregister);
1009
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -04001010err_unlock_policy:
Dave Jones45709112008-03-05 14:07:34 -05001011 unlock_policy_rwsem_write(cpu);
Xiaotian Fengcad70a62010-07-20 20:11:02 +08001012 free_cpumask_var(policy->related_cpus);
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -04001013err_free_cpumask:
1014 free_cpumask_var(policy->cpus);
1015err_free_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 kfree(policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017nomem_out:
1018 module_put(cpufreq_driver->owner);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001019module_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 return ret;
1021}
1022
1023
1024/**
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001025 * __cpufreq_remove_dev - remove a CPU device
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 *
1027 * Removes the cpufreq interface for a CPU device.
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001028 * Caller should already have policy_rwsem in write mode for this CPU.
1029 * This routine frees the rwsem before returning.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 */
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001031static int __cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001033 unsigned int cpu = dev->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 unsigned long flags;
1035 struct cpufreq_policy *data;
Amerigo Wang499bca92010-03-04 03:23:46 -05001036 struct kobject *kobj;
1037 struct completion *cmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038#ifdef CONFIG_SMP
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001039 struct device *cpu_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 unsigned int j;
1041#endif
1042
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001043 pr_debug("unregistering CPU %u\n", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 spin_lock_irqsave(&cpufreq_driver_lock, flags);
Mike Travis7a6aedf2008-03-25 15:06:53 -07001046 data = per_cpu(cpufreq_cpu_data, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
1048 if (!data) {
1049 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001050 unlock_policy_rwsem_write(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 return -EINVAL;
1052 }
Mike Travis7a6aedf2008-03-25 15:06:53 -07001053 per_cpu(cpufreq_cpu_data, cpu) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055
1056#ifdef CONFIG_SMP
1057 /* if this isn't the CPU which is the parent of the kobj, we
Dave Jones32ee8c32006-02-28 00:43:23 -05001058 * only need to unlink, put and exit
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 */
1060 if (unlikely(cpu != data->cpu)) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001061 pr_debug("removing link\n");
Rusty Russell835481d2009-01-04 05:18:06 -08001062 cpumask_clear_cpu(cpu, data->cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001064 kobj = &dev->kobj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 cpufreq_cpu_put(data);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001066 unlock_policy_rwsem_write(cpu);
Amerigo Wang499bca92010-03-04 03:23:46 -05001067 sysfs_remove_link(kobj, "cpufreq");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 return 0;
1069 }
1070#endif
1071
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072#ifdef CONFIG_SMP
Thomas Renninger084f3492007-07-09 11:35:28 -07001073
1074#ifdef CONFIG_HOTPLUG_CPU
Dmitry Monakhove77b89f2009-10-05 00:38:55 +04001075 strncpy(per_cpu(cpufreq_cpu_governor, cpu), data->governor->name,
1076 CPUFREQ_NAME_LEN);
Thomas Renninger084f3492007-07-09 11:35:28 -07001077#endif
1078
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 /* if we have other CPUs still registered, we need to unlink them,
1080 * or else wait_for_completion below will lock up. Clean the
Mike Travis7a6aedf2008-03-25 15:06:53 -07001081 * per_cpu(cpufreq_cpu_data) while holding the lock, and remove
1082 * the sysfs links afterwards.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 */
Rusty Russell835481d2009-01-04 05:18:06 -08001084 if (unlikely(cpumask_weight(data->cpus) > 1)) {
1085 for_each_cpu(j, data->cpus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (j == cpu)
1087 continue;
Mike Travis7a6aedf2008-03-25 15:06:53 -07001088 per_cpu(cpufreq_cpu_data, j) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 }
1090 }
1091
1092 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1093
Rusty Russell835481d2009-01-04 05:18:06 -08001094 if (unlikely(cpumask_weight(data->cpus) > 1)) {
1095 for_each_cpu(j, data->cpus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 if (j == cpu)
1097 continue;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001098 pr_debug("removing link for cpu %u\n", j);
Thomas Renninger084f3492007-07-09 11:35:28 -07001099#ifdef CONFIG_HOTPLUG_CPU
Dmitry Monakhove77b89f2009-10-05 00:38:55 +04001100 strncpy(per_cpu(cpufreq_cpu_governor, j),
1101 data->governor->name, CPUFREQ_NAME_LEN);
Thomas Renninger084f3492007-07-09 11:35:28 -07001102#endif
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001103 cpu_dev = get_cpu_device(j);
1104 kobj = &cpu_dev->kobj;
Amerigo Wang499bca92010-03-04 03:23:46 -05001105 unlock_policy_rwsem_write(cpu);
1106 sysfs_remove_link(kobj, "cpufreq");
1107 lock_policy_rwsem_write(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 cpufreq_cpu_put(data);
1109 }
1110 }
1111#else
1112 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1113#endif
1114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (cpufreq_driver->target)
1116 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001117
Amerigo Wang499bca92010-03-04 03:23:46 -05001118 kobj = &data->kobj;
1119 cmp = &data->kobj_unregister;
1120 unlock_policy_rwsem_write(cpu);
1121 kobject_put(kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 /* we need to make sure that the underlying kobj is actually
Dave Jones32ee8c32006-02-28 00:43:23 -05001124 * not referenced anymore by anybody before we proceed with
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 * unloading.
1126 */
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001127 pr_debug("waiting for dropping of refcount\n");
Amerigo Wang499bca92010-03-04 03:23:46 -05001128 wait_for_completion(cmp);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001129 pr_debug("wait complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Amerigo Wang499bca92010-03-04 03:23:46 -05001131 lock_policy_rwsem_write(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 if (cpufreq_driver->exit)
1133 cpufreq_driver->exit(data);
venkatesh.pallipadi@intel.com7d26e2d2009-07-02 17:08:30 -07001134 unlock_policy_rwsem_write(cpu);
1135
Jacob Shin27ecddc2011-04-27 13:32:11 -05001136#ifdef CONFIG_HOTPLUG_CPU
1137 /* when the CPU which is the parent of the kobj is hotplugged
1138 * offline, check for siblings, and create cpufreq sysfs interface
1139 * and symlinks
1140 */
1141 if (unlikely(cpumask_weight(data->cpus) > 1)) {
1142 /* first sibling now owns the new sysfs dir */
1143 cpumask_clear_cpu(cpu, data->cpus);
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001144 cpufreq_add_dev(get_cpu_device(cpumask_first(data->cpus)), NULL);
Jacob Shin27ecddc2011-04-27 13:32:11 -05001145
1146 /* finally remove our own symlink */
1147 lock_policy_rwsem_write(cpu);
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001148 __cpufreq_remove_dev(dev, sif);
Jacob Shin27ecddc2011-04-27 13:32:11 -05001149 }
1150#endif
1151
Rusty Russell835481d2009-01-04 05:18:06 -08001152 free_cpumask_var(data->related_cpus);
1153 free_cpumask_var(data->cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 kfree(data);
1155
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 return 0;
1157}
1158
1159
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001160static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001161{
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001162 unsigned int cpu = dev->id;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001163 int retval;
Venki Pallipadiec282972007-03-26 12:03:19 -07001164
1165 if (cpu_is_offline(cpu))
1166 return 0;
1167
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001168 if (unlikely(lock_policy_rwsem_write(cpu)))
1169 BUG();
1170
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001171 retval = __cpufreq_remove_dev(dev, sif);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001172 return retval;
1173}
1174
1175
David Howells65f27f32006-11-22 14:55:48 +00001176static void handle_update(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177{
David Howells65f27f32006-11-22 14:55:48 +00001178 struct cpufreq_policy *policy =
1179 container_of(work, struct cpufreq_policy, update);
1180 unsigned int cpu = policy->cpu;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001181 pr_debug("handle_update for cpu %u called\n", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 cpufreq_update_policy(cpu);
1183}
1184
1185/**
1186 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble.
1187 * @cpu: cpu number
1188 * @old_freq: CPU frequency the kernel thinks the CPU runs at
1189 * @new_freq: CPU frequency the CPU actually runs at
1190 *
Dave Jones29464f22009-01-18 01:37:11 -05001191 * We adjust to current frequency first, and need to clean up later.
1192 * So either call to cpufreq_update_policy() or schedule handle_update()).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 */
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301194static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
1195 unsigned int new_freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
1197 struct cpufreq_freqs freqs;
1198
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001199 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 "core thinks of %u, is %u kHz.\n", old_freq, new_freq);
1201
1202 freqs.cpu = cpu;
1203 freqs.old = old_freq;
1204 freqs.new = new_freq;
1205 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
1206 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
1207}
1208
1209
Dave Jones32ee8c32006-02-28 00:43:23 -05001210/**
Dhaval Giani4ab70df2006-12-13 14:49:15 +05301211 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -08001212 * @cpu: CPU number
1213 *
1214 * This is the last known freq, without actually getting it from the driver.
1215 * Return value will be same as what is shown in scaling_cur_freq in sysfs.
1216 */
1217unsigned int cpufreq_quick_get(unsigned int cpu)
1218{
1219 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301220 unsigned int ret_freq = 0;
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -08001221
1222 if (policy) {
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301223 ret_freq = policy->cur;
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -08001224 cpufreq_cpu_put(policy);
1225 }
1226
Dave Jones4d34a672008-02-07 16:33:49 -05001227 return ret_freq;
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -08001228}
1229EXPORT_SYMBOL(cpufreq_quick_get);
1230
Jesse Barnes3d737102011-06-28 10:59:12 -07001231/**
1232 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1233 * @cpu: CPU number
1234 *
1235 * Just return the max possible frequency for a given CPU.
1236 */
1237unsigned int cpufreq_quick_get_max(unsigned int cpu)
1238{
1239 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1240 unsigned int ret_freq = 0;
1241
1242 if (policy) {
1243 ret_freq = policy->max;
1244 cpufreq_cpu_put(policy);
1245 }
1246
1247 return ret_freq;
1248}
1249EXPORT_SYMBOL(cpufreq_quick_get_max);
1250
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -08001251
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001252static unsigned int __cpufreq_get(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
Mike Travis7a6aedf2008-03-25 15:06:53 -07001254 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301255 unsigned int ret_freq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (!cpufreq_driver->get)
Dave Jones4d34a672008-02-07 16:33:49 -05001258 return ret_freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301260 ret_freq = cpufreq_driver->get(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301262 if (ret_freq && policy->cur &&
1263 !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
1264 /* verify no discrepancy between actual and
1265 saved value exists */
1266 if (unlikely(ret_freq != policy->cur)) {
1267 cpufreq_out_of_sync(cpu, policy->cur, ret_freq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 schedule_work(&policy->update);
1269 }
1270 }
1271
Dave Jones4d34a672008-02-07 16:33:49 -05001272 return ret_freq;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001273}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001275/**
1276 * cpufreq_get - get the current CPU frequency (in kHz)
1277 * @cpu: CPU number
1278 *
1279 * Get the CPU current (static) CPU frequency
1280 */
1281unsigned int cpufreq_get(unsigned int cpu)
1282{
1283 unsigned int ret_freq = 0;
1284 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1285
1286 if (!policy)
1287 goto out;
1288
1289 if (unlikely(lock_policy_rwsem_read(cpu)))
1290 goto out_policy;
1291
1292 ret_freq = __cpufreq_get(cpu);
1293
1294 unlock_policy_rwsem_read(cpu);
1295
1296out_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 cpufreq_cpu_put(policy);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001298out:
Dave Jones4d34a672008-02-07 16:33:49 -05001299 return ret_freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300}
1301EXPORT_SYMBOL(cpufreq_get);
1302
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001303static struct subsys_interface cpufreq_interface = {
1304 .name = "cpufreq",
1305 .subsys = &cpu_subsys,
1306 .add_dev = cpufreq_add_dev,
1307 .remove_dev = cpufreq_remove_dev,
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001308};
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
1311/**
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001312 * cpufreq_bp_suspend - Prepare the boot CPU for system suspend.
1313 *
1314 * This function is only executed for the boot processor. The other CPUs
1315 * have been put offline by means of CPU hotplug.
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001316 */
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001317static int cpufreq_bp_suspend(void)
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001318{
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301319 int ret = 0;
Dave Jones4bc5d342009-08-04 14:03:25 -04001320
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001321 int cpu = smp_processor_id();
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001322 struct cpufreq_policy *cpu_policy;
1323
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001324 pr_debug("suspending cpu %u\n", cpu);
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001325
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001326 /* If there's no policy for the boot CPU, we have nothing to do. */
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001327 cpu_policy = cpufreq_cpu_get(cpu);
1328 if (!cpu_policy)
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001329 return 0;
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001330
1331 if (cpufreq_driver->suspend) {
Rafael J. Wysocki7ca64e22011-03-10 21:13:05 +01001332 ret = cpufreq_driver->suspend(cpu_policy);
Dominik Brodowskice6c3992009-08-07 22:58:51 +02001333 if (ret)
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001334 printk(KERN_ERR "cpufreq: suspend failed in ->suspend "
1335 "step on CPU %u\n", cpu_policy->cpu);
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001336 }
1337
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001338 cpufreq_cpu_put(cpu_policy);
Dave Jonesc9060492008-02-07 16:32:18 -05001339 return ret;
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001340}
1341
1342/**
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001343 * cpufreq_bp_resume - Restore proper frequency handling of the boot CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 *
1345 * 1.) resume CPUfreq hardware support (cpufreq_driver->resume())
Dominik Brodowskice6c3992009-08-07 22:58:51 +02001346 * 2.) schedule call cpufreq_update_policy() ASAP as interrupts are
1347 * restored. It will verify that the current freq is in sync with
1348 * what we believe it to be. This is a bit later than when it
1349 * should be, but nonethteless it's better than calling
1350 * cpufreq_driver->get() here which might re-enable interrupts...
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001351 *
1352 * This function is only executed for the boot CPU. The other CPUs have not
1353 * been turned on yet.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 */
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001355static void cpufreq_bp_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301357 int ret = 0;
Dave Jones4bc5d342009-08-04 14:03:25 -04001358
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001359 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 struct cpufreq_policy *cpu_policy;
1361
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001362 pr_debug("resuming cpu %u\n", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001364 /* If there's no policy for the boot CPU, we have nothing to do. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 cpu_policy = cpufreq_cpu_get(cpu);
1366 if (!cpu_policy)
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001367 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 if (cpufreq_driver->resume) {
1370 ret = cpufreq_driver->resume(cpu_policy);
1371 if (ret) {
1372 printk(KERN_ERR "cpufreq: resume failed in ->resume "
1373 "step on CPU %u\n", cpu_policy->cpu);
Dave Jonesc9060492008-02-07 16:32:18 -05001374 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 }
1376 }
1377
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 schedule_work(&cpu_policy->update);
Dominik Brodowskice6c3992009-08-07 22:58:51 +02001379
Dave Jonesc9060492008-02-07 16:32:18 -05001380fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 cpufreq_cpu_put(cpu_policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382}
1383
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001384static struct syscore_ops cpufreq_syscore_ops = {
1385 .suspend = cpufreq_bp_suspend,
1386 .resume = cpufreq_bp_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387};
1388
1389
1390/*********************************************************************
1391 * NOTIFIER LISTS INTERFACE *
1392 *********************************************************************/
1393
1394/**
1395 * cpufreq_register_notifier - register a driver with cpufreq
1396 * @nb: notifier function to register
1397 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1398 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001399 * Add a driver to one of two lists: either a list of drivers that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 * are notified about clock rate changes (once before and once after
1401 * the transition), or a list of drivers that are notified about
1402 * changes in cpufreq policy.
1403 *
1404 * This function may sleep, and has the same return conditions as
Alan Sterne041c682006-03-27 01:16:30 -08001405 * blocking_notifier_chain_register.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 */
1407int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1408{
1409 int ret;
1410
Cesar Eduardo Barros74212ca2008-02-16 08:41:24 -02001411 WARN_ON(!init_cpufreq_transition_notifier_list_called);
1412
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 switch (list) {
1414 case CPUFREQ_TRANSITION_NOTIFIER:
Alan Sternb4dfdbb2006-10-04 02:17:06 -07001415 ret = srcu_notifier_chain_register(
Alan Sterne041c682006-03-27 01:16:30 -08001416 &cpufreq_transition_notifier_list, nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 break;
1418 case CPUFREQ_POLICY_NOTIFIER:
Alan Sterne041c682006-03-27 01:16:30 -08001419 ret = blocking_notifier_chain_register(
1420 &cpufreq_policy_notifier_list, nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 break;
1422 default:
1423 ret = -EINVAL;
1424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
1426 return ret;
1427}
1428EXPORT_SYMBOL(cpufreq_register_notifier);
1429
1430
1431/**
1432 * cpufreq_unregister_notifier - unregister a driver with cpufreq
1433 * @nb: notifier block to be unregistered
1434 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1435 *
1436 * Remove a driver from the CPU frequency notifier list.
1437 *
1438 * This function may sleep, and has the same return conditions as
Alan Sterne041c682006-03-27 01:16:30 -08001439 * blocking_notifier_chain_unregister.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 */
1441int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list)
1442{
1443 int ret;
1444
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 switch (list) {
1446 case CPUFREQ_TRANSITION_NOTIFIER:
Alan Sternb4dfdbb2006-10-04 02:17:06 -07001447 ret = srcu_notifier_chain_unregister(
Alan Sterne041c682006-03-27 01:16:30 -08001448 &cpufreq_transition_notifier_list, nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 break;
1450 case CPUFREQ_POLICY_NOTIFIER:
Alan Sterne041c682006-03-27 01:16:30 -08001451 ret = blocking_notifier_chain_unregister(
1452 &cpufreq_policy_notifier_list, nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 break;
1454 default:
1455 ret = -EINVAL;
1456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 return ret;
1459}
1460EXPORT_SYMBOL(cpufreq_unregister_notifier);
1461
1462
1463/*********************************************************************
1464 * GOVERNORS *
1465 *********************************************************************/
1466
1467
1468int __cpufreq_driver_target(struct cpufreq_policy *policy,
1469 unsigned int target_freq,
1470 unsigned int relation)
1471{
1472 int retval = -EINVAL;
Ashok Rajc32b6b82005-10-30 14:59:54 -08001473
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001474 if (cpufreq_disabled())
1475 return -ENODEV;
1476
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001477 pr_debug("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 target_freq, relation);
1479 if (cpu_online(policy->cpu) && cpufreq_driver->target)
1480 retval = cpufreq_driver->target(policy, target_freq, relation);
Ashok Raj90d45d12005-11-08 21:34:24 -08001481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 return retval;
1483}
1484EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
1485
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486int cpufreq_driver_target(struct cpufreq_policy *policy,
1487 unsigned int target_freq,
1488 unsigned int relation)
1489{
Julia Lawallf1829e42008-07-25 22:44:53 +02001490 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
1492 policy = cpufreq_cpu_get(policy->cpu);
1493 if (!policy)
Julia Lawallf1829e42008-07-25 22:44:53 +02001494 goto no_policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001496 if (unlikely(lock_policy_rwsem_write(policy->cpu)))
Julia Lawallf1829e42008-07-25 22:44:53 +02001497 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499 ret = __cpufreq_driver_target(policy, target_freq, relation);
1500
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001501 unlock_policy_rwsem_write(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Julia Lawallf1829e42008-07-25 22:44:53 +02001503fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 cpufreq_cpu_put(policy);
Julia Lawallf1829e42008-07-25 22:44:53 +02001505no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 return ret;
1507}
1508EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1509
venkatesh.pallipadi@intel.combf0b90e2008-08-04 11:59:07 -07001510int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu)
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001511{
1512 int ret = 0;
1513
1514 policy = cpufreq_cpu_get(policy->cpu);
1515 if (!policy)
1516 return -EINVAL;
1517
venkatesh.pallipadi@intel.combf0b90e2008-08-04 11:59:07 -07001518 if (cpu_online(cpu) && cpufreq_driver->getavg)
1519 ret = cpufreq_driver->getavg(policy, cpu);
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001520
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001521 cpufreq_cpu_put(policy);
1522 return ret;
1523}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001524EXPORT_SYMBOL_GPL(__cpufreq_driver_getavg);
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001525
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001526/*
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001527 * when "event" is CPUFREQ_GOV_LIMITS
1528 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301530static int __cpufreq_governor(struct cpufreq_policy *policy,
1531 unsigned int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Dave Jonescc993ca2005-07-28 09:43:56 -07001533 int ret;
Thomas Renninger6afde102007-10-02 13:28:13 -07001534
1535 /* Only must be defined when default governor is known to have latency
1536 restrictions, like e.g. conservative or ondemand.
1537 That this is the case is already ensured in Kconfig
1538 */
1539#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
1540 struct cpufreq_governor *gov = &cpufreq_gov_performance;
1541#else
1542 struct cpufreq_governor *gov = NULL;
1543#endif
Thomas Renninger1c256242007-10-02 13:28:12 -07001544
1545 if (policy->governor->max_transition_latency &&
1546 policy->cpuinfo.transition_latency >
1547 policy->governor->max_transition_latency) {
Thomas Renninger6afde102007-10-02 13:28:13 -07001548 if (!gov)
1549 return -EINVAL;
1550 else {
1551 printk(KERN_WARNING "%s governor failed, too long"
1552 " transition latency of HW, fallback"
1553 " to %s governor\n",
1554 policy->governor->name,
1555 gov->name);
1556 policy->governor = gov;
1557 }
Thomas Renninger1c256242007-10-02 13:28:12 -07001558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560 if (!try_module_get(policy->governor->owner))
1561 return -EINVAL;
1562
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001563 pr_debug("__cpufreq_governor for CPU %u, event %u\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301564 policy->cpu, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 ret = policy->governor->governor(policy, event);
1566
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301567 /* we keep one module reference alive for
1568 each CPU governed by this CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 if ((event != CPUFREQ_GOV_START) || ret)
1570 module_put(policy->governor->owner);
1571 if ((event == CPUFREQ_GOV_STOP) && !ret)
1572 module_put(policy->governor->owner);
1573
1574 return ret;
1575}
1576
1577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578int cpufreq_register_governor(struct cpufreq_governor *governor)
1579{
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -07001580 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582 if (!governor)
1583 return -EINVAL;
1584
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001585 if (cpufreq_disabled())
1586 return -ENODEV;
1587
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001588 mutex_lock(&cpufreq_governor_mutex);
Dave Jones32ee8c32006-02-28 00:43:23 -05001589
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -07001590 err = -EBUSY;
1591 if (__find_governor(governor->name) == NULL) {
1592 err = 0;
1593 list_add(&governor->governor_list, &cpufreq_governor_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
Dave Jones32ee8c32006-02-28 00:43:23 -05001596 mutex_unlock(&cpufreq_governor_mutex);
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -07001597 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598}
1599EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1600
1601
1602void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1603{
Prarit Bhargava90e41ba2009-11-12 09:18:46 -05001604#ifdef CONFIG_HOTPLUG_CPU
1605 int cpu;
1606#endif
1607
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 if (!governor)
1609 return;
1610
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001611 if (cpufreq_disabled())
1612 return;
1613
Prarit Bhargava90e41ba2009-11-12 09:18:46 -05001614#ifdef CONFIG_HOTPLUG_CPU
1615 for_each_present_cpu(cpu) {
1616 if (cpu_online(cpu))
1617 continue;
1618 if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
1619 strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
1620 }
1621#endif
1622
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001623 mutex_lock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 list_del(&governor->governor_list);
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001625 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 return;
1627}
1628EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
1629
1630
1631
1632/*********************************************************************
1633 * POLICY INTERFACE *
1634 *********************************************************************/
1635
1636/**
1637 * cpufreq_get_policy - get the current cpufreq_policy
Dave Jones29464f22009-01-18 01:37:11 -05001638 * @policy: struct cpufreq_policy into which the current cpufreq_policy
1639 * is written
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 *
1641 * Reads the current cpufreq policy.
1642 */
1643int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1644{
1645 struct cpufreq_policy *cpu_policy;
1646 if (!policy)
1647 return -EINVAL;
1648
1649 cpu_policy = cpufreq_cpu_get(cpu);
1650 if (!cpu_policy)
1651 return -EINVAL;
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655 cpufreq_cpu_put(cpu_policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 return 0;
1657}
1658EXPORT_SYMBOL(cpufreq_get_policy);
1659
1660
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001661/*
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301662 * data : current policy.
1663 * policy : policy to be set.
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001664 */
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301665static int __cpufreq_set_policy(struct cpufreq_policy *data,
1666 struct cpufreq_policy *policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667{
1668 int ret = 0;
1669
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001670 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 policy->min, policy->max);
1672
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301673 memcpy(&policy->cpuinfo, &data->cpuinfo,
1674 sizeof(struct cpufreq_cpuinfo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
Yi Yang53391fa2008-01-30 13:33:34 +01001676 if (policy->min > data->max || policy->max < data->min) {
Mattia Dongili9c9a43e2006-07-05 23:12:20 +02001677 ret = -EINVAL;
1678 goto error_out;
1679 }
1680
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 /* verify the cpu speed can be set within this limit */
1682 ret = cpufreq_driver->verify(policy);
1683 if (ret)
1684 goto error_out;
1685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 /* adjust if necessary - all reasons */
Alan Sterne041c682006-03-27 01:16:30 -08001687 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1688 CPUFREQ_ADJUST, policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690 /* adjust if necessary - hardware incompatibility*/
Alan Sterne041c682006-03-27 01:16:30 -08001691 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1692 CPUFREQ_INCOMPATIBLE, policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
1694 /* verify the cpu speed can be set within this limit,
1695 which might be different to the first one */
1696 ret = cpufreq_driver->verify(policy);
Alan Sterne041c682006-03-27 01:16:30 -08001697 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 goto error_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
1700 /* notification of the new policy */
Alan Sterne041c682006-03-27 01:16:30 -08001701 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1702 CPUFREQ_NOTIFY, policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Dave Jones7d5e3502006-02-02 17:03:42 -05001704 data->min = policy->min;
1705 data->max = policy->max;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001707 pr_debug("new min and max freqs are %u - %u kHz\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301708 data->min, data->max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 if (cpufreq_driver->setpolicy) {
1711 data->policy = policy->policy;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001712 pr_debug("setting range\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 ret = cpufreq_driver->setpolicy(policy);
1714 } else {
1715 if (policy->governor != data->governor) {
1716 /* save old, working values */
1717 struct cpufreq_governor *old_gov = data->governor;
1718
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001719 pr_debug("governor switch\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 /* end old governor */
Andrej Gelenbergffe62752010-05-14 15:15:58 -07001722 if (data->governor)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
1724
1725 /* start new governor */
1726 data->governor = policy->governor;
1727 if (__cpufreq_governor(data, CPUFREQ_GOV_START)) {
1728 /* new governor failed, so re-start old one */
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001729 pr_debug("starting governor %s failed\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301730 data->governor->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 if (old_gov) {
1732 data->governor = old_gov;
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301733 __cpufreq_governor(data,
1734 CPUFREQ_GOV_START);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 }
1736 ret = -EINVAL;
1737 goto error_out;
1738 }
1739 /* might be a policy change, too, so fall through */
1740 }
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001741 pr_debug("governor: change or update limits\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS);
1743 }
1744
Dave Jones7d5e3502006-02-02 17:03:42 -05001745error_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 return ret;
1747}
1748
1749/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
1751 * @cpu: CPU which shall be re-evaluated
1752 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001753 * Useful for policy notifiers which have different necessities
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 * at different times.
1755 */
1756int cpufreq_update_policy(unsigned int cpu)
1757{
1758 struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
1759 struct cpufreq_policy policy;
Julia Lawallf1829e42008-07-25 22:44:53 +02001760 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Julia Lawallf1829e42008-07-25 22:44:53 +02001762 if (!data) {
1763 ret = -ENODEV;
1764 goto no_policy;
1765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Julia Lawallf1829e42008-07-25 22:44:53 +02001767 if (unlikely(lock_policy_rwsem_write(cpu))) {
1768 ret = -EINVAL;
1769 goto fail;
1770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001772 pr_debug("updating policy for CPU %u\n", cpu);
Dave Jones7d5e3502006-02-02 17:03:42 -05001773 memcpy(&policy, data, sizeof(struct cpufreq_policy));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 policy.min = data->user_policy.min;
1775 policy.max = data->user_policy.max;
1776 policy.policy = data->user_policy.policy;
1777 policy.governor = data->user_policy.governor;
1778
Thomas Renninger0961dd02006-01-26 18:46:33 +01001779 /* BIOS might change freq behind our back
1780 -> ask driver for current freq and notify governors about a change */
1781 if (cpufreq_driver->get) {
1782 policy.cur = cpufreq_driver->get(cpu);
Thomas Renningera85f7bd2006-02-01 11:36:04 +01001783 if (!data->cur) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001784 pr_debug("Driver did not initialize current freq");
Thomas Renningera85f7bd2006-02-01 11:36:04 +01001785 data->cur = policy.cur;
1786 } else {
1787 if (data->cur != policy.cur)
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301788 cpufreq_out_of_sync(cpu, data->cur,
1789 policy.cur);
Thomas Renningera85f7bd2006-02-01 11:36:04 +01001790 }
Thomas Renninger0961dd02006-01-26 18:46:33 +01001791 }
1792
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 ret = __cpufreq_set_policy(data, &policy);
1794
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001795 unlock_policy_rwsem_write(cpu);
1796
Julia Lawallf1829e42008-07-25 22:44:53 +02001797fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 cpufreq_cpu_put(data);
Julia Lawallf1829e42008-07-25 22:44:53 +02001799no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 return ret;
1801}
1802EXPORT_SYMBOL(cpufreq_update_policy);
1803
Satyam Sharmadd184a02007-10-02 13:28:14 -07001804static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
Ashok Rajc32b6b82005-10-30 14:59:54 -08001805 unsigned long action, void *hcpu)
1806{
1807 unsigned int cpu = (unsigned long)hcpu;
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001808 struct device *dev;
Ashok Rajc32b6b82005-10-30 14:59:54 -08001809
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001810 dev = get_cpu_device(cpu);
1811 if (dev) {
Ashok Rajc32b6b82005-10-30 14:59:54 -08001812 switch (action) {
1813 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001814 case CPU_ONLINE_FROZEN:
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001815 cpufreq_add_dev(dev, NULL);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001816 break;
1817 case CPU_DOWN_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001818 case CPU_DOWN_PREPARE_FROZEN:
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001819 if (unlikely(lock_policy_rwsem_write(cpu)))
1820 BUG();
1821
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001822 __cpufreq_remove_dev(dev, NULL);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001823 break;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001824 case CPU_DOWN_FAILED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001825 case CPU_DOWN_FAILED_FROZEN:
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001826 cpufreq_add_dev(dev, NULL);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001827 break;
1828 }
1829 }
1830 return NOTIFY_OK;
1831}
1832
Neal Buckendahl9c36f742010-06-22 22:02:44 -05001833static struct notifier_block __refdata cpufreq_cpu_notifier = {
Ashok Rajc32b6b82005-10-30 14:59:54 -08001834 .notifier_call = cpufreq_cpu_callback,
1835};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
1837/*********************************************************************
1838 * REGISTER / UNREGISTER CPUFREQ DRIVER *
1839 *********************************************************************/
1840
1841/**
1842 * cpufreq_register_driver - register a CPU Frequency driver
1843 * @driver_data: A struct cpufreq_driver containing the values#
1844 * submitted by the CPU Frequency driver.
1845 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001846 * Registers a CPU Frequency driver to this core code. This code
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 * returns zero on success, -EBUSY when another driver got here first
Dave Jones32ee8c32006-02-28 00:43:23 -05001848 * (and isn't unregistered in the meantime).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 *
1850 */
Linus Torvalds221dee22007-02-26 14:55:48 -08001851int cpufreq_register_driver(struct cpufreq_driver *driver_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852{
1853 unsigned long flags;
1854 int ret;
1855
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001856 if (cpufreq_disabled())
1857 return -ENODEV;
1858
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 if (!driver_data || !driver_data->verify || !driver_data->init ||
1860 ((!driver_data->setpolicy) && (!driver_data->target)))
1861 return -EINVAL;
1862
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001863 pr_debug("trying to register driver %s\n", driver_data->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 if (driver_data->setpolicy)
1866 driver_data->flags |= CPUFREQ_CONST_LOOPS;
1867
1868 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1869 if (cpufreq_driver) {
1870 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1871 return -EBUSY;
1872 }
1873 cpufreq_driver = driver_data;
1874 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1875
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001876 ret = subsys_interface_register(&cpufreq_interface);
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001877 if (ret)
1878 goto err_null_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001880 if (!(cpufreq_driver->flags & CPUFREQ_STICKY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 int i;
1882 ret = -ENODEV;
1883
1884 /* check for at least one working CPU */
Mike Travis7a6aedf2008-03-25 15:06:53 -07001885 for (i = 0; i < nr_cpu_ids; i++)
1886 if (cpu_possible(i) && per_cpu(cpufreq_cpu_data, i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 ret = 0;
Mike Travis7a6aedf2008-03-25 15:06:53 -07001888 break;
1889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 /* if all ->init() calls failed, unregister */
1892 if (ret) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001893 pr_debug("no CPU initialized for driver %s\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301894 driver_data->name);
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001895 goto err_if_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
1897 }
1898
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001899 register_hotcpu_notifier(&cpufreq_cpu_notifier);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001900 pr_debug("driver %s up and running\n", driver_data->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001902 return 0;
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001903err_if_unreg:
1904 subsys_interface_unregister(&cpufreq_interface);
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001905err_null_driver:
1906 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1907 cpufreq_driver = NULL;
1908 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Dave Jones4d34a672008-02-07 16:33:49 -05001909 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910}
1911EXPORT_SYMBOL_GPL(cpufreq_register_driver);
1912
1913
1914/**
1915 * cpufreq_unregister_driver - unregister the current CPUFreq driver
1916 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001917 * Unregister the current CPUFreq driver. Only call this if you have
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 * the right to do so, i.e. if you have succeeded in initialising before!
1919 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
1920 * currently not initialised.
1921 */
Linus Torvalds221dee22007-02-26 14:55:48 -08001922int cpufreq_unregister_driver(struct cpufreq_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923{
1924 unsigned long flags;
1925
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001926 if (!cpufreq_driver || (driver != cpufreq_driver))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001929 pr_debug("unregistering driver %s\n", driver->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001931 subsys_interface_unregister(&cpufreq_interface);
Chandra Seetharaman65edc682006-06-27 02:54:08 -07001932 unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933
1934 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1935 cpufreq_driver = NULL;
1936 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1937
1938 return 0;
1939}
1940EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001941
1942static int __init cpufreq_core_init(void)
1943{
1944 int cpu;
1945
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001946 if (cpufreq_disabled())
1947 return -ENODEV;
1948
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001949 for_each_possible_cpu(cpu) {
Tejun Heof1625062009-10-29 22:34:13 +09001950 per_cpu(cpufreq_policy_cpu, cpu) = -1;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001951 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu));
1952 }
Thomas Renninger8aa84ad2009-07-24 15:25:05 +02001953
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001954 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
Thomas Renninger8aa84ad2009-07-24 15:25:05 +02001955 BUG_ON(!cpufreq_global_kobject);
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001956 register_syscore_ops(&cpufreq_syscore_ops);
Thomas Renninger8aa84ad2009-07-24 15:25:05 +02001957
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001958 return 0;
1959}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001960core_initcall(cpufreq_core_init);