Lines Matching +full:opp +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Generic OPP OF helpers
5 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
22 #include "opp.h"
24 /* OPP tables with uninitialized required OPPs, protected by opp_table_lock */
28 * Returns opp descriptor node for a device node, caller must
34 /* "operating-points-v2" can be an array for power domain providers */ in _opp_of_get_opp_desc_node()
35 return of_parse_phandle(np, "operating-points-v2", index); in _opp_of_get_opp_desc_node()
38 /* Returns opp descriptor node for a device, caller must do of_node_put() */
41 return _opp_of_get_opp_desc_node(dev->of_node, 0); in dev_pm_opp_of_get_opp_desc_node()
50 np = _opp_of_get_opp_desc_node(dev->of_node, index); in _managed_opp()
55 if (opp_table->np == np) { in _managed_opp()
57 * Multiple devices can point to the same OPP table and in _managed_opp()
58 * so will have same node-pointer, np. in _managed_opp()
61 * OPP table contains a "opp-shared" property. in _managed_opp()
63 if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) { in _managed_opp()
77 /* The caller must call dev_pm_opp_put() after the OPP is used */
81 struct dev_pm_opp *opp; in _find_opp_of_np() local
83 mutex_lock(&opp_table->lock); in _find_opp_of_np()
85 list_for_each_entry(opp, &opp_table->opp_list, node) { in _find_opp_of_np()
86 if (opp->np == opp_np) { in _find_opp_of_np()
87 dev_pm_opp_get(opp); in _find_opp_of_np()
88 mutex_unlock(&opp_table->lock); in _find_opp_of_np()
89 return opp; in _find_opp_of_np()
93 mutex_unlock(&opp_table->lock); in _find_opp_of_np()
101 return of_parse_phandle(np, "required-opps", index); in of_parse_required_opp()
119 if (opp_table_np == opp_table->np) { in _find_table_of_opp_np()
128 return ERR_PTR(-ENODEV); in _find_table_of_opp_np()
134 struct opp_table **required_opp_tables = opp_table->required_opp_tables; in _opp_table_free_required_tables()
140 for (i = 0; i < opp_table->required_opp_count; i++) { in _opp_table_free_required_tables()
149 opp_table->required_opp_count = 0; in _opp_table_free_required_tables()
150 opp_table->required_opp_tables = NULL; in _opp_table_free_required_tables()
153 list_del(&opp_table->lazy); in _opp_table_free_required_tables()
158 * Populate all devices and opp tables which are part of "required-opps" list.
159 * Checking only the first OPP node should be enough.
170 /* Traversing the first OPP node is all we need */ in _opp_table_alloc_required_tables()
173 dev_warn(dev, "Empty OPP table\n"); in _opp_table_alloc_required_tables()
178 count = of_count_phandle_with_args(np, "required-opps", NULL); in _opp_table_alloc_required_tables()
187 opp_table->required_opp_tables = required_opp_tables; in _opp_table_alloc_required_tables()
188 opp_table->required_opp_count = count; in _opp_table_alloc_required_tables()
205 * The OPP table is not held while allocating the table, take it in _opp_table_alloc_required_tables()
209 list_add(&opp_table->lazy, &lazy_opp_tables); in _opp_table_alloc_required_tables()
233 np = of_node_get(dev->of_node); in _of_init_opp_table()
237 if (!of_property_read_u32(np, "clock-latency", &val)) in _of_init_opp_table()
238 opp_table->clock_latency_ns_max = val; in _of_init_opp_table()
239 of_property_read_u32(np, "voltage-tolerance", in _of_init_opp_table()
240 &opp_table->voltage_tolerance_v1); in _of_init_opp_table()
242 if (of_property_present(np, "#power-domain-cells")) in _of_init_opp_table()
243 opp_table->is_genpd = true; in _of_init_opp_table()
245 /* Get OPP table node */ in _of_init_opp_table()
252 if (of_property_read_bool(opp_np, "opp-shared")) in _of_init_opp_table()
253 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; in _of_init_opp_table()
255 opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; in _of_init_opp_table()
257 opp_table->np = opp_np; in _of_init_opp_table()
265 of_node_put(opp_table->np); in _of_clear_opp_table()
273 struct dev_pm_opp *opp) in _of_opp_free_required_opps() argument
275 struct dev_pm_opp **required_opps = opp->required_opps; in _of_opp_free_required_opps()
281 for (i = 0; i < opp_table->required_opp_count; i++) { in _of_opp_free_required_opps()
289 opp->required_opps = NULL; in _of_opp_free_required_opps()
293 void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp) in _of_clear_opp() argument
295 _of_opp_free_required_opps(opp_table, opp); in _of_clear_opp()
296 of_node_put(opp->np); in _of_clear_opp()
299 /* Populate all required OPPs which are part of "required-opps" list */
301 struct dev_pm_opp *opp) in _of_opp_alloc_required_opps() argument
306 int i, ret, count = opp_table->required_opp_count; in _of_opp_alloc_required_opps()
313 return -ENOMEM; in _of_opp_alloc_required_opps()
315 opp->required_opps = required_opps; in _of_opp_alloc_required_opps()
318 required_table = opp_table->required_opp_tables[i]; in _of_opp_alloc_required_opps()
324 np = of_parse_required_opp(opp->np, i); in _of_opp_alloc_required_opps()
326 ret = -ENODEV; in _of_opp_alloc_required_opps()
334 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n", in _of_opp_alloc_required_opps()
335 __func__, opp->np, i); in _of_opp_alloc_required_opps()
336 ret = -ENODEV; in _of_opp_alloc_required_opps()
344 _of_opp_free_required_opps(opp_table, opp); in _of_opp_alloc_required_opps()
349 /* Link required OPPs for an individual OPP */
354 struct dev_pm_opp *opp; in lazy_link_required_opps() local
356 list_for_each_entry(opp, &opp_table->opp_list, node) { in lazy_link_required_opps()
357 required_np = of_parse_required_opp(opp->np, index); in lazy_link_required_opps()
359 return -ENODEV; in lazy_link_required_opps()
361 opp->required_opps[index] = _find_opp_of_np(new_table, required_np); in lazy_link_required_opps()
364 if (!opp->required_opps[index]) { in lazy_link_required_opps()
365 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n", in lazy_link_required_opps()
366 __func__, opp->np, index); in lazy_link_required_opps()
367 return -ENODEV; in lazy_link_required_opps()
374 /* Link required OPPs for all OPPs of the newly added OPP table */
379 struct dev_pm_opp *opp; in lazy_link_required_opp_table() local
388 opp_np = of_get_next_available_child(opp_table->np, NULL); in lazy_link_required_opp_table()
390 for (i = 0; i < opp_table->required_opp_count; i++) { in lazy_link_required_opp_table()
391 required_opp_tables = opp_table->required_opp_tables; in lazy_link_required_opp_table()
393 /* Required opp-table is already parsed */ in lazy_link_required_opp_table()
405 * Newly added table isn't the required opp-table for in lazy_link_required_opp_table()
408 if (required_table_np != new_table->np) { in lazy_link_required_opp_table()
427 /* All required opp-tables found, remove from lazy list */ in lazy_link_required_opp_table()
430 list_del_init(&opp_table->lazy); in lazy_link_required_opp_table()
432 list_for_each_entry(opp, &opp_table->opp_list, node) in lazy_link_required_opp_table()
433 _required_opps_available(opp, opp_table->required_opp_count); in lazy_link_required_opp_table()
446 np = of_node_get(dev->of_node); in _bandwidth_supported()
448 return -ENODEV; in _bandwidth_supported()
453 opp_np = of_node_get(opp_table->np); in _bandwidth_supported()
456 /* Lets not fail in case we are parsing opp-v1 bindings */ in _bandwidth_supported()
460 /* Checking only first OPP is sufficient */ in _bandwidth_supported()
464 dev_err(dev, "OPP table empty\n"); in _bandwidth_supported()
465 return -EINVAL; in _bandwidth_supported()
468 prop = of_find_property(np, "opp-peak-kBps", NULL); in _bandwidth_supported()
471 if (!prop || !prop->length) in _bandwidth_supported()
474 return 1; in _bandwidth_supported()
485 if (ret == -EINVAL) in dev_pm_opp_of_find_icc_paths()
486 return 0; /* Empty OPP table is a valid corner-case, let's not fail */ in dev_pm_opp_of_find_icc_paths()
492 np = of_node_get(dev->of_node); in dev_pm_opp_of_find_icc_paths()
497 "#interconnect-cells"); in dev_pm_opp_of_find_icc_paths()
502 /* two phandles when #interconnect-cells = <1> */ in dev_pm_opp_of_find_icc_paths()
505 return -EINVAL; in dev_pm_opp_of_find_icc_paths()
511 return -ENOMEM; in dev_pm_opp_of_find_icc_paths()
522 opp_table->paths = paths; in dev_pm_opp_of_find_icc_paths()
523 opp_table->path_count = num_paths; in dev_pm_opp_of_find_icc_paths()
528 while (i--) in dev_pm_opp_of_find_icc_paths()
540 unsigned int levels = opp_table->supported_hw_count; in _opp_is_supported()
544 if (!opp_table->supported_hw) { in _opp_is_supported()
547 * platform but there is an opp-supported-hw value set for in _opp_is_supported()
548 * an OPP then the OPP should not be enabled as there is in _opp_is_supported()
551 if (of_property_present(np, "opp-supported-hw")) in _opp_is_supported()
557 count = of_property_count_u32_elems(np, "opp-supported-hw"); in _opp_is_supported()
559 dev_err(dev, "%s: Invalid opp-supported-hw property (%d)\n", in _opp_is_supported()
571 ret = of_property_read_u32_index(np, "opp-supported-hw", in _opp_is_supported()
574 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n", in _opp_is_supported()
580 if (!(val & opp_table->supported_hw[j])) { in _opp_is_supported()
593 static u32 *_parse_named_prop(struct dev_pm_opp *opp, struct device *dev, in _parse_named_prop() argument
602 /* Search for "opp-<prop_type>-<name>" */ in _parse_named_prop()
603 if (opp_table->prop_name) { in _parse_named_prop()
604 snprintf(name, sizeof(name), "opp-%s-%s", prop_type, in _parse_named_prop()
605 opp_table->prop_name); in _parse_named_prop()
606 prop = of_find_property(opp->np, name, NULL); in _parse_named_prop()
610 /* Search for "opp-<prop_type>" */ in _parse_named_prop()
611 snprintf(name, sizeof(name), "opp-%s", prop_type); in _parse_named_prop()
612 prop = of_find_property(opp->np, name, NULL); in _parse_named_prop()
617 count = of_property_count_u32_elems(opp->np, name); in _parse_named_prop()
627 * regulator_count to 1. in _parse_named_prop()
629 if (unlikely(opp_table->regulator_count == -1)) in _parse_named_prop()
630 opp_table->regulator_count = 1; in _parse_named_prop()
632 if (count != opp_table->regulator_count && in _parse_named_prop()
633 (!triplet || count != opp_table->regulator_count * 3)) { in _parse_named_prop()
635 __func__, prop_type, count, opp_table->regulator_count); in _parse_named_prop()
636 return ERR_PTR(-EINVAL); in _parse_named_prop()
641 return ERR_PTR(-EINVAL); in _parse_named_prop()
643 ret = of_property_read_u32_array(opp->np, name, out, count); in _parse_named_prop()
647 return ERR_PTR(-EINVAL); in _parse_named_prop()
651 *triplet = count != opp_table->regulator_count; in _parse_named_prop()
656 static u32 *opp_parse_microvolt(struct dev_pm_opp *opp, struct device *dev, in opp_parse_microvolt() argument
661 microvolt = _parse_named_prop(opp, dev, opp_table, "microvolt", triplet); in opp_parse_microvolt()
669 * information is provided. Check only for the first OPP, as in opp_parse_microvolt()
673 if (list_empty(&opp_table->opp_list) && in opp_parse_microvolt()
674 opp_table->regulator_count > 0) { in opp_parse_microvolt()
675 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n", in opp_parse_microvolt()
677 return ERR_PTR(-EINVAL); in opp_parse_microvolt()
684 static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, in opp_parse_supplies() argument
691 microvolt = opp_parse_microvolt(opp, dev, opp_table, &triplet); in opp_parse_supplies()
695 microamp = _parse_named_prop(opp, dev, opp_table, "microamp", NULL); in opp_parse_supplies()
701 microwatt = _parse_named_prop(opp, dev, opp_table, "microwatt", NULL); in opp_parse_supplies()
711 if (unlikely(opp_table->regulator_count == -1)) { in opp_parse_supplies()
712 opp_table->regulator_count = 0; in opp_parse_supplies()
716 for (i = 0, j = 0; i < opp_table->regulator_count; i++) { in opp_parse_supplies()
718 opp->supplies[i].u_volt = microvolt[j++]; in opp_parse_supplies()
721 opp->supplies[i].u_volt_min = microvolt[j++]; in opp_parse_supplies()
722 opp->supplies[i].u_volt_max = microvolt[j++]; in opp_parse_supplies()
724 opp->supplies[i].u_volt_min = opp->supplies[i].u_volt; in opp_parse_supplies()
725 opp->supplies[i].u_volt_max = opp->supplies[i].u_volt; in opp_parse_supplies()
730 opp->supplies[i].u_amp = microamp[i]; in opp_parse_supplies()
733 opp->supplies[i].u_watt = microwatt[i]; in opp_parse_supplies()
746 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
748 * @dev: device pointer used to lookup OPP table.
765 prop = of_find_property(np, "opp-hz", NULL); in _read_rate()
767 return -ENODEV; in _read_rate()
769 count = prop->length / sizeof(u64); in _read_rate()
770 if (opp_table->clk_count != count) { in _read_rate()
771 pr_err("%s: Count mismatch between opp-hz and clk_count (%d %d)\n", in _read_rate()
772 __func__, count, opp_table->clk_count); in _read_rate()
773 return -EINVAL; in _read_rate()
778 return -ENOMEM; in _read_rate()
780 ret = of_property_read_u64_array(np, "opp-hz", rates, count); in _read_rate()
782 pr_err("%s: Error parsing opp-hz: %d\n", __func__, ret); in _read_rate()
790 new_opp->rates[i] = (unsigned long)rates[i]; in _read_rate()
793 WARN_ON(new_opp->rates[i] != rates[i]); in _read_rate()
805 const char *name = peak ? "opp-peak-kBps" : "opp-avg-kBps"; in _read_bw()
812 return -ENODEV; in _read_bw()
814 count = prop->length / sizeof(u32); in _read_bw()
815 if (opp_table->path_count != count) { in _read_bw()
817 __func__, name, count, opp_table->path_count); in _read_bw()
818 return -EINVAL; in _read_bw()
823 return -ENOMEM; in _read_bw()
833 new_opp->bandwidth[i].peak = kBps_to_icc(bw[i]); in _read_bw()
835 new_opp->bandwidth[i].avg = kBps_to_icc(bw[i]); in _read_bw()
852 else if (ret != -ENODEV) in _read_opp_key()
857 * opp-peak-kBps = <path1_value path2_value>; in _read_opp_key()
858 * opp-avg-kBps = <path1_value path2_value>; in _read_opp_key()
867 if (ret && ret != -ENODEV) in _read_opp_key()
870 if (!of_property_read_u32(np, "opp-level", &new_opp->level)) in _read_opp_key()
880 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
881 * @opp_table: OPP table
885 * This function adds an opp definition to the opp table and returns status. The
886 * opp can be controlled using dev_pm_opp_enable/disable functions and may be
890 * Valid OPP pointer:
893 * Duplicate OPPs (both freq and volt are same) and opp->available
894 * OR if the OPP is not supported by hardware.
895 * ERR_PTR(-EEXIST):
897 * Duplicate OPPs (both freq and volt are same) and !opp->available
898 * ERR_PTR(-ENOMEM):
900 * ERR_PTR(-EINVAL):
901 * Failed parsing the OPP node
912 return ERR_PTR(-ENOMEM); in _opp_add_static_v2()
916 dev_err(dev, "%s: opp key field not found\n", __func__); in _opp_add_static_v2()
920 /* Check if the OPP supports hardware's hierarchy of versions or not */ in _opp_add_static_v2()
922 dev_dbg(dev, "OPP not supported by hardware: %s\n", in _opp_add_static_v2()
927 new_opp->turbo = of_property_read_bool(np, "turbo-mode"); in _opp_add_static_v2()
929 new_opp->np = of_node_get(np); in _opp_add_static_v2()
930 new_opp->dynamic = false; in _opp_add_static_v2()
931 new_opp->available = true; in _opp_add_static_v2()
937 if (!of_property_read_u32(np, "clock-latency-ns", &val)) in _opp_add_static_v2()
938 new_opp->clock_latency_ns = val; in _opp_add_static_v2()
947 if (ret == -EBUSY) in _opp_add_static_v2()
952 /* OPP to select on device suspend */ in _opp_add_static_v2()
953 if (of_property_read_bool(np, "opp-suspend")) { in _opp_add_static_v2()
954 if (opp_table->suspend_opp) { in _opp_add_static_v2()
955 /* Pick the OPP with higher rate/bw/level as suspend OPP */ in _opp_add_static_v2()
956 if (_opp_compare_key(opp_table, new_opp, opp_table->suspend_opp) == 1) { in _opp_add_static_v2()
957 opp_table->suspend_opp->suspend = false; in _opp_add_static_v2()
958 new_opp->suspend = true; in _opp_add_static_v2()
959 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
962 new_opp->suspend = true; in _opp_add_static_v2()
963 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
967 if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max) in _opp_add_static_v2()
968 opp_table->clock_latency_ns_max = new_opp->clock_latency_ns; in _opp_add_static_v2()
971 __func__, new_opp->turbo, new_opp->rates[0], in _opp_add_static_v2()
972 new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min, in _opp_add_static_v2()
973 new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns, in _opp_add_static_v2()
974 new_opp->level); in _opp_add_static_v2()
980 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); in _opp_add_static_v2()
991 /* Initializes OPP tables based on new bindings */
996 struct dev_pm_opp *opp; in _of_add_opp_table_v2() local
998 /* OPP table is already initialized for the device */ in _of_add_opp_table_v2()
999 mutex_lock(&opp_table->lock); in _of_add_opp_table_v2()
1000 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v2()
1001 opp_table->parsed_static_opps++; in _of_add_opp_table_v2()
1002 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1006 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v2()
1007 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1009 /* We have opp-table node now, iterate over it and add OPPs */ in _of_add_opp_table_v2()
1010 for_each_available_child_of_node(opp_table->np, np) { in _of_add_opp_table_v2()
1011 opp = _opp_add_static_v2(opp_table, dev, np); in _of_add_opp_table_v2()
1012 if (IS_ERR(opp)) { in _of_add_opp_table_v2()
1013 ret = PTR_ERR(opp); in _of_add_opp_table_v2()
1014 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, in _of_add_opp_table_v2()
1018 } else if (opp) { in _of_add_opp_table_v2()
1026 ret = -ENOENT; in _of_add_opp_table_v2()
1040 /* Initializes OPP tables based on old-deprecated bindings */
1047 mutex_lock(&opp_table->lock); in _of_add_opp_table_v1()
1048 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v1()
1049 opp_table->parsed_static_opps++; in _of_add_opp_table_v1()
1050 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1054 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v1()
1055 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1057 prop = of_find_property(dev->of_node, "operating-points", NULL); in _of_add_opp_table_v1()
1059 ret = -ENODEV; in _of_add_opp_table_v1()
1062 if (!prop->value) { in _of_add_opp_table_v1()
1063 ret = -ENODATA; in _of_add_opp_table_v1()
1068 * Each OPP is a set of tuples consisting of frequency and in _of_add_opp_table_v1()
1069 * voltage like <freq-kHz vol-uV>. in _of_add_opp_table_v1()
1071 nr = prop->length / sizeof(u32); in _of_add_opp_table_v1()
1073 dev_err(dev, "%s: Invalid OPP table\n", __func__); in _of_add_opp_table_v1()
1074 ret = -EINVAL; in _of_add_opp_table_v1()
1078 val = prop->value; in _of_add_opp_table_v1()
1085 dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", in _of_add_opp_table_v1()
1089 nr -= 2; in _of_add_opp_table_v1()
1107 * If only one phandle is present, then the same OPP table in _of_add_table_indexed()
1110 count = of_count_phandle_with_args(dev->of_node, in _of_add_table_indexed()
1111 "operating-points-v2", NULL); in _of_add_table_indexed()
1112 if (count == 1) in _of_add_table_indexed()
1124 if (opp_table->np) in _of_add_table_indexed()
1152 * devm_pm_opp_of_add_table() - Initialize opp table from device tree
1153 * @dev: device pointer used to lookup OPP table.
1155 * Register the initial OPP table with the OPP library for given device.
1161 * Duplicate OPPs (both freq and volt are same) and opp->available
1162 * -EEXIST Freq are same and volt are different OR
1163 * Duplicate OPPs (both freq and volt are same) and !opp->available
1164 * -ENOMEM Memory allocation failure
1165 * -ENODEV when 'operating-points' property is not found or is invalid data
1167 * -ENODATA when empty 'operating-points' property is found
1168 * -EINVAL when invalid entries are found in opp-v2 table
1177 * dev_pm_opp_of_add_table() - Initialize opp table from device tree
1178 * @dev: device pointer used to lookup OPP table.
1180 * Register the initial OPP table with the OPP library for given device.
1184 * Duplicate OPPs (both freq and volt are same) and opp->available
1185 * -EEXIST Freq are same and volt are different OR
1186 * Duplicate OPPs (both freq and volt are same) and !opp->available
1187 * -ENOMEM Memory allocation failure
1188 * -ENODEV when 'operating-points' property is not found or is invalid data
1190 * -ENODATA when empty 'operating-points' property is found
1191 * -EINVAL when invalid entries are found in opp-v2 table
1200 * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
1201 * @dev: device pointer used to lookup OPP table.
1204 * Register the initial OPP table with the OPP library for given device only
1205 * using the "operating-points-v2" property.
1216 * devm_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
1217 * @dev: device pointer used to lookup OPP table.
1220 * This is a resource-managed variant of dev_pm_opp_of_add_table_indexed().
1231 * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
1232 * @cpumask: cpumask for which OPP table needs to be removed
1234 * This removes the OPP tables for CPUs present in the @cpumask.
1239 _dev_pm_opp_cpumask_remove_table(cpumask, -1); in dev_pm_opp_of_cpumask_remove_table()
1244 * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
1245 * @cpumask: cpumask for which OPP table needs to be added.
1247 * This adds the OPP tables for CPUs present in the @cpumask.
1255 return -ENODEV; in dev_pm_opp_of_cpumask_add_table()
1262 ret = -ENODEV; in dev_pm_opp_of_cpumask_add_table()
1269 * OPP may get registered dynamically, don't print error in dev_pm_opp_of_cpumask_add_table()
1272 pr_debug("%s: couldn't find opp table for cpu:%d, %d\n", in dev_pm_opp_of_cpumask_add_table()
1290 * Works only for OPP v2 bindings.
1292 * Returns -ENOENT if operating-points-v2 bindings aren't supported.
1295 * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
1296 * @cpu_dev using operating-points-v2
1304 * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
1312 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
1315 dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__); in dev_pm_opp_of_get_sharing_cpus()
1316 return -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1319 cpumask_set_cpu(cpu_dev->id, cpumask); in dev_pm_opp_of_get_sharing_cpus()
1322 if (!of_property_read_bool(np, "opp-shared")) in dev_pm_opp_of_get_sharing_cpus()
1326 if (cpu == cpu_dev->id) in dev_pm_opp_of_get_sharing_cpus()
1333 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1337 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
1341 pr_err("%pOF: Couldn't find opp node\n", cpu_np); in dev_pm_opp_of_get_sharing_cpus()
1342 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1346 /* CPUs are sharing opp node */ in dev_pm_opp_of_get_sharing_cpus()
1360 …* of_get_required_opp_performance_state() - Search for required OPP and return its performance sta…
1361 * @np: Node that contains the "required-opps" property.
1364 * Returns the performance state of the OPP pointed out by the "required-opps"
1372 struct dev_pm_opp *opp; in of_get_required_opp_performance_state() local
1375 int pstate = -EINVAL; in of_get_required_opp_performance_state()
1379 return -ENODEV; in of_get_required_opp_performance_state()
1383 pr_err("%s: Failed to find required OPP table %pOF: %ld\n", in of_get_required_opp_performance_state()
1388 /* The OPP tables must belong to a genpd */ in of_get_required_opp_performance_state()
1389 if (unlikely(!opp_table->is_genpd)) { in of_get_required_opp_performance_state()
1394 opp = _find_opp_of_np(opp_table, required_np); in of_get_required_opp_performance_state()
1395 if (opp) { in of_get_required_opp_performance_state()
1396 pstate = opp->level; in of_get_required_opp_performance_state()
1397 dev_pm_opp_put(opp); in of_get_required_opp_performance_state()
1410 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
1411 * @opp: opp for which DT node has to be returned for
1413 * Return: DT node corresponding to the opp, else 0 on success.
1417 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) in dev_pm_opp_get_of_node() argument
1419 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_of_node()
1424 return of_node_get(opp->np); in dev_pm_opp_get_of_node()
1431 * existing OPP, or at the frequency of the first OPP above @kHz otherwise
1435 * Returns 0 on success or a proper -EINVAL value in case of error.
1440 struct dev_pm_opp *opp; in _get_dt_power() local
1443 /* Find the right frequency and related OPP */ in _get_dt_power()
1445 opp = dev_pm_opp_find_freq_ceil(dev, &opp_freq); in _get_dt_power()
1446 if (IS_ERR(opp)) in _get_dt_power()
1447 return -EINVAL; in _get_dt_power()
1449 opp_power = dev_pm_opp_get_power(opp); in _get_dt_power()
1450 dev_pm_opp_put(opp); in _get_dt_power()
1452 return -EINVAL; in _get_dt_power()
1463 * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
1467 * respectively the voltage and frequency of the OPP.
1469 * Returns -EINVAL if the power calculation failed because of missing
1475 struct dev_pm_opp *opp; in _get_power() local
1482 np = of_node_get(dev->of_node); in _get_power()
1484 return -EINVAL; in _get_power()
1486 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in _get_power()
1489 return -EINVAL; in _get_power()
1492 opp = dev_pm_opp_find_freq_ceil(dev, &Hz); in _get_power()
1493 if (IS_ERR(opp)) in _get_power()
1494 return -EINVAL; in _get_power()
1496 mV = dev_pm_opp_get_voltage(opp) / 1000; in _get_power()
1497 dev_pm_opp_put(opp); in _get_power()
1499 return -EINVAL; in _get_power()
1502 /* Provide power in micro-Watts */ in _get_power()
1514 struct dev_pm_opp *opp; in _of_has_opp_microwatt_property() local
1516 /* Check if at least one OPP has needed property */ in _of_has_opp_microwatt_property()
1517 opp = dev_pm_opp_find_freq_ceil(dev, &freq); in _of_has_opp_microwatt_property()
1518 if (IS_ERR(opp)) in _of_has_opp_microwatt_property()
1521 power = dev_pm_opp_get_power(opp); in _of_has_opp_microwatt_property()
1522 dev_pm_opp_put(opp); in _of_has_opp_microwatt_property()
1530 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model
1535 * This checks whether the "dynamic-power-coefficient" devicetree property has
1548 ret = -EINVAL; in dev_pm_opp_of_register_em()
1554 ret = -EINVAL; in dev_pm_opp_of_register_em()
1564 np = of_node_get(dev->of_node); in dev_pm_opp_of_register_em()
1566 ret = -EINVAL; in dev_pm_opp_of_register_em()
1571 * Register an EM only if the 'dynamic-power-coefficient' property is in dev_pm_opp_of_register_em()
1577 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in dev_pm_opp_of_register_em()
1580 dev_dbg(dev, "Couldn't find proper 'dynamic-power-coefficient' in DT\n"); in dev_pm_opp_of_register_em()
1581 ret = -EINVAL; in dev_pm_opp_of_register_em()