blob: 9af14a8bbcdbba16cf60e1ef9ad45dfaec67a9fc [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
Viresh Kumar6954ca92013-01-12 05:14:40 +000050/* Used when we unregister cpufreq driver */
51static struct cpumask cpufreq_online_mask;
52
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080053/*
54 * cpu_policy_rwsem is a per CPU reader-writer semaphore designed to cure
55 * all cpufreq/hotplug/workqueue/etc related lock issues.
56 *
57 * The rules for this semaphore:
58 * - Any routine that wants to read from the policy structure will
59 * do a down_read on this semaphore.
60 * - Any routine that will write to the policy structure and/or may take away
61 * the policy altogether (eg. CPU hotplug), will hold this lock in write
62 * mode before doing so.
63 *
64 * Additional rules:
65 * - All holders of the lock should check to make sure that the CPU they
66 * are concerned with are online after they get the lock.
67 * - Governor routines that can be called in cpufreq hotplug path should not
68 * take this sem as top level hotplug notifier handler takes this.
Mathieu Desnoyers395913d2009-06-08 13:17:31 -040069 * - Lock should not be held across
70 * __cpufreq_governor(data, CPUFREQ_GOV_STOP);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080071 */
Tejun Heof1625062009-10-29 22:34:13 +090072static DEFINE_PER_CPU(int, cpufreq_policy_cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080073static DEFINE_PER_CPU(struct rw_semaphore, cpu_policy_rwsem);
74
75#define lock_policy_rwsem(mode, cpu) \
Amerigo Wang226528c2010-03-04 03:23:36 -050076static int lock_policy_rwsem_##mode \
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080077(int cpu) \
78{ \
Tejun Heof1625062009-10-29 22:34:13 +090079 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080080 BUG_ON(policy_cpu == -1); \
81 down_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \
82 if (unlikely(!cpu_online(cpu))) { \
83 up_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \
84 return -1; \
85 } \
86 \
87 return 0; \
88}
89
90lock_policy_rwsem(read, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080091
92lock_policy_rwsem(write, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080093
Amerigo Wang226528c2010-03-04 03:23:36 -050094static void unlock_policy_rwsem_read(int cpu)
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080095{
Tejun Heof1625062009-10-29 22:34:13 +090096 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -080097 BUG_ON(policy_cpu == -1);
98 up_read(&per_cpu(cpu_policy_rwsem, policy_cpu));
99}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800100
Amerigo Wang226528c2010-03-04 03:23:36 -0500101static void unlock_policy_rwsem_write(int cpu)
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800102{
Tejun Heof1625062009-10-29 22:34:13 +0900103 int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800104 BUG_ON(policy_cpu == -1);
105 up_write(&per_cpu(cpu_policy_rwsem, policy_cpu));
106}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800107
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* internal prototypes */
Dave Jones29464f22009-01-18 01:37:11 -0500110static int __cpufreq_governor(struct cpufreq_policy *policy,
111 unsigned int event);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800112static unsigned int __cpufreq_get(unsigned int cpu);
David Howells65f27f32006-11-22 14:55:48 +0000113static void handle_update(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/**
Dave Jones32ee8c32006-02-28 00:43:23 -0500116 * Two notifier lists: the "policy" list is involved in the
117 * validation process for a new CPU frequency policy; the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 * "transition" list for kernel code that needs to handle
119 * changes to devices when the CPU clock speed changes.
120 * The mutex locks both lists.
121 */
Alan Sterne041c682006-03-27 01:16:30 -0800122static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700123static struct srcu_notifier_head cpufreq_transition_notifier_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Cesar Eduardo Barros74212ca2008-02-16 08:41:24 -0200125static bool init_cpufreq_transition_notifier_list_called;
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700126static int __init init_cpufreq_transition_notifier_list(void)
127{
128 srcu_init_notifier_head(&cpufreq_transition_notifier_list);
Cesar Eduardo Barros74212ca2008-02-16 08:41:24 -0200129 init_cpufreq_transition_notifier_list_called = true;
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700130 return 0;
131}
Linus Torvaldsb3438f82006-11-20 11:47:18 -0800132pure_initcall(init_cpufreq_transition_notifier_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -0400134static int off __read_mostly;
Viresh Kumarda584452012-10-26 00:51:32 +0200135static int cpufreq_disabled(void)
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -0400136{
137 return off;
138}
139void disable_cpufreq(void)
140{
141 off = 1;
142}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static LIST_HEAD(cpufreq_governor_list);
Dave Jones29464f22009-01-18 01:37:11 -0500144static DEFINE_MUTEX(cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Stephen Boyda9144432012-07-20 18:14:38 +0000146static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 struct cpufreq_policy *data;
149 unsigned long flags;
150
Mike Travis7a6aedf2008-03-25 15:06:53 -0700151 if (cpu >= nr_cpu_ids)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 goto err_out;
153
154 /* get the cpufreq driver */
155 spin_lock_irqsave(&cpufreq_driver_lock, flags);
156
157 if (!cpufreq_driver)
158 goto err_out_unlock;
159
160 if (!try_module_get(cpufreq_driver->owner))
161 goto err_out_unlock;
162
163
164 /* get the CPU */
Mike Travis7a6aedf2008-03-25 15:06:53 -0700165 data = per_cpu(cpufreq_cpu_data, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 if (!data)
168 goto err_out_put_module;
169
Stephen Boyda9144432012-07-20 18:14:38 +0000170 if (!sysfs && !kobject_get(&data->kobj))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 goto err_out_put_module;
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return data;
175
Dave Jones7d5e3502006-02-02 17:03:42 -0500176err_out_put_module:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 module_put(cpufreq_driver->owner);
Dave Jones7d5e3502006-02-02 17:03:42 -0500178err_out_unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Dave Jones7d5e3502006-02-02 17:03:42 -0500180err_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return NULL;
182}
Stephen Boyda9144432012-07-20 18:14:38 +0000183
184struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
185{
186 return __cpufreq_cpu_get(cpu, false);
187}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
189
Stephen Boyda9144432012-07-20 18:14:38 +0000190static struct cpufreq_policy *cpufreq_cpu_get_sysfs(unsigned int cpu)
191{
192 return __cpufreq_cpu_get(cpu, true);
193}
194
195static void __cpufreq_cpu_put(struct cpufreq_policy *data, bool sysfs)
196{
197 if (!sysfs)
198 kobject_put(&data->kobj);
199 module_put(cpufreq_driver->owner);
200}
Dave Jones7d5e3502006-02-02 17:03:42 -0500201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202void cpufreq_cpu_put(struct cpufreq_policy *data)
203{
Stephen Boyda9144432012-07-20 18:14:38 +0000204 __cpufreq_cpu_put(data, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
207
Stephen Boyda9144432012-07-20 18:14:38 +0000208static void cpufreq_cpu_put_sysfs(struct cpufreq_policy *data)
209{
210 __cpufreq_cpu_put(data, true);
211}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213/*********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
215 *********************************************************************/
216
217/**
218 * adjust_jiffies - adjust the system "loops_per_jiffy"
219 *
220 * This function alters the system "loops_per_jiffy" for the clock
221 * speed change. Note that loops_per_jiffy cannot be updated on SMP
Dave Jones32ee8c32006-02-28 00:43:23 -0500222 * systems as each CPU might be scaled differently. So, use the arch
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 * per-CPU loops_per_jiffy value wherever possible.
224 */
225#ifndef CONFIG_SMP
226static unsigned long l_p_j_ref;
227static unsigned int l_p_j_ref_freq;
228
Arjan van de Ven858119e2006-01-14 13:20:43 -0800229static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
231 if (ci->flags & CPUFREQ_CONST_LOOPS)
232 return;
233
234 if (!l_p_j_ref_freq) {
235 l_p_j_ref = loops_per_jiffy;
236 l_p_j_ref_freq = ci->old;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200237 pr_debug("saving %lu as reference value for loops_per_jiffy; "
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530238 "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
Afzal Mohammedd08de0c12012-01-04 10:52:46 +0530240 if ((val == CPUFREQ_POSTCHANGE && ci->old != ci->new) ||
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -0700241 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530242 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
243 ci->new);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200244 pr_debug("scaling loops_per_jiffy to %lu "
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530245 "for frequency %u kHz\n", loops_per_jiffy, ci->new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247}
248#else
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530249static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
250{
251 return;
252}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253#endif
254
255
256/**
Dave Jonese4472cb2006-01-31 15:53:55 -0800257 * cpufreq_notify_transition - call notifier chain and adjust_jiffies
258 * on frequency transition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 *
Dave Jonese4472cb2006-01-31 15:53:55 -0800260 * This function calls the transition notifiers and the "adjust_jiffies"
261 * function. It is called twice on all CPU frequency changes that have
Dave Jones32ee8c32006-02-28 00:43:23 -0500262 * external effects.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 */
264void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
265{
Dave Jonese4472cb2006-01-31 15:53:55 -0800266 struct cpufreq_policy *policy;
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 BUG_ON(irqs_disabled());
269
270 freqs->flags = cpufreq_driver->flags;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200271 pr_debug("notification %u of frequency transition to %u kHz\n",
Dave Jonese4472cb2006-01-31 15:53:55 -0800272 state, freqs->new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Mike Travis7a6aedf2008-03-25 15:06:53 -0700274 policy = per_cpu(cpufreq_cpu_data, freqs->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 switch (state) {
Dave Jonese4472cb2006-01-31 15:53:55 -0800276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 case CPUFREQ_PRECHANGE:
Dave Jones32ee8c32006-02-28 00:43:23 -0500278 /* detect if the driver reported a value as "old frequency"
Dave Jonese4472cb2006-01-31 15:53:55 -0800279 * which is not equal to what the cpufreq core thinks is
280 * "old frequency".
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 */
282 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
Dave Jonese4472cb2006-01-31 15:53:55 -0800283 if ((policy) && (policy->cpu == freqs->cpu) &&
284 (policy->cur) && (policy->cur != freqs->old)) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200285 pr_debug("Warning: CPU frequency is"
Dave Jonese4472cb2006-01-31 15:53:55 -0800286 " %u, cpufreq assumed %u kHz.\n",
287 freqs->old, policy->cur);
288 freqs->old = policy->cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 }
290 }
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700291 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
Alan Sterne041c682006-03-27 01:16:30 -0800292 CPUFREQ_PRECHANGE, freqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
294 break;
Dave Jonese4472cb2006-01-31 15:53:55 -0800295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 case CPUFREQ_POSTCHANGE:
297 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200298 pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new,
Thomas Renninger6f4f2722010-04-20 13:17:36 +0200299 (unsigned long)freqs->cpu);
300 trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu);
Thomas Renninger25e41932011-01-03 17:50:44 +0100301 trace_cpu_frequency(freqs->new, freqs->cpu);
Alan Sternb4dfdbb2006-10-04 02:17:06 -0700302 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
Alan Sterne041c682006-03-27 01:16:30 -0800303 CPUFREQ_POSTCHANGE, freqs);
Dave Jonese4472cb2006-01-31 15:53:55 -0800304 if (likely(policy) && likely(policy->cpu == freqs->cpu))
305 policy->cur = freqs->new;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 break;
307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
309EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
310
311
312
313/*********************************************************************
314 * SYSFS INTERFACE *
315 *********************************************************************/
316
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700317static struct cpufreq_governor *__find_governor(const char *str_governor)
318{
319 struct cpufreq_governor *t;
320
321 list_for_each_entry(t, &cpufreq_governor_list, governor_list)
Dave Jones29464f22009-01-18 01:37:11 -0500322 if (!strnicmp(str_governor, t->name, CPUFREQ_NAME_LEN))
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700323 return t;
324
325 return NULL;
326}
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328/**
329 * cpufreq_parse_governor - parse a governor string
330 */
Dave Jones905d77c2008-03-05 14:28:32 -0500331static int cpufreq_parse_governor(char *str_governor, unsigned int *policy,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 struct cpufreq_governor **governor)
333{
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700334 int err = -EINVAL;
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 if (!cpufreq_driver)
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700337 goto out;
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 if (cpufreq_driver->setpolicy) {
340 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
341 *policy = CPUFREQ_POLICY_PERFORMANCE;
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700342 err = 0;
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530343 } else if (!strnicmp(str_governor, "powersave",
344 CPUFREQ_NAME_LEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 *policy = CPUFREQ_POLICY_POWERSAVE;
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700346 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700348 } else if (cpufreq_driver->target) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 struct cpufreq_governor *t;
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700350
akpm@osdl.org3fc54d32006-01-13 15:54:22 -0800351 mutex_lock(&cpufreq_governor_mutex);
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700352
353 t = __find_governor(str_governor);
354
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700355 if (t == NULL) {
Kees Cook1a8e1462011-05-04 08:38:56 -0700356 int ret;
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700357
Kees Cook1a8e1462011-05-04 08:38:56 -0700358 mutex_unlock(&cpufreq_governor_mutex);
359 ret = request_module("cpufreq_%s", str_governor);
360 mutex_lock(&cpufreq_governor_mutex);
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700361
Kees Cook1a8e1462011-05-04 08:38:56 -0700362 if (ret == 0)
363 t = __find_governor(str_governor);
Jeremy Fitzhardingeea714972006-07-06 12:32:01 -0700364 }
365
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700366 if (t != NULL) {
367 *governor = t;
368 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700370
akpm@osdl.org3fc54d32006-01-13 15:54:22 -0800371 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 }
Dave Jones29464f22009-01-18 01:37:11 -0500373out:
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -0700374 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378/**
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530379 * cpufreq_per_cpu_attr_read() / show_##file_name() -
380 * print out cpufreq information
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 *
382 * Write out information from cpufreq_driver->policy[cpu]; object must be
383 * "unsigned int".
384 */
385
Dave Jones32ee8c32006-02-28 00:43:23 -0500386#define show_one(file_name, object) \
387static ssize_t show_##file_name \
Dave Jones905d77c2008-03-05 14:28:32 -0500388(struct cpufreq_policy *policy, char *buf) \
Dave Jones32ee8c32006-02-28 00:43:23 -0500389{ \
Dave Jones29464f22009-01-18 01:37:11 -0500390 return sprintf(buf, "%u\n", policy->object); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392
393show_one(cpuinfo_min_freq, cpuinfo.min_freq);
394show_one(cpuinfo_max_freq, cpuinfo.max_freq);
Thomas Renningered129782009-02-04 01:17:41 +0100395show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396show_one(scaling_min_freq, min);
397show_one(scaling_max_freq, max);
398show_one(scaling_cur_freq, cur);
399
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530400static int __cpufreq_set_policy(struct cpufreq_policy *data,
401 struct cpufreq_policy *policy);
Thomas Renninger7970e082006-04-13 15:14:04 +0200402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403/**
404 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
405 */
406#define store_one(file_name, object) \
407static ssize_t store_##file_name \
Dave Jones905d77c2008-03-05 14:28:32 -0500408(struct cpufreq_policy *policy, const char *buf, size_t count) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{ \
Jingoo Hanf55c9c22012-10-31 05:49:13 +0000410 unsigned int ret; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 struct cpufreq_policy new_policy; \
412 \
413 ret = cpufreq_get_policy(&new_policy, policy->cpu); \
414 if (ret) \
415 return -EINVAL; \
416 \
Dave Jones29464f22009-01-18 01:37:11 -0500417 ret = sscanf(buf, "%u", &new_policy.object); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (ret != 1) \
419 return -EINVAL; \
420 \
Thomas Renninger7970e082006-04-13 15:14:04 +0200421 ret = __cpufreq_set_policy(policy, &new_policy); \
422 policy->user_policy.object = policy->object; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 \
424 return ret ? ret : count; \
425}
426
Dave Jones29464f22009-01-18 01:37:11 -0500427store_one(scaling_min_freq, min);
428store_one(scaling_max_freq, max);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430/**
431 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
432 */
Dave Jones905d77c2008-03-05 14:28:32 -0500433static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
434 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800436 unsigned int cur_freq = __cpufreq_get(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 if (!cur_freq)
438 return sprintf(buf, "<unknown>");
439 return sprintf(buf, "%u\n", cur_freq);
440}
441
442
443/**
444 * show_scaling_governor - show the current policy for the specified CPU
445 */
Dave Jones905d77c2008-03-05 14:28:32 -0500446static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Dave Jones29464f22009-01-18 01:37:11 -0500448 if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 return sprintf(buf, "powersave\n");
450 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
451 return sprintf(buf, "performance\n");
452 else if (policy->governor)
viresh kumar4b972f02012-10-23 01:23:43 +0200453 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n",
Dave Jones29464f22009-01-18 01:37:11 -0500454 policy->governor->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 return -EINVAL;
456}
457
458
459/**
460 * store_scaling_governor - store policy for the specified CPU
461 */
Dave Jones905d77c2008-03-05 14:28:32 -0500462static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
463 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Jingoo Hanf55c9c22012-10-31 05:49:13 +0000465 unsigned int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 char str_governor[16];
467 struct cpufreq_policy new_policy;
468
469 ret = cpufreq_get_policy(&new_policy, policy->cpu);
470 if (ret)
471 return ret;
472
Dave Jones29464f22009-01-18 01:37:11 -0500473 ret = sscanf(buf, "%15s", str_governor);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 if (ret != 1)
475 return -EINVAL;
476
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530477 if (cpufreq_parse_governor(str_governor, &new_policy.policy,
478 &new_policy.governor))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 return -EINVAL;
480
Thomas Renninger7970e082006-04-13 15:14:04 +0200481 /* Do not use cpufreq_set_policy here or the user_policy.max
482 will be wrongly overridden */
Thomas Renninger7970e082006-04-13 15:14:04 +0200483 ret = __cpufreq_set_policy(policy, &new_policy);
484
485 policy->user_policy.policy = policy->policy;
486 policy->user_policy.governor = policy->governor;
Thomas Renninger7970e082006-04-13 15:14:04 +0200487
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530488 if (ret)
489 return ret;
490 else
491 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
494/**
495 * show_scaling_driver - show the cpufreq driver currently loaded
496 */
Dave Jones905d77c2008-03-05 14:28:32 -0500497static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
viresh kumar4b972f02012-10-23 01:23:43 +0200499 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500}
501
502/**
503 * show_scaling_available_governors - show the available CPUfreq governors
504 */
Dave Jones905d77c2008-03-05 14:28:32 -0500505static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
506 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508 ssize_t i = 0;
509 struct cpufreq_governor *t;
510
511 if (!cpufreq_driver->target) {
512 i += sprintf(buf, "performance powersave");
513 goto out;
514 }
515
516 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
Dave Jones29464f22009-01-18 01:37:11 -0500517 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
518 - (CPUFREQ_NAME_LEN + 2)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 goto out;
viresh kumar4b972f02012-10-23 01:23:43 +0200520 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
Dave Jones7d5e3502006-02-02 17:03:42 -0500522out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 i += sprintf(&buf[i], "\n");
524 return i;
525}
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700526
Rusty Russell835481d2009-01-04 05:18:06 -0800527static ssize_t show_cpus(const struct cpumask *mask, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
529 ssize_t i = 0;
530 unsigned int cpu;
531
Rusty Russell835481d2009-01-04 05:18:06 -0800532 for_each_cpu(cpu, mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (i)
534 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
535 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
536 if (i >= (PAGE_SIZE - 5))
Dave Jones29464f22009-01-18 01:37:11 -0500537 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
539 i += sprintf(&buf[i], "\n");
540 return i;
541}
542
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700543/**
544 * show_related_cpus - show the CPUs affected by each transition even if
545 * hw coordination is in use
546 */
547static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
548{
Rusty Russell835481d2009-01-04 05:18:06 -0800549 if (cpumask_empty(policy->related_cpus))
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700550 return show_cpus(policy->cpus, buf);
551 return show_cpus(policy->related_cpus, buf);
552}
553
554/**
555 * show_affected_cpus - show the CPUs affected by each transition
556 */
557static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
558{
559 return show_cpus(policy->cpus, buf);
560}
561
Venki Pallipadi9e769882007-10-26 10:18:21 -0700562static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
Dave Jones905d77c2008-03-05 14:28:32 -0500563 const char *buf, size_t count)
Venki Pallipadi9e769882007-10-26 10:18:21 -0700564{
565 unsigned int freq = 0;
566 unsigned int ret;
567
CHIKAMA masaki879000f2008-06-05 22:46:33 -0700568 if (!policy->governor || !policy->governor->store_setspeed)
Venki Pallipadi9e769882007-10-26 10:18:21 -0700569 return -EINVAL;
570
571 ret = sscanf(buf, "%u", &freq);
572 if (ret != 1)
573 return -EINVAL;
574
575 policy->governor->store_setspeed(policy, freq);
576
577 return count;
578}
579
580static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
581{
CHIKAMA masaki879000f2008-06-05 22:46:33 -0700582 if (!policy->governor || !policy->governor->show_setspeed)
Venki Pallipadi9e769882007-10-26 10:18:21 -0700583 return sprintf(buf, "<unsupported>\n");
584
585 return policy->governor->show_setspeed(policy, buf);
586}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Thomas Renningere2f74f32009-11-19 12:31:01 +0100588/**
viresh kumar8bf1ac72012-10-23 01:23:33 +0200589 * show_bios_limit - show the current cpufreq HW/BIOS limitation
Thomas Renningere2f74f32009-11-19 12:31:01 +0100590 */
591static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
592{
593 unsigned int limit;
594 int ret;
595 if (cpufreq_driver->bios_limit) {
596 ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
597 if (!ret)
598 return sprintf(buf, "%u\n", limit);
599 }
600 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
601}
602
Borislav Petkov6dad2a22010-03-31 21:56:46 +0200603cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
604cpufreq_freq_attr_ro(cpuinfo_min_freq);
605cpufreq_freq_attr_ro(cpuinfo_max_freq);
606cpufreq_freq_attr_ro(cpuinfo_transition_latency);
607cpufreq_freq_attr_ro(scaling_available_governors);
608cpufreq_freq_attr_ro(scaling_driver);
609cpufreq_freq_attr_ro(scaling_cur_freq);
610cpufreq_freq_attr_ro(bios_limit);
611cpufreq_freq_attr_ro(related_cpus);
612cpufreq_freq_attr_ro(affected_cpus);
613cpufreq_freq_attr_rw(scaling_min_freq);
614cpufreq_freq_attr_rw(scaling_max_freq);
615cpufreq_freq_attr_rw(scaling_governor);
616cpufreq_freq_attr_rw(scaling_setspeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Dave Jones905d77c2008-03-05 14:28:32 -0500618static struct attribute *default_attrs[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 &cpuinfo_min_freq.attr,
620 &cpuinfo_max_freq.attr,
Thomas Renningered129782009-02-04 01:17:41 +0100621 &cpuinfo_transition_latency.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 &scaling_min_freq.attr,
623 &scaling_max_freq.attr,
624 &affected_cpus.attr,
Darrick J. Wonge8628dd2008-04-18 13:31:12 -0700625 &related_cpus.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 &scaling_governor.attr,
627 &scaling_driver.attr,
628 &scaling_available_governors.attr,
Venki Pallipadi9e769882007-10-26 10:18:21 -0700629 &scaling_setspeed.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 NULL
631};
632
Thomas Renninger8aa84ad2009-07-24 15:25:05 +0200633struct kobject *cpufreq_global_kobject;
634EXPORT_SYMBOL(cpufreq_global_kobject);
635
Dave Jones29464f22009-01-18 01:37:11 -0500636#define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
637#define to_attr(a) container_of(a, struct freq_attr, attr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Dave Jones29464f22009-01-18 01:37:11 -0500639static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640{
Dave Jones905d77c2008-03-05 14:28:32 -0500641 struct cpufreq_policy *policy = to_policy(kobj);
642 struct freq_attr *fattr = to_attr(attr);
Dave Jones0db4a8a2008-03-05 14:20:57 -0500643 ssize_t ret = -EINVAL;
Stephen Boyda9144432012-07-20 18:14:38 +0000644 policy = cpufreq_cpu_get_sysfs(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (!policy)
Dave Jones0db4a8a2008-03-05 14:20:57 -0500646 goto no_policy;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800647
648 if (lock_policy_rwsem_read(policy->cpu) < 0)
Dave Jones0db4a8a2008-03-05 14:20:57 -0500649 goto fail;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800650
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530651 if (fattr->show)
652 ret = fattr->show(policy, buf);
653 else
654 ret = -EIO;
655
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800656 unlock_policy_rwsem_read(policy->cpu);
Dave Jones0db4a8a2008-03-05 14:20:57 -0500657fail:
Stephen Boyda9144432012-07-20 18:14:38 +0000658 cpufreq_cpu_put_sysfs(policy);
Dave Jones0db4a8a2008-03-05 14:20:57 -0500659no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 return ret;
661}
662
Dave Jones905d77c2008-03-05 14:28:32 -0500663static ssize_t store(struct kobject *kobj, struct attribute *attr,
664 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
Dave Jones905d77c2008-03-05 14:28:32 -0500666 struct cpufreq_policy *policy = to_policy(kobj);
667 struct freq_attr *fattr = to_attr(attr);
Dave Jonesa07530b2008-03-05 14:22:25 -0500668 ssize_t ret = -EINVAL;
Stephen Boyda9144432012-07-20 18:14:38 +0000669 policy = cpufreq_cpu_get_sysfs(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 if (!policy)
Dave Jonesa07530b2008-03-05 14:22:25 -0500671 goto no_policy;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800672
673 if (lock_policy_rwsem_write(policy->cpu) < 0)
Dave Jonesa07530b2008-03-05 14:22:25 -0500674 goto fail;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800675
Gautham R Shenoye08f5f52006-10-26 16:20:58 +0530676 if (fattr->store)
677 ret = fattr->store(policy, buf, count);
678 else
679 ret = -EIO;
680
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800681 unlock_policy_rwsem_write(policy->cpu);
Dave Jonesa07530b2008-03-05 14:22:25 -0500682fail:
Stephen Boyda9144432012-07-20 18:14:38 +0000683 cpufreq_cpu_put_sysfs(policy);
Dave Jonesa07530b2008-03-05 14:22:25 -0500684no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 return ret;
686}
687
Dave Jones905d77c2008-03-05 14:28:32 -0500688static void cpufreq_sysfs_release(struct kobject *kobj)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
Dave Jones905d77c2008-03-05 14:28:32 -0500690 struct cpufreq_policy *policy = to_policy(kobj);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200691 pr_debug("last reference is dropped\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 complete(&policy->kobj_unregister);
693}
694
Emese Revfy52cf25d2010-01-19 02:58:23 +0100695static const struct sysfs_ops sysfs_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .show = show,
697 .store = store,
698};
699
700static struct kobj_type ktype_cpufreq = {
701 .sysfs_ops = &sysfs_ops,
702 .default_attrs = default_attrs,
703 .release = cpufreq_sysfs_release,
704};
705
Thomas Renninger4bfa0422009-07-24 15:25:03 +0200706/*
707 * Returns:
708 * Negative: Failure
709 * 0: Success
710 * Positive: When we have a managed CPU and the sysfs got symlinked
711 */
Alex Chiangcf3289d02009-11-17 20:27:08 -0700712static int cpufreq_add_dev_policy(unsigned int cpu,
713 struct cpufreq_policy *policy,
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800714 struct device *dev)
Dave Jonesecf7e462009-07-08 18:48:47 -0400715{
716 int ret = 0;
717#ifdef CONFIG_SMP
718 unsigned long flags;
719 unsigned int j;
Dave Jonesecf7e462009-07-08 18:48:47 -0400720#ifdef CONFIG_HOTPLUG_CPU
Dmitry Monakhove77b89f2009-10-05 00:38:55 +0400721 struct cpufreq_governor *gov;
722
723 gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu));
724 if (gov) {
725 policy->governor = gov;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200726 pr_debug("Restoring governor %s for cpu %d\n",
Dave Jonesecf7e462009-07-08 18:48:47 -0400727 policy->governor->name, cpu);
728 }
729#endif
730
731 for_each_cpu(j, policy->cpus) {
732 struct cpufreq_policy *managed_policy;
733
734 if (cpu == j)
735 continue;
736
737 /* Check for existing affected CPUs.
738 * They may not be aware of it due to CPU Hotplug.
739 * cpufreq_cpu_put is called when the device is removed
740 * in __cpufreq_remove_dev()
741 */
742 managed_policy = cpufreq_cpu_get(j);
743 if (unlikely(managed_policy)) {
744
745 /* Set proper policy_cpu */
746 unlock_policy_rwsem_write(cpu);
Tejun Heof1625062009-10-29 22:34:13 +0900747 per_cpu(cpufreq_policy_cpu, cpu) = managed_policy->cpu;
Dave Jonesecf7e462009-07-08 18:48:47 -0400748
749 if (lock_policy_rwsem_write(cpu) < 0) {
750 /* Should not go through policy unlock path */
751 if (cpufreq_driver->exit)
752 cpufreq_driver->exit(policy);
753 cpufreq_cpu_put(managed_policy);
754 return -EBUSY;
755 }
756
Viresh Kumarf6a74092013-01-12 05:14:39 +0000757 __cpufreq_governor(managed_policy, CPUFREQ_GOV_STOP);
758
Dave Jonesecf7e462009-07-08 18:48:47 -0400759 spin_lock_irqsave(&cpufreq_driver_lock, flags);
760 cpumask_copy(managed_policy->cpus, policy->cpus);
761 per_cpu(cpufreq_cpu_data, cpu) = managed_policy;
762 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
763
Viresh Kumarf6a74092013-01-12 05:14:39 +0000764 __cpufreq_governor(managed_policy, CPUFREQ_GOV_START);
765 __cpufreq_governor(managed_policy, CPUFREQ_GOV_LIMITS);
766
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200767 pr_debug("CPU already managed, adding link\n");
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800768 ret = sysfs_create_link(&dev->kobj,
Dave Jonesecf7e462009-07-08 18:48:47 -0400769 &managed_policy->kobj,
770 "cpufreq");
771 if (ret)
772 cpufreq_cpu_put(managed_policy);
773 /*
774 * Success. We only needed to be added to the mask.
775 * Call driver->exit() because only the cpu parent of
776 * the kobj needed to call init().
777 */
778 if (cpufreq_driver->exit)
779 cpufreq_driver->exit(policy);
Thomas Renninger4bfa0422009-07-24 15:25:03 +0200780
781 if (!ret)
782 return 1;
783 else
784 return ret;
Dave Jonesecf7e462009-07-08 18:48:47 -0400785 }
786 }
787#endif
788 return ret;
789}
790
791
Dave Jones19d6f7e2009-07-08 17:35:39 -0400792/* symlink affected CPUs */
Alex Chiangcf3289d02009-11-17 20:27:08 -0700793static int cpufreq_add_dev_symlink(unsigned int cpu,
794 struct cpufreq_policy *policy)
Dave Jones19d6f7e2009-07-08 17:35:39 -0400795{
796 unsigned int j;
797 int ret = 0;
798
799 for_each_cpu(j, policy->cpus) {
800 struct cpufreq_policy *managed_policy;
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800801 struct device *cpu_dev;
Dave Jones19d6f7e2009-07-08 17:35:39 -0400802
803 if (j == cpu)
804 continue;
805 if (!cpu_online(j))
806 continue;
807
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200808 pr_debug("CPU %u already managed, adding link\n", j);
Dave Jones19d6f7e2009-07-08 17:35:39 -0400809 managed_policy = cpufreq_cpu_get(cpu);
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800810 cpu_dev = get_cpu_device(j);
811 ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj,
Dave Jones19d6f7e2009-07-08 17:35:39 -0400812 "cpufreq");
813 if (ret) {
814 cpufreq_cpu_put(managed_policy);
815 return ret;
816 }
817 }
818 return ret;
819}
820
Alex Chiangcf3289d02009-11-17 20:27:08 -0700821static int cpufreq_add_dev_interface(unsigned int cpu,
822 struct cpufreq_policy *policy,
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800823 struct device *dev)
Dave Jones909a6942009-07-08 18:05:42 -0400824{
Dave Jonesecf7e462009-07-08 18:48:47 -0400825 struct cpufreq_policy new_policy;
Dave Jones909a6942009-07-08 18:05:42 -0400826 struct freq_attr **drv_attr;
827 unsigned long flags;
828 int ret = 0;
829 unsigned int j;
830
831 /* prepare interface data */
832 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800833 &dev->kobj, "cpufreq");
Dave Jones909a6942009-07-08 18:05:42 -0400834 if (ret)
835 return ret;
836
837 /* set up files for this cpu device */
838 drv_attr = cpufreq_driver->attr;
839 while ((drv_attr) && (*drv_attr)) {
840 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
841 if (ret)
842 goto err_out_kobj_put;
843 drv_attr++;
844 }
845 if (cpufreq_driver->get) {
846 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
847 if (ret)
848 goto err_out_kobj_put;
849 }
850 if (cpufreq_driver->target) {
851 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
852 if (ret)
853 goto err_out_kobj_put;
854 }
Thomas Renningere2f74f32009-11-19 12:31:01 +0100855 if (cpufreq_driver->bios_limit) {
856 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
857 if (ret)
858 goto err_out_kobj_put;
859 }
Dave Jones909a6942009-07-08 18:05:42 -0400860
861 spin_lock_irqsave(&cpufreq_driver_lock, flags);
862 for_each_cpu(j, policy->cpus) {
Julia Lawallbec037a2010-08-05 22:23:00 +0200863 if (!cpu_online(j))
864 continue;
Dave Jones909a6942009-07-08 18:05:42 -0400865 per_cpu(cpufreq_cpu_data, j) = policy;
Tejun Heof1625062009-10-29 22:34:13 +0900866 per_cpu(cpufreq_policy_cpu, j) = policy->cpu;
Dave Jones909a6942009-07-08 18:05:42 -0400867 }
868 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
869
870 ret = cpufreq_add_dev_symlink(cpu, policy);
Dave Jonesecf7e462009-07-08 18:48:47 -0400871 if (ret)
872 goto err_out_kobj_put;
873
874 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
875 /* assure that the starting sequence is run in __cpufreq_set_policy */
876 policy->governor = NULL;
877
878 /* set default policy */
879 ret = __cpufreq_set_policy(policy, &new_policy);
880 policy->user_policy.policy = policy->policy;
881 policy->user_policy.governor = policy->governor;
882
883 if (ret) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200884 pr_debug("setting policy failed\n");
Dave Jonesecf7e462009-07-08 18:48:47 -0400885 if (cpufreq_driver->exit)
886 cpufreq_driver->exit(policy);
887 }
Dave Jones909a6942009-07-08 18:05:42 -0400888 return ret;
889
890err_out_kobj_put:
891 kobject_put(&policy->kobj);
892 wait_for_completion(&policy->kobj_unregister);
893 return ret;
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897/**
898 * cpufreq_add_dev - add a CPU device
899 *
Dave Jones32ee8c32006-02-28 00:43:23 -0500900 * Adds the cpufreq interface for a CPU device.
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400901 *
902 * The Oracle says: try running cpufreq registration/unregistration concurrently
903 * with with cpu hotplugging and all hell will break loose. Tried to clean this
904 * mess up, but more thorough testing is needed. - Mathieu
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 */
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800906static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907{
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800908 unsigned int cpu = dev->id;
Prarit Bhargava90e41ba2009-11-12 09:18:46 -0500909 int ret = 0, found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 struct cpufreq_policy *policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 unsigned long flags;
912 unsigned int j;
Prarit Bhargava90e41ba2009-11-12 09:18:46 -0500913#ifdef CONFIG_HOTPLUG_CPU
914 int sibling;
915#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Ashok Rajc32b6b82005-10-30 14:59:54 -0800917 if (cpu_is_offline(cpu))
918 return 0;
919
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200920 pr_debug("adding CPU %u\n", cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922#ifdef CONFIG_SMP
923 /* check whether a different CPU already registered this
924 * CPU because it is in the same boat. */
925 policy = cpufreq_cpu_get(cpu);
926 if (unlikely(policy)) {
Dave Jones8ff69732006-03-05 03:37:23 -0500927 cpufreq_cpu_put(policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 return 0;
929 }
930#endif
931
932 if (!try_module_get(cpufreq_driver->owner)) {
933 ret = -EINVAL;
934 goto module_out;
935 }
936
Dave Jones059019a2009-07-08 16:30:03 -0400937 ret = -ENOMEM;
Dave Jonese98df502005-10-20 15:17:43 -0700938 policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL);
Dave Jones059019a2009-07-08 16:30:03 -0400939 if (!policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 goto nomem_out;
Dave Jones059019a2009-07-08 16:30:03 -0400941
942 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400943 goto err_free_policy;
Dave Jones059019a2009-07-08 16:30:03 -0400944
945 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400946 goto err_free_cpumask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
948 policy->cpu = cpu;
Rusty Russell835481d2009-01-04 05:18:06 -0800949 cpumask_copy(policy->cpus, cpumask_of(cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800951 /* Initially set CPU itself as the policy_cpu */
Tejun Heof1625062009-10-29 22:34:13 +0900952 per_cpu(cpufreq_policy_cpu, cpu) = cpu;
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400953 ret = (lock_policy_rwsem_write(cpu) < 0);
954 WARN_ON(ret);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -0800955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 init_completion(&policy->kobj_unregister);
David Howells65f27f32006-11-22 14:55:48 +0000957 INIT_WORK(&policy->update, handle_update);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Thomas Renninger8122c6c2007-10-02 13:28:09 -0700959 /* Set governor before ->init, so that driver could check it */
Prarit Bhargava90e41ba2009-11-12 09:18:46 -0500960#ifdef CONFIG_HOTPLUG_CPU
961 for_each_online_cpu(sibling) {
962 struct cpufreq_policy *cp = per_cpu(cpufreq_cpu_data, sibling);
963 if (cp && cp->governor &&
964 (cpumask_test_cpu(cpu, cp->related_cpus))) {
965 policy->governor = cp->governor;
966 found = 1;
967 break;
968 }
969 }
970#endif
971 if (!found)
972 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 /* call driver. From then on the cpufreq must be able
974 * to accept all calls to ->verify and ->setpolicy for this CPU
975 */
976 ret = cpufreq_driver->init(policy);
977 if (ret) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +0200978 pr_debug("initialization failed\n");
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -0400979 goto err_unlock_policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 }
Viresh Kumar643ae6e2013-01-12 05:14:38 +0000981
982 /*
983 * affected cpus must always be the one, which are online. We aren't
984 * managing offline cpus here.
985 */
986 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
Viresh Kumar6954ca92013-01-12 05:14:40 +0000987 cpumask_and(policy->cpus, policy->cpus, &cpufreq_online_mask);
Viresh Kumar643ae6e2013-01-12 05:14:38 +0000988
Mike Chan187d9f42008-12-04 12:19:17 -0800989 policy->user_policy.min = policy->min;
990 policy->user_policy.max = policy->max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Thomas Renningera1531ac2008-07-29 22:32:58 -0700992 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
993 CPUFREQ_START, policy);
994
Kay Sievers8a25a2f2011-12-21 14:29:42 -0800995 ret = cpufreq_add_dev_policy(cpu, policy, dev);
Thomas Renninger4bfa0422009-07-24 15:25:03 +0200996 if (ret) {
997 if (ret > 0)
998 /* This is a managed cpu, symlink created,
999 exit with 0 */
1000 ret = 0;
Dave Jonesecf7e462009-07-08 18:48:47 -04001001 goto err_unlock_policy;
Thomas Renninger4bfa0422009-07-24 15:25:03 +02001002 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001004 ret = cpufreq_add_dev_interface(cpu, policy, dev);
Dave Jones19d6f7e2009-07-08 17:35:39 -04001005 if (ret)
1006 goto err_out_unregister;
Dave Jones8ff69732006-03-05 03:37:23 -05001007
Lothar Waßmanndca02612008-05-29 17:54:52 +02001008 unlock_policy_rwsem_write(cpu);
1009
Greg Kroah-Hartman038c5b32007-12-17 15:54:39 -04001010 kobject_uevent(&policy->kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 module_put(cpufreq_driver->owner);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001012 pr_debug("initialization complete\n");
Dave Jones87c32272006-03-29 01:48:37 -05001013
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 return 0;
1015
1016
1017err_out_unregister:
1018 spin_lock_irqsave(&cpufreq_driver_lock, flags);
Rusty Russell835481d2009-01-04 05:18:06 -08001019 for_each_cpu(j, policy->cpus)
Mike Travis7a6aedf2008-03-25 15:06:53 -07001020 per_cpu(cpufreq_cpu_data, j) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1022
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -08001023 kobject_put(&policy->kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 wait_for_completion(&policy->kobj_unregister);
1025
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -04001026err_unlock_policy:
Dave Jones45709112008-03-05 14:07:34 -05001027 unlock_policy_rwsem_write(cpu);
Xiaotian Fengcad70a62010-07-20 20:11:02 +08001028 free_cpumask_var(policy->related_cpus);
Mathieu Desnoyers3f4a7822009-07-03 11:25:16 -04001029err_free_cpumask:
1030 free_cpumask_var(policy->cpus);
1031err_free_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 kfree(policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033nomem_out:
1034 module_put(cpufreq_driver->owner);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001035module_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 return ret;
1037}
1038
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001039static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1040{
1041 int j;
1042
1043 policy->last_cpu = policy->cpu;
1044 policy->cpu = cpu;
1045
1046 for_each_cpu(j, policy->cpus) {
1047 if (!cpu_online(j))
1048 continue;
1049 per_cpu(cpufreq_policy_cpu, j) = cpu;
1050 }
1051
1052#ifdef CONFIG_CPU_FREQ_TABLE
1053 cpufreq_frequency_table_update_policy_cpu(policy);
1054#endif
1055 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1056 CPUFREQ_UPDATE_POLICY_CPU, policy);
1057}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059/**
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001060 * __cpufreq_remove_dev - remove a CPU device
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 *
1062 * Removes the cpufreq interface for a CPU device.
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001063 * Caller should already have policy_rwsem in write mode for this CPU.
1064 * This routine frees the rwsem before returning.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 */
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001066static int __cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001068 unsigned int cpu = dev->id, ret, cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 unsigned long flags;
1070 struct cpufreq_policy *data;
Amerigo Wang499bca92010-03-04 03:23:46 -05001071 struct kobject *kobj;
1072 struct completion *cmp;
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001073 struct device *cpu_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001075 pr_debug("%s: unregistering CPU %u\n", __func__, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077 spin_lock_irqsave(&cpufreq_driver_lock, flags);
Mike Travis7a6aedf2008-03-25 15:06:53 -07001078 data = per_cpu(cpufreq_cpu_data, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 if (!data) {
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001081 pr_debug("%s: No cpu_data found\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001083 unlock_policy_rwsem_write(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 return -EINVAL;
1085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001087 if (cpufreq_driver->target)
Viresh Kumarf6a74092013-01-12 05:14:39 +00001088 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
Thomas Renninger084f3492007-07-09 11:35:28 -07001089
1090#ifdef CONFIG_HOTPLUG_CPU
Dmitry Monakhove77b89f2009-10-05 00:38:55 +04001091 strncpy(per_cpu(cpufreq_cpu_governor, cpu), data->governor->name,
1092 CPUFREQ_NAME_LEN);
Thomas Renninger084f3492007-07-09 11:35:28 -07001093#endif
1094
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001095 per_cpu(cpufreq_cpu_data, cpu) = NULL;
1096 cpus = cpumask_weight(data->cpus);
1097 cpumask_clear_cpu(cpu, data->cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001099 if (unlikely((cpu == data->cpu) && (cpus > 1))) {
Jacob Shin27ecddc2011-04-27 13:32:11 -05001100 /* first sibling now owns the new sysfs dir */
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001101 cpu_dev = get_cpu_device(cpumask_first(data->cpus));
1102 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1103 ret = kobject_move(&data->kobj, &cpu_dev->kobj);
1104 if (ret) {
1105 pr_err("%s: Failed to move kobj: %d", __func__, ret);
1106 cpumask_set_cpu(cpu, data->cpus);
1107 ret = sysfs_create_link(&cpu_dev->kobj, &data->kobj,
1108 "cpufreq");
1109 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1110 unlock_policy_rwsem_write(cpu);
1111 return -EINVAL;
1112 }
Jacob Shin27ecddc2011-04-27 13:32:11 -05001113
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001114 update_policy_cpu(data, cpu_dev->id);
1115 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n",
1116 __func__, cpu_dev->id, cpu);
Jacob Shin27ecddc2011-04-27 13:32:11 -05001117 }
Jacob Shin27ecddc2011-04-27 13:32:11 -05001118
Viresh Kumarb8eed8a2013-01-14 13:23:03 +00001119 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1120
1121 pr_debug("%s: removing link, cpu: %d\n", __func__, cpu);
1122 cpufreq_cpu_put(data);
1123 unlock_policy_rwsem_write(cpu);
1124 sysfs_remove_link(&dev->kobj, "cpufreq");
1125
1126 /* If cpu is last user of policy, free policy */
1127 if (cpus == 1) {
1128 lock_policy_rwsem_write(cpu);
1129 kobj = &data->kobj;
1130 cmp = &data->kobj_unregister;
1131 unlock_policy_rwsem_write(cpu);
1132 kobject_put(kobj);
1133
1134 /* we need to make sure that the underlying kobj is actually
1135 * not referenced anymore by anybody before we proceed with
1136 * unloading.
1137 */
1138 pr_debug("waiting for dropping of refcount\n");
1139 wait_for_completion(cmp);
1140 pr_debug("wait complete\n");
1141
1142 lock_policy_rwsem_write(cpu);
1143 if (cpufreq_driver->exit)
1144 cpufreq_driver->exit(data);
1145 unlock_policy_rwsem_write(cpu);
1146
1147 free_cpumask_var(data->related_cpus);
1148 free_cpumask_var(data->cpus);
1149 kfree(data);
1150 } else if (cpufreq_driver->target) {
1151 __cpufreq_governor(data, CPUFREQ_GOV_START);
1152 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS);
1153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 return 0;
1156}
1157
1158
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001159static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001160{
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001161 unsigned int cpu = dev->id;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001162 int retval;
Venki Pallipadiec282972007-03-26 12:03:19 -07001163
1164 if (cpu_is_offline(cpu))
1165 return 0;
1166
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001167 if (unlikely(lock_policy_rwsem_write(cpu)))
1168 BUG();
1169
Viresh Kumar6954ca92013-01-12 05:14:40 +00001170 cpumask_clear_cpu(cpu, &cpufreq_online_mask);
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;
Viresh Kumar72499242012-10-31 01:28:21 +01001473 unsigned int old_target_freq = target_freq;
Ashok Rajc32b6b82005-10-30 14:59:54 -08001474
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001475 if (cpufreq_disabled())
1476 return -ENODEV;
1477
Viresh Kumar72499242012-10-31 01:28:21 +01001478 /* Make sure that target_freq is within supported range */
1479 if (target_freq > policy->max)
1480 target_freq = policy->max;
1481 if (target_freq < policy->min)
1482 target_freq = policy->min;
1483
1484 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
1485 policy->cpu, target_freq, relation, old_target_freq);
Viresh Kumar5a1c0222012-10-31 01:28:15 +01001486
1487 if (target_freq == policy->cur)
1488 return 0;
1489
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 if (cpu_online(policy->cpu) && cpufreq_driver->target)
1491 retval = cpufreq_driver->target(policy, target_freq, relation);
Ashok Raj90d45d12005-11-08 21:34:24 -08001492
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 return retval;
1494}
1495EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
1496
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497int cpufreq_driver_target(struct cpufreq_policy *policy,
1498 unsigned int target_freq,
1499 unsigned int relation)
1500{
Julia Lawallf1829e42008-07-25 22:44:53 +02001501 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
1503 policy = cpufreq_cpu_get(policy->cpu);
1504 if (!policy)
Julia Lawallf1829e42008-07-25 22:44:53 +02001505 goto no_policy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001507 if (unlikely(lock_policy_rwsem_write(policy->cpu)))
Julia Lawallf1829e42008-07-25 22:44:53 +02001508 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 ret = __cpufreq_driver_target(policy, target_freq, relation);
1511
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001512 unlock_policy_rwsem_write(policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Julia Lawallf1829e42008-07-25 22:44:53 +02001514fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 cpufreq_cpu_put(policy);
Julia Lawallf1829e42008-07-25 22:44:53 +02001516no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 return ret;
1518}
1519EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1520
venkatesh.pallipadi@intel.combf0b90e2008-08-04 11:59:07 -07001521int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu)
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001522{
1523 int ret = 0;
1524
Viresh Kumar0676f7f2012-10-24 23:39:48 +02001525 if (!(cpu_online(cpu) && cpufreq_driver->getavg))
1526 return 0;
1527
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001528 policy = cpufreq_cpu_get(policy->cpu);
1529 if (!policy)
1530 return -EINVAL;
1531
Viresh Kumar0676f7f2012-10-24 23:39:48 +02001532 ret = cpufreq_driver->getavg(policy, cpu);
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001533
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001534 cpufreq_cpu_put(policy);
1535 return ret;
1536}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001537EXPORT_SYMBOL_GPL(__cpufreq_driver_getavg);
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -07001538
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001539/*
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001540 * when "event" is CPUFREQ_GOV_LIMITS
1541 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301543static int __cpufreq_governor(struct cpufreq_policy *policy,
1544 unsigned int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Dave Jonescc993ca2005-07-28 09:43:56 -07001546 int ret;
Thomas Renninger6afde102007-10-02 13:28:13 -07001547
1548 /* Only must be defined when default governor is known to have latency
1549 restrictions, like e.g. conservative or ondemand.
1550 That this is the case is already ensured in Kconfig
1551 */
1552#ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
1553 struct cpufreq_governor *gov = &cpufreq_gov_performance;
1554#else
1555 struct cpufreq_governor *gov = NULL;
1556#endif
Thomas Renninger1c256242007-10-02 13:28:12 -07001557
1558 if (policy->governor->max_transition_latency &&
1559 policy->cpuinfo.transition_latency >
1560 policy->governor->max_transition_latency) {
Thomas Renninger6afde102007-10-02 13:28:13 -07001561 if (!gov)
1562 return -EINVAL;
1563 else {
1564 printk(KERN_WARNING "%s governor failed, too long"
1565 " transition latency of HW, fallback"
1566 " to %s governor\n",
1567 policy->governor->name,
1568 gov->name);
1569 policy->governor = gov;
1570 }
Thomas Renninger1c256242007-10-02 13:28:12 -07001571 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 if (!try_module_get(policy->governor->owner))
1574 return -EINVAL;
1575
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001576 pr_debug("__cpufreq_governor for CPU %u, event %u\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301577 policy->cpu, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 ret = policy->governor->governor(policy, event);
1579
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301580 /* we keep one module reference alive for
1581 each CPU governed by this CPU */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 if ((event != CPUFREQ_GOV_START) || ret)
1583 module_put(policy->governor->owner);
1584 if ((event == CPUFREQ_GOV_STOP) && !ret)
1585 module_put(policy->governor->owner);
1586
1587 return ret;
1588}
1589
1590
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591int cpufreq_register_governor(struct cpufreq_governor *governor)
1592{
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -07001593 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
1595 if (!governor)
1596 return -EINVAL;
1597
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001598 if (cpufreq_disabled())
1599 return -ENODEV;
1600
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001601 mutex_lock(&cpufreq_governor_mutex);
Dave Jones32ee8c32006-02-28 00:43:23 -05001602
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -07001603 err = -EBUSY;
1604 if (__find_governor(governor->name) == NULL) {
1605 err = 0;
1606 list_add(&governor->governor_list, &cpufreq_governor_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Dave Jones32ee8c32006-02-28 00:43:23 -05001609 mutex_unlock(&cpufreq_governor_mutex);
Jeremy Fitzhardinge3bcb09a2006-07-06 12:30:26 -07001610 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611}
1612EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1613
1614
1615void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1616{
Prarit Bhargava90e41ba2009-11-12 09:18:46 -05001617#ifdef CONFIG_HOTPLUG_CPU
1618 int cpu;
1619#endif
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 if (!governor)
1622 return;
1623
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001624 if (cpufreq_disabled())
1625 return;
1626
Prarit Bhargava90e41ba2009-11-12 09:18:46 -05001627#ifdef CONFIG_HOTPLUG_CPU
1628 for_each_present_cpu(cpu) {
1629 if (cpu_online(cpu))
1630 continue;
1631 if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
1632 strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
1633 }
1634#endif
1635
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001636 mutex_lock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 list_del(&governor->governor_list);
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001638 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 return;
1640}
1641EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
1642
1643
1644
1645/*********************************************************************
1646 * POLICY INTERFACE *
1647 *********************************************************************/
1648
1649/**
1650 * cpufreq_get_policy - get the current cpufreq_policy
Dave Jones29464f22009-01-18 01:37:11 -05001651 * @policy: struct cpufreq_policy into which the current cpufreq_policy
1652 * is written
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 *
1654 * Reads the current cpufreq policy.
1655 */
1656int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1657{
1658 struct cpufreq_policy *cpu_policy;
1659 if (!policy)
1660 return -EINVAL;
1661
1662 cpu_policy = cpufreq_cpu_get(cpu);
1663 if (!cpu_policy)
1664 return -EINVAL;
1665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 cpufreq_cpu_put(cpu_policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 return 0;
1670}
1671EXPORT_SYMBOL(cpufreq_get_policy);
1672
1673
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001674/*
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301675 * data : current policy.
1676 * policy : policy to be set.
Arjan van de Ven153d7f32006-07-26 15:40:07 +02001677 */
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301678static int __cpufreq_set_policy(struct cpufreq_policy *data,
1679 struct cpufreq_policy *policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680{
1681 int ret = 0;
1682
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001683 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 policy->min, policy->max);
1685
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301686 memcpy(&policy->cpuinfo, &data->cpuinfo,
1687 sizeof(struct cpufreq_cpuinfo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Yi Yang53391fa2008-01-30 13:33:34 +01001689 if (policy->min > data->max || policy->max < data->min) {
Mattia Dongili9c9a43e2006-07-05 23:12:20 +02001690 ret = -EINVAL;
1691 goto error_out;
1692 }
1693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 /* verify the cpu speed can be set within this limit */
1695 ret = cpufreq_driver->verify(policy);
1696 if (ret)
1697 goto error_out;
1698
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 /* adjust if necessary - all reasons */
Alan Sterne041c682006-03-27 01:16:30 -08001700 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1701 CPUFREQ_ADJUST, policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
1703 /* adjust if necessary - hardware incompatibility*/
Alan Sterne041c682006-03-27 01:16:30 -08001704 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1705 CPUFREQ_INCOMPATIBLE, policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
1707 /* verify the cpu speed can be set within this limit,
1708 which might be different to the first one */
1709 ret = cpufreq_driver->verify(policy);
Alan Sterne041c682006-03-27 01:16:30 -08001710 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 goto error_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
1713 /* notification of the new policy */
Alan Sterne041c682006-03-27 01:16:30 -08001714 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1715 CPUFREQ_NOTIFY, policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Dave Jones7d5e3502006-02-02 17:03:42 -05001717 data->min = policy->min;
1718 data->max = policy->max;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001720 pr_debug("new min and max freqs are %u - %u kHz\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301721 data->min, data->max);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
1723 if (cpufreq_driver->setpolicy) {
1724 data->policy = policy->policy;
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001725 pr_debug("setting range\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 ret = cpufreq_driver->setpolicy(policy);
1727 } else {
1728 if (policy->governor != data->governor) {
1729 /* save old, working values */
1730 struct cpufreq_governor *old_gov = data->governor;
1731
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001732 pr_debug("governor switch\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 /* end old governor */
Andrej Gelenbergffe62752010-05-14 15:15:58 -07001735 if (data->governor)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
1737
1738 /* start new governor */
1739 data->governor = policy->governor;
1740 if (__cpufreq_governor(data, CPUFREQ_GOV_START)) {
1741 /* new governor failed, so re-start old one */
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001742 pr_debug("starting governor %s failed\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301743 data->governor->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 if (old_gov) {
1745 data->governor = old_gov;
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301746 __cpufreq_governor(data,
1747 CPUFREQ_GOV_START);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 }
1749 ret = -EINVAL;
1750 goto error_out;
1751 }
1752 /* might be a policy change, too, so fall through */
1753 }
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001754 pr_debug("governor: change or update limits\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS);
1756 }
1757
Dave Jones7d5e3502006-02-02 17:03:42 -05001758error_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return ret;
1760}
1761
1762/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
1764 * @cpu: CPU which shall be re-evaluated
1765 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001766 * Useful for policy notifiers which have different necessities
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 * at different times.
1768 */
1769int cpufreq_update_policy(unsigned int cpu)
1770{
1771 struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
1772 struct cpufreq_policy policy;
Julia Lawallf1829e42008-07-25 22:44:53 +02001773 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Julia Lawallf1829e42008-07-25 22:44:53 +02001775 if (!data) {
1776 ret = -ENODEV;
1777 goto no_policy;
1778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Julia Lawallf1829e42008-07-25 22:44:53 +02001780 if (unlikely(lock_policy_rwsem_write(cpu))) {
1781 ret = -EINVAL;
1782 goto fail;
1783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001785 pr_debug("updating policy for CPU %u\n", cpu);
Dave Jones7d5e3502006-02-02 17:03:42 -05001786 memcpy(&policy, data, sizeof(struct cpufreq_policy));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 policy.min = data->user_policy.min;
1788 policy.max = data->user_policy.max;
1789 policy.policy = data->user_policy.policy;
1790 policy.governor = data->user_policy.governor;
1791
Thomas Renninger0961dd02006-01-26 18:46:33 +01001792 /* BIOS might change freq behind our back
1793 -> ask driver for current freq and notify governors about a change */
1794 if (cpufreq_driver->get) {
1795 policy.cur = cpufreq_driver->get(cpu);
Thomas Renningera85f7bd2006-02-01 11:36:04 +01001796 if (!data->cur) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001797 pr_debug("Driver did not initialize current freq");
Thomas Renningera85f7bd2006-02-01 11:36:04 +01001798 data->cur = policy.cur;
1799 } else {
1800 if (data->cur != policy.cur)
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301801 cpufreq_out_of_sync(cpu, data->cur,
1802 policy.cur);
Thomas Renningera85f7bd2006-02-01 11:36:04 +01001803 }
Thomas Renninger0961dd02006-01-26 18:46:33 +01001804 }
1805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 ret = __cpufreq_set_policy(data, &policy);
1807
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001808 unlock_policy_rwsem_write(cpu);
1809
Julia Lawallf1829e42008-07-25 22:44:53 +02001810fail:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 cpufreq_cpu_put(data);
Julia Lawallf1829e42008-07-25 22:44:53 +02001812no_policy:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 return ret;
1814}
1815EXPORT_SYMBOL(cpufreq_update_policy);
1816
Satyam Sharmadd184a02007-10-02 13:28:14 -07001817static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
Ashok Rajc32b6b82005-10-30 14:59:54 -08001818 unsigned long action, void *hcpu)
1819{
1820 unsigned int cpu = (unsigned long)hcpu;
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001821 struct device *dev;
Ashok Rajc32b6b82005-10-30 14:59:54 -08001822
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001823 dev = get_cpu_device(cpu);
1824 if (dev) {
Ashok Rajc32b6b82005-10-30 14:59:54 -08001825 switch (action) {
1826 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001827 case CPU_ONLINE_FROZEN:
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001828 cpufreq_add_dev(dev, NULL);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001829 break;
1830 case CPU_DOWN_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001831 case CPU_DOWN_PREPARE_FROZEN:
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001832 if (unlikely(lock_policy_rwsem_write(cpu)))
1833 BUG();
1834
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001835 __cpufreq_remove_dev(dev, NULL);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001836 break;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001837 case CPU_DOWN_FAILED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -07001838 case CPU_DOWN_FAILED_FROZEN:
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001839 cpufreq_add_dev(dev, NULL);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001840 break;
1841 }
1842 }
1843 return NOTIFY_OK;
1844}
1845
Neal Buckendahl9c36f742010-06-22 22:02:44 -05001846static struct notifier_block __refdata cpufreq_cpu_notifier = {
Ashok Rajc32b6b82005-10-30 14:59:54 -08001847 .notifier_call = cpufreq_cpu_callback,
1848};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
1850/*********************************************************************
1851 * REGISTER / UNREGISTER CPUFREQ DRIVER *
1852 *********************************************************************/
1853
1854/**
1855 * cpufreq_register_driver - register a CPU Frequency driver
1856 * @driver_data: A struct cpufreq_driver containing the values#
1857 * submitted by the CPU Frequency driver.
1858 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001859 * Registers a CPU Frequency driver to this core code. This code
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 * returns zero on success, -EBUSY when another driver got here first
Dave Jones32ee8c32006-02-28 00:43:23 -05001861 * (and isn't unregistered in the meantime).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 *
1863 */
Linus Torvalds221dee22007-02-26 14:55:48 -08001864int cpufreq_register_driver(struct cpufreq_driver *driver_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865{
1866 unsigned long flags;
1867 int ret;
1868
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001869 if (cpufreq_disabled())
1870 return -ENODEV;
1871
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 if (!driver_data || !driver_data->verify || !driver_data->init ||
1873 ((!driver_data->setpolicy) && (!driver_data->target)))
1874 return -EINVAL;
1875
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001876 pr_debug("trying to register driver %s\n", driver_data->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
1878 if (driver_data->setpolicy)
1879 driver_data->flags |= CPUFREQ_CONST_LOOPS;
1880
1881 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1882 if (cpufreq_driver) {
1883 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1884 return -EBUSY;
1885 }
1886 cpufreq_driver = driver_data;
1887 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1888
Viresh Kumar6954ca92013-01-12 05:14:40 +00001889 cpumask_setall(&cpufreq_online_mask);
1890
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001891 ret = subsys_interface_register(&cpufreq_interface);
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001892 if (ret)
1893 goto err_null_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001895 if (!(cpufreq_driver->flags & CPUFREQ_STICKY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 int i;
1897 ret = -ENODEV;
1898
1899 /* check for at least one working CPU */
Mike Travis7a6aedf2008-03-25 15:06:53 -07001900 for (i = 0; i < nr_cpu_ids; i++)
1901 if (cpu_possible(i) && per_cpu(cpufreq_cpu_data, i)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 ret = 0;
Mike Travis7a6aedf2008-03-25 15:06:53 -07001903 break;
1904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
1906 /* if all ->init() calls failed, unregister */
1907 if (ret) {
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001908 pr_debug("no CPU initialized for driver %s\n",
Gautham R Shenoye08f5f52006-10-26 16:20:58 +05301909 driver_data->name);
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001910 goto err_if_unreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 }
1912 }
1913
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001914 register_hotcpu_notifier(&cpufreq_cpu_notifier);
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001915 pr_debug("driver %s up and running\n", driver_data->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001917 return 0;
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001918err_if_unreg:
1919 subsys_interface_unregister(&cpufreq_interface);
Jiri Slaby8f5bc2a2011-03-01 17:41:10 +01001920err_null_driver:
1921 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1922 cpufreq_driver = NULL;
1923 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Dave Jones4d34a672008-02-07 16:33:49 -05001924 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925}
1926EXPORT_SYMBOL_GPL(cpufreq_register_driver);
1927
1928
1929/**
1930 * cpufreq_unregister_driver - unregister the current CPUFreq driver
1931 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001932 * Unregister the current CPUFreq driver. Only call this if you have
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 * the right to do so, i.e. if you have succeeded in initialising before!
1934 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
1935 * currently not initialised.
1936 */
Linus Torvalds221dee22007-02-26 14:55:48 -08001937int cpufreq_unregister_driver(struct cpufreq_driver *driver)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938{
1939 unsigned long flags;
1940
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001941 if (!cpufreq_driver || (driver != cpufreq_driver))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Dominik Brodowski2d06d8c2011-03-27 15:04:46 +02001944 pr_debug("unregistering driver %s\n", driver->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001946 subsys_interface_unregister(&cpufreq_interface);
Chandra Seetharaman65edc682006-06-27 02:54:08 -07001947 unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1950 cpufreq_driver = NULL;
1951 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1952
1953 return 0;
1954}
1955EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001956
1957static int __init cpufreq_core_init(void)
1958{
1959 int cpu;
1960
Konrad Rzeszutek Wilka7b422c2012-03-13 19:18:39 -04001961 if (cpufreq_disabled())
1962 return -ENODEV;
1963
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001964 for_each_possible_cpu(cpu) {
Tejun Heof1625062009-10-29 22:34:13 +09001965 per_cpu(cpufreq_policy_cpu, cpu) = -1;
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001966 init_rwsem(&per_cpu(cpu_policy_rwsem, cpu));
1967 }
Thomas Renninger8aa84ad2009-07-24 15:25:05 +02001968
Kay Sievers8a25a2f2011-12-21 14:29:42 -08001969 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
Thomas Renninger8aa84ad2009-07-24 15:25:05 +02001970 BUG_ON(!cpufreq_global_kobject);
Rafael J. Wysockie00e56d2011-03-23 22:16:32 +01001971 register_syscore_ops(&cpufreq_syscore_ops);
Thomas Renninger8aa84ad2009-07-24 15:25:05 +02001972
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001973 return 0;
1974}
Venkatesh Pallipadi5a01f2e2007-02-05 16:12:44 -08001975core_initcall(cpufreq_core_init);