aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-03-17 08:51:39 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-03-17 08:51:39 -0400
commit15afee3aeac874ac274d3d8e8783b3ada4125672 (patch)
tree4fa5c63100d15ce16cb91e89f5fc5695699978ba /drivers/cpufreq
parent2ed99e39cb9392312c100d9da591c20641c64d12 (diff)
parent2449d33a40553504867f407dd713e9bcf6f9fe24 (diff)
Merge back earlier 'pm-cpufreq' material.
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/Kconfig2
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c1
-rw-r--r--drivers/cpufreq/arm_big_little.c1
-rw-r--r--drivers/cpufreq/blackfin-cpufreq.c1
-rw-r--r--drivers/cpufreq/cpufreq-cpu0.c1
-rw-r--r--drivers/cpufreq/cpufreq.c415
-rw-r--r--drivers/cpufreq/cpufreq_stats.c38
-rw-r--r--drivers/cpufreq/cris-artpec3-cpufreq.c1
-rw-r--r--drivers/cpufreq/cris-etraxfs-cpufreq.c1
-rw-r--r--drivers/cpufreq/davinci-cpufreq.c1
-rw-r--r--drivers/cpufreq/e_powersaver.c1
-rw-r--r--drivers/cpufreq/elanfreq.c1
-rw-r--r--drivers/cpufreq/exynos-cpufreq.c97
-rw-r--r--drivers/cpufreq/exynos5440-cpufreq.c1
-rw-r--r--drivers/cpufreq/freq_table.c46
-rw-r--r--drivers/cpufreq/ia64-acpi-cpufreq.c1
-rw-r--r--drivers/cpufreq/imx6q-cpufreq.c1
-rw-r--r--drivers/cpufreq/intel_pstate.c26
-rw-r--r--drivers/cpufreq/kirkwood-cpufreq.c1
-rw-r--r--drivers/cpufreq/longhaul.c1
-rw-r--r--drivers/cpufreq/loongson2_cpufreq.c1
-rw-r--r--drivers/cpufreq/omap-cpufreq.c1
-rw-r--r--drivers/cpufreq/p4-clockmod.c1
-rw-r--r--drivers/cpufreq/pasemi-cpufreq.c1
-rw-r--r--drivers/cpufreq/powernow-k6.c1
-rw-r--r--drivers/cpufreq/powernow-k7.c2
-rw-r--r--drivers/cpufreq/powernow-k8.c2
-rw-r--r--drivers/cpufreq/ppc-corenet-cpufreq.c1
-rw-r--r--drivers/cpufreq/ppc_cbe_cpufreq.c1
-rw-r--r--drivers/cpufreq/pxa2xx-cpufreq.c1
-rw-r--r--drivers/cpufreq/pxa3xx-cpufreq.c1
-rw-r--r--drivers/cpufreq/s5pv210-cpufreq.c49
-rw-r--r--drivers/cpufreq/sc520_freq.c1
-rw-r--r--drivers/cpufreq/sh-cpufreq.c1
-rw-r--r--drivers/cpufreq/sparc-us2e-cpufreq.c4
-rw-r--r--drivers/cpufreq/sparc-us3-cpufreq.c4
-rw-r--r--drivers/cpufreq/spear-cpufreq.c14
-rw-r--r--drivers/cpufreq/speedstep-centrino.c2
-rw-r--r--drivers/cpufreq/speedstep-ich.c1
-rw-r--r--drivers/cpufreq/speedstep-smi.c1
-rw-r--r--drivers/cpufreq/tegra-cpufreq.c47
41 files changed, 271 insertions, 504 deletions
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig
index 4b029c0944af..1fbe11f2a146 100644
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -200,7 +200,7 @@ source "drivers/cpufreq/Kconfig.x86"
200endmenu 200endmenu
201 201
202menu "ARM CPU frequency scaling drivers" 202menu "ARM CPU frequency scaling drivers"
203depends on ARM 203depends on ARM || ARM64
204source "drivers/cpufreq/Kconfig.arm" 204source "drivers/cpufreq/Kconfig.arm"
205endmenu 205endmenu
206 206
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 18448a7e9f86..822ca03a87f7 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -855,7 +855,6 @@ static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
855 pr_debug("acpi_cpufreq_cpu_exit\n"); 855 pr_debug("acpi_cpufreq_cpu_exit\n");
856 856
857 if (data) { 857 if (data) {
858 cpufreq_frequency_table_put_attr(policy->cpu);
859 per_cpu(acfreq_data, policy->cpu) = NULL; 858 per_cpu(acfreq_data, policy->cpu) = NULL;
860 acpi_processor_unregister_performance(data->acpi_data, 859 acpi_processor_unregister_performance(data->acpi_data,
861 policy->cpu); 860 policy->cpu);
diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c
index 72f87e9317e3..3d8707848035 100644
--- a/drivers/cpufreq/arm_big_little.c
+++ b/drivers/cpufreq/arm_big_little.c
@@ -478,7 +478,6 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
478 return -ENODEV; 478 return -ENODEV;
479 } 479 }
480 480
481 cpufreq_frequency_table_put_attr(policy->cpu);
482 put_cluster_clk_and_freq_table(cpu_dev); 481 put_cluster_clk_and_freq_table(cpu_dev);
483 dev_dbg(cpu_dev, "%s: Exited, cpu: %d\n", __func__, policy->cpu); 482 dev_dbg(cpu_dev, "%s: Exited, cpu: %d\n", __func__, policy->cpu);
484 483
diff --git a/drivers/cpufreq/blackfin-cpufreq.c b/drivers/cpufreq/blackfin-cpufreq.c
index e9e63fc9c2c9..a9f8e5bd0716 100644
--- a/drivers/cpufreq/blackfin-cpufreq.c
+++ b/drivers/cpufreq/blackfin-cpufreq.c
@@ -195,7 +195,6 @@ static struct cpufreq_driver bfin_driver = {
195 .target_index = bfin_target, 195 .target_index = bfin_target,
196 .get = bfin_getfreq_khz, 196 .get = bfin_getfreq_khz,
197 .init = __bfin_cpu_init, 197 .init = __bfin_cpu_init,
198 .exit = cpufreq_generic_exit,
199 .name = "bfin cpufreq", 198 .name = "bfin cpufreq",
200 .attr = cpufreq_generic_attr, 199 .attr = cpufreq_generic_attr,
201}; 200};
diff --git a/drivers/cpufreq/cpufreq-cpu0.c b/drivers/cpufreq/cpufreq-cpu0.c
index 0c12ffc0ebcb..1bf6bbac3e03 100644
--- a/drivers/cpufreq/cpufreq-cpu0.c
+++ b/drivers/cpufreq/cpufreq-cpu0.c
@@ -109,7 +109,6 @@ static struct cpufreq_driver cpu0_cpufreq_driver = {
109 .target_index = cpu0_set_target, 109 .target_index = cpu0_set_target,
110 .get = cpufreq_generic_get, 110 .get = cpufreq_generic_get,
111 .init = cpu0_cpufreq_init, 111 .init = cpu0_cpufreq_init,
112 .exit = cpufreq_generic_exit,
113 .name = "generic_cpu0", 112 .name = "generic_cpu0",
114 .attr = cpufreq_generic_attr, 113 .attr = cpufreq_generic_attr,
115}; 114};
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 199b52b7c3e1..2677ff1c0a2c 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -26,7 +26,7 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/syscore_ops.h> 29#include <linux/suspend.h>
30#include <linux/tick.h> 30#include <linux/tick.h>
31#include <trace/events/power.h> 31#include <trace/events/power.h>
32 32
@@ -42,10 +42,11 @@ static DEFINE_RWLOCK(cpufreq_driver_lock);
42DEFINE_MUTEX(cpufreq_governor_lock); 42DEFINE_MUTEX(cpufreq_governor_lock);
43static LIST_HEAD(cpufreq_policy_list); 43static LIST_HEAD(cpufreq_policy_list);
44 44
45#ifdef CONFIG_HOTPLUG_CPU
46/* This one keeps track of the previously set governor of a removed CPU */ 45/* This one keeps track of the previously set governor of a removed CPU */
47static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); 46static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor);
48#endif 47
48/* Flag to suspend/resume CPUFreq governors */
49static bool cpufreq_suspended;
49 50
50static inline bool has_target(void) 51static inline bool has_target(void)
51{ 52{
@@ -181,8 +182,8 @@ unsigned int cpufreq_generic_get(unsigned int cpu)
181 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); 182 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
182 183
183 if (!policy || IS_ERR(policy->clk)) { 184 if (!policy || IS_ERR(policy->clk)) {
184 pr_err("%s: No %s associated to cpu: %d\n", __func__, 185 pr_err("%s: No %s associated to cpu: %d\n",
185 policy ? "clk" : "policy", cpu); 186 __func__, policy ? "clk" : "policy", cpu);
186 return 0; 187 return 0;
187 } 188 }
188 189
@@ -190,6 +191,12 @@ unsigned int cpufreq_generic_get(unsigned int cpu)
190} 191}
191EXPORT_SYMBOL_GPL(cpufreq_generic_get); 192EXPORT_SYMBOL_GPL(cpufreq_generic_get);
192 193
194/* Only for cpufreq core internal use */
195struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu)
196{
197 return per_cpu(cpufreq_cpu_data, cpu);
198}
199
193struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) 200struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
194{ 201{
195 struct cpufreq_policy *policy = NULL; 202 struct cpufreq_policy *policy = NULL;
@@ -254,15 +261,15 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
254 if (!l_p_j_ref_freq) { 261 if (!l_p_j_ref_freq) {
255 l_p_j_ref = loops_per_jiffy; 262 l_p_j_ref = loops_per_jiffy;
256 l_p_j_ref_freq = ci->old; 263 l_p_j_ref_freq = ci->old;
257 pr_debug("saving %lu as reference value for loops_per_jiffy; " 264 pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n",
258 "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); 265 l_p_j_ref, l_p_j_ref_freq);
259 } 266 }
260 if ((val == CPUFREQ_POSTCHANGE && ci->old != ci->new) || 267 if ((val == CPUFREQ_POSTCHANGE && ci->old != ci->new) ||
261 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { 268 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
262 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, 269 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
263 ci->new); 270 ci->new);
264 pr_debug("scaling loops_per_jiffy to %lu " 271 pr_debug("scaling loops_per_jiffy to %lu for frequency %u kHz\n",
265 "for frequency %u kHz\n", loops_per_jiffy, ci->new); 272 loops_per_jiffy, ci->new);
266 } 273 }
267} 274}
268#else 275#else
@@ -282,7 +289,7 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
282 289
283 freqs->flags = cpufreq_driver->flags; 290 freqs->flags = cpufreq_driver->flags;
284 pr_debug("notification %u of frequency transition to %u kHz\n", 291 pr_debug("notification %u of frequency transition to %u kHz\n",
285 state, freqs->new); 292 state, freqs->new);
286 293
287 switch (state) { 294 switch (state) {
288 295
@@ -294,9 +301,8 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
294 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { 301 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
295 if ((policy) && (policy->cpu == freqs->cpu) && 302 if ((policy) && (policy->cpu == freqs->cpu) &&
296 (policy->cur) && (policy->cur != freqs->old)) { 303 (policy->cur) && (policy->cur != freqs->old)) {
297 pr_debug("Warning: CPU frequency is" 304 pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
298 " %u, cpufreq assumed %u kHz.\n", 305 freqs->old, policy->cur);
299 freqs->old, policy->cur);
300 freqs->old = policy->cur; 306 freqs->old = policy->cur;
301 } 307 }
302 } 308 }
@@ -307,8 +313,8 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
307 313
308 case CPUFREQ_POSTCHANGE: 314 case CPUFREQ_POSTCHANGE:
309 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); 315 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
310 pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, 316 pr_debug("FREQ: %lu - CPU: %lu\n",
311 (unsigned long)freqs->cpu); 317 (unsigned long)freqs->new, (unsigned long)freqs->cpu);
312 trace_cpu_frequency(freqs->new, freqs->cpu); 318 trace_cpu_frequency(freqs->new, freqs->cpu);
313 srcu_notifier_call_chain(&cpufreq_transition_notifier_list, 319 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
314 CPUFREQ_POSTCHANGE, freqs); 320 CPUFREQ_POSTCHANGE, freqs);
@@ -352,7 +358,7 @@ EXPORT_SYMBOL_GPL(cpufreq_notify_post_transition);
352/********************************************************************* 358/*********************************************************************
353 * SYSFS INTERFACE * 359 * SYSFS INTERFACE *
354 *********************************************************************/ 360 *********************************************************************/
355ssize_t show_boost(struct kobject *kobj, 361static ssize_t show_boost(struct kobject *kobj,
356 struct attribute *attr, char *buf) 362 struct attribute *attr, char *buf)
357{ 363{
358 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); 364 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
@@ -368,13 +374,13 @@ static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
368 return -EINVAL; 374 return -EINVAL;
369 375
370 if (cpufreq_boost_trigger_state(enable)) { 376 if (cpufreq_boost_trigger_state(enable)) {
371 pr_err("%s: Cannot %s BOOST!\n", __func__, 377 pr_err("%s: Cannot %s BOOST!\n",
372 enable ? "enable" : "disable"); 378 __func__, enable ? "enable" : "disable");
373 return -EINVAL; 379 return -EINVAL;
374 } 380 }
375 381
376 pr_debug("%s: cpufreq BOOST %s\n", __func__, 382 pr_debug("%s: cpufreq BOOST %s\n",
377 enable ? "enabled" : "disabled"); 383 __func__, enable ? "enabled" : "disabled");
378 384
379 return count; 385 return count;
380} 386}
@@ -879,18 +885,25 @@ err_out_kobj_put:
879 885
880static void cpufreq_init_policy(struct cpufreq_policy *policy) 886static void cpufreq_init_policy(struct cpufreq_policy *policy)
881{ 887{
888 struct cpufreq_governor *gov = NULL;
882 struct cpufreq_policy new_policy; 889 struct cpufreq_policy new_policy;
883 int ret = 0; 890 int ret = 0;
884 891
885 memcpy(&new_policy, policy, sizeof(*policy)); 892 memcpy(&new_policy, policy, sizeof(*policy));
886 893
894 /* Update governor of new_policy to the governor used before hotplug */
895 gov = __find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu));
896 if (gov)
897 pr_debug("Restoring governor %s for cpu %d\n",
898 policy->governor->name, policy->cpu);
899 else
900 gov = CPUFREQ_DEFAULT_GOVERNOR;
901
902 new_policy.governor = gov;
903
887 /* Use the default policy if its valid. */ 904 /* Use the default policy if its valid. */
888 if (cpufreq_driver->setpolicy) 905 if (cpufreq_driver->setpolicy)
889 cpufreq_parse_governor(policy->governor->name, 906 cpufreq_parse_governor(gov->name, &new_policy.policy, NULL);
890 &new_policy.policy, NULL);
891
892 /* assure that the starting sequence is run in cpufreq_set_policy */
893 policy->governor = NULL;
894 907
895 /* set default policy */ 908 /* set default policy */
896 ret = cpufreq_set_policy(policy, &new_policy); 909 ret = cpufreq_set_policy(policy, &new_policy);
@@ -949,6 +962,8 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
949 962
950 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 963 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
951 964
965 policy->governor = NULL;
966
952 return policy; 967 return policy;
953} 968}
954 969
@@ -1022,21 +1037,19 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1022 1037
1023 up_write(&policy->rwsem); 1038 up_write(&policy->rwsem);
1024 1039
1025 cpufreq_frequency_table_update_policy_cpu(policy);
1026 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1040 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1027 CPUFREQ_UPDATE_POLICY_CPU, policy); 1041 CPUFREQ_UPDATE_POLICY_CPU, policy);
1028} 1042}
1029 1043
1030static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, 1044static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1031 bool frozen)
1032{ 1045{
1033 unsigned int j, cpu = dev->id; 1046 unsigned int j, cpu = dev->id;
1034 int ret = -ENOMEM; 1047 int ret = -ENOMEM;
1035 struct cpufreq_policy *policy; 1048 struct cpufreq_policy *policy;
1036 unsigned long flags; 1049 unsigned long flags;
1050 bool recover_policy = cpufreq_suspended;
1037#ifdef CONFIG_HOTPLUG_CPU 1051#ifdef CONFIG_HOTPLUG_CPU
1038 struct cpufreq_policy *tpolicy; 1052 struct cpufreq_policy *tpolicy;
1039 struct cpufreq_governor *gov;
1040#endif 1053#endif
1041 1054
1042 if (cpu_is_offline(cpu)) 1055 if (cpu_is_offline(cpu))
@@ -1075,9 +1088,9 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1075 * Restore the saved policy when doing light-weight init and fall back 1088 * Restore the saved policy when doing light-weight init and fall back
1076 * to the full init if that fails. 1089 * to the full init if that fails.
1077 */ 1090 */
1078 policy = frozen ? cpufreq_policy_restore(cpu) : NULL; 1091 policy = recover_policy ? cpufreq_policy_restore(cpu) : NULL;
1079 if (!policy) { 1092 if (!policy) {
1080 frozen = false; 1093 recover_policy = false;
1081 policy = cpufreq_policy_alloc(); 1094 policy = cpufreq_policy_alloc();
1082 if (!policy) 1095 if (!policy)
1083 goto nomem_out; 1096 goto nomem_out;
@@ -1089,12 +1102,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1089 * the creation of a brand new one. So we need to perform this update 1102 * the creation of a brand new one. So we need to perform this update
1090 * by invoking update_policy_cpu(). 1103 * by invoking update_policy_cpu().
1091 */ 1104 */
1092 if (frozen && cpu != policy->cpu) 1105 if (recover_policy && cpu != policy->cpu)
1093 update_policy_cpu(policy, cpu); 1106 update_policy_cpu(policy, cpu);
1094 else 1107 else
1095 policy->cpu = cpu; 1108 policy->cpu = cpu;
1096 1109
1097 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
1098 cpumask_copy(policy->cpus, cpumask_of(cpu)); 1110 cpumask_copy(policy->cpus, cpumask_of(cpu));
1099 1111
1100 init_completion(&policy->kobj_unregister); 1112 init_completion(&policy->kobj_unregister);
@@ -1118,7 +1130,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1118 */ 1130 */
1119 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); 1131 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1120 1132
1121 if (!frozen) { 1133 if (!recover_policy) {
1122 policy->user_policy.min = policy->min; 1134 policy->user_policy.min = policy->min;
1123 policy->user_policy.max = policy->max; 1135 policy->user_policy.max = policy->max;
1124 } 1136 }
@@ -1180,16 +1192,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1180 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1192 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1181 CPUFREQ_START, policy); 1193 CPUFREQ_START, policy);
1182 1194
1183#ifdef CONFIG_HOTPLUG_CPU 1195 if (!recover_policy) {
1184 gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu));
1185 if (gov) {
1186 policy->governor = gov;
1187 pr_debug("Restoring governor %s for cpu %d\n",
1188 policy->governor->name, cpu);
1189 }
1190#endif
1191
1192 if (!frozen) {
1193 ret = cpufreq_add_dev_interface(policy, dev); 1196 ret = cpufreq_add_dev_interface(policy, dev);
1194 if (ret) 1197 if (ret)
1195 goto err_out_unregister; 1198 goto err_out_unregister;
@@ -1203,7 +1206,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1203 1206
1204 cpufreq_init_policy(policy); 1207 cpufreq_init_policy(policy);
1205 1208
1206 if (!frozen) { 1209 if (!recover_policy) {
1207 policy->user_policy.policy = policy->policy; 1210 policy->user_policy.policy = policy->policy;
1208 policy->user_policy.governor = policy->governor; 1211 policy->user_policy.governor = policy->governor;
1209 } 1212 }
@@ -1226,7 +1229,7 @@ err_get_freq:
1226 if (cpufreq_driver->exit) 1229 if (cpufreq_driver->exit)
1227 cpufreq_driver->exit(policy); 1230 cpufreq_driver->exit(policy);
1228err_set_policy_cpu: 1231err_set_policy_cpu:
1229 if (frozen) { 1232 if (recover_policy) {
1230 /* Do not leave stale fallback data behind. */ 1233 /* Do not leave stale fallback data behind. */
1231 per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL; 1234 per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL;
1232 cpufreq_policy_put_kobj(policy); 1235 cpufreq_policy_put_kobj(policy);
@@ -1250,7 +1253,7 @@ nomem_out:
1250 */ 1253 */
1251static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1254static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1252{ 1255{
1253 return __cpufreq_add_dev(dev, sif, false); 1256 return __cpufreq_add_dev(dev, sif);
1254} 1257}
1255 1258
1256static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, 1259static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
@@ -1265,7 +1268,7 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1265 sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); 1268 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1266 ret = kobject_move(&policy->kobj, &cpu_dev->kobj); 1269 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1267 if (ret) { 1270 if (ret) {
1268 pr_err("%s: Failed to move kobj: %d", __func__, ret); 1271 pr_err("%s: Failed to move kobj: %d\n", __func__, ret);
1269 1272
1270 down_write(&policy->rwsem); 1273 down_write(&policy->rwsem);
1271 cpumask_set_cpu(old_cpu, policy->cpus); 1274 cpumask_set_cpu(old_cpu, policy->cpus);
@@ -1281,8 +1284,7 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1281} 1284}
1282 1285
1283static int __cpufreq_remove_dev_prepare(struct device *dev, 1286static int __cpufreq_remove_dev_prepare(struct device *dev,
1284 struct subsys_interface *sif, 1287 struct subsys_interface *sif)
1285 bool frozen)
1286{ 1288{
1287 unsigned int cpu = dev->id, cpus; 1289 unsigned int cpu = dev->id, cpus;
1288 int new_cpu, ret; 1290 int new_cpu, ret;
@@ -1296,7 +1298,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1296 policy = per_cpu(cpufreq_cpu_data, cpu); 1298 policy = per_cpu(cpufreq_cpu_data, cpu);
1297 1299
1298 /* Save the policy somewhere when doing a light-weight tear-down */ 1300 /* Save the policy somewhere when doing a light-weight tear-down */
1299 if (frozen) 1301 if (cpufreq_suspended)
1300 per_cpu(cpufreq_cpu_data_fallback, cpu) = policy; 1302 per_cpu(cpufreq_cpu_data_fallback, cpu) = policy;
1301 1303
1302 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1304 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -1314,11 +1316,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1314 } 1316 }
1315 } 1317 }
1316 1318
1317#ifdef CONFIG_HOTPLUG_CPU
1318 if (!cpufreq_driver->setpolicy) 1319 if (!cpufreq_driver->setpolicy)
1319 strncpy(per_cpu(cpufreq_cpu_governor, cpu), 1320 strncpy(per_cpu(cpufreq_cpu_governor, cpu),
1320 policy->governor->name, CPUFREQ_NAME_LEN); 1321 policy->governor->name, CPUFREQ_NAME_LEN);
1321#endif
1322 1322
1323 down_read(&policy->rwsem); 1323 down_read(&policy->rwsem);
1324 cpus = cpumask_weight(policy->cpus); 1324 cpus = cpumask_weight(policy->cpus);
@@ -1331,9 +1331,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1331 if (new_cpu >= 0) { 1331 if (new_cpu >= 0) {
1332 update_policy_cpu(policy, new_cpu); 1332 update_policy_cpu(policy, new_cpu);
1333 1333
1334 if (!frozen) { 1334 if (!cpufreq_suspended) {
1335 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n", 1335 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n",
1336 __func__, new_cpu, cpu); 1336 __func__, new_cpu, cpu);
1337 } 1337 }
1338 } 1338 }
1339 } 1339 }
@@ -1342,8 +1342,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1342} 1342}
1343 1343
1344static int __cpufreq_remove_dev_finish(struct device *dev, 1344static int __cpufreq_remove_dev_finish(struct device *dev,
1345 struct subsys_interface *sif, 1345 struct subsys_interface *sif)
1346 bool frozen)
1347{ 1346{
1348 unsigned int cpu = dev->id, cpus; 1347 unsigned int cpu = dev->id, cpus;
1349 int ret; 1348 int ret;
@@ -1373,12 +1372,12 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1373 CPUFREQ_GOV_POLICY_EXIT); 1372 CPUFREQ_GOV_POLICY_EXIT);
1374 if (ret) { 1373 if (ret) {
1375 pr_err("%s: Failed to exit governor\n", 1374 pr_err("%s: Failed to exit governor\n",
1376 __func__); 1375 __func__);
1377 return ret; 1376 return ret;
1378 } 1377 }
1379 } 1378 }
1380 1379
1381 if (!frozen) 1380 if (!cpufreq_suspended)
1382 cpufreq_policy_put_kobj(policy); 1381 cpufreq_policy_put_kobj(policy);
1383 1382
1384 /* 1383 /*
@@ -1394,14 +1393,14 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1394 list_del(&policy->policy_list); 1393 list_del(&policy->policy_list);
1395 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1394 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1396 1395
1397 if (!frozen) 1396 if (!cpufreq_suspended)
1398 cpufreq_policy_free(policy); 1397 cpufreq_policy_free(policy);
1399 } else { 1398 } else {
1400 if (has_target()) { 1399 if (has_target()) {
1401 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) || 1400 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) ||
1402 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) { 1401 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) {
1403 pr_err("%s: Failed to start governor\n", 1402 pr_err("%s: Failed to start governor\n",
1404 __func__); 1403 __func__);
1405 return ret; 1404 return ret;
1406 } 1405 }
1407 } 1406 }
@@ -1424,10 +1423,10 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1424 if (cpu_is_offline(cpu)) 1423 if (cpu_is_offline(cpu))
1425 return 0; 1424 return 0;
1426 1425
1427 ret = __cpufreq_remove_dev_prepare(dev, sif, false); 1426 ret = __cpufreq_remove_dev_prepare(dev, sif);
1428 1427
1429 if (!ret) 1428 if (!ret)
1430 ret = __cpufreq_remove_dev_finish(dev, sif, false); 1429 ret = __cpufreq_remove_dev_finish(dev, sif);
1431 1430
1432 return ret; 1431 return ret;
1433} 1432}
@@ -1458,8 +1457,8 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
1458 struct cpufreq_freqs freqs; 1457 struct cpufreq_freqs freqs;
1459 unsigned long flags; 1458 unsigned long flags;
1460 1459
1461 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing " 1460 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing core thinks of %u, is %u kHz\n",
1462 "core thinks of %u, is %u kHz.\n", old_freq, new_freq); 1461 old_freq, new_freq);
1463 1462
1464 freqs.old = old_freq; 1463 freqs.old = old_freq;
1465 freqs.new = new_freq; 1464 freqs.new = new_freq;
@@ -1570,83 +1569,104 @@ static struct subsys_interface cpufreq_interface = {
1570 .remove_dev = cpufreq_remove_dev, 1569 .remove_dev = cpufreq_remove_dev,
1571}; 1570};
1572 1571
1572/*
1573 * In case platform wants some specific frequency to be configured
1574 * during suspend..
1575 */
1576int cpufreq_generic_suspend(struct cpufreq_policy *policy)
1577{
1578 int ret;
1579
1580 if (!policy->suspend_freq) {
1581 pr_err("%s: suspend_freq can't be zero\n", __func__);
1582 return -EINVAL;
1583 }
1584
1585 pr_debug("%s: Setting suspend-freq: %u\n", __func__,
1586 policy->suspend_freq);
1587
1588 ret = __cpufreq_driver_target(policy, policy->suspend_freq,
1589 CPUFREQ_RELATION_H);
1590 if (ret)
1591 pr_err("%s: unable to set suspend-freq: %u. err: %d\n",
1592 __func__, policy->suspend_freq, ret);
1593
1594 return ret;
1595}
1596EXPORT_SYMBOL(cpufreq_generic_suspend);
1597
1573/** 1598/**
1574 * cpufreq_bp_suspend - Prepare the boot CPU for system suspend. 1599 * cpufreq_suspend() - Suspend CPUFreq governors
1575 * 1600 *
1576 * This function is only executed for the boot processor. The other CPUs 1601 * Called during system wide Suspend/Hibernate cycles for suspending governors
1577 * have been put offline by means of CPU hotplug. 1602 * as some platforms can't change frequency after this point in suspend cycle.
1603 * Because some of the devices (like: i2c, regulators, etc) they use for
1604 * changing frequency are suspended quickly after this point.
1578 */ 1605 */
1579static int cpufreq_bp_suspend(void) 1606void cpufreq_suspend(void)
1580{ 1607{
1581 int ret = 0;
1582
1583 int cpu = smp_processor_id();
1584 struct cpufreq_policy *policy; 1608 struct cpufreq_policy *policy;
1585 1609
1586 pr_debug("suspending cpu %u\n", cpu); 1610 if (!cpufreq_driver)
1611 return;
1587 1612
1588 /* If there's no policy for the boot CPU, we have nothing to do. */ 1613 if (!has_target())
1589 policy = cpufreq_cpu_get(cpu); 1614 return;
1590 if (!policy)
1591 return 0;
1592 1615
1593 if (cpufreq_driver->suspend) { 1616 pr_debug("%s: Suspending Governors\n", __func__);
1594 ret = cpufreq_driver->suspend(policy); 1617
1595 if (ret) 1618 list_for_each_entry(policy, &cpufreq_policy_list, policy_list) {
1596 printk(KERN_ERR "cpufreq: suspend failed in ->suspend " 1619 if (__cpufreq_governor(policy, CPUFREQ_GOV_STOP))
1597 "step on CPU %u\n", policy->cpu); 1620 pr_err("%s: Failed to stop governor for policy: %p\n",
1621 __func__, policy);
1622 else if (cpufreq_driver->suspend
1623 && cpufreq_driver->suspend(policy))
1624 pr_err("%s: Failed to suspend driver: %p\n", __func__,
1625 policy);
1598 } 1626 }
1599 1627
1600 cpufreq_cpu_put(policy); 1628 cpufreq_suspended = true;
1601 return ret;
1602} 1629}
1603 1630
1604/** 1631/**
1605 * cpufreq_bp_resume - Restore proper frequency handling of the boot CPU. 1632 * cpufreq_resume() - Resume CPUFreq governors
1606 * 1633 *
1607 * 1.) resume CPUfreq hardware support (cpufreq_driver->resume()) 1634 * Called during system wide Suspend/Hibernate cycle for resuming governors that
1608 * 2.) schedule call cpufreq_update_policy() ASAP as interrupts are 1635 * are suspended with cpufreq_suspend().
1609 * restored. It will verify that the current freq is in sync with
1610 * what we believe it to be. This is a bit later than when it
1611 * should be, but nonethteless it's better than calling
1612 * cpufreq_driver->get() here which might re-enable interrupts...
1613 *
1614 * This function is only executed for the boot CPU. The other CPUs have not
1615 * been turned on yet.
1616 */ 1636 */
1617static void cpufreq_bp_resume(void) 1637void cpufreq_resume(void)
1618{ 1638{
1619 int ret = 0;
1620
1621 int cpu = smp_processor_id();
1622 struct cpufreq_policy *policy; 1639 struct cpufreq_policy *policy;
1623 1640
1624 pr_debug("resuming cpu %u\n", cpu); 1641 if (!cpufreq_driver)
1642 return;
1625 1643
1626 /* If there's no policy for the boot CPU, we have nothing to do. */ 1644 if (!has_target())
1627 policy = cpufreq_cpu_get(cpu);
1628 if (!policy)
1629 return; 1645 return;
1630 1646
1631 if (cpufreq_driver->resume) { 1647 pr_debug("%s: Resuming Governors\n", __func__);
1632 ret = cpufreq_driver->resume(policy);
1633 if (ret) {
1634 printk(KERN_ERR "cpufreq: resume failed in ->resume "
1635 "step on CPU %u\n", policy->cpu);
1636 goto fail;
1637 }
1638 }
1639 1648
1640 schedule_work(&policy->update); 1649 cpufreq_suspended = false;
1641 1650
1642fail: 1651 list_for_each_entry(policy, &cpufreq_policy_list, policy_list) {
1643 cpufreq_cpu_put(policy); 1652 if (__cpufreq_governor(policy, CPUFREQ_GOV_START)
1644} 1653 || __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))
1654 pr_err("%s: Failed to start governor for policy: %p\n",
1655 __func__, policy);
1656 else if (cpufreq_driver->resume
1657 && cpufreq_driver->resume(policy))
1658 pr_err("%s: Failed to resume driver: %p\n", __func__,
1659 policy);
1645 1660
1646static struct syscore_ops cpufreq_syscore_ops = { 1661 /*
1647 .suspend = cpufreq_bp_suspend, 1662 * schedule call cpufreq_update_policy() for boot CPU, i.e. last
1648 .resume = cpufreq_bp_resume, 1663 * policy in list. It will verify that the current freq is in
1649}; 1664 * sync with what we believe it to be.
1665 */
1666 if (list_is_last(&policy->policy_list, &cpufreq_policy_list))
1667 schedule_work(&policy->update);
1668 }
1669}
1650 1670
1651/** 1671/**
1652 * cpufreq_get_current_driver - return current driver's name 1672 * cpufreq_get_current_driver - return current driver's name
@@ -1762,7 +1782,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1762 target_freq = policy->min; 1782 target_freq = policy->min;
1763 1783
1764 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n", 1784 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
1765 policy->cpu, target_freq, relation, old_target_freq); 1785 policy->cpu, target_freq, relation, old_target_freq);
1766 1786
1767 /* 1787 /*
1768 * This might look like a redundant call as we are checking it again 1788 * This might look like a redundant call as we are checking it again
@@ -1807,8 +1827,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1807 freqs.flags = 0; 1827 freqs.flags = 0;
1808 1828
1809 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", 1829 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
1810 __func__, policy->cpu, freqs.old, 1830 __func__, policy->cpu, freqs.old, freqs.new);
1811 freqs.new);
1812 1831
1813 cpufreq_notify_transition(policy, &freqs, 1832 cpufreq_notify_transition(policy, &freqs,
1814 CPUFREQ_PRECHANGE); 1833 CPUFREQ_PRECHANGE);
@@ -1817,7 +1836,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1817 retval = cpufreq_driver->target_index(policy, index); 1836 retval = cpufreq_driver->target_index(policy, index);
1818 if (retval) 1837 if (retval)
1819 pr_err("%s: Failed to change cpu frequency: %d\n", 1838 pr_err("%s: Failed to change cpu frequency: %d\n",
1820 __func__, retval); 1839 __func__, retval);
1821 1840
1822 if (notify) 1841 if (notify)
1823 cpufreq_notify_post_transition(policy, &freqs, retval); 1842 cpufreq_notify_post_transition(policy, &freqs, retval);
@@ -1863,17 +1882,18 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1863 struct cpufreq_governor *gov = NULL; 1882 struct cpufreq_governor *gov = NULL;
1864#endif 1883#endif
1865 1884
1885 /* Don't start any governor operations if we are entering suspend */
1886 if (cpufreq_suspended)
1887 return 0;
1888
1866 if (policy->governor->max_transition_latency && 1889 if (policy->governor->max_transition_latency &&
1867 policy->cpuinfo.transition_latency > 1890 policy->cpuinfo.transition_latency >
1868 policy->governor->max_transition_latency) { 1891 policy->governor->max_transition_latency) {
1869 if (!gov) 1892 if (!gov)
1870 return -EINVAL; 1893 return -EINVAL;
1871 else { 1894 else {
1872 printk(KERN_WARNING "%s governor failed, too long" 1895 pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
1873 " transition latency of HW, fallback" 1896 policy->governor->name, gov->name);
1874 " to %s governor\n",
1875 policy->governor->name,
1876 gov->name);
1877 policy->governor = gov; 1897 policy->governor = gov;
1878 } 1898 }
1879 } 1899 }
@@ -1883,7 +1903,7 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1883 return -EINVAL; 1903 return -EINVAL;
1884 1904
1885 pr_debug("__cpufreq_governor for CPU %u, event %u\n", 1905 pr_debug("__cpufreq_governor for CPU %u, event %u\n",
1886 policy->cpu, event); 1906 policy->cpu, event);
1887 1907
1888 mutex_lock(&cpufreq_governor_lock); 1908 mutex_lock(&cpufreq_governor_lock);
1889 if ((policy->governor_enabled && event == CPUFREQ_GOV_START) 1909 if ((policy->governor_enabled && event == CPUFREQ_GOV_START)
@@ -1950,9 +1970,7 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1950 1970
1951void cpufreq_unregister_governor(struct cpufreq_governor *governor) 1971void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1952{ 1972{
1953#ifdef CONFIG_HOTPLUG_CPU
1954 int cpu; 1973 int cpu;
1955#endif
1956 1974
1957 if (!governor) 1975 if (!governor)
1958 return; 1976 return;
@@ -1960,14 +1978,12 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1960 if (cpufreq_disabled()) 1978 if (cpufreq_disabled())
1961 return; 1979 return;
1962 1980
1963#ifdef CONFIG_HOTPLUG_CPU
1964 for_each_present_cpu(cpu) { 1981 for_each_present_cpu(cpu) {
1965 if (cpu_online(cpu)) 1982 if (cpu_online(cpu))
1966 continue; 1983 continue;
1967 if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) 1984 if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
1968 strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); 1985 strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
1969 } 1986 }
1970#endif
1971 1987
1972 mutex_lock(&cpufreq_governor_mutex); 1988 mutex_lock(&cpufreq_governor_mutex);
1973 list_del(&governor->governor_list); 1989 list_del(&governor->governor_list);
@@ -2012,22 +2028,21 @@ EXPORT_SYMBOL(cpufreq_get_policy);
2012static int cpufreq_set_policy(struct cpufreq_policy *policy, 2028static int cpufreq_set_policy(struct cpufreq_policy *policy,
2013 struct cpufreq_policy *new_policy) 2029 struct cpufreq_policy *new_policy)
2014{ 2030{
2015 int ret = 0, failed = 1; 2031 struct cpufreq_governor *old_gov;
2032 int ret;
2016 2033
2017 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", new_policy->cpu, 2034 pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
2018 new_policy->min, new_policy->max); 2035 new_policy->cpu, new_policy->min, new_policy->max);
2019 2036
2020 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); 2037 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
2021 2038
2022 if (new_policy->min > policy->max || new_policy->max < policy->min) { 2039 if (new_policy->min > policy->max || new_policy->max < policy->min)
2023 ret = -EINVAL; 2040 return -EINVAL;
2024 goto error_out;
2025 }
2026 2041
2027 /* verify the cpu speed can be set within this limit */ 2042 /* verify the cpu speed can be set within this limit */
2028 ret = cpufreq_driver->verify(new_policy); 2043 ret = cpufreq_driver->verify(new_policy);
2029 if (ret) 2044 if (ret)
2030 goto error_out; 2045 return ret;
2031 2046
2032 /* adjust if necessary - all reasons */ 2047 /* adjust if necessary - all reasons */
2033 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 2048 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
@@ -2043,7 +2058,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
2043 */ 2058 */
2044 ret = cpufreq_driver->verify(new_policy); 2059 ret = cpufreq_driver->verify(new_policy);
2045 if (ret) 2060 if (ret)
2046 goto error_out; 2061 return ret;
2047 2062
2048 /* notification of the new policy */ 2063 /* notification of the new policy */
2049 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 2064 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
@@ -2053,63 +2068,53 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
2053 policy->max = new_policy->max; 2068 policy->max = new_policy->max;
2054 2069
2055 pr_debug("new min and max freqs are %u - %u kHz\n", 2070 pr_debug("new min and max freqs are %u - %u kHz\n",
2056 policy->min, policy->max); 2071 policy->min, policy->max);
2057 2072
2058 if (cpufreq_driver->setpolicy) { 2073 if (cpufreq_driver->setpolicy) {
2059 policy->policy = new_policy->policy; 2074 policy->policy = new_policy->policy;
2060 pr_debug("setting range\n"); 2075 pr_debug("setting range\n");
2061 ret = cpufreq_driver->setpolicy(new_policy); 2076 return cpufreq_driver->setpolicy(new_policy);
2062 } else { 2077 }
2063 if (new_policy->governor != policy->governor) {
2064 /* save old, working values */
2065 struct cpufreq_governor *old_gov = policy->governor;
2066
2067 pr_debug("governor switch\n");
2068
2069 /* end old governor */
2070 if (policy->governor) {
2071 __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
2072 up_write(&policy->rwsem);
2073 __cpufreq_governor(policy,
2074 CPUFREQ_GOV_POLICY_EXIT);
2075 down_write(&policy->rwsem);
2076 }
2077 2078
2078 /* start new governor */ 2079 if (new_policy->governor == policy->governor)
2079 policy->governor = new_policy->governor; 2080 goto out;
2080 if (!__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) {
2081 if (!__cpufreq_governor(policy, CPUFREQ_GOV_START)) {
2082 failed = 0;
2083 } else {
2084 up_write(&policy->rwsem);
2085 __cpufreq_governor(policy,
2086 CPUFREQ_GOV_POLICY_EXIT);
2087 down_write(&policy->rwsem);
2088 }
2089 }
2090 2081
2091 if (failed) { 2082 pr_debug("governor switch\n");
2092 /* new governor failed, so re-start old one */ 2083
2093 pr_debug("starting governor %s failed\n", 2084 /* save old, working values */
2094 policy->governor->name); 2085 old_gov = policy->governor;
2095 if (old_gov) { 2086 /* end old governor */
2096 policy->governor = old_gov; 2087 if (old_gov) {
2097 __cpufreq_governor(policy, 2088 __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
2098 CPUFREQ_GOV_POLICY_INIT); 2089 up_write(&policy->rwsem);
2099 __cpufreq_governor(policy, 2090 __cpufreq_governor(policy,CPUFREQ_GOV_POLICY_EXIT);
2100 CPUFREQ_GOV_START); 2091 down_write(&policy->rwsem);
2101 }
2102 ret = -EINVAL;
2103 goto error_out;
2104 }
2105 /* might be a policy change, too, so fall through */
2106 }
2107 pr_debug("governor: change or update limits\n");
2108 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2109 } 2092 }
2110 2093
2111error_out: 2094 /* start new governor */
2112 return ret; 2095 policy->governor = new_policy->governor;
2096 if (!__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) {
2097 if (!__cpufreq_governor(policy, CPUFREQ_GOV_START))
2098 goto out;
2099
2100 up_write(&policy->rwsem);
2101 __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
2102 down_write(&policy->rwsem);
2103 }
2104
2105 /* new governor failed, so re-start old one */
2106 pr_debug("starting governor %s failed\n", policy->governor->name);
2107 if (old_gov) {
2108 policy->governor = old_gov;
2109 __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT);
2110 __cpufreq_governor(policy, CPUFREQ_GOV_START);
2111 }
2112
2113 return -EINVAL;
2114
2115 out:
2116 pr_debug("governor: change or update limits\n");
2117 return __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2113} 2118}
2114 2119
2115/** 2120/**
@@ -2145,8 +2150,13 @@ int cpufreq_update_policy(unsigned int cpu)
2145 */ 2150 */
2146 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { 2151 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2147 new_policy.cur = cpufreq_driver->get(cpu); 2152 new_policy.cur = cpufreq_driver->get(cpu);
2153 if (WARN_ON(!new_policy.cur)) {
2154 ret = -EIO;
2155 goto no_policy;
2156 }
2157
2148 if (!policy->cur) { 2158 if (!policy->cur) {
2149 pr_debug("Driver did not initialize current freq"); 2159 pr_debug("Driver did not initialize current freq\n");
2150 policy->cur = new_policy.cur; 2160 policy->cur = new_policy.cur;
2151 } else { 2161 } else {
2152 if (policy->cur != new_policy.cur && has_target()) 2162 if (policy->cur != new_policy.cur && has_target())
@@ -2170,30 +2180,24 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
2170{ 2180{
2171 unsigned int cpu = (unsigned long)hcpu; 2181 unsigned int cpu = (unsigned long)hcpu;
2172 struct device *dev; 2182 struct device *dev;
2173 bool frozen = false;
2174 2183
2175 dev = get_cpu_device(cpu); 2184 dev = get_cpu_device(cpu);
2176 if (dev) { 2185 if (dev) {
2177
2178 if (action & CPU_TASKS_FROZEN)
2179 frozen = true;
2180
2181 switch (action & ~CPU_TASKS_FROZEN) { 2186 switch (action & ~CPU_TASKS_FROZEN) {
2182 case CPU_ONLINE: 2187 case CPU_ONLINE:
2183 __cpufreq_add_dev(dev, NULL, frozen); 2188 __cpufreq_add_dev(dev, NULL);
2184 cpufreq_update_policy(cpu);
2185 break; 2189 break;
2186 2190
2187 case CPU_DOWN_PREPARE: 2191 case CPU_DOWN_PREPARE:
2188 __cpufreq_remove_dev_prepare(dev, NULL, frozen); 2192 __cpufreq_remove_dev_prepare(dev, NULL);
2189 break; 2193 break;
2190 2194
2191 case CPU_POST_DEAD: 2195 case CPU_POST_DEAD:
2192 __cpufreq_remove_dev_finish(dev, NULL, frozen); 2196 __cpufreq_remove_dev_finish(dev, NULL);
2193 break; 2197 break;
2194 2198
2195 case CPU_DOWN_FAILED: 2199 case CPU_DOWN_FAILED:
2196 __cpufreq_add_dev(dev, NULL, frozen); 2200 __cpufreq_add_dev(dev, NULL);
2197 break; 2201 break;
2198 } 2202 }
2199 } 2203 }
@@ -2249,8 +2253,8 @@ int cpufreq_boost_trigger_state(int state)
2249 cpufreq_driver->boost_enabled = !state; 2253 cpufreq_driver->boost_enabled = !state;
2250 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 2254 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2251 2255
2252 pr_err("%s: Cannot %s BOOST\n", __func__, 2256 pr_err("%s: Cannot %s BOOST\n",
2253 state ? "enable" : "disable"); 2257 __func__, state ? "enable" : "disable");
2254 } 2258 }
2255 2259
2256 return ret; 2260 return ret;
@@ -2322,7 +2326,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
2322 ret = cpufreq_sysfs_create_file(&boost.attr); 2326 ret = cpufreq_sysfs_create_file(&boost.attr);
2323 if (ret) { 2327 if (ret) {
2324 pr_err("%s: cannot register global BOOST sysfs file\n", 2328 pr_err("%s: cannot register global BOOST sysfs file\n",
2325 __func__); 2329 __func__);
2326 goto err_null_driver; 2330 goto err_null_driver;
2327 } 2331 }
2328 } 2332 }
@@ -2345,7 +2349,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
2345 /* if all ->init() calls failed, unregister */ 2349 /* if all ->init() calls failed, unregister */
2346 if (ret) { 2350 if (ret) {
2347 pr_debug("no CPU initialized for driver %s\n", 2351 pr_debug("no CPU initialized for driver %s\n",
2348 driver_data->name); 2352 driver_data->name);
2349 goto err_if_unreg; 2353 goto err_if_unreg;
2350 } 2354 }
2351 } 2355 }
@@ -2409,7 +2413,6 @@ static int __init cpufreq_core_init(void)
2409 2413
2410 cpufreq_global_kobject = kobject_create(); 2414 cpufreq_global_kobject = kobject_create();
2411 BUG_ON(!cpufreq_global_kobject); 2415 BUG_ON(!cpufreq_global_kobject);
2412 register_syscore_ops(&cpufreq_syscore_ops);
2413 2416
2414 return 0; 2417 return 0;
2415} 2418}
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index 5793e1447fb1..eb214d83ad6b 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -180,27 +180,25 @@ static void cpufreq_stats_free_table(unsigned int cpu)
180 cpufreq_cpu_put(policy); 180 cpufreq_cpu_put(policy);
181} 181}
182 182
183static int __cpufreq_stats_create_table(struct cpufreq_policy *policy, 183static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
184 struct cpufreq_frequency_table *table)
185{ 184{
186 unsigned int i, j, count = 0, ret = 0; 185 unsigned int i, j, count = 0, ret = 0;
187 struct cpufreq_stats *stat; 186 struct cpufreq_stats *stat;
188 struct cpufreq_policy *current_policy;
189 unsigned int alloc_size; 187 unsigned int alloc_size;
190 unsigned int cpu = policy->cpu; 188 unsigned int cpu = policy->cpu;
189 struct cpufreq_frequency_table *table;
190
191 table = cpufreq_frequency_get_table(cpu);
192 if (unlikely(!table))
193 return 0;
194
191 if (per_cpu(cpufreq_stats_table, cpu)) 195 if (per_cpu(cpufreq_stats_table, cpu))
192 return -EBUSY; 196 return -EBUSY;
193 stat = kzalloc(sizeof(*stat), GFP_KERNEL); 197 stat = kzalloc(sizeof(*stat), GFP_KERNEL);
194 if ((stat) == NULL) 198 if ((stat) == NULL)
195 return -ENOMEM; 199 return -ENOMEM;
196 200
197 current_policy = cpufreq_cpu_get(cpu); 201 ret = sysfs_create_group(&policy->kobj, &stats_attr_group);
198 if (current_policy == NULL) {
199 ret = -EINVAL;
200 goto error_get_fail;
201 }
202
203 ret = sysfs_create_group(&current_policy->kobj, &stats_attr_group);
204 if (ret) 202 if (ret)
205 goto error_out; 203 goto error_out;
206 204
@@ -223,7 +221,7 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy,
223 stat->time_in_state = kzalloc(alloc_size, GFP_KERNEL); 221 stat->time_in_state = kzalloc(alloc_size, GFP_KERNEL);
224 if (!stat->time_in_state) { 222 if (!stat->time_in_state) {
225 ret = -ENOMEM; 223 ret = -ENOMEM;
226 goto error_out; 224 goto error_alloc;
227 } 225 }
228 stat->freq_table = (unsigned int *)(stat->time_in_state + count); 226 stat->freq_table = (unsigned int *)(stat->time_in_state + count);
229 227
@@ -243,11 +241,10 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy,
243 stat->last_time = get_jiffies_64(); 241 stat->last_time = get_jiffies_64();
244 stat->last_index = freq_table_get_index(stat, policy->cur); 242 stat->last_index = freq_table_get_index(stat, policy->cur);
245 spin_unlock(&cpufreq_stats_lock); 243 spin_unlock(&cpufreq_stats_lock);
246 cpufreq_cpu_put(current_policy);
247 return 0; 244 return 0;
245error_alloc:
246 sysfs_remove_group(&policy->kobj, &stats_attr_group);
248error_out: 247error_out:
249 cpufreq_cpu_put(current_policy);
250error_get_fail:
251 kfree(stat); 248 kfree(stat);
252 per_cpu(cpufreq_stats_table, cpu) = NULL; 249 per_cpu(cpufreq_stats_table, cpu) = NULL;
253 return ret; 250 return ret;
@@ -256,7 +253,6 @@ error_get_fail:
256static void cpufreq_stats_create_table(unsigned int cpu) 253static void cpufreq_stats_create_table(unsigned int cpu)
257{ 254{
258 struct cpufreq_policy *policy; 255 struct cpufreq_policy *policy;
259 struct cpufreq_frequency_table *table;
260 256
261 /* 257 /*
262 * "likely(!policy)" because normally cpufreq_stats will be registered 258 * "likely(!policy)" because normally cpufreq_stats will be registered
@@ -266,9 +262,7 @@ static void cpufreq_stats_create_table(unsigned int cpu)
266 if (likely(!policy)) 262 if (likely(!policy))
267 return; 263 return;
268 264
269 table = cpufreq_frequency_get_table(policy->cpu); 265 __cpufreq_stats_create_table(policy);
270 if (likely(table))
271 __cpufreq_stats_create_table(policy, table);
272 266
273 cpufreq_cpu_put(policy); 267 cpufreq_cpu_put(policy);
274} 268}
@@ -291,20 +285,14 @@ static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
291{ 285{
292 int ret = 0; 286 int ret = 0;
293 struct cpufreq_policy *policy = data; 287 struct cpufreq_policy *policy = data;
294 struct cpufreq_frequency_table *table;
295 unsigned int cpu = policy->cpu;
296 288
297 if (val == CPUFREQ_UPDATE_POLICY_CPU) { 289 if (val == CPUFREQ_UPDATE_POLICY_CPU) {
298 cpufreq_stats_update_policy_cpu(policy); 290 cpufreq_stats_update_policy_cpu(policy);
299 return 0; 291 return 0;
300 } 292 }
301 293
302 table = cpufreq_frequency_get_table(cpu);
303 if (!table)
304 return 0;
305
306 if (val == CPUFREQ_CREATE_POLICY) 294 if (val == CPUFREQ_CREATE_POLICY)
307 ret = __cpufreq_stats_create_table(policy, table); 295 ret = __cpufreq_stats_create_table(policy);
308 else if (val == CPUFREQ_REMOVE_POLICY) 296 else if (val == CPUFREQ_REMOVE_POLICY)
309 __cpufreq_stats_free_table(policy); 297 __cpufreq_stats_free_table(policy);
310 298
diff --git a/drivers/cpufreq/cris-artpec3-cpufreq.c b/drivers/cpufreq/cris-artpec3-cpufreq.c
index 86559040c54c..d4573032cbbc 100644
--- a/drivers/cpufreq/cris-artpec3-cpufreq.c
+++ b/drivers/cpufreq/cris-artpec3-cpufreq.c
@@ -57,7 +57,6 @@ static struct cpufreq_driver cris_freq_driver = {
57 .verify = cpufreq_generic_frequency_table_verify, 57 .verify = cpufreq_generic_frequency_table_verify,
58 .target_index = cris_freq_target, 58 .target_index = cris_freq_target,
59 .init = cris_freq_cpu_init, 59 .init = cris_freq_cpu_init,
60 .exit = cpufreq_generic_exit,
61 .name = "cris_freq", 60 .name = "cris_freq",
62 .attr = cpufreq_generic_attr, 61 .attr = cpufreq_generic_attr,
63}; 62};
diff --git a/drivers/cpufreq/cris-etraxfs-cpufreq.c b/drivers/cpufreq/cris-etraxfs-cpufreq.c
index 26d940d40b1d..13c3361437f7 100644
--- a/drivers/cpufreq/cris-etraxfs-cpufreq.c
+++ b/drivers/cpufreq/cris-etraxfs-cpufreq.c
@@ -57,7 +57,6 @@ static struct cpufreq_driver cris_freq_driver = {
57 .verify = cpufreq_generic_frequency_table_verify, 57 .verify = cpufreq_generic_frequency_table_verify,
58 .target_index = cris_freq_target, 58 .target_index = cris_freq_target,
59 .init = cris_freq_cpu_init, 59 .init = cris_freq_cpu_init,
60 .exit = cpufreq_generic_exit,
61 .name = "cris_freq", 60 .name = "cris_freq",
62 .attr = cpufreq_generic_attr, 61 .attr = cpufreq_generic_attr,
63}; 62};
diff --git a/drivers/cpufreq/davinci-cpufreq.c b/drivers/cpufreq/davinci-cpufreq.c
index 2cf33848d86e..28a16dc6e02e 100644
--- a/drivers/cpufreq/davinci-cpufreq.c
+++ b/drivers/cpufreq/davinci-cpufreq.c
@@ -125,7 +125,6 @@ static struct cpufreq_driver davinci_driver = {
125 .target_index = davinci_target, 125 .target_index = davinci_target,
126 .get = cpufreq_generic_get, 126 .get = cpufreq_generic_get,
127 .init = davinci_cpu_init, 127 .init = davinci_cpu_init,
128 .exit = cpufreq_generic_exit,
129 .name = "davinci", 128 .name = "davinci",
130 .attr = cpufreq_generic_attr, 129 .attr = cpufreq_generic_attr,
131}; 130};
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c
index 9012b8bb6b64..a0d2a423cea9 100644
--- a/drivers/cpufreq/e_powersaver.c
+++ b/drivers/cpufreq/e_powersaver.c
@@ -382,7 +382,6 @@ static int eps_cpu_exit(struct cpufreq_policy *policy)
382 unsigned int cpu = policy->cpu; 382 unsigned int cpu = policy->cpu;
383 383
384 /* Bye */ 384 /* Bye */
385 cpufreq_frequency_table_put_attr(policy->cpu);
386 kfree(eps_cpu[cpu]); 385 kfree(eps_cpu[cpu]);
387 eps_cpu[cpu] = NULL; 386 eps_cpu[cpu] = NULL;
388 return 0; 387 return 0;
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c
index de08acff5101..c987e94708f5 100644
--- a/drivers/cpufreq/elanfreq.c
+++ b/drivers/cpufreq/elanfreq.c
@@ -198,7 +198,6 @@ static struct cpufreq_driver elanfreq_driver = {
198 .verify = cpufreq_generic_frequency_table_verify, 198 .verify = cpufreq_generic_frequency_table_verify,
199 .target_index = elanfreq_target, 199 .target_index = elanfreq_target,
200 .init = elanfreq_cpu_init, 200 .init = elanfreq_cpu_init,
201 .exit = cpufreq_generic_exit,
202 .name = "elanfreq", 201 .name = "elanfreq",
203 .attr = cpufreq_generic_attr, 202 .attr = cpufreq_generic_attr,
204}; 203};
diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index fcd2914d081a..f99cfe24e7bc 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -16,7 +16,6 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/cpufreq.h> 18#include <linux/cpufreq.h>
19#include <linux/suspend.h>
20#include <linux/platform_device.h> 19#include <linux/platform_device.h>
21 20
22#include <plat/cpu.h> 21#include <plat/cpu.h>
@@ -24,12 +23,8 @@
24#include "exynos-cpufreq.h" 23#include "exynos-cpufreq.h"
25 24
26static struct exynos_dvfs_info *exynos_info; 25static struct exynos_dvfs_info *exynos_info;
27
28static struct regulator *arm_regulator; 26static struct regulator *arm_regulator;
29
30static unsigned int locking_frequency; 27static unsigned int locking_frequency;
31static bool frequency_locked;
32static DEFINE_MUTEX(cpufreq_lock);
33 28
34static int exynos_cpufreq_get_index(unsigned int freq) 29static int exynos_cpufreq_get_index(unsigned int freq)
35{ 30{
@@ -134,83 +129,13 @@ out:
134 129
135static int exynos_target(struct cpufreq_policy *policy, unsigned int index) 130static int exynos_target(struct cpufreq_policy *policy, unsigned int index)
136{ 131{
137 struct cpufreq_frequency_table *freq_table = exynos_info->freq_table; 132 return exynos_cpufreq_scale(exynos_info->freq_table[index].frequency);
138 int ret = 0;
139
140 mutex_lock(&cpufreq_lock);
141
142 if (frequency_locked)
143 goto out;
144
145 ret = exynos_cpufreq_scale(freq_table[index].frequency);
146
147out:
148 mutex_unlock(&cpufreq_lock);
149
150 return ret;
151}
152
153#ifdef CONFIG_PM
154static int exynos_cpufreq_suspend(struct cpufreq_policy *policy)
155{
156 return 0;
157}
158
159static int exynos_cpufreq_resume(struct cpufreq_policy *policy)
160{
161 return 0;
162}
163#endif
164
165/**
166 * exynos_cpufreq_pm_notifier - block CPUFREQ's activities in suspend-resume
167 * context
168 * @notifier
169 * @pm_event
170 * @v
171 *
172 * While frequency_locked == true, target() ignores every frequency but
173 * locking_frequency. The locking_frequency value is the initial frequency,
174 * which is set by the bootloader. In order to eliminate possible
175 * inconsistency in clock values, we save and restore frequencies during
176 * suspend and resume and block CPUFREQ activities. Note that the standard
177 * suspend/resume cannot be used as they are too deep (syscore_ops) for
178 * regulator actions.
179 */
180static int exynos_cpufreq_pm_notifier(struct notifier_block *notifier,
181 unsigned long pm_event, void *v)
182{
183 int ret;
184
185 switch (pm_event) {
186 case PM_SUSPEND_PREPARE:
187 mutex_lock(&cpufreq_lock);
188 frequency_locked = true;
189 mutex_unlock(&cpufreq_lock);
190
191 ret = exynos_cpufreq_scale(locking_frequency);
192 if (ret < 0)
193 return NOTIFY_BAD;
194
195 break;
196
197 case PM_POST_SUSPEND:
198 mutex_lock(&cpufreq_lock);
199 frequency_locked = false;
200 mutex_unlock(&cpufreq_lock);
201 break;
202 }
203
204 return NOTIFY_OK;
205} 133}
206 134
207static struct notifier_block exynos_cpufreq_nb = {
208 .notifier_call = exynos_cpufreq_pm_notifier,
209};
210
211static int exynos_cpufreq_cpu_init(struct cpufreq_policy *policy) 135static int exynos_cpufreq_cpu_init(struct cpufreq_policy *policy)
212{ 136{
213 policy->clk = exynos_info->cpu_clk; 137 policy->clk = exynos_info->cpu_clk;
138 policy->suspend_freq = locking_frequency;
214 return cpufreq_generic_init(policy, exynos_info->freq_table, 100000); 139 return cpufreq_generic_init(policy, exynos_info->freq_table, 100000);
215} 140}
216 141
@@ -220,15 +145,13 @@ static struct cpufreq_driver exynos_driver = {
220 .target_index = exynos_target, 145 .target_index = exynos_target,
221 .get = cpufreq_generic_get, 146 .get = cpufreq_generic_get,
222 .init = exynos_cpufreq_cpu_init, 147 .init = exynos_cpufreq_cpu_init,
223 .exit = cpufreq_generic_exit,
224 .name = "exynos_cpufreq", 148 .name = "exynos_cpufreq",
225 .attr = cpufreq_generic_attr, 149 .attr = cpufreq_generic_attr,
226#ifdef CONFIG_ARM_EXYNOS_CPU_FREQ_BOOST_SW 150#ifdef CONFIG_ARM_EXYNOS_CPU_FREQ_BOOST_SW
227 .boost_supported = true, 151 .boost_supported = true,
228#endif 152#endif
229#ifdef CONFIG_PM 153#ifdef CONFIG_PM
230 .suspend = exynos_cpufreq_suspend, 154 .suspend = cpufreq_generic_suspend,
231 .resume = exynos_cpufreq_resume,
232#endif 155#endif
233}; 156};
234 157
@@ -263,19 +186,13 @@ static int exynos_cpufreq_probe(struct platform_device *pdev)
263 goto err_vdd_arm; 186 goto err_vdd_arm;
264 } 187 }
265 188
189 /* Done here as we want to capture boot frequency */
266 locking_frequency = clk_get_rate(exynos_info->cpu_clk) / 1000; 190 locking_frequency = clk_get_rate(exynos_info->cpu_clk) / 1000;
267 191
268 register_pm_notifier(&exynos_cpufreq_nb); 192 if (!cpufreq_register_driver(&exynos_driver))
269 193 return 0;
270 if (cpufreq_register_driver(&exynos_driver)) {
271 pr_err("%s: failed to register cpufreq driver\n", __func__);
272 goto err_cpufreq;
273 }
274
275 return 0;
276err_cpufreq:
277 unregister_pm_notifier(&exynos_cpufreq_nb);
278 194
195 pr_err("%s: failed to register cpufreq driver\n", __func__);
279 regulator_put(arm_regulator); 196 regulator_put(arm_regulator);
280err_vdd_arm: 197err_vdd_arm:
281 kfree(exynos_info); 198 kfree(exynos_info);
diff --git a/drivers/cpufreq/exynos5440-cpufreq.c b/drivers/cpufreq/exynos5440-cpufreq.c
index 49b756015316..7f776aa91e2f 100644
--- a/drivers/cpufreq/exynos5440-cpufreq.c
+++ b/drivers/cpufreq/exynos5440-cpufreq.c
@@ -312,7 +312,6 @@ static struct cpufreq_driver exynos_driver = {
312 .target_index = exynos_target, 312 .target_index = exynos_target,
313 .get = cpufreq_generic_get, 313 .get = cpufreq_generic_get,
314 .init = exynos_cpufreq_cpu_init, 314 .init = exynos_cpufreq_cpu_init,
315 .exit = cpufreq_generic_exit,
316 .name = CPUFREQ_NAME, 315 .name = CPUFREQ_NAME,
317 .attr = cpufreq_generic_attr, 316 .attr = cpufreq_generic_attr,
318}; 317};
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 8e54f97899ba..65a477075b3f 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -91,8 +91,8 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
91EXPORT_SYMBOL_GPL(cpufreq_frequency_table_verify); 91EXPORT_SYMBOL_GPL(cpufreq_frequency_table_verify);
92 92
93/* 93/*
94 * Generic routine to verify policy & frequency table, requires driver to call 94 * Generic routine to verify policy & frequency table, requires driver to set
95 * cpufreq_frequency_table_get_attr() prior to it. 95 * policy->freq_table prior to it.
96 */ 96 */
97int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy) 97int cpufreq_generic_frequency_table_verify(struct cpufreq_policy *policy)
98{ 98{
@@ -203,8 +203,6 @@ int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
203} 203}
204EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_index); 204EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_index);
205 205
206static DEFINE_PER_CPU(struct cpufreq_frequency_table *, cpufreq_show_table);
207
208/** 206/**
209 * show_available_freqs - show available frequencies for the specified CPU 207 * show_available_freqs - show available frequencies for the specified CPU
210 */ 208 */
@@ -212,15 +210,12 @@ static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf,
212 bool show_boost) 210 bool show_boost)
213{ 211{
214 unsigned int i = 0; 212 unsigned int i = 0;
215 unsigned int cpu = policy->cpu;
216 ssize_t count = 0; 213 ssize_t count = 0;
217 struct cpufreq_frequency_table *table; 214 struct cpufreq_frequency_table *table = policy->freq_table;
218 215
219 if (!per_cpu(cpufreq_show_table, cpu)) 216 if (!table)
220 return -ENODEV; 217 return -ENODEV;
221 218
222 table = per_cpu(cpufreq_show_table, cpu);
223
224 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 219 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
225 if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 220 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
226 continue; 221 continue;
@@ -283,49 +278,24 @@ struct freq_attr *cpufreq_generic_attr[] = {
283}; 278};
284EXPORT_SYMBOL_GPL(cpufreq_generic_attr); 279EXPORT_SYMBOL_GPL(cpufreq_generic_attr);
285 280
286/*
287 * if you use these, you must assure that the frequency table is valid
288 * all the time between get_attr and put_attr!
289 */
290void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
291 unsigned int cpu)
292{
293 pr_debug("setting show_table for cpu %u to %p\n", cpu, table);
294 per_cpu(cpufreq_show_table, cpu) = table;
295}
296EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr);
297
298void cpufreq_frequency_table_put_attr(unsigned int cpu)
299{
300 pr_debug("clearing show_table for cpu %u\n", cpu);
301 per_cpu(cpufreq_show_table, cpu) = NULL;
302}
303EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr);
304
305int cpufreq_table_validate_and_show(struct cpufreq_policy *policy, 281int cpufreq_table_validate_and_show(struct cpufreq_policy *policy,
306 struct cpufreq_frequency_table *table) 282 struct cpufreq_frequency_table *table)
307{ 283{
308 int ret = cpufreq_frequency_table_cpuinfo(policy, table); 284 int ret = cpufreq_frequency_table_cpuinfo(policy, table);
309 285
310 if (!ret) 286 if (!ret)
311 cpufreq_frequency_table_get_attr(table, policy->cpu); 287 policy->freq_table = table;
312 288
313 return ret; 289 return ret;
314} 290}
315EXPORT_SYMBOL_GPL(cpufreq_table_validate_and_show); 291EXPORT_SYMBOL_GPL(cpufreq_table_validate_and_show);
316 292
317void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy) 293struct cpufreq_policy *cpufreq_cpu_get_raw(unsigned int cpu);
318{
319 pr_debug("Updating show_table for new_cpu %u from last_cpu %u\n",
320 policy->cpu, policy->last_cpu);
321 per_cpu(cpufreq_show_table, policy->cpu) = per_cpu(cpufreq_show_table,
322 policy->last_cpu);
323 per_cpu(cpufreq_show_table, policy->last_cpu) = NULL;
324}
325 294
326struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu) 295struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
327{ 296{
328 return per_cpu(cpufreq_show_table, cpu); 297 struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
298 return policy ? policy->freq_table : NULL;
329} 299}
330EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table); 300EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
331 301
diff --git a/drivers/cpufreq/ia64-acpi-cpufreq.c b/drivers/cpufreq/ia64-acpi-cpufreq.c
index 53c6ac637e10..a22b5d182e0e 100644
--- a/drivers/cpufreq/ia64-acpi-cpufreq.c
+++ b/drivers/cpufreq/ia64-acpi-cpufreq.c
@@ -332,7 +332,6 @@ acpi_cpufreq_cpu_exit (
332 pr_debug("acpi_cpufreq_cpu_exit\n"); 332 pr_debug("acpi_cpufreq_cpu_exit\n");
333 333
334 if (data) { 334 if (data) {
335 cpufreq_frequency_table_put_attr(policy->cpu);
336 acpi_io_data[policy->cpu] = NULL; 335 acpi_io_data[policy->cpu] = NULL;
337 acpi_processor_unregister_performance(&data->acpi_data, 336 acpi_processor_unregister_performance(&data->acpi_data,
338 policy->cpu); 337 policy->cpu);
diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index ce69059be1fc..e27fca86fe4f 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -144,7 +144,6 @@ static struct cpufreq_driver imx6q_cpufreq_driver = {
144 .target_index = imx6q_set_target, 144 .target_index = imx6q_set_target,
145 .get = cpufreq_generic_get, 145 .get = cpufreq_generic_get,
146 .init = imx6q_cpufreq_init, 146 .init = imx6q_cpufreq_init,
147 .exit = cpufreq_generic_exit,
148 .name = "imx6q-cpufreq", 147 .name = "imx6q-cpufreq",
149 .attr = cpufreq_generic_attr, 148 .attr = cpufreq_generic_attr,
150}; 149};
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 2cd36b9297f3..9ab109c0f90c 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -99,8 +99,7 @@ struct cpudata {
99 u64 prev_aperf; 99 u64 prev_aperf;
100 u64 prev_mperf; 100 u64 prev_mperf;
101 unsigned long long prev_tsc; 101 unsigned long long prev_tsc;
102 int sample_ptr; 102 struct sample sample;
103 struct sample samples[SAMPLE_COUNT];
104}; 103};
105 104
106static struct cpudata **all_cpu_data; 105static struct cpudata **all_cpu_data;
@@ -154,7 +153,7 @@ static inline void pid_reset(struct _pid *pid, int setpoint, int busy,
154 pid->setpoint = setpoint; 153 pid->setpoint = setpoint;
155 pid->deadband = deadband; 154 pid->deadband = deadband;
156 pid->integral = int_tofp(integral); 155 pid->integral = int_tofp(integral);
157 pid->last_err = setpoint - busy; 156 pid->last_err = int_tofp(setpoint) - int_tofp(busy);
158} 157}
159 158
160static inline void pid_p_gain_set(struct _pid *pid, int percent) 159static inline void pid_p_gain_set(struct _pid *pid, int percent)
@@ -586,15 +585,14 @@ static inline void intel_pstate_sample(struct cpudata *cpu)
586 mperf = mperf >> FRAC_BITS; 585 mperf = mperf >> FRAC_BITS;
587 tsc = tsc >> FRAC_BITS; 586 tsc = tsc >> FRAC_BITS;
588 587
589 cpu->sample_ptr = (cpu->sample_ptr + 1) % SAMPLE_COUNT; 588 cpu->sample.aperf = aperf;
590 cpu->samples[cpu->sample_ptr].aperf = aperf; 589 cpu->sample.mperf = mperf;
591 cpu->samples[cpu->sample_ptr].mperf = mperf; 590 cpu->sample.tsc = tsc;
592 cpu->samples[cpu->sample_ptr].tsc = tsc; 591 cpu->sample.aperf -= cpu->prev_aperf;
593 cpu->samples[cpu->sample_ptr].aperf -= cpu->prev_aperf; 592 cpu->sample.mperf -= cpu->prev_mperf;
594 cpu->samples[cpu->sample_ptr].mperf -= cpu->prev_mperf; 593 cpu->sample.tsc -= cpu->prev_tsc;
595 cpu->samples[cpu->sample_ptr].tsc -= cpu->prev_tsc;
596 594
597 intel_pstate_calc_busy(cpu, &cpu->samples[cpu->sample_ptr]); 595 intel_pstate_calc_busy(cpu, &cpu->sample);
598 596
599 cpu->prev_aperf = aperf; 597 cpu->prev_aperf = aperf;
600 cpu->prev_mperf = mperf; 598 cpu->prev_mperf = mperf;
@@ -614,7 +612,7 @@ static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)
614{ 612{
615 int32_t core_busy, max_pstate, current_pstate; 613 int32_t core_busy, max_pstate, current_pstate;
616 614
617 core_busy = cpu->samples[cpu->sample_ptr].core_pct_busy; 615 core_busy = cpu->sample.core_pct_busy;
618 max_pstate = int_tofp(cpu->pstate.max_pstate); 616 max_pstate = int_tofp(cpu->pstate.max_pstate);
619 current_pstate = int_tofp(cpu->pstate.current_pstate); 617 current_pstate = int_tofp(cpu->pstate.current_pstate);
620 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate)); 618 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate));
@@ -648,7 +646,7 @@ static void intel_pstate_timer_func(unsigned long __data)
648 646
649 intel_pstate_sample(cpu); 647 intel_pstate_sample(cpu);
650 648
651 sample = &cpu->samples[cpu->sample_ptr]; 649 sample = &cpu->sample;
652 650
653 intel_pstate_adjust_busy_pstate(cpu); 651 intel_pstate_adjust_busy_pstate(cpu);
654 652
@@ -729,7 +727,7 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
729 cpu = all_cpu_data[cpu_num]; 727 cpu = all_cpu_data[cpu_num];
730 if (!cpu) 728 if (!cpu)
731 return 0; 729 return 0;
732 sample = &cpu->samples[cpu->sample_ptr]; 730 sample = &cpu->sample;
733 return sample->freq; 731 return sample->freq;
734} 732}
735 733
diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
index eb7abe345b50..3d114bc5a97a 100644
--- a/drivers/cpufreq/kirkwood-cpufreq.c
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -102,7 +102,6 @@ static struct cpufreq_driver kirkwood_cpufreq_driver = {
102 .verify = cpufreq_generic_frequency_table_verify, 102 .verify = cpufreq_generic_frequency_table_verify,
103 .target_index = kirkwood_cpufreq_target, 103 .target_index = kirkwood_cpufreq_target,
104 .init = kirkwood_cpufreq_cpu_init, 104 .init = kirkwood_cpufreq_cpu_init,
105 .exit = cpufreq_generic_exit,
106 .name = "kirkwood-cpufreq", 105 .name = "kirkwood-cpufreq",
107 .attr = cpufreq_generic_attr, 106 .attr = cpufreq_generic_attr,
108}; 107};
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 45bafddfd8ea..7b94da3d2d10 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -913,7 +913,6 @@ static struct cpufreq_driver longhaul_driver = {
913 .target_index = longhaul_target, 913 .target_index = longhaul_target,
914 .get = longhaul_get, 914 .get = longhaul_get,
915 .init = longhaul_cpu_init, 915 .init = longhaul_cpu_init,
916 .exit = cpufreq_generic_exit,
917 .name = "longhaul", 916 .name = "longhaul",
918 .attr = cpufreq_generic_attr, 917 .attr = cpufreq_generic_attr,
919}; 918};
diff --git a/drivers/cpufreq/loongson2_cpufreq.c b/drivers/cpufreq/loongson2_cpufreq.c
index b6581abc9207..a3588d61d933 100644
--- a/drivers/cpufreq/loongson2_cpufreq.c
+++ b/drivers/cpufreq/loongson2_cpufreq.c
@@ -104,7 +104,6 @@ static int loongson2_cpufreq_cpu_init(struct cpufreq_policy *policy)
104 104
105static int loongson2_cpufreq_exit(struct cpufreq_policy *policy) 105static int loongson2_cpufreq_exit(struct cpufreq_policy *policy)
106{ 106{
107 cpufreq_frequency_table_put_attr(policy->cpu);
108 clk_put(policy->clk); 107 clk_put(policy->clk);
109 return 0; 108 return 0;
110} 109}
diff --git a/drivers/cpufreq/omap-cpufreq.c b/drivers/cpufreq/omap-cpufreq.c
index 590f5b66d181..5f69c9aa703c 100644
--- a/drivers/cpufreq/omap-cpufreq.c
+++ b/drivers/cpufreq/omap-cpufreq.c
@@ -143,7 +143,6 @@ fail:
143 143
144static int omap_cpu_exit(struct cpufreq_policy *policy) 144static int omap_cpu_exit(struct cpufreq_policy *policy)
145{ 145{
146 cpufreq_frequency_table_put_attr(policy->cpu);
147 freq_table_free(); 146 freq_table_free();
148 clk_put(policy->clk); 147 clk_put(policy->clk);
149 return 0; 148 return 0;
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
index 3d1cba9fd5f9..74f593e70e19 100644
--- a/drivers/cpufreq/p4-clockmod.c
+++ b/drivers/cpufreq/p4-clockmod.c
@@ -237,7 +237,6 @@ static struct cpufreq_driver p4clockmod_driver = {
237 .verify = cpufreq_generic_frequency_table_verify, 237 .verify = cpufreq_generic_frequency_table_verify,
238 .target_index = cpufreq_p4_target, 238 .target_index = cpufreq_p4_target,
239 .init = cpufreq_p4_cpu_init, 239 .init = cpufreq_p4_cpu_init,
240 .exit = cpufreq_generic_exit,
241 .get = cpufreq_p4_get, 240 .get = cpufreq_p4_get,
242 .name = "p4-clockmod", 241 .name = "p4-clockmod",
243 .attr = cpufreq_generic_attr, 242 .attr = cpufreq_generic_attr,
diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
index 0426008380d8..6a2b7d3e85a7 100644
--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -234,7 +234,6 @@ static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy)
234 if (sdcpwr_mapbase) 234 if (sdcpwr_mapbase)
235 iounmap(sdcpwr_mapbase); 235 iounmap(sdcpwr_mapbase);
236 236
237 cpufreq_frequency_table_put_attr(policy->cpu);
238 return 0; 237 return 0;
239} 238}
240 239
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index b9a444e358b5..ce27e6c26c94 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -231,7 +231,6 @@ static int powernow_k6_cpu_exit(struct cpufreq_policy *policy)
231 if (i == max_multiplier) 231 if (i == max_multiplier)
232 powernow_k6_target(policy, i); 232 powernow_k6_target(policy, i);
233 } 233 }
234 cpufreq_frequency_table_put_attr(policy->cpu);
235 return 0; 234 return 0;
236} 235}
237 236
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index 946708a1d745..0e68e0275621 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -664,8 +664,6 @@ static int powernow_cpu_init(struct cpufreq_policy *policy)
664 664
665static int powernow_cpu_exit(struct cpufreq_policy *policy) 665static int powernow_cpu_exit(struct cpufreq_policy *policy)
666{ 666{
667 cpufreq_frequency_table_put_attr(policy->cpu);
668
669#ifdef CONFIG_X86_POWERNOW_K7_ACPI 667#ifdef CONFIG_X86_POWERNOW_K7_ACPI
670 if (acpi_processor_perf) { 668 if (acpi_processor_perf) {
671 acpi_processor_unregister_performance(acpi_processor_perf, 0); 669 acpi_processor_unregister_performance(acpi_processor_perf, 0);
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index 6684e0342792..27eb2be44de5 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -1164,8 +1164,6 @@ static int powernowk8_cpu_exit(struct cpufreq_policy *pol)
1164 1164
1165 powernow_k8_cpu_exit_acpi(data); 1165 powernow_k8_cpu_exit_acpi(data);
1166 1166
1167 cpufreq_frequency_table_put_attr(pol->cpu);
1168
1169 kfree(data->powernow_table); 1167 kfree(data->powernow_table);
1170 kfree(data); 1168 kfree(data);
1171 for_each_cpu(cpu, pol->cpus) 1169 for_each_cpu(cpu, pol->cpus)
diff --git a/drivers/cpufreq/ppc-corenet-cpufreq.c b/drivers/cpufreq/ppc-corenet-cpufreq.c
index 051000f44ca2..037949d575bd 100644
--- a/drivers/cpufreq/ppc-corenet-cpufreq.c
+++ b/drivers/cpufreq/ppc-corenet-cpufreq.c
@@ -228,7 +228,6 @@ static int __exit corenet_cpufreq_cpu_exit(struct cpufreq_policy *policy)
228 struct cpu_data *data = per_cpu(cpu_data, policy->cpu); 228 struct cpu_data *data = per_cpu(cpu_data, policy->cpu);
229 unsigned int cpu; 229 unsigned int cpu;
230 230
231 cpufreq_frequency_table_put_attr(policy->cpu);
232 of_node_put(data->parent); 231 of_node_put(data->parent);
233 kfree(data->table); 232 kfree(data->table);
234 kfree(data); 233 kfree(data);
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index e42ca9c31cea..af7b1cabd1e7 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -141,7 +141,6 @@ static struct cpufreq_driver cbe_cpufreq_driver = {
141 .verify = cpufreq_generic_frequency_table_verify, 141 .verify = cpufreq_generic_frequency_table_verify,
142 .target_index = cbe_cpufreq_target, 142 .target_index = cbe_cpufreq_target,
143 .init = cbe_cpufreq_cpu_init, 143 .init = cbe_cpufreq_cpu_init,
144 .exit = cpufreq_generic_exit,
145 .name = "cbe-cpufreq", 144 .name = "cbe-cpufreq",
146 .flags = CPUFREQ_CONST_LOOPS, 145 .flags = CPUFREQ_CONST_LOOPS,
147}; 146};
diff --git a/drivers/cpufreq/pxa2xx-cpufreq.c b/drivers/cpufreq/pxa2xx-cpufreq.c
index a9195a86b069..e24269ab4e9b 100644
--- a/drivers/cpufreq/pxa2xx-cpufreq.c
+++ b/drivers/cpufreq/pxa2xx-cpufreq.c
@@ -427,7 +427,6 @@ static struct cpufreq_driver pxa_cpufreq_driver = {
427 .verify = cpufreq_generic_frequency_table_verify, 427 .verify = cpufreq_generic_frequency_table_verify,
428 .target_index = pxa_set_target, 428 .target_index = pxa_set_target,
429 .init = pxa_cpufreq_init, 429 .init = pxa_cpufreq_init,
430 .exit = cpufreq_generic_exit,
431 .get = pxa_cpufreq_get, 430 .get = pxa_cpufreq_get,
432 .name = "PXA2xx", 431 .name = "PXA2xx",
433}; 432};
diff --git a/drivers/cpufreq/pxa3xx-cpufreq.c b/drivers/cpufreq/pxa3xx-cpufreq.c
index 3785687e9d70..a01275900389 100644
--- a/drivers/cpufreq/pxa3xx-cpufreq.c
+++ b/drivers/cpufreq/pxa3xx-cpufreq.c
@@ -205,7 +205,6 @@ static struct cpufreq_driver pxa3xx_cpufreq_driver = {
205 .verify = cpufreq_generic_frequency_table_verify, 205 .verify = cpufreq_generic_frequency_table_verify,
206 .target_index = pxa3xx_cpufreq_set, 206 .target_index = pxa3xx_cpufreq_set,
207 .init = pxa3xx_cpufreq_init, 207 .init = pxa3xx_cpufreq_init,
208 .exit = cpufreq_generic_exit,
209 .get = pxa3xx_cpufreq_get, 208 .get = pxa3xx_cpufreq_get,
210 .name = "pxa3xx-cpufreq", 209 .name = "pxa3xx-cpufreq",
211}; 210};
diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
index 55a8e9fa9435..72421534fff5 100644
--- a/drivers/cpufreq/s5pv210-cpufreq.c
+++ b/drivers/cpufreq/s5pv210-cpufreq.c
@@ -18,7 +18,6 @@
18#include <linux/cpufreq.h> 18#include <linux/cpufreq.h>
19#include <linux/reboot.h> 19#include <linux/reboot.h>
20#include <linux/regulator/consumer.h> 20#include <linux/regulator/consumer.h>
21#include <linux/suspend.h>
22 21
23#include <mach/map.h> 22#include <mach/map.h>
24#include <mach/regs-clock.h> 23#include <mach/regs-clock.h>
@@ -435,18 +434,6 @@ exit:
435 return ret; 434 return ret;
436} 435}
437 436
438#ifdef CONFIG_PM
439static int s5pv210_cpufreq_suspend(struct cpufreq_policy *policy)
440{
441 return 0;
442}
443
444static int s5pv210_cpufreq_resume(struct cpufreq_policy *policy)
445{
446 return 0;
447}
448#endif
449
450static int check_mem_type(void __iomem *dmc_reg) 437static int check_mem_type(void __iomem *dmc_reg)
451{ 438{
452 unsigned long val; 439 unsigned long val;
@@ -502,6 +489,7 @@ static int __init s5pv210_cpu_init(struct cpufreq_policy *policy)
502 s5pv210_dram_conf[1].refresh = (__raw_readl(S5P_VA_DMC1 + 0x30) * 1000); 489 s5pv210_dram_conf[1].refresh = (__raw_readl(S5P_VA_DMC1 + 0x30) * 1000);
503 s5pv210_dram_conf[1].freq = clk_get_rate(dmc1_clk); 490 s5pv210_dram_conf[1].freq = clk_get_rate(dmc1_clk);
504 491
492 policy->suspend_freq = SLEEP_FREQ;
505 return cpufreq_generic_init(policy, s5pv210_freq_table, 40000); 493 return cpufreq_generic_init(policy, s5pv210_freq_table, 40000);
506 494
507out_dmc1: 495out_dmc1:
@@ -511,32 +499,6 @@ out_dmc0:
511 return ret; 499 return ret;
512} 500}
513 501
514static int s5pv210_cpufreq_notifier_event(struct notifier_block *this,
515 unsigned long event, void *ptr)
516{
517 int ret;
518
519 switch (event) {
520 case PM_SUSPEND_PREPARE:
521 ret = cpufreq_driver_target(cpufreq_cpu_get(0), SLEEP_FREQ, 0);
522 if (ret < 0)
523 return NOTIFY_BAD;
524
525 /* Disable updation of cpu frequency */
526 no_cpufreq_access = true;
527 return NOTIFY_OK;
528 case PM_POST_RESTORE:
529 case PM_POST_SUSPEND:
530 /* Enable updation of cpu frequency */
531 no_cpufreq_access = false;
532 cpufreq_driver_target(cpufreq_cpu_get(0), SLEEP_FREQ, 0);
533
534 return NOTIFY_OK;
535 }
536
537 return NOTIFY_DONE;
538}
539
540static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this, 502static int s5pv210_cpufreq_reboot_notifier_event(struct notifier_block *this,
541 unsigned long event, void *ptr) 503 unsigned long event, void *ptr)
542{ 504{
@@ -558,15 +520,11 @@ static struct cpufreq_driver s5pv210_driver = {
558 .init = s5pv210_cpu_init, 520 .init = s5pv210_cpu_init,
559 .name = "s5pv210", 521 .name = "s5pv210",
560#ifdef CONFIG_PM 522#ifdef CONFIG_PM
561 .suspend = s5pv210_cpufreq_suspend, 523 .suspend = cpufreq_generic_suspend,
562 .resume = s5pv210_cpufreq_resume, 524 .resume = cpufreq_generic_suspend, /* We need to set SLEEP FREQ again */
563#endif 525#endif
564}; 526};
565 527
566static struct notifier_block s5pv210_cpufreq_notifier = {
567 .notifier_call = s5pv210_cpufreq_notifier_event,
568};
569
570static struct notifier_block s5pv210_cpufreq_reboot_notifier = { 528static struct notifier_block s5pv210_cpufreq_reboot_notifier = {
571 .notifier_call = s5pv210_cpufreq_reboot_notifier_event, 529 .notifier_call = s5pv210_cpufreq_reboot_notifier_event,
572}; 530};
@@ -586,7 +544,6 @@ static int __init s5pv210_cpufreq_init(void)
586 return PTR_ERR(int_regulator); 544 return PTR_ERR(int_regulator);
587 } 545 }
588 546
589 register_pm_notifier(&s5pv210_cpufreq_notifier);
590 register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier); 547 register_reboot_notifier(&s5pv210_cpufreq_reboot_notifier);
591 548
592 return cpufreq_register_driver(&s5pv210_driver); 549 return cpufreq_register_driver(&s5pv210_driver);
diff --git a/drivers/cpufreq/sc520_freq.c b/drivers/cpufreq/sc520_freq.c
index 6adb354e359c..69371bf0886d 100644
--- a/drivers/cpufreq/sc520_freq.c
+++ b/drivers/cpufreq/sc520_freq.c
@@ -93,7 +93,6 @@ static struct cpufreq_driver sc520_freq_driver = {
93 .verify = cpufreq_generic_frequency_table_verify, 93 .verify = cpufreq_generic_frequency_table_verify,
94 .target_index = sc520_freq_target, 94 .target_index = sc520_freq_target,
95 .init = sc520_freq_cpu_init, 95 .init = sc520_freq_cpu_init,
96 .exit = cpufreq_generic_exit,
97 .name = "sc520_freq", 96 .name = "sc520_freq",
98 .attr = cpufreq_generic_attr, 97 .attr = cpufreq_generic_attr,
99}; 98};
diff --git a/drivers/cpufreq/sh-cpufreq.c b/drivers/cpufreq/sh-cpufreq.c
index 387af12503a6..696170ebd3a3 100644
--- a/drivers/cpufreq/sh-cpufreq.c
+++ b/drivers/cpufreq/sh-cpufreq.c
@@ -143,7 +143,6 @@ static int sh_cpufreq_cpu_exit(struct cpufreq_policy *policy)
143 unsigned int cpu = policy->cpu; 143 unsigned int cpu = policy->cpu;
144 struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu); 144 struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu);
145 145
146 cpufreq_frequency_table_put_attr(cpu);
147 clk_put(cpuclk); 146 clk_put(cpuclk);
148 147
149 return 0; 148 return 0;
diff --git a/drivers/cpufreq/sparc-us2e-cpufreq.c b/drivers/cpufreq/sparc-us2e-cpufreq.c
index 62aa23e219d4..b73feeb666f9 100644
--- a/drivers/cpufreq/sparc-us2e-cpufreq.c
+++ b/drivers/cpufreq/sparc-us2e-cpufreq.c
@@ -301,10 +301,8 @@ static int __init us2e_freq_cpu_init(struct cpufreq_policy *policy)
301 301
302static int us2e_freq_cpu_exit(struct cpufreq_policy *policy) 302static int us2e_freq_cpu_exit(struct cpufreq_policy *policy)
303{ 303{
304 if (cpufreq_us2e_driver) { 304 if (cpufreq_us2e_driver)
305 cpufreq_frequency_table_put_attr(policy->cpu);
306 us2e_freq_target(policy, 0); 305 us2e_freq_target(policy, 0);
307 }
308 306
309 return 0; 307 return 0;
310} 308}
diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
index 724ffbd7105d..9bb42ba50efa 100644
--- a/drivers/cpufreq/sparc-us3-cpufreq.c
+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
@@ -156,10 +156,8 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
156 156
157static int us3_freq_cpu_exit(struct cpufreq_policy *policy) 157static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
158{ 158{
159 if (cpufreq_us3_driver) { 159 if (cpufreq_us3_driver)
160 cpufreq_frequency_table_put_attr(policy->cpu);
161 us3_freq_target(policy, 0); 160 us3_freq_target(policy, 0);
162 }
163 161
164 return 0; 162 return 0;
165} 163}
diff --git a/drivers/cpufreq/spear-cpufreq.c b/drivers/cpufreq/spear-cpufreq.c
index 5c86e3fa5593..4cfdcff8a310 100644
--- a/drivers/cpufreq/spear-cpufreq.c
+++ b/drivers/cpufreq/spear-cpufreq.c
@@ -19,6 +19,7 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/of_device.h> 21#include <linux/of_device.h>
22#include <linux/platform_device.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23#include <linux/types.h> 24#include <linux/types.h>
24 25
@@ -163,11 +164,10 @@ static struct cpufreq_driver spear_cpufreq_driver = {
163 .target_index = spear_cpufreq_target, 164 .target_index = spear_cpufreq_target,
164 .get = cpufreq_generic_get, 165 .get = cpufreq_generic_get,
165 .init = spear_cpufreq_init, 166 .init = spear_cpufreq_init,
166 .exit = cpufreq_generic_exit,
167 .attr = cpufreq_generic_attr, 167 .attr = cpufreq_generic_attr,
168}; 168};
169 169
170static int spear_cpufreq_driver_init(void) 170static int spear_cpufreq_probe(struct platform_device *pdev)
171{ 171{
172 struct device_node *np; 172 struct device_node *np;
173 const struct property *prop; 173 const struct property *prop;
@@ -235,7 +235,15 @@ out_put_node:
235 of_node_put(np); 235 of_node_put(np);
236 return ret; 236 return ret;
237} 237}
238late_initcall(spear_cpufreq_driver_init); 238
239static struct platform_driver spear_cpufreq_platdrv = {
240 .driver = {
241 .name = "spear-cpufreq",
242 .owner = THIS_MODULE,
243 },
244 .probe = spear_cpufreq_probe,
245};
246module_platform_driver(spear_cpufreq_platdrv);
239 247
240MODULE_AUTHOR("Deepak Sikri <deepak.sikri@st.com>"); 248MODULE_AUTHOR("Deepak Sikri <deepak.sikri@st.com>");
241MODULE_DESCRIPTION("SPEAr CPUFreq driver"); 249MODULE_DESCRIPTION("SPEAr CPUFreq driver");
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 4e1daca5ce3b..6723f0390f20 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -406,8 +406,6 @@ static int centrino_cpu_exit(struct cpufreq_policy *policy)
406 if (!per_cpu(centrino_model, cpu)) 406 if (!per_cpu(centrino_model, cpu))
407 return -ENODEV; 407 return -ENODEV;
408 408
409 cpufreq_frequency_table_put_attr(cpu);
410
411 per_cpu(centrino_model, cpu) = NULL; 409 per_cpu(centrino_model, cpu) = NULL;
412 410
413 return 0; 411 return 0;
diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
index 7639b2be2a90..394ac159312a 100644
--- a/drivers/cpufreq/speedstep-ich.c
+++ b/drivers/cpufreq/speedstep-ich.c
@@ -311,7 +311,6 @@ static struct cpufreq_driver speedstep_driver = {
311 .verify = cpufreq_generic_frequency_table_verify, 311 .verify = cpufreq_generic_frequency_table_verify,
312 .target_index = speedstep_target, 312 .target_index = speedstep_target,
313 .init = speedstep_cpu_init, 313 .init = speedstep_cpu_init,
314 .exit = cpufreq_generic_exit,
315 .get = speedstep_get, 314 .get = speedstep_get,
316 .attr = cpufreq_generic_attr, 315 .attr = cpufreq_generic_attr,
317}; 316};
diff --git a/drivers/cpufreq/speedstep-smi.c b/drivers/cpufreq/speedstep-smi.c
index 998c17b42200..db5d274dc13a 100644
--- a/drivers/cpufreq/speedstep-smi.c
+++ b/drivers/cpufreq/speedstep-smi.c
@@ -280,7 +280,6 @@ static struct cpufreq_driver speedstep_driver = {
280 .verify = cpufreq_generic_frequency_table_verify, 280 .verify = cpufreq_generic_frequency_table_verify,
281 .target_index = speedstep_target, 281 .target_index = speedstep_target,
282 .init = speedstep_cpu_init, 282 .init = speedstep_cpu_init,
283 .exit = cpufreq_generic_exit,
284 .get = speedstep_get, 283 .get = speedstep_get,
285 .resume = speedstep_resume, 284 .resume = speedstep_resume,
286 .attr = cpufreq_generic_attr, 285 .attr = cpufreq_generic_attr,
diff --git a/drivers/cpufreq/tegra-cpufreq.c b/drivers/cpufreq/tegra-cpufreq.c
index e652c1bd8d0f..63f00598a251 100644
--- a/drivers/cpufreq/tegra-cpufreq.c
+++ b/drivers/cpufreq/tegra-cpufreq.c
@@ -26,7 +26,6 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/clk.h> 27#include <linux/clk.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/suspend.h>
30 29
31static struct cpufreq_frequency_table freq_table[] = { 30static struct cpufreq_frequency_table freq_table[] = {
32 { .frequency = 216000 }, 31 { .frequency = 216000 },
@@ -47,9 +46,6 @@ static struct clk *pll_x_clk;
47static struct clk *pll_p_clk; 46static struct clk *pll_p_clk;
48static struct clk *emc_clk; 47static struct clk *emc_clk;
49 48
50static DEFINE_MUTEX(tegra_cpu_lock);
51static bool is_suspended;
52
53static int tegra_cpu_clk_set_rate(unsigned long rate) 49static int tegra_cpu_clk_set_rate(unsigned long rate)
54{ 50{
55 int ret; 51 int ret;
@@ -112,42 +108,9 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,
112 108
113static int tegra_target(struct cpufreq_policy *policy, unsigned int index) 109static int tegra_target(struct cpufreq_policy *policy, unsigned int index)
114{ 110{
115 int ret = -EBUSY; 111 return tegra_update_cpu_speed(policy, freq_table[index].frequency);
116
117 mutex_lock(&tegra_cpu_lock);
118
119 if (!is_suspended)
120 ret = tegra_update_cpu_speed(policy,
121 freq_table[index].frequency);
122
123 mutex_unlock(&tegra_cpu_lock);
124 return ret;
125} 112}
126 113
127static int tegra_pm_notify(struct notifier_block *nb, unsigned long event,
128 void *dummy)
129{
130 mutex_lock(&tegra_cpu_lock);
131 if (event == PM_SUSPEND_PREPARE) {
132 struct cpufreq_policy *policy = cpufreq_cpu_get(0);
133 is_suspended = true;
134 pr_info("Tegra cpufreq suspend: setting frequency to %d kHz\n",
135 freq_table[0].frequency);
136 if (clk_get_rate(cpu_clk) / 1000 != freq_table[0].frequency)
137 tegra_update_cpu_speed(policy, freq_table[0].frequency);
138 cpufreq_cpu_put(policy);
139 } else if (event == PM_POST_SUSPEND) {
140 is_suspended = false;
141 }
142 mutex_unlock(&tegra_cpu_lock);
143
144 return NOTIFY_OK;
145}
146
147static struct notifier_block tegra_cpu_pm_notifier = {
148 .notifier_call = tegra_pm_notify,
149};
150
151static int tegra_cpu_init(struct cpufreq_policy *policy) 114static int tegra_cpu_init(struct cpufreq_policy *policy)
152{ 115{
153 int ret; 116 int ret;
@@ -166,16 +129,13 @@ static int tegra_cpu_init(struct cpufreq_policy *policy)
166 return ret; 129 return ret;
167 } 130 }
168 131
169 if (policy->cpu == 0)
170 register_pm_notifier(&tegra_cpu_pm_notifier);
171
172 policy->clk = cpu_clk; 132 policy->clk = cpu_clk;
133 policy->suspend_freq = freq_table[0].frequency;
173 return 0; 134 return 0;
174} 135}
175 136
176static int tegra_cpu_exit(struct cpufreq_policy *policy) 137static int tegra_cpu_exit(struct cpufreq_policy *policy)
177{ 138{
178 cpufreq_frequency_table_put_attr(policy->cpu);
179 clk_disable_unprepare(cpu_clk); 139 clk_disable_unprepare(cpu_clk);
180 clk_disable_unprepare(emc_clk); 140 clk_disable_unprepare(emc_clk);
181 return 0; 141 return 0;
@@ -190,6 +150,9 @@ static struct cpufreq_driver tegra_cpufreq_driver = {
190 .exit = tegra_cpu_exit, 150 .exit = tegra_cpu_exit,
191 .name = "tegra", 151 .name = "tegra",
192 .attr = cpufreq_generic_attr, 152 .attr = cpufreq_generic_attr,
153#ifdef CONFIG_PM
154 .suspend = cpufreq_generic_suspend,
155#endif
193}; 156};
194 157
195static int __init tegra_cpufreq_init(void) 158static int __init tegra_cpufreq_init(void)