hc
2023-08-30 862c27fc9920c83318c784bfdadf43a65df1ec8f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd
 */
#include <common.h>
#include <dm.h>
#include <clk.h>
#include <dvfs.h>
#include <thermal.h>
#include <linux/list.h>
 
#include <asm/arch/clock.h>
#include <power/regulator.h>
#ifdef CONFIG_ROCKCHIP_DMC
#include <asm/arch/rockchip_dmc.h>
#endif
 
/*
 * # This is a simple wide temperature(ie. wtemp) dvfs driver, the policy is:
 *
 * 1. U-Boot parse cpu/dmc opp table from kernel dtb, anyone of
 *    "rockchip,low-temp = <...>" and "rockchip,high-temp = <...>" present in
 *    cpu/dmc nodes means wtemp is enabled.
 *
 *    1.1. When temperature trigger "rockchip,low-temp", increase 50mv voltage
 *         as target voltage. If target voltage is over "rockchip,max-volt",
 *         just set "rockchip,max-volt" as target voltage and lower 2 level freq,
 *
 *    1.2. When temperature trigger "rockchip,high-temp", just apply opp table[0]
 *         voltage and freq.
 *
 * 2. U-Boot parse cpu/dmc thermal zone "trip-point-0" temperature from kernel
 *    dtb, and apply the same rules as above [1.2] policy.
 *
 *
 * # The dvfs policy apply moment is:
 *
 * 1. Appy it after clk and regulator drivers setup;
 * 2. Repeat apply it by CONFIG_PREBOOT command until achieve the target
 *    temperature. user should add: #define CONFIG_PREBOOT "dvfs repeat" and
 *    assign repeat property in dts:
 *
 *    uboot-wide-temperature {
 *        status = "okay";
 *        compatible = "rockchip,uboot-wide-temperature";
 *
 *        cpu,low-temp-repeat;
 *        cpu,high-temp-repeat;
 *        dmc,low-temp-repeat;
 *        dmc,high-temp-repeat;
 *    };
 */
 
#define FDT_PATH_CPUS        "/cpus"
#define FDT_PATH_DMC        "/dmc"
#define FDT_PATH_THREMAL_TRIP_POINT0    \
   "/thermal-zones/soc-thermal/trips/trip-point-0"
#define FDT_PATH_THREMAL_COOLING_MAPS    \
   "/thermal-zones/soc-thermal/cooling-maps"
 
#define OPP_TABLE_MAX        20
#define RATE_LOWER_LEVEL_N    2
#define DIFF_VOLTAGE_UV        50000
#define TEMP_STRING_LEN        12
#define REPEAT_PERIOD_US    1000000
 
static LIST_HEAD(pm_e_head);
 
enum pm_id {
   PM_CPU,
   PM_DMC,
};
 
enum pm_event {
   PM_EVT_NONE = 0x0,
   PM_EVT_LOW  = 0x1,
   PM_EVT_HIGH = 0x2,
   PM_EVT_BOTH = PM_EVT_LOW | PM_EVT_HIGH,
};
 
struct opp_table {
   u64 hz;
   u32 uv;
};
 
struct lmt_param {
   int low_temp;        /* milli degree */
   int high_temp;        /* milli degree */
   int tz_temp;        /* milli degree */
   int max_volt;        /* uV */
 
   bool htemp_repeat;
   bool ltemp_repeat;
 
   bool ltemp_limit;
   bool htemp_limit;
   bool tztemp_limit;
};
 
struct pm_element {
   int id;
   const char *name;
   const char *supply_name;
   int volt_diff;
   u32 opp_nr;
   struct opp_table opp[OPP_TABLE_MAX];
   struct lmt_param lmt;
   struct udevice *supply;
   struct clk clk;
   struct list_head node;
};
 
struct wtemp_dvfs_priv {
   struct udevice *thermal;
   struct pm_element *cpu;
   struct pm_element *dmc;
};
 
