Lines Matching +full:energy +full:- +full:empty

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
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()
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()
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()
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()
88 mutex_unlock(&opp_table->lock); 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.
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()
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()
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()
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()
296 of_node_put(opp->np); in _of_clear_opp()
299 /* Populate all required OPPs which are part of "required-opps" list */
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()
335 __func__, opp->np, i); in _of_opp_alloc_required_opps()
336 ret = -ENODEV; in _of_opp_alloc_required_opps()
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()
366 __func__, opp->np, index); in lazy_link_required_opps()
367 return -ENODEV; in lazy_link_required_opps()
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()
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()
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()
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()
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()
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()
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()
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
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)
893 * Duplicate OPPs (both freq and volt are same) and opp->available
895 * ERR_PTR(-EEXIST):
897 * Duplicate OPPs (both freq and volt are same) and !opp->available
898 * ERR_PTR(-ENOMEM):
900 * ERR_PTR(-EINVAL):
912 return ERR_PTR(-ENOMEM); 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()
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()
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()
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()
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()
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()
1074 ret = -EINVAL; in _of_add_opp_table_v1()
1078 val = prop->value; in _of_add_opp_table_v1()
1089 nr -= 2; in _of_add_opp_table_v1()
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
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
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
1205 * using the "operating-points-v2" property.
1216 * devm_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
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
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
1255 return -ENODEV; in dev_pm_opp_of_cpumask_add_table()
1262 ret = -ENODEV; in dev_pm_opp_of_cpumask_add_table()
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.
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()
1342 ret = -ENOENT; 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"
1375 int pstate = -EINVAL; in of_get_required_opp_performance_state()
1379 return -ENODEV; in of_get_required_opp_performance_state()
1389 if (unlikely(!opp_table->is_genpd)) { in of_get_required_opp_performance_state()
1396 pstate = opp->level; in of_get_required_opp_performance_state()
1410 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
1424 return of_node_get(opp->np); in dev_pm_opp_get_of_node()
1429 * Callback function provided to the Energy Model framework upon registration.
1435 * Returns 0 on success or a proper -EINVAL value in case of error.
1447 return -EINVAL; in _get_dt_power()
1452 return -EINVAL; in _get_dt_power()
1461 * Callback function provided to the Energy Model framework upon registration.
1469 * Returns -EINVAL if the power calculation failed because of missing
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()
1494 return -EINVAL; in _get_power()
1499 return -EINVAL; in _get_power()
1502 /* Provide power in micro-Watts */ in _get_power()
1530 * dev_pm_opp_of_register_em() - Attempt to register an Energy Model
1531 * @dev : Device for which an Energy Model has to be registered
1532 * @cpus : CPUs for which an Energy Model has to be registered. For
1535 * This checks whether the "dynamic-power-coefficient" devicetree property has
1536 * been specified, and tries to register an Energy Model with it if it has.
1548 ret = -EINVAL; in dev_pm_opp_of_register_em()
1554 ret = -EINVAL; in dev_pm_opp_of_register_em()
1558 /* First, try to find more precised Energy Model in DT */ 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()
1595 dev_dbg(dev, "Couldn't register Energy Model %d\n", ret); in dev_pm_opp_of_register_em()