aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-03-20 08:26:12 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-03-20 08:26:12 -0400
commit5a2d853ffcf961d6b7d491858946878676aeae3e (patch)
tree175363121484297399d90cd1c25b4035f2463e5c
parentf71a822fc09f45d2e9e0476d8bf026aff21d4139 (diff)
parentbb18008f8086283f8f03e8e50fbbf17f213b9ea9 (diff)
Merge branch 'pm-cpufreq'
* pm-cpufreq: (30 commits) intel_pstate: Set core to min P state during core offline cpufreq: Add stop CPU callback to cpufreq_driver interface cpufreq: Remove unnecessary braces cpufreq: Fix checkpatch errors and warnings cpufreq: powerpc: add cpufreq transition latency for FSL e500mc SoCs cpufreq: remove unused notifier: CPUFREQ_{SUSPENDCHANGE|RESUMECHANGE} cpufreq: Do not allow ->setpolicy drivers to provide ->target cpufreq: arm_big_little: set 'physical_cluster' for each CPU cpufreq: arm_big_little: make vexpress driver depend on bL core driver cpufreq: SPEAr: Instantiate as platform_driver cpufreq: Remove unnecessary variable/parameter 'frozen' cpufreq: Remove cpufreq_generic_exit() cpufreq: add 'freq_table' in struct cpufreq_policy cpufreq: Reformat printk() statements cpufreq: Tegra: Use cpufreq_generic_suspend() cpufreq: s5pv210: Use cpufreq_generic_suspend() cpufreq: exynos: Use cpufreq_generic_suspend() cpufreq: Implement cpufreq_generic_suspend() cpufreq: suspend governors on system suspend/hibernate cpufreq: move call to __find_governor() to cpufreq_init_policy() ...
-rw-r--r--Documentation/cpu-freq/core.txt4
-rw-r--r--Documentation/cpu-freq/cpu-drivers.txt8
-rw-r--r--arch/arm/kernel/smp.c3
-rw-r--r--arch/arm/kernel/smp_twd.c2
-rw-r--r--arch/arm/mach-pxa/viper.c3
-rw-r--r--arch/arm/mach-spear/spear1310.c1
-rw-r--r--arch/arm/mach-spear/spear1340.c1
-rw-r--r--arch/arm64/Kconfig8
-rw-r--r--arch/powerpc/oprofile/op_model_cell.c3
-rw-r--r--arch/sparc/kernel/time_64.c3
-rw-r--r--arch/x86/kernel/tsc.c3
-rw-r--r--drivers/base/power/main.c5
-rw-r--r--drivers/cpufreq/Kconfig2
-rw-r--r--drivers/cpufreq/Kconfig.arm17
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c1
-rw-r--r--drivers/cpufreq/arm_big_little.c6
-rw-r--r--drivers/cpufreq/blackfin-cpufreq.c1
-rw-r--r--drivers/cpufreq/cpufreq-cpu0.c1
-rw-r--r--drivers/cpufreq/cpufreq.c446
-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.c45
-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.c5
-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
-rw-r--r--drivers/pcmcia/sa11xx_base.c3
-rw-r--r--drivers/tty/serial/sh-sci.c3
-rw-r--r--include/linux/cpufreq.h25
57 files changed, 357 insertions, 569 deletions
diff --git a/Documentation/cpu-freq/core.txt b/Documentation/cpu-freq/core.txt
index ce0666e51036..0060d76b445f 100644
--- a/Documentation/cpu-freq/core.txt
+++ b/Documentation/cpu-freq/core.txt
@@ -92,7 +92,3 @@ values:
92cpu - number of the affected CPU 92cpu - number of the affected CPU
93old - old frequency 93old - old frequency
94new - new frequency 94new - new frequency
95
96If the cpufreq core detects the frequency has changed while the system
97was suspended, these notifiers are called with CPUFREQ_RESUMECHANGE as
98second argument.
diff --git a/Documentation/cpu-freq/cpu-drivers.txt b/Documentation/cpu-freq/cpu-drivers.txt
index 8b1a4451422e..48da5fdcb9f1 100644
--- a/Documentation/cpu-freq/cpu-drivers.txt
+++ b/Documentation/cpu-freq/cpu-drivers.txt
@@ -61,7 +61,13 @@ target_index - See below on the differences.
61 61
62And optionally 62And optionally
63 63
64cpufreq_driver.exit - A pointer to a per-CPU cleanup function. 64cpufreq_driver.exit - A pointer to a per-CPU cleanup
65 function called during CPU_POST_DEAD
66 phase of cpu hotplug process.
67
68cpufreq_driver.stop_cpu - A pointer to a per-CPU stop function
69 called during CPU_DOWN_PREPARE phase of
70 cpu hotplug process.
65 71
66cpufreq_driver.resume - A pointer to a per-CPU resume function 72cpufreq_driver.resume - A pointer to a per-CPU resume function
67 which is called with interrupts disabled 73 which is called with interrupts disabled
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index b7b4c86e338b..7c4fada440f0 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -674,8 +674,7 @@ static int cpufreq_callback(struct notifier_block *nb,
674 } 674 }
675 675
676 if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) || 676 if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) ||
677 (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) || 677 (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) {
678 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
679 loops_per_jiffy = cpufreq_scale(global_l_p_j_ref, 678 loops_per_jiffy = cpufreq_scale(global_l_p_j_ref,
680 global_l_p_j_ref_freq, 679 global_l_p_j_ref_freq,
681 freq->new); 680 freq->new);
diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index 6591e26fc13f..dfc32130bc44 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -166,7 +166,7 @@ static int twd_cpufreq_transition(struct notifier_block *nb,
166 * frequency. The timer is local to a cpu, so cross-call to the 166 * frequency. The timer is local to a cpu, so cross-call to the
167 * changing cpu. 167 * changing cpu.
168 */ 168 */
169 if (state == CPUFREQ_POSTCHANGE || state == CPUFREQ_RESUMECHANGE) 169 if (state == CPUFREQ_POSTCHANGE)
170 smp_call_function_single(freqs->cpu, twd_update_frequency, 170 smp_call_function_single(freqs->cpu, twd_update_frequency,
171 NULL, 1); 171 NULL, 1);
172 172
diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index 29905b127ad9..41f27f667ca8 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -885,9 +885,6 @@ static int viper_cpufreq_notifier(struct notifier_block *nb,
885 viper_set_core_cpu_voltage(freq->new, 0); 885 viper_set_core_cpu_voltage(freq->new, 0);
886 } 886 }
887 break; 887 break;
888 case CPUFREQ_RESUMECHANGE:
889 viper_set_core_cpu_voltage(freq->new, 0);
890 break;
891 default: 888 default:
892 /* ignore */ 889 /* ignore */
893 break; 890 break;
diff --git a/arch/arm/mach-spear/spear1310.c b/arch/arm/mach-spear/spear1310.c
index 7ad003001ab7..824b12a56a42 100644
--- a/arch/arm/mach-spear/spear1310.c
+++ b/arch/arm/mach-spear/spear1310.c
@@ -28,6 +28,7 @@
28static void __init spear1310_dt_init(void) 28static void __init spear1310_dt_init(void)
29{ 29{
30 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); 30 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
31 platform_device_register_simple("spear-cpufreq", -1, NULL, 0);
31} 32}
32 33
33static const char * const spear1310_dt_board_compat[] = { 34static const char * const spear1310_dt_board_compat[] = {
diff --git a/arch/arm/mach-spear/spear1340.c b/arch/arm/mach-spear/spear1340.c
index 3fb683424729..7b6bff7154e1 100644
--- a/arch/arm/mach-spear/spear1340.c
+++ b/arch/arm/mach-spear/spear1340.c
@@ -143,6 +143,7 @@ static void __init spear1340_dt_init(void)
143{ 143{
144 of_platform_populate(NULL, of_default_bus_match_table, 144 of_platform_populate(NULL, of_default_bus_match_table,
145 spear1340_auxdata_lookup, NULL); 145 spear1340_auxdata_lookup, NULL);
146 platform_device_register_simple("spear-cpufreq", -1, NULL, 0);
146} 147}
147 148
148static const char * const spear1340_dt_board_compat[] = { 149static const char * const spear1340_dt_board_compat[] = {
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 27bbcfc7202a..c6e2f5bb1a7b 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -303,6 +303,14 @@ source "drivers/cpuidle/Kconfig"
303 303
304endmenu 304endmenu
305 305
306menu "Power management options"
307
308source "kernel/power/Kconfig"
309
310source "drivers/cpufreq/Kconfig"
311
312endmenu
313
306source "net/Kconfig" 314source "net/Kconfig"
307 315
308source "drivers/Kconfig" 316source "drivers/Kconfig"
diff --git a/arch/powerpc/oprofile/op_model_cell.c b/arch/powerpc/oprofile/op_model_cell.c
index 1f0ebdeea5f7..863d89386f60 100644
--- a/arch/powerpc/oprofile/op_model_cell.c
+++ b/arch/powerpc/oprofile/op_model_cell.c
@@ -1121,8 +1121,7 @@ oprof_cpufreq_notify(struct notifier_block *nb, unsigned long val, void *data)
1121 int ret = 0; 1121 int ret = 0;
1122 struct cpufreq_freqs *frq = data; 1122 struct cpufreq_freqs *frq = data;
1123 if ((val == CPUFREQ_PRECHANGE && frq->old < frq->new) || 1123 if ((val == CPUFREQ_PRECHANGE && frq->old < frq->new) ||
1124 (val == CPUFREQ_POSTCHANGE && frq->old > frq->new) || 1124 (val == CPUFREQ_POSTCHANGE && frq->old > frq->new))
1125 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE))
1126 set_spu_profiling_frequency(frq->new, spu_cycle_reset); 1125 set_spu_profiling_frequency(frq->new, spu_cycle_reset);
1127 return ret; 1126 return ret;
1128} 1127}
diff --git a/arch/sparc/kernel/time_64.c b/arch/sparc/kernel/time_64.c
index c3d82b5f54ca..b397e053b872 100644
--- a/arch/sparc/kernel/time_64.c
+++ b/arch/sparc/kernel/time_64.c
@@ -659,8 +659,7 @@ static int sparc64_cpufreq_notifier(struct notifier_block *nb, unsigned long val
659 ft->clock_tick_ref = cpu_data(cpu).clock_tick; 659 ft->clock_tick_ref = cpu_data(cpu).clock_tick;
660 } 660 }
661 if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) || 661 if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) ||
662 (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) || 662 (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) {
663 (val == CPUFREQ_RESUMECHANGE)) {
664 cpu_data(cpu).clock_tick = 663 cpu_data(cpu).clock_tick =
665 cpufreq_scale(ft->clock_tick_ref, 664 cpufreq_scale(ft->clock_tick_ref,
666 ft->ref_freq, 665 ft->ref_freq,
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index cfbe99f88830..7a9296ab8834 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -914,8 +914,7 @@ static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
914 tsc_khz_ref = tsc_khz; 914 tsc_khz_ref = tsc_khz;
915 } 915 }
916 if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) || 916 if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) ||
917 (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) || 917 (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) {
918 (val == CPUFREQ_RESUMECHANGE)) {
919 *lpj = cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new); 918 *lpj = cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
920 919
921 tsc_khz = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new); 920 tsc_khz = cpufreq_scale(tsc_khz_ref, ref_freq, freq->new);
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 42355e442a5d..86d5e4fb5b98 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -29,6 +29,7 @@
29#include <linux/async.h> 29#include <linux/async.h>
30#include <linux/suspend.h> 30#include <linux/suspend.h>
31#include <trace/events/power.h> 31#include <trace/events/power.h>
32#include <linux/cpufreq.h>
32#include <linux/cpuidle.h> 33#include <linux/cpuidle.h>
33#include <linux/timer.h> 34#include <linux/timer.h>
34 35
@@ -866,6 +867,8 @@ void dpm_resume(pm_message_t state)
866 mutex_unlock(&dpm_list_mtx); 867 mutex_unlock(&dpm_list_mtx);
867 async_synchronize_full(); 868 async_synchronize_full();
868 dpm_show_time(starttime, state, NULL); 869 dpm_show_time(starttime, state, NULL);
870
871 cpufreq_resume();
869} 872}
870 873
871/** 874/**
@@ -1434,6 +1437,8 @@ int dpm_suspend(pm_message_t state)
1434 1437
1435 might_sleep(); 1438 might_sleep();
1436 1439
1440 cpufreq_suspend();
1441
1437 mutex_lock(&dpm_list_mtx); 1442 mutex_lock(&dpm_list_mtx);
1438 pm_transition = state; 1443 pm_transition = state;
1439 async_error = 0; 1444 async_error = 0;
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/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 31297499a60a..9fb627046e17 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -2,6 +2,7 @@
2# ARM CPU Frequency scaling drivers 2# ARM CPU Frequency scaling drivers
3# 3#
4 4
5# big LITTLE core layer and glue drivers
5config ARM_BIG_LITTLE_CPUFREQ 6config ARM_BIG_LITTLE_CPUFREQ
6 tristate "Generic ARM big LITTLE CPUfreq driver" 7 tristate "Generic ARM big LITTLE CPUfreq driver"
7 depends on ARM && BIG_LITTLE && ARM_CPU_TOPOLOGY && HAVE_CLK 8 depends on ARM && BIG_LITTLE && ARM_CPU_TOPOLOGY && HAVE_CLK
@@ -16,6 +17,14 @@ config ARM_DT_BL_CPUFREQ
16 This enables probing via DT for Generic CPUfreq driver for ARM 17 This enables probing via DT for Generic CPUfreq driver for ARM
17 big.LITTLE platform. This gets frequency tables from DT. 18 big.LITTLE platform. This gets frequency tables from DT.
18 19
20config ARM_VEXPRESS_SPC_CPUFREQ
21 tristate "Versatile Express SPC based CPUfreq driver"
22 depends on ARM_BIG_LITTLE_CPUFREQ && ARCH_VEXPRESS_SPC
23 help
24 This add the CPUfreq driver support for Versatile Express
25 big.LITTLE platforms using SPC for power management.
26
27
19config ARM_EXYNOS_CPUFREQ 28config ARM_EXYNOS_CPUFREQ
20 bool 29 bool
21 30
@@ -241,11 +250,3 @@ config ARM_TEGRA_CPUFREQ
241 default y 250 default y
242 help 251 help
243 This adds the CPUFreq driver support for TEGRA SOCs. 252 This adds the CPUFreq driver support for TEGRA SOCs.
244
245config ARM_VEXPRESS_SPC_CPUFREQ
246 tristate "Versatile Express SPC based CPUfreq driver"
247 select ARM_BIG_LITTLE_CPUFREQ
248 depends on ARCH_VEXPRESS_SPC
249 help
250 This add the CPUfreq driver support for Versatile Express
251 big.LITTLE platforms using SPC for power management.
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..bad2ed317ba2 100644
--- a/drivers/cpufreq/arm_big_little.c
+++ b/drivers/cpufreq/arm_big_little.c
@@ -446,9 +446,12 @@ static int bL_cpufreq_init(struct cpufreq_policy *policy)
446 } 446 }
447 447
448 if (cur_cluster < MAX_CLUSTERS) { 448 if (cur_cluster < MAX_CLUSTERS) {
449 int cpu;
450
449 cpumask_copy(policy->cpus, topology_core_cpumask(policy->cpu)); 451 cpumask_copy(policy->cpus, topology_core_cpumask(policy->cpu));
450 452
451 per_cpu(physical_cluster, policy->cpu) = cur_cluster; 453 for_each_cpu(cpu, policy->cpus)
454 per_cpu(physical_cluster, cpu) = cur_cluster;
452 } else { 455 } else {
453 /* Assumption: during init, we are always running on A15 */ 456 /* Assumption: during init, we are always running on A15 */
454 per_cpu(physical_cluster, policy->cpu) = A15_CLUSTER; 457 per_cpu(physical_cluster, policy->cpu) = A15_CLUSTER;
@@ -478,7 +481,6 @@ static int bL_cpufreq_exit(struct cpufreq_policy *policy)
478 return -ENODEV; 481 return -ENODEV;
479 } 482 }
480 483
481 cpufreq_frequency_table_put_attr(policy->cpu);
482 put_cluster_clk_and_freq_table(cpu_dev); 484 put_cluster_clk_and_freq_table(cpu_dev);
483 dev_dbg(cpu_dev, "%s: Exited, cpu: %d\n", __func__, policy->cpu); 485 dev_dbg(cpu_dev, "%s: Exited, cpu: %d\n", __func__, policy->cpu);
484 486
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..3aa7a7a226b3 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,14 @@ 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)) {
262 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, 268 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq,
263 ci->new); 269 ci->new);
264 pr_debug("scaling loops_per_jiffy to %lu " 270 pr_debug("scaling loops_per_jiffy to %lu for frequency %u kHz\n",
265 "for frequency %u kHz\n", loops_per_jiffy, ci->new); 271 loops_per_jiffy, ci->new);
266 } 272 }
267} 273}
268#else 274#else
@@ -282,7 +288,7 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
282 288
283 freqs->flags = cpufreq_driver->flags; 289 freqs->flags = cpufreq_driver->flags;
284 pr_debug("notification %u of frequency transition to %u kHz\n", 290 pr_debug("notification %u of frequency transition to %u kHz\n",
285 state, freqs->new); 291 state, freqs->new);
286 292
287 switch (state) { 293 switch (state) {
288 294
@@ -294,9 +300,8 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
294 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { 300 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
295 if ((policy) && (policy->cpu == freqs->cpu) && 301 if ((policy) && (policy->cpu == freqs->cpu) &&
296 (policy->cur) && (policy->cur != freqs->old)) { 302 (policy->cur) && (policy->cur != freqs->old)) {
297 pr_debug("Warning: CPU frequency is" 303 pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
298 " %u, cpufreq assumed %u kHz.\n", 304 freqs->old, policy->cur);
299 freqs->old, policy->cur);
300 freqs->old = policy->cur; 305 freqs->old = policy->cur;
301 } 306 }
302 } 307 }
@@ -307,8 +312,8 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
307 312
308 case CPUFREQ_POSTCHANGE: 313 case CPUFREQ_POSTCHANGE:
309 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); 314 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
310 pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, 315 pr_debug("FREQ: %lu - CPU: %lu\n",
311 (unsigned long)freqs->cpu); 316 (unsigned long)freqs->new, (unsigned long)freqs->cpu);
312 trace_cpu_frequency(freqs->new, freqs->cpu); 317 trace_cpu_frequency(freqs->new, freqs->cpu);
313 srcu_notifier_call_chain(&cpufreq_transition_notifier_list, 318 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
314 CPUFREQ_POSTCHANGE, freqs); 319 CPUFREQ_POSTCHANGE, freqs);
@@ -352,7 +357,7 @@ EXPORT_SYMBOL_GPL(cpufreq_notify_post_transition);
352/********************************************************************* 357/*********************************************************************
353 * SYSFS INTERFACE * 358 * SYSFS INTERFACE *
354 *********************************************************************/ 359 *********************************************************************/
355ssize_t show_boost(struct kobject *kobj, 360static ssize_t show_boost(struct kobject *kobj,
356 struct attribute *attr, char *buf) 361 struct attribute *attr, char *buf)
357{ 362{
358 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); 363 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled);
@@ -368,13 +373,13 @@ static ssize_t store_boost(struct kobject *kobj, struct attribute *attr,
368 return -EINVAL; 373 return -EINVAL;
369 374
370 if (cpufreq_boost_trigger_state(enable)) { 375 if (cpufreq_boost_trigger_state(enable)) {
371 pr_err("%s: Cannot %s BOOST!\n", __func__, 376 pr_err("%s: Cannot %s BOOST!\n",
372 enable ? "enable" : "disable"); 377 __func__, enable ? "enable" : "disable");
373 return -EINVAL; 378 return -EINVAL;
374 } 379 }
375 380
376 pr_debug("%s: cpufreq BOOST %s\n", __func__, 381 pr_debug("%s: cpufreq BOOST %s\n",
377 enable ? "enabled" : "disabled"); 382 __func__, enable ? "enabled" : "disabled");
378 383
379 return count; 384 return count;
380} 385}
@@ -879,18 +884,25 @@ err_out_kobj_put:
879 884
880static void cpufreq_init_policy(struct cpufreq_policy *policy) 885static void cpufreq_init_policy(struct cpufreq_policy *policy)
881{ 886{
887 struct cpufreq_governor *gov = NULL;
882 struct cpufreq_policy new_policy; 888 struct cpufreq_policy new_policy;
883 int ret = 0; 889 int ret = 0;
884 890
885 memcpy(&new_policy, policy, sizeof(*policy)); 891 memcpy(&new_policy, policy, sizeof(*policy));
886 892
893 /* Update governor of new_policy to the governor used before hotplug */
894 gov = __find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu));
895 if (gov)
896 pr_debug("Restoring governor %s for cpu %d\n",
897 policy->governor->name, policy->cpu);
898 else
899 gov = CPUFREQ_DEFAULT_GOVERNOR;
900
901 new_policy.governor = gov;
902
887 /* Use the default policy if its valid. */ 903 /* Use the default policy if its valid. */
888 if (cpufreq_driver->setpolicy) 904 if (cpufreq_driver->setpolicy)
889 cpufreq_parse_governor(policy->governor->name, 905 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 906
895 /* set default policy */ 907 /* set default policy */
896 ret = cpufreq_set_policy(policy, &new_policy); 908 ret = cpufreq_set_policy(policy, &new_policy);
@@ -927,8 +939,11 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy,
927 up_write(&policy->rwsem); 939 up_write(&policy->rwsem);
928 940
929 if (has_target()) { 941 if (has_target()) {
930 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) || 942 ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
931 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) { 943 if (!ret)
944 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
945
946 if (ret) {
932 pr_err("%s: Failed to start governor\n", __func__); 947 pr_err("%s: Failed to start governor\n", __func__);
933 return ret; 948 return ret;
934 } 949 }
@@ -949,6 +964,8 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
949 964
950 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 965 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
951 966
967 policy->governor = NULL;
968
952 return policy; 969 return policy;
953} 970}
954 971
@@ -1022,21 +1039,19 @@ static void update_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1022 1039
1023 up_write(&policy->rwsem); 1040 up_write(&policy->rwsem);
1024 1041
1025 cpufreq_frequency_table_update_policy_cpu(policy);
1026 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1042 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1027 CPUFREQ_UPDATE_POLICY_CPU, policy); 1043 CPUFREQ_UPDATE_POLICY_CPU, policy);
1028} 1044}
1029 1045
1030static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, 1046static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1031 bool frozen)
1032{ 1047{
1033 unsigned int j, cpu = dev->id; 1048 unsigned int j, cpu = dev->id;
1034 int ret = -ENOMEM; 1049 int ret = -ENOMEM;
1035 struct cpufreq_policy *policy; 1050 struct cpufreq_policy *policy;
1036 unsigned long flags; 1051 unsigned long flags;
1052 bool recover_policy = cpufreq_suspended;
1037#ifdef CONFIG_HOTPLUG_CPU 1053#ifdef CONFIG_HOTPLUG_CPU
1038 struct cpufreq_policy *tpolicy; 1054 struct cpufreq_policy *tpolicy;
1039 struct cpufreq_governor *gov;
1040#endif 1055#endif
1041 1056
1042 if (cpu_is_offline(cpu)) 1057 if (cpu_is_offline(cpu))
@@ -1075,9 +1090,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 1090 * Restore the saved policy when doing light-weight init and fall back
1076 * to the full init if that fails. 1091 * to the full init if that fails.
1077 */ 1092 */
1078 policy = frozen ? cpufreq_policy_restore(cpu) : NULL; 1093 policy = recover_policy ? cpufreq_policy_restore(cpu) : NULL;
1079 if (!policy) { 1094 if (!policy) {
1080 frozen = false; 1095 recover_policy = false;
1081 policy = cpufreq_policy_alloc(); 1096 policy = cpufreq_policy_alloc();
1082 if (!policy) 1097 if (!policy)
1083 goto nomem_out; 1098 goto nomem_out;
@@ -1089,12 +1104,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 1104 * the creation of a brand new one. So we need to perform this update
1090 * by invoking update_policy_cpu(). 1105 * by invoking update_policy_cpu().
1091 */ 1106 */
1092 if (frozen && cpu != policy->cpu) 1107 if (recover_policy && cpu != policy->cpu)
1093 update_policy_cpu(policy, cpu); 1108 update_policy_cpu(policy, cpu);
1094 else 1109 else
1095 policy->cpu = cpu; 1110 policy->cpu = cpu;
1096 1111
1097 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
1098 cpumask_copy(policy->cpus, cpumask_of(cpu)); 1112 cpumask_copy(policy->cpus, cpumask_of(cpu));
1099 1113
1100 init_completion(&policy->kobj_unregister); 1114 init_completion(&policy->kobj_unregister);
@@ -1118,7 +1132,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1118 */ 1132 */
1119 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); 1133 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1120 1134
1121 if (!frozen) { 1135 if (!recover_policy) {
1122 policy->user_policy.min = policy->min; 1136 policy->user_policy.min = policy->min;
1123 policy->user_policy.max = policy->max; 1137 policy->user_policy.max = policy->max;
1124 } 1138 }
@@ -1180,16 +1194,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1180 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 1194 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1181 CPUFREQ_START, policy); 1195 CPUFREQ_START, policy);
1182 1196
1183#ifdef CONFIG_HOTPLUG_CPU 1197 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); 1198 ret = cpufreq_add_dev_interface(policy, dev);
1194 if (ret) 1199 if (ret)
1195 goto err_out_unregister; 1200 goto err_out_unregister;
@@ -1203,7 +1208,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
1203 1208
1204 cpufreq_init_policy(policy); 1209 cpufreq_init_policy(policy);
1205 1210
1206 if (!frozen) { 1211 if (!recover_policy) {
1207 policy->user_policy.policy = policy->policy; 1212 policy->user_policy.policy = policy->policy;
1208 policy->user_policy.governor = policy->governor; 1213 policy->user_policy.governor = policy->governor;
1209 } 1214 }
@@ -1226,7 +1231,7 @@ err_get_freq:
1226 if (cpufreq_driver->exit) 1231 if (cpufreq_driver->exit)
1227 cpufreq_driver->exit(policy); 1232 cpufreq_driver->exit(policy);
1228err_set_policy_cpu: 1233err_set_policy_cpu:
1229 if (frozen) { 1234 if (recover_policy) {
1230 /* Do not leave stale fallback data behind. */ 1235 /* Do not leave stale fallback data behind. */
1231 per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL; 1236 per_cpu(cpufreq_cpu_data_fallback, cpu) = NULL;
1232 cpufreq_policy_put_kobj(policy); 1237 cpufreq_policy_put_kobj(policy);
@@ -1250,7 +1255,7 @@ nomem_out:
1250 */ 1255 */
1251static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif) 1256static int cpufreq_add_dev(struct device *dev, struct subsys_interface *sif)
1252{ 1257{
1253 return __cpufreq_add_dev(dev, sif, false); 1258 return __cpufreq_add_dev(dev, sif);
1254} 1259}
1255 1260
1256static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy, 1261static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
@@ -1265,7 +1270,7 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1265 sysfs_remove_link(&cpu_dev->kobj, "cpufreq"); 1270 sysfs_remove_link(&cpu_dev->kobj, "cpufreq");
1266 ret = kobject_move(&policy->kobj, &cpu_dev->kobj); 1271 ret = kobject_move(&policy->kobj, &cpu_dev->kobj);
1267 if (ret) { 1272 if (ret) {
1268 pr_err("%s: Failed to move kobj: %d", __func__, ret); 1273 pr_err("%s: Failed to move kobj: %d\n", __func__, ret);
1269 1274
1270 down_write(&policy->rwsem); 1275 down_write(&policy->rwsem);
1271 cpumask_set_cpu(old_cpu, policy->cpus); 1276 cpumask_set_cpu(old_cpu, policy->cpus);
@@ -1281,8 +1286,7 @@ static int cpufreq_nominate_new_policy_cpu(struct cpufreq_policy *policy,
1281} 1286}
1282 1287
1283static int __cpufreq_remove_dev_prepare(struct device *dev, 1288static int __cpufreq_remove_dev_prepare(struct device *dev,
1284 struct subsys_interface *sif, 1289 struct subsys_interface *sif)
1285 bool frozen)
1286{ 1290{
1287 unsigned int cpu = dev->id, cpus; 1291 unsigned int cpu = dev->id, cpus;
1288 int new_cpu, ret; 1292 int new_cpu, ret;
@@ -1296,7 +1300,7 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1296 policy = per_cpu(cpufreq_cpu_data, cpu); 1300 policy = per_cpu(cpufreq_cpu_data, cpu);
1297 1301
1298 /* Save the policy somewhere when doing a light-weight tear-down */ 1302 /* Save the policy somewhere when doing a light-weight tear-down */
1299 if (frozen) 1303 if (cpufreq_suspended)
1300 per_cpu(cpufreq_cpu_data_fallback, cpu) = policy; 1304 per_cpu(cpufreq_cpu_data_fallback, cpu) = policy;
1301 1305
1302 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1306 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -1314,11 +1318,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1314 } 1318 }
1315 } 1319 }
1316 1320
1317#ifdef CONFIG_HOTPLUG_CPU
1318 if (!cpufreq_driver->setpolicy) 1321 if (!cpufreq_driver->setpolicy)
1319 strncpy(per_cpu(cpufreq_cpu_governor, cpu), 1322 strncpy(per_cpu(cpufreq_cpu_governor, cpu),
1320 policy->governor->name, CPUFREQ_NAME_LEN); 1323 policy->governor->name, CPUFREQ_NAME_LEN);
1321#endif
1322 1324
1323 down_read(&policy->rwsem); 1325 down_read(&policy->rwsem);
1324 cpus = cpumask_weight(policy->cpus); 1326 cpus = cpumask_weight(policy->cpus);
@@ -1331,19 +1333,19 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
1331 if (new_cpu >= 0) { 1333 if (new_cpu >= 0) {
1332 update_policy_cpu(policy, new_cpu); 1334 update_policy_cpu(policy, new_cpu);
1333 1335
1334 if (!frozen) { 1336 if (!cpufreq_suspended)
1335 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n", 1337 pr_debug("%s: policy Kobject moved to cpu: %d from: %d\n",
1336 __func__, new_cpu, cpu); 1338 __func__, new_cpu, cpu);
1337 }
1338 } 1339 }
1340 } else if (cpufreq_driver->stop_cpu && cpufreq_driver->setpolicy) {
1341 cpufreq_driver->stop_cpu(policy);
1339 } 1342 }
1340 1343
1341 return 0; 1344 return 0;
1342} 1345}
1343 1346
1344static int __cpufreq_remove_dev_finish(struct device *dev, 1347static int __cpufreq_remove_dev_finish(struct device *dev,
1345 struct subsys_interface *sif, 1348 struct subsys_interface *sif)
1346 bool frozen)
1347{ 1349{
1348 unsigned int cpu = dev->id, cpus; 1350 unsigned int cpu = dev->id, cpus;
1349 int ret; 1351 int ret;
@@ -1373,12 +1375,12 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1373 CPUFREQ_GOV_POLICY_EXIT); 1375 CPUFREQ_GOV_POLICY_EXIT);
1374 if (ret) { 1376 if (ret) {
1375 pr_err("%s: Failed to exit governor\n", 1377 pr_err("%s: Failed to exit governor\n",
1376 __func__); 1378 __func__);
1377 return ret; 1379 return ret;
1378 } 1380 }
1379 } 1381 }
1380 1382
1381 if (!frozen) 1383 if (!cpufreq_suspended)
1382 cpufreq_policy_put_kobj(policy); 1384 cpufreq_policy_put_kobj(policy);
1383 1385
1384 /* 1386 /*
@@ -1394,16 +1396,16 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
1394 list_del(&policy->policy_list); 1396 list_del(&policy->policy_list);
1395 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 1397 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1396 1398
1397 if (!frozen) 1399 if (!cpufreq_suspended)
1398 cpufreq_policy_free(policy); 1400 cpufreq_policy_free(policy);
1399 } else { 1401 } else if (has_target()) {
1400 if (has_target()) { 1402 ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
1401 if ((ret = __cpufreq_governor(policy, CPUFREQ_GOV_START)) || 1403 if (!ret)
1402 (ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))) { 1404 ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
1403 pr_err("%s: Failed to start governor\n", 1405
1404 __func__); 1406 if (ret) {
1405 return ret; 1407 pr_err("%s: Failed to start governor\n", __func__);
1406 } 1408 return ret;
1407 } 1409 }
1408 } 1410 }
1409 1411
@@ -1424,10 +1426,10 @@ static int cpufreq_remove_dev(struct device *dev, struct subsys_interface *sif)
1424 if (cpu_is_offline(cpu)) 1426 if (cpu_is_offline(cpu))
1425 return 0; 1427 return 0;
1426 1428
1427 ret = __cpufreq_remove_dev_prepare(dev, sif, false); 1429 ret = __cpufreq_remove_dev_prepare(dev, sif);
1428 1430
1429 if (!ret) 1431 if (!ret)
1430 ret = __cpufreq_remove_dev_finish(dev, sif, false); 1432 ret = __cpufreq_remove_dev_finish(dev, sif);
1431 1433
1432 return ret; 1434 return ret;
1433} 1435}
@@ -1458,8 +1460,8 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
1458 struct cpufreq_freqs freqs; 1460 struct cpufreq_freqs freqs;
1459 unsigned long flags; 1461 unsigned long flags;
1460 1462
1461 pr_debug("Warning: CPU frequency out of sync: cpufreq and timing " 1463 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); 1464 old_freq, new_freq);
1463 1465
1464 freqs.old = old_freq; 1466 freqs.old = old_freq;
1465 freqs.new = new_freq; 1467 freqs.new = new_freq;
@@ -1570,83 +1572,104 @@ static struct subsys_interface cpufreq_interface = {
1570 .remove_dev = cpufreq_remove_dev, 1572 .remove_dev = cpufreq_remove_dev,
1571}; 1573};
1572 1574
1575/*
1576 * In case platform wants some specific frequency to be configured
1577 * during suspend..
1578 */
1579int cpufreq_generic_suspend(struct cpufreq_policy *policy)
1580{
1581 int ret;
1582
1583 if (!policy->suspend_freq) {
1584 pr_err("%s: suspend_freq can't be zero\n", __func__);
1585 return -EINVAL;
1586 }
1587
1588 pr_debug("%s: Setting suspend-freq: %u\n", __func__,
1589 policy->suspend_freq);
1590
1591 ret = __cpufreq_driver_target(policy, policy->suspend_freq,
1592 CPUFREQ_RELATION_H);
1593 if (ret)
1594 pr_err("%s: unable to set suspend-freq: %u. err: %d\n",
1595 __func__, policy->suspend_freq, ret);
1596
1597 return ret;
1598}
1599EXPORT_SYMBOL(cpufreq_generic_suspend);
1600
1573/** 1601/**
1574 * cpufreq_bp_suspend - Prepare the boot CPU for system suspend. 1602 * cpufreq_suspend() - Suspend CPUFreq governors
1575 * 1603 *
1576 * This function is only executed for the boot processor. The other CPUs 1604 * Called during system wide Suspend/Hibernate cycles for suspending governors
1577 * have been put offline by means of CPU hotplug. 1605 * as some platforms can't change frequency after this point in suspend cycle.
1606 * Because some of the devices (like: i2c, regulators, etc) they use for
1607 * changing frequency are suspended quickly after this point.
1578 */ 1608 */
1579static int cpufreq_bp_suspend(void) 1609void cpufreq_suspend(void)
1580{ 1610{
1581 int ret = 0;
1582
1583 int cpu = smp_processor_id();
1584 struct cpufreq_policy *policy; 1611 struct cpufreq_policy *policy;
1585 1612
1586 pr_debug("suspending cpu %u\n", cpu); 1613 if (!cpufreq_driver)
1614 return;
1587 1615
1588 /* If there's no policy for the boot CPU, we have nothing to do. */ 1616 if (!has_target())
1589 policy = cpufreq_cpu_get(cpu); 1617 return;
1590 if (!policy)
1591 return 0;
1592 1618
1593 if (cpufreq_driver->suspend) { 1619 pr_debug("%s: Suspending Governors\n", __func__);
1594 ret = cpufreq_driver->suspend(policy); 1620
1595 if (ret) 1621 list_for_each_entry(policy, &cpufreq_policy_list, policy_list) {
1596 printk(KERN_ERR "cpufreq: suspend failed in ->suspend " 1622 if (__cpufreq_governor(policy, CPUFREQ_GOV_STOP))
1597 "step on CPU %u\n", policy->cpu); 1623 pr_err("%s: Failed to stop governor for policy: %p\n",
1624 __func__, policy);
1625 else if (cpufreq_driver->suspend
1626 && cpufreq_driver->suspend(policy))
1627 pr_err("%s: Failed to suspend driver: %p\n", __func__,
1628 policy);
1598 } 1629 }
1599 1630
1600 cpufreq_cpu_put(policy); 1631 cpufreq_suspended = true;
1601 return ret;
1602} 1632}
1603 1633
1604/** 1634/**
1605 * cpufreq_bp_resume - Restore proper frequency handling of the boot CPU. 1635 * cpufreq_resume() - Resume CPUFreq governors
1606 * 1636 *
1607 * 1.) resume CPUfreq hardware support (cpufreq_driver->resume()) 1637 * Called during system wide Suspend/Hibernate cycle for resuming governors that
1608 * 2.) schedule call cpufreq_update_policy() ASAP as interrupts are 1638 * 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 */ 1639 */
1617static void cpufreq_bp_resume(void) 1640void cpufreq_resume(void)
1618{ 1641{
1619 int ret = 0;
1620
1621 int cpu = smp_processor_id();
1622 struct cpufreq_policy *policy; 1642 struct cpufreq_policy *policy;
1623 1643
1624 pr_debug("resuming cpu %u\n", cpu); 1644 if (!cpufreq_driver)
1645 return;
1625 1646
1626 /* If there's no policy for the boot CPU, we have nothing to do. */ 1647 if (!has_target())
1627 policy = cpufreq_cpu_get(cpu);
1628 if (!policy)
1629 return; 1648 return;
1630 1649
1631 if (cpufreq_driver->resume) { 1650 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 1651
1640 schedule_work(&policy->update); 1652 cpufreq_suspended = false;
1641 1653
1642fail: 1654 list_for_each_entry(policy, &cpufreq_policy_list, policy_list) {
1643 cpufreq_cpu_put(policy); 1655 if (__cpufreq_governor(policy, CPUFREQ_GOV_START)
1644} 1656 || __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS))
1657 pr_err("%s: Failed to start governor for policy: %p\n",
1658 __func__, policy);
1659 else if (cpufreq_driver->resume
1660 && cpufreq_driver->resume(policy))
1661 pr_err("%s: Failed to resume driver: %p\n", __func__,
1662 policy);
1645 1663
1646static struct syscore_ops cpufreq_syscore_ops = { 1664 /*
1647 .suspend = cpufreq_bp_suspend, 1665 * schedule call cpufreq_update_policy() for boot CPU, i.e. last
1648 .resume = cpufreq_bp_resume, 1666 * policy in list. It will verify that the current freq is in
1649}; 1667 * sync with what we believe it to be.
1668 */
1669 if (list_is_last(&policy->policy_list, &cpufreq_policy_list))
1670 schedule_work(&policy->update);
1671 }
1672}
1650 1673
1651/** 1674/**
1652 * cpufreq_get_current_driver - return current driver's name 1675 * cpufreq_get_current_driver - return current driver's name
@@ -1762,7 +1785,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1762 target_freq = policy->min; 1785 target_freq = policy->min;
1763 1786
1764 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n", 1787 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
1765 policy->cpu, target_freq, relation, old_target_freq); 1788 policy->cpu, target_freq, relation, old_target_freq);
1766 1789
1767 /* 1790 /*
1768 * This might look like a redundant call as we are checking it again 1791 * This might look like a redundant call as we are checking it again
@@ -1807,8 +1830,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1807 freqs.flags = 0; 1830 freqs.flags = 0;
1808 1831
1809 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", 1832 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
1810 __func__, policy->cpu, freqs.old, 1833 __func__, policy->cpu, freqs.old, freqs.new);
1811 freqs.new);
1812 1834
1813 cpufreq_notify_transition(policy, &freqs, 1835 cpufreq_notify_transition(policy, &freqs,
1814 CPUFREQ_PRECHANGE); 1836 CPUFREQ_PRECHANGE);
@@ -1817,7 +1839,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1817 retval = cpufreq_driver->target_index(policy, index); 1839 retval = cpufreq_driver->target_index(policy, index);
1818 if (retval) 1840 if (retval)
1819 pr_err("%s: Failed to change cpu frequency: %d\n", 1841 pr_err("%s: Failed to change cpu frequency: %d\n",
1820 __func__, retval); 1842 __func__, retval);
1821 1843
1822 if (notify) 1844 if (notify)
1823 cpufreq_notify_post_transition(policy, &freqs, retval); 1845 cpufreq_notify_post_transition(policy, &freqs, retval);
@@ -1863,17 +1885,18 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1863 struct cpufreq_governor *gov = NULL; 1885 struct cpufreq_governor *gov = NULL;
1864#endif 1886#endif
1865 1887
1888 /* Don't start any governor operations if we are entering suspend */
1889 if (cpufreq_suspended)
1890 return 0;
1891
1866 if (policy->governor->max_transition_latency && 1892 if (policy->governor->max_transition_latency &&
1867 policy->cpuinfo.transition_latency > 1893 policy->cpuinfo.transition_latency >
1868 policy->governor->max_transition_latency) { 1894 policy->governor->max_transition_latency) {
1869 if (!gov) 1895 if (!gov)
1870 return -EINVAL; 1896 return -EINVAL;
1871 else { 1897 else {
1872 printk(KERN_WARNING "%s governor failed, too long" 1898 pr_warn("%s governor failed, too long transition latency of HW, fallback to %s governor\n",
1873 " transition latency of HW, fallback" 1899 policy->governor->name, gov->name);
1874 " to %s governor\n",
1875 policy->governor->name,
1876 gov->name);
1877 policy->governor = gov; 1900 policy->governor = gov;
1878 } 1901 }
1879 } 1902 }
@@ -1883,7 +1906,7 @@ static int __cpufreq_governor(struct cpufreq_policy *policy,
1883 return -EINVAL; 1906 return -EINVAL;
1884 1907
1885 pr_debug("__cpufreq_governor for CPU %u, event %u\n", 1908 pr_debug("__cpufreq_governor for CPU %u, event %u\n",
1886 policy->cpu, event); 1909 policy->cpu, event);
1887 1910
1888 mutex_lock(&cpufreq_governor_lock); 1911 mutex_lock(&cpufreq_governor_lock);
1889 if ((policy->governor_enabled && event == CPUFREQ_GOV_START) 1912 if ((policy->governor_enabled && event == CPUFREQ_GOV_START)
@@ -1950,9 +1973,7 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1950 1973
1951void cpufreq_unregister_governor(struct cpufreq_governor *governor) 1974void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1952{ 1975{
1953#ifdef CONFIG_HOTPLUG_CPU
1954 int cpu; 1976 int cpu;
1955#endif
1956 1977
1957 if (!governor) 1978 if (!governor)
1958 return; 1979 return;
@@ -1960,14 +1981,12 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1960 if (cpufreq_disabled()) 1981 if (cpufreq_disabled())
1961 return; 1982 return;
1962 1983
1963#ifdef CONFIG_HOTPLUG_CPU
1964 for_each_present_cpu(cpu) { 1984 for_each_present_cpu(cpu) {
1965 if (cpu_online(cpu)) 1985 if (cpu_online(cpu))
1966 continue; 1986 continue;
1967 if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) 1987 if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
1968 strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); 1988 strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
1969 } 1989 }
1970#endif
1971 1990
1972 mutex_lock(&cpufreq_governor_mutex); 1991 mutex_lock(&cpufreq_governor_mutex);
1973 list_del(&governor->governor_list); 1992 list_del(&governor->governor_list);
@@ -2012,22 +2031,21 @@ EXPORT_SYMBOL(cpufreq_get_policy);
2012static int cpufreq_set_policy(struct cpufreq_policy *policy, 2031static int cpufreq_set_policy(struct cpufreq_policy *policy,
2013 struct cpufreq_policy *new_policy) 2032 struct cpufreq_policy *new_policy)
2014{ 2033{
2015 int ret = 0, failed = 1; 2034 struct cpufreq_governor *old_gov;
2035 int ret;
2016 2036
2017 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", new_policy->cpu, 2037 pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
2018 new_policy->min, new_policy->max); 2038 new_policy->cpu, new_policy->min, new_policy->max);
2019 2039
2020 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); 2040 memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
2021 2041
2022 if (new_policy->min > policy->max || new_policy->max < policy->min) { 2042 if (new_policy->min > policy->max || new_policy->max < policy->min)
2023 ret = -EINVAL; 2043 return -EINVAL;
2024 goto error_out;
2025 }
2026 2044
2027 /* verify the cpu speed can be set within this limit */ 2045 /* verify the cpu speed can be set within this limit */
2028 ret = cpufreq_driver->verify(new_policy); 2046 ret = cpufreq_driver->verify(new_policy);
2029 if (ret) 2047 if (ret)
2030 goto error_out; 2048 return ret;
2031 2049
2032 /* adjust if necessary - all reasons */ 2050 /* adjust if necessary - all reasons */
2033 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 2051 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
@@ -2043,7 +2061,7 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
2043 */ 2061 */
2044 ret = cpufreq_driver->verify(new_policy); 2062 ret = cpufreq_driver->verify(new_policy);
2045 if (ret) 2063 if (ret)
2046 goto error_out; 2064 return ret;
2047 2065
2048 /* notification of the new policy */ 2066 /* notification of the new policy */
2049 blocking_notifier_call_chain(&cpufreq_policy_notifier_list, 2067 blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
@@ -2053,63 +2071,53 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
2053 policy->max = new_policy->max; 2071 policy->max = new_policy->max;
2054 2072
2055 pr_debug("new min and max freqs are %u - %u kHz\n", 2073 pr_debug("new min and max freqs are %u - %u kHz\n",
2056 policy->min, policy->max); 2074 policy->min, policy->max);
2057 2075
2058 if (cpufreq_driver->setpolicy) { 2076 if (cpufreq_driver->setpolicy) {
2059 policy->policy = new_policy->policy; 2077 policy->policy = new_policy->policy;
2060 pr_debug("setting range\n"); 2078 pr_debug("setting range\n");
2061 ret = cpufreq_driver->setpolicy(new_policy); 2079 return cpufreq_driver->setpolicy(new_policy);
2062 } else { 2080 }
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 2081
2078 /* start new governor */ 2082 if (new_policy->governor == policy->governor)
2079 policy->governor = new_policy->governor; 2083 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 2084
2091 if (failed) { 2085 pr_debug("governor switch\n");
2092 /* new governor failed, so re-start old one */ 2086
2093 pr_debug("starting governor %s failed\n", 2087 /* save old, working values */
2094 policy->governor->name); 2088 old_gov = policy->governor;
2095 if (old_gov) { 2089 /* end old governor */
2096 policy->governor = old_gov; 2090 if (old_gov) {
2097 __cpufreq_governor(policy, 2091 __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
2098 CPUFREQ_GOV_POLICY_INIT); 2092 up_write(&policy->rwsem);
2099 __cpufreq_governor(policy, 2093 __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
2100 CPUFREQ_GOV_START); 2094 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 } 2095 }
2110 2096
2111error_out: 2097 /* start new governor */
2112 return ret; 2098 policy->governor = new_policy->governor;
2099 if (!__cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT)) {
2100 if (!__cpufreq_governor(policy, CPUFREQ_GOV_START))
2101 goto out;
2102
2103 up_write(&policy->rwsem);
2104 __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_EXIT);
2105 down_write(&policy->rwsem);
2106 }
2107
2108 /* new governor failed, so re-start old one */
2109 pr_debug("starting governor %s failed\n", policy->governor->name);
2110 if (old_gov) {
2111 policy->governor = old_gov;
2112 __cpufreq_governor(policy, CPUFREQ_GOV_POLICY_INIT);
2113 __cpufreq_governor(policy, CPUFREQ_GOV_START);
2114 }
2115
2116 return -EINVAL;
2117
2118 out:
2119 pr_debug("governor: change or update limits\n");
2120 return __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
2113} 2121}
2114 2122
2115/** 2123/**
@@ -2145,8 +2153,13 @@ int cpufreq_update_policy(unsigned int cpu)
2145 */ 2153 */
2146 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { 2154 if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2147 new_policy.cur = cpufreq_driver->get(cpu); 2155 new_policy.cur = cpufreq_driver->get(cpu);
2156 if (WARN_ON(!new_policy.cur)) {
2157 ret = -EIO;
2158 goto no_policy;
2159 }
2160
2148 if (!policy->cur) { 2161 if (!policy->cur) {
2149 pr_debug("Driver did not initialize current freq"); 2162 pr_debug("Driver did not initialize current freq\n");
2150 policy->cur = new_policy.cur; 2163 policy->cur = new_policy.cur;
2151 } else { 2164 } else {
2152 if (policy->cur != new_policy.cur && has_target()) 2165 if (policy->cur != new_policy.cur && has_target())
@@ -2170,30 +2183,24 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
2170{ 2183{
2171 unsigned int cpu = (unsigned long)hcpu; 2184 unsigned int cpu = (unsigned long)hcpu;
2172 struct device *dev; 2185 struct device *dev;
2173 bool frozen = false;
2174 2186
2175 dev = get_cpu_device(cpu); 2187 dev = get_cpu_device(cpu);
2176 if (dev) { 2188 if (dev) {
2177
2178 if (action & CPU_TASKS_FROZEN)
2179 frozen = true;
2180
2181 switch (action & ~CPU_TASKS_FROZEN) { 2189 switch (action & ~CPU_TASKS_FROZEN) {
2182 case CPU_ONLINE: 2190 case CPU_ONLINE:
2183 __cpufreq_add_dev(dev, NULL, frozen); 2191 __cpufreq_add_dev(dev, NULL);
2184 cpufreq_update_policy(cpu);
2185 break; 2192 break;
2186 2193
2187 case CPU_DOWN_PREPARE: 2194 case CPU_DOWN_PREPARE:
2188 __cpufreq_remove_dev_prepare(dev, NULL, frozen); 2195 __cpufreq_remove_dev_prepare(dev, NULL);
2189 break; 2196 break;
2190 2197
2191 case CPU_POST_DEAD: 2198 case CPU_POST_DEAD:
2192 __cpufreq_remove_dev_finish(dev, NULL, frozen); 2199 __cpufreq_remove_dev_finish(dev, NULL);
2193 break; 2200 break;
2194 2201
2195 case CPU_DOWN_FAILED: 2202 case CPU_DOWN_FAILED:
2196 __cpufreq_add_dev(dev, NULL, frozen); 2203 __cpufreq_add_dev(dev, NULL);
2197 break; 2204 break;
2198 } 2205 }
2199 } 2206 }
@@ -2249,8 +2256,8 @@ int cpufreq_boost_trigger_state(int state)
2249 cpufreq_driver->boost_enabled = !state; 2256 cpufreq_driver->boost_enabled = !state;
2250 write_unlock_irqrestore(&cpufreq_driver_lock, flags); 2257 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2251 2258
2252 pr_err("%s: Cannot %s BOOST\n", __func__, 2259 pr_err("%s: Cannot %s BOOST\n",
2253 state ? "enable" : "disable"); 2260 __func__, state ? "enable" : "disable");
2254 } 2261 }
2255 2262
2256 return ret; 2263 return ret;
@@ -2295,7 +2302,9 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
2295 2302
2296 if (!driver_data || !driver_data->verify || !driver_data->init || 2303 if (!driver_data || !driver_data->verify || !driver_data->init ||
2297 !(driver_data->setpolicy || driver_data->target_index || 2304 !(driver_data->setpolicy || driver_data->target_index ||
2298 driver_data->target)) 2305 driver_data->target) ||
2306 (driver_data->setpolicy && (driver_data->target_index ||
2307 driver_data->target)))
2299 return -EINVAL; 2308 return -EINVAL;
2300 2309
2301 pr_debug("trying to register driver %s\n", driver_data->name); 2310 pr_debug("trying to register driver %s\n", driver_data->name);
@@ -2322,7 +2331,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
2322 ret = cpufreq_sysfs_create_file(&boost.attr); 2331 ret = cpufreq_sysfs_create_file(&boost.attr);
2323 if (ret) { 2332 if (ret) {
2324 pr_err("%s: cannot register global BOOST sysfs file\n", 2333 pr_err("%s: cannot register global BOOST sysfs file\n",
2325 __func__); 2334 __func__);
2326 goto err_null_driver; 2335 goto err_null_driver;
2327 } 2336 }
2328 } 2337 }
@@ -2345,7 +2354,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
2345 /* if all ->init() calls failed, unregister */ 2354 /* if all ->init() calls failed, unregister */
2346 if (ret) { 2355 if (ret) {
2347 pr_debug("no CPU initialized for driver %s\n", 2356 pr_debug("no CPU initialized for driver %s\n",
2348 driver_data->name); 2357 driver_data->name);
2349 goto err_if_unreg; 2358 goto err_if_unreg;
2350 } 2359 }
2351 } 2360 }
@@ -2409,7 +2418,6 @@ static int __init cpufreq_core_init(void)
2409 2418
2410 cpufreq_global_kobject = kobject_create(); 2419 cpufreq_global_kobject = kobject_create();
2411 BUG_ON(!cpufreq_global_kobject); 2420 BUG_ON(!cpufreq_global_kobject);
2412 register_syscore_ops(&cpufreq_syscore_ops);
2413 2421
2414 return 0; 2422 return 0;
2415} 2423}
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..bcb9a6d0ae11 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)
@@ -447,7 +446,7 @@ static void core_set_pstate(struct cpudata *cpudata, int pstate)
447 if (limits.no_turbo) 446 if (limits.no_turbo)
448 val |= (u64)1 << 32; 447 val |= (u64)1 << 32;
449 448
450 wrmsrl(MSR_IA32_PERF_CTL, val); 449 wrmsrl_on_cpu(cpudata->cpu, MSR_IA32_PERF_CTL, val);
451} 450}
452 451
453static struct cpu_defaults core_params = { 452static struct cpu_defaults core_params = {
@@ -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
@@ -773,14 +771,17 @@ static int intel_pstate_verify_policy(struct cpufreq_policy *policy)
773 return 0; 771 return 0;
774} 772}
775 773
776static int intel_pstate_cpu_exit(struct cpufreq_policy *policy) 774static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
777{ 775{
778 int cpu = policy->cpu; 776 int cpu_num = policy->cpu;
777 struct cpudata *cpu = all_cpu_data[cpu_num];
779 778
780 del_timer(&all_cpu_data[cpu]->timer); 779 pr_info("intel_pstate CPU %d exiting\n", cpu_num);
781 kfree(all_cpu_data[cpu]); 780
782 all_cpu_data[cpu] = NULL; 781 del_timer(&all_cpu_data[cpu_num]->timer);
783 return 0; 782 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
783 kfree(all_cpu_data[cpu_num]);
784 all_cpu_data[cpu_num] = NULL;
784} 785}
785 786
786static int intel_pstate_cpu_init(struct cpufreq_policy *policy) 787static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
@@ -818,7 +819,7 @@ static struct cpufreq_driver intel_pstate_driver = {
818 .setpolicy = intel_pstate_set_policy, 819 .setpolicy = intel_pstate_set_policy,
819 .get = intel_pstate_get, 820 .get = intel_pstate_get,
820 .init = intel_pstate_cpu_init, 821 .init = intel_pstate_cpu_init,
821 .exit = intel_pstate_cpu_exit, 822 .stop_cpu = intel_pstate_stop_cpu,
822 .name = "intel_pstate", 823 .name = "intel_pstate",
823}; 824};
824 825
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..3bd9123e7026 100644
--- a/drivers/cpufreq/ppc-corenet-cpufreq.c
+++ b/drivers/cpufreq/ppc-corenet-cpufreq.c
@@ -21,6 +21,7 @@
21#include <linux/of.h> 21#include <linux/of.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/smp.h> 23#include <linux/smp.h>
24#include <sysdev/fsl_soc.h>
24 25
25/** 26/**
26 * struct cpu_data - per CPU data struct 27 * struct cpu_data - per CPU data struct
@@ -205,7 +206,8 @@ static int corenet_cpufreq_cpu_init(struct cpufreq_policy *policy)
205 for_each_cpu(i, per_cpu(cpu_mask, cpu)) 206 for_each_cpu(i, per_cpu(cpu_mask, cpu))
206 per_cpu(cpu_data, i) = data; 207 per_cpu(cpu_data, i) = data;
207 208
208 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 209 policy->cpuinfo.transition_latency =
210 (12 * NSEC_PER_SEC) / fsl_get_sys_freq();
209 of_node_put(np); 211 of_node_put(np);
210 212
211 return 0; 213 return 0;
@@ -228,7 +230,6 @@ static int __exit corenet_cpufreq_cpu_exit(struct cpufreq_policy *policy)
228 struct cpu_data *data = per_cpu(cpu_data, policy->cpu); 230 struct cpu_data *data = per_cpu(cpu_data, policy->cpu);
229 unsigned int cpu; 231 unsigned int cpu;
230 232
231 cpufreq_frequency_table_put_attr(policy->cpu);
232 of_node_put(data->parent); 233 of_node_put(data->parent);
233 kfree(data->table); 234 kfree(data->table);
234 kfree(data); 235 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)
diff --git a/drivers/pcmcia/sa11xx_base.c b/drivers/pcmcia/sa11xx_base.c
index 6eecd7cddf57..54d3089d157b 100644
--- a/drivers/pcmcia/sa11xx_base.c
+++ b/drivers/pcmcia/sa11xx_base.c
@@ -125,9 +125,6 @@ sa1100_pcmcia_frequency_change(struct soc_pcmcia_socket *skt,
125 if (freqs->new < freqs->old) 125 if (freqs->new < freqs->old)
126 sa1100_pcmcia_set_mecr(skt, freqs->new); 126 sa1100_pcmcia_set_mecr(skt, freqs->new);
127 break; 127 break;
128 case CPUFREQ_RESUMECHANGE:
129 sa1100_pcmcia_set_mecr(skt, freqs->new);
130 break;
131 } 128 }
132 129
133 return 0; 130 return 0;
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index be33d2b0613b..7e0b62602632 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1041,8 +1041,7 @@ static int sci_notifier(struct notifier_block *self,
1041 1041
1042 sci_port = container_of(self, struct sci_port, freq_transition); 1042 sci_port = container_of(self, struct sci_port, freq_transition);
1043 1043
1044 if ((phase == CPUFREQ_POSTCHANGE) || 1044 if (phase == CPUFREQ_POSTCHANGE) {
1045 (phase == CPUFREQ_RESUMECHANGE)) {
1046 struct uart_port *port = &sci_port->port; 1045 struct uart_port *port = &sci_port->port;
1047 1046
1048 spin_lock_irqsave(&port->lock, flags); 1047 spin_lock_irqsave(&port->lock, flags);
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 4d89e0e6f9cc..2d2e62c8666a 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -74,6 +74,8 @@ struct cpufreq_policy {
74 unsigned int max; /* in kHz */ 74 unsigned int max; /* in kHz */
75 unsigned int cur; /* in kHz, only needed if cpufreq 75 unsigned int cur; /* in kHz, only needed if cpufreq
76 * governors are used */ 76 * governors are used */
77 unsigned int suspend_freq; /* freq to set during suspend */
78
77 unsigned int policy; /* see above */ 79 unsigned int policy; /* see above */
78 struct cpufreq_governor *governor; /* see below */ 80 struct cpufreq_governor *governor; /* see below */
79 void *governor_data; 81 void *governor_data;
@@ -83,6 +85,7 @@ struct cpufreq_policy {
83 * called, but you're in IRQ context */ 85 * called, but you're in IRQ context */
84 86
85 struct cpufreq_real_policy user_policy; 87 struct cpufreq_real_policy user_policy;
88 struct cpufreq_frequency_table *freq_table;
86 89
87 struct list_head policy_list; 90 struct list_head policy_list;
88 struct kobject kobj; 91 struct kobject kobj;
@@ -224,6 +227,7 @@ struct cpufreq_driver {
224 int (*bios_limit) (int cpu, unsigned int *limit); 227 int (*bios_limit) (int cpu, unsigned int *limit);
225 228
226 int (*exit) (struct cpufreq_policy *policy); 229 int (*exit) (struct cpufreq_policy *policy);
230 void (*stop_cpu) (struct cpufreq_policy *policy);
227 int (*suspend) (struct cpufreq_policy *policy); 231 int (*suspend) (struct cpufreq_policy *policy);
228 int (*resume) (struct cpufreq_policy *policy); 232 int (*resume) (struct cpufreq_policy *policy);
229 struct freq_attr **attr; 233 struct freq_attr **attr;
@@ -296,6 +300,15 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy)
296 policy->cpuinfo.max_freq); 300 policy->cpuinfo.max_freq);
297} 301}
298 302
303#ifdef CONFIG_CPU_FREQ
304void cpufreq_suspend(void);
305void cpufreq_resume(void);
306int cpufreq_generic_suspend(struct cpufreq_policy *policy);
307#else
308static inline void cpufreq_suspend(void) {}
309static inline void cpufreq_resume(void) {}
310#endif
311
299/********************************************************************* 312/*********************************************************************
300 * CPUFREQ NOTIFIER INTERFACE * 313 * CPUFREQ NOTIFIER INTERFACE *
301 *********************************************************************/ 314 *********************************************************************/
@@ -306,8 +319,6 @@ cpufreq_verify_within_cpu_limits(struct cpufreq_policy *policy)
306/* Transition notifiers */ 319/* Transition notifiers */
307#define CPUFREQ_PRECHANGE (0) 320#define CPUFREQ_PRECHANGE (0)
308#define CPUFREQ_POSTCHANGE (1) 321#define CPUFREQ_POSTCHANGE (1)
309#define CPUFREQ_RESUMECHANGE (8)
310#define CPUFREQ_SUSPENDCHANGE (9)
311 322
312/* Policy Notifiers */ 323/* Policy Notifiers */
313#define CPUFREQ_ADJUST (0) 324#define CPUFREQ_ADJUST (0)
@@ -463,7 +474,6 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
463int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, 474int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
464 unsigned int freq); 475 unsigned int freq);
465 476
466void cpufreq_frequency_table_update_policy_cpu(struct cpufreq_policy *policy);
467ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf); 477ssize_t cpufreq_show_cpus(const struct cpumask *mask, char *buf);
468 478
469#ifdef CONFIG_CPU_FREQ 479#ifdef CONFIG_CPU_FREQ
@@ -490,9 +500,6 @@ struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu);
490/* the following are really really optional */ 500/* the following are really really optional */
491extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs; 501extern struct freq_attr cpufreq_freq_attr_scaling_available_freqs;
492extern struct freq_attr *cpufreq_generic_attr[]; 502extern struct freq_attr *cpufreq_generic_attr[];
493void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
494 unsigned int cpu);
495void cpufreq_frequency_table_put_attr(unsigned int cpu);
496int cpufreq_table_validate_and_show(struct cpufreq_policy *policy, 503int cpufreq_table_validate_and_show(struct cpufreq_policy *policy,
497 struct cpufreq_frequency_table *table); 504 struct cpufreq_frequency_table *table);
498 505
@@ -500,10 +507,4 @@ unsigned int cpufreq_generic_get(unsigned int cpu);
500int cpufreq_generic_init(struct cpufreq_policy *policy, 507int cpufreq_generic_init(struct cpufreq_policy *policy,
501 struct cpufreq_frequency_table *table, 508 struct cpufreq_frequency_table *table,
502 unsigned int transition_latency); 509 unsigned int transition_latency);
503static inline int cpufreq_generic_exit(struct cpufreq_policy *policy)
504{
505 cpufreq_frequency_table_put_attr(policy->cpu);
506 return 0;
507}
508
509#endif /* _LINUX_CPUFREQ_H */ 510#endif /* _LINUX_CPUFREQ_H */