static struct pm_element pm_cpu = {
   .id        = PM_CPU,
   .name        = "cpu",
   .supply_name    = "cpu-supply",
   .volt_diff    = DIFF_VOLTAGE_UV,
};
 
static struct pm_element pm_dmc = {
   .id        = PM_DMC,
   .name        = "dmc",
   .supply_name    = "center-supply",
   .volt_diff    = DIFF_VOLTAGE_UV,
};
 
static void temp2string(int temp, char *data, int len)
{
   int decimal_point;
   int integer;
 
   integer = abs(temp) / 1000;
   decimal_point = abs(temp) % 1000;
   snprintf(data, len, "%s%d.%d",
        temp < 0 ? "-" : "", integer, decimal_point);
}
 
static ulong wtemp_get_lowlevel_rate(ulong rate, u32 level,
                    struct pm_element *e)
{
   struct opp_table *opp;
   int i, count, idx = 0;
 
   opp = e->opp;
   count = e->opp_nr;
 
   for (i = 0; i < count; i++) {
       if (opp[i].hz >= rate) {
           idx = (i <= level) ? 0 : i - level;
           break;
       }
   }
 
   return opp[idx].hz;
}
 
static ulong __wtemp_clk_get_rate(struct pm_element *e)
{
#ifdef CONFIG_ROCKCHIP_DMC
   if (e->id == PM_DMC)
       return rockchip_ddrclk_sip_recalc_rate_v2();
#endif
   return clk_get_rate(&e->clk);
}
 
static ulong __wtemp_clk_set_rate(struct pm_element *e, ulong rate)
{
#ifdef CONFIG_ROCKCHIP_DMC
   if (e->id == PM_DMC) {
       rate = rockchip_ddrclk_sip_round_rate_v2(rate);
       rockchip_ddrclk_sip_set_rate_v2(rate);
   } else
#endif
       clk_set_rate(&e->clk, rate);
 
   return rate;
}
 
static int __wtemp_regulator_get_value(struct pm_element *e)
{
   return regulator_get_value(e->supply);
}
 
static int __wtemp_regulator_set_value(struct pm_element *e, int value)
{
   return regulator_set_value(e->supply, value);
}
 
/*
 * Policy: Increase voltage
 *
 * 1. target volt = original volt + diff volt;
 * 2. If target volt is not over max_volt, just set it;
 * 3. Otherwise set max_volt as target volt and lower the rate(front N level).
 */
static void wtemp_dvfs_low_temp_adjust(struct udevice *dev, struct pm_element *e)
{
   struct wtemp_dvfs_priv *priv = dev_get_priv(dev);
   ulong org_rate, tgt_rate, rb_rate;
   int org_volt, tgt_volt, rb_volt;
 
   org_rate = __wtemp_clk_get_rate(e);
   org_volt = __wtemp_regulator_get_value(e);
   tgt_volt = org_volt + e->volt_diff;
   if ((e->lmt.max_volt != -ENODATA) && (tgt_volt > e->lmt.max_volt)) {
       tgt_volt = e->lmt.max_volt;
       __wtemp_regulator_set_value(e, tgt_volt);
       tgt_rate = wtemp_get_lowlevel_rate(org_rate,
                       RATE_LOWER_LEVEL_N, priv->cpu);
       tgt_rate = __wtemp_clk_set_rate(e, tgt_rate);
   } else {
       __wtemp_regulator_set_value(e, tgt_volt);
       tgt_rate = org_rate;
   }
 
   /* Check */
   rb_rate = __wtemp_clk_get_rate(e);
   rb_volt = __wtemp_regulator_get_value(e);
   if (tgt_rate != rb_rate)
       printf("DVFS: %s: target rate=%ld, readback rate=%ld !\n",
              e->name, tgt_rate, rb_rate);
   if (tgt_volt != rb_volt)
       printf("DVFS: %s: target volt=%d, readback volt=%d !\n",
              e->name, tgt_volt, rb_volt);
 
   printf("DVFS: %s(low): %ld->%ld Hz, %d->%d uV\n",
          e->name, org_rate, rb_rate, org_volt, rb_volt);
}
 
