2 * Generic OPP OF helpers
4 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/cpu.h>
17 #include <linux/errno.h>
18 #include <linux/device.h>
19 #include <linux/of_device.h>
20 #include <linux/pm_domain.h>
21 #include <linux/slab.h>
22 #include <linux/export.h>
27 * Returns opp descriptor node for a device node, caller must
30 static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np,
33 /* "operating-points-v2" can be an array for power domain providers */
34 return of_parse_phandle(np, "operating-points-v2", index);
37 /* Returns opp descriptor node for a device, caller must do of_node_put() */
38 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
40 return _opp_of_get_opp_desc_node(dev->of_node, 0);
42 EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node);
44 struct opp_table *_managed_opp(struct device *dev, int index)
46 struct opp_table *opp_table, *managed_table = NULL;
47 struct device_node *np;
49 np = _opp_of_get_opp_desc_node(dev->of_node, index);
53 list_for_each_entry(opp_table, &opp_tables, node) {
54 if (opp_table->np == np) {
56 * Multiple devices can point to the same OPP table and
57 * so will have same node-pointer, np.
59 * But the OPPs will be considered as shared only if the
60 * OPP table contains a "opp-shared" property.
62 if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) {
63 _get_opp_table_kref(opp_table);
64 managed_table = opp_table;
76 /* The caller must call dev_pm_opp_put() after the OPP is used */
77 static struct dev_pm_opp *_find_opp_of_np(struct opp_table *opp_table,
78 struct device_node *opp_np)
80 struct dev_pm_opp *opp;
82 lockdep_assert_held(&opp_table_lock);
84 mutex_lock(&opp_table->lock);
86 list_for_each_entry(opp, &opp_table->opp_list, node) {
87 if (opp->np == opp_np) {
89 mutex_unlock(&opp_table->lock);
94 mutex_unlock(&opp_table->lock);
99 static struct device_node *of_parse_required_opp(struct device_node *np,
102 struct device_node *required_np;
104 required_np = of_parse_phandle(np, "required-opps", index);
105 if (unlikely(!required_np)) {
106 pr_err("%s: Unable to parse required-opps: %pOF, index: %d\n",
107 __func__, np, index);
113 /* The caller must call dev_pm_opp_put_opp_table() after the table is used */
114 static struct opp_table *_find_table_of_opp_np(struct device_node *opp_np)
116 struct opp_table *opp_table;
117 struct device_node *opp_table_np;
119 lockdep_assert_held(&opp_table_lock);
121 opp_table_np = of_get_parent(opp_np);
125 /* It is safe to put the node now as all we need now is its address */
126 of_node_put(opp_table_np);
128 list_for_each_entry(opp_table, &opp_tables, node) {
129 if (opp_table_np == opp_table->np) {
130 _get_opp_table_kref(opp_table);
136 return ERR_PTR(-ENODEV);
139 /* Free resources previously acquired by _opp_table_alloc_required_tables() */
140 static void _opp_table_free_required_tables(struct opp_table *opp_table)
142 struct opp_table **required_opp_tables = opp_table->required_opp_tables;
143 struct device **genpd_virt_devs = opp_table->genpd_virt_devs;
146 if (!required_opp_tables)
149 for (i = 0; i < opp_table->required_opp_count; i++) {
150 if (IS_ERR_OR_NULL(required_opp_tables[i]))
153 dev_pm_opp_put_opp_table(required_opp_tables[i]);
156 kfree(required_opp_tables);
157 kfree(genpd_virt_devs);
159 opp_table->required_opp_count = 0;
160 opp_table->genpd_virt_devs = NULL;
161 opp_table->required_opp_tables = NULL;
165 * Populate all devices and opp tables which are part of "required-opps" list.
166 * Checking only the first OPP node should be enough.
168 static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
170 struct device_node *opp_np)
172 struct opp_table **required_opp_tables;
173 struct device **genpd_virt_devs = NULL;
174 struct device_node *required_np, *np;
177 /* Traversing the first OPP node is all we need */
178 np = of_get_next_available_child(opp_np, NULL);
180 dev_err(dev, "Empty OPP table\n");
184 count = of_count_phandle_with_args(np, "required-opps", NULL);
189 genpd_virt_devs = kcalloc(count, sizeof(*genpd_virt_devs),
191 if (!genpd_virt_devs)
195 required_opp_tables = kcalloc(count, sizeof(*required_opp_tables),
197 if (!required_opp_tables) {
198 kfree(genpd_virt_devs);
202 opp_table->genpd_virt_devs = genpd_virt_devs;
203 opp_table->required_opp_tables = required_opp_tables;
204 opp_table->required_opp_count = count;
206 for (i = 0; i < count; i++) {
207 required_np = of_parse_required_opp(np, i);
209 goto free_required_tables;
211 required_opp_tables[i] = _find_table_of_opp_np(required_np);
212 of_node_put(required_np);
214 if (IS_ERR(required_opp_tables[i]))
215 goto free_required_tables;
218 * We only support genpd's OPPs in the "required-opps" for now,
219 * as we don't know how much about other cases. Error out if the
220 * required OPP doesn't belong to a genpd.
222 if (!required_opp_tables[i]->is_genpd) {
223 dev_err(dev, "required-opp doesn't belong to genpd: %pOF\n",
225 goto free_required_tables;
231 free_required_tables:
232 _opp_table_free_required_tables(opp_table);
237 void _of_init_opp_table(struct opp_table *opp_table, struct device *dev,
240 struct device_node *np, *opp_np;
244 * Only required for backward compatibility with v1 bindings, but isn't
245 * harmful for other cases. And so we do it unconditionally.
247 np = of_node_get(dev->of_node);
251 if (!of_property_read_u32(np, "clock-latency", &val))
252 opp_table->clock_latency_ns_max = val;
253 of_property_read_u32(np, "voltage-tolerance",
254 &opp_table->voltage_tolerance_v1);
256 if (of_find_property(np, "#power-domain-cells", NULL))
257 opp_table->is_genpd = true;
259 /* Get OPP table node */
260 opp_np = _opp_of_get_opp_desc_node(np, index);
266 if (of_property_read_bool(opp_np, "opp-shared"))
267 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
269 opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE;
271 opp_table->np = opp_np;
273 _opp_table_alloc_required_tables(opp_table, dev, opp_np);
277 void _of_clear_opp_table(struct opp_table *opp_table)
279 _opp_table_free_required_tables(opp_table);
283 * Release all resources previously acquired with a call to
284 * _of_opp_alloc_required_opps().
286 void _of_opp_free_required_opps(struct opp_table *opp_table,
287 struct dev_pm_opp *opp)
289 struct dev_pm_opp **required_opps = opp->required_opps;
295 for (i = 0; i < opp_table->required_opp_count; i++) {
296 if (!required_opps[i])
299 /* Put the reference back */
300 dev_pm_opp_put(required_opps[i]);
303 kfree(required_opps);
304 opp->required_opps = NULL;
307 /* Populate all required OPPs which are part of "required-opps" list */
308 static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
309 struct dev_pm_opp *opp)
311 struct dev_pm_opp **required_opps;
312 struct opp_table *required_table;
313 struct device_node *np;
314 int i, ret, count = opp_table->required_opp_count;
319 required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL);
323 opp->required_opps = required_opps;
325 for (i = 0; i < count; i++) {
326 required_table = opp_table->required_opp_tables[i];
328 np = of_parse_required_opp(opp->np, i);
331 goto free_required_opps;
334 required_opps[i] = _find_opp_of_np(required_table, np);
337 if (!required_opps[i]) {
338 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
339 __func__, opp->np, i);
341 goto free_required_opps;
348 _of_opp_free_required_opps(opp_table, opp);
353 static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,
354 struct device_node *np)
356 unsigned int count = opp_table->supported_hw_count;
360 if (!opp_table->supported_hw) {
362 * In the case that no supported_hw has been set by the
363 * platform but there is an opp-supported-hw value set for
364 * an OPP then the OPP should not be enabled as there is
365 * no way to see if the hardware supports it.
367 if (of_find_property(np, "opp-supported-hw", NULL))
374 ret = of_property_read_u32_index(np, "opp-supported-hw", count,
377 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n",
378 __func__, count, ret);
382 /* Both of these are bitwise masks of the versions */
383 if (!(version & opp_table->supported_hw[count]))
390 static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
391 struct opp_table *opp_table)
393 u32 *microvolt, *microamp = NULL;
394 int supplies = opp_table->regulator_count, vcount, icount, ret, i, j;
395 struct property *prop = NULL;
398 /* Search for "opp-microvolt-<name>" */
399 if (opp_table->prop_name) {
400 snprintf(name, sizeof(name), "opp-microvolt-%s",
401 opp_table->prop_name);
402 prop = of_find_property(opp->np, name, NULL);
406 /* Search for "opp-microvolt" */
407 sprintf(name, "opp-microvolt");
408 prop = of_find_property(opp->np, name, NULL);
410 /* Missing property isn't a problem, but an invalid entry is */
412 if (unlikely(supplies == -1)) {
413 /* Initialize regulator_count */
414 opp_table->regulator_count = 0;
421 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n",
427 if (unlikely(supplies == -1)) {
428 /* Initialize regulator_count */
429 supplies = opp_table->regulator_count = 1;
430 } else if (unlikely(!supplies)) {
431 dev_err(dev, "%s: opp-microvolt wasn't expected\n", __func__);
435 vcount = of_property_count_u32_elems(opp->np, name);
437 dev_err(dev, "%s: Invalid %s property (%d)\n",
438 __func__, name, vcount);
442 /* There can be one or three elements per supply */
443 if (vcount != supplies && vcount != supplies * 3) {
444 dev_err(dev, "%s: Invalid number of elements in %s property (%d) with supplies (%d)\n",
445 __func__, name, vcount, supplies);
449 microvolt = kmalloc_array(vcount, sizeof(*microvolt), GFP_KERNEL);
453 ret = of_property_read_u32_array(opp->np, name, microvolt, vcount);
455 dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret);
460 /* Search for "opp-microamp-<name>" */
462 if (opp_table->prop_name) {
463 snprintf(name, sizeof(name), "opp-microamp-%s",
464 opp_table->prop_name);
465 prop = of_find_property(opp->np, name, NULL);
469 /* Search for "opp-microamp" */
470 sprintf(name, "opp-microamp");
471 prop = of_find_property(opp->np, name, NULL);
475 icount = of_property_count_u32_elems(opp->np, name);
477 dev_err(dev, "%s: Invalid %s property (%d)\n", __func__,
483 if (icount != supplies) {
484 dev_err(dev, "%s: Invalid number of elements in %s property (%d) with supplies (%d)\n",
485 __func__, name, icount, supplies);
490 microamp = kmalloc_array(icount, sizeof(*microamp), GFP_KERNEL);
496 ret = of_property_read_u32_array(opp->np, name, microamp,
499 dev_err(dev, "%s: error parsing %s: %d\n", __func__,
506 for (i = 0, j = 0; i < supplies; i++) {
507 opp->supplies[i].u_volt = microvolt[j++];
509 if (vcount == supplies) {
510 opp->supplies[i].u_volt_min = opp->supplies[i].u_volt;
511 opp->supplies[i].u_volt_max = opp->supplies[i].u_volt;
513 opp->supplies[i].u_volt_min = microvolt[j++];
514 opp->supplies[i].u_volt_max = microvolt[j++];
518 opp->supplies[i].u_amp = microamp[i];
530 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
532 * @dev: device pointer used to lookup OPP table.
534 * Free OPPs created using static entries present in DT.
536 void dev_pm_opp_of_remove_table(struct device *dev)
538 _dev_pm_opp_find_and_remove_table(dev);
540 EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
543 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
544 * @opp_table: OPP table
545 * @dev: device for which we do this operation
548 * This function adds an opp definition to the opp table and returns status. The
549 * opp can be controlled using dev_pm_opp_enable/disable functions and may be
550 * removed by dev_pm_opp_remove.
556 * Duplicate OPPs (both freq and volt are same) and opp->available
557 * OR if the OPP is not supported by hardware.
559 * Freq are same and volt are different OR
560 * Duplicate OPPs (both freq and volt are same) and !opp->available
562 * Memory allocation failure
564 * Failed parsing the OPP node
566 static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
567 struct device *dev, struct device_node *np)
569 struct dev_pm_opp *new_opp;
573 bool rate_not_available = false;
575 new_opp = _opp_allocate(opp_table);
577 return ERR_PTR(-ENOMEM);
579 ret = of_property_read_u64(np, "opp-hz", &rate);
581 /* "opp-hz" is optional for devices like power domains. */
582 if (!opp_table->is_genpd) {
583 dev_err(dev, "%s: opp-hz not found\n", __func__);
587 rate_not_available = true;
590 * Rate is defined as an unsigned long in clk API, and so
591 * casting explicitly to its type. Must be fixed once rate is 64
592 * bit guaranteed in clk API.
594 new_opp->rate = (unsigned long)rate;
597 /* Check if the OPP supports hardware's hierarchy of versions or not */
598 if (!_opp_is_supported(dev, opp_table, np)) {
599 dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate);
603 new_opp->turbo = of_property_read_bool(np, "turbo-mode");
606 new_opp->dynamic = false;
607 new_opp->available = true;
609 ret = _of_opp_alloc_required_opps(opp_table, new_opp);
613 if (!of_property_read_u32(np, "clock-latency-ns", &val))
614 new_opp->clock_latency_ns = val;
616 ret = opp_parse_supplies(new_opp, dev, opp_table);
618 goto free_required_opps;
620 if (opp_table->is_genpd)
621 new_opp->pstate = pm_genpd_opp_to_performance_state(dev, new_opp);
623 ret = _opp_add(dev, new_opp, opp_table, rate_not_available);
625 /* Don't return error for duplicate OPPs */
628 goto free_required_opps;
631 /* OPP to select on device suspend */
632 if (of_property_read_bool(np, "opp-suspend")) {
633 if (opp_table->suspend_opp) {
634 dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n",
635 __func__, opp_table->suspend_opp->rate,
638 new_opp->suspend = true;
639 opp_table->suspend_opp = new_opp;
643 if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max)
644 opp_table->clock_latency_ns_max = new_opp->clock_latency_ns;
646 pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",
647 __func__, new_opp->turbo, new_opp->rate,
648 new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min,
649 new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns);
652 * Notify the changes in the availability of the operable
653 * frequency/voltage list.
655 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp);
659 _of_opp_free_required_opps(opp_table, new_opp);
666 /* Initializes OPP tables based on new bindings */
667 static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
669 struct device_node *np;
670 int ret, count = 0, pstate_count = 0;
671 struct dev_pm_opp *opp;
673 /* OPP table is already initialized for the device */
674 if (opp_table->parsed_static_opps) {
675 kref_get(&opp_table->list_kref);
679 kref_init(&opp_table->list_kref);
681 /* We have opp-table node now, iterate over it and add OPPs */
682 for_each_available_child_of_node(opp_table->np, np) {
683 opp = _opp_add_static_v2(opp_table, dev, np);
686 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
695 /* There should be one of more OPP defined */
696 if (WARN_ON(!count)) {
701 list_for_each_entry(opp, &opp_table->opp_list, node)
702 pstate_count += !!opp->pstate;
704 /* Either all or none of the nodes shall have performance state set */
705 if (pstate_count && pstate_count != count) {
706 dev_err(dev, "Not all nodes have performance state set (%d: %d)\n",
707 count, pstate_count);
713 opp_table->genpd_performance_state = true;
715 opp_table->parsed_static_opps = true;
720 _put_opp_list_kref(opp_table);
725 /* Initializes OPP tables based on old-deprecated bindings */
726 static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
728 const struct property *prop;
732 prop = of_find_property(dev->of_node, "operating-points", NULL);
739 * Each OPP is a set of tuples consisting of frequency and
740 * voltage like <freq-kHz vol-uV>.
742 nr = prop->length / sizeof(u32);
744 dev_err(dev, "%s: Invalid OPP table\n", __func__);
748 kref_init(&opp_table->list_kref);
752 unsigned long freq = be32_to_cpup(val++) * 1000;
753 unsigned long volt = be32_to_cpup(val++);
755 ret = _opp_add_v1(opp_table, dev, freq, volt, false);
757 dev_err(dev, "%s: Failed to add OPP %ld (%d)\n",
758 __func__, freq, ret);
759 _put_opp_list_kref(opp_table);
769 * dev_pm_opp_of_add_table() - Initialize opp table from device tree
770 * @dev: device pointer used to lookup OPP table.
772 * Register the initial OPP table with the OPP library for given device.
776 * Duplicate OPPs (both freq and volt are same) and opp->available
777 * -EEXIST Freq are same and volt are different OR
778 * Duplicate OPPs (both freq and volt are same) and !opp->available
779 * -ENOMEM Memory allocation failure
780 * -ENODEV when 'operating-points' property is not found or is invalid data
782 * -ENODATA when empty 'operating-points' property is found
783 * -EINVAL when invalid entries are found in opp-v2 table
785 int dev_pm_opp_of_add_table(struct device *dev)
787 struct opp_table *opp_table;
790 opp_table = dev_pm_opp_get_opp_table_indexed(dev, 0);
795 * OPPs have two version of bindings now. Also try the old (v1)
796 * bindings for backward compatibility with older dtbs.
799 ret = _of_add_opp_table_v2(dev, opp_table);
801 ret = _of_add_opp_table_v1(dev, opp_table);
804 dev_pm_opp_put_opp_table(opp_table);
808 EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);
811 * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
812 * @dev: device pointer used to lookup OPP table.
813 * @index: Index number.
815 * Register the initial OPP table with the OPP library for given device only
816 * using the "operating-points-v2" property.
820 * Duplicate OPPs (both freq and volt are same) and opp->available
821 * -EEXIST Freq are same and volt are different OR
822 * Duplicate OPPs (both freq and volt are same) and !opp->available
823 * -ENOMEM Memory allocation failure
824 * -ENODEV when 'operating-points' property is not found or is invalid data
826 * -ENODATA when empty 'operating-points' property is found
827 * -EINVAL when invalid entries are found in opp-v2 table
829 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
831 struct opp_table *opp_table;
836 * If only one phandle is present, then the same OPP table
837 * applies for all index requests.
839 count = of_count_phandle_with_args(dev->of_node,
840 "operating-points-v2", NULL);
845 opp_table = dev_pm_opp_get_opp_table_indexed(dev, index);
849 ret = _of_add_opp_table_v2(dev, opp_table);
851 dev_pm_opp_put_opp_table(opp_table);
855 EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed);
857 /* CPU device specific helpers */
860 * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
861 * @cpumask: cpumask for which OPP table needs to be removed
863 * This removes the OPP tables for CPUs present in the @cpumask.
864 * This should be used only to remove static entries created from DT.
866 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
868 _dev_pm_opp_cpumask_remove_table(cpumask, -1);
870 EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);
873 * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
874 * @cpumask: cpumask for which OPP table needs to be added.
876 * This adds the OPP tables for CPUs present in the @cpumask.
878 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
880 struct device *cpu_dev;
883 if (WARN_ON(cpumask_empty(cpumask)))
886 for_each_cpu(cpu, cpumask) {
887 cpu_dev = get_cpu_device(cpu);
889 pr_err("%s: failed to get cpu%d device\n", __func__,
895 ret = dev_pm_opp_of_add_table(cpu_dev);
898 * OPP may get registered dynamically, don't print error
901 pr_debug("%s: couldn't find opp table for cpu:%d, %d\n",
911 /* Free all other OPPs */
912 _dev_pm_opp_cpumask_remove_table(cpumask, cpu);
916 EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);
919 * Works only for OPP v2 bindings.
921 * Returns -ENOENT if operating-points-v2 bindings aren't supported.
924 * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
925 * @cpu_dev using operating-points-v2
928 * @cpu_dev: CPU device for which we do this operation
929 * @cpumask: cpumask to update with information of sharing CPUs
931 * This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev.
933 * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
935 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
936 struct cpumask *cpumask)
938 struct device_node *np, *tmp_np, *cpu_np;
941 /* Get OPP descriptor node */
942 np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
944 dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__);
948 cpumask_set_cpu(cpu_dev->id, cpumask);
950 /* OPPs are shared ? */
951 if (!of_property_read_bool(np, "opp-shared"))
954 for_each_possible_cpu(cpu) {
955 if (cpu == cpu_dev->id)
958 cpu_np = of_cpu_device_node_get(cpu);
960 dev_err(cpu_dev, "%s: failed to get cpu%d node\n",
966 /* Get OPP descriptor node */
967 tmp_np = _opp_of_get_opp_desc_node(cpu_np, 0);
970 pr_err("%pOF: Couldn't find opp node\n", cpu_np);
975 /* CPUs are sharing opp node */
977 cpumask_set_cpu(cpu, cpumask);
986 EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
989 * of_get_required_opp_performance_state() - Search for required OPP and return its performance state.
990 * @np: Node that contains the "required-opps" property.
991 * @index: Index of the phandle to parse.
993 * Returns the performance state of the OPP pointed out by the "required-opps"
994 * property at @index in @np.
996 * Return: Zero or positive performance state on success, otherwise negative
999 int of_get_required_opp_performance_state(struct device_node *np, int index)
1001 struct dev_pm_opp *opp;
1002 struct device_node *required_np;
1003 struct opp_table *opp_table;
1004 int pstate = -EINVAL;
1006 required_np = of_parse_required_opp(np, index);
1010 opp_table = _find_table_of_opp_np(required_np);
1011 if (IS_ERR(opp_table)) {
1012 pr_err("%s: Failed to find required OPP table %pOF: %ld\n",
1013 __func__, np, PTR_ERR(opp_table));
1014 goto put_required_np;
1017 opp = _find_opp_of_np(opp_table, required_np);
1019 pstate = opp->pstate;
1020 dev_pm_opp_put(opp);
1023 dev_pm_opp_put_opp_table(opp_table);
1026 of_node_put(required_np);
1030 EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state);
1033 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
1034 * @opp: opp for which DT node has to be returned for
1036 * Return: DT node corresponding to the opp, else 0 on success.
1038 * The caller needs to put the node with of_node_put() after using it.
1040 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
1042 if (IS_ERR_OR_NULL(opp)) {
1043 pr_err("%s: Invalid parameters\n", __func__);
1047 return of_node_get(opp->np);
1049 EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);