2 * linux/drivers/cpufreq/cpufreq.c
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 * (C) 2013 Viresh Kumar <viresh.kumar@linaro.org>
8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
9 * Added handling for CPU hotplug
10 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
11 * Fix handling for CPU hotplug -- affected CPUs
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/cpu.h>
21 #include <linux/cpufreq.h>
22 #include <linux/delay.h>
23 #include <linux/device.h>
24 #include <linux/init.h>
25 #include <linux/kernel_stat.h>
26 #include <linux/module.h>
27 #include <linux/mutex.h>
28 #include <linux/slab.h>
29 #include <linux/suspend.h>
30 #include <linux/syscore_ops.h>
31 #include <linux/tick.h>
32 #include <linux/sched.h>
33 #include <trace/events/power.h>
35 static LIST_HEAD(cpufreq_policy_list);
37 static inline bool policy_is_inactive(struct cpufreq_policy *policy)
39 return cpumask_empty(policy->cpus);
42 static bool suitable_policy(struct cpufreq_policy *policy, bool active)
44 return active == !policy_is_inactive(policy);
47 /* Finds Next Acive/Inactive policy */
48 static struct cpufreq_policy *next_policy(struct cpufreq_policy *policy,
52 policy = list_next_entry(policy, policy_list);
54 /* No more policies in the list */
55 if (&policy->policy_list == &cpufreq_policy_list)
57 } while (!suitable_policy(policy, active));
62 static struct cpufreq_policy *first_policy(bool active)
64 struct cpufreq_policy *policy;
66 /* No policies in the list */
67 if (list_empty(&cpufreq_policy_list))
70 policy = list_first_entry(&cpufreq_policy_list, typeof(*policy),
73 if (!suitable_policy(policy, active))
74 policy = next_policy(policy, active);
79 /* Macros to iterate over CPU policies */
80 #define for_each_suitable_policy(__policy, __active) \
81 for (__policy = first_policy(__active); \
83 __policy = next_policy(__policy, __active))
85 #define for_each_active_policy(__policy) \
86 for_each_suitable_policy(__policy, true)
87 #define for_each_inactive_policy(__policy) \
88 for_each_suitable_policy(__policy, false)
90 #define for_each_policy(__policy) \
91 list_for_each_entry(__policy, &cpufreq_policy_list, policy_list)
93 /* Iterate over governors */
94 static LIST_HEAD(cpufreq_governor_list);
95 #define for_each_governor(__governor) \
96 list_for_each_entry(__governor, &cpufreq_governor_list, governor_list)
99 * The "cpufreq driver" - the arch- or hardware-dependent low
100 * level driver of CPUFreq support, and its spinlock. This lock
101 * also protects the cpufreq_cpu_data array.
103 static struct cpufreq_driver *cpufreq_driver;
104 static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
105 static DEFINE_RWLOCK(cpufreq_driver_lock);
106 DEFINE_MUTEX(cpufreq_governor_lock);
108 /* Flag to suspend/resume CPUFreq governors */
109 static bool cpufreq_suspended;
111 static inline bool has_target(void)
113 return cpufreq_driver->target_index || cpufreq_driver->target;
116 /* internal prototypes */
117 static int __cpufreq_governor(struct cpufreq_policy *policy,
119 static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
120 static void handle_update(struct work_struct *work);
123 * Two notifier lists: the "policy" list is involved in the
124 * validation process for a new CPU frequency policy; the
125 * "transition" list for kernel code that needs to handle
126 * changes to devices when the CPU clock speed changes.
127 * The mutex locks both lists.
129 static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
130 static struct srcu_notifier_head cpufreq_transition_notifier_list;
132 static bool init_cpufreq_transition_notifier_list_called;
133 static int __init init_cpufreq_transition_notifier_list(void)
135 srcu_init_notifier_head(&cpufreq_transition_notifier_list);
136 init_cpufreq_transition_notifier_list_called = true;
139 pure_initcall(init_cpufreq_transition_notifier_list);
141 static int off __read_mostly;
142 static int cpufreq_disabled(void)
146 void disable_cpufreq(void)
150 static DEFINE_MUTEX(cpufreq_governor_mutex);
152 bool have_governor_per_policy(void)
154 return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY);
156 EXPORT_SYMBOL_GPL(have_governor_per_policy);
158 bool cpufreq_driver_is_slow(void)
160 return !(cpufreq_driver->flags & CPUFREQ_DRIVER_FAST);
162 EXPORT_SYMBOL_GPL(cpufreq_driver_is_slow);
164 struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy)
166 if (have_governor_per_policy())
167 return &policy->kobj;
169 return cpufreq_global_kobject;
171 EXPORT_SYMBOL_GPL(get_governor_parent_kobj);
173 struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
175 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
177 return policy && !policy_is_inactive(policy) ?
178 policy->freq_table : NULL;
180 EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
182 static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
188 cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
190 busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER];
191 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM];
192 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ];
193 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ];
194 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL];
195 busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE];
197 idle_time = cur_wall_time - busy_time;
199 *wall = cputime_to_usecs(cur_wall_time);
201 return cputime_to_usecs(idle_time);
204 u64 get_cpu_idle_time(unsigned int cpu, u64 *wall, int io_busy)
206 u64 idle_time = get_cpu_idle_time_us(cpu, io_busy ? wall : NULL);
208 if (idle_time == -1ULL)
209 return get_cpu_idle_time_jiffy(cpu, wall);
211 idle_time += get_cpu_iowait_time_us(cpu, wall);
215 EXPORT_SYMBOL_GPL(get_cpu_idle_time);
218 * This is a generic cpufreq init() routine which can be used by cpufreq
219 * drivers of SMP systems. It will do following:
220 * - validate & show freq table passed
221 * - set policies transition latency
222 * - policy->cpus with all possible CPUs
224 int cpufreq_generic_init(struct cpufreq_policy *policy,
225 struct cpufreq_frequency_table *table,
226 unsigned int transition_latency)
230 ret = cpufreq_table_validate_and_show(policy, table);
232 pr_err("%s: invalid frequency table: %d\n", __func__, ret);
236 policy->cpuinfo.transition_latency = transition_latency;
239 * The driver only supports the SMP configuration where all processors
240 * share the clock and voltage and clock.
242 cpumask_setall(policy->cpus);
246 EXPORT_SYMBOL_GPL(cpufreq_generic_init);
248 struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
250 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
252 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL;
254 EXPORT_SYMBOL_GPL(cpufreq_cpu_get_raw);
256 unsigned int cpufreq_generic_get(unsigned int cpu)
258 struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
260 if (!policy || IS_ERR(policy->clk)) {
261 pr_err("%s: No %s associated to cpu: %d\n",
262 __func__, policy ? "clk" : "policy", cpu);
266 return clk_get_rate(policy->clk) / 1000;
268 EXPORT_SYMBOL_GPL(cpufreq_generic_get);
271 * cpufreq_cpu_get: returns policy for a cpu and marks it busy.
273 * @cpu: cpu to find policy for.
275 * This returns policy for 'cpu', returns NULL if it doesn't exist.
276 * It also increments the kobject reference count to mark it busy and so would
277 * require a corresponding call to cpufreq_cpu_put() to decrement it back.
278 * If corresponding call cpufreq_cpu_put() isn't made, the policy wouldn't be
279 * freed as that depends on the kobj count.
281 * Return: A valid policy on success, otherwise NULL on failure.
283 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
285 struct cpufreq_policy *policy = NULL;
288 if (WARN_ON(cpu >= nr_cpu_ids))
291 /* get the cpufreq driver */
292 read_lock_irqsave(&cpufreq_driver_lock, flags);
294 if (cpufreq_driver) {
296 policy = cpufreq_cpu_get_raw(cpu);
298 kobject_get(&policy->kobj);
301 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
305 EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
308 * cpufreq_cpu_put: Decrements the usage count of a policy
310 * @policy: policy earlier returned by cpufreq_cpu_get().
312 * This decrements the kobject reference count incremented earlier by calling
315 void cpufreq_cpu_put(struct cpufreq_policy *policy)
317 kobject_put(&policy->kobj);
319 EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
321 /*********************************************************************
322 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
323 *********************************************************************/
326 * adjust_jiffies - adjust the system "loops_per_jiffy"
328 * This function alters the system "loops_per_jiffy" for the clock
329 * speed change. Note that loops_per_jiffy cannot be updated on SMP
330 * systems as each CPU might be scaled differently. So, use the arch
331 * per-CPU loops_per_jiffy value wherever possible.
333 static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
336 static unsigned long l_p_j_ref;
337 static unsigned int l_p_j_ref_freq;
339 if (ci->flags & CPUFREQ_CONST_LOOPS)
342 if (!l_p_j_ref_freq) {
343 l_p_j_ref = loops_per_jiffy;
344 l_p_j_ref_freq = ci->old;
345 pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n",
346 l_p_j_ref, l_p_j_ref_freq);
348 if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) {
349 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
351 pr_debug("scaling loops_per_jiffy to %lu for frequency %u kHz\n",
352 loops_per_jiffy, ci->new);
357 /*********************************************************************
358 * FREQUENCY INVARIANT CPU CAPACITY *
359 *********************************************************************/
361 static DEFINE_PER_CPU(unsigned long, freq_scale) = SCHED_CAPACITY_SCALE;
362 static DEFINE_PER_CPU(unsigned long, max_freq_scale) = SCHED_CAPACITY_SCALE;
365 scale_freq_capacity(struct cpufreq_policy *policy, struct cpufreq_freqs *freqs)
367 unsigned long cur = freqs ? freqs->new : policy->cur;
368 unsigned long scale = (cur << SCHED_CAPACITY_SHIFT) / policy->max;
369 struct cpufreq_cpuinfo *cpuinfo = &policy->cpuinfo;
372 pr_debug("cpus %*pbl cur/cur max freq %lu/%u kHz freq scale %lu\n",
373 cpumask_pr_args(policy->cpus), cur, policy->max, scale);
375 for_each_cpu(cpu, policy->cpus)
376 per_cpu(freq_scale, cpu) = scale;
381 scale = (policy->max << SCHED_CAPACITY_SHIFT) / cpuinfo->max_freq;
383 pr_debug("cpus %*pbl cur max/max freq %u/%u kHz max freq scale %lu\n",
384 cpumask_pr_args(policy->cpus), policy->max, cpuinfo->max_freq,
387 for_each_cpu(cpu, policy->cpus)
388 per_cpu(max_freq_scale, cpu) = scale;
391 unsigned long cpufreq_scale_freq_capacity(struct sched_domain *sd, int cpu)
393 return per_cpu(freq_scale, cpu);
396 unsigned long cpufreq_scale_max_freq_capacity(int cpu)
398 return per_cpu(max_freq_scale, cpu);
401 static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
402 struct cpufreq_freqs *freqs, unsigned int state)
404 BUG_ON(irqs_disabled());
406 if (cpufreq_disabled())
409 freqs->flags = cpufreq_driver->flags;
410 pr_debug("notification %u of frequency transition to %u kHz\n",
415 case CPUFREQ_PRECHANGE:
416 /* detect if the driver reported a value as "old frequency"
417 * which is not equal to what the cpufreq core thinks is
420 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
421 if ((policy) && (policy->cpu == freqs->cpu) &&
422 (policy->cur) && (policy->cur != freqs->old)) {
423 pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
424 freqs->old, policy->cur);
425 freqs->old = policy->cur;
428 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
429 CPUFREQ_PRECHANGE, freqs);
430 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
433 case CPUFREQ_POSTCHANGE:
434 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
435 pr_debug("FREQ: %lu - CPU: %lu\n",
436 (unsigned long)freqs->new, (unsigned long)freqs->cpu);
437 trace_cpu_frequency(freqs->new, freqs->cpu);
438 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
439 CPUFREQ_POSTCHANGE, freqs);
440 if (likely(policy) && likely(policy->cpu == freqs->cpu))
441 policy->cur = freqs->new;
447 * cpufreq_notify_transition - call notifier chain and adjust_jiffies
448 * on frequency transition.
450 * This function calls the transition notifiers and the "adjust_jiffies"
451 * function. It is called twice on all CPU frequency changes that have
454 static void cpufreq_notify_transition(struct cpufreq_policy *policy,
455 struct cpufreq_freqs *freqs, unsigned int state)
457 for_each_cpu(freqs->cpu, policy->cpus)
458 __cpufreq_notify_transition(policy, freqs, state);
461 /* Do post notifications when there are chances that transition has failed */
462 static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,
463 struct cpufreq_freqs *freqs, int transition_failed)
465 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
466 if (!transition_failed)
469 swap(freqs->old, freqs->new);
470 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
471 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
474 void cpufreq_freq_transition_begin(struct cpufreq_policy *policy,
475 struct cpufreq_freqs *freqs)
480 * Catch double invocations of _begin() which lead to self-deadlock.
481 * ASYNC_NOTIFICATION drivers are left out because the cpufreq core
482 * doesn't invoke _begin() on their behalf, and hence the chances of
483 * double invocations are very low. Moreover, there are scenarios
484 * where these checks can emit false-positive warnings in these
485 * drivers; so we avoid that by skipping them altogether.
487 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION)
488 && current == policy->transition_task);
491 wait_event(policy->transition_wait, !policy->transition_ongoing);
493 spin_lock(&policy->transition_lock);
495 if (unlikely(policy->transition_ongoing)) {
496 spin_unlock(&policy->transition_lock);
500 policy->transition_ongoing = true;
501 policy->transition_task = current;
503 spin_unlock(&policy->transition_lock);
505 scale_freq_capacity(policy, freqs);
506 for_each_cpu(cpu, policy->cpus)
507 trace_cpu_capacity(capacity_curr_of(cpu), cpu);
509 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
511 EXPORT_SYMBOL_GPL(cpufreq_freq_transition_begin);
513 void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
514 struct cpufreq_freqs *freqs, int transition_failed)
516 if (unlikely(WARN_ON(!policy->transition_ongoing)))
519 cpufreq_notify_post_transition(policy, freqs, transition_failed);
521 policy->transition_ongoing = false;
522 policy->transition_task = NULL;
524 wake_up(&policy->transition_wait);
526 EXPORT_SYMBOL_GPL(cpufreq_freq_transition_end);
529 /*********************************************************************
531 *********************************************************************/
532 static ssize_t show_boost(struct kobject *kobj,
533 struct attribute *attr, char *buf)
535 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
538 static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
539 const char *buf, size_t count)
543 ret = sscanf(buf, "%d", &enable);
544 if (ret != 1 || enable < 0 || enable > 1)
547 if (cpufreq_boost_trigger_state(enable)) {
548 pr_err("%s: Cannot %s BOOST!\n",
549 __func__, enable ? "enable" : "disable");
553 pr_debug("%s: cpufreq BOOST %s\n",
554 __func__, enable ? "enabled" : "disabled");
558 define_one_global_rw(boost);
560 static struct cpufreq_governor *find_governor(const char *str_governor)
562 struct cpufreq_governor *t;
565 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN))
572 * cpufreq_parse_governor - parse a governor string
574 static int cpufreq_parse_governor(char *str_governor, unsigned int *policy,
575 struct cpufreq_governor **governor)
579 if (cpufreq_driver->setpolicy) {
580 if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
581 *policy = CPUFREQ_POLICY_PERFORMANCE;
583 } else if (!strncasecmp(str_governor, "powersave",
585 *policy = CPUFREQ_POLICY_POWERSAVE;
589 struct cpufreq_governor *t;
591 mutex_lock(&cpufreq_governor_mutex);
593 t = find_governor(str_governor);
598 mutex_unlock(&cpufreq_governor_mutex);
599 ret = request_module("cpufreq_%s", str_governor);
600 mutex_lock(&cpufreq_governor_mutex);
603 t = find_governor(str_governor);
611 mutex_unlock(&cpufreq_governor_mutex);
617 * cpufreq_per_cpu_attr_read() / show_##file_name() -
618 * print out cpufreq information
620 * Write out information from cpufreq_driver->policy[cpu]; object must be
624 #define show_one(file_name, object) \
625 static ssize_t show_##file_name \
626 (struct cpufreq_policy *policy, char *buf) \
628 return sprintf(buf, "%u\n", policy->object); \
631 show_one(cpuinfo_min_freq, cpuinfo.min_freq);
632 show_one(cpuinfo_max_freq, cpuinfo.max_freq);
633 show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
634 show_one(scaling_min_freq, min);
635 show_one(scaling_max_freq, max);
637 static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf)
641 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
642 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu));
644 ret = sprintf(buf, "%u\n", policy->cur);
648 static int cpufreq_set_policy(struct cpufreq_policy *policy,
649 struct cpufreq_policy *new_policy);
652 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
654 #define store_one(file_name, object) \
655 static ssize_t store_##file_name \
656 (struct cpufreq_policy *policy, const char *buf, size_t count) \
659 struct cpufreq_policy new_policy; \
661 memcpy(&new_policy, policy, sizeof(*policy)); \
663 ret = sscanf(buf, "%u", &new_policy.object); \
667 temp = new_policy.object; \
668 ret = cpufreq_set_policy(policy, &new_policy); \
670 policy->user_policy.object = temp; \
672 return ret ? ret : count; \
675 store_one(scaling_min_freq, min);
676 store_one(scaling_max_freq, max);
679 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
681 static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
684 unsigned int cur_freq = __cpufreq_get(policy);
686 return sprintf(buf, "<unknown>");
687 return sprintf(buf, "%u\n", cur_freq);
691 * show_scaling_governor - show the current policy for the specified CPU
693 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
695 if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
696 return sprintf(buf, "powersave\n");
697 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
698 return sprintf(buf, "performance\n");
699 else if (policy->governor)
700 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n",
701 policy->governor->name);
706 * store_scaling_governor - store policy for the specified CPU
708 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
709 const char *buf, size_t count)
712 char str_governor[16];
713 struct cpufreq_policy new_policy;
715 memcpy(&new_policy, policy, sizeof(*policy));
717 ret = sscanf(buf, "%15s", str_governor);
721 if (cpufreq_parse_governor(str_governor, &new_policy.policy,
722 &new_policy.governor))
725 ret = cpufreq_set_policy(policy, &new_policy);
726 return ret ? ret : count;
730 * show_scaling_driver - show the cpufreq driver currently loaded
732 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
734 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
738 * show_scaling_available_governors - show the available CPUfreq governors
740 static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
744 struct cpufreq_governor *t;
747 i += sprintf(buf, "performance powersave");
751 for_each_governor(t) {
752 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
753 - (CPUFREQ_NAME_LEN + 2)))
755 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
758 i += sprintf(&buf[i], "\n");
762 ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf)
767 for_each_cpu(cpu, mask) {
769 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
770 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
771 if (i >= (PAGE_SIZE - 5))
774 i += sprintf(&buf[i], "\n");
777 EXPORT_SYMBOL_GPL(cpufreq_show_cpus);
780 * show_related_cpus - show the CPUs affected by each transition even if
781 * hw coordination is in use
783 static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
785 return cpufreq_show_cpus(policy->related_cpus, buf);
789 * show_affected_cpus - show the CPUs affected by each transition
791 static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
793 return cpufreq_show_cpus(policy->cpus, buf);
796 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
797 const char *buf, size_t count)
799 unsigned int freq = 0;
802 if (!policy->governor || !policy->governor->store_setspeed)
805 ret = sscanf(buf, "%u", &freq);
809 policy->governor->store_setspeed(policy, freq);
814 static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
816 if (!policy->governor || !policy->governor->show_setspeed)
817 return sprintf(buf, "<unsupported>\n");
819 return policy->governor->show_setspeed(policy, buf);
823 * show_bios_limit - show the current cpufreq HW/BIOS limitation
825 static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
829 if (cpufreq_driver->bios_limit) {
830 ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
832 return sprintf(buf, "%u\n", limit);
834 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
837 cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
838 cpufreq_freq_attr_ro(cpuinfo_min_freq);
839 cpufreq_freq_attr_ro(cpuinfo_max_freq);
840 cpufreq_freq_attr_ro(cpuinfo_transition_latency);
841 cpufreq_freq_attr_ro(scaling_available_governors);
842 cpufreq_freq_attr_ro(scaling_driver);
843 cpufreq_freq_attr_ro(scaling_cur_freq);
844 cpufreq_freq_attr_ro(bios_limit);
845 cpufreq_freq_attr_ro(related_cpus);
846 cpufreq_freq_attr_ro(affected_cpus);
847 cpufreq_freq_attr_rw(scaling_min_freq);
848 cpufreq_freq_attr_rw(scaling_max_freq);
849 cpufreq_freq_attr_rw(scaling_governor);
850 cpufreq_freq_attr_rw(scaling_setspeed);
852 static struct attribute *default_attrs[] = {
853 &cpuinfo_min_freq.attr,
854 &cpuinfo_max_freq.attr,
855 &cpuinfo_transition_latency.attr,
856 &scaling_min_freq.attr,
857 &scaling_max_freq.attr,
860 &scaling_governor.attr,
861 &scaling_driver.attr,
862 &scaling_available_governors.attr,
863 &scaling_setspeed.attr,
867 #define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
868 #define to_attr(a) container_of(a, struct freq_attr, attr)
870 static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
872 struct cpufreq_policy *policy = to_policy(kobj);
873 struct freq_attr *fattr = to_attr(attr);
876 down_read(&policy->rwsem);
879 ret = fattr->show(policy, buf);
883 up_read(&policy->rwsem);
888 static ssize_t store(struct kobject *kobj, struct attribute *attr,
889 const char *buf, size_t count)
891 struct cpufreq_policy *policy = to_policy(kobj);
892 struct freq_attr *fattr = to_attr(attr);
893 ssize_t ret = -EINVAL;
897 if (!cpu_online(policy->cpu))
900 down_write(&policy->rwsem);
903 ret = fattr->store(policy, buf, count);
907 up_write(&policy->rwsem);
914 static void cpufreq_sysfs_release(struct kobject *kobj)
916 struct cpufreq_policy *policy = to_policy(kobj);
917 pr_debug("last reference is dropped\n");
918 complete(&policy->kobj_unregister);
921 static const struct sysfs_ops sysfs_ops = {
926 static struct kobj_type ktype_cpufreq = {
927 .sysfs_ops = &sysfs_ops,
928 .default_attrs = default_attrs,
929 .release = cpufreq_sysfs_release,
932 static int add_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu)
934 struct device *cpu_dev;
936 pr_debug("%s: Adding symlink for CPU: %u\n", __func__, cpu);
941 cpu_dev = get_cpu_device(cpu);
942 if (WARN_ON(!cpu_dev))
945 return sysfs_create_link(&cpu_dev->kobj, &policy->kobj, "cpufreq");
948 static void remove_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu)
950 struct device *cpu_dev;
952 pr_debug("%s: Removing symlink for CPU: %u\n", __func__, cpu);
954 cpu_dev = get_cpu_device(cpu);
955 if (WARN_ON(!cpu_dev))
958 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
961 /* Add/remove symlinks for all related CPUs */
962 static int cpufreq_add_dev_symlink(struct cpufreq_policy *policy)
967 /* Some related CPUs might not be present (physically hotplugged) */
968 for_each_cpu(j, policy->real_cpus) {
969 ret = add_cpu_dev_symlink(policy, j);
977 static void cpufreq_remove_dev_symlink(struct cpufreq_policy *policy)
981 /* Some related CPUs might not be present (physically hotplugged) */
982 for_each_cpu(j, policy->real_cpus)
983 remove_cpu_dev_symlink(policy, j);
986 static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
988 struct freq_attr **drv_attr;
991 /* set up files for this cpu device */
992 drv_attr = cpufreq_driver->attr;
993 while (drv_attr && *drv_attr) {
994 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
999 if (cpufreq_driver->get) {
1000 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
1005 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
1009 if (cpufreq_driver->bios_limit) {
1010 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
1015 return cpufreq_add_dev_symlink(policy);
1018 static int cpufreq_init_policy(struct cpufreq_policy *policy)
1020 struct cpufreq_governor *gov = NULL;
1021 struct cpufreq_policy new_policy;
1023 memcpy(&new_policy, policy, sizeof(*policy));
1025 /* Update governor of new_policy to the governor used before hotplug */
1026 gov = find_governor(policy->last_governor);
1028 pr_debug("Restoring governor %s for cpu %d\n",
1029 policy->governor->name, policy->cpu);
1031 gov = CPUFREQ_DEFAULT_GOVERNOR;
1033 new_policy.governor = gov;
1035 /* Use the default policy if there is no last_policy. */
1036 if (cpufreq_driver->setpolicy) {
1037 if (policy->last_policy)
1038 new_policy.policy = policy->last_policy;
1040 cpufreq_parse_governor(gov->name, &new_policy.policy,
1043 /* set default policy */
1044 return cpufreq_set_policy(policy, &new_policy);
1047 static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1051 /* Has this CPU been taken care of already? */
1052 if (cpumask_test_cpu(cpu, policy->cpus))
1056 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1058 pr_err("%s: Failed to stop governor\n", __func__);
1063 down_write(&policy->rwsem);
1064 cpumask_set_cpu(cpu, policy->cpus);
1065 up_write(&policy->rwsem);
1068 ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
1070 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
1073 pr_err("%s: Failed to start governor\n", __func__);
1081 static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
1083 struct device *dev = get_cpu_device(cpu);
1084 struct cpufreq_policy *policy;
1089 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
1093 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1094 goto err_free_policy;
1096 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1097 goto err_free_cpumask;
1099 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL))
1100 goto err_free_rcpumask;
1102 kobject_init(&policy->kobj, &ktype_cpufreq);
1103 INIT_LIST_HEAD(&policy->policy_list);
1104 init_rwsem(&policy->rwsem);
1105 spin_lock_init(&policy->transition_lock);
1106 init_waitqueue_head(&policy->transition_wait);
1107 init_completion(&policy->kobj_unregister);
1108 INIT_WORK(&policy->update, handle_update);
1114 free_cpumask_var(policy->related_cpus);
1116 free_cpumask_var(policy->cpus);
1123 static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy, bool notify)
1125 struct kobject *kobj;
1126 struct completion *cmp;
1129 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1130 CPUFREQ_REMOVE_POLICY, policy);
1132 down_write(&policy->rwsem);
1133 cpufreq_remove_dev_symlink(policy);
1134 kobj = &policy->kobj;
1135 cmp = &policy->kobj_unregister;
1136 up_write(&policy->rwsem);
1140 * We need to make sure that the underlying kobj is
1141 * actually not referenced anymore by anybody before we
1142 * proceed with unloading.
1144 pr_debug("waiting for dropping of refcount\n");
1145 wait_for_completion(cmp);
1146 pr_debug("wait complete\n");
1149 static void cpufreq_policy_free(struct cpufreq_policy *policy, bool notify)
1151 unsigned long flags;
1154 /* Remove policy from list */
1155 write_lock_irqsave(&cpufreq_driver_lock, flags);
1156 list_del(&policy->policy_list);
1158 for_each_cpu(cpu, policy->related_cpus)
1159 per_cpu(cpufreq_cpu_data, cpu) = NULL;
1160 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1162 cpufreq_policy_put_kobj(policy, notify);
1163 free_cpumask_var(policy->real_cpus);
1164 free_cpumask_var(policy->related_cpus);
1165 free_cpumask_var(policy->cpus);
1169 static int cpufreq_online(unsigned int cpu)
1171 struct cpufreq_policy *policy;
1173 unsigned long flags;
1177 pr_debug("%s: bringing CPU%u online\n", __func__, cpu);
1179 /* Check if this CPU already has a policy to manage it */
1180 policy = per_cpu(cpufreq_cpu_data, cpu);
1182 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus));
1183 if (!policy_is_inactive(policy))
1184 return cpufreq_add_policy_cpu(policy, cpu);
1186 /* This is the only online CPU for the policy. Start over. */
1188 down_write(&policy->rwsem);
1190 policy->governor = NULL;
1191 up_write(&policy->rwsem);
1194 policy = cpufreq_policy_alloc(cpu);
1199 cpumask_copy(policy->cpus, cpumask_of(cpu));
1201 /* call driver. From then on the cpufreq must be able
1202 * to accept all calls to ->verify and ->setpolicy for this CPU
1204 ret = cpufreq_driver->init(policy);
1206 pr_debug("initialization failed\n");
1207 goto out_free_policy;
1210 down_write(&policy->rwsem);
1213 /* related_cpus should at least include policy->cpus. */
1214 cpumask_copy(policy->related_cpus, policy->cpus);
1215 /* Remember CPUs present at the policy creation time. */
1216 cpumask_and(policy->real_cpus, policy->cpus, cpu_present_mask);
1218 /* Name and add the kobject */
1219 ret = kobject_add(&policy->kobj, cpufreq_global_kobject,
1221 cpumask_first(policy->related_cpus));
1223 pr_err("%s: failed to add policy->kobj: %d\n", __func__,
1225 goto out_exit_policy;
1230 * affected cpus must always be the one, which are online. We aren't
1231 * managing offline cpus here.
1233 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1236 policy->user_policy.min = policy->min;
1237 policy->user_policy.max = policy->max;
1239 write_lock_irqsave(&cpufreq_driver_lock, flags);
1240 for_each_cpu(j, policy->related_cpus)
1241 per_cpu(cpufreq_cpu_data, j) = policy;
1242 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1245 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
1246 policy->cur = cpufreq_driver->get(policy->cpu);
1248 pr_err("%s: ->get() failed\n", __func__);
1249 goto out_exit_policy;
1254 * Sometimes boot loaders set CPU frequency to a value outside of
1255 * frequency table present with cpufreq core. In such cases CPU might be
1256 * unstable if it has to run on that frequency for long duration of time
1257 * and so its better to set it to a frequency which is specified in
1258 * freq-table. This also makes cpufreq stats inconsistent as
1259 * cpufreq-stats would fail to register because current frequency of CPU
1260 * isn't found in freq-table.
1262 * Because we don't want this change to effect boot process badly, we go
1263 * for the next freq which is >= policy->cur ('cur' must be set by now,
1264 * otherwise we will end up setting freq to lowest of the table as 'cur'
1265 * is initialized to zero).
1267 * We are passing target-freq as "policy->cur - 1" otherwise
1268 * __cpufreq_driver_target() would simply fail, as policy->cur will be
1269 * equal to target-freq.
1271 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK)
1273 /* Are we running at unknown frequency ? */
1274 ret = cpufreq_frequency_table_get_index(policy, policy->cur);
1275 if (ret == -EINVAL) {
1276 /* Warn user and fix it */
1277 pr_warn("%s: CPU%d: Running at unlisted freq: %u KHz\n",
1278 __func__, policy->cpu, policy->cur);
1279 ret = __cpufreq_driver_target(policy, policy->cur - 1,
1280 CPUFREQ_RELATION_L);
1283 * Reaching here after boot in a few seconds may not
1284 * mean that system will remain stable at "unknown"
1285 * frequency for longer duration. Hence, a BUG_ON().
1288 pr_warn("%s: CPU%d: Unlisted initial frequency changed to: %u KHz\n",
1289 __func__, policy->cpu, policy->cur);
1293 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1294 CPUFREQ_START, policy);
1297 ret = cpufreq_add_dev_interface(policy);
1299 goto out_exit_policy;
1300 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1301 CPUFREQ_CREATE_POLICY, policy);
1303 write_lock_irqsave(&cpufreq_driver_lock, flags);
1304 list_add(&policy->policy_list, &cpufreq_policy_list);
1305 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1308 ret = cpufreq_init_policy(policy);
1310 pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
1311 __func__, cpu, ret);
1312 /* cpufreq_policy_free() will notify based on this */
1314 goto out_exit_policy;
1317 up_write(&policy->rwsem);
1319 kobject_uevent(&policy->kobj, KOBJ_ADD);
1321 /* Callback for handling stuff after policy is ready */
1322 if (cpufreq_driver->ready)
1323 cpufreq_driver->ready(policy);
1325 pr_debug("initialization complete\n");
1330 up_write(&policy->rwsem);
1332 if (cpufreq_driver->exit)
1333 cpufreq_driver->exit(policy);
1335 cpufreq_policy_free(policy, !new_policy);
1340 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1342 * @sif: Subsystem interface structure pointer (not used)
1344 static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1346 unsigned cpu = dev->id;
1349 dev_dbg(dev, "%s: adding CPU%u\n", __func__, cpu);
1351 if (cpu_online(cpu)) {
1352 ret = cpufreq_online(cpu);
1355 * A hotplug notifier will follow and we will handle it as CPU
1356 * online then. For now, just create the sysfs link, unless
1357 * there is no policy or the link is already present.
1359 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1361 ret = policy && !cpumask_test_and_set_cpu(cpu, policy->real_cpus)
1362 ? add_cpu_dev_symlink(policy, cpu) : 0;
1368 static void cpufreq_offline_prepare(unsigned int cpu)
1370 struct cpufreq_policy *policy;
1372 pr_debug("%s: unregistering CPU %u\n", __func__, cpu);
1374 policy = cpufreq_cpu_get_raw(cpu);
1376 pr_debug("%s: No cpu_data found\n", __func__);
1381 int ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
1383 pr_err("%s: Failed to stop governor\n", __func__);
1386 down_write(&policy->rwsem);
1387 cpumask_clear_cpu(cpu, policy->cpus);
1389 if (policy_is_inactive(policy)) {
1391 strncpy(policy->last_governor, policy->governor->name,
1394 policy->last_policy = policy->policy;
1395 } else if (cpu == policy->cpu) {
1396 /* Nominate new CPU */
1397 policy->cpu = cpumask_any(policy->cpus);
1399 up_write(&policy->rwsem);
1401 /* Start governor again for active policy */
1402 if (!policy_is_inactive(policy)) {
1404 int ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
1406 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
1409 pr_err("%s: Failed to start governor\n", __func__);
1411 } else if (cpufreq_driver->stop_cpu) {
1412 cpufreq_driver->stop_cpu(policy);
1416 static void cpufreq_offline_finish(unsigned int cpu)
1418 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1421 pr_debug("%s: No cpu_data found\n", __func__);
1425 /* Only proceed for inactive policies */
1426 if (!policy_is_inactive(policy))
1429 /* If cpu is last user of policy, free policy */
1431 int ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
1433 pr_err("%s: Failed to exit governor\n", __func__);
1437 * Perform the ->exit() even during light-weight tear-down,
1438 * since this is a core component, and is essential for the
1439 * subsequent light-weight ->init() to succeed.
1441 if (cpufreq_driver->exit) {
1442 cpufreq_driver->exit(policy);
1443 policy->freq_table = NULL;
1448 * cpufreq_remove_dev - remove a CPU device
1450 * Removes the cpufreq interface for a CPU device.
1452 static void cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1454 unsigned int cpu = dev->id;
1455 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1460 if (cpu_online(cpu)) {
1461 cpufreq_offline_prepare(cpu);
1462 cpufreq_offline_finish(cpu);
1465 cpumask_clear_cpu(cpu, policy->real_cpus);
1466 remove_cpu_dev_symlink(policy, cpu);
1468 if (cpumask_empty(policy->real_cpus))
1469 cpufreq_policy_free(policy, true);
1472 static void handle_update(struct work_struct *work)
1474 struct cpufreq_policy *policy =
1475 container_of(work, struct cpufreq_policy, update);
1476 unsigned int cpu = policy->cpu;
1477 pr_debug("handle_update for cpu %u called\n", cpu);
1478 cpufreq_update_policy(cpu);
1482 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
1484 * @policy: policy managing CPUs
1485 * @new_freq: CPU frequency the CPU actually runs at
1487 * We adjust to current frequency first, and need to clean up later.
1488 * So either call to cpufreq_update_policy() or schedule handle_update()).
1490 static void cpufreq_out_of_sync(struct cpufreq_policy *policy,
1491 unsigned int new_freq)
1493 struct cpufreq_freqs freqs;
1495 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing core thinks of %u, is %u kHz\n",
1496 policy->cur, new_freq);
1498 freqs.old = policy->cur;
1499 freqs.new = new_freq;
1501 cpufreq_freq_transition_begin(policy, &freqs);
1502 cpufreq_freq_transition_end(policy, &freqs, 0);
1506 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1509 * This is the last known freq, without actually getting it from the driver.
1510 * Return value will be same as what is shown in scaling_cur_freq in sysfs.
1512 unsigned int cpufreq_quick_get(unsigned int cpu)
1514 struct cpufreq_policy *policy;
1515 unsigned int ret_freq = 0;
1517 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get)
1518 return cpufreq_driver->get(cpu);
1520 policy = cpufreq_cpu_get(cpu);
1522 ret_freq = policy->cur;
1523 cpufreq_cpu_put(policy);
1528 EXPORT_SYMBOL(cpufreq_quick_get);
1531 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1534 * Just return the max possible frequency for a given CPU.
1536 unsigned int cpufreq_quick_get_max(unsigned int cpu)
1538 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1539 unsigned int ret_freq = 0;
1542 ret_freq = policy->max;
1543 cpufreq_cpu_put(policy);
1548 EXPORT_SYMBOL(cpufreq_quick_get_max);
1550 static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
1552 unsigned int ret_freq = 0;
1554 if (!cpufreq_driver->get)
1557 ret_freq = cpufreq_driver->get(policy->cpu);
1559 /* Updating inactive policies is invalid, so avoid doing that. */
1560 if (unlikely(policy_is_inactive(policy)))
1563 if (ret_freq && policy->cur &&
1564 !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
1565 /* verify no discrepancy between actual and
1566 saved value exists */
1567 if (unlikely(ret_freq != policy->cur)) {
1568 cpufreq_out_of_sync(policy, ret_freq);
1569 schedule_work(&policy->update);
1577 * cpufreq_get - get the current CPU frequency (in kHz)
1580 * Get the CPU current (static) CPU frequency
1582 unsigned int cpufreq_get(unsigned int cpu)
1584 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1585 unsigned int ret_freq = 0;
1588 down_read(&policy->rwsem);
1589 ret_freq = __cpufreq_get(policy);
1590 up_read(&policy->rwsem);
1592 cpufreq_cpu_put(policy);
1597 EXPORT_SYMBOL(cpufreq_get);
1599 static struct subsys_interface cpufreq_interface = {
1601 .subsys = &cpu_subsys,
1602 .add_dev = cpufreq_add_dev,
1603 .remove_dev = cpufreq_remove_dev,
1607 * In case platform wants some specific frequency to be configured
1610 int cpufreq_generic_suspend(struct cpufreq_policy *policy)
1614 if (!policy->suspend_freq) {
1615 pr_debug("%s: suspend_freq not defined\n", __func__);
1619 pr_debug("%s: Setting suspend-freq: %u\n", __func__,
1620 policy->suspend_freq);
1622 ret = __cpufreq_driver_target(policy, policy->suspend_freq,
1623 CPUFREQ_RELATION_H);
1625 pr_err("%s: unable to set suspend-freq: %u. err: %d\n",
1626 __func__, policy->suspend_freq, ret);
1630 EXPORT_SYMBOL(cpufreq_generic_suspend);
1633 * cpufreq_suspend() - Suspend CPUFreq governors
1635 * Called during system wide Suspend/Hibernate cycles for suspending governors
1636 * as some platforms can't change frequency after this point in suspend cycle.
1637 * Because some of the devices (like: i2c, regulators, etc) they use for
1638 * changing frequency are suspended quickly after this point.
1640 void cpufreq_suspend(void)
1642 struct cpufreq_policy *policy;
1644 if (!cpufreq_driver)
1650 pr_debug("%s: Suspending Governors\n", __func__);
1652 for_each_active_policy(policy) {
1653 if (__cpufreq_governor(policy, CPUFREQ_GOV_STOP))
1654 pr_err("%s: Failed to stop governor for policy: %p\n",
1656 else if (cpufreq_driver->suspend
1657 && cpufreq_driver->suspend(policy))
1658 pr_err("%s: Failed to suspend driver: %p\n", __func__,
1663 cpufreq_suspended = true;
1667 * cpufreq_resume() - Resume CPUFreq governors
1669 * Called during system wide Suspend/Hibernate cycle for resuming governors that
1670 * are suspended with cpufreq_suspend().
1672 void cpufreq_resume(void)
1674 struct cpufreq_policy *policy;
1676 if (!cpufreq_driver)
1679 cpufreq_suspended = false;
1684 pr_debug("%s: Resuming Governors\n", __func__);
1686 for_each_active_policy(policy) {
1687 if (cpufreq_driver->resume && cpufreq_driver->resume(policy))
1688 pr_err("%s: Failed to resume driver: %p\n", __func__,
1690 else if (__cpufreq_governor(policy, CPUFREQ_GOV_START)
1691 || __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))
1692 pr_err("%s: Failed to start governor for policy: %p\n",
1697 * schedule call cpufreq_update_policy() for first-online CPU, as that
1698 * wouldn't be hotplugged-out on suspend. It will verify that the
1699 * current freq is in sync with what we believe it to be.
1701 policy = cpufreq_cpu_get_raw(cpumask_first(cpu_online_mask));
1702 if (WARN_ON(!policy))
1705 schedule_work(&policy->update);
1709 * cpufreq_get_current_driver - return current driver's name
1711 * Return the name string of the currently loaded cpufreq driver
1714 const char *cpufreq_get_current_driver(void)
1717 return cpufreq_driver->name;
1721 EXPORT_SYMBOL_GPL(cpufreq_get_current_driver);
1724 * cpufreq_get_driver_data - return current driver data
1726 * Return the private data of the currently loaded cpufreq
1727 * driver, or NULL if no cpufreq driver is loaded.
1729 void *cpufreq_get_driver_data(void)
1732 return cpufreq_driver->driver_data;
1736 EXPORT_SYMBOL_GPL(cpufreq_get_driver_data);
1738 /*********************************************************************
1739 * NOTIFIER LISTS INTERFACE *
1740 *********************************************************************/
1743 * cpufreq_register_notifier - register a driver with cpufreq
1744 * @nb: notifier function to register
1745 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1747 * Add a driver to one of two lists: either a list of drivers that
1748 * are notified about clock rate changes (once before and once after
1749 * the transition), or a list of drivers that are notified about
1750 * changes in cpufreq policy.
1752 * This function may sleep, and has the same return conditions as
1753 * blocking_notifier_chain_register.
1755 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1759 if (cpufreq_disabled())
1762 WARN_ON(!init_cpufreq_transition_notifier_list_called);
1765 case CPUFREQ_TRANSITION_NOTIFIER:
1766 ret = srcu_notifier_chain_register(
1767 &cpufreq_transition_notifier_list, nb);
1769 case CPUFREQ_POLICY_NOTIFIER:
1770 ret = blocking_notifier_chain_register(
1771 &cpufreq_policy_notifier_list, nb);
1779 EXPORT_SYMBOL(cpufreq_register_notifier);
1782 * cpufreq_unregister_notifier - unregister a driver with cpufreq
1783 * @nb: notifier block to be unregistered
1784 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1786 * Remove a driver from the CPU frequency notifier list.
1788 * This function may sleep, and has the same return conditions as
1789 * blocking_notifier_chain_unregister.
1791 int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list)
1795 if (cpufreq_disabled())
1799 case CPUFREQ_TRANSITION_NOTIFIER:
1800 ret = srcu_notifier_chain_unregister(
1801 &cpufreq_transition_notifier_list, nb);
1803 case CPUFREQ_POLICY_NOTIFIER:
1804 ret = blocking_notifier_chain_unregister(
1805 &cpufreq_policy_notifier_list, nb);
1813 EXPORT_SYMBOL(cpufreq_unregister_notifier);
1816 /*********************************************************************
1818 *********************************************************************/
1820 /* Must set freqs->new to intermediate frequency */
1821 static int __target_intermediate(struct cpufreq_policy *policy,
1822 struct cpufreq_freqs *freqs, int index)
1826 freqs->new = cpufreq_driver->get_intermediate(policy, index);
1828 /* We don't need to switch to intermediate freq */
1832 pr_debug("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n",
1833 __func__, policy->cpu, freqs->old, freqs->new);
1835 cpufreq_freq_transition_begin(policy, freqs);
1836 ret = cpufreq_driver->target_intermediate(policy, index);
1837 cpufreq_freq_transition_end(policy, freqs, ret);
1840 pr_err("%s: Failed to change to intermediate frequency: %d\n",
1846 static int __target_index(struct cpufreq_policy *policy,
1847 struct cpufreq_frequency_table *freq_table, int index)
1849 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0};
1850 unsigned int intermediate_freq = 0;
1851 int retval = -EINVAL;
1854 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION);
1856 /* Handle switching to intermediate frequency */
1857 if (cpufreq_driver->get_intermediate) {
1858 retval = __target_intermediate(policy, &freqs, index);
1862 intermediate_freq = freqs.new;
1863 /* Set old freq to intermediate */
1864 if (intermediate_freq)
1865 freqs.old = freqs.new;
1868 freqs.new = freq_table[index].frequency;
1869 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
1870 __func__, policy->cpu, freqs.old, freqs.new);
1872 cpufreq_freq_transition_begin(policy, &freqs);
1875 retval = cpufreq_driver->target_index(policy, index);
1877 pr_err("%s: Failed to change cpu frequency: %d\n", __func__,
1881 cpufreq_freq_transition_end(policy, &freqs, retval);
1884 * Failed after setting to intermediate freq? Driver should have
1885 * reverted back to initial frequency and so should we. Check
1886 * here for intermediate_freq instead of get_intermediate, in
1887 * case we haven't switched to intermediate freq at all.
1889 if (unlikely(retval && intermediate_freq)) {
1890 freqs.old = intermediate_freq;
1891 freqs.new = policy->restore_freq;
1892 cpufreq_freq_transition_begin(policy, &freqs);
1893 cpufreq_freq_transition_end(policy, &freqs, 0);
1900 int __cpufreq_driver_target(struct cpufreq_policy *policy,
1901 unsigned int target_freq,
1902 unsigned int relation)
1904 unsigned int old_target_freq = target_freq;
1905 int retval = -EINVAL;
1907 if (cpufreq_disabled())
1910 /* Make sure that target_freq is within supported range */
1911 if (target_freq > policy->max)
1912 target_freq = policy->max;
1913 if (target_freq < policy->min)
1914 target_freq = policy->min;
1916 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
1917 policy->cpu, target_freq, relation, old_target_freq);
1920 * This might look like a redundant call as we are checking it again
1921 * after finding index. But it is left intentionally for cases where
1922 * exactly same freq is called again and so we can save on few function
1925 if (target_freq == policy->cur)
1928 /* Save last value to restore later on errors */
1929 policy->restore_freq = policy->cur;
1931 if (cpufreq_driver->target)
1932 retval = cpufreq_driver->target(policy, target_freq, relation);
1933 else if (cpufreq_driver->target_index) {
1934 struct cpufreq_frequency_table *freq_table;
1937 freq_table = cpufreq_frequency_get_table(policy->cpu);
1938 if (unlikely(!freq_table)) {
1939 pr_err("%s: Unable to find freq_table\n", __func__);
1943 retval = cpufreq_frequency_table_target(policy, freq_table,
1944 target_freq, relation, &index);
1945 if (unlikely(retval)) {
1946 pr_err("%s: Unable to find matching freq\n", __func__);
1950 if (freq_table[index].frequency == policy->cur) {
1955 retval = __target_index(policy, freq_table, index);
1961 EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
1963 int cpufreq_driver_target(struct cpufreq_policy *policy,
1964 unsigned int target_freq,
1965 unsigned int relation)
1969 down_write(&policy->rwsem);
1971 ret = __cpufreq_driver_target(policy, target_freq, relation);
1973 up_write(&policy->rwsem);
1977 EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1979 static int __cpufreq_governor(struct cpufreq_policy *policy,
1984 /* Only must be defined when default governor is known to have latency
1985 restrictions, like e.g. conservative or ondemand.
1986 That this is the case is already ensured in Kconfig
1988 #ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE
1989 struct cpufreq_governor *gov = &cpufreq_gov_performance;
1991 struct cpufreq_governor *gov = NULL;
1994 /* Don't start any governor operations if we are entering suspend */
1995 if (cpufreq_suspended)
1998 * Governor might not be initiated here if ACPI _PPC changed
1999 * notification happened, so check it.
2001 if (!policy->governor)
2004 if (policy->governor->max_transition_latency &&
2005 policy->cpuinfo.transition_latency >
2006 policy->governor->max_transition_latency) {
2010 pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
2011 policy->governor->name, gov->name);
2012 policy->governor = gov;
2016 if (event == CPUFREQ_GOV_POLICY_INIT)
2017 if (!try_module_get(policy->governor->owner))
2020 pr_debug("%s: for CPU %u, event %u\n", __func__, policy->cpu, event);
2022 mutex_lock(&cpufreq_governor_lock);
2023 if ((policy->governor_enabled && event == CPUFREQ_GOV_START)
2024 || (!policy->governor_enabled
2025 && (event == CPUFREQ_GOV_LIMITS || event == CPUFREQ_GOV_STOP))) {
2026 mutex_unlock(&cpufreq_governor_lock);
2030 if (event == CPUFREQ_GOV_STOP)
2031 policy->governor_enabled = false;
2032 else if (event == CPUFREQ_GOV_START)
2033 policy->governor_enabled = true;
2035 mutex_unlock(&cpufreq_governor_lock);
2037 ret = policy->governor->governor(policy, event);
2040 if (event == CPUFREQ_GOV_POLICY_INIT)
2041 policy->governor->initialized++;
2042 else if (event == CPUFREQ_GOV_POLICY_EXIT)
2043 policy->governor->initialized--;
2045 /* Restore original values */
2046 mutex_lock(&cpufreq_governor_lock);
2047 if (event == CPUFREQ_GOV_STOP)
2048 policy->governor_enabled = true;
2049 else if (event == CPUFREQ_GOV_START)
2050 policy->governor_enabled = false;
2051 mutex_unlock(&cpufreq_governor_lock);
2054 if (((event == CPUFREQ_GOV_POLICY_INIT) && ret) ||
2055 ((event == CPUFREQ_GOV_POLICY_EXIT) && !ret))
2056 module_put(policy->governor->owner);
2061 int cpufreq_register_governor(struct cpufreq_governor *governor)
2068 if (cpufreq_disabled())
2071 mutex_lock(&cpufreq_governor_mutex);
2073 governor->initialized = 0;
2075 if (!find_governor(governor->name)) {
2077 list_add(&governor->governor_list, &cpufreq_governor_list);
2080 mutex_unlock(&cpufreq_governor_mutex);
2083 EXPORT_SYMBOL_GPL(cpufreq_register_governor);
2085 void cpufreq_unregister_governor(struct cpufreq_governor *governor)
2087 struct cpufreq_policy *policy;
2088 unsigned long flags;
2093 if (cpufreq_disabled())
2096 /* clear last_governor for all inactive policies */
2097 read_lock_irqsave(&cpufreq_driver_lock, flags);
2098 for_each_inactive_policy(policy) {
2099 if (!strcmp(policy->last_governor, governor->name)) {
2100 policy->governor = NULL;
2101 strcpy(policy->last_governor, "\0");
2104 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
2106 mutex_lock(&cpufreq_governor_mutex);
2107 list_del(&governor->governor_list);
2108 mutex_unlock(&cpufreq_governor_mutex);
2111 EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
2114 /*********************************************************************
2115 * POLICY INTERFACE *
2116 *********************************************************************/
2119 * cpufreq_get_policy - get the current cpufreq_policy
2120 * @policy: struct cpufreq_policy into which the current cpufreq_policy
2123 * Reads the current cpufreq policy.
2125 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
2127 struct cpufreq_policy *cpu_policy;
2131 cpu_policy = cpufreq_cpu_get(cpu);
2135 memcpy(policy, cpu_policy, sizeof(*policy));
2137 cpufreq_cpu_put(cpu_policy);
2140 EXPORT_SYMBOL(cpufreq_get_policy);
2143 * policy : current policy.
2144 * new_policy: policy to be set.
2146 static int cpufreq_set_policy(struct cpufreq_policy *policy,
2147 struct cpufreq_policy *new_policy)
2149 struct cpufreq_governor *old_gov;
2152 pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
2153 new_policy->cpu, new_policy->min, new_policy->max);
2155 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
2158 * This check works well when we store new min/max freq attributes,
2159 * because new_policy is a copy of policy with one field updated.
2161 if (new_policy->min > new_policy->max)
2164 /* verify the cpu speed can be set within this limit */
2165 ret = cpufreq_driver->verify(new_policy);
2169 /* adjust if necessary - all reasons */
2170 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
2171 CPUFREQ_ADJUST, new_policy);
2174 * verify the cpu speed can be set within this limit, which might be
2175 * different to the first one
2177 ret = cpufreq_driver->verify(new_policy);
2181 /* notification of the new policy */
2182 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
2183 CPUFREQ_NOTIFY, new_policy);
2185 scale_freq_capacity(new_policy, NULL);
2187 policy->min = new_policy->min;
2188 policy->max = new_policy->max;
2189 trace_cpu_frequency_limits(policy->max, policy->min, policy->cpu);
2191 pr_debug("new min and max freqs are %u - %u kHz\n",
2192 policy->min, policy->max);
2194 if (cpufreq_driver->setpolicy) {
2195 policy->policy = new_policy->policy;
2196 pr_debug("setting range\n");
2197 return cpufreq_driver->setpolicy(new_policy);
2200 if (new_policy->governor == policy->governor)
2203 pr_debug("governor switch\n");
2205 /* save old, working values */
2206 old_gov = policy->governor;
2207 /* end old governor */
2209 ret = __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
2211 /* This can happen due to race with other operations */
2212 pr_debug("%s: Failed to Stop Governor: %s (%d)\n",
2213 __func__, old_gov->name, ret);
2217 up_write(&policy->rwsem);
2218 ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
2219 down_write(&policy->rwsem);
2222 pr_err("%s: Failed to Exit Governor: %s (%d)\n",
2223 __func__, old_gov->name, ret);
2228 /* start new governor */
2229 policy->governor = new_policy->governor;
2230 ret = __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT);
2232 ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
2236 up_write(&policy->rwsem);
2237 __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
2238 down_write(&policy->rwsem);
2241 /* new governor failed, so re-start old one */
2242 pr_debug("starting governor %s failed\n", policy->governor->name);
2244 policy->governor = old_gov;
2245 if (__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT))
2246 policy->governor = NULL;
2248 __cpufreq_governor(policy, CPUFREQ_GOV_START);
2254 pr_debug("governor: change or update limits\n");
2255 return __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2259 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
2260 * @cpu: CPU which shall be re-evaluated
2262 * Useful for policy notifiers which have different necessities
2263 * at different times.
2265 int cpufreq_update_policy(unsigned int cpu)
2267 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
2268 struct cpufreq_policy new_policy;
2274 down_write(&policy->rwsem);
2276 pr_debug("updating policy for CPU %u\n", cpu);
2277 memcpy(&new_policy, policy, sizeof(*policy));
2278 new_policy.min = policy->user_policy.min;
2279 new_policy.max = policy->user_policy.max;
2282 * BIOS might change freq behind our back
2283 * -> ask driver for current freq and notify governors about a change
2285 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2286 new_policy.cur = cpufreq_driver->get(cpu);
2287 if (WARN_ON(!new_policy.cur)) {
2293 pr_debug("Driver did not initialize current freq\n");
2294 policy->cur = new_policy.cur;
2296 if (policy->cur != new_policy.cur && has_target())
2297 cpufreq_out_of_sync(policy, new_policy.cur);
2301 ret = cpufreq_set_policy(policy, &new_policy);
2304 up_write(&policy->rwsem);
2306 cpufreq_cpu_put(policy);
2309 EXPORT_SYMBOL(cpufreq_update_policy);
2311 static int cpufreq_cpu_callback(struct notifier_block *nfb,
2312 unsigned long action, void *hcpu)
2314 unsigned int cpu = (unsigned long)hcpu;
2316 switch (action & ~CPU_TASKS_FROZEN) {
2318 cpufreq_online(cpu);
2321 case CPU_DOWN_PREPARE:
2322 cpufreq_offline_prepare(cpu);
2326 cpufreq_offline_finish(cpu);
2329 case CPU_DOWN_FAILED:
2330 cpufreq_online(cpu);
2336 static struct notifier_block __refdata cpufreq_cpu_notifier = {
2337 .notifier_call = cpufreq_cpu_callback,
2340 /*********************************************************************
2342 *********************************************************************/
2343 static int cpufreq_boost_set_sw(int state)
2345 struct cpufreq_frequency_table *freq_table;
2346 struct cpufreq_policy *policy;
2349 for_each_active_policy(policy) {
2350 freq_table = cpufreq_frequency_get_table(policy->cpu);
2352 ret = cpufreq_frequency_table_cpuinfo(policy,
2355 pr_err("%s: Policy frequency update failed\n",
2359 policy->user_policy.max = policy->max;
2360 __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2367 int cpufreq_boost_trigger_state(int state)
2369 unsigned long flags;
2372 if (cpufreq_driver->boost_enabled == state)
2375 write_lock_irqsave(&cpufreq_driver_lock, flags);
2376 cpufreq_driver->boost_enabled = state;
2377 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2379 ret = cpufreq_driver->set_boost(state);
2381 write_lock_irqsave(&cpufreq_driver_lock, flags);
2382 cpufreq_driver->boost_enabled = !state;
2383 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2385 pr_err("%s: Cannot %s BOOST\n",
2386 __func__, state ? "enable" : "disable");
2392 int cpufreq_boost_supported(void)
2394 if (likely(cpufreq_driver))
2395 return cpufreq_driver->boost_supported;
2399 EXPORT_SYMBOL_GPL(cpufreq_boost_supported);
2401 static int create_boost_sysfs_file(void)
2405 if (!cpufreq_boost_supported())
2409 * Check if driver provides function to enable boost -
2410 * if not, use cpufreq_boost_set_sw as default
2412 if (!cpufreq_driver->set_boost)
2413 cpufreq_driver->set_boost = cpufreq_boost_set_sw;
2415 ret = sysfs_create_file(cpufreq_global_kobject, &boost.attr);
2417 pr_err("%s: cannot register global BOOST sysfs file\n",
2423 static void remove_boost_sysfs_file(void)
2425 if (cpufreq_boost_supported())
2426 sysfs_remove_file(cpufreq_global_kobject, &boost.attr);
2429 int cpufreq_enable_boost_support(void)
2431 if (!cpufreq_driver)
2434 if (cpufreq_boost_supported())
2437 cpufreq_driver->boost_supported = true;
2439 /* This will get removed on driver unregister */
2440 return create_boost_sysfs_file();
2442 EXPORT_SYMBOL_GPL(cpufreq_enable_boost_support);
2444 int cpufreq_boost_enabled(void)
2446 return cpufreq_driver->boost_enabled;
2448 EXPORT_SYMBOL_GPL(cpufreq_boost_enabled);
2450 /*********************************************************************
2451 * REGISTER / UNREGISTER CPUFREQ DRIVER *
2452 *********************************************************************/
2455 * cpufreq_register_driver - register a CPU Frequency driver
2456 * @driver_data: A struct cpufreq_driver containing the values#
2457 * submitted by the CPU Frequency driver.
2459 * Registers a CPU Frequency driver to this core code. This code
2460 * returns zero on success, -EBUSY when another driver got here first
2461 * (and isn't unregistered in the meantime).
2464 int cpufreq_register_driver(struct cpufreq_driver *driver_data)
2466 unsigned long flags;
2469 if (cpufreq_disabled())
2472 if (!driver_data || !driver_data->verify || !driver_data->init ||
2473 !(driver_data->setpolicy || driver_data->target_index ||
2474 driver_data->target) ||
2475 (driver_data->setpolicy && (driver_data->target_index ||
2476 driver_data->target)) ||
2477 (!!driver_data->get_intermediate != !!driver_data->target_intermediate))
2480 pr_debug("trying to register driver %s\n", driver_data->name);
2482 /* Protect against concurrent CPU online/offline. */
2485 write_lock_irqsave(&cpufreq_driver_lock, flags);
2486 if (cpufreq_driver) {
2487 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2491 cpufreq_driver = driver_data;
2492 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2494 if (driver_data->setpolicy)
2495 driver_data->flags |= CPUFREQ_CONST_LOOPS;
2497 ret = create_boost_sysfs_file();
2499 goto err_null_driver;
2501 ret = subsys_interface_register(&cpufreq_interface);
2503 goto err_boost_unreg;
2505 if (!(cpufreq_driver->flags & CPUFREQ_STICKY) &&
2506 list_empty(&cpufreq_policy_list)) {
2507 /* if all ->init() calls failed, unregister */
2508 pr_debug("%s: No CPU initialized for driver %s\n", __func__,
2513 register_hotcpu_notifier(&cpufreq_cpu_notifier);
2514 pr_debug("driver %s up and running\n", driver_data->name);
2521 subsys_interface_unregister(&cpufreq_interface);
2523 remove_boost_sysfs_file();
2525 write_lock_irqsave(&cpufreq_driver_lock, flags);
2526 cpufreq_driver = NULL;
2527 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2530 EXPORT_SYMBOL_GPL(cpufreq_register_driver);
2533 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2535 * Unregister the current CPUFreq driver. Only call this if you have
2536 * the right to do so, i.e. if you have succeeded in initialising before!
2537 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
2538 * currently not initialised.
2540 int cpufreq_unregister_driver(struct cpufreq_driver *driver)
2542 unsigned long flags;
2544 if (!cpufreq_driver || (driver != cpufreq_driver))
2547 pr_debug("unregistering driver %s\n", driver->name);
2549 /* Protect against concurrent cpu hotplug */
2551 subsys_interface_unregister(&cpufreq_interface);
2552 remove_boost_sysfs_file();
2553 unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
2555 write_lock_irqsave(&cpufreq_driver_lock, flags);
2557 cpufreq_driver = NULL;
2559 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2564 EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
2567 * Stop cpufreq at shutdown to make sure it isn't holding any locks
2568 * or mutexes when secondary CPUs are halted.
2570 static struct syscore_ops cpufreq_syscore_ops = {
2571 .shutdown = cpufreq_suspend,
2574 struct kobject *cpufreq_global_kobject;
2575 EXPORT_SYMBOL(cpufreq_global_kobject);
2577 static int __init cpufreq_core_init(void)
2579 if (cpufreq_disabled())
2582 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
2583 BUG_ON(!cpufreq_global_kobject);
2585 register_syscore_ops(&cpufreq_syscore_ops);
2589 core_initcall(cpufreq_core_init);