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"
25 * Returns opp descriptor node for a device node, caller must
31 /* "operating-points-v2" can be an array for power domain providers */ in _opp_of_get_opp_desc_node()
32 return of_parse_phandle(np, "operating-points-v2", index); in _opp_of_get_opp_desc_node()
35 /* Returns opp descriptor node for a device, caller must do of_node_put() */
38 return _opp_of_get_opp_desc_node(dev->of_node, 0); in dev_pm_opp_of_get_opp_desc_node()
47 np = _opp_of_get_opp_desc_node(dev->of_node, index); in _managed_opp()
52 if (opp_table->np == np) { in _managed_opp()
54 * Multiple devices can point to the same OPP table and in _managed_opp()
55 * so will have same node-pointer, np. in _managed_opp()
58 * OPP table contains a "opp-shared" property. in _managed_opp()
60 if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) { in _managed_opp()
74 /* The caller must call dev_pm_opp_put() after the OPP is used */
78 struct dev_pm_opp *opp; in _find_opp_of_np() local
80 mutex_lock(&opp_table->lock); in _find_opp_of_np()
82 list_for_each_entry(opp, &opp_table->opp_list, node) { in _find_opp_of_np()
83 if (opp->np == opp_np) { in _find_opp_of_np()
84 dev_pm_opp_get(opp); in _find_opp_of_np()
85 mutex_unlock(&opp_table->lock); in _find_opp_of_np()
86 return opp; in _find_opp_of_np()
90 mutex_unlock(&opp_table->lock); in _find_opp_of_np()
98 return of_parse_phandle(np, "required-opps", index); in of_parse_required_opp()
101 /* The caller must call dev_pm_opp_put_opp_table() after the table is used */
116 if (opp_table_np == opp_table->np) { in _find_table_of_opp_np()
125 return ERR_PTR(-ENODEV); in _find_table_of_opp_np()
131 struct opp_table **required_opp_tables = opp_table->required_opp_tables; in _opp_table_free_required_tables()
137 for (i = 0; i < opp_table->required_opp_count; i++) { in _opp_table_free_required_tables()
146 opp_table->required_opp_count = 0; in _opp_table_free_required_tables()
147 opp_table->required_opp_tables = NULL; in _opp_table_free_required_tables()
148 list_del(&opp_table->lazy); in _opp_table_free_required_tables()
152 * Populate all devices and opp tables which are part of "required-opps" list.
153 * Checking only the first OPP node should be enough.
164 /* Traversing the first OPP node is all we need */ in _opp_table_alloc_required_tables()
167 dev_warn(dev, "Empty OPP table\n"); in _opp_table_alloc_required_tables()
172 count = of_count_phandle_with_args(np, "required-opps", NULL); in _opp_table_alloc_required_tables()
181 opp_table->required_opp_tables = required_opp_tables; in _opp_table_alloc_required_tables()
182 opp_table->required_opp_count = count; in _opp_table_alloc_required_tables()
198 list_add(&opp_table->lazy, &lazy_opp_tables); in _opp_table_alloc_required_tables()
218 np = of_node_get(dev->of_node); in _of_init_opp_table()
222 if (!of_property_read_u32(np, "clock-latency", &val)) in _of_init_opp_table()
223 opp_table->clock_latency_ns_max = val; in _of_init_opp_table()
224 of_property_read_u32(np, "voltage-tolerance", in _of_init_opp_table()
225 &opp_table->voltage_tolerance_v1); in _of_init_opp_table()
227 if (of_find_property(np, "#power-domain-cells", NULL)) in _of_init_opp_table()
228 opp_table->is_genpd = true; in _of_init_opp_table()
230 /* Get OPP table node */ in _of_init_opp_table()
237 if (of_property_read_bool(opp_np, "opp-shared")) in _of_init_opp_table()
238 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; in _of_init_opp_table()
240 opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; in _of_init_opp_table()
242 opp_table->np = opp_np; in _of_init_opp_table()
250 of_node_put(opp_table->np); in _of_clear_opp_table()
258 struct dev_pm_opp *opp) in _of_opp_free_required_opps() argument
260 struct dev_pm_opp **required_opps = opp->required_opps; in _of_opp_free_required_opps()
266 for (i = 0; i < opp_table->required_opp_count; i++) { in _of_opp_free_required_opps()
274 opp->required_opps = NULL; in _of_opp_free_required_opps()
278 void _of_clear_opp(struct opp_table *opp_table, struct dev_pm_opp *opp) in _of_clear_opp() argument
280 _of_opp_free_required_opps(opp_table, opp); in _of_clear_opp()
281 of_node_put(opp->np); in _of_clear_opp()
284 /* Populate all required OPPs which are part of "required-opps" list */
286 struct dev_pm_opp *opp) in _of_opp_alloc_required_opps() argument
291 int i, ret, count = opp_table->required_opp_count; in _of_opp_alloc_required_opps()
298 return -ENOMEM; in _of_opp_alloc_required_opps()
300 opp->required_opps = required_opps; in _of_opp_alloc_required_opps()
303 required_table = opp_table->required_opp_tables[i]; in _of_opp_alloc_required_opps()
305 /* Required table not added yet, we will link later */ in _of_opp_alloc_required_opps()
309 np = of_parse_required_opp(opp->np, i); in _of_opp_alloc_required_opps()
311 ret = -ENODEV; in _of_opp_alloc_required_opps()
319 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n", in _of_opp_alloc_required_opps()
320 __func__, opp->np, i); in _of_opp_alloc_required_opps()
321 ret = -ENODEV; in _of_opp_alloc_required_opps()
329 _of_opp_free_required_opps(opp_table, opp); in _of_opp_alloc_required_opps()
334 /* Link required OPPs for an individual OPP */
339 struct dev_pm_opp *opp; in lazy_link_required_opps() local
341 list_for_each_entry(opp, &opp_table->opp_list, node) { in lazy_link_required_opps()
342 required_np = of_parse_required_opp(opp->np, index); in lazy_link_required_opps()
344 return -ENODEV; in lazy_link_required_opps()
346 opp->required_opps[index] = _find_opp_of_np(new_table, required_np); in lazy_link_required_opps()
349 if (!opp->required_opps[index]) { in lazy_link_required_opps()
350 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n", in lazy_link_required_opps()
351 __func__, opp->np, index); in lazy_link_required_opps()
352 return -ENODEV; in lazy_link_required_opps()
359 /* Link required OPPs for all OPPs of the newly added OPP table */
364 struct dev_pm_opp *opp; in lazy_link_required_opp_table() local
373 opp_np = of_get_next_available_child(opp_table->np, NULL); in lazy_link_required_opp_table()
375 for (i = 0; i < opp_table->required_opp_count; i++) { in lazy_link_required_opp_table()
376 required_opp_tables = opp_table->required_opp_tables; in lazy_link_required_opp_table()
378 /* Required opp-table is already parsed */ in lazy_link_required_opp_table()
390 * Newly added table isn't the required opp-table for in lazy_link_required_opp_table()
393 if (required_table_np != new_table->np) { in lazy_link_required_opp_table()
412 /* All required opp-tables found, remove from lazy list */ in lazy_link_required_opp_table()
414 list_del_init(&opp_table->lazy); in lazy_link_required_opp_table()
416 list_for_each_entry(opp, &opp_table->opp_list, node) in lazy_link_required_opp_table()
417 _required_opps_available(opp, opp_table->required_opp_count); in lazy_link_required_opp_table()
430 np = of_node_get(dev->of_node); in _bandwidth_supported()
432 return -ENODEV; in _bandwidth_supported()
437 opp_np = of_node_get(opp_table->np); in _bandwidth_supported()
440 /* Lets not fail in case we are parsing opp-v1 bindings */ in _bandwidth_supported()
444 /* Checking only first OPP is sufficient */ in _bandwidth_supported()
448 dev_err(dev, "OPP table empty\n"); in _bandwidth_supported()
449 return -EINVAL; in _bandwidth_supported()
452 prop = of_find_property(np, "opp-peak-kBps", NULL); in _bandwidth_supported()
455 if (!prop || !prop->length) in _bandwidth_supported()
469 if (ret == -EINVAL) in dev_pm_opp_of_find_icc_paths()
470 return 0; /* Empty OPP table is a valid corner-case, let's not fail */ in dev_pm_opp_of_find_icc_paths()
476 np = of_node_get(dev->of_node); in dev_pm_opp_of_find_icc_paths()
481 "#interconnect-cells"); in dev_pm_opp_of_find_icc_paths()
486 /* two phandles when #interconnect-cells = <1> */ in dev_pm_opp_of_find_icc_paths()
489 return -EINVAL; in dev_pm_opp_of_find_icc_paths()
495 return -ENOMEM; in dev_pm_opp_of_find_icc_paths()
501 if (ret != -EPROBE_DEFER) { in dev_pm_opp_of_find_icc_paths()
510 opp_table->paths = paths; in dev_pm_opp_of_find_icc_paths()
511 opp_table->path_count = num_paths; in dev_pm_opp_of_find_icc_paths()
516 while (i--) in dev_pm_opp_of_find_icc_paths()
528 unsigned int levels = opp_table->supported_hw_count; in _opp_is_supported()
532 if (!opp_table->supported_hw) { in _opp_is_supported()
535 * platform but there is an opp-supported-hw value set for in _opp_is_supported()
536 * an OPP then the OPP should not be enabled as there is in _opp_is_supported()
539 if (of_find_property(np, "opp-supported-hw", NULL)) in _opp_is_supported()
545 count = of_property_count_u32_elems(np, "opp-supported-hw"); in _opp_is_supported()
547 dev_err(dev, "%s: Invalid opp-supported-hw property (%d)\n", in _opp_is_supported()
559 ret = of_property_read_u32_index(np, "opp-supported-hw", in _opp_is_supported()
562 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n", in _opp_is_supported()
568 if (!(val & opp_table->supported_hw[j])) { in _opp_is_supported()
581 static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, in opp_parse_supplies() argument
585 int supplies = opp_table->regulator_count; in opp_parse_supplies()
590 /* Search for "opp-microvolt-<name>" */ in opp_parse_supplies()
591 if (opp_table->prop_name) { in opp_parse_supplies()
592 snprintf(name, sizeof(name), "opp-microvolt-%s", in opp_parse_supplies()
593 opp_table->prop_name); in opp_parse_supplies()
594 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
598 /* Search for "opp-microvolt" */ in opp_parse_supplies()
599 sprintf(name, "opp-microvolt"); in opp_parse_supplies()
600 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
604 if (unlikely(supplies == -1)) { in opp_parse_supplies()
606 opp_table->regulator_count = 0; in opp_parse_supplies()
613 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n", in opp_parse_supplies()
615 return -EINVAL; in opp_parse_supplies()
619 if (unlikely(supplies == -1)) { in opp_parse_supplies()
621 supplies = opp_table->regulator_count = 1; in opp_parse_supplies()
623 dev_err(dev, "%s: opp-microvolt wasn't expected\n", __func__); in opp_parse_supplies()
624 return -EINVAL; in opp_parse_supplies()
627 vcount = of_property_count_u32_elems(opp->np, name); in opp_parse_supplies()
638 return -EINVAL; in opp_parse_supplies()
643 return -ENOMEM; in opp_parse_supplies()
645 ret = of_property_read_u32_array(opp->np, name, microvolt, vcount); in opp_parse_supplies()
648 ret = -EINVAL; in opp_parse_supplies()
652 /* Search for "opp-microamp-<name>" */ in opp_parse_supplies()
654 if (opp_table->prop_name) { in opp_parse_supplies()
655 snprintf(name, sizeof(name), "opp-microamp-%s", in opp_parse_supplies()
656 opp_table->prop_name); in opp_parse_supplies()
657 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
661 /* Search for "opp-microamp" */ in opp_parse_supplies()
662 sprintf(name, "opp-microamp"); in opp_parse_supplies()
663 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
667 icount = of_property_count_u32_elems(opp->np, name); in opp_parse_supplies()
678 ret = -EINVAL; in opp_parse_supplies()
684 ret = -EINVAL; in opp_parse_supplies()
688 ret = of_property_read_u32_array(opp->np, name, microamp, in opp_parse_supplies()
693 ret = -EINVAL; in opp_parse_supplies()
698 /* Search for "opp-microwatt" */ in opp_parse_supplies()
699 sprintf(name, "opp-microwatt"); in opp_parse_supplies()
700 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
703 pcount = of_property_count_u32_elems(opp->np, name); in opp_parse_supplies()
714 ret = -EINVAL; in opp_parse_supplies()
721 ret = -EINVAL; in opp_parse_supplies()
725 ret = of_property_read_u32_array(opp->np, name, microwatt, in opp_parse_supplies()
730 ret = -EINVAL; in opp_parse_supplies()
736 opp->supplies[i].u_volt = microvolt[j++]; in opp_parse_supplies()
739 opp->supplies[i].u_volt_min = opp->supplies[i].u_volt; in opp_parse_supplies()
740 opp->supplies[i].u_volt_max = opp->supplies[i].u_volt; in opp_parse_supplies()
742 opp->supplies[i].u_volt_min = microvolt[j++]; in opp_parse_supplies()
743 opp->supplies[i].u_volt_max = microvolt[j++]; in opp_parse_supplies()
747 opp->supplies[i].u_amp = microamp[i]; in opp_parse_supplies()
750 opp->supplies[i].u_watt = microwatt[i]; in opp_parse_supplies()
764 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
766 * @dev: device pointer used to lookup OPP table.
783 prop = of_find_property(np, "opp-hz", NULL); in _read_rate()
785 return -ENODEV; in _read_rate()
787 count = prop->length / sizeof(u64); in _read_rate()
788 if (opp_table->clk_count != count) { in _read_rate()
789 pr_err("%s: Count mismatch between opp-hz and clk_count (%d %d)\n", in _read_rate()
790 __func__, count, opp_table->clk_count); in _read_rate()
791 return -EINVAL; in _read_rate()
796 return -ENOMEM; in _read_rate()
798 ret = of_property_read_u64_array(np, "opp-hz", rates, count); in _read_rate()
800 pr_err("%s: Error parsing opp-hz: %d\n", __func__, ret); in _read_rate()
808 new_opp->rates[i] = (unsigned long)rates[i]; in _read_rate()
811 WARN_ON(new_opp->rates[i] != rates[i]); in _read_rate()
823 const char *name = peak ? "opp-peak-kBps" : "opp-avg-kBps"; in _read_bw()
830 return -ENODEV; in _read_bw()
832 count = prop->length / sizeof(u32); in _read_bw()
833 if (opp_table->path_count != count) { in _read_bw()
835 __func__, name, count, opp_table->path_count); in _read_bw()
836 return -EINVAL; in _read_bw()
841 return -ENOMEM; in _read_bw()
851 new_opp->bandwidth[i].peak = kBps_to_icc(bw[i]); in _read_bw()
853 new_opp->bandwidth[i].avg = kBps_to_icc(bw[i]); in _read_bw()
870 else if (ret != -ENODEV) in _read_opp_key()
875 * opp-peak-kBps = <path1_value path2_value>; in _read_opp_key()
876 * opp-avg-kBps = <path1_value path2_value>; in _read_opp_key()
885 if (ret && ret != -ENODEV) in _read_opp_key()
888 if (!of_property_read_u32(np, "opp-level", &new_opp->level)) in _read_opp_key()
898 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
899 * @opp_table: OPP table
903 * This function adds an opp definition to the opp table and returns status. The
904 * opp can be controlled using dev_pm_opp_enable/disable functions and may be
908 * Valid OPP pointer:
911 * Duplicate OPPs (both freq and volt are same) and opp->available
912 * OR if the OPP is not supported by hardware.
913 * ERR_PTR(-EEXIST):
915 * Duplicate OPPs (both freq and volt are same) and !opp->available
916 * ERR_PTR(-ENOMEM):
918 * ERR_PTR(-EINVAL):
919 * Failed parsing the OPP node
930 return ERR_PTR(-ENOMEM); in _opp_add_static_v2()
934 dev_err(dev, "%s: opp key field not found\n", __func__); in _opp_add_static_v2()
938 /* Check if the OPP supports hardware's hierarchy of versions or not */ in _opp_add_static_v2()
940 dev_dbg(dev, "OPP not supported by hardware: %s\n", in _opp_add_static_v2()
945 new_opp->turbo = of_property_read_bool(np, "turbo-mode"); in _opp_add_static_v2()
947 new_opp->np = of_node_get(np); in _opp_add_static_v2()
948 new_opp->dynamic = false; in _opp_add_static_v2()
949 new_opp->available = true; in _opp_add_static_v2()
955 if (!of_property_read_u32(np, "clock-latency-ns", &val)) in _opp_add_static_v2()
956 new_opp->clock_latency_ns = val; in _opp_add_static_v2()
962 if (opp_table->is_genpd) in _opp_add_static_v2()
963 new_opp->pstate = pm_genpd_opp_to_performance_state(dev, new_opp); in _opp_add_static_v2()
968 if (ret == -EBUSY) in _opp_add_static_v2()
973 /* OPP to select on device suspend */ in _opp_add_static_v2()
974 if (of_property_read_bool(np, "opp-suspend")) { in _opp_add_static_v2()
975 if (opp_table->suspend_opp) { in _opp_add_static_v2()
976 /* Pick the OPP with higher rate/bw/level as suspend OPP */ in _opp_add_static_v2()
977 if (_opp_compare_key(opp_table, new_opp, opp_table->suspend_opp) == 1) { in _opp_add_static_v2()
978 opp_table->suspend_opp->suspend = false; in _opp_add_static_v2()
979 new_opp->suspend = true; in _opp_add_static_v2()
980 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
983 new_opp->suspend = true; in _opp_add_static_v2()
984 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
988 if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max) in _opp_add_static_v2()
989 opp_table->clock_latency_ns_max = new_opp->clock_latency_ns; in _opp_add_static_v2()
992 __func__, new_opp->turbo, new_opp->rates[0], in _opp_add_static_v2()
993 new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min, in _opp_add_static_v2()
994 new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns, in _opp_add_static_v2()
995 new_opp->level); in _opp_add_static_v2()
1001 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); in _opp_add_static_v2()
1012 /* Initializes OPP tables based on new bindings */
1017 struct dev_pm_opp *opp; in _of_add_opp_table_v2() local
1019 /* OPP table is already initialized for the device */ in _of_add_opp_table_v2()
1020 mutex_lock(&opp_table->lock); in _of_add_opp_table_v2()
1021 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v2()
1022 opp_table->parsed_static_opps++; in _of_add_opp_table_v2()
1023 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1027 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v2()
1028 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v2()
1030 /* We have opp-table node now, iterate over it and add OPPs */ in _of_add_opp_table_v2()
1031 for_each_available_child_of_node(opp_table->np, np) { in _of_add_opp_table_v2()
1032 opp = _opp_add_static_v2(opp_table, dev, np); in _of_add_opp_table_v2()
1033 if (IS_ERR(opp)) { in _of_add_opp_table_v2()
1034 ret = PTR_ERR(opp); in _of_add_opp_table_v2()
1035 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, in _of_add_opp_table_v2()
1039 } else if (opp) { in _of_add_opp_table_v2()
1047 ret = -ENOENT; in _of_add_opp_table_v2()
1051 list_for_each_entry(opp, &opp_table->opp_list, node) { in _of_add_opp_table_v2()
1052 /* Any non-zero performance state would enable the feature */ in _of_add_opp_table_v2()
1053 if (opp->pstate) { in _of_add_opp_table_v2()
1054 opp_table->genpd_performance_state = true; in _of_add_opp_table_v2()
1069 /* Initializes OPP tables based on old-deprecated bindings */
1076 mutex_lock(&opp_table->lock); in _of_add_opp_table_v1()
1077 if (opp_table->parsed_static_opps) { in _of_add_opp_table_v1()
1078 opp_table->parsed_static_opps++; in _of_add_opp_table_v1()
1079 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1083 opp_table->parsed_static_opps = 1; in _of_add_opp_table_v1()
1084 mutex_unlock(&opp_table->lock); in _of_add_opp_table_v1()
1086 prop = of_find_property(dev->of_node, "operating-points", NULL); in _of_add_opp_table_v1()
1088 ret = -ENODEV; in _of_add_opp_table_v1()
1091 if (!prop->value) { in _of_add_opp_table_v1()
1092 ret = -ENODATA; in _of_add_opp_table_v1()
1097 * Each OPP is a set of tuples consisting of frequency and in _of_add_opp_table_v1()
1098 * voltage like <freq-kHz vol-uV>. in _of_add_opp_table_v1()
1100 nr = prop->length / sizeof(u32); in _of_add_opp_table_v1()
1102 dev_err(dev, "%s: Invalid OPP table\n", __func__); in _of_add_opp_table_v1()
1103 ret = -EINVAL; in _of_add_opp_table_v1()
1107 val = prop->value; in _of_add_opp_table_v1()
1114 dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", in _of_add_opp_table_v1()
1118 nr -= 2; in _of_add_opp_table_v1()
1136 * If only one phandle is present, then the same OPP table in _of_add_table_indexed()
1139 count = of_count_phandle_with_args(dev->of_node, in _of_add_table_indexed()
1140 "operating-points-v2", NULL); in _of_add_table_indexed()
1153 if (opp_table->np) in _of_add_table_indexed()
1181 * devm_pm_opp_of_add_table() - Initialize opp table from device tree
1182 * @dev: device pointer used to lookup OPP table.
1184 * Register the initial OPP table with the OPP library for given device.
1190 * Duplicate OPPs (both freq and volt are same) and opp->available
1191 * -EEXIST Freq are same and volt are different OR
1192 * Duplicate OPPs (both freq and volt are same) and !opp->available
1193 * -ENOMEM Memory allocation failure
1194 * -ENODEV when 'operating-points' property is not found or is invalid data
1196 * -ENODATA when empty 'operating-points' property is found
1197 * -EINVAL when invalid entries are found in opp-v2 table
1206 * dev_pm_opp_of_add_table() - Initialize opp table from device tree
1207 * @dev: device pointer used to lookup OPP table.
1209 * Register the initial OPP table with the OPP library for given device.
1213 * Duplicate OPPs (both freq and volt are same) and opp->available
1214 * -EEXIST Freq are same and volt are different OR
1215 * Duplicate OPPs (both freq and volt are same) and !opp->available
1216 * -ENOMEM Memory allocation failure
1217 * -ENODEV when 'operating-points' property is not found or is invalid data
1219 * -ENODATA when empty 'operating-points' property is found
1220 * -EINVAL when invalid entries are found in opp-v2 table
1229 * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
1230 * @dev: device pointer used to lookup OPP table.
1233 * Register the initial OPP table with the OPP library for given device only
1234 * using the "operating-points-v2" property.
1245 * devm_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
1246 * @dev: device pointer used to lookup OPP table.
1249 * This is a resource-managed variant of dev_pm_opp_of_add_table_indexed().
1260 * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
1261 * @cpumask: cpumask for which OPP table needs to be removed
1263 * This removes the OPP tables for CPUs present in the @cpumask.
1268 _dev_pm_opp_cpumask_remove_table(cpumask, -1); in dev_pm_opp_of_cpumask_remove_table()
1273 * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
1274 * @cpumask: cpumask for which OPP table needs to be added.
1276 * This adds the OPP tables for CPUs present in the @cpumask.
1284 return -ENODEV; in dev_pm_opp_of_cpumask_add_table()
1291 ret = -ENODEV; in dev_pm_opp_of_cpumask_add_table()
1298 * OPP may get registered dynamically, don't print error in dev_pm_opp_of_cpumask_add_table()
1301 pr_debug("%s: couldn't find opp table for cpu:%d, %d\n", in dev_pm_opp_of_cpumask_add_table()
1319 * Works only for OPP v2 bindings.
1321 * Returns -ENOENT if operating-points-v2 bindings aren't supported.
1324 * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
1325 * @cpu_dev using operating-points-v2
1333 * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
1341 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
1344 dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__); in dev_pm_opp_of_get_sharing_cpus()
1345 return -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1348 cpumask_set_cpu(cpu_dev->id, cpumask); in dev_pm_opp_of_get_sharing_cpus()
1351 if (!of_property_read_bool(np, "opp-shared")) in dev_pm_opp_of_get_sharing_cpus()
1355 if (cpu == cpu_dev->id) in dev_pm_opp_of_get_sharing_cpus()
1362 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1366 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
1370 pr_err("%pOF: Couldn't find opp node\n", cpu_np); in dev_pm_opp_of_get_sharing_cpus()
1371 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
1375 /* CPUs are sharing opp node */ in dev_pm_opp_of_get_sharing_cpus()
1389 …* of_get_required_opp_performance_state() - Search for required OPP and return its performance sta…
1390 * @np: Node that contains the "required-opps" property.
1393 * Returns the performance state of the OPP pointed out by the "required-opps"
1401 struct dev_pm_opp *opp; in of_get_required_opp_performance_state() local
1404 int pstate = -EINVAL; in of_get_required_opp_performance_state()
1408 return -ENODEV; in of_get_required_opp_performance_state()
1412 pr_err("%s: Failed to find required OPP table %pOF: %ld\n", in of_get_required_opp_performance_state()
1417 opp = _find_opp_of_np(opp_table, required_np); in of_get_required_opp_performance_state()
1418 if (opp) { in of_get_required_opp_performance_state()
1419 pstate = opp->pstate; in of_get_required_opp_performance_state()
1420 dev_pm_opp_put(opp); in of_get_required_opp_performance_state()
1433 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
1434 * @opp: opp for which DT node has to be returned for
1436 * Return: DT node corresponding to the opp, else 0 on success.
1440 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) in dev_pm_opp_get_of_node() argument
1442 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_of_node()
1447 return of_node_get(opp->np); in dev_pm_opp_get_of_node()
1454 * existing OPP, or at the frequency of the first OPP above @kHz otherwise
1458 * Returns 0 on success or a proper -EINVAL value in case of error.
1463 struct dev_pm_opp *opp; in _get_dt_power() local
1466 /* Find the right frequency and related OPP */ in _get_dt_power()
1468 opp = dev_pm_opp_find_freq_ceil(dev, &opp_freq); in _get_dt_power()
1469 if (IS_ERR(opp)) in _get_dt_power()
1470 return -EINVAL; in _get_dt_power()
1472 opp_power = dev_pm_opp_get_power(opp); in _get_dt_power()
1473 dev_pm_opp_put(opp); in _get_dt_power()
1475 return -EINVAL; in _get_dt_power()
1486 * of an existing OPP, or at the frequency of the first OPP above @kHz otherwise
1490 * respectively the voltage and frequency of the OPP.
1492 * Returns -EINVAL if the power calculation failed because of missing
1498 struct dev_pm_opp *opp; in _get_power() local
1505 np = of_node_get(dev->of_node); in _get_power()
1507 return -EINVAL; in _get_power()
1509 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in _get_power()
1512 return -EINVAL; in _get_power()
1515 opp = dev_pm_opp_find_freq_ceil(dev, &Hz); in _get_power()
1516 if (IS_ERR(opp)) in _get_power()
1517 return -EINVAL; in _get_power()
1519 mV = dev_pm_opp_get_voltage(opp) / 1000; in _get_power()
1520 dev_pm_opp_put(opp); in _get_power()
1522 return -EINVAL; in _get_power()
1525 /* Provide power in micro-Watts */ in _get_power()
1537 struct dev_pm_opp *opp; in _of_has_opp_microwatt_property() local
1539 /* Check if at least one OPP has needed property */ in _of_has_opp_microwatt_property()
1540 opp = dev_pm_opp_find_freq_ceil(dev, &freq); in _of_has_opp_microwatt_property()
1541 if (IS_ERR(opp)) in _of_has_opp_microwatt_property()
1544 power = dev_pm_opp_get_power(opp); in _of_has_opp_microwatt_property()
1545 dev_pm_opp_put(opp); in _of_has_opp_microwatt_property()
1553 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model
1558 * This checks whether the "dynamic-power-coefficient" devicetree property has
1571 ret = -EINVAL; in dev_pm_opp_of_register_em()
1577 ret = -EINVAL; in dev_pm_opp_of_register_em()
1587 np = of_node_get(dev->of_node); in dev_pm_opp_of_register_em()
1589 ret = -EINVAL; in dev_pm_opp_of_register_em()
1594 * Register an EM only if the 'dynamic-power-coefficient' property is in dev_pm_opp_of_register_em()
1600 ret = of_property_read_u32(np, "dynamic-power-coefficient", &cap); in dev_pm_opp_of_register_em()
1603 dev_dbg(dev, "Couldn't find proper 'dynamic-power-coefficient' in DT\n"); in dev_pm_opp_of_register_em()
1604 ret = -EINVAL; in dev_pm_opp_of_register_em()