Lines Matching +full:opp +full:- +full:table +full:- +full:2
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, 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()
319 /* Populate all required OPPs which are part of "required-opps" list */
321 struct dev_pm_opp *opp) in _of_opp_alloc_required_opps() argument
324 int i, ret, count = opp_table->required_opp_count; in _of_opp_alloc_required_opps()
329 opp->required_opps = kcalloc(count, sizeof(*opp->required_opps), GFP_KERNEL); in _of_opp_alloc_required_opps()
330 if (!opp->required_opps) in _of_opp_alloc_required_opps()
331 return -ENOMEM; in _of_opp_alloc_required_opps()
334 required_table = opp_table->required_opp_tables[i]; in _of_opp_alloc_required_opps()
336 /* Required table not added yet, we will link later */ in _of_opp_alloc_required_opps()
340 ret = _link_required_opps(opp, required_table, i); in _of_opp_alloc_required_opps()
348 _of_opp_free_required_opps(opp_table, opp); in _of_opp_alloc_required_opps()
353 /* Link required OPPs for an individual OPP */
357 struct dev_pm_opp *opp; in lazy_link_required_opps() local
360 list_for_each_entry(opp, &opp_table->opp_list, node) { in lazy_link_required_opps()
361 ret = _link_required_opps(opp, new_table, index); in lazy_link_required_opps()
369 /* Link required OPPs for all OPPs of the newly added OPP table */
374 struct dev_pm_opp *opp; in lazy_link_required_opp_table() local
383 opp_np = of_get_next_available_child(opp_table->np, NULL); in lazy_link_required_opp_table()
385 for (i = 0; i < opp_table->required_opp_count; i++) { in lazy_link_required_opp_table()
386 required_opp_tables = opp_table->required_opp_tables; in lazy_link_required_opp_table()
388 /* Required opp-table is already parsed */ in lazy_link_required_opp_table()
400 * Newly added table isn't the required opp-table for in lazy_link_required_opp_table()
403 if (required_table_np != new_table->np) { in lazy_link_required_opp_table()
422 /* All required opp-tables found, remove from lazy list */ in lazy_link_required_opp_table()
424 list_del_init(&opp_table->lazy); in lazy_link_required_opp_table()
426 list_for_each_entry(opp, &opp_table->opp_list, node) in lazy_link_required_opp_table()
427 _required_opps_available(opp, opp_table->required_opp_count); in lazy_link_required_opp_table()
440 np = of_node_get(dev->of_node); in _bandwidth_supported()
442 return -ENODEV; in _bandwidth_supported()
447 opp_np = of_node_get(opp_table->np); in _bandwidth_supported()
450 /* Lets not fail in case we are parsing opp-v1 bindings */ in _bandwidth_supported()
454 /* Checking only first OPP is sufficient */ in _bandwidth_supported()
458 dev_err(dev, "OPP table empty\n"); in _bandwidth_supported()
459 return -EINVAL; in _bandwidth_supported()
462 prop = of_find_property(np, "opp-peak-kBps", NULL); in _bandwidth_supported()
465 if (!prop || !prop->length) in _bandwidth_supported()
479 if (ret == -EINVAL) in dev_pm_opp_of_find_icc_paths()
480 return 0; /* Empty OPP table is a valid corner-case, let's not fail */ in dev_pm_opp_of_find_icc_paths()
486 np = of_node_get(dev->of_node); in dev_pm_opp_of_find_icc_paths()
491 "#interconnect-cells"); in dev_pm_opp_of_find_icc_paths()
496 /* two phandles when #interconnect-cells = <1> */ in dev_pm_opp_of_find_icc_paths()
497 if (count % 2) { in dev_pm_opp_of_find_icc_paths()
499 return -EINVAL; in dev_pm_opp_of_find_icc_paths()
502 num_paths = count / 2; in dev_pm_opp_of_find_icc_paths()
505 return -ENOMEM; in dev_pm_opp_of_find_icc_paths()
516 opp_table->paths = paths; in dev_pm_opp_of_find_icc_paths()
517 opp_table->path_count = num_paths; in dev_pm_opp_of_find_icc_paths()
522 while (i--) in dev_pm_opp_of_find_icc_paths()
534 unsigned int levels = opp_table->supported_hw_count; in _opp_is_supported()
538 if (!opp_table->supported_hw) { in _opp_is_supported()
541 * platform but there is an opp-supported-hw value set for in _opp_is_supported()
542 * an OPP then the OPP should not be enabled as there is in _opp_is_supported()
545 if (of_property_present(np, "opp-supported-hw")) in _opp_is_supported()
551 count = of_property_count_u32_elems(np, "opp-supported-hw"); in _opp_is_supported()
553 dev_err(dev, "%s: Invalid opp-supported-hw property (%d)\n", in _opp_is_supported()
565 ret = of_property_read_u32_index(np, "opp-supported-hw", in _opp_is_supported()
568 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n", in _opp_is_supported()
574 if (!(val & opp_table->supported_hw[j])) { in _opp_is_supported()
587 static u32 *_parse_named_prop(struct dev_pm_opp *opp, struct device *dev, in _parse_named_prop() argument
596 /* Search for "opp-<prop_type>-<name>" */ in _parse_named_prop()
597 if (opp_table->prop_name) { in _parse_named_prop()
598 snprintf(name, sizeof(name), "opp-%s-%s", prop_type, in _parse_named_prop()
599 opp_table->prop_name); in _parse_named_prop()
600 prop = of_find_property(opp->np, name, NULL); in _parse_named_prop()
604 /* Search for "opp-<prop_type>" */ in _parse_named_prop()
605 snprintf(name, sizeof(name), "opp-%s", prop_type); in _parse_named_prop()
606 prop = of_find_property(opp->np, name, NULL); in _parse_named_prop()
611 count = of_property_count_u32_elems(opp->np, name); in _parse_named_prop()
623 if (unlikely(opp_table->regulator_count == -1)) in _parse_named_prop()
624 opp_table->regulator_count = 1; in _parse_named_prop()
626 if (count != opp_table->regulator_count && in _parse_named_prop()
627 (!triplet || count != opp_table->regulator_count * 3)) { in _parse_named_prop()
629 __func__, prop_type, count, opp_table->regulator_count); in _parse_named_prop()
630 return ERR_PTR(-EINVAL); in _parse_named_prop()
635 return ERR_PTR(-EINVAL); in _parse_named_prop()
637 ret = of_property_read_u32_array(opp->np, name, out, count); in _parse_named_prop()
641 return ERR_PTR(-EINVAL); in _parse_named_prop()
645 *triplet = count != opp_table->regulator_count; in _parse_named_prop()
650 static u32 *opp_parse_microvolt(struct dev_pm_opp *opp, struct device *dev, in opp_parse_microvolt() argument
655 microvolt = _parse_named_prop(opp, dev, opp_table, "microvolt", triplet); in opp_parse_microvolt()
663 * information is provided. Check only for the first OPP, as in opp_parse_microvolt()
667 if (list_empty(&opp_table->opp_list) && in opp_parse_microvolt()
668 opp_table->regulator_count > 0) { in opp_parse_microvolt()
669 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n", in opp_parse_microvolt()
671 return ERR_PTR(-EINVAL); in opp_parse_microvolt()
678 static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, in opp_parse_supplies() argument
685 microvolt = opp_parse_microvolt(opp, dev, opp_table, &triplet); in opp_parse_supplies()
689 microamp = _parse_named_prop(opp, dev, opp_table, "microamp", NULL); in opp_parse_supplies()
695 microwatt = _parse_named_prop(opp, dev, opp_table, "microwatt", NULL); in opp_parse_supplies()
705 if (unlikely(opp_table->regulator_count == -1)) { in opp_parse_supplies()
706 opp_table->regulator_count = 0; in opp_parse_supplies()
710 for (i = 0, j = 0; i < opp_table->regulator_count; i++) { in opp_parse_supplies()
712 opp->supplies[i].u_volt = microvolt[j++]; in opp_parse_supplies()
715 opp->supplies[i].u_volt_min = microvolt[j++]; in opp_parse_supplies()
716 opp->supplies[i].u_volt_max = microvolt[j++]; in opp_parse_supplies()
718 opp->supplies[i].u_volt_min = opp->supplies[i].u_volt; in opp_parse_supplies()
719 opp->supplies[i].u_volt_max = opp->supplies[i].u_volt; in opp_parse_supplies()
724 opp->supplies[i].u_amp = microamp[i]; in opp_parse_supplies()
727 opp->supplies[i].u_watt = microwatt[i]; in opp_parse_supplies()
740 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
742 * @dev: device pointer used to lookup OPP table.
759 prop = of_find_property(np, "opp-hz", NULL); in _read_rate()
761 return -ENODEV; in _read_rate()
763 count = prop->length / sizeof(u64); in _read_rate()
764 if (opp_table->clk_count != count) { in _read_rate()
765 pr_err("%s: Count mismatch between opp-hz and clk_count (%d %d)\n", in _read_rate()
766 __func__, count, opp_table->clk_count); in _read_rate()
767 return -EINVAL; in _read_rate()
772 return -ENOMEM; in _read_rate()
774 ret = of_property_read_u64_array(np, "opp-hz", rates, count); in _read_rate()
776 pr_err("%s: Error parsing opp-hz: %d\n", __func__, ret); in _read_rate()
784 new_opp->rates[i] = (unsigned long)rates[i]; in _read_rate()
787 WARN_ON(new_opp->rates[i] != rates[i]); in _read_rate()
799 const char *name = peak ? "opp-peak-kBps" : "opp-avg-kBps"; in _read_bw()
806 return -ENODEV; in _read_bw()
808 count = prop->length / sizeof(u32); in _read_bw()
809 if (opp_table->path_count != count) { in _read_bw()
811 __func__, name, count, opp_table->path_count); in _read_bw()
812 return -EINVAL; in _read_bw()
817 return -ENOMEM; in _read_bw()
827 new_opp->bandwidth[i].peak = kBps_to_icc(bw[i]); in _read_bw()
829 new_opp->bandwidth[i].avg = kBps_to_icc(bw[i]); in _read_bw()
846 else if (ret != -ENODEV) in _read_opp_key()
851 * opp-peak-kBps = <path1_value path2_value>; in _read_opp_key()
852 * opp-avg-kBps = <path1_value path2_value>; in _read_opp_key()
861 if (ret && ret != -ENODEV) in _read_opp_key()
864 if (!of_property_read_u32(np, "opp-level", &new_opp->level)) in _read_opp_key()
874 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
875 * @opp_table: OPP table
879 * This function adds an opp definition to the opp table and returns status. The
880 * opp can be controlled using dev_pm_opp_enable/disable functions and may be
884 * Valid OPP pointer:
887 * Duplicate OPPs (both freq and volt are same) and opp->available
888 * OR if the OPP is not supported by hardware.
889 * ERR_PTR(-EEXIST):
891 * Duplicate OPPs (both freq and volt are same) and !opp->available
892 * ERR_PTR(-ENOMEM):
894 * ERR_PTR(-EINVAL):
895 * Failed parsing the OPP node
906 return ERR_PTR(-ENOMEM); in _opp_add_static_v2()
910 dev_err(dev, "%s: opp key field not found\n", __func__); in _opp_add_static_v2()
914 /* Check if the OPP supports hardware's hierarchy of versions or not */ in _opp_add_static_v2()
916 dev_dbg(dev, "OPP not supported by hardware: %s\n", in _opp_add_static_v2()
921 new_opp->turbo = of_property_read_bool(np, "turbo-mode"); in _opp_add_static_v2()
923 new_opp->np = of_node_get(np); in _opp_add_static_v2()
924 new_opp->dynamic = false; in _opp_add_static_v2()
925 new_opp->available = true; in _opp_add_static_v2()
931 if (!of_property_read_u32(np, "clock-latency-ns", &val)) in _opp_add_static_v2()
932 new_opp->clock_latency_ns = val; in _opp_add_static_v2()
941 if (ret == -EBUSY) in _opp_add_static_v2()
946 /* OPP to select on device suspend */ in _opp_add_static_v2()
947 if (of_property_read_bool(np, "opp-suspend")) { in _opp_add_static_v2()
948 if (opp_table->suspend_opp) { in _opp_add_static_v2()
949 /* Pick the OPP with higher rate/bw/level as suspend OPP */ in _opp_add_static_v2()
950 if (_opp_compare_key(opp_table, new_opp, opp_table->suspend_opp) == 1) { in _opp_add_static_v2()
951 opp_table->suspend_opp->suspend = false; in _opp_add_static_v2()
952 new_opp->suspend = true; in _opp_add_static_v2()
953 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
956 new_opp->suspend = true; in _opp_add_static_v2()
957 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
961 if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max) in _opp_add_static_v2()
962 opp_table->clock_latency_ns_max = new_opp->clock_latency_ns; in _opp_add_static_v2()
965 __func__, new_opp->turbo, new_opp->rates[0], in _opp_add_static_v2()
966 new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min, in _opp_add_static_v2()
967 new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns, in _opp_add_static_v2()
968 new_opp->level); in _opp_add_static_v2()
974 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); in _opp_add_static_v2()
987 /* Initializes OPP tables based on new bindings */
992 struct dev_pm_opp *opp; in _of_add_opp_table_v2() local
994 /* OPP table is already initialized for the device */ in _of_add_opp_table_v2()
995 mutex_lock(&opp_table->lock); in _of_add_opp_table_v2()
996 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v2()
997 opp_table->parsed_static_opps++; in _of_add_opp_table_v2()
998 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1002 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v2()
1003 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1005 /* We have opp-table node now, iterate over it and add OPPs */ in _of_add_opp_table_v2()
1006 for_each_available_child_of_node(opp_table->np, np) { in _of_add_opp_table_v2()
1007 opp = _opp_add_static_v2(opp_table, dev, np); in _of_add_opp_table_v2()
1008 if (IS_ERR(opp)) { in _of_add_opp_table_v2()
1009 ret = PTR_ERR(opp); in _of_add_opp_table_v2()
1010 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, in _of_add_opp_table_v2()
1014 } else if (opp) { in _of_add_opp_table_v2()
1022 ret = -ENOENT; in _of_add_opp_table_v2()
1036 /* Initializes OPP tables based on old-deprecated bindings */
1043 mutex_lock(&opp_table->lock); in _of_add_opp_table_v1()
1044 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v1()
1045 opp_table->parsed_static_opps++; in _of_add_opp_table_v1()
1046 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1050 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v1()
1051 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1053 prop = of_find_property(dev->of_node, "operating-points", NULL); in _of_add_opp_table_v1()
1055 ret = -ENODEV; in _of_add_opp_table_v1()
1058 if (!prop->value) { in _of_add_opp_table_v1()
1059 ret = -ENODATA; in _of_add_opp_table_v1()
1064 * Each OPP is a set of tuples consisting of frequency and in _of_add_opp_table_v1()
1065 * voltage like <freq-kHz vol-uV>. in _of_add_opp_table_v1()
1067 nr = prop->length / sizeof(u32); in _of_add_opp_table_v1()
1068 if (nr % 2) { in _of_add_opp_table_v1()
1069 dev_err(dev, "%s: Invalid OPP table\n", __func__); in _of_add_opp_table_v1()
1070 ret = -EINVAL; in _of_add_opp_table_v1()
1074 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()
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 if (opp->level == OPP_LEVEL_UNSET) { in of_get_required_opp_performance_state()
1397 pr_err("%s: OPP levels aren't available for %pOF\n", in of_get_required_opp_performance_state()
1400 pstate = opp->level; in of_get_required_opp_performance_state()
1402 dev_pm_opp_put(opp); in of_get_required_opp_performance_state()
1416 * dev_pm_opp_of_has_required_opp - Find out if a required-opps exists.
1419 * Returns true if the device's node has a "operating-points-v2" property and if
1420 * the corresponding node for the opp-table describes opp nodes that uses the
1421 * "required-opps" property.
1423 * Return: True if a required-opps is present, else false.
1430 opp_np = _opp_of_get_opp_desc_node(dev->of_node, 0); in dev_pm_opp_of_has_required_opp()
1437 dev_warn(dev, "Empty OPP table\n"); in dev_pm_opp_of_has_required_opp()
1441 count = of_count_phandle_with_args(np, "required-opps", NULL); in dev_pm_opp_of_has_required_opp()
1448 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
1449 * @opp: opp for which DT node has to be returned for
1451 * Return: DT node corresponding to the opp, else 0 on success.
1455 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) in dev_pm_opp_get_of_node() argument
1457 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_of_node()
1462 return of_node_get(opp->np); in dev_pm_opp_get_of_node()
1469 * existing OPP, or at the frequency of the first OPP above @kHz otherwise
1473 * Returns 0 on success or a proper -EINVAL value in case of error.
1478 struct dev_pm_opp *opp; in _get_dt_power() local
1481 /* Find the right frequency and related OPP */ in _get_dt_power()
1483 opp = dev_pm_opp_find_freq_ceil(dev, &opp_freq); in _get_dt_power()
1484 if (IS_ERR(opp)) in _get_dt_power()
1485 return -EINVAL; in _get_dt_power()
1487 opp_power = dev_pm_opp_get_power(opp); in _get_dt_power()
1488 dev_pm_opp_put(opp); in _get_dt_power()
1490 return -EINVAL; in _get_dt_power()
1499 * dev_pm_opp_calc_power() - Calculate power value for device with EM
1505 * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
1508 * P = C * V^2 * f with C being the device's capacitance and V and f
1509 * respectively the voltage and frequency of the OPP.
1513 * Returns -EINVAL if the power calculation failed because of missing
1519 struct dev_pm_opp *opp; in dev_pm_opp_calc_power() local
1526 np = of_node_get(dev->of_node); in dev_pm_opp_calc_power()
1528 return -EINVAL; in dev_pm_opp_calc_power()
1530 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in dev_pm_opp_calc_power()
1533 return -EINVAL; in dev_pm_opp_calc_power()
1536 opp = dev_pm_opp_find_freq_ceil(dev, &Hz); in dev_pm_opp_calc_power()
1537 if (IS_ERR(opp)) in dev_pm_opp_calc_power()
1538 return -EINVAL; in dev_pm_opp_calc_power()
1540 mV = dev_pm_opp_get_voltage(opp) / 1000; in dev_pm_opp_calc_power()
1541 dev_pm_opp_put(opp); in dev_pm_opp_calc_power()
1543 return -EINVAL; in dev_pm_opp_calc_power()
1546 /* Provide power in micro-Watts */ in dev_pm_opp_calc_power()
1559 struct dev_pm_opp *opp; in _of_has_opp_microwatt_property() local
1561 /* Check if at least one OPP has needed property */ in _of_has_opp_microwatt_property()
1562 opp = dev_pm_opp_find_freq_ceil(dev, &freq); in _of_has_opp_microwatt_property()
1563 if (IS_ERR(opp)) in _of_has_opp_microwatt_property()
1566 power = dev_pm_opp_get_power(opp); in _of_has_opp_microwatt_property()
1567 dev_pm_opp_put(opp); in _of_has_opp_microwatt_property()
1575 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model
1580 * This checks whether the "dynamic-power-coefficient" devicetree property has
1593 ret = -EINVAL; in dev_pm_opp_of_register_em()
1599 ret = -EINVAL; in dev_pm_opp_of_register_em()
1609 np = of_node_get(dev->of_node); in dev_pm_opp_of_register_em()
1611 ret = -EINVAL; in dev_pm_opp_of_register_em()
1616 * Register an EM only if the 'dynamic-power-coefficient' property is in dev_pm_opp_of_register_em()
1622 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in dev_pm_opp_of_register_em()
1625 dev_dbg(dev, "Couldn't find proper 'dynamic-power-coefficient' in DT\n"); in dev_pm_opp_of_register_em()
1626 ret = -EINVAL; in dev_pm_opp_of_register_em()