1 // SPDX-License-Identifier: GPL-2.0-only
3 * Tegra124 DFLL FCPU clock source driver
5 * Copyright (C) 2012-2019 NVIDIA Corporation. All rights reserved.
7 * Aleksandr Frid <afrid@nvidia.com>
8 * Paul Walmsley <pwalmsley@nvidia.com>
11 #include <linux/cpu.h>
12 #include <linux/err.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/of_device.h>
16 #include <linux/platform_device.h>
17 #include <linux/regulator/consumer.h>
18 #include <soc/tegra/fuse.h>
24 struct dfll_fcpu_data
{
25 const unsigned long *cpu_max_freq_table
;
26 unsigned int cpu_max_freq_table_size
;
27 const struct cvb_table
*cpu_cvb_tables
;
28 unsigned int cpu_cvb_tables_size
;
31 /* Maximum CPU frequency, indexed by CPU speedo id */
32 static const unsigned long tegra124_cpu_max_freq_table
[] = {
39 static const struct cvb_table tegra124_cpu_cvb_tables
[] = {
43 .min_millivolts
= 900,
44 .max_millivolts
= 1260,
46 .voltage_scale
= 1000,
48 { 204000000UL, { 1112619, -29295, 402 } },
49 { 306000000UL, { 1150460, -30585, 402 } },
50 { 408000000UL, { 1190122, -31865, 402 } },
51 { 510000000UL, { 1231606, -33155, 402 } },
52 { 612000000UL, { 1274912, -34435, 402 } },
53 { 714000000UL, { 1320040, -35725, 402 } },
54 { 816000000UL, { 1366990, -37005, 402 } },
55 { 918000000UL, { 1415762, -38295, 402 } },
56 { 1020000000UL, { 1466355, -39575, 402 } },
57 { 1122000000UL, { 1518771, -40865, 402 } },
58 { 1224000000UL, { 1573009, -42145, 402 } },
59 { 1326000000UL, { 1629068, -43435, 402 } },
60 { 1428000000UL, { 1686950, -44715, 402 } },
61 { 1530000000UL, { 1746653, -46005, 402 } },
62 { 1632000000UL, { 1808179, -47285, 402 } },
63 { 1734000000UL, { 1871526, -48575, 402 } },
64 { 1836000000UL, { 1936696, -49855, 402 } },
65 { 1938000000UL, { 2003687, -51145, 402 } },
66 { 2014500000UL, { 2054787, -52095, 402 } },
67 { 2116500000UL, { 2124957, -53385, 402 } },
68 { 2218500000UL, { 2196950, -54665, 402 } },
69 { 2320500000UL, { 2270765, -55955, 402 } },
70 { 2422500000UL, { 2346401, -57235, 402 } },
71 { 2524500000UL, { 2437299, -58535, 402 } },
75 .tune0_low
= 0x005020ff,
76 .tune0_high
= 0x005040ff,
82 static const unsigned long tegra210_cpu_max_freq_table
[] = {
96 #define CPU_CVB_TABLE \
97 .speedo_scale = 100, \
98 .voltage_scale = 1000, \
100 { 204000000UL, { 1007452, -23865, 370 } }, \
101 { 306000000UL, { 1052709, -24875, 370 } }, \
102 { 408000000UL, { 1099069, -25895, 370 } }, \
103 { 510000000UL, { 1146534, -26905, 370 } }, \
104 { 612000000UL, { 1195102, -27915, 370 } }, \
105 { 714000000UL, { 1244773, -28925, 370 } }, \
106 { 816000000UL, { 1295549, -29935, 370 } }, \
107 { 918000000UL, { 1347428, -30955, 370 } }, \
108 { 1020000000UL, { 1400411, -31965, 370 } }, \
109 { 1122000000UL, { 1454497, -32975, 370 } }, \
110 { 1224000000UL, { 1509687, -33985, 370 } }, \
111 { 1326000000UL, { 1565981, -35005, 370 } }, \
112 { 1428000000UL, { 1623379, -36015, 370 } }, \
113 { 1530000000UL, { 1681880, -37025, 370 } }, \
114 { 1632000000UL, { 1741485, -38035, 370 } }, \
115 { 1734000000UL, { 1802194, -39055, 370 } }, \
116 { 1836000000UL, { 1864006, -40065, 370 } }, \
117 { 1912500000UL, { 1910780, -40815, 370 } }, \
118 { 2014500000UL, { 1227000, 0, 0 } }, \
119 { 2218500000UL, { 1227000, 0, 0 } }, \
120 { 0UL, { 0, 0, 0 } }, \
123 #define CPU_CVB_TABLE_XA \
124 .speedo_scale = 100, \
125 .voltage_scale = 1000, \
127 { 204000000UL, { 1250024, -39785, 565 } }, \
128 { 306000000UL, { 1297556, -41145, 565 } }, \
129 { 408000000UL, { 1346718, -42505, 565 } }, \
130 { 510000000UL, { 1397511, -43855, 565 } }, \
131 { 612000000UL, { 1449933, -45215, 565 } }, \
132 { 714000000UL, { 1503986, -46575, 565 } }, \
133 { 816000000UL, { 1559669, -47935, 565 } }, \
134 { 918000000UL, { 1616982, -49295, 565 } }, \
135 { 1020000000UL, { 1675926, -50645, 565 } }, \
136 { 1122000000UL, { 1736500, -52005, 565 } }, \
137 { 1224000000UL, { 1798704, -53365, 565 } }, \
138 { 1326000000UL, { 1862538, -54725, 565 } }, \
139 { 1428000000UL, { 1928003, -56085, 565 } }, \
140 { 1530000000UL, { 1995097, -57435, 565 } }, \
141 { 1606500000UL, { 2046149, -58445, 565 } }, \
142 { 1632000000UL, { 2063822, -58795, 565 } }, \
143 { 0UL, { 0, 0, 0 } }, \
146 #define CPU_CVB_TABLE_EUCM1 \
147 .speedo_scale = 100, \
148 .voltage_scale = 1000, \
150 { 204000000UL, { 734429, 0, 0 } }, \
151 { 306000000UL, { 768191, 0, 0 } }, \
152 { 408000000UL, { 801953, 0, 0 } }, \
153 { 510000000UL, { 835715, 0, 0 } }, \
154 { 612000000UL, { 869477, 0, 0 } }, \
155 { 714000000UL, { 903239, 0, 0 } }, \
156 { 816000000UL, { 937001, 0, 0 } }, \
157 { 918000000UL, { 970763, 0, 0 } }, \
158 { 1020000000UL, { 1004525, 0, 0 } }, \
159 { 1122000000UL, { 1038287, 0, 0 } }, \
160 { 1224000000UL, { 1072049, 0, 0 } }, \
161 { 1326000000UL, { 1105811, 0, 0 } }, \
162 { 1428000000UL, { 1130000, 0, 0 } }, \
163 { 1555500000UL, { 1130000, 0, 0 } }, \
164 { 1632000000UL, { 1170000, 0, 0 } }, \
165 { 1734000000UL, { 1227500, 0, 0 } }, \
166 { 0UL, { 0, 0, 0 } }, \
169 #define CPU_CVB_TABLE_EUCM2 \
170 .speedo_scale = 100, \
171 .voltage_scale = 1000, \
173 { 204000000UL, { 742283, 0, 0 } }, \
174 { 306000000UL, { 776249, 0, 0 } }, \
175 { 408000000UL, { 810215, 0, 0 } }, \
176 { 510000000UL, { 844181, 0, 0 } }, \
177 { 612000000UL, { 878147, 0, 0 } }, \
178 { 714000000UL, { 912113, 0, 0 } }, \
179 { 816000000UL, { 946079, 0, 0 } }, \
180 { 918000000UL, { 980045, 0, 0 } }, \
181 { 1020000000UL, { 1014011, 0, 0 } }, \
182 { 1122000000UL, { 1047977, 0, 0 } }, \
183 { 1224000000UL, { 1081943, 0, 0 } }, \
184 { 1326000000UL, { 1090000, 0, 0 } }, \
185 { 1479000000UL, { 1090000, 0, 0 } }, \
186 { 1555500000UL, { 1162000, 0, 0 } }, \
187 { 1683000000UL, { 1195000, 0, 0 } }, \
188 { 0UL, { 0, 0, 0 } }, \
191 #define CPU_CVB_TABLE_EUCM2_JOINT_RAIL \
192 .speedo_scale = 100, \
193 .voltage_scale = 1000, \
195 { 204000000UL, { 742283, 0, 0 } }, \
196 { 306000000UL, { 776249, 0, 0 } }, \
197 { 408000000UL, { 810215, 0, 0 } }, \
198 { 510000000UL, { 844181, 0, 0 } }, \
199 { 612000000UL, { 878147, 0, 0 } }, \
200 { 714000000UL, { 912113, 0, 0 } }, \
201 { 816000000UL, { 946079, 0, 0 } }, \
202 { 918000000UL, { 980045, 0, 0 } }, \
203 { 1020000000UL, { 1014011, 0, 0 } }, \
204 { 1122000000UL, { 1047977, 0, 0 } }, \
205 { 1224000000UL, { 1081943, 0, 0 } }, \
206 { 1326000000UL, { 1090000, 0, 0 } }, \
207 { 1479000000UL, { 1090000, 0, 0 } }, \
208 { 1504500000UL, { 1120000, 0, 0 } }, \
209 { 0UL, { 0, 0, 0 } }, \
212 #define CPU_CVB_TABLE_ODN \
213 .speedo_scale = 100, \
214 .voltage_scale = 1000, \
216 { 204000000UL, { 721094, 0, 0 } }, \
217 { 306000000UL, { 754040, 0, 0 } }, \
218 { 408000000UL, { 786986, 0, 0 } }, \
219 { 510000000UL, { 819932, 0, 0 } }, \
220 { 612000000UL, { 852878, 0, 0 } }, \
221 { 714000000UL, { 885824, 0, 0 } }, \
222 { 816000000UL, { 918770, 0, 0 } }, \
223 { 918000000UL, { 915716, 0, 0 } }, \
224 { 1020000000UL, { 984662, 0, 0 } }, \
225 { 1122000000UL, { 1017608, 0, 0 } }, \
226 { 1224000000UL, { 1050554, 0, 0 } }, \
227 { 1326000000UL, { 1083500, 0, 0 } }, \
228 { 1428000000UL, { 1116446, 0, 0 } }, \
229 { 1581000000UL, { 1130000, 0, 0 } }, \
230 { 1683000000UL, { 1168000, 0, 0 } }, \
231 { 1785000000UL, { 1227500, 0, 0 } }, \
232 { 0UL, { 0, 0, 0 } }, \
235 static struct cvb_table tegra210_cpu_cvb_tables
[] = {
239 .min_millivolts
= 840,
240 .max_millivolts
= 1120,
241 CPU_CVB_TABLE_EUCM2_JOINT_RAIL
,
243 .tune0_low
= 0xffead0ff,
244 .tune0_high
= 0xffead0ff,
246 .tune_high_min_millivolts
= 864,
252 .min_millivolts
= 840,
253 .max_millivolts
= 1120,
254 CPU_CVB_TABLE_EUCM2_JOINT_RAIL
,
256 .tune0_low
= 0xffead0ff,
257 .tune0_high
= 0xffead0ff,
259 .tune_high_min_millivolts
= 864,
265 .min_millivolts
= 900,
266 .max_millivolts
= 1162,
269 .tune0_low
= 0xffead0ff,
270 .tune0_high
= 0xffead0ff,
277 .min_millivolts
= 900,
278 .max_millivolts
= 1162,
281 .tune0_low
= 0xffead0ff,
282 .tune0_high
= 0xffead0ff,
289 .min_millivolts
= 900,
290 .max_millivolts
= 1195,
293 .tune0_low
= 0xffead0ff,
294 .tune0_high
= 0xffead0ff,
301 .min_millivolts
= 900,
302 .max_millivolts
= 1195,
305 .tune0_low
= 0xffead0ff,
306 .tune0_high
= 0xffead0ff,
313 .min_millivolts
= 841,
314 .max_millivolts
= 1227,
317 .tune0_low
= 0xffead0ff,
318 .tune0_high
= 0xffead0ff,
320 .tune_high_min_millivolts
= 864,
326 .min_millivolts
= 841,
327 .max_millivolts
= 1227,
330 .tune0_low
= 0xffead0ff,
331 .tune0_high
= 0xffead0ff,
333 .tune_high_min_millivolts
= 864,
339 .min_millivolts
= 870,
340 .max_millivolts
= 1150,
343 .tune0_low
= 0xffead0ff,
350 .min_millivolts
= 870,
351 .max_millivolts
= 1150,
354 .tune0_low
= 0xffead0ff,
361 .min_millivolts
= 818,
362 .max_millivolts
= 1227,
365 .tune0_low
= 0xffead0ff,
366 .tune0_high
= 0xffead0ff,
368 .tune_high_min_millivolts
= 864,
374 .min_millivolts
= 818,
375 .max_millivolts
= 1227,
378 .tune0_low
= 0xffead0ff,
379 .tune0_high
= 0xffead0ff,
381 .tune_high_min_millivolts
= 864,
387 .min_millivolts
= 918,
388 .max_millivolts
= 1113,
391 .tune0_low
= 0xffead0ff,
398 .min_millivolts
= 825,
399 .max_millivolts
= 1227,
402 .tune0_low
= 0xffead0ff,
403 .tune0_high
= 0xffead0ff,
405 .tune_high_min_millivolts
= 864,
411 .min_millivolts
= 825,
412 .max_millivolts
= 1227,
415 .tune0_low
= 0xffead0ff,
416 .tune0_high
= 0xffead0ff,
418 .tune_high_min_millivolts
= 864,
424 .min_millivolts
= 870,
425 .max_millivolts
= 1227,
428 .tune0_low
= 0xffead0ff,
435 .min_millivolts
= 870,
436 .max_millivolts
= 1227,
439 .tune0_low
= 0xffead0ff,
446 .min_millivolts
= 837,
447 .max_millivolts
= 1227,
450 .tune0_low
= 0xffead0ff,
451 .tune0_high
= 0xffead0ff,
453 .tune_high_min_millivolts
= 864,
459 .min_millivolts
= 837,
460 .max_millivolts
= 1227,
463 .tune0_low
= 0xffead0ff,
464 .tune0_high
= 0xffead0ff,
466 .tune_high_min_millivolts
= 864,
472 .min_millivolts
= 850,
473 .max_millivolts
= 1170,
476 .tune0_low
= 0xffead0ff,
477 .tune0_high
= 0xffead0ff,
479 .tune_high_min_millivolts
= 864,
485 .min_millivolts
= 850,
486 .max_millivolts
= 1170,
489 .tune0_low
= 0xffead0ff,
490 .tune0_high
= 0xffead0ff,
492 .tune_high_min_millivolts
= 864,
497 static const struct dfll_fcpu_data tegra124_dfll_fcpu_data
= {
498 .cpu_max_freq_table
= tegra124_cpu_max_freq_table
,
499 .cpu_max_freq_table_size
= ARRAY_SIZE(tegra124_cpu_max_freq_table
),
500 .cpu_cvb_tables
= tegra124_cpu_cvb_tables
,
501 .cpu_cvb_tables_size
= ARRAY_SIZE(tegra124_cpu_cvb_tables
)
504 static const struct dfll_fcpu_data tegra210_dfll_fcpu_data
= {
505 .cpu_max_freq_table
= tegra210_cpu_max_freq_table
,
506 .cpu_max_freq_table_size
= ARRAY_SIZE(tegra210_cpu_max_freq_table
),
507 .cpu_cvb_tables
= tegra210_cpu_cvb_tables
,
508 .cpu_cvb_tables_size
= ARRAY_SIZE(tegra210_cpu_cvb_tables
),
511 static const struct of_device_id tegra124_dfll_fcpu_of_match
[] = {
513 .compatible
= "nvidia,tegra124-dfll",
514 .data
= &tegra124_dfll_fcpu_data
,
517 .compatible
= "nvidia,tegra210-dfll",
518 .data
= &tegra210_dfll_fcpu_data
523 static void get_alignment_from_dt(struct device
*dev
,
524 struct rail_alignment
*align
)
526 if (of_property_read_u32(dev
->of_node
,
527 "nvidia,pwm-voltage-step-microvolts",
531 if (of_property_read_u32(dev
->of_node
,
532 "nvidia,pwm-min-microvolts",
534 align
->offset_uv
= 0;
537 static int get_alignment_from_regulator(struct device
*dev
,
538 struct rail_alignment
*align
)
540 struct regulator
*reg
= devm_regulator_get(dev
, "vdd-cpu");
545 align
->offset_uv
= regulator_list_voltage(reg
, 0);
546 align
->step_uv
= regulator_get_linear_step(reg
);
548 devm_regulator_put(reg
);
553 static int tegra124_dfll_fcpu_probe(struct platform_device
*pdev
)
555 int process_id
, speedo_id
, speedo_value
, err
;
556 struct tegra_dfll_soc_data
*soc
;
557 const struct dfll_fcpu_data
*fcpu_data
;
558 struct rail_alignment align
;
560 fcpu_data
= of_device_get_match_data(&pdev
->dev
);
564 process_id
= tegra_sku_info
.cpu_process_id
;
565 speedo_id
= tegra_sku_info
.cpu_speedo_id
;
566 speedo_value
= tegra_sku_info
.cpu_speedo_value
;
568 if (speedo_id
>= fcpu_data
->cpu_max_freq_table_size
) {
569 dev_err(&pdev
->dev
, "unknown max CPU freq for speedo_id=%d\n",
574 soc
= devm_kzalloc(&pdev
->dev
, sizeof(*soc
), GFP_KERNEL
);
578 soc
->dev
= get_cpu_device(0);
580 dev_err(&pdev
->dev
, "no CPU0 device\n");
584 if (of_property_read_bool(pdev
->dev
.of_node
, "nvidia,pwm-to-pmic")) {
585 get_alignment_from_dt(&pdev
->dev
, &align
);
587 err
= get_alignment_from_regulator(&pdev
->dev
, &align
);
592 soc
->max_freq
= fcpu_data
->cpu_max_freq_table
[speedo_id
];
594 soc
->cvb
= tegra_cvb_add_opp_table(soc
->dev
, fcpu_data
->cpu_cvb_tables
,
595 fcpu_data
->cpu_cvb_tables_size
,
596 &align
, process_id
, speedo_id
,
597 speedo_value
, soc
->max_freq
);
598 soc
->alignment
= align
;
600 if (IS_ERR(soc
->cvb
)) {
601 dev_err(&pdev
->dev
, "couldn't add OPP table: %ld\n",
603 return PTR_ERR(soc
->cvb
);
606 err
= tegra_dfll_register(pdev
, soc
);
608 tegra_cvb_remove_opp_table(soc
->dev
, soc
->cvb
, soc
->max_freq
);
615 static int tegra124_dfll_fcpu_remove(struct platform_device
*pdev
)
617 struct tegra_dfll_soc_data
*soc
;
619 soc
= tegra_dfll_unregister(pdev
);
621 dev_err(&pdev
->dev
, "failed to unregister DFLL: %ld\n",
626 tegra_cvb_remove_opp_table(soc
->dev
, soc
->cvb
, soc
->max_freq
);
631 static const struct dev_pm_ops tegra124_dfll_pm_ops
= {
632 SET_RUNTIME_PM_OPS(tegra_dfll_runtime_suspend
,
633 tegra_dfll_runtime_resume
, NULL
)
634 SET_SYSTEM_SLEEP_PM_OPS(tegra_dfll_suspend
, tegra_dfll_resume
)
637 static struct platform_driver tegra124_dfll_fcpu_driver
= {
638 .probe
= tegra124_dfll_fcpu_probe
,
639 .remove
= tegra124_dfll_fcpu_remove
,
641 .name
= "tegra124-dfll",
642 .of_match_table
= tegra124_dfll_fcpu_of_match
,
643 .pm
= &tegra124_dfll_pm_ops
,
646 builtin_platform_driver(tegra124_dfll_fcpu_driver
);