/*
 * Policy:
 *
 * Just set opp table[0] volt and rate, i.e. the lowest performance.
 */
static void wtemp_dvfs_high_temp_adjust(struct udevice *dev, struct pm_element *e)
{
   ulong org_rate, tgt_rate, rb_rate;
   int org_volt, tgt_volt, rb_volt;
 
   /* Apply opp[0] */
   org_rate = __wtemp_clk_get_rate(e);
   tgt_rate = e->opp[0].hz;
   tgt_rate = __wtemp_clk_set_rate(e, tgt_rate);
 
   org_volt = __wtemp_regulator_get_value(e);
   tgt_volt = e->opp[0].uv;
   __wtemp_regulator_set_value(e, tgt_volt);
 
   /* Check */
   rb_rate = __wtemp_clk_get_rate(e);
   rb_volt = __wtemp_regulator_get_value(e);
   if (tgt_rate != rb_rate)
       printf("DVFS: %s: target rate=%ld, readback rate=%ld !\n",
              e->name, tgt_rate, rb_rate);
   if (tgt_volt != rb_volt)
       printf("DVFS: %s: target volt=%d, readback volt=%d !\n",
              e->name, tgt_volt, rb_volt);
 
   printf("DVFS: %s(high): %ld->%ld Hz, %d->%d uV\n",
          e->name, org_rate, tgt_rate, org_volt, tgt_volt);
}
 
static bool wtemp_dvfs_is_effect(struct pm_element *e,
                int temp, enum pm_event evt)
{
   if (evt & PM_EVT_LOW) {
       if (e->lmt.ltemp_limit && temp <= e->lmt.low_temp)
           return false;
   }
 
   if (evt & PM_EVT_HIGH) {
       if (e->lmt.tztemp_limit && temp >= e->lmt.tz_temp)
           return false;
       else if (e->lmt.htemp_limit && temp >= e->lmt.high_temp)
           return false;
   }
 
   return true;
}
 
static int __wtemp_dvfs_apply(struct udevice *dev, struct pm_element *e,
                 int temp, enum pm_event evt)
{
   enum pm_event ret = PM_EVT_NONE;
 
   if (evt & PM_EVT_LOW) {
       /* Over lowest temperature: increase voltage */
       if (e->lmt.ltemp_limit && temp <= e->lmt.low_temp) {
           ret |= PM_EVT_LOW;
           wtemp_dvfs_low_temp_adjust(dev, e);
       }
   }
 
   if (evt & PM_EVT_HIGH) {
       /* Over highest/thermal_zone temperature: decrease rate and voltage */
       if (e->lmt.tztemp_limit && temp >= e->lmt.tz_temp) {
           ret |= PM_EVT_HIGH;
           wtemp_dvfs_high_temp_adjust(dev, e);
       } else if (e->lmt.htemp_limit && temp >= e->lmt.high_temp) {
           ret |= PM_EVT_HIGH;
           wtemp_dvfs_high_temp_adjust(dev, e);
       }
   }
 
   return ret;
}
 
static int __wtemp_common_ofdata_to_platdata(ofnode node, struct pm_element *e)
{
   ofnode supply, opp_node;
   u32 phandle, uv, clock[2];
   uint64_t hz;
   int ret;
 
   /* Get regulator and clk */
   if (!ofnode_read_u32(node, e->supply_name, &phandle)) {
       supply = ofnode_get_by_phandle(phandle);
       ret = regulator_get_by_devname(supply.np->name, &e->supply);
       if (ret) {
           printf("DVFS: %s: Get supply(%s) failed, ret=%d",
                  e->name, supply.np->full_name, ret);
           return ret;
       }
       debug("DVFS: supply: %s\n", supply.np->full_name);
   }
 
   if (!ofnode_read_u32_array(node, "clocks", clock, ARRAY_SIZE(clock))) {
       e->clk.id = clock[1];
       ret = rockchip_get_clk(&e->clk.dev);
       if (ret) {
           printf("DVFS: %s: Get clk failed, ret=%d\n", e->name, ret);
           return ret;
       }
   }
 
   /* Get opp-table & limit param */
   if (!ofnode_read_u32(node, "operating-points-v2", &phandle)) {
       opp_node = ofnode_get_by_phandle(phandle);
       e->lmt.low_temp = ofnode_read_s32_default(opp_node,
                       "rockchip,low-temp", -ENODATA);
       e->lmt.high_temp = ofnode_read_s32_default(opp_node,
                       "rockchip,high-temp", -ENODATA);
       e->lmt.max_volt = ofnode_read_u32_default(opp_node,
                       "rockchip,max-volt", -ENODATA);
 
       debug("DVFS: %s: low-temp=%d, high-temp=%d, max-volt=%d\n",
             e->name, e->lmt.low_temp, e->lmt.high_temp,
             e->lmt.max_volt);
 
       ofnode_for_each_subnode(node, opp_node) {
           if (e->opp_nr >= OPP_TABLE_MAX) {
               printf("DVFS: over max(%d) opp table items\n",
                      OPP_TABLE_MAX);
               break;
           }
           ofnode_read_u64(node, "opp-hz", &hz);
           ofnode_read_u32_array(node, "opp-microvolt", &uv, 1);
           e->opp[e->opp_nr].hz = hz;
           e->opp[e->opp_nr].uv = uv;
           e->opp_nr++;
           debug("DVFS: %s: opp[%d]: hz=%lld, uv=%d, %s\n",
                 e->name, e->opp_nr - 1,
                 hz, uv, ofnode_get_name(node));
       }
   }
   if (!e->opp_nr) {
       printf("DVFS: %s: Can't find opp table\n", e->name);
       return -EINVAL;
   }
 
   if (e->lmt.max_volt == -ENODATA)
       e->lmt.max_volt = e->opp[e->opp_nr - 1].uv;
   if (e->lmt.low_temp != -ENODATA)
       e->lmt.ltemp_limit = true;
   if (e->lmt.high_temp != -ENODATA)
       e->lmt.htemp_limit = true;
 
   return 0;
}
 
static int wtemp_dvfs_apply(struct udevice *dev)
{
   struct wtemp_dvfs_priv *priv = dev_get_priv(dev);
   struct list_head *node;
   struct pm_element *e;
   char s_temp[TEMP_STRING_LEN];
   int temp, ret;
 
   ret = thermal_get_temp(priv->thermal, &temp);
   if (ret) {
       printf("DVFS: Get temperature failed, ret=%d\n", ret);
       return ret;
   }
 
   temp2string(temp, s_temp, TEMP_STRING_LEN);
   printf("DVFS: %s'c\n", s_temp);
 
   /* Apply dvfs policy for all pm element */
   list_for_each(node, &pm_e_head) {
       e = list_entry(node, struct pm_element, node);
       __wtemp_dvfs_apply(dev, e, temp, PM_EVT_BOTH);
   }
 
   return 0;
}
 
static int wtemp_dvfs_repeat_apply(struct udevice *dev)
{
   struct wtemp_dvfs_priv *priv = dev_get_priv(dev);
   struct list_head *node;
   struct pm_element *e;
   enum pm_event applied;
   char s_temp[TEMP_STRING_LEN];
   int temp, ret;
 
repeat:
   ret = thermal_get_temp(priv->thermal, &temp);
   if (ret) {
       printf("DVFS: Get thermal temperature failed, ret=%d\n", ret);
       return false;
   }
 
   /* Apply dvfs policy for all pm element if there is repeat request */
   applied = PM_EVT_NONE;
   list_for_each(node, &pm_e_head) {
       e = list_entry(node, struct pm_element, node);
       if (e->lmt.ltemp_repeat)
           applied |= __wtemp_dvfs_apply(dev, e, temp, PM_EVT_LOW);
       if (e->lmt.htemp_repeat)
           applied |= __wtemp_dvfs_apply(dev, e, temp, PM_EVT_HIGH);
   }
 
   /* Everything is fine, exit */
   if (applied == PM_EVT_NONE)
       goto finish;
 
   /* Check repeat result */
   udelay(REPEAT_PERIOD_US);
   list_for_each(node, &pm_e_head) {
       e = list_entry(node, struct pm_element, node);
       if (e->lmt.ltemp_repeat &&
           !wtemp_dvfs_is_effect(e, temp, PM_EVT_LOW))
           goto repeat;
       if (e->lmt.htemp_repeat &&
           !wtemp_dvfs_is_effect(e, temp, PM_EVT_HIGH))
           goto repeat;
   }
 
finish:
   list_for_each(node, &pm_e_head) {
       e = list_entry(node, struct pm_element, node);
       temp2string(temp, s_temp, TEMP_STRING_LEN);
       printf("DVFS: %s %s'c, %ld Hz, %d uV\n", e->name,
              s_temp, __wtemp_clk_get_rate(e),
              __wtemp_regulator_get_value(e));
   }
 
   return 0;
}
 
static void print_e_state(void)
{
   struct pm_element *e;
   struct list_head *node;
   char s_low[TEMP_STRING_LEN];
   char s_high[TEMP_STRING_LEN];
   char s_tz[TEMP_STRING_LEN];
 
   list_for_each(node, &pm_e_head) {
       e = list_entry(node, struct pm_element, node);
       if (!e->lmt.ltemp_limit &&
           !e->lmt.htemp_limit && !e->lmt.tztemp_limit)
           return;
 
       temp2string(e->lmt.tz_temp, s_tz, TEMP_STRING_LEN);
       temp2string(e->lmt.low_temp, s_low, TEMP_STRING_LEN);
       temp2string(e->lmt.high_temp, s_high, TEMP_STRING_LEN);
       printf("DVFS: %s: low=%s'c, high=%s'c, Vmax=%duV, tz_temp=%s'c, "
             "h_repeat=%d, l_repeat=%d\n",
             e->name, e->lmt.ltemp_limit ? s_low : NULL,
             e->lmt.htemp_limit ? s_high : NULL,
             e->lmt.max_volt,
             e->lmt.tztemp_limit ? s_tz : NULL,
             e->lmt.htemp_repeat, e->lmt.ltemp_repeat);
   }
}
 
static int wtemp_dvfs_ofdata_to_platdata(struct udevice *dev)
{
   struct wtemp_dvfs_priv *priv = dev_get_priv(dev);
   ofnode tz_trip0, cooling_maps, node;
   ofnode cpus, cpu, dmc;
   const char *name;
   int ret, tz_temp;
   u32 phandle;
 
   INIT_LIST_HEAD(&pm_e_head);
 
   /* 1. Parse cpu node */
   priv->cpu = &pm_cpu;
   cpus = ofnode_path(FDT_PATH_CPUS);
   if (!ofnode_valid(cpus)) {
       debug("DVFS: Can't find %s\n", FDT_PATH_CPUS);
       goto parse_dmc;
   }
 
   ofnode_for_each_subnode(cpu, cpus) {
       name = ofnode_get_property(cpu, "device_type", NULL);
       if (!name)
           continue;
       if (!strcmp(name, "cpu")) {
           ret = __wtemp_common_ofdata_to_platdata(cpu, priv->cpu);
           if (ret)
               return ret;
           break;
       }
   }
 
   priv->cpu->lmt.ltemp_repeat =
       dev_read_bool(dev, "cpu,low-temp-repeat");
   priv->cpu->lmt.htemp_repeat =
       dev_read_bool(dev, "cpu,high-temp-repeat");
 
   list_add_tail(&priv->cpu->node, &pm_e_head);
 
   /* 2. Parse dmc node */
parse_dmc:
   priv->dmc = &pm_dmc;
   dmc = ofnode_path(FDT_PATH_DMC);
   if (!ofnode_valid(dmc)) {
       debug("DVFS: Can't find %s\n", FDT_PATH_CPUS);
       goto parse_tz;
   }
   if (!IS_ENABLED(CONFIG_ROCKCHIP_DMC)) {
       debug("DVFS: CONFIG_ROCKCHIP_DMC is disabled\n");
       goto parse_tz;
   }
 
   ret = __wtemp_common_ofdata_to_platdata(dmc, priv->dmc);
   if (ret)
       return ret;
 
   priv->dmc->lmt.ltemp_repeat =
       dev_read_bool(dev, "dmc,low-temp-repeat");
   priv->dmc->lmt.htemp_repeat =
       dev_read_bool(dev, "dmc,high-temp-repeat");
 
   list_add_tail(&priv->dmc->node, &pm_e_head);
 
   /* 3. Parse thermal zone node */
parse_tz:
   tz_trip0 = ofnode_path(FDT_PATH_THREMAL_TRIP_POINT0);
   if (!ofnode_valid(tz_trip0)) {
       debug("DVFS: Can't find %s\n", FDT_PATH_THREMAL_TRIP_POINT0);
       goto finish;
   }
 
   tz_temp = ofnode_read_s32_default(tz_trip0, "temperature", -ENODATA);
   if (tz_temp == -ENODATA) {
       debug("DVFS: Can't get thermal zone trip0 temperature\n");
       goto finish;
   }
 
   cooling_maps = ofnode_path(FDT_PATH_THREMAL_COOLING_MAPS);
   if (!ofnode_valid(cooling_maps)) {
       debug("DVFS: Can't find %s\n", FDT_PATH_THREMAL_COOLING_MAPS);
       goto finish;
   }
 
   ofnode_for_each_subnode(node, cooling_maps) {
       ofnode_read_u32_array(node, "cooling-device", &phandle, 1);
       name = ofnode_get_name(ofnode_get_by_phandle(phandle));
       if (!name)
           continue;
       if (strstr(name, "cpu")) {
           priv->cpu->lmt.tztemp_limit = true;
           priv->cpu->lmt.tz_temp = tz_temp;
       } else if (strstr(name, "dmc")) {
           priv->dmc->lmt.tztemp_limit = true;
           priv->dmc->lmt.tz_temp = tz_temp;
       }
   }
 
finish:
   print_e_state();
 
   return 0;
}
 
static const struct dm_dvfs_ops wtemp_dvfs_ops = {
   .apply = wtemp_dvfs_apply,
   .repeat_apply = wtemp_dvfs_repeat_apply,
};
 
static int wtemp_dvfs_probe(struct udevice *dev)
{
   struct wtemp_dvfs_priv *priv = dev_get_priv(dev);
   int ret;
 
#ifdef CONFIG_ROCKCHIP_DMC
   struct udevice *ram_dev;
 
   /* Init dmc */
   ret = uclass_get_device(UCLASS_RAM, 0, &ram_dev);
   if (ret) {
       printf("DVFS: Get dmc device failed, ret=%d\n", ret);
       return ret;
   }
#endif
   /* Init thermal */
   ret = uclass_get_device(UCLASS_THERMAL, 0, &priv->thermal);
   if (ret) {
       printf("DVFS: Get thermal device failed, ret=%d\n", ret);
       return ret;
   }
 
   return 0;
}
 
static const struct udevice_id wtemp_dvfs_match[] = {
   { .compatible = "rockchip,uboot-wide-temperature", },
   {},
};
 
U_BOOT_DRIVER(rockchip_wide_temp_dvfs) = {
   .name              = "rockchip_wide_temp_dvfs",
   .id              = UCLASS_DVFS,
   .ops              = &wtemp_dvfs_ops,
   .of_match          = wtemp_dvfs_match,
   .probe              = wtemp_dvfs_probe,
   .ofdata_to_platdata   = wtemp_dvfs_ofdata_to_platdata,
   .priv_auto_alloc_size = sizeof(struct wtemp_dvfs_priv),
};