blob: 71aef28953c23fd991b0cdfcdb31a6acfeb0c671 [file] [log] [blame]
Viresh Kumarf47b72a2016-05-05 16:20:33 +05301/*
2 * Generic OPP OF helpers
3 *
4 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
5 * Nishanth Menon
6 * Romit Dasgupta
7 * Kevin Hilman
8 *
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.
12 */
13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
16#include <linux/cpu.h>
17#include <linux/errno.h>
18#include <linux/device.h>
Sudeep Holla98679992017-10-12 11:32:23 +010019#include <linux/of_device.h>
Viresh Kumar3ba98322016-11-18 15:47:46 +053020#include <linux/pm_domain.h>
Viresh Kumardfbe4672016-12-01 16:28:19 +053021#include <linux/slab.h>
Viresh Kumarf47b72a2016-05-05 16:20:33 +053022#include <linux/export.h>
23
24#include "opp.h"
25
Viresh Kumarf06ed902018-06-14 12:04:43 +053026/*
27 * Returns opp descriptor node for a device node, caller must
28 * do of_node_put().
29 */
30static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np,
31 int index)
32{
33 /* "operating-points-v2" can be an array for power domain providers */
34 return of_parse_phandle(np, "operating-points-v2", index);
35}
36
37/* Returns opp descriptor node for a device, caller must do of_node_put() */
38struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
39{
40 return _opp_of_get_opp_desc_node(dev->of_node, 0);
41}
42EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node);
43
Viresh Kumar283d55e2018-09-07 09:01:54 +053044struct opp_table *_managed_opp(struct device *dev, int index)
Viresh Kumarf47b72a2016-05-05 16:20:33 +053045{
Viresh Kumarb83c1892017-01-23 10:11:45 +053046 struct opp_table *opp_table, *managed_table = NULL;
Viresh Kumar283d55e2018-09-07 09:01:54 +053047 struct device_node *np;
Viresh Kumarb83c1892017-01-23 10:11:45 +053048
Viresh Kumar283d55e2018-09-07 09:01:54 +053049 np = _opp_of_get_opp_desc_node(dev->of_node, index);
50 if (!np)
51 return NULL;
Viresh Kumarf47b72a2016-05-05 16:20:33 +053052
Viresh Kumar052c6f12017-01-23 10:11:49 +053053 list_for_each_entry(opp_table, &opp_tables, node) {
Viresh Kumarf47b72a2016-05-05 16:20:33 +053054 if (opp_table->np == np) {
55 /*
56 * Multiple devices can point to the same OPP table and
57 * so will have same node-pointer, np.
58 *
59 * But the OPPs will be considered as shared only if the
60 * OPP table contains a "opp-shared" property.
61 */
Viresh Kumarb83c1892017-01-23 10:11:45 +053062 if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) {
63 _get_opp_table_kref(opp_table);
64 managed_table = opp_table;
65 }
Viresh Kumar79ee2e82016-06-16 19:03:11 +053066
Viresh Kumarb83c1892017-01-23 10:11:45 +053067 break;
Viresh Kumarf47b72a2016-05-05 16:20:33 +053068 }
69 }
70
Viresh Kumar283d55e2018-09-07 09:01:54 +053071 of_node_put(np);
Viresh Kumarb83c1892017-01-23 10:11:45 +053072
73 return managed_table;
Viresh Kumarf47b72a2016-05-05 16:20:33 +053074}
75
Viresh Kumar5d6d1062018-06-07 14:50:43 +053076/* The caller must call dev_pm_opp_put() after the OPP is used */
77static struct dev_pm_opp *_find_opp_of_np(struct opp_table *opp_table,
78 struct device_node *opp_np)
79{
80 struct dev_pm_opp *opp;
81
82 lockdep_assert_held(&opp_table_lock);
83
84 mutex_lock(&opp_table->lock);
85
86 list_for_each_entry(opp, &opp_table->opp_list, node) {
87 if (opp->np == opp_np) {
88 dev_pm_opp_get(opp);
89 mutex_unlock(&opp_table->lock);
90 return opp;
91 }
92 }
93
94 mutex_unlock(&opp_table->lock);
95
96 return NULL;
97}
98
99static struct device_node *of_parse_required_opp(struct device_node *np,
100 int index)
101{
102 struct device_node *required_np;
103
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);
108 }
109
110 return required_np;
111}
112
113/* The caller must call dev_pm_opp_put_opp_table() after the table is used */
114static struct opp_table *_find_table_of_opp_np(struct device_node *opp_np)
115{
116 struct opp_table *opp_table;
117 struct dev_pm_opp *opp;
118
119 lockdep_assert_held(&opp_table_lock);
120
121 list_for_each_entry(opp_table, &opp_tables, node) {
122 opp = _find_opp_of_np(opp_table, opp_np);
123 if (opp) {
124 dev_pm_opp_put(opp);
125 _get_opp_table_kref(opp_table);
126 return opp_table;
127 }
128 }
129
130 return ERR_PTR(-ENODEV);
131}
132
133/* Free resources previously acquired by _opp_table_alloc_required_tables() */
134static void _opp_table_free_required_tables(struct opp_table *opp_table)
135{
136 struct opp_table **required_opp_tables = opp_table->required_opp_tables;
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530137 struct device **genpd_virt_devs = opp_table->genpd_virt_devs;
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530138 int i;
139
140 if (!required_opp_tables)
141 return;
142
143 for (i = 0; i < opp_table->required_opp_count; i++) {
144 if (IS_ERR_OR_NULL(required_opp_tables[i]))
145 break;
146
147 dev_pm_opp_put_opp_table(required_opp_tables[i]);
148 }
149
150 kfree(required_opp_tables);
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530151 kfree(genpd_virt_devs);
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530152
153 opp_table->required_opp_count = 0;
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530154 opp_table->genpd_virt_devs = NULL;
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530155 opp_table->required_opp_tables = NULL;
156}
157
158/*
159 * Populate all devices and opp tables which are part of "required-opps" list.
160 * Checking only the first OPP node should be enough.
161 */
162static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
163 struct device *dev,
164 struct device_node *opp_np)
165{
166 struct opp_table **required_opp_tables;
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530167 struct device **genpd_virt_devs = NULL;
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530168 struct device_node *required_np, *np;
169 int count, i;
170
171 /* Traversing the first OPP node is all we need */
172 np = of_get_next_available_child(opp_np, NULL);
173 if (!np) {
174 dev_err(dev, "Empty OPP table\n");
175 return;
176 }
177
178 count = of_count_phandle_with_args(np, "required-opps", NULL);
179 if (!count)
180 goto put_np;
181
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530182 if (count > 1) {
183 genpd_virt_devs = kcalloc(count, sizeof(*genpd_virt_devs),
184 GFP_KERNEL);
185 if (!genpd_virt_devs)
186 goto put_np;
187 }
188
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530189 required_opp_tables = kcalloc(count, sizeof(*required_opp_tables),
190 GFP_KERNEL);
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530191 if (!required_opp_tables) {
192 kfree(genpd_virt_devs);
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530193 goto put_np;
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530194 }
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530195
Viresh Kumar4f018bc2018-06-26 16:29:34 +0530196 opp_table->genpd_virt_devs = genpd_virt_devs;
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530197 opp_table->required_opp_tables = required_opp_tables;
198 opp_table->required_opp_count = count;
199
200 for (i = 0; i < count; i++) {
201 required_np = of_parse_required_opp(np, i);
202 if (!required_np)
203 goto free_required_tables;
204
205 required_opp_tables[i] = _find_table_of_opp_np(required_np);
206 of_node_put(required_np);
207
208 if (IS_ERR(required_opp_tables[i]))
209 goto free_required_tables;
210
211 /*
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.
215 */
216 if (!required_opp_tables[i]->is_genpd) {
217 dev_err(dev, "required-opp doesn't belong to genpd: %pOF\n",
218 required_np);
219 goto free_required_tables;
220 }
221 }
222
223 goto put_np;
224
225free_required_tables:
226 _opp_table_free_required_tables(opp_table);
227put_np:
228 of_node_put(np);
229}
230
Viresh Kumareb7c87432018-09-05 16:17:14 +0530231void _of_init_opp_table(struct opp_table *opp_table, struct device *dev,
232 int index)
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530233{
Viresh Kumarf06ed902018-06-14 12:04:43 +0530234 struct device_node *np, *opp_np;
235 u32 val;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530236
237 /*
238 * Only required for backward compatibility with v1 bindings, but isn't
239 * harmful for other cases. And so we do it unconditionally.
240 */
241 np = of_node_get(dev->of_node);
Viresh Kumarf06ed902018-06-14 12:04:43 +0530242 if (!np)
243 return;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530244
Viresh Kumarf06ed902018-06-14 12:04:43 +0530245 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);
249
Viresh Kumar61d8e7c2018-06-13 16:00:11 +0530250 if (of_find_property(np, "#power-domain-cells", NULL))
251 opp_table->is_genpd = true;
252
Viresh Kumarf06ed902018-06-14 12:04:43 +0530253 /* Get OPP table node */
254 opp_np = _opp_of_get_opp_desc_node(np, index);
255 of_node_put(np);
256
257 if (!opp_np)
258 return;
259
260 if (of_property_read_bool(opp_np, "opp-shared"))
261 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
262 else
263 opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE;
264
265 opp_table->np = opp_np;
266
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530267 _opp_table_alloc_required_tables(opp_table, dev, opp_np);
Viresh Kumarf06ed902018-06-14 12:04:43 +0530268 of_node_put(opp_np);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530269}
270
Viresh Kumar5d6d1062018-06-07 14:50:43 +0530271void _of_clear_opp_table(struct opp_table *opp_table)
272{
273 _opp_table_free_required_tables(opp_table);
274}
275
Viresh Kumarda544b62018-06-07 14:50:43 +0530276/*
277 * Release all resources previously acquired with a call to
278 * _of_opp_alloc_required_opps().
279 */
280void _of_opp_free_required_opps(struct opp_table *opp_table,
281 struct dev_pm_opp *opp)
282{
283 struct dev_pm_opp **required_opps = opp->required_opps;
284 int i;
285
286 if (!required_opps)
287 return;
288
289 for (i = 0; i < opp_table->required_opp_count; i++) {
290 if (!required_opps[i])
291 break;
292
293 /* Put the reference back */
294 dev_pm_opp_put(required_opps[i]);
295 }
296
297 kfree(required_opps);
298 opp->required_opps = NULL;
299}
300
301/* Populate all required OPPs which are part of "required-opps" list */
302static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
303 struct dev_pm_opp *opp)
304{
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;
309
310 if (!count)
311 return 0;
312
313 required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL);
314 if (!required_opps)
315 return -ENOMEM;
316
317 opp->required_opps = required_opps;
318
319 for (i = 0; i < count; i++) {
320 required_table = opp_table->required_opp_tables[i];
321
322 np = of_parse_required_opp(opp->np, i);
323 if (unlikely(!np)) {
324 ret = -ENODEV;
325 goto free_required_opps;
326 }
327
328 required_opps[i] = _find_opp_of_np(required_table, np);
329 of_node_put(np);
330
331 if (!required_opps[i]) {
332 pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
333 __func__, opp->np, i);
334 ret = -ENODEV;
335 goto free_required_opps;
336 }
337 }
338
339 return 0;
340
341free_required_opps:
342 _of_opp_free_required_opps(opp_table, opp);
343
344 return ret;
345}
346
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530347static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,
348 struct device_node *np)
349{
350 unsigned int count = opp_table->supported_hw_count;
351 u32 version;
352 int ret;
353
Dave Gerlacha4ee4542016-09-23 15:07:47 -0500354 if (!opp_table->supported_hw) {
355 /*
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.
360 */
361 if (of_find_property(np, "opp-supported-hw", NULL))
362 return false;
363 else
364 return true;
365 }
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530366
367 while (count--) {
368 ret = of_property_read_u32_index(np, "opp-supported-hw", count,
369 &version);
370 if (ret) {
371 dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n",
372 __func__, count, ret);
373 return false;
374 }
375
376 /* Both of these are bitwise masks of the versions */
377 if (!(version & opp_table->supported_hw[count]))
378 return false;
379 }
380
381 return true;
382}
383
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530384static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
385 struct opp_table *opp_table)
386{
Viresh Kumardfbe4672016-12-01 16:28:19 +0530387 u32 *microvolt, *microamp = NULL;
388 int supplies, vcount, icount, ret, i, j;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530389 struct property *prop = NULL;
390 char name[NAME_MAX];
391
Viresh Kumardfbe4672016-12-01 16:28:19 +0530392 supplies = opp_table->regulator_count ? opp_table->regulator_count : 1;
393
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530394 /* 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);
399 }
400
401 if (!prop) {
402 /* Search for "opp-microvolt" */
403 sprintf(name, "opp-microvolt");
404 prop = of_find_property(opp->np, name, NULL);
405
406 /* Missing property isn't a problem, but an invalid entry is */
Viresh Kumar688a48b2017-05-23 09:32:12 +0530407 if (!prop) {
408 if (!opp_table->regulator_count)
409 return 0;
410
411 dev_err(dev, "%s: opp-microvolt missing although OPP managing regulators\n",
412 __func__);
413 return -EINVAL;
414 }
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530415 }
416
Viresh Kumardfbe4672016-12-01 16:28:19 +0530417 vcount = of_property_count_u32_elems(opp->np, name);
418 if (vcount < 0) {
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530419 dev_err(dev, "%s: Invalid %s property (%d)\n",
Viresh Kumardfbe4672016-12-01 16:28:19 +0530420 __func__, name, vcount);
421 return vcount;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530422 }
423
Viresh Kumardfbe4672016-12-01 16:28:19 +0530424 /* 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);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530428 return -EINVAL;
429 }
430
Viresh Kumardfbe4672016-12-01 16:28:19 +0530431 microvolt = kmalloc_array(vcount, sizeof(*microvolt), GFP_KERNEL);
432 if (!microvolt)
433 return -ENOMEM;
434
435 ret = of_property_read_u32_array(opp->np, name, microvolt, vcount);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530436 if (ret) {
437 dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret);
Viresh Kumardfbe4672016-12-01 16:28:19 +0530438 ret = -EINVAL;
439 goto free_microvolt;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530440 }
441
442 /* Search for "opp-microamp-<name>" */
443 prop = NULL;
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);
448 }
449
450 if (!prop) {
451 /* Search for "opp-microamp" */
452 sprintf(name, "opp-microamp");
453 prop = of_find_property(opp->np, name, NULL);
454 }
455
Viresh Kumardfbe4672016-12-01 16:28:19 +0530456 if (prop) {
457 icount = of_property_count_u32_elems(opp->np, name);
458 if (icount < 0) {
459 dev_err(dev, "%s: Invalid %s property (%d)\n", __func__,
460 name, icount);
461 ret = icount;
462 goto free_microvolt;
463 }
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530464
Viresh Kumardfbe4672016-12-01 16:28:19 +0530465 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);
468 ret = -EINVAL;
469 goto free_microvolt;
470 }
471
472 microamp = kmalloc_array(icount, sizeof(*microamp), GFP_KERNEL);
473 if (!microamp) {
474 ret = -EINVAL;
475 goto free_microvolt;
476 }
477
478 ret = of_property_read_u32_array(opp->np, name, microamp,
479 icount);
480 if (ret) {
481 dev_err(dev, "%s: error parsing %s: %d\n", __func__,
482 name, ret);
483 ret = -EINVAL;
484 goto free_microamp;
485 }
486 }
487
488 for (i = 0, j = 0; i < supplies; i++) {
489 opp->supplies[i].u_volt = microvolt[j++];
490
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;
494 } else {
495 opp->supplies[i].u_volt_min = microvolt[j++];
496 opp->supplies[i].u_volt_max = microvolt[j++];
497 }
498
499 if (microamp)
500 opp->supplies[i].u_amp = microamp[i];
501 }
502
503free_microamp:
504 kfree(microamp);
505free_microvolt:
506 kfree(microvolt);
507
508 return ret;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530509}
510
511/**
512 * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT
513 * entries
514 * @dev: device pointer used to lookup OPP table.
515 *
516 * Free OPPs created using static entries present in DT.
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530517 */
518void dev_pm_opp_of_remove_table(struct device *dev)
519{
Viresh Kumar2a4eb732018-09-13 13:14:36 +0530520 _dev_pm_opp_find_and_remove_table(dev);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530521}
522EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
523
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530524/**
525 * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
Viresh Kumar8cd2f6e2017-01-02 14:41:01 +0530526 * @opp_table: OPP table
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530527 * @dev: device for which we do this operation
528 * @np: device node
529 *
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.
533 *
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530534 * Return:
Dave Gerlachdeac8702018-10-03 16:13:15 +0530535 * Valid OPP pointer:
536 * On success
537 * NULL:
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530538 * Duplicate OPPs (both freq and volt are same) and opp->available
Dave Gerlachdeac8702018-10-03 16:13:15 +0530539 * OR if the OPP is not supported by hardware.
540 * ERR_PTR(-EEXIST):
541 * Freq are same and volt are different OR
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530542 * Duplicate OPPs (both freq and volt are same) and !opp->available
Dave Gerlachdeac8702018-10-03 16:13:15 +0530543 * ERR_PTR(-ENOMEM):
544 * Memory allocation failure
545 * ERR_PTR(-EINVAL):
546 * Failed parsing the OPP node
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530547 */
Dave Gerlachdeac8702018-10-03 16:13:15 +0530548static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
549 struct device *dev, struct device_node *np)
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530550{
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530551 struct dev_pm_opp *new_opp;
Dan Carpenter6a89e012018-05-16 12:52:41 +0300552 u64 rate = 0;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530553 u32 val;
554 int ret;
Viresh Kumara1e8c132018-04-06 14:35:45 +0530555 bool rate_not_available = false;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530556
Viresh Kumar8cd2f6e2017-01-02 14:41:01 +0530557 new_opp = _opp_allocate(opp_table);
558 if (!new_opp)
Dave Gerlachdeac8702018-10-03 16:13:15 +0530559 return ERR_PTR(-ENOMEM);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530560
561 ret = of_property_read_u64(np, "opp-hz", &rate);
562 if (ret < 0) {
Viresh Kumara1e8c132018-04-06 14:35:45 +0530563 /* "opp-hz" is optional for devices like power domains. */
Viresh Kumar61d8e7c2018-06-13 16:00:11 +0530564 if (!opp_table->is_genpd) {
Viresh Kumara1e8c132018-04-06 14:35:45 +0530565 dev_err(dev, "%s: opp-hz not found\n", __func__);
566 goto free_opp;
567 }
568
569 rate_not_available = true;
570 } else {
571 /*
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.
575 */
576 new_opp->rate = (unsigned long)rate;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530577 }
578
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);
582 goto free_opp;
583 }
584
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530585 new_opp->turbo = of_property_read_bool(np, "turbo-mode");
586
587 new_opp->np = np;
588 new_opp->dynamic = false;
589 new_opp->available = true;
590
Viresh Kumarda544b62018-06-07 14:50:43 +0530591 ret = _of_opp_alloc_required_opps(opp_table, new_opp);
592 if (ret)
593 goto free_opp;
594
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530595 if (!of_property_read_u32(np, "clock-latency-ns", &val))
596 new_opp->clock_latency_ns = val;
597
Viresh Kumar3ba98322016-11-18 15:47:46 +0530598 new_opp->pstate = of_genpd_opp_to_performance_state(dev, np);
599
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530600 ret = opp_parse_supplies(new_opp, dev, opp_table);
601 if (ret)
Viresh Kumarda544b62018-06-07 14:50:43 +0530602 goto free_required_opps;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530603
Viresh Kumara1e8c132018-04-06 14:35:45 +0530604 ret = _opp_add(dev, new_opp, opp_table, rate_not_available);
Viresh Kumar7f8538e2017-01-02 14:40:55 +0530605 if (ret) {
606 /* Don't return error for duplicate OPPs */
607 if (ret == -EBUSY)
608 ret = 0;
Viresh Kumarda544b62018-06-07 14:50:43 +0530609 goto free_required_opps;
Viresh Kumar7f8538e2017-01-02 14:40:55 +0530610 }
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530611
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,
617 new_opp->rate);
618 } else {
619 new_opp->suspend = true;
620 opp_table->suspend_opp = new_opp;
621 }
622 }
623
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;
626
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530627 pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n",
Viresh Kumar0f0fe7e2016-12-01 16:28:17 +0530628 __func__, new_opp->turbo, new_opp->rate,
Viresh Kumardfbe4672016-12-01 16:28:19 +0530629 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);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530631
632 /*
633 * Notify the changes in the availability of the operable
634 * frequency/voltage list.
635 */
Viresh Kumar052c6f12017-01-23 10:11:49 +0530636 blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp);
Dave Gerlachdeac8702018-10-03 16:13:15 +0530637 return new_opp;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530638
Viresh Kumarda544b62018-06-07 14:50:43 +0530639free_required_opps:
640 _of_opp_free_required_opps(opp_table, new_opp);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530641free_opp:
Viresh Kumar8cd2f6e2017-01-02 14:41:01 +0530642 _opp_free(new_opp);
643
Dave Gerlachdeac8702018-10-03 16:13:15 +0530644 return ERR_PTR(ret);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530645}
646
647/* Initializes OPP tables based on new bindings */
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530648static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530649{
650 struct device_node *np;
Viresh Kumar283d55e2018-09-07 09:01:54 +0530651 int ret, count = 0, pstate_count = 0;
Viresh Kumar3ba98322016-11-18 15:47:46 +0530652 struct dev_pm_opp *opp;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530653
Viresh Kumar283d55e2018-09-07 09:01:54 +0530654 /* OPP table is already initialized for the device */
655 if (opp_table->parsed_static_opps) {
656 kref_get(&opp_table->list_kref);
657 return 0;
658 }
659
Viresh Kumard0e8ae62018-09-11 11:14:11 +0530660 kref_init(&opp_table->list_kref);
661
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530662 /* We have opp-table node now, iterate over it and add OPPs */
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530663 for_each_available_child_of_node(opp_table->np, np) {
Dave Gerlachdeac8702018-10-03 16:13:15 +0530664 opp = _opp_add_static_v2(opp_table, dev, np);
665 if (IS_ERR(opp)) {
666 ret = PTR_ERR(opp);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530667 dev_err(dev, "%s: Failed to add OPP, %d\n", __func__,
668 ret);
Tobias Jordan7978db32017-10-04 11:35:03 +0530669 of_node_put(np);
Viresh Kumarcdd6ed92018-09-12 12:35:19 +0530670 goto put_list_kref;
Dave Gerlachdeac8702018-10-03 16:13:15 +0530671 } else if (opp) {
672 count++;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530673 }
674 }
675
676 /* There should be one of more OPP defined */
Viresh Kumar8cd2f6e2017-01-02 14:41:01 +0530677 if (WARN_ON(!count)) {
678 ret = -ENOENT;
Viresh Kumarcdd6ed92018-09-12 12:35:19 +0530679 goto put_list_kref;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530680 }
681
Viresh Kumar3ba98322016-11-18 15:47:46 +0530682 list_for_each_entry(opp, &opp_table->opp_list, node)
683 pstate_count += !!opp->pstate;
684
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);
689 ret = -ENOENT;
Viresh Kumarcdd6ed92018-09-12 12:35:19 +0530690 goto put_list_kref;
Viresh Kumar3ba98322016-11-18 15:47:46 +0530691 }
692
693 if (pstate_count)
694 opp_table->genpd_performance_state = true;
695
Viresh Kumarf06ed902018-06-14 12:04:43 +0530696 opp_table->parsed_static_opps = true;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530697
Viresh Kumarcdd6ed92018-09-12 12:35:19 +0530698 return 0;
699
700put_list_kref:
701 _put_opp_list_kref(opp_table);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530702
703 return ret;
704}
705
706/* Initializes OPP tables based on old-deprecated bindings */
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530707static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530708{
709 const struct property *prop;
710 const __be32 *val;
Viresh Kumar8cd2f6e2017-01-02 14:41:01 +0530711 int nr, ret = 0;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530712
713 prop = of_find_property(dev->of_node, "operating-points", NULL);
714 if (!prop)
715 return -ENODEV;
716 if (!prop->value)
717 return -ENODATA;
718
719 /*
720 * Each OPP is a set of tuples consisting of frequency and
721 * voltage like <freq-kHz vol-uV>.
722 */
723 nr = prop->length / sizeof(u32);
724 if (nr % 2) {
725 dev_err(dev, "%s: Invalid OPP table\n", __func__);
726 return -EINVAL;
727 }
728
Viresh Kumard0e8ae62018-09-11 11:14:11 +0530729 kref_init(&opp_table->list_kref);
730
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530731 val = prop->value;
732 while (nr) {
733 unsigned long freq = be32_to_cpup(val++) * 1000;
734 unsigned long volt = be32_to_cpup(val++);
735
Viresh Kumar8cd2f6e2017-01-02 14:41:01 +0530736 ret = _opp_add_v1(opp_table, dev, freq, volt, false);
Viresh Kumar04a86a82017-01-02 14:40:58 +0530737 if (ret) {
738 dev_err(dev, "%s: Failed to add OPP %ld (%d)\n",
739 __func__, freq, ret);
Viresh Kumarcdd6ed92018-09-12 12:35:19 +0530740 _put_opp_list_kref(opp_table);
Viresh Kumarcdd6ed92018-09-12 12:35:19 +0530741 return ret;
Viresh Kumar04a86a82017-01-02 14:40:58 +0530742 }
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530743 nr -= 2;
744 }
745
Viresh Kumar8cd2f6e2017-01-02 14:41:01 +0530746 return ret;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530747}
748
749/**
750 * dev_pm_opp_of_add_table() - Initialize opp table from device tree
751 * @dev: device pointer used to lookup OPP table.
752 *
753 * Register the initial OPP table with the OPP library for given device.
754 *
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530755 * Return:
756 * 0 On success OR
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
762 * in device node.
763 * -ENODATA when empty 'operating-points' property is found
764 * -EINVAL when invalid entries are found in opp-v2 table
765 */
766int dev_pm_opp_of_add_table(struct device *dev)
767{
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530768 struct opp_table *opp_table;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530769 int ret;
770
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530771 opp_table = dev_pm_opp_get_opp_table_indexed(dev, 0);
772 if (!opp_table)
773 return -ENOMEM;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530774
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530775 /*
776 * OPPs have two version of bindings now. Also try the old (v1)
777 * bindings for backward compatibility with older dtbs.
778 */
779 if (opp_table->np)
780 ret = _of_add_opp_table_v2(dev, opp_table);
781 else
782 ret = _of_add_opp_table_v1(dev, opp_table);
783
784 if (ret)
785 dev_pm_opp_put_opp_table(opp_table);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530786
787 return ret;
788}
789EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);
790
Viresh Kumarfa9b2742017-04-26 10:45:46 +0530791/**
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.
795 *
796 * Register the initial OPP table with the OPP library for given device only
797 * using the "operating-points-v2" property.
798 *
799 * Return:
800 * 0 On success OR
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
806 * in device node.
807 * -ENODATA when empty 'operating-points' property is found
808 * -EINVAL when invalid entries are found in opp-v2 table
809 */
810int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
811{
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530812 struct opp_table *opp_table;
Viresh Kumar8a352fd2018-05-30 15:19:38 +0530813 int ret, count;
Viresh Kumarfa9b2742017-04-26 10:45:46 +0530814
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530815 if (index) {
Viresh Kumar8a352fd2018-05-30 15:19:38 +0530816 /*
817 * If only one phandle is present, then the same OPP table
818 * applies for all index requests.
819 */
820 count = of_count_phandle_with_args(dev->of_node,
821 "operating-points-v2", NULL);
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530822 if (count != 1)
823 return -ENODEV;
Viresh Kumar8a352fd2018-05-30 15:19:38 +0530824
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530825 index = 0;
Viresh Kumar8a352fd2018-05-30 15:19:38 +0530826 }
Viresh Kumarfa9b2742017-04-26 10:45:46 +0530827
Viresh Kumar5ed4cec2018-09-12 11:21:17 +0530828 opp_table = dev_pm_opp_get_opp_table_indexed(dev, index);
829 if (!opp_table)
830 return -ENOMEM;
831
832 ret = _of_add_opp_table_v2(dev, opp_table);
833 if (ret)
834 dev_pm_opp_put_opp_table(opp_table);
Viresh Kumarfa9b2742017-04-26 10:45:46 +0530835
836 return ret;
837}
838EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed);
839
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530840/* CPU device specific helpers */
841
842/**
843 * dev_pm_opp_of_cpumask_remove_table() - Removes OPP table for @cpumask
844 * @cpumask: cpumask for which OPP table needs to be removed
845 *
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.
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530848 */
849void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask)
850{
Viresh Kumar2a4eb732018-09-13 13:14:36 +0530851 _dev_pm_opp_cpumask_remove_table(cpumask, -1);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530852}
853EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table);
854
855/**
856 * dev_pm_opp_of_cpumask_add_table() - Adds OPP table for @cpumask
857 * @cpumask: cpumask for which OPP table needs to be added.
858 *
859 * This adds the OPP tables for CPUs present in the @cpumask.
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530860 */
861int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask)
862{
863 struct device *cpu_dev;
Viresh Kumar50b6b872018-10-03 15:12:06 +0530864 int cpu, ret;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530865
Viresh Kumar50b6b872018-10-03 15:12:06 +0530866 if (WARN_ON(cpumask_empty(cpumask)))
867 return -ENODEV;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530868
869 for_each_cpu(cpu, cpumask) {
870 cpu_dev = get_cpu_device(cpu);
871 if (!cpu_dev) {
872 pr_err("%s: failed to get cpu%d device\n", __func__,
873 cpu);
Viresh Kumar50b6b872018-10-03 15:12:06 +0530874 ret = -ENODEV;
875 goto remove_table;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530876 }
877
878 ret = dev_pm_opp_of_add_table(cpu_dev);
879 if (ret) {
Viresh Kumar5b606972017-07-12 09:21:49 +0530880 /*
881 * OPP may get registered dynamically, don't print error
882 * message here.
883 */
884 pr_debug("%s: couldn't find opp table for cpu:%d, %d\n",
885 __func__, cpu, ret);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530886
Viresh Kumar50b6b872018-10-03 15:12:06 +0530887 goto remove_table;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530888 }
889 }
890
Viresh Kumar50b6b872018-10-03 15:12:06 +0530891 return 0;
892
893remove_table:
894 /* Free all other OPPs */
895 _dev_pm_opp_cpumask_remove_table(cpumask, cpu);
896
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530897 return ret;
898}
899EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_add_table);
900
901/*
902 * Works only for OPP v2 bindings.
903 *
904 * Returns -ENOENT if operating-points-v2 bindings aren't supported.
905 */
906/**
907 * dev_pm_opp_of_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with
908 * @cpu_dev using operating-points-v2
909 * bindings.
910 *
911 * @cpu_dev: CPU device for which we do this operation
912 * @cpumask: cpumask to update with information of sharing CPUs
913 *
914 * This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev.
915 *
916 * Returns -ENOENT if operating-points-v2 isn't present for @cpu_dev.
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530917 */
918int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
919 struct cpumask *cpumask)
920{
Waldemar Rymarkiewicz76279292017-07-27 12:01:17 +0200921 struct device_node *np, *tmp_np, *cpu_np;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530922 int cpu, ret = 0;
923
924 /* Get OPP descriptor node */
Dave Gerlach0764c602017-02-03 11:29:26 -0600925 np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530926 if (!np) {
Masahiro Yamada349aa922016-10-20 16:12:49 +0900927 dev_dbg(cpu_dev, "%s: Couldn't find opp node.\n", __func__);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530928 return -ENOENT;
929 }
930
931 cpumask_set_cpu(cpu_dev->id, cpumask);
932
933 /* OPPs are shared ? */
934 if (!of_property_read_bool(np, "opp-shared"))
935 goto put_cpu_node;
936
937 for_each_possible_cpu(cpu) {
938 if (cpu == cpu_dev->id)
939 continue;
940
Sudeep Holla98679992017-10-12 11:32:23 +0100941 cpu_np = of_cpu_device_node_get(cpu);
Waldemar Rymarkiewicz76279292017-07-27 12:01:17 +0200942 if (!cpu_np) {
943 dev_err(cpu_dev, "%s: failed to get cpu%d node\n",
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530944 __func__, cpu);
Waldemar Rymarkiewicz76279292017-07-27 12:01:17 +0200945 ret = -ENOENT;
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530946 goto put_cpu_node;
947 }
948
949 /* Get OPP descriptor node */
Viresh Kumarfa9b2742017-04-26 10:45:46 +0530950 tmp_np = _opp_of_get_opp_desc_node(cpu_np, 0);
Sudeep Holla98679992017-10-12 11:32:23 +0100951 of_node_put(cpu_np);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530952 if (!tmp_np) {
Waldemar Rymarkiewicz76279292017-07-27 12:01:17 +0200953 pr_err("%pOF: Couldn't find opp node\n", cpu_np);
Viresh Kumarf47b72a2016-05-05 16:20:33 +0530954 ret = -ENOENT;
955 goto put_cpu_node;
956 }
957
958 /* CPUs are sharing opp node */
959 if (np == tmp_np)
960 cpumask_set_cpu(cpu, cpumask);
961
962 of_node_put(tmp_np);
963 }
964
965put_cpu_node:
966 of_node_put(np);
967 return ret;
968}
969EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
Viresh Kumara88bd2a2017-11-29 15:18:36 +0530970
971/**
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.
975 *
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.
979 *
980 * Return: Matching opp, else returns ERR_PTR in case of error and should be
981 * handled using IS_ERR.
982 *
983 * The callers are required to call dev_pm_opp_put() for the returned OPP after
984 * use.
985 */
986struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev,
987 struct device_node *np)
988{
989 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV);
990 struct device_node *required_np;
991 struct opp_table *opp_table;
992
993 opp_table = _find_opp_table(dev);
994 if (IS_ERR(opp_table))
995 return ERR_CAST(opp_table);
996
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");
1000 goto put_opp_table;
1001 }
1002
1003 mutex_lock(&opp_table->lock);
1004
1005 list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
1006 if (temp_opp->available && temp_opp->np == required_np) {
1007 opp = temp_opp;
1008
1009 /* Increment the reference count of OPP */
1010 dev_pm_opp_get(opp);
1011 break;
1012 }
1013 }
1014
1015 mutex_unlock(&opp_table->lock);
1016
1017 of_node_put(required_np);
1018put_opp_table:
1019 dev_pm_opp_put_opp_table(opp_table);
1020
1021 return opp;
1022}
1023EXPORT_SYMBOL_GPL(of_dev_pm_opp_find_required_opp);
Viresh Kumare2f4b5f2018-01-12 10:03:45 +05301024
1025/**
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
1028 *
1029 * Return: DT node corresponding to the opp, else 0 on success.
1030 *
1031 * The caller needs to put the node with of_node_put() after using it.
1032 */
1033struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
1034{
1035 if (IS_ERR_OR_NULL(opp)) {
1036 pr_err("%s: Invalid parameters\n", __func__);
1037 return NULL;
1038 }
1039
1040 return of_node_get(opp->np);
1041}
1042EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);