ipq806x: set v4.9 as default
[openwrt/openwrt.git] / target / linux / ipq806x / patches-4.4 / 169-OPP-Support-adjusting-OPP-voltages-at-runtime.patch
1 From 111139c943a082364fbbcd9e0cc94cd442481340 Mon Sep 17 00:00:00 2001
2 From: Stephen Boyd <sboyd@codeaurora.org>
3 Date: Mon, 1 Jun 2015 18:47:56 -0700
4 Subject: PM / OPP: Support adjusting OPP voltages at runtime
5
6 On some SoCs the Adaptive Voltage Scaling (AVS) technique is
7 employed to optimize the operating voltage of a device. At a
8 given frequency, the hardware monitors dynamic factors and either
9 makes a suggestion for how much to adjust a voltage for the
10 current frequency, or it automatically adjusts the voltage
11 without software intervention. Add an API to the OPP library for
12 the former case, so that AVS type devices can update the voltages
13 for an OPP when the hardware determines the voltage should
14 change. The assumption is that drivers like CPUfreq or devfreq
15 will register for the OPP notifiers and adjust the voltage
16 according to suggestions that AVS makes.
17
18 Cc: Nishanth Menon <nm@ti.com>
19 Cc: Viresh Kumar <viresh.kumar@linaro.org>
20 Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
21 Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
22 ---
23 drivers/base/power/opp/core.c | 77 +++++++++++++++++++++++++++++++++++++++++++
24 include/linux/pm_opp.h | 10 ++++++
25 2 files changed, 87 insertions(+)
26
27 --- a/drivers/base/power/opp/core.c
28 +++ b/drivers/base/power/opp/core.c
29 @@ -1039,6 +1039,83 @@ unlock:
30 }
31
32 /**
33 + * dev_pm_opp_adjust_voltage() - helper to change the voltage of an opp
34 + * @dev: device for which we do this operation
35 + * @freq: OPP frequency to adjust voltage of
36 + * @u_volt: new OPP voltage
37 + *
38 + * Change the voltage of an OPP with an RCU operation.
39 + *
40 + * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the
41 + * copy operation, returns 0 if no modifcation was done OR modification was
42 + * successful.
43 + *
44 + * Locking: The internal device_opp and opp structures are RCU protected.
45 + * Hence this function internally uses RCU updater strategy with mutex locks to
46 + * keep the integrity of the internal data structures. Callers should ensure
47 + * that this function is *NOT* called under RCU protection or in contexts where
48 + * mutex locking or synchronize_rcu() blocking calls cannot be used.
49 + */
50 +int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
51 + unsigned long u_volt)
52 +{
53 + struct device_opp *dev_opp;
54 + struct dev_pm_opp *new_opp, *tmp_opp, *opp = ERR_PTR(-ENODEV);
55 + int r = 0;
56 +
57 + /* keep the node allocated */
58 + new_opp = kmalloc(sizeof(*new_opp), GFP_KERNEL);
59 + if (!new_opp)
60 + return -ENOMEM;
61 +
62 + mutex_lock(&dev_opp_list_lock);
63 +
64 + /* Find the device_opp */
65 + dev_opp = _find_device_opp(dev);
66 + if (IS_ERR(dev_opp)) {
67 + r = PTR_ERR(dev_opp);
68 + dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r);
69 + goto unlock;
70 + }
71 +
72 + /* Do we have the frequency? */
73 + list_for_each_entry(tmp_opp, &dev_opp->opp_list, node) {
74 + if (tmp_opp->rate == freq) {
75 + opp = tmp_opp;
76 + break;
77 + }
78 + }
79 + if (IS_ERR(opp)) {
80 + r = PTR_ERR(opp);
81 + goto unlock;
82 + }
83 +
84 + /* Is update really needed? */
85 + if (opp->u_volt == u_volt)
86 + goto unlock;
87 + /* copy the old data over */
88 + *new_opp = *opp;
89 +
90 + /* plug in new node */
91 + new_opp->u_volt = u_volt;
92 +
93 + list_replace_rcu(&opp->node, &new_opp->node);
94 + mutex_unlock(&dev_opp_list_lock);
95 + call_srcu(&dev_opp->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu);
96 +
97 + /* Notify the change of the OPP */
98 + srcu_notifier_call_chain(&dev_opp->srcu_head, OPP_EVENT_ADJUST_VOLTAGE,
99 + new_opp);
100 +
101 + return 0;
102 +
103 +unlock:
104 + mutex_unlock(&dev_opp_list_lock);
105 + kfree(new_opp);
106 + return r;
107 +}
108 +
109 +/**
110 * dev_pm_opp_enable() - Enable a specific OPP
111 * @dev: device for which we do this operation
112 * @freq: OPP frequency to enable
113 --- a/include/linux/pm_opp.h
114 +++ b/include/linux/pm_opp.h
115 @@ -22,6 +22,7 @@ struct device;
116
117 enum dev_pm_opp_event {
118 OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
119 + OPP_EVENT_ADJUST_VOLTAGE,
120 };
121
122 #if defined(CONFIG_PM_OPP)
123 @@ -50,6 +51,9 @@ int dev_pm_opp_add(struct device *dev, u
124 unsigned long u_volt);
125 void dev_pm_opp_remove(struct device *dev, unsigned long freq);
126
127 +int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
128 + unsigned long u_volt);
129 +
130 int dev_pm_opp_enable(struct device *dev, unsigned long freq);
131
132 int dev_pm_opp_disable(struct device *dev, unsigned long freq);
133 @@ -114,6 +118,12 @@ static inline void dev_pm_opp_remove(str
134 {
135 }
136
137 +static inline int dev_pm_opp_adjust_voltage(struct device *dev,
138 + unsigned long freq, unsigned long u_volt)
139 +{
140 + return 0;
141 +}
142 +
143 static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
144 {
145 return 0;