2 * drivers/platform/tegra/tegra21_dvfs.c
4 * Copyright (c) 2012-2015 NVIDIA CORPORATION. All rights reserved.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/string.h>
20 #include <linux/module.h>
21 #include <linux/clk.h>
22 #include <linux/kobject.h>
23 #include <linux/err.h>
24 #include <linux/tegra-fuse.h>
25 #include <linux/pm_qos.h>
26 #include <linux/of_address.h>
28 #include <linux/platform/tegra/clock.h>
29 #include <linux/platform/tegra/dvfs.h>
30 #include <linux/platform/tegra/tegra_cl_dvfs.h>
31 #include <linux/platform/tegra/cpu-tegra.h>
33 #include "tegra_core_sysfs_limits.h"
35 static bool tegra_dvfs_cpu_disabled;
36 static bool tegra_dvfs_core_disabled;
37 static bool tegra_dvfs_gpu_disabled;
42 /* FIXME: need tegra21 step */
43 #define VDD_SAFE_STEP 100
45 static int vdd_core_vmin_trips_table[MAX_THERMAL_LIMITS];
46 static int vdd_core_therm_floors_table[MAX_THERMAL_LIMITS];
47 static struct tegra_cooling_device core_vmin_cdev = {
48 .compatible = "nvidia,tegra210-rail-vmin-cdev",
50 static int vdd_core_vmax_trips_table[MAX_THERMAL_LIMITS];
51 static int vdd_core_therm_caps_table[MAX_THERMAL_LIMITS];
52 static struct tegra_cooling_device core_vmax_cdev = {
53 .compatible = "nvidia,tegra210-rail-vmax-cdev",
56 static int vdd_cpu_vmin_trips_table[MAX_THERMAL_LIMITS];
57 static int vdd_cpu_therm_floors_table[MAX_THERMAL_LIMITS];
58 static struct tegra_cooling_device cpu_vmin_cdev = {
59 .compatible = "nvidia,tegra210-rail-vmin-cdev",
61 static int vdd_cpu_vmax_trips_table[MAX_THERMAL_LIMITS];
62 static int vdd_cpu_therm_caps_table[MAX_THERMAL_LIMITS];
63 #ifndef CONFIG_TEGRA_CPU_VOLT_CAP
64 static struct tegra_cooling_device cpu_vmax_cdev = {
65 .compatible = "nvidia,tegra210-rail-vmax-cdev",
69 static struct clk *vgpu_cap_clk;
70 static unsigned long gpu_cap_rates[MAX_THERMAL_LIMITS];
71 static int vdd_gpu_vmax_trips_table[MAX_THERMAL_LIMITS];
72 static int vdd_gpu_therm_caps_table[MAX_THERMAL_LIMITS];
73 static struct tegra_cooling_device gpu_vmax_cdev = {
74 .compatible = "nvidia,tegra210-rail-vmax-cdev",
76 static struct tegra_cooling_device gpu_vts_cdev = {
77 .compatible = "nvidia,tegra210-rail-scaling-cdev",
80 static struct dvfs_rail tegra21_dvfs_rail_vdd_cpu = {
82 .max_millivolts = 1300,
83 .step = VDD_SAFE_STEP,
86 .vmin_cdev = &cpu_vmin_cdev,
87 #ifndef CONFIG_TEGRA_CPU_VOLT_CAP
88 .vmax_cdev = &cpu_vmax_cdev,
91 .step_uv = 6250, /* 6.25mV */
94 .bin_uV = 6250, /* 6.25mV */
96 .version = "p4v57_p4Av05",
99 static struct dvfs_rail tegra21_dvfs_rail_vdd_core = {
100 .reg_id = "vdd_core",
101 .max_millivolts = 1300,
102 .step = VDD_SAFE_STEP,
104 .vmin_cdev = &core_vmin_cdev,
105 .vmax_cdev = &core_vmax_cdev,
107 .step_uv = 12500, /* 12.5mV */
109 .version = "p4v50_p4Av05",
112 static struct dvfs_rail tegra21_dvfs_rail_vdd_gpu = {
114 .max_millivolts = 1300,
115 .step = VDD_SAFE_STEP,
118 .vts_cdev = &gpu_vts_cdev,
119 .vmax_cdev = &gpu_vmax_cdev,
121 .step_uv = 6250, /* 6.25mV */
124 .bin_uV = 6250, /* 6.25mV */
126 .version = "p4v50_p4Av05",
129 static struct dvfs_rail *tegra21_dvfs_rails[] = {
130 &tegra21_dvfs_rail_vdd_cpu,
131 &tegra21_dvfs_rail_vdd_core,
132 &tegra21_dvfs_rail_vdd_gpu,
135 /* FIXME: Remove after bringup */
136 #define BRINGUP_CVB_V_MARGIN 25
137 #define BRINGUP_CVB_V_MARGIN_EX 5
138 #define CPU_BOOST_THRESHOLD 2014500
140 /* CPU DVFS tables */
141 #define CPU_CVB_TABLE \
143 .speedo_scale = 100, \
144 .voltage_scale = 1000, \
146 /* f dfll: c0, c1, c2 pll: c0, c1, c2 */ \
147 { 204000, { 1007452, -23865, 370 }, { 0, 0, 0 } }, \
148 { 306000, { 1052709, -24875, 370 }, { 0, 0, 0 } }, \
149 { 408000, { 1099069, -25895, 370 }, { 0, 0, 0 } }, \
150 { 510000, { 1146534, -26905, 370 }, { 0, 0, 0 } }, \
151 { 612000, { 1195102, -27915, 370 }, { 0, 0, 0 } }, \
152 { 714000, { 1244773, -28925, 370 }, { 0, 0, 0 } }, \
153 { 816000, { 1295549, -29935, 370 }, { 0, 0, 0 } }, \
154 { 918000, { 1347428, -30955, 370 }, { 0, 0, 0 } }, \
155 { 1020000, { 1400411, -31965, 370 }, { -2875621, 358099, -8585 } }, \
156 { 1122000, { 1454497, -32975, 370 }, { -52225, 104159, -2816 } }, \
157 { 1224000, { 1509687, -33985, 370 }, { 1076868, 8356, -727 } }, \
158 { 1326000, { 1565981, -35005, 370 }, { 2208191, -84659, 1240 } }, \
159 { 1428000, { 1623379, -36015, 370 }, { 2519460, -105063, 1611 } }, \
160 { 1530000, { 1681880, -37025, 370 }, { 2639809, -108729, 1626 } }, \
161 { 1632000, { 1741485, -38035, 370 }, { 2889664, -122173, 1834 } }, \
162 { 1734000, { 1802194, -39055, 370 }, { 3386160, -154021, 2393 } }, \
163 { 1836000, { 1864006, -40065, 370 }, { 5100873, -279186, 4747 } }, \
164 { 1912500, { 1910780, -40815, 370 }, { 5100873, -279186, 4747 } }, \
165 { 2014500, { 1227000, 0, 0 }, { 5100873, -279186, 4747 } }, \
166 { 2218500, { 1227000, 0, 0 }, { 5100873, -279186, 4747 } }, \
170 #define CPU_CVB_TABLE_XA \
172 .speedo_scale = 100, \
173 .voltage_scale = 1000, \
175 /* f dfll: c0, c1, c2 pll: c0, c1, c2 */ \
176 { 204000, { 1352603, -57545, 1150 }, { 0, 0, 0 } }, \
177 { 306000, { 1412572, -59595, 1150 }, { 0, 0, 0 } }, \
178 { 408000, { 1474199, -61635, 1150 }, { 0, 0, 0 } }, \
179 { 510000, { 1537484, -63675, 1150 }, { 0, 0, 0 } }, \
180 { 612000, { 1602427, -65715, 1150 }, { 0, 0, 0 } }, \
181 { 714000, { 1669028, -67755, 1150 }, { 0, 0, 0 } }, \
182 { 816000, { 1737288, -69795, 1150 }, { 0, 0, 0 } }, \
183 { 918000, { 1807205, -71845, 1150 }, { 0, 0, 0 } }, \
184 { 1020000, { 1878780, -73885, 1150 }, { -2875621, 358099, -8585 } }, \
185 { 1122000, { 1952013, -75925, 1150 }, { -52225, 104159, -2816 } }, \
186 { 1224000, { 2026905, -77965, 1150 }, { 1076868, 8356, -727 } }, \
187 { 1326000, { 2103454, -80005, 1150 }, { 2208191, -84659, 1240 } }, \
188 { 1428000, { 2181661, -82055, 1150 }, { 2519460, -105063, 1611 } }, \
189 { 1530000, { 2261527, -84095, 1150 }, { 2639809, -108729, 1626 } }, \
190 { 1606500, { 2320112, -85615, 1150 }, { 2889664, -122173, 1834 } }, \
191 { 1632000, { 2343050, -86135, 1150 }, { 3386160, -154021, 2393 } }, \
195 #define CPU_CVB_TABLE_EUCM1 \
197 .speedo_scale = 100, \
198 .voltage_scale = 1000, \
200 /* f dfll: c0, c1, c2 pll: c0, c1, c2 */ \
201 { 204000, { 734429, 0, 0 }, { 0, 0, 0 } }, \
202 { 306000, { 768191, 0, 0 }, { 0, 0, 0 } }, \
203 { 408000, { 801953, 0, 0 }, { 0, 0, 0 } }, \
204 { 510000, { 835715, 0, 0 }, { 0, 0, 0 } }, \
205 { 612000, { 869477, 0, 0 }, { 0, 0, 0 } }, \
206 { 714000, { 903239, 0, 0 }, { 0, 0, 0 } }, \
207 { 816000, { 937001, 0, 0 }, { 0, 0, 0 } }, \
208 { 918000, { 970763, 0, 0 }, { 0, 0, 0 } }, \
209 { 1020000, { 1004525, 0, 0 }, { -2875621, 358099, -8585 } }, \
210 { 1122000, { 1038287, 0, 0 }, { -52225, 104159, -2816 } }, \
211 { 1224000, { 1072049, 0, 0 }, { 1076868, 8356, -727 } }, \
212 { 1326000, { 1105811, 0, 0 }, { 2208191, -84659, 1240 } }, \
213 { 1428000, { 1130000, 0, 0 }, { 2519460, -105063, 1611 } }, \
214 { 1555500, { 1130000, 0, 0 }, { 2639809, -108729, 1626 } }, \
215 { 1632000, { 1170000, 0, 0 }, { 2889664, -122173, 1834 } }, \
216 { 1734000, { 1227500, 0, 0 }, { 3386160, -154021, 2393 } }, \
220 #define CPU_CVB_TABLE_EUCM2 \
222 .speedo_scale = 100, \
223 .voltage_scale = 1000, \
225 /* f dfll: c0, c1, c2 pll: c0, c1, c2 */ \
226 { 204000, { 742283 , 0, 0 }, { 0, 0, 0 } }, \
227 { 306000, { 776249 , 0, 0 }, { 0, 0, 0 } }, \
228 { 408000, { 810215 , 0, 0 }, { 0, 0, 0 } }, \
229 { 510000, { 844181 , 0, 0 }, { 0, 0, 0 } }, \
230 { 612000, { 878147 , 0, 0 }, { 0, 0, 0 } }, \
231 { 714000, { 912113 , 0, 0 }, { 0, 0, 0 } }, \
232 { 816000, { 946079 , 0, 0 }, { 0, 0, 0 } }, \
233 { 918000, { 980045 , 0, 0 }, { 0, 0, 0 } }, \
234 { 1020000, { 1014011, 0, 0 }, { -2875621, 358099, -8585 } }, \
235 { 1122000, { 1047977, 0, 0 }, { -52225, 104159, -2816 } }, \
236 { 1224000, { 1081943, 0, 0 }, { 1076868, 8356, -727 } }, \
237 { 1326000, { 1090000, 0, 0 }, { 2208191, -84659, 1240 } }, \
238 { 1479000, { 1090000, 0, 0 }, { 2519460, -105063, 1611 } }, \
239 { 1555500, { 1162000, 0, 0 }, { 2639809, -108729, 1626 } }, \
240 { 1683000, { 1195000, 0, 0 }, { 2889664, -122173, 1834 } }, \
244 static struct cpu_cvb_dvfs cpu_cvb_dvfs_table[] = {
251 .droop_rate_min = 1000000,
252 .min_millivolts = 900,
255 .min_millivolts = 950,
267 .droop_rate_min = 1000000,
268 .min_millivolts = 900,
271 .min_millivolts = 950,
283 .tune0_high_mv = 0xFFEAD0FF,
284 .tune_high_min_millivolts = 864,
286 .droop_rate_min = 1000000,
287 .min_millivolts = 841,
290 .min_millivolts = 950,
301 .tune0_high_mv = 0xFFEAD0FF,
302 .tune_high_min_millivolts = 864,
304 .droop_rate_min = 1000000,
305 .min_millivolts = 841,
308 .min_millivolts = 950,
321 .droop_rate_min = 1000000,
322 .min_millivolts = 870,
325 .min_millivolts = 950,
337 .droop_rate_min = 1000000,
338 .min_millivolts = 870,
341 .min_millivolts = 950,
353 .tune0_high_mv = 0xFFEAD0FF,
354 .tune_high_min_millivolts = 864,
356 .droop_rate_min = 1000000,
357 .min_millivolts = 818,
360 .min_millivolts = 950,
371 .tune0_high_mv = 0xFFEAD0FF,
372 .tune_high_min_millivolts = 864,
374 .droop_rate_min = 1000000,
375 .min_millivolts = 818,
378 .min_millivolts = 950,
391 .droop_rate_min = 1000000,
392 .min_millivolts = 918,
395 .min_millivolts = 950,
407 .droop_rate_min = 1000000,
408 .min_millivolts = 918,
411 .min_millivolts = 950,
423 .tune0_high_mv = 0xFFEAD0FF,
424 .tune_high_min_millivolts = 864,
426 .droop_rate_min = 1000000,
427 .min_millivolts = 822,
430 .min_millivolts = 950,
441 .tune0_high_mv = 0xFFEAD0FF,
442 .tune_high_min_millivolts = 864,
444 .droop_rate_min = 1000000,
445 .min_millivolts = 822,
448 .min_millivolts = 950,
461 .droop_rate_min = 1000000,
462 .min_millivolts = 870,
465 .min_millivolts = 950,
477 .droop_rate_min = 1000000,
478 .min_millivolts = 870,
481 .min_millivolts = 950,
493 .tune0_high_mv = 0xFFEAD0FF,
494 .tune_high_min_millivolts = 864,
496 .droop_rate_min = 1000000,
497 .min_millivolts = 837,
500 .min_millivolts = 950,
511 .tune0_high_mv = 0xFFEAD0FF,
512 .tune_high_min_millivolts = 864,
514 .droop_rate_min = 1000000,
515 .min_millivolts = 837,
518 .min_millivolts = 950,
530 .tune0_high_mv = 0xFFEAD0FF,
531 .tune_high_min_millivolts = 864,
533 .droop_rate_min = 1000000,
534 .min_millivolts = 850,
537 .min_millivolts = 950,
548 .tune0_high_mv = 0xFFEAD0FF,
549 .tune_high_min_millivolts = 864,
551 .droop_rate_min = 1000000,
552 .min_millivolts = 850,
555 .min_millivolts = 950,
563 static int cpu_millivolts[MAX_DVFS_FREQS];
564 static int cpu_dfll_millivolts[MAX_DVFS_FREQS];
566 static struct dvfs cpu_dvfs = {
568 .millivolts = cpu_millivolts,
569 .dfll_millivolts = cpu_dfll_millivolts,
571 .dvfs_rail = &tegra21_dvfs_rail_vdd_cpu,
574 /* CPU LP DVFS tables */
575 #define CPU_LP_CVB_TABLE \
577 .speedo_scale = 100, \
578 .voltage_scale = 1000, \
580 /* f dfll pll: c0, c1, c2 */ \
581 { 204000, { }, { 1112126, -14875, -200 }, }, \
582 { 307200, { }, { 1155822, -15435, -200 }, }, \
583 { 403200, { }, { 1202425, -16005, -200 }, }, \
584 { 518400, { }, { 1251935, -16565, -200 }, }, \
585 { 614400, { }, { 1304351, -17125, -200 }, }, \
586 { 710400, { }, { 1359673, -17685, -200 }, }, \
587 { 825600, { }, { 1417902, -18245, -200 }, }, \
588 { 921600, { }, { 1479037, -18815, -200 }, }, \
589 { 1036800, { }, { 1543079, -19375, -200 }, }, \
590 { 1132800, { }, { 1610027, -19935, -200 }, }, \
591 { 1228800, { }, { 1675881, -20495, -200 }, }, \
595 #define CPU_LP_CVB_TABLE_XA \
597 .speedo_scale = 100, \
598 .voltage_scale = 1000, \
600 /* f dfll pll: c0, c1, c2 */ \
601 { 204000, { }, { 1163829, -15535, -200 }, }, \
602 { 307200, { }, { 1210942, -16095, -200 }, }, \
603 { 403200, { }, { 1260961, -16665, -200 }, }, \
604 { 518400, { }, { 1313886, -17225, -200 }, }, \
605 { 614400, { }, { 1369717, -17785, -200 }, }, \
606 { 710400, { }, { 1428454, -18345, -200 }, }, \
607 { 825600, { }, { 1490098, -18905, -200 }, }, \
608 { 921600, { }, { 1548647, -19475, -200 }, }, \
609 { 940800, { }, { 1556912, -19605, -200 }, }, \
613 static struct cpu_cvb_dvfs cpu_lp_cvb_dvfs_table[] = {
618 .min_millivolts = 818,
628 .min_millivolts = 918,
638 .min_millivolts = 822,
648 .min_millivolts = 837,
658 .min_millivolts = 850,
666 static int cpu_lp_millivolts[MAX_DVFS_FREQS];
668 static struct dvfs cpu_lp_dvfs = {
669 .clk_name = "cpu_lp",
670 .millivolts = cpu_lp_millivolts,
672 .dvfs_rail = &tegra21_dvfs_rail_vdd_cpu,
675 /* GPU DVFS tables */
676 #define NA_FREQ_CVB_TABLE \
678 .speedo_scale = 100, \
679 .thermal_scale = 10, \
680 .voltage_scale = 1000, \
682 /* f dfll pll: c0, c1, c2, c3, c4, c5 */ \
683 { 76800, { }, { 814294, 8144, -940, 808, -21583, 226 }, }, \
684 { 153600, { }, { 856185, 8144, -940, 808, -21583, 226 }, }, \
685 { 230400, { }, { 898077, 8144, -940, 808, -21583, 226 }, }, \
686 { 307200, { }, { 939968, 8144, -940, 808, -21583, 226 }, }, \
687 { 384000, { }, { 981860, 8144, -940, 808, -21583, 226 }, }, \
688 { 460800, { }, { 1023751, 8144, -940, 808, -21583, 226 }, }, \
689 { 537600, { }, { 1065642, 8144, -940, 808, -21583, 226 }, }, \
690 { 614400, { }, { 1107534, 8144, -940, 808, -21583, 226 }, }, \
691 { 691200, { }, { 1149425, 8144, -940, 808, -21583, 226 }, }, \
692 { 768000, { }, { 1191317, 8144, -940, 808, -21583, 226 }, }, \
693 { 844800, { }, { 1233208, 8144, -940, 808, -21583, 226 }, }, \
694 { 921600, { }, { 1275100, 8144, -940, 808, -21583, 226 }, }, \
695 { 998400, { }, { 1316991, 8144, -940, 808, -21583, 226 }, }, \
699 #define NA_FREQ_CVB_TABLE_XA \
701 .speedo_scale = 100, \
702 .thermal_scale = 10, \
703 .voltage_scale = 1000, \
705 /* f dfll pll: c0, c1, c2, c3, c4, c5 */ \
706 { 76800, { }, { 1133092, -20365, -177, 306, -13906, 428 }, }, \
707 { 153600, { }, { 1174337, -20365, -177, 306, -13906, 428 }, }, \
708 { 230400, { }, { 1215582, -20365, -177, 306, -13906, 428 }, }, \
709 { 345600, { }, { 1277341, -20365, -177, 306, -13906, 428 }, }, \
710 { 384000, { }, { 1298071, -20365, -177, 306, -13906, 428 }, }, \
711 { 460800, { }, { 1339315, -20365, -177, 306, -13906, 428 }, }, \
712 { 537600, { }, { 1380560, -20365, -177, 306, -13906, 428 }, }, \
713 { 614400, { }, { 1421804, -20365, -177, 306, -13906, 428 }, }, \
714 { 691200, { }, { 1463049, -20365, -177, 306, -13906, 428 }, }, \
715 { 768000, { }, { 1504293, -20365, -177, 306, -13906, 428 }, }, \
716 { 806400, { }, { 1519915, -20365, -177, 306, -13906, 428 }, }, \
720 #define FIXED_FREQ_CVB_TABLE \
722 .speedo_scale = 100, \
723 .thermal_scale = 10, \
724 .voltage_scale = 1000, \
726 /* f dfll pll: c0, c1, c2 */ \
727 { 76800, { }, { 1786666, -85625, 1632 }, }, \
728 { 153600, { }, { 1846729, -87525, 1632 }, }, \
729 { 230400, { }, { 1910480, -89425, 1632 }, }, \
730 { 307200, { }, { 1977920, -91325, 1632 }, }, \
731 { 384000, { }, { 2049049, -93215, 1632 }, }, \
732 { 460800, { }, { 2122872, -95095, 1632 }, }, \
733 { 537600, { }, { 2201331, -96985, 1632 }, }, \
734 { 614400, { }, { 2283479, -98885, 1632 }, }, \
735 { 691200, { }, { 2369315, -100785, 1632 }, }, \
736 { 768000, { }, { 2458841, -102685, 1632 }, }, \
737 { 844800, { }, { 2550821, -104555, 1632 }, }, \
738 { 921600, { }, { 2647676, -106455, 1632 }, }, \
742 static struct gpu_cvb_dvfs gpu_cvb_dvfs_table[] = {
747 .min_millivolts = 918,
751 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
752 NA_FREQ_CVB_TABLE_XA,
754 FIXED_FREQ_CVB_TABLE,
762 .min_millivolts = 810,
766 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
769 FIXED_FREQ_CVB_TABLE,
777 .min_millivolts = 818,
781 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
784 FIXED_FREQ_CVB_TABLE,
792 .min_millivolts = 840,
796 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
799 FIXED_FREQ_CVB_TABLE,
807 .min_millivolts = 950,
809 #ifdef CONFIG_TEGRA_GPU_DVFS
815 FIXED_FREQ_CVB_TABLE,
819 static int gpu_vmin[MAX_THERMAL_RANGES];
820 static int gpu_peak_millivolts[MAX_DVFS_FREQS];
821 static int gpu_millivolts[MAX_THERMAL_RANGES][MAX_DVFS_FREQS];
822 static struct dvfs gpu_dvfs = {
825 .dvfs_rail = &tegra21_dvfs_rail_vdd_gpu,
828 /* Core DVFS tables */
829 static const int core_millivolts[MAX_DVFS_FREQS] = {
830 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1062, 1075, 1100, 1125 };
832 #define CORE_DVFS(_clk_name, _speedo_id, _process_id, _auto, _mult, _freqs...) \
834 .clk_name = _clk_name, \
835 .speedo_id = _speedo_id, \
836 .process_id = _process_id, \
838 .freqs_mult = _mult, \
839 .millivolts = core_millivolts, \
840 .auto_dvfs = _auto, \
841 .dvfs_rail = &tegra21_dvfs_rail_vdd_core, \
844 #define OVRRD_DVFS(_clk_name, _speedo_id, _process_id, _auto, _mult, _freqs...) \
846 .clk_name = _clk_name, \
847 .speedo_id = _speedo_id, \
848 .process_id = _process_id, \
850 .freqs_mult = _mult, \
851 .millivolts = core_millivolts, \
852 .auto_dvfs = _auto, \
853 .can_override = true, \
854 .dvfs_rail = &tegra21_dvfs_rail_vdd_core, \
858 * Exceptions in the below table that disable framework auto-dvfs:
860 * sbus: Tegra21 platform code calls tegra_dvfs_set_rate manually;
861 * it is necessary for special handling of system clock skipper enabled on T210
863 * display: display driver calls tegra_dvfs_set_rate manually;
864 * it is necessary because display clock divider is internal to the display
865 * block, and controlled by driver directly.
867 * uart: has internal clock divider controlled by driver directly; respectively
868 * defined as manual DVFS clock (however, UART is voltage independent, so no DVFS
869 * is enabled on UART clocks, and driver does not call tegra_dvfs_set_rate).
871 * i2c5: power-i2c transport for PMIC voltage control; voltage independent -
872 * possible deadlock, otherwise.
874 * pwm: transport for OVR voltage control; voltage independent - possible
875 * deadlock, otherwise.
877 static struct dvfs core_dvfs_table[] = {
879 /* Core voltages(mV): 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1062, 1075, 1100, 1125 */
880 CORE_DVFS("emc", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000),
882 CORE_DVFS("vic03", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 601600, 601600),
883 CORE_DVFS("nvjpg", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 601600, 601600),
884 CORE_DVFS("se", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 601600, 601600),
885 CORE_DVFS("tsecb", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 601600, 601600),
886 CORE_DVFS("c2bus", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 601600, 601600),
888 CORE_DVFS("msenc", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 652800, 652800),
889 CORE_DVFS("nvdec", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 652800, 652800),
890 CORE_DVFS("c3bus", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 652800, 652800),
892 CORE_DVFS("vi", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 716800, 716800),
893 CORE_DVFS("isp", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 716800, 716800),
894 CORE_DVFS("cbus", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 716800, 716800),
896 CORE_DVFS("adsp_bus", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 806400, 806400),
897 CORE_DVFS("ape", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 550400, 550400),
899 CORE_DVFS("sbus", 1, -1, 0, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 408000, 408000),
900 CORE_DVFS("host1x", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 408000, 408000),
901 CORE_DVFS("tsec", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 408000, 408000),
902 CORE_DVFS("mselect", 1, -1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 408000, 408000),
904 CORE_DVFS("disp1", 1, -1, 0, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 614400, 614400),
905 CORE_DVFS("disp2", 1, -1, 0, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 614400, 614400),
908 /* Core voltages(mV): 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1062, 1075, 1100, 1125 */
909 CORE_DVFS("emc", 0, 0, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000),
911 CORE_DVFS("vic03", 0, 0, 1, KHZ, 140800, 140800, 268800, 332800, 371200, 409600, 435200, 473600, 499200, 537600, 563200, 563200, 588800, 601600, 627200),
912 CORE_DVFS("nvjpg", 0, 0, 1, KHZ, 140800, 140800, 268800, 332800, 371200, 409600, 435200, 473600, 499200, 537600, 563200, 563200, 588800, 601600, 627200),
913 CORE_DVFS("se", 0, 0, 1, KHZ, 140800, 140800, 268800, 332800, 371200, 409600, 435200, 473600, 499200, 537600, 563200, 563200, 588800, 601600, 627200),
914 CORE_DVFS("tsecb", 0, 0, 1, KHZ, 140800, 140800, 268800, 332800, 371200, 409600, 435200, 473600, 499200, 537600, 563200, 563200, 588800, 601600, 627200),
915 CORE_DVFS("c2bus", 0, 0, 1, KHZ, 140800, 140800, 268800, 332800, 371200, 409600, 435200, 473600, 499200, 537600, 563200, 563200, 588800, 601600, 627200),
917 CORE_DVFS("msenc", 0, 0, 1, KHZ, 192000, 192000, 345600, 396800, 435200, 473600, 512000, 563200, 601600, 627200, 652800, 652800, 678400, 691200, 716800),
918 CORE_DVFS("nvdec", 0, 0, 1, KHZ, 192000, 192000, 345600, 396800, 435200, 473600, 512000, 563200, 601600, 627200, 652800, 652800, 678400, 691200, 716800),
919 CORE_DVFS("c3bus", 0, 0, 1, KHZ, 192000, 192000, 345600, 396800, 435200, 473600, 512000, 563200, 601600, 627200, 652800, 652800, 678400, 691200, 716800),
921 CORE_DVFS("vi", 0, 0, 1, KHZ, 217600, 217600, 307200, 307200, 371200, 435200, 499200, 550400, 614400, 678400, 742400, 742400, 793600, 793600, 793600),
922 CORE_DVFS("isp", 0, 0, 1, KHZ, 217600, 217600, 307200, 307200, 371200, 435200, 499200, 550400, 614400, 678400, 742400, 742400, 793600, 793600, 793600),
923 CORE_DVFS("cbus", 0, 0, 1, KHZ, 217600, 217600, 307200, 307200, 371200, 435200, 499200, 550400, 614400, 678400, 742400, 742400, 793600, 793600, 793600),
925 CORE_DVFS("adsp_bus", 0, 0, 1, KHZ, 153600, 153600, 332800, 371200, 422400, 486400, 563200, 614400, 691200, 742400, 780800, 780800, 819200, 844800, 844800),
926 CORE_DVFS("ape", 0, 0, 1, KHZ, 140800, 140800, 230400, 268800, 307200, 345600, 384000, 448000, 486400, 499200, 499200, 499200, 499200, 499200, 499200),
928 CORE_DVFS("sbus", 0, 0, 0, KHZ, 115200, 115200, 179200, 217600, 243200, 268800, 294400, 320000, 345600, 358400, 371200, 371200, 384000, 408000, 408000),
929 CORE_DVFS("host1x", 0, 0, 1, KHZ, 81600, 81600, 140800, 153600, 166400, 192000, 230400, 281600, 320000, 345600, 371200, 371200, 384000, 408000, 408000),
930 CORE_DVFS("tsec", 0, 0, 1, KHZ, 217600, 217600, 384000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
931 CORE_DVFS("mselect", 0, 0, 1, KHZ, 204000, 204000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
933 CORE_DVFS("disp1", 0, 0, 0, KHZ, 153600, 153600, 332800, 371200, 409600, 422400, 460800, 499200, 537600, 576000, 601600, 601600, 640000, 665600, 665600),
934 CORE_DVFS("disp2", 0, 0, 0, KHZ, 153600, 153600, 332800, 371200, 409600, 422400, 460800, 499200, 537600, 576000, 601600, 601600, 640000, 665600, 665600),
936 /* Core voltages(mV): 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1062, 1075, 1100, 1125 */
937 CORE_DVFS("emc", 0, 1, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000),
939 CORE_DVFS("vic03", 0, 1, 1, KHZ, 192000, 192000, 307200, 345600, 409600, 486400, 524800, 550400, 576000, 588800, 614400, 614400, 627200, 627200, 627200),
940 CORE_DVFS("nvjpg", 0, 1, 1, KHZ, 192000, 192000, 307200, 345600, 409600, 486400, 524800, 550400, 576000, 588800, 614400, 614400, 627200, 627200, 627200),
941 CORE_DVFS("se", 0, 1, 1, KHZ, 192000, 192000, 307200, 345600, 409600, 486400, 524800, 550400, 576000, 588800, 614400, 614400, 627200, 627200, 627200),
942 CORE_DVFS("tsecb", 0, 1, 1, KHZ, 192000, 192000, 307200, 345600, 409600, 486400, 524800, 550400, 576000, 588800, 614400, 614400, 627200, 627200, 627200),
943 CORE_DVFS("c2bus", 0, 1, 1, KHZ, 192000, 192000, 307200, 345600, 409600, 486400, 524800, 550400, 576000, 588800, 614400, 614400, 627200, 627200, 627200),
945 CORE_DVFS("msenc", 0, 1, 1, KHZ, 268800, 268800, 384000, 448000, 486400, 550400, 576000, 614400, 652800, 678400, 691200, 691200, 716800, 716800, 716800),
946 CORE_DVFS("nvdec", 0, 1, 1, KHZ, 268800, 268800, 384000, 448000, 486400, 550400, 576000, 614400, 652800, 678400, 691200, 691200, 716800, 716800, 716800),
947 CORE_DVFS("c3bus", 0, 1, 1, KHZ, 268800, 268800, 384000, 448000, 486400, 550400, 576000, 614400, 652800, 678400, 691200, 691200, 716800, 716800, 716800),
949 CORE_DVFS("vi", 0, 1, 1, KHZ, 268800, 268800, 473600, 473600, 576000, 588800, 678400, 691200, 691200, 691200, 793600, 793600, 793600, 793600, 793600),
950 CORE_DVFS("isp", 0, 1, 1, KHZ, 268800, 268800, 473600, 473600, 576000, 588800, 678400, 691200, 691200, 691200, 793600, 793600, 793600, 793600, 793600),
951 CORE_DVFS("cbus", 0, 1, 1, KHZ, 268800, 268800, 473600, 473600, 576000, 588800, 678400, 691200, 691200, 691200, 793600, 793600, 793600, 793600, 793600),
953 CORE_DVFS("adsp_bus", 0, 1, 1, KHZ, 230400, 230400, 422400, 460800, 524800, 601600, 652800, 704000, 755200, 819200, 844800, 844800, 844800, 844800, 844800),
954 CORE_DVFS("ape", 0, 1, 1, KHZ, 179200, 179200, 307200, 345600, 371200, 409600, 422400, 460800, 499200, 499200, 499200, 499200, 499200, 499200, 499200),
956 CORE_DVFS("sbus", 0, 1, 0, KHZ, 140800, 140800, 230400, 256000, 281600, 307200, 332800, 358400, 371200, 408000, 408000, 408000, 408000, 408000, 408000),
957 CORE_DVFS("host1x", 0, 1, 1, KHZ, 81600, 81600, 153600, 179200, 192000, 217600, 345600, 358400, 384000, 408000, 408000, 408000, 408000, 408000, 408000),
958 CORE_DVFS("tsec", 0, 1, 1, KHZ, 268800, 268800, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
959 CORE_DVFS("mselect", 0, 1, 1, KHZ, 204000, 204000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
961 CORE_DVFS("disp1", 0, 1, 0, KHZ, 243200, 243200, 422400, 460800, 499200, 524800, 563200, 576000, 601600, 640000, 665600, 665600, 665600, 665600, 665600),
962 CORE_DVFS("disp2", 0, 1, 0, KHZ, 243200, 243200, 422400, 460800, 499200, 524800, 563200, 576000, 601600, 640000, 665600, 665600, 665600, 665600, 665600),
964 /* Core voltages(mV): 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1062, 1075, 1100, 1125 */
965 CORE_DVFS("emc", 0, 2, 1, KHZ, 1, 1, 1, 1, 1, 1, 1, 1, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000, 1200000),
967 CORE_DVFS("vic03", 0, 2, 1, KHZ, 230400, 230400, 371200, 448000, 499200, 563200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200),
968 CORE_DVFS("nvjpg", 0, 2, 1, KHZ, 230400, 230400, 371200, 448000, 499200, 563200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200),
969 CORE_DVFS("se", 0, 2, 1, KHZ, 230400, 230400, 371200, 448000, 499200, 563200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200),
970 CORE_DVFS("tsecb", 0, 2, 1, KHZ, 230400, 230400, 371200, 448000, 499200, 563200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200),
971 CORE_DVFS("c2bus", 0, 2, 1, KHZ, 230400, 230400, 371200, 448000, 499200, 563200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200, 627200),
973 CORE_DVFS("msenc", 0, 2, 1, KHZ, 307200, 307200, 486400, 563200, 614400, 640000, 652800, 678400, 716800, 716800, 716800, 716800, 716800, 716800, 716800),
974 CORE_DVFS("nvdec", 0, 2, 1, KHZ, 307200, 307200, 486400, 563200, 614400, 640000, 652800, 678400, 716800, 716800, 716800, 716800, 716800, 716800, 716800),
975 CORE_DVFS("c3bus", 0, 2, 1, KHZ, 307200, 307200, 486400, 563200, 614400, 640000, 652800, 678400, 716800, 716800, 716800, 716800, 716800, 716800, 716800),
977 CORE_DVFS("vi", 0, 2, 1, KHZ, 384000, 384000, 588800, 678400, 691200, 691200, 768000, 793600, 793600, 793600, 793600, 793600, 793600, 793600, 793600),
978 CORE_DVFS("isp", 0, 2, 1, KHZ, 384000, 384000, 588800, 678400, 691200, 691200, 768000, 793600, 793600, 793600, 793600, 793600, 793600, 793600, 793600),
979 CORE_DVFS("cbus", 0, 2, 1, KHZ, 384000, 384000, 588800, 678400, 691200, 691200, 768000, 793600, 793600, 793600, 793600, 793600, 793600, 793600, 793600),
981 CORE_DVFS("adsp_bus", 0, 2, 1, KHZ, 281600, 281600, 499200, 576000, 652800, 691200, 755200, 793600, 844800, 844800, 844800, 844800, 844800, 844800, 844800),
982 CORE_DVFS("ape", 0, 2, 1, KHZ, 230400, 230400, 358400, 396800, 422400, 486400, 499200, 499200, 499200, 499200, 499200, 499200, 499200, 499200, 499200),
984 CORE_DVFS("sbus", 0, 2, 0, KHZ, 204800, 204800, 307200, 332800, 371200, 384000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
985 CORE_DVFS("host1x", 0, 2, 1, KHZ, 128000, 128000, 217600, 345600, 384000, 384000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
986 CORE_DVFS("tsec", 0, 2, 1, KHZ, 345600, 345600, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
987 CORE_DVFS("mselect", 0, 2, 1, KHZ, 204000, 204000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000, 408000),
989 CORE_DVFS("disp1", 0, 2, 0, KHZ, 345600, 345600, 486400, 524800, 563200, 576000, 627200, 640000, 665600, 665600, 665600, 665600, 665600, 665600, 665600),
990 CORE_DVFS("disp2", 0, 2, 0, KHZ, 345600, 345600, 486400, 524800, 563200, 576000, 627200, 640000, 665600, 665600, 665600, 665600, 665600, 665600, 665600),
993 /* Core voltages(mV): 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1062, 1075, 1100, 1125 */
994 CORE_DVFS("pll_a", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
995 CORE_DVFS("pll_c", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
996 CORE_DVFS("pll_c2", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
997 CORE_DVFS("pll_c3", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
998 CORE_DVFS("pll_c4_out0", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
999 CORE_DVFS("pll_d_out0", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
1000 CORE_DVFS("pll_d2", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
1001 CORE_DVFS("pll_dp", -1, -1, 1, KHZ, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000, 1130000),
1003 /* Core voltages(mV): 800, 825, 850, 875, 900, 925, 950, 975, 1000, 1025, 1050, 1062, 1075, 1100, 1125 */
1004 CORE_DVFS("csi", -1, -1, 1, KHZ, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000),
1005 CORE_DVFS("cilab", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1006 CORE_DVFS("cilcd", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1007 CORE_DVFS("cile", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1009 CORE_DVFS("dsia", -1, -1, 1, KHZ, 500000, 500000, 500000, 500000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000),
1010 CORE_DVFS("dsib", -1, -1, 1, KHZ, 500000, 500000, 500000, 500000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000, 750000),
1012 CORE_DVFS("dsialp", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1013 CORE_DVFS("dsiblp", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1015 CORE_DVFS("sor0", -1, -1, 1, KHZ, 162000, 162000, 270000, 270000, 270000, 540000, 540000, 540000, 540000, 540000, 540000, 540000, 540000, 540000, 540000),
1016 CORE_DVFS("sor1", -1, -1, 1, KHZ, 148500, 148500, 297000, 297000, 297000, 297000, 297000, 594000, 594000, 594000, 594000, 594000, 594000, 594000, 594000),
1018 CORE_DVFS("i2s0", -1, -1, 1, KHZ, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576),
1019 CORE_DVFS("i2s1", -1, -1, 1, KHZ, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576),
1020 CORE_DVFS("i2s2", -1, -1, 1, KHZ, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576),
1021 CORE_DVFS("i2s3", -1, -1, 1, KHZ, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576),
1022 CORE_DVFS("i2s4", -1, -1, 1, KHZ, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576, 24576),
1024 CORE_DVFS("d_audio", -1, -1, 1, KHZ, 49152, 49152, 98304, 98304, 98304, 98304, 98304, 98304, 98304, 98304, 98304, 98304, 98304, 98304, 98304),
1025 CORE_DVFS("spdif_out", -1, -1, 1, KHZ, 24576, 24576, 24576, 24576, 24576, 24576, 24728, 24728, 24728, 24728, 24728, 24728, 24728, 24728, 24728),
1026 CORE_DVFS("dmic1", -1, -1, 1, KHZ, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190),
1027 CORE_DVFS("dmic2", -1, -1, 1, KHZ, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190),
1028 CORE_DVFS("dmic3", -1, -1, 1, KHZ, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190, 12190),
1030 CORE_DVFS("hda", -1, -1, 1, KHZ, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000, 51000),
1031 CORE_DVFS("hda2codec_2x", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000),
1033 CORE_DVFS("sdmmc2", -1, -1, 1, KHZ, 1, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1034 CORE_DVFS("sdmmc4", -1, -1, 1, KHZ, 1, 200000, 266000, 266000, 266000, 266000, 266000, 266000, 266000, 266000, 266000, 266000, 266000, 266000, 266000),
1035 CORE_DVFS("sdmmc2_ddr", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1036 CORE_DVFS("sdmmc4_ddr", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1038 CORE_DVFS("sdmmc1", -1, -1, 1, KHZ, 136000, 136000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1039 CORE_DVFS("sdmmc3", -1, -1, 1, KHZ, 136000, 136000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1041 CORE_DVFS("sdmmc1_ddr", -1, -1, 1, KHZ, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000),
1042 CORE_DVFS("sdmmc3_ddr", -1, -1, 1, KHZ, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000, 96000),
1044 CORE_DVFS("xusb_falcon_src", -1, -1, 1, KHZ, 1, 1, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000),
1045 CORE_DVFS("xusb_host_src", -1, -1, 1, KHZ, 1, 1, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000),
1046 CORE_DVFS("xusb_dev_src", -1, -1, 1, KHZ, 1, 1, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000),
1047 CORE_DVFS("xusb_ssp_src", -1, -1, 1, KHZ, 1, 1, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000),
1048 CORE_DVFS("xusb_fs_src", -1, -1, 1, KHZ, 1, 1, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000),
1049 CORE_DVFS("xusb_hs_src", -1, -1, 1, KHZ, 1, 1, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000),
1050 CORE_DVFS("usbd", -1, -1, 1, KHZ, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000),
1051 CORE_DVFS("usb2", -1, -1, 1, KHZ, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000),
1052 CORE_DVFS("usb3", -1, -1, 1, KHZ, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000, 480000),
1054 CORE_DVFS("sata", -1, -1, 1, KHZ, 1, 1, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
1055 CORE_DVFS("sata_oob", -1, -1, 1, KHZ, 1, 1, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1056 CORE_DVFS("pciex", -1, -1, 1, KHZ, 1, 1, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000),
1058 CORE_DVFS("i2c1", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1059 CORE_DVFS("i2c2", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1060 CORE_DVFS("i2c3", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1061 CORE_DVFS("i2c4", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1062 CORE_DVFS("i2c5", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1063 CORE_DVFS("i2c6", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1064 CORE_DVFS("vii2c", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1066 CORE_DVFS("pwm", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000),
1068 CORE_DVFS("uarta", -1, -1, 0, KHZ, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1069 CORE_DVFS("uartb", -1, -1, 0, KHZ, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1070 CORE_DVFS("uartc", -1, -1, 0, KHZ, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1071 CORE_DVFS("uartd", -1, -1, 0, KHZ, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1072 CORE_DVFS("uartape", -1, -1, 0, KHZ, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000, 204000),
1074 CORE_DVFS("soc_therm", -1, -1, 1, KHZ, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000, 136000),
1075 CORE_DVFS("tsensor", -1, -1, 1, KHZ, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200, 19200),
1078 static struct dvfs sor1_dp_dvfs_table[] = {
1079 CORE_DVFS("sor1", -1, -1, 1, KHZ, 162000, 162000, 270000, 270000, 270000, 540000, 540000, 540000, 540000, 540000, 540000, 540000, 540000, 540000, 540000),
1082 static struct dvfs spi_dvfs_table[] = {
1083 CORE_DVFS("sbc1", -1, -1, 1, KHZ, 12000, 35000, 50000, 50000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000),
1084 CORE_DVFS("sbc2", -1, -1, 1, KHZ, 12000, 35000, 50000, 50000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000),
1085 CORE_DVFS("sbc3", -1, -1, 1, KHZ, 12000, 35000, 50000, 50000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000),
1086 CORE_DVFS("sbc4", -1, -1, 1, KHZ, 12000, 35000, 50000, 50000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000, 65000),
1090 static struct dvfs spi_slave_dvfs_table[] = {
1091 CORE_DVFS("sbc1", -1, -1, 1, KHZ, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000),
1092 CORE_DVFS("sbc2", -1, -1, 1, KHZ, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000),
1093 CORE_DVFS("sbc3", -1, -1, 1, KHZ, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000),
1094 CORE_DVFS("sbc4", -1, -1, 1, KHZ, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000, 45000),
1098 static struct dvfs qspi_sdr_dvfs_table[] = {
1099 CORE_DVFS("qspi", -1, -1, 1, KHZ, 81600, 81600, 116600, 116600, 116600, 116600, 116600, 116600, 116600, 116600, 116600, 116600, 116600, 116600, 116600),
1102 static struct dvfs qspi_ddr_dvfs_table[] = {
1103 CORE_DVFS("qspi", -1, -1, 1, KHZ, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600, 81600),
1106 static int tegra_dvfs_disable_core_set(const char *arg,
1107 const struct kernel_param *kp)
1111 ret = param_set_bool(arg, kp);
1115 if (tegra_dvfs_core_disabled)
1116 tegra_dvfs_rail_disable(&tegra21_dvfs_rail_vdd_core);
1118 tegra_dvfs_rail_enable(&tegra21_dvfs_rail_vdd_core);
1123 static int tegra_dvfs_disable_cpu_set(const char *arg,
1124 const struct kernel_param *kp)
1128 ret = param_set_bool(arg, kp);
1132 if (tegra_dvfs_cpu_disabled)
1133 tegra_dvfs_rail_disable(&tegra21_dvfs_rail_vdd_cpu);
1135 tegra_dvfs_rail_enable(&tegra21_dvfs_rail_vdd_cpu);
1140 static int tegra_dvfs_disable_gpu_set(const char *arg,
1141 const struct kernel_param *kp)
1145 ret = param_set_bool(arg, kp);
1149 if (tegra_dvfs_gpu_disabled)
1150 tegra_dvfs_rail_disable(&tegra21_dvfs_rail_vdd_gpu);
1152 tegra_dvfs_rail_enable(&tegra21_dvfs_rail_vdd_gpu);
1157 static int tegra_dvfs_disable_get(char *buffer, const struct kernel_param *kp)
1159 return param_get_bool(buffer, kp);
1162 static struct kernel_param_ops tegra_dvfs_disable_core_ops = {
1163 .set = tegra_dvfs_disable_core_set,
1164 .get = tegra_dvfs_disable_get,
1167 static struct kernel_param_ops tegra_dvfs_disable_cpu_ops = {
1168 .set = tegra_dvfs_disable_cpu_set,
1169 .get = tegra_dvfs_disable_get,
1172 static struct kernel_param_ops tegra_dvfs_disable_gpu_ops = {
1173 .set = tegra_dvfs_disable_gpu_set,
1174 .get = tegra_dvfs_disable_get,
1177 module_param_cb(disable_core, &tegra_dvfs_disable_core_ops,
1178 &tegra_dvfs_core_disabled, 0644);
1179 module_param_cb(disable_cpu, &tegra_dvfs_disable_cpu_ops,
1180 &tegra_dvfs_cpu_disabled, 0644);
1181 module_param_cb(disable_gpu, &tegra_dvfs_disable_gpu_ops,
1182 &tegra_dvfs_gpu_disabled, 0644);
1184 static bool __init match_dvfs_one(const char *name,
1185 int dvfs_speedo_id, int dvfs_process_id,
1186 int speedo_id, int process_id)
1188 if ((dvfs_process_id != -1 && dvfs_process_id != process_id) ||
1189 (dvfs_speedo_id != -1 && dvfs_speedo_id != speedo_id)) {
1190 pr_debug("tegra21_dvfs: rejected %s speedo %d, process %d\n",
1191 name, dvfs_speedo_id, dvfs_process_id);
1197 /* cvb_mv = ((c2 * speedo / s_scale + c1) * speedo / s_scale + c0) / v_scale */
1198 static inline int get_cvb_voltage(int speedo, int s_scale,
1199 struct cvb_dvfs_parameters *cvb)
1201 /* apply only speedo scale: output mv = cvb_mv * v_scale */
1203 mv = DIV_ROUND_CLOSEST(cvb->c2 * speedo, s_scale);
1204 mv = DIV_ROUND_CLOSEST((mv + cvb->c1) * speedo, s_scale) + cvb->c0;
1209 ((c3 * speedo / s_scale + c4 + c5 * T / t_scale) * T / t_scale) / v_scale */
1210 static inline int get_cvb_t_voltage(int speedo, int s_scale, int t, int t_scale,
1211 struct cvb_dvfs_parameters *cvb)
1213 /* apply speedo & temperature scales: output mv = cvb_t_mv * v_scale */
1215 mv = DIV_ROUND_CLOSEST(cvb->c3 * speedo, s_scale) + cvb->c4 +
1216 DIV_ROUND_CLOSEST(cvb->c5 * t, t_scale);
1217 mv = DIV_ROUND_CLOSEST(mv * t, t_scale);
1221 static int round_cvb_voltage(int mv, int v_scale, struct rail_alignment *align)
1223 /* combined: apply voltage scale and round to cvb alignment step */
1225 int step = (align->step_uv ? : 1000) * v_scale;
1226 int offset = align->offset_uv * v_scale;
1228 uv = max(mv * 1000, offset) - offset;
1229 uv = DIV_ROUND_UP(uv, step) * align->step_uv + align->offset_uv;
1233 static int round_voltage(int mv, struct rail_alignment *align, bool up)
1235 if (align->step_uv) {
1236 int uv = max(mv * 1000, align->offset_uv) - align->offset_uv;
1237 uv = (uv + (up ? align->step_uv - 1 : 0)) / align->step_uv;
1238 return (uv * align->step_uv + align->offset_uv) / 1000;
1243 /* Setup CPU clusters tables */
1246 * Setup fast CPU DVFS tables in PLL and DFLL modes from CVB data, determine
1247 * nominal voltage for CPU rail, and CPU maximum frequency. Note that entire
1248 * frequency range is guaranteed only when DFLL is used as CPU clock source.
1249 * Reaching maximum frequency on PLL may not be possible within nominal voltage
1250 * range (DVFS core would fail frequency request in this case, so that voltage
1251 * limit is not violated). Error when CPU DVFS table can not be constructed must
1254 static int __init set_cpu_dvfs_data(unsigned long max_freq,
1255 struct cpu_cvb_dvfs *d, struct dvfs *cpu_dvfs, int *max_freq_index)
1257 int j, mv, min_mv, dfll_mv, min_dfll_mv;
1258 unsigned long fmax_at_vmin = 0;
1259 unsigned long fmax_pll_mode = 0;
1260 unsigned long fmin_use_dfll = 0;
1261 int speedo = tegra_cpu_speedo_value();
1263 struct cvb_dvfs_table *table = NULL;
1264 struct dvfs_rail *rail = &tegra21_dvfs_rail_vdd_cpu;
1265 struct rail_alignment *align = &rail->alignment;
1267 min_dfll_mv = d->dfll_tune_data.min_millivolts;
1268 if (min_dfll_mv < rail->min_millivolts) {
1269 pr_debug("tegra21_dvfs: dfll min %dmV below rail min %dmV\n",
1270 min_dfll_mv, rail->min_millivolts);
1271 min_dfll_mv = rail->min_millivolts;
1273 min_dfll_mv = round_voltage(min_dfll_mv, align, true);
1275 min_mv = d->pll_tune_data.min_millivolts;
1276 if (min_mv < rail->min_millivolts) {
1277 pr_debug("tegra21_dvfs: pll min %dmV below rail min %dmV\n",
1278 min_mv, rail->min_millivolts);
1279 min_mv = rail->min_millivolts;
1281 min_mv = round_voltage(min_mv, align, true);
1283 d->max_mv = round_voltage(d->max_mv, align, false);
1284 BUG_ON(d->max_mv > rail->max_millivolts);
1287 * Use CVB table to fill in CPU dvfs frequencies and voltages. Each
1288 * CVB entry specifies CPU frequency and CVB coefficients to calculate
1289 * the respective voltage when either DFLL or PLL is used as CPU clock
1292 * Different minimum voltage limits are applied to DFLL and PLL sources.
1293 * Same maximum voltage limit is used for both sources, but differently:
1294 * directly limit voltage for DFLL, and limit maximum frequency for PLL.
1296 for (j = 0; j < MAX_DVFS_FREQS; j++) {
1297 table = &d->cvb_table[j];
1298 if (!table->freq || (table->freq > max_freq))
1301 dfll_mv = get_cvb_voltage(
1302 speedo, d->speedo_scale, &table->cvb_dfll_param);
1303 dfll_mv = round_cvb_voltage(dfll_mv, d->voltage_scale, align);
1304 dfll_mv = max(dfll_mv, min_dfll_mv);
1306 mv = get_cvb_voltage(
1307 speedo, d->speedo_scale, &table->cvb_pll_param);
1308 #ifdef BRINGUP_CVB_V_MARGIN
1309 mv = mv * (100 + BRINGUP_CVB_V_MARGIN +
1310 BRINGUP_CVB_V_MARGIN_EX) / 100;
1312 mv = round_cvb_voltage(mv, d->voltage_scale, align);
1313 mv = max(mv, min_mv);
1316 * Check maximum frequency at minimum voltage for dfll source;
1317 * round down unless all table entries are above Vmin, then use
1318 * the 1st entry as is.
1320 if (dfll_mv > min_dfll_mv) {
1322 fmax_at_vmin = table->freq;
1324 fmax_at_vmin = cpu_dvfs->freqs[j - 1];
1327 /* Clip maximum frequency at maximum voltage for pll source */
1328 if (mv > d->max_mv) {
1330 break; /* 1st entry already above Vmax */
1332 fmax_pll_mode = cpu_dvfs->freqs[j - 1];
1335 /* Minimum rate with pll source voltage above dfll Vmin */
1336 if ((mv >= min_dfll_mv) && (!fmin_use_dfll))
1337 fmin_use_dfll = table->freq;
1339 /* fill in dvfs tables */
1340 cpu_dvfs->freqs[j] = table->freq;
1341 cpu_dfll_millivolts[j] = min(dfll_mv, d->max_mv);
1342 cpu_millivolts[j] = mv;
1345 /* Table must not be empty, must have at least one entry above Vmin */
1346 if (!j || !fmax_at_vmin) {
1347 pr_err("tegra21_dvfs: invalid cpu dvfs table\n");
1351 /* In the dfll operating range dfll voltage at any rate should be
1352 better (below) than pll voltage */
1353 if (!fmin_use_dfll || (fmin_use_dfll > fmax_at_vmin)) {
1354 WARN(1, "tegra21_dvfs: pll voltage is below dfll in the dfll"
1355 " operating range\n");
1356 fmin_use_dfll = fmax_at_vmin;
1359 /* dvfs tables are successfully populated - fill in the rest */
1360 cpu_dvfs->speedo_id = d->speedo_id;
1361 cpu_dvfs->boost_table = max_freq > CPU_BOOST_THRESHOLD;
1362 cpu_dvfs->process_id = d->process_id;
1363 cpu_dvfs->freqs_mult = d->freqs_mult;
1364 cpu_dvfs->dvfs_rail->nominal_millivolts = min(d->max_mv,
1365 max(cpu_millivolts[j - 1], cpu_dfll_millivolts[j - 1]));
1366 *max_freq_index = j - 1;
1368 cpu_dvfs->dfll_data = d->dfll_tune_data;
1369 cpu_dvfs->dfll_data.max_rate_boost = fmax_pll_mode ?
1370 (cpu_dvfs->freqs[j - 1] - fmax_pll_mode) * d->freqs_mult : 0;
1371 cpu_dvfs->dfll_data.out_rate_min = fmax_at_vmin * d->freqs_mult;
1372 cpu_dvfs->dfll_data.use_dfll_rate_min = fmin_use_dfll * d->freqs_mult;
1373 cpu_dvfs->dfll_data.min_millivolts = min_dfll_mv;
1375 if (tegra_dfll_boot_req_khz()) {
1376 /* If boot on DFLL, rail is already under DFLL control */
1377 cpu_dvfs->dfll_data.dfll_boot_khz = tegra_dfll_boot_req_khz();
1378 rail->dfll_mode = true;
1384 static void __init init_cpu_dvfs_table(int *cpu_max_freq_index)
1387 int cpu_speedo_id = tegra_cpu_speedo_id();
1388 int cpu_process_id = tegra_cpu_process_id();
1390 for (ret = 0, i = 0; i < ARRAY_SIZE(cpu_cvb_dvfs_table); i++) {
1391 struct cpu_cvb_dvfs *d = &cpu_cvb_dvfs_table[i];
1392 unsigned long max_freq = d->max_freq;
1393 if (match_dvfs_one("cpu cvb", d->speedo_id, d->process_id,
1394 cpu_speedo_id, cpu_process_id)) {
1395 ret = set_cpu_dvfs_data(max_freq,
1396 d, &cpu_dvfs, cpu_max_freq_index);
1400 BUG_ON((i == ARRAY_SIZE(cpu_cvb_dvfs_table)) || ret);
1404 * Setup slow CPU (a.k.a LP CPU) DVFS table from CVB data. Only PLL is used as
1405 * a clock source for slow CPU. Its maximum frequency must be reached within
1406 * nominal voltage -- CVB frequency list is cut off at rate that exceeds either
1407 * sku-based maximum limit or requires voltage above nominal. Error when DVFS
1408 * table can not be constructed must never happen.
1410 * Final CPU rail nominal voltage is set as maximum of fast and slow CPUs
1413 static int __init set_cpu_lp_dvfs_data(unsigned long max_freq,
1414 struct cpu_cvb_dvfs *d, struct dvfs *cpu_lp_dvfs, int *max_freq_index)
1417 int speedo = tegra_cpu_speedo_value(); /* FIXME cpu_lp_speedo */
1419 struct cvb_dvfs_table *table = NULL;
1420 struct dvfs_rail *rail = &tegra21_dvfs_rail_vdd_cpu;
1421 struct rail_alignment *align = &rail->alignment;
1423 min_mv = d->pll_tune_data.min_millivolts;
1424 if (min_mv < rail->min_millivolts) {
1425 pr_debug("tegra21_dvfs: scpu min %dmV below rail min %dmV\n",
1426 min_mv, rail->min_millivolts);
1427 min_mv = rail->min_millivolts;
1429 min_mv = round_voltage(min_mv, align, true);
1431 d->max_mv = round_voltage(d->max_mv, align, false);
1432 BUG_ON(d->max_mv > rail->max_millivolts);
1433 rail->nominal_millivolts = max(rail->nominal_millivolts, d->max_mv);
1436 * Use CVB table to fill in CPU dvfs frequencies and voltages. Each
1437 * CVB entry specifies CPU frequency and CVB coefficients to calculate
1438 * the respective voltage. Only PLL is used as CPU LP clock source, and
1439 * the respective minimum limit is applied to each table entry. Table
1440 * construction is aborted if calculated voltage is above maximum limit.
1442 for (j = 0; j < MAX_DVFS_FREQS; j++) {
1443 table = &d->cvb_table[j];
1444 if (!table->freq || (table->freq > max_freq))
1447 mv = get_cvb_voltage(
1448 speedo, d->speedo_scale, &table->cvb_pll_param);
1449 mv = round_cvb_voltage(mv, d->voltage_scale, align);
1450 mv = max(mv, min_mv);
1452 if (mv > d->max_mv) {
1453 pr_warn("tegra21_dvfs: %dmV for %s rate %lu above limit %dmV\n",
1454 mv, cpu_lp_dvfs->clk_name, table->freq, d->max_mv);
1458 /* fill in dvfs tables */
1459 cpu_lp_dvfs->freqs[j] = table->freq;
1460 cpu_lp_millivolts[j] = mv;
1463 /* Table must not be empty */
1465 pr_err("tegra21_dvfs: invalid cpu lp dvfs table\n");
1469 /* dvfs tables are successfully populated - fill in the rest */
1470 cpu_lp_dvfs->speedo_id = d->speedo_id;
1471 cpu_lp_dvfs->process_id = d->process_id;
1472 cpu_lp_dvfs->freqs_mult = d->freqs_mult;
1473 *max_freq_index = j - 1;
1478 static void __init init_cpu_lp_dvfs_table(int *cpu_lp_max_freq_index)
1481 int cpu_lp_speedo_id = tegra_cpu_speedo_id(); /* FIXME cpu_lp_ */
1482 int cpu_lp_process_id = tegra_cpu_process_id(); /* FIXME cpu_lp_ */
1484 for (ret = 0, i = 0; i < ARRAY_SIZE(cpu_lp_cvb_dvfs_table); i++) {
1485 struct cpu_cvb_dvfs *d = &cpu_lp_cvb_dvfs_table[i];
1486 unsigned long max_freq = d->max_freq;
1487 if (match_dvfs_one("cpu lp cvb", d->speedo_id, d->process_id,
1488 cpu_lp_speedo_id, cpu_lp_process_id)) {
1489 ret = set_cpu_lp_dvfs_data(max_freq,
1490 d, &cpu_lp_dvfs, cpu_lp_max_freq_index);
1494 BUG_ON((i == ARRAY_SIZE(cpu_lp_cvb_dvfs_table)) || ret);
1498 * Common for both CPU clusters: initialize thermal profiles, and register
1499 * Vmax cooling device.
1501 static int __init init_cpu_rail_thermal_profile(struct dvfs *cpu_dvfs)
1503 struct dvfs_rail *rail = &tegra21_dvfs_rail_vdd_cpu;
1506 * Failure to get/configure trips may not be fatal for boot - let it
1507 * boot, even with partial configuration with appropriate WARNING, and
1508 * invalidate cdev. It must not happen with production DT, of course.
1510 if (rail->vmin_cdev) {
1511 if (tegra_dvfs_rail_of_init_vmin_thermal_profile(
1512 vdd_cpu_vmin_trips_table, vdd_cpu_therm_floors_table,
1513 rail, &cpu_dvfs->dfll_data))
1514 rail->vmin_cdev = NULL;
1517 if (rail->vmax_cdev) {
1518 if (tegra_dvfs_rail_of_init_vmax_thermal_profile(
1519 vdd_cpu_vmax_trips_table, vdd_cpu_therm_caps_table,
1520 rail, &cpu_dvfs->dfll_data))
1521 rail->vmax_cdev = NULL;
1528 * CPU Vmax cooling device registration for pll mode:
1529 * - Use CPU capping method provided by CPUFREQ platform driver
1530 * - Skip registration if most aggressive cap is at/above maximum voltage
1532 static int __init tegra21_dvfs_register_cpu_vmax_cdev(void)
1534 struct dvfs_rail *rail;
1536 rail = &tegra21_dvfs_rail_vdd_cpu;
1537 rail->apply_vmax_cap = tegra_cpu_volt_cap_apply;
1538 if (rail->vmax_cdev) {
1539 int i = rail->vmax_cdev->trip_temperatures_num;
1540 if (i && rail->therm_mv_caps[i-1] < rail->nominal_millivolts)
1541 tegra_dvfs_rail_register_vmax_cdev(rail);
1545 late_initcall(tegra21_dvfs_register_cpu_vmax_cdev);
1548 /* Setup GPU tables */
1551 * Find maximum GPU frequency that can be reached at minimum voltage across all
1552 * temperature ranges.
1554 static unsigned long __init find_gpu_fmax_at_vmin(
1555 struct dvfs *gpu_dvfs, int thermal_ranges, int freqs_num)
1558 unsigned long fmax = ULONG_MAX;
1561 * For voltage scaling row in each temperature range, as well as peak
1562 * voltage row find maximum frequency at lowest voltage, and return
1563 * minimax. On Tegra21 all GPU DVFS thermal dependencies are integrated
1564 * into thermal DVFS table (i.e., there is no separate thermal floors
1565 * applied in the rail level). Hence, returned frequency specifies max
1566 * frequency safe at minimum voltage across all temperature ranges.
1568 for (j = 0; j < thermal_ranges; j++) {
1569 for (i = 1; i < freqs_num; i++) {
1570 if (gpu_millivolts[j][i] > gpu_millivolts[j][0])
1573 fmax = min(fmax, gpu_dvfs->freqs[i - 1]);
1576 for (i = 1; i < freqs_num; i++) {
1577 if (gpu_peak_millivolts[i] > gpu_peak_millivolts[0])
1580 fmax = min(fmax, gpu_dvfs->freqs[i - 1]);
1586 * Determine minimum voltage safe at maximum frequency across all temperature
1589 static int __init find_gpu_vmin_at_fmax(
1590 struct dvfs *gpu_dvfs, int thermal_ranges, int freqs_num)
1595 * For voltage scaling row in each temperature range find minimum
1596 * voltage at maximum frequency and return max Vmin across ranges.
1598 for (vmin = 0, j = 0; j < thermal_ranges; j++)
1599 vmin = max(vmin, gpu_millivolts[j][freqs_num-1]);
1605 * Init thermal scaling trips, find number of thermal ranges; note that the 1st
1606 * trip-point is used for voltage calculations within the lowest range, but
1607 * should not be actually set. Hence, at least 2 scaling trip-points must be
1608 * specified in DT; number of scaling ranges = number of trips in DT; number
1609 * of scaling trips bound to scaling cdev is number of trips in DT minus one.
1611 * Failure to get/configure trips may not be fatal for boot - let it try,
1612 * anyway, with appropriate WARNING. It must not happen with production DT, of
1615 static int __init init_gpu_rail_thermal_scaling(struct dvfs_rail *rail,
1616 struct gpu_cvb_dvfs *d)
1618 int thermal_ranges = 1; /* No thermal depndencies */
1620 if (!rail->vts_cdev)
1623 thermal_ranges = of_tegra_dvfs_rail_get_cdev_trips(
1624 rail->vts_cdev, d->vts_trips_table, d->therm_floors_table,
1625 &rail->alignment, true);
1627 if (thermal_ranges < 0) {
1628 WARN(1, "tegra21_dvfs: %s: failed to get trips from DT\n",
1633 if (thermal_ranges < 2) {
1634 WARN(1, "tegra21_dvfs: %s: only %d trip (must be at least 2)\n",
1635 rail->reg_id, thermal_ranges);
1639 rail->vts_cdev->trip_temperatures_num = thermal_ranges - 1;
1640 rail->vts_cdev->trip_temperatures = d->vts_trips_table;
1641 return thermal_ranges;
1645 * Initialize thermal capping trips and rates: for each cap point (Tk, Vk) find
1646 * min{ maxF(V <= Vk, j), j >= j0 }, where j0 is index for minimum scaling
1647 * trip-point above Tk with margin: j0 = min{ j, Tj >= Tk - margin }.
1649 #define CAP_TRIP_ON_SCALING_MARGIN 5
1650 static void __init init_gpu_cap_rates(struct dvfs *gpu_dvfs,
1651 struct dvfs_rail *rail, int thermal_ranges, int freqs_num)
1655 for (k = 0; k < rail->vmax_cdev->trip_temperatures_num; k++) {
1656 int cap_tempr = vdd_gpu_vmax_trips_table[k];
1657 int cap_level = vdd_gpu_therm_caps_table[k];
1658 unsigned long cap_freq = clk_get_max_rate(vgpu_cap_clk);
1660 for (j = 0; j < thermal_ranges; j++) {
1661 if ((j < thermal_ranges - 1) && /* vts trips=ranges-1 */
1662 (rail->vts_cdev->trip_temperatures[j] +
1663 CAP_TRIP_ON_SCALING_MARGIN < cap_tempr))
1666 for (i = 1; i < freqs_num; i++) {
1667 if (gpu_millivolts[j][i] > cap_level)
1670 cap_freq = min(cap_freq, gpu_dvfs->freqs[i - 1]);
1672 gpu_cap_rates[k] = cap_freq * gpu_dvfs->freqs_mult;
1676 static int __init init_gpu_rail_thermal_caps(struct dvfs *gpu_dvfs,
1677 struct dvfs_rail *rail, int thermal_ranges, int freqs_num)
1679 const char *cap_clk_name = "cap.vgpu.gbus";
1681 if (!rail->vmax_cdev)
1684 vgpu_cap_clk = tegra_get_clock_by_name(cap_clk_name);
1685 if (!vgpu_cap_clk) {
1686 WARN(1, "tegra21_dvfs: %s: failed to get cap clock %s\n",
1687 rail->reg_id, cap_clk_name);
1691 if (tegra_dvfs_rail_of_init_vmax_thermal_profile(
1692 vdd_gpu_vmax_trips_table, vdd_gpu_therm_caps_table, rail, NULL))
1696 init_gpu_cap_rates(gpu_dvfs, rail, thermal_ranges, freqs_num);
1700 rail->vmax_cdev = NULL;
1705 * Setup gpu dvfs tables from cvb data, determine nominal voltage for gpu rail,
1706 * and gpu maximum frequency. Error when gpu dvfs table can not be constructed
1707 * must never happen.
1709 static int __init set_gpu_dvfs_data(unsigned long max_freq,
1710 struct gpu_cvb_dvfs *d, struct dvfs *gpu_dvfs, int *max_freq_index)
1712 int i, j, thermal_ranges, mv, min_mv;
1713 struct cvb_dvfs_table *table = NULL;
1714 int speedo = tegra_gpu_speedo_value();
1715 struct dvfs_rail *rail = &tegra21_dvfs_rail_vdd_gpu;
1716 struct rail_alignment *align = &rail->alignment;
1718 d->max_mv = round_voltage(d->max_mv, align, false);
1719 min_mv = d->pll_tune_data.min_millivolts;
1720 if (min_mv < rail->min_millivolts) {
1721 pr_debug("tegra21_dvfs: gpu min %dmV below rail min %dmV\n",
1722 min_mv, rail->min_millivolts);
1723 min_mv = rail->min_millivolts;
1727 * Get scaling thermal ranges; 1 range implies no thermal dependency.
1728 * Invalidate scaling cooling device in the latter case.
1730 thermal_ranges = init_gpu_rail_thermal_scaling(rail, d);
1731 if (thermal_ranges == 1)
1732 rail->vts_cdev = NULL;
1735 * Apply fixed thermal floor for each temperature range
1737 for (j = 0; j < thermal_ranges; j++) {
1738 mv = max(min_mv, d->therm_floors_table[j]);
1739 gpu_vmin[j] = round_voltage(mv, align, true);
1743 * Use CVB table to fill in gpu dvfs frequencies and voltages. Each
1744 * CVB entry specifies gpu frequency and CVB coefficients to calculate
1745 * the respective voltage.
1747 for (i = 0; i < MAX_DVFS_FREQS; i++) {
1748 table = &d->cvb_table[i];
1749 if (!table->freq || (table->freq > max_freq))
1752 mv = get_cvb_voltage(
1753 speedo, d->speedo_scale, &table->cvb_pll_param);
1754 for (j = 0; j < thermal_ranges; j++) {
1756 int t = thermal_ranges == 1 ? 0 :
1757 rail->vts_cdev->trip_temperatures[j];
1759 /* get thermal offset for this trip-point */
1760 mvj += get_cvb_t_voltage(speedo, d->speedo_scale,
1761 t, d->thermal_scale, &table->cvb_pll_param);
1762 mvj = round_cvb_voltage(mvj, d->voltage_scale, align);
1764 /* clip to minimum, abort if above maximum */
1765 mvj = max(mvj, gpu_vmin[j]);
1766 if (mvj > d->max_mv)
1770 * Update voltage for adjacent ranges bounded by this
1771 * trip-point (cvb & dvfs are transpose matrices, and
1772 * cvb freq row index is column index for dvfs matrix)
1774 gpu_millivolts[j][i] = mvj;
1775 if (j && (gpu_millivolts[j-1][i] < mvj))
1776 gpu_millivolts[j-1][i] = mvj;
1778 /* Make sure all voltages for this frequency are below max */
1779 if (j < thermal_ranges)
1782 /* fill in gpu dvfs tables */
1783 gpu_dvfs->freqs[i] = table->freq;
1787 * Table must not be empty, must have at least one entry in range, and
1788 * must specify monotonically increasing voltage on frequency dependency
1789 * in each temperature range.
1791 if (!i || tegra_dvfs_init_thermal_dvfs_voltages(&gpu_millivolts[0][0],
1792 gpu_peak_millivolts, i, thermal_ranges, gpu_dvfs)) {
1793 pr_err("tegra21_dvfs: invalid gpu dvfs table\n");
1797 /* Shift out the 1st trip-point */
1798 for (j = 1; j < thermal_ranges; j++)
1799 rail->vts_cdev->trip_temperatures[j - 1] =
1800 rail->vts_cdev->trip_temperatures[j];
1802 /* dvfs tables are successfully populated - fill in the gpu dvfs */
1803 gpu_dvfs->speedo_id = d->speedo_id;
1804 gpu_dvfs->process_id = d->process_id;
1805 gpu_dvfs->freqs_mult = d->freqs_mult;
1807 *max_freq_index = i - 1;
1809 gpu_dvfs->dvfs_rail->nominal_millivolts = min(d->max_mv,
1810 find_gpu_vmin_at_fmax(gpu_dvfs, thermal_ranges, i));
1812 gpu_dvfs->fmax_at_vmin_safe_t = d->freqs_mult *
1813 find_gpu_fmax_at_vmin(gpu_dvfs, thermal_ranges, i);
1815 /* Initialize thermal capping */
1816 init_gpu_rail_thermal_caps(gpu_dvfs, rail, thermal_ranges, i);
1818 #ifdef CONFIG_TEGRA_USE_NA_GPCPLL
1820 * Set NA DVFS flag, if GPCPLL NA mode is enabled. This is necessary to
1821 * make sure that GPCPLL configuration is updated by tegra core DVFS
1822 * when thermal DVFS cooling device state is changed. Since tegra core
1823 * DVFS does not support NA operations for Vmin cooling device, GPU Vmin
1824 * thermal floors have been integrated with thermal DVFS, and no Vmin
1825 * cooling device is installed.
1827 if (tegra_fuse_can_use_na_gpcpll())
1828 gpu_dvfs->na_dvfs = 1;
1833 static void __init init_gpu_dvfs_table(int *gpu_max_freq_index)
1836 int gpu_speedo_id = tegra_gpu_speedo_id();
1837 int gpu_process_id = tegra_gpu_process_id();
1839 for (ret = 0, i = 0; i < ARRAY_SIZE(gpu_cvb_dvfs_table); i++) {
1840 struct gpu_cvb_dvfs *d = &gpu_cvb_dvfs_table[i];
1841 unsigned long max_freq = d->max_freq;
1842 if (match_dvfs_one("gpu cvb", d->speedo_id, d->process_id,
1843 gpu_speedo_id, gpu_process_id)) {
1844 ret = set_gpu_dvfs_data(max_freq,
1845 d, &gpu_dvfs, gpu_max_freq_index);
1849 BUG_ON((i == ARRAY_SIZE(gpu_cvb_dvfs_table)) || ret);
1853 * GPU Vmax cooling device registration:
1854 * - Use Tegra21 GPU capping method that applies pre-populated cap rates
1855 * adjusted for each voltage cap trip-point (in case when GPU thermal
1856 * scaling initialization failed, fall back on using WC rate limit across all
1858 * - Skip registration if most aggressive cap is at/above maximum voltage
1860 static int tegra21_gpu_volt_cap_apply(int *cap_idx, int new_idx, int level)
1863 unsigned long flags;
1864 unsigned long cap_rate;
1869 clk_lock_save(vgpu_cap_clk, &flags);
1873 if (gpu_dvfs.dvfs_rail->vts_cdev && gpu_dvfs.therm_dvfs)
1874 cap_rate = gpu_cap_rates[new_idx - 1];
1876 cap_rate = tegra_dvfs_predict_hz_at_mv_max_tfloor(
1877 clk_get_parent(vgpu_cap_clk), level);
1879 cap_rate = clk_get_max_rate(vgpu_cap_clk);
1882 if (!IS_ERR_VALUE(cap_rate))
1883 ret = clk_set_rate_locked(vgpu_cap_clk, cap_rate);
1885 pr_err("tegra21_dvfs: Failed to find GPU cap rate for %dmV\n",
1888 clk_unlock_restore(vgpu_cap_clk, &flags);
1892 static int __init tegra21_dvfs_register_gpu_vmax_cdev(void)
1894 struct dvfs_rail *rail;
1896 rail = &tegra21_dvfs_rail_vdd_gpu;
1897 rail->apply_vmax_cap = tegra21_gpu_volt_cap_apply;
1898 if (rail->vmax_cdev) {
1899 int i = rail->vmax_cdev->trip_temperatures_num;
1900 if (i && rail->therm_mv_caps[i-1] < rail->nominal_millivolts)
1901 tegra_dvfs_rail_register_vmax_cdev(rail);
1905 late_initcall(tegra21_dvfs_register_gpu_vmax_cdev);
1908 * SPI DVFS tables are different in master and in slave mode. Use master tables
1909 * by default. Check if slave mode is specified for enabled SPI devices in DT,
1910 * and overwrite master table for the respective SPI controller.
1913 static __initdata struct {
1917 { 0x7000d400, &spi_dvfs_table[0] },
1918 { 0x7000d600, &spi_dvfs_table[1] },
1919 { 0x7000d800, &spi_dvfs_table[2] },
1920 { 0x7000da00, &spi_dvfs_table[3] },
1923 static int __init of_update_spi_slave_dvfs(struct device_node *dn)
1929 if (!of_device_is_available(dn))
1932 reg = of_get_property(dn, "reg", NULL);
1933 if (reg && of_can_translate_address(dn))
1934 addr = of_translate_address(dn, reg);
1936 for (i = 0; i < ARRAY_SIZE(spi_map); i++) {
1937 if (spi_map[i].address == addr) {
1938 spi_map[i].d = &spi_slave_dvfs_table[i];
1945 static __initdata struct of_device_id tegra21_dvfs_spi_slave_of_match[] = {
1946 { .compatible = "nvidia,tegra210-spi-slave",
1947 .data = of_update_spi_slave_dvfs, },
1951 static void __init init_spi_dvfs(int soc_speedo_id, int core_process_id,
1952 int core_nominal_mv_index)
1956 of_tegra_dvfs_init(tegra21_dvfs_spi_slave_of_match);
1958 for (i = 0; i < ARRAY_SIZE(spi_map); i++) {
1959 struct dvfs *d = spi_map[i].d;
1960 if (!match_dvfs_one(d->clk_name, d->speedo_id,
1961 d->process_id, soc_speedo_id, core_process_id))
1963 tegra_init_dvfs_one(d, core_nominal_mv_index);
1968 * QSPI DVFS tables are different in SDR and DDR modes. Use SDR tables by
1969 * default. Check if DDR mode is specified for enabled QSPI device in DT,
1970 * and overwrite DVFS table, respectively.
1973 static __initdata struct dvfs *qspi_dvfs = &qspi_sdr_dvfs_table[0];
1975 static int __init of_update_qspi_dvfs(struct device_node *dn)
1977 if (of_device_is_available(dn)) {
1978 if (of_get_property(dn, "nvidia,x4-is-ddr", NULL))
1979 qspi_dvfs = &qspi_ddr_dvfs_table[0];
1984 static __initdata struct of_device_id tegra21_dvfs_qspi_of_match[] = {
1985 { .compatible = "nvidia,tegra210-qspi", .data = of_update_qspi_dvfs, },
1989 static void __init init_qspi_dvfs(int soc_speedo_id, int core_process_id,
1990 int core_nominal_mv_index)
1993 struct device_node *dn;
1995 of_tegra_dvfs_init(tegra21_dvfs_qspi_of_match);
1997 if (match_dvfs_one(qspi_dvfs->clk_name, qspi_dvfs->speedo_id,
1998 qspi_dvfs->process_id, soc_speedo_id, core_process_id))
1999 tegra_init_dvfs_one(qspi_dvfs, core_nominal_mv_index);
2003 * SOR1 in HDMI and DP modes has different DVFS tables. The HDMI table is
2004 * specified as primary, and DP mode table is installed as alternative one.
2006 static void __init init_sor1_dp_dvfs(int soc_speedo_id, int core_process_id)
2009 struct dvfs *alt_d = &sor1_dp_dvfs_table[0];
2010 struct dvfs_rail *rail = &tegra21_dvfs_rail_vdd_core;
2011 struct clk *c = tegra_get_clock_by_name(alt_d->clk_name);
2013 if (!c || !c->dvfs) {
2014 if (rail->min_millivolts != rail->nominal_millivolts)
2015 pr_err("tegra21_dvfs: invalid clock %s for alt dvfs\n",
2020 if (match_dvfs_one(alt_d->clk_name, alt_d->speedo_id, alt_d->process_id,
2021 soc_speedo_id, core_process_id)) {
2022 for (i = 0; i < c->dvfs->num_freqs; i++)
2023 alt_d->freqs[i] *= alt_d->freqs_mult;
2024 tegra_dvfs_alt_freqs_install_always(c->dvfs, alt_d->freqs);
2029 * Clip sku-based core nominal voltage to core DVFS voltage ladder
2031 static int __init get_core_nominal_mv_index(int speedo_id)
2034 int mv = tegra_core_speedo_mv();
2035 int core_edp_voltage = get_core_edp();
2038 * Start with nominal level for the chips with this speedo_id. Then,
2039 * make sure core nominal voltage is below edp limit for the board
2040 * (if edp limit is set).
2042 if (!core_edp_voltage)
2043 core_edp_voltage = 1125; /* default 1.125V EDP limit */
2045 mv = min(mv, core_edp_voltage);
2046 #ifndef CONFIG_TEGRA_CORE_DVFS
2047 mv = min(mv, 1000); /* Vmax if scaling is disabled */
2049 /* Round nominal level down to the nearest core scaling step */
2050 for (i = 0; i < MAX_DVFS_FREQS; i++) {
2051 if ((core_millivolts[i] == 0) || (mv < core_millivolts[i]))
2056 pr_err("tegra21_dvfs: unable to adjust core dvfs table to"
2057 " nominal voltage %d\n", mv);
2064 * Clip sku-based core minimum voltage to core DVFS voltage ladder
2066 static int __init get_core_minimum_mv_index(void)
2069 int mv = tegra_core_speedo_min_mv();
2072 * Start with minimum level for the chip sku/speedo. Then, make sure it
2073 * is above initial rail minimum, and finally round up to DVFS voltages.
2075 mv = max(mv, tegra21_dvfs_rail_vdd_core.min_millivolts);
2076 for (i = 0; i < MAX_DVFS_FREQS - 1; i++) {
2077 if ((core_millivolts[i+1] == 0) || (mv <= core_millivolts[i]))
2083 static int __init init_core_rail_thermal_profile(void)
2085 struct dvfs_rail *rail = &tegra21_dvfs_rail_vdd_core;
2088 * Failure to get/configure trips may not be fatal for boot - let it
2089 * boot, even with partial configuration with appropriate WARNING, and
2090 * invalidate cdev. It must not happen with production DT, of course.
2092 if (rail->vmin_cdev) {
2093 if (tegra_dvfs_rail_of_init_vmin_thermal_profile(
2094 vdd_core_vmin_trips_table, vdd_core_therm_floors_table,
2096 rail->vmin_cdev = NULL;
2099 if (rail->vmax_cdev) {
2100 if (tegra_dvfs_rail_of_init_vmax_thermal_profile(
2101 vdd_core_vmax_trips_table, vdd_core_therm_caps_table,
2103 rail->vmax_cdev = NULL;
2109 static int __init of_rails_init(struct device_node *dn)
2113 if (!of_device_is_available(dn))
2116 for (i = 0; i < ARRAY_SIZE(tegra21_dvfs_rails); i++) {
2117 struct dvfs_rail *rail = tegra21_dvfs_rails[i];
2118 if (!of_tegra_dvfs_rail_node_parse(dn, rail)) {
2119 rail->stats.bin_uV = rail->alignment.step_uv;
2126 static __initdata struct of_device_id tegra21_dvfs_rail_of_match[] = {
2127 { .compatible = "nvidia,tegra210-dvfs-rail", .data = of_rails_init, },
2131 void __init tegra21x_init_dvfs(void)
2133 int soc_speedo_id = tegra_soc_speedo_id();
2134 int core_process_id = tegra_core_process_id();
2137 int core_nominal_mv_index;
2138 int gpu_max_freq_index = 0;
2139 int cpu_max_freq_index = 0;
2140 int cpu_lp_max_freq_index = 0;
2142 #ifndef CONFIG_TEGRA_CORE_DVFS
2143 tegra_dvfs_core_disabled = true;
2145 #ifndef CONFIG_TEGRA_CPU_DVFS
2146 tegra_dvfs_cpu_disabled = true;
2148 #ifndef CONFIG_TEGRA_GPU_DVFS
2149 tegra_dvfs_gpu_disabled = true;
2152 of_tegra_dvfs_init(tegra21_dvfs_rail_of_match);
2155 * Find nominal and minimum voltages for core rail before rail
2156 * init. Nominal voltage index in core scaling ladder can also be
2157 * used to determine max dvfs frequencies for all core clocks. In
2158 * case of error disable core scaling and set index to 0, so that
2159 * core clocks would not exceed rates allowed at minimum voltage.
2161 core_nominal_mv_index = get_core_nominal_mv_index(soc_speedo_id);
2162 if (core_nominal_mv_index < 0) {
2163 tegra21_dvfs_rail_vdd_core.disabled = true;
2164 tegra_dvfs_core_disabled = true;
2165 core_nominal_mv_index = 0;
2167 tegra21_dvfs_rail_vdd_core.nominal_millivolts =
2168 core_millivolts[core_nominal_mv_index];
2170 i = get_core_minimum_mv_index();
2171 BUG_ON(i > core_nominal_mv_index);
2172 tegra21_dvfs_rail_vdd_core.min_millivolts = core_millivolts[i];
2175 * Construct fast and slow CPU DVFS tables from CVB data; find maximum
2176 * frequency, minimum and nominal voltage for each CPU cluster, and
2177 * combined rail limits (fast CPU should be initialized 1st).
2179 init_cpu_dvfs_table(&cpu_max_freq_index);
2180 init_cpu_lp_dvfs_table(&cpu_lp_max_freq_index);
2182 /* Init cpu thermal profile */
2183 init_cpu_rail_thermal_profile(&cpu_dvfs);
2186 * Construct GPU DVFS table from CVB data; find GPU maximum frequency,
2187 * and nominal voltage.
2189 init_gpu_dvfs_table(&gpu_max_freq_index);
2191 /* Init core thermal profile */
2192 init_core_rail_thermal_profile();
2194 /* Init rail structures and dependencies */
2195 tegra_dvfs_init_rails(tegra21_dvfs_rails,
2196 ARRAY_SIZE(tegra21_dvfs_rails));
2198 /* Search core dvfs table for speedo/process matching entries and
2199 initialize dvfs-ed clocks */
2200 if (!tegra_platform_is_linsim()) {
2201 for (i = 0; i < ARRAY_SIZE(core_dvfs_table); i++) {
2202 struct dvfs *d = &core_dvfs_table[i];
2203 if (!match_dvfs_one(d->clk_name, d->speedo_id,
2204 d->process_id, soc_speedo_id, core_process_id))
2206 tegra_init_dvfs_one(d, core_nominal_mv_index);
2208 init_spi_dvfs(soc_speedo_id, core_process_id,
2209 core_nominal_mv_index);
2210 init_qspi_dvfs(soc_speedo_id, core_process_id,
2211 core_nominal_mv_index);
2212 init_sor1_dp_dvfs(soc_speedo_id, core_process_id);
2215 /* Initialize matching gpu dvfs entry already found when nominal
2216 voltage was determined */
2217 tegra_init_dvfs_one(&gpu_dvfs, gpu_max_freq_index);
2219 /* Initialize matching cpu dvfs entry already found when nominal
2220 voltage was determined */
2221 tegra_init_dvfs_one(&cpu_dvfs, cpu_max_freq_index);
2222 tegra_init_dvfs_one(&cpu_lp_dvfs, cpu_lp_max_freq_index);
2224 /* Finally disable dvfs on rails if necessary */
2225 if (tegra_dvfs_core_disabled)
2226 tegra_dvfs_rail_disable(&tegra21_dvfs_rail_vdd_core);
2227 if (tegra_dvfs_cpu_disabled)
2228 tegra_dvfs_rail_disable(&tegra21_dvfs_rail_vdd_cpu);
2229 if (tegra_dvfs_gpu_disabled)
2230 tegra_dvfs_rail_disable(&tegra21_dvfs_rail_vdd_gpu);
2232 for (i = 0; i < ARRAY_SIZE(tegra21_dvfs_rails); i++) {
2233 struct dvfs_rail *rail = tegra21_dvfs_rails[i];
2234 pr_info("tegra dvfs: %s: nominal %dmV, offset %duV, step %duV, scaling %s\n",
2235 rail->reg_id, rail->nominal_millivolts,
2236 rail->alignment.offset_uv, rail->alignment.step_uv,
2237 rail->disabled ? "disabled" : "enabled");
2241 int tegra_dvfs_rail_disable_prepare(struct dvfs_rail *rail)
2246 int tegra_dvfs_rail_post_enable(struct dvfs_rail *rail)
2251 #ifdef CONFIG_TEGRA_CORE_VOLT_CAP
2252 /* Core voltage and bus cap object and tables */
2253 static struct kobject *cap_kobj;
2254 static struct kobject *gpu_kobj;
2256 static struct core_dvfs_cap_table tegra21_core_cap_table[] = {
2257 { .cap_name = "cap.vcore.c2bus" },
2258 { .cap_name = "cap.vcore.c3bus" },
2259 { .cap_name = "cap.vcore.cbus" },
2260 { .cap_name = "cap.vcore.sclk" },
2261 { .cap_name = "cap.vcore.emc" },
2262 { .cap_name = "cap.vcore.host1x" },
2263 { .cap_name = "cap.vcore.mselect" },
2264 { .cap_name = "cap.vcore.ape" },
2265 { .cap_name = "cap.vcore.abus" },
2268 static struct core_bus_limit_table tegra21_gpu_cap_syfs = {
2269 .limit_clk_name = "cap.profile.gbus",
2270 .refcnt_attr = {.attr = {.name = "gpu_cap_state", .mode = 0644} },
2271 .level_attr = {.attr = {.name = "gpu_cap_rate", .mode = 0644} },
2272 .pm_qos_class = PM_QOS_GPU_FREQ_MAX,
2275 static struct core_bus_limit_table tegra21_gpu_floor_sysfs = {
2276 .limit_clk_name = "floor.profile.gbus",
2277 .refcnt_attr = {.attr = {.name = "gpu_floor_state", .mode = 0644} },
2278 .level_attr = {.attr = {.name = "gpu_floor_rate", .mode = 0644} },
2279 .pm_qos_class = PM_QOS_GPU_FREQ_MIN,
2282 static struct core_bus_rates_table tegra21_gpu_rates_sysfs = {
2283 .bus_clk_name = "gbus",
2284 .rate_attr = {.attr = {.name = "gpu_rate", .mode = 0444} },
2285 .available_rates_attr = {
2286 .attr = {.name = "gpu_available_rates", .mode = 0444} },
2287 .time_at_user_rate_attr = {
2288 .attr = {.name = "gpu_time_at_user_rate", .mode = 0444} },
2292 * Core Vmax cooling device registration:
2293 * - Use VDD_CORE capping method provided by DVFS
2294 * - Skip registration if most aggressive cap is at/above maximum voltage
2296 static void __init tegra21_dvfs_register_core_vmax_cdev(void)
2298 struct dvfs_rail *rail;
2300 rail = &tegra21_dvfs_rail_vdd_core;
2301 rail->apply_vmax_cap = tegra_dvfs_therm_vmax_core_cap_apply;
2302 if (rail->vmax_cdev) {
2303 int i = rail->vmax_cdev->trip_temperatures_num;
2304 if (i && rail->therm_mv_caps[i-1] < rail->nominal_millivolts)
2305 tegra_dvfs_rail_register_vmax_cdev(rail);
2310 * Initialize core capping interfaces. It can happen only after DVFS is ready.
2311 * Therefore this late initcall must be invoked after clock late initcall where
2312 * DVFS is initialized -- assured by the order in Make file. In addition core
2313 * Vmax cooling device operation depends on core cap interface. Hence, register
2314 * core Vmax cooling device here as well.
2316 static int __init tegra21_dvfs_init_core_cap(void)
2320 if (tegra_platform_is_qt())
2323 /* Init core voltage cap interface */
2324 cap_kobj = kobject_create_and_add("tegra_cap", kernel_kobj);
2326 pr_err("tegra21_dvfs: failed to create sysfs cap object\n");
2330 ret = tegra_init_core_cap(tegra21_core_cap_table,
2331 ARRAY_SIZE(tegra21_core_cap_table),
2332 core_millivolts, ARRAY_SIZE(core_millivolts), cap_kobj);
2334 pr_err("tegra21_dvfs: failed to init core cap interface (%d)\n",
2336 kobject_del(cap_kobj);
2339 tegra_core_cap_debug_init();
2340 pr_info("tegra dvfs: tegra sysfs cap interface is initialized\n");
2342 /* Register core Vmax cooling device */
2343 tegra21_dvfs_register_core_vmax_cdev();
2345 /* Init core shared buses rate limit interfaces */
2346 gpu_kobj = kobject_create_and_add("tegra_gpu", kernel_kobj);
2348 pr_err("tegra21_dvfs: failed to create sysfs gpu object\n");
2352 ret = tegra_init_shared_bus_cap(&tegra21_gpu_cap_syfs,
2355 pr_err("tegra21_dvfs: failed to init gpu cap interface (%d)\n",
2357 kobject_del(gpu_kobj);
2361 ret = tegra_init_shared_bus_floor(&tegra21_gpu_floor_sysfs,
2364 pr_err("tegra21_dvfs: failed to init gpu floor interface (%d)\n",
2366 kobject_del(gpu_kobj);
2370 /* Init core shared buses rate inforamtion interfaces */
2371 ret = tegra_init_sysfs_shared_bus_rate(&tegra21_gpu_rates_sysfs,
2374 pr_err("tegra21_dvfs: failed to init gpu rates interface (%d)\n",
2376 kobject_del(gpu_kobj);
2380 pr_info("tegra dvfs: tegra sysfs gpu interface is initialized\n");
2384 late_initcall(tegra21_dvfs_init_core_cap);