2 * Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/clk.h>
20 #include <linux/clk-provider.h>
21 #include <linux/of_address.h>
22 #include <linux/thermal.h>
23 #include <linux/regulator/consumer.h>
25 #include <soc/tegra/cvb.h>
26 #include <soc/tegra/tegra-dfll.h>
27 #include <soc/tegra/tegra-dvfs.h>
28 #include <soc/tegra/fuse.h>
29 #include <soc/tegra/tegra_emc.h>
31 #include <dt-bindings/thermal/tegra210b01-trips.h>
35 #define VDD_SAFE_STEP 100
37 /* Margin % applied to PLL CVB tables */
38 #define CVB_PLL_MARGIN 30
40 #define VDD_CPU_INDEX 0
41 #define VDD_CORE_INDEX 1
42 #define VDD_GPU_INDEX 2
44 struct tegra_dvfs_data {
45 struct dvfs_rail **rails;
47 struct cpu_dvfs *cpu_fv_table;
48 int cpu_fv_table_size;
49 struct cvb_dvfs *gpu_cvb_table;
50 int gpu_cvb_table_size;
51 struct dvb_dvfs *emc_dvb_table;
52 int emc_dvb_table_size;
55 struct dvfs *core_vf_table;
56 int core_vf_table_size;
57 struct dvfs *spi_vf_table;
58 struct dvfs *spi_slave_vf_table;
59 struct dvfs *qspi_sdr_vf_table;
60 struct dvfs *qspi_ddr_vf_table;
61 struct dvfs *sor1_dp_vf_table;
62 int sor1_dp_vf_table_size;
63 int (*get_core_min_mv)(void);
64 int (*get_core_max_mv)(void);
66 struct dvfs_therm_limits *core_floors;
67 struct dvfs_therm_limits *core_caps;
68 struct dvfs_therm_limits *core_caps_ucm2;
69 const char *core_dvfs_ver;
72 static struct tegra_dvfs_data *dvfs_data;
74 static bool tegra_dvfs_cpu_disabled;
75 static bool tegra_dvfs_core_disabled;
76 static bool tegra_dvfs_gpu_disabled;
77 static int cpu_millivolts[MAX_DVFS_FREQS];
78 static int cpu_dfll_millivolts[MAX_DVFS_FREQS];
79 static int cpu_lp_millivolts[MAX_DVFS_FREQS];
81 static struct dvfs_therm_limits
82 tegra210_core_therm_floors[MAX_THERMAL_LIMITS] = {
87 static struct dvfs_therm_limits
88 tegra210_core_therm_caps[MAX_THERMAL_LIMITS] = {
93 static struct dvfs_therm_limits
94 tegra210_core_therm_caps_ucm2[MAX_THERMAL_LIMITS] = {
99 static struct dvfs_therm_limits
100 tegra210b01_core_therm_floors[MAX_THERMAL_LIMITS] = {
101 {TEGRA210B01_SOC_THERMAL_FLOOR_0 / 1000, 800},
105 static struct dvfs_therm_limits
106 tegra210b01_core_therm_caps[MAX_THERMAL_LIMITS] = {
107 {TEGRA210B01_SOC_THERMAL_CAP_0 / 1000, 1010},
111 static struct dvfs_therm_limits
112 tegra210b01_core_therm_caps_ucm2[MAX_THERMAL_LIMITS] = {
113 {TEGRA210B01_SOC_THERMAL_CAP_0 / 1000, 1010},
118 static struct dvfs_rail tegra210_dvfs_rail_vdd_cpu = {
120 .max_millivolts = 1300,
121 .min_millivolts = 800,
122 .step = VDD_SAFE_STEP,
127 .step_uv = 6250, /* 6.25mV */
130 .bin_uv = 6250, /* 6.25mV */
135 static struct dvfs_rail tegra210_dvfs_rail_vdd_core = {
136 .reg_id = "vdd-core",
137 .max_millivolts = 1300,
138 .step = VDD_SAFE_STEP,
141 .step_uv = 12500, /* 12.5mV */
144 .bin_uv = 12500, /* 12.5mV */
149 static struct dvfs_rail tegra210_dvfs_rail_vdd_gpu = {
151 .max_millivolts = 1300,
152 .step = VDD_SAFE_STEP,
155 .step_uv = 10000, /* 10mV */
158 .bin_uv = 10000, /* 10mV */
163 static struct dvfs_rail *tegra210_dvfs_rails[] = {
164 [VDD_CPU_INDEX] = &tegra210_dvfs_rail_vdd_cpu,
165 [VDD_CORE_INDEX] = &tegra210_dvfs_rail_vdd_core,
166 [VDD_GPU_INDEX] = &tegra210_dvfs_rail_vdd_gpu,
169 static struct dvfs_rail tegra210b01_dvfs_rail_vdd_core = {
170 .reg_id = "vdd-core",
171 .max_millivolts = 1300,
172 .step = VDD_SAFE_STEP,
175 .step_uv = 12500, /* 12.5mV */
178 .bin_uv = 12500, /* 12.5mV */
182 static struct dvfs_rail tegra210b01_dvfs_rail_vdd_cpu = {
184 .max_millivolts = 1125,
185 .step = VDD_SAFE_STEP,
190 .step_uv = 5000, /* 5.0mV */
193 .bin_uv = 5000, /* 5.0mV */
197 static struct dvfs_rail tegra210b01_dvfs_rail_vdd_gpu = {
199 .max_millivolts = 1125,
200 .step = VDD_SAFE_STEP,
203 .step_uv = 5000, /* 5mV */
206 .bin_uv = 5000, /* 10mV */
208 .vts_floors_table = /* applied if no vts cdev */
209 { {TEGRA210B01_GPU_DVFS_THERMAL_MIN / 1000, 800 }, },
213 static struct dvfs_rail *tegra210b01_dvfs_rails[] = {
214 [VDD_CPU_INDEX] = &tegra210b01_dvfs_rail_vdd_cpu,
215 [VDD_CORE_INDEX] = &tegra210b01_dvfs_rail_vdd_core,
216 [VDD_GPU_INDEX] = &tegra210b01_dvfs_rail_vdd_gpu,
219 static struct dvfs_rail vdd_cpu_rail;
220 static struct dvfs_rail vdd_gpu_rail;
221 static struct dvfs_rail vdd_core_rail;
223 static struct dvfs_rail *vdd_dvfs_rails[] = {
224 [VDD_CPU_INDEX] = &vdd_cpu_rail,
225 [VDD_CORE_INDEX] = &vdd_core_rail,
226 [VDD_GPU_INDEX] = &vdd_gpu_rail,
229 static struct dvfs cpu_dvfs = {
230 .clk_name = "cclk_g",
231 .millivolts = cpu_millivolts,
232 .dfll_millivolts = cpu_dfll_millivolts,
234 .dvfs_rail = &vdd_cpu_rail,
237 /* CPU DVFS tables */
238 #define CPU_PLL_CVB_TABLE \
239 .pll_min_millivolts = 950, \
240 .speedo_scale = 100, \
241 .voltage_scale = 1000, \
243 {204000000UL, { 0, 0, 0 } }, \
244 {306000000UL, { 0, 0, 0 } }, \
245 {408000000UL, { 0, 0, 0 } }, \
246 {510000000UL, { 0, 0, 0 } }, \
247 {612000000UL, { 0, 0, 0 } }, \
248 {714000000UL, { 0, 0, 0 } }, \
249 {816000000UL, { 0, 0, 0 } }, \
250 {918000000UL, { 0, 0, 0 } }, \
251 {1020000000UL, { -2875621, 358099, -8585 } }, \
252 {1122000000UL, { -52225, 104159, -2816 } }, \
253 {1224000000UL, { 1076868, 8356, -727 } }, \
254 {1326000000UL, { 2208191, -84659, 1240 } }, \
255 {1428000000UL, { 2519460, -105063, 1611 } }, \
256 {1530000000UL, { 2639809, -108729, 1626 } }, \
257 {1632000000UL, { 2889664, -122173, 1834 } }, \
258 {1734000000UL, { 3386160, -154021, 2393 } }, \
259 {1836000000UL, { 5100873, -279186, 4747 } }, \
260 {1912500000UL, { 5100873, -279186, 4747 } }, \
261 {2014500000UL, { 5100873, -279186, 4747 } }, \
262 {2218500000UL, { 5100873, -279186, 4747 } }, \
266 #define CPU_PLL_CVB_TABLE_XA \
267 .pll_min_millivolts = 950, \
268 .speedo_scale = 100, \
269 .voltage_scale = 1000, \
271 {204000000UL, { 0, 0, 0 } }, \
272 {306000000UL, { 0, 0, 0 } }, \
273 {408000000UL, { 0, 0, 0 } }, \
274 {510000000UL, { 0, 0, 0 } }, \
275 {612000000UL, { 0, 0, 0 } }, \
276 {714000000UL, { 0, 0, 0 } }, \
277 {816000000UL, { 0, 0, 0 } }, \
278 {918000000UL, { 0, 0, 0 } }, \
279 {1020000000UL, { -2875621, 358099, -8585 } }, \
280 {1122000000UL, { -52225, 104159, -2816 } }, \
281 {1224000000UL, { 1076868, 8356, -727 } }, \
282 {1326000000UL, { 2208191, -84659, 1240 } }, \
283 {1428000000UL, { 2519460, -105063, 1611 } }, \
284 {1530000000UL, { 2639809, -108729, 1626 } }, \
285 {1606500000UL, { 2889664, -122173, 1834 } }, \
286 {1632000000UL, { 3386160, -154021, 2393 } }, \
290 #define CPU_PLL_CVB_TABLE_EUCM1 \
291 .pll_min_millivolts = 950, \
292 .speedo_scale = 100, \
293 .voltage_scale = 1000, \
295 {204000000UL, { 0, 0, 0 } }, \
296 {306000000UL, { 0, 0, 0 } }, \
297 {408000000UL, { 0, 0, 0 } }, \
298 {510000000UL, { 0, 0, 0 } }, \
299 {612000000UL, { 0, 0, 0 } }, \
300 {714000000UL, { 0, 0, 0 } }, \
301 {816000000UL, { 0, 0, 0 } }, \
302 {918000000UL, { 0, 0, 0 } }, \
303 {1020000000UL, { -2875621, 358099, -8585 } }, \
304 {1122000000UL, { -52225, 104159, -2816 } }, \
305 {1224000000UL, { 1076868, 8356, -727 } }, \
306 {1326000000UL, { 2208191, -84659, 1240 } }, \
307 {1428000000UL, { 2519460, -105063, 1611 } }, \
308 {1555500000UL, { 2639809, -108729, 1626 } }, \
309 {1632000000UL, { 2889664, -122173, 1834 } }, \
310 {1734000000UL, { 3386160, -154021, 2393 } }, \
314 #define CPU_PLL_CVB_TABLE_EUCM2 \
315 .pll_min_millivolts = 950, \
316 .speedo_scale = 100, \
317 .voltage_scale = 1000, \
319 {204000000UL, { 0, 0, 0 } }, \
320 {306000000UL, { 0, 0, 0 } }, \
321 {408000000UL, { 0, 0, 0 } }, \
322 {510000000UL, { 0, 0, 0 } }, \
323 {612000000UL, { 0, 0, 0 } }, \
324 {714000000UL, { 0, 0, 0 } }, \
325 {816000000UL, { 0, 0, 0 } }, \
326 {918000000UL, { 0, 0, 0 } }, \
327 {1020000000UL, { -2875621, 358099, -8585 } }, \
328 {1122000000UL, { -52225, 104159, -2816 } }, \
329 {1224000000UL, { 1076868, 8356, -727 } }, \
330 {1326000000UL, { 2208191, -84659, 1240 } }, \
331 {1479000000UL, { 2519460, -105063, 1611 } }, \
332 {1555500000UL, { 2639809, -108729, 1626 } }, \
333 {1683000000UL, { 2889664, -122173, 1834 } }, \
337 #define CPU_PLL_CVB_TABLE_EUCM2_JOINT_RAIL \
338 .pll_min_millivolts = 950, \
339 .speedo_scale = 100, \
340 .voltage_scale = 1000, \
342 {204000000UL, { 0, 0, 0 } }, \
343 {306000000UL, { 0, 0, 0 } }, \
344 {408000000UL, { 0, 0, 0 } }, \
345 {510000000UL, { 0, 0, 0 } }, \
346 {612000000UL, { 0, 0, 0 } }, \
347 {714000000UL, { 0, 0, 0 } }, \
348 {816000000UL, { 0, 0, 0 } }, \
349 {918000000UL, { 0, 0, 0 } }, \
350 {1020000000UL, { -2875621, 358099, -8585 } }, \
351 {1122000000UL, { -52225, 104159, -2816 } }, \
352 {1224000000UL, { 1076868, 8356, -727 } }, \
353 {1326000000UL, { 2208191, -84659, 1240 } }, \
354 {1479000000UL, { 2519460, -105063, 1611 } }, \
355 {1504500000UL, { 2639809, -108729, 1626 } }, \
359 #define CPU_PLL_CVB_TABLE_ODN \
360 .pll_min_millivolts = 950, \
361 .speedo_scale = 100, \
362 .voltage_scale = 1000, \
364 {204000000UL, { 0, 0, 0 } }, \
365 {306000000UL, { 0, 0, 0 } }, \
366 {408000000UL, { 0, 0, 0 } }, \
367 {510000000UL, { 0, 0, 0 } }, \
368 {612000000UL, { 0, 0, 0 } }, \
369 {714000000UL, { 0, 0, 0 } }, \
370 {816000000UL, { 0, 0, 0 } }, \
371 {918000000UL, { 0, 0, 0 } }, \
372 {1020000000UL, { -2875621, 358099, -8585 } }, \
373 {1122000000UL, { -52225, 104159, -2816 } }, \
374 {1224000000UL, { 1076868, 8356, -727 } }, \
375 {1326000000UL, { 2208191, -84659, 1240 } }, \
376 {1428000000UL, { 2519460, -105063, 1611 } }, \
377 {1581000000UL, { 2889664, -122173, 1834 } }, \
378 {1683000000UL, { 5100873, -279186, 4747 } }, \
379 {1785000000UL, { 5100873, -279186, 4747 } }, \
383 static struct cpu_dvfs cpu_fv_dvfs_table[] = {
389 CPU_PLL_CVB_TABLE_EUCM2_JOINT_RAIL,
396 CPU_PLL_CVB_TABLE_EUCM2_JOINT_RAIL,
403 CPU_PLL_CVB_TABLE_EUCM2,
410 CPU_PLL_CVB_TABLE_EUCM2,
417 CPU_PLL_CVB_TABLE_EUCM2,
424 CPU_PLL_CVB_TABLE_EUCM2,
431 CPU_PLL_CVB_TABLE_EUCM1,
438 CPU_PLL_CVB_TABLE_EUCM1,
473 CPU_PLL_CVB_TABLE_XA,
480 CPU_PLL_CVB_TABLE_ODN,
487 CPU_PLL_CVB_TABLE_ODN,
533 #define CPUB01_PLL_CVB_TABLE_SLT \
534 .speedo_scale = 100, \
535 .voltage_scale = 1000, \
538 { 204000000UL, { 0, 0, 0 } }, \
539 { 306000000UL, { 0, 0, 0 } }, \
540 { 408000000UL, { 0, 0, 0 } }, \
541 { 510000000UL, { 0, 0, 0 } }, \
542 { 612000000UL, { 0, 0, 0 } }, \
543 { 714000000UL, { 0, 0, 0 } }, \
544 { 816000000UL, { 0, 0, 0 } }, \
545 { 918000000UL, { 0, 0, 0 } }, \
546 { 1020000000UL, { 1120000, 0, 0 } }, \
547 { 1122000000UL, { 1120000, 0, 0 } }, \
548 { 1224000000UL, { 1120000, 0, 0 } }, \
549 { 1326000000UL, { 1120000, 0, 0 } }, \
550 { 1428000000UL, { 1120000, 0, 0 } }, \
551 { 1581000000UL, { 1120000, 0, 0 } }, \
552 { 1683000000UL, { 1120000, 0, 0 } }, \
553 { 1785000000UL, { 1120000, 0, 0 } }, \
554 { 1887000000UL, { 1120000, 0, 0 } }, \
555 { 1963500000UL, { 1120000, 0, 0 } }, \
556 { 2091000000UL, { 1120000, 0, 0 } }, \
559 .pll_min_millivolts = 800
561 #define CPUB01_PLL_CVB_TABLE \
562 .speedo_scale = 100, \
563 .voltage_scale = 1000, \
566 { 204000000UL, { 0, 0, 0 } }, \
567 { 306000000UL, { 0, 0, 0 } }, \
568 { 408000000UL, { 0, 0, 0 } }, \
569 { 510000000UL, { 0, 0, 0 } }, \
570 { 612000000UL, { 0, 0, 0 } }, \
571 { 714000000UL, { 0, 0, 0 } }, \
572 { 816000000UL, { 0, 0, 0 } }, \
573 { 918000000UL, { 0, 0, 0 } }, \
574 { 1020000000UL, { 1120000, 0, 0 } }, \
575 { 1122000000UL, { 1120000, 0, 0 } }, \
576 { 1224000000UL, { 1120000, 0, 0 } }, \
577 { 1326000000UL, { 1120000, 0, 0 } }, \
578 { 1428000000UL, { 1120000, 0, 0 } }, \
579 { 1581000000UL, { 1120000, 0, 0 } }, \
580 { 1683000000UL, { 1120000, 0, 0 } }, \
581 { 1785000000UL, { 1120000, 0, 0 } }, \
582 { 1887000000UL, { 1120000, 0, 0 } }, \
583 { 1963500000UL, { 1120000, 0, 0 } }, \
584 { 2014500000UL, { 1120000, 0, 0 } }, \
587 .pll_min_millivolts = 800
589 static struct cpu_dvfs cpub01_fv_dvfs_table[] = {
594 CPUB01_PLL_CVB_TABLE_SLT,
600 CPUB01_PLL_CVB_TABLE,
605 /* CPU LP DVFS tables */
606 static unsigned long cpu_lp_max_freq[] = {
607 /* speedo_id 0 1 2 3 4 5 */
608 1132800, 1132800, 1132800, 1132800, 940800, 1132800
611 #define CPU_LP_FV_TABLE \
628 static struct cpu_dvfs cpu_lp_fv_dvfs_table[] = {
659 static struct dvfs cpu_lp_dvfs = {
660 .clk_name = "cclk_lp",
661 .millivolts = cpu_lp_millivolts,
663 .dvfs_rail = &vdd_cpu_rail,
667 /* GPU DVFS tables */
668 #define NA_FREQ_CVB_TABLE \
670 .speedo_scale = 100, \
671 .thermal_scale = 10, \
672 .voltage_scale = 1000, \
674 /* f dfll pll: c0, c1, c2, c3, c4, c5 */ \
675 { 76800, { }, { 814294, 8144, -940, 808, -21583, 226 }, }, \
676 { 153600, { }, { 856185, 8144, -940, 808, -21583, 226 }, }, \
677 { 230400, { }, { 898077, 8144, -940, 808, -21583, 226 }, }, \
678 { 307200, { }, { 939968, 8144, -940, 808, -21583, 226 }, }, \
679 { 384000, { }, { 981860, 8144, -940, 808, -21583, 226 }, }, \
680 { 460800, { }, { 1023751, 8144, -940, 808, -21583, 226 }, }, \
681 { 537600, { }, { 1065642, 8144, -940, 808, -21583, 226 }, }, \
682 { 614400, { }, { 1107534, 8144, -940, 808, -21583, 226 }, }, \
683 { 691200, { }, { 1149425, 8144, -940, 808, -21583, 226 }, }, \
684 { 768000, { }, { 1191317, 8144, -940, 808, -21583, 226 }, }, \
685 { 844800, { }, { 1233208, 8144, -940, 808, -21583, 226 }, }, \
686 { 921600, { }, { 1275100, 8144, -940, 808, -21583, 226 }, }, \
687 { 998400, { }, { 1316991, 8144, -940, 808, -21583, 226 }, }, \
691 #define NA_FREQ_CVB_TABLE_XA \
693 .speedo_scale = 100, \
694 .thermal_scale = 10, \
695 .voltage_scale = 1000, \
697 /* f dfll pll: c0, c1, c2, c3, c4, c5 */ \
698 { 76800, { }, { 1526811, -59106, 963, 238, -11292, 185 }, }, \
699 { 153600, { }, { 1543573, -57798, 910, 179, -9918, 191 }, }, \
700 { 230400, { }, { 1567838, -56991, 869, 60, -8545, 203 }, }, \
701 { 307200, { }, { 1600241, -56742, 841, 0, -7019, 209 }, }, \
702 { 384000, { }, { 1635184, -56501, 813, 0, -5493, 221 }, }, \
703 { 460800, { }, { 1672308, -56300, 787, -119, -3662, 226 }, }, \
704 { 537600, { }, { 1712114, -56093, 759, -179, -1526, 238 }, }, \
705 { 614400, { }, { 1756009, -56048, 737, -298, 610, 244 }, }, \
706 { 691200, { }, { 1790251, -54860, 687, -358, 3204, 238 }, }, \
707 { 768000, { }, { 1783830, -49449, 532, -477, 6714, 197 }, }, \
708 { 844800, { }, { 1819706, -45928, 379, -358, 7019, 89 }, }, \
712 #define FIXED_FREQ_CVB_TABLE \
714 .speedo_scale = 100, \
715 .thermal_scale = 10, \
716 .voltage_scale = 1000, \
718 /* f dfll pll: c0, c1, c2 */ \
719 { 76800, { }, { 1786666, -85625, 1632 }, }, \
720 { 153600, { }, { 1846729, -87525, 1632 }, }, \
721 { 230400, { }, { 1910480, -89425, 1632 }, }, \
722 { 307200, { }, { 1977920, -91325, 1632 }, }, \
723 { 384000, { }, { 2049049, -93215, 1632 }, }, \
724 { 460800, { }, { 2122872, -95095, 1632 }, }, \
725 { 537600, { }, { 2201331, -96985, 1632 }, }, \
726 { 614400, { }, { 2283479, -98885, 1632 }, }, \
727 { 691200, { }, { 2369315, -100785, 1632 }, }, \
728 { 768000, { }, { 2458841, -102685, 1632 }, }, \
729 { 844800, { }, { 2550821, -104555, 1632 }, }, \
730 { 921600, { }, { 2647676, -106455, 1632 }, }, \
734 static struct dvfs gpu_dvfs = {
737 .dvfs_rail = &vdd_gpu_rail,
740 static struct cvb_dvfs gpu_cvb_dvfs_table[] = {
744 .pll_min_millivolts = 918,
747 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
748 NA_FREQ_CVB_TABLE_XA,
750 FIXED_FREQ_CVB_TABLE,
757 .pll_min_millivolts = 810,
760 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
763 FIXED_FREQ_CVB_TABLE,
770 .pll_min_millivolts = 818,
773 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
776 FIXED_FREQ_CVB_TABLE,
783 .pll_min_millivolts = 840,
786 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
789 FIXED_FREQ_CVB_TABLE,
796 .pll_min_millivolts = 950,
797 #ifdef CONFIG_TEGRA_GPU_DVFS
803 FIXED_FREQ_CVB_TABLE,
807 #define GPUB01_NA_CVB_TABLE_SLT \
809 .speedo_scale = 100, \
810 .thermal_scale = 10, \
811 .voltage_scale = 1000, \
813 /* f dfll pll: c0, c1, c2, c3, c4, c5 */ \
814 { 76800, { }, { 590000, 0, 0, 0, 0, 0 }, }, \
815 { 153600, { }, { 590000, 0, 0, 0, 0, 0 }, }, \
816 { 230400, { }, { 590000, 0, 0, 0, 0, 0 }, }, \
817 { 307200, { }, { 590000, 0, 0, 0, 0, 0 }, }, \
818 { 384000, { }, { 590000, 0, 0, 0, 0, 0 }, }, \
819 { 460800, { }, { 795089, -11096, -163, 298, -10421, 162 }, }, \
820 { 537600, { }, { 795089, -11096, -163, 298, -10421, 162 }, }, \
821 { 614400, { }, { 820606, -6285, -452, 238, -6182, 81 }, }, \
822 { 691200, { }, { 846289, -4565, -552, 119, -3958, -2 }, }, \
823 { 768000, { }, { 888720, -5110, -584, 0, -2849, 39 }, }, \
824 { 844800, { }, { 936634, -6089, -602, -60, -99, -93 }, }, \
825 { 921600, { }, { 982562, -7373, -614, -179, 1797, -13 }, }, \
826 { 998400, { }, { 1090179, -14125, -497, -179, 3518, 9 }, }, \
827 { 1075200, { }, { 1155798, -13465, -648, 0, 1077, 40 }, }, \
828 { 1152000, { }, { 1198568, -10904, -830, 0, 1469, 110 }, }, \
829 { 1228800, { }, { 1269988, -12707, -859, 0, 3722, 313 }, }, \
830 { 1267200, { }, { 1308155, -13694, -867, 0, 3681, 559 }, }, \
833 .cvb_vmin = { 0, { }, { 590000, 0, 0 }, }, \
834 .cvb_version = "NAPLL En - p4v2-AggressiveSLT"
836 #define GPUB01_NA_CVB_TABLE \
838 .speedo_scale = 100, \
839 .thermal_scale = 10, \
840 .voltage_scale = 1000, \
842 /* f dfll pll: c0, c1, c2, c3, c4, c5 */ \
843 { 76800, { }, { 610000, 0, 0, 0, 0, 0 }, }, \
844 { 153600, { }, { 610000, 0, 0, 0, 0, 0 }, }, \
845 { 230400, { }, { 610000, 0, 0, 0, 0, 0 }, }, \
846 { 307200, { }, { 610000, 0, 0, 0, 0, 0 }, }, \
847 { 384000, { }, { 610000, 0, 0, 0, 0, 0 }, }, \
848 { 460800, { }, { 610000, 0, 0, 0, 0, 0 }, }, \
849 { 537600, { }, { 801688, -10900, -163, 298, -10599, 162 }, }, \
850 { 614400, { }, { 824214, -5743, -452, 238, -6325, 81 }, }, \
851 { 691200, { }, { 848830, -3903, -552, 119, -4030, -2 }, }, \
852 { 768000, { }, { 891575, -4409, -584, 0, -2849, 39 }, }, \
853 { 844800, { }, { 940071, -5367, -602, -60, -63, -93 }, }, \
854 { 921600, { }, { 986765, -6637, -614, -179, 1905, -13 }, }, \
855 { 998400, { }, { 1098475, -13529, -497, -179, 3626, 9 }, }, \
856 { 1075200, { }, { 1163644, -12688, -648, 0, 1077, 40 }, }, \
857 { 1152000, { }, { 1204812, -9908, -830, 0, 1469, 110 }, }, \
858 { 1228800, { }, { 1277303, -11675, -859, 0, 3722, 313 }, }, \
859 { 1267200, { }, { 1335531, -12567, -867, 0, 3681, 559 }, }, \
862 .cvb_vmin = { 0, { }, { 610000, 0, 0 }, }, \
863 .cvb_version = "NAPLL En - p4v3"
865 static struct cvb_dvfs gpub01_cvb_dvfs_table[] = {
871 GPUB01_NA_CVB_TABLE_SLT,
882 static int gpu_vmin[MAX_THERMAL_RANGES];
883 static int gpu_peak_millivolts[MAX_DVFS_FREQS];
884 static int gpu_millivolts[MAX_THERMAL_RANGES][MAX_DVFS_FREQS];
885 static struct dvfs_therm_limits vdd_gpu_therm_caps_table[MAX_THERMAL_LIMITS];
886 static struct dvfs_therm_limits vdd_gpu_therm_caps_ucm2_table[MAX_THERMAL_LIMITS];
887 static unsigned long gpu_cap_rates[MAX_THERMAL_LIMITS];
888 static struct clk *vgpu_cap_clk;
890 /* Core DVFS tables */
891 static int core_millivolts[MAX_DVFS_FREQS];
893 #define CORE_DVFS(_clk_name, _speedo_id, _process_id, _auto, _mult, _freqs...) \
895 .clk_name = _clk_name, \
896 .speedo_id = _speedo_id, \
897 .process_id = _process_id, \
899 .freqs_mult = _mult, \
900 .millivolts = core_millivolts, \
901 .auto_dvfs = _auto, \
902 .dvfs_rail = &vdd_core_rail, \
906 /* Include T210 core DVFS tables generated from characterization data */
907 #include "tegra210-core-dvfs.c"
909 /* Include T210b01 core DVFS tables generated from characterization data */
910 #include "tegra210b01-core-dvfs.c"
911 #include "tegra210b01-slt-core-dvfs.c"
913 int tegra_dvfs_disable_core_set(const char *arg, const struct kernel_param *kp)
917 ret = param_set_bool(arg, kp);
921 if (tegra_dvfs_core_disabled)
922 tegra_dvfs_rail_disable(&vdd_core_rail);
924 tegra_dvfs_rail_enable(&vdd_core_rail);
929 int tegra_dvfs_disable_cpu_set(const char *arg, const struct kernel_param *kp)
933 ret = param_set_bool(arg, kp);
937 if (tegra_dvfs_cpu_disabled)
938 tegra_dvfs_rail_disable(&vdd_cpu_rail);
940 tegra_dvfs_rail_enable(&vdd_cpu_rail);
945 int tegra_dvfs_disable_gpu_set(const char *arg, const struct kernel_param *kp)
949 ret = param_set_bool(arg, kp);
953 if (tegra_dvfs_gpu_disabled)
954 tegra_dvfs_rail_disable(&vdd_gpu_rail);
956 tegra_dvfs_rail_enable(&vdd_gpu_rail);
961 int tegra_dvfs_disable_get(char *buffer, const struct kernel_param *kp)
963 return param_get_bool(buffer, kp);
966 static struct kernel_param_ops tegra_dvfs_disable_core_ops = {
967 .set = tegra_dvfs_disable_core_set,
968 .get = tegra_dvfs_disable_get,
971 static struct kernel_param_ops tegra_dvfs_disable_cpu_ops = {
972 .set = tegra_dvfs_disable_cpu_set,
973 .get = tegra_dvfs_disable_get,
976 static struct kernel_param_ops tegra_dvfs_disable_gpu_ops = {
977 .set = tegra_dvfs_disable_gpu_set,
978 .get = tegra_dvfs_disable_get,
981 module_param_cb(disable_core, &tegra_dvfs_disable_core_ops,
982 &tegra_dvfs_core_disabled, 0644);
983 module_param_cb(disable_cpu, &tegra_dvfs_disable_cpu_ops,
984 &tegra_dvfs_cpu_disabled, 0644);
985 module_param_cb(disable_gpu, &tegra_dvfs_disable_gpu_ops,
986 &tegra_dvfs_gpu_disabled, 0644);
988 static void init_dvfs_one(struct dvfs *d, int max_freq_index)
991 struct clk *c = clk_get_sys(d->clk_name, d->clk_name);
994 pr_info("tegra210_dvfs: no clock found for %s\n",
999 d->max_millivolts = d->dvfs_rail->nominal_millivolts;
1000 d->num_freqs = max_freq_index + 1;
1002 ret = tegra_setup_dvfs(c, d);
1004 pr_err("tegra210_dvfs: failed to enable dvfs on %s\n",
1008 static bool match_dvfs_one(const char *name, int dvfs_speedo_id,
1009 int dvfs_process_id, int speedo_id, int process_id)
1011 if ((dvfs_process_id != -1 && dvfs_process_id != process_id) ||
1012 (dvfs_speedo_id != -1 && dvfs_speedo_id != speedo_id)) {
1013 pr_debug("tegra210_dvfs: rejected %s speedo %d, process %d\n",
1014 name, dvfs_speedo_id, dvfs_process_id);
1020 static int set_cpu_dvfs_data(struct cpu_dvfs *d,
1021 struct dvfs *cpu_dvfs, int *max_freq_index)
1023 int i, mv, dfll_mv, min_mv, min_dfll_mv, num_freqs;
1024 unsigned long fmax_at_vmin = 0;
1025 unsigned long fmin_use_dfll = 0;
1026 unsigned long *freqs;
1027 int *dfll_millivolts;
1028 struct rail_alignment *align = tegra_dfll_get_alignment();
1029 const char *version = tegra_dfll_get_cvb_version();
1030 int speedo = tegra_sku_info.cpu_speedo_value;
1032 if (align == ERR_PTR(-EPROBE_DEFER))
1033 return -EPROBE_DEFER;
1035 vdd_cpu_rail.nvver = version;
1037 min_dfll_mv = d->min_mv;
1038 if (min_dfll_mv < vdd_cpu_rail.min_millivolts) {
1039 pr_debug("tegra210_dvfs: dfll min %dmV below rail min %dmV\n",
1040 min_dfll_mv, vdd_cpu_rail.min_millivolts);
1041 min_dfll_mv = vdd_cpu_rail.min_millivolts;
1043 min_dfll_mv = tegra_round_voltage(min_dfll_mv, align, true);
1044 d->max_mv = tegra_round_voltage(d->max_mv, align, false);
1046 min_mv = d->pll_min_millivolts;
1047 if (min_mv < vdd_cpu_rail.min_millivolts) {
1048 pr_debug("tegra210_dvfs: pll min %dmV below rail min %dmV\n",
1049 min_mv, vdd_cpu_rail.min_millivolts);
1050 min_mv = vdd_cpu_rail.min_millivolts;
1052 min_mv = tegra_round_voltage(min_mv, align, true);
1054 if (tegra_get_cpu_fv_table(&num_freqs, &freqs, &dfll_millivolts))
1055 return -EPROBE_DEFER;
1057 for (i = 0; i < num_freqs; i++) {
1058 if (freqs[i] != d->cvb_pll_table[i].freq) {
1059 pr_err("Err: DFLL freq ladder does not match PLL's\n");
1064 * Check maximum frequency at minimum voltage for dfll source;
1065 * round down unless all table entries are above Vmin, then use
1066 * the 1st entry as is.
1068 dfll_mv = max(dfll_millivolts[i] / 1000, min_dfll_mv);
1069 if (dfll_mv > min_dfll_mv) {
1071 fmax_at_vmin = freqs[i];
1073 fmax_at_vmin = freqs[i - 1];
1076 /* Clip maximum frequency at maximum voltage for pll source */
1077 mv = tegra_get_cvb_voltage(speedo, d->speedo_scale,
1078 &d->cvb_pll_table[i].coefficients);
1079 mv = (100 + CVB_PLL_MARGIN) * mv / 100;
1080 mv = tegra_round_cvb_voltage(mv, d->voltage_scale, align);
1081 mv = max(mv, min_mv);
1082 if ((mv > d->max_mv) && !i) {
1083 pr_err("Err: volt of 1st entry is higher than Vmax\n");
1087 /* Minimum rate with pll source voltage above dfll Vmin */
1088 if ((mv >= min_dfll_mv) && !fmin_use_dfll)
1089 fmin_use_dfll = freqs[i];
1091 /* fill in dvfs tables */
1092 cpu_dvfs->freqs[i] = freqs[i];
1093 cpu_millivolts[i] = mv;
1094 cpu_dfll_millivolts[i] = min(dfll_mv, d->max_mv);
1098 * In the dfll operating range dfll voltage at any rate should be
1099 * better (below) than pll voltage
1101 if (!fmin_use_dfll || (fmin_use_dfll > fmax_at_vmin))
1102 fmin_use_dfll = fmax_at_vmin;
1104 /* dvfs tables are successfully populated - fill in the rest */
1105 cpu_dvfs->speedo_id = d->speedo_id;
1106 cpu_dvfs->process_id = d->process_id;
1107 cpu_dvfs->dvfs_rail->nominal_millivolts = min(d->max_mv,
1108 max(cpu_millivolts[i - 1], cpu_dfll_millivolts[i - 1]));
1109 *max_freq_index = i - 1;
1111 cpu_dvfs->use_dfll_rate_min = fmin_use_dfll;
1117 * Setup slow CPU (a.k.a LP CPU) DVFS table from FV data. Only PLL is used as
1118 * a clock source for slow CPU. Its maximum frequency must be reached within
1119 * nominal voltage -- FV frequency list is cut off at rate that exceeds either
1120 * sku-based maximum limit or requires voltage above nominal. Error when DVFS
1121 * table can not be constructed must never happen.
1123 * Final CPU rail nominal voltage is set as maximum of fast and slow CPUs
1126 static int set_cpu_lp_dvfs_data(unsigned long max_freq, struct cpu_dvfs *d,
1127 struct dvfs *cpu_lp_dvfs, int *max_freq_index)
1130 struct rail_alignment *align = &vdd_cpu_rail.alignment;
1133 if (min_mv < vdd_cpu_rail.min_millivolts) {
1134 pr_debug("tegra210_dvfs: scpu min %dmV below rail min %dmV\n",
1135 min_mv, vdd_cpu_rail.min_millivolts);
1136 min_mv = vdd_cpu_rail.min_millivolts;
1138 min_mv = tegra_round_voltage(min_mv, align, true);
1140 d->max_mv = tegra_round_voltage(d->max_mv, align, false);
1141 BUG_ON(d->max_mv > vdd_cpu_rail.max_millivolts);
1142 cpu_lp_dvfs->dvfs_rail->nominal_millivolts =
1143 max(cpu_lp_dvfs->dvfs_rail->nominal_millivolts, d->max_mv);
1145 for (i = 0; i < MAX_DVFS_FREQS; i++) {
1146 struct cpu_pll_fv_table *t = &d->fv_table[i];
1147 if (!t->freq || t->freq > max_freq)
1151 mv = max(mv, min_mv);
1152 if (mv > d->max_mv) {
1153 pr_warn("tegra210_dvfs: %dmV for %s rate %d above limit %dmV\n",
1154 mv, cpu_lp_dvfs->clk_name, t->freq, d->max_mv);
1158 /* fill in dvfs tables */
1159 cpu_lp_dvfs->freqs[i] = t->freq;
1160 cpu_lp_millivolts[i] = mv;
1163 /* Table must not be empty */
1165 pr_err("tegra210_dvfs: invalid cpu lp dvfs table\n");
1169 /* dvfs tables are successfully populated - fill in the rest */
1170 cpu_lp_dvfs->speedo_id = d->speedo_id;
1171 cpu_lp_dvfs->process_id = d->process_id;
1172 *max_freq_index = i - 1;
1177 int of_tegra_dvfs_init(const struct of_device_id *matches)
1180 struct device_node *np;
1182 for_each_matching_node(np, matches) {
1183 const struct of_device_id *match = of_match_node(matches, np);
1184 int (*dvfs_init_cb)(struct device_node *) = match->data;
1186 ret = dvfs_init_cb(np);
1188 pr_err("dt: Failed to read %s data from DT\n",
1197 * QSPI DVFS tables are different in SDR and DDR modes. Use SDR tables by
1198 * default. Check if DDR mode is specified for enabled QSPI device in DT,
1199 * and overwrite DVFS table, respectively.
1202 static struct dvfs *qspi_dvfs;
1204 static int of_update_qspi_dvfs(struct device_node *dn)
1206 if (of_device_is_available(dn)) {
1207 if (of_get_property(dn, "nvidia,x4-is-ddr", NULL))
1208 qspi_dvfs = &dvfs_data->qspi_ddr_vf_table[0];
1213 static struct of_device_id tegra210_dvfs_qspi_of_match[] = {
1214 { .compatible = "nvidia,tegra210-qspi", .data = of_update_qspi_dvfs, },
1218 static void init_qspi_dvfs(int soc_speedo_id, int core_process_id,
1219 int core_nominal_mv_index)
1221 qspi_dvfs = &dvfs_data->qspi_sdr_vf_table[0];
1223 of_tegra_dvfs_init(tegra210_dvfs_qspi_of_match);
1225 if (match_dvfs_one(qspi_dvfs->clk_name, qspi_dvfs->speedo_id,
1226 qspi_dvfs->process_id, soc_speedo_id, core_process_id))
1227 init_dvfs_one(qspi_dvfs, core_nominal_mv_index);
1231 * SPI DVFS tables are different in master and in slave mode. Use master tables
1232 * by default. Check if slave mode is specified for enabled SPI devices in DT,
1233 * and overwrite master table for the respective SPI controller.
1246 static int of_update_spi_slave_dvfs(struct device_node *dn)
1252 if (!of_device_is_available(dn))
1255 reg = of_get_property(dn, "reg", NULL);
1257 addr = of_translate_address(dn, reg);
1259 for (i = 0; i < ARRAY_SIZE(spi_map); i++) {
1260 if (spi_map[i].address == addr) {
1261 spi_map[i].d = &dvfs_data->spi_slave_vf_table[i];
1268 static struct of_device_id tegra21_dvfs_spi_slave_of_match[] = {
1269 { .compatible = "nvidia,tegra210-spi-slave",
1270 .data = of_update_spi_slave_dvfs, },
1274 static void init_spi_dvfs(int soc_speedo_id, int core_process_id,
1275 int core_nominal_mv_index)
1279 for (i = 0; i < ARRAY_SIZE(spi_map); i++)
1280 spi_map[i].d = &dvfs_data->spi_vf_table[i];
1282 of_tegra_dvfs_init(tegra21_dvfs_spi_slave_of_match);
1284 for (i = 0; i < ARRAY_SIZE(spi_map); i++) {
1285 struct dvfs *d = spi_map[i].d;
1286 if (!match_dvfs_one(d->clk_name, d->speedo_id,
1287 d->process_id, soc_speedo_id, core_process_id))
1289 init_dvfs_one(d, core_nominal_mv_index);
1293 static void init_sor1_dvfs(int soc_speedo_id, int core_process_id,
1294 int core_nominal_mv_index)
1296 struct dvfs *sor1_dp_dvfs = &dvfs_data->sor1_dp_vf_table[0];
1298 int i, n = dvfs_data->sor1_dp_vf_table_size;
1300 c = clk_get_sys(sor1_dp_dvfs->clk_name, sor1_dp_dvfs->clk_name);
1302 pr_debug("init_sor1_dvfs: no clock found for %s\n",
1303 sor1_dp_dvfs->clk_name);
1307 for (i = 0; i < n; i++, sor1_dp_dvfs++) {
1308 if (match_dvfs_one(sor1_dp_dvfs->clk_name,
1309 sor1_dp_dvfs->speedo_id, sor1_dp_dvfs->process_id,
1310 soc_speedo_id, core_process_id)) {
1311 tegra_dvfs_add_alt_freqs(c, sor1_dp_dvfs);
1320 static int get_core_sku_max_mv(void)
1322 int speedo_rev = tegra_sku_info.speedo_rev;
1324 switch (tegra_sku_info.soc_process_id) {
1326 if (tegra_sku_info.soc_speedo_id == 1)
1328 if (speedo_rev <= 1)
1337 pr_err("Un-supported Tegra210 speedo %d\n",
1338 tegra_sku_info.soc_speedo_id);
1343 static int get_core_sku_min_mv(void)
1345 int rev = tegra_sku_info.revision;
1346 bool a02 = (rev == TEGRA_REVISION_A02) || (rev == TEGRA_REVISION_A02p);
1348 if (tegra_sku_info.soc_speedo_id == 1)
1351 switch (tegra_sku_info.sku_id) {
1370 static int get_coreb01_sku_max_mv(void)
1372 switch (tegra_sku_info.soc_process_id) {
1380 pr_err("Un-supported Tegra210b01 process id %d\n",
1381 tegra_sku_info.soc_process_id);
1386 static int get_coreb01slt_sku_max_mv(void)
1388 return get_coreb01_sku_max_mv();
1391 static int get_coreb01_sku_min_mv(void)
1396 static int get_coreb01slt_sku_min_mv(void)
1401 static int get_core_nominal_mv_index(int speedo_id)
1404 int mv = dvfs_data->get_core_max_mv();
1409 /* Round nominal level down to the nearest core scaling step */
1410 for (i = 0; i < MAX_DVFS_FREQS; i++) {
1411 if ((core_millivolts[i] == 0) || (mv < core_millivolts[i]))
1416 pr_err("tegra210-dvfs: failed to get nominal idx at volt %d\n",
1424 static int get_core_min_mv_index(void)
1427 int mv = dvfs_data->get_core_min_mv();
1432 /* Round minimum level up to the nearest core scaling step */
1433 for (i = 0; i < MAX_DVFS_FREQS - 1; i++) {
1434 if ((core_millivolts[i+1] == 0) || (mv <= core_millivolts[i]))
1441 static int init_cpu_dvfs_table(struct cpu_dvfs *fv_dvfs_table,
1442 int table_size, int *cpu_max_freq_index)
1445 int cpu_speedo_id = tegra_sku_info.cpu_speedo_id;
1446 int cpu_process_id = tegra_sku_info.cpu_process_id;
1448 for (ret = 0, i = 0; i < table_size; i++) {
1449 struct cpu_dvfs *d = &fv_dvfs_table[i];
1451 if (match_dvfs_one("cpu dvfs", d->speedo_id, d->process_id,
1452 cpu_speedo_id, cpu_process_id)) {
1453 ret = set_cpu_dvfs_data(
1454 d, &cpu_dvfs, cpu_max_freq_index);
1460 BUG_ON(i == table_size);
1465 static int init_cpu_lp_dvfs_table(int *cpu_lp_max_freq_index)
1468 unsigned int cpu_lp_speedo_id = tegra_sku_info.cpu_speedo_id;
1469 int cpu_lp_process_id = tegra_sku_info.cpu_process_id;
1470 unsigned long max_freq;
1472 if (cpu_lp_speedo_id >= ARRAY_SIZE(cpu_lp_max_freq))
1473 max_freq = cpu_lp_max_freq[0];
1475 max_freq = cpu_lp_max_freq[cpu_lp_speedo_id];
1477 for (ret = 0, i = 0; i < ARRAY_SIZE(cpu_lp_fv_dvfs_table); i++) {
1478 struct cpu_dvfs *d = &cpu_lp_fv_dvfs_table[i];
1479 if (match_dvfs_one("cpu lp dvfs", d->speedo_id, d->process_id,
1480 cpu_lp_speedo_id, cpu_lp_process_id)) {
1481 ret = set_cpu_lp_dvfs_data(max_freq,
1482 d, &cpu_lp_dvfs, cpu_lp_max_freq_index);
1490 static void adjust_emc_dvfs_from_timing_table(struct dvfs *d)
1495 for (i = 0; i < ARRAY_SIZE(core_millivolts); i++) {
1496 if (core_millivolts[i] == 0)
1499 rate = tegra210_predict_emc_rate(core_millivolts[i]);
1500 if (IS_ERR_VALUE(rate))
1508 static unsigned long dvb_predict_rate(
1509 int process_id, struct dvb_dvfs *dvbd, int mv)
1512 unsigned long rate = 0;
1514 for (i = 0; i < MAX_DVFS_FREQS; i++) {
1515 if (!dvbd->dvb_table[i].freq)
1517 if (dvbd->dvb_table[i].mvolts[process_id] > mv)
1519 rate = dvbd->dvb_table[i].freq * dvbd->freqs_mult;
1525 static void adjust_emc_dvfs_from_dvb_table(
1526 int process_id, struct dvb_dvfs *dvbd, struct dvfs *d)
1531 if (process_id > MAX_PROCESS_ID) {
1532 WARN(1, "Process id %d above emc dvb table max\n", process_id);
1536 for (i = 0; i < ARRAY_SIZE(core_millivolts); i++) {
1537 if (core_millivolts[i] == 0)
1540 rate = dvb_predict_rate(process_id, dvbd, core_millivolts[i]);
1546 static struct dvb_dvfs *get_emc_dvb_dvfs(int speedo_id)
1550 if (dvfs_data->emc_dvb_table) {
1551 for (i = 0; i < dvfs_data->emc_dvb_table_size; i++) {
1552 struct dvb_dvfs *dvbd = &dvfs_data->emc_dvb_table[i];
1554 if (dvbd->speedo_id == -1 ||
1555 dvbd->speedo_id == speedo_id)
1563 * Find maximum GPU frequency that can be reached at minimum voltage across all
1564 * temperature ranges.
1566 static unsigned long find_gpu_fmax_at_vmin(
1567 struct dvfs *gpu_dvfs, int thermal_ranges, int freqs_num)
1570 unsigned long fmax = ULONG_MAX;
1573 * For voltage scaling row in each temperature range, as well as peak
1574 * voltage row find maximum frequency at lowest voltage, and return
1575 * minimax. On Tegra21 all GPU DVFS thermal dependencies are integrated
1576 * into thermal DVFS table (i.e., there is no separate thermal floors
1577 * applied in the rail level). Hence, returned frequency specifies max
1578 * frequency safe at minimum voltage across all temperature ranges.
1580 for (j = 0; j < thermal_ranges; j++) {
1581 for (i = 1; i < freqs_num; i++) {
1582 if (gpu_millivolts[j][i] > gpu_millivolts[j][0])
1585 fmax = min(fmax, gpu_dvfs->freqs[i - 1]);
1588 for (i = 1; i < freqs_num; i++) {
1589 if (gpu_peak_millivolts[i] > gpu_peak_millivolts[0])
1592 fmax = min(fmax, gpu_dvfs->freqs[i - 1]);
1598 * Determine minimum voltage safe at maximum frequency across all temperature
1601 static int find_gpu_vmin_at_fmax(
1602 struct dvfs *gpu_dvfs, int thermal_ranges, int freqs_num)
1607 * For voltage scaling row in each temperature range find minimum
1608 * voltage at maximum frequency and return max Vmin across ranges.
1610 for (vmin = 0, j = 0; j < thermal_ranges; j++)
1611 vmin = max(vmin, gpu_millivolts[j][freqs_num-1]);
1616 static int of_parse_dvfs_rail_cdev_trips(struct device_node *node,
1617 int *therm_trips_table,
1618 struct dvfs_therm_limits *therm_limits_table,
1619 struct dvfs_therm_limits *therm_limits_ucm2_table,
1620 struct rail_alignment *align, bool up)
1622 struct of_phandle_iter iter;
1623 int cells_num, i = 0, t;
1625 /* 1 cell per trip-point, if constraint is specified */
1626 cells_num = of_property_read_bool(node, "nvidia,constraint-ucm2") ? 2 :
1627 of_property_read_bool(node, "nvidia,constraint") ? 1 : 0;
1629 if (of_phandle_iterator_init(&iter, node, "nvidia,trips",
1633 while (!of_phandle_iterator_next(&iter)) {
1634 struct device_node *trip_dn = iter.node;
1636 if (i >= MAX_THERMAL_LIMITS) {
1637 pr_err("tegra_dvfs: list of scaling cdev trips exceeds max limit\n");
1641 if (of_property_read_s32(trip_dn, "temperature", &t)) {
1642 pr_err("tegra_dvfs: failed to read scalings cdev trip %d\n", i);
1646 if (therm_trips_table)
1647 therm_trips_table[i] = t / 1000; /* convert mC to C */
1649 if (cells_num && therm_limits_table) {
1651 struct of_phandle_args dvfs_args;
1652 dvfs_args.args_count = of_phandle_iterator_args(&iter,
1653 dvfs_args.args, MAX_PHANDLE_ARGS);
1655 mv = dvfs_args.args[0];
1656 mv = tegra_round_voltage(mv, align, up);
1657 therm_limits_table[i].temperature = t / 1000;
1658 therm_limits_table[i].mv = mv;
1659 if (cells_num == 2 && therm_limits_ucm2_table) {
1660 mv = dvfs_args.args[1];
1661 mv = tegra_round_voltage(mv, align, up);
1662 therm_limits_ucm2_table[i].temperature = t/1000;
1663 therm_limits_ucm2_table[i].mv = mv;
1672 static int init_gpu_rail_thermal_scaling(struct device_node *node,
1673 struct dvfs_rail *rail,
1677 struct device_node *cdev_node;
1679 cdev_node = of_find_compatible_node(NULL, NULL,
1680 "nvidia,tegra210-rail-scaling-cdev");
1681 if (!cdev_node || !of_device_is_available(cdev_node))
1684 rail->vts_of_node = cdev_node;
1686 thermal_ranges = of_parse_dvfs_rail_cdev_trips(cdev_node,
1687 &rail->vts_trips_table[0], &rail->vts_floors_table[0],
1688 NULL, &rail->alignment, true);
1690 if (thermal_ranges <= 0)
1693 rail->vts_number_of_trips = thermal_ranges - 1;
1695 return thermal_ranges;
1698 /* cooling device to limit GPU frequenct based on the vmax thermal profile */
1699 #define GPU_MAX_RATE 1300000000UL
1700 static int gpu_dvfs_rail_get_vmax_cdev_max_state(
1701 struct thermal_cooling_device *cdev, unsigned long *max_state)
1703 struct dvfs_rail *rail = cdev->devdata;
1705 *max_state = rail->therm_caps_size;
1710 static int gpu_dvfs_rail_get_vmax_cdev_cur_state(
1711 struct thermal_cooling_device *cdev, unsigned long *cur_state)
1713 struct dvfs_rail *rail = cdev->devdata;
1715 *cur_state = rail->therm_cap_idx;
1720 static int gpu_dvfs_rail_set_vmax_cdev_cur_state(
1721 struct thermal_cooling_device *cdev, unsigned long cur_state)
1723 struct dvfs_rail *rail = cdev->devdata;
1724 int level = 0, err = -EINVAL;
1725 unsigned long cap_rate = GPU_MAX_RATE;
1728 level = rail->therm_caps[cur_state - 1].mv;
1731 if (rail->vts_cdev && gpu_dvfs.therm_dvfs)
1732 cap_rate = gpu_cap_rates[cur_state - 1];
1734 cap_rate = tegra_dvfs_predict_hz_at_mv_max_tfloor(
1735 gpu_dvfs.clk, level);
1738 if (!IS_ERR_VALUE(cap_rate)) {
1739 err = clk_set_rate(vgpu_cap_clk, cap_rate);
1741 pr_err("tegra_dvfs: Failed to set GPU cap rate %lu\n",
1744 pr_err("tegra_dvfs: Failed to find GPU cap rate for %dmV\n",
1748 rail->therm_cap_idx = cur_state;
1753 static struct thermal_cooling_device_ops gpu_dvfs_rail_vmax_cooling_ops = {
1754 .get_max_state = gpu_dvfs_rail_get_vmax_cdev_max_state,
1755 .get_cur_state = gpu_dvfs_rail_get_vmax_cdev_cur_state,
1756 .set_cur_state = gpu_dvfs_rail_set_vmax_cdev_cur_state,
1759 #define CAP_TRIP_ON_SCALING_MARGIN 5
1761 static int init_gpu_rail_thermal_caps(struct device_node *node,
1762 struct dvfs *dvfs, struct dvfs_rail *rail, int thermal_ranges,
1765 struct device_node *cdev_node;
1766 int num_trips, i, j, k;
1767 bool ucm2 = tegra_sku_info.ucm == TEGRA_UCM2;
1769 if (thermal_ranges <= 1 )
1772 cdev_node = of_find_compatible_node(NULL, NULL,
1773 "nvidia,tegra210-rail-vmax-cdev");
1774 if (!cdev_node || !of_device_is_available(cdev_node))
1777 rail->vmax_of_node = cdev_node;
1779 vgpu_cap_clk = of_clk_get_by_name(cdev_node, "cap-clk");
1780 if (IS_ERR(vgpu_cap_clk))
1783 num_trips = of_parse_dvfs_rail_cdev_trips(cdev_node,
1784 NULL, vdd_gpu_therm_caps_table, vdd_gpu_therm_caps_ucm2_table,
1785 &rail->alignment, false);
1790 ucm2 ? vdd_gpu_therm_caps_ucm2_table : vdd_gpu_therm_caps_table;
1791 if (!rail->therm_caps[0].mv) {
1792 pr_err("tegra_dvfs: invalid gpu cap table\n");
1793 rail->therm_caps = NULL;
1796 rail->therm_caps_size = num_trips;
1797 rail->therm_cap_idx = num_trips;
1799 for (k = 0; k < num_trips; k++) {
1800 int cap_tempr = rail->therm_caps[k].temperature;
1801 int cap_level = rail->therm_caps[k].mv;
1802 unsigned long cap_freq = GPU_MAX_RATE;
1804 for (j = 0; j < thermal_ranges; j++) {
1805 if ((j < thermal_ranges - 1) && /* vts trips=ranges-1 */
1806 (rail->vts_trips_table[j] +
1807 CAP_TRIP_ON_SCALING_MARGIN < cap_tempr))
1810 for (i = 1; i < freqs_num; i++) {
1811 if (gpu_millivolts[j][i] > cap_level)
1814 cap_freq = min(cap_freq, dvfs->freqs[i - 1]);
1816 gpu_cap_rates[k] = cap_freq * dvfs->freqs_mult;
1820 clk_set_rate(vgpu_cap_clk, gpu_cap_rates[num_trips - 1]);
1821 rail->vmax_cdev = thermal_of_cooling_device_register(rail->vmax_of_node,
1822 "GPU-cap", rail, &gpu_dvfs_rail_vmax_cooling_ops);
1823 pr_info("tegra_dvfs: GPU-cap: %sregistered\n",
1824 IS_ERR_OR_NULL(rail->vmax_cdev) ? "not " : "");
1830 * Setup gpu dvfs tables from cvb data, determine nominal voltage for gpu rail,
1831 * and gpu maximum frequency. Error when gpu dvfs table can not be constructed
1832 * must never happen.
1834 static int set_gpu_dvfs_data(struct device_node *node, unsigned long max_freq,
1835 struct cvb_dvfs *d, struct dvfs *gpu_dvfs, int *max_freq_index)
1837 int i, j, thermal_ranges, mv, min_mv, err;
1838 struct cvb_dvfs_table *table = NULL;
1839 int speedo = tegra_sku_info.gpu_speedo_value;
1840 struct dvfs_rail *rail = &vdd_gpu_rail;
1841 struct rail_alignment *align = &rail->alignment;
1843 rail->nvver = d->cvb_version;
1845 d->max_mv = tegra_round_voltage(d->max_mv, align, false);
1846 min_mv = d->pll_min_millivolts;
1847 mv = tegra_get_cvb_voltage(
1848 speedo, d->speedo_scale, &d->cvb_vmin.cvb_pll_param);
1849 mv = tegra_round_cvb_voltage(mv, d->voltage_scale, align);
1850 min_mv = max(min_mv, mv);
1851 if (min_mv < rail->min_millivolts) {
1852 pr_debug("tegra21_dvfs: gpu min %dmV below rail min %dmV\n",
1853 min_mv, rail->min_millivolts);
1854 min_mv = rail->min_millivolts;
1858 * Get scaling thermal ranges; 1 range implies no thermal dependency.
1859 * Invalidate scaling cooling device in the latter case.
1861 thermal_ranges = init_gpu_rail_thermal_scaling(node, rail, d);
1862 if (thermal_ranges == 1)
1863 rail->vts_cdev = NULL;
1866 * Apply fixed thermal floor for each temperature range
1868 for (j = 0; j < thermal_ranges; j++) {
1869 mv = max(min_mv, (int)rail->vts_floors_table[j].mv);
1870 gpu_vmin[j] = tegra_round_voltage(mv, align, true);
1874 * Use CVB table to fill in gpu dvfs frequencies and voltages. Each
1875 * CVB entry specifies gpu frequency and CVB coefficients to calculate
1876 * the respective voltage.
1878 for (i = 0; i < MAX_DVFS_FREQS; i++) {
1879 table = &d->cvb_table[i];
1880 if (!table->freq || (table->freq > max_freq))
1883 mv = tegra_get_cvb_voltage(
1884 speedo, d->speedo_scale, &table->cvb_pll_param);
1886 for (j = 0; j < thermal_ranges; j++) {
1890 if (thermal_ranges > 1)
1891 t = rail->vts_trips_table[j];
1893 /* get thermal offset for this trip-point */
1894 mvj += tegra_get_cvb_t_voltage(speedo, d->speedo_scale,
1895 t, d->thermal_scale, &table->cvb_pll_param);
1896 mvj = tegra_round_cvb_voltage(mvj, d->voltage_scale, align);
1898 /* clip to minimum, abort if above maximum */
1899 mvj = max(mvj, gpu_vmin[j]);
1900 if (mvj > d->max_mv)
1904 * Update voltage for adjacent ranges bounded by this
1905 * trip-point (cvb & dvfs are transpose matrices, and
1906 * cvb freq row index is column index for dvfs matrix)
1908 gpu_millivolts[j][i] = mvj;
1909 if (j && (gpu_millivolts[j-1][i] < mvj))
1910 gpu_millivolts[j-1][i] = mvj;
1912 /* Make sure all voltages for this frequency are below max */
1913 if (j < thermal_ranges)
1916 /* fill in gpu dvfs tables */
1917 gpu_dvfs->freqs[i] = table->freq;
1920 gpu_dvfs->millivolts = &gpu_millivolts[0][0];
1923 * Table must not be empty, must have at least one entry in range, and
1924 * must specify monotonically increasing voltage on frequency dependency
1925 * in each temperature range.
1927 err = tegra_dvfs_init_thermal_dvfs_voltages(&gpu_millivolts[0][0],
1928 gpu_peak_millivolts, i, thermal_ranges, gpu_dvfs);
1931 pr_err("tegra21_dvfs: invalid gpu dvfs table\n");
1935 /* Shift out the 1st trip-point */
1936 for (j = 1; j < thermal_ranges; j++)
1937 rail->vts_trips_table[j - 1] = rail->vts_trips_table[j];
1939 /* dvfs tables are successfully populated - fill in the gpu dvfs */
1940 gpu_dvfs->speedo_id = d->speedo_id;
1941 gpu_dvfs->process_id = d->process_id;
1942 gpu_dvfs->freqs_mult = d->freqs_mult;
1944 *max_freq_index = i - 1;
1946 gpu_dvfs->dvfs_rail->nominal_millivolts = min(d->max_mv,
1947 find_gpu_vmin_at_fmax(gpu_dvfs, thermal_ranges, i));
1949 gpu_dvfs->fmax_at_vmin_safe_t = d->freqs_mult *
1950 find_gpu_fmax_at_vmin(gpu_dvfs, thermal_ranges, i);
1952 /* Initialize thermal capping */
1953 init_gpu_rail_thermal_caps(node, gpu_dvfs, rail, thermal_ranges, i);
1955 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
1957 * Set NA DVFS flag, if GPCPLL NA mode is enabled. This is necessary to
1958 * make sure that GPCPLL configuration is updated by tegra core DVFS
1959 * when thermal DVFS cooling device state is changed. Since tegra core
1960 * DVFS does not support NA operations for Vmin cooling device, GPU Vmin
1961 * thermal floors have been integrated with thermal DVFS, and no Vmin
1962 * cooling device is installed.
1964 if (tegra_sku_info.gpu_speedo_id)
1965 gpu_dvfs->na_dvfs = 1;
1967 if (of_device_is_compatible(node, "nvidia,tegra210b01-dvfs"))
1968 WARN(1, "TEGRA_USE_NA_GPCPLL must be set on T210b01\n");
1973 static void init_gpu_dvfs_table(struct device_node *node,
1974 struct cvb_dvfs *cvb_dvfs_table, int table_size,
1975 int *gpu_max_freq_index)
1978 int gpu_speedo_id = tegra_sku_info.gpu_speedo_id;
1979 int gpu_process_id = tegra_sku_info.gpu_process_id;
1981 for (ret = 0, i = 0; i < table_size; i++) {
1982 struct cvb_dvfs *d = &cvb_dvfs_table[i];
1983 unsigned long max_freq = d->max_freq;
1986 if (!of_property_read_u32(node, "nvidia,gpu-max-freq-khz", &f))
1987 max_freq = min(max_freq, (unsigned long)f);
1989 if (match_dvfs_one("gpu cvb", d->speedo_id, d->process_id,
1990 gpu_speedo_id, gpu_process_id)) {
1991 ret = set_gpu_dvfs_data(node, max_freq,
1992 d, &gpu_dvfs, gpu_max_freq_index);
1996 BUG_ON((i == table_size) || ret);
1999 static void init_core_dvfs_table(int soc_speedo_id, int core_process_id)
2001 int core_nominal_mv_index;
2002 int core_min_mv_index;
2004 static bool initialized;
2012 * Find nominal voltages for core (1st) and cpu rails before rail
2013 * init. Nominal voltage index in core scaling ladder can also be
2014 * used to determine max dvfs frequencies for all core clocks. In
2015 * case of error disable core scaling and set index to 0, so that
2016 * core clocks would not exceed rates allowed at minimum voltage.
2018 core_nominal_mv_index = get_core_nominal_mv_index(soc_speedo_id);
2019 if (core_nominal_mv_index < 0) {
2020 vdd_core_rail.disabled = true;
2021 tegra_dvfs_core_disabled = true;
2022 core_nominal_mv_index = 0;
2025 core_min_mv_index = get_core_min_mv_index();
2026 if (core_min_mv_index < 0) {
2027 vdd_core_rail.disabled = true;
2028 tegra_dvfs_core_disabled = true;
2029 core_min_mv_index = 0;
2032 vdd_core_rail.nominal_millivolts =
2033 core_millivolts[core_nominal_mv_index];
2034 vdd_core_rail.min_millivolts =
2035 core_millivolts[core_min_mv_index];
2036 vdd_core_rail.nvver = dvfs_data->core_dvfs_ver;
2039 * Search core dvfs table for speedo/process matching entries and
2040 * initialize dvfs-ed clocks
2042 for (i = 0; i < dvfs_data->core_vf_table_size; i++) {
2043 struct dvfs *d = &dvfs_data->core_vf_table[i];
2044 if (!match_dvfs_one(d->clk_name, d->speedo_id,
2045 d->process_id, soc_speedo_id, core_process_id))
2047 init_dvfs_one(d, core_nominal_mv_index);
2050 * If EMC DVB table is installed, use it to set EMC VF opps.
2051 * Otherwise, EMC dvfs is board dependent, EMC frequencies are
2052 * determined by the Tegra BCT and the board specific EMC DFS
2053 * table owned by EMC driver.
2055 if (!strcmp(d->clk_name, "emc") && tegra210_emc_is_ready()) {
2056 struct dvb_dvfs *dvbd = get_emc_dvb_dvfs(soc_speedo_id);
2059 adjust_emc_dvfs_from_dvb_table(
2060 core_process_id, dvbd, d);
2062 adjust_emc_dvfs_from_timing_table(d);
2066 init_qspi_dvfs(soc_speedo_id, core_process_id, core_nominal_mv_index);
2067 init_sor1_dvfs(soc_speedo_id, core_process_id, core_nominal_mv_index);
2068 init_spi_dvfs(soc_speedo_id, core_process_id, core_nominal_mv_index);
2071 static void init_dvfs_data(struct tegra_dvfs_data *data)
2074 static bool initialized;
2083 BUG_ON(dvfs_data->rails_num != ARRAY_SIZE(vdd_dvfs_rails));
2084 vdd_cpu_rail = *dvfs_data->rails[VDD_CPU_INDEX];
2085 vdd_core_rail = *dvfs_data->rails[VDD_CORE_INDEX];
2086 vdd_gpu_rail = *dvfs_data->rails[VDD_GPU_INDEX];
2088 for (i = 0; i < MAX_DVFS_FREQS; i++)
2089 core_millivolts[i] = dvfs_data->core_mv[i];
2092 static struct tegra_dvfs_data tegra210_dvfs_data = {
2093 .rails = tegra210_dvfs_rails,
2094 .rails_num = ARRAY_SIZE(tegra210_dvfs_rails),
2095 .cpu_fv_table = cpu_fv_dvfs_table,
2096 .cpu_fv_table_size = ARRAY_SIZE(cpu_fv_dvfs_table),
2097 .gpu_cvb_table = gpu_cvb_dvfs_table,
2098 .gpu_cvb_table_size = ARRAY_SIZE(gpu_cvb_dvfs_table),
2100 .core_mv = core_voltages_mv,
2101 .core_vf_table = core_dvfs_table,
2102 .core_vf_table_size = ARRAY_SIZE(core_dvfs_table),
2103 .spi_vf_table = spi_dvfs_table,
2104 .spi_slave_vf_table = spi_slave_dvfs_table,
2105 .qspi_sdr_vf_table = qspi_sdr_dvfs_table,
2106 .qspi_ddr_vf_table = qspi_ddr_dvfs_table,
2107 .sor1_dp_vf_table = sor1_dp_dvfs_table,
2108 .sor1_dp_vf_table_size = ARRAY_SIZE(sor1_dp_dvfs_table),
2109 .get_core_min_mv = get_core_sku_min_mv,
2110 .get_core_max_mv = get_core_sku_max_mv,
2112 .core_floors = tegra210_core_therm_floors,
2113 .core_caps = tegra210_core_therm_caps,
2114 .core_caps_ucm2 = tegra210_core_therm_caps_ucm2,
2117 static struct tegra_dvfs_data tegra210b01_dvfs_data = {
2118 .rails = tegra210b01_dvfs_rails,
2119 .rails_num = ARRAY_SIZE(tegra210b01_dvfs_rails),
2120 .cpu_fv_table = cpub01_fv_dvfs_table,
2121 .cpu_fv_table_size = ARRAY_SIZE(cpub01_fv_dvfs_table),
2122 .gpu_cvb_table = gpub01_cvb_dvfs_table,
2123 .gpu_cvb_table_size = ARRAY_SIZE(gpub01_cvb_dvfs_table),
2125 .emc_dvb_table = emcb01_dvb_dvfs_table,
2126 .emc_dvb_table_size = ARRAY_SIZE(emcb01_dvb_dvfs_table),
2128 .core_mv = coreb01_voltages_mv,
2129 .core_vf_table = coreb01_dvfs_table,
2130 .core_vf_table_size = ARRAY_SIZE(coreb01_dvfs_table),
2131 .spi_vf_table = spib01_dvfs_table,
2132 .spi_slave_vf_table = spi_slaveb01_dvfs_table,
2133 .qspi_sdr_vf_table = qspi_sdrb01_dvfs_table,
2134 .qspi_ddr_vf_table = qspi_ddrb01_dvfs_table,
2135 .sor1_dp_vf_table = sor1_dpb01_dvfs_table,
2136 .sor1_dp_vf_table_size = ARRAY_SIZE(sor1_dpb01_dvfs_table),
2137 .get_core_min_mv = get_coreb01_sku_min_mv,
2138 .get_core_max_mv = get_coreb01_sku_max_mv,
2140 .core_floors = tegra210b01_core_therm_floors,
2141 .core_caps = tegra210b01_core_therm_caps,
2142 .core_caps_ucm2 = tegra210b01_core_therm_caps_ucm2,
2144 .core_dvfs_ver = coreb01_dvfs_table_ver,
2147 static struct tegra_dvfs_data tegra210b01slt_dvfs_data = {
2148 .rails = tegra210b01_dvfs_rails,
2149 .rails_num = ARRAY_SIZE(tegra210b01_dvfs_rails),
2150 .cpu_fv_table = cpub01_fv_dvfs_table,
2151 .cpu_fv_table_size = ARRAY_SIZE(cpub01_fv_dvfs_table),
2152 .gpu_cvb_table = gpub01_cvb_dvfs_table,
2153 .gpu_cvb_table_size = ARRAY_SIZE(gpub01_cvb_dvfs_table),
2155 .emc_dvb_table = emcb01slt_dvb_dvfs_table,
2156 .emc_dvb_table_size = ARRAY_SIZE(emcb01slt_dvb_dvfs_table),
2158 .core_mv = coreb01slt_voltages_mv,
2159 .core_vf_table = coreb01slt_dvfs_table,
2160 .core_vf_table_size = ARRAY_SIZE(coreb01slt_dvfs_table),
2161 .spi_vf_table = spib01slt_dvfs_table,
2162 .spi_slave_vf_table = spi_slaveb01slt_dvfs_table,
2163 .qspi_sdr_vf_table = qspi_sdrb01slt_dvfs_table,
2164 .qspi_ddr_vf_table = qspi_ddrb01slt_dvfs_table,
2165 .sor1_dp_vf_table = sor1_dpb01slt_dvfs_table,
2166 .sor1_dp_vf_table_size = ARRAY_SIZE(sor1_dpb01slt_dvfs_table),
2167 .get_core_min_mv = get_coreb01slt_sku_min_mv,
2168 .get_core_max_mv = get_coreb01slt_sku_max_mv,
2170 .core_floors = tegra210b01_core_therm_floors,
2171 .core_caps = tegra210b01_core_therm_caps,
2172 .core_caps_ucm2 = tegra210b01_core_therm_caps_ucm2,
2174 .core_dvfs_ver = coreb01slt_dvfs_table_ver,
2177 static void disable_rail_scaling(struct device_node *np)
2179 /* With DFLL as clock source CPU rail scaling cannot be disabled */
2181 if (tegra_dvfs_core_disabled ||
2182 of_property_read_bool(np, "nvidia,core-rail-scaling-disabled")) {
2183 vdd_dvfs_rails[VDD_CORE_INDEX]->disabled = true;
2185 if (tegra_dvfs_gpu_disabled ||
2186 of_property_read_bool(np, "nvidia,gpu-rail-scaling-disabled")) {
2187 vdd_dvfs_rails[VDD_GPU_INDEX]->disabled = true;
2191 static int tegra210x_init_dvfs(struct device *dev, bool cpu_lp_init)
2193 int soc_speedo_id = tegra_sku_info.soc_speedo_id;
2194 int core_process_id = tegra_sku_info.soc_process_id;
2195 bool ucm2 = tegra_sku_info.ucm == TEGRA_UCM2;
2197 int cpu_max_freq_index = 0;
2198 int cpu_lp_max_freq_index = 0;
2199 int gpu_max_freq_index = 0;
2200 struct device_node *node = dev->of_node;
2202 tegra_dvfs_init_rails_lists(vdd_dvfs_rails, dvfs_data->rails_num);
2203 init_core_dvfs_table(soc_speedo_id, core_process_id);
2205 /* Get rails alignment, defer probe if regulators are not ready */
2206 for (i = 0; i < dvfs_data->rails_num; i++) {
2207 struct regulator *reg;
2208 unsigned int step_uv;
2209 int min_uV, max_uV, ret;
2211 reg = regulator_get(dev, vdd_dvfs_rails[i]->reg_id);
2213 pr_info("tegra_dvfs: Unable to get %s rail for step info, defering probe\n",
2214 vdd_dvfs_rails[i]->reg_id);
2215 return -EPROBE_DEFER;
2218 ret = regulator_get_constraint_voltages(reg, &min_uV, &max_uV);
2220 vdd_dvfs_rails[i]->alignment.offset_uv = min_uV;
2222 step_uv = regulator_get_linear_step(reg); /* 1st try get step */
2223 if (!step_uv && !ret) { /* if no step, try to calculate it */
2224 int n_voltages = regulator_count_voltages(reg);
2227 step_uv = (max_uV - min_uV) / (n_voltages - 1);
2230 vdd_dvfs_rails[i]->alignment.step_uv = step_uv;
2231 vdd_dvfs_rails[i]->stats.bin_uv = step_uv;
2237 * Construct fast and slow CPU DVFS tables from FV data; find maximum
2238 * frequency, minimum and nominal voltage for each CPU cluster, and
2239 * combined rail limits (fast CPU should be initialized 1st).
2241 ret = init_cpu_dvfs_table(dvfs_data->cpu_fv_table,
2242 dvfs_data->cpu_fv_table_size, &cpu_max_freq_index);
2247 ret = init_cpu_lp_dvfs_table(&cpu_lp_max_freq_index);
2253 * Construct GPU DVFS table from CVB data; find GPU maximum frequency,
2254 * and nominal voltage.
2256 init_gpu_dvfs_table(node, dvfs_data->gpu_cvb_table,
2257 dvfs_data->gpu_cvb_table_size, &gpu_max_freq_index);
2259 /* Init core thermal floors abd caps */
2260 vdd_core_rail.therm_floors = dvfs_data->core_floors;
2261 vdd_core_rail.therm_caps =
2262 ucm2 ? dvfs_data->core_caps_ucm2 : dvfs_data->core_caps;
2263 tegra_dvfs_core_init_therm_limits(&vdd_core_rail);
2265 /* Init rail structures and dependencies */
2266 tegra_dvfs_init_rails(vdd_dvfs_rails, dvfs_data->rails_num);
2268 if (of_property_read_bool(of_chosen, "nvidia,tegra-joint_xpu_rail"))
2269 vdd_dvfs_rails[VDD_GPU_INDEX]->joint_rail_with_dfll = true;
2272 * Initialize matching cpu dvfs entry already found when nominal
2273 * voltage was determined
2275 init_dvfs_one(&cpu_dvfs, cpu_max_freq_index);
2277 init_dvfs_one(&cpu_lp_dvfs, cpu_lp_max_freq_index);
2278 init_dvfs_one(&gpu_dvfs, gpu_max_freq_index);
2280 disable_rail_scaling(node);
2282 for (i = 0; i < dvfs_data->rails_num; i++) {
2283 struct dvfs_rail *rail = vdd_dvfs_rails[i];
2284 pr_info("tegra dvfs: %s: nominal %dmV, offset %duV, step %duV, scaling %s\n",
2285 rail->reg_id, rail->nominal_millivolts,
2286 rail->alignment.offset_uv, rail->alignment.step_uv,
2287 rail->disabled ? "disabled" : "enabled");
2294 int tegra210_init_dvfs(struct device *dev)
2296 init_dvfs_data(&tegra210_dvfs_data);
2297 return tegra210x_init_dvfs(dev, true);
2300 int tegra210b01_init_dvfs(struct device *dev)
2302 if (tegra_sku_info.soc_speedo_id == 2)
2303 init_dvfs_data(&tegra210b01slt_dvfs_data);
2305 init_dvfs_data(&tegra210b01_dvfs_data);
2307 return tegra210x_init_dvfs(dev, false);