Lines Matching refs:opp_table

40 static bool _find_opp_dev(const struct device *dev, struct opp_table *opp_table)  in _find_opp_dev()  argument
45 mutex_lock(&opp_table->lock); in _find_opp_dev()
46 list_for_each_entry(opp_dev, &opp_table->dev_list, node) in _find_opp_dev()
52 mutex_unlock(&opp_table->lock); in _find_opp_dev()
56 static struct opp_table *_find_opp_table_unlocked(struct device *dev) in _find_opp_table_unlocked()
58 struct opp_table *opp_table; in _find_opp_table_unlocked() local
60 list_for_each_entry(opp_table, &opp_tables, node) { in _find_opp_table_unlocked()
61 if (_find_opp_dev(dev, opp_table)) { in _find_opp_table_unlocked()
62 _get_opp_table_kref(opp_table); in _find_opp_table_unlocked()
63 return opp_table; in _find_opp_table_unlocked()
81 struct opp_table *_find_opp_table(struct device *dev) in _find_opp_table()
83 struct opp_table *opp_table; in _find_opp_table() local
91 opp_table = _find_opp_table_unlocked(dev); in _find_opp_table()
94 return opp_table; in _find_opp_table()
104 static bool assert_single_clk(struct opp_table *opp_table, in assert_single_clk() argument
107 return !WARN_ON(opp_table->clk_count > 1); in assert_single_clk()
113 static bool assert_clk_index(struct opp_table *opp_table, in assert_clk_index() argument
116 return opp_table->clk_count > index; in assert_clk_index()
122 static bool assert_bandwidth_index(struct opp_table *opp_table, in assert_bandwidth_index() argument
125 return opp_table->path_count > index; in assert_bandwidth_index()
143 if (index >= opp->opp_table->path_count) in dev_pm_opp_get_bw()
193 sizeof(*supplies) * opp->opp_table->regulator_count); in dev_pm_opp_get_supplies()
216 for (i = 0; i < opp->opp_table->regulator_count; i++) in dev_pm_opp_get_power()
234 if (IS_ERR_OR_NULL(opp) || index >= opp->opp_table->clk_count) { in dev_pm_opp_get_freq_indexed()
274 index >= opp->opp_table->required_opp_count) { in dev_pm_opp_get_required_pstate()
280 if (lazy_linking_pending(opp->opp_table)) in dev_pm_opp_get_required_pstate()
284 if (unlikely(!opp->opp_table->required_opp_tables[index]->is_genpd)) { in dev_pm_opp_get_required_pstate()
322 struct opp_table *opp_table; in dev_pm_opp_get_max_clock_latency() local
325 opp_table = _find_opp_table(dev); in dev_pm_opp_get_max_clock_latency()
326 if (IS_ERR(opp_table)) in dev_pm_opp_get_max_clock_latency()
329 clock_latency_ns = opp_table->clock_latency_ns_max; in dev_pm_opp_get_max_clock_latency()
331 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_max_clock_latency()
345 struct opp_table *opp_table; in dev_pm_opp_get_max_volt_latency() local
355 opp_table = _find_opp_table(dev); in dev_pm_opp_get_max_volt_latency()
356 if (IS_ERR(opp_table)) in dev_pm_opp_get_max_volt_latency()
360 if (!opp_table->regulators) in dev_pm_opp_get_max_volt_latency()
363 count = opp_table->regulator_count; in dev_pm_opp_get_max_volt_latency()
369 mutex_lock(&opp_table->lock); in dev_pm_opp_get_max_volt_latency()
375 list_for_each_entry(opp, &opp_table->opp_list, node) { in dev_pm_opp_get_max_volt_latency()
386 mutex_unlock(&opp_table->lock); in dev_pm_opp_get_max_volt_latency()
393 reg = opp_table->regulators[i]; in dev_pm_opp_get_max_volt_latency()
401 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_max_volt_latency()
431 struct opp_table *opp_table; in dev_pm_opp_get_suspend_opp_freq() local
434 opp_table = _find_opp_table(dev); in dev_pm_opp_get_suspend_opp_freq()
435 if (IS_ERR(opp_table)) in dev_pm_opp_get_suspend_opp_freq()
438 if (opp_table->suspend_opp && opp_table->suspend_opp->available) in dev_pm_opp_get_suspend_opp_freq()
439 freq = dev_pm_opp_get_freq(opp_table->suspend_opp); in dev_pm_opp_get_suspend_opp_freq()
441 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_suspend_opp_freq()
447 int _get_opp_count(struct opp_table *opp_table) in _get_opp_count() argument
452 mutex_lock(&opp_table->lock); in _get_opp_count()
454 list_for_each_entry(opp, &opp_table->opp_list, node) { in _get_opp_count()
459 mutex_unlock(&opp_table->lock); in _get_opp_count()
473 struct opp_table *opp_table; in dev_pm_opp_get_opp_count() local
476 opp_table = _find_opp_table(dev); in dev_pm_opp_get_opp_count()
477 if (IS_ERR(opp_table)) { in dev_pm_opp_get_opp_count()
478 count = PTR_ERR(opp_table); in dev_pm_opp_get_opp_count()
484 count = _get_opp_count(opp_table); in dev_pm_opp_get_opp_count()
485 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_get_opp_count()
541 static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table, in _opp_table_find_key() argument
546 bool (*assert)(struct opp_table *opp_table, unsigned int index)) in _opp_table_find_key() argument
551 if (assert && !assert(opp_table, index)) in _opp_table_find_key()
554 mutex_lock(&opp_table->lock); in _opp_table_find_key()
556 list_for_each_entry(temp_opp, &opp_table->opp_list, node) { in _opp_table_find_key()
569 mutex_unlock(&opp_table->lock); in _opp_table_find_key()
579 bool (*assert)(struct opp_table *opp_table, unsigned int index)) in _find_key() argument
581 struct opp_table *opp_table; in _find_key() local
584 opp_table = _find_opp_table(dev); in _find_key()
585 if (IS_ERR(opp_table)) { in _find_key()
587 PTR_ERR(opp_table)); in _find_key()
588 return ERR_CAST(opp_table); in _find_key()
591 opp = _opp_table_find_key(opp_table, key, index, available, read, in _find_key()
594 dev_pm_opp_put_opp_table(opp_table); in _find_key()
602 bool (*assert)(struct opp_table *opp_table, unsigned int index)) in _find_key_exact() argument
612 static struct dev_pm_opp *_opp_table_find_key_ceil(struct opp_table *opp_table, in _opp_table_find_key_ceil() argument
615 bool (*assert)(struct opp_table *opp_table, unsigned int index)) in _opp_table_find_key_ceil() argument
617 return _opp_table_find_key(opp_table, key, index, available, read, in _opp_table_find_key_ceil()
624 bool (*assert)(struct opp_table *opp_table, unsigned int index)) in _find_key_ceil() argument
633 bool (*assert)(struct opp_table *opp_table, unsigned int index)) in _find_key_floor() argument
699 static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table, in _find_freq_ceil() argument
702 return _opp_table_find_key_ceil(opp_table, freq, 0, true, _read_freq, in _find_freq_ceil()
992 _opp_config_clk_single(struct device *dev, struct opp_table *opp_table, in _opp_config_clk_single() argument
1009 ret = clk_set_rate(opp_table->clk, freq); in _opp_config_clk_single()
1014 opp_table->current_rate_single_clk = freq; in _opp_config_clk_single()
1025 struct opp_table *opp_table, struct dev_pm_opp *opp, void *data, in dev_pm_opp_config_clks_simple() argument
1031 for (i = opp_table->clk_count - 1; i >= 0; i--) { in dev_pm_opp_config_clks_simple()
1032 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]); in dev_pm_opp_config_clks_simple()
1040 for (i = 0; i < opp_table->clk_count; i++) { in dev_pm_opp_config_clks_simple()
1041 ret = clk_set_rate(opp_table->clks[i], opp->rates[i]); in dev_pm_opp_config_clks_simple()
1075 if (unlikely(!new_opp->opp_table->enabled)) { in _opp_config_regulator_single()
1084 static int _set_opp_bw(const struct opp_table *opp_table, in _set_opp_bw() argument
1090 if (!opp_table->paths) in _set_opp_bw()
1093 for (i = 0; i < opp_table->path_count; i++) { in _set_opp_bw()
1101 ret = icc_set_bw(opp_table->paths[i], avg, peak); in _set_opp_bw()
1134 static int _set_required_opps(struct device *dev, struct opp_table *opp_table, in _set_required_opps() argument
1137 struct device **devs = opp_table->required_devs; in _set_required_opps()
1145 if (lazy_linking_pending(opp_table)) in _set_required_opps()
1151 target = opp_table->required_opp_count; in _set_required_opps()
1154 index = opp_table->required_opp_count - 1; in _set_required_opps()
1174 static void _find_current_opp(struct device *dev, struct opp_table *opp_table) in _find_current_opp() argument
1179 if (!IS_ERR(opp_table->clk)) { in _find_current_opp()
1180 freq = clk_get_rate(opp_table->clk); in _find_current_opp()
1181 opp = _find_freq_ceil(opp_table, &freq); in _find_current_opp()
1190 mutex_lock(&opp_table->lock); in _find_current_opp()
1191 opp = list_first_entry(&opp_table->opp_list, struct dev_pm_opp, node); in _find_current_opp()
1193 mutex_unlock(&opp_table->lock); in _find_current_opp()
1196 opp_table->current_opp = opp; in _find_current_opp()
1199 static int _disable_opp_table(struct device *dev, struct opp_table *opp_table) in _disable_opp_table() argument
1203 if (!opp_table->enabled) in _disable_opp_table()
1211 if (!_get_opp_count(opp_table)) in _disable_opp_table()
1214 ret = _set_opp_bw(opp_table, NULL, dev); in _disable_opp_table()
1218 if (opp_table->regulators) in _disable_opp_table()
1219 regulator_disable(opp_table->regulators[0]); in _disable_opp_table()
1225 ret = _set_required_opps(dev, opp_table, NULL, false); in _disable_opp_table()
1228 opp_table->enabled = false; in _disable_opp_table()
1232 static int _set_opp(struct device *dev, struct opp_table *opp_table, in _set_opp() argument
1239 return _disable_opp_table(dev, opp_table); in _set_opp()
1242 if (unlikely(!opp_table->current_opp)) in _set_opp()
1243 _find_current_opp(dev, opp_table); in _set_opp()
1245 old_opp = opp_table->current_opp; in _set_opp()
1248 if (!forced && old_opp == opp && opp_table->enabled) { in _set_opp()
1258 scaling_down = _opp_compare_key(opp_table, old_opp, opp); in _set_opp()
1264 ret = _set_required_opps(dev, opp_table, opp, true); in _set_opp()
1274 ret = _set_opp_bw(opp_table, opp, dev); in _set_opp()
1280 if (opp_table->config_regulators) { in _set_opp()
1281 ret = opp_table->config_regulators(dev, old_opp, opp, in _set_opp()
1282 opp_table->regulators, in _set_opp()
1283 opp_table->regulator_count); in _set_opp()
1292 if (opp_table->config_clks) { in _set_opp()
1293 ret = opp_table->config_clks(dev, opp_table, opp, clk_data, scaling_down); in _set_opp()
1300 if (opp_table->config_regulators) { in _set_opp()
1301 ret = opp_table->config_regulators(dev, old_opp, opp, in _set_opp()
1302 opp_table->regulators, in _set_opp()
1303 opp_table->regulator_count); in _set_opp()
1311 ret = _set_opp_bw(opp_table, opp, dev); in _set_opp()
1321 ret = _set_required_opps(dev, opp_table, opp, false); in _set_opp()
1328 opp_table->enabled = true; in _set_opp()
1333 opp_table->current_opp = opp; in _set_opp()
1351 struct opp_table *opp_table; in dev_pm_opp_set_rate() local
1357 opp_table = _find_opp_table(dev); in dev_pm_opp_set_rate()
1358 if (IS_ERR(opp_table)) { in dev_pm_opp_set_rate()
1360 return PTR_ERR(opp_table); in dev_pm_opp_set_rate()
1371 if (!_get_opp_count(opp_table)) { in dev_pm_opp_set_rate()
1372 ret = opp_table->config_clks(dev, opp_table, NULL, in dev_pm_opp_set_rate()
1377 freq = clk_round_rate(opp_table->clk, target_freq); in dev_pm_opp_set_rate()
1387 opp = _find_freq_ceil(opp_table, &temp_freq); in dev_pm_opp_set_rate()
1402 forced = opp_table->current_rate_single_clk != freq; in dev_pm_opp_set_rate()
1405 ret = _set_opp(dev, opp_table, opp, &freq, forced); in dev_pm_opp_set_rate()
1411 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_set_rate()
1428 struct opp_table *opp_table; in dev_pm_opp_set_opp() local
1431 opp_table = _find_opp_table(dev); in dev_pm_opp_set_opp()
1432 if (IS_ERR(opp_table)) { in dev_pm_opp_set_opp()
1434 return PTR_ERR(opp_table); in dev_pm_opp_set_opp()
1437 ret = _set_opp(dev, opp_table, opp, NULL, false); in dev_pm_opp_set_opp()
1438 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_set_opp()
1446 struct opp_table *opp_table) in _remove_opp_dev() argument
1448 opp_debug_unregister(opp_dev, opp_table); in _remove_opp_dev()
1454 struct opp_table *opp_table) in _add_opp_dev() argument
1465 mutex_lock(&opp_table->lock); in _add_opp_dev()
1466 list_add(&opp_dev->node, &opp_table->dev_list); in _add_opp_dev()
1467 mutex_unlock(&opp_table->lock); in _add_opp_dev()
1470 opp_debug_register(opp_dev, opp_table); in _add_opp_dev()
1475 static struct opp_table *_allocate_opp_table(struct device *dev, int index) in _allocate_opp_table()
1477 struct opp_table *opp_table; in _allocate_opp_table() local
1485 opp_table = kzalloc(sizeof(*opp_table), GFP_KERNEL); in _allocate_opp_table()
1486 if (!opp_table) in _allocate_opp_table()
1489 mutex_init(&opp_table->lock); in _allocate_opp_table()
1490 INIT_LIST_HEAD(&opp_table->dev_list); in _allocate_opp_table()
1491 INIT_LIST_HEAD(&opp_table->lazy); in _allocate_opp_table()
1493 opp_table->clk = ERR_PTR(-ENODEV); in _allocate_opp_table()
1496 opp_table->regulator_count = -1; in _allocate_opp_table()
1498 opp_dev = _add_opp_dev(dev, opp_table); in _allocate_opp_table()
1504 _of_init_opp_table(opp_table, dev, index); in _allocate_opp_table()
1507 ret = dev_pm_opp_of_find_icc_paths(dev, opp_table); in _allocate_opp_table()
1516 BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head); in _allocate_opp_table()
1517 INIT_LIST_HEAD(&opp_table->opp_list); in _allocate_opp_table()
1518 kref_init(&opp_table->kref); in _allocate_opp_table()
1520 return opp_table; in _allocate_opp_table()
1523 _of_clear_opp_table(opp_table); in _allocate_opp_table()
1524 _remove_opp_dev(opp_dev, opp_table); in _allocate_opp_table()
1525 mutex_destroy(&opp_table->lock); in _allocate_opp_table()
1527 kfree(opp_table); in _allocate_opp_table()
1531 static struct opp_table *_update_opp_table_clk(struct device *dev, in _update_opp_table_clk()
1532 struct opp_table *opp_table, in _update_opp_table_clk() argument
1541 if (!getclk || IS_ERR(opp_table) || !IS_ERR(opp_table->clk) || in _update_opp_table_clk()
1542 opp_table->clks) in _update_opp_table_clk()
1543 return opp_table; in _update_opp_table_clk()
1546 opp_table->clk = clk_get(dev, NULL); in _update_opp_table_clk()
1548 ret = PTR_ERR_OR_ZERO(opp_table->clk); in _update_opp_table_clk()
1550 opp_table->config_clks = _opp_config_clk_single; in _update_opp_table_clk()
1551 opp_table->clk_count = 1; in _update_opp_table_clk()
1552 return opp_table; in _update_opp_table_clk()
1568 opp_table->clk_count = 1; in _update_opp_table_clk()
1571 return opp_table; in _update_opp_table_clk()
1574 dev_pm_opp_put_opp_table(opp_table); in _update_opp_table_clk()
1595 struct opp_table *_add_opp_table_indexed(struct device *dev, int index, in _add_opp_table_indexed()
1598 struct opp_table *opp_table; in _add_opp_table_indexed() local
1603 opp_table = _find_opp_table_unlocked(dev); in _add_opp_table_indexed()
1604 if (!IS_ERR(opp_table)) in _add_opp_table_indexed()
1618 opp_table = _managed_opp(dev, index); in _add_opp_table_indexed()
1623 if (opp_table) { in _add_opp_table_indexed()
1624 if (!_add_opp_dev(dev, opp_table)) { in _add_opp_table_indexed()
1625 dev_pm_opp_put_opp_table(opp_table); in _add_opp_table_indexed()
1626 opp_table = ERR_PTR(-ENOMEM); in _add_opp_table_indexed()
1631 opp_table = _allocate_opp_table(dev, index); in _add_opp_table_indexed()
1634 if (!IS_ERR(opp_table)) in _add_opp_table_indexed()
1635 list_add(&opp_table->node, &opp_tables); in _add_opp_table_indexed()
1643 return _update_opp_table_clk(dev, opp_table, getclk); in _add_opp_table_indexed()
1646 static struct opp_table *_add_opp_table(struct device *dev, bool getclk) in _add_opp_table()
1651 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) in dev_pm_opp_get_opp_table()
1659 struct opp_table *opp_table = container_of(kref, struct opp_table, kref); in _opp_table_kref_release() local
1664 list_del(&opp_table->node); in _opp_table_kref_release()
1667 if (opp_table->current_opp) in _opp_table_kref_release()
1668 dev_pm_opp_put(opp_table->current_opp); in _opp_table_kref_release()
1670 _of_clear_opp_table(opp_table); in _opp_table_kref_release()
1673 if (!IS_ERR(opp_table->clk)) in _opp_table_kref_release()
1674 clk_put(opp_table->clk); in _opp_table_kref_release()
1676 if (opp_table->paths) { in _opp_table_kref_release()
1677 for (i = 0; i < opp_table->path_count; i++) in _opp_table_kref_release()
1678 icc_put(opp_table->paths[i]); in _opp_table_kref_release()
1679 kfree(opp_table->paths); in _opp_table_kref_release()
1682 WARN_ON(!list_empty(&opp_table->opp_list)); in _opp_table_kref_release()
1684 list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node) in _opp_table_kref_release()
1685 _remove_opp_dev(opp_dev, opp_table); in _opp_table_kref_release()
1687 mutex_destroy(&opp_table->lock); in _opp_table_kref_release()
1688 kfree(opp_table); in _opp_table_kref_release()
1691 void _get_opp_table_kref(struct opp_table *opp_table) in _get_opp_table_kref() argument
1693 kref_get(&opp_table->kref); in _get_opp_table_kref()
1696 void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) in dev_pm_opp_get_opp_table_ref() argument
1698 _get_opp_table_kref(opp_table); in dev_pm_opp_get_opp_table_ref()
1702 void dev_pm_opp_put_opp_table(struct opp_table *opp_table) in dev_pm_opp_put_opp_table() argument
1704 kref_put_mutex(&opp_table->kref, _opp_table_kref_release, in dev_pm_opp_put_opp_table()
1717 struct opp_table *opp_table = opp->opp_table; in _opp_kref_release() local
1720 mutex_unlock(&opp_table->lock); in _opp_kref_release()
1726 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp); in _opp_kref_release()
1727 _of_clear_opp(opp_table, opp); in _opp_kref_release()
1740 kref_put_mutex(&opp->kref, _opp_kref_release, &opp->opp_table->lock); in dev_pm_opp_put()
1754 struct opp_table *opp_table; in dev_pm_opp_remove() local
1756 opp_table = _find_opp_table(dev); in dev_pm_opp_remove()
1757 if (IS_ERR(opp_table)) in dev_pm_opp_remove()
1760 if (!assert_single_clk(opp_table, 0)) in dev_pm_opp_remove()
1763 mutex_lock(&opp_table->lock); in dev_pm_opp_remove()
1765 list_for_each_entry(iter, &opp_table->opp_list, node) { in dev_pm_opp_remove()
1772 mutex_unlock(&opp_table->lock); in dev_pm_opp_remove()
1778 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove()
1786 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove()
1790 static struct dev_pm_opp *_opp_get_next(struct opp_table *opp_table, in _opp_get_next() argument
1795 mutex_lock(&opp_table->lock); in _opp_get_next()
1796 list_for_each_entry(temp, &opp_table->opp_list, node) { in _opp_get_next()
1807 mutex_unlock(&opp_table->lock); in _opp_get_next()
1816 static void _opp_remove_all(struct opp_table *opp_table, bool dynamic) in _opp_remove_all() argument
1820 while ((opp = _opp_get_next(opp_table, dynamic))) { in _opp_remove_all()
1826 dev_pm_opp_put_opp_table(opp_table); in _opp_remove_all()
1830 bool _opp_remove_all_static(struct opp_table *opp_table) in _opp_remove_all_static() argument
1832 mutex_lock(&opp_table->lock); in _opp_remove_all_static()
1834 if (!opp_table->parsed_static_opps) { in _opp_remove_all_static()
1835 mutex_unlock(&opp_table->lock); in _opp_remove_all_static()
1839 if (--opp_table->parsed_static_opps) { in _opp_remove_all_static()
1840 mutex_unlock(&opp_table->lock); in _opp_remove_all_static()
1844 mutex_unlock(&opp_table->lock); in _opp_remove_all_static()
1846 _opp_remove_all(opp_table, false); in _opp_remove_all_static()
1858 struct opp_table *opp_table; in dev_pm_opp_remove_all_dynamic() local
1860 opp_table = _find_opp_table(dev); in dev_pm_opp_remove_all_dynamic()
1861 if (IS_ERR(opp_table)) in dev_pm_opp_remove_all_dynamic()
1864 _opp_remove_all(opp_table, true); in dev_pm_opp_remove_all_dynamic()
1867 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove_all_dynamic()
1871 struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table) in _opp_allocate() argument
1877 supply_count = opp_table->regulator_count > 0 ? in _opp_allocate()
1878 opp_table->regulator_count : 1; in _opp_allocate()
1880 clk_size = sizeof(*opp->rates) * opp_table->clk_count; in _opp_allocate()
1881 icc_size = sizeof(*opp->bandwidth) * opp_table->path_count; in _opp_allocate()
1894 opp->bandwidth = (struct dev_pm_opp_icc_bw *)(opp->rates + opp_table->clk_count); in _opp_allocate()
1904 struct opp_table *opp_table) in _opp_supported_by_regulators() argument
1909 if (!opp_table->regulators) in _opp_supported_by_regulators()
1912 for (i = 0; i < opp_table->regulator_count; i++) { in _opp_supported_by_regulators()
1913 reg = opp_table->regulators[i]; in _opp_supported_by_regulators()
1928 static int _opp_compare_rate(struct opp_table *opp_table, in _opp_compare_rate() argument
1933 for (i = 0; i < opp_table->clk_count; i++) { in _opp_compare_rate()
1942 static int _opp_compare_bw(struct opp_table *opp_table, struct dev_pm_opp *opp1, in _opp_compare_bw() argument
1947 for (i = 0; i < opp_table->path_count; i++) { in _opp_compare_bw()
1962 int _opp_compare_key(struct opp_table *opp_table, struct dev_pm_opp *opp1, in _opp_compare_key() argument
1967 ret = _opp_compare_rate(opp_table, opp1, opp2); in _opp_compare_key()
1971 ret = _opp_compare_bw(opp_table, opp1, opp2); in _opp_compare_key()
1983 struct opp_table *opp_table, in _opp_is_duplicate() argument
1997 list_for_each_entry(opp, &opp_table->opp_list, node) { in _opp_is_duplicate()
1998 opp_cmp = _opp_compare_key(opp_table, new_opp, opp); in _opp_is_duplicate()
2047 struct opp_table *opp_table) in _opp_add() argument
2052 mutex_lock(&opp_table->lock); in _opp_add()
2053 head = &opp_table->opp_list; in _opp_add()
2055 ret = _opp_is_duplicate(dev, new_opp, opp_table, &head); in _opp_add()
2057 mutex_unlock(&opp_table->lock); in _opp_add()
2062 mutex_unlock(&opp_table->lock); in _opp_add()
2064 new_opp->opp_table = opp_table; in _opp_add()
2067 opp_debug_create_one(new_opp, opp_table); in _opp_add()
2069 if (!_opp_supported_by_regulators(new_opp, opp_table)) { in _opp_add()
2076 if (lazy_linking_pending(opp_table)) in _opp_add()
2079 _required_opps_available(new_opp, opp_table->required_opp_count); in _opp_add()
2105 int _opp_add_v1(struct opp_table *opp_table, struct device *dev, in _opp_add_v1() argument
2112 if (!assert_single_clk(opp_table, 0)) in _opp_add_v1()
2115 new_opp = _opp_allocate(opp_table); in _opp_add_v1()
2123 tol = u_volt * opp_table->voltage_tolerance_v1 / 100; in _opp_add_v1()
2130 ret = _opp_add(dev, new_opp, opp_table); in _opp_add_v1()
2142 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); in _opp_add_v1()
2157 static int _opp_set_supported_hw(struct opp_table *opp_table, in _opp_set_supported_hw() argument
2161 if (opp_table->supported_hw) in _opp_set_supported_hw()
2164 opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions), in _opp_set_supported_hw()
2166 if (!opp_table->supported_hw) in _opp_set_supported_hw()
2169 opp_table->supported_hw_count = count; in _opp_set_supported_hw()
2174 static void _opp_put_supported_hw(struct opp_table *opp_table) in _opp_put_supported_hw() argument
2176 if (opp_table->supported_hw) { in _opp_put_supported_hw()
2177 kfree(opp_table->supported_hw); in _opp_put_supported_hw()
2178 opp_table->supported_hw = NULL; in _opp_put_supported_hw()
2179 opp_table->supported_hw_count = 0; in _opp_put_supported_hw()
2189 static int _opp_set_prop_name(struct opp_table *opp_table, const char *name) in _opp_set_prop_name() argument
2192 if (!opp_table->prop_name) { in _opp_set_prop_name()
2193 opp_table->prop_name = kstrdup(name, GFP_KERNEL); in _opp_set_prop_name()
2194 if (!opp_table->prop_name) in _opp_set_prop_name()
2201 static void _opp_put_prop_name(struct opp_table *opp_table) in _opp_put_prop_name() argument
2203 if (opp_table->prop_name) { in _opp_put_prop_name()
2204 kfree(opp_table->prop_name); in _opp_put_prop_name()
2205 opp_table->prop_name = NULL; in _opp_put_prop_name()
2216 static int _opp_set_regulators(struct opp_table *opp_table, struct device *dev, in _opp_set_regulators() argument
2231 if (opp_table->regulators) in _opp_set_regulators()
2234 opp_table->regulators = kmalloc_array(count, in _opp_set_regulators()
2235 sizeof(*opp_table->regulators), in _opp_set_regulators()
2237 if (!opp_table->regulators) in _opp_set_regulators()
2249 opp_table->regulators[i] = reg; in _opp_set_regulators()
2252 opp_table->regulator_count = count; in _opp_set_regulators()
2256 opp_table->config_regulators = _opp_config_regulator_single; in _opp_set_regulators()
2262 regulator_put(opp_table->regulators[--i]); in _opp_set_regulators()
2264 kfree(opp_table->regulators); in _opp_set_regulators()
2265 opp_table->regulators = NULL; in _opp_set_regulators()
2266 opp_table->regulator_count = -1; in _opp_set_regulators()
2271 static void _opp_put_regulators(struct opp_table *opp_table) in _opp_put_regulators() argument
2275 if (!opp_table->regulators) in _opp_put_regulators()
2278 if (opp_table->enabled) { in _opp_put_regulators()
2279 for (i = opp_table->regulator_count - 1; i >= 0; i--) in _opp_put_regulators()
2280 regulator_disable(opp_table->regulators[i]); in _opp_put_regulators()
2283 for (i = opp_table->regulator_count - 1; i >= 0; i--) in _opp_put_regulators()
2284 regulator_put(opp_table->regulators[i]); in _opp_put_regulators()
2286 kfree(opp_table->regulators); in _opp_put_regulators()
2287 opp_table->regulators = NULL; in _opp_put_regulators()
2288 opp_table->regulator_count = -1; in _opp_put_regulators()
2291 static void _put_clks(struct opp_table *opp_table, int count) in _put_clks() argument
2296 clk_put(opp_table->clks[i]); in _put_clks()
2298 kfree(opp_table->clks); in _put_clks()
2299 opp_table->clks = NULL; in _put_clks()
2311 static int _opp_set_clknames(struct opp_table *opp_table, struct device *dev, in _opp_set_clknames() argument
2335 if (opp_table->clks) in _opp_set_clknames()
2338 opp_table->clks = kmalloc_array(count, sizeof(*opp_table->clks), in _opp_set_clknames()
2340 if (!opp_table->clks) in _opp_set_clknames()
2353 opp_table->clks[i] = clk; in _opp_set_clknames()
2356 opp_table->clk_count = count; in _opp_set_clknames()
2357 opp_table->config_clks = config_clks; in _opp_set_clknames()
2361 if (!opp_table->config_clks) in _opp_set_clknames()
2362 opp_table->config_clks = _opp_config_clk_single; in _opp_set_clknames()
2376 opp_table->clk = opp_table->clks[0]; in _opp_set_clknames()
2382 _put_clks(opp_table, i); in _opp_set_clknames()
2386 static void _opp_put_clknames(struct opp_table *opp_table) in _opp_put_clknames() argument
2388 if (!opp_table->clks) in _opp_put_clknames()
2391 opp_table->config_clks = NULL; in _opp_put_clknames()
2392 opp_table->clk = ERR_PTR(-ENODEV); in _opp_put_clknames()
2394 _put_clks(opp_table, opp_table->clk_count); in _opp_put_clknames()
2402 static int _opp_set_config_regulators_helper(struct opp_table *opp_table, in _opp_set_config_regulators_helper() argument
2406 if (!opp_table->config_regulators) in _opp_set_config_regulators_helper()
2407 opp_table->config_regulators = config_regulators; in _opp_set_config_regulators_helper()
2412 static void _opp_put_config_regulators_helper(struct opp_table *opp_table) in _opp_put_config_regulators_helper() argument
2414 if (opp_table->config_regulators) in _opp_put_config_regulators_helper()
2415 opp_table->config_regulators = NULL; in _opp_put_config_regulators_helper()
2418 static int _opp_set_required_dev(struct opp_table *opp_table, in _opp_set_required_dev() argument
2423 struct opp_table *required_table, *pd_table; in _opp_set_required_dev()
2427 if (opp_table->is_genpd) { in _opp_set_required_dev()
2432 if (index >= opp_table->required_opp_count) { in _opp_set_required_dev()
2437 required_table = opp_table->required_opp_tables[index]; in _opp_set_required_dev()
2464 opp_table->required_opp_tables[index] = pd_table; in _opp_set_required_dev()
2470 opp_table->required_devs[index] = required_dev; in _opp_set_required_dev()
2474 static void _opp_put_required_dev(struct opp_table *opp_table, in _opp_put_required_dev() argument
2477 opp_table->required_devs[index] = NULL; in _opp_put_required_dev()
2483 _opp_put_required_dev(data->opp_table, in _opp_clear_config()
2486 _opp_put_regulators(data->opp_table); in _opp_clear_config()
2488 _opp_put_supported_hw(data->opp_table); in _opp_clear_config()
2490 _opp_put_config_regulators_helper(data->opp_table); in _opp_clear_config()
2492 _opp_put_prop_name(data->opp_table); in _opp_clear_config()
2494 _opp_put_clknames(data->opp_table); in _opp_clear_config()
2496 dev_pm_opp_put_opp_table(data->opp_table); in _opp_clear_config()
2519 struct opp_table *opp_table; in dev_pm_opp_set_config() local
2528 opp_table = _add_opp_table(dev, false); in dev_pm_opp_set_config()
2529 if (IS_ERR(opp_table)) { in dev_pm_opp_set_config()
2531 return PTR_ERR(opp_table); in dev_pm_opp_set_config()
2534 data->opp_table = opp_table; in dev_pm_opp_set_config()
2538 if (WARN_ON(!list_empty(&opp_table->opp_list))) { in dev_pm_opp_set_config()
2545 ret = _opp_set_clknames(opp_table, dev, config->clk_names, in dev_pm_opp_set_config()
2559 ret = _opp_set_prop_name(opp_table, config->prop_name); in dev_pm_opp_set_config()
2568 ret = _opp_set_config_regulators_helper(opp_table, dev, in dev_pm_opp_set_config()
2578 ret = _opp_set_supported_hw(opp_table, config->supported_hw, in dev_pm_opp_set_config()
2588 ret = _opp_set_regulators(opp_table, dev, in dev_pm_opp_set_config()
2597 ret = _opp_set_required_dev(opp_table, dev, in dev_pm_opp_set_config()
2693 struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, in dev_pm_opp_xlate_required_opp()
2694 struct opp_table *dst_table, in dev_pm_opp_xlate_required_opp()
2747 int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, in dev_pm_opp_xlate_performance_state()
2748 struct opp_table *dst_table, in dev_pm_opp_xlate_performance_state()
2822 struct opp_table *opp_table; in dev_pm_opp_add_dynamic() local
2825 opp_table = _add_opp_table(dev, true); in dev_pm_opp_add_dynamic()
2826 if (IS_ERR(opp_table)) in dev_pm_opp_add_dynamic()
2827 return PTR_ERR(opp_table); in dev_pm_opp_add_dynamic()
2830 opp_table->regulator_count = 1; in dev_pm_opp_add_dynamic()
2832 ret = _opp_add_v1(opp_table, dev, data, true); in dev_pm_opp_add_dynamic()
2834 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_add_dynamic()
2856 struct opp_table *opp_table; in _opp_set_availability() local
2861 opp_table = _find_opp_table(dev); in _opp_set_availability()
2862 if (IS_ERR(opp_table)) { in _opp_set_availability()
2863 r = PTR_ERR(opp_table); in _opp_set_availability()
2868 if (!assert_single_clk(opp_table, 0)) { in _opp_set_availability()
2873 mutex_lock(&opp_table->lock); in _opp_set_availability()
2876 list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { in _opp_set_availability()
2895 mutex_unlock(&opp_table->lock); in _opp_set_availability()
2899 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ENABLE, in _opp_set_availability()
2902 blocking_notifier_call_chain(&opp_table->head, in _opp_set_availability()
2909 mutex_unlock(&opp_table->lock); in _opp_set_availability()
2911 dev_pm_opp_put_opp_table(opp_table); in _opp_set_availability()
2932 struct opp_table *opp_table; in dev_pm_opp_adjust_voltage() local
2937 opp_table = _find_opp_table(dev); in dev_pm_opp_adjust_voltage()
2938 if (IS_ERR(opp_table)) { in dev_pm_opp_adjust_voltage()
2939 r = PTR_ERR(opp_table); in dev_pm_opp_adjust_voltage()
2944 if (!assert_single_clk(opp_table, 0)) { in dev_pm_opp_adjust_voltage()
2949 mutex_lock(&opp_table->lock); in dev_pm_opp_adjust_voltage()
2952 list_for_each_entry(tmp_opp, &opp_table->opp_list, node) { in dev_pm_opp_adjust_voltage()
2973 mutex_unlock(&opp_table->lock); in dev_pm_opp_adjust_voltage()
2976 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADJUST_VOLTAGE, in dev_pm_opp_adjust_voltage()
2983 mutex_unlock(&opp_table->lock); in dev_pm_opp_adjust_voltage()
2985 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_adjust_voltage()
3000 struct opp_table *opp_table; in dev_pm_opp_sync_regulators() local
3005 opp_table = _find_opp_table(dev); in dev_pm_opp_sync_regulators()
3006 if (IS_ERR(opp_table)) in dev_pm_opp_sync_regulators()
3010 if (unlikely(!opp_table->regulators)) in dev_pm_opp_sync_regulators()
3014 if (!opp_table->enabled) in dev_pm_opp_sync_regulators()
3017 for (i = 0; i < opp_table->regulator_count; i++) { in dev_pm_opp_sync_regulators()
3018 reg = opp_table->regulators[i]; in dev_pm_opp_sync_regulators()
3025 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_sync_regulators()
3079 struct opp_table *opp_table; in dev_pm_opp_register_notifier() local
3082 opp_table = _find_opp_table(dev); in dev_pm_opp_register_notifier()
3083 if (IS_ERR(opp_table)) in dev_pm_opp_register_notifier()
3084 return PTR_ERR(opp_table); in dev_pm_opp_register_notifier()
3086 ret = blocking_notifier_chain_register(&opp_table->head, nb); in dev_pm_opp_register_notifier()
3088 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_register_notifier()
3104 struct opp_table *opp_table; in dev_pm_opp_unregister_notifier() local
3107 opp_table = _find_opp_table(dev); in dev_pm_opp_unregister_notifier()
3108 if (IS_ERR(opp_table)) in dev_pm_opp_unregister_notifier()
3109 return PTR_ERR(opp_table); in dev_pm_opp_unregister_notifier()
3111 ret = blocking_notifier_chain_unregister(&opp_table->head, nb); in dev_pm_opp_unregister_notifier()
3113 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_unregister_notifier()
3128 struct opp_table *opp_table; in dev_pm_opp_remove_table() local
3131 opp_table = _find_opp_table(dev); in dev_pm_opp_remove_table()
3132 if (IS_ERR(opp_table)) { in dev_pm_opp_remove_table()
3133 int error = PTR_ERR(opp_table); in dev_pm_opp_remove_table()
3147 if (_opp_remove_all_static(opp_table)) in dev_pm_opp_remove_table()
3148 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove_table()
3151 dev_pm_opp_put_opp_table(opp_table); in dev_pm_opp_remove_table()