Lines Matching full:opp_table
26 * The root of the list of all opp-tables. All opp_table structures branch off
27 * from here, with each opp_table containing the list of opps it supports in
43 static bool _find_opp_dev(const struct device *dev, struct opp_table *opp_table) in _find_opp_dev() argument
48 mutex_lock(&opp_table->lock); in _find_opp_dev()
49 list_for_each_entry(opp_dev, &opp_table->dev_list, node) in _find_opp_dev()
55 mutex_unlock(&opp_table->lock); in _find_opp_dev()
59 static struct opp_table *_find_opp_table_unlocked(struct device *dev) in _find_opp_table_unlocked()
61 struct opp_table *opp_table; in _find_opp_table_unlocked() local
63 list_for_each_entry(opp_table, &opp_tables, node) { in _find_opp_table_unlocked()
64 if (_find_opp_dev(dev, opp_table)) { in _find_opp_table_unlocked()
65 _get_opp_table_kref(opp_table); in _find_opp_table_unlocked()
66 return opp_table; in _find_opp_table_unlocked()
74 * _find_opp_table() - find opp_table struct using device pointer
79 * Return: pointer to 'struct opp_table' if found, otherwise -ENODEV or
84 struct opp_table *_find_opp_table(struct device *dev) in _find_opp_table()
86 struct opp_table *opp_table; in _find_opp_table() local
94 opp_table = _find_opp_table_unlocked(dev); in _find_opp_table()
97 return opp_table; in _find_opp_table()
107 static bool assert_single_clk(struct opp_table *opp_table) in assert_single_clk() argument
109 return !WARN_ON(opp_table->clk_count > 1); in assert_single_clk()
152 sizeof(*supplies) * opp->opp_table->regulator_count); in dev_pm_opp_get_supplies()
175 for (i = 0; i < opp->opp_table->regulator_count; i++) in dev_pm_opp_get_power()
196 if (!assert_single_clk(opp->opp_table)) in dev_pm_opp_get_freq()
234 index >= opp->opp_table->required_opp_count) { in dev_pm_opp_get_required_pstate()
240 if (lazy_linking_pending(opp->opp_table)) in dev_pm_opp_get_required_pstate()
276 struct opp_table *opp_table; in dev_pm_opp_get_max_clock_latency() local
279 opp_table = _find_opp_table(dev); in dev_pm_opp_get_max_clock_latency()
280 if (IS_ERR(opp_table)) in dev_pm_opp_get_max_clock_latency()
283 clock_latency_ns = opp_table->clock_latency_ns_max; in dev_pm_opp_get_max_clock_latency()
285 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_max_clock_latency()
299 struct opp_table *opp_table; in dev_pm_opp_get_max_volt_latency() local
309 opp_table = _find_opp_table(dev); in dev_pm_opp_get_max_volt_latency()
310 if (IS_ERR(opp_table)) in dev_pm_opp_get_max_volt_latency()
314 if (!opp_table->regulators) in dev_pm_opp_get_max_volt_latency()
317 count = opp_table->regulator_count; in dev_pm_opp_get_max_volt_latency()
323 mutex_lock(&opp_table->lock); in dev_pm_opp_get_max_volt_latency()
329 list_for_each_entry(opp, &opp_table->opp_list, node) { in dev_pm_opp_get_max_volt_latency()
340 mutex_unlock(&opp_table->lock); in dev_pm_opp_get_max_volt_latency()
343 * The caller needs to ensure that opp_table (and hence the regulator) in dev_pm_opp_get_max_volt_latency()
347 reg = opp_table->regulators[i]; in dev_pm_opp_get_max_volt_latency()
355 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_max_volt_latency()
385 struct opp_table *opp_table; in dev_pm_opp_get_suspend_opp_freq() local
388 opp_table = _find_opp_table(dev); in dev_pm_opp_get_suspend_opp_freq()
389 if (IS_ERR(opp_table)) in dev_pm_opp_get_suspend_opp_freq()
392 if (opp_table->suspend_opp && opp_table->suspend_opp->available) in dev_pm_opp_get_suspend_opp_freq()
393 freq = dev_pm_opp_get_freq(opp_table->suspend_opp); in dev_pm_opp_get_suspend_opp_freq()
395 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_suspend_opp_freq()
401 int _get_opp_count(struct opp_table *opp_table) in _get_opp_count() argument
406 mutex_lock(&opp_table->lock); in _get_opp_count()
408 list_for_each_entry(opp, &opp_table->opp_list, node) { in _get_opp_count()
413 mutex_unlock(&opp_table->lock); in _get_opp_count()
427 struct opp_table *opp_table; in dev_pm_opp_get_opp_count() local
430 opp_table = _find_opp_table(dev); in dev_pm_opp_get_opp_count()
431 if (IS_ERR(opp_table)) { in dev_pm_opp_get_opp_count()
432 count = PTR_ERR(opp_table); in dev_pm_opp_get_opp_count()
438 count = _get_opp_count(opp_table); in dev_pm_opp_get_opp_count()
439 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_opp_count()
495 static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table, in _opp_table_find_key() argument
500 bool (*assert)(struct opp_table *opp_table)) in _opp_table_find_key() argument
505 if (assert && !assert(opp_table)) in _opp_table_find_key()
508 mutex_lock(&opp_table->lock); in _opp_table_find_key()
510 list_for_each_entry(temp_opp, &opp_table->opp_list, node) { in _opp_table_find_key()
523 mutex_unlock(&opp_table->lock); in _opp_table_find_key()
533 bool (*assert)(struct opp_table *opp_table)) in _find_key() argument
535 struct opp_table *opp_table; in _find_key() local
538 opp_table = _find_opp_table(dev); in _find_key()
539 if (IS_ERR(opp_table)) { in _find_key()
541 PTR_ERR(opp_table)); in _find_key()
542 return ERR_CAST(opp_table); in _find_key()
545 opp = _opp_table_find_key(opp_table, key, index, available, read, in _find_key()
548 dev_pm_opp_put_opp_table(opp_table); in _find_key()
556 bool (*assert)(struct opp_table *opp_table)) in _find_key_exact() argument
566 static struct dev_pm_opp *_opp_table_find_key_ceil(struct opp_table *opp_table, in _opp_table_find_key_ceil() argument
569 bool (*assert)(struct opp_table *opp_table)) in _opp_table_find_key_ceil() argument
571 return _opp_table_find_key(opp_table, key, index, available, read, in _opp_table_find_key_ceil()
578 bool (*assert)(struct opp_table *opp_table)) in _find_key_ceil() argument
587 bool (*assert)(struct opp_table *opp_table)) in _find_key_floor() argument
624 static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, in _find_freq_ceil() argument
627 return _opp_table_find_key_ceil(opp_table, freq, 0, true, _read_freq, in _find_freq_ceil()
818 _opp_config_clk_single(struct device *dev, struct opp_table *opp_table, in _opp_config_clk_single() argument
835 ret = clk_set_rate(opp_table->clk, freq); in _opp_config_clk_single()
840 opp_table->rate_clk_single = freq; in _opp_config_clk_single()
851 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, in dev_pm_opp_config_clks_simple() argument
857 for (i = opp_table->clk_count - 1; i >= 0; i--) { in dev_pm_opp_config_clks_simple()
858 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]); in dev_pm_opp_config_clks_simple()
866 for (i = 0; i < opp_table->clk_count; i++) { in dev_pm_opp_config_clks_simple()
867 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]); in dev_pm_opp_config_clks_simple()
901 if (unlikely(!new_opp->opp_table->enabled)) { in _opp_config_regulator_single()
910 static int _set_opp_bw(const struct opp_table *opp_table, in _set_opp_bw() argument
916 if (!opp_table->paths) in _set_opp_bw()
919 for (i = 0; i < opp_table->path_count; i++) { in _set_opp_bw()
927 ret = icc_set_bw(opp_table->paths[i], avg, peak); in _set_opp_bw()
958 struct opp_table *opp_table, in _set_required_opps() argument
961 struct opp_table **required_opp_tables = opp_table->required_opp_tables; in _set_required_opps()
962 struct device **genpd_virt_devs = opp_table->genpd_virt_devs; in _set_required_opps()
969 if (lazy_linking_pending(opp_table)) in _set_required_opps()
992 mutex_lock(&opp_table->genpd_virt_dev_lock); in _set_required_opps()
996 for (i = 0; i < opp_table->required_opp_count; i++) { in _set_required_opps()
1002 for (i = opp_table->required_opp_count - 1; i >= 0; i--) { in _set_required_opps()
1009 mutex_unlock(&opp_table->genpd_virt_dev_lock); in _set_required_opps()
1014 static void _find_current_opp(struct device *dev, struct opp_table *opp_table) in _find_current_opp() argument
1019 if (!IS_ERR(opp_table->clk)) { in _find_current_opp()
1020 freq = clk_get_rate(opp_table->clk); in _find_current_opp()
1021 opp = _find_freq_ceil(opp_table, &freq); in _find_current_opp()
1030 mutex_lock(&opp_table->lock); in _find_current_opp()
1031 opp = list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node); in _find_current_opp()
1033 mutex_unlock(&opp_table->lock); in _find_current_opp()
1036 opp_table->current_opp = opp; in _find_current_opp()
1039 static int _disable_opp_table(struct device *dev, struct opp_table *opp_table) in _disable_opp_table() argument
1043 if (!opp_table->enabled) in _disable_opp_table()
1051 if (!_get_opp_count(opp_table)) in _disable_opp_table()
1054 ret = _set_opp_bw(opp_table, NULL, dev); in _disable_opp_table()
1058 if (opp_table->regulators) in _disable_opp_table()
1059 regulator_disable(opp_table->regulators[0]); in _disable_opp_table()
1061 ret = _set_required_opps(dev, opp_table, NULL, false); in _disable_opp_table()
1063 opp_table->enabled = false; in _disable_opp_table()
1067 static int _set_opp(struct device *dev, struct opp_table *opp_table, in _set_opp() argument
1074 return _disable_opp_table(dev, opp_table); in _set_opp()
1077 if (unlikely(!opp_table->current_opp)) in _set_opp()
1078 _find_current_opp(dev, opp_table); in _set_opp()
1080 old_opp = opp_table->current_opp; in _set_opp()
1083 if (!forced && old_opp == opp && opp_table->enabled) { in _set_opp()
1093 scaling_down = _opp_compare_key(opp_table, old_opp, opp); in _set_opp()
1099 ret = _set_required_opps(dev, opp_table, opp, true); in _set_opp()
1105 ret = _set_opp_bw(opp_table, opp, dev); in _set_opp()
1111 if (opp_table->config_regulators) { in _set_opp()
1112 ret = opp_table->config_regulators(dev, old_opp, opp, in _set_opp()
1113 opp_table->regulators, in _set_opp()
1114 opp_table->regulator_count); in _set_opp()
1123 if (opp_table->config_clks) { in _set_opp()
1124 ret = opp_table->config_clks(dev, opp_table, opp, clk_data, scaling_down); in _set_opp()
1131 if (opp_table->config_regulators) { in _set_opp()
1132 ret = opp_table->config_regulators(dev, old_opp, opp, in _set_opp()
1133 opp_table->regulators, in _set_opp()
1134 opp_table->regulator_count); in _set_opp()
1142 ret = _set_opp_bw(opp_table, opp, dev); in _set_opp()
1148 ret = _set_required_opps(dev, opp_table, opp, false); in _set_opp()
1155 opp_table->enabled = true; in _set_opp()
1160 opp_table->current_opp = opp; in _set_opp()
1178 struct opp_table *opp_table; in dev_pm_opp_set_rate() local
1184 opp_table = _find_opp_table(dev); in dev_pm_opp_set_rate()
1185 if (IS_ERR(opp_table)) { in dev_pm_opp_set_rate()
1187 return PTR_ERR(opp_table); in dev_pm_opp_set_rate()
1198 if (!_get_opp_count(opp_table)) { in dev_pm_opp_set_rate()
1199 ret = opp_table->config_clks(dev, opp_table, NULL, in dev_pm_opp_set_rate()
1204 freq = clk_round_rate(opp_table->clk, target_freq); in dev_pm_opp_set_rate()
1214 opp = _find_freq_ceil(opp_table, &temp_freq); in dev_pm_opp_set_rate()
1229 forced = opp_table->rate_clk_single != target_freq; in dev_pm_opp_set_rate()
1232 ret = _set_opp(dev, opp_table, opp, &target_freq, forced); in dev_pm_opp_set_rate()
1238 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_set_rate()
1255 struct opp_table *opp_table; in dev_pm_opp_set_opp() local
1258 opp_table = _find_opp_table(dev); in dev_pm_opp_set_opp()
1259 if (IS_ERR(opp_table)) { in dev_pm_opp_set_opp()
1261 return PTR_ERR(opp_table); in dev_pm_opp_set_opp()
1264 ret = _set_opp(dev, opp_table, opp, NULL, false); in dev_pm_opp_set_opp()
1265 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_set_opp()
1273 struct opp_table *opp_table) in _remove_opp_dev() argument
1275 opp_debug_unregister(opp_dev, opp_table); in _remove_opp_dev()
1281 struct opp_table *opp_table) in _add_opp_dev() argument
1292 mutex_lock(&opp_table->lock); in _add_opp_dev()
1293 list_add(&opp_dev->node, &opp_table->dev_list); in _add_opp_dev()
1294 mutex_unlock(&opp_table->lock); in _add_opp_dev()
1296 /* Create debugfs entries for the opp_table */ in _add_opp_dev()
1297 opp_debug_register(opp_dev, opp_table); in _add_opp_dev()
1302 static struct opp_table *_allocate_opp_table(struct device *dev, int index) in _allocate_opp_table()
1304 struct opp_table *opp_table; in _allocate_opp_table() local
1312 opp_table = kzalloc(sizeof(*opp_table), GFP_KERNEL); in _allocate_opp_table()
1313 if (!opp_table) in _allocate_opp_table()
1316 mutex_init(&opp_table->lock); in _allocate_opp_table()
1317 mutex_init(&opp_table->genpd_virt_dev_lock); in _allocate_opp_table()
1318 INIT_LIST_HEAD(&opp_table->dev_list); in _allocate_opp_table()
1319 INIT_LIST_HEAD(&opp_table->lazy); in _allocate_opp_table()
1321 opp_table->clk = ERR_PTR(-ENODEV); in _allocate_opp_table()
1324 opp_table->regulator_count = -1; in _allocate_opp_table()
1326 opp_dev = _add_opp_dev(dev, opp_table); in _allocate_opp_table()
1332 _of_init_opp_table(opp_table, dev, index); in _allocate_opp_table()
1335 ret = dev_pm_opp_of_find_icc_paths(dev, opp_table); in _allocate_opp_table()
1344 BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head); in _allocate_opp_table()
1345 INIT_LIST_HEAD(&opp_table->opp_list); in _allocate_opp_table()
1346 kref_init(&opp_table->kref); in _allocate_opp_table()
1348 return opp_table; in _allocate_opp_table()
1351 _remove_opp_dev(opp_dev, opp_table); in _allocate_opp_table()
1353 kfree(opp_table); in _allocate_opp_table()
1357 void _get_opp_table_kref(struct opp_table *opp_table) in _get_opp_table_kref() argument
1359 kref_get(&opp_table->kref); in _get_opp_table_kref()
1362 static struct opp_table *_update_opp_table_clk(struct device *dev, in _update_opp_table_clk()
1363 struct opp_table *opp_table, in _update_opp_table_clk() argument
1372 if (!getclk || IS_ERR(opp_table) || !IS_ERR(opp_table->clk) || in _update_opp_table_clk()
1373 opp_table->clks) in _update_opp_table_clk()
1374 return opp_table; in _update_opp_table_clk()
1377 opp_table->clk = clk_get(dev, NULL); in _update_opp_table_clk()
1379 ret = PTR_ERR_OR_ZERO(opp_table->clk); in _update_opp_table_clk()
1381 opp_table->config_clks = _opp_config_clk_single; in _update_opp_table_clk()
1382 opp_table->clk_count = 1; in _update_opp_table_clk()
1383 return opp_table; in _update_opp_table_clk()
1399 opp_table->clk_count = 1; in _update_opp_table_clk()
1402 return opp_table; in _update_opp_table_clk()
1405 dev_pm_opp_put_opp_table(opp_table); in _update_opp_table_clk()
1426 struct opp_table *_add_opp_table_indexed(struct device *dev, int index, in _add_opp_table_indexed()
1429 struct opp_table *opp_table; in _add_opp_table_indexed() local
1434 opp_table = _find_opp_table_unlocked(dev); in _add_opp_table_indexed()
1435 if (!IS_ERR(opp_table)) in _add_opp_table_indexed()
1449 opp_table = _managed_opp(dev, index); in _add_opp_table_indexed()
1454 if (opp_table) { in _add_opp_table_indexed()
1455 if (!_add_opp_dev(dev, opp_table)) { in _add_opp_table_indexed()
1456 dev_pm_opp_put_opp_table(opp_table); in _add_opp_table_indexed()
1457 opp_table = ERR_PTR(-ENOMEM); in _add_opp_table_indexed()
1462 opp_table = _allocate_opp_table(dev, index); in _add_opp_table_indexed()
1465 if (!IS_ERR(opp_table)) in _add_opp_table_indexed()
1466 list_add(&opp_table->node, &opp_tables); in _add_opp_table_indexed()
1474 return _update_opp_table_clk(dev, opp_table, getclk); in _add_opp_table_indexed()
1477 static struct opp_table *_add_opp_table(struct device *dev, bool getclk) in _add_opp_table()
1482 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) in dev_pm_opp_get_opp_table()
1490 struct opp_table *opp_table = container_of(kref, struct opp_table, kref); in _opp_table_kref_release() local
1495 list_del(&opp_table->node); in _opp_table_kref_release()
1498 if (opp_table->current_opp) in _opp_table_kref_release()
1499 dev_pm_opp_put(opp_table->current_opp); in _opp_table_kref_release()
1501 _of_clear_opp_table(opp_table); in _opp_table_kref_release()
1504 if (!IS_ERR(opp_table->clk)) in _opp_table_kref_release()
1505 clk_put(opp_table->clk); in _opp_table_kref_release()
1507 if (opp_table->paths) { in _opp_table_kref_release()
1508 for (i = 0; i < opp_table->path_count; i++) in _opp_table_kref_release()
1509 icc_put(opp_table->paths[i]); in _opp_table_kref_release()
1510 kfree(opp_table->paths); in _opp_table_kref_release()
1513 WARN_ON(!list_empty(&opp_table->opp_list)); in _opp_table_kref_release()
1515 list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node) { in _opp_table_kref_release()
1520 if (opp_table->genpd_performance_state) in _opp_table_kref_release()
1523 _remove_opp_dev(opp_dev, opp_table); in _opp_table_kref_release()
1526 mutex_destroy(&opp_table->genpd_virt_dev_lock); in _opp_table_kref_release()
1527 mutex_destroy(&opp_table->lock); in _opp_table_kref_release()
1528 kfree(opp_table); in _opp_table_kref_release()
1531 void dev_pm_opp_put_opp_table(struct opp_table *opp_table) in dev_pm_opp_put_opp_table() argument
1533 kref_put_mutex(&opp_table->kref, _opp_table_kref_release, in dev_pm_opp_put_opp_table()
1546 struct opp_table *opp_table = opp->opp_table; in _opp_kref_release() local
1549 mutex_unlock(&opp_table->lock); in _opp_kref_release()
1555 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp); in _opp_kref_release()
1556 _of_clear_opp(opp_table, opp); in _opp_kref_release()
1568 kref_put_mutex(&opp->kref, _opp_kref_release, &opp->opp_table->lock); in dev_pm_opp_put()
1582 struct opp_table *opp_table; in dev_pm_opp_remove() local
1584 opp_table = _find_opp_table(dev); in dev_pm_opp_remove()
1585 if (IS_ERR(opp_table)) in dev_pm_opp_remove()
1588 if (!assert_single_clk(opp_table)) in dev_pm_opp_remove()
1591 mutex_lock(&opp_table->lock); in dev_pm_opp_remove()
1593 list_for_each_entry(iter, &opp_table->opp_list, node) { in dev_pm_opp_remove()
1600 mutex_unlock(&opp_table->lock); in dev_pm_opp_remove()
1606 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove()
1614 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove()
1618 static struct dev_pm_opp *_opp_get_next(struct opp_table *opp_table, in _opp_get_next() argument
1623 mutex_lock(&opp_table->lock); in _opp_get_next()
1624 list_for_each_entry(temp, &opp_table->opp_list, node) { in _opp_get_next()
1635 mutex_unlock(&opp_table->lock); in _opp_get_next()
1642 * called without the opp_table->lock held.
1644 static void _opp_remove_all(struct opp_table *opp_table, bool dynamic) in _opp_remove_all() argument
1648 while ((opp = _opp_get_next(opp_table, dynamic))) { in _opp_remove_all()
1654 dev_pm_opp_put_opp_table(opp_table); in _opp_remove_all()
1658 bool _opp_remove_all_static(struct opp_table *opp_table) in _opp_remove_all_static() argument
1660 mutex_lock(&opp_table->lock); in _opp_remove_all_static()
1662 if (!opp_table->parsed_static_opps) { in _opp_remove_all_static()
1663 mutex_unlock(&opp_table->lock); in _opp_remove_all_static()
1667 if (--opp_table->parsed_static_opps) { in _opp_remove_all_static()
1668 mutex_unlock(&opp_table->lock); in _opp_remove_all_static()
1672 mutex_unlock(&opp_table->lock); in _opp_remove_all_static()
1674 _opp_remove_all(opp_table, false); in _opp_remove_all_static()
1686 struct opp_table *opp_table; in dev_pm_opp_remove_all_dynamic() local
1688 opp_table = _find_opp_table(dev); in dev_pm_opp_remove_all_dynamic()
1689 if (IS_ERR(opp_table)) in dev_pm_opp_remove_all_dynamic()
1692 _opp_remove_all(opp_table, true); in dev_pm_opp_remove_all_dynamic()
1695 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove_all_dynamic()
1699 struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table) in _opp_allocate() argument
1705 supply_count = opp_table->regulator_count > 0 ? in _opp_allocate()
1706 opp_table->regulator_count : 1; in _opp_allocate()
1708 clk_size = sizeof(*opp->rates) * opp_table->clk_count; in _opp_allocate()
1709 icc_size = sizeof(*opp->bandwidth) * opp_table->path_count; in _opp_allocate()
1722 opp->bandwidth = (struct dev_pm_opp_icc_bw *)(opp->rates + opp_table->clk_count); in _opp_allocate()
1730 struct opp_table *opp_table) in _opp_supported_by_regulators() argument
1735 if (!opp_table->regulators) in _opp_supported_by_regulators()
1738 for (i = 0; i < opp_table->regulator_count; i++) { in _opp_supported_by_regulators()
1739 reg = opp_table->regulators[i]; in _opp_supported_by_regulators()
1754 static int _opp_compare_rate(struct opp_table *opp_table, in _opp_compare_rate() argument
1759 for (i = 0; i < opp_table->clk_count; i++) { in _opp_compare_rate()
1768 static int _opp_compare_bw(struct opp_table *opp_table, struct dev_pm_opp *opp1, in _opp_compare_bw() argument
1773 for (i = 0; i < opp_table->path_count; i++) { in _opp_compare_bw()
1788 int _opp_compare_key(struct opp_table *opp_table, struct dev_pm_opp *opp1, in _opp_compare_key() argument
1793 ret = _opp_compare_rate(opp_table, opp1, opp2); in _opp_compare_key()
1797 ret = _opp_compare_bw(opp_table, opp1, opp2); in _opp_compare_key()
1809 struct opp_table *opp_table, in _opp_is_duplicate() argument
1819 * Need to use &opp_table->opp_list in the condition part of the 'for' in _opp_is_duplicate()
1823 list_for_each_entry(opp, &opp_table->opp_list, node) { in _opp_is_duplicate()
1824 opp_cmp = _opp_compare_key(opp_table, new_opp, opp); in _opp_is_duplicate()
1873 struct opp_table *opp_table) in _opp_add() argument
1878 mutex_lock(&opp_table->lock); in _opp_add()
1879 head = &opp_table->opp_list; in _opp_add()
1881 ret = _opp_is_duplicate(dev, new_opp, opp_table, &head); in _opp_add()
1883 mutex_unlock(&opp_table->lock); in _opp_add()
1888 mutex_unlock(&opp_table->lock); in _opp_add()
1890 new_opp->opp_table = opp_table; in _opp_add()
1893 opp_debug_create_one(new_opp, opp_table); in _opp_add()
1895 if (!_opp_supported_by_regulators(new_opp, opp_table)) { in _opp_add()
1902 if (lazy_linking_pending(opp_table)) in _opp_add()
1905 _required_opps_available(new_opp, opp_table->required_opp_count); in _opp_add()
1912 * @opp_table: OPP table
1932 int _opp_add_v1(struct opp_table *opp_table, struct device *dev, in _opp_add_v1() argument
1939 if (!assert_single_clk(opp_table)) in _opp_add_v1()
1942 new_opp = _opp_allocate(opp_table); in _opp_add_v1()
1948 tol = u_volt * opp_table->voltage_tolerance_v1 / 100; in _opp_add_v1()
1955 ret = _opp_add(dev, new_opp, opp_table); in _opp_add_v1()
1967 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); in _opp_add_v1()
1987 static int _opp_set_supported_hw(struct opp_table *opp_table, in _opp_set_supported_hw() argument
1991 if (opp_table->supported_hw) in _opp_set_supported_hw()
1994 opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions), in _opp_set_supported_hw()
1996 if (!opp_table->supported_hw) in _opp_set_supported_hw()
1999 opp_table->supported_hw_count = count; in _opp_set_supported_hw()
2006 * @opp_table: OPP table returned by _opp_set_supported_hw().
2009 * _opp_set_supported_hw(). Until this is called, the opp_table structure
2012 static void _opp_put_supported_hw(struct opp_table *opp_table) in _opp_put_supported_hw() argument
2014 if (opp_table->supported_hw) { in _opp_put_supported_hw()
2015 kfree(opp_table->supported_hw); in _opp_put_supported_hw()
2016 opp_table->supported_hw = NULL; in _opp_put_supported_hw()
2017 opp_table->supported_hw_count = 0; in _opp_put_supported_hw()
2031 static int _opp_set_prop_name(struct opp_table *opp_table, const char *name) in _opp_set_prop_name() argument
2034 if (!opp_table->prop_name) { in _opp_set_prop_name()
2035 opp_table->prop_name = kstrdup(name, GFP_KERNEL); in _opp_set_prop_name()
2036 if (!opp_table->prop_name) in _opp_set_prop_name()
2045 * @opp_table: OPP table returned by _opp_set_prop_name().
2048 * _opp_set_prop_name(). Until this is called, the opp_table structure
2051 static void _opp_put_prop_name(struct opp_table *opp_table) in _opp_put_prop_name() argument
2053 if (opp_table->prop_name) { in _opp_put_prop_name()
2054 kfree(opp_table->prop_name); in _opp_put_prop_name()
2055 opp_table->prop_name = NULL; in _opp_put_prop_name()
2071 static int _opp_set_regulators(struct opp_table *opp_table, struct device *dev, in _opp_set_regulators() argument
2086 if (opp_table->regulators) in _opp_set_regulators()
2089 opp_table->regulators = kmalloc_array(count, in _opp_set_regulators()
2090 sizeof(*opp_table->regulators), in _opp_set_regulators()
2092 if (!opp_table->regulators) in _opp_set_regulators()
2104 opp_table->regulators[i] = reg; in _opp_set_regulators()
2107 opp_table->regulator_count = count; in _opp_set_regulators()
2111 opp_table->config_regulators = _opp_config_regulator_single; in _opp_set_regulators()
2117 regulator_put(opp_table->regulators[--i]); in _opp_set_regulators()
2119 kfree(opp_table->regulators); in _opp_set_regulators()
2120 opp_table->regulators = NULL; in _opp_set_regulators()
2121 opp_table->regulator_count = -1; in _opp_set_regulators()
2128 * @opp_table: OPP table returned from _opp_set_regulators().
2130 static void _opp_put_regulators(struct opp_table *opp_table) in _opp_put_regulators() argument
2134 if (!opp_table->regulators) in _opp_put_regulators()
2137 if (opp_table->enabled) { in _opp_put_regulators()
2138 for (i = opp_table->regulator_count - 1; i >= 0; i--) in _opp_put_regulators()
2139 regulator_disable(opp_table->regulators[i]); in _opp_put_regulators()
2142 for (i = opp_table->regulator_count - 1; i >= 0; i--) in _opp_put_regulators()
2143 regulator_put(opp_table->regulators[i]); in _opp_put_regulators()
2145 kfree(opp_table->regulators); in _opp_put_regulators()
2146 opp_table->regulators = NULL; in _opp_put_regulators()
2147 opp_table->regulator_count = -1; in _opp_put_regulators()
2150 static void _put_clks(struct opp_table *opp_table, int count) in _put_clks() argument
2155 clk_put(opp_table->clks[i]); in _put_clks()
2157 kfree(opp_table->clks); in _put_clks()
2158 opp_table->clks = NULL; in _put_clks()
2174 static int _opp_set_clknames(struct opp_table *opp_table, struct device *dev, in _opp_set_clknames() argument
2198 if (opp_table->clks) in _opp_set_clknames()
2201 opp_table->clks = kmalloc_array(count, sizeof(*opp_table->clks), in _opp_set_clknames()
2203 if (!opp_table->clks) in _opp_set_clknames()
2216 opp_table->clks[i] = clk; in _opp_set_clknames()
2219 opp_table->clk_count = count; in _opp_set_clknames()
2220 opp_table->config_clks = config_clks; in _opp_set_clknames()
2224 if (!opp_table->config_clks) in _opp_set_clknames()
2225 opp_table->config_clks = _opp_config_clk_single; in _opp_set_clknames()
2239 opp_table->clk = opp_table->clks[0]; in _opp_set_clknames()
2245 _put_clks(opp_table, i); in _opp_set_clknames()
2251 * @opp_table: OPP table returned from _opp_set_clknames().
2253 static void _opp_put_clknames(struct opp_table *opp_table) in _opp_put_clknames() argument
2255 if (!opp_table->clks) in _opp_put_clknames()
2258 opp_table->config_clks = NULL; in _opp_put_clknames()
2259 opp_table->clk = ERR_PTR(-ENODEV); in _opp_put_clknames()
2261 _put_clks(opp_table, opp_table->clk_count); in _opp_put_clknames()
2273 static int _opp_set_config_regulators_helper(struct opp_table *opp_table, in _opp_set_config_regulators_helper() argument
2277 if (!opp_table->config_regulators) in _opp_set_config_regulators_helper()
2278 opp_table->config_regulators = config_regulators; in _opp_set_config_regulators_helper()
2286 * @opp_table: OPP table returned from _opp_set_config_regulators_helper().
2290 static void _opp_put_config_regulators_helper(struct opp_table *opp_table) in _opp_put_config_regulators_helper() argument
2292 if (opp_table->config_regulators) in _opp_put_config_regulators_helper()
2293 opp_table->config_regulators = NULL; in _opp_put_config_regulators_helper()
2296 static void _detach_genpd(struct opp_table *opp_table) in _detach_genpd() argument
2300 if (!opp_table->genpd_virt_devs) in _detach_genpd()
2303 for (index = 0; index < opp_table->required_opp_count; index++) { in _detach_genpd()
2304 if (!opp_table->genpd_virt_devs[index]) in _detach_genpd()
2307 dev_pm_domain_detach(opp_table->genpd_virt_devs[index], false); in _detach_genpd()
2308 opp_table->genpd_virt_devs[index] = NULL; in _detach_genpd()
2311 kfree(opp_table->genpd_virt_devs); in _detach_genpd()
2312 opp_table->genpd_virt_devs = NULL; in _detach_genpd()
2337 static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev, in _opp_attach_genpd() argument
2344 if (opp_table->genpd_virt_devs) in _opp_attach_genpd()
2352 if (!opp_table->required_opp_count) in _opp_attach_genpd()
2355 mutex_lock(&opp_table->genpd_virt_dev_lock); in _opp_attach_genpd()
2357 opp_table->genpd_virt_devs = kcalloc(opp_table->required_opp_count, in _opp_attach_genpd()
2358 sizeof(*opp_table->genpd_virt_devs), in _opp_attach_genpd()
2360 if (!opp_table->genpd_virt_devs) in _opp_attach_genpd()
2364 if (index >= opp_table->required_opp_count) { in _opp_attach_genpd()
2366 *name, opp_table->required_opp_count, index); in _opp_attach_genpd()
2377 opp_table->genpd_virt_devs[index] = virt_dev; in _opp_attach_genpd()
2383 *virt_devs = opp_table->genpd_virt_devs; in _opp_attach_genpd()
2384 mutex_unlock(&opp_table->genpd_virt_dev_lock); in _opp_attach_genpd()
2389 _detach_genpd(opp_table); in _opp_attach_genpd()
2391 mutex_unlock(&opp_table->genpd_virt_dev_lock); in _opp_attach_genpd()
2398 * @opp_table: OPP table returned by _opp_attach_genpd().
2403 static void _opp_detach_genpd(struct opp_table *opp_table) in _opp_detach_genpd() argument
2409 mutex_lock(&opp_table->genpd_virt_dev_lock); in _opp_detach_genpd()
2410 _detach_genpd(opp_table); in _opp_detach_genpd()
2411 mutex_unlock(&opp_table->genpd_virt_dev_lock); in _opp_detach_genpd()
2417 _opp_detach_genpd(data->opp_table); in _opp_clear_config()
2419 _opp_put_regulators(data->opp_table); in _opp_clear_config()
2421 _opp_put_supported_hw(data->opp_table); in _opp_clear_config()
2423 _opp_put_config_regulators_helper(data->opp_table); in _opp_clear_config()
2425 _opp_put_prop_name(data->opp_table); in _opp_clear_config()
2427 _opp_put_clknames(data->opp_table); in _opp_clear_config()
2429 dev_pm_opp_put_opp_table(data->opp_table); in _opp_clear_config()
2452 struct opp_table *opp_table; in dev_pm_opp_set_config() local
2461 opp_table = _add_opp_table(dev, false); in dev_pm_opp_set_config()
2462 if (IS_ERR(opp_table)) { in dev_pm_opp_set_config()
2464 return PTR_ERR(opp_table); in dev_pm_opp_set_config()
2467 data->opp_table = opp_table; in dev_pm_opp_set_config()
2471 if (WARN_ON(!list_empty(&opp_table->opp_list))) { in dev_pm_opp_set_config()
2478 ret = _opp_set_clknames(opp_table, dev, config->clk_names, in dev_pm_opp_set_config()
2492 ret = _opp_set_prop_name(opp_table, config->prop_name); in dev_pm_opp_set_config()
2501 ret = _opp_set_config_regulators_helper(opp_table, dev, in dev_pm_opp_set_config()
2511 ret = _opp_set_supported_hw(opp_table, config->supported_hw, in dev_pm_opp_set_config()
2521 ret = _opp_set_regulators(opp_table, dev, in dev_pm_opp_set_config()
2531 ret = _opp_attach_genpd(opp_table, dev, config->genpd_names, in dev_pm_opp_set_config()
2554 * @opp_table: OPP table returned from dev_pm_opp_set_config().
2625 struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, in dev_pm_opp_xlate_required_opp()
2626 struct opp_table *dst_table, in dev_pm_opp_xlate_required_opp()
2679 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, in dev_pm_opp_xlate_performance_state()
2680 struct opp_table *dst_table, in dev_pm_opp_xlate_performance_state()
2749 struct opp_table *opp_table; in dev_pm_opp_add() local
2752 opp_table = _add_opp_table(dev, true); in dev_pm_opp_add()
2753 if (IS_ERR(opp_table)) in dev_pm_opp_add()
2754 return PTR_ERR(opp_table); in dev_pm_opp_add()
2757 opp_table->regulator_count = 1; in dev_pm_opp_add()
2759 ret = _opp_add_v1(opp_table, dev, freq, u_volt, true); in dev_pm_opp_add()
2761 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_add()
2783 struct opp_table *opp_table; in _opp_set_availability() local
2787 /* Find the opp_table */ in _opp_set_availability()
2788 opp_table = _find_opp_table(dev); in _opp_set_availability()
2789 if (IS_ERR(opp_table)) { in _opp_set_availability()
2790 r = PTR_ERR(opp_table); in _opp_set_availability()
2795 if (!assert_single_clk(opp_table)) { in _opp_set_availability()
2800 mutex_lock(&opp_table->lock); in _opp_set_availability()
2803 list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { in _opp_set_availability()
2822 mutex_unlock(&opp_table->lock); in _opp_set_availability()
2826 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ENABLE, in _opp_set_availability()
2829 blocking_notifier_call_chain(&opp_table->head, in _opp_set_availability()
2836 mutex_unlock(&opp_table->lock); in _opp_set_availability()
2838 dev_pm_opp_put_opp_table(opp_table); in _opp_set_availability()
2859 struct opp_table *opp_table; in dev_pm_opp_adjust_voltage() local
2863 /* Find the opp_table */ in dev_pm_opp_adjust_voltage()
2864 opp_table = _find_opp_table(dev); in dev_pm_opp_adjust_voltage()
2865 if (IS_ERR(opp_table)) { in dev_pm_opp_adjust_voltage()
2866 r = PTR_ERR(opp_table); in dev_pm_opp_adjust_voltage()
2871 if (!assert_single_clk(opp_table)) { in dev_pm_opp_adjust_voltage()
2876 mutex_lock(&opp_table->lock); in dev_pm_opp_adjust_voltage()
2879 list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { in dev_pm_opp_adjust_voltage()
2900 mutex_unlock(&opp_table->lock); in dev_pm_opp_adjust_voltage()
2903 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADJUST_VOLTAGE, in dev_pm_opp_adjust_voltage()
2910 mutex_unlock(&opp_table->lock); in dev_pm_opp_adjust_voltage()
2912 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_adjust_voltage()
2965 struct opp_table *opp_table; in dev_pm_opp_register_notifier() local
2968 opp_table = _find_opp_table(dev); in dev_pm_opp_register_notifier()
2969 if (IS_ERR(opp_table)) in dev_pm_opp_register_notifier()
2970 return PTR_ERR(opp_table); in dev_pm_opp_register_notifier()
2972 ret = blocking_notifier_chain_register(&opp_table->head, nb); in dev_pm_opp_register_notifier()
2974 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_register_notifier()
2990 struct opp_table *opp_table; in dev_pm_opp_unregister_notifier() local
2993 opp_table = _find_opp_table(dev); in dev_pm_opp_unregister_notifier()
2994 if (IS_ERR(opp_table)) in dev_pm_opp_unregister_notifier()
2995 return PTR_ERR(opp_table); in dev_pm_opp_unregister_notifier()
2997 ret = blocking_notifier_chain_unregister(&opp_table->head, nb); in dev_pm_opp_unregister_notifier()
2999 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_unregister_notifier()
3014 struct opp_table *opp_table; in dev_pm_opp_remove_table() local
3017 opp_table = _find_opp_table(dev); in dev_pm_opp_remove_table()
3018 if (IS_ERR(opp_table)) { in dev_pm_opp_remove_table()
3019 int error = PTR_ERR(opp_table); in dev_pm_opp_remove_table()
3022 WARN(1, "%s: opp_table: %d\n", in dev_pm_opp_remove_table()
3033 if (_opp_remove_all_static(opp_table)) in dev_pm_opp_remove_table()
3034 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove_table()
3037 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove_table()
3051 struct opp_table *opp_table; in dev_pm_opp_sync_regulators() local
3056 opp_table = _find_opp_table(dev); in dev_pm_opp_sync_regulators()
3057 if (IS_ERR(opp_table)) in dev_pm_opp_sync_regulators()
3061 if (unlikely(!opp_table->regulators)) in dev_pm_opp_sync_regulators()
3065 if (!opp_table->enabled) in dev_pm_opp_sync_regulators()
3068 for (i = 0; i < opp_table->regulator_count; i++) { in dev_pm_opp_sync_regulators()
3069 reg = opp_table->regulators[i]; in dev_pm_opp_sync_regulators()
3076 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_sync_regulators()