Lines Matching +full:opp +full:- +full:table
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()
104 /* The caller must call dev_pm_opp_put_opp_table() after the table is used */
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()
182 size = sizeof(*required_opp_tables) + sizeof(*opp_table->required_devs); 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_devs = (void *)(required_opp_tables + count); in _opp_table_alloc_required_tables()
189 opp_table->required_opp_count = count; in _opp_table_alloc_required_tables()
206 * The OPP table is not held while allocating the table, take it in _opp_table_alloc_required_tables()
210 list_add(&opp_table->lazy, &lazy_opp_tables); in _opp_table_alloc_required_tables()
232 np = of_node_get(dev->of_node); in _of_init_opp_table()
236 if (!of_property_read_u32(np, "clock-latency", &val)) in _of_init_opp_table()
237 opp_table->clock_latency_ns_max = val; in _of_init_opp_table()
238 of_property_read_u32(np, "voltage-tolerance", in _of_init_opp_table()
239 &opp_table->voltage_tolerance_v1); in _of_init_opp_table()
241 if (of_property_present(np, "#power-domain-cells")) in _of_init_opp_table()
242 opp_table->is_genpd = true; in _of_init_opp_table()
244 /* Get OPP table node */ in _of_init_opp_table()
251 if (of_property_read_bool(opp_np, "opp-shared")) in _of_init_opp_table()
252 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; in _of_init_opp_table()
254 opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; in _of_init_opp_table()
256 opp_table->np = opp_np; in _of_init_opp_table()
264 of_node_put(opp_table->np); in _of_clear_opp_table()
272 struct dev_pm_opp *opp) in _of_opp_free_required_opps() argument
274 struct dev_pm_opp **required_opps = opp->required_opps; in _of_opp_free_required_opps()
280 for (i = 0; i < opp_table->required_opp_count; i++) { in _of_opp_free_required_opps()
288 opp->required_opps = NULL; in _of_opp_free_required_opps()
292 void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp) in _of_clear_opp() argument
294 _of_opp_free_required_opps(opp_table, opp); in _of_clear_opp()
295 of_node_put(opp->np); in _of_clear_opp()
298 static int _link_required_opps(struct dev_pm_opp *opp, struct opp_table *opp_table, in _link_required_opps() argument
303 np = of_parse_required_opp(opp->np, index); in _link_required_opps()
305 return -ENODEV; in _link_required_opps()
307 opp->required_opps[index] = _find_opp_of_np(required_table, np); in _link_required_opps()
310 if (!opp->required_opps[index]) { in _link_required_opps()
311 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n", in _link_required_opps()
312 __func__, opp->np, index); in _link_required_opps()
313 return -ENODEV; in _link_required_opps()
317 * There are two genpd (as required-opp) cases that we need to handle, in _link_required_opps()
325 * "opp-level" and single "required-opps" entry pointing to a genpd's in _link_required_opps()
326 * OPP, as that would make the OPP core call in _link_required_opps()
329 * case where the OPP's level is directly available without required-opp in _link_required_opps()
335 * There is another case though, where a genpd's OPP table has in _link_required_opps()
336 * required-opps set to a parent genpd. The OPP core expects the user to in _link_required_opps()
340 if (required_table->is_genpd && opp_table->required_opp_count == 1 && in _link_required_opps()
341 !opp_table->required_devs[0]) { in _link_required_opps()
343 if (!opp_table->is_genpd) { in _link_required_opps()
344 if (!WARN_ON(opp->level != OPP_LEVEL_UNSET)) in _link_required_opps()
345 opp->level = opp->required_opps[0]->level; in _link_required_opps()
352 /* Populate all required OPPs which are part of "required-opps" list */
354 struct dev_pm_opp *opp) in _of_opp_alloc_required_opps() argument
357 int i, ret, count = opp_table->required_opp_count; in _of_opp_alloc_required_opps()
362 opp->required_opps = kcalloc(count, sizeof(*opp->required_opps), GFP_KERNEL); in _of_opp_alloc_required_opps()
363 if (!opp->required_opps) in _of_opp_alloc_required_opps()
364 return -ENOMEM; in _of_opp_alloc_required_opps()
367 required_table = opp_table->required_opp_tables[i]; in _of_opp_alloc_required_opps()
369 /* Required table not added yet, we will link later */ in _of_opp_alloc_required_opps()
373 ret = _link_required_opps(opp, opp_table, required_table, i); in _of_opp_alloc_required_opps()
381 _of_opp_free_required_opps(opp_table, opp); in _of_opp_alloc_required_opps()
386 /* Link required OPPs for an individual OPP */
390 struct dev_pm_opp *opp; in lazy_link_required_opps() local
393 list_for_each_entry(opp, &opp_table->opp_list, node) { in lazy_link_required_opps()
394 ret = _link_required_opps(opp, opp_table, new_table, index); in lazy_link_required_opps()
402 /* Link required OPPs for all OPPs of the newly added OPP table */
407 struct dev_pm_opp *opp; in lazy_link_required_opp_table() local
416 opp_np = of_get_next_available_child(opp_table->np, NULL); in lazy_link_required_opp_table()
418 for (i = 0; i < opp_table->required_opp_count; i++) { in lazy_link_required_opp_table()
419 required_opp_tables = opp_table->required_opp_tables; in lazy_link_required_opp_table()
421 /* Required opp-table is already parsed */ in lazy_link_required_opp_table()
433 * Newly added table isn't the required opp-table for in lazy_link_required_opp_table()
436 if (required_table_np != new_table->np) { in lazy_link_required_opp_table()
455 /* All required opp-tables found, remove from lazy list */ in lazy_link_required_opp_table()
457 list_del_init(&opp_table->lazy); in lazy_link_required_opp_table()
459 list_for_each_entry(opp, &opp_table->opp_list, node) in lazy_link_required_opp_table()
460 _required_opps_available(opp, opp_table->required_opp_count); in lazy_link_required_opp_table()
473 np = of_node_get(dev->of_node); in _bandwidth_supported()
475 return -ENODEV; in _bandwidth_supported()
480 opp_np = of_node_get(opp_table->np); in _bandwidth_supported()
483 /* Lets not fail in case we are parsing opp-v1 bindings */ in _bandwidth_supported()
487 /* Checking only first OPP is sufficient */ in _bandwidth_supported()
491 dev_err(dev, "OPP table empty\n"); in _bandwidth_supported()
492 return -EINVAL; in _bandwidth_supported()
495 prop = of_find_property(np, "opp-peak-kBps", NULL); in _bandwidth_supported()
498 if (!prop || !prop->length) in _bandwidth_supported()
512 if (ret == -EINVAL) in dev_pm_opp_of_find_icc_paths()
513 return 0; /* Empty OPP table is a valid corner-case, let's not fail */ in dev_pm_opp_of_find_icc_paths()
519 np = of_node_get(dev->of_node); in dev_pm_opp_of_find_icc_paths()
524 "#interconnect-cells"); in dev_pm_opp_of_find_icc_paths()
529 /* two phandles when #interconnect-cells = <1> */ in dev_pm_opp_of_find_icc_paths()
532 return -EINVAL; in dev_pm_opp_of_find_icc_paths()
538 return -ENOMEM; in dev_pm_opp_of_find_icc_paths()
549 opp_table->paths = paths; in dev_pm_opp_of_find_icc_paths()
550 opp_table->path_count = num_paths; in dev_pm_opp_of_find_icc_paths()
555 while (i--) in dev_pm_opp_of_find_icc_paths()
567 unsigned int levels = opp_table->supported_hw_count; in _opp_is_supported()
571 if (!opp_table->supported_hw) { in _opp_is_supported()
574 * platform but there is an opp-supported-hw value set for in _opp_is_supported()
575 * an OPP then the OPP should not be enabled as there is in _opp_is_supported()
578 if (of_property_present(np, "opp-supported-hw")) in _opp_is_supported()
584 count = of_property_count_u32_elems(np, "opp-supported-hw"); in _opp_is_supported()
586 dev_err(dev, "%s: Invalid opp-supported-hw property (%d)\n", in _opp_is_supported()
598 ret = of_property_read_u32_index(np, "opp-supported-hw", in _opp_is_supported()
601 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n", in _opp_is_supported()
607 if (!(val & opp_table->supported_hw[j])) { in _opp_is_supported()
620 static u32 *_parse_named_prop(struct dev_pm_opp *opp, struct device *dev, in _parse_named_prop() argument
629 /* Search for "opp-<prop_type>-<name>" */ in _parse_named_prop()
630 if (opp_table->prop_name) { in _parse_named_prop()
631 snprintf(name, sizeof(name), "opp-%s-%s", prop_type, in _parse_named_prop()
632 opp_table->prop_name); in _parse_named_prop()
633 prop = of_find_property(opp->np, name, NULL); in _parse_named_prop()
637 /* Search for "opp-<prop_type>" */ in _parse_named_prop()
638 snprintf(name, sizeof(name), "opp-%s", prop_type); in _parse_named_prop()
639 prop = of_find_property(opp->np, name, NULL); in _parse_named_prop()
644 count = of_property_count_u32_elems(opp->np, name); in _parse_named_prop()
656 if (unlikely(opp_table->regulator_count == -1)) in _parse_named_prop()
657 opp_table->regulator_count = 1; in _parse_named_prop()
659 if (count != opp_table->regulator_count && in _parse_named_prop()
660 (!triplet || count != opp_table->regulator_count * 3)) { in _parse_named_prop()
662 __func__, prop_type, count, opp_table->regulator_count); in _parse_named_prop()
663 return ERR_PTR(-EINVAL); in _parse_named_prop()
668 return ERR_PTR(-EINVAL); in _parse_named_prop()
670 ret = of_property_read_u32_array(opp->np, name, out, count); in _parse_named_prop()
674 return ERR_PTR(-EINVAL); in _parse_named_prop()
678 *triplet = count != opp_table->regulator_count; in _parse_named_prop()
683 static u32 *opp_parse_microvolt(struct dev_pm_opp *opp, struct device *dev, in opp_parse_microvolt() argument
688 microvolt = _parse_named_prop(opp, dev, opp_table, "microvolt", triplet); in opp_parse_microvolt()
696 * information is provided. Check only for the first OPP, as in opp_parse_microvolt()
700 if (list_empty(&opp_table->opp_list) && in opp_parse_microvolt()
701 opp_table->regulator_count > 0) { in opp_parse_microvolt()
702 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n", in opp_parse_microvolt()
704 return ERR_PTR(-EINVAL); in opp_parse_microvolt()
711 static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, in opp_parse_supplies() argument
718 microvolt = opp_parse_microvolt(opp, dev, opp_table, &triplet); in opp_parse_supplies()
722 microamp = _parse_named_prop(opp, dev, opp_table, "microamp", NULL); in opp_parse_supplies()
728 microwatt = _parse_named_prop(opp, dev, opp_table, "microwatt", NULL); in opp_parse_supplies()
738 if (unlikely(opp_table->regulator_count == -1)) { in opp_parse_supplies()
739 opp_table->regulator_count = 0; in opp_parse_supplies()
743 for (i = 0, j = 0; i < opp_table->regulator_count; i++) { in opp_parse_supplies()
745 opp->supplies[i].u_volt = microvolt[j++]; in opp_parse_supplies()
748 opp->supplies[i].u_volt_min = microvolt[j++]; in opp_parse_supplies()
749 opp->supplies[i].u_volt_max = microvolt[j++]; in opp_parse_supplies()
751 opp->supplies[i].u_volt_min = opp->supplies[i].u_volt; in opp_parse_supplies()
752 opp->supplies[i].u_volt_max = opp->supplies[i].u_volt; in opp_parse_supplies()
757 opp->supplies[i].u_amp = microamp[i]; in opp_parse_supplies()
760 opp->supplies[i].u_watt = microwatt[i]; in opp_parse_supplies()
773 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
775 * @dev: device pointer used to lookup OPP table.
792 prop = of_find_property(np, "opp-hz", NULL); in _read_rate()
794 return -ENODEV; in _read_rate()
796 count = prop->length / sizeof(u64); in _read_rate()
797 if (opp_table->clk_count != count) { in _read_rate()
798 pr_err("%s: Count mismatch between opp-hz and clk_count (%d %d)\n", in _read_rate()
799 __func__, count, opp_table->clk_count); in _read_rate()
800 return -EINVAL; in _read_rate()
805 return -ENOMEM; in _read_rate()
807 ret = of_property_read_u64_array(np, "opp-hz", rates, count); in _read_rate()
809 pr_err("%s: Error parsing opp-hz: %d\n", __func__, ret); in _read_rate()
817 new_opp->rates[i] = (unsigned long)rates[i]; in _read_rate()
820 WARN_ON(new_opp->rates[i] != rates[i]); in _read_rate()
832 const char *name = peak ? "opp-peak-kBps" : "opp-avg-kBps"; in _read_bw()
839 return -ENODEV; in _read_bw()
841 count = prop->length / sizeof(u32); in _read_bw()
842 if (opp_table->path_count != count) { in _read_bw()
844 __func__, name, count, opp_table->path_count); in _read_bw()
845 return -EINVAL; in _read_bw()
850 return -ENOMEM; in _read_bw()
860 new_opp->bandwidth[i].peak = kBps_to_icc(bw[i]); in _read_bw()
862 new_opp->bandwidth[i].avg = kBps_to_icc(bw[i]); in _read_bw()
879 else if (ret != -ENODEV) in _read_opp_key()
884 * opp-peak-kBps = <path1_value path2_value>; in _read_opp_key()
885 * opp-avg-kBps = <path1_value path2_value>; in _read_opp_key()
894 if (ret && ret != -ENODEV) in _read_opp_key()
897 if (!of_property_read_u32(np, "opp-level", &new_opp->level)) in _read_opp_key()
907 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
908 * @opp_table: OPP table
912 * This function adds an opp definition to the opp table and returns status. The
913 * opp can be controlled using dev_pm_opp_enable/disable functions and may be
917 * Valid OPP pointer:
920 * Duplicate OPPs (both freq and volt are same) and opp->available
921 * OR if the OPP is not supported by hardware.
922 * ERR_PTR(-EEXIST):
924 * Duplicate OPPs (both freq and volt are same) and !opp->available
925 * ERR_PTR(-ENOMEM):
927 * ERR_PTR(-EINVAL):
928 * Failed parsing the OPP node
939 return ERR_PTR(-ENOMEM); in _opp_add_static_v2()
943 dev_err(dev, "%s: opp key field not found\n", __func__); in _opp_add_static_v2()
947 /* Check if the OPP supports hardware's hierarchy of versions or not */ in _opp_add_static_v2()
949 dev_dbg(dev, "OPP not supported by hardware: %s\n", in _opp_add_static_v2()
954 new_opp->turbo = of_property_read_bool(np, "turbo-mode"); in _opp_add_static_v2()
956 new_opp->np = of_node_get(np); in _opp_add_static_v2()
957 new_opp->dynamic = false; in _opp_add_static_v2()
958 new_opp->available = true; in _opp_add_static_v2()
964 if (!of_property_read_u32(np, "clock-latency-ns", &val)) in _opp_add_static_v2()
965 new_opp->clock_latency_ns = val; in _opp_add_static_v2()
974 if (ret == -EBUSY) in _opp_add_static_v2()
979 /* OPP to select on device suspend */ in _opp_add_static_v2()
980 if (of_property_read_bool(np, "opp-suspend")) { in _opp_add_static_v2()
981 if (opp_table->suspend_opp) { in _opp_add_static_v2()
982 /* Pick the OPP with higher rate/bw/level as suspend OPP */ in _opp_add_static_v2()
983 if (_opp_compare_key(opp_table, new_opp, opp_table->suspend_opp) == 1) { in _opp_add_static_v2()
984 opp_table->suspend_opp->suspend = false; in _opp_add_static_v2()
985 new_opp->suspend = true; in _opp_add_static_v2()
986 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
989 new_opp->suspend = true; in _opp_add_static_v2()
990 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
994 if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max) in _opp_add_static_v2()
995 opp_table->clock_latency_ns_max = new_opp->clock_latency_ns; in _opp_add_static_v2()
998 __func__, new_opp->turbo, new_opp->rates[0], in _opp_add_static_v2()
999 new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min, in _opp_add_static_v2()
1000 new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns, in _opp_add_static_v2()
1001 new_opp->level); in _opp_add_static_v2()
1007 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); in _opp_add_static_v2()
1018 /* Initializes OPP tables based on new bindings */
1023 struct dev_pm_opp *opp; in _of_add_opp_table_v2() local
1025 /* OPP table is already initialized for the device */ in _of_add_opp_table_v2()
1026 mutex_lock(&opp_table->lock); in _of_add_opp_table_v2()
1027 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v2()
1028 opp_table->parsed_static_opps++; in _of_add_opp_table_v2()
1029 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1033 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v2()
1034 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1036 /* We have opp-table node now, iterate over it and add OPPs */ in _of_add_opp_table_v2()
1037 for_each_available_child_of_node(opp_table->np, np) { in _of_add_opp_table_v2()
1038 opp = _opp_add_static_v2(opp_table, dev, np); in _of_add_opp_table_v2()
1039 if (IS_ERR(opp)) { in _of_add_opp_table_v2()
1040 ret = PTR_ERR(opp); in _of_add_opp_table_v2()
1041 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, in _of_add_opp_table_v2()
1045 } else if (opp) { in _of_add_opp_table_v2()
1053 ret = -ENOENT; in _of_add_opp_table_v2()
1067 /* Initializes OPP tables based on old-deprecated bindings */
1074 mutex_lock(&opp_table->lock); in _of_add_opp_table_v1()
1075 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v1()
1076 opp_table->parsed_static_opps++; in _of_add_opp_table_v1()
1077 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1081 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v1()
1082 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1084 prop = of_find_property(dev->of_node, "operating-points", NULL); in _of_add_opp_table_v1()
1086 ret = -ENODEV; in _of_add_opp_table_v1()
1089 if (!prop->value) { in _of_add_opp_table_v1()
1090 ret = -ENODATA; in _of_add_opp_table_v1()
1095 * Each OPP is a set of tuples consisting of frequency and in _of_add_opp_table_v1()
1096 * voltage like <freq-kHz vol-uV>. in _of_add_opp_table_v1()
1098 nr = prop->length / sizeof(u32); in _of_add_opp_table_v1()
1100 dev_err(dev, "%s: Invalid OPP table\n", __func__); in _of_add_opp_table_v1()
1101 ret = -EINVAL; in _of_add_opp_table_v1()
1105 val = prop->value; in _of_add_opp_table_v1()
1116 dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", in _of_add_opp_table_v1()
1120 nr -= 2; in _of_add_opp_table_v1()
1138 * If only one phandle is present, then the same OPP table in _of_add_table_indexed()
1141 count = of_count_phandle_with_args(dev->of_node, in _of_add_table_indexed()
1142 "operating-points-v2", NULL); in _of_add_table_indexed()
1155 if (opp_table->np) in _of_add_table_indexed()
1183 * devm_pm_opp_of_add_table() - Initialize opp table from device tree
1184 * @dev: device pointer used to lookup OPP table.
1186 * Register the initial OPP table with the OPP library for given device.
1192 * Duplicate OPPs (both freq and volt are same) and opp->available
1193 * -EEXIST Freq are same and volt are different OR
1194 * Duplicate OPPs (both freq and volt are same) and !opp->available
1195 * -ENOMEM Memory allocation failure
1196 * -ENODEV when 'operating-points' property is not found or is invalid data
1198 * -ENODATA when empty 'operating-points' property is found
1199 * -EINVAL when invalid entries are found in opp-v2 table
1208 * dev_pm_opp_of_add_table() - Initialize opp table from device tree
1209 * @dev: device pointer used to lookup OPP table.
1211 * Register the initial OPP table with the OPP library for given device.
1215 * Duplicate OPPs (both freq and volt are same) and opp->available
1216 * -EEXIST Freq are same and volt are different OR
1217 * Duplicate OPPs (both freq and volt are same) and !opp->available
1218 * -ENOMEM Memory allocation failure
1219 * -ENODEV when 'operating-points' property is not found or is invalid data
1221 * -ENODATA when empty 'operating-points' property is found
1222 * -EINVAL when invalid entries are found in opp-v2 table
1231 * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
1232 * @dev: device pointer used to lookup OPP table.
1235 * Register the initial OPP table with the OPP library for given device only
1236 * using the "operating-points-v2" property.
1247 * devm_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
1248 * @dev: device pointer used to lookup OPP table.
1251 * This is a resource-managed variant of dev_pm_opp_of_add_table_indexed().
1262 * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
1263 * @cpumask: cpumask for which OPP table needs to be removed
1265 * This removes the OPP tables for CPUs present in the @cpumask.
1270 _dev_pm_opp_cpumask_remove_table(cpumask, -1); in dev_pm_opp_of_cpumask_remove_table()
1275 * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
1276 * @cpumask: cpumask for which OPP table needs to be added.
1278 * This adds the OPP tables for CPUs present in the @cpumask.
1286 return -ENODEV; in dev_pm_opp_of_cpumask_add_table()
1293 ret = -ENODEV; in dev_pm_opp_of_cpumask_add_table()
1300 * OPP may get registered dynamically, don't print error in dev_pm_opp_of_cpumask_add_table()
1303 pr_debug("%s: couldn't find opp table for cpu:%d, %d\n", in dev_pm_opp_of_cpumask_add_table()
1321 * Works only for OPP v2 bindings.
1323 * Returns -ENOENT if operating-points-v2 bindings aren't supported.
1326 * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
1327 * @cpu_dev using operating-points-v2
1335 * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
1343 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
1346 dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__); in dev_pm_opp_of_get_sharing_cpus()
1347 return -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1350 cpumask_set_cpu(cpu_dev->id, cpumask); in dev_pm_opp_of_get_sharing_cpus()
1353 if (!of_property_read_bool(np, "opp-shared")) in dev_pm_opp_of_get_sharing_cpus()
1357 if (cpu == cpu_dev->id) in dev_pm_opp_of_get_sharing_cpus()
1364 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1368 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
1372 pr_err("%pOF: Couldn't find opp node\n", cpu_np); in dev_pm_opp_of_get_sharing_cpus()
1373 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1377 /* CPUs are sharing opp node */ in dev_pm_opp_of_get_sharing_cpus()
1391 …* of_get_required_opp_performance_state() - Search for required OPP and return its performance sta…
1392 * @np: Node that contains the "required-opps" property.
1395 * Returns the performance state of the OPP pointed out by the "required-opps"
1403 struct dev_pm_opp *opp; in of_get_required_opp_performance_state() local
1406 int pstate = -EINVAL; in of_get_required_opp_performance_state()
1410 return -ENODEV; in of_get_required_opp_performance_state()
1414 pr_err("%s: Failed to find required OPP table %pOF: %ld\n", in of_get_required_opp_performance_state()
1419 /* The OPP tables must belong to a genpd */ in of_get_required_opp_performance_state()
1420 if (unlikely(!opp_table->is_genpd)) { in of_get_required_opp_performance_state()
1425 opp = _find_opp_of_np(opp_table, required_np); in of_get_required_opp_performance_state()
1426 if (opp) { in of_get_required_opp_performance_state()
1427 if (opp->level == OPP_LEVEL_UNSET) { in of_get_required_opp_performance_state()
1428 pr_err("%s: OPP levels aren't available for %pOF\n", in of_get_required_opp_performance_state()
1431 pstate = opp->level; in of_get_required_opp_performance_state()
1433 dev_pm_opp_put(opp); in of_get_required_opp_performance_state()
1447 * dev_pm_opp_of_has_required_opp - Find out if a required-opps exists.
1450 * Returns true if the device's node has a "operating-points-v2" property and if
1451 * the corresponding node for the opp-table describes opp nodes that uses the
1452 * "required-opps" property.
1454 * Return: True if a required-opps is present, else false.
1461 opp_np = _opp_of_get_opp_desc_node(dev->of_node, 0); in dev_pm_opp_of_has_required_opp()
1468 dev_warn(dev, "Empty OPP table\n"); in dev_pm_opp_of_has_required_opp()
1472 count = of_count_phandle_with_args(np, "required-opps", NULL); in dev_pm_opp_of_has_required_opp()
1479 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
1480 * @opp: opp for which DT node has to be returned for
1482 * Return: DT node corresponding to the opp, else 0 on success.
1486 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) in dev_pm_opp_get_of_node() argument
1488 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_of_node()
1493 return of_node_get(opp->np); in dev_pm_opp_get_of_node()
1500 * existing OPP, or at the frequency of the first OPP above @kHz otherwise
1504 * Returns 0 on success or a proper -EINVAL value in case of error.
1509 struct dev_pm_opp *opp; in _get_dt_power() local
1512 /* Find the right frequency and related OPP */ in _get_dt_power()
1514 opp = dev_pm_opp_find_freq_ceil(dev, &opp_freq); in _get_dt_power()
1515 if (IS_ERR(opp)) in _get_dt_power()
1516 return -EINVAL; in _get_dt_power()
1518 opp_power = dev_pm_opp_get_power(opp); in _get_dt_power()
1519 dev_pm_opp_put(opp); in _get_dt_power()
1521 return -EINVAL; in _get_dt_power()
1530 * dev_pm_opp_calc_power() - Calculate power value for device with EM
1536 * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
1540 * respectively the voltage and frequency of the OPP.
1544 * Returns -EINVAL if the power calculation failed because of missing
1550 struct dev_pm_opp *opp; in dev_pm_opp_calc_power() local
1557 np = of_node_get(dev->of_node); in dev_pm_opp_calc_power()
1559 return -EINVAL; in dev_pm_opp_calc_power()
1561 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in dev_pm_opp_calc_power()
1564 return -EINVAL; in dev_pm_opp_calc_power()
1567 opp = dev_pm_opp_find_freq_ceil(dev, &Hz); in dev_pm_opp_calc_power()
1568 if (IS_ERR(opp)) in dev_pm_opp_calc_power()
1569 return -EINVAL; in dev_pm_opp_calc_power()
1571 mV = dev_pm_opp_get_voltage(opp) / 1000; in dev_pm_opp_calc_power()
1572 dev_pm_opp_put(opp); in dev_pm_opp_calc_power()
1574 return -EINVAL; in dev_pm_opp_calc_power()
1577 /* Provide power in micro-Watts */ in dev_pm_opp_calc_power()
1590 struct dev_pm_opp *opp; in _of_has_opp_microwatt_property() local
1592 /* Check if at least one OPP has needed property */ in _of_has_opp_microwatt_property()
1593 opp = dev_pm_opp_find_freq_ceil(dev, &freq); in _of_has_opp_microwatt_property()
1594 if (IS_ERR(opp)) in _of_has_opp_microwatt_property()
1597 power = dev_pm_opp_get_power(opp); in _of_has_opp_microwatt_property()
1598 dev_pm_opp_put(opp); in _of_has_opp_microwatt_property()
1606 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model
1611 * This checks whether the "dynamic-power-coefficient" devicetree property has
1624 ret = -EINVAL; in dev_pm_opp_of_register_em()
1630 ret = -EINVAL; in dev_pm_opp_of_register_em()
1640 np = of_node_get(dev->of_node); in dev_pm_opp_of_register_em()
1642 ret = -EINVAL; in dev_pm_opp_of_register_em()
1647 * Register an EM only if the 'dynamic-power-coefficient' property is in dev_pm_opp_of_register_em()
1653 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in dev_pm_opp_of_register_em()
1656 dev_dbg(dev, "Couldn't find proper 'dynamic-power-coefficient' in DT\n"); in dev_pm_opp_of_register_em()
1657 ret = -EINVAL; in dev_pm_opp_of_register_em()