aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-06-03 17:13:20 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-06-03 17:13:20 -0400
commit057beb1de54d33ecfd3397ed219b1f4518e3b470 (patch)
tree7c67e9d8c88093a3d551111e56401826a964ffba
parent42a09284fab8abc15c8554f2e2aa2368161c77c6 (diff)
parent5ece2399181a5abaf42a4cb607463770686778e6 (diff)
Merge branch 'pm-cpufreq'
* pm-cpufreq: (28 commits) cpufreq: handle calls to ->target_index() in separate routine cpufreq: s5pv210: drop check for CONFIG_PM_VERBOSE cpufreq: intel_pstate: Remove unused member name of cpudata cpufreq: Break out early when frequency equals target_freq cpufreq: Tegra: drop wrapper around tegra_update_cpu_speed() cpufreq: imx6q: Remove unused include cpufreq: imx6q: Drop devm_clk/regulator_get usage cpufreq: powernow-k8: Suppress checkpatch warnings cpufreq: powernv: make local function static cpufreq: Enable big.LITTLE cpufreq driver on arm64 cpufreq: nforce2: remove DEFINE_PCI_DEVICE_TABLE macro intel_pstate: Add CPU IDs for Broadwell processors cpufreq: Fix build error on some platforms that use cpufreq_for_each_* PM / OPP: Move cpufreq specific OPP functions out of generic OPP library PM / OPP: Remove cpufreq wrapper dependency on internal data organization cpufreq: Catch double invocations of cpufreq_freq_transition_begin/end intel_pstate: Remove sample parameter in intel_pstate_calc_busy cpufreq: Kconfig: Fix spelling errors cpufreq: Make linux-pm@vger.kernel.org official mailing list cpufreq: exynos: Use dev_err/info function instead of pr_err/info ...
-rw-r--r--Documentation/ABI/testing/sysfs-devices-system-cpu4
-rw-r--r--Documentation/cpu-freq/core.txt29
-rw-r--r--Documentation/cpu-freq/cpu-drivers.txt19
-rw-r--r--Documentation/cpu-freq/index.txt4
-rw-r--r--Documentation/power/opp.txt40
-rw-r--r--MAINTAINERS2
-rw-r--r--arch/arm/mach-davinci/da850.c9
-rw-r--r--arch/mips/loongson/lemote-2f/clock.c17
-rw-r--r--drivers/base/power/opp.c91
-rw-r--r--drivers/cpufreq/Kconfig.arm7
-rw-r--r--drivers/cpufreq/Kconfig.x864
-rw-r--r--drivers/cpufreq/Makefile2
-rw-r--r--drivers/cpufreq/acpi-cpufreq.c9
-rw-r--r--drivers/cpufreq/arm_big_little.c16
-rw-r--r--drivers/cpufreq/cpufreq-nforce2.c2
-rw-r--r--drivers/cpufreq/cpufreq.c70
-rw-r--r--drivers/cpufreq/cpufreq_opp.c110
-rw-r--r--drivers/cpufreq/cpufreq_stats.c24
-rw-r--r--drivers/cpufreq/dbx500-cpufreq.c8
-rw-r--r--drivers/cpufreq/elanfreq.c9
-rw-r--r--drivers/cpufreq/exynos-cpufreq.c32
-rw-r--r--drivers/cpufreq/exynos-cpufreq.h1
-rw-r--r--drivers/cpufreq/exynos5440-cpufreq.c30
-rw-r--r--drivers/cpufreq/freq_table.c64
-rw-r--r--drivers/cpufreq/imx6q-cpufreq.c54
-rw-r--r--drivers/cpufreq/intel_pstate.c15
-rw-r--r--drivers/cpufreq/longhaul.c11
-rw-r--r--drivers/cpufreq/pasemi-cpufreq.c10
-rw-r--r--drivers/cpufreq/powernow-k6.c14
-rw-r--r--drivers/cpufreq/powernow-k8.c180
-rw-r--r--drivers/cpufreq/powernow-k8.h2
-rw-r--r--drivers/cpufreq/powernv-cpufreq.c2
-rw-r--r--drivers/cpufreq/ppc_cbe_cpufreq.c9
-rw-r--r--drivers/cpufreq/s3c2416-cpufreq.c40
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c15
-rw-r--r--drivers/cpufreq/s5pv210-cpufreq.c6
-rw-r--r--drivers/cpufreq/speedstep-centrino.c2
-rw-r--r--drivers/cpufreq/tegra-cpufreq.c9
-rw-r--r--drivers/mfd/db8500-prcmu.c19
-rw-r--r--drivers/net/irda/sh_sir.c14
-rw-r--r--drivers/sh/clk/core.c20
-rw-r--r--drivers/thermal/cpu_cooling.c33
-rw-r--r--include/linux/cpufreq.h50
-rw-r--r--include/linux/pm_opp.h20
-rw-r--r--tools/power/cpupower/Makefile2
-rw-r--r--tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c2
46 files changed, 576 insertions, 556 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index d5a0d33c571f..acb9bfc89b48 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -128,7 +128,7 @@ Description: Discover cpuidle policy and mechanism
128 128
129What: /sys/devices/system/cpu/cpu#/cpufreq/* 129What: /sys/devices/system/cpu/cpu#/cpufreq/*
130Date: pre-git history 130Date: pre-git history
131Contact: cpufreq@vger.kernel.org 131Contact: linux-pm@vger.kernel.org
132Description: Discover and change clock speed of CPUs 132Description: Discover and change clock speed of CPUs
133 133
134 Clock scaling allows you to change the clock speed of the 134 Clock scaling allows you to change the clock speed of the
@@ -146,7 +146,7 @@ Description: Discover and change clock speed of CPUs
146 146
147What: /sys/devices/system/cpu/cpu#/cpufreq/freqdomain_cpus 147What: /sys/devices/system/cpu/cpu#/cpufreq/freqdomain_cpus
148Date: June 2013 148Date: June 2013
149Contact: cpufreq@vger.kernel.org 149Contact: linux-pm@vger.kernel.org
150Description: Discover CPUs in the same CPU frequency coordination domain 150Description: Discover CPUs in the same CPU frequency coordination domain
151 151
152 freqdomain_cpus is the list of CPUs (online+offline) that share 152 freqdomain_cpus is the list of CPUs (online+offline) that share
diff --git a/Documentation/cpu-freq/core.txt b/Documentation/cpu-freq/core.txt
index 0060d76b445f..70933eadc308 100644
--- a/Documentation/cpu-freq/core.txt
+++ b/Documentation/cpu-freq/core.txt
@@ -20,6 +20,7 @@ Contents:
20--------- 20---------
211. CPUFreq core and interfaces 211. CPUFreq core and interfaces
222. CPUFreq notifiers 222. CPUFreq notifiers
233. CPUFreq Table Generation with Operating Performance Point (OPP)
23 24
241. General Information 251. General Information
25======================= 26=======================
@@ -92,3 +93,31 @@ values:
92cpu - number of the affected CPU 93cpu - number of the affected CPU
93old - old frequency 94old - old frequency
94new - new frequency 95new - new frequency
96
973. CPUFreq Table Generation with Operating Performance Point (OPP)
98==================================================================
99For details about OPP, see Documentation/power/opp.txt
100
101dev_pm_opp_init_cpufreq_table - cpufreq framework typically is initialized with
102 cpufreq_frequency_table_cpuinfo which is provided with the list of
103 frequencies that are available for operation. This function provides
104 a ready to use conversion routine to translate the OPP layer's internal
105 information about the available frequencies into a format readily
106 providable to cpufreq.
107
108 WARNING: Do not use this function in interrupt context.
109
110 Example:
111 soc_pm_init()
112 {
113 /* Do things */
114 r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
115 if (!r)
116 cpufreq_frequency_table_cpuinfo(policy, freq_table);
117 /* Do other things */
118 }
119
120 NOTE: This function is available only if CONFIG_CPU_FREQ is enabled in
121 addition to CONFIG_PM_OPP.
122
123dev_pm_opp_free_cpufreq_table - Free up the table allocated by dev_pm_opp_init_cpufreq_table
diff --git a/Documentation/cpu-freq/cpu-drivers.txt b/Documentation/cpu-freq/cpu-drivers.txt
index 48da5fdcb9f1..b045fe54986a 100644
--- a/Documentation/cpu-freq/cpu-drivers.txt
+++ b/Documentation/cpu-freq/cpu-drivers.txt
@@ -228,3 +228,22 @@ is the corresponding frequency table helper for the ->target
228stage. Just pass the values to this function, and the unsigned int 228stage. Just pass the values to this function, and the unsigned int
229index returns the number of the frequency table entry which contains 229index returns the number of the frequency table entry which contains
230the frequency the CPU shall be set to. 230the frequency the CPU shall be set to.
231
232The following macros can be used as iterators over cpufreq_frequency_table:
233
234cpufreq_for_each_entry(pos, table) - iterates over all entries of frequency
235table.
236
237cpufreq-for_each_valid_entry(pos, table) - iterates over all entries,
238excluding CPUFREQ_ENTRY_INVALID frequencies.
239Use arguments "pos" - a cpufreq_frequency_table * as a loop cursor and
240"table" - the cpufreq_frequency_table * you want to iterate over.
241
242For example:
243
244 struct cpufreq_frequency_table *pos, *driver_freq_table;
245
246 cpufreq_for_each_entry(pos, driver_freq_table) {
247 /* Do something with pos */
248 pos->frequency = ...
249 }
diff --git a/Documentation/cpu-freq/index.txt b/Documentation/cpu-freq/index.txt
index 3d0b915035b9..dc024ab4054f 100644
--- a/Documentation/cpu-freq/index.txt
+++ b/Documentation/cpu-freq/index.txt
@@ -35,8 +35,8 @@ Mailing List
35------------ 35------------
36There is a CPU frequency changing CVS commit and general list where 36There is a CPU frequency changing CVS commit and general list where
37you can report bugs, problems or submit patches. To post a message, 37you can report bugs, problems or submit patches. To post a message,
38send an email to cpufreq@vger.kernel.org, to subscribe go to 38send an email to linux-pm@vger.kernel.org, to subscribe go to
39http://vger.kernel.org/vger-lists.html#cpufreq and follow the 39http://vger.kernel.org/vger-lists.html#linux-pm and follow the
40instructions there. 40instructions there.
41 41
42Links 42Links
diff --git a/Documentation/power/opp.txt b/Documentation/power/opp.txt
index b8a907dc0169..a9adad828cdc 100644
--- a/Documentation/power/opp.txt
+++ b/Documentation/power/opp.txt
@@ -10,8 +10,7 @@ Contents
103. OPP Search Functions 103. OPP Search Functions
114. OPP Availability Control Functions 114. OPP Availability Control Functions
125. OPP Data Retrieval Functions 125. OPP Data Retrieval Functions
136. Cpufreq Table Generation 136. Data Structures
147. Data Structures
15 14
161. Introduction 151. Introduction
17=============== 16===============
@@ -72,7 +71,6 @@ operations until that OPP could be re-enabled if possible.
72OPP library facilitates this concept in it's implementation. The following 71OPP library facilitates this concept in it's implementation. The following
73operational functions operate only on available opps: 72operational functions operate only on available opps:
74opp_find_freq_{ceil, floor}, dev_pm_opp_get_voltage, dev_pm_opp_get_freq, dev_pm_opp_get_opp_count 73opp_find_freq_{ceil, floor}, dev_pm_opp_get_voltage, dev_pm_opp_get_freq, dev_pm_opp_get_opp_count
75and dev_pm_opp_init_cpufreq_table
76 74
77dev_pm_opp_find_freq_exact is meant to be used to find the opp pointer which can then 75dev_pm_opp_find_freq_exact is meant to be used to find the opp pointer which can then
78be used for dev_pm_opp_enable/disable functions to make an opp available as required. 76be used for dev_pm_opp_enable/disable functions to make an opp available as required.
@@ -96,10 +94,9 @@ using RCU read locks. The opp_find_freq_{exact,ceil,floor},
96opp_get_{voltage, freq, opp_count} fall into this category. 94opp_get_{voltage, freq, opp_count} fall into this category.
97 95
98opp_{add,enable,disable} are updaters which use mutex and implement it's own 96opp_{add,enable,disable} are updaters which use mutex and implement it's own
99RCU locking mechanisms. dev_pm_opp_init_cpufreq_table acts as an updater and uses 97RCU locking mechanisms. These functions should *NOT* be called under RCU locks
100mutex to implment RCU updater strategy. These functions should *NOT* be called 98and other contexts that prevent blocking functions in RCU or mutex operations
101under RCU locks and other contexts that prevent blocking functions in RCU or 99from working.
102mutex operations from working.
103 100
1042. Initial OPP List Registration 1012. Initial OPP List Registration
105================================ 102================================
@@ -311,34 +308,7 @@ dev_pm_opp_get_opp_count - Retrieve the number of available opps for a device
311 /* Do other things */ 308 /* Do other things */
312 } 309 }
313 310
3146. Cpufreq Table Generation 3116. Data Structures
315===========================
316dev_pm_opp_init_cpufreq_table - cpufreq framework typically is initialized with
317 cpufreq_frequency_table_cpuinfo which is provided with the list of
318 frequencies that are available for operation. This function provides
319 a ready to use conversion routine to translate the OPP layer's internal
320 information about the available frequencies into a format readily
321 providable to cpufreq.
322
323 WARNING: Do not use this function in interrupt context.
324
325 Example:
326 soc_pm_init()
327 {
328 /* Do things */
329 r = dev_pm_opp_init_cpufreq_table(dev, &freq_table);
330 if (!r)
331 cpufreq_frequency_table_cpuinfo(policy, freq_table);
332 /* Do other things */
333 }
334
335 NOTE: This function is available only if CONFIG_CPU_FREQ is enabled in
336 addition to CONFIG_PM as power management feature is required to
337 dynamically scale voltage and frequency in a system.
338
339dev_pm_opp_free_cpufreq_table - Free up the table allocated by dev_pm_opp_init_cpufreq_table
340
3417. Data Structures
342================== 312==================
343Typically an SoC contains multiple voltage domains which are variable. Each 313Typically an SoC contains multiple voltage domains which are variable. Each
344domain is represented by a device pointer. The relationship to OPP can be 314domain is represented by a device pointer. The relationship to OPP can be
diff --git a/MAINTAINERS b/MAINTAINERS
index 4ba0253dd593..16c12107c15f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2410,7 +2410,6 @@ F: drivers/net/ethernet/ti/cpmac.c
2410CPU FREQUENCY DRIVERS 2410CPU FREQUENCY DRIVERS
2411M: Rafael J. Wysocki <rjw@rjwysocki.net> 2411M: Rafael J. Wysocki <rjw@rjwysocki.net>
2412M: Viresh Kumar <viresh.kumar@linaro.org> 2412M: Viresh Kumar <viresh.kumar@linaro.org>
2413L: cpufreq@vger.kernel.org
2414L: linux-pm@vger.kernel.org 2413L: linux-pm@vger.kernel.org
2415S: Maintained 2414S: Maintained
2416T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git 2415T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
@@ -2421,7 +2420,6 @@ F: include/linux/cpufreq.h
2421CPU FREQUENCY DRIVERS - ARM BIG LITTLE 2420CPU FREQUENCY DRIVERS - ARM BIG LITTLE
2422M: Viresh Kumar <viresh.kumar@linaro.org> 2421M: Viresh Kumar <viresh.kumar@linaro.org>
2423M: Sudeep Holla <sudeep.holla@arm.com> 2422M: Sudeep Holla <sudeep.holla@arm.com>
2424L: cpufreq@vger.kernel.org
2425L: linux-pm@vger.kernel.org 2423L: linux-pm@vger.kernel.org
2426W: http://www.arm.com/products/processors/technologies/biglittleprocessing.php 2424W: http://www.arm.com/products/processors/technologies/biglittleprocessing.php
2427S: Maintained 2425S: Maintained
diff --git a/arch/arm/mach-davinci/da850.c b/arch/arm/mach-davinci/da850.c
index 85399c98f84a..45ce065e7170 100644
--- a/arch/arm/mach-davinci/da850.c
+++ b/arch/arm/mach-davinci/da850.c
@@ -1092,20 +1092,21 @@ int da850_register_cpufreq(char *async_clk)
1092 1092
1093static int da850_round_armrate(struct clk *clk, unsigned long rate) 1093static int da850_round_armrate(struct clk *clk, unsigned long rate)
1094{ 1094{
1095 int i, ret = 0, diff; 1095 int ret = 0, diff;
1096 unsigned int best = (unsigned int) -1; 1096 unsigned int best = (unsigned int) -1;
1097 struct cpufreq_frequency_table *table = cpufreq_info.freq_table; 1097 struct cpufreq_frequency_table *table = cpufreq_info.freq_table;
1098 struct cpufreq_frequency_table *pos;
1098 1099
1099 rate /= 1000; /* convert to kHz */ 1100 rate /= 1000; /* convert to kHz */
1100 1101
1101 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 1102 cpufreq_for_each_entry(pos, table) {
1102 diff = table[i].frequency - rate; 1103 diff = pos->frequency - rate;
1103 if (diff < 0) 1104 if (diff < 0)
1104 diff = -diff; 1105 diff = -diff;
1105 1106
1106 if (diff < best) { 1107 if (diff < best) {
1107 best = diff; 1108 best = diff;
1108 ret = table[i].frequency; 1109 ret = pos->frequency;
1109 } 1110 }
1110 } 1111 }
1111 1112
diff --git a/arch/mips/loongson/lemote-2f/clock.c b/arch/mips/loongson/lemote-2f/clock.c
index 67dd94ef28e6..1eed38e28b1e 100644
--- a/arch/mips/loongson/lemote-2f/clock.c
+++ b/arch/mips/loongson/lemote-2f/clock.c
@@ -91,10 +91,9 @@ EXPORT_SYMBOL(clk_put);
91 91
92int clk_set_rate(struct clk *clk, unsigned long rate) 92int clk_set_rate(struct clk *clk, unsigned long rate)
93{ 93{
94 unsigned int rate_khz = rate / 1000; 94 struct cpufreq_frequency_table *pos;
95 int ret = 0; 95 int ret = 0;
96 int regval; 96 int regval;
97 int i;
98 97
99 if (likely(clk->ops && clk->ops->set_rate)) { 98 if (likely(clk->ops && clk->ops->set_rate)) {
100 unsigned long flags; 99 unsigned long flags;
@@ -107,22 +106,16 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
107 if (unlikely(clk->flags & CLK_RATE_PROPAGATES)) 106 if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
108 propagate_rate(clk); 107 propagate_rate(clk);
109 108
110 for (i = 0; loongson2_clockmod_table[i].frequency != CPUFREQ_TABLE_END; 109 cpufreq_for_each_valid_entry(pos, loongson2_clockmod_table)
111 i++) { 110 if (rate == pos->frequency)
112 if (loongson2_clockmod_table[i].frequency ==
113 CPUFREQ_ENTRY_INVALID)
114 continue;
115 if (rate_khz == loongson2_clockmod_table[i].frequency)
116 break; 111 break;
117 } 112 if (rate != pos->frequency)
118 if (rate_khz != loongson2_clockmod_table[i].frequency)
119 return -ENOTSUPP; 113 return -ENOTSUPP;
120 114
121 clk->rate = rate; 115 clk->rate = rate;
122 116
123 regval = LOONGSON_CHIPCFG0; 117 regval = LOONGSON_CHIPCFG0;
124 regval = (regval & ~0x7) | 118 regval = (regval & ~0x7) | (pos->driver_data - 1);
125 (loongson2_clockmod_table[i].driver_data - 1);
126 LOONGSON_CHIPCFG0 = regval; 119 LOONGSON_CHIPCFG0 = regval;
127 120
128 return ret; 121 return ret;
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 39412c15db70..89ced955fafa 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -15,7 +15,6 @@
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/cpufreq.h>
19#include <linux/device.h> 18#include <linux/device.h>
20#include <linux/list.h> 19#include <linux/list.h>
21#include <linux/rculist.h> 20#include <linux/rculist.h>
@@ -619,96 +618,6 @@ int dev_pm_opp_disable(struct device *dev, unsigned long freq)
619} 618}
620EXPORT_SYMBOL_GPL(dev_pm_opp_disable); 619EXPORT_SYMBOL_GPL(dev_pm_opp_disable);
621 620
622#ifdef CONFIG_CPU_FREQ
623/**
624 * dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device
625 * @dev: device for which we do this operation
626 * @table: Cpufreq table returned back to caller
627 *
628 * Generate a cpufreq table for a provided device- this assumes that the
629 * opp list is already initialized and ready for usage.
630 *
631 * This function allocates required memory for the cpufreq table. It is
632 * expected that the caller does the required maintenance such as freeing
633 * the table as required.
634 *
635 * Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM
636 * if no memory available for the operation (table is not populated), returns 0
637 * if successful and table is populated.
638 *
639 * WARNING: It is important for the callers to ensure refreshing their copy of
640 * the table if any of the mentioned functions have been invoked in the interim.
641 *
642 * Locking: The internal device_opp and opp structures are RCU protected.
643 * To simplify the logic, we pretend we are updater and hold relevant mutex here
644 * Callers should ensure that this function is *NOT* called under RCU protection
645 * or in contexts where mutex locking cannot be used.
646 */
647int dev_pm_opp_init_cpufreq_table(struct device *dev,
648 struct cpufreq_frequency_table **table)
649{
650 struct device_opp *dev_opp;
651 struct dev_pm_opp *opp;
652 struct cpufreq_frequency_table *freq_table;
653 int i = 0;
654
655 /* Pretend as if I am an updater */
656 mutex_lock(&dev_opp_list_lock);
657
658 dev_opp = find_device_opp(dev);
659 if (IS_ERR(dev_opp)) {
660 int r = PTR_ERR(dev_opp);
661 mutex_unlock(&dev_opp_list_lock);
662 dev_err(dev, "%s: Device OPP not found (%d)\n", __func__, r);
663 return r;
664 }
665
666 freq_table = kzalloc(sizeof(struct cpufreq_frequency_table) *
667 (dev_pm_opp_get_opp_count(dev) + 1), GFP_KERNEL);
668 if (!freq_table) {
669 mutex_unlock(&dev_opp_list_lock);
670 dev_warn(dev, "%s: Unable to allocate frequency table\n",
671 __func__);
672 return -ENOMEM;
673 }
674
675 list_for_each_entry(opp, &dev_opp->opp_list, node) {
676 if (opp->available) {
677 freq_table[i].driver_data = i;
678 freq_table[i].frequency = opp->rate / 1000;
679 i++;
680 }
681 }
682 mutex_unlock(&dev_opp_list_lock);
683
684 freq_table[i].driver_data = i;
685 freq_table[i].frequency = CPUFREQ_TABLE_END;
686
687 *table = &freq_table[0];
688
689 return 0;
690}
691EXPORT_SYMBOL_GPL(dev_pm_opp_init_cpufreq_table);
692
693/**
694 * dev_pm_opp_free_cpufreq_table() - free the cpufreq table
695 * @dev: device for which we do this operation
696 * @table: table to free
697 *
698 * Free up the table allocated by dev_pm_opp_init_cpufreq_table
699 */
700void dev_pm_opp_free_cpufreq_table(struct device *dev,
701 struct cpufreq_frequency_table **table)
702{
703 if (!table)
704 return;
705
706 kfree(*table);
707 *table = NULL;
708}
709EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);
710#endif /* CONFIG_CPU_FREQ */
711
712/** 621/**
713 * dev_pm_opp_get_notifier() - find notifier_head of the device with opp 622 * dev_pm_opp_get_notifier() - find notifier_head of the device with opp
714 * @dev: device pointer used to lookup device OPPs. 623 * @dev: device pointer used to lookup device OPPs.
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 580503513f0f..6a7dd3e958d5 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -5,7 +5,8 @@
5# big LITTLE core layer and glue drivers 5# big LITTLE core layer and glue drivers
6config ARM_BIG_LITTLE_CPUFREQ 6config ARM_BIG_LITTLE_CPUFREQ
7 tristate "Generic ARM big LITTLE CPUfreq driver" 7 tristate "Generic ARM big LITTLE CPUfreq driver"
8 depends on ARM && BIG_LITTLE && ARM_CPU_TOPOLOGY && HAVE_CLK 8 depends on (BIG_LITTLE && ARM_CPU_TOPOLOGY) || (ARM64 && SMP)
9 depends on HAVE_CLK
9 select PM_OPP 10 select PM_OPP
10 help 11 help
11 This enables the Generic CPUfreq driver for ARM big.LITTLE platforms. 12 This enables the Generic CPUfreq driver for ARM big.LITTLE platforms.
@@ -85,7 +86,7 @@ config ARM_EXYNOS_CPU_FREQ_BOOST_SW
85 It allows usage of special frequencies for Samsung Exynos 86 It allows usage of special frequencies for Samsung Exynos
86 processors if thermal conditions are appropriate. 87 processors if thermal conditions are appropriate.
87 88
88 It reguires, for safe operation, thermal framework with properly 89 It requires, for safe operation, thermal framework with properly
89 defined trip points. 90 defined trip points.
90 91
91 If in doubt, say N. 92 If in doubt, say N.
@@ -186,7 +187,7 @@ config ARM_S3C2416_CPUFREQ
186 S3C2450 SoC. The S3C2416 supports changing the rate of the 187 S3C2450 SoC. The S3C2416 supports changing the rate of the
187 armdiv clock source and also entering a so called dynamic 188 armdiv clock source and also entering a so called dynamic
188 voltage scaling mode in which it is possible to reduce the 189 voltage scaling mode in which it is possible to reduce the
189 core voltage of the cpu. 190 core voltage of the CPU.
190 191
191 If in doubt, say N. 192 If in doubt, say N.
192 193
diff --git a/drivers/cpufreq/Kconfig.x86 b/drivers/cpufreq/Kconfig.x86
index d369349eeaab..89ae88f91895 100644
--- a/drivers/cpufreq/Kconfig.x86
+++ b/drivers/cpufreq/Kconfig.x86
@@ -10,7 +10,7 @@ config X86_INTEL_PSTATE
10 The driver implements an internal governor and will become 10 The driver implements an internal governor and will become
11 the scaling driver and governor for Sandy bridge processors. 11 the scaling driver and governor for Sandy bridge processors.
12 12
13 When this driver is enabled it will become the perferred 13 When this driver is enabled it will become the preferred
14 scaling driver for Sandy bridge processors. 14 scaling driver for Sandy bridge processors.
15 15
16 If in doubt, say N. 16 If in doubt, say N.
@@ -52,7 +52,7 @@ config X86_ACPI_CPUFREQ_CPB
52 help 52 help
53 The powernow-k8 driver used to provide a sysfs knob called "cpb" 53 The powernow-k8 driver used to provide a sysfs knob called "cpb"
54 to disable the Core Performance Boosting feature of AMD CPUs. This 54 to disable the Core Performance Boosting feature of AMD CPUs. This
55 file has now been superseeded by the more generic "boost" entry. 55 file has now been superseded by the more generic "boost" entry.
56 56
57 By enabling this option the acpi_cpufreq driver provides the old 57 By enabling this option the acpi_cpufreq driver provides the old
58 entry in addition to the new boost ones, for compatibility reasons. 58 entry in addition to the new boost ones, for compatibility reasons.
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 0dbb963c1aef..738c8b7b17dc 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -1,5 +1,7 @@
1# CPUfreq core 1# CPUfreq core
2obj-$(CONFIG_CPU_FREQ) += cpufreq.o freq_table.o 2obj-$(CONFIG_CPU_FREQ) += cpufreq.o freq_table.o
3obj-$(CONFIG_PM_OPP) += cpufreq_opp.o
4
3# CPUfreq stats 5# CPUfreq stats
4obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o 6obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o
5 7
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
index 000e4e0afd7e..b0c18ed8d83f 100644
--- a/drivers/cpufreq/acpi-cpufreq.c
+++ b/drivers/cpufreq/acpi-cpufreq.c
@@ -213,7 +213,7 @@ static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data)
213 213
214static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data) 214static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
215{ 215{
216 int i; 216 struct cpufreq_frequency_table *pos;
217 struct acpi_processor_performance *perf; 217 struct acpi_processor_performance *perf;
218 218
219 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) 219 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
@@ -223,10 +223,9 @@ static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
223 223
224 perf = data->acpi_data; 224 perf = data->acpi_data;
225 225
226 for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { 226 cpufreq_for_each_entry(pos, data->freq_table)
227 if (msr == perf->states[data->freq_table[i].driver_data].status) 227 if (msr == perf->states[pos->driver_data].status)
228 return data->freq_table[i].frequency; 228 return pos->frequency;
229 }
230 return data->freq_table[0].frequency; 229 return data->freq_table[0].frequency;
231} 230}
232 231
diff --git a/drivers/cpufreq/arm_big_little.c b/drivers/cpufreq/arm_big_little.c
index bad2ed317ba2..1f4d4e315057 100644
--- a/drivers/cpufreq/arm_big_little.c
+++ b/drivers/cpufreq/arm_big_little.c
@@ -226,22 +226,22 @@ static inline u32 get_table_count(struct cpufreq_frequency_table *table)
226/* get the minimum frequency in the cpufreq_frequency_table */ 226/* get the minimum frequency in the cpufreq_frequency_table */
227static inline u32 get_table_min(struct cpufreq_frequency_table *table) 227static inline u32 get_table_min(struct cpufreq_frequency_table *table)
228{ 228{
229 int i; 229 struct cpufreq_frequency_table *pos;
230 uint32_t min_freq = ~0; 230 uint32_t min_freq = ~0;
231 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) 231 cpufreq_for_each_entry(pos, table)
232 if (table[i].frequency < min_freq) 232 if (pos->frequency < min_freq)
233 min_freq = table[i].frequency; 233 min_freq = pos->frequency;
234 return min_freq; 234 return min_freq;
235} 235}
236 236
237/* get the maximum frequency in the cpufreq_frequency_table */ 237/* get the maximum frequency in the cpufreq_frequency_table */
238static inline u32 get_table_max(struct cpufreq_frequency_table *table) 238static inline u32 get_table_max(struct cpufreq_frequency_table *table)
239{ 239{
240 int i; 240 struct cpufreq_frequency_table *pos;
241 uint32_t max_freq = 0; 241 uint32_t max_freq = 0;
242 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) 242 cpufreq_for_each_entry(pos, table)
243 if (table[i].frequency > max_freq) 243 if (pos->frequency > max_freq)
244 max_freq = table[i].frequency; 244 max_freq = pos->frequency;
245 return max_freq; 245 return max_freq;
246} 246}
247 247
diff --git a/drivers/cpufreq/cpufreq-nforce2.c b/drivers/cpufreq/cpufreq-nforce2.c
index bc447b9003c3..a2258090b58b 100644
--- a/drivers/cpufreq/cpufreq-nforce2.c
+++ b/drivers/cpufreq/cpufreq-nforce2.c
@@ -379,7 +379,7 @@ static struct cpufreq_driver nforce2_driver = {
379}; 379};
380 380
381#ifdef MODULE 381#ifdef MODULE
382static DEFINE_PCI_DEVICE_TABLE(nforce2_ids) = { 382static const struct pci_device_id nforce2_ids[] = {
383 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2 }, 383 { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2 },
384 {} 384 {}
385}; 385};
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index abda6609d3e7..ae11dd51f81d 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -354,6 +354,18 @@ static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,
354void cpufreq_freq_transition_begin(struct cpufreq_policy *policy, 354void cpufreq_freq_transition_begin(struct cpufreq_policy *policy,
355 struct cpufreq_freqs *freqs) 355 struct cpufreq_freqs *freqs)
356{ 356{
357
358 /*
359 * Catch double invocations of _begin() which lead to self-deadlock.
360 * ASYNC_NOTIFICATION drivers are left out because the cpufreq core
361 * doesn't invoke _begin() on their behalf, and hence the chances of
362 * double invocations are very low. Moreover, there are scenarios
363 * where these checks can emit false-positive warnings in these
364 * drivers; so we avoid that by skipping them altogether.
365 */
366 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION)
367 && current == policy->transition_task);
368
357wait: 369wait:
358 wait_event(policy->transition_wait, !policy->transition_ongoing); 370 wait_event(policy->transition_wait, !policy->transition_ongoing);
359 371
@@ -365,6 +377,7 @@ wait:
365 } 377 }
366 378
367 policy->transition_ongoing = true; 379 policy->transition_ongoing = true;
380 policy->transition_task = current;
368 381
369 spin_unlock(&policy->transition_lock); 382 spin_unlock(&policy->transition_lock);
370 383
@@ -381,6 +394,7 @@ void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
381 cpufreq_notify_post_transition(policy, freqs, transition_failed); 394 cpufreq_notify_post_transition(policy, freqs, transition_failed);
382 395
383 policy->transition_ongoing = false; 396 policy->transition_ongoing = false;
397 policy->transition_task = NULL;
384 398
385 wake_up(&policy->transition_wait); 399 wake_up(&policy->transition_wait);
386} 400}
@@ -1802,12 +1816,43 @@ EXPORT_SYMBOL(cpufreq_unregister_notifier);
1802 * GOVERNORS * 1816 * GOVERNORS *
1803 *********************************************************************/ 1817 *********************************************************************/
1804 1818
1819static int __target_index(struct cpufreq_policy *policy,
1820 struct cpufreq_frequency_table *freq_table, int index)
1821{
1822 struct cpufreq_freqs freqs;
1823 int retval = -EINVAL;
1824 bool notify;
1825
1826 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION);
1827
1828 if (notify) {
1829 freqs.old = policy->cur;
1830 freqs.new = freq_table[index].frequency;
1831 freqs.flags = 0;
1832
1833 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
1834 __func__, policy->cpu, freqs.old, freqs.new);
1835
1836 cpufreq_freq_transition_begin(policy, &freqs);
1837 }
1838
1839 retval = cpufreq_driver->target_index(policy, index);
1840 if (retval)
1841 pr_err("%s: Failed to change cpu frequency: %d\n", __func__,
1842 retval);
1843
1844 if (notify)
1845 cpufreq_freq_transition_end(policy, &freqs, retval);
1846
1847 return retval;
1848}
1849
1805int __cpufreq_driver_target(struct cpufreq_policy *policy, 1850int __cpufreq_driver_target(struct cpufreq_policy *policy,
1806 unsigned int target_freq, 1851 unsigned int target_freq,
1807 unsigned int relation) 1852 unsigned int relation)
1808{ 1853{
1809 int retval = -EINVAL;
1810 unsigned int old_target_freq = target_freq; 1854 unsigned int old_target_freq = target_freq;
1855 int retval = -EINVAL;
1811 1856
1812 if (cpufreq_disabled()) 1857 if (cpufreq_disabled())
1813 return -ENODEV; 1858 return -ENODEV;
@@ -1834,8 +1879,6 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1834 retval = cpufreq_driver->target(policy, target_freq, relation); 1879 retval = cpufreq_driver->target(policy, target_freq, relation);
1835 else if (cpufreq_driver->target_index) { 1880 else if (cpufreq_driver->target_index) {
1836 struct cpufreq_frequency_table *freq_table; 1881 struct cpufreq_frequency_table *freq_table;
1837 struct cpufreq_freqs freqs;
1838 bool notify;
1839 int index; 1882 int index;
1840 1883
1841 freq_table = cpufreq_frequency_get_table(policy->cpu); 1884 freq_table = cpufreq_frequency_get_table(policy->cpu);
@@ -1856,26 +1899,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
1856 goto out; 1899 goto out;
1857 } 1900 }
1858 1901
1859 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION); 1902 retval = __target_index(policy, freq_table, index);
1860
1861 if (notify) {
1862 freqs.old = policy->cur;
1863 freqs.new = freq_table[index].frequency;
1864 freqs.flags = 0;
1865
1866 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n",
1867 __func__, policy->cpu, freqs.old, freqs.new);
1868
1869 cpufreq_freq_transition_begin(policy, &freqs);
1870 }
1871
1872 retval = cpufreq_driver->target_index(policy, index);
1873 if (retval)
1874 pr_err("%s: Failed to change cpu frequency: %d\n",
1875 __func__, retval);
1876
1877 if (notify)
1878 cpufreq_freq_transition_end(policy, &freqs, retval);
1879 } 1903 }
1880 1904
1881out: 1905out:
diff --git a/drivers/cpufreq/cpufreq_opp.c b/drivers/cpufreq/cpufreq_opp.c
new file mode 100644
index 000000000000..c0c6f4a4eccf
--- /dev/null
+++ b/drivers/cpufreq/cpufreq_opp.c
@@ -0,0 +1,110 @@
1/*
2 * Generic OPP helper interface for CPUFreq drivers
3 *
4 * Copyright (C) 2009-2014 Texas Instruments Incorporated.
5 * Nishanth Menon
6 * Romit Dasgupta
7 * Kevin Hilman
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#include <linux/cpufreq.h>
14#include <linux/device.h>
15#include <linux/err.h>
16#include <linux/errno.h>
17#include <linux/export.h>
18#include <linux/kernel.h>
19#include <linux/pm_opp.h>
20#include <linux/rcupdate.h>
21#include <linux/slab.h>
22
23/**
24 * dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device
25 * @dev: device for which we do this operation
26 * @table: Cpufreq table returned back to caller
27 *
28 * Generate a cpufreq table for a provided device- this assumes that the
29 * opp list is already initialized and ready for usage.
30 *
31 * This function allocates required memory for the cpufreq table. It is
32 * expected that the caller does the required maintenance such as freeing
33 * the table as required.
34 *
35 * Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM
36 * if no memory available for the operation (table is not populated), returns 0
37 * if successful and table is populated.
38 *
39 * WARNING: It is important for the callers to ensure refreshing their copy of
40 * the table if any of the mentioned functions have been invoked in the interim.
41 *
42 * Locking: The internal device_opp and opp structures are RCU protected.
43 * Since we just use the regular accessor functions to access the internal data
44 * structures, we use RCU read lock inside this function. As a result, users of
45 * this function DONOT need to use explicit locks for invoking.
46 */
47int dev_pm_opp_init_cpufreq_table(struct device *dev,
48 struct cpufreq_frequency_table **table)
49{
50 struct dev_pm_opp *opp;
51 struct cpufreq_frequency_table *freq_table = NULL;
52 int i, max_opps, ret = 0;
53 unsigned long rate;
54
55 rcu_read_lock();
56
57 max_opps = dev_pm_opp_get_opp_count(dev);
58 if (max_opps <= 0) {
59 ret = max_opps ? max_opps : -ENODATA;
60 goto out;
61 }
62
63 freq_table = kzalloc(sizeof(*freq_table) * (max_opps + 1), GFP_KERNEL);
64 if (!freq_table) {
65 ret = -ENOMEM;
66 goto out;
67 }
68
69 for (i = 0, rate = 0; i < max_opps; i++, rate++) {
70 /* find next rate */
71 opp = dev_pm_opp_find_freq_ceil(dev, &rate);
72 if (IS_ERR(opp)) {
73 ret = PTR_ERR(opp);
74 goto out;
75 }
76 freq_table[i].driver_data = i;
77 freq_table[i].frequency = rate / 1000;
78 }
79
80 freq_table[i].driver_data = i;
81 freq_table[i].frequency = CPUFREQ_TABLE_END;
82
83 *table = &freq_table[0];
84
85out:
86 rcu_read_unlock();
87 if (ret)
88 kfree(freq_table);
89
90 return ret;
91}
92EXPORT_SYMBOL_GPL(dev_pm_opp_init_cpufreq_table);
93
94/**
95 * dev_pm_opp_free_cpufreq_table() - free the cpufreq table
96 * @dev: device for which we do this operation
97 * @table: table to free
98 *
99 * Free up the table allocated by dev_pm_opp_init_cpufreq_table
100 */
101void dev_pm_opp_free_cpufreq_table(struct device *dev,
102 struct cpufreq_frequency_table **table)
103{
104 if (!table)
105 return;
106
107 kfree(*table);
108 *table = NULL;
109}
110EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index ecaaebf969fc..0cd9b4dcef99 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -182,11 +182,11 @@ static void cpufreq_stats_free_table(unsigned int cpu)
182 182
183static int __cpufreq_stats_create_table(struct cpufreq_policy *policy) 183static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
184{ 184{
185 unsigned int i, j, count = 0, ret = 0; 185 unsigned int i, count = 0, ret = 0;
186 struct cpufreq_stats *stat; 186 struct cpufreq_stats *stat;
187 unsigned int alloc_size; 187 unsigned int alloc_size;
188 unsigned int cpu = policy->cpu; 188 unsigned int cpu = policy->cpu;
189 struct cpufreq_frequency_table *table; 189 struct cpufreq_frequency_table *pos, *table;
190 190
191 table = cpufreq_frequency_get_table(cpu); 191 table = cpufreq_frequency_get_table(cpu);
192 if (unlikely(!table)) 192 if (unlikely(!table))
@@ -205,12 +205,8 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
205 stat->cpu = cpu; 205 stat->cpu = cpu;
206 per_cpu(cpufreq_stats_table, cpu) = stat; 206 per_cpu(cpufreq_stats_table, cpu) = stat;
207 207
208 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 208 cpufreq_for_each_valid_entry(pos, table)
209 unsigned int freq = table[i].frequency;
210 if (freq == CPUFREQ_ENTRY_INVALID)
211 continue;
212 count++; 209 count++;
213 }
214 210
215 alloc_size = count * sizeof(int) + count * sizeof(u64); 211 alloc_size = count * sizeof(int) + count * sizeof(u64);
216 212
@@ -228,15 +224,11 @@ static int __cpufreq_stats_create_table(struct cpufreq_policy *policy)
228#ifdef CONFIG_CPU_FREQ_STAT_DETAILS 224#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
229 stat->trans_table = stat->freq_table + count; 225 stat->trans_table = stat->freq_table + count;
230#endif 226#endif
231 j = 0; 227 i = 0;
232 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 228 cpufreq_for_each_valid_entry(pos, table)
233 unsigned int freq = table[i].frequency; 229 if (freq_table_get_index(stat, pos->frequency) == -1)
234 if (freq == CPUFREQ_ENTRY_INVALID) 230 stat->freq_table[i++] = pos->frequency;
235 continue; 231 stat->state_num = i;
236 if (freq_table_get_index(stat, freq) == -1)
237 stat->freq_table[j++] = freq;
238 }
239 stat->state_num = j;
240 spin_lock(&cpufreq_stats_lock); 232 spin_lock(&cpufreq_stats_lock);
241 stat->last_time = get_jiffies_64(); 233 stat->last_time = get_jiffies_64();
242 stat->last_index = freq_table_get_index(stat, policy->cur); 234 stat->last_index = freq_table_get_index(stat, policy->cur);
diff --git a/drivers/cpufreq/dbx500-cpufreq.c b/drivers/cpufreq/dbx500-cpufreq.c
index 412a78bb0c94..4bebc1b5db48 100644
--- a/drivers/cpufreq/dbx500-cpufreq.c
+++ b/drivers/cpufreq/dbx500-cpufreq.c
@@ -45,7 +45,7 @@ static struct cpufreq_driver dbx500_cpufreq_driver = {
45 45
46static int dbx500_cpufreq_probe(struct platform_device *pdev) 46static int dbx500_cpufreq_probe(struct platform_device *pdev)
47{ 47{
48 int i = 0; 48 struct cpufreq_frequency_table *pos;
49 49
50 freq_table = dev_get_platdata(&pdev->dev); 50 freq_table = dev_get_platdata(&pdev->dev);
51 if (!freq_table) { 51 if (!freq_table) {
@@ -60,10 +60,8 @@ static int dbx500_cpufreq_probe(struct platform_device *pdev)
60 } 60 }
61 61
62 pr_info("dbx500-cpufreq: Available frequencies:\n"); 62 pr_info("dbx500-cpufreq: Available frequencies:\n");
63 while (freq_table[i].frequency != CPUFREQ_TABLE_END) { 63 cpufreq_for_each_entry(pos, freq_table)
64 pr_info(" %d Mhz\n", freq_table[i].frequency/1000); 64 pr_info(" %d Mhz\n", pos->frequency / 1000);
65 i++;
66 }
67 65
68 return cpufreq_register_driver(&dbx500_cpufreq_driver); 66 return cpufreq_register_driver(&dbx500_cpufreq_driver);
69} 67}
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c
index 7f5d2a68c353..1c06e786c9ba 100644
--- a/drivers/cpufreq/elanfreq.c
+++ b/drivers/cpufreq/elanfreq.c
@@ -147,7 +147,7 @@ static int elanfreq_target(struct cpufreq_policy *policy,
147static int elanfreq_cpu_init(struct cpufreq_policy *policy) 147static int elanfreq_cpu_init(struct cpufreq_policy *policy)
148{ 148{
149 struct cpuinfo_x86 *c = &cpu_data(0); 149 struct cpuinfo_x86 *c = &cpu_data(0);
150 unsigned int i; 150 struct cpufreq_frequency_table *pos;
151 151
152 /* capability check */ 152 /* capability check */
153 if ((c->x86_vendor != X86_VENDOR_AMD) || 153 if ((c->x86_vendor != X86_VENDOR_AMD) ||
@@ -159,10 +159,9 @@ static int elanfreq_cpu_init(struct cpufreq_policy *policy)
159 max_freq = elanfreq_get_cpu_frequency(0); 159 max_freq = elanfreq_get_cpu_frequency(0);
160 160
161 /* table init */ 161 /* table init */
162 for (i = 0; (elanfreq_table[i].frequency != CPUFREQ_TABLE_END); i++) { 162 cpufreq_for_each_entry(pos, elanfreq_table)
163 if (elanfreq_table[i].frequency > max_freq) 163 if (pos->frequency > max_freq)
164 elanfreq_table[i].frequency = CPUFREQ_ENTRY_INVALID; 164 pos->frequency = CPUFREQ_ENTRY_INVALID;
165 }
166 165
167 /* cpuinfo and default policy values */ 166 /* cpuinfo and default policy values */
168 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; 167 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index f99cfe24e7bc..c3e55aa28cf8 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -29,17 +29,16 @@ static unsigned int locking_frequency;
29static int exynos_cpufreq_get_index(unsigned int freq) 29static int exynos_cpufreq_get_index(unsigned int freq)
30{ 30{
31 struct cpufreq_frequency_table *freq_table = exynos_info->freq_table; 31 struct cpufreq_frequency_table *freq_table = exynos_info->freq_table;
32 int index; 32 struct cpufreq_frequency_table *pos;
33 33
34 for (index = 0; 34 cpufreq_for_each_entry(pos, freq_table)
35 freq_table[index].frequency != CPUFREQ_TABLE_END; index++) 35 if (pos->frequency == freq)
36 if (freq_table[index].frequency == freq)
37 break; 36 break;
38 37
39 if (freq_table[index].frequency == CPUFREQ_TABLE_END) 38 if (pos->frequency == CPUFREQ_TABLE_END)
40 return -EINVAL; 39 return -EINVAL;
41 40
42 return index; 41 return pos - freq_table;
43} 42}
44 43
45static int exynos_cpufreq_scale(unsigned int target_freq) 44static int exynos_cpufreq_scale(unsigned int target_freq)
@@ -49,6 +48,7 @@ static int exynos_cpufreq_scale(unsigned int target_freq)
49 struct cpufreq_policy *policy = cpufreq_cpu_get(0); 48 struct cpufreq_policy *policy = cpufreq_cpu_get(0);
50 unsigned int arm_volt, safe_arm_volt = 0; 49 unsigned int arm_volt, safe_arm_volt = 0;
51 unsigned int mpll_freq_khz = exynos_info->mpll_freq_khz; 50 unsigned int mpll_freq_khz = exynos_info->mpll_freq_khz;
51 struct device *dev = exynos_info->dev;
52 unsigned int old_freq; 52 unsigned int old_freq;
53 int index, old_index; 53 int index, old_index;
54 int ret = 0; 54 int ret = 0;
@@ -90,8 +90,8 @@ static int exynos_cpufreq_scale(unsigned int target_freq)
90 /* Firstly, voltage up to increase frequency */ 90 /* Firstly, voltage up to increase frequency */
91 ret = regulator_set_voltage(arm_regulator, arm_volt, arm_volt); 91 ret = regulator_set_voltage(arm_regulator, arm_volt, arm_volt);
92 if (ret) { 92 if (ret) {
93 pr_err("%s: failed to set cpu voltage to %d\n", 93 dev_err(dev, "failed to set cpu voltage to %d\n",
94 __func__, arm_volt); 94 arm_volt);
95 return ret; 95 return ret;
96 } 96 }
97 } 97 }
@@ -100,8 +100,8 @@ static int exynos_cpufreq_scale(unsigned int target_freq)
100 ret = regulator_set_voltage(arm_regulator, safe_arm_volt, 100 ret = regulator_set_voltage(arm_regulator, safe_arm_volt,
101 safe_arm_volt); 101 safe_arm_volt);
102 if (ret) { 102 if (ret) {
103 pr_err("%s: failed to set cpu voltage to %d\n", 103 dev_err(dev, "failed to set cpu voltage to %d\n",
104 __func__, safe_arm_volt); 104 safe_arm_volt);
105 return ret; 105 return ret;
106 } 106 }
107 } 107 }
@@ -115,8 +115,8 @@ static int exynos_cpufreq_scale(unsigned int target_freq)
115 ret = regulator_set_voltage(arm_regulator, arm_volt, 115 ret = regulator_set_voltage(arm_regulator, arm_volt,
116 arm_volt); 116 arm_volt);
117 if (ret) { 117 if (ret) {
118 pr_err("%s: failed to set cpu voltage to %d\n", 118 dev_err(dev, "failed to set cpu voltage to %d\n",
119 __func__, arm_volt); 119 arm_volt);
120 goto out; 120 goto out;
121 } 121 }
122 } 122 }
@@ -163,6 +163,8 @@ static int exynos_cpufreq_probe(struct platform_device *pdev)
163 if (!exynos_info) 163 if (!exynos_info)
164 return -ENOMEM; 164 return -ENOMEM;
165 165
166 exynos_info->dev = &pdev->dev;
167
166 if (soc_is_exynos4210()) 168 if (soc_is_exynos4210())
167 ret = exynos4210_cpufreq_init(exynos_info); 169 ret = exynos4210_cpufreq_init(exynos_info);
168 else if (soc_is_exynos4212() || soc_is_exynos4412()) 170 else if (soc_is_exynos4212() || soc_is_exynos4412())
@@ -176,13 +178,13 @@ static int exynos_cpufreq_probe(struct platform_device *pdev)
176 goto err_vdd_arm; 178 goto err_vdd_arm;
177 179
178 if (exynos_info->set_freq == NULL) { 180 if (exynos_info->set_freq == NULL) {
179 pr_err("%s: No set_freq function (ERR)\n", __func__); 181 dev_err(&pdev->dev, "No set_freq function (ERR)\n");
180 goto err_vdd_arm; 182 goto err_vdd_arm;
181 } 183 }
182 184
183 arm_regulator = regulator_get(NULL, "vdd_arm"); 185 arm_regulator = regulator_get(NULL, "vdd_arm");
184 if (IS_ERR(arm_regulator)) { 186 if (IS_ERR(arm_regulator)) {
185 pr_err("%s: failed to get resource vdd_arm\n", __func__); 187 dev_err(&pdev->dev, "failed to get resource vdd_arm\n");
186 goto err_vdd_arm; 188 goto err_vdd_arm;
187 } 189 }
188 190
@@ -192,7 +194,7 @@ static int exynos_cpufreq_probe(struct platform_device *pdev)
192 if (!cpufreq_register_driver(&exynos_driver)) 194 if (!cpufreq_register_driver(&exynos_driver))
193 return 0; 195 return 0;
194 196
195 pr_err("%s: failed to register cpufreq driver\n", __func__); 197 dev_err(&pdev->dev, "failed to register cpufreq driver\n");
196 regulator_put(arm_regulator); 198 regulator_put(arm_regulator);
197err_vdd_arm: 199err_vdd_arm:
198 kfree(exynos_info); 200 kfree(exynos_info);
diff --git a/drivers/cpufreq/exynos-cpufreq.h b/drivers/cpufreq/exynos-cpufreq.h
index 3ddade8a5125..b72ff10a040e 100644
--- a/drivers/cpufreq/exynos-cpufreq.h
+++ b/drivers/cpufreq/exynos-cpufreq.h
@@ -34,6 +34,7 @@ struct apll_freq {
34}; 34};
35 35
36struct exynos_dvfs_info { 36struct exynos_dvfs_info {
37 struct device *dev;
37 unsigned long mpll_freq_khz; 38 unsigned long mpll_freq_khz;
38 unsigned int pll_safe_idx; 39 unsigned int pll_safe_idx;
39 struct clk *cpu_clk; 40 struct clk *cpu_clk;
diff --git a/drivers/cpufreq/exynos5440-cpufreq.c b/drivers/cpufreq/exynos5440-cpufreq.c
index a6b8214d7b77..f33f25b483ca 100644
--- a/drivers/cpufreq/exynos5440-cpufreq.c
+++ b/drivers/cpufreq/exynos5440-cpufreq.c
@@ -114,25 +114,23 @@ static struct cpufreq_freqs freqs;
114 114
115static int init_div_table(void) 115static int init_div_table(void)
116{ 116{
117 struct cpufreq_frequency_table *freq_tbl = dvfs_info->freq_table; 117 struct cpufreq_frequency_table *pos, *freq_tbl = dvfs_info->freq_table;
118 unsigned int tmp, clk_div, ema_div, freq, volt_id; 118 unsigned int tmp, clk_div, ema_div, freq, volt_id;
119 int i = 0;
120 struct dev_pm_opp *opp; 119 struct dev_pm_opp *opp;
121 120
122 rcu_read_lock(); 121 rcu_read_lock();
123 for (i = 0; freq_tbl[i].frequency != CPUFREQ_TABLE_END; i++) { 122 cpufreq_for_each_entry(pos, freq_tbl) {
124
125 opp = dev_pm_opp_find_freq_exact(dvfs_info->dev, 123 opp = dev_pm_opp_find_freq_exact(dvfs_info->dev,
126 freq_tbl[i].frequency * 1000, true); 124 pos->frequency * 1000, true);
127 if (IS_ERR(opp)) { 125 if (IS_ERR(opp)) {
128 rcu_read_unlock(); 126 rcu_read_unlock();
129 dev_err(dvfs_info->dev, 127 dev_err(dvfs_info->dev,
130 "failed to find valid OPP for %u KHZ\n", 128 "failed to find valid OPP for %u KHZ\n",
131 freq_tbl[i].frequency); 129 pos->frequency);
132 return PTR_ERR(opp); 130 return PTR_ERR(opp);
133 } 131 }
134 132
135 freq = freq_tbl[i].frequency / 1000; /* In MHZ */ 133 freq = pos->frequency / 1000; /* In MHZ */
136 clk_div = ((freq / CPU_DIV_FREQ_MAX) & P0_7_CPUCLKDEV_MASK) 134 clk_div = ((freq / CPU_DIV_FREQ_MAX) & P0_7_CPUCLKDEV_MASK)
137 << P0_7_CPUCLKDEV_SHIFT; 135 << P0_7_CPUCLKDEV_SHIFT;
138 clk_div |= ((freq / CPU_ATB_FREQ_MAX) & P0_7_ATBCLKDEV_MASK) 136 clk_div |= ((freq / CPU_ATB_FREQ_MAX) & P0_7_ATBCLKDEV_MASK)
@@ -157,7 +155,8 @@ static int init_div_table(void)
157 tmp = (clk_div | ema_div | (volt_id << P0_7_VDD_SHIFT) 155 tmp = (clk_div | ema_div | (volt_id << P0_7_VDD_SHIFT)
158 | ((freq / FREQ_UNIT) << P0_7_FREQ_SHIFT)); 156 | ((freq / FREQ_UNIT) << P0_7_FREQ_SHIFT));
159 157
160 __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 * i); 158 __raw_writel(tmp, dvfs_info->base + XMU_PMU_P0_7 + 4 *
159 (pos - freq_tbl));
161 } 160 }
162 161
163 rcu_read_unlock(); 162 rcu_read_unlock();
@@ -166,8 +165,9 @@ static int init_div_table(void)
166 165
167static void exynos_enable_dvfs(unsigned int cur_frequency) 166static void exynos_enable_dvfs(unsigned int cur_frequency)
168{ 167{
169 unsigned int tmp, i, cpu; 168 unsigned int tmp, cpu;
170 struct cpufreq_frequency_table *freq_table = dvfs_info->freq_table; 169 struct cpufreq_frequency_table *freq_table = dvfs_info->freq_table;
170 struct cpufreq_frequency_table *pos;
171 /* Disable DVFS */ 171 /* Disable DVFS */
172 __raw_writel(0, dvfs_info->base + XMU_DVFS_CTRL); 172 __raw_writel(0, dvfs_info->base + XMU_DVFS_CTRL);
173 173
@@ -182,15 +182,15 @@ static void exynos_enable_dvfs(unsigned int cur_frequency)
182 __raw_writel(tmp, dvfs_info->base + XMU_PMUIRQEN); 182 __raw_writel(tmp, dvfs_info->base + XMU_PMUIRQEN);
183 183
184 /* Set initial performance index */ 184 /* Set initial performance index */
185 for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) 185 cpufreq_for_each_entry(pos, freq_table)
186 if (freq_table[i].frequency == cur_frequency) 186 if (pos->frequency == cur_frequency)
187 break; 187 break;
188 188
189 if (freq_table[i].frequency == CPUFREQ_TABLE_END) { 189 if (pos->frequency == CPUFREQ_TABLE_END) {
190 dev_crit(dvfs_info->dev, "Boot up frequency not supported\n"); 190 dev_crit(dvfs_info->dev, "Boot up frequency not supported\n");
191 /* Assign the highest frequency */ 191 /* Assign the highest frequency */
192 i = 0; 192 pos = freq_table;
193 cur_frequency = freq_table[i].frequency; 193 cur_frequency = pos->frequency;
194 } 194 }
195 195
196 dev_info(dvfs_info->dev, "Setting dvfs initial frequency = %uKHZ", 196 dev_info(dvfs_info->dev, "Setting dvfs initial frequency = %uKHZ",
@@ -199,7 +199,7 @@ static void exynos_enable_dvfs(unsigned int cur_frequency)
199 for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++) { 199 for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++) {
200 tmp = __raw_readl(dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4); 200 tmp = __raw_readl(dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4);
201 tmp &= ~(P_VALUE_MASK << C0_3_PSTATE_NEW_SHIFT); 201 tmp &= ~(P_VALUE_MASK << C0_3_PSTATE_NEW_SHIFT);
202 tmp |= (i << C0_3_PSTATE_NEW_SHIFT); 202 tmp |= ((pos - freq_table) << C0_3_PSTATE_NEW_SHIFT);
203 __raw_writel(tmp, dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4); 203 __raw_writel(tmp, dvfs_info->base + XMU_C0_3_PSTATE + cpu * 4);
204 } 204 }
205 205
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 08e7bbcf6d73..1632981c4b25 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -21,22 +21,19 @@
21int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, 21int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
22 struct cpufreq_frequency_table *table) 22 struct cpufreq_frequency_table *table)
23{ 23{
24 struct cpufreq_frequency_table *pos;
24 unsigned int min_freq = ~0; 25 unsigned int min_freq = ~0;
25 unsigned int max_freq = 0; 26 unsigned int max_freq = 0;
26 unsigned int i; 27 unsigned int freq;
27 28
28 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 29 cpufreq_for_each_valid_entry(pos, table) {
29 unsigned int freq = table[i].frequency; 30 freq = pos->frequency;
30 if (freq == CPUFREQ_ENTRY_INVALID) {
31 pr_debug("table entry %u is invalid, skipping\n", i);
32 31
33 continue;
34 }
35 if (!cpufreq_boost_enabled() 32 if (!cpufreq_boost_enabled()
36 && (table[i].flags & CPUFREQ_BOOST_FREQ)) 33 && (pos->flags & CPUFREQ_BOOST_FREQ))
37 continue; 34 continue;
38 35
39 pr_debug("table entry %u: %u kHz\n", i, freq); 36 pr_debug("table entry %u: %u kHz\n", (int)(pos - table), freq);
40 if (freq < min_freq) 37 if (freq < min_freq)
41 min_freq = freq; 38 min_freq = freq;
42 if (freq > max_freq) 39 if (freq > max_freq)
@@ -57,7 +54,8 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_cpuinfo);
57int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, 54int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
58 struct cpufreq_frequency_table *table) 55 struct cpufreq_frequency_table *table)
59{ 56{
60 unsigned int next_larger = ~0, freq, i = 0; 57 struct cpufreq_frequency_table *pos;
58 unsigned int freq, next_larger = ~0;
61 bool found = false; 59 bool found = false;
62 60
63 pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n", 61 pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",
@@ -65,9 +63,9 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
65 63
66 cpufreq_verify_within_cpu_limits(policy); 64 cpufreq_verify_within_cpu_limits(policy);
67 65
68 for (; freq = table[i].frequency, freq != CPUFREQ_TABLE_END; i++) { 66 cpufreq_for_each_valid_entry(pos, table) {
69 if (freq == CPUFREQ_ENTRY_INVALID) 67 freq = pos->frequency;
70 continue; 68
71 if ((freq >= policy->min) && (freq <= policy->max)) { 69 if ((freq >= policy->min) && (freq <= policy->max)) {
72 found = true; 70 found = true;
73 break; 71 break;
@@ -118,7 +116,8 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
118 .driver_data = ~0, 116 .driver_data = ~0,
119 .frequency = 0, 117 .frequency = 0,
120 }; 118 };
121 unsigned int i; 119 struct cpufreq_frequency_table *pos;
120 unsigned int freq, i = 0;
122 121
123 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", 122 pr_debug("request for target %u kHz (relation: %u) for cpu %u\n",
124 target_freq, relation, policy->cpu); 123 target_freq, relation, policy->cpu);
@@ -132,15 +131,19 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
132 break; 131 break;
133 } 132 }
134 133
135 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 134 cpufreq_for_each_valid_entry(pos, table) {
136 unsigned int freq = table[i].frequency; 135 freq = pos->frequency;
137 if (freq == CPUFREQ_ENTRY_INVALID) 136
138 continue; 137 i = pos - table;
139 if ((freq < policy->min) || (freq > policy->max)) 138 if ((freq < policy->min) || (freq > policy->max))
140 continue; 139 continue;
140 if (freq == target_freq) {
141 optimal.driver_data = i;
142 break;
143 }
141 switch (relation) { 144 switch (relation) {
142 case CPUFREQ_RELATION_H: 145 case CPUFREQ_RELATION_H:
143 if (freq <= target_freq) { 146 if (freq < target_freq) {
144 if (freq >= optimal.frequency) { 147 if (freq >= optimal.frequency) {
145 optimal.frequency = freq; 148 optimal.frequency = freq;
146 optimal.driver_data = i; 149 optimal.driver_data = i;
@@ -153,7 +156,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
153 } 156 }
154 break; 157 break;
155 case CPUFREQ_RELATION_L: 158 case CPUFREQ_RELATION_L:
156 if (freq >= target_freq) { 159 if (freq > target_freq) {
157 if (freq <= optimal.frequency) { 160 if (freq <= optimal.frequency) {
158 optimal.frequency = freq; 161 optimal.frequency = freq;
159 optimal.driver_data = i; 162 optimal.driver_data = i;
@@ -184,8 +187,7 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
184int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy, 187int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
185 unsigned int freq) 188 unsigned int freq)
186{ 189{
187 struct cpufreq_frequency_table *table; 190 struct cpufreq_frequency_table *pos, *table;
188 int i;
189 191
190 table = cpufreq_frequency_get_table(policy->cpu); 192 table = cpufreq_frequency_get_table(policy->cpu);
191 if (unlikely(!table)) { 193 if (unlikely(!table)) {
@@ -193,10 +195,9 @@ int cpufreq_frequency_table_get_index(struct cpufreq_policy *policy,
193 return -ENOENT; 195 return -ENOENT;
194 } 196 }
195 197
196 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 198 cpufreq_for_each_valid_entry(pos, table)
197 if (table[i].frequency == freq) 199 if (pos->frequency == freq)
198 return i; 200 return pos - table;
199 }
200 201
201 return -EINVAL; 202 return -EINVAL;
202} 203}
@@ -208,16 +209,13 @@ EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_index);
208static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf, 209static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf,
209 bool show_boost) 210 bool show_boost)
210{ 211{
211 unsigned int i = 0;
212 ssize_t count = 0; 212 ssize_t count = 0;
213 struct cpufreq_frequency_table *table = policy->freq_table; 213 struct cpufreq_frequency_table *pos, *table = policy->freq_table;
214 214
215 if (!table) 215 if (!table)
216 return -ENODEV; 216 return -ENODEV;
217 217
218 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 218 cpufreq_for_each_valid_entry(pos, table) {
219 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
220 continue;
221 /* 219 /*
222 * show_boost = true and driver_data = BOOST freq 220 * show_boost = true and driver_data = BOOST freq
223 * display BOOST freqs 221 * display BOOST freqs
@@ -229,10 +227,10 @@ static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf,
229 * show_boost = false and driver_data != BOOST freq 227 * show_boost = false and driver_data != BOOST freq
230 * display NON BOOST freqs 228 * display NON BOOST freqs
231 */ 229 */
232 if (show_boost ^ (table[i].flags & CPUFREQ_BOOST_FREQ)) 230 if (show_boost ^ (pos->flags & CPUFREQ_BOOST_FREQ))
233 continue; 231 continue;
234 232
235 count += sprintf(&buf[count], "%d ", table[i].frequency); 233 count += sprintf(&buf[count], "%d ", pos->frequency);
236 } 234 }
237 count += sprintf(&buf[count], "\n"); 235 count += sprintf(&buf[count], "\n");
238 236
diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index e27fca86fe4f..af366c21d4b4 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -9,7 +9,6 @@
9#include <linux/clk.h> 9#include <linux/clk.h>
10#include <linux/cpu.h> 10#include <linux/cpu.h>
11#include <linux/cpufreq.h> 11#include <linux/cpufreq.h>
12#include <linux/delay.h>
13#include <linux/err.h> 12#include <linux/err.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/of.h> 14#include <linux/of.h>
@@ -170,25 +169,25 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
170 return -ENOENT; 169 return -ENOENT;
171 } 170 }
172 171
173 arm_clk = devm_clk_get(cpu_dev, "arm"); 172 arm_clk = clk_get(cpu_dev, "arm");
174 pll1_sys_clk = devm_clk_get(cpu_dev, "pll1_sys"); 173 pll1_sys_clk = clk_get(cpu_dev, "pll1_sys");
175 pll1_sw_clk = devm_clk_get(cpu_dev, "pll1_sw"); 174 pll1_sw_clk = clk_get(cpu_dev, "pll1_sw");
176 step_clk = devm_clk_get(cpu_dev, "step"); 175 step_clk = clk_get(cpu_dev, "step");
177 pll2_pfd2_396m_clk = devm_clk_get(cpu_dev, "pll2_pfd2_396m"); 176 pll2_pfd2_396m_clk = clk_get(cpu_dev, "pll2_pfd2_396m");
178 if (IS_ERR(arm_clk) || IS_ERR(pll1_sys_clk) || IS_ERR(pll1_sw_clk) || 177 if (IS_ERR(arm_clk) || IS_ERR(pll1_sys_clk) || IS_ERR(pll1_sw_clk) ||
179 IS_ERR(step_clk) || IS_ERR(pll2_pfd2_396m_clk)) { 178 IS_ERR(step_clk) || IS_ERR(pll2_pfd2_396m_clk)) {
180 dev_err(cpu_dev, "failed to get clocks\n"); 179 dev_err(cpu_dev, "failed to get clocks\n");
181 ret = -ENOENT; 180 ret = -ENOENT;
182 goto put_node; 181 goto put_clk;
183 } 182 }
184 183
185 arm_reg = devm_regulator_get(cpu_dev, "arm"); 184 arm_reg = regulator_get(cpu_dev, "arm");
186 pu_reg = devm_regulator_get(cpu_dev, "pu"); 185 pu_reg = regulator_get(cpu_dev, "pu");
187 soc_reg = devm_regulator_get(cpu_dev, "soc"); 186 soc_reg = regulator_get(cpu_dev, "soc");
188 if (IS_ERR(arm_reg) || IS_ERR(pu_reg) || IS_ERR(soc_reg)) { 187 if (IS_ERR(arm_reg) || IS_ERR(pu_reg) || IS_ERR(soc_reg)) {
189 dev_err(cpu_dev, "failed to get regulators\n"); 188 dev_err(cpu_dev, "failed to get regulators\n");
190 ret = -ENOENT; 189 ret = -ENOENT;
191 goto put_node; 190 goto put_reg;
192 } 191 }
193 192
194 /* 193 /*
@@ -201,21 +200,21 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
201 ret = of_init_opp_table(cpu_dev); 200 ret = of_init_opp_table(cpu_dev);
202 if (ret < 0) { 201 if (ret < 0) {
203 dev_err(cpu_dev, "failed to init OPP table: %d\n", ret); 202 dev_err(cpu_dev, "failed to init OPP table: %d\n", ret);
204 goto put_node; 203 goto put_reg;
205 } 204 }
206 205
207 num = dev_pm_opp_get_opp_count(cpu_dev); 206 num = dev_pm_opp_get_opp_count(cpu_dev);
208 if (num < 0) { 207 if (num < 0) {
209 ret = num; 208 ret = num;
210 dev_err(cpu_dev, "no OPP table is found: %d\n", ret); 209 dev_err(cpu_dev, "no OPP table is found: %d\n", ret);
211 goto put_node; 210 goto put_reg;
212 } 211 }
213 } 212 }
214 213
215 ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table); 214 ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &freq_table);
216 if (ret) { 215 if (ret) {
217 dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret); 216 dev_err(cpu_dev, "failed to init cpufreq table: %d\n", ret);
218 goto put_node; 217 goto put_reg;
219 } 218 }
220 219
221 /* Make imx6_soc_volt array's size same as arm opp number */ 220 /* Make imx6_soc_volt array's size same as arm opp number */
@@ -301,7 +300,24 @@ soc_opp_out:
301 300
302free_freq_table: 301free_freq_table:
303 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table); 302 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
304put_node: 303put_reg:
304 if (!IS_ERR(arm_reg))
305 regulator_put(arm_reg);
306 if (!IS_ERR(pu_reg))
307 regulator_put(pu_reg);
308 if (!IS_ERR(soc_reg))
309 regulator_put(soc_reg);
310put_clk:
311 if (!IS_ERR(arm_clk))
312 clk_put(arm_clk);
313 if (!IS_ERR(pll1_sys_clk))
314 clk_put(pll1_sys_clk);
315 if (!IS_ERR(pll1_sw_clk))
316 clk_put(pll1_sw_clk);
317 if (!IS_ERR(step_clk))
318 clk_put(step_clk);
319 if (!IS_ERR(pll2_pfd2_396m_clk))
320 clk_put(pll2_pfd2_396m_clk);
305 of_node_put(np); 321 of_node_put(np);
306 return ret; 322 return ret;
307} 323}
@@ -310,6 +326,14 @@ static int imx6q_cpufreq_remove(struct platform_device *pdev)
310{ 326{
311 cpufreq_unregister_driver(&imx6q_cpufreq_driver); 327 cpufreq_unregister_driver(&imx6q_cpufreq_driver);
312 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table); 328 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
329 regulator_put(arm_reg);
330 regulator_put(pu_reg);
331 regulator_put(soc_reg);
332 clk_put(arm_clk);
333 clk_put(pll1_sys_clk);
334 clk_put(pll1_sw_clk);
335 clk_put(step_clk);
336 clk_put(pll2_pfd2_396m_clk);
313 337
314 return 0; 338 return 0;
315} 339}
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index db2e45b4808e..aebd4572eb6d 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -32,8 +32,6 @@
32#include <asm/msr.h> 32#include <asm/msr.h>
33#include <asm/cpu_device_id.h> 33#include <asm/cpu_device_id.h>
34 34
35#define SAMPLE_COUNT 3
36
37#define BYT_RATIOS 0x66a 35#define BYT_RATIOS 0x66a
38#define BYT_VIDS 0x66b 36#define BYT_VIDS 0x66b
39#define BYT_TURBO_RATIOS 0x66c 37#define BYT_TURBO_RATIOS 0x66c
@@ -90,8 +88,6 @@ struct _pid {
90struct cpudata { 88struct cpudata {
91 int cpu; 89 int cpu;
92 90
93 char name[64];
94
95 struct timer_list timer; 91 struct timer_list timer;
96 92
97 struct pstate_data pstate; 93 struct pstate_data pstate;
@@ -549,8 +545,6 @@ static inline void intel_pstate_pstate_decrease(struct cpudata *cpu, int steps)
549 545
550static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) 546static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
551{ 547{
552 sprintf(cpu->name, "Intel 2nd generation core");
553
554 cpu->pstate.min_pstate = pstate_funcs.get_min(); 548 cpu->pstate.min_pstate = pstate_funcs.get_min();
555 cpu->pstate.max_pstate = pstate_funcs.get_max(); 549 cpu->pstate.max_pstate = pstate_funcs.get_max();
556 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo(); 550 cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
@@ -560,9 +554,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
560 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate); 554 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
561} 555}
562 556
563static inline void intel_pstate_calc_busy(struct cpudata *cpu, 557static inline void intel_pstate_calc_busy(struct cpudata *cpu)
564 struct sample *sample)
565{ 558{
559 struct sample *sample = &cpu->sample;
566 int64_t core_pct; 560 int64_t core_pct;
567 int32_t rem; 561 int32_t rem;
568 562
@@ -595,7 +589,7 @@ static inline void intel_pstate_sample(struct cpudata *cpu)
595 cpu->sample.aperf -= cpu->prev_aperf; 589 cpu->sample.aperf -= cpu->prev_aperf;
596 cpu->sample.mperf -= cpu->prev_mperf; 590 cpu->sample.mperf -= cpu->prev_mperf;
597 591
598 intel_pstate_calc_busy(cpu, &cpu->sample); 592 intel_pstate_calc_busy(cpu);
599 593
600 cpu->prev_aperf = aperf; 594 cpu->prev_aperf = aperf;
601 cpu->prev_mperf = mperf; 595 cpu->prev_mperf = mperf;
@@ -684,10 +678,13 @@ static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
684 ICPU(0x37, byt_params), 678 ICPU(0x37, byt_params),
685 ICPU(0x3a, core_params), 679 ICPU(0x3a, core_params),
686 ICPU(0x3c, core_params), 680 ICPU(0x3c, core_params),
681 ICPU(0x3d, core_params),
687 ICPU(0x3e, core_params), 682 ICPU(0x3e, core_params),
688 ICPU(0x3f, core_params), 683 ICPU(0x3f, core_params),
689 ICPU(0x45, core_params), 684 ICPU(0x45, core_params),
690 ICPU(0x46, core_params), 685 ICPU(0x46, core_params),
686 ICPU(0x4f, core_params),
687 ICPU(0x56, core_params),
691 {} 688 {}
692}; 689};
693MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids); 690MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids);
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 5c4369b5d834..c913906a719e 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -530,6 +530,7 @@ static int longhaul_get_ranges(void)
530 530
531static void longhaul_setup_voltagescaling(void) 531static void longhaul_setup_voltagescaling(void)
532{ 532{
533 struct cpufreq_frequency_table *freq_pos;
533 union msr_longhaul longhaul; 534 union msr_longhaul longhaul;
534 struct mV_pos minvid, maxvid, vid; 535 struct mV_pos minvid, maxvid, vid;
535 unsigned int j, speed, pos, kHz_step, numvscales; 536 unsigned int j, speed, pos, kHz_step, numvscales;
@@ -608,18 +609,16 @@ static void longhaul_setup_voltagescaling(void)
608 /* Calculate kHz for one voltage step */ 609 /* Calculate kHz for one voltage step */
609 kHz_step = (highest_speed - min_vid_speed) / numvscales; 610 kHz_step = (highest_speed - min_vid_speed) / numvscales;
610 611
611 j = 0; 612 cpufreq_for_each_entry(freq_pos, longhaul_table) {
612 while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { 613 speed = freq_pos->frequency;
613 speed = longhaul_table[j].frequency;
614 if (speed > min_vid_speed) 614 if (speed > min_vid_speed)
615 pos = (speed - min_vid_speed) / kHz_step + minvid.pos; 615 pos = (speed - min_vid_speed) / kHz_step + minvid.pos;
616 else 616 else
617 pos = minvid.pos; 617 pos = minvid.pos;
618 longhaul_table[j].driver_data |= mV_vrm_table[pos] << 8; 618 freq_pos->driver_data |= mV_vrm_table[pos] << 8;
619 vid = vrm_mV_table[mV_vrm_table[pos]]; 619 vid = vrm_mV_table[mV_vrm_table[pos]];
620 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", 620 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",
621 speed, j, vid.mV); 621 speed, (int)(freq_pos - longhaul_table), vid.mV);
622 j++;
623 } 622 }
624 623
625 can_scale_voltage = 1; 624 can_scale_voltage = 1;
diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
index 84c84b5f0f3a..35dd4d7ffee0 100644
--- a/drivers/cpufreq/pasemi-cpufreq.c
+++ b/drivers/cpufreq/pasemi-cpufreq.c
@@ -136,9 +136,10 @@ void restore_astate(int cpu)
136 136
137static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy) 137static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
138{ 138{
139 struct cpufreq_frequency_table *pos;
139 const u32 *max_freqp; 140 const u32 *max_freqp;
140 u32 max_freq; 141 u32 max_freq;
141 int i, cur_astate; 142 int cur_astate;
142 struct resource res; 143 struct resource res;
143 struct device_node *cpu, *dn; 144 struct device_node *cpu, *dn;
144 int err = -ENODEV; 145 int err = -ENODEV;
@@ -197,10 +198,9 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
197 pr_debug("initializing frequency table\n"); 198 pr_debug("initializing frequency table\n");
198 199
199 /* initialize frequency table */ 200 /* initialize frequency table */
200 for (i=0; pas_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { 201 cpufreq_for_each_entry(pos, pas_freqs) {
201 pas_freqs[i].frequency = 202 pos->frequency = get_astate_freq(pos->driver_data) * 100000;
202 get_astate_freq(pas_freqs[i].driver_data) * 100000; 203 pr_debug("%d: %d\n", (int)(pos - pas_freqs), pos->frequency);
203 pr_debug("%d: %d\n", i, pas_freqs[i].frequency);
204 } 204 }
205 205
206 cur_astate = get_cur_astate(policy->cpu); 206 cur_astate = get_cur_astate(policy->cpu);
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c
index 78904e6ca4a0..c8012bc86910 100644
--- a/drivers/cpufreq/powernow-k6.c
+++ b/drivers/cpufreq/powernow-k6.c
@@ -151,6 +151,7 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
151 151
152static int powernow_k6_cpu_init(struct cpufreq_policy *policy) 152static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
153{ 153{
154 struct cpufreq_frequency_table *pos;
154 unsigned int i, f; 155 unsigned int i, f;
155 unsigned khz; 156 unsigned khz;
156 157
@@ -168,12 +169,11 @@ static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
168 } 169 }
169 } 170 }
170 if (param_max_multiplier) { 171 if (param_max_multiplier) {
171 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 172 cpufreq_for_each_entry(pos, clock_ratio)
172 if (clock_ratio[i].driver_data == param_max_multiplier) { 173 if (pos->driver_data == param_max_multiplier) {
173 max_multiplier = param_max_multiplier; 174 max_multiplier = param_max_multiplier;
174 goto have_max_multiplier; 175 goto have_max_multiplier;
175 } 176 }
176 }
177 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n"); 177 printk(KERN_ERR "powernow-k6: invalid max_multiplier parameter, valid parameters 20, 30, 35, 40, 45, 50, 55, 60\n");
178 return -EINVAL; 178 return -EINVAL;
179 } 179 }
@@ -201,12 +201,12 @@ have_busfreq:
201 param_busfreq = busfreq * 10; 201 param_busfreq = busfreq * 10;
202 202
203 /* table init */ 203 /* table init */
204 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 204 cpufreq_for_each_entry(pos, clock_ratio) {
205 f = clock_ratio[i].driver_data; 205 f = pos->driver_data;
206 if (f > max_multiplier) 206 if (f > max_multiplier)
207 clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; 207 pos->frequency = CPUFREQ_ENTRY_INVALID;
208 else 208 else
209 clock_ratio[i].frequency = busfreq * f; 209 pos->frequency = busfreq * f;
210 } 210 }
211 211
212 /* cpuinfo and default policy values */ 212 /* cpuinfo and default policy values */
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
index 1b6ae6b57c11..f9ce7e4bf0fe 100644
--- a/drivers/cpufreq/powernow-k8.c
+++ b/drivers/cpufreq/powernow-k8.c
@@ -27,6 +27,8 @@
27 * power and thermal data sheets, (e.g. 30417.pdf, 30430.pdf, 43375.pdf) 27 * power and thermal data sheets, (e.g. 30417.pdf, 30430.pdf, 43375.pdf)
28 */ 28 */
29 29
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
30#include <linux/kernel.h> 32#include <linux/kernel.h>
31#include <linux/smp.h> 33#include <linux/smp.h>
32#include <linux/module.h> 34#include <linux/module.h>
@@ -45,7 +47,6 @@
45#include <linux/mutex.h> 47#include <linux/mutex.h>
46#include <acpi/processor.h> 48#include <acpi/processor.h>
47 49
48#define PFX "powernow-k8: "
49#define VERSION "version 2.20.00" 50#define VERSION "version 2.20.00"
50#include "powernow-k8.h" 51#include "powernow-k8.h"
51 52
@@ -161,7 +162,7 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
161 u32 i = 0; 162 u32 i = 0;
162 163
163 if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) { 164 if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) {
164 printk(KERN_ERR PFX "internal error - overflow on fid write\n"); 165 pr_err("internal error - overflow on fid write\n");
165 return 1; 166 return 1;
166 } 167 }
167 168
@@ -175,9 +176,7 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
175 do { 176 do {
176 wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); 177 wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
177 if (i++ > 100) { 178 if (i++ > 100) {
178 printk(KERN_ERR PFX 179 pr_err("Hardware error - pending bit very stuck - no further pstate changes possible\n");
179 "Hardware error - pending bit very stuck - "
180 "no further pstate changes possible\n");
181 return 1; 180 return 1;
182 } 181 }
183 } while (query_current_values_with_pending_wait(data)); 182 } while (query_current_values_with_pending_wait(data));
@@ -185,15 +184,13 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
185 count_off_irt(data); 184 count_off_irt(data);
186 185
187 if (savevid != data->currvid) { 186 if (savevid != data->currvid) {
188 printk(KERN_ERR PFX 187 pr_err("vid change on fid trans, old 0x%x, new 0x%x\n",
189 "vid change on fid trans, old 0x%x, new 0x%x\n", 188 savevid, data->currvid);
190 savevid, data->currvid);
191 return 1; 189 return 1;
192 } 190 }
193 191
194 if (fid != data->currfid) { 192 if (fid != data->currfid) {
195 printk(KERN_ERR PFX 193 pr_err("fid trans failed, fid 0x%x, curr 0x%x\n", fid,
196 "fid trans failed, fid 0x%x, curr 0x%x\n", fid,
197 data->currfid); 194 data->currfid);
198 return 1; 195 return 1;
199 } 196 }
@@ -209,7 +206,7 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
209 int i = 0; 206 int i = 0;
210 207
211 if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) { 208 if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) {
212 printk(KERN_ERR PFX "internal error - overflow on vid write\n"); 209 pr_err("internal error - overflow on vid write\n");
213 return 1; 210 return 1;
214 } 211 }
215 212
@@ -223,23 +220,19 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
223 do { 220 do {
224 wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS); 221 wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
225 if (i++ > 100) { 222 if (i++ > 100) {
226 printk(KERN_ERR PFX "internal error - pending bit " 223 pr_err("internal error - pending bit very stuck - no further pstate changes possible\n");
227 "very stuck - no further pstate "
228 "changes possible\n");
229 return 1; 224 return 1;
230 } 225 }
231 } while (query_current_values_with_pending_wait(data)); 226 } while (query_current_values_with_pending_wait(data));
232 227
233 if (savefid != data->currfid) { 228 if (savefid != data->currfid) {
234 printk(KERN_ERR PFX "fid changed on vid trans, old " 229 pr_err("fid changed on vid trans, old 0x%x new 0x%x\n",
235 "0x%x new 0x%x\n", 230 savefid, data->currfid);
236 savefid, data->currfid);
237 return 1; 231 return 1;
238 } 232 }
239 233
240 if (vid != data->currvid) { 234 if (vid != data->currvid) {
241 printk(KERN_ERR PFX "vid trans failed, vid 0x%x, " 235 pr_err("vid trans failed, vid 0x%x, curr 0x%x\n",
242 "curr 0x%x\n",
243 vid, data->currvid); 236 vid, data->currvid);
244 return 1; 237 return 1;
245 } 238 }
@@ -283,8 +276,7 @@ static int transition_fid_vid(struct powernow_k8_data *data,
283 return 1; 276 return 1;
284 277
285 if ((reqfid != data->currfid) || (reqvid != data->currvid)) { 278 if ((reqfid != data->currfid) || (reqvid != data->currvid)) {
286 printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, " 279 pr_err("failed (cpu%d): req 0x%x 0x%x, curr 0x%x 0x%x\n",
287 "curr 0x%x 0x%x\n",
288 smp_processor_id(), 280 smp_processor_id(),
289 reqfid, reqvid, data->currfid, data->currvid); 281 reqfid, reqvid, data->currfid, data->currvid);
290 return 1; 282 return 1;
@@ -304,8 +296,7 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data,
304 u32 savefid = data->currfid; 296 u32 savefid = data->currfid;
305 u32 maxvid, lo, rvomult = 1; 297 u32 maxvid, lo, rvomult = 1;
306 298
307 pr_debug("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, " 299 pr_debug("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, reqvid 0x%x, rvo 0x%x\n",
308 "reqvid 0x%x, rvo 0x%x\n",
309 smp_processor_id(), 300 smp_processor_id(),
310 data->currfid, data->currvid, reqvid, data->rvo); 301 data->currfid, data->currvid, reqvid, data->rvo);
311 302
@@ -342,8 +333,7 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data,
342 return 1; 333 return 1;
343 334
344 if (savefid != data->currfid) { 335 if (savefid != data->currfid) {
345 printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n", 336 pr_err("ph1 err, currfid changed 0x%x\n", data->currfid);
346 data->currfid);
347 return 1; 337 return 1;
348 } 338 }
349 339
@@ -360,13 +350,11 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
360 u32 fid_interval, savevid = data->currvid; 350 u32 fid_interval, savevid = data->currvid;
361 351
362 if (data->currfid == reqfid) { 352 if (data->currfid == reqfid) {
363 printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", 353 pr_err("ph2 null fid transition 0x%x\n", data->currfid);
364 data->currfid);
365 return 0; 354 return 0;
366 } 355 }
367 356
368 pr_debug("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, " 357 pr_debug("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, reqfid 0x%x\n",
369 "reqfid 0x%x\n",
370 smp_processor_id(), 358 smp_processor_id(),
371 data->currfid, data->currvid, reqfid); 359 data->currfid, data->currvid, reqfid);
372 360
@@ -409,15 +397,13 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
409 return 1; 397 return 1;
410 398
411 if (data->currfid != reqfid) { 399 if (data->currfid != reqfid) {
412 printk(KERN_ERR PFX 400 pr_err("ph2: mismatch, failed fid transition, curr 0x%x, req 0x%x\n",
413 "ph2: mismatch, failed fid transition, "
414 "curr 0x%x, req 0x%x\n",
415 data->currfid, reqfid); 401 data->currfid, reqfid);
416 return 1; 402 return 1;
417 } 403 }
418 404
419 if (savevid != data->currvid) { 405 if (savevid != data->currvid) {
420 printk(KERN_ERR PFX "ph2: vid changed, save 0x%x, curr 0x%x\n", 406 pr_err("ph2: vid changed, save 0x%x, curr 0x%x\n",
421 savevid, data->currvid); 407 savevid, data->currvid);
422 return 1; 408 return 1;
423 } 409 }
@@ -444,17 +430,14 @@ static int core_voltage_post_transition(struct powernow_k8_data *data,
444 return 1; 430 return 1;
445 431
446 if (savefid != data->currfid) { 432 if (savefid != data->currfid) {
447 printk(KERN_ERR PFX 433 pr_err("ph3: bad fid change, save 0x%x, curr 0x%x\n",
448 "ph3: bad fid change, save 0x%x, curr 0x%x\n", 434 savefid, data->currfid);
449 savefid, data->currfid);
450 return 1; 435 return 1;
451 } 436 }
452 437
453 if (data->currvid != reqvid) { 438 if (data->currvid != reqvid) {
454 printk(KERN_ERR PFX 439 pr_err("ph3: failed vid transition\n, req 0x%x, curr 0x%x",
455 "ph3: failed vid transition\n, " 440 reqvid, data->currvid);
456 "req 0x%x, curr 0x%x",
457 reqvid, data->currvid);
458 return 1; 441 return 1;
459 } 442 }
460 } 443 }
@@ -498,23 +481,20 @@ static void check_supported_cpu(void *_rc)
498 if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { 481 if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) {
499 if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || 482 if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) ||
500 ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) { 483 ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) {
501 printk(KERN_INFO PFX 484 pr_info("Processor cpuid %x not supported\n", eax);
502 "Processor cpuid %x not supported\n", eax);
503 return; 485 return;
504 } 486 }
505 487
506 eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES); 488 eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES);
507 if (eax < CPUID_FREQ_VOLT_CAPABILITIES) { 489 if (eax < CPUID_FREQ_VOLT_CAPABILITIES) {
508 printk(KERN_INFO PFX 490 pr_info("No frequency change capabilities detected\n");
509 "No frequency change capabilities detected\n");
510 return; 491 return;
511 } 492 }
512 493
513 cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); 494 cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx);
514 if ((edx & P_STATE_TRANSITION_CAPABLE) 495 if ((edx & P_STATE_TRANSITION_CAPABLE)
515 != P_STATE_TRANSITION_CAPABLE) { 496 != P_STATE_TRANSITION_CAPABLE) {
516 printk(KERN_INFO PFX 497 pr_info("Power state transitions not supported\n");
517 "Power state transitions not supported\n");
518 return; 498 return;
519 } 499 }
520 *rc = 0; 500 *rc = 0;
@@ -529,43 +509,39 @@ static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst,
529 509
530 for (j = 0; j < data->numps; j++) { 510 for (j = 0; j < data->numps; j++) {
531 if (pst[j].vid > LEAST_VID) { 511 if (pst[j].vid > LEAST_VID) {
532 printk(KERN_ERR FW_BUG PFX "vid %d invalid : 0x%x\n", 512 pr_err(FW_BUG "vid %d invalid : 0x%x\n", j,
533 j, pst[j].vid); 513 pst[j].vid);
534 return -EINVAL; 514 return -EINVAL;
535 } 515 }
536 if (pst[j].vid < data->rvo) { 516 if (pst[j].vid < data->rvo) {
537 /* vid + rvo >= 0 */ 517 /* vid + rvo >= 0 */
538 printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate" 518 pr_err(FW_BUG "0 vid exceeded with pstate %d\n", j);
539 " %d\n", j);
540 return -ENODEV; 519 return -ENODEV;
541 } 520 }
542 if (pst[j].vid < maxvid + data->rvo) { 521 if (pst[j].vid < maxvid + data->rvo) {
543 /* vid + rvo >= maxvid */ 522 /* vid + rvo >= maxvid */
544 printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate" 523 pr_err(FW_BUG "maxvid exceeded with pstate %d\n", j);
545 " %d\n", j);
546 return -ENODEV; 524 return -ENODEV;
547 } 525 }
548 if (pst[j].fid > MAX_FID) { 526 if (pst[j].fid > MAX_FID) {
549 printk(KERN_ERR FW_BUG PFX "maxfid exceeded with pstate" 527 pr_err(FW_BUG "maxfid exceeded with pstate %d\n", j);
550 " %d\n", j);
551 return -ENODEV; 528 return -ENODEV;
552 } 529 }
553 if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) { 530 if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) {
554 /* Only first fid is allowed to be in "low" range */ 531 /* Only first fid is allowed to be in "low" range */
555 printk(KERN_ERR FW_BUG PFX "two low fids - %d : " 532 pr_err(FW_BUG "two low fids - %d : 0x%x\n", j,
556 "0x%x\n", j, pst[j].fid); 533 pst[j].fid);
557 return -EINVAL; 534 return -EINVAL;
558 } 535 }
559 if (pst[j].fid < lastfid) 536 if (pst[j].fid < lastfid)
560 lastfid = pst[j].fid; 537 lastfid = pst[j].fid;
561 } 538 }
562 if (lastfid & 1) { 539 if (lastfid & 1) {
563 printk(KERN_ERR FW_BUG PFX "lastfid invalid\n"); 540 pr_err(FW_BUG "lastfid invalid\n");
564 return -EINVAL; 541 return -EINVAL;
565 } 542 }
566 if (lastfid > LO_FID_TABLE_TOP) 543 if (lastfid > LO_FID_TABLE_TOP)
567 printk(KERN_INFO FW_BUG PFX 544 pr_info(FW_BUG "first fid not from lo freq table\n");
568 "first fid not from lo freq table\n");
569 545
570 return 0; 546 return 0;
571} 547}
@@ -582,16 +558,14 @@ static void print_basics(struct powernow_k8_data *data)
582 for (j = 0; j < data->numps; j++) { 558 for (j = 0; j < data->numps; j++) {
583 if (data->powernow_table[j].frequency != 559 if (data->powernow_table[j].frequency !=
584 CPUFREQ_ENTRY_INVALID) { 560 CPUFREQ_ENTRY_INVALID) {
585 printk(KERN_INFO PFX 561 pr_info("fid 0x%x (%d MHz), vid 0x%x\n",
586 "fid 0x%x (%d MHz), vid 0x%x\n", 562 data->powernow_table[j].driver_data & 0xff,
587 data->powernow_table[j].driver_data & 0xff, 563 data->powernow_table[j].frequency/1000,
588 data->powernow_table[j].frequency/1000, 564 data->powernow_table[j].driver_data >> 8);
589 data->powernow_table[j].driver_data >> 8);
590 } 565 }
591 } 566 }
592 if (data->batps) 567 if (data->batps)
593 printk(KERN_INFO PFX "Only %d pstates on battery\n", 568 pr_info("Only %d pstates on battery\n", data->batps);
594 data->batps);
595} 569}
596 570
597static int fill_powernow_table(struct powernow_k8_data *data, 571static int fill_powernow_table(struct powernow_k8_data *data,
@@ -602,21 +576,20 @@ static int fill_powernow_table(struct powernow_k8_data *data,
602 576
603 if (data->batps) { 577 if (data->batps) {
604 /* use ACPI support to get full speed on mains power */ 578 /* use ACPI support to get full speed on mains power */
605 printk(KERN_WARNING PFX 579 pr_warn("Only %d pstates usable (use ACPI driver for full range\n",
606 "Only %d pstates usable (use ACPI driver for full " 580 data->batps);
607 "range\n", data->batps);
608 data->numps = data->batps; 581 data->numps = data->batps;
609 } 582 }
610 583
611 for (j = 1; j < data->numps; j++) { 584 for (j = 1; j < data->numps; j++) {
612 if (pst[j-1].fid >= pst[j].fid) { 585 if (pst[j-1].fid >= pst[j].fid) {
613 printk(KERN_ERR PFX "PST out of sequence\n"); 586 pr_err("PST out of sequence\n");
614 return -EINVAL; 587 return -EINVAL;
615 } 588 }
616 } 589 }
617 590
618 if (data->numps < 2) { 591 if (data->numps < 2) {
619 printk(KERN_ERR PFX "no p states to transition\n"); 592 pr_err("no p states to transition\n");
620 return -ENODEV; 593 return -ENODEV;
621 } 594 }
622 595
@@ -626,7 +599,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,
626 powernow_table = kzalloc((sizeof(*powernow_table) 599 powernow_table = kzalloc((sizeof(*powernow_table)
627 * (data->numps + 1)), GFP_KERNEL); 600 * (data->numps + 1)), GFP_KERNEL);
628 if (!powernow_table) { 601 if (!powernow_table) {
629 printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); 602 pr_err("powernow_table memory alloc failure\n");
630 return -ENOMEM; 603 return -ENOMEM;
631 } 604 }
632 605
@@ -681,13 +654,13 @@ static int find_psb_table(struct powernow_k8_data *data)
681 654
682 pr_debug("table vers: 0x%x\n", psb->tableversion); 655 pr_debug("table vers: 0x%x\n", psb->tableversion);
683 if (psb->tableversion != PSB_VERSION_1_4) { 656 if (psb->tableversion != PSB_VERSION_1_4) {
684 printk(KERN_ERR FW_BUG PFX "PSB table is not v1.4\n"); 657 pr_err(FW_BUG "PSB table is not v1.4\n");
685 return -ENODEV; 658 return -ENODEV;
686 } 659 }
687 660
688 pr_debug("flags: 0x%x\n", psb->flags1); 661 pr_debug("flags: 0x%x\n", psb->flags1);
689 if (psb->flags1) { 662 if (psb->flags1) {
690 printk(KERN_ERR FW_BUG PFX "unknown flags\n"); 663 pr_err(FW_BUG "unknown flags\n");
691 return -ENODEV; 664 return -ENODEV;
692 } 665 }
693 666
@@ -716,7 +689,7 @@ static int find_psb_table(struct powernow_k8_data *data)
716 cpst = 1; 689 cpst = 1;
717 } 690 }
718 if (cpst != 1) { 691 if (cpst != 1) {
719 printk(KERN_ERR FW_BUG PFX "numpst must be 1\n"); 692 pr_err(FW_BUG "numpst must be 1\n");
720 return -ENODEV; 693 return -ENODEV;
721 } 694 }
722 695
@@ -742,9 +715,8 @@ static int find_psb_table(struct powernow_k8_data *data)
742 * BIOS and Kernel Developer's Guide, which is available on 715 * BIOS and Kernel Developer's Guide, which is available on
743 * www.amd.com 716 * www.amd.com
744 */ 717 */
745 printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n"); 718 pr_err(FW_BUG "No PSB or ACPI _PSS objects\n");
746 printk(KERN_ERR PFX "Make sure that your BIOS is up to date" 719 pr_err("Make sure that your BIOS is up to date and Cool'N'Quiet support is enabled in BIOS setup\n");
747 " and Cool'N'Quiet support is enabled in BIOS setup\n");
748 return -ENODEV; 720 return -ENODEV;
749} 721}
750 722
@@ -819,8 +791,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
819 acpi_processor_notify_smm(THIS_MODULE); 791 acpi_processor_notify_smm(THIS_MODULE);
820 792
821 if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) { 793 if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) {
822 printk(KERN_ERR PFX 794 pr_err("unable to alloc powernow_k8_data cpumask\n");
823 "unable to alloc powernow_k8_data cpumask\n");
824 ret_val = -ENOMEM; 795 ret_val = -ENOMEM;
825 goto err_out_mem; 796 goto err_out_mem;
826 } 797 }
@@ -885,9 +856,8 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
885 } 856 }
886 857
887 if (freq != (data->acpi_data.states[i].core_frequency * 1000)) { 858 if (freq != (data->acpi_data.states[i].core_frequency * 1000)) {
888 printk(KERN_INFO PFX "invalid freq entries " 859 pr_info("invalid freq entries %u kHz vs. %u kHz\n",
889 "%u kHz vs. %u kHz\n", freq, 860 freq, (unsigned int)
890 (unsigned int)
891 (data->acpi_data.states[i].core_frequency 861 (data->acpi_data.states[i].core_frequency
892 * 1000)); 862 * 1000));
893 invalidate_entry(powernow_table, i); 863 invalidate_entry(powernow_table, i);
@@ -916,7 +886,7 @@ static int get_transition_latency(struct powernow_k8_data *data)
916 max_latency = cur_latency; 886 max_latency = cur_latency;
917 } 887 }
918 if (max_latency == 0) { 888 if (max_latency == 0) {
919 pr_err(FW_WARN PFX "Invalid zero transition latency\n"); 889 pr_err(FW_WARN "Invalid zero transition latency\n");
920 max_latency = 1; 890 max_latency = 1;
921 } 891 }
922 /* value in usecs, needs to be in nanoseconds */ 892 /* value in usecs, needs to be in nanoseconds */
@@ -991,7 +961,7 @@ static long powernowk8_target_fn(void *arg)
991 checkvid = data->currvid; 961 checkvid = data->currvid;
992 962
993 if (pending_bit_stuck()) { 963 if (pending_bit_stuck()) {
994 printk(KERN_ERR PFX "failing targ, change pending bit set\n"); 964 pr_err("failing targ, change pending bit set\n");
995 return -EIO; 965 return -EIO;
996 } 966 }
997 967
@@ -1003,12 +973,11 @@ static long powernowk8_target_fn(void *arg)
1003 return -EIO; 973 return -EIO;
1004 974
1005 pr_debug("targ: curr fid 0x%x, vid 0x%x\n", 975 pr_debug("targ: curr fid 0x%x, vid 0x%x\n",
1006 data->currfid, data->currvid); 976 data->currfid, data->currvid);
1007 977
1008 if ((checkvid != data->currvid) || 978 if ((checkvid != data->currvid) ||
1009 (checkfid != data->currfid)) { 979 (checkfid != data->currfid)) {
1010 pr_info(PFX 980 pr_info("error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n",
1011 "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n",
1012 checkfid, data->currfid, 981 checkfid, data->currfid,
1013 checkvid, data->currvid); 982 checkvid, data->currvid);
1014 } 983 }
@@ -1020,7 +989,7 @@ static long powernowk8_target_fn(void *arg)
1020 ret = transition_frequency_fidvid(data, newstate); 989 ret = transition_frequency_fidvid(data, newstate);
1021 990
1022 if (ret) { 991 if (ret) {
1023 printk(KERN_ERR PFX "transition frequency failed\n"); 992 pr_err("transition frequency failed\n");
1024 mutex_unlock(&fidvid_mutex); 993 mutex_unlock(&fidvid_mutex);
1025 return 1; 994 return 1;
1026 } 995 }
@@ -1049,7 +1018,7 @@ static void powernowk8_cpu_init_on_cpu(void *_init_on_cpu)
1049 struct init_on_cpu *init_on_cpu = _init_on_cpu; 1018 struct init_on_cpu *init_on_cpu = _init_on_cpu;
1050 1019
1051 if (pending_bit_stuck()) { 1020 if (pending_bit_stuck()) {
1052 printk(KERN_ERR PFX "failing init, change pending bit set\n"); 1021 pr_err("failing init, change pending bit set\n");
1053 init_on_cpu->rc = -ENODEV; 1022 init_on_cpu->rc = -ENODEV;
1054 return; 1023 return;
1055 } 1024 }
@@ -1064,11 +1033,10 @@ static void powernowk8_cpu_init_on_cpu(void *_init_on_cpu)
1064 init_on_cpu->rc = 0; 1033 init_on_cpu->rc = 0;
1065} 1034}
1066 1035
1067static const char missing_pss_msg[] = 1036#define MISSING_PSS_MSG \
1068 KERN_ERR 1037 FW_BUG "No compatible ACPI _PSS objects found.\n" \
1069 FW_BUG PFX "No compatible ACPI _PSS objects found.\n" 1038 FW_BUG "First, make sure Cool'N'Quiet is enabled in the BIOS.\n" \
1070 FW_BUG PFX "First, make sure Cool'N'Quiet is enabled in the BIOS.\n" 1039 FW_BUG "If that doesn't help, try upgrading your BIOS.\n"
1071 FW_BUG PFX "If that doesn't help, try upgrading your BIOS.\n";
1072 1040
1073/* per CPU init entry point to the driver */ 1041/* per CPU init entry point to the driver */
1074static int powernowk8_cpu_init(struct cpufreq_policy *pol) 1042static int powernowk8_cpu_init(struct cpufreq_policy *pol)
@@ -1083,7 +1051,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1083 1051
1084 data = kzalloc(sizeof(*data), GFP_KERNEL); 1052 data = kzalloc(sizeof(*data), GFP_KERNEL);
1085 if (!data) { 1053 if (!data) {
1086 printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); 1054 pr_err("unable to alloc powernow_k8_data");
1087 return -ENOMEM; 1055 return -ENOMEM;
1088 } 1056 }
1089 1057
@@ -1095,13 +1063,11 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1095 * an UP version, and is deprecated by AMD. 1063 * an UP version, and is deprecated by AMD.
1096 */ 1064 */
1097 if (num_online_cpus() != 1) { 1065 if (num_online_cpus() != 1) {
1098 printk_once(missing_pss_msg); 1066 pr_err_once(MISSING_PSS_MSG);
1099 goto err_out; 1067 goto err_out;
1100 } 1068 }
1101 if (pol->cpu != 0) { 1069 if (pol->cpu != 0) {
1102 printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " 1070 pr_err(FW_BUG "No ACPI _PSS objects for CPU other than CPU0. Complain to your BIOS vendor.\n");
1103 "CPU other than CPU0. Complain to your BIOS "
1104 "vendor.\n");
1105 goto err_out; 1071 goto err_out;
1106 } 1072 }
1107 rc = find_psb_table(data); 1073 rc = find_psb_table(data);
@@ -1129,7 +1095,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1129 1095
1130 /* min/max the cpu is capable of */ 1096 /* min/max the cpu is capable of */
1131 if (cpufreq_table_validate_and_show(pol, data->powernow_table)) { 1097 if (cpufreq_table_validate_and_show(pol, data->powernow_table)) {
1132 printk(KERN_ERR FW_BUG PFX "invalid powernow_table\n"); 1098 pr_err(FW_BUG "invalid powernow_table\n");
1133 powernow_k8_cpu_exit_acpi(data); 1099 powernow_k8_cpu_exit_acpi(data);
1134 kfree(data->powernow_table); 1100 kfree(data->powernow_table);
1135 kfree(data); 1101 kfree(data);
@@ -1137,7 +1103,7 @@ static int powernowk8_cpu_init(struct cpufreq_policy *pol)
1137 } 1103 }
1138 1104
1139 pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n", 1105 pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n",
1140 data->currfid, data->currvid); 1106 data->currfid, data->currvid);
1141 1107
1142 /* Point all the CPUs in this policy to the same data */ 1108 /* Point all the CPUs in this policy to the same data */
1143 for_each_cpu(cpu, pol->cpus) 1109 for_each_cpu(cpu, pol->cpus)
@@ -1220,12 +1186,12 @@ static void __request_acpi_cpufreq(void)
1220 goto request; 1186 goto request;
1221 1187
1222 if (strncmp(cur_drv, drv, min_t(size_t, strlen(cur_drv), strlen(drv)))) 1188 if (strncmp(cur_drv, drv, min_t(size_t, strlen(cur_drv), strlen(drv))))
1223 pr_warn(PFX "WTF driver: %s\n", cur_drv); 1189 pr_warn("WTF driver: %s\n", cur_drv);
1224 1190
1225 return; 1191 return;
1226 1192
1227 request: 1193 request:
1228 pr_warn(PFX "This CPU is not supported anymore, using acpi-cpufreq instead.\n"); 1194 pr_warn("This CPU is not supported anymore, using acpi-cpufreq instead.\n");
1229 request_module(drv); 1195 request_module(drv);
1230} 1196}
1231 1197
@@ -1260,7 +1226,7 @@ static int powernowk8_init(void)
1260 if (ret) 1226 if (ret)
1261 return ret; 1227 return ret;
1262 1228
1263 pr_info(PFX "Found %d %s (%d cpu cores) (" VERSION ")\n", 1229 pr_info("Found %d %s (%d cpu cores) (" VERSION ")\n",
1264 num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus); 1230 num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus);
1265 1231
1266 return ret; 1232 return ret;
@@ -1274,8 +1240,8 @@ static void __exit powernowk8_exit(void)
1274 cpufreq_unregister_driver(&cpufreq_amd64_driver); 1240 cpufreq_unregister_driver(&cpufreq_amd64_driver);
1275} 1241}
1276 1242
1277MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and " 1243MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com>");
1278 "Mark Langsdorf <mark.langsdorf@amd.com>"); 1244MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@amd.com>");
1279MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver."); 1245MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver.");
1280MODULE_LICENSE("GPL"); 1246MODULE_LICENSE("GPL");
1281 1247
diff --git a/drivers/cpufreq/powernow-k8.h b/drivers/cpufreq/powernow-k8.h
index 79329d4d5abe..45ce11e86626 100644
--- a/drivers/cpufreq/powernow-k8.h
+++ b/drivers/cpufreq/powernow-k8.h
@@ -19,7 +19,7 @@ struct powernow_k8_data {
19 u32 vidmvs; /* usable value calculated from mvs */ 19 u32 vidmvs; /* usable value calculated from mvs */
20 u32 vstable; /* voltage stabilization time, units 20 us */ 20 u32 vstable; /* voltage stabilization time, units 20 us */
21 u32 plllock; /* pll lock time, units 1 us */ 21 u32 plllock; /* pll lock time, units 1 us */
22 u32 exttype; /* extended interface = 1 */ 22 u32 exttype; /* extended interface = 1 */
23 23
24 /* keep track of the current fid / vid or pstate */ 24 /* keep track of the current fid / vid or pstate */
25 u32 currvid; 25 u32 currvid;
diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index af4968813e76..bb1d08dc8cc8 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -235,7 +235,7 @@ static void powernv_read_cpu_freq(void *arg)
235 * firmware for CPU 'cpu'. This value is reported through the sysfs 235 * firmware for CPU 'cpu'. This value is reported through the sysfs
236 * file cpuinfo_cur_freq. 236 * file cpuinfo_cur_freq.
237 */ 237 */
238unsigned int powernv_cpufreq_get(unsigned int cpu) 238static unsigned int powernv_cpufreq_get(unsigned int cpu)
239{ 239{
240 struct powernv_smp_call_data freq_data; 240 struct powernv_smp_call_data freq_data;
241 241
diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
index 5be8a48dba74..5a4c5a639f61 100644
--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
+++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
@@ -67,9 +67,10 @@ static int set_pmode(unsigned int cpu, unsigned int slow_mode)
67 67
68static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy) 68static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
69{ 69{
70 struct cpufreq_frequency_table *pos;
70 const u32 *max_freqp; 71 const u32 *max_freqp;
71 u32 max_freq; 72 u32 max_freq;
72 int i, cur_pmode; 73 int cur_pmode;
73 struct device_node *cpu; 74 struct device_node *cpu;
74 75
75 cpu = of_get_cpu_node(policy->cpu, NULL); 76 cpu = of_get_cpu_node(policy->cpu, NULL);
@@ -102,9 +103,9 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
102 pr_debug("initializing frequency table\n"); 103 pr_debug("initializing frequency table\n");
103 104
104 /* initialize frequency table */ 105 /* initialize frequency table */
105 for (i=0; cbe_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { 106 cpufreq_for_each_entry(pos, cbe_freqs) {
106 cbe_freqs[i].frequency = max_freq / cbe_freqs[i].driver_data; 107 pos->frequency = max_freq / pos->driver_data;
107 pr_debug("%d: %d\n", i, cbe_freqs[i].frequency); 108 pr_debug("%d: %d\n", (int)(pos - cbe_freqs), pos->frequency);
108 } 109 }
109 110
110 /* if DEBUG is enabled set_pmode() measures the latency 111 /* if DEBUG is enabled set_pmode() measures the latency
diff --git a/drivers/cpufreq/s3c2416-cpufreq.c b/drivers/cpufreq/s3c2416-cpufreq.c
index 4626f90559b5..2fd53eaaec20 100644
--- a/drivers/cpufreq/s3c2416-cpufreq.c
+++ b/drivers/cpufreq/s3c2416-cpufreq.c
@@ -266,7 +266,7 @@ out:
266static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq) 266static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)
267{ 267{
268 int count, v, i, found; 268 int count, v, i, found;
269 struct cpufreq_frequency_table *freq; 269 struct cpufreq_frequency_table *pos;
270 struct s3c2416_dvfs *dvfs; 270 struct s3c2416_dvfs *dvfs;
271 271
272 count = regulator_count_voltages(s3c_freq->vddarm); 272 count = regulator_count_voltages(s3c_freq->vddarm);
@@ -275,12 +275,11 @@ static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)
275 return; 275 return;
276 } 276 }
277 277
278 freq = s3c_freq->freq_table; 278 if (!count)
279 while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) { 279 goto out;
280 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
281 continue;
282 280
283 dvfs = &s3c2416_dvfs_table[freq->driver_data]; 281 cpufreq_for_each_valid_entry(pos, s3c_freq->freq_table) {
282 dvfs = &s3c2416_dvfs_table[pos->driver_data];
284 found = 0; 283 found = 0;
285 284
286 /* Check only the min-voltage, more is always ok on S3C2416 */ 285 /* Check only the min-voltage, more is always ok on S3C2416 */
@@ -292,13 +291,12 @@ static void __init s3c2416_cpufreq_cfg_regulator(struct s3c2416_data *s3c_freq)
292 291
293 if (!found) { 292 if (!found) {
294 pr_debug("cpufreq: %dkHz unsupported by regulator\n", 293 pr_debug("cpufreq: %dkHz unsupported by regulator\n",
295 freq->frequency); 294 pos->frequency);
296 freq->frequency = CPUFREQ_ENTRY_INVALID; 295 pos->frequency = CPUFREQ_ENTRY_INVALID;
297 } 296 }
298
299 freq++;
300 } 297 }
301 298
299out:
302 /* Guessed */ 300 /* Guessed */
303 s3c_freq->regulator_latency = 1 * 1000 * 1000; 301 s3c_freq->regulator_latency = 1 * 1000 * 1000;
304} 302}
@@ -338,7 +336,7 @@ static struct notifier_block s3c2416_cpufreq_reboot_notifier = {
338static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy) 336static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy)
339{ 337{
340 struct s3c2416_data *s3c_freq = &s3c2416_cpufreq; 338 struct s3c2416_data *s3c_freq = &s3c2416_cpufreq;
341 struct cpufreq_frequency_table *freq; 339 struct cpufreq_frequency_table *pos;
342 struct clk *msysclk; 340 struct clk *msysclk;
343 unsigned long rate; 341 unsigned long rate;
344 int ret; 342 int ret;
@@ -427,31 +425,27 @@ static int __init s3c2416_cpufreq_driver_init(struct cpufreq_policy *policy)
427 s3c_freq->regulator_latency = 0; 425 s3c_freq->regulator_latency = 0;
428#endif 426#endif
429 427
430 freq = s3c_freq->freq_table; 428 cpufreq_for_each_entry(pos, s3c_freq->freq_table) {
431 while (freq->frequency != CPUFREQ_TABLE_END) {
432 /* special handling for dvs mode */ 429 /* special handling for dvs mode */
433 if (freq->driver_data == 0) { 430 if (pos->driver_data == 0) {
434 if (!s3c_freq->hclk) { 431 if (!s3c_freq->hclk) {
435 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n", 432 pr_debug("cpufreq: %dkHz unsupported as it would need unavailable dvs mode\n",
436 freq->frequency); 433 pos->frequency);
437 freq->frequency = CPUFREQ_ENTRY_INVALID; 434 pos->frequency = CPUFREQ_ENTRY_INVALID;
438 } else { 435 } else {
439 freq++;
440 continue; 436 continue;
441 } 437 }
442 } 438 }
443 439
444 /* Check for frequencies we can generate */ 440 /* Check for frequencies we can generate */
445 rate = clk_round_rate(s3c_freq->armdiv, 441 rate = clk_round_rate(s3c_freq->armdiv,
446 freq->frequency * 1000); 442 pos->frequency * 1000);
447 rate /= 1000; 443 rate /= 1000;
448 if (rate != freq->frequency) { 444 if (rate != pos->frequency) {
449 pr_debug("cpufreq: %dkHz unsupported by clock (clk_round_rate return %lu)\n", 445 pr_debug("cpufreq: %dkHz unsupported by clock (clk_round_rate return %lu)\n",
450 freq->frequency, rate); 446 pos->frequency, rate);
451 freq->frequency = CPUFREQ_ENTRY_INVALID; 447 pos->frequency = CPUFREQ_ENTRY_INVALID;
452 } 448 }
453
454 freq++;
455 } 449 }
456 450
457 /* Datasheet says PLL stabalisation time must be at least 300us, 451 /* Datasheet says PLL stabalisation time must be at least 300us,
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index ff7d3ecb85f0..176e84cc3991 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -118,11 +118,10 @@ static void __init s3c64xx_cpufreq_config_regulator(void)
118 pr_err("Unable to check supported voltages\n"); 118 pr_err("Unable to check supported voltages\n");
119 } 119 }
120 120
121 freq = s3c64xx_freq_table; 121 if (!count)
122 while (count > 0 && freq->frequency != CPUFREQ_TABLE_END) { 122 goto out;
123 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
124 continue;
125 123
124 cpufreq_for_each_valid_entry(freq, s3c64xx_freq_table) {
126 dvfs = &s3c64xx_dvfs_table[freq->driver_data]; 125 dvfs = &s3c64xx_dvfs_table[freq->driver_data];
127 found = 0; 126 found = 0;
128 127
@@ -137,10 +136,9 @@ static void __init s3c64xx_cpufreq_config_regulator(void)
137 freq->frequency); 136 freq->frequency);
138 freq->frequency = CPUFREQ_ENTRY_INVALID; 137 freq->frequency = CPUFREQ_ENTRY_INVALID;
139 } 138 }
140
141 freq++;
142 } 139 }
143 140
141out:
144 /* Guess based on having to do an I2C/SPI write; in future we 142 /* Guess based on having to do an I2C/SPI write; in future we
145 * will be able to query the regulator performance here. */ 143 * will be able to query the regulator performance here. */
146 regulator_latency = 1 * 1000 * 1000; 144 regulator_latency = 1 * 1000 * 1000;
@@ -179,8 +177,7 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
179 } 177 }
180#endif 178#endif
181 179
182 freq = s3c64xx_freq_table; 180 cpufreq_for_each_entry(freq, s3c64xx_freq_table) {
183 while (freq->frequency != CPUFREQ_TABLE_END) {
184 unsigned long r; 181 unsigned long r;
185 182
186 /* Check for frequencies we can generate */ 183 /* Check for frequencies we can generate */
@@ -196,8 +193,6 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
196 * frequency is the maximum we can support. */ 193 * frequency is the maximum we can support. */
197 if (!vddarm && freq->frequency > clk_get_rate(policy->clk) / 1000) 194 if (!vddarm && freq->frequency > clk_get_rate(policy->clk) / 1000)
198 freq->frequency = CPUFREQ_ENTRY_INVALID; 195 freq->frequency = CPUFREQ_ENTRY_INVALID;
199
200 freq++;
201 } 196 }
202 197
203 /* Datasheet says PLL stabalisation time (if we were to use 198 /* Datasheet says PLL stabalisation time (if we were to use
diff --git a/drivers/cpufreq/s5pv210-cpufreq.c b/drivers/cpufreq/s5pv210-cpufreq.c
index ab2c1a40d437..19a10b89fef7 100644
--- a/drivers/cpufreq/s5pv210-cpufreq.c
+++ b/drivers/cpufreq/s5pv210-cpufreq.c
@@ -175,10 +175,8 @@ static int s5pv210_target(struct cpufreq_policy *policy, unsigned int index)
175 mutex_lock(&set_freq_lock); 175 mutex_lock(&set_freq_lock);
176 176
177 if (no_cpufreq_access) { 177 if (no_cpufreq_access) {
178#ifdef CONFIG_PM_VERBOSE 178 pr_err("Denied access to %s as it is disabled temporarily\n",
179 pr_err("%s:%d denied access to %s as it is disabled" 179 __func__);
180 "temporarily\n", __FILE__, __LINE__, __func__);
181#endif
182 ret = -EINVAL; 180 ret = -EINVAL;
183 goto exit; 181 goto exit;
184 } 182 }
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
index 6723f0390f20..7d4a31571608 100644
--- a/drivers/cpufreq/speedstep-centrino.c
+++ b/drivers/cpufreq/speedstep-centrino.c
@@ -28,7 +28,7 @@
28#include <asm/cpu_device_id.h> 28#include <asm/cpu_device_id.h>
29 29
30#define PFX "speedstep-centrino: " 30#define PFX "speedstep-centrino: "
31#define MAINTAINER "cpufreq@vger.kernel.org" 31#define MAINTAINER "linux-pm@vger.kernel.org"
32 32
33#define INTEL_MSR_RANGE (0xffff) 33#define INTEL_MSR_RANGE (0xffff)
34 34
diff --git a/drivers/cpufreq/tegra-cpufreq.c b/drivers/cpufreq/tegra-cpufreq.c
index 63f00598a251..6e774c6ac20b 100644
--- a/drivers/cpufreq/tegra-cpufreq.c
+++ b/drivers/cpufreq/tegra-cpufreq.c
@@ -82,9 +82,9 @@ out:
82 return ret; 82 return ret;
83} 83}
84 84
85static int tegra_update_cpu_speed(struct cpufreq_policy *policy, 85static int tegra_target(struct cpufreq_policy *policy, unsigned int index)
86 unsigned long rate)
87{ 86{
87 unsigned long rate = freq_table[index].frequency;
88 int ret = 0; 88 int ret = 0;
89 89
90 /* 90 /*
@@ -106,11 +106,6 @@ static int tegra_update_cpu_speed(struct cpufreq_policy *policy,
106 return ret; 106 return ret;
107} 107}
108 108
109static int tegra_target(struct cpufreq_policy *policy, unsigned int index)
110{
111 return tegra_update_cpu_speed(policy, freq_table[index].frequency);
112}
113
114static int tegra_cpu_init(struct cpufreq_policy *policy) 109static int tegra_cpu_init(struct cpufreq_policy *policy)
115{ 110{
116 int ret; 111 int ret;
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 7694e0700d34..b11fdd63eecd 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -1734,18 +1734,17 @@ static struct cpufreq_frequency_table db8500_cpufreq_table[] = {
1734 1734
1735static long round_armss_rate(unsigned long rate) 1735static long round_armss_rate(unsigned long rate)
1736{ 1736{
1737 struct cpufreq_frequency_table *pos;
1737 long freq = 0; 1738 long freq = 0;
1738 int i = 0;
1739 1739
1740 /* cpufreq table frequencies is in KHz. */ 1740 /* cpufreq table frequencies is in KHz. */
1741 rate = rate / 1000; 1741 rate = rate / 1000;
1742 1742
1743 /* Find the corresponding arm opp from the cpufreq table. */ 1743 /* Find the corresponding arm opp from the cpufreq table. */
1744 while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) { 1744 cpufreq_for_each_entry(pos, db8500_cpufreq_table) {
1745 freq = db8500_cpufreq_table[i].frequency; 1745 freq = pos->frequency;
1746 if (freq == rate) 1746 if (freq == rate)
1747 break; 1747 break;
1748 i++;
1749 } 1748 }
1750 1749
1751 /* Return the last valid value, even if a match was not found. */ 1750 /* Return the last valid value, even if a match was not found. */
@@ -1886,23 +1885,21 @@ static void set_clock_rate(u8 clock, unsigned long rate)
1886 1885
1887static int set_armss_rate(unsigned long rate) 1886static int set_armss_rate(unsigned long rate)
1888{ 1887{
1889 int i = 0; 1888 struct cpufreq_frequency_table *pos;
1890 1889
1891 /* cpufreq table frequencies is in KHz. */ 1890 /* cpufreq table frequencies is in KHz. */
1892 rate = rate / 1000; 1891 rate = rate / 1000;
1893 1892
1894 /* Find the corresponding arm opp from the cpufreq table. */ 1893 /* Find the corresponding arm opp from the cpufreq table. */
1895 while (db8500_cpufreq_table[i].frequency != CPUFREQ_TABLE_END) { 1894 cpufreq_for_each_entry(pos, db8500_cpufreq_table)
1896 if (db8500_cpufreq_table[i].frequency == rate) 1895 if (pos->frequency == rate)
1897 break; 1896 break;
1898 i++;
1899 }
1900 1897
1901 if (db8500_cpufreq_table[i].frequency != rate) 1898 if (pos->frequency != rate)
1902 return -EINVAL; 1899 return -EINVAL;
1903 1900
1904 /* Set the new arm opp. */ 1901 /* Set the new arm opp. */
1905 return db8500_prcmu_set_arm_opp(db8500_cpufreq_table[i].driver_data); 1902 return db8500_prcmu_set_arm_opp(pos->driver_data);
1906} 1903}
1907 1904
1908static int set_plldsi_rate(unsigned long rate) 1905static int set_plldsi_rate(unsigned long rate)
diff --git a/drivers/net/irda/sh_sir.c b/drivers/net/irda/sh_sir.c
index cadf52e22464..e3fe9a286136 100644
--- a/drivers/net/irda/sh_sir.c
+++ b/drivers/net/irda/sh_sir.c
@@ -217,21 +217,17 @@ crc_init_out:
217static u32 sh_sir_find_sclk(struct clk *irda_clk) 217static u32 sh_sir_find_sclk(struct clk *irda_clk)
218{ 218{
219 struct cpufreq_frequency_table *freq_table = irda_clk->freq_table; 219 struct cpufreq_frequency_table *freq_table = irda_clk->freq_table;
220 struct cpufreq_frequency_table *pos;
220 struct clk *pclk = clk_get(NULL, "peripheral_clk"); 221 struct clk *pclk = clk_get(NULL, "peripheral_clk");
221 u32 limit, min = 0xffffffff, tmp; 222 u32 limit, min = 0xffffffff, tmp;
222 int i, index = 0; 223 int index = 0;
223 224
224 limit = clk_get_rate(pclk); 225 limit = clk_get_rate(pclk);
225 clk_put(pclk); 226 clk_put(pclk);
226 227
227 /* IrDA can not set over peripheral_clk */ 228 /* IrDA can not set over peripheral_clk */
228 for (i = 0; 229 cpufreq_for_each_valid_entry(pos, freq_table) {
229 freq_table[i].frequency != CPUFREQ_TABLE_END; 230 u32 freq = pos->frequency;
230 i++) {
231 u32 freq = freq_table[i].frequency;
232
233 if (freq == CPUFREQ_ENTRY_INVALID)
234 continue;
235 231
236 /* IrDA should not over peripheral_clk */ 232 /* IrDA should not over peripheral_clk */
237 if (freq > limit) 233 if (freq > limit)
@@ -240,7 +236,7 @@ static u32 sh_sir_find_sclk(struct clk *irda_clk)
240 tmp = freq % SCLK_BASE; 236 tmp = freq % SCLK_BASE;
241 if (tmp < min) { 237 if (tmp < min) {
242 min = tmp; 238 min = tmp;
243 index = i; 239 index = pos - freq_table;
244 } 240 }
245 } 241 }
246 242
diff --git a/drivers/sh/clk/core.c b/drivers/sh/clk/core.c
index 74727851820d..be56b22ca941 100644
--- a/drivers/sh/clk/core.c
+++ b/drivers/sh/clk/core.c
@@ -196,17 +196,11 @@ int clk_rate_table_find(struct clk *clk,
196 struct cpufreq_frequency_table *freq_table, 196 struct cpufreq_frequency_table *freq_table,
197 unsigned long rate) 197 unsigned long rate)
198{ 198{
199 int i; 199 struct cpufreq_frequency_table *pos;
200
201 for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
202 unsigned long freq = freq_table[i].frequency;
203 200
204 if (freq == CPUFREQ_ENTRY_INVALID) 201 cpufreq_for_each_valid_entry(pos, freq_table)
205 continue; 202 if (pos->frequency == rate)
206 203 return pos - freq_table;
207 if (freq == rate)
208 return i;
209 }
210 204
211 return -ENOENT; 205 return -ENOENT;
212} 206}
@@ -575,11 +569,7 @@ long clk_round_parent(struct clk *clk, unsigned long target,
575 return abs(target - *best_freq); 569 return abs(target - *best_freq);
576 } 570 }
577 571
578 for (freq = parent->freq_table; freq->frequency != CPUFREQ_TABLE_END; 572 cpufreq_for_each_valid_entry(freq, parent->freq_table) {
579 freq++) {
580 if (freq->frequency == CPUFREQ_ENTRY_INVALID)
581 continue;
582
583 if (unlikely(freq->frequency / target <= div_min - 1)) { 573 if (unlikely(freq->frequency / target <= div_min - 1)) {
584 unsigned long freq_max; 574 unsigned long freq_max;
585 575
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 4246262c4bd2..84a75f89bf74 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -144,11 +144,11 @@ static int get_property(unsigned int cpu, unsigned long input,
144 unsigned int *output, 144 unsigned int *output,
145 enum cpufreq_cooling_property property) 145 enum cpufreq_cooling_property property)
146{ 146{
147 int i, j; 147 int i;
148 unsigned long max_level = 0, level = 0; 148 unsigned long max_level = 0, level = 0;
149 unsigned int freq = CPUFREQ_ENTRY_INVALID; 149 unsigned int freq = CPUFREQ_ENTRY_INVALID;
150 int descend = -1; 150 int descend = -1;
151 struct cpufreq_frequency_table *table = 151 struct cpufreq_frequency_table *pos, *table =
152 cpufreq_frequency_get_table(cpu); 152 cpufreq_frequency_get_table(cpu);
153 153
154 if (!output) 154 if (!output)
@@ -157,20 +157,16 @@ static int get_property(unsigned int cpu, unsigned long input,
157 if (!table) 157 if (!table)
158 return -EINVAL; 158 return -EINVAL;
159 159
160 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 160 cpufreq_for_each_valid_entry(pos, table) {
161 /* ignore invalid entries */
162 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
163 continue;
164
165 /* ignore duplicate entry */ 161 /* ignore duplicate entry */
166 if (freq == table[i].frequency) 162 if (freq == pos->frequency)
167 continue; 163 continue;
168 164
169 /* get the frequency order */ 165 /* get the frequency order */
170 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1) 166 if (freq != CPUFREQ_ENTRY_INVALID && descend == -1)
171 descend = !!(freq > table[i].frequency); 167 descend = freq > pos->frequency;
172 168
173 freq = table[i].frequency; 169 freq = pos->frequency;
174 max_level++; 170 max_level++;
175 } 171 }
176 172
@@ -190,29 +186,26 @@ static int get_property(unsigned int cpu, unsigned long input,
190 if (property == GET_FREQ) 186 if (property == GET_FREQ)
191 level = descend ? input : (max_level - input); 187 level = descend ? input : (max_level - input);
192 188
193 for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 189 i = 0;
194 /* ignore invalid entry */ 190 cpufreq_for_each_valid_entry(pos, table) {
195 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
196 continue;
197
198 /* ignore duplicate entry */ 191 /* ignore duplicate entry */
199 if (freq == table[i].frequency) 192 if (freq == pos->frequency)
200 continue; 193 continue;
201 194
202 /* now we have a valid frequency entry */ 195 /* now we have a valid frequency entry */
203 freq = table[i].frequency; 196 freq = pos->frequency;
204 197
205 if (property == GET_LEVEL && (unsigned int)input == freq) { 198 if (property == GET_LEVEL && (unsigned int)input == freq) {
206 /* get level by frequency */ 199 /* get level by frequency */
207 *output = descend ? j : (max_level - j); 200 *output = descend ? i : (max_level - i);
208 return 0; 201 return 0;
209 } 202 }
210 if (property == GET_FREQ && level == j) { 203 if (property == GET_FREQ && level == i) {
211 /* get frequency by level */ 204 /* get frequency by level */
212 *output = freq; 205 *output = freq;
213 return 0; 206 return 0;
214 } 207 }
215 j++; 208 i++;
216 } 209 }
217 210
218 return -EINVAL; 211 return -EINVAL;
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 5ae5100c1f24..3f458896d45c 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -110,6 +110,7 @@ struct cpufreq_policy {
110 bool transition_ongoing; /* Tracks transition status */ 110 bool transition_ongoing; /* Tracks transition status */
111 spinlock_t transition_lock; 111 spinlock_t transition_lock;
112 wait_queue_head_t transition_wait; 112 wait_queue_head_t transition_wait;
113 struct task_struct *transition_task; /* Task which is doing the transition */
113}; 114};
114 115
115/* Only for ACPI */ 116/* Only for ACPI */
@@ -468,6 +469,55 @@ struct cpufreq_frequency_table {
468 * order */ 469 * order */
469}; 470};
470 471
472#if defined(CONFIG_CPU_FREQ) && defined(CONFIG_PM_OPP)
473int dev_pm_opp_init_cpufreq_table(struct device *dev,
474 struct cpufreq_frequency_table **table);
475void dev_pm_opp_free_cpufreq_table(struct device *dev,
476 struct cpufreq_frequency_table **table);
477#else
478static inline int dev_pm_opp_init_cpufreq_table(struct device *dev,
479 struct cpufreq_frequency_table
480 **table)
481{
482 return -EINVAL;
483}
484
485static inline void dev_pm_opp_free_cpufreq_table(struct device *dev,
486 struct cpufreq_frequency_table
487 **table)
488{
489}
490#endif
491
492static inline bool cpufreq_next_valid(struct cpufreq_frequency_table **pos)
493{
494 while ((*pos)->frequency != CPUFREQ_TABLE_END)
495 if ((*pos)->frequency != CPUFREQ_ENTRY_INVALID)
496 return true;
497 else
498 (*pos)++;
499 return false;
500}
501
502/*
503 * cpufreq_for_each_entry - iterate over a cpufreq_frequency_table
504 * @pos: the cpufreq_frequency_table * to use as a loop cursor.
505 * @table: the cpufreq_frequency_table * to iterate over.
506 */
507
508#define cpufreq_for_each_entry(pos, table) \
509 for (pos = table; pos->frequency != CPUFREQ_TABLE_END; pos++)
510
511/*
512 * cpufreq_for_each_valid_entry - iterate over a cpufreq_frequency_table
513 * excluding CPUFREQ_ENTRY_INVALID frequencies.
514 * @pos: the cpufreq_frequency_table * to use as a loop cursor.
515 * @table: the cpufreq_frequency_table * to iterate over.
516 */
517
518#define cpufreq_for_each_valid_entry(pos, table) \
519 for (pos = table; cpufreq_next_valid(&pos); pos++)
520
471int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, 521int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
472 struct cpufreq_frequency_table *table); 522 struct cpufreq_frequency_table *table);
473 523
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 5151b0059585..0330217abfad 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -15,7 +15,6 @@
15#define __LINUX_OPP_H__ 15#define __LINUX_OPP_H__
16 16
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/cpufreq.h>
19#include <linux/notifier.h> 18#include <linux/notifier.h>
20 19
21struct dev_pm_opp; 20struct dev_pm_opp;
@@ -117,23 +116,4 @@ static inline int of_init_opp_table(struct device *dev)
117} 116}
118#endif 117#endif
119 118
120#if defined(CONFIG_CPU_FREQ) && defined(CONFIG_PM_OPP)
121int dev_pm_opp_init_cpufreq_table(struct device *dev,
122 struct cpufreq_frequency_table **table);
123void dev_pm_opp_free_cpufreq_table(struct device *dev,
124 struct cpufreq_frequency_table **table);
125#else
126static inline int dev_pm_opp_init_cpufreq_table(struct device *dev,
127 struct cpufreq_frequency_table **table)
128{
129 return -EINVAL;
130}
131
132static inline
133void dev_pm_opp_free_cpufreq_table(struct device *dev,
134 struct cpufreq_frequency_table **table)
135{
136}
137#endif /* CONFIG_CPU_FREQ */
138
139#endif /* __LINUX_OPP_H__ */ 119#endif /* __LINUX_OPP_H__ */
diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile
index cbfec92af327..3651db7eda23 100644
--- a/tools/power/cpupower/Makefile
+++ b/tools/power/cpupower/Makefile
@@ -62,7 +62,7 @@ LIB_MAJ= 0.0.0
62LIB_MIN= 0 62LIB_MIN= 0
63 63
64PACKAGE = cpupower 64PACKAGE = cpupower
65PACKAGE_BUGREPORT = cpufreq@vger.kernel.org 65PACKAGE_BUGREPORT = linux-pm@vger.kernel.org
66LANGUAGES = de fr it cs pt 66LANGUAGES = de fr it cs pt
67 67
68 68
diff --git a/tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c b/tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c
index 0f10b81e3322..5224ee5b392d 100644
--- a/tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c
+++ b/tools/power/cpupower/debug/kernel/cpufreq-test_tsc.c
@@ -18,7 +18,7 @@
18 * 5.) if the third value, "diff_pmtmr", changes between 2. and 4., the 18 * 5.) if the third value, "diff_pmtmr", changes between 2. and 4., the
19 * TSC-based delay routine on the Linux kernel does not correctly 19 * TSC-based delay routine on the Linux kernel does not correctly
20 * handle the cpufreq transition. Please report this to 20 * handle the cpufreq transition. Please report this to
21 * cpufreq@vger.kernel.org 21 * linux-pm@vger.kernel.org
22 */ 22 */
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>