aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2015-09-04 04:17:25 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-09-14 20:03:16 -0400
commit33692dc381f9b89ddfc408631bf670ac2fd08ffc (patch)
treef5b66650807dc06131d56bb352cd68977e12ef2d /drivers/cpufreq
parent8f8d37b2537a28b5b2e3cb60dfc85a2a1303f99b (diff)
PM / OPP: Move opp core to its own directory
OPP code is expanding and is already present in multiple directories (cpufreq and power). Lets move it to its own directory, to manage it better. This also moves/renames the cpufreq_opp file to cpu.c, as it will contain helpers for cpu device. Its not just about cpufreq, other frameworks can use OPPs as well. Reviewed-by: Stephen Boyd <sboyd@codeaurora.org> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/Makefile1
-rw-r--r--drivers/cpufreq/cpufreq_opp.c114
2 files changed, 0 insertions, 115 deletions
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 41340384f11f..be46ce0a358e 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -1,6 +1,5 @@
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
5# CPUfreq stats 4# CPUfreq stats
6obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o 5obj-$(CONFIG_CPU_FREQ_STAT) += cpufreq_stats.o
diff --git a/drivers/cpufreq/cpufreq_opp.c b/drivers/cpufreq/cpufreq_opp.c
deleted file mode 100644
index 0f5e6d5f6da0..000000000000
--- a/drivers/cpufreq/cpufreq_opp.c
+++ /dev/null
@@ -1,114 +0,0 @@
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 = kcalloc((max_opps + 1), sizeof(*freq_table), GFP_ATOMIC);
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 /* Is Boost/turbo opp ? */
80 if (dev_pm_opp_is_turbo(opp))
81 freq_table[i].flags = CPUFREQ_BOOST_FREQ;
82 }
83
84 freq_table[i].driver_data = i;
85 freq_table[i].frequency = CPUFREQ_TABLE_END;
86
87 *table = &freq_table[0];
88
89out:
90 rcu_read_unlock();
91 if (ret)
92 kfree(freq_table);
93
94 return ret;
95}
96EXPORT_SYMBOL_GPL(dev_pm_opp_init_cpufreq_table);
97
98/**
99 * dev_pm_opp_free_cpufreq_table() - free the cpufreq table
100 * @dev: device for which we do this operation
101 * @table: table to free
102 *
103 * Free up the table allocated by dev_pm_opp_init_cpufreq_table
104 */
105void dev_pm_opp_free_cpufreq_table(struct device *dev,
106 struct cpufreq_frequency_table **table)
107{
108 if (!table)
109 return;
110
111 kfree(*table);
112 *table = NULL;
113}
114EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);