Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Generic OPP Interface |
| 3 | * |
| 4 | * Copyright (C) 2009-2010 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 | |
Viresh Kumar | d6d2a52 | 2015-10-17 09:45:18 +0530 | [diff] [blame] | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
Viresh Kumar | d54974c | 2016-02-09 10:30:38 +0530 | [diff] [blame] | 16 | #include <linux/clk.h> |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 17 | #include <linux/errno.h> |
| 18 | #include <linux/err.h> |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 19 | #include <linux/slab.h> |
Paul Gortmaker | 51990e8 | 2012-01-22 11:23:42 -0500 | [diff] [blame] | 20 | #include <linux/device.h> |
Liam Girdwood | 80126ce | 2012-10-23 01:27:44 +0200 | [diff] [blame] | 21 | #include <linux/export.h> |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 22 | #include <linux/regulator/consumer.h> |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 23 | |
Viresh Kumar | f59d3ee | 2015-09-04 13:47:26 +0530 | [diff] [blame] | 24 | #include "opp.h" |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 25 | |
| 26 | /* |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 27 | * The root of the list of all opp-tables. All opp_table structures branch off |
| 28 | * from here, with each opp_table containing the list of opps it supports in |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 29 | * various states of availability. |
| 30 | */ |
Viresh Kumar | f47b72a | 2016-05-05 16:20:33 +0530 | [diff] [blame] | 31 | LIST_HEAD(opp_tables); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 32 | /* Lock to allow exclusive modification to the device and opp lists */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 33 | DEFINE_MUTEX(opp_table_lock); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 34 | |
Dmitry Torokhov | b02ded2 | 2014-12-16 15:09:36 -0800 | [diff] [blame] | 35 | #define opp_rcu_lockdep_assert() \ |
| 36 | do { \ |
Paul E. McKenney | f78f5b9 | 2015-06-18 15:50:02 -0700 | [diff] [blame] | 37 | RCU_LOCKDEP_WARN(!rcu_read_lock_held() && \ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 38 | !lockdep_is_held(&opp_table_lock), \ |
| 39 | "Missing rcu_read_lock() or " \ |
| 40 | "opp_table_lock protection"); \ |
Dmitry Torokhov | b02ded2 | 2014-12-16 15:09:36 -0800 | [diff] [blame] | 41 | } while (0) |
| 42 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 43 | static struct opp_device *_find_opp_dev(const struct device *dev, |
| 44 | struct opp_table *opp_table) |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 45 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 46 | struct opp_device *opp_dev; |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 47 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 48 | list_for_each_entry(opp_dev, &opp_table->dev_list, node) |
| 49 | if (opp_dev->dev == dev) |
| 50 | return opp_dev; |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 51 | |
| 52 | return NULL; |
| 53 | } |
| 54 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 55 | /** |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 56 | * _find_opp_table() - find opp_table struct using device pointer |
| 57 | * @dev: device pointer used to lookup OPP table |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 58 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 59 | * Search OPP table for one containing matching device. Does a RCU reader |
| 60 | * operation to grab the pointer needed. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 61 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 62 | * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 63 | * -EINVAL based on type of error. |
| 64 | * |
Viresh Kumar | 0597e81 | 2015-11-05 14:21:21 +0530 | [diff] [blame] | 65 | * Locking: For readers, this function must be called under rcu_read_lock(). |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 66 | * opp_table is a RCU protected pointer, which means that opp_table is valid |
Viresh Kumar | 0597e81 | 2015-11-05 14:21:21 +0530 | [diff] [blame] | 67 | * as long as we are under RCU lock. |
| 68 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 69 | * For Writers, this function must be called with opp_table_lock held. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 70 | */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 71 | struct opp_table *_find_opp_table(struct device *dev) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 72 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 73 | struct opp_table *opp_table; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 74 | |
Viresh Kumar | 0597e81 | 2015-11-05 14:21:21 +0530 | [diff] [blame] | 75 | opp_rcu_lockdep_assert(); |
| 76 | |
Viresh Kumar | 50a3cb0 | 2015-08-12 15:59:39 +0530 | [diff] [blame] | 77 | if (IS_ERR_OR_NULL(dev)) { |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 78 | pr_err("%s: Invalid parameters\n", __func__); |
| 79 | return ERR_PTR(-EINVAL); |
| 80 | } |
| 81 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 82 | list_for_each_entry_rcu(opp_table, &opp_tables, node) |
| 83 | if (_find_opp_dev(dev, opp_table)) |
| 84 | return opp_table; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 85 | |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 86 | return ERR_PTR(-ENODEV); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
Linus Torvalds | baf51c4 | 2015-11-11 09:03:01 -0800 | [diff] [blame] | 90 | * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 91 | * @opp: opp for which voltage has to be returned for |
| 92 | * |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 93 | * Return: voltage in micro volt corresponding to the opp, else |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 94 | * return 0 |
| 95 | * |
| 96 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| 97 | * protected pointer. This means that opp which could have been fetched by |
| 98 | * opp_find_freq_{exact,ceil,floor} functions is valid as long as we are |
| 99 | * under RCU lock. The pointer returned by the opp_find_freq family must be |
| 100 | * used in the same section as the usage of this function with the pointer |
| 101 | * prior to unlocking with rcu_read_unlock() to maintain the integrity of the |
| 102 | * pointer. |
| 103 | */ |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 104 | unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 105 | { |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 106 | struct dev_pm_opp *tmp_opp; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 107 | unsigned long v = 0; |
| 108 | |
Krzysztof Kozlowski | 04bf1c7 | 2015-01-09 09:27:57 +0100 | [diff] [blame] | 109 | opp_rcu_lockdep_assert(); |
| 110 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 111 | tmp_opp = rcu_dereference(opp); |
Linus Torvalds | baf51c4 | 2015-11-11 09:03:01 -0800 | [diff] [blame] | 112 | if (IS_ERR_OR_NULL(tmp_opp)) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 113 | pr_err("%s: Invalid parameters\n", __func__); |
| 114 | else |
| 115 | v = tmp_opp->u_volt; |
| 116 | |
| 117 | return v; |
| 118 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 119 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_voltage); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 120 | |
| 121 | /** |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 122 | * dev_pm_opp_get_freq() - Gets the frequency corresponding to an available opp |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 123 | * @opp: opp for which frequency has to be returned for |
| 124 | * |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 125 | * Return: frequency in hertz corresponding to the opp, else |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 126 | * return 0 |
| 127 | * |
| 128 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| 129 | * protected pointer. This means that opp which could have been fetched by |
| 130 | * opp_find_freq_{exact,ceil,floor} functions is valid as long as we are |
| 131 | * under RCU lock. The pointer returned by the opp_find_freq family must be |
| 132 | * used in the same section as the usage of this function with the pointer |
| 133 | * prior to unlocking with rcu_read_unlock() to maintain the integrity of the |
| 134 | * pointer. |
| 135 | */ |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 136 | unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 137 | { |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 138 | struct dev_pm_opp *tmp_opp; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 139 | unsigned long f = 0; |
| 140 | |
Krzysztof Kozlowski | 04bf1c7 | 2015-01-09 09:27:57 +0100 | [diff] [blame] | 141 | opp_rcu_lockdep_assert(); |
| 142 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 143 | tmp_opp = rcu_dereference(opp); |
Viresh Kumar | 50a3cb0 | 2015-08-12 15:59:39 +0530 | [diff] [blame] | 144 | if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 145 | pr_err("%s: Invalid parameters\n", __func__); |
| 146 | else |
| 147 | f = tmp_opp->rate; |
| 148 | |
| 149 | return f; |
| 150 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 151 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 152 | |
| 153 | /** |
Bartlomiej Zolnierkiewicz | 19445b2 | 2015-07-09 17:43:35 +0200 | [diff] [blame] | 154 | * dev_pm_opp_is_turbo() - Returns if opp is turbo OPP or not |
| 155 | * @opp: opp for which turbo mode is being verified |
| 156 | * |
| 157 | * Turbo OPPs are not for normal use, and can be enabled (under certain |
| 158 | * conditions) for short duration of times to finish high throughput work |
| 159 | * quickly. Running on them for longer times may overheat the chip. |
| 160 | * |
| 161 | * Return: true if opp is turbo opp, else false. |
| 162 | * |
| 163 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| 164 | * protected pointer. This means that opp which could have been fetched by |
| 165 | * opp_find_freq_{exact,ceil,floor} functions is valid as long as we are |
| 166 | * under RCU lock. The pointer returned by the opp_find_freq family must be |
| 167 | * used in the same section as the usage of this function with the pointer |
| 168 | * prior to unlocking with rcu_read_unlock() to maintain the integrity of the |
| 169 | * pointer. |
| 170 | */ |
| 171 | bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp) |
| 172 | { |
| 173 | struct dev_pm_opp *tmp_opp; |
| 174 | |
| 175 | opp_rcu_lockdep_assert(); |
| 176 | |
| 177 | tmp_opp = rcu_dereference(opp); |
| 178 | if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available) { |
| 179 | pr_err("%s: Invalid parameters\n", __func__); |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | return tmp_opp->turbo; |
| 184 | } |
| 185 | EXPORT_SYMBOL_GPL(dev_pm_opp_is_turbo); |
| 186 | |
| 187 | /** |
Viresh Kumar | 3ca9bb3 | 2015-07-29 16:23:03 +0530 | [diff] [blame] | 188 | * dev_pm_opp_get_max_clock_latency() - Get max clock latency in nanoseconds |
| 189 | * @dev: device for which we do this operation |
| 190 | * |
| 191 | * Return: This function returns the max clock latency in nanoseconds. |
| 192 | * |
| 193 | * Locking: This function takes rcu_read_lock(). |
| 194 | */ |
| 195 | unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev) |
| 196 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 197 | struct opp_table *opp_table; |
Viresh Kumar | 3ca9bb3 | 2015-07-29 16:23:03 +0530 | [diff] [blame] | 198 | unsigned long clock_latency_ns; |
| 199 | |
| 200 | rcu_read_lock(); |
| 201 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 202 | opp_table = _find_opp_table(dev); |
| 203 | if (IS_ERR(opp_table)) |
Viresh Kumar | 3ca9bb3 | 2015-07-29 16:23:03 +0530 | [diff] [blame] | 204 | clock_latency_ns = 0; |
| 205 | else |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 206 | clock_latency_ns = opp_table->clock_latency_ns_max; |
Viresh Kumar | 3ca9bb3 | 2015-07-29 16:23:03 +0530 | [diff] [blame] | 207 | |
| 208 | rcu_read_unlock(); |
| 209 | return clock_latency_ns; |
| 210 | } |
| 211 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_clock_latency); |
| 212 | |
| 213 | /** |
Viresh Kumar | 655c9df | 2016-02-09 10:30:35 +0530 | [diff] [blame] | 214 | * dev_pm_opp_get_max_volt_latency() - Get max voltage latency in nanoseconds |
| 215 | * @dev: device for which we do this operation |
| 216 | * |
| 217 | * Return: This function returns the max voltage latency in nanoseconds. |
| 218 | * |
| 219 | * Locking: This function takes rcu_read_lock(). |
| 220 | */ |
| 221 | unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev) |
| 222 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 223 | struct opp_table *opp_table; |
Viresh Kumar | 655c9df | 2016-02-09 10:30:35 +0530 | [diff] [blame] | 224 | struct dev_pm_opp *opp; |
| 225 | struct regulator *reg; |
| 226 | unsigned long latency_ns = 0; |
| 227 | unsigned long min_uV = ~0, max_uV = 0; |
| 228 | int ret; |
| 229 | |
| 230 | rcu_read_lock(); |
| 231 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 232 | opp_table = _find_opp_table(dev); |
| 233 | if (IS_ERR(opp_table)) { |
Viresh Kumar | 655c9df | 2016-02-09 10:30:35 +0530 | [diff] [blame] | 234 | rcu_read_unlock(); |
| 235 | return 0; |
| 236 | } |
| 237 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 238 | reg = opp_table->regulator; |
Viresh Kumar | 0c717d0 | 2016-02-15 21:56:42 +0530 | [diff] [blame] | 239 | if (IS_ERR(reg)) { |
Viresh Kumar | 655c9df | 2016-02-09 10:30:35 +0530 | [diff] [blame] | 240 | /* Regulator may not be required for device */ |
Viresh Kumar | 655c9df | 2016-02-09 10:30:35 +0530 | [diff] [blame] | 241 | rcu_read_unlock(); |
| 242 | return 0; |
| 243 | } |
| 244 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 245 | list_for_each_entry_rcu(opp, &opp_table->opp_list, node) { |
Viresh Kumar | 655c9df | 2016-02-09 10:30:35 +0530 | [diff] [blame] | 246 | if (!opp->available) |
| 247 | continue; |
| 248 | |
| 249 | if (opp->u_volt_min < min_uV) |
| 250 | min_uV = opp->u_volt_min; |
| 251 | if (opp->u_volt_max > max_uV) |
| 252 | max_uV = opp->u_volt_max; |
| 253 | } |
| 254 | |
| 255 | rcu_read_unlock(); |
| 256 | |
| 257 | /* |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 258 | * The caller needs to ensure that opp_table (and hence the regulator) |
Viresh Kumar | 655c9df | 2016-02-09 10:30:35 +0530 | [diff] [blame] | 259 | * isn't freed, while we are executing this routine. |
| 260 | */ |
| 261 | ret = regulator_set_voltage_time(reg, min_uV, max_uV); |
| 262 | if (ret > 0) |
| 263 | latency_ns = ret * 1000; |
| 264 | |
| 265 | return latency_ns; |
| 266 | } |
| 267 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_volt_latency); |
| 268 | |
| 269 | /** |
Viresh Kumar | 2174344 | 2016-02-09 10:30:36 +0530 | [diff] [blame] | 270 | * dev_pm_opp_get_max_transition_latency() - Get max transition latency in |
| 271 | * nanoseconds |
| 272 | * @dev: device for which we do this operation |
| 273 | * |
| 274 | * Return: This function returns the max transition latency, in nanoseconds, to |
| 275 | * switch from one OPP to other. |
| 276 | * |
| 277 | * Locking: This function takes rcu_read_lock(). |
| 278 | */ |
| 279 | unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev) |
| 280 | { |
| 281 | return dev_pm_opp_get_max_volt_latency(dev) + |
| 282 | dev_pm_opp_get_max_clock_latency(dev); |
| 283 | } |
| 284 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_transition_latency); |
| 285 | |
| 286 | /** |
Bartlomiej Zolnierkiewicz | 4eafbd1 | 2015-09-08 18:41:01 +0200 | [diff] [blame] | 287 | * dev_pm_opp_get_suspend_opp() - Get suspend opp |
| 288 | * @dev: device for which we do this operation |
| 289 | * |
| 290 | * Return: This function returns pointer to the suspend opp if it is |
Viresh Kumar | 1b2b90c | 2015-09-09 16:58:22 +0530 | [diff] [blame] | 291 | * defined and available, otherwise it returns NULL. |
Bartlomiej Zolnierkiewicz | 4eafbd1 | 2015-09-08 18:41:01 +0200 | [diff] [blame] | 292 | * |
| 293 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| 294 | * protected pointer. The reason for the same is that the opp pointer which is |
| 295 | * returned will remain valid for use with opp_get_{voltage, freq} only while |
| 296 | * under the locked area. The pointer returned must be used prior to unlocking |
| 297 | * with rcu_read_unlock() to maintain the integrity of the pointer. |
| 298 | */ |
| 299 | struct dev_pm_opp *dev_pm_opp_get_suspend_opp(struct device *dev) |
| 300 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 301 | struct opp_table *opp_table; |
Bartlomiej Zolnierkiewicz | 4eafbd1 | 2015-09-08 18:41:01 +0200 | [diff] [blame] | 302 | |
| 303 | opp_rcu_lockdep_assert(); |
| 304 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 305 | opp_table = _find_opp_table(dev); |
| 306 | if (IS_ERR(opp_table) || !opp_table->suspend_opp || |
| 307 | !opp_table->suspend_opp->available) |
Viresh Kumar | 1b2b90c | 2015-09-09 16:58:22 +0530 | [diff] [blame] | 308 | return NULL; |
Bartlomiej Zolnierkiewicz | 4eafbd1 | 2015-09-08 18:41:01 +0200 | [diff] [blame] | 309 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 310 | return opp_table->suspend_opp; |
Bartlomiej Zolnierkiewicz | 4eafbd1 | 2015-09-08 18:41:01 +0200 | [diff] [blame] | 311 | } |
| 312 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp); |
| 313 | |
| 314 | /** |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 315 | * dev_pm_opp_get_opp_count() - Get number of opps available in the opp table |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 316 | * @dev: device for which we do this operation |
| 317 | * |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 318 | * Return: This function returns the number of available opps if there are any, |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 319 | * else returns 0 if none or the corresponding error value. |
| 320 | * |
Dmitry Torokhov | b4718c0 | 2014-12-16 15:09:38 -0800 | [diff] [blame] | 321 | * Locking: This function takes rcu_read_lock(). |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 322 | */ |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 323 | int dev_pm_opp_get_opp_count(struct device *dev) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 324 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 325 | struct opp_table *opp_table; |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 326 | struct dev_pm_opp *temp_opp; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 327 | int count = 0; |
| 328 | |
Dmitry Torokhov | b4718c0 | 2014-12-16 15:09:38 -0800 | [diff] [blame] | 329 | rcu_read_lock(); |
Dmitry Torokhov | b02ded2 | 2014-12-16 15:09:36 -0800 | [diff] [blame] | 330 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 331 | opp_table = _find_opp_table(dev); |
| 332 | if (IS_ERR(opp_table)) { |
| 333 | count = PTR_ERR(opp_table); |
Fabio Estevam | c236525 | 2017-09-29 14:39:49 -0300 | [diff] [blame] | 334 | dev_dbg(dev, "%s: OPP table not found (%d)\n", |
Dmitry Torokhov | b4718c0 | 2014-12-16 15:09:38 -0800 | [diff] [blame] | 335 | __func__, count); |
| 336 | goto out_unlock; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 339 | list_for_each_entry_rcu(temp_opp, &opp_table->opp_list, node) { |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 340 | if (temp_opp->available) |
| 341 | count++; |
| 342 | } |
| 343 | |
Dmitry Torokhov | b4718c0 | 2014-12-16 15:09:38 -0800 | [diff] [blame] | 344 | out_unlock: |
| 345 | rcu_read_unlock(); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 346 | return count; |
| 347 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 348 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 349 | |
| 350 | /** |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 351 | * dev_pm_opp_find_freq_exact() - search for an exact frequency |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 352 | * @dev: device for which we do this operation |
| 353 | * @freq: frequency to search for |
Nishanth Menon | 7ae4961 | 2011-02-25 23:46:18 +0100 | [diff] [blame] | 354 | * @available: true/false - match for available opp |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 355 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 356 | * Return: Searches for exact match in the opp table and returns pointer to the |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 357 | * matching opp if found, else returns ERR_PTR in case of error and should |
| 358 | * be handled using IS_ERR. Error return values can be: |
Nishanth Menon | 0779726 | 2012-10-24 22:00:12 +0200 | [diff] [blame] | 359 | * EINVAL: for bad pointer |
| 360 | * ERANGE: no match found for search |
| 361 | * ENODEV: if device not found in list of registered devices |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 362 | * |
| 363 | * Note: available is a modifier for the search. if available=true, then the |
| 364 | * match is for exact matching frequency and is available in the stored OPP |
| 365 | * table. if false, the match is for exact frequency which is not available. |
| 366 | * |
| 367 | * This provides a mechanism to enable an opp which is not available currently |
| 368 | * or the opposite as well. |
| 369 | * |
| 370 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| 371 | * protected pointer. The reason for the same is that the opp pointer which is |
| 372 | * returned will remain valid for use with opp_get_{voltage, freq} only while |
| 373 | * under the locked area. The pointer returned must be used prior to unlocking |
| 374 | * with rcu_read_unlock() to maintain the integrity of the pointer. |
| 375 | */ |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 376 | struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, |
| 377 | unsigned long freq, |
| 378 | bool available) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 379 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 380 | struct opp_table *opp_table; |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 381 | struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 382 | |
Dmitry Torokhov | b02ded2 | 2014-12-16 15:09:36 -0800 | [diff] [blame] | 383 | opp_rcu_lockdep_assert(); |
| 384 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 385 | opp_table = _find_opp_table(dev); |
| 386 | if (IS_ERR(opp_table)) { |
| 387 | int r = PTR_ERR(opp_table); |
| 388 | |
| 389 | dev_err(dev, "%s: OPP table not found (%d)\n", __func__, r); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 390 | return ERR_PTR(r); |
| 391 | } |
| 392 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 393 | list_for_each_entry_rcu(temp_opp, &opp_table->opp_list, node) { |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 394 | if (temp_opp->available == available && |
| 395 | temp_opp->rate == freq) { |
| 396 | opp = temp_opp; |
| 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return opp; |
| 402 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 403 | EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 404 | |
Jisheng Zhang | 067b7ce | 2016-07-25 14:11:16 +0800 | [diff] [blame] | 405 | static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, |
| 406 | unsigned long *freq) |
| 407 | { |
| 408 | struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); |
| 409 | |
| 410 | list_for_each_entry_rcu(temp_opp, &opp_table->opp_list, node) { |
| 411 | if (temp_opp->available && temp_opp->rate >= *freq) { |
| 412 | opp = temp_opp; |
| 413 | *freq = opp->rate; |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | return opp; |
| 419 | } |
| 420 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 421 | /** |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 422 | * dev_pm_opp_find_freq_ceil() - Search for an rounded ceil freq |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 423 | * @dev: device for which we do this operation |
| 424 | * @freq: Start frequency |
| 425 | * |
| 426 | * Search for the matching ceil *available* OPP from a starting freq |
| 427 | * for a device. |
| 428 | * |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 429 | * Return: matching *opp and refreshes *freq accordingly, else returns |
Nishanth Menon | 0779726 | 2012-10-24 22:00:12 +0200 | [diff] [blame] | 430 | * ERR_PTR in case of error and should be handled using IS_ERR. Error return |
| 431 | * values can be: |
| 432 | * EINVAL: for bad pointer |
| 433 | * ERANGE: no match found for search |
| 434 | * ENODEV: if device not found in list of registered devices |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 435 | * |
| 436 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| 437 | * protected pointer. The reason for the same is that the opp pointer which is |
| 438 | * returned will remain valid for use with opp_get_{voltage, freq} only while |
| 439 | * under the locked area. The pointer returned must be used prior to unlocking |
| 440 | * with rcu_read_unlock() to maintain the integrity of the pointer. |
| 441 | */ |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 442 | struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, |
| 443 | unsigned long *freq) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 444 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 445 | struct opp_table *opp_table; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 446 | |
Dmitry Torokhov | b02ded2 | 2014-12-16 15:09:36 -0800 | [diff] [blame] | 447 | opp_rcu_lockdep_assert(); |
| 448 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 449 | if (!dev || !freq) { |
| 450 | dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq); |
| 451 | return ERR_PTR(-EINVAL); |
| 452 | } |
| 453 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 454 | opp_table = _find_opp_table(dev); |
| 455 | if (IS_ERR(opp_table)) |
| 456 | return ERR_CAST(opp_table); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 457 | |
Jisheng Zhang | 067b7ce | 2016-07-25 14:11:16 +0800 | [diff] [blame] | 458 | return _find_freq_ceil(opp_table, freq); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 459 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 460 | EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 461 | |
| 462 | /** |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 463 | * dev_pm_opp_find_freq_floor() - Search for a rounded floor freq |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 464 | * @dev: device for which we do this operation |
| 465 | * @freq: Start frequency |
| 466 | * |
| 467 | * Search for the matching floor *available* OPP from a starting freq |
| 468 | * for a device. |
| 469 | * |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 470 | * Return: matching *opp and refreshes *freq accordingly, else returns |
Nishanth Menon | 0779726 | 2012-10-24 22:00:12 +0200 | [diff] [blame] | 471 | * ERR_PTR in case of error and should be handled using IS_ERR. Error return |
| 472 | * values can be: |
| 473 | * EINVAL: for bad pointer |
| 474 | * ERANGE: no match found for search |
| 475 | * ENODEV: if device not found in list of registered devices |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 476 | * |
| 477 | * Locking: This function must be called under rcu_read_lock(). opp is a rcu |
| 478 | * protected pointer. The reason for the same is that the opp pointer which is |
| 479 | * returned will remain valid for use with opp_get_{voltage, freq} only while |
| 480 | * under the locked area. The pointer returned must be used prior to unlocking |
| 481 | * with rcu_read_unlock() to maintain the integrity of the pointer. |
| 482 | */ |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 483 | struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, |
| 484 | unsigned long *freq) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 485 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 486 | struct opp_table *opp_table; |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 487 | struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 488 | |
Dmitry Torokhov | b02ded2 | 2014-12-16 15:09:36 -0800 | [diff] [blame] | 489 | opp_rcu_lockdep_assert(); |
| 490 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 491 | if (!dev || !freq) { |
| 492 | dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq); |
| 493 | return ERR_PTR(-EINVAL); |
| 494 | } |
| 495 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 496 | opp_table = _find_opp_table(dev); |
| 497 | if (IS_ERR(opp_table)) |
| 498 | return ERR_CAST(opp_table); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 499 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 500 | list_for_each_entry_rcu(temp_opp, &opp_table->opp_list, node) { |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 501 | if (temp_opp->available) { |
| 502 | /* go to the next node, before choosing prev */ |
| 503 | if (temp_opp->rate > *freq) |
| 504 | break; |
| 505 | else |
| 506 | opp = temp_opp; |
| 507 | } |
| 508 | } |
| 509 | if (!IS_ERR(opp)) |
| 510 | *freq = opp->rate; |
| 511 | |
| 512 | return opp; |
| 513 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 514 | EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 515 | |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 516 | /* |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 517 | * The caller needs to ensure that opp_table (and hence the clk) isn't freed, |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 518 | * while clk returned here is used. |
| 519 | */ |
| 520 | static struct clk *_get_opp_clk(struct device *dev) |
| 521 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 522 | struct opp_table *opp_table; |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 523 | struct clk *clk; |
| 524 | |
| 525 | rcu_read_lock(); |
| 526 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 527 | opp_table = _find_opp_table(dev); |
| 528 | if (IS_ERR(opp_table)) { |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 529 | dev_err(dev, "%s: device opp doesn't exist\n", __func__); |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 530 | clk = ERR_CAST(opp_table); |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 531 | goto unlock; |
| 532 | } |
| 533 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 534 | clk = opp_table->clk; |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 535 | if (IS_ERR(clk)) |
| 536 | dev_err(dev, "%s: No clock available for the device\n", |
| 537 | __func__); |
| 538 | |
| 539 | unlock: |
| 540 | rcu_read_unlock(); |
| 541 | return clk; |
| 542 | } |
| 543 | |
| 544 | static int _set_opp_voltage(struct device *dev, struct regulator *reg, |
| 545 | unsigned long u_volt, unsigned long u_volt_min, |
| 546 | unsigned long u_volt_max) |
| 547 | { |
| 548 | int ret; |
| 549 | |
| 550 | /* Regulator not available for device */ |
| 551 | if (IS_ERR(reg)) { |
| 552 | dev_dbg(dev, "%s: regulator not available: %ld\n", __func__, |
| 553 | PTR_ERR(reg)); |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | dev_dbg(dev, "%s: voltages (mV): %lu %lu %lu\n", __func__, u_volt_min, |
| 558 | u_volt, u_volt_max); |
| 559 | |
| 560 | ret = regulator_set_voltage_triplet(reg, u_volt_min, u_volt, |
| 561 | u_volt_max); |
| 562 | if (ret) |
| 563 | dev_err(dev, "%s: failed to set voltage (%lu %lu %lu mV): %d\n", |
| 564 | __func__, u_volt_min, u_volt, u_volt_max, ret); |
| 565 | |
| 566 | return ret; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * dev_pm_opp_set_rate() - Configure new OPP based on frequency |
| 571 | * @dev: device for which we do this operation |
| 572 | * @target_freq: frequency to achieve |
| 573 | * |
| 574 | * This configures the power-supplies and clock source to the levels specified |
| 575 | * by the OPP corresponding to the target_freq. |
| 576 | * |
| 577 | * Locking: This function takes rcu_read_lock(). |
| 578 | */ |
| 579 | int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) |
| 580 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 581 | struct opp_table *opp_table; |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 582 | struct dev_pm_opp *old_opp, *opp; |
| 583 | struct regulator *reg; |
| 584 | struct clk *clk; |
| 585 | unsigned long freq, old_freq; |
| 586 | unsigned long u_volt, u_volt_min, u_volt_max; |
Viresh Kumar | 7ac62bc | 2016-12-01 16:28:16 +0530 | [diff] [blame] | 587 | unsigned long old_u_volt, old_u_volt_min, old_u_volt_max; |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 588 | int ret; |
| 589 | |
| 590 | if (unlikely(!target_freq)) { |
| 591 | dev_err(dev, "%s: Invalid target frequency %lu\n", __func__, |
| 592 | target_freq); |
| 593 | return -EINVAL; |
| 594 | } |
| 595 | |
| 596 | clk = _get_opp_clk(dev); |
| 597 | if (IS_ERR(clk)) |
| 598 | return PTR_ERR(clk); |
| 599 | |
| 600 | freq = clk_round_rate(clk, target_freq); |
| 601 | if ((long)freq <= 0) |
| 602 | freq = target_freq; |
| 603 | |
| 604 | old_freq = clk_get_rate(clk); |
| 605 | |
| 606 | /* Return early if nothing to do */ |
| 607 | if (old_freq == freq) { |
| 608 | dev_dbg(dev, "%s: old/new frequencies (%lu Hz) are same, nothing to do\n", |
| 609 | __func__, freq); |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | rcu_read_lock(); |
| 614 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 615 | opp_table = _find_opp_table(dev); |
| 616 | if (IS_ERR(opp_table)) { |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 617 | dev_err(dev, "%s: device opp doesn't exist\n", __func__); |
| 618 | rcu_read_unlock(); |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 619 | return PTR_ERR(opp_table); |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 620 | } |
| 621 | |
Jisheng Zhang | 067b7ce | 2016-07-25 14:11:16 +0800 | [diff] [blame] | 622 | old_opp = _find_freq_ceil(opp_table, &old_freq); |
Arnd Bergmann | 4df27c9 | 2016-09-15 17:38:38 +0200 | [diff] [blame] | 623 | if (IS_ERR(old_opp)) { |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 624 | dev_err(dev, "%s: failed to find current OPP for freq %lu (%ld)\n", |
| 625 | __func__, old_freq, PTR_ERR(old_opp)); |
| 626 | } |
| 627 | |
Jisheng Zhang | 067b7ce | 2016-07-25 14:11:16 +0800 | [diff] [blame] | 628 | opp = _find_freq_ceil(opp_table, &freq); |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 629 | if (IS_ERR(opp)) { |
| 630 | ret = PTR_ERR(opp); |
| 631 | dev_err(dev, "%s: failed to find OPP for freq %lu (%d)\n", |
| 632 | __func__, freq, ret); |
| 633 | rcu_read_unlock(); |
| 634 | return ret; |
| 635 | } |
| 636 | |
Viresh Kumar | 7ac62bc | 2016-12-01 16:28:16 +0530 | [diff] [blame] | 637 | if (IS_ERR(old_opp)) { |
| 638 | old_u_volt = 0; |
| 639 | } else { |
| 640 | old_u_volt = old_opp->u_volt; |
| 641 | old_u_volt_min = old_opp->u_volt_min; |
| 642 | old_u_volt_max = old_opp->u_volt_max; |
| 643 | } |
| 644 | |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 645 | u_volt = opp->u_volt; |
| 646 | u_volt_min = opp->u_volt_min; |
| 647 | u_volt_max = opp->u_volt_max; |
| 648 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 649 | reg = opp_table->regulator; |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 650 | |
| 651 | rcu_read_unlock(); |
| 652 | |
| 653 | /* Scaling up? Scale voltage before frequency */ |
| 654 | if (freq > old_freq) { |
| 655 | ret = _set_opp_voltage(dev, reg, u_volt, u_volt_min, |
| 656 | u_volt_max); |
| 657 | if (ret) |
| 658 | goto restore_voltage; |
| 659 | } |
| 660 | |
| 661 | /* Change frequency */ |
| 662 | |
| 663 | dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", |
| 664 | __func__, old_freq, freq); |
| 665 | |
| 666 | ret = clk_set_rate(clk, freq); |
| 667 | if (ret) { |
| 668 | dev_err(dev, "%s: failed to set clock rate: %d\n", __func__, |
| 669 | ret); |
| 670 | goto restore_voltage; |
| 671 | } |
| 672 | |
| 673 | /* Scaling down? Scale voltage after frequency */ |
| 674 | if (freq < old_freq) { |
| 675 | ret = _set_opp_voltage(dev, reg, u_volt, u_volt_min, |
| 676 | u_volt_max); |
| 677 | if (ret) |
| 678 | goto restore_freq; |
| 679 | } |
| 680 | |
| 681 | return 0; |
| 682 | |
| 683 | restore_freq: |
| 684 | if (clk_set_rate(clk, old_freq)) |
| 685 | dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", |
| 686 | __func__, old_freq); |
| 687 | restore_voltage: |
| 688 | /* This shouldn't harm even if the voltages weren't updated earlier */ |
Viresh Kumar | 7ac62bc | 2016-12-01 16:28:16 +0530 | [diff] [blame] | 689 | if (old_u_volt) { |
| 690 | _set_opp_voltage(dev, reg, old_u_volt, old_u_volt_min, |
| 691 | old_u_volt_max); |
| 692 | } |
Viresh Kumar | 6a0712f | 2016-02-09 10:30:39 +0530 | [diff] [blame] | 693 | |
| 694 | return ret; |
| 695 | } |
| 696 | EXPORT_SYMBOL_GPL(dev_pm_opp_set_rate); |
| 697 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 698 | /* OPP-dev Helpers */ |
| 699 | static void _kfree_opp_dev_rcu(struct rcu_head *head) |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 700 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 701 | struct opp_device *opp_dev; |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 702 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 703 | opp_dev = container_of(head, struct opp_device, rcu_head); |
| 704 | kfree_rcu(opp_dev, rcu_head); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 705 | } |
| 706 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 707 | static void _remove_opp_dev(struct opp_device *opp_dev, |
| 708 | struct opp_table *opp_table) |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 709 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 710 | opp_debug_unregister(opp_dev, opp_table); |
| 711 | list_del(&opp_dev->node); |
| 712 | call_srcu(&opp_table->srcu_head.srcu, &opp_dev->rcu_head, |
| 713 | _kfree_opp_dev_rcu); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 714 | } |
| 715 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 716 | struct opp_device *_add_opp_dev(const struct device *dev, |
| 717 | struct opp_table *opp_table) |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 718 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 719 | struct opp_device *opp_dev; |
Viresh Kumar | deaa514 | 2015-11-11 07:59:01 +0530 | [diff] [blame] | 720 | int ret; |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 721 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 722 | opp_dev = kzalloc(sizeof(*opp_dev), GFP_KERNEL); |
| 723 | if (!opp_dev) |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 724 | return NULL; |
| 725 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 726 | /* Initialize opp-dev */ |
| 727 | opp_dev->dev = dev; |
| 728 | list_add_rcu(&opp_dev->node, &opp_table->dev_list); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 729 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 730 | /* Create debugfs entries for the opp_table */ |
| 731 | ret = opp_debug_register(opp_dev, opp_table); |
Viresh Kumar | deaa514 | 2015-11-11 07:59:01 +0530 | [diff] [blame] | 732 | if (ret) |
| 733 | dev_err(dev, "%s: Failed to register opp debugfs (%d)\n", |
| 734 | __func__, ret); |
| 735 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 736 | return opp_dev; |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 737 | } |
| 738 | |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 739 | /** |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 740 | * _add_opp_table() - Find OPP table or allocate a new one |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 741 | * @dev: device for which we do this operation |
| 742 | * |
Viresh Kumar | aa5f2f8 | 2015-07-29 16:23:00 +0530 | [diff] [blame] | 743 | * It tries to find an existing table first, if it couldn't find one, it |
| 744 | * allocates a new OPP table and returns that. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 745 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 746 | * Return: valid opp_table pointer if success, else NULL. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 747 | */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 748 | static struct opp_table *_add_opp_table(struct device *dev) |
Viresh Kumar | 07cce74 | 2014-12-10 09:45:34 +0530 | [diff] [blame] | 749 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 750 | struct opp_table *opp_table; |
| 751 | struct opp_device *opp_dev; |
Viresh Kumar | d54974c | 2016-02-09 10:30:38 +0530 | [diff] [blame] | 752 | int ret; |
Viresh Kumar | 07cce74 | 2014-12-10 09:45:34 +0530 | [diff] [blame] | 753 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 754 | /* Check for existing table for 'dev' first */ |
| 755 | opp_table = _find_opp_table(dev); |
| 756 | if (!IS_ERR(opp_table)) |
| 757 | return opp_table; |
Viresh Kumar | 07cce74 | 2014-12-10 09:45:34 +0530 | [diff] [blame] | 758 | |
| 759 | /* |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 760 | * Allocate a new OPP table. In the infrequent case where a new |
Viresh Kumar | 07cce74 | 2014-12-10 09:45:34 +0530 | [diff] [blame] | 761 | * device is needed to be added, we pay this penalty. |
| 762 | */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 763 | opp_table = kzalloc(sizeof(*opp_table), GFP_KERNEL); |
| 764 | if (!opp_table) |
Viresh Kumar | 07cce74 | 2014-12-10 09:45:34 +0530 | [diff] [blame] | 765 | return NULL; |
| 766 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 767 | INIT_LIST_HEAD(&opp_table->dev_list); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 768 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 769 | opp_dev = _add_opp_dev(dev, opp_table); |
| 770 | if (!opp_dev) { |
| 771 | kfree(opp_table); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 772 | return NULL; |
| 773 | } |
| 774 | |
Viresh Kumar | f47b72a | 2016-05-05 16:20:33 +0530 | [diff] [blame] | 775 | _of_init_opp_table(opp_table, dev); |
Viresh Kumar | 50f8cfb | 2016-02-09 10:30:37 +0530 | [diff] [blame] | 776 | |
Viresh Kumar | 0c717d0 | 2016-02-15 21:56:42 +0530 | [diff] [blame] | 777 | /* Set regulator to a non-NULL error value */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 778 | opp_table->regulator = ERR_PTR(-ENXIO); |
Viresh Kumar | 0c717d0 | 2016-02-15 21:56:42 +0530 | [diff] [blame] | 779 | |
Viresh Kumar | d54974c | 2016-02-09 10:30:38 +0530 | [diff] [blame] | 780 | /* Find clk for the device */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 781 | opp_table->clk = clk_get(dev, NULL); |
| 782 | if (IS_ERR(opp_table->clk)) { |
| 783 | ret = PTR_ERR(opp_table->clk); |
Viresh Kumar | d54974c | 2016-02-09 10:30:38 +0530 | [diff] [blame] | 784 | if (ret != -EPROBE_DEFER) |
| 785 | dev_dbg(dev, "%s: Couldn't find clock: %d\n", __func__, |
| 786 | ret); |
| 787 | } |
| 788 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 789 | srcu_init_notifier_head(&opp_table->srcu_head); |
| 790 | INIT_LIST_HEAD(&opp_table->opp_list); |
Viresh Kumar | 07cce74 | 2014-12-10 09:45:34 +0530 | [diff] [blame] | 791 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 792 | /* Secure the device table modification */ |
| 793 | list_add_rcu(&opp_table->node, &opp_tables); |
| 794 | return opp_table; |
Viresh Kumar | 07cce74 | 2014-12-10 09:45:34 +0530 | [diff] [blame] | 795 | } |
| 796 | |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 797 | /** |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 798 | * _kfree_device_rcu() - Free opp_table RCU handler |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 799 | * @head: RCU head |
| 800 | */ |
Nishanth Menon | 327854c | 2014-12-24 11:22:56 -0600 | [diff] [blame] | 801 | static void _kfree_device_rcu(struct rcu_head *head) |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 802 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 803 | struct opp_table *opp_table = container_of(head, struct opp_table, |
| 804 | rcu_head); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 805 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 806 | kfree_rcu(opp_table, rcu_head); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 807 | } |
| 808 | |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 809 | /** |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 810 | * _remove_opp_table() - Removes a OPP table |
| 811 | * @opp_table: OPP table to be removed. |
Viresh Kumar | 3bac42c | 2015-07-29 16:22:59 +0530 | [diff] [blame] | 812 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 813 | * Removes/frees OPP table if it doesn't contain any OPPs. |
Viresh Kumar | 3bac42c | 2015-07-29 16:22:59 +0530 | [diff] [blame] | 814 | */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 815 | static void _remove_opp_table(struct opp_table *opp_table) |
Viresh Kumar | 3bac42c | 2015-07-29 16:22:59 +0530 | [diff] [blame] | 816 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 817 | struct opp_device *opp_dev; |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 818 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 819 | if (!list_empty(&opp_table->opp_list)) |
Viresh Kumar | 3bac42c | 2015-07-29 16:22:59 +0530 | [diff] [blame] | 820 | return; |
| 821 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 822 | if (opp_table->supported_hw) |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 823 | return; |
| 824 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 825 | if (opp_table->prop_name) |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 826 | return; |
| 827 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 828 | if (!IS_ERR(opp_table->regulator)) |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 829 | return; |
| 830 | |
Viresh Kumar | d54974c | 2016-02-09 10:30:38 +0530 | [diff] [blame] | 831 | /* Release clk */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 832 | if (!IS_ERR(opp_table->clk)) |
| 833 | clk_put(opp_table->clk); |
Viresh Kumar | d54974c | 2016-02-09 10:30:38 +0530 | [diff] [blame] | 834 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 835 | opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, |
| 836 | node); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 837 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 838 | _remove_opp_dev(opp_dev, opp_table); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 839 | |
| 840 | /* dev_list must be empty now */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 841 | WARN_ON(!list_empty(&opp_table->dev_list)); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 842 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 843 | list_del_rcu(&opp_table->node); |
| 844 | call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head, |
Viresh Kumar | 3bac42c | 2015-07-29 16:22:59 +0530 | [diff] [blame] | 845 | _kfree_device_rcu); |
| 846 | } |
| 847 | |
| 848 | /** |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 849 | * _kfree_opp_rcu() - Free OPP RCU handler |
| 850 | * @head: RCU head |
| 851 | */ |
| 852 | static void _kfree_opp_rcu(struct rcu_head *head) |
| 853 | { |
| 854 | struct dev_pm_opp *opp = container_of(head, struct dev_pm_opp, rcu_head); |
| 855 | |
| 856 | kfree_rcu(opp, rcu_head); |
| 857 | } |
| 858 | |
| 859 | /** |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 860 | * _opp_remove() - Remove an OPP from a table definition |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 861 | * @opp_table: points back to the opp_table struct this opp belongs to |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 862 | * @opp: pointer to the OPP to remove |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 863 | * @notify: OPP_EVENT_REMOVE notification should be sent or not |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 864 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 865 | * This function removes an opp definition from the opp table. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 866 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 867 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 868 | * It is assumed that the caller holds required mutex for an RCU updater |
| 869 | * strategy. |
| 870 | */ |
Viresh Kumar | f47b72a | 2016-05-05 16:20:33 +0530 | [diff] [blame] | 871 | void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp, |
| 872 | bool notify) |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 873 | { |
| 874 | /* |
| 875 | * Notify the changes in the availability of the operable |
| 876 | * frequency/voltage list. |
| 877 | */ |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 878 | if (notify) |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 879 | srcu_notifier_call_chain(&opp_table->srcu_head, |
| 880 | OPP_EVENT_REMOVE, opp); |
Viresh Kumar | deaa514 | 2015-11-11 07:59:01 +0530 | [diff] [blame] | 881 | opp_debug_remove_one(opp); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 882 | list_del_rcu(&opp->node); |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 883 | call_srcu(&opp_table->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 884 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 885 | _remove_opp_table(opp_table); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | /** |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 889 | * dev_pm_opp_remove() - Remove an OPP from OPP table |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 890 | * @dev: device for which we do this operation |
| 891 | * @freq: OPP to remove with matching 'freq' |
| 892 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 893 | * This function removes an opp from the opp table. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 894 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 895 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 896 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 897 | * to keep the integrity of the internal data structures. Callers should ensure |
| 898 | * that this function is *NOT* called under RCU protection or in contexts where |
| 899 | * mutex cannot be locked. |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 900 | */ |
| 901 | void dev_pm_opp_remove(struct device *dev, unsigned long freq) |
| 902 | { |
| 903 | struct dev_pm_opp *opp; |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 904 | struct opp_table *opp_table; |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 905 | bool found = false; |
| 906 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 907 | /* Hold our table modification lock here */ |
| 908 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 909 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 910 | opp_table = _find_opp_table(dev); |
| 911 | if (IS_ERR(opp_table)) |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 912 | goto unlock; |
| 913 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 914 | list_for_each_entry(opp, &opp_table->opp_list, node) { |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 915 | if (opp->rate == freq) { |
| 916 | found = true; |
| 917 | break; |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | if (!found) { |
| 922 | dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n", |
| 923 | __func__, freq); |
| 924 | goto unlock; |
| 925 | } |
| 926 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 927 | _opp_remove(opp_table, opp, true); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 928 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 929 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 930 | } |
| 931 | EXPORT_SYMBOL_GPL(dev_pm_opp_remove); |
| 932 | |
Viresh Kumar | f47b72a | 2016-05-05 16:20:33 +0530 | [diff] [blame] | 933 | struct dev_pm_opp *_allocate_opp(struct device *dev, |
| 934 | struct opp_table **opp_table) |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 935 | { |
| 936 | struct dev_pm_opp *opp; |
| 937 | |
| 938 | /* allocate new OPP node */ |
| 939 | opp = kzalloc(sizeof(*opp), GFP_KERNEL); |
| 940 | if (!opp) |
| 941 | return NULL; |
| 942 | |
| 943 | INIT_LIST_HEAD(&opp->node); |
| 944 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 945 | *opp_table = _add_opp_table(dev); |
| 946 | if (!*opp_table) { |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 947 | kfree(opp); |
| 948 | return NULL; |
| 949 | } |
| 950 | |
| 951 | return opp; |
| 952 | } |
| 953 | |
Viresh Kumar | 7d34d56 | 2016-02-09 10:30:34 +0530 | [diff] [blame] | 954 | static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 955 | struct opp_table *opp_table) |
Viresh Kumar | 7d34d56 | 2016-02-09 10:30:34 +0530 | [diff] [blame] | 956 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 957 | struct regulator *reg = opp_table->regulator; |
Viresh Kumar | 7d34d56 | 2016-02-09 10:30:34 +0530 | [diff] [blame] | 958 | |
Viresh Kumar | 0c717d0 | 2016-02-15 21:56:42 +0530 | [diff] [blame] | 959 | if (!IS_ERR(reg) && |
Viresh Kumar | 7d34d56 | 2016-02-09 10:30:34 +0530 | [diff] [blame] | 960 | !regulator_is_supported_voltage(reg, opp->u_volt_min, |
| 961 | opp->u_volt_max)) { |
| 962 | pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n", |
| 963 | __func__, opp->u_volt_min, opp->u_volt_max); |
| 964 | return false; |
| 965 | } |
| 966 | |
| 967 | return true; |
| 968 | } |
| 969 | |
Viresh Kumar | f47b72a | 2016-05-05 16:20:33 +0530 | [diff] [blame] | 970 | int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, |
| 971 | struct opp_table *opp_table) |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 972 | { |
| 973 | struct dev_pm_opp *opp; |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 974 | struct list_head *head = &opp_table->opp_list; |
Viresh Kumar | deaa514 | 2015-11-11 07:59:01 +0530 | [diff] [blame] | 975 | int ret; |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 976 | |
| 977 | /* |
| 978 | * Insert new OPP in order of increasing frequency and discard if |
| 979 | * already present. |
| 980 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 981 | * Need to use &opp_table->opp_list in the condition part of the 'for' |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 982 | * loop, don't replace it with head otherwise it will become an infinite |
| 983 | * loop. |
| 984 | */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 985 | list_for_each_entry_rcu(opp, &opp_table->opp_list, node) { |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 986 | if (new_opp->rate > opp->rate) { |
| 987 | head = &opp->node; |
| 988 | continue; |
| 989 | } |
| 990 | |
| 991 | if (new_opp->rate < opp->rate) |
| 992 | break; |
| 993 | |
| 994 | /* Duplicate OPPs */ |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 995 | dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n", |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 996 | __func__, opp->rate, opp->u_volt, opp->available, |
| 997 | new_opp->rate, new_opp->u_volt, new_opp->available); |
| 998 | |
| 999 | return opp->available && new_opp->u_volt == opp->u_volt ? |
| 1000 | 0 : -EEXIST; |
| 1001 | } |
| 1002 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1003 | new_opp->opp_table = opp_table; |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 1004 | list_add_rcu(&new_opp->node, head); |
| 1005 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1006 | ret = opp_debug_create_one(new_opp, opp_table); |
Viresh Kumar | deaa514 | 2015-11-11 07:59:01 +0530 | [diff] [blame] | 1007 | if (ret) |
| 1008 | dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n", |
| 1009 | __func__, ret); |
| 1010 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1011 | if (!_opp_supported_by_regulators(new_opp, opp_table)) { |
Viresh Kumar | 7d34d56 | 2016-02-09 10:30:34 +0530 | [diff] [blame] | 1012 | new_opp->available = false; |
| 1013 | dev_warn(dev, "%s: OPP not supported by regulators (%lu)\n", |
| 1014 | __func__, new_opp->rate); |
| 1015 | } |
| 1016 | |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1020 | /** |
Viresh Kumar | b64b9c3 | 2015-10-15 21:42:44 +0530 | [diff] [blame] | 1021 | * _opp_add_v1() - Allocate a OPP based on v1 bindings. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1022 | * @dev: device for which we do this operation |
| 1023 | * @freq: Frequency in Hz for this OPP |
| 1024 | * @u_volt: Voltage in uVolts for this OPP |
| 1025 | * @dynamic: Dynamically added OPPs. |
| 1026 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1027 | * This function adds an opp definition to the opp table and returns status. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1028 | * The opp is made available by default and it can be controlled using |
| 1029 | * dev_pm_opp_enable/disable functions and may be removed by dev_pm_opp_remove. |
| 1030 | * |
Viresh Kumar | 8f8d37b | 2015-09-04 13:47:24 +0530 | [diff] [blame] | 1031 | * NOTE: "dynamic" parameter impacts OPPs added by the dev_pm_opp_of_add_table |
| 1032 | * and freed by dev_pm_opp_of_remove_table. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1033 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1034 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1035 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1036 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1037 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1038 | * mutex cannot be locked. |
| 1039 | * |
| 1040 | * Return: |
| 1041 | * 0 On success OR |
| 1042 | * Duplicate OPPs (both freq and volt are same) and opp->available |
| 1043 | * -EEXIST Freq are same and volt are different OR |
| 1044 | * Duplicate OPPs (both freq and volt are same) and !opp->available |
| 1045 | * -ENOMEM Memory allocation failure |
| 1046 | */ |
Viresh Kumar | f47b72a | 2016-05-05 16:20:33 +0530 | [diff] [blame] | 1047 | int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, |
| 1048 | bool dynamic) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1049 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1050 | struct opp_table *opp_table; |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 1051 | struct dev_pm_opp *new_opp; |
Viresh Kumar | 50f8cfb | 2016-02-09 10:30:37 +0530 | [diff] [blame] | 1052 | unsigned long tol; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1053 | int ret; |
| 1054 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1055 | /* Hold our table modification lock here */ |
| 1056 | mutex_lock(&opp_table_lock); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1057 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1058 | new_opp = _allocate_opp(dev, &opp_table); |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 1059 | if (!new_opp) { |
| 1060 | ret = -ENOMEM; |
| 1061 | goto unlock; |
| 1062 | } |
| 1063 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1064 | /* populate the opp table */ |
| 1065 | new_opp->rate = freq; |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1066 | tol = u_volt * opp_table->voltage_tolerance_v1 / 100; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1067 | new_opp->u_volt = u_volt; |
Viresh Kumar | 50f8cfb | 2016-02-09 10:30:37 +0530 | [diff] [blame] | 1068 | new_opp->u_volt_min = u_volt - tol; |
| 1069 | new_opp->u_volt_max = u_volt + tol; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1070 | new_opp->available = true; |
Viresh Kumar | aa5f2f8 | 2015-07-29 16:23:00 +0530 | [diff] [blame] | 1071 | new_opp->dynamic = dynamic; |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 1072 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1073 | ret = _opp_add(dev, new_opp, opp_table); |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 1074 | if (ret) |
| 1075 | goto free_opp; |
| 1076 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1077 | mutex_unlock(&opp_table_lock); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1078 | |
| 1079 | /* |
| 1080 | * Notify the changes in the availability of the operable |
| 1081 | * frequency/voltage list. |
| 1082 | */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1083 | srcu_notifier_call_chain(&opp_table->srcu_head, OPP_EVENT_ADD, new_opp); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1084 | return 0; |
| 1085 | |
| 1086 | free_opp: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1087 | _opp_remove(opp_table, new_opp, false); |
Viresh Kumar | 23dacf6 | 2015-07-29 16:23:01 +0530 | [diff] [blame] | 1088 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1089 | mutex_unlock(&opp_table_lock); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1090 | return ret; |
| 1091 | } |
Viresh Kumar | 38393409 | 2014-11-25 16:04:18 +0530 | [diff] [blame] | 1092 | |
Viresh Kumar | 2746590 | 2015-07-29 16:23:02 +0530 | [diff] [blame] | 1093 | /** |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1094 | * dev_pm_opp_set_supported_hw() - Set supported platforms |
| 1095 | * @dev: Device for which supported-hw has to be set. |
| 1096 | * @versions: Array of hierarchy of versions to match. |
| 1097 | * @count: Number of elements in the array. |
| 1098 | * |
| 1099 | * This is required only for the V2 bindings, and it enables a platform to |
| 1100 | * specify the hierarchy of versions it supports. OPP layer will then enable |
| 1101 | * OPPs, which are available for those versions, based on its 'opp-supported-hw' |
| 1102 | * property. |
| 1103 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1104 | * Locking: The internal opp_table and opp structures are RCU protected. |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1105 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1106 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1107 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1108 | * mutex cannot be locked. |
| 1109 | */ |
| 1110 | int dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, |
| 1111 | unsigned int count) |
| 1112 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1113 | struct opp_table *opp_table; |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1114 | int ret = 0; |
| 1115 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1116 | /* Hold our table modification lock here */ |
| 1117 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1118 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1119 | opp_table = _add_opp_table(dev); |
| 1120 | if (!opp_table) { |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1121 | ret = -ENOMEM; |
| 1122 | goto unlock; |
| 1123 | } |
| 1124 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1125 | /* Make sure there are no concurrent readers while updating opp_table */ |
| 1126 | WARN_ON(!list_empty(&opp_table->opp_list)); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1127 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1128 | /* Do we already have a version hierarchy associated with opp_table? */ |
| 1129 | if (opp_table->supported_hw) { |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1130 | dev_err(dev, "%s: Already have supported hardware list\n", |
| 1131 | __func__); |
| 1132 | ret = -EBUSY; |
| 1133 | goto err; |
| 1134 | } |
| 1135 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1136 | opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions), |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1137 | GFP_KERNEL); |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1138 | if (!opp_table->supported_hw) { |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1139 | ret = -ENOMEM; |
| 1140 | goto err; |
| 1141 | } |
| 1142 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1143 | opp_table->supported_hw_count = count; |
| 1144 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1145 | return 0; |
| 1146 | |
| 1147 | err: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1148 | _remove_opp_table(opp_table); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1149 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1150 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1151 | |
| 1152 | return ret; |
| 1153 | } |
| 1154 | EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw); |
| 1155 | |
| 1156 | /** |
| 1157 | * dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw |
Viresh Kumar | a5da644 | 2016-02-16 14:17:52 +0530 | [diff] [blame] | 1158 | * @dev: Device for which supported-hw has to be put. |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1159 | * |
| 1160 | * This is required only for the V2 bindings, and is called for a matching |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1161 | * dev_pm_opp_set_supported_hw(). Until this is called, the opp_table structure |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1162 | * will not be freed. |
| 1163 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1164 | * Locking: The internal opp_table and opp structures are RCU protected. |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1165 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1166 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1167 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1168 | * mutex cannot be locked. |
| 1169 | */ |
| 1170 | void dev_pm_opp_put_supported_hw(struct device *dev) |
| 1171 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1172 | struct opp_table *opp_table; |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1173 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1174 | /* Hold our table modification lock here */ |
| 1175 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1176 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1177 | /* Check for existing table for 'dev' first */ |
| 1178 | opp_table = _find_opp_table(dev); |
| 1179 | if (IS_ERR(opp_table)) { |
| 1180 | dev_err(dev, "Failed to find opp_table: %ld\n", |
| 1181 | PTR_ERR(opp_table)); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1182 | goto unlock; |
| 1183 | } |
| 1184 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1185 | /* Make sure there are no concurrent readers while updating opp_table */ |
| 1186 | WARN_ON(!list_empty(&opp_table->opp_list)); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1187 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1188 | if (!opp_table->supported_hw) { |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1189 | dev_err(dev, "%s: Doesn't have supported hardware list\n", |
| 1190 | __func__); |
| 1191 | goto unlock; |
| 1192 | } |
| 1193 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1194 | kfree(opp_table->supported_hw); |
| 1195 | opp_table->supported_hw = NULL; |
| 1196 | opp_table->supported_hw_count = 0; |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1197 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1198 | /* Try freeing opp_table if this was the last blocking resource */ |
| 1199 | _remove_opp_table(opp_table); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1200 | |
| 1201 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1202 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 7de36b0 | 2015-12-09 08:01:46 +0530 | [diff] [blame] | 1203 | } |
| 1204 | EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); |
| 1205 | |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1206 | /** |
| 1207 | * dev_pm_opp_set_prop_name() - Set prop-extn name |
Viresh Kumar | a5da644 | 2016-02-16 14:17:52 +0530 | [diff] [blame] | 1208 | * @dev: Device for which the prop-name has to be set. |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1209 | * @name: name to postfix to properties. |
| 1210 | * |
| 1211 | * This is required only for the V2 bindings, and it enables a platform to |
| 1212 | * specify the extn to be used for certain property names. The properties to |
| 1213 | * which the extension will apply are opp-microvolt and opp-microamp. OPP core |
| 1214 | * should postfix the property name with -<name> while looking for them. |
| 1215 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1216 | * Locking: The internal opp_table and opp structures are RCU protected. |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1217 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1218 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1219 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1220 | * mutex cannot be locked. |
| 1221 | */ |
| 1222 | int dev_pm_opp_set_prop_name(struct device *dev, const char *name) |
| 1223 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1224 | struct opp_table *opp_table; |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1225 | int ret = 0; |
| 1226 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1227 | /* Hold our table modification lock here */ |
| 1228 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1229 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1230 | opp_table = _add_opp_table(dev); |
| 1231 | if (!opp_table) { |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1232 | ret = -ENOMEM; |
| 1233 | goto unlock; |
| 1234 | } |
| 1235 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1236 | /* Make sure there are no concurrent readers while updating opp_table */ |
| 1237 | WARN_ON(!list_empty(&opp_table->opp_list)); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1238 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1239 | /* Do we already have a prop-name associated with opp_table? */ |
| 1240 | if (opp_table->prop_name) { |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1241 | dev_err(dev, "%s: Already have prop-name %s\n", __func__, |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1242 | opp_table->prop_name); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1243 | ret = -EBUSY; |
| 1244 | goto err; |
| 1245 | } |
| 1246 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1247 | opp_table->prop_name = kstrdup(name, GFP_KERNEL); |
| 1248 | if (!opp_table->prop_name) { |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1249 | ret = -ENOMEM; |
| 1250 | goto err; |
| 1251 | } |
| 1252 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1253 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1254 | return 0; |
| 1255 | |
| 1256 | err: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1257 | _remove_opp_table(opp_table); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1258 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1259 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1260 | |
| 1261 | return ret; |
| 1262 | } |
| 1263 | EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name); |
| 1264 | |
| 1265 | /** |
| 1266 | * dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name |
Viresh Kumar | a5da644 | 2016-02-16 14:17:52 +0530 | [diff] [blame] | 1267 | * @dev: Device for which the prop-name has to be put. |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1268 | * |
| 1269 | * This is required only for the V2 bindings, and is called for a matching |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1270 | * dev_pm_opp_set_prop_name(). Until this is called, the opp_table structure |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1271 | * will not be freed. |
| 1272 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1273 | * Locking: The internal opp_table and opp structures are RCU protected. |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1274 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1275 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1276 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1277 | * mutex cannot be locked. |
| 1278 | */ |
| 1279 | void dev_pm_opp_put_prop_name(struct device *dev) |
| 1280 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1281 | struct opp_table *opp_table; |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1282 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1283 | /* Hold our table modification lock here */ |
| 1284 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1285 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1286 | /* Check for existing table for 'dev' first */ |
| 1287 | opp_table = _find_opp_table(dev); |
| 1288 | if (IS_ERR(opp_table)) { |
| 1289 | dev_err(dev, "Failed to find opp_table: %ld\n", |
| 1290 | PTR_ERR(opp_table)); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1291 | goto unlock; |
| 1292 | } |
| 1293 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1294 | /* Make sure there are no concurrent readers while updating opp_table */ |
| 1295 | WARN_ON(!list_empty(&opp_table->opp_list)); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1296 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1297 | if (!opp_table->prop_name) { |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1298 | dev_err(dev, "%s: Doesn't have a prop-name\n", __func__); |
| 1299 | goto unlock; |
| 1300 | } |
| 1301 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1302 | kfree(opp_table->prop_name); |
| 1303 | opp_table->prop_name = NULL; |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1304 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1305 | /* Try freeing opp_table if this was the last blocking resource */ |
| 1306 | _remove_opp_table(opp_table); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1307 | |
| 1308 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1309 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 01fb4d3 | 2015-12-09 08:01:47 +0530 | [diff] [blame] | 1310 | } |
| 1311 | EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name); |
| 1312 | |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1313 | /** |
| 1314 | * dev_pm_opp_set_regulator() - Set regulator name for the device |
| 1315 | * @dev: Device for which regulator name is being set. |
| 1316 | * @name: Name of the regulator. |
| 1317 | * |
| 1318 | * In order to support OPP switching, OPP layer needs to know the name of the |
| 1319 | * device's regulator, as the core would be required to switch voltages as well. |
| 1320 | * |
| 1321 | * This must be called before any OPPs are initialized for the device. |
| 1322 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1323 | * Locking: The internal opp_table and opp structures are RCU protected. |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1324 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1325 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1326 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1327 | * mutex cannot be locked. |
| 1328 | */ |
Stephen Boyd | c7a8a0a | 2016-11-30 16:21:25 +0530 | [diff] [blame] | 1329 | struct opp_table *dev_pm_opp_set_regulator(struct device *dev, const char *name) |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1330 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1331 | struct opp_table *opp_table; |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1332 | struct regulator *reg; |
| 1333 | int ret; |
| 1334 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1335 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1336 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1337 | opp_table = _add_opp_table(dev); |
| 1338 | if (!opp_table) { |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1339 | ret = -ENOMEM; |
| 1340 | goto unlock; |
| 1341 | } |
| 1342 | |
| 1343 | /* This should be called before OPPs are initialized */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1344 | if (WARN_ON(!list_empty(&opp_table->opp_list))) { |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1345 | ret = -EBUSY; |
| 1346 | goto err; |
| 1347 | } |
| 1348 | |
| 1349 | /* Already have a regulator set */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1350 | if (WARN_ON(!IS_ERR(opp_table->regulator))) { |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1351 | ret = -EBUSY; |
| 1352 | goto err; |
| 1353 | } |
| 1354 | /* Allocate the regulator */ |
| 1355 | reg = regulator_get_optional(dev, name); |
| 1356 | if (IS_ERR(reg)) { |
| 1357 | ret = PTR_ERR(reg); |
| 1358 | if (ret != -EPROBE_DEFER) |
| 1359 | dev_err(dev, "%s: no regulator (%s) found: %d\n", |
| 1360 | __func__, name, ret); |
| 1361 | goto err; |
| 1362 | } |
| 1363 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1364 | opp_table->regulator = reg; |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1365 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1366 | mutex_unlock(&opp_table_lock); |
Stephen Boyd | c7a8a0a | 2016-11-30 16:21:25 +0530 | [diff] [blame] | 1367 | return opp_table; |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1368 | |
| 1369 | err: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1370 | _remove_opp_table(opp_table); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1371 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1372 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1373 | |
Stephen Boyd | c7a8a0a | 2016-11-30 16:21:25 +0530 | [diff] [blame] | 1374 | return ERR_PTR(ret); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1375 | } |
| 1376 | EXPORT_SYMBOL_GPL(dev_pm_opp_set_regulator); |
| 1377 | |
| 1378 | /** |
| 1379 | * dev_pm_opp_put_regulator() - Releases resources blocked for regulator |
Stephen Boyd | c7a8a0a | 2016-11-30 16:21:25 +0530 | [diff] [blame] | 1380 | * @opp_table: OPP table returned from dev_pm_opp_set_regulator(). |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1381 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1382 | * Locking: The internal opp_table and opp structures are RCU protected. |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1383 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1384 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1385 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1386 | * mutex cannot be locked. |
| 1387 | */ |
Stephen Boyd | c7a8a0a | 2016-11-30 16:21:25 +0530 | [diff] [blame] | 1388 | void dev_pm_opp_put_regulator(struct opp_table *opp_table) |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1389 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1390 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1391 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1392 | if (IS_ERR(opp_table->regulator)) { |
Stephen Boyd | c7a8a0a | 2016-11-30 16:21:25 +0530 | [diff] [blame] | 1393 | pr_err("%s: Doesn't have regulator set\n", __func__); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1394 | goto unlock; |
| 1395 | } |
| 1396 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1397 | /* Make sure there are no concurrent readers while updating opp_table */ |
| 1398 | WARN_ON(!list_empty(&opp_table->opp_list)); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1399 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1400 | regulator_put(opp_table->regulator); |
| 1401 | opp_table->regulator = ERR_PTR(-ENXIO); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1402 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1403 | /* Try freeing opp_table if this was the last blocking resource */ |
| 1404 | _remove_opp_table(opp_table); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1405 | |
| 1406 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1407 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 9f8ea96 | 2016-02-09 10:30:33 +0530 | [diff] [blame] | 1408 | } |
| 1409 | EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulator); |
| 1410 | |
Viresh Kumar | 38393409 | 2014-11-25 16:04:18 +0530 | [diff] [blame] | 1411 | /** |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1412 | * dev_pm_opp_add() - Add an OPP table from a table definitions |
| 1413 | * @dev: device for which we do this operation |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 1414 | * @freq: Frequency in Hz for this OPP |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1415 | * @u_volt: Voltage in uVolts for this OPP |
| 1416 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1417 | * This function adds an opp definition to the opp table and returns status. |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 1418 | * The opp is made available by default and it can be controlled using |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1419 | * dev_pm_opp_enable/disable functions. |
| 1420 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1421 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1422 | * Hence this function internally uses RCU updater strategy with mutex locks |
| 1423 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1424 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1425 | * mutex cannot be locked. |
| 1426 | * |
Viresh Kumar | a7470db | 2014-11-25 16:04:17 +0530 | [diff] [blame] | 1427 | * Return: |
| 1428 | * 0 On success OR |
| 1429 | * Duplicate OPPs (both freq and volt are same) and opp->available |
| 1430 | * -EEXIST Freq are same and volt are different OR |
| 1431 | * Duplicate OPPs (both freq and volt are same) and !opp->available |
Viresh Kumar | 38393409 | 2014-11-25 16:04:18 +0530 | [diff] [blame] | 1432 | * -ENOMEM Memory allocation failure |
Viresh Kumar | a7470db | 2014-11-25 16:04:17 +0530 | [diff] [blame] | 1433 | */ |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1434 | int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) |
| 1435 | { |
Viresh Kumar | b64b9c3 | 2015-10-15 21:42:44 +0530 | [diff] [blame] | 1436 | return _opp_add_v1(dev, freq, u_volt, true); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1437 | } |
| 1438 | EXPORT_SYMBOL_GPL(dev_pm_opp_add); |
| 1439 | |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1440 | /** |
Nishanth Menon | 327854c | 2014-12-24 11:22:56 -0600 | [diff] [blame] | 1441 | * _opp_set_availability() - helper to set the availability of an opp |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1442 | * @dev: device for which we do this operation |
| 1443 | * @freq: OPP frequency to modify availability |
| 1444 | * @availability_req: availability status requested for this opp |
| 1445 | * |
| 1446 | * Set the availability of an OPP with an RCU operation, opp_{enable,disable} |
| 1447 | * share a common logic which is isolated here. |
| 1448 | * |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1449 | * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the |
Stephen Boyd | e1a2d49 | 2015-09-24 12:28:44 -0700 | [diff] [blame] | 1450 | * copy operation, returns 0 if no modification was done OR modification was |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1451 | * successful. |
| 1452 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1453 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1454 | * Hence this function internally uses RCU updater strategy with mutex locks to |
| 1455 | * keep the integrity of the internal data structures. Callers should ensure |
| 1456 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1457 | * mutex locking or synchronize_rcu() blocking calls cannot be used. |
| 1458 | */ |
Nishanth Menon | 327854c | 2014-12-24 11:22:56 -0600 | [diff] [blame] | 1459 | static int _opp_set_availability(struct device *dev, unsigned long freq, |
| 1460 | bool availability_req) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1461 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1462 | struct opp_table *opp_table; |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 1463 | struct dev_pm_opp *new_opp, *tmp_opp, *opp = ERR_PTR(-ENODEV); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1464 | int r = 0; |
| 1465 | |
| 1466 | /* keep the node allocated */ |
Nishanth Menon | 47d43ba | 2013-09-19 16:03:51 -0500 | [diff] [blame] | 1467 | new_opp = kmalloc(sizeof(*new_opp), GFP_KERNEL); |
Quentin Lambert | 59d84ca | 2015-02-09 10:45:32 +0100 | [diff] [blame] | 1468 | if (!new_opp) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1469 | return -ENOMEM; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1470 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1471 | mutex_lock(&opp_table_lock); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1472 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1473 | /* Find the opp_table */ |
| 1474 | opp_table = _find_opp_table(dev); |
| 1475 | if (IS_ERR(opp_table)) { |
| 1476 | r = PTR_ERR(opp_table); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1477 | dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r); |
| 1478 | goto unlock; |
| 1479 | } |
| 1480 | |
| 1481 | /* Do we have the frequency? */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1482 | list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1483 | if (tmp_opp->rate == freq) { |
| 1484 | opp = tmp_opp; |
| 1485 | break; |
| 1486 | } |
| 1487 | } |
| 1488 | if (IS_ERR(opp)) { |
| 1489 | r = PTR_ERR(opp); |
| 1490 | goto unlock; |
| 1491 | } |
| 1492 | |
| 1493 | /* Is update really needed? */ |
| 1494 | if (opp->available == availability_req) |
| 1495 | goto unlock; |
| 1496 | /* copy the old data over */ |
| 1497 | *new_opp = *opp; |
| 1498 | |
| 1499 | /* plug in new node */ |
| 1500 | new_opp->available = availability_req; |
| 1501 | |
| 1502 | list_replace_rcu(&opp->node, &new_opp->node); |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1503 | mutex_unlock(&opp_table_lock); |
| 1504 | call_srcu(&opp_table->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1505 | |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1506 | /* Notify the change of the OPP availability */ |
| 1507 | if (availability_req) |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1508 | srcu_notifier_call_chain(&opp_table->srcu_head, |
| 1509 | OPP_EVENT_ENABLE, new_opp); |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1510 | else |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1511 | srcu_notifier_call_chain(&opp_table->srcu_head, |
| 1512 | OPP_EVENT_DISABLE, new_opp); |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1513 | |
Vincent Guittot | dde8437 | 2012-10-23 01:21:49 +0200 | [diff] [blame] | 1514 | return 0; |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1515 | |
| 1516 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1517 | mutex_unlock(&opp_table_lock); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1518 | kfree(new_opp); |
| 1519 | return r; |
| 1520 | } |
| 1521 | |
| 1522 | /** |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1523 | * dev_pm_opp_enable() - Enable a specific OPP |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1524 | * @dev: device for which we do this operation |
| 1525 | * @freq: OPP frequency to enable |
| 1526 | * |
| 1527 | * Enables a provided opp. If the operation is valid, this returns 0, else the |
| 1528 | * corresponding error value. It is meant to be used for users an OPP available |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1529 | * after being temporarily made unavailable with dev_pm_opp_disable. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1530 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1531 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1532 | * Hence this function indirectly uses RCU and mutex locks to keep the |
| 1533 | * integrity of the internal data structures. Callers should ensure that |
| 1534 | * this function is *NOT* called under RCU protection or in contexts where |
| 1535 | * mutex locking or synchronize_rcu() blocking calls cannot be used. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1536 | * |
| 1537 | * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the |
Stephen Boyd | e1a2d49 | 2015-09-24 12:28:44 -0700 | [diff] [blame] | 1538 | * copy operation, returns 0 if no modification was done OR modification was |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1539 | * successful. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1540 | */ |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1541 | int dev_pm_opp_enable(struct device *dev, unsigned long freq) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1542 | { |
Nishanth Menon | 327854c | 2014-12-24 11:22:56 -0600 | [diff] [blame] | 1543 | return _opp_set_availability(dev, freq, true); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1544 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1545 | EXPORT_SYMBOL_GPL(dev_pm_opp_enable); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1546 | |
| 1547 | /** |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1548 | * dev_pm_opp_disable() - Disable a specific OPP |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1549 | * @dev: device for which we do this operation |
| 1550 | * @freq: OPP frequency to disable |
| 1551 | * |
| 1552 | * Disables a provided opp. If the operation is valid, this returns |
| 1553 | * 0, else the corresponding error value. It is meant to be a temporary |
| 1554 | * control by users to make this OPP not available until the circumstances are |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1555 | * right to make it available again (with a call to dev_pm_opp_enable). |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1556 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1557 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1558 | * Hence this function indirectly uses RCU and mutex locks to keep the |
| 1559 | * integrity of the internal data structures. Callers should ensure that |
| 1560 | * this function is *NOT* called under RCU protection or in contexts where |
| 1561 | * mutex locking or synchronize_rcu() blocking calls cannot be used. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1562 | * |
| 1563 | * Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the |
Stephen Boyd | e1a2d49 | 2015-09-24 12:28:44 -0700 | [diff] [blame] | 1564 | * copy operation, returns 0 if no modification was done OR modification was |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1565 | * successful. |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1566 | */ |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1567 | int dev_pm_opp_disable(struct device *dev, unsigned long freq) |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1568 | { |
Nishanth Menon | 327854c | 2014-12-24 11:22:56 -0600 | [diff] [blame] | 1569 | return _opp_set_availability(dev, freq, false); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1570 | } |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1571 | EXPORT_SYMBOL_GPL(dev_pm_opp_disable); |
Nishanth Menon | e1f60b2 | 2010-10-13 00:13:10 +0200 | [diff] [blame] | 1572 | |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1573 | /** |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1574 | * dev_pm_opp_get_notifier() - find notifier_head of the device with opp |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1575 | * @dev: device pointer used to lookup OPP table. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1576 | * |
| 1577 | * Return: pointer to notifier head if found, otherwise -ENODEV or |
| 1578 | * -EINVAL based on type of error casted as pointer. value must be checked |
| 1579 | * with IS_ERR to determine valid pointer or error result. |
| 1580 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1581 | * Locking: This function must be called under rcu_read_lock(). opp_table is a |
| 1582 | * RCU protected pointer. The reason for the same is that the opp pointer which |
| 1583 | * is returned will remain valid for use with opp_get_{voltage, freq} only while |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1584 | * under the locked area. The pointer returned must be used prior to unlocking |
| 1585 | * with rcu_read_unlock() to maintain the integrity of the pointer. |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1586 | */ |
Nishanth Menon | 5d4879c | 2013-09-19 16:03:50 -0500 | [diff] [blame] | 1587 | struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev) |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1588 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1589 | struct opp_table *opp_table = _find_opp_table(dev); |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1590 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1591 | if (IS_ERR(opp_table)) |
| 1592 | return ERR_CAST(opp_table); /* matching type */ |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1593 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1594 | return &opp_table->srcu_head; |
MyungJoo Ham | 03ca370 | 2011-09-30 22:35:12 +0200 | [diff] [blame] | 1595 | } |
Nishanth Menon | 4679ec3 | 2014-12-24 11:22:55 -0600 | [diff] [blame] | 1596 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier); |
Shawn Guo | b496dfb | 2012-09-05 01:09:12 +0200 | [diff] [blame] | 1597 | |
Sudeep Holla | 411466c | 2016-05-03 15:05:04 +0100 | [diff] [blame] | 1598 | /* |
| 1599 | * Free OPPs either created using static entries present in DT or even the |
| 1600 | * dynamically added entries based on remove_all param. |
Shawn Guo | b496dfb | 2012-09-05 01:09:12 +0200 | [diff] [blame] | 1601 | */ |
Viresh Kumar | f47b72a | 2016-05-05 16:20:33 +0530 | [diff] [blame] | 1602 | void _dev_pm_opp_remove_table(struct device *dev, bool remove_all) |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1603 | { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1604 | struct opp_table *opp_table; |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1605 | struct dev_pm_opp *opp, *tmp; |
| 1606 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1607 | /* Hold our table modification lock here */ |
| 1608 | mutex_lock(&opp_table_lock); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 1609 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1610 | /* Check for existing table for 'dev' */ |
| 1611 | opp_table = _find_opp_table(dev); |
| 1612 | if (IS_ERR(opp_table)) { |
| 1613 | int error = PTR_ERR(opp_table); |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1614 | |
| 1615 | if (error != -ENODEV) |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1616 | WARN(1, "%s: opp_table: %d\n", |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1617 | IS_ERR_OR_NULL(dev) ? |
| 1618 | "Invalid device" : dev_name(dev), |
| 1619 | error); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 1620 | goto unlock; |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1621 | } |
| 1622 | |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1623 | /* Find if opp_table manages a single device */ |
| 1624 | if (list_is_singular(&opp_table->dev_list)) { |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 1625 | /* Free static OPPs */ |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1626 | list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { |
Sudeep Holla | 411466c | 2016-05-03 15:05:04 +0100 | [diff] [blame] | 1627 | if (remove_all || !opp->dynamic) |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1628 | _opp_remove(opp_table, opp, true); |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 1629 | } |
| 1630 | } else { |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1631 | _remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table); |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1632 | } |
| 1633 | |
Viresh Kumar | 0644165 | 2015-07-29 16:23:04 +0530 | [diff] [blame] | 1634 | unlock: |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1635 | mutex_unlock(&opp_table_lock); |
Viresh Kumar | 737002b | 2015-07-29 16:22:58 +0530 | [diff] [blame] | 1636 | } |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 1637 | |
| 1638 | /** |
Sudeep Holla | 411466c | 2016-05-03 15:05:04 +0100 | [diff] [blame] | 1639 | * dev_pm_opp_remove_table() - Free all OPPs associated with the device |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1640 | * @dev: device pointer used to lookup OPP table. |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 1641 | * |
Sudeep Holla | 411466c | 2016-05-03 15:05:04 +0100 | [diff] [blame] | 1642 | * Free both OPPs created using static entries present in DT and the |
| 1643 | * dynamically added entries. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1644 | * |
Viresh Kumar | 2c2709d | 2016-02-16 14:17:53 +0530 | [diff] [blame] | 1645 | * Locking: The internal opp_table and opp structures are RCU protected. |
Nishanth Menon | 984f16c | 2014-12-24 11:22:57 -0600 | [diff] [blame] | 1646 | * Hence this function indirectly uses RCU updater strategy with mutex locks |
| 1647 | * to keep the integrity of the internal data structures. Callers should ensure |
| 1648 | * that this function is *NOT* called under RCU protection or in contexts where |
| 1649 | * mutex cannot be locked. |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 1650 | */ |
Sudeep Holla | 411466c | 2016-05-03 15:05:04 +0100 | [diff] [blame] | 1651 | void dev_pm_opp_remove_table(struct device *dev) |
Viresh Kumar | 129eec5 | 2014-11-27 08:54:06 +0530 | [diff] [blame] | 1652 | { |
Sudeep Holla | 411466c | 2016-05-03 15:05:04 +0100 | [diff] [blame] | 1653 | _dev_pm_opp_remove_table(dev, true); |
Viresh Kumar | 8d4d4e9 | 2015-06-12 17:10:38 +0530 | [diff] [blame] | 1654 | } |
Sudeep Holla | 411466c | 2016-05-03 15:05:04 +0100 | [diff] [blame] | 1655 | EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table); |