Lines Matching full:opp
3 * Generic OPP Interface
23 #include "opp.h"
26 * The root of the list of all opp-tables. All opp_table structures branch off
32 /* Lock to allow exclusive modification to the device and opp lists */
37 /* OPP ID allocator */
67 * @dev: device pointer used to lookup OPP table
69 * Search OPP table for one containing matching device.
91 * representation in the OPP table and manage the clock configuration themselves
119 * dev_pm_opp_get_bw() - Gets the bandwidth corresponding to an opp
120 * @opp: opp for which bandwidth has to be returned for
126 unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index) in dev_pm_opp_get_bw() argument
128 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_bw()
133 if (index >= opp->opp_table->path_count) in dev_pm_opp_get_bw()
136 if (!opp->bandwidth) in dev_pm_opp_get_bw()
139 return peak ? opp->bandwidth[index].peak : opp->bandwidth[index].avg; in dev_pm_opp_get_bw()
144 * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
145 * @opp: opp for which voltage has to be returned for
147 * Return: voltage in micro volt corresponding to the opp, else
152 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) in dev_pm_opp_get_voltage() argument
154 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_voltage()
159 return opp->supplies[0].u_volt; in dev_pm_opp_get_voltage()
164 * dev_pm_opp_get_supplies() - Gets the supply information corresponding to an opp
165 * @opp: opp for which voltage has to be returned for
174 int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, in dev_pm_opp_get_supplies() argument
177 if (IS_ERR_OR_NULL(opp) || !supplies) { in dev_pm_opp_get_supplies()
182 memcpy(supplies, opp->supplies, in dev_pm_opp_get_supplies()
183 sizeof(*supplies) * opp->opp_table->regulator_count); in dev_pm_opp_get_supplies()
189 * dev_pm_opp_get_power() - Gets the power corresponding to an opp
190 * @opp: opp for which power has to be returned for
192 * Return: power in micro watt corresponding to the opp, else
197 unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp) in dev_pm_opp_get_power() argument
202 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_power()
206 for (i = 0; i < opp->opp_table->regulator_count; i++) in dev_pm_opp_get_power()
207 opp_power += opp->supplies[i].u_watt; in dev_pm_opp_get_power()
215 * available opp with specified index
216 * @opp: opp for which frequency has to be returned for
217 * @index: index of the frequency within the required opp
219 * Return: frequency in hertz corresponding to the opp with specified index,
222 unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index) in dev_pm_opp_get_freq_indexed() argument
224 if (IS_ERR_OR_NULL(opp) || index >= opp->opp_table->clk_count) { in dev_pm_opp_get_freq_indexed()
229 return opp->rates[index]; in dev_pm_opp_get_freq_indexed()
234 * dev_pm_opp_get_level() - Gets the level corresponding to an available opp
235 * @opp: opp for which level value has to be returned for
237 * Return: level read from device tree corresponding to the opp, else
240 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) in dev_pm_opp_get_level() argument
242 if (IS_ERR_OR_NULL(opp) || !opp->available) { in dev_pm_opp_get_level()
247 return opp->level; in dev_pm_opp_get_level()
253 * corresponding to an available opp
254 * @opp: opp for which performance state has to be returned for
255 * @index: index of the required opp
258 * required opp, else return U32_MAX.
260 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, in dev_pm_opp_get_required_pstate() argument
263 if (IS_ERR_OR_NULL(opp) || !opp->available || in dev_pm_opp_get_required_pstate()
264 index >= opp->opp_table->required_opp_count) { in dev_pm_opp_get_required_pstate()
270 if (lazy_linking_pending(opp->opp_table)) in dev_pm_opp_get_required_pstate()
273 /* The required OPP table must belong to a genpd */ in dev_pm_opp_get_required_pstate()
274 if (unlikely(!opp->opp_table->required_opp_tables[index]->is_genpd)) { in dev_pm_opp_get_required_pstate()
279 return opp->required_opps[index]->level; in dev_pm_opp_get_required_pstate()
284 * dev_pm_opp_is_turbo() - Returns if opp is turbo OPP or not
285 * @opp: opp for which turbo mode is being verified
291 * Return: true if opp is turbo opp, else false.
293 bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp) in dev_pm_opp_is_turbo() argument
295 if (IS_ERR_OR_NULL(opp) || !opp->available) { in dev_pm_opp_is_turbo()
300 return opp->turbo; in dev_pm_opp_is_turbo()
330 struct dev_pm_opp *opp; in dev_pm_opp_get_max_volt_latency() local
360 list_for_each_entry(opp, &opp_table->opp_list, node) { in dev_pm_opp_get_max_volt_latency()
361 if (!opp->available) in dev_pm_opp_get_max_volt_latency()
364 if (opp->supplies[i].u_volt_min < uV[i].min) in dev_pm_opp_get_max_volt_latency()
365 uV[i].min = opp->supplies[i].u_volt_min; in dev_pm_opp_get_max_volt_latency()
366 if (opp->supplies[i].u_volt_max > uV[i].max) in dev_pm_opp_get_max_volt_latency()
367 uV[i].max = opp->supplies[i].u_volt_max; in dev_pm_opp_get_max_volt_latency()
395 * switch from one OPP to other.
405 * dev_pm_opp_get_suspend_opp_freq() - Get frequency of suspend opp in Hz
408 * Return: This function returns the frequency of the OPP marked as suspend_opp
430 struct dev_pm_opp *opp; in _get_opp_count() local
435 list_for_each_entry(opp, &opp_table->opp_list, node) { in _get_opp_count()
436 if (opp->available) in _get_opp_count()
444 * dev_pm_opp_get_opp_count() - Get number of opps available in the opp table
456 dev_dbg(dev, "%s: OPP table not found (%ld)\n", in dev_pm_opp_get_opp_count()
466 static unsigned long _read_freq(struct dev_pm_opp *opp, int index) in _read_freq() argument
468 return opp->rates[index]; in _read_freq()
471 static unsigned long _read_level(struct dev_pm_opp *opp, int index) in _read_level() argument
473 return opp->level; in _read_level()
476 static unsigned long _read_bw(struct dev_pm_opp *opp, int index) in _read_bw() argument
478 return opp->bandwidth[index].peak; in _read_bw()
481 static unsigned long _read_opp_key(struct dev_pm_opp *opp, int index, in _read_opp_key() argument
484 key->bw = opp->bandwidth ? opp->bandwidth[index].peak : 0; in _read_opp_key()
485 key->freq = opp->rates[index]; in _read_opp_key()
486 key->level = opp->level; in _read_opp_key()
492 static bool _compare_exact(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, in _compare_exact() argument
496 *opp = temp_opp; in _compare_exact()
503 static bool _compare_ceil(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, in _compare_ceil() argument
507 *opp = temp_opp; in _compare_ceil()
514 static bool _compare_floor(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, in _compare_floor() argument
520 *opp = temp_opp; in _compare_floor()
524 static bool _compare_opp_key_exact(struct dev_pm_opp **opp, in _compare_opp_key_exact() argument
533 *opp = temp_opp; in _compare_opp_key_exact()
543 unsigned long (*read)(struct dev_pm_opp *opp, int index), in _opp_table_find_key() argument
544 bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, in _opp_table_find_key() argument
548 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); in _opp_table_find_key() local
558 if (compare(&opp, temp_opp, read(temp_opp, index), *key)) in _opp_table_find_key()
563 /* Increment the reference count of OPP */ in _opp_table_find_key()
564 if (!IS_ERR(opp)) { in _opp_table_find_key()
565 *key = read(opp, index); in _opp_table_find_key()
566 dev_pm_opp_get(opp); in _opp_table_find_key()
569 return opp; in _opp_table_find_key()
574 unsigned long (*read)(struct dev_pm_opp *opp, int index, in _opp_table_find_opp_key() argument
576 bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, in _opp_table_find_opp_key() argument
580 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE); in _opp_table_find_opp_key() local
592 if (compare(&opp, temp_opp, &temp_key, key)) { in _opp_table_find_opp_key()
593 /* Increment the reference count of OPP */ in _opp_table_find_opp_key()
594 dev_pm_opp_get(opp); in _opp_table_find_opp_key()
600 return opp; in _opp_table_find_opp_key()
605 unsigned long (*read)(struct dev_pm_opp *opp, int index), in _find_key() argument
606 bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp, in _find_key() argument
614 dev_err(dev, "%s: OPP table not found (%ld)\n", __func__, in _find_key()
625 unsigned long (*read)(struct dev_pm_opp *opp, int index), in _find_key_exact() argument
638 unsigned long (*read)(struct dev_pm_opp *opp, int index), in _opp_table_find_key_ceil() argument
647 unsigned long (*read)(struct dev_pm_opp *opp, int index), in _find_key_ceil() argument
656 unsigned long (*read)(struct dev_pm_opp *opp, int index), in _find_key_floor() argument
667 * @available: true/false - match for available opp
669 * Return: Searches for exact match in the opp table and returns pointer to the
670 * matching opp if found, else returns ERR_PTR in case of error and should
677 * match is for exact matching frequency and is available in the stored OPP
680 * This provides a mechanism to enable an opp which is not available currently
683 * The callers are required to call dev_pm_opp_put() for the returned OPP after
695 * dev_pm_opp_find_key_exact() - Search for an OPP with exact key set
696 * @dev: Device for which the OPP is being searched
697 * @key: OPP key set to match
698 * @available: true/false - match for available OPP
700 * Search for an exact match of the key set in the OPP table.
702 * Return: A matching opp on success, else ERR_PTR in case of error.
710 * OPP table. If false, the match is for exact key which is not available.
712 * This provides a mechanism to enable an OPP which is not available currently
715 * The callers are required to call dev_pm_opp_put() for the returned OPP after
725 dev_err(dev, "%s: OPP table not found (%ld)\n", __func__, in dev_pm_opp_find_key_exact()
742 * @available: true/false - match for available opp
744 * Search for the matching exact OPP for the clock corresponding to the
747 * Return: matching *opp , else returns ERR_PTR in case of error and should be
753 * The callers are required to call dev_pm_opp_put() for the returned OPP after
777 * Search for the matching ceil *available* OPP from a starting freq
780 * Return: matching *opp and refreshes *freq accordingly, else returns
787 * The callers are required to call dev_pm_opp_put() for the returned OPP after
804 * Search for the matching ceil *available* OPP for the clock corresponding to
807 * Return: matching *opp and refreshes *freq accordingly, else returns
814 * The callers are required to call dev_pm_opp_put() for the returned OPP after
831 * Search for the matching floor *available* OPP from a starting freq
834 * Return: matching *opp and refreshes *freq accordingly, else returns
841 * The callers are required to call dev_pm_opp_put() for the returned OPP after
858 * Search for the matching floor *available* OPP for the clock corresponding to
861 * Return: matching *opp and refreshes *freq accordingly, else returns
868 * The callers are required to call dev_pm_opp_put() for the returned OPP after
884 * Return: Searches for exact match in the opp table and returns pointer to the
885 * matching opp if found, else returns ERR_PTR in case of error and should
891 * The callers are required to call dev_pm_opp_put() for the returned OPP after
906 * Return: Searches for rounded up match in the opp table and returns pointer
907 * to the matching opp if found, else returns ERR_PTR in case of error and
913 * The callers are required to call dev_pm_opp_put() for the returned OPP after
920 struct dev_pm_opp *opp; in dev_pm_opp_find_level_ceil() local
922 opp = _find_key_ceil(dev, &temp, 0, true, _read_level, NULL); in dev_pm_opp_find_level_ceil()
923 if (IS_ERR(opp)) in dev_pm_opp_find_level_ceil()
924 return opp; in dev_pm_opp_find_level_ceil()
928 dev_err(dev, "%s: OPP levels aren't available\n", __func__); in dev_pm_opp_find_level_ceil()
929 dev_pm_opp_put(opp); in dev_pm_opp_find_level_ceil()
934 return opp; in dev_pm_opp_find_level_ceil()
943 * Search for the matching floor *available* OPP from a starting level
946 * Return: matching *opp and refreshes *level accordingly, else returns
953 * The callers are required to call dev_pm_opp_put() for the returned OPP after
960 struct dev_pm_opp *opp; in dev_pm_opp_find_level_floor() local
962 opp = _find_key_floor(dev, &temp, 0, true, _read_level, NULL); in dev_pm_opp_find_level_floor()
964 return opp; in dev_pm_opp_find_level_floor()
974 * Search for the matching floor *available* OPP from a starting bandwidth
977 * Return: matching *opp and refreshes *bw accordingly, else returns
984 * The callers are required to call dev_pm_opp_put() for the returned OPP after
991 struct dev_pm_opp *opp; in dev_pm_opp_find_bw_ceil() local
993 opp = _find_key_ceil(dev, &temp, index, true, _read_bw, in dev_pm_opp_find_bw_ceil()
996 return opp; in dev_pm_opp_find_bw_ceil()
1006 * Search for the matching floor *available* OPP from a starting bandwidth
1009 * Return: matching *opp and refreshes *bw accordingly, else returns
1016 * The callers are required to call dev_pm_opp_put() for the returned OPP after
1023 struct dev_pm_opp *opp; in dev_pm_opp_find_bw_floor() local
1025 opp = _find_key_floor(dev, &temp, index, true, _read_bw, in dev_pm_opp_find_bw_floor()
1028 return opp; in dev_pm_opp_find_bw_floor()
1059 struct dev_pm_opp *opp, void *data, bool scaling_down) in _opp_config_clk_single() argument
1065 /* One of target and opp must be available */ in _opp_config_clk_single()
1068 } else if (opp) { in _opp_config_clk_single()
1069 freq = opp->rates[0]; in _opp_config_clk_single()
1091 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, in dev_pm_opp_config_clks_simple() argument
1098 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]); in dev_pm_opp_config_clks_simple()
1107 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]); in dev_pm_opp_config_clks_simple()
1151 struct dev_pm_opp *opp, struct device *dev) in _set_opp_bw() argument
1160 if (!opp) { in _set_opp_bw()
1164 avg = opp->bandwidth[i].avg; in _set_opp_bw()
1165 peak = opp->bandwidth[i].peak; in _set_opp_bw()
1170 opp ? "set" : "remove", i, ret); in _set_opp_bw()
1178 static int _set_opp_level(struct device *dev, struct dev_pm_opp *opp) in _set_opp_level() argument
1183 if (opp) { in _set_opp_level()
1184 if (opp->level == OPP_LEVEL_UNSET) in _set_opp_level()
1187 level = opp->level; in _set_opp_level()
1201 struct dev_pm_opp *opp, bool up) in _set_required_opps() argument
1227 required_opp = opp ? opp->required_opps[index] : NULL; in _set_required_opps()
1242 struct dev_pm_opp *opp = ERR_PTR(-ENODEV); in _find_current_opp() local
1247 opp = _find_freq_ceil(opp_table, &freq); in _find_current_opp()
1251 * Unable to find the current OPP ? Pick the first from the list since in _find_current_opp()
1255 if (IS_ERR(opp)) { in _find_current_opp()
1257 opp = dev_pm_opp_get(list_first_entry(&opp_table->opp_list, in _find_current_opp()
1261 opp_table->current_opp = opp; in _find_current_opp()
1273 * have OPP table for the device, while others don't and in _disable_opp_table()
1298 struct dev_pm_opp *opp, void *clk_data, bool forced) in _set_opp() argument
1303 if (unlikely(!opp)) in _set_opp()
1306 /* Find the currently set OPP if we don't know already */ in _set_opp()
1313 if (!forced && old_opp == opp && opp_table->enabled) { in _set_opp()
1318 dev_dbg(dev, "%s: switching OPP: Freq %lu -> %lu Hz, Level %u -> %u, Bw %u -> %u\n", in _set_opp()
1319 __func__, old_opp->rates[0], opp->rates[0], old_opp->level, in _set_opp()
1320 opp->level, old_opp->bandwidth ? old_opp->bandwidth[0].peak : 0, in _set_opp()
1321 opp->bandwidth ? opp->bandwidth[0].peak : 0); in _set_opp()
1323 scaling_down = _opp_compare_key(opp_table, old_opp, opp); in _set_opp()
1329 ret = _set_required_opps(dev, opp_table, opp, true); in _set_opp()
1335 ret = _set_opp_level(dev, opp); in _set_opp()
1339 ret = _set_opp_bw(opp_table, opp, dev); in _set_opp()
1346 ret = opp_table->config_regulators(dev, old_opp, opp, in _set_opp()
1358 ret = opp_table->config_clks(dev, opp_table, opp, clk_data, scaling_down); in _set_opp()
1366 ret = opp_table->config_regulators(dev, old_opp, opp, in _set_opp()
1376 ret = _set_opp_bw(opp_table, opp, dev); in _set_opp()
1382 ret = _set_opp_level(dev, opp); in _set_opp()
1386 ret = _set_required_opps(dev, opp_table, opp, false); in _set_opp()
1397 opp_table->current_opp = dev_pm_opp_get(opp); in _set_opp()
1403 * dev_pm_opp_set_rate() - Configure new OPP based on frequency
1407 * This configures the power-supplies to the levels specified by the OPP
1410 * provided by the opp, should have already rounded to the target OPP's
1415 struct dev_pm_opp *opp __free(put_opp) = NULL; in dev_pm_opp_set_rate()
1423 dev_err(dev, "%s: device's opp table doesn't exist\n", __func__); in dev_pm_opp_set_rate()
1429 * For IO devices which require an OPP on some platforms/SoCs in dev_pm_opp_set_rate()
1431 * we look for empty OPP tables with just a clock handle and in dev_pm_opp_set_rate()
1446 * frequencies than the OPP table, don't update the frequency we in dev_pm_opp_set_rate()
1450 opp = _find_freq_ceil(opp_table, &temp_freq); in dev_pm_opp_set_rate()
1451 if (IS_ERR(opp)) { in dev_pm_opp_set_rate()
1452 dev_err(dev, "%s: failed to find OPP for freq %lu (%ld)\n", in dev_pm_opp_set_rate()
1453 __func__, freq, PTR_ERR(opp)); in dev_pm_opp_set_rate()
1454 return PTR_ERR(opp); in dev_pm_opp_set_rate()
1458 * An OPP entry specifies the highest frequency at which other in dev_pm_opp_set_rate()
1459 * properties of the OPP entry apply. Even if the new OPP is in dev_pm_opp_set_rate()
1467 return _set_opp(dev, opp_table, opp, &freq, forced); in dev_pm_opp_set_rate()
1472 * dev_pm_opp_set_opp() - Configure device for OPP
1474 * @opp: OPP to set to
1476 * This configures the device based on the properties of the OPP passed to this
1481 int dev_pm_opp_set_opp(struct device *dev, struct dev_pm_opp *opp) in dev_pm_opp_set_opp() argument
1487 dev_err(dev, "%s: device opp doesn't exist\n", __func__); in dev_pm_opp_set_opp()
1491 return _set_opp(dev, opp_table, opp, NULL, false); in dev_pm_opp_set_opp()
1495 /* OPP-dev Helpers */
1513 /* Initialize opp-dev */ in _add_opp_dev()
1532 * Allocate a new OPP table. In the infrequent case where a new in _allocate_opp_table()
1607 * There are few platforms which don't want the OPP core to in _update_opp_table_clk()
1610 * contains a valid clk entry. The OPP nodes in DT may still in _update_opp_table_clk()
1611 * contain "opp-hz" property though, which we need to parse and in _update_opp_table_clk()
1612 * allow the platform to find an OPP based on freq later on. in _update_opp_table_clk()
1616 * frequency in opp->rates and also parse the entries in DT. in _update_opp_table_clk()
1631 * We need to make sure that the OPP table for a device doesn't get added twice,
1639 * indirect users of OPP core.
1643 * of adding an OPP table and others should wait for it to finish.
1658 * The opp_tables list or an OPP table's dev_list is getting updated by in _add_opp_table_indexed()
1755 void _opp_free(struct dev_pm_opp *opp) in _opp_free() argument
1757 kfree(opp); in _opp_free()
1762 struct dev_pm_opp *opp = container_of(kref, struct dev_pm_opp, kref); in _opp_kref_release() local
1763 struct opp_table *opp_table = opp->opp_table; in _opp_kref_release()
1765 list_del(&opp->node); in _opp_kref_release()
1772 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp); in _opp_kref_release()
1773 _of_clear_opp(opp_table, opp); in _opp_kref_release()
1774 opp_debug_remove_one(opp); in _opp_kref_release()
1775 kfree(opp); in _opp_kref_release()
1778 struct dev_pm_opp *dev_pm_opp_get(struct dev_pm_opp *opp) in dev_pm_opp_get() argument
1780 kref_get(&opp->kref); in dev_pm_opp_get()
1781 return opp; in dev_pm_opp_get()
1785 void dev_pm_opp_put(struct dev_pm_opp *opp) in dev_pm_opp_put() argument
1787 kref_put_mutex(&opp->kref, _opp_kref_release, &opp->opp_table->lock); in dev_pm_opp_put()
1792 * dev_pm_opp_remove() - Remove an OPP from OPP table
1794 * @freq: OPP to remove with matching 'freq'
1796 * This function removes an opp from the opp table.
1800 struct dev_pm_opp *opp = NULL, *iter; in dev_pm_opp_remove() local
1814 opp = iter; in dev_pm_opp_remove()
1820 if (opp) { in dev_pm_opp_remove()
1821 dev_pm_opp_put(opp); in dev_pm_opp_remove()
1826 dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n", in dev_pm_opp_remove()
1835 struct dev_pm_opp *opp; in _opp_get_next() local
1839 list_for_each_entry(opp, &opp_table->opp_list, node) { in _opp_get_next()
1841 * Refcount must be dropped only once for each OPP by OPP core, in _opp_get_next()
1844 if (!opp->removed && dynamic == opp->dynamic) in _opp_get_next()
1845 return opp; in _opp_get_next()
1858 struct dev_pm_opp *opp; in _opp_remove_all() local
1860 while ((opp = _opp_get_next(opp_table, dynamic))) { in _opp_remove_all()
1861 opp->removed = true; in _opp_remove_all()
1862 dev_pm_opp_put(opp); in _opp_remove_all()
1888 * This function removes all dynamically created OPPs from the opp table.
1904 struct dev_pm_opp *opp; in _opp_allocate() local
1910 supply_size = sizeof(*opp->supplies) * supply_count; in _opp_allocate()
1911 clk_size = sizeof(*opp->rates) * opp_table->clk_count; in _opp_allocate()
1912 icc_size = sizeof(*opp->bandwidth) * opp_table->path_count; in _opp_allocate()
1914 /* allocate new OPP node and supplies structures */ in _opp_allocate()
1915 opp = kzalloc(sizeof(*opp) + supply_size + clk_size + icc_size, GFP_KERNEL); in _opp_allocate()
1916 if (!opp) in _opp_allocate()
1919 /* Put the supplies, bw and clock at the end of the OPP structure */ in _opp_allocate()
1920 opp->supplies = (struct dev_pm_opp_supply *)(opp + 1); in _opp_allocate()
1922 opp->rates = (unsigned long *)(opp->supplies + supply_count); in _opp_allocate()
1925 opp->bandwidth = (struct dev_pm_opp_icc_bw *)(opp->rates + opp_table->clk_count); in _opp_allocate()
1927 INIT_LIST_HEAD(&opp->node); in _opp_allocate()
1929 opp->level = OPP_LEVEL_UNSET; in _opp_allocate()
1931 return opp; in _opp_allocate()
1934 static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, in _opp_supported_by_regulators() argument
1947 opp->supplies[i].u_volt_min, in _opp_supported_by_regulators()
1948 opp->supplies[i].u_volt_max)) { in _opp_supported_by_regulators()
1949 pr_warn("%s: OPP minuV: %lu maxuV: %lu, not supported by regulator\n", in _opp_supported_by_regulators()
1950 __func__, opp->supplies[i].u_volt_min, in _opp_supported_by_regulators()
1951 opp->supplies[i].u_volt_max); in _opp_supported_by_regulators()
2017 struct dev_pm_opp *opp; in _opp_is_duplicate() local
2021 * Insert new OPP in order of increasing frequency and discard if in _opp_is_duplicate()
2028 list_for_each_entry(opp, &opp_table->opp_list, node) { in _opp_is_duplicate()
2029 opp_cmp = _opp_compare_key(opp_table, new_opp, opp); in _opp_is_duplicate()
2031 *head = &opp->node; in _opp_is_duplicate()
2040 __func__, opp->rates[0], opp->supplies[0].u_volt, in _opp_is_duplicate()
2041 opp->available, new_opp->rates[0], in _opp_is_duplicate()
2045 return opp->available && in _opp_is_duplicate()
2046 new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST; in _opp_is_duplicate()
2052 void _required_opps_available(struct dev_pm_opp *opp, int count) in _required_opps_available() argument
2057 if (opp->required_opps[i]->available) in _required_opps_available()
2060 opp->available = false; in _required_opps_available()
2061 pr_warn("%s: OPP not supported by required OPP %pOF (%lu)\n", in _required_opps_available()
2062 __func__, opp->required_opps[i]->np, opp->rates[0]); in _required_opps_available()
2070 * -EBUSY: For OPP with same freq/volt and is available. The callers of
2073 * kernel try to initialize the OPP table.
2074 * -EEXIST: For OPP with same freq but different volt or is unavailable. This
2100 dev_warn(dev, "%s: OPP not supported by regulators (%lu)\n", in _opp_add()
2114 * _opp_add_v1() - Allocate a OPP based on v1 bindings.
2115 * @opp_table: OPP table
2117 * @data: The OPP data for the OPP to add
2120 * This function adds an opp definition to the opp table and returns status.
2121 * The opp is made available by default and it can be controlled using
2129 * Duplicate OPPs (both freq and volt are same) and opp->available
2131 * Duplicate OPPs (both freq and volt are same) and !opp->available
2148 /* populate the opp table */ in _opp_add_v1()
2182 * specify the hierarchy of versions it supports. OPP layer will then enable
2183 * OPPs, which are available for those versions, based on its 'opp-supported-hw'
2189 /* Another CPU that shares the OPP table has set the property ? */ in _opp_set_supported_hw()
2215 * which the extension will apply are opp-microvolt and opp-microamp. OPP core
2220 /* Another CPU that shares the OPP table has set the property ? */ in _opp_set_prop_name()
2239 * In order to support OPP switching, OPP layer needs to know the name of the
2259 /* Another CPU that shares the OPP table has set the regulators ? */ in _opp_set_regulators()
2330 * In order to support OPP switching, OPP layer needs to get pointers to the
2333 * clocks available, the OPP core needs to know the exact names of the clks to
2361 /* Another CPU that shares the OPP table has set the clkname ? */ in _opp_set_clknames()
2431 /* Another CPU that shares the OPP table has set the helper ? */ in _opp_set_config_regulators_helper()
2465 dev_err(dev, "Missing OPP table, unable to set the required devs\n"); in _opp_set_required_dev()
2470 * The required_opp_tables parsing is not perfect, as the OPP core does in _opp_set_required_dev()
2472 * required_opp_tables entry to the first OPP table in the "opp_tables" in _opp_set_required_dev()
2475 * If the target DT OPP table is used by multiple devices and they all in _opp_set_required_dev()
2527 * dev_pm_opp_set_config() - Set OPP configuration for the device.
2529 * @config: OPP configuration.
2531 * This allows all device OPP configurations to be performed at once.
2534 * be called multiple times for the same OPP table, for example once for each
2536 * calls to dev_pm_opp_clear_config() in order to free the OPP table properly.
2647 * dev_pm_opp_clear_config() - Releases resources blocked for OPP configuration.
2650 * This allows all device OPP configurations to be cleared at once. This must be
2654 * Currently the first call itself ends up freeing all the OPP configurations,
2655 * while the later ones only drop the OPP table reference. This works well for
2656 * now as we would never want to use an half initialized OPP table and want to
2684 * devm_pm_opp_set_config() - Set OPP configuration for the device.
2686 * @config: OPP configuration.
2688 * This allows all device OPP configurations to be performed at once.
2706 * dev_pm_opp_xlate_required_opp() - Find required OPP for @src_table OPP.
2707 * @src_table: OPP table which has @dst_table as one of its required OPP table.
2708 * @dst_table: Required OPP table of the @src_table.
2709 * @src_opp: OPP from the @src_table.
2711 * This function returns the OPP (present in @dst_table) pointed out by the
2714 * The callers are required to call dev_pm_opp_put() for the returned OPP after
2723 struct dev_pm_opp *opp, *dest_opp = ERR_PTR(-ENODEV); in dev_pm_opp_xlate_required_opp() local
2739 list_for_each_entry(opp, &src_table->opp_list, node) { in dev_pm_opp_xlate_required_opp()
2740 if (opp == src_opp) { in dev_pm_opp_xlate_required_opp()
2741 dest_opp = dev_pm_opp_get(opp->required_opps[i]); in dev_pm_opp_xlate_required_opp()
2750 pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__, in dev_pm_opp_xlate_required_opp()
2759 * dev_pm_opp_xlate_performance_state() - Find required OPP's pstate for src_table.
2760 * @src_table: OPP table which has dst_table as one of its required OPP table.
2761 * @dst_table: Required OPP table of the src_table.
2764 * This Returns pstate of the OPP (present in @dst_table) pointed out by the
2765 * "required-opps" property of the OPP (present in @src_table) which has
2775 struct dev_pm_opp *opp; in dev_pm_opp_xlate_performance_state() local
2788 /* Both OPP tables must belong to genpds */ in dev_pm_opp_xlate_performance_state()
2804 pr_err("%s: Couldn't find matching OPP table (%p: %p)\n", in dev_pm_opp_xlate_performance_state()
2811 list_for_each_entry(opp, &src_table->opp_list, node) { in dev_pm_opp_xlate_performance_state()
2812 if (opp->level == pstate) in dev_pm_opp_xlate_performance_state()
2813 return opp->required_opps[i]->level; in dev_pm_opp_xlate_performance_state()
2816 pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__, src_table, in dev_pm_opp_xlate_performance_state()
2823 * dev_pm_opp_add_dynamic() - Add an OPP table from a table definitions
2825 * @data: The OPP data for the OPP to add
2827 * This function adds an opp definition to the opp table and returns status.
2828 * The opp is made available by default and it can be controlled using
2833 * Duplicate OPPs (both freq and volt are same) and opp->available
2835 * Duplicate OPPs (both freq and volt are same) and !opp->available
2859 * _opp_set_availability() - helper to set the availability of an opp
2861 * @freq: OPP frequency to modify availability
2862 * @availability_req: availability status requested for this opp
2864 * Set the availability of an OPP, opp_{enable,disable} share a common logic
2874 struct dev_pm_opp *opp __free(put_opp) = ERR_PTR(-ENODEV), *tmp_opp; in _opp_set_availability()
2881 dev_warn(dev, "%s: Device OPP not found (%ld)\n", __func__, in _opp_set_availability()
2893 opp = dev_pm_opp_get(tmp_opp); in _opp_set_availability()
2896 if (opp->available == availability_req) in _opp_set_availability()
2899 opp->available = availability_req; in _opp_set_availability()
2905 if (IS_ERR(opp)) in _opp_set_availability()
2906 return PTR_ERR(opp); in _opp_set_availability()
2908 /* Notify the change of the OPP availability */ in _opp_set_availability()
2911 opp); in _opp_set_availability()
2914 OPP_EVENT_DISABLE, opp); in _opp_set_availability()
2920 * dev_pm_opp_adjust_voltage() - helper to change the voltage of an OPP
2922 * @freq: OPP frequency to adjust voltage of
2923 * @u_volt: new OPP target voltage
2924 * @u_volt_min: new OPP min voltage
2925 * @u_volt_max: new OPP max voltage
2936 struct dev_pm_opp *opp __free(put_opp) = ERR_PTR(-ENODEV), *tmp_opp; in dev_pm_opp_adjust_voltage()
2945 dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r); in dev_pm_opp_adjust_voltage()
2956 opp = dev_pm_opp_get(tmp_opp); in dev_pm_opp_adjust_voltage()
2959 if (opp->supplies->u_volt == u_volt) in dev_pm_opp_adjust_voltage()
2962 opp->supplies->u_volt = u_volt; in dev_pm_opp_adjust_voltage()
2963 opp->supplies->u_volt_min = u_volt_min; in dev_pm_opp_adjust_voltage()
2964 opp->supplies->u_volt_max = u_volt_max; in dev_pm_opp_adjust_voltage()
2971 if (IS_ERR(opp)) in dev_pm_opp_adjust_voltage()
2972 return PTR_ERR(opp); in dev_pm_opp_adjust_voltage()
2974 /* Notify the voltage change of the OPP */ in dev_pm_opp_adjust_voltage()
2976 opp); in dev_pm_opp_adjust_voltage()
2986 * Sync voltage state of the OPP table regulators.
2995 /* Device may not have OPP table */ in dev_pm_opp_sync_regulators()
3022 * dev_pm_opp_enable() - Enable a specific OPP
3024 * @freq: OPP frequency to enable
3026 * Enables a provided opp. If the operation is valid, this returns 0, else the
3027 * corresponding error value. It is meant to be used for users an OPP available
3041 * dev_pm_opp_disable() - Disable a specific OPP
3043 * @freq: OPP frequency to disable
3045 * Disables a provided opp. If the operation is valid, this returns
3047 * control by users to make this OPP not available until the circumstances are
3061 * dev_pm_opp_register_notifier() - Register OPP notifier for the device
3080 * dev_pm_opp_unregister_notifier() - Unregister OPP notifier for the device
3101 * @dev: device pointer used to lookup OPP table.
3124 * Drop the extra reference only if the OPP table was successfully added in dev_pm_opp_remove_table()