• Home
  • Raw
  • Download

Lines Matching +full:opp +full:- +full:table

2  * Generic OPP OF helpers
4 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
24 #include "opp.h"
33 if (opp_table->np == np) { in _managed_opp()
35 * Multiple devices can point to the same OPP table and in _managed_opp()
36 * so will have same node-pointer, np. in _managed_opp()
39 * OPP table contains a "opp-shared" property. in _managed_opp()
41 if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) { in _managed_opp()
63 np = of_node_get(dev->of_node); in _of_init_opp_table()
67 if (!of_property_read_u32(np, "clock-latency", &val)) in _of_init_opp_table()
68 opp_table->clock_latency_ns_max = val; in _of_init_opp_table()
69 of_property_read_u32(np, "voltage-tolerance", in _of_init_opp_table()
70 &opp_table->voltage_tolerance_v1); in _of_init_opp_table()
78 unsigned int count = opp_table->supported_hw_count; in _opp_is_supported()
82 if (!opp_table->supported_hw) { in _opp_is_supported()
85 * platform but there is an opp-supported-hw value set for in _opp_is_supported()
86 * an OPP then the OPP should not be enabled as there is in _opp_is_supported()
89 if (of_find_property(np, "opp-supported-hw", NULL)) in _opp_is_supported()
95 while (count--) { in _opp_is_supported()
96 ret = of_property_read_u32_index(np, "opp-supported-hw", count, in _opp_is_supported()
99 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n", in _opp_is_supported()
105 if (!(version & opp_table->supported_hw[count])) in _opp_is_supported()
112 static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, in opp_parse_supplies() argument
116 int supplies = opp_table->regulator_count, vcount, icount, ret, i, j; in opp_parse_supplies()
120 /* Search for "opp-microvolt-<name>" */ in opp_parse_supplies()
121 if (opp_table->prop_name) { in opp_parse_supplies()
122 snprintf(name, sizeof(name), "opp-microvolt-%s", in opp_parse_supplies()
123 opp_table->prop_name); in opp_parse_supplies()
124 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
128 /* Search for "opp-microvolt" */ in opp_parse_supplies()
129 sprintf(name, "opp-microvolt"); in opp_parse_supplies()
130 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
134 if (unlikely(supplies == -1)) { in opp_parse_supplies()
136 opp_table->regulator_count = 0; in opp_parse_supplies()
143 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n", in opp_parse_supplies()
145 return -EINVAL; in opp_parse_supplies()
149 if (unlikely(supplies == -1)) { in opp_parse_supplies()
151 supplies = opp_table->regulator_count = 1; in opp_parse_supplies()
153 dev_err(dev, "%s: opp-microvolt wasn't expected\n", __func__); in opp_parse_supplies()
154 return -EINVAL; in opp_parse_supplies()
157 vcount = of_property_count_u32_elems(opp->np, name); in opp_parse_supplies()
168 return -EINVAL; in opp_parse_supplies()
173 return -ENOMEM; in opp_parse_supplies()
175 ret = of_property_read_u32_array(opp->np, name, microvolt, vcount); in opp_parse_supplies()
178 ret = -EINVAL; in opp_parse_supplies()
182 /* Search for "opp-microamp-<name>" */ in opp_parse_supplies()
184 if (opp_table->prop_name) { in opp_parse_supplies()
185 snprintf(name, sizeof(name), "opp-microamp-%s", in opp_parse_supplies()
186 opp_table->prop_name); in opp_parse_supplies()
187 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
191 /* Search for "opp-microamp" */ in opp_parse_supplies()
192 sprintf(name, "opp-microamp"); in opp_parse_supplies()
193 prop = of_find_property(opp->np, name, NULL); in opp_parse_supplies()
197 icount = of_property_count_u32_elems(opp->np, name); in opp_parse_supplies()
208 ret = -EINVAL; in opp_parse_supplies()
214 ret = -EINVAL; in opp_parse_supplies()
218 ret = of_property_read_u32_array(opp->np, name, microamp, in opp_parse_supplies()
223 ret = -EINVAL; in opp_parse_supplies()
229 opp->supplies[i].u_volt = microvolt[j++]; in opp_parse_supplies()
232 opp->supplies[i].u_volt_min = opp->supplies[i].u_volt; in opp_parse_supplies()
233 opp->supplies[i].u_volt_max = opp->supplies[i].u_volt; in opp_parse_supplies()
235 opp->supplies[i].u_volt_min = microvolt[j++]; in opp_parse_supplies()
236 opp->supplies[i].u_volt_max = microvolt[j++]; in opp_parse_supplies()
240 opp->supplies[i].u_amp = microamp[i]; in opp_parse_supplies()
252 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
254 * @dev: device pointer used to lookup OPP table.
264 /* Returns opp descriptor node for a device node, caller must
269 /* "operating-points-v2" can be an array for power domain providers */ in _opp_of_get_opp_desc_node()
270 return of_parse_phandle(np, "operating-points-v2", index); in _opp_of_get_opp_desc_node()
273 /* Returns opp descriptor node for a device, caller must do of_node_put() */
276 return _opp_of_get_opp_desc_node(dev->of_node, 0); in dev_pm_opp_of_get_opp_desc_node()
281 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
282 * @opp_table: OPP table
286 * This function adds an opp definition to the opp table and returns status. The
287 * opp can be controlled using dev_pm_opp_enable/disable functions and may be
292 * Duplicate OPPs (both freq and volt are same) and opp->available
293 * -EEXIST Freq are same and volt are different OR
294 * Duplicate OPPs (both freq and volt are same) and !opp->available
295 * -ENOMEM Memory allocation failure
296 * -EINVAL Failed parsing the OPP node
309 return -ENOMEM; in _opp_add_static_v2()
311 ret = of_property_read_u64(np, "opp-hz", &rate); in _opp_add_static_v2()
313 /* "opp-hz" is optional for devices like power domains. */ in _opp_add_static_v2()
314 if (!of_find_property(dev->of_node, "#power-domain-cells", in _opp_add_static_v2()
316 dev_err(dev, "%s: opp-hz not found\n", __func__); in _opp_add_static_v2()
327 new_opp->rate = (unsigned long)rate; in _opp_add_static_v2()
330 /* Check if the OPP supports hardware's hierarchy of versions or not */ in _opp_add_static_v2()
332 dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate); in _opp_add_static_v2()
336 new_opp->turbo = of_property_read_bool(np, "turbo-mode"); in _opp_add_static_v2()
338 new_opp->np = np; in _opp_add_static_v2()
339 new_opp->dynamic = false; in _opp_add_static_v2()
340 new_opp->available = true; in _opp_add_static_v2()
342 if (!of_property_read_u32(np, "clock-latency-ns", &val)) in _opp_add_static_v2()
343 new_opp->clock_latency_ns = val; in _opp_add_static_v2()
345 new_opp->pstate = of_genpd_opp_to_performance_state(dev, np); in _opp_add_static_v2()
354 if (ret == -EBUSY) in _opp_add_static_v2()
359 /* OPP to select on device suspend */ in _opp_add_static_v2()
360 if (of_property_read_bool(np, "opp-suspend")) { in _opp_add_static_v2()
361 if (opp_table->suspend_opp) { in _opp_add_static_v2()
363 __func__, opp_table->suspend_opp->rate, in _opp_add_static_v2()
364 new_opp->rate); in _opp_add_static_v2()
366 new_opp->suspend = true; in _opp_add_static_v2()
367 opp_table->suspend_opp = new_opp; in _opp_add_static_v2()
371 if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max) in _opp_add_static_v2()
372 opp_table->clock_latency_ns_max = new_opp->clock_latency_ns; in _opp_add_static_v2()
375 __func__, new_opp->turbo, new_opp->rate, in _opp_add_static_v2()
376 new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min, in _opp_add_static_v2()
377 new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns); in _opp_add_static_v2()
383 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp); in _opp_add_static_v2()
392 /* Initializes OPP tables based on new bindings */
398 struct dev_pm_opp *opp; in _of_add_opp_table_v2() local
404 ret = -ENOMEM; in _of_add_opp_table_v2()
410 return -ENOMEM; in _of_add_opp_table_v2()
412 /* We have opp-table node now, iterate over it and add OPPs */ in _of_add_opp_table_v2()
418 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, in _of_add_opp_table_v2()
426 /* There should be one of more OPP defined */ in _of_add_opp_table_v2()
428 ret = -ENOENT; in _of_add_opp_table_v2()
432 list_for_each_entry(opp, &opp_table->opp_list, node) in _of_add_opp_table_v2()
433 pstate_count += !!opp->pstate; in _of_add_opp_table_v2()
439 ret = -ENOENT; in _of_add_opp_table_v2()
445 opp_table->genpd_performance_state = true; in _of_add_opp_table_v2()
447 opp_table->np = opp_np; in _of_add_opp_table_v2()
448 if (of_property_read_bool(opp_np, "opp-shared")) in _of_add_opp_table_v2()
449 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; in _of_add_opp_table_v2()
451 opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; in _of_add_opp_table_v2()
459 /* Initializes OPP tables based on old-deprecated bindings */
467 prop = of_find_property(dev->of_node, "operating-points", NULL); in _of_add_opp_table_v1()
469 return -ENODEV; in _of_add_opp_table_v1()
470 if (!prop->value) in _of_add_opp_table_v1()
471 return -ENODATA; in _of_add_opp_table_v1()
474 * Each OPP is a set of tuples consisting of frequency and in _of_add_opp_table_v1()
475 * voltage like <freq-kHz vol-uV>. in _of_add_opp_table_v1()
477 nr = prop->length / sizeof(u32); in _of_add_opp_table_v1()
479 dev_err(dev, "%s: Invalid OPP table\n", __func__); in _of_add_opp_table_v1()
480 return -EINVAL; in _of_add_opp_table_v1()
485 return -ENOMEM; in _of_add_opp_table_v1()
487 val = prop->value; in _of_add_opp_table_v1()
494 dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", in _of_add_opp_table_v1()
499 nr -= 2; in _of_add_opp_table_v1()
507 * dev_pm_opp_of_add_table() - Initialize opp table from device tree
508 * @dev: device pointer used to lookup OPP table.
510 * Register the initial OPP table with the OPP library for given device.
514 * Duplicate OPPs (both freq and volt are same) and opp->available
515 * -EEXIST Freq are same and volt are different OR
516 * Duplicate OPPs (both freq and volt are same) and !opp->available
517 * -ENOMEM Memory allocation failure
518 * -ENODEV when 'operating-points' property is not found or is invalid data
520 * -ENODATA when empty 'operating-points' property is found
521 * -EINVAL when invalid entries are found in opp-v2 table
535 * Try old-deprecated bindings for backward compatibility with in dev_pm_opp_of_add_table()
549 * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
550 * @dev: device pointer used to lookup OPP table.
553 * Register the initial OPP table with the OPP library for given device only
554 * using the "operating-points-v2" property.
558 * Duplicate OPPs (both freq and volt are same) and opp->available
559 * -EEXIST Freq are same and volt are different OR
560 * Duplicate OPPs (both freq and volt are same) and !opp->available
561 * -ENOMEM Memory allocation failure
562 * -ENODEV when 'operating-points' property is not found or is invalid data
564 * -ENODATA when empty 'operating-points' property is found
565 * -EINVAL when invalid entries are found in opp-v2 table
573 opp_np = _opp_of_get_opp_desc_node(dev->of_node, index); in dev_pm_opp_of_add_table_indexed()
576 * If only one phandle is present, then the same OPP table in dev_pm_opp_of_add_table_indexed()
579 count = of_count_phandle_with_args(dev->of_node, in dev_pm_opp_of_add_table_indexed()
580 "operating-points-v2", NULL); in dev_pm_opp_of_add_table_indexed()
586 return -ENODEV; in dev_pm_opp_of_add_table_indexed()
599 * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
600 * @cpumask: cpumask for which OPP table needs to be removed
602 * This removes the OPP tables for CPUs present in the @cpumask.
612 * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
613 * @cpumask: cpumask for which OPP table needs to be added.
615 * This adds the OPP tables for CPUs present in the @cpumask.
635 * OPP may get registered dynamically, don't print error in dev_pm_opp_of_cpumask_add_table()
638 pr_debug("%s: couldn't find opp table for cpu:%d, %d\n", in dev_pm_opp_of_cpumask_add_table()
652 * Works only for OPP v2 bindings.
654 * Returns -ENOENT if operating-points-v2 bindings aren't supported.
657 * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
658 * @cpu_dev using operating-points-v2
666 * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
674 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
677 dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__); in dev_pm_opp_of_get_sharing_cpus()
678 return -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
681 cpumask_set_cpu(cpu_dev->id, cpumask); in dev_pm_opp_of_get_sharing_cpus()
684 if (!of_property_read_bool(np, "opp-shared")) in dev_pm_opp_of_get_sharing_cpus()
688 if (cpu == cpu_dev->id) in dev_pm_opp_of_get_sharing_cpus()
695 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
699 /* Get OPP descriptor node */ in dev_pm_opp_of_get_sharing_cpus()
703 pr_err("%pOF: Couldn't find opp node\n", cpu_np); in dev_pm_opp_of_get_sharing_cpus()
704 ret = -ENOENT; in dev_pm_opp_of_get_sharing_cpus()
708 /* CPUs are sharing opp node */ in dev_pm_opp_of_get_sharing_cpus()
722 * of_dev_pm_opp_find_required_opp() - Search for required OPP.
723 * @dev: The device whose OPP node is referenced by the 'np' DT node.
724 * @np: Node that contains the "required-opps" property.
726 * Returns the OPP of the device 'dev', whose phandle is present in the "np"
727 * node. Although the "required-opps" property supports having multiple
730 * Return: Matching opp, else returns ERR_PTR in case of error and should be
733 * The callers are required to call dev_pm_opp_put() for the returned OPP after
739 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV); in of_dev_pm_opp_find_required_opp() local
747 required_np = of_parse_phandle(np, "required-opps", 0); in of_dev_pm_opp_find_required_opp()
749 dev_err(dev, "Unable to parse required-opps\n"); in of_dev_pm_opp_find_required_opp()
753 mutex_lock(&opp_table->lock); in of_dev_pm_opp_find_required_opp()
755 list_for_each_entry(temp_opp, &opp_table->opp_list, node) { in of_dev_pm_opp_find_required_opp()
756 if (temp_opp->available && temp_opp->np == required_np) { in of_dev_pm_opp_find_required_opp()
757 opp = temp_opp; in of_dev_pm_opp_find_required_opp()
759 /* Increment the reference count of OPP */ in of_dev_pm_opp_find_required_opp()
760 dev_pm_opp_get(opp); in of_dev_pm_opp_find_required_opp()
765 mutex_unlock(&opp_table->lock); in of_dev_pm_opp_find_required_opp()
771 return opp; in of_dev_pm_opp_find_required_opp()
776 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
777 * @opp: opp for which DT node has to be returned for
779 * Return: DT node corresponding to the opp, else 0 on success.
783 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp) in dev_pm_opp_get_of_node() argument
785 if (IS_ERR_OR_NULL(opp)) { in dev_pm_opp_get_of_node()
790 return of_node_get(opp->np); in dev_pm_opp_get_of_node()