aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-04-02 05:00:46 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-04-02 05:00:46 -0400
commita9f36db7ec653ddeba81ba43d56103eab1ab912a (patch)
tree17abf63bec87037440114906d167da485446ee06
parente3a495c4ee64eb2ce8aaef244d7a0b68fd5216fd (diff)
parent3d41386d556db9f720e00de3e11e45f39cb5071c (diff)
Merge branch 'pm-cpufreq'
* pm-cpufreq: (38 commits) cpufreq: CPPC: Use transition_delay_us depending transition_latency cpufreq: tegra186: Don't validate the frequency table twice cpufreq: speedstep: Don't validate the frequency table twice cpufreq: sparc: Don't validate the frequency table twice cpufreq: sh: Don't validate the frequency table twice cpufreq: sfi: Don't validate the frequency table twice cpufreq: scpi: Don't validate the frequency table twice cpufreq: sc520: Don't validate the frequency table twice cpufreq: s3c24xx: Don't validate the frequency table twice cpufreq: qoirq: Don't validate the frequency table twice cpufreq: pxa: Don't validate the frequency table twice cpufreq: ppc_cbe: Don't validate the frequency table twice cpufreq: powernow: Don't validate the frequency table twice cpufreq: p4-clockmod: Don't validate the frequency table twice cpufreq: mediatek: Don't validate the frequency table twice cpufreq: longhaul: Don't validate the frequency table twice cpufreq: ia64-acpi: Don't validate the frequency table twice cpufreq: elanfreq: Don't validate the frequency table twice cpufreq: e_powersaver: Don't validate the frequency table twice cpufreq: cpufreq-dt: Don't validate the frequency table twice ...
-rw-r--r--Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt4
-rw-r--r--Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek.txt4
-rw-r--r--arch/arm/boot/dts/mt7623.dtsi2
-rw-r--r--drivers/cpufreq/Kconfig.arm1
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c20
-rw-r--r--drivers/cpufreq/arm_big_little.c9
-rw-r--r--drivers/cpufreq/brcmstb-avs-cpufreq.c6
-rw-r--r--drivers/cpufreq/cppc_cpufreq.c12
-rw-r--r--drivers/cpufreq/cpufreq-dt.c8
-rw-r--r--drivers/cpufreq/cpufreq.c28
-rw-r--r--drivers/cpufreq/e_powersaver.c8
-rw-r--r--drivers/cpufreq/elanfreq.c3
-rw-r--r--drivers/cpufreq/freq_table.c16
-rw-r--r--drivers/cpufreq/ia64-acpi-cpufreq.c7
-rw-r--r--drivers/cpufreq/imx6q-cpufreq.c7
-rw-r--r--drivers/cpufreq/longhaul.c3
-rw-r--r--drivers/cpufreq/mediatek-cpufreq.c13
-rw-r--r--drivers/cpufreq/p4-clockmod.c3
-rw-r--r--drivers/cpufreq/powernow-k6.c3
-rw-r--r--drivers/cpufreq/powernow-k7.c3
-rw-r--r--drivers/cpufreq/powernow-k8.c24
-rw-r--r--drivers/cpufreq/powernv-cpufreq.c11
-rw-r--r--drivers/cpufreq/ppc_cbe_cpufreq.c5
-rw-r--r--drivers/cpufreq/pxa2xx-cpufreq.c4
-rw-r--r--drivers/cpufreq/pxa3xx-cpufreq.c4
-rw-r--r--drivers/cpufreq/qoriq-cpufreq.c21
-rw-r--r--drivers/cpufreq/s3c24xx-cpufreq.c13
-rw-r--r--drivers/cpufreq/sc520_freq.c3
-rw-r--r--drivers/cpufreq/scpi-cpufreq.c10
-rw-r--r--drivers/cpufreq/sfi-cpufreq.c3
-rw-r--r--drivers/cpufreq/sh-cpufreq.c22
-rw-r--r--drivers/cpufreq/sparc-us2e-cpufreq.c3
-rw-r--r--drivers/cpufreq/sparc-us3-cpufreq.c3
-rw-r--r--drivers/cpufreq/speedstep-centrino.c4
-rw-r--r--drivers/cpufreq/speedstep-ich.c4
-rw-r--r--drivers/cpufreq/speedstep-smi.c4
-rw-r--r--drivers/cpufreq/tegra186-cpufreq.c3
-rw-r--r--include/linux/cpufreq.h1
38 files changed, 124 insertions, 178 deletions
diff --git a/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt b/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt
index dd3929e85dec..332aed8f4597 100644
--- a/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt
+++ b/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt
@@ -18,8 +18,6 @@ Optional properties:
18 in unit of nanoseconds. 18 in unit of nanoseconds.
19- voltage-tolerance: Specify the CPU voltage tolerance in percentage. 19- voltage-tolerance: Specify the CPU voltage tolerance in percentage.
20- #cooling-cells: 20- #cooling-cells:
21- cooling-min-level:
22- cooling-max-level:
23 Please refer to Documentation/devicetree/bindings/thermal/thermal.txt. 21 Please refer to Documentation/devicetree/bindings/thermal/thermal.txt.
24 22
25Examples: 23Examples:
@@ -40,8 +38,6 @@ cpus {
40 >; 38 >;
41 clock-latency = <61036>; /* two CLK32 periods */ 39 clock-latency = <61036>; /* two CLK32 periods */
42 #cooling-cells = <2>; 40 #cooling-cells = <2>;
43 cooling-min-level = <0>;
44 cooling-max-level = <2>;
45 }; 41 };
46 42
47 cpu@1 { 43 cpu@1 {
diff --git a/Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek.txt b/Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek.txt
index f6403089edcf..d36f07e0a2bb 100644
--- a/Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek.txt
+++ b/Documentation/devicetree/bindings/cpufreq/cpufreq-mediatek.txt
@@ -21,8 +21,6 @@ Optional properties:
21 flow is handled by hardware, hence no software "voltage tracking" is 21 flow is handled by hardware, hence no software "voltage tracking" is
22 needed. 22 needed.
23- #cooling-cells: 23- #cooling-cells:
24- cooling-min-level:
25- cooling-max-level:
26 Please refer to Documentation/devicetree/bindings/thermal/thermal.txt 24 Please refer to Documentation/devicetree/bindings/thermal/thermal.txt
27 for detail. 25 for detail.
28 26
@@ -67,8 +65,6 @@ Example 1 (MT7623 SoC):
67 clock-names = "cpu", "intermediate"; 65 clock-names = "cpu", "intermediate";
68 operating-points-v2 = <&cpu_opp_table>; 66 operating-points-v2 = <&cpu_opp_table>;
69 #cooling-cells = <2>; 67 #cooling-cells = <2>;
70 cooling-min-level = <0>;
71 cooling-max-level = <7>;
72 }; 68 };
73 cpu@1 { 69 cpu@1 {
74 device_type = "cpu"; 70 device_type = "cpu";
diff --git a/arch/arm/boot/dts/mt7623.dtsi b/arch/arm/boot/dts/mt7623.dtsi
index b750da5362f7..8e7c65464c9d 100644
--- a/arch/arm/boot/dts/mt7623.dtsi
+++ b/arch/arm/boot/dts/mt7623.dtsi
@@ -87,8 +87,6 @@
87 clock-names = "cpu", "intermediate"; 87 clock-names = "cpu", "intermediate";
88 operating-points-v2 = <&cpu_opp_table>; 88 operating-points-v2 = <&cpu_opp_table>;
89 #cooling-cells = <2>; 89 #cooling-cells = <2>;
90 cooling-min-level = <0>;
91 cooling-max-level = <7>;
92 clock-frequency = <1300000000>; 90 clock-frequency = <1300000000>;
93 }; 91 };
94 92
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index fb586e09682d..833b5f41f596 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -45,6 +45,7 @@ config ARM_DT_BL_CPUFREQ
45config ARM_SCPI_CPUFREQ 45config ARM_SCPI_CPUFREQ
46 tristate "SCPI based CPUfreq driver" 46 tristate "SCPI based CPUfreq driver"
47 depends on ARM_SCPI_PROTOCOL && COMMON_CLK_SCPI 47 depends on ARM_SCPI_PROTOCOL && COMMON_CLK_SCPI
48 depends on !CPU_THERMAL || THERMAL
48 help 49 help
49 This adds the CPUfreq driver support for ARM platforms using SCPI 50 This adds the CPUfreq driver support for ARM platforms using SCPI
50 protocol for CPU power management. 51 protocol for CPU power management.
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index d0c34df0529c..9449657d72f0 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -794,15 +794,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
794 valid_states++; 794 valid_states++;
795 } 795 }
796 freq_table[valid_states].frequency = CPUFREQ_TABLE_END; 796 freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
797 policy->freq_table = freq_table;
797 perf->state = 0; 798 perf->state = 0;
798 799
799 result = cpufreq_table_validate_and_show(policy, freq_table);
800 if (result)
801 goto err_freqfree;
802
803 if (perf->states[0].core_frequency * 1000 != policy->cpuinfo.max_freq)
804 pr_warn(FW_WARN "P-state 0 is not max freq\n");
805
806 switch (perf->control_register.space_id) { 800 switch (perf->control_register.space_id) {
807 case ACPI_ADR_SPACE_SYSTEM_IO: 801 case ACPI_ADR_SPACE_SYSTEM_IO:
808 /* 802 /*
@@ -842,8 +836,6 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
842 836
843 return result; 837 return result;
844 838
845err_freqfree:
846 kfree(freq_table);
847err_unreg: 839err_unreg:
848 acpi_processor_unregister_performance(cpu); 840 acpi_processor_unregister_performance(cpu);
849err_free_mask: 841err_free_mask:
@@ -871,6 +863,15 @@ static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
871 return 0; 863 return 0;
872} 864}
873 865
866static void acpi_cpufreq_cpu_ready(struct cpufreq_policy *policy)
867{
868 struct acpi_processor_performance *perf = per_cpu_ptr(acpi_perf_data,
869 policy->cpu);
870
871 if (perf->states[0].core_frequency * 1000 != policy->cpuinfo.max_freq)
872 pr_warn(FW_WARN "P-state 0 is not max freq\n");
873}
874
874static int acpi_cpufreq_resume(struct cpufreq_policy *policy) 875static int acpi_cpufreq_resume(struct cpufreq_policy *policy)
875{ 876{
876 struct acpi_cpufreq_data *data = policy->driver_data; 877 struct acpi_cpufreq_data *data = policy->driver_data;
@@ -898,6 +899,7 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
898 .bios_limit = acpi_processor_get_bios_limit, 899 .bios_limit = acpi_processor_get_bios_limit,
899 .init = acpi_cpufreq_cpu_init, 900 .init = acpi_cpufreq_cpu_init,
900 .exit = acpi_cpufreq_cpu_exit, 901 .exit = acpi_cpufreq_cpu_exit,
902 .ready = acpi_cpufreq_cpu_ready,
901 .resume = acpi_cpufreq_resume, 903 .resume = acpi_cpufreq_resume,
902 .name = "acpi-cpufreq", 904 .name = "acpi-cpufreq",
903 .attr = acpi_cpufreq_attr, 905 .attr = acpi_cpufreq_attr,
diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c
index c56b57dcfda5..1d7ef5fc1977 100644
--- a/drivers/cpufreq/arm_big_little.c
+++ b/drivers/cpufreq/arm_big_little.c
@@ -483,14 +483,7 @@ static int bL_cpufreq_init(struct cpufreq_policy *policy)
483 if (ret) 483 if (ret)
484 return ret; 484 return ret;
485 485
486 ret = cpufreq_table_validate_and_show(policy, freq_table[cur_cluster]); 486 policy->freq_table = freq_table[cur_cluster];
487 if (ret) {
488 dev_err(cpu_dev, "CPU %d, cluster: %d invalid freq table\n",
489 policy->cpu, cur_cluster);
490 put_cluster_clk_and_freq_table(cpu_dev, policy->cpus);
491 return ret;
492 }
493
494 policy->cpuinfo.transition_latency = 487 policy->cpuinfo.transition_latency =
495 arm_bL_ops->get_transition_latency(cpu_dev); 488 arm_bL_ops->get_transition_latency(cpu_dev);
496 489
diff --git a/drivers/cpufreq/brcmstb-avs-cpufreq.c b/drivers/cpufreq/brcmstb-avs-cpufreq.c
index 7281a2c19c36..6cdac1aaf23c 100644
--- a/drivers/cpufreq/brcmstb-avs-cpufreq.c
+++ b/drivers/cpufreq/brcmstb-avs-cpufreq.c
@@ -902,11 +902,7 @@ static int brcm_avs_cpufreq_init(struct cpufreq_policy *policy)
902 return ret; 902 return ret;
903 } 903 }
904 904
905 ret = cpufreq_table_validate_and_show(policy, freq_table); 905 policy->freq_table = freq_table;
906 if (ret) {
907 dev_err(dev, "invalid frequency table: %d\n", ret);
908 return ret;
909 }
910 906
911 /* All cores share the same clock and thus the same policy. */ 907 /* All cores share the same clock and thus the same policy. */
912 cpumask_setall(policy->cpus); 908 cpumask_setall(policy->cpus);
diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index a1c3025f9df7..8300a9fcb80c 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -20,6 +20,7 @@
20#include <linux/cpu.h> 20#include <linux/cpu.h>
21#include <linux/cpufreq.h> 21#include <linux/cpufreq.h>
22#include <linux/dmi.h> 22#include <linux/dmi.h>
23#include <linux/time.h>
23#include <linux/vmalloc.h> 24#include <linux/vmalloc.h>
24 25
25#include <asm/unaligned.h> 26#include <asm/unaligned.h>
@@ -162,6 +163,8 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
162 policy->cpuinfo.max_freq = cppc_dmi_max_khz; 163 policy->cpuinfo.max_freq = cppc_dmi_max_khz;
163 164
164 policy->cpuinfo.transition_latency = cppc_get_transition_latency(cpu_num); 165 policy->cpuinfo.transition_latency = cppc_get_transition_latency(cpu_num);
166 policy->transition_delay_us = cppc_get_transition_latency(cpu_num) /
167 NSEC_PER_USEC;
165 policy->shared_type = cpu->shared_type; 168 policy->shared_type = cpu->shared_type;
166 169
167 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) 170 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY)
@@ -230,8 +233,13 @@ static int __init cppc_cpufreq_init(void)
230 return ret; 233 return ret;
231 234
232out: 235out:
233 for_each_possible_cpu(i) 236 for_each_possible_cpu(i) {
234 kfree(all_cpu_data[i]); 237 cpu = all_cpu_data[i];
238 if (!cpu)
239 break;
240 free_cpumask_var(cpu->shared_cpu_map);
241 kfree(cpu);
242 }
235 243
236 kfree(all_cpu_data); 244 kfree(all_cpu_data);
237 return -ENODEV; 245 return -ENODEV;
diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index de3d104c25d7..190ea0dccb79 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -258,16 +258,10 @@ static int cpufreq_init(struct cpufreq_policy *policy)
258 priv->cpu_dev = cpu_dev; 258 priv->cpu_dev = cpu_dev;
259 policy->driver_data = priv; 259 policy->driver_data = priv;
260 policy->clk = cpu_clk; 260 policy->clk = cpu_clk;
261 policy->freq_table = freq_table;
261 262
262 policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000; 263 policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000;
263 264
264 ret = cpufreq_table_validate_and_show(policy, freq_table);
265 if (ret) {
266 dev_err(cpu_dev, "%s: invalid frequency table: %d\n", __func__,
267 ret);
268 goto out_free_cpufreq_table;
269 }
270
271 /* Support turbo/boost mode */ 265 /* Support turbo/boost mode */
272 if (policy_has_boost_freq(policy)) { 266 if (policy_has_boost_freq(policy)) {
273 /* This gets disabled by core on driver unregister */ 267 /* This gets disabled by core on driver unregister */
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index de33ebf008ad..075d18f6ba7a 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -178,14 +178,7 @@ int cpufreq_generic_init(struct cpufreq_policy *policy,
178 struct cpufreq_frequency_table *table, 178 struct cpufreq_frequency_table *table,
179 unsigned int transition_latency) 179 unsigned int transition_latency)
180{ 180{
181 int ret; 181 policy->freq_table = table;
182
183 ret = cpufreq_table_validate_and_show(policy, table);
184 if (ret) {
185 pr_err("%s: invalid frequency table: %d\n", __func__, ret);
186 return ret;
187 }
188
189 policy->cpuinfo.transition_latency = transition_latency; 182 policy->cpuinfo.transition_latency = transition_latency;
190 183
191 /* 184 /*
@@ -1219,6 +1212,10 @@ static int cpufreq_online(unsigned int cpu)
1219 goto out_free_policy; 1212 goto out_free_policy;
1220 } 1213 }
1221 1214
1215 ret = cpufreq_table_validate_and_sort(policy);
1216 if (ret)
1217 goto out_exit_policy;
1218
1222 down_write(&policy->rwsem); 1219 down_write(&policy->rwsem);
1223 1220
1224 if (new_policy) { 1221 if (new_policy) {
@@ -1249,7 +1246,7 @@ static int cpufreq_online(unsigned int cpu)
1249 policy->cur = cpufreq_driver->get(policy->cpu); 1246 policy->cur = cpufreq_driver->get(policy->cpu);
1250 if (!policy->cur) { 1247 if (!policy->cur) {
1251 pr_err("%s: ->get() failed\n", __func__); 1248 pr_err("%s: ->get() failed\n", __func__);
1252 goto out_exit_policy; 1249 goto out_destroy_policy;
1253 } 1250 }
1254 } 1251 }
1255 1252
@@ -1296,7 +1293,7 @@ static int cpufreq_online(unsigned int cpu)
1296 if (new_policy) { 1293 if (new_policy) {
1297 ret = cpufreq_add_dev_interface(policy); 1294 ret = cpufreq_add_dev_interface(policy);
1298 if (ret) 1295 if (ret)
1299 goto out_exit_policy; 1296 goto out_destroy_policy;
1300 1297
1301 cpufreq_stats_create_table(policy); 1298 cpufreq_stats_create_table(policy);
1302 1299
@@ -1311,7 +1308,7 @@ static int cpufreq_online(unsigned int cpu)
1311 __func__, cpu, ret); 1308 __func__, cpu, ret);
1312 /* cpufreq_policy_free() will notify based on this */ 1309 /* cpufreq_policy_free() will notify based on this */
1313 new_policy = false; 1310 new_policy = false;
1314 goto out_exit_policy; 1311 goto out_destroy_policy;
1315 } 1312 }
1316 1313
1317 up_write(&policy->rwsem); 1314 up_write(&policy->rwsem);
@@ -1326,15 +1323,16 @@ static int cpufreq_online(unsigned int cpu)
1326 1323
1327 return 0; 1324 return 0;
1328 1325
1329out_exit_policy: 1326out_destroy_policy:
1327 for_each_cpu(j, policy->real_cpus)
1328 remove_cpu_dev_symlink(policy, get_cpu_device(j));
1329
1330 up_write(&policy->rwsem); 1330 up_write(&policy->rwsem);
1331 1331
1332out_exit_policy:
1332 if (cpufreq_driver->exit) 1333 if (cpufreq_driver->exit)
1333 cpufreq_driver->exit(policy); 1334 cpufreq_driver->exit(policy);
1334 1335
1335 for_each_cpu(j, policy->real_cpus)
1336 remove_cpu_dev_symlink(policy, get_cpu_device(j));
1337
1338out_free_policy: 1336out_free_policy:
1339 cpufreq_policy_free(policy); 1337 cpufreq_policy_free(policy);
1340 return ret; 1338 return ret;
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c
index cdf097b29862..60bea302abbe 100644
--- a/drivers/cpufreq/e_powersaver.c
+++ b/drivers/cpufreq/e_powersaver.c
@@ -184,7 +184,6 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
184 struct cpuinfo_x86 *c = &cpu_data(0); 184 struct cpuinfo_x86 *c = &cpu_data(0);
185 struct cpufreq_frequency_table *f_table; 185 struct cpufreq_frequency_table *f_table;
186 int k, step, voltage; 186 int k, step, voltage;
187 int ret;
188 int states; 187 int states;
189#if IS_ENABLED(CONFIG_ACPI_PROCESSOR) 188#if IS_ENABLED(CONFIG_ACPI_PROCESSOR)
190 unsigned int limit; 189 unsigned int limit;
@@ -359,12 +358,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
359 } 358 }
360 359
361 policy->cpuinfo.transition_latency = 140000; /* 844mV -> 700mV in ns */ 360 policy->cpuinfo.transition_latency = 140000; /* 844mV -> 700mV in ns */
362 361 policy->freq_table = &centaur->freq_table[0];
363 ret = cpufreq_table_validate_and_show(policy, &centaur->freq_table[0]);
364 if (ret) {
365 kfree(centaur);
366 return ret;
367 }
368 362
369 return 0; 363 return 0;
370} 364}
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c
index 45e2ca62515e..03419f064752 100644
--- a/drivers/cpufreq/elanfreq.c
+++ b/drivers/cpufreq/elanfreq.c
@@ -165,7 +165,8 @@ static int elanfreq_cpu_init(struct cpufreq_policy *policy)
165 if (pos->frequency > max_freq) 165 if (pos->frequency > max_freq)
166 pos->frequency = CPUFREQ_ENTRY_INVALID; 166 pos->frequency = CPUFREQ_ENTRY_INVALID;
167 167
168 return cpufreq_table_validate_and_show(policy, elanfreq_table); 168 policy->freq_table = elanfreq_table;
169 return 0;
169} 170}
170 171
171 172
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 6d007f824ca7..10e119ae66dd 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -362,10 +362,24 @@ int cpufreq_table_validate_and_show(struct cpufreq_policy *policy,
362 return ret; 362 return ret;
363 363
364 policy->freq_table = table; 364 policy->freq_table = table;
365 return set_freq_table_sorted(policy); 365 return 0;
366} 366}
367EXPORT_SYMBOL_GPL(cpufreq_table_validate_and_show); 367EXPORT_SYMBOL_GPL(cpufreq_table_validate_and_show);
368 368
369int cpufreq_table_validate_and_sort(struct cpufreq_policy *policy)
370{
371 int ret;
372
373 if (!policy->freq_table)
374 return 0;
375
376 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
377 if (ret)
378 return ret;
379
380 return set_freq_table_sorted(policy);
381}
382
369MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); 383MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
370MODULE_DESCRIPTION("CPUfreq frequency table helpers"); 384MODULE_DESCRIPTION("CPUfreq frequency table helpers");
371MODULE_LICENSE("GPL"); 385MODULE_LICENSE("GPL");
diff --git a/drivers/cpufreq/ia64-acpi-cpufreq.c b/drivers/cpufreq/ia64-acpi-cpufreq.c
index a757c0a1e7b5..7974a2fdb760 100644
--- a/drivers/cpufreq/ia64-acpi-cpufreq.c
+++ b/drivers/cpufreq/ia64-acpi-cpufreq.c
@@ -270,10 +270,7 @@ acpi_cpufreq_cpu_init (
270 } 270 }
271 } 271 }
272 272
273 result = cpufreq_table_validate_and_show(policy, freq_table); 273 policy->freq_table = freq_table;
274 if (result) {
275 goto err_freqfree;
276 }
277 274
278 /* notify BIOS that we exist */ 275 /* notify BIOS that we exist */
279 acpi_processor_notify_smm(THIS_MODULE); 276 acpi_processor_notify_smm(THIS_MODULE);
@@ -296,8 +293,6 @@ acpi_cpufreq_cpu_init (
296 293
297 return (result); 294 return (result);
298 295
299 err_freqfree:
300 kfree(freq_table);
301 err_unreg: 296 err_unreg:
302 acpi_processor_unregister_performance(cpu); 297 acpi_processor_unregister_performance(cpu);
303 err_free: 298 err_free:
diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index ff67859948b3..83cf631fc9bc 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -52,6 +52,7 @@ static struct clk_bulk_data clks[] = {
52static struct device *cpu_dev; 52static struct device *cpu_dev;
53static bool free_opp; 53static bool free_opp;
54static struct cpufreq_frequency_table *freq_table; 54static struct cpufreq_frequency_table *freq_table;
55static unsigned int max_freq;
55static unsigned int transition_latency; 56static unsigned int transition_latency;
56 57
57static u32 *imx6_soc_volt; 58static u32 *imx6_soc_volt;
@@ -196,7 +197,7 @@ static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
196 197
197 policy->clk = clks[ARM].clk; 198 policy->clk = clks[ARM].clk;
198 ret = cpufreq_generic_init(policy, freq_table, transition_latency); 199 ret = cpufreq_generic_init(policy, freq_table, transition_latency);
199 policy->suspend_freq = policy->max; 200 policy->suspend_freq = max_freq;
200 201
201 return ret; 202 return ret;
202} 203}
@@ -437,12 +438,12 @@ soc_opp_out:
437 * freq_table initialised from OPP is therefore sorted in the 438 * freq_table initialised from OPP is therefore sorted in the
438 * same order. 439 * same order.
439 */ 440 */
441 max_freq = freq_table[--num].frequency;
440 opp = dev_pm_opp_find_freq_exact(cpu_dev, 442 opp = dev_pm_opp_find_freq_exact(cpu_dev,
441 freq_table[0].frequency * 1000, true); 443 freq_table[0].frequency * 1000, true);
442 min_volt = dev_pm_opp_get_voltage(opp); 444 min_volt = dev_pm_opp_get_voltage(opp);
443 dev_pm_opp_put(opp); 445 dev_pm_opp_put(opp);
444 opp = dev_pm_opp_find_freq_exact(cpu_dev, 446 opp = dev_pm_opp_find_freq_exact(cpu_dev, max_freq * 1000, true);
445 freq_table[--num].frequency * 1000, true);
446 max_volt = dev_pm_opp_get_voltage(opp); 447 max_volt = dev_pm_opp_get_voltage(opp);
447 dev_pm_opp_put(opp); 448 dev_pm_opp_put(opp);
448 449
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index f730b6528c18..61a4c5b08219 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -895,8 +895,9 @@ static int longhaul_cpu_init(struct cpufreq_policy *policy)
895 longhaul_setup_voltagescaling(); 895 longhaul_setup_voltagescaling();
896 896
897 policy->transition_delay_us = 200000; /* usec */ 897 policy->transition_delay_us = 200000; /* usec */
898 policy->freq_table = longhaul_table;
898 899
899 return cpufreq_table_validate_and_show(policy, longhaul_table); 900 return 0;
900} 901}
901 902
902static struct cpufreq_driver longhaul_driver = { 903static struct cpufreq_driver longhaul_driver = {
diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
index 8c04dddd3c28..eb8920d39818 100644
--- a/drivers/cpufreq/mediatek-cpufreq.c
+++ b/drivers/cpufreq/mediatek-cpufreq.c
@@ -460,21 +460,12 @@ static int mtk_cpufreq_init(struct cpufreq_policy *policy)
460 return ret; 460 return ret;
461 } 461 }
462 462
463 ret = cpufreq_table_validate_and_show(policy, freq_table);
464 if (ret) {
465 pr_err("%s: invalid frequency table: %d\n", __func__, ret);
466 goto out_free_cpufreq_table;
467 }
468
469 cpumask_copy(policy->cpus, &info->cpus); 463 cpumask_copy(policy->cpus, &info->cpus);
464 policy->freq_table = freq_table;
470 policy->driver_data = info; 465 policy->driver_data = info;
471 policy->clk = info->cpu_clk; 466 policy->clk = info->cpu_clk;
472 467
473 return 0; 468 return 0;
474
475out_free_cpufreq_table:
476 dev_pm_opp_free_cpufreq_table(info->cpu_dev, &freq_table);
477 return ret;
478} 469}
479 470
480static int mtk_cpufreq_exit(struct cpufreq_policy *policy) 471static int mtk_cpufreq_exit(struct cpufreq_policy *policy)
@@ -578,7 +569,7 @@ static int __init mtk_cpufreq_driver_init(void)
578 match = of_match_node(mtk_cpufreq_machines, np); 569 match = of_match_node(mtk_cpufreq_machines, np);
579 of_node_put(np); 570 of_node_put(np);
580 if (!match) { 571 if (!match) {
581 pr_warn("Machine is not compatible with mtk-cpufreq\n"); 572 pr_debug("Machine is not compatible with mtk-cpufreq\n");
582 return -ENODEV; 573 return -ENODEV;
583 } 574 }
584 575
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
index a25741b1281b..911206243050 100644
--- a/drivers/cpufreq/p4-clockmod.c
+++ b/drivers/cpufreq/p4-clockmod.c
@@ -202,8 +202,9 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
202 /* the transition latency is set to be 1 higher than the maximum 202 /* the transition latency is set to be 1 higher than the maximum
203 * transition latency of the ondemand governor */ 203 * transition latency of the ondemand governor */
204 policy->cpuinfo.transition_latency = 10000001; 204 policy->cpuinfo.transition_latency = 10000001;
205 policy->freq_table = &p4clockmod_table[0];
205 206
206 return cpufreq_table_validate_and_show(policy, &p4clockmod_table[0]); 207 return 0;
207} 208}
208 209
209 210
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index dedd2568e852..8a8ea68611a8 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -214,8 +214,9 @@ have_busfreq:
214 214
215 /* cpuinfo and default policy values */ 215 /* cpuinfo and default policy values */
216 policy->cpuinfo.transition_latency = 500000; 216 policy->cpuinfo.transition_latency = 500000;
217 policy->freq_table = clock_ratio;
217 218
218 return cpufreq_table_validate_and_show(policy, clock_ratio); 219 return 0;
219} 220}
220 221
221 222
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c
index 302e9ce793a0..d6cb052b0a75 100644
--- a/drivers/cpufreq/powernow-k7.c
+++ b/drivers/cpufreq/powernow-k7.c
@@ -639,8 +639,9 @@ static int powernow_cpu_init(struct cpufreq_policy *policy)
639 639
640 policy->cpuinfo.transition_latency = 640 policy->cpuinfo.transition_latency =
641 cpufreq_scale(2000000UL, fsb, latency); 641 cpufreq_scale(2000000UL, fsb, latency);
642 policy->freq_table = powernow_table;
642 643
643 return cpufreq_table_validate_and_show(policy, powernow_table); 644 return 0;
644} 645}
645 646
646static int powernow_cpu_exit(struct cpufreq_policy *policy) 647static int powernow_cpu_exit(struct cpufreq_policy *policy)
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index b01e31db5f83..fb77b39a4ce3 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -122,14 +122,12 @@ static int query_current_values_with_pending_wait(struct powernow_k8_data *data)
122static void count_off_irt(struct powernow_k8_data *data) 122static void count_off_irt(struct powernow_k8_data *data)
123{ 123{
124 udelay((1 << data->irt) * 10); 124 udelay((1 << data->irt) * 10);
125 return;
126} 125}
127 126
128/* the voltage stabilization time */ 127/* the voltage stabilization time */
129static void count_off_vst(struct powernow_k8_data *data) 128static void count_off_vst(struct powernow_k8_data *data)
130{ 129{
131 udelay(data->vstable * VST_UNITS_20US); 130 udelay(data->vstable * VST_UNITS_20US);
132 return;
133} 131}
134 132
135/* need to init the control msr to a safe value (for each cpu) */ 133/* need to init the control msr to a safe value (for each cpu) */
@@ -591,10 +589,8 @@ static int fill_powernow_table(struct powernow_k8_data *data,
591 589
592 powernow_table = kzalloc((sizeof(*powernow_table) 590 powernow_table = kzalloc((sizeof(*powernow_table)
593 * (data->numps + 1)), GFP_KERNEL); 591 * (data->numps + 1)), GFP_KERNEL);
594 if (!powernow_table) { 592 if (!powernow_table)
595 pr_err("powernow_table memory alloc failure\n");
596 return -ENOMEM; 593 return -ENOMEM;
597 }
598 594
599 for (j = 0; j < data->numps; j++) { 595 for (j = 0; j < data->numps; j++) {
600 int freq; 596 int freq;
@@ -760,10 +756,8 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
760 /* fill in data->powernow_table */ 756 /* fill in data->powernow_table */
761 powernow_table = kzalloc((sizeof(*powernow_table) 757 powernow_table = kzalloc((sizeof(*powernow_table)
762 * (data->acpi_data.state_count + 1)), GFP_KERNEL); 758 * (data->acpi_data.state_count + 1)), GFP_KERNEL);
763 if (!powernow_table) { 759 if (!powernow_table)
764 pr_debug("powernow_table memory alloc failure\n");
765 goto err_out; 760 goto err_out;
766 }
767 761
768 /* fill in data */ 762 /* fill in data */
769 data->numps = data->acpi_data.state_count; 763 data->numps = data->acpi_data.state_count;
@@ -1042,10 +1036,8 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1042 return -ENODEV; 1036 return -ENODEV;
1043 1037
1044 data = kzalloc(sizeof(*data), GFP_KERNEL); 1038 data = kzalloc(sizeof(*data), GFP_KERNEL);
1045 if (!data) { 1039 if (!data)
1046 pr_err("unable to alloc powernow_k8_data\n");
1047 return -ENOMEM; 1040 return -ENOMEM;
1048 }
1049 1041
1050 data->cpu = pol->cpu; 1042 data->cpu = pol->cpu;
1051 1043
@@ -1084,15 +1076,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1084 1076
1085 cpumask_copy(pol->cpus, topology_core_cpumask(pol->cpu)); 1077 cpumask_copy(pol->cpus, topology_core_cpumask(pol->cpu));
1086 data->available_cores = pol->cpus; 1078 data->available_cores = pol->cpus;
1087 1079 pol->freq_table = data->powernow_table;
1088 /* min/max the cpu is capable of */
1089 if (cpufreq_table_validate_and_show(pol, data->powernow_table)) {
1090 pr_err(FW_BUG "invalid powernow_table\n");
1091 powernow_k8_cpu_exit_acpi(data);
1092 kfree(data->powernow_table);
1093 kfree(data);
1094 return -EINVAL;
1095 }
1096 1080
1097 pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n", 1081 pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
1098 data->currfid, data->currvid); 1082 data->currfid, data->currvid);
diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 29cdec198657..0591874856d3 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -812,7 +812,7 @@ gpstates_done:
812 812
813static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy) 813static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
814{ 814{
815 int base, i, ret; 815 int base, i;
816 struct kernfs_node *kn; 816 struct kernfs_node *kn;
817 struct global_pstate_info *gpstates; 817 struct global_pstate_info *gpstates;
818 818
@@ -848,15 +848,10 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
848 gpstates->timer.expires = jiffies + 848 gpstates->timer.expires = jiffies +
849 msecs_to_jiffies(GPSTATE_TIMER_INTERVAL); 849 msecs_to_jiffies(GPSTATE_TIMER_INTERVAL);
850 spin_lock_init(&gpstates->gpstate_lock); 850 spin_lock_init(&gpstates->gpstate_lock);
851 ret = cpufreq_table_validate_and_show(policy, powernv_freqs);
852
853 if (ret < 0) {
854 kfree(policy->driver_data);
855 return ret;
856 }
857 851
852 policy->freq_table = powernv_freqs;
858 policy->fast_switch_possible = true; 853 policy->fast_switch_possible = true;
859 return ret; 854 return 0;
860} 855}
861 856
862static int powernv_cpufreq_cpu_exit(struct cpufreq_policy *policy) 857static int powernv_cpufreq_cpu_exit(struct cpufreq_policy *policy)
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index 5a4c5a639f61..41a0f0be3f9f 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -121,9 +121,8 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
121 cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); 121 cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu));
122#endif 122#endif
123 123
124 /* this ensures that policy->cpuinfo_min 124 policy->freq_table = cbe_freqs;
125 * and policy->cpuinfo_max are set correctly */ 125 return 0;
126 return cpufreq_table_validate_and_show(policy, cbe_freqs);
127} 126}
128 127
129static int cbe_cpufreq_target(struct cpufreq_policy *policy, 128static int cbe_cpufreq_target(struct cpufreq_policy *policy,
diff --git a/drivers/cpufreq/pxa2xx-cpufreq.c b/drivers/cpufreq/pxa2xx-cpufreq.c
index 06b024a3e474..46254e583982 100644
--- a/drivers/cpufreq/pxa2xx-cpufreq.c
+++ b/drivers/cpufreq/pxa2xx-cpufreq.c
@@ -292,10 +292,10 @@ static int pxa_cpufreq_init(struct cpufreq_policy *policy)
292 pr_info("using %s frequency table\n", 292 pr_info("using %s frequency table\n",
293 pxa255_turbo_table ? "turbo" : "run"); 293 pxa255_turbo_table ? "turbo" : "run");
294 294
295 cpufreq_table_validate_and_show(policy, pxa255_freq_table); 295 policy->freq_table = pxa255_freq_table;
296 } 296 }
297 else if (cpu_is_pxa27x()) { 297 else if (cpu_is_pxa27x()) {
298 cpufreq_table_validate_and_show(policy, pxa27x_freq_table); 298 policy->freq_table = pxa27x_freq_table;
299 } 299 }
300 300
301 pr_info("frequency change support initialized\n"); 301 pr_info("frequency change support initialized\n");
diff --git a/drivers/cpufreq/pxa3xx-cpufreq.c b/drivers/cpufreq/pxa3xx-cpufreq.c
index a01275900389..7acc7fa4536d 100644
--- a/drivers/cpufreq/pxa3xx-cpufreq.c
+++ b/drivers/cpufreq/pxa3xx-cpufreq.c
@@ -108,7 +108,9 @@ static int setup_freqs_table(struct cpufreq_policy *policy,
108 pxa3xx_freqs_num = num; 108 pxa3xx_freqs_num = num;
109 pxa3xx_freqs_table = table; 109 pxa3xx_freqs_table = table;
110 110
111 return cpufreq_table_validate_and_show(policy, table); 111 policy->freq_table = table;
112
113 return 0;
112} 114}
113 115
114static void __update_core_freq(struct pxa3xx_freq_info *info) 116static void __update_core_freq(struct pxa3xx_freq_info *info)
diff --git a/drivers/cpufreq/qoriq-cpufreq.c b/drivers/cpufreq/qoriq-cpufreq.c
index 0562761a3dec..3d773f64b4df 100644
--- a/drivers/cpufreq/qoriq-cpufreq.c
+++ b/drivers/cpufreq/qoriq-cpufreq.c
@@ -165,7 +165,7 @@ static void freq_table_sort(struct cpufreq_frequency_table *freq_table,
165static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy) 165static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy)
166{ 166{
167 struct device_node *np; 167 struct device_node *np;
168 int i, count, ret; 168 int i, count;
169 u32 freq; 169 u32 freq;
170 struct clk *clk; 170 struct clk *clk;
171 const struct clk_hw *hwclk; 171 const struct clk_hw *hwclk;
@@ -192,16 +192,12 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy)
192 count = clk_hw_get_num_parents(hwclk); 192 count = clk_hw_get_num_parents(hwclk);
193 193
194 data->pclk = kcalloc(count, sizeof(struct clk *), GFP_KERNEL); 194 data->pclk = kcalloc(count, sizeof(struct clk *), GFP_KERNEL);
195 if (!data->pclk) { 195 if (!data->pclk)
196 pr_err("%s: no memory\n", __func__);
197 goto err_nomem2; 196 goto err_nomem2;
198 }
199 197
200 table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL); 198 table = kcalloc(count + 1, sizeof(*table), GFP_KERNEL);
201 if (!table) { 199 if (!table)
202 pr_err("%s: no memory\n", __func__);
203 goto err_pclk; 200 goto err_pclk;
204 }
205 201
206 for (i = 0; i < count; i++) { 202 for (i = 0; i < count; i++) {
207 clk = clk_hw_get_parent_by_index(hwclk, i)->clk; 203 clk = clk_hw_get_parent_by_index(hwclk, i)->clk;
@@ -213,14 +209,7 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy)
213 freq_table_redup(table, count); 209 freq_table_redup(table, count);
214 freq_table_sort(table, count); 210 freq_table_sort(table, count);
215 table[i].frequency = CPUFREQ_TABLE_END; 211 table[i].frequency = CPUFREQ_TABLE_END;
216 212 policy->freq_table = table;
217 /* set the min and max frequency properly */
218 ret = cpufreq_table_validate_and_show(policy, table);
219 if (ret) {
220 pr_err("invalid frequency table: %d\n", ret);
221 goto err_nomem1;
222 }
223
224 data->table = table; 213 data->table = table;
225 214
226 /* update ->cpus if we have cluster, no harm if not */ 215 /* update ->cpus if we have cluster, no harm if not */
@@ -236,8 +225,6 @@ static int qoriq_cpufreq_cpu_init(struct cpufreq_policy *policy)
236 225
237 return 0; 226 return 0;
238 227
239err_nomem1:
240 kfree(table);
241err_pclk: 228err_pclk:
242 kfree(data->pclk); 229 kfree(data->pclk);
243err_nomem2: 230err_nomem2:
diff --git a/drivers/cpufreq/s3c24xx-cpufreq.c b/drivers/cpufreq/s3c24xx-cpufreq.c
index 6bebc1f9f55a..909bd6e27639 100644
--- a/drivers/cpufreq/s3c24xx-cpufreq.c
+++ b/drivers/cpufreq/s3c24xx-cpufreq.c
@@ -351,11 +351,8 @@ struct clk *s3c_cpufreq_clk_get(struct device *dev, const char *name)
351static int s3c_cpufreq_init(struct cpufreq_policy *policy) 351static int s3c_cpufreq_init(struct cpufreq_policy *policy)
352{ 352{
353 policy->clk = clk_arm; 353 policy->clk = clk_arm;
354
355 policy->cpuinfo.transition_latency = cpu_cur.info->latency; 354 policy->cpuinfo.transition_latency = cpu_cur.info->latency;
356 355 policy->freq_table = ftab;
357 if (ftab)
358 return cpufreq_table_validate_and_show(policy, ftab);
359 356
360 return 0; 357 return 0;
361} 358}
@@ -479,10 +476,8 @@ int __init s3c_cpufreq_setboard(struct s3c_cpufreq_board *board)
479 * initdata. */ 476 * initdata. */
480 477
481 ours = kzalloc(sizeof(*ours), GFP_KERNEL); 478 ours = kzalloc(sizeof(*ours), GFP_KERNEL);
482 if (ours == NULL) { 479 if (!ours)
483 pr_err("%s: no memory\n", __func__);
484 return -ENOMEM; 480 return -ENOMEM;
485 }
486 481
487 *ours = *board; 482 *ours = *board;
488 cpu_cur.board = ours; 483 cpu_cur.board = ours;
@@ -568,10 +563,8 @@ static int s3c_cpufreq_build_freq(void)
568 size++; 563 size++;
569 564
570 ftab = kzalloc(sizeof(*ftab) * size, GFP_KERNEL); 565 ftab = kzalloc(sizeof(*ftab) * size, GFP_KERNEL);
571 if (!ftab) { 566 if (!ftab)
572 pr_err("%s: no memory for tables\n", __func__);
573 return -ENOMEM; 567 return -ENOMEM;
574 }
575 568
576 ftab_size = size; 569 ftab_size = size;
577 570
diff --git a/drivers/cpufreq/sc520_freq.c b/drivers/cpufreq/sc520_freq.c
index 4225501a4b78..abaa75e86148 100644
--- a/drivers/cpufreq/sc520_freq.c
+++ b/drivers/cpufreq/sc520_freq.c
@@ -83,8 +83,9 @@ static int sc520_freq_cpu_init(struct cpufreq_policy *policy)
83 83
84 /* cpuinfo and default policy values */ 84 /* cpuinfo and default policy values */
85 policy->cpuinfo.transition_latency = 1000000; /* 1ms */ 85 policy->cpuinfo.transition_latency = 1000000; /* 1ms */
86 policy->freq_table = sc520_freq_table;
86 87
87 return cpufreq_table_validate_and_show(policy, sc520_freq_table); 88 return 0;
88} 89}
89 90
90 91
diff --git a/drivers/cpufreq/scpi-cpufreq.c b/drivers/cpufreq/scpi-cpufreq.c
index d300a163945f..87a98ec77773 100644
--- a/drivers/cpufreq/scpi-cpufreq.c
+++ b/drivers/cpufreq/scpi-cpufreq.c
@@ -158,13 +158,7 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy)
158 } 158 }
159 159
160 policy->driver_data = priv; 160 policy->driver_data = priv;
161 161 policy->freq_table = freq_table;
162 ret = cpufreq_table_validate_and_show(policy, freq_table);
163 if (ret) {
164 dev_err(cpu_dev, "%s: invalid frequency table: %d\n", __func__,
165 ret);
166 goto out_put_clk;
167 }
168 162
169 /* scpi allows DVFS request for any domain from any CPU */ 163 /* scpi allows DVFS request for any domain from any CPU */
170 policy->dvfs_possible_from_any_cpu = true; 164 policy->dvfs_possible_from_any_cpu = true;
@@ -178,8 +172,6 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy)
178 policy->fast_switch_possible = false; 172 policy->fast_switch_possible = false;
179 return 0; 173 return 0;
180 174
181out_put_clk:
182 clk_put(priv->clk);
183out_free_cpufreq_table: 175out_free_cpufreq_table:
184 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table); 176 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
185out_free_priv: 177out_free_priv:
diff --git a/drivers/cpufreq/sfi-cpufreq.c b/drivers/cpufreq/sfi-cpufreq.c
index 3779742f86e3..9767afe05da2 100644
--- a/drivers/cpufreq/sfi-cpufreq.c
+++ b/drivers/cpufreq/sfi-cpufreq.c
@@ -72,8 +72,9 @@ static int sfi_cpufreq_cpu_init(struct cpufreq_policy *policy)
72{ 72{
73 policy->shared_type = CPUFREQ_SHARED_TYPE_HW; 73 policy->shared_type = CPUFREQ_SHARED_TYPE_HW;
74 policy->cpuinfo.transition_latency = 100000; /* 100us */ 74 policy->cpuinfo.transition_latency = 100000; /* 100us */
75 policy->freq_table = freq_table;
75 76
76 return cpufreq_table_validate_and_show(policy, freq_table); 77 return 0;
77} 78}
78 79
79static struct cpufreq_driver sfi_cpufreq_driver = { 80static struct cpufreq_driver sfi_cpufreq_driver = {
diff --git a/drivers/cpufreq/sh-cpufreq.c b/drivers/cpufreq/sh-cpufreq.c
index 28893d435cf5..5096c0ab781b 100644
--- a/drivers/cpufreq/sh-cpufreq.c
+++ b/drivers/cpufreq/sh-cpufreq.c
@@ -122,11 +122,7 @@ static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
122 122
123 freq_table = cpuclk->nr_freqs ? cpuclk->freq_table : NULL; 123 freq_table = cpuclk->nr_freqs ? cpuclk->freq_table : NULL;
124 if (freq_table) { 124 if (freq_table) {
125 int result; 125 policy->freq_table = freq_table;
126
127 result = cpufreq_table_validate_and_show(policy, freq_table);
128 if (result)
129 return result;
130 } else { 126 } else {
131 dev_notice(dev, "no frequency table found, falling back " 127 dev_notice(dev, "no frequency table found, falling back "
132 "to rate rounding.\n"); 128 "to rate rounding.\n");
@@ -137,11 +133,6 @@ static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
137 (clk_round_rate(cpuclk, ~0UL) + 500) / 1000; 133 (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
138 } 134 }
139 135
140 dev_info(dev, "CPU Frequencies - Minimum %u.%03u MHz, "
141 "Maximum %u.%03u MHz.\n",
142 policy->min / 1000, policy->min % 1000,
143 policy->max / 1000, policy->max % 1000);
144
145 return 0; 136 return 0;
146} 137}
147 138
@@ -155,6 +146,16 @@ static int sh_cpufreq_cpu_exit(struct cpufreq_policy *policy)
155 return 0; 146 return 0;
156} 147}
157 148
149static void sh_cpufreq_cpu_ready(struct cpufreq_policy *policy)
150{
151 struct device *dev = get_cpu_device(policy->cpu);
152
153 dev_info(dev, "CPU Frequencies - Minimum %u.%03u MHz, "
154 "Maximum %u.%03u MHz.\n",
155 policy->min / 1000, policy->min % 1000,
156 policy->max / 1000, policy->max % 1000);
157}
158
158static struct cpufreq_driver sh_cpufreq_driver = { 159static struct cpufreq_driver sh_cpufreq_driver = {
159 .name = "sh", 160 .name = "sh",
160 .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, 161 .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
@@ -163,6 +164,7 @@ static struct cpufreq_driver sh_cpufreq_driver = {
163 .verify = sh_cpufreq_verify, 164 .verify = sh_cpufreq_verify,
164 .init = sh_cpufreq_cpu_init, 165 .init = sh_cpufreq_cpu_init,
165 .exit = sh_cpufreq_cpu_exit, 166 .exit = sh_cpufreq_cpu_exit,
167 .ready = sh_cpufreq_cpu_ready,
166 .attr = cpufreq_generic_attr, 168 .attr = cpufreq_generic_attr,
167}; 169};
168 170
diff --git a/drivers/cpufreq/sparc-us2e-cpufreq.c b/drivers/cpufreq/sparc-us2e-cpufreq.c
index 90f33efee5fc..bbd1d1e166b8 100644
--- a/drivers/cpufreq/sparc-us2e-cpufreq.c
+++ b/drivers/cpufreq/sparc-us2e-cpufreq.c
@@ -292,8 +292,9 @@ static int __init us2e_freq_cpu_init(struct cpufreq_policy *policy)
292 292
293 policy->cpuinfo.transition_latency = 0; 293 policy->cpuinfo.transition_latency = 0;
294 policy->cur = clock_tick; 294 policy->cur = clock_tick;
295 policy->freq_table = table;
295 296
296 return cpufreq_table_validate_and_show(policy, table); 297 return 0;
297} 298}
298 299
299static int us2e_freq_cpu_exit(struct cpufreq_policy *policy) 300static int us2e_freq_cpu_exit(struct cpufreq_policy *policy)
diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
index 30645b0118f9..51e3c6018e74 100644
--- a/drivers/cpufreq/sparc-us3-cpufreq.c
+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
@@ -136,8 +136,9 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
136 136
137 policy->cpuinfo.transition_latency = 0; 137 policy->cpuinfo.transition_latency = 0;
138 policy->cur = clock_tick; 138 policy->cur = clock_tick;
139 policy->freq_table = table;
139 140
140 return cpufreq_table_validate_and_show(policy, table); 141 return 0;
141} 142}
142 143
143static int us3_freq_cpu_exit(struct cpufreq_policy *policy) 144static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 4fa5adf16c70..a1fb735685db 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -394,9 +394,9 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
394 394
395 policy->cpuinfo.transition_latency = 10000; 395 policy->cpuinfo.transition_latency = 10000;
396 /* 10uS transition latency */ 396 /* 10uS transition latency */
397 policy->freq_table = per_cpu(centrino_model, policy->cpu)->op_points;
397 398
398 return cpufreq_table_validate_and_show(policy, 399 return 0;
399 per_cpu(centrino_model, policy->cpu)->op_points);
400} 400}
401 401
402static int centrino_cpu_exit(struct cpufreq_policy *policy) 402static int centrino_cpu_exit(struct cpufreq_policy *policy)
diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c
index 0412a246a785..fbbcb88db061 100644
--- a/drivers/cpufreq/speedstep-ich.c
+++ b/drivers/cpufreq/speedstep-ich.c
@@ -304,7 +304,9 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
304 if (gf.ret) 304 if (gf.ret)
305 return gf.ret; 305 return gf.ret;
306 306
307 return cpufreq_table_validate_and_show(policy, speedstep_freqs); 307 policy->freq_table = speedstep_freqs;
308
309 return 0;
308} 310}
309 311
310 312
diff --git a/drivers/cpufreq/speedstep-smi.c b/drivers/cpufreq/speedstep-smi.c
index d23f24ccff38..01fe70dae20b 100644
--- a/drivers/cpufreq/speedstep-smi.c
+++ b/drivers/cpufreq/speedstep-smi.c
@@ -266,7 +266,9 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
266 pr_debug("workaround worked.\n"); 266 pr_debug("workaround worked.\n");
267 } 267 }
268 268
269 return cpufreq_table_validate_and_show(policy, speedstep_freqs); 269 policy->freq_table = speedstep_freqs;
270
271 return 0;
270} 272}
271 273
272static unsigned int speedstep_get(unsigned int cpu) 274static unsigned int speedstep_get(unsigned int cpu)
diff --git a/drivers/cpufreq/tegra186-cpufreq.c b/drivers/cpufreq/tegra186-cpufreq.c
index fe7875311d62..1f59966573aa 100644
--- a/drivers/cpufreq/tegra186-cpufreq.c
+++ b/drivers/cpufreq/tegra186-cpufreq.c
@@ -78,7 +78,8 @@ static int tegra186_cpufreq_init(struct cpufreq_policy *policy)
78 78
79 policy->driver_data = 79 policy->driver_data =
80 data->regs + info->offset + EDVD_CORE_VOLT_FREQ(core); 80 data->regs + info->offset + EDVD_CORE_VOLT_FREQ(core);
81 cpufreq_table_validate_and_show(policy, cluster->table); 81 policy->freq_table = cluster->table;
82 break;
82 } 83 }
83 84
84 policy->cpuinfo.transition_latency = 300 * 1000; 85 policy->cpuinfo.transition_latency = 300 * 1000;
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 21e8d248d956..1fe49724da9e 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -962,6 +962,7 @@ extern struct freq_attr cpufreq_freq_attr_scaling_boost_freqs;
962extern struct freq_attr *cpufreq_generic_attr[]; 962extern struct freq_attr *cpufreq_generic_attr[];
963int cpufreq_table_validate_and_show(struct cpufreq_policy *policy, 963int cpufreq_table_validate_and_show(struct cpufreq_policy *policy,
964 struct cpufreq_frequency_table *table); 964 struct cpufreq_frequency_table *table);
965int cpufreq_table_validate_and_sort(struct cpufreq_policy *policy);
965 966
966unsigned int cpufreq_generic_get(unsigned int cpu); 967unsigned int cpufreq_generic_get(unsigned int cpu);
967int cpufreq_generic_init(struct cpufreq_policy *policy, 968int cpufreq_generic_init(struct cpufreq_policy *policy,