aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
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/base
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/base')
-rw-r--r--drivers/base/power/Makefile2
-rw-r--r--drivers/base/power/opp/Makefile2
-rw-r--r--drivers/base/power/opp/core.c (renamed from drivers/base/power/opp.c)0
-rw-r--r--drivers/base/power/opp/cpu.c116
4 files changed, 119 insertions, 1 deletions
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index f94a6ccfe787..5998c53280f5 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,7 +1,7 @@
1obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o 1obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o
2obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o 2obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o
3obj-$(CONFIG_PM_TRACE_RTC) += trace.o 3obj-$(CONFIG_PM_TRACE_RTC) += trace.o
4obj-$(CONFIG_PM_OPP) += opp.o 4obj-$(CONFIG_PM_OPP) += opp/
5obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o 5obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o
6obj-$(CONFIG_HAVE_CLK) += clock_ops.o 6obj-$(CONFIG_HAVE_CLK) += clock_ops.o
7 7
diff --git a/drivers/base/power/opp/Makefile b/drivers/base/power/opp/Makefile
new file mode 100644
index 000000000000..33c1e18c41a4
--- /dev/null
+++ b/drivers/base/power/opp/Makefile
@@ -0,0 +1,2 @@
1ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
2obj-y += core.o cpu.o
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp/core.c
index aeff1cfb46f2..aeff1cfb46f2 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp/core.c
diff --git a/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c
new file mode 100644
index 000000000000..0dd033016e9d
--- /dev/null
+++ b/drivers/base/power/opp/cpu.c
@@ -0,0 +1,116 @@
1/*
2 * Generic OPP helper interface for CPU device
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#ifdef CONFIG_CPU_FREQ
24/**
25 * dev_pm_opp_init_cpufreq_table() - create a cpufreq table for a device
26 * @dev: device for which we do this operation
27 * @table: Cpufreq table returned back to caller
28 *
29 * Generate a cpufreq table for a provided device- this assumes that the
30 * opp list is already initialized and ready for usage.
31 *
32 * This function allocates required memory for the cpufreq table. It is
33 * expected that the caller does the required maintenance such as freeing
34 * the table as required.
35 *
36 * Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM
37 * if no memory available for the operation (table is not populated), returns 0
38 * if successful and table is populated.
39 *
40 * WARNING: It is important for the callers to ensure refreshing their copy of
41 * the table if any of the mentioned functions have been invoked in the interim.
42 *
43 * Locking: The internal device_opp and opp structures are RCU protected.
44 * Since we just use the regular accessor functions to access the internal data
45 * structures, we use RCU read lock inside this function. As a result, users of
46 * this function DONOT need to use explicit locks for invoking.
47 */
48int dev_pm_opp_init_cpufreq_table(struct device *dev,
49 struct cpufreq_frequency_table **table)
50{
51 struct dev_pm_opp *opp;
52 struct cpufreq_frequency_table *freq_table = NULL;
53 int i, max_opps, ret = 0;
54 unsigned long rate;
55
56 rcu_read_lock();
57
58 max_opps = dev_pm_opp_get_opp_count(dev);
59 if (max_opps <= 0) {
60 ret = max_opps ? max_opps : -ENODATA;
61 goto out;
62 }
63
64 freq_table = kcalloc((max_opps + 1), sizeof(*freq_table), GFP_ATOMIC);
65 if (!freq_table) {
66 ret = -ENOMEM;
67 goto out;
68 }
69
70 for (i = 0, rate = 0; i < max_opps; i++, rate++) {
71 /* find next rate */
72 opp = dev_pm_opp_find_freq_ceil(dev, &rate);
73 if (IS_ERR(opp)) {
74 ret = PTR_ERR(opp);
75 goto out;
76 }
77 freq_table[i].driver_data = i;
78 freq_table[i].frequency = rate / 1000;
79
80 /* Is Boost/turbo opp ? */
81 if (dev_pm_opp_is_turbo(opp))
82 freq_table[i].flags = CPUFREQ_BOOST_FREQ;
83 }
84
85 freq_table[i].driver_data = i;
86 freq_table[i].frequency = CPUFREQ_TABLE_END;
87
88 *table = &freq_table[0];
89
90out:
91 rcu_read_unlock();
92 if (ret)
93 kfree(freq_table);
94
95 return ret;
96}
97EXPORT_SYMBOL_GPL(dev_pm_opp_init_cpufreq_table);
98
99/**
100 * dev_pm_opp_free_cpufreq_table() - free the cpufreq table
101 * @dev: device for which we do this operation
102 * @table: table to free
103 *
104 * Free up the table allocated by dev_pm_opp_init_cpufreq_table
105 */
106void dev_pm_opp_free_cpufreq_table(struct device *dev,
107 struct cpufreq_frequency_table **table)
108{
109 if (!table)
110 return;
111
112 kfree(*table);
113 *table = NULL;
114}
115EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table);
116#endif /* CONFIG_CPU_FREQ */