Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/cpufreq/cpufreq.c |
| 3 | * |
| 4 | * Copyright (C) 2001 Russell King |
| 5 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> |
| 6 | * |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 7 | * Oct 2005 - Ashok Raj <ashok.raj@intel.com> |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 8 | * Added handling for CPU hotplug |
Dave Jones | 8ff6973 | 2006-03-05 03:37:23 -0500 | [diff] [blame] | 9 | * Feb 2006 - Jacob Shin <jacob.shin@amd.com> |
| 10 | * Fix handling for CPU hotplug -- affected CPUs |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * 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 Kumar | db70115 | 2012-10-23 01:29:03 +0200 | [diff] [blame] | 18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #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.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 33 | #include <linux/syscore_ops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Thomas Renninger | 6f4f272 | 2010-04-20 13:17:36 +0200 | [diff] [blame] | 35 | #include <trace/events/power.h> |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | /** |
Dave Jones | cd87847 | 2006-08-11 17:59:28 -0400 | [diff] [blame] | 38 | * The "cpufreq driver" - the arch- or hardware-dependent low |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | * level driver of CPUFreq support, and its spinlock. This lock |
| 40 | * also protects the cpufreq_cpu_data array. |
| 41 | */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 42 | static struct cpufreq_driver __rcu *cpufreq_driver; |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 43 | static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); |
Thomas Renninger | 084f349 | 2007-07-09 11:35:28 -0700 | [diff] [blame] | 44 | #ifdef CONFIG_HOTPLUG_CPU |
| 45 | /* This one keeps track of the previously set governor of a removed CPU */ |
Dmitry Monakhov | e77b89f | 2009-10-05 00:38:55 +0400 | [diff] [blame] | 46 | static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); |
Thomas Renninger | 084f349 | 2007-07-09 11:35:28 -0700 | [diff] [blame] | 47 | #endif |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 48 | static DEFINE_RWLOCK(cpufreq_driver_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 50 | /* |
| 51 | * cpu_policy_rwsem is a per CPU reader-writer semaphore designed to cure |
| 52 | * all cpufreq/hotplug/workqueue/etc related lock issues. |
| 53 | * |
| 54 | * The rules for this semaphore: |
| 55 | * - Any routine that wants to read from the policy structure will |
| 56 | * do a down_read on this semaphore. |
| 57 | * - Any routine that will write to the policy structure and/or may take away |
| 58 | * the policy altogether (eg. CPU hotplug), will hold this lock in write |
| 59 | * mode before doing so. |
| 60 | * |
| 61 | * Additional rules: |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 62 | * - Governor routines that can be called in cpufreq hotplug path should not |
| 63 | * take this sem as top level hotplug notifier handler takes this. |
Mathieu Desnoyers | 395913d | 2009-06-08 13:17:31 -0400 | [diff] [blame] | 64 | * - Lock should not be held across |
| 65 | * __cpufreq_governor(data, CPUFREQ_GOV_STOP); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 66 | */ |
Tejun Heo | f162506 | 2009-10-29 22:34:13 +0900 | [diff] [blame] | 67 | static DEFINE_PER_CPU(int, cpufreq_policy_cpu); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 68 | static DEFINE_PER_CPU(struct rw_semaphore, cpu_policy_rwsem); |
| 69 | |
| 70 | #define lock_policy_rwsem(mode, cpu) \ |
Viresh Kumar | fa1d8af | 2013-02-07 15:38:42 +0530 | [diff] [blame] | 71 | static int lock_policy_rwsem_##mode(int cpu) \ |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 72 | { \ |
Tejun Heo | f162506 | 2009-10-29 22:34:13 +0900 | [diff] [blame] | 73 | int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \ |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 74 | BUG_ON(policy_cpu == -1); \ |
| 75 | down_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \ |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 76 | \ |
| 77 | return 0; \ |
| 78 | } |
| 79 | |
| 80 | lock_policy_rwsem(read, cpu); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 81 | lock_policy_rwsem(write, cpu); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 82 | |
Viresh Kumar | fa1d8af | 2013-02-07 15:38:42 +0530 | [diff] [blame] | 83 | #define unlock_policy_rwsem(mode, cpu) \ |
| 84 | static void unlock_policy_rwsem_##mode(int cpu) \ |
| 85 | { \ |
| 86 | int policy_cpu = per_cpu(cpufreq_policy_cpu, cpu); \ |
| 87 | BUG_ON(policy_cpu == -1); \ |
| 88 | up_##mode(&per_cpu(cpu_policy_rwsem, policy_cpu)); \ |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 89 | } |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 90 | |
Viresh Kumar | fa1d8af | 2013-02-07 15:38:42 +0530 | [diff] [blame] | 91 | unlock_policy_rwsem(read, cpu); |
| 92 | unlock_policy_rwsem(write, cpu); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /* internal prototypes */ |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 95 | static int __cpufreq_governor(struct cpufreq_policy *policy, |
| 96 | unsigned int event); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 97 | static unsigned int __cpufreq_get(unsigned int cpu); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 98 | static void handle_update(struct work_struct *work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 101 | * Two notifier lists: the "policy" list is involved in the |
| 102 | * validation process for a new CPU frequency policy; the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | * "transition" list for kernel code that needs to handle |
| 104 | * changes to devices when the CPU clock speed changes. |
| 105 | * The mutex locks both lists. |
| 106 | */ |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 107 | static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list); |
Alan Stern | b4dfdbb | 2006-10-04 02:17:06 -0700 | [diff] [blame] | 108 | static struct srcu_notifier_head cpufreq_transition_notifier_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Cesar Eduardo Barros | 74212ca | 2008-02-16 08:41:24 -0200 | [diff] [blame] | 110 | static bool init_cpufreq_transition_notifier_list_called; |
Alan Stern | b4dfdbb | 2006-10-04 02:17:06 -0700 | [diff] [blame] | 111 | static int __init init_cpufreq_transition_notifier_list(void) |
| 112 | { |
| 113 | srcu_init_notifier_head(&cpufreq_transition_notifier_list); |
Cesar Eduardo Barros | 74212ca | 2008-02-16 08:41:24 -0200 | [diff] [blame] | 114 | init_cpufreq_transition_notifier_list_called = true; |
Alan Stern | b4dfdbb | 2006-10-04 02:17:06 -0700 | [diff] [blame] | 115 | return 0; |
| 116 | } |
Linus Torvalds | b3438f8 | 2006-11-20 11:47:18 -0800 | [diff] [blame] | 117 | pure_initcall(init_cpufreq_transition_notifier_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Konrad Rzeszutek Wilk | a7b422c | 2012-03-13 19:18:39 -0400 | [diff] [blame] | 119 | static int off __read_mostly; |
Viresh Kumar | da58445 | 2012-10-26 00:51:32 +0200 | [diff] [blame] | 120 | static int cpufreq_disabled(void) |
Konrad Rzeszutek Wilk | a7b422c | 2012-03-13 19:18:39 -0400 | [diff] [blame] | 121 | { |
| 122 | return off; |
| 123 | } |
| 124 | void disable_cpufreq(void) |
| 125 | { |
| 126 | off = 1; |
| 127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | static LIST_HEAD(cpufreq_governor_list); |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 129 | static DEFINE_MUTEX(cpufreq_governor_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Viresh Kumar | 4d5dcc4 | 2013-03-27 15:58:58 +0000 | [diff] [blame] | 131 | bool have_governor_per_policy(void) |
| 132 | { |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 133 | bool have_governor_per_policy; |
| 134 | rcu_read_lock(); |
| 135 | have_governor_per_policy = |
| 136 | rcu_dereference(cpufreq_driver)->have_governor_per_policy; |
| 137 | rcu_read_unlock(); |
| 138 | return have_governor_per_policy; |
Viresh Kumar | 4d5dcc4 | 2013-03-27 15:58:58 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 141 | static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | struct cpufreq_policy *data; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 144 | struct cpufreq_driver *driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | unsigned long flags; |
| 146 | |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 147 | if (cpu >= nr_cpu_ids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | goto err_out; |
| 149 | |
| 150 | /* get the cpufreq driver */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 151 | rcu_read_lock(); |
| 152 | driver = rcu_dereference(cpufreq_driver); |
| 153 | |
| 154 | if (!driver) |
| 155 | goto err_out_unlock; |
| 156 | |
| 157 | if (!try_module_get(driver->owner)) |
| 158 | goto err_out_unlock; |
| 159 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 160 | read_lock_irqsave(&cpufreq_driver_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* get the CPU */ |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 163 | data = per_cpu(cpufreq_cpu_data, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | if (!data) |
| 166 | goto err_out_put_module; |
| 167 | |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 168 | if (!sysfs && !kobject_get(&data->kobj)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | goto err_out_put_module; |
| 170 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 171 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 172 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | return data; |
| 174 | |
Dave Jones | 7d5e350 | 2006-02-02 17:03:42 -0500 | [diff] [blame] | 175 | err_out_put_module: |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 176 | module_put(driver->owner); |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 177 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 178 | err_out_unlock: |
| 179 | rcu_read_unlock(); |
Dave Jones | 7d5e350 | 2006-02-02 17:03:42 -0500 | [diff] [blame] | 180 | err_out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | return NULL; |
| 182 | } |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 183 | |
| 184 | struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) |
| 185 | { |
Dirk Brandewie | d5aaffa | 2013-01-17 16:22:21 +0000 | [diff] [blame] | 186 | if (cpufreq_disabled()) |
| 187 | return NULL; |
| 188 | |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 189 | return __cpufreq_cpu_get(cpu, false); |
| 190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | EXPORT_SYMBOL_GPL(cpufreq_cpu_get); |
| 192 | |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 193 | static struct cpufreq_policy *cpufreq_cpu_get_sysfs(unsigned int cpu) |
| 194 | { |
| 195 | return __cpufreq_cpu_get(cpu, true); |
| 196 | } |
| 197 | |
| 198 | static void __cpufreq_cpu_put(struct cpufreq_policy *data, bool sysfs) |
| 199 | { |
| 200 | if (!sysfs) |
| 201 | kobject_put(&data->kobj); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 202 | rcu_read_lock(); |
| 203 | module_put(rcu_dereference(cpufreq_driver)->owner); |
| 204 | rcu_read_unlock(); |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 205 | } |
Dave Jones | 7d5e350 | 2006-02-02 17:03:42 -0500 | [diff] [blame] | 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | void cpufreq_cpu_put(struct cpufreq_policy *data) |
| 208 | { |
Dirk Brandewie | d5aaffa | 2013-01-17 16:22:21 +0000 | [diff] [blame] | 209 | if (cpufreq_disabled()) |
| 210 | return; |
| 211 | |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 212 | __cpufreq_cpu_put(data, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | EXPORT_SYMBOL_GPL(cpufreq_cpu_put); |
| 215 | |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 216 | static void cpufreq_cpu_put_sysfs(struct cpufreq_policy *data) |
| 217 | { |
| 218 | __cpufreq_cpu_put(data, true); |
| 219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /********************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * |
| 223 | *********************************************************************/ |
| 224 | |
| 225 | /** |
| 226 | * adjust_jiffies - adjust the system "loops_per_jiffy" |
| 227 | * |
| 228 | * This function alters the system "loops_per_jiffy" for the clock |
| 229 | * speed change. Note that loops_per_jiffy cannot be updated on SMP |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 230 | * systems as each CPU might be scaled differently. So, use the arch |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | * per-CPU loops_per_jiffy value wherever possible. |
| 232 | */ |
| 233 | #ifndef CONFIG_SMP |
| 234 | static unsigned long l_p_j_ref; |
| 235 | static unsigned int l_p_j_ref_freq; |
| 236 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 237 | static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
| 239 | if (ci->flags & CPUFREQ_CONST_LOOPS) |
| 240 | return; |
| 241 | |
| 242 | if (!l_p_j_ref_freq) { |
| 243 | l_p_j_ref = loops_per_jiffy; |
| 244 | l_p_j_ref_freq = ci->old; |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 245 | pr_debug("saving %lu as reference value for loops_per_jiffy; " |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 246 | "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
Afzal Mohammed | d08de0c1 | 2012-01-04 10:52:46 +0530 | [diff] [blame] | 248 | if ((val == CPUFREQ_POSTCHANGE && ci->old != ci->new) || |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 249 | (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 250 | loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, |
| 251 | ci->new); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 252 | pr_debug("scaling loops_per_jiffy to %lu " |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 253 | "for frequency %u kHz\n", loops_per_jiffy, ci->new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | #else |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 257 | static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) |
| 258 | { |
| 259 | return; |
| 260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | #endif |
| 262 | |
| 263 | |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 264 | void __cpufreq_notify_transition(struct cpufreq_policy *policy, |
| 265 | struct cpufreq_freqs *freqs, unsigned int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
| 267 | BUG_ON(irqs_disabled()); |
| 268 | |
Dirk Brandewie | d5aaffa | 2013-01-17 16:22:21 +0000 | [diff] [blame] | 269 | if (cpufreq_disabled()) |
| 270 | return; |
| 271 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 272 | rcu_read_lock(); |
| 273 | freqs->flags = rcu_dereference(cpufreq_driver)->flags; |
| 274 | rcu_read_unlock(); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 275 | pr_debug("notification %u of frequency transition to %u kHz\n", |
Dave Jones | e4472cb | 2006-01-31 15:53:55 -0800 | [diff] [blame] | 276 | state, freqs->new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | switch (state) { |
Dave Jones | e4472cb | 2006-01-31 15:53:55 -0800 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | case CPUFREQ_PRECHANGE: |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 281 | /* detect if the driver reported a value as "old frequency" |
Dave Jones | e4472cb | 2006-01-31 15:53:55 -0800 | [diff] [blame] | 282 | * which is not equal to what the cpufreq core thinks is |
| 283 | * "old frequency". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 285 | if (!(freqs->flags & CPUFREQ_CONST_LOOPS)) { |
Dave Jones | e4472cb | 2006-01-31 15:53:55 -0800 | [diff] [blame] | 286 | if ((policy) && (policy->cpu == freqs->cpu) && |
| 287 | (policy->cur) && (policy->cur != freqs->old)) { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 288 | pr_debug("Warning: CPU frequency is" |
Dave Jones | e4472cb | 2006-01-31 15:53:55 -0800 | [diff] [blame] | 289 | " %u, cpufreq assumed %u kHz.\n", |
| 290 | freqs->old, policy->cur); |
| 291 | freqs->old = policy->cur; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
Alan Stern | b4dfdbb | 2006-10-04 02:17:06 -0700 | [diff] [blame] | 294 | srcu_notifier_call_chain(&cpufreq_transition_notifier_list, |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 295 | CPUFREQ_PRECHANGE, freqs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | adjust_jiffies(CPUFREQ_PRECHANGE, freqs); |
| 297 | break; |
Dave Jones | e4472cb | 2006-01-31 15:53:55 -0800 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | case CPUFREQ_POSTCHANGE: |
| 300 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 301 | pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, |
Thomas Renninger | 6f4f272 | 2010-04-20 13:17:36 +0200 | [diff] [blame] | 302 | (unsigned long)freqs->cpu); |
Thomas Renninger | 25e4193 | 2011-01-03 17:50:44 +0100 | [diff] [blame] | 303 | trace_cpu_frequency(freqs->new, freqs->cpu); |
Alan Stern | b4dfdbb | 2006-10-04 02:17:06 -0700 | [diff] [blame] | 304 | srcu_notifier_call_chain(&cpufreq_transition_notifier_list, |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 305 | CPUFREQ_POSTCHANGE, freqs); |
Dave Jones | e4472cb | 2006-01-31 15:53:55 -0800 | [diff] [blame] | 306 | if (likely(policy) && likely(policy->cpu == freqs->cpu)) |
| 307 | policy->cur = freqs->new; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | break; |
| 309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 311 | /** |
| 312 | * cpufreq_notify_transition - call notifier chain and adjust_jiffies |
| 313 | * on frequency transition. |
| 314 | * |
| 315 | * This function calls the transition notifiers and the "adjust_jiffies" |
| 316 | * function. It is called twice on all CPU frequency changes that have |
| 317 | * external effects. |
| 318 | */ |
| 319 | void cpufreq_notify_transition(struct cpufreq_policy *policy, |
| 320 | struct cpufreq_freqs *freqs, unsigned int state) |
| 321 | { |
| 322 | for_each_cpu(freqs->cpu, policy->cpus) |
| 323 | __cpufreq_notify_transition(policy, freqs, state); |
| 324 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | EXPORT_SYMBOL_GPL(cpufreq_notify_transition); |
| 326 | |
| 327 | |
| 328 | |
| 329 | /********************************************************************* |
| 330 | * SYSFS INTERFACE * |
| 331 | *********************************************************************/ |
| 332 | |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 333 | static struct cpufreq_governor *__find_governor(const char *str_governor) |
| 334 | { |
| 335 | struct cpufreq_governor *t; |
| 336 | |
| 337 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 338 | if (!strnicmp(str_governor, t->name, CPUFREQ_NAME_LEN)) |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 339 | return t; |
| 340 | |
| 341 | return NULL; |
| 342 | } |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | /** |
| 345 | * cpufreq_parse_governor - parse a governor string |
| 346 | */ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 347 | static int cpufreq_parse_governor(char *str_governor, unsigned int *policy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | struct cpufreq_governor **governor) |
| 349 | { |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 350 | int err = -EINVAL; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 351 | struct cpufreq_driver *driver; |
| 352 | bool has_setpolicy; |
| 353 | bool has_target; |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 354 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 355 | rcu_read_lock(); |
| 356 | driver = rcu_dereference(cpufreq_driver); |
| 357 | if (!driver) { |
| 358 | rcu_read_unlock(); |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 359 | goto out; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 360 | } |
| 361 | has_setpolicy = driver->setpolicy ? true : false; |
| 362 | has_target = driver->target ? true : false; |
| 363 | rcu_read_unlock(); |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 364 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 365 | if (has_setpolicy) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) { |
| 367 | *policy = CPUFREQ_POLICY_PERFORMANCE; |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 368 | err = 0; |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 369 | } else if (!strnicmp(str_governor, "powersave", |
| 370 | CPUFREQ_NAME_LEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | *policy = CPUFREQ_POLICY_POWERSAVE; |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 372 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 374 | } else if (has_target) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | struct cpufreq_governor *t; |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 376 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 377 | mutex_lock(&cpufreq_governor_mutex); |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 378 | |
| 379 | t = __find_governor(str_governor); |
| 380 | |
Jeremy Fitzhardinge | ea71497 | 2006-07-06 12:32:01 -0700 | [diff] [blame] | 381 | if (t == NULL) { |
Kees Cook | 1a8e146 | 2011-05-04 08:38:56 -0700 | [diff] [blame] | 382 | int ret; |
Jeremy Fitzhardinge | ea71497 | 2006-07-06 12:32:01 -0700 | [diff] [blame] | 383 | |
Kees Cook | 1a8e146 | 2011-05-04 08:38:56 -0700 | [diff] [blame] | 384 | mutex_unlock(&cpufreq_governor_mutex); |
| 385 | ret = request_module("cpufreq_%s", str_governor); |
| 386 | mutex_lock(&cpufreq_governor_mutex); |
Jeremy Fitzhardinge | ea71497 | 2006-07-06 12:32:01 -0700 | [diff] [blame] | 387 | |
Kees Cook | 1a8e146 | 2011-05-04 08:38:56 -0700 | [diff] [blame] | 388 | if (ret == 0) |
| 389 | t = __find_governor(str_governor); |
Jeremy Fitzhardinge | ea71497 | 2006-07-06 12:32:01 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 392 | if (t != NULL) { |
| 393 | *governor = t; |
| 394 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | } |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 396 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 397 | mutex_unlock(&cpufreq_governor_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 399 | out: |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 400 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | /** |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 405 | * cpufreq_per_cpu_attr_read() / show_##file_name() - |
| 406 | * print out cpufreq information |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | * |
| 408 | * Write out information from cpufreq_driver->policy[cpu]; object must be |
| 409 | * "unsigned int". |
| 410 | */ |
| 411 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 412 | #define show_one(file_name, object) \ |
| 413 | static ssize_t show_##file_name \ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 414 | (struct cpufreq_policy *policy, char *buf) \ |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 415 | { \ |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 416 | return sprintf(buf, "%u\n", policy->object); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | show_one(cpuinfo_min_freq, cpuinfo.min_freq); |
| 420 | show_one(cpuinfo_max_freq, cpuinfo.max_freq); |
Thomas Renninger | ed12978 | 2009-02-04 01:17:41 +0100 | [diff] [blame] | 421 | show_one(cpuinfo_transition_latency, cpuinfo.transition_latency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | show_one(scaling_min_freq, min); |
| 423 | show_one(scaling_max_freq, max); |
| 424 | show_one(scaling_cur_freq, cur); |
| 425 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 426 | static int __cpufreq_set_policy(struct cpufreq_policy *data, |
| 427 | struct cpufreq_policy *policy); |
Thomas Renninger | 7970e08 | 2006-04-13 15:14:04 +0200 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | /** |
| 430 | * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access |
| 431 | */ |
| 432 | #define store_one(file_name, object) \ |
| 433 | static ssize_t store_##file_name \ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 434 | (struct cpufreq_policy *policy, const char *buf, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { \ |
Jingoo Han | f55c9c2 | 2012-10-31 05:49:13 +0000 | [diff] [blame] | 436 | unsigned int ret; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | struct cpufreq_policy new_policy; \ |
| 438 | \ |
| 439 | ret = cpufreq_get_policy(&new_policy, policy->cpu); \ |
| 440 | if (ret) \ |
| 441 | return -EINVAL; \ |
| 442 | \ |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 443 | ret = sscanf(buf, "%u", &new_policy.object); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | if (ret != 1) \ |
| 445 | return -EINVAL; \ |
| 446 | \ |
Thomas Renninger | 7970e08 | 2006-04-13 15:14:04 +0200 | [diff] [blame] | 447 | ret = __cpufreq_set_policy(policy, &new_policy); \ |
| 448 | policy->user_policy.object = policy->object; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | \ |
| 450 | return ret ? ret : count; \ |
| 451 | } |
| 452 | |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 453 | store_one(scaling_min_freq, min); |
| 454 | store_one(scaling_max_freq, max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | /** |
| 457 | * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware |
| 458 | */ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 459 | static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy, |
| 460 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 462 | unsigned int cur_freq = __cpufreq_get(policy->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | if (!cur_freq) |
| 464 | return sprintf(buf, "<unknown>"); |
| 465 | return sprintf(buf, "%u\n", cur_freq); |
| 466 | } |
| 467 | |
| 468 | |
| 469 | /** |
| 470 | * show_scaling_governor - show the current policy for the specified CPU |
| 471 | */ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 472 | static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | { |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 474 | if (policy->policy == CPUFREQ_POLICY_POWERSAVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return sprintf(buf, "powersave\n"); |
| 476 | else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) |
| 477 | return sprintf(buf, "performance\n"); |
| 478 | else if (policy->governor) |
viresh kumar | 4b972f0 | 2012-10-23 01:23:43 +0200 | [diff] [blame] | 479 | return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 480 | policy->governor->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | return -EINVAL; |
| 482 | } |
| 483 | |
| 484 | |
| 485 | /** |
| 486 | * store_scaling_governor - store policy for the specified CPU |
| 487 | */ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 488 | static ssize_t store_scaling_governor(struct cpufreq_policy *policy, |
| 489 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Jingoo Han | f55c9c2 | 2012-10-31 05:49:13 +0000 | [diff] [blame] | 491 | unsigned int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | char str_governor[16]; |
| 493 | struct cpufreq_policy new_policy; |
| 494 | |
| 495 | ret = cpufreq_get_policy(&new_policy, policy->cpu); |
| 496 | if (ret) |
| 497 | return ret; |
| 498 | |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 499 | ret = sscanf(buf, "%15s", str_governor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (ret != 1) |
| 501 | return -EINVAL; |
| 502 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 503 | if (cpufreq_parse_governor(str_governor, &new_policy.policy, |
| 504 | &new_policy.governor)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return -EINVAL; |
| 506 | |
Thomas Renninger | 7970e08 | 2006-04-13 15:14:04 +0200 | [diff] [blame] | 507 | /* Do not use cpufreq_set_policy here or the user_policy.max |
| 508 | will be wrongly overridden */ |
Thomas Renninger | 7970e08 | 2006-04-13 15:14:04 +0200 | [diff] [blame] | 509 | ret = __cpufreq_set_policy(policy, &new_policy); |
| 510 | |
| 511 | policy->user_policy.policy = policy->policy; |
| 512 | policy->user_policy.governor = policy->governor; |
Thomas Renninger | 7970e08 | 2006-04-13 15:14:04 +0200 | [diff] [blame] | 513 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 514 | if (ret) |
| 515 | return ret; |
| 516 | else |
| 517 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
| 521 | * show_scaling_driver - show the cpufreq driver currently loaded |
| 522 | */ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 523 | static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | { |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 525 | ssize_t size; |
| 526 | rcu_read_lock(); |
| 527 | size = scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", |
| 528 | rcu_dereference(cpufreq_driver)->name); |
| 529 | rcu_read_unlock(); |
| 530 | return size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * show_scaling_available_governors - show the available CPUfreq governors |
| 535 | */ |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 536 | static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, |
| 537 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
| 539 | ssize_t i = 0; |
| 540 | struct cpufreq_governor *t; |
| 541 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 542 | rcu_read_lock(); |
| 543 | if (!rcu_dereference(cpufreq_driver)->target) { |
| 544 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | i += sprintf(buf, "performance powersave"); |
| 546 | goto out; |
| 547 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 548 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
| 550 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) { |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 551 | if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) |
| 552 | - (CPUFREQ_NAME_LEN + 2))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | goto out; |
viresh kumar | 4b972f0 | 2012-10-23 01:23:43 +0200 | [diff] [blame] | 554 | i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
Dave Jones | 7d5e350 | 2006-02-02 17:03:42 -0500 | [diff] [blame] | 556 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | i += sprintf(&buf[i], "\n"); |
| 558 | return i; |
| 559 | } |
Darrick J. Wong | e8628dd | 2008-04-18 13:31:12 -0700 | [diff] [blame] | 560 | |
Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 561 | static ssize_t show_cpus(const struct cpumask *mask, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
| 563 | ssize_t i = 0; |
| 564 | unsigned int cpu; |
| 565 | |
Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 566 | for_each_cpu(cpu, mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | if (i) |
| 568 | i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); |
| 569 | i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); |
| 570 | if (i >= (PAGE_SIZE - 5)) |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 571 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
| 573 | i += sprintf(&buf[i], "\n"); |
| 574 | return i; |
| 575 | } |
| 576 | |
Darrick J. Wong | e8628dd | 2008-04-18 13:31:12 -0700 | [diff] [blame] | 577 | /** |
| 578 | * show_related_cpus - show the CPUs affected by each transition even if |
| 579 | * hw coordination is in use |
| 580 | */ |
| 581 | static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf) |
| 582 | { |
Darrick J. Wong | e8628dd | 2008-04-18 13:31:12 -0700 | [diff] [blame] | 583 | return show_cpus(policy->related_cpus, buf); |
| 584 | } |
| 585 | |
| 586 | /** |
| 587 | * show_affected_cpus - show the CPUs affected by each transition |
| 588 | */ |
| 589 | static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf) |
| 590 | { |
| 591 | return show_cpus(policy->cpus, buf); |
| 592 | } |
| 593 | |
Venki Pallipadi | 9e76988 | 2007-10-26 10:18:21 -0700 | [diff] [blame] | 594 | static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy, |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 595 | const char *buf, size_t count) |
Venki Pallipadi | 9e76988 | 2007-10-26 10:18:21 -0700 | [diff] [blame] | 596 | { |
| 597 | unsigned int freq = 0; |
| 598 | unsigned int ret; |
| 599 | |
CHIKAMA masaki | 879000f | 2008-06-05 22:46:33 -0700 | [diff] [blame] | 600 | if (!policy->governor || !policy->governor->store_setspeed) |
Venki Pallipadi | 9e76988 | 2007-10-26 10:18:21 -0700 | [diff] [blame] | 601 | return -EINVAL; |
| 602 | |
| 603 | ret = sscanf(buf, "%u", &freq); |
| 604 | if (ret != 1) |
| 605 | return -EINVAL; |
| 606 | |
| 607 | policy->governor->store_setspeed(policy, freq); |
| 608 | |
| 609 | return count; |
| 610 | } |
| 611 | |
| 612 | static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf) |
| 613 | { |
CHIKAMA masaki | 879000f | 2008-06-05 22:46:33 -0700 | [diff] [blame] | 614 | if (!policy->governor || !policy->governor->show_setspeed) |
Venki Pallipadi | 9e76988 | 2007-10-26 10:18:21 -0700 | [diff] [blame] | 615 | return sprintf(buf, "<unsupported>\n"); |
| 616 | |
| 617 | return policy->governor->show_setspeed(policy, buf); |
| 618 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Thomas Renninger | e2f74f3 | 2009-11-19 12:31:01 +0100 | [diff] [blame] | 620 | /** |
viresh kumar | 8bf1ac72 | 2012-10-23 01:23:33 +0200 | [diff] [blame] | 621 | * show_bios_limit - show the current cpufreq HW/BIOS limitation |
Thomas Renninger | e2f74f3 | 2009-11-19 12:31:01 +0100 | [diff] [blame] | 622 | */ |
| 623 | static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf) |
| 624 | { |
| 625 | unsigned int limit; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 626 | int (*bios_limit)(int cpu, unsigned int *limit); |
Thomas Renninger | e2f74f3 | 2009-11-19 12:31:01 +0100 | [diff] [blame] | 627 | int ret; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 628 | |
| 629 | rcu_read_lock(); |
| 630 | bios_limit = rcu_dereference(cpufreq_driver)->bios_limit; |
| 631 | rcu_read_unlock(); |
| 632 | |
| 633 | if (bios_limit) { |
| 634 | ret = bios_limit(policy->cpu, &limit); |
Thomas Renninger | e2f74f3 | 2009-11-19 12:31:01 +0100 | [diff] [blame] | 635 | if (!ret) |
| 636 | return sprintf(buf, "%u\n", limit); |
| 637 | } |
| 638 | return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); |
| 639 | } |
| 640 | |
Borislav Petkov | 6dad2a2 | 2010-03-31 21:56:46 +0200 | [diff] [blame] | 641 | cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400); |
| 642 | cpufreq_freq_attr_ro(cpuinfo_min_freq); |
| 643 | cpufreq_freq_attr_ro(cpuinfo_max_freq); |
| 644 | cpufreq_freq_attr_ro(cpuinfo_transition_latency); |
| 645 | cpufreq_freq_attr_ro(scaling_available_governors); |
| 646 | cpufreq_freq_attr_ro(scaling_driver); |
| 647 | cpufreq_freq_attr_ro(scaling_cur_freq); |
| 648 | cpufreq_freq_attr_ro(bios_limit); |
| 649 | cpufreq_freq_attr_ro(related_cpus); |
| 650 | cpufreq_freq_attr_ro(affected_cpus); |
| 651 | cpufreq_freq_attr_rw(scaling_min_freq); |
| 652 | cpufreq_freq_attr_rw(scaling_max_freq); |
| 653 | cpufreq_freq_attr_rw(scaling_governor); |
| 654 | cpufreq_freq_attr_rw(scaling_setspeed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 656 | static struct attribute *default_attrs[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | &cpuinfo_min_freq.attr, |
| 658 | &cpuinfo_max_freq.attr, |
Thomas Renninger | ed12978 | 2009-02-04 01:17:41 +0100 | [diff] [blame] | 659 | &cpuinfo_transition_latency.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | &scaling_min_freq.attr, |
| 661 | &scaling_max_freq.attr, |
| 662 | &affected_cpus.attr, |
Darrick J. Wong | e8628dd | 2008-04-18 13:31:12 -0700 | [diff] [blame] | 663 | &related_cpus.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | &scaling_governor.attr, |
| 665 | &scaling_driver.attr, |
| 666 | &scaling_available_governors.attr, |
Venki Pallipadi | 9e76988 | 2007-10-26 10:18:21 -0700 | [diff] [blame] | 667 | &scaling_setspeed.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | NULL |
| 669 | }; |
| 670 | |
Thomas Renninger | 8aa84ad | 2009-07-24 15:25:05 +0200 | [diff] [blame] | 671 | struct kobject *cpufreq_global_kobject; |
| 672 | EXPORT_SYMBOL(cpufreq_global_kobject); |
| 673 | |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 674 | #define to_policy(k) container_of(k, struct cpufreq_policy, kobj) |
| 675 | #define to_attr(a) container_of(a, struct freq_attr, attr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 677 | static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 679 | struct cpufreq_policy *policy = to_policy(kobj); |
| 680 | struct freq_attr *fattr = to_attr(attr); |
Dave Jones | 0db4a8a | 2008-03-05 14:20:57 -0500 | [diff] [blame] | 681 | ssize_t ret = -EINVAL; |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 682 | policy = cpufreq_cpu_get_sysfs(policy->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | if (!policy) |
Dave Jones | 0db4a8a | 2008-03-05 14:20:57 -0500 | [diff] [blame] | 684 | goto no_policy; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 685 | |
| 686 | if (lock_policy_rwsem_read(policy->cpu) < 0) |
Dave Jones | 0db4a8a | 2008-03-05 14:20:57 -0500 | [diff] [blame] | 687 | goto fail; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 688 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 689 | if (fattr->show) |
| 690 | ret = fattr->show(policy, buf); |
| 691 | else |
| 692 | ret = -EIO; |
| 693 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 694 | unlock_policy_rwsem_read(policy->cpu); |
Dave Jones | 0db4a8a | 2008-03-05 14:20:57 -0500 | [diff] [blame] | 695 | fail: |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 696 | cpufreq_cpu_put_sysfs(policy); |
Dave Jones | 0db4a8a | 2008-03-05 14:20:57 -0500 | [diff] [blame] | 697 | no_policy: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | return ret; |
| 699 | } |
| 700 | |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 701 | static ssize_t store(struct kobject *kobj, struct attribute *attr, |
| 702 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 704 | struct cpufreq_policy *policy = to_policy(kobj); |
| 705 | struct freq_attr *fattr = to_attr(attr); |
Dave Jones | a07530b | 2008-03-05 14:22:25 -0500 | [diff] [blame] | 706 | ssize_t ret = -EINVAL; |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 707 | policy = cpufreq_cpu_get_sysfs(policy->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | if (!policy) |
Dave Jones | a07530b | 2008-03-05 14:22:25 -0500 | [diff] [blame] | 709 | goto no_policy; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 710 | |
| 711 | if (lock_policy_rwsem_write(policy->cpu) < 0) |
Dave Jones | a07530b | 2008-03-05 14:22:25 -0500 | [diff] [blame] | 712 | goto fail; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 713 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 714 | if (fattr->store) |
| 715 | ret = fattr->store(policy, buf, count); |
| 716 | else |
| 717 | ret = -EIO; |
| 718 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 719 | unlock_policy_rwsem_write(policy->cpu); |
Dave Jones | a07530b | 2008-03-05 14:22:25 -0500 | [diff] [blame] | 720 | fail: |
Stephen Boyd | a914443 | 2012-07-20 18:14:38 +0000 | [diff] [blame] | 721 | cpufreq_cpu_put_sysfs(policy); |
Dave Jones | a07530b | 2008-03-05 14:22:25 -0500 | [diff] [blame] | 722 | no_policy: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | return ret; |
| 724 | } |
| 725 | |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 726 | static void cpufreq_sysfs_release(struct kobject *kobj) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
Dave Jones | 905d77c | 2008-03-05 14:28:32 -0500 | [diff] [blame] | 728 | struct cpufreq_policy *policy = to_policy(kobj); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 729 | pr_debug("last reference is dropped\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | complete(&policy->kobj_unregister); |
| 731 | } |
| 732 | |
Emese Revfy | 52cf25d | 2010-01-19 02:58:23 +0100 | [diff] [blame] | 733 | static const struct sysfs_ops sysfs_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | .show = show, |
| 735 | .store = store, |
| 736 | }; |
| 737 | |
| 738 | static struct kobj_type ktype_cpufreq = { |
| 739 | .sysfs_ops = &sysfs_ops, |
| 740 | .default_attrs = default_attrs, |
| 741 | .release = cpufreq_sysfs_release, |
| 742 | }; |
| 743 | |
Dave Jones | 19d6f7e | 2009-07-08 17:35:39 -0400 | [diff] [blame] | 744 | /* symlink affected CPUs */ |
Alex Chiang | cf3289d0 | 2009-11-17 20:27:08 -0700 | [diff] [blame] | 745 | static int cpufreq_add_dev_symlink(unsigned int cpu, |
| 746 | struct cpufreq_policy *policy) |
Dave Jones | 19d6f7e | 2009-07-08 17:35:39 -0400 | [diff] [blame] | 747 | { |
| 748 | unsigned int j; |
| 749 | int ret = 0; |
| 750 | |
| 751 | for_each_cpu(j, policy->cpus) { |
| 752 | struct cpufreq_policy *managed_policy; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 753 | struct device *cpu_dev; |
Dave Jones | 19d6f7e | 2009-07-08 17:35:39 -0400 | [diff] [blame] | 754 | |
| 755 | if (j == cpu) |
| 756 | continue; |
Dave Jones | 19d6f7e | 2009-07-08 17:35:39 -0400 | [diff] [blame] | 757 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 758 | pr_debug("CPU %u already managed, adding link\n", j); |
Dave Jones | 19d6f7e | 2009-07-08 17:35:39 -0400 | [diff] [blame] | 759 | managed_policy = cpufreq_cpu_get(cpu); |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 760 | cpu_dev = get_cpu_device(j); |
| 761 | ret = sysfs_create_link(&cpu_dev->kobj, &policy->kobj, |
Dave Jones | 19d6f7e | 2009-07-08 17:35:39 -0400 | [diff] [blame] | 762 | "cpufreq"); |
| 763 | if (ret) { |
| 764 | cpufreq_cpu_put(managed_policy); |
| 765 | return ret; |
| 766 | } |
| 767 | } |
| 768 | return ret; |
| 769 | } |
| 770 | |
Alex Chiang | cf3289d0 | 2009-11-17 20:27:08 -0700 | [diff] [blame] | 771 | static int cpufreq_add_dev_interface(unsigned int cpu, |
| 772 | struct cpufreq_policy *policy, |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 773 | struct device *dev) |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 774 | { |
Dave Jones | ecf7e46 | 2009-07-08 18:48:47 -0400 | [diff] [blame] | 775 | struct cpufreq_policy new_policy; |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 776 | struct freq_attr **drv_attr; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 777 | struct cpufreq_driver *driver; |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 778 | unsigned long flags; |
| 779 | int ret = 0; |
| 780 | unsigned int j; |
| 781 | |
| 782 | /* prepare interface data */ |
| 783 | ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 784 | &dev->kobj, "cpufreq"); |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 785 | if (ret) |
| 786 | return ret; |
| 787 | |
| 788 | /* set up files for this cpu device */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 789 | rcu_read_lock(); |
| 790 | driver = rcu_dereference(cpufreq_driver); |
| 791 | drv_attr = driver->attr; |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 792 | while ((drv_attr) && (*drv_attr)) { |
| 793 | ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); |
| 794 | if (ret) |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 795 | goto err_out_unlock; |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 796 | drv_attr++; |
| 797 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 798 | if (driver->get) { |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 799 | ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); |
| 800 | if (ret) |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 801 | goto err_out_unlock; |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 802 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 803 | if (driver->target) { |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 804 | ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); |
| 805 | if (ret) |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 806 | goto err_out_unlock; |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 807 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 808 | if (driver->bios_limit) { |
Thomas Renninger | e2f74f3 | 2009-11-19 12:31:01 +0100 | [diff] [blame] | 809 | ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); |
| 810 | if (ret) |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 811 | goto err_out_unlock; |
Thomas Renninger | e2f74f3 | 2009-11-19 12:31:01 +0100 | [diff] [blame] | 812 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 813 | rcu_read_unlock(); |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 814 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 815 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 816 | for_each_cpu(j, policy->cpus) { |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 817 | per_cpu(cpufreq_cpu_data, j) = policy; |
Tejun Heo | f162506 | 2009-10-29 22:34:13 +0900 | [diff] [blame] | 818 | per_cpu(cpufreq_policy_cpu, j) = policy->cpu; |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 819 | } |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 820 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 821 | |
| 822 | ret = cpufreq_add_dev_symlink(cpu, policy); |
Dave Jones | ecf7e46 | 2009-07-08 18:48:47 -0400 | [diff] [blame] | 823 | if (ret) |
| 824 | goto err_out_kobj_put; |
| 825 | |
| 826 | memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); |
| 827 | /* assure that the starting sequence is run in __cpufreq_set_policy */ |
| 828 | policy->governor = NULL; |
| 829 | |
| 830 | /* set default policy */ |
| 831 | ret = __cpufreq_set_policy(policy, &new_policy); |
| 832 | policy->user_policy.policy = policy->policy; |
| 833 | policy->user_policy.governor = policy->governor; |
| 834 | |
| 835 | if (ret) { |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 836 | int (*exit)(struct cpufreq_policy *policy); |
| 837 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 838 | pr_debug("setting policy failed\n"); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 839 | rcu_read_lock(); |
| 840 | exit = rcu_dereference(cpufreq_driver)->exit; |
| 841 | rcu_read_unlock(); |
| 842 | if (exit) |
| 843 | exit(policy); |
| 844 | |
Dave Jones | ecf7e46 | 2009-07-08 18:48:47 -0400 | [diff] [blame] | 845 | } |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 846 | return ret; |
| 847 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 848 | err_out_unlock: |
| 849 | rcu_read_unlock(); |
Dave Jones | 909a694 | 2009-07-08 18:05:42 -0400 | [diff] [blame] | 850 | err_out_kobj_put: |
| 851 | kobject_put(&policy->kobj); |
| 852 | wait_for_completion(&policy->kobj_unregister); |
| 853 | return ret; |
| 854 | } |
| 855 | |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 856 | #ifdef CONFIG_HOTPLUG_CPU |
| 857 | static int cpufreq_add_policy_cpu(unsigned int cpu, unsigned int sibling, |
| 858 | struct device *dev) |
| 859 | { |
| 860 | struct cpufreq_policy *policy; |
| 861 | int ret = 0; |
| 862 | unsigned long flags; |
| 863 | |
| 864 | policy = cpufreq_cpu_get(sibling); |
| 865 | WARN_ON(!policy); |
| 866 | |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 867 | __cpufreq_governor(policy, CPUFREQ_GOV_STOP); |
| 868 | |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 869 | lock_policy_rwsem_write(sibling); |
| 870 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 871 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 872 | |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 873 | cpumask_set_cpu(cpu, policy->cpus); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 874 | per_cpu(cpufreq_policy_cpu, cpu) = policy->cpu; |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 875 | per_cpu(cpufreq_cpu_data, cpu) = policy; |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 876 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 877 | |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 878 | unlock_policy_rwsem_write(sibling); |
| 879 | |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 880 | __cpufreq_governor(policy, CPUFREQ_GOV_START); |
| 881 | __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS); |
| 882 | |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 883 | ret = sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"); |
| 884 | if (ret) { |
| 885 | cpufreq_cpu_put(policy); |
| 886 | return ret; |
| 887 | } |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | /** |
| 894 | * cpufreq_add_dev - add a CPU device |
| 895 | * |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 896 | * Adds the cpufreq interface for a CPU device. |
Mathieu Desnoyers | 3f4a782 | 2009-07-03 11:25:16 -0400 | [diff] [blame] | 897 | * |
| 898 | * The Oracle says: try running cpufreq registration/unregistration concurrently |
| 899 | * with with cpu hotplugging and all hell will break loose. Tried to clean this |
| 900 | * mess up, but more thorough testing is needed. - Mathieu |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 902 | static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 904 | unsigned int j, cpu = dev->id; |
Viresh Kumar | 6592246 | 2013-02-07 10:56:03 +0530 | [diff] [blame] | 905 | int ret = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | struct cpufreq_policy *policy; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 907 | struct cpufreq_driver *driver; |
| 908 | int (*init)(struct cpufreq_policy *policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | unsigned long flags; |
Prarit Bhargava | 90e41ba | 2009-11-12 09:18:46 -0500 | [diff] [blame] | 910 | #ifdef CONFIG_HOTPLUG_CPU |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 911 | struct cpufreq_governor *gov; |
Prarit Bhargava | 90e41ba | 2009-11-12 09:18:46 -0500 | [diff] [blame] | 912 | int sibling; |
| 913 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 915 | if (cpu_is_offline(cpu)) |
| 916 | return 0; |
| 917 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 918 | pr_debug("adding CPU %u\n", cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
| 920 | #ifdef CONFIG_SMP |
| 921 | /* check whether a different CPU already registered this |
| 922 | * CPU because it is in the same boat. */ |
| 923 | policy = cpufreq_cpu_get(cpu); |
| 924 | if (unlikely(policy)) { |
Dave Jones | 8ff6973 | 2006-03-05 03:37:23 -0500 | [diff] [blame] | 925 | cpufreq_cpu_put(policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | return 0; |
| 927 | } |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 928 | |
| 929 | #ifdef CONFIG_HOTPLUG_CPU |
| 930 | /* Check if this cpu was hot-unplugged earlier and has siblings */ |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 931 | read_lock_irqsave(&cpufreq_driver_lock, flags); |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 932 | for_each_online_cpu(sibling) { |
| 933 | struct cpufreq_policy *cp = per_cpu(cpufreq_cpu_data, sibling); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 934 | if (cp && cpumask_test_cpu(cpu, cp->related_cpus)) { |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 935 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 936 | return cpufreq_add_policy_cpu(cpu, sibling, dev); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 937 | } |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 938 | } |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 939 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 940 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | #endif |
| 942 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 943 | rcu_read_lock(); |
| 944 | driver = rcu_dereference(cpufreq_driver); |
| 945 | if (!try_module_get(driver->owner)) { |
| 946 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | ret = -EINVAL; |
| 948 | goto module_out; |
| 949 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 950 | init = driver->init; |
| 951 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Dave Jones | e98df50 | 2005-10-20 15:17:43 -0700 | [diff] [blame] | 953 | policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL); |
Dave Jones | 059019a | 2009-07-08 16:30:03 -0400 | [diff] [blame] | 954 | if (!policy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | goto nomem_out; |
Dave Jones | 059019a | 2009-07-08 16:30:03 -0400 | [diff] [blame] | 956 | |
| 957 | if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) |
Mathieu Desnoyers | 3f4a782 | 2009-07-03 11:25:16 -0400 | [diff] [blame] | 958 | goto err_free_policy; |
Dave Jones | 059019a | 2009-07-08 16:30:03 -0400 | [diff] [blame] | 959 | |
| 960 | if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) |
Mathieu Desnoyers | 3f4a782 | 2009-07-03 11:25:16 -0400 | [diff] [blame] | 961 | goto err_free_cpumask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | |
| 963 | policy->cpu = cpu; |
Viresh Kumar | 6592246 | 2013-02-07 10:56:03 +0530 | [diff] [blame] | 964 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; |
Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 965 | cpumask_copy(policy->cpus, cpumask_of(cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 967 | /* Initially set CPU itself as the policy_cpu */ |
Tejun Heo | f162506 | 2009-10-29 22:34:13 +0900 | [diff] [blame] | 968 | per_cpu(cpufreq_policy_cpu, cpu) = cpu; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | init_completion(&policy->kobj_unregister); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 971 | INIT_WORK(&policy->update, handle_update); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
| 973 | /* call driver. From then on the cpufreq must be able |
| 974 | * to accept all calls to ->verify and ->setpolicy for this CPU |
| 975 | */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 976 | ret = init(policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | if (ret) { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 978 | pr_debug("initialization failed\n"); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 979 | goto err_set_policy_cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | } |
Viresh Kumar | 643ae6e | 2013-01-12 05:14:38 +0000 | [diff] [blame] | 981 | |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 982 | /* related cpus should atleast have policy->cpus */ |
| 983 | cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); |
| 984 | |
Viresh Kumar | 643ae6e | 2013-01-12 05:14:38 +0000 | [diff] [blame] | 985 | /* |
| 986 | * affected cpus must always be the one, which are online. We aren't |
| 987 | * managing offline cpus here. |
| 988 | */ |
| 989 | cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); |
| 990 | |
Mike Chan | 187d9f4 | 2008-12-04 12:19:17 -0800 | [diff] [blame] | 991 | policy->user_policy.min = policy->min; |
| 992 | policy->user_policy.max = policy->max; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
Thomas Renninger | a1531ac | 2008-07-29 22:32:58 -0700 | [diff] [blame] | 994 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
| 995 | CPUFREQ_START, policy); |
| 996 | |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 997 | #ifdef CONFIG_HOTPLUG_CPU |
| 998 | gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); |
| 999 | if (gov) { |
| 1000 | policy->governor = gov; |
| 1001 | pr_debug("Restoring governor %s for cpu %d\n", |
| 1002 | policy->governor->name, cpu); |
Thomas Renninger | 4bfa042 | 2009-07-24 15:25:03 +0200 | [diff] [blame] | 1003 | } |
Viresh Kumar | fcf8058 | 2013-01-29 14:39:08 +0000 | [diff] [blame] | 1004 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1006 | ret = cpufreq_add_dev_interface(cpu, policy, dev); |
Dave Jones | 19d6f7e | 2009-07-08 17:35:39 -0400 | [diff] [blame] | 1007 | if (ret) |
| 1008 | goto err_out_unregister; |
Dave Jones | 8ff6973 | 2006-03-05 03:37:23 -0500 | [diff] [blame] | 1009 | |
Greg Kroah-Hartman | 038c5b3 | 2007-12-17 15:54:39 -0400 | [diff] [blame] | 1010 | kobject_uevent(&policy->kobj, KOBJ_ADD); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1011 | rcu_read_lock(); |
| 1012 | module_put(rcu_dereference(cpufreq_driver)->owner); |
| 1013 | rcu_read_unlock(); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1014 | pr_debug("initialization complete\n"); |
Dave Jones | 87c3227 | 2006-03-29 01:48:37 -0500 | [diff] [blame] | 1015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | return 0; |
| 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | err_out_unregister: |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 1019 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 1020 | for_each_cpu(j, policy->cpus) |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 1021 | per_cpu(cpufreq_cpu_data, j) = NULL; |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 1022 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | |
Greg Kroah-Hartman | c10997f | 2007-12-20 08:13:05 -0800 | [diff] [blame] | 1024 | kobject_put(&policy->kobj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | wait_for_completion(&policy->kobj_unregister); |
| 1026 | |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1027 | err_set_policy_cpu: |
| 1028 | per_cpu(cpufreq_policy_cpu, cpu) = -1; |
Xiaotian Feng | cad70a6 | 2010-07-20 20:11:02 +0800 | [diff] [blame] | 1029 | free_cpumask_var(policy->related_cpus); |
Mathieu Desnoyers | 3f4a782 | 2009-07-03 11:25:16 -0400 | [diff] [blame] | 1030 | err_free_cpumask: |
| 1031 | free_cpumask_var(policy->cpus); |
| 1032 | err_free_policy: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | kfree(policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | nomem_out: |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1035 | rcu_read_lock(); |
| 1036 | module_put(rcu_dereference(cpufreq_driver)->owner); |
| 1037 | rcu_read_unlock(); |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1038 | module_out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | return ret; |
| 1040 | } |
| 1041 | |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1042 | static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) |
| 1043 | { |
| 1044 | int j; |
| 1045 | |
| 1046 | policy->last_cpu = policy->cpu; |
| 1047 | policy->cpu = cpu; |
| 1048 | |
Viresh Kumar | 3361b7b | 2013-02-04 11:38:51 +0000 | [diff] [blame] | 1049 | for_each_cpu(j, policy->cpus) |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1050 | per_cpu(cpufreq_policy_cpu, j) = cpu; |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
| 1059 | /** |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1060 | * __cpufreq_remove_dev - remove a CPU device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | * |
| 1062 | * Removes the cpufreq interface for a CPU device. |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1063 | * Caller should already have policy_rwsem in write mode for this CPU. |
| 1064 | * This routine frees the rwsem before returning. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | */ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1066 | static int __cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1068 | unsigned int cpu = dev->id, ret, cpus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | unsigned long flags; |
| 1070 | struct cpufreq_policy *data; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1071 | struct cpufreq_driver *driver; |
Amerigo Wang | 499bca9 | 2010-03-04 03:23:46 -0500 | [diff] [blame] | 1072 | struct kobject *kobj; |
| 1073 | struct completion *cmp; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1074 | struct device *cpu_dev; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1075 | bool has_target; |
| 1076 | int (*exit)(struct cpufreq_policy *policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1078 | pr_debug("%s: unregistering CPU %u\n", __func__, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 1080 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | data = per_cpu(cpufreq_cpu_data, cpu); |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 1083 | per_cpu(cpufreq_cpu_data, cpu) = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 1085 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | if (!data) { |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1088 | pr_debug("%s: No cpu_data found\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1092 | rcu_read_lock(); |
| 1093 | driver = rcu_dereference(cpufreq_driver); |
| 1094 | has_target = driver->target ? true : false; |
| 1095 | exit = driver->exit; |
| 1096 | if (has_target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1098 | |
Jacob Shin | 27ecddc | 2011-04-27 13:32:11 -0500 | [diff] [blame] | 1099 | #ifdef CONFIG_HOTPLUG_CPU |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1100 | if (!driver->setpolicy) |
Dirk Brandewie | fa69e33 | 2013-02-06 09:02:11 -0800 | [diff] [blame] | 1101 | strncpy(per_cpu(cpufreq_cpu_governor, cpu), |
| 1102 | data->governor->name, CPUFREQ_NAME_LEN); |
Jacob Shin | 27ecddc | 2011-04-27 13:32:11 -0500 | [diff] [blame] | 1103 | #endif |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1104 | rcu_read_unlock(); |
Jacob Shin | 27ecddc | 2011-04-27 13:32:11 -0500 | [diff] [blame] | 1105 | |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1106 | WARN_ON(lock_policy_rwsem_write(cpu)); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1107 | cpus = cpumask_weight(data->cpus); |
Viresh Kumar | e4969eb | 2013-04-11 08:04:53 +0000 | [diff] [blame^] | 1108 | |
| 1109 | if (cpus > 1) |
| 1110 | cpumask_clear_cpu(cpu, data->cpus); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1111 | unlock_policy_rwsem_write(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
Viresh Kumar | 73bf0fc | 2013-02-05 22:21:14 +0100 | [diff] [blame] | 1113 | if (cpu != data->cpu) { |
| 1114 | sysfs_remove_link(&dev->kobj, "cpufreq"); |
| 1115 | } else if (cpus > 1) { |
Venki Pallipadi | ec28297 | 2007-03-26 12:03:19 -0700 | [diff] [blame] | 1116 | /* first sibling now owns the new sysfs dir */ |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1117 | cpu_dev = get_cpu_device(cpumask_first(data->cpus)); |
| 1118 | sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); |
| 1119 | ret = kobject_move(&data->kobj, &cpu_dev->kobj); |
| 1120 | if (ret) { |
| 1121 | pr_err("%s: Failed to move kobj: %d", __func__, ret); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1122 | |
| 1123 | WARN_ON(lock_policy_rwsem_write(cpu)); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1124 | cpumask_set_cpu(cpu, data->cpus); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1125 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 1126 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1127 | per_cpu(cpufreq_cpu_data, cpu) = data; |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 1128 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1129 | |
| 1130 | unlock_policy_rwsem_write(cpu); |
| 1131 | |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1132 | ret = sysfs_create_link(&cpu_dev->kobj, &data->kobj, |
| 1133 | "cpufreq"); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1134 | return -EINVAL; |
| 1135 | } |
Venki Pallipadi | ec28297 | 2007-03-26 12:03:19 -0700 | [diff] [blame] | 1136 | |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1137 | WARN_ON(lock_policy_rwsem_write(cpu)); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1138 | update_policy_cpu(data, cpu_dev->id); |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1139 | unlock_policy_rwsem_write(cpu); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1140 | pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n", |
| 1141 | __func__, cpu_dev->id, cpu); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1142 | } |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1143 | |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1144 | pr_debug("%s: removing link, cpu: %d\n", __func__, cpu); |
| 1145 | cpufreq_cpu_put(data); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1146 | |
| 1147 | /* If cpu is last user of policy, free policy */ |
| 1148 | if (cpus == 1) { |
Viresh Kumar | 7bd353a | 2013-03-27 15:58:57 +0000 | [diff] [blame] | 1149 | __cpufreq_governor(data, CPUFREQ_GOV_POLICY_EXIT); |
| 1150 | |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1151 | lock_policy_rwsem_read(cpu); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1152 | kobj = &data->kobj; |
| 1153 | cmp = &data->kobj_unregister; |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1154 | unlock_policy_rwsem_read(cpu); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1155 | kobject_put(kobj); |
| 1156 | |
| 1157 | /* we need to make sure that the underlying kobj is actually |
| 1158 | * not referenced anymore by anybody before we proceed with |
| 1159 | * unloading. |
| 1160 | */ |
| 1161 | pr_debug("waiting for dropping of refcount\n"); |
| 1162 | wait_for_completion(cmp); |
| 1163 | pr_debug("wait complete\n"); |
| 1164 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1165 | if (exit) |
| 1166 | exit(data); |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1167 | |
| 1168 | free_cpumask_var(data->related_cpus); |
| 1169 | free_cpumask_var(data->cpus); |
| 1170 | kfree(data); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1171 | } else if (has_target) { |
Viresh Kumar | b8eed8a | 2013-01-14 13:23:03 +0000 | [diff] [blame] | 1172 | __cpufreq_governor(data, CPUFREQ_GOV_START); |
| 1173 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); |
| 1174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
Viresh Kumar | 2eaa3e2 | 2013-02-07 10:55:00 +0530 | [diff] [blame] | 1176 | per_cpu(cpufreq_policy_cpu, cpu) = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1181 | static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif) |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1182 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1183 | unsigned int cpu = dev->id; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1184 | int retval; |
| 1185 | |
| 1186 | if (cpu_is_offline(cpu)) |
| 1187 | return 0; |
| 1188 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1189 | retval = __cpufreq_remove_dev(dev, sif); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1190 | return retval; |
| 1191 | } |
| 1192 | |
| 1193 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1194 | static void handle_update(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1196 | struct cpufreq_policy *policy = |
| 1197 | container_of(work, struct cpufreq_policy, update); |
| 1198 | unsigned int cpu = policy->cpu; |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1199 | pr_debug("handle_update for cpu %u called\n", cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | cpufreq_update_policy(cpu); |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble. |
| 1205 | * @cpu: cpu number |
| 1206 | * @old_freq: CPU frequency the kernel thinks the CPU runs at |
| 1207 | * @new_freq: CPU frequency the CPU actually runs at |
| 1208 | * |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 1209 | * We adjust to current frequency first, and need to clean up later. |
| 1210 | * So either call to cpufreq_update_policy() or schedule handle_update()). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | */ |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1212 | static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, |
| 1213 | unsigned int new_freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | { |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 1215 | struct cpufreq_policy *policy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | struct cpufreq_freqs freqs; |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 1217 | unsigned long flags; |
| 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1220 | pr_debug("Warning: CPU frequency out of sync: cpufreq and timing " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); |
| 1222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | freqs.old = old_freq; |
| 1224 | freqs.new = new_freq; |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 1225 | |
| 1226 | read_lock_irqsave(&cpufreq_driver_lock, flags); |
| 1227 | policy = per_cpu(cpufreq_cpu_data, cpu); |
| 1228 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); |
| 1229 | |
| 1230 | cpufreq_notify_transition(policy, &freqs, CPUFREQ_PRECHANGE); |
| 1231 | cpufreq_notify_transition(policy, &freqs, CPUFREQ_POSTCHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 1235 | /** |
Dhaval Giani | 4ab70df | 2006-12-13 14:49:15 +0530 | [diff] [blame] | 1236 | * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur |
Venkatesh Pallipadi | 95235ca | 2005-12-02 10:43:20 -0800 | [diff] [blame] | 1237 | * @cpu: CPU number |
| 1238 | * |
| 1239 | * This is the last known freq, without actually getting it from the driver. |
| 1240 | * Return value will be same as what is shown in scaling_cur_freq in sysfs. |
| 1241 | */ |
| 1242 | unsigned int cpufreq_quick_get(unsigned int cpu) |
| 1243 | { |
Dirk Brandewie | 9e21ba8 | 2013-02-06 09:02:08 -0800 | [diff] [blame] | 1244 | struct cpufreq_policy *policy; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1245 | struct cpufreq_driver *driver; |
| 1246 | unsigned int (*get)(unsigned int cpu); |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1247 | unsigned int ret_freq = 0; |
Venkatesh Pallipadi | 95235ca | 2005-12-02 10:43:20 -0800 | [diff] [blame] | 1248 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1249 | rcu_read_lock(); |
| 1250 | driver = rcu_dereference(cpufreq_driver); |
| 1251 | if (driver && driver->setpolicy && driver->get) { |
| 1252 | get = driver->get; |
| 1253 | rcu_read_unlock(); |
| 1254 | return get(cpu); |
| 1255 | } |
| 1256 | rcu_read_unlock(); |
Dirk Brandewie | 9e21ba8 | 2013-02-06 09:02:08 -0800 | [diff] [blame] | 1257 | |
| 1258 | policy = cpufreq_cpu_get(cpu); |
Venkatesh Pallipadi | 95235ca | 2005-12-02 10:43:20 -0800 | [diff] [blame] | 1259 | if (policy) { |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1260 | ret_freq = policy->cur; |
Venkatesh Pallipadi | 95235ca | 2005-12-02 10:43:20 -0800 | [diff] [blame] | 1261 | cpufreq_cpu_put(policy); |
| 1262 | } |
| 1263 | |
Dave Jones | 4d34a67 | 2008-02-07 16:33:49 -0500 | [diff] [blame] | 1264 | return ret_freq; |
Venkatesh Pallipadi | 95235ca | 2005-12-02 10:43:20 -0800 | [diff] [blame] | 1265 | } |
| 1266 | EXPORT_SYMBOL(cpufreq_quick_get); |
| 1267 | |
Jesse Barnes | 3d73710 | 2011-06-28 10:59:12 -0700 | [diff] [blame] | 1268 | /** |
| 1269 | * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU |
| 1270 | * @cpu: CPU number |
| 1271 | * |
| 1272 | * Just return the max possible frequency for a given CPU. |
| 1273 | */ |
| 1274 | unsigned int cpufreq_quick_get_max(unsigned int cpu) |
| 1275 | { |
| 1276 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
| 1277 | unsigned int ret_freq = 0; |
| 1278 | |
| 1279 | if (policy) { |
| 1280 | ret_freq = policy->max; |
| 1281 | cpufreq_cpu_put(policy); |
| 1282 | } |
| 1283 | |
| 1284 | return ret_freq; |
| 1285 | } |
| 1286 | EXPORT_SYMBOL(cpufreq_quick_get_max); |
| 1287 | |
Venkatesh Pallipadi | 95235ca | 2005-12-02 10:43:20 -0800 | [diff] [blame] | 1288 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1289 | static unsigned int __cpufreq_get(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | { |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 1291 | struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1292 | struct cpufreq_driver *driver; |
| 1293 | unsigned int (*get)(unsigned int cpu); |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1294 | unsigned int ret_freq = 0; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1295 | u8 flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1297 | |
| 1298 | rcu_read_lock(); |
| 1299 | driver = rcu_dereference(cpufreq_driver); |
| 1300 | if (!driver->get) { |
| 1301 | rcu_read_unlock(); |
Dave Jones | 4d34a67 | 2008-02-07 16:33:49 -0500 | [diff] [blame] | 1302 | return ret_freq; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1303 | } |
| 1304 | flags = driver->flags; |
| 1305 | get = driver->get; |
| 1306 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1308 | ret_freq = get(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1310 | if (ret_freq && policy->cur && |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1311 | !(flags & CPUFREQ_CONST_LOOPS)) { |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1312 | /* verify no discrepancy between actual and |
| 1313 | saved value exists */ |
| 1314 | if (unlikely(ret_freq != policy->cur)) { |
| 1315 | cpufreq_out_of_sync(cpu, policy->cur, ret_freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | schedule_work(&policy->update); |
| 1317 | } |
| 1318 | } |
| 1319 | |
Dave Jones | 4d34a67 | 2008-02-07 16:33:49 -0500 | [diff] [blame] | 1320 | return ret_freq; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1323 | /** |
| 1324 | * cpufreq_get - get the current CPU frequency (in kHz) |
| 1325 | * @cpu: CPU number |
| 1326 | * |
| 1327 | * Get the CPU current (static) CPU frequency |
| 1328 | */ |
| 1329 | unsigned int cpufreq_get(unsigned int cpu) |
| 1330 | { |
| 1331 | unsigned int ret_freq = 0; |
| 1332 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
| 1333 | |
| 1334 | if (!policy) |
| 1335 | goto out; |
| 1336 | |
| 1337 | if (unlikely(lock_policy_rwsem_read(cpu))) |
| 1338 | goto out_policy; |
| 1339 | |
| 1340 | ret_freq = __cpufreq_get(cpu); |
| 1341 | |
| 1342 | unlock_policy_rwsem_read(cpu); |
| 1343 | |
| 1344 | out_policy: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | cpufreq_cpu_put(policy); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1346 | out: |
Dave Jones | 4d34a67 | 2008-02-07 16:33:49 -0500 | [diff] [blame] | 1347 | return ret_freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | } |
| 1349 | EXPORT_SYMBOL(cpufreq_get); |
| 1350 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1351 | static struct subsys_interface cpufreq_interface = { |
| 1352 | .name = "cpufreq", |
| 1353 | .subsys = &cpu_subsys, |
| 1354 | .add_dev = cpufreq_add_dev, |
| 1355 | .remove_dev = cpufreq_remove_dev, |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1356 | }; |
| 1357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
| 1359 | /** |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1360 | * cpufreq_bp_suspend - Prepare the boot CPU for system suspend. |
| 1361 | * |
| 1362 | * This function is only executed for the boot processor. The other CPUs |
| 1363 | * have been put offline by means of CPU hotplug. |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1364 | */ |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1365 | static int cpufreq_bp_suspend(void) |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1366 | { |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1367 | int (*suspend)(struct cpufreq_policy *policy); |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1368 | int ret = 0; |
Dave Jones | 4bc5d34 | 2009-08-04 14:03:25 -0400 | [diff] [blame] | 1369 | |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1370 | int cpu = smp_processor_id(); |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1371 | struct cpufreq_policy *cpu_policy; |
| 1372 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1373 | pr_debug("suspending cpu %u\n", cpu); |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1374 | |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1375 | /* If there's no policy for the boot CPU, we have nothing to do. */ |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1376 | cpu_policy = cpufreq_cpu_get(cpu); |
| 1377 | if (!cpu_policy) |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1378 | return 0; |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1379 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1380 | rcu_read_lock(); |
| 1381 | suspend = rcu_dereference(cpufreq_driver)->suspend; |
| 1382 | rcu_read_unlock(); |
| 1383 | if (suspend) { |
| 1384 | ret = suspend(cpu_policy); |
Dominik Brodowski | ce6c399 | 2009-08-07 22:58:51 +0200 | [diff] [blame] | 1385 | if (ret) |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1386 | printk(KERN_ERR "cpufreq: suspend failed in ->suspend " |
| 1387 | "step on CPU %u\n", cpu_policy->cpu); |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1390 | cpufreq_cpu_put(cpu_policy); |
Dave Jones | c906049 | 2008-02-07 16:32:18 -0500 | [diff] [blame] | 1391 | return ret; |
Benjamin Herrenschmidt | 42d4dc3 | 2005-04-29 07:40:12 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1395 | * cpufreq_bp_resume - Restore proper frequency handling of the boot CPU. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | * |
| 1397 | * 1.) resume CPUfreq hardware support (cpufreq_driver->resume()) |
Dominik Brodowski | ce6c399 | 2009-08-07 22:58:51 +0200 | [diff] [blame] | 1398 | * 2.) schedule call cpufreq_update_policy() ASAP as interrupts are |
| 1399 | * restored. It will verify that the current freq is in sync with |
| 1400 | * what we believe it to be. This is a bit later than when it |
| 1401 | * should be, but nonethteless it's better than calling |
| 1402 | * cpufreq_driver->get() here which might re-enable interrupts... |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1403 | * |
| 1404 | * This function is only executed for the boot CPU. The other CPUs have not |
| 1405 | * been turned on yet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | */ |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1407 | static void cpufreq_bp_resume(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | { |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1409 | int ret = 0; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1410 | int (*resume)(struct cpufreq_policy *policy); |
Dave Jones | 4bc5d34 | 2009-08-04 14:03:25 -0400 | [diff] [blame] | 1411 | |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1412 | int cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | struct cpufreq_policy *cpu_policy; |
| 1414 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1415 | pr_debug("resuming cpu %u\n", cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1417 | /* If there's no policy for the boot CPU, we have nothing to do. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | cpu_policy = cpufreq_cpu_get(cpu); |
| 1419 | if (!cpu_policy) |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1420 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1422 | rcu_read_lock(); |
| 1423 | resume = rcu_dereference(cpufreq_driver)->resume; |
| 1424 | rcu_read_unlock(); |
| 1425 | |
| 1426 | if (resume) { |
| 1427 | ret = resume(cpu_policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | if (ret) { |
| 1429 | printk(KERN_ERR "cpufreq: resume failed in ->resume " |
| 1430 | "step on CPU %u\n", cpu_policy->cpu); |
Dave Jones | c906049 | 2008-02-07 16:32:18 -0500 | [diff] [blame] | 1431 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | } |
| 1434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | schedule_work(&cpu_policy->update); |
Dominik Brodowski | ce6c399 | 2009-08-07 22:58:51 +0200 | [diff] [blame] | 1436 | |
Dave Jones | c906049 | 2008-02-07 16:32:18 -0500 | [diff] [blame] | 1437 | fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | cpufreq_cpu_put(cpu_policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 1441 | static struct syscore_ops cpufreq_syscore_ops = { |
| 1442 | .suspend = cpufreq_bp_suspend, |
| 1443 | .resume = cpufreq_bp_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | }; |
| 1445 | |
Borislav Petkov | 9d95046 | 2013-01-20 10:24:28 +0000 | [diff] [blame] | 1446 | /** |
| 1447 | * cpufreq_get_current_driver - return current driver's name |
| 1448 | * |
| 1449 | * Return the name string of the currently loaded cpufreq driver |
| 1450 | * or NULL, if none. |
| 1451 | */ |
| 1452 | const char *cpufreq_get_current_driver(void) |
| 1453 | { |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1454 | struct cpufreq_driver *driver; |
| 1455 | const char *name = NULL; |
| 1456 | rcu_read_lock(); |
| 1457 | driver = rcu_dereference(cpufreq_driver); |
| 1458 | if (driver) |
| 1459 | name = driver->name; |
| 1460 | rcu_read_unlock(); |
| 1461 | return name; |
Borislav Petkov | 9d95046 | 2013-01-20 10:24:28 +0000 | [diff] [blame] | 1462 | } |
| 1463 | EXPORT_SYMBOL_GPL(cpufreq_get_current_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | |
| 1465 | /********************************************************************* |
| 1466 | * NOTIFIER LISTS INTERFACE * |
| 1467 | *********************************************************************/ |
| 1468 | |
| 1469 | /** |
| 1470 | * cpufreq_register_notifier - register a driver with cpufreq |
| 1471 | * @nb: notifier function to register |
| 1472 | * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER |
| 1473 | * |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 1474 | * Add a driver to one of two lists: either a list of drivers that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | * are notified about clock rate changes (once before and once after |
| 1476 | * the transition), or a list of drivers that are notified about |
| 1477 | * changes in cpufreq policy. |
| 1478 | * |
| 1479 | * This function may sleep, and has the same return conditions as |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1480 | * blocking_notifier_chain_register. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | */ |
| 1482 | int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list) |
| 1483 | { |
| 1484 | int ret; |
| 1485 | |
Dirk Brandewie | d5aaffa | 2013-01-17 16:22:21 +0000 | [diff] [blame] | 1486 | if (cpufreq_disabled()) |
| 1487 | return -EINVAL; |
| 1488 | |
Cesar Eduardo Barros | 74212ca | 2008-02-16 08:41:24 -0200 | [diff] [blame] | 1489 | WARN_ON(!init_cpufreq_transition_notifier_list_called); |
| 1490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | switch (list) { |
| 1492 | case CPUFREQ_TRANSITION_NOTIFIER: |
Alan Stern | b4dfdbb | 2006-10-04 02:17:06 -0700 | [diff] [blame] | 1493 | ret = srcu_notifier_chain_register( |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1494 | &cpufreq_transition_notifier_list, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | break; |
| 1496 | case CPUFREQ_POLICY_NOTIFIER: |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1497 | ret = blocking_notifier_chain_register( |
| 1498 | &cpufreq_policy_notifier_list, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | break; |
| 1500 | default: |
| 1501 | ret = -EINVAL; |
| 1502 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
| 1504 | return ret; |
| 1505 | } |
| 1506 | EXPORT_SYMBOL(cpufreq_register_notifier); |
| 1507 | |
| 1508 | |
| 1509 | /** |
| 1510 | * cpufreq_unregister_notifier - unregister a driver with cpufreq |
| 1511 | * @nb: notifier block to be unregistered |
| 1512 | * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER |
| 1513 | * |
| 1514 | * Remove a driver from the CPU frequency notifier list. |
| 1515 | * |
| 1516 | * This function may sleep, and has the same return conditions as |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1517 | * blocking_notifier_chain_unregister. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | */ |
| 1519 | int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list) |
| 1520 | { |
| 1521 | int ret; |
| 1522 | |
Dirk Brandewie | d5aaffa | 2013-01-17 16:22:21 +0000 | [diff] [blame] | 1523 | if (cpufreq_disabled()) |
| 1524 | return -EINVAL; |
| 1525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | switch (list) { |
| 1527 | case CPUFREQ_TRANSITION_NOTIFIER: |
Alan Stern | b4dfdbb | 2006-10-04 02:17:06 -0700 | [diff] [blame] | 1528 | ret = srcu_notifier_chain_unregister( |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1529 | &cpufreq_transition_notifier_list, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | break; |
| 1531 | case CPUFREQ_POLICY_NOTIFIER: |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1532 | ret = blocking_notifier_chain_unregister( |
| 1533 | &cpufreq_policy_notifier_list, nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | break; |
| 1535 | default: |
| 1536 | ret = -EINVAL; |
| 1537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | |
| 1539 | return ret; |
| 1540 | } |
| 1541 | EXPORT_SYMBOL(cpufreq_unregister_notifier); |
| 1542 | |
| 1543 | |
| 1544 | /********************************************************************* |
| 1545 | * GOVERNORS * |
| 1546 | *********************************************************************/ |
| 1547 | |
| 1548 | |
| 1549 | int __cpufreq_driver_target(struct cpufreq_policy *policy, |
| 1550 | unsigned int target_freq, |
| 1551 | unsigned int relation) |
| 1552 | { |
| 1553 | int retval = -EINVAL; |
Viresh Kumar | 7249924 | 2012-10-31 01:28:21 +0100 | [diff] [blame] | 1554 | unsigned int old_target_freq = target_freq; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1555 | int (*target)(struct cpufreq_policy *policy, |
| 1556 | unsigned int target_freq, |
| 1557 | unsigned int relation); |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1558 | |
Konrad Rzeszutek Wilk | a7b422c | 2012-03-13 19:18:39 -0400 | [diff] [blame] | 1559 | if (cpufreq_disabled()) |
| 1560 | return -ENODEV; |
| 1561 | |
Viresh Kumar | 7249924 | 2012-10-31 01:28:21 +0100 | [diff] [blame] | 1562 | /* Make sure that target_freq is within supported range */ |
| 1563 | if (target_freq > policy->max) |
| 1564 | target_freq = policy->max; |
| 1565 | if (target_freq < policy->min) |
| 1566 | target_freq = policy->min; |
| 1567 | |
| 1568 | pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n", |
| 1569 | policy->cpu, target_freq, relation, old_target_freq); |
Viresh Kumar | 5a1c022 | 2012-10-31 01:28:15 +0100 | [diff] [blame] | 1570 | |
| 1571 | if (target_freq == policy->cur) |
| 1572 | return 0; |
| 1573 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1574 | rcu_read_lock(); |
| 1575 | target = rcu_dereference(cpufreq_driver)->target; |
| 1576 | rcu_read_unlock(); |
| 1577 | if (target) |
| 1578 | retval = target(policy, target_freq, relation); |
Ashok Raj | 90d45d1 | 2005-11-08 21:34:24 -0800 | [diff] [blame] | 1579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | return retval; |
| 1581 | } |
| 1582 | EXPORT_SYMBOL_GPL(__cpufreq_driver_target); |
| 1583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | int cpufreq_driver_target(struct cpufreq_policy *policy, |
| 1585 | unsigned int target_freq, |
| 1586 | unsigned int relation) |
| 1587 | { |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1588 | int ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | |
| 1590 | policy = cpufreq_cpu_get(policy->cpu); |
| 1591 | if (!policy) |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1592 | goto no_policy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1594 | if (unlikely(lock_policy_rwsem_write(policy->cpu))) |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1595 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | |
| 1597 | ret = __cpufreq_driver_target(policy, target_freq, relation); |
| 1598 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1599 | unlock_policy_rwsem_write(policy->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1601 | fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | cpufreq_cpu_put(policy); |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1603 | no_policy: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | return ret; |
| 1605 | } |
| 1606 | EXPORT_SYMBOL_GPL(cpufreq_driver_target); |
| 1607 | |
venkatesh.pallipadi@intel.com | bf0b90e | 2008-08-04 11:59:07 -0700 | [diff] [blame] | 1608 | int __cpufreq_driver_getavg(struct cpufreq_policy *policy, unsigned int cpu) |
Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 1609 | { |
| 1610 | int ret = 0; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1611 | unsigned int (*getavg)(struct cpufreq_policy *policy, |
| 1612 | unsigned int cpu); |
Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 1613 | |
Dirk Brandewie | d5aaffa | 2013-01-17 16:22:21 +0000 | [diff] [blame] | 1614 | if (cpufreq_disabled()) |
| 1615 | return ret; |
| 1616 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1617 | rcu_read_lock(); |
| 1618 | getavg = rcu_dereference(cpufreq_driver)->getavg; |
| 1619 | rcu_read_unlock(); |
| 1620 | |
| 1621 | if (!getavg) |
Viresh Kumar | 0676f7f | 2012-10-24 23:39:48 +0200 | [diff] [blame] | 1622 | return 0; |
| 1623 | |
Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 1624 | policy = cpufreq_cpu_get(policy->cpu); |
| 1625 | if (!policy) |
| 1626 | return -EINVAL; |
| 1627 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1628 | ret = getavg(policy, cpu); |
Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 1629 | |
Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 1630 | cpufreq_cpu_put(policy); |
| 1631 | return ret; |
| 1632 | } |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1633 | EXPORT_SYMBOL_GPL(__cpufreq_driver_getavg); |
Venkatesh Pallipadi | dfde5d6 | 2006-10-03 12:38:45 -0700 | [diff] [blame] | 1634 | |
Arjan van de Ven | 153d7f3 | 2006-07-26 15:40:07 +0200 | [diff] [blame] | 1635 | /* |
Arjan van de Ven | 153d7f3 | 2006-07-26 15:40:07 +0200 | [diff] [blame] | 1636 | * when "event" is CPUFREQ_GOV_LIMITS |
| 1637 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1639 | static int __cpufreq_governor(struct cpufreq_policy *policy, |
| 1640 | unsigned int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | { |
Dave Jones | cc993ca | 2005-07-28 09:43:56 -0700 | [diff] [blame] | 1642 | int ret; |
Thomas Renninger | 6afde10 | 2007-10-02 13:28:13 -0700 | [diff] [blame] | 1643 | |
| 1644 | /* Only must be defined when default governor is known to have latency |
| 1645 | restrictions, like e.g. conservative or ondemand. |
| 1646 | That this is the case is already ensured in Kconfig |
| 1647 | */ |
| 1648 | #ifdef CONFIG_CPU_FREQ_GOV_PERFORMANCE |
| 1649 | struct cpufreq_governor *gov = &cpufreq_gov_performance; |
| 1650 | #else |
| 1651 | struct cpufreq_governor *gov = NULL; |
| 1652 | #endif |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 1653 | |
| 1654 | if (policy->governor->max_transition_latency && |
| 1655 | policy->cpuinfo.transition_latency > |
| 1656 | policy->governor->max_transition_latency) { |
Thomas Renninger | 6afde10 | 2007-10-02 13:28:13 -0700 | [diff] [blame] | 1657 | if (!gov) |
| 1658 | return -EINVAL; |
| 1659 | else { |
| 1660 | printk(KERN_WARNING "%s governor failed, too long" |
| 1661 | " transition latency of HW, fallback" |
| 1662 | " to %s governor\n", |
| 1663 | policy->governor->name, |
| 1664 | gov->name); |
| 1665 | policy->governor = gov; |
| 1666 | } |
Thomas Renninger | 1c25624 | 2007-10-02 13:28:12 -0700 | [diff] [blame] | 1667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
| 1669 | if (!try_module_get(policy->governor->owner)) |
| 1670 | return -EINVAL; |
| 1671 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1672 | pr_debug("__cpufreq_governor for CPU %u, event %u\n", |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1673 | policy->cpu, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | ret = policy->governor->governor(policy, event); |
| 1675 | |
Viresh Kumar | 4d5dcc4 | 2013-03-27 15:58:58 +0000 | [diff] [blame] | 1676 | if (!ret) { |
| 1677 | if (event == CPUFREQ_GOV_POLICY_INIT) |
| 1678 | policy->governor->initialized++; |
| 1679 | else if (event == CPUFREQ_GOV_POLICY_EXIT) |
| 1680 | policy->governor->initialized--; |
| 1681 | } |
Viresh Kumar | b394058 | 2013-02-01 05:42:58 +0000 | [diff] [blame] | 1682 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1683 | /* we keep one module reference alive for |
| 1684 | each CPU governed by this CPU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | if ((event != CPUFREQ_GOV_START) || ret) |
| 1686 | module_put(policy->governor->owner); |
| 1687 | if ((event == CPUFREQ_GOV_STOP) && !ret) |
| 1688 | module_put(policy->governor->owner); |
| 1689 | |
| 1690 | return ret; |
| 1691 | } |
| 1692 | |
| 1693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | int cpufreq_register_governor(struct cpufreq_governor *governor) |
| 1695 | { |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 1696 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
| 1698 | if (!governor) |
| 1699 | return -EINVAL; |
| 1700 | |
Konrad Rzeszutek Wilk | a7b422c | 2012-03-13 19:18:39 -0400 | [diff] [blame] | 1701 | if (cpufreq_disabled()) |
| 1702 | return -ENODEV; |
| 1703 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 1704 | mutex_lock(&cpufreq_governor_mutex); |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 1705 | |
Viresh Kumar | b394058 | 2013-02-01 05:42:58 +0000 | [diff] [blame] | 1706 | governor->initialized = 0; |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 1707 | err = -EBUSY; |
| 1708 | if (__find_governor(governor->name) == NULL) { |
| 1709 | err = 0; |
| 1710 | list_add(&governor->governor_list, &cpufreq_governor_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 1713 | mutex_unlock(&cpufreq_governor_mutex); |
Jeremy Fitzhardinge | 3bcb09a | 2006-07-06 12:30:26 -0700 | [diff] [blame] | 1714 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | EXPORT_SYMBOL_GPL(cpufreq_register_governor); |
| 1717 | |
| 1718 | |
| 1719 | void cpufreq_unregister_governor(struct cpufreq_governor *governor) |
| 1720 | { |
Prarit Bhargava | 90e41ba | 2009-11-12 09:18:46 -0500 | [diff] [blame] | 1721 | #ifdef CONFIG_HOTPLUG_CPU |
| 1722 | int cpu; |
| 1723 | #endif |
| 1724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | if (!governor) |
| 1726 | return; |
| 1727 | |
Konrad Rzeszutek Wilk | a7b422c | 2012-03-13 19:18:39 -0400 | [diff] [blame] | 1728 | if (cpufreq_disabled()) |
| 1729 | return; |
| 1730 | |
Prarit Bhargava | 90e41ba | 2009-11-12 09:18:46 -0500 | [diff] [blame] | 1731 | #ifdef CONFIG_HOTPLUG_CPU |
| 1732 | for_each_present_cpu(cpu) { |
| 1733 | if (cpu_online(cpu)) |
| 1734 | continue; |
| 1735 | if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) |
| 1736 | strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); |
| 1737 | } |
| 1738 | #endif |
| 1739 | |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 1740 | mutex_lock(&cpufreq_governor_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | list_del(&governor->governor_list); |
akpm@osdl.org | 3fc54d3 | 2006-01-13 15:54:22 -0800 | [diff] [blame] | 1742 | mutex_unlock(&cpufreq_governor_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | return; |
| 1744 | } |
| 1745 | EXPORT_SYMBOL_GPL(cpufreq_unregister_governor); |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | /********************************************************************* |
| 1750 | * POLICY INTERFACE * |
| 1751 | *********************************************************************/ |
| 1752 | |
| 1753 | /** |
| 1754 | * cpufreq_get_policy - get the current cpufreq_policy |
Dave Jones | 29464f2 | 2009-01-18 01:37:11 -0500 | [diff] [blame] | 1755 | * @policy: struct cpufreq_policy into which the current cpufreq_policy |
| 1756 | * is written |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | * |
| 1758 | * Reads the current cpufreq policy. |
| 1759 | */ |
| 1760 | int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) |
| 1761 | { |
| 1762 | struct cpufreq_policy *cpu_policy; |
| 1763 | if (!policy) |
| 1764 | return -EINVAL; |
| 1765 | |
| 1766 | cpu_policy = cpufreq_cpu_get(cpu); |
| 1767 | if (!cpu_policy) |
| 1768 | return -EINVAL; |
| 1769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | |
| 1772 | cpufreq_cpu_put(cpu_policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | return 0; |
| 1774 | } |
| 1775 | EXPORT_SYMBOL(cpufreq_get_policy); |
| 1776 | |
| 1777 | |
Arjan van de Ven | 153d7f3 | 2006-07-26 15:40:07 +0200 | [diff] [blame] | 1778 | /* |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1779 | * data : current policy. |
| 1780 | * policy : policy to be set. |
Arjan van de Ven | 153d7f3 | 2006-07-26 15:40:07 +0200 | [diff] [blame] | 1781 | */ |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1782 | static int __cpufreq_set_policy(struct cpufreq_policy *data, |
| 1783 | struct cpufreq_policy *policy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | { |
Viresh Kumar | 7bd353a | 2013-03-27 15:58:57 +0000 | [diff] [blame] | 1785 | int ret = 0, failed = 1; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1786 | struct cpufreq_driver *driver; |
| 1787 | int (*verify)(struct cpufreq_policy *policy); |
| 1788 | int (*setpolicy)(struct cpufreq_policy *policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1790 | pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | policy->min, policy->max); |
| 1792 | |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1793 | memcpy(&policy->cpuinfo, &data->cpuinfo, |
| 1794 | sizeof(struct cpufreq_cpuinfo)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | |
Yi Yang | 53391fa | 2008-01-30 13:33:34 +0100 | [diff] [blame] | 1796 | if (policy->min > data->max || policy->max < data->min) { |
Mattia Dongili | 9c9a43e | 2006-07-05 23:12:20 +0200 | [diff] [blame] | 1797 | ret = -EINVAL; |
| 1798 | goto error_out; |
| 1799 | } |
| 1800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | /* verify the cpu speed can be set within this limit */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1802 | rcu_read_lock(); |
| 1803 | driver = rcu_dereference(cpufreq_driver); |
| 1804 | verify = driver->verify; |
| 1805 | setpolicy = driver->setpolicy; |
| 1806 | rcu_read_unlock(); |
| 1807 | |
| 1808 | ret = verify(policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | if (ret) |
| 1810 | goto error_out; |
| 1811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | /* adjust if necessary - all reasons */ |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1813 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
| 1814 | CPUFREQ_ADJUST, policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | |
| 1816 | /* adjust if necessary - hardware incompatibility*/ |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1817 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
| 1818 | CPUFREQ_INCOMPATIBLE, policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | |
| 1820 | /* verify the cpu speed can be set within this limit, |
| 1821 | which might be different to the first one */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1822 | ret = verify(policy); |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1823 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | goto error_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
| 1826 | /* notification of the new policy */ |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 1827 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
| 1828 | CPUFREQ_NOTIFY, policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | |
Dave Jones | 7d5e350 | 2006-02-02 17:03:42 -0500 | [diff] [blame] | 1830 | data->min = policy->min; |
| 1831 | data->max = policy->max; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1833 | pr_debug("new min and max freqs are %u - %u kHz\n", |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1834 | data->min, data->max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1836 | if (setpolicy) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | data->policy = policy->policy; |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1838 | pr_debug("setting range\n"); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1839 | ret = setpolicy(policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | } else { |
| 1841 | if (policy->governor != data->governor) { |
| 1842 | /* save old, working values */ |
| 1843 | struct cpufreq_governor *old_gov = data->governor; |
| 1844 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1845 | pr_debug("governor switch\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | |
| 1847 | /* end old governor */ |
Viresh Kumar | 7bd353a | 2013-03-27 15:58:57 +0000 | [diff] [blame] | 1848 | if (data->governor) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); |
Viresh Kumar | 7bd353a | 2013-03-27 15:58:57 +0000 | [diff] [blame] | 1850 | __cpufreq_governor(data, |
| 1851 | CPUFREQ_GOV_POLICY_EXIT); |
| 1852 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | |
| 1854 | /* start new governor */ |
| 1855 | data->governor = policy->governor; |
Viresh Kumar | 7bd353a | 2013-03-27 15:58:57 +0000 | [diff] [blame] | 1856 | if (!__cpufreq_governor(data, CPUFREQ_GOV_POLICY_INIT)) { |
| 1857 | if (!__cpufreq_governor(data, CPUFREQ_GOV_START)) |
| 1858 | failed = 0; |
| 1859 | else |
| 1860 | __cpufreq_governor(data, |
| 1861 | CPUFREQ_GOV_POLICY_EXIT); |
| 1862 | } |
| 1863 | |
| 1864 | if (failed) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | /* new governor failed, so re-start old one */ |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1866 | pr_debug("starting governor %s failed\n", |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1867 | data->governor->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | if (old_gov) { |
| 1869 | data->governor = old_gov; |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1870 | __cpufreq_governor(data, |
Viresh Kumar | 7bd353a | 2013-03-27 15:58:57 +0000 | [diff] [blame] | 1871 | CPUFREQ_GOV_POLICY_INIT); |
| 1872 | __cpufreq_governor(data, |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1873 | CPUFREQ_GOV_START); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
| 1875 | ret = -EINVAL; |
| 1876 | goto error_out; |
| 1877 | } |
| 1878 | /* might be a policy change, too, so fall through */ |
| 1879 | } |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1880 | pr_debug("governor: change or update limits\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); |
| 1882 | } |
| 1883 | |
Dave Jones | 7d5e350 | 2006-02-02 17:03:42 -0500 | [diff] [blame] | 1884 | error_out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | return ret; |
| 1886 | } |
| 1887 | |
| 1888 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | * cpufreq_update_policy - re-evaluate an existing cpufreq policy |
| 1890 | * @cpu: CPU which shall be re-evaluated |
| 1891 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1892 | * Useful for policy notifiers which have different necessities |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | * at different times. |
| 1894 | */ |
| 1895 | int cpufreq_update_policy(unsigned int cpu) |
| 1896 | { |
| 1897 | struct cpufreq_policy *data = cpufreq_cpu_get(cpu); |
| 1898 | struct cpufreq_policy policy; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1899 | struct cpufreq_driver *driver; |
| 1900 | unsigned int (*get)(unsigned int cpu); |
| 1901 | int (*target)(struct cpufreq_policy *policy, |
| 1902 | unsigned int target_freq, |
| 1903 | unsigned int relation); |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1904 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1906 | if (!data) { |
| 1907 | ret = -ENODEV; |
| 1908 | goto no_policy; |
| 1909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1911 | if (unlikely(lock_policy_rwsem_write(cpu))) { |
| 1912 | ret = -EINVAL; |
| 1913 | goto fail; |
| 1914 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1916 | pr_debug("updating policy for CPU %u\n", cpu); |
Dave Jones | 7d5e350 | 2006-02-02 17:03:42 -0500 | [diff] [blame] | 1917 | memcpy(&policy, data, sizeof(struct cpufreq_policy)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | policy.min = data->user_policy.min; |
| 1919 | policy.max = data->user_policy.max; |
| 1920 | policy.policy = data->user_policy.policy; |
| 1921 | policy.governor = data->user_policy.governor; |
| 1922 | |
Thomas Renninger | 0961dd0 | 2006-01-26 18:46:33 +0100 | [diff] [blame] | 1923 | /* BIOS might change freq behind our back |
| 1924 | -> ask driver for current freq and notify governors about a change */ |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1925 | rcu_read_lock(); |
| 1926 | driver = rcu_access_pointer(cpufreq_driver); |
| 1927 | get = driver->get; |
| 1928 | target = driver->target; |
| 1929 | rcu_read_unlock(); |
| 1930 | if (get) { |
| 1931 | policy.cur = get(cpu); |
Thomas Renninger | a85f7bd | 2006-02-01 11:36:04 +0100 | [diff] [blame] | 1932 | if (!data->cur) { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 1933 | pr_debug("Driver did not initialize current freq"); |
Thomas Renninger | a85f7bd | 2006-02-01 11:36:04 +0100 | [diff] [blame] | 1934 | data->cur = policy.cur; |
| 1935 | } else { |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 1936 | if (data->cur != policy.cur && target) |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 1937 | cpufreq_out_of_sync(cpu, data->cur, |
| 1938 | policy.cur); |
Thomas Renninger | a85f7bd | 2006-02-01 11:36:04 +0100 | [diff] [blame] | 1939 | } |
Thomas Renninger | 0961dd0 | 2006-01-26 18:46:33 +0100 | [diff] [blame] | 1940 | } |
| 1941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | ret = __cpufreq_set_policy(data, &policy); |
| 1943 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1944 | unlock_policy_rwsem_write(cpu); |
| 1945 | |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1946 | fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | cpufreq_cpu_put(data); |
Julia Lawall | f1829e4 | 2008-07-25 22:44:53 +0200 | [diff] [blame] | 1948 | no_policy: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | return ret; |
| 1950 | } |
| 1951 | EXPORT_SYMBOL(cpufreq_update_policy); |
| 1952 | |
Satyam Sharma | dd184a0 | 2007-10-02 13:28:14 -0700 | [diff] [blame] | 1953 | static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb, |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1954 | unsigned long action, void *hcpu) |
| 1955 | { |
| 1956 | unsigned int cpu = (unsigned long)hcpu; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1957 | struct device *dev; |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1958 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1959 | dev = get_cpu_device(cpu); |
| 1960 | if (dev) { |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1961 | switch (action) { |
| 1962 | case CPU_ONLINE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 1963 | case CPU_ONLINE_FROZEN: |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1964 | cpufreq_add_dev(dev, NULL); |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1965 | break; |
| 1966 | case CPU_DOWN_PREPARE: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 1967 | case CPU_DOWN_PREPARE_FROZEN: |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1968 | __cpufreq_remove_dev(dev, NULL); |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1969 | break; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 1970 | case CPU_DOWN_FAILED: |
Rafael J. Wysocki | 8bb7844 | 2007-05-09 02:35:10 -0700 | [diff] [blame] | 1971 | case CPU_DOWN_FAILED_FROZEN: |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 1972 | cpufreq_add_dev(dev, NULL); |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1973 | break; |
| 1974 | } |
| 1975 | } |
| 1976 | return NOTIFY_OK; |
| 1977 | } |
| 1978 | |
Neal Buckendahl | 9c36f74 | 2010-06-22 22:02:44 -0500 | [diff] [blame] | 1979 | static struct notifier_block __refdata cpufreq_cpu_notifier = { |
Ashok Raj | c32b6b8 | 2005-10-30 14:59:54 -0800 | [diff] [blame] | 1980 | .notifier_call = cpufreq_cpu_callback, |
| 1981 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | |
| 1983 | /********************************************************************* |
| 1984 | * REGISTER / UNREGISTER CPUFREQ DRIVER * |
| 1985 | *********************************************************************/ |
| 1986 | |
| 1987 | /** |
| 1988 | * cpufreq_register_driver - register a CPU Frequency driver |
| 1989 | * @driver_data: A struct cpufreq_driver containing the values# |
| 1990 | * submitted by the CPU Frequency driver. |
| 1991 | * |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 1992 | * Registers a CPU Frequency driver to this core code. This code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | * returns zero on success, -EBUSY when another driver got here first |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 1994 | * (and isn't unregistered in the meantime). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | * |
| 1996 | */ |
Linus Torvalds | 221dee2 | 2007-02-26 14:55:48 -0800 | [diff] [blame] | 1997 | int cpufreq_register_driver(struct cpufreq_driver *driver_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | { |
| 1999 | unsigned long flags; |
| 2000 | int ret; |
| 2001 | |
Konrad Rzeszutek Wilk | a7b422c | 2012-03-13 19:18:39 -0400 | [diff] [blame] | 2002 | if (cpufreq_disabled()) |
| 2003 | return -ENODEV; |
| 2004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | if (!driver_data || !driver_data->verify || !driver_data->init || |
| 2006 | ((!driver_data->setpolicy) && (!driver_data->target))) |
| 2007 | return -EINVAL; |
| 2008 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 2009 | pr_debug("trying to register driver %s\n", driver_data->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
| 2011 | if (driver_data->setpolicy) |
| 2012 | driver_data->flags |= CPUFREQ_CONST_LOOPS; |
| 2013 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 2014 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2015 | if (rcu_access_pointer(cpufreq_driver)) { |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 2016 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | return -EBUSY; |
| 2018 | } |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2019 | rcu_assign_pointer(cpufreq_driver, driver_data); |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 2020 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2021 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 2023 | ret = subsys_interface_register(&cpufreq_interface); |
Jiri Slaby | 8f5bc2a | 2011-03-01 17:41:10 +0100 | [diff] [blame] | 2024 | if (ret) |
| 2025 | goto err_null_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2027 | if (!(driver_data->flags & CPUFREQ_STICKY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | int i; |
| 2029 | ret = -ENODEV; |
| 2030 | |
| 2031 | /* check for at least one working CPU */ |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 2032 | for (i = 0; i < nr_cpu_ids; i++) |
| 2033 | if (cpu_possible(i) && per_cpu(cpufreq_cpu_data, i)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | ret = 0; |
Mike Travis | 7a6aedf | 2008-03-25 15:06:53 -0700 | [diff] [blame] | 2035 | break; |
| 2036 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
| 2038 | /* if all ->init() calls failed, unregister */ |
| 2039 | if (ret) { |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 2040 | pr_debug("no CPU initialized for driver %s\n", |
Gautham R Shenoy | e08f5f5 | 2006-10-26 16:20:58 +0530 | [diff] [blame] | 2041 | driver_data->name); |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 2042 | goto err_if_unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | |
Jiri Slaby | 8f5bc2a | 2011-03-01 17:41:10 +0100 | [diff] [blame] | 2046 | register_hotcpu_notifier(&cpufreq_cpu_notifier); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 2047 | pr_debug("driver %s up and running\n", driver_data->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | |
Jiri Slaby | 8f5bc2a | 2011-03-01 17:41:10 +0100 | [diff] [blame] | 2049 | return 0; |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 2050 | err_if_unreg: |
| 2051 | subsys_interface_unregister(&cpufreq_interface); |
Jiri Slaby | 8f5bc2a | 2011-03-01 17:41:10 +0100 | [diff] [blame] | 2052 | err_null_driver: |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 2053 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2054 | rcu_assign_pointer(cpufreq_driver, NULL); |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 2055 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2056 | synchronize_rcu(); |
Dave Jones | 4d34a67 | 2008-02-07 16:33:49 -0500 | [diff] [blame] | 2057 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | } |
| 2059 | EXPORT_SYMBOL_GPL(cpufreq_register_driver); |
| 2060 | |
| 2061 | |
| 2062 | /** |
| 2063 | * cpufreq_unregister_driver - unregister the current CPUFreq driver |
| 2064 | * |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 2065 | * Unregister the current CPUFreq driver. Only call this if you have |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | * the right to do so, i.e. if you have succeeded in initialising before! |
| 2067 | * Returns zero if successful, and -EINVAL if the cpufreq_driver is |
| 2068 | * currently not initialised. |
| 2069 | */ |
Linus Torvalds | 221dee2 | 2007-02-26 14:55:48 -0800 | [diff] [blame] | 2070 | int cpufreq_unregister_driver(struct cpufreq_driver *driver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | { |
| 2072 | unsigned long flags; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2073 | struct cpufreq_driver *old_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2075 | rcu_read_lock(); |
| 2076 | old_driver = rcu_access_pointer(cpufreq_driver); |
| 2077 | if (!old_driver || (driver != old_driver)) { |
| 2078 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | return -EINVAL; |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2080 | } |
| 2081 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 2083 | pr_debug("unregistering driver %s\n", driver->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 2085 | subsys_interface_unregister(&cpufreq_interface); |
Chandra Seetharaman | 65edc68 | 2006-06-27 02:54:08 -0700 | [diff] [blame] | 2086 | unregister_hotcpu_notifier(&cpufreq_cpu_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 2088 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2089 | rcu_assign_pointer(cpufreq_driver, NULL); |
Nathan Zimmer | 0d1857a | 2013-02-22 16:24:34 +0000 | [diff] [blame] | 2090 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
Nathan Zimmer | 5800043 | 2013-04-04 14:53:25 +0000 | [diff] [blame] | 2091 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | |
| 2093 | return 0; |
| 2094 | } |
| 2095 | EXPORT_SYMBOL_GPL(cpufreq_unregister_driver); |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 2096 | |
| 2097 | static int __init cpufreq_core_init(void) |
| 2098 | { |
| 2099 | int cpu; |
| 2100 | |
Konrad Rzeszutek Wilk | a7b422c | 2012-03-13 19:18:39 -0400 | [diff] [blame] | 2101 | if (cpufreq_disabled()) |
| 2102 | return -ENODEV; |
| 2103 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 2104 | for_each_possible_cpu(cpu) { |
Tejun Heo | f162506 | 2009-10-29 22:34:13 +0900 | [diff] [blame] | 2105 | per_cpu(cpufreq_policy_cpu, cpu) = -1; |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 2106 | init_rwsem(&per_cpu(cpu_policy_rwsem, cpu)); |
| 2107 | } |
Thomas Renninger | 8aa84ad | 2009-07-24 15:25:05 +0200 | [diff] [blame] | 2108 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 2109 | cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); |
Thomas Renninger | 8aa84ad | 2009-07-24 15:25:05 +0200 | [diff] [blame] | 2110 | BUG_ON(!cpufreq_global_kobject); |
Rafael J. Wysocki | e00e56d | 2011-03-23 22:16:32 +0100 | [diff] [blame] | 2111 | register_syscore_ops(&cpufreq_syscore_ops); |
Thomas Renninger | 8aa84ad | 2009-07-24 15:25:05 +0200 | [diff] [blame] | 2112 | |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 2113 | return 0; |
| 2114 | } |
Venkatesh Pallipadi | 5a01f2e | 2007-02-05 16:12:44 -0800 | [diff] [blame] | 2115 | core_initcall(cpufreq_core_init); |