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 dev_pm_opp *opp;
119 lockdep_assert_held(&opp_table_lock);
121 list_for_each_entry(opp_table, &opp_tables, node) {
122 opp = _find_opp_of_np(opp_table, opp_np);
125 _get_opp_table_kref(opp_table);
130 return ERR_PTR(-ENODEV);
133 /* Free resources previously acquired by _opp_table_alloc_required_tables() */
134 static void _opp_table_free_required_tables(struct opp_table *opp_table)
136 struct opp_table **required_opp_tables = opp_table->required_opp_tables;
137 struct device **genpd_virt_devs = opp_table->genpd_virt_devs;
140 if (!required_opp_tables)
143 for (i = 0; i < opp_table->required_opp_count; i++) {
144 if (IS_ERR_OR_NULL(required_opp_tables[i]))
147 dev_pm_opp_put_opp_table(required_opp_tables[i]);
150 kfree(required_opp_tables);
151 kfree(genpd_virt_devs);
153 opp_table->required_opp_count = 0;
154 opp_table->genpd_virt_devs = NULL;
155 opp_table->required_opp_tables = NULL;
159 * Populate all devices and opp tables which are part of "required-opps" list.
160 * Checking only the first OPP node should be enough.
162 static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
164 struct device_node *opp_np)
166 struct opp_table **required_opp_tables;
167 struct device **genpd_virt_devs = NULL;
168 struct device_node *required_np, *np;
171 /* Traversing the first OPP node is all we need */
172 np = of_get_next_available_child(opp_np, NULL);
174 dev_err(dev, "Empty OPP table\n");
178 count = of_count_phandle_with_args(np, "required-opps", NULL);
183 genpd_virt_devs = kcalloc(count, sizeof(*genpd_virt_devs),
185 if (!genpd_virt_devs)
189 required_opp_tables = kcalloc(count, sizeof(*required_opp_tables),
191 if (!required_opp_tables) {
192 kfree(genpd_virt_devs);
196 opp_table->genpd_virt_devs = genpd_virt_devs;
197 opp_table->required_opp_tables = required_opp_tables;
198 opp_table->required_opp_count = count;
200 for (i = 0; i < count; i++) {
201 required_np = of_parse_required_opp(np, i);
203 goto free_required_tables;
205 required_opp_tables[i] = _find_table_of_opp_np(required_np);
206 of_node_put(required_np);
208 if (IS_ERR(required_opp_tables[i]))
209 goto free_required_tables;
212 * We only support genpd's OPPs in the "required-opps" for now,
213 * as we don't know how much about other cases. Error out if the
214 * required OPP doesn't belong to a genpd.
216 if (!required_opp_tables[i]->is_genpd) {
217 dev_err(dev, "required-opp doesn't belong to genpd: %pOF\n",
219 goto free_required_tables;
225 free_required_tables:
226 _opp_table_free_required_tables(opp_table);
231 void _of_init_opp_table(struct opp_table *opp_table, struct device *dev,
234 struct device_node *np, *opp_np;
238 * Only required for backward compatibility with v1 bindings, but isn't
239 * harmful for other cases. And so we do it unconditionally.
241 np = of_node_get(dev->of_node);
245 if (!of_property_read_u32(np, "clock-latency", &val))
246 opp_table->clock_latency_ns_max = val;
247 of_property_read_u32(np, "voltage-tolerance",
248 &opp_table->voltage_tolerance_v1);
250 if (of_find_property(np, "#power-domain-cells", NULL))
251 opp_table->is_genpd = true;
253 /* Get OPP table node */
254 opp_np = _opp_of_get_opp_desc_node(np, index);
260 if (of_property_read_bool(opp_np, "opp-shared"))
261 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
263 opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE;
265 opp_table->np = opp_np;
267 _opp_table_alloc_required_tables(opp_table, dev, opp_np);
271 void _of_clear_opp_table(struct opp_table *opp_table)
273 _opp_table_free_required_tables(opp_table);
277 * Release all resources previously acquired with a call to
278 * _of_opp_alloc_required_opps().
280 void _of_opp_free_required_opps(struct opp_table *opp_table,
281 struct dev_pm_opp *opp)
283 struct dev_pm_opp **required_opps = opp->required_opps;
289 for (i = 0; i < opp_table->required_opp_count; i++) {
290 if (!required_opps[i])
293 /* Put the reference back */
294 dev_pm_opp_put(required_opps[i]);
297 kfree(required_opps);
298 opp->required_opps = NULL;
301 /* Populate all required OPPs which are part of "required-opps" list */
302 static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
303 struct dev_pm_opp *opp)
305 struct dev_pm_opp **required_opps;
306 struct opp_table *required_table;
307 struct device_node *np;
308 int i, ret, count = opp_table->required_opp_count;
313 required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL);
317 opp->required_opps = required_opps;
319 for (i = 0; i < count; i++) {
320 required_table = opp_table->required_opp_tables[i];
322 np = of_parse_required_opp(opp->np, i);
325 goto free_required_opps;
328 required_opps[i] = _find_opp_of_np(required_table, np);
331 if (!required_opps[i]) {
332 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
333 __func__, opp->np, i);
335 goto free_required_opps;
342 _of_opp_free_required_opps(opp_table, opp);
347 static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,
348 struct device_node *np)
350 unsigned int count = opp_table->supported_hw_count;
354 if (!opp_table->supported_hw) {
356 * In the case that no supported_hw has been set by the
357 * platform but there is an opp-supported-hw value set for
358 * an OPP then the OPP should not be enabled as there is
359 * no way to see if the hardware supports it.
361 if (of_find_property(np, "opp-supported-hw", NULL))
368 ret = of_property_read_u32_index(np, "opp-supported-hw", count,
371 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n",
372 __func__, count, ret);
376 /* Both of these are bitwise masks of the versions */
377 if (!(version & opp_table->supported_hw[count]))
384 static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
385 struct opp_table *opp_table)
387 u32 *microvolt, *microamp = NULL;
388 int supplies, vcount, icount, ret, i, j;
389 struct property *prop = NULL;
392 supplies = opp_table->regulator_count ? opp_table->regulator_count : 1;
394 /* Search for "opp-microvolt-<name>" */
395 if (opp_table->prop_name) {
396 snprintf(name, sizeof(name), "opp-microvolt-%s",
397 opp_table->prop_name);
398 prop = of_find_property(opp->np, name, NULL);
402 /* Search for "opp-microvolt" */
403 sprintf(name, "opp-microvolt");
404 prop = of_find_property(opp->np, name, NULL);
406 /* Missing property isn't a problem, but an invalid entry is */
408 if (!opp_table->regulator_count)
411 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n",
417 vcount = of_property_count_u32_elems(opp->np, name);
419 dev_err(dev, "%s: Invalid %s property (%d)\n",
420 __func__, name, vcount);
424 /* There can be one or three elements per supply */
425 if (vcount != supplies && vcount != supplies * 3) {
426 dev_err(dev, "%s: Invalid number of elements in %s property (%d) with supplies (%d)\n",
427 __func__, name, vcount, supplies);
431 microvolt = kmalloc_array(vcount, sizeof(*microvolt), GFP_KERNEL);
435 ret = of_property_read_u32_array(opp->np, name, microvolt, vcount);
437 dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret);
442 /* Search for "opp-microamp-<name>" */
444 if (opp_table->prop_name) {
445 snprintf(name, sizeof(name), "opp-microamp-%s",
446 opp_table->prop_name);
447 prop = of_find_property(opp->np, name, NULL);
451 /* Search for "opp-microamp" */
452 sprintf(name, "opp-microamp");
453 prop = of_find_property(opp->np, name, NULL);
457 icount = of_property_count_u32_elems(opp->np, name);
459 dev_err(dev, "%s: Invalid %s property (%d)\n", __func__,
465 if (icount != supplies) {
466 dev_err(dev, "%s: Invalid number of elements in %s property (%d) with supplies (%d)\n",
467 __func__, name, icount, supplies);
472 microamp = kmalloc_array(icount, sizeof(*microamp), GFP_KERNEL);
478 ret = of_property_read_u32_array(opp->np, name, microamp,
481 dev_err(dev, "%s: error parsing %s: %d\n", __func__,
488 for (i = 0, j = 0; i < supplies; i++) {
489 opp->supplies[i].u_volt = microvolt[j++];
491 if (vcount == supplies) {
492 opp->supplies[i].u_volt_min = opp->supplies[i].u_volt;
493 opp->supplies[i].u_volt_max = opp->supplies[i].u_volt;
495 opp->supplies[i].u_volt_min = microvolt[j++];
496 opp->supplies[i].u_volt_max = microvolt[j++];
500 opp->supplies[i].u_amp = microamp[i];
512 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
514 * @dev: device pointer used to lookup OPP table.
516 * Free OPPs created using static entries present in DT.
518 void dev_pm_opp_of_remove_table(struct device *dev)
520 _dev_pm_opp_find_and_remove_table(dev);
522 EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
525 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
526 * @opp_table: OPP table
527 * @dev: device for which we do this operation
530 * This function adds an opp definition to the opp table and returns status. The
531 * opp can be controlled using dev_pm_opp_enable/disable functions and may be
532 * removed by dev_pm_opp_remove.
538 * Duplicate OPPs (both freq and volt are same) and opp->available
539 * OR if the OPP is not supported by hardware.
541 * Freq are same and volt are different OR
542 * Duplicate OPPs (both freq and volt are same) and !opp->available
544 * Memory allocation failure
546 * Failed parsing the OPP node
548 static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
549 struct device *dev, struct device_node *np)
551 struct dev_pm_opp *new_opp;
555 bool rate_not_available = false;
557 new_opp = _opp_allocate(opp_table);
559 return ERR_PTR(-ENOMEM);
561 ret = of_property_read_u64(np, "opp-hz", &rate);
563 /* "opp-hz" is optional for devices like power domains. */
564 if (!opp_table->is_genpd) {
565 dev_err(dev, "%s: opp-hz not found\n", __func__);
569 rate_not_available = true;
572 * Rate is defined as an unsigned long in clk API, and so
573 * casting explicitly to its type. Must be fixed once rate is 64
574 * bit guaranteed in clk API.
576 new_opp->rate = (unsigned long)rate;
579 /* Check if the OPP supports hardware's hierarchy of versions or not */
580 if (!_opp_is_supported(dev, opp_table, np)) {
581 dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate);
585 new_opp->turbo = of_property_read_bool(np, "turbo-mode");
588 new_opp->dynamic = false;
589 new_opp->available = true;
591 ret = _of_opp_alloc_required_opps(opp_table, new_opp);
595 if (!of_property_read_u32(np, "clock-latency-ns", &val))
596 new_opp->clock_latency_ns = val;
598 new_opp->pstate = of_genpd_opp_to_performance_state(dev, np);
600 ret = opp_parse_supplies(new_opp, dev, opp_table);
602 goto free_required_opps;
604 ret = _opp_add(dev, new_opp, opp_table, rate_not_available);
606 /* Don't return error for duplicate OPPs */
609 goto free_required_opps;
612 /* OPP to select on device suspend */
613 if (of_property_read_bool(np, "opp-suspend")) {
614 if (opp_table->suspend_opp) {
615 dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n",
616 __func__, opp_table->suspend_opp->rate,
619 new_opp->suspend = true;
620 opp_table->suspend_opp = new_opp;
624 if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max)
625 opp_table->clock_latency_ns_max = new_opp->clock_latency_ns;
627 pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",
628 __func__, new_opp->turbo, new_opp->rate,
629 new_opp->supplies[0].u_volt, new_opp->supplies[0].u_volt_min,
630 new_opp->supplies[0].u_volt_max, new_opp->clock_latency_ns);
633 * Notify the changes in the availability of the operable
634 * frequency/voltage list.
636 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp);
640 _of_opp_free_required_opps(opp_table, new_opp);
647 /* Initializes OPP tables based on new bindings */
648 static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
650 struct device_node *np;
651 int ret, count = 0, pstate_count = 0;
652 struct dev_pm_opp *opp;
654 /* OPP table is already initialized for the device */
655 if (opp_table->parsed_static_opps) {
656 kref_get(&opp_table->list_kref);
660 kref_init(&opp_table->list_kref);
662 /* We have opp-table node now, iterate over it and add OPPs */
663 for_each_available_child_of_node(opp_table->np, np) {
664 opp = _opp_add_static_v2(opp_table, dev, np);
667 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
676 /* There should be one of more OPP defined */
677 if (WARN_ON(!count)) {
682 list_for_each_entry(opp, &opp_table->opp_list, node)
683 pstate_count += !!opp->pstate;
685 /* Either all or none of the nodes shall have performance state set */
686 if (pstate_count && pstate_count != count) {
687 dev_err(dev, "Not all nodes have performance state set (%d: %d)\n",
688 count, pstate_count);
694 opp_table->genpd_performance_state = true;
696 opp_table->parsed_static_opps = true;
701 _put_opp_list_kref(opp_table);
706 /* Initializes OPP tables based on old-deprecated bindings */
707 static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
709 const struct property *prop;
713 prop = of_find_property(dev->of_node, "operating-points", NULL);
720 * Each OPP is a set of tuples consisting of frequency and
721 * voltage like <freq-kHz vol-uV>.
723 nr = prop->length / sizeof(u32);
725 dev_err(dev, "%s: Invalid OPP table\n", __func__);
729 kref_init(&opp_table->list_kref);
733 unsigned long freq = be32_to_cpup(val++) * 1000;
734 unsigned long volt = be32_to_cpup(val++);
736 ret = _opp_add_v1(opp_table, dev, freq, volt, false);
738 dev_err(dev, "%s: Failed to add OPP %ld (%d)\n",
739 __func__, freq, ret);
740 _put_opp_list_kref(opp_table);
750 * dev_pm_opp_of_add_table() - Initialize opp table from device tree
751 * @dev: device pointer used to lookup OPP table.
753 * Register the initial OPP table with the OPP library for given device.
757 * Duplicate OPPs (both freq and volt are same) and opp->available
758 * -EEXIST Freq are same and volt are different OR
759 * Duplicate OPPs (both freq and volt are same) and !opp->available
760 * -ENOMEM Memory allocation failure
761 * -ENODEV when 'operating-points' property is not found or is invalid data
763 * -ENODATA when empty 'operating-points' property is found
764 * -EINVAL when invalid entries are found in opp-v2 table
766 int dev_pm_opp_of_add_table(struct device *dev)
768 struct opp_table *opp_table;
771 opp_table = dev_pm_opp_get_opp_table_indexed(dev, 0);
776 * OPPs have two version of bindings now. Also try the old (v1)
777 * bindings for backward compatibility with older dtbs.
780 ret = _of_add_opp_table_v2(dev, opp_table);
782 ret = _of_add_opp_table_v1(dev, opp_table);
785 dev_pm_opp_put_opp_table(opp_table);
789 EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);
792 * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
793 * @dev: device pointer used to lookup OPP table.
794 * @index: Index number.
796 * Register the initial OPP table with the OPP library for given device only
797 * using the "operating-points-v2" property.
801 * Duplicate OPPs (both freq and volt are same) and opp->available
802 * -EEXIST Freq are same and volt are different OR
803 * Duplicate OPPs (both freq and volt are same) and !opp->available
804 * -ENOMEM Memory allocation failure
805 * -ENODEV when 'operating-points' property is not found or is invalid data
807 * -ENODATA when empty 'operating-points' property is found
808 * -EINVAL when invalid entries are found in opp-v2 table
810 int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
812 struct opp_table *opp_table;
817 * If only one phandle is present, then the same OPP table
818 * applies for all index requests.
820 count = of_count_phandle_with_args(dev->of_node,
821 "operating-points-v2", NULL);
828 opp_table = dev_pm_opp_get_opp_table_indexed(dev, index);
832 ret = _of_add_opp_table_v2(dev, opp_table);
834 dev_pm_opp_put_opp_table(opp_table);
838 EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed);
840 /* CPU device specific helpers */
843 * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
844 * @cpumask: cpumask for which OPP table needs to be removed
846 * This removes the OPP tables for CPUs present in the @cpumask.
847 * This should be used only to remove static entries created from DT.
849 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
851 _dev_pm_opp_cpumask_remove_table(cpumask, -1);
853 EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);
856 * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
857 * @cpumask: cpumask for which OPP table needs to be added.
859 * This adds the OPP tables for CPUs present in the @cpumask.
861 int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
863 struct device *cpu_dev;
866 if (WARN_ON(cpumask_empty(cpumask)))
869 for_each_cpu(cpu, cpumask) {
870 cpu_dev = get_cpu_device(cpu);
872 pr_err("%s: failed to get cpu%d device\n", __func__,
878 ret = dev_pm_opp_of_add_table(cpu_dev);
881 * OPP may get registered dynamically, don't print error
884 pr_debug("%s: couldn't find opp table for cpu:%d, %d\n",
894 /* Free all other OPPs */
895 _dev_pm_opp_cpumask_remove_table(cpumask, cpu);
899 EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);
902 * Works only for OPP v2 bindings.
904 * Returns -ENOENT if operating-points-v2 bindings aren't supported.
907 * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
908 * @cpu_dev using operating-points-v2
911 * @cpu_dev: CPU device for which we do this operation
912 * @cpumask: cpumask to update with information of sharing CPUs
914 * This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev.
916 * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
918 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
919 struct cpumask *cpumask)
921 struct device_node *np, *tmp_np, *cpu_np;
924 /* Get OPP descriptor node */
925 np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
927 dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__);
931 cpumask_set_cpu(cpu_dev->id, cpumask);
933 /* OPPs are shared ? */
934 if (!of_property_read_bool(np, "opp-shared"))
937 for_each_possible_cpu(cpu) {
938 if (cpu == cpu_dev->id)
941 cpu_np = of_cpu_device_node_get(cpu);
943 dev_err(cpu_dev, "%s: failed to get cpu%d node\n",
949 /* Get OPP descriptor node */
950 tmp_np = _opp_of_get_opp_desc_node(cpu_np, 0);
953 pr_err("%pOF: Couldn't find opp node\n", cpu_np);
958 /* CPUs are sharing opp node */
960 cpumask_set_cpu(cpu, cpumask);
969 EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
972 * of_dev_pm_opp_find_required_opp() - Search for required OPP.
973 * @dev: The device whose OPP node is referenced by the 'np' DT node.
974 * @np: Node that contains the "required-opps" property.
976 * Returns the OPP of the device 'dev', whose phandle is present in the "np"
977 * node. Although the "required-opps" property supports having multiple
978 * phandles, this helper routine only parses the very first phandle in the list.
980 * Return: Matching opp, else returns ERR_PTR in case of error and should be
981 * handled using IS_ERR.
983 * The callers are required to call dev_pm_opp_put() for the returned OPP after
986 struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev,
987 struct device_node *np)
989 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV);
990 struct device_node *required_np;
991 struct opp_table *opp_table;
993 opp_table = _find_opp_table(dev);
994 if (IS_ERR(opp_table))
995 return ERR_CAST(opp_table);
997 required_np = of_parse_phandle(np, "required-opps", 0);
998 if (unlikely(!required_np)) {
999 dev_err(dev, "Unable to parse required-opps\n");
1003 mutex_lock(&opp_table->lock);
1005 list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
1006 if (temp_opp->available && temp_opp->np == required_np) {
1009 /* Increment the reference count of OPP */
1010 dev_pm_opp_get(opp);
1015 mutex_unlock(&opp_table->lock);
1017 of_node_put(required_np);
1019 dev_pm_opp_put_opp_table(opp_table);
1023 EXPORT_SYMBOL_GPL(of_dev_pm_opp_find_required_opp);
1026 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
1027 * @opp: opp for which DT node has to be returned for
1029 * Return: DT node corresponding to the opp, else 0 on success.
1031 * The caller needs to put the node with of_node_put() after using it.
1033 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
1035 if (IS_ERR_OR_NULL(opp)) {
1036 pr_err("%s: Invalid parameters\n", __func__);
1040 return of_node_get(opp->np);
1042 EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);