aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/cpu-freq/core.txt29
-rw-r--r--Documentation/power/opp.txt40
-rw-r--r--drivers/base/power/opp.c92
-rw-r--r--drivers/cpufreq/Makefile2
-rw-r--r--drivers/cpufreq/cpufreq_opp.c110
-rw-r--r--include/linux/cpufreq.h21
-rw-r--r--include/linux/pm_opp.h20
7 files changed, 167 insertions, 147 deletions
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/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/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 38b43bb20878..d9e376a6d19d 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>
@@ -596,97 +595,6 @@ int dev_pm_opp_disable(struct device *dev, unsigned long freq)
596} 595}
597EXPORT_SYMBOL_GPL(dev_pm_opp_disable); 596EXPORT_SYMBOL_GPL(dev_pm_opp_disable);
598 597
599#ifdef CONFIG_CPU_FREQ
600/**
601 * dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device
602 * @dev: device for which we do this operation
603 * @table: Cpufreq table returned back to caller
604 *
605 * Generate a cpufreq table for a provided device- this assumes that the
606 * opp list is already initialized and ready for usage.
607 *
608 * This function allocates required memory for the cpufreq table. It is
609 * expected that the caller does the required maintenance such as freeing
610 * the table as required.
611 *
612 * Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM
613 * if no memory available for the operation (table is not populated), returns 0
614 * if successful and table is populated.
615 *
616 * WARNING: It is important for the callers to ensure refreshing their copy of
617 * the table if any of the mentioned functions have been invoked in the interim.
618 *
619 * Locking: The internal device_opp and opp structures are RCU protected.
620 * Since we just use the regular accessor functions to access the internal data
621 * structures, we use RCU read lock inside this function. As a result, users of
622 * this function DONOT need to use explicit locks for invoking.
623 */
624int dev_pm_opp_init_cpufreq_table(struct device *dev,
625 struct cpufreq_frequency_table **table)
626{
627 struct dev_pm_opp *opp;
628 struct cpufreq_frequency_table *freq_table = NULL;
629 int i, max_opps, ret = 0;
630 unsigned long rate;
631
632 rcu_read_lock();
633
634 max_opps = dev_pm_opp_get_opp_count(dev);
635 if (max_opps <= 0) {
636 ret = max_opps ? max_opps : -ENODATA;
637 goto out;
638 }
639
640 freq_table = kzalloc(sizeof(*freq_table) * (max_opps + 1), GFP_KERNEL);
641 if (!freq_table) {
642 ret = -ENOMEM;
643 goto out;
644 }
645