2 * arch/arm/mach-tegra/tegra11_dvfs.c
4 * Copyright (C) 2012 NVIDIA Corporation.
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>
29 #include "tegra_cl_dvfs.h"
31 static bool tegra_dvfs_cpu_disabled;
32 static bool tegra_dvfs_core_disabled;
37 /* FIXME: need tegra11 step */
38 #define VDD_SAFE_STEP 100
40 static int dvfs_temperatures[] = { 20, };
42 static struct tegra_cooling_device cpu_dfll_cdev = {
43 .cdev_type = "cpu_dfll",
44 .trip_temperatures = dvfs_temperatures,
45 .trip_temperatures_num = ARRAY_SIZE(dvfs_temperatures),
48 static struct tegra_cooling_device core_cdev = {
50 .trip_temperatures = dvfs_temperatures,
51 .trip_temperatures_num = ARRAY_SIZE(dvfs_temperatures),
54 static struct dvfs_rail tegra11_dvfs_rail_vdd_cpu = {
56 .max_millivolts = 1400,
57 .min_millivolts = 800,
58 .step = VDD_SAFE_STEP,
60 .min_millivolts_cold = 1000,
61 .dfll_mode_cdev = &cpu_dfll_cdev,
64 static struct dvfs_rail tegra11_dvfs_rail_vdd_core = {
66 .max_millivolts = 1400,
67 .min_millivolts = 800,
68 .step = VDD_SAFE_STEP,
69 .min_millivolts_cold = 950,
70 .pll_mode_cdev = &core_cdev,
73 static struct dvfs_rail *tegra11_dvfs_rails[] = {
74 &tegra11_dvfs_rail_vdd_cpu,
75 &tegra11_dvfs_rail_vdd_core,
78 /* default cvb alignment on Tegra11 - 10mV */
79 int __attribute__((weak)) tegra_get_cvb_alignment_uV(void)
85 static struct cpu_cvb_dvfs cpu_cvb_dvfs_table[] = {
91 .tune0_high_mv = 0x00b0019d,
93 .droop_rate_min = 1000000,
94 .min_millivolts = 1000,
101 /*f dfll: c0, c1, c2 pll: c0, c1, c2 */
102 { 306000, { 107330, -1569, 0}, { 90000, 0, 0} },
103 { 408000, { 111250, -1666, 0}, { 90000, 0, 0} },
104 { 510000, { 110000, -1460, 0}, { 94000, 0, 0} },
105 { 612000, { 117290, -1745, 0}, { 94000, 0, 0} },
106 { 714000, { 122700, -1910, 0}, { 99000, 0, 0} },
107 { 816000, { 125620, -1945, 0}, { 99000, 0, 0} },
108 { 918000, { 130560, -2076, 0}, { 103000, 0, 0} },
109 {1020000, { 137280, -2303, 0}, { 103000, 0, 0} },
110 {1122000, { 146440, -2660, 0}, { 109000, 0, 0} },
111 {1224000, { 152190, -2825, 0}, { 109000, 0, 0} },
112 {1326000, { 157520, -2953, 0}, { 112000, 0, 0} },
113 {1428000, { 166100, -3261, 0}, { 140000, 0, 0} },
114 {1530000, { 176410, -3647, 0}, { 140000, 0, 0} },
115 {1632000, { 189620, -4186, 0}, { 140000, 0, 0} },
116 {1734000, { 203190, -4725, 0}, { 140000, 0, 0} },
117 {1836000, { 222670, -5573, 0}, { 140000, 0, 0} },
118 {1938000, { 256210, -7165, 0}, { 140000, 0, 0} },
119 {2040000, { 250050, -6544, 0}, { 140000, 0, 0} },
120 { 0, { 0, 0, 0}, { 0, 0, 0} },
128 .tune0_high_mv = 0x00b0009d,
130 .droop_rate_min = 1000000,
131 .tune_high_min_millivolts = 1000,
132 .min_millivolts = 900,
137 .voltage_scale = 1000,
139 /*f dfll: c0, c1, c2 pll: c0, c1, c2 */
140 { 306000, { 2190643, -141851, 3576}, { 900000, 0, 0} },
141 { 408000, { 2250968, -144331, 3576}, { 900000, 0, 0} },
142 { 510000, { 2313333, -146811, 3576}, { 940000, 0, 0} },
143 { 612000, { 2377738, -149291, 3576}, { 940000, 0, 0} },
144 { 714000, { 2444183, -151771, 3576}, { 990000, 0, 0} },
145 { 816000, { 2512669, -154251, 3576}, { 990000, 0, 0} },
146 { 918000, { 2583194, -156731, 3576}, { 1030000, 0, 0} },
147 {1020000, { 2655759, -159211, 3576}, { 1030000, 0, 0} },
148 {1122000, { 2730365, -161691, 3576}, { 1090000, 0, 0} },
149 {1224000, { 2807010, -164171, 3576}, { 1090000, 0, 0} },
150 {1326000, { 2885696, -166651, 3576}, { 1120000, 0, 0} },
151 {1428000, { 2966422, -169131, 3576}, { 1400000, 0, 0} },
152 {1530000, { 3049183, -171601, 3576}, { 1400000, 0, 0} },
153 {1606500, { 3112179, -173451, 3576}, { 1400000, 0, 0} },
154 {1708500, { 3198504, -175931, 3576}, { 1400000, 0, 0} },
155 {1810500, { 3304747, -179126, 3576}, { 1400000, 0, 0} },
156 { 0, { 0, 0, 0}, { 0, 0, 0} },
164 .tune0_high_mv = 0x00b0009d,
166 .droop_rate_min = 1000000,
167 .tune_high_min_millivolts = 1000,
168 .min_millivolts = 900,
173 .voltage_scale = 1000,
175 /*f dfll: c0, c1, c2 pll: c0, c1, c2 */
176 { 306000, { 2190643, -141851, 3576}, { 900000, 0, 0} },
177 { 408000, { 2250968, -144331, 3576}, { 900000, 0, 0} },
178 { 510000, { 2313333, -146811, 3576}, { 940000, 0, 0} },
179 { 612000, { 2377738, -149291, 3576}, { 940000, 0, 0} },
180 { 714000, { 2444183, -151771, 3576}, { 990000, 0, 0} },
181 { 816000, { 2512669, -154251, 3576}, { 990000, 0, 0} },
182 { 918000, { 2583194, -156731, 3576}, { 1030000, 0, 0} },
183 {1020000, { 2655759, -159211, 3576}, { 1030000, 0, 0} },
184 {1122000, { 2730365, -161691, 3576}, { 1090000, 0, 0} },
185 {1224000, { 2807010, -164171, 3576}, { 1090000, 0, 0} },
186 {1326000, { 2885696, -166651, 3576}, { 1120000, 0, 0} },
187 {1428000, { 2966422, -169131, 3576}, { 1400000, 0, 0} },
188 {1530000, { 3049183, -171601, 3576}, { 1400000, 0, 0} },
189 {1606500, { 3112179, -173451, 3576}, { 1400000, 0, 0} },
190 {1708500, { 3198504, -175931, 3576}, { 1400000, 0, 0} },
191 {1810500, { 3304747, -179126, 3576}, { 1400000, 0, 0} },
192 { 0, { 0, 0, 0}, { 0, 0, 0} },
200 .tune0_high_mv = 0x00b0009d,
202 .droop_rate_min = 1000000,
203 .tune_high_min_millivolts = 1000,
204 .min_millivolts = 900,
209 .voltage_scale = 1000,
211 /*f dfll: c0, c1, c2 pll: c0, c1, c2 */
212 { 306000, { 2190643, -141851, 3576}, { 900000, 0, 0} },
213 { 408000, { 2250968, -144331, 3576}, { 900000, 0, 0} },
214 { 510000, { 2313333, -146811, 3576}, { 940000, 0, 0} },
215 { 612000, { 2377738, -149291, 3576}, { 940000, 0, 0} },
216 { 714000, { 2444183, -151771, 3576}, { 990000, 0, 0} },
217 { 816000, { 2512669, -154251, 3576}, { 990000, 0, 0} },
218 { 918000, { 2583194, -156731, 3576}, { 1030000, 0, 0} },
219 {1020000, { 2655759, -159211, 3576}, { 1030000, 0, 0} },
220 {1122000, { 2730365, -161691, 3576}, { 1090000, 0, 0} },
221 {1224000, { 2807010, -164171, 3576}, { 1090000, 0, 0} },
222 {1326000, { 2885696, -166651, 3576}, { 1120000, 0, 0} },
223 {1428000, { 2966422, -169131, 3576}, { 1400000, 0, 0} },
224 {1530000, { 3049183, -171601, 3576}, { 1400000, 0, 0} },
225 {1606500, { 3112179, -173451, 3576}, { 1400000, 0, 0} },
226 {1708500, { 3198504, -175931, 3576}, { 1400000, 0, 0} },
227 {1810500, { 3304747, -179126, 3576}, { 1400000, 0, 0} },
228 {1912500, { 3395401, -181606, 3576}, { 1400000, 0, 0} },
229 { 0, { 0, 0, 0}, { 0, 0, 0} },
234 static int cpu_millivolts[MAX_DVFS_FREQS];
235 static int cpu_dfll_millivolts[MAX_DVFS_FREQS];
237 static struct dvfs cpu_dvfs = {
239 .millivolts = cpu_millivolts,
240 .dfll_millivolts = cpu_dfll_millivolts,
242 .dvfs_rail = &tegra11_dvfs_rail_vdd_cpu,
245 /* Core DVFS tables */
246 /* FIXME: real data */
247 static const int core_millivolts[MAX_DVFS_FREQS] = {
248 900, 950, 1000, 1050, 1100, 1120, 1170, 1200, 1250};
250 #define CORE_DVFS(_clk_name, _speedo_id, _process_id, _auto, _mult, _freqs...) \
252 .clk_name = _clk_name, \
253 .speedo_id = _speedo_id, \
254 .process_id = _process_id, \
256 .freqs_mult = _mult, \
257 .millivolts = core_millivolts, \
258 .auto_dvfs = _auto, \
259 .dvfs_rail = &tegra11_dvfs_rail_vdd_core, \
262 static struct dvfs core_dvfs_table[] = {
263 /* Core voltages (mV): 900, 950, 1000, 1050, 1100, 1120, 1170, 1200, 1250 */
264 /* Clock limits for internal blocks, PLLs */
265 #ifndef CONFIG_TEGRA_SIMULATION_PLATFORM
266 CORE_DVFS("emc", -1, -1, 1, KHZ, 1, 1, 1, 1, 800000, 800000, 933000, 933000, 1066000),
268 CORE_DVFS("cpu_lp", 0, 0, 1, KHZ, 228000, 306000, 396000, 528000, 648000, 696000, 696000, 696000, 696000),
269 CORE_DVFS("cpu_lp", 0, 1, 1, KHZ, 468000, 480000, 612000, 696000, 696000, 696000, 696000, 696000, 696000),
270 CORE_DVFS("cpu_lp", 1, 1, 1, KHZ, 468000, 480000, 612000, 714000, 792000, 816000, 816000, 816000, 816000),
272 CORE_DVFS("sbus", 0, 0, 1, KHZ, 1, 188000, 240000, 276000, 324000, 336000, 336000, 336000, 336000),
273 CORE_DVFS("sbus", 0, 1, 1, KHZ, 1, 264000, 300000, 336000, 336000, 336000, 336000, 336000, 336000),
274 CORE_DVFS("sbus", 1, 1, 1, KHZ, 1, 264000, 300000, 336000, 372000, 384000, 384000, 384000, 384000),
276 CORE_DVFS("vi", -1, 0, 1, KHZ, 144000, 216000, 240000, 312000, 372000, 408000, 408000, 408000, 408000),
277 CORE_DVFS("vi", -1, 1, 1, KHZ, 144000, 216000, 240000, 408000, 408000, 408000, 408000, 408000, 408000),
279 CORE_DVFS("2d", -1, 0, 1, KHZ, 192000, 228000, 300000, 396000, 492000, 516000, 516000, 516000, 600000),
280 CORE_DVFS("3d", -1, 0, 1, KHZ, 192000, 228000, 300000, 396000, 492000, 516000, 516000, 516000, 600000),
281 CORE_DVFS("epp", -1, 0, 1, KHZ, 192000, 228000, 300000, 396000, 492000, 516000, 516000, 516000, 600000),
283 CORE_DVFS("2d", -1, 1, 1, KHZ, 276000, 348000, 420000, 492000, 528000, 564000, 600000, 636000, 672000),
284 CORE_DVFS("3d", -1, 1, 1, KHZ, 276000, 348000, 420000, 492000, 528000, 564000, 600000, 636000, 672000),
285 CORE_DVFS("epp", -1, 1, 1, KHZ, 276000, 348000, 420000, 492000, 528000, 564000, 600000, 636000, 672000),
287 CORE_DVFS("msenc", 0, 0, 1, KHZ, 144000, 182000, 240000, 312000, 384000, 408000, 408000, 408000, 408000),
288 CORE_DVFS("se", 0, 0, 1, KHZ, 144000, 182000, 240000, 312000, 384000, 408000, 408000, 408000, 408000),
289 CORE_DVFS("tsec", 0, 0, 1, KHZ, 144000, 182000, 240000, 312000, 384000, 408000, 408000, 408000, 408000),
290 CORE_DVFS("vde", 0, 0, 1, KHZ, 144000, 182000, 240000, 312000, 384000, 408000, 408000, 408000, 408000),
292 CORE_DVFS("msenc", 0, 1, 1, KHZ, 228000, 288000, 360000, 408000, 408000, 408000, 408000, 408000, 408000),
293 CORE_DVFS("se", 0, 1, 1, KHZ, 228000, 288000, 360000, 408000, 408000, 408000, 408000, 408000, 408000),
294 CORE_DVFS("tsec", 0, 1, 1, KHZ, 228000, 288000, 360000, 408000, 408000, 408000, 408000, 408000, 408000),
295 CORE_DVFS("vde", 0, 1, 1, KHZ, 228000, 288000, 360000, 408000, 408000, 408000, 408000, 408000, 408000),
297 CORE_DVFS("msenc", 1, 1, 1, KHZ, 228000, 288000, 360000, 420000, 468000, 480000, 480000, 480000, 480000),
298 CORE_DVFS("se", 1, 1, 1, KHZ, 228000, 288000, 360000, 420000, 468000, 480000, 480000, 480000, 480000),
299 CORE_DVFS("tsec", 1, 1, 1, KHZ, 228000, 288000, 360000, 420000, 468000, 480000, 480000, 480000, 480000),
300 CORE_DVFS("vde", 1, 1, 1, KHZ, 228000, 288000, 360000, 420000, 468000, 480000, 480000, 480000, 480000),
302 CORE_DVFS("host1x", 0, 0, 1, KHZ, 144000, 188000, 240000, 276000, 324000, 336000, 336000, 336000, 336000),
303 CORE_DVFS("host1x", 0, 1, 1, KHZ, 216000, 264000, 300000, 336000, 336000, 336000, 336000, 336000, 336000),
304 CORE_DVFS("host1x", 1, 1, 1, KHZ, 216000, 264000, 300000, 336000, 372000, 384000, 384000, 384000, 384000),
306 #ifdef CONFIG_TEGRA_DUAL_CBUS
307 CORE_DVFS("c2bus", -1, 0, 1, KHZ, 192000, 228000, 300000, 396000, 492000, 516000, 516000, 516000, 600000),
308 CORE_DVFS("c2bus", -1, 1, 1, KHZ, 276000, 348000, 420000, 492000, 528000, 564000, 600000, 600000, 672000),
309 CORE_DVFS("c3bus", 0, 0, 1, KHZ, 144000, 182000, 240000, 312000, 384000, 408000, 408000, 408000, 408000),
310 CORE_DVFS("c3bus", 0, 1, 1, KHZ, 228000, 288000, 360000, 408000, 408000, 408000, 408000, 408000, 408000),
311 CORE_DVFS("c3bus", 1, 1, 1, KHZ, 228000, 288000, 360000, 420000, 468000, 480000, 480000, 480000, 480000),
313 CORE_DVFS("cbus", 0, 0, 1, KHZ, 144000, 182000, 240000, 312000, 384000, 408000, 408000, 408000, 408000),
314 CORE_DVFS("cbus", 0, 1, 1, KHZ, 228000, 288000, 360000, 408000, 408000, 408000, 408000, 408000, 408000),
315 CORE_DVFS("cbus", 1, 1, 1, KHZ, 228000, 288000, 360000, 420000, 468000, 480000, 480000, 480000, 480000),
318 CORE_DVFS("pll_m", -1, -1, 1, KHZ, 1, 800000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000),
319 CORE_DVFS("pll_c", -1, -1, 1, KHZ, 1, 800000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000),
320 CORE_DVFS("pll_c2", -1, -1, 1, KHZ, 1, 800000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000),
321 CORE_DVFS("pll_c3", -1, -1, 1, KHZ, 1, 800000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000, 1066000),
323 /* Core voltages (mV): 900, 950, 1000, 1050, 1100, 1120, 1170, 1200, 1250 */
324 /* Clock limits for I/O peripherals */
325 CORE_DVFS("sbc1", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 52000, 52000, 52000, 52000, 52000),
326 CORE_DVFS("sbc2", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 52000, 52000, 52000, 52000, 52000),
327 CORE_DVFS("sbc3", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 52000, 52000, 52000, 52000, 52000),
328 CORE_DVFS("sbc4", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 52000, 52000, 52000, 52000, 52000),
329 CORE_DVFS("sbc5", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 52000, 52000, 52000, 52000, 52000),
330 CORE_DVFS("sbc6", -1, -1, 1, KHZ, 48000, 48000, 48000, 48000, 52000, 52000, 52000, 52000, 52000),
332 CORE_DVFS("sdmmc1", -1, -1, 1, KHZ, 81600, 81600, 81600, 81600, 81600, 81600, 204000, 204000, 204000),
333 CORE_DVFS("sdmmc3", -1, -1, 1, KHZ, 81600, 81600, 81600, 81600, 204000, 204000, 204000, 204000, 204000),
334 CORE_DVFS("sdmmc4", -1, -1, 1, KHZ, 102000, 102000, 102000, 102000, 102000, 102000, 198000, 198000, 198000),
336 CORE_DVFS("csi", -1, -1, 1, KHZ, 1, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
337 CORE_DVFS("cilab", -1, -1, 1, KHZ, 1, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
338 CORE_DVFS("cilcd", -1, -1, 1, KHZ, 1, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
339 CORE_DVFS("cile", -1, -1, 1, KHZ, 1, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
341 CORE_DVFS("dsia", -1, -1, 1, KHZ, 1, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000),
342 CORE_DVFS("dsib", -1, -1, 1, KHZ, 1, 500000, 500000, 500000, 500000, 500000, 500000, 500000, 500000),
343 CORE_DVFS("dsialp", -1, -1, 1, KHZ, 1, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
344 CORE_DVFS("dsiblp", -1, -1, 1, KHZ, 1, 102000, 102000, 102000, 102000, 102000, 102000, 102000, 102000),
345 CORE_DVFS("hdmi", -1, -1, 1, KHZ, 148500, 148500, 148500, 297000, 297000, 297000, 297000, 297000, 297000),
348 * The clock rate for the display controllers that determines the
349 * necessary core voltage depends on a divider that is internal
350 * to the display block. Disable auto-dvfs on the display clocks,
351 * and let the display driver call tegra_dvfs_set_rate manually
353 CORE_DVFS("disp1", -1, -1, 0, KHZ, 148500, 166000, 166000, 297000, 297000, 297000, 297000, 297000, 297000),
354 CORE_DVFS("disp2", -1, -1, 0, KHZ, 148500, 166000, 166000, 297000, 297000, 297000, 297000, 297000, 297000),
357 CORE_DVFS("xusb_falcon_src", -1, -1, 1, KHZ, 1, 336000, 336000, 336000, 336000, 336000, 336000, 336000, 336000),
358 CORE_DVFS("xusb_host_src", -1, -1, 1, KHZ, 1, 112000, 112000, 112000, 112000, 112000, 112000, 112000, 112000),
359 CORE_DVFS("xusb_dev_src", -1, -1, 1, KHZ, 1, 58300, 58300, 112000, 112000, 112000, 112000, 112000, 112000),
360 CORE_DVFS("xusb_ss_src", -1, -1, 1, KHZ, 1, 120000, 120000, 120000, 120000, 120000, 120000, 120000, 120000),
361 CORE_DVFS("xusb_fs_src", -1, -1, 1, KHZ, 1, 48000, 48000, 48000, 48000, 48000, 48000, 48000, 48000),
362 CORE_DVFS("xusb_hs_src", -1, -1, 1, KHZ, 1, 60000, 60000, 60000, 60000, 60000, 60000, 60000, 60000),
366 int tegra_dvfs_disable_core_set(const char *arg, const struct kernel_param *kp)
370 ret = param_set_bool(arg, kp);
374 if (tegra_dvfs_core_disabled)
375 tegra_dvfs_rail_disable(&tegra11_dvfs_rail_vdd_core);
377 tegra_dvfs_rail_enable(&tegra11_dvfs_rail_vdd_core);
382 int tegra_dvfs_disable_cpu_set(const char *arg, const struct kernel_param *kp)
386 ret = param_set_bool(arg, kp);
390 if (tegra_dvfs_cpu_disabled)
391 tegra_dvfs_rail_disable(&tegra11_dvfs_rail_vdd_cpu);
393 tegra_dvfs_rail_enable(&tegra11_dvfs_rail_vdd_cpu);
398 int tegra_dvfs_disable_get(char *buffer, const struct kernel_param *kp)
400 return param_get_bool(buffer, kp);
403 static struct kernel_param_ops tegra_dvfs_disable_core_ops = {
404 .set = tegra_dvfs_disable_core_set,
405 .get = tegra_dvfs_disable_get,
408 static struct kernel_param_ops tegra_dvfs_disable_cpu_ops = {
409 .set = tegra_dvfs_disable_cpu_set,
410 .get = tegra_dvfs_disable_get,
413 module_param_cb(disable_core, &tegra_dvfs_disable_core_ops,
414 &tegra_dvfs_core_disabled, 0644);
415 module_param_cb(disable_cpu, &tegra_dvfs_disable_cpu_ops,
416 &tegra_dvfs_cpu_disabled, 0644);
419 static bool __init can_update_max_rate(struct clk *c, struct dvfs *d)
421 /* Don't update manual dvfs clocks */
426 * Don't update EMC shared bus, since EMC dvfs is board dependent: max
427 * rate and EMC scaling frequencies are determined by tegra BCT (flashed
428 * together with the image) and board specific EMC DFS table; we will
429 * check the scaling ladder against nominal core voltage when the table
430 * is loaded (and if on particular board the table is not loaded, EMC
431 * scaling is disabled).
433 if (c->ops->shared_bus_update && (c->flags & PERIPH_EMC_ENB))
437 * Don't update shared cbus, and don't propagate common cbus dvfs
438 * limit down to shared users, but set maximum rate for each user
439 * equal to the respective client limit.
441 if (c->ops->shared_bus_update && (c->flags & PERIPH_ON_CBUS)) {
446 user, &c->shared_bus_list, u.shared_bus_user.node) {
447 if (user->u.shared_bus_user.client) {
448 rate = user->u.shared_bus_user.client->max_rate;
449 user->max_rate = rate;
450 user->u.shared_bus_user.rate = rate;
456 /* Other, than EMC and cbus, auto-dvfs clocks can be updated */
460 static void __init init_dvfs_one(struct dvfs *d, int max_freq_index)
463 struct clk *c = tegra_get_clock_by_name(d->clk_name);
466 pr_debug("tegra11_dvfs: no clock found for %s\n",
471 /* Update max rate for auto-dvfs clocks, with shared bus exceptions */
472 if (can_update_max_rate(c, d)) {
473 BUG_ON(!d->freqs[max_freq_index]);
475 c, d->freqs[max_freq_index] * d->freqs_mult);
477 d->max_millivolts = d->dvfs_rail->nominal_millivolts;
479 ret = tegra_enable_dvfs_on_clk(c, d);
481 pr_err("tegra11_dvfs: failed to enable dvfs on %s\n", c->name);
484 static bool __init match_dvfs_one(struct dvfs *d, int speedo_id, int process_id)
486 if ((d->process_id != -1 && d->process_id != process_id) ||
487 (d->speedo_id != -1 && d->speedo_id != speedo_id)) {
488 pr_debug("tegra11_dvfs: rejected %s speedo %d,"
489 " process %d\n", d->clk_name, d->speedo_id,
496 static bool __init match_cpu_cvb_one(struct cpu_cvb_dvfs *d,
497 int speedo_id, int process_id)
499 if ((d->process_id != -1 && d->process_id != process_id) ||
500 (d->speedo_id != -1 && d->speedo_id != speedo_id)) {
501 pr_debug("tegra11_dvfs: rejected cpu cvb speedo %d,"
502 " process %d\n", d->speedo_id, d->process_id);
508 /* cvb_mv = ((c2 * speedo / s_scale + c1) * speedo / s_scale + c0) / v_scale */
509 static inline int get_cvb_voltage(int speedo, int s_scale,
510 struct cpu_cvb_dvfs_parameters *cvb)
512 /* apply only speedo scale: output mv = cvb_mv * v_scale */
514 mv = DIV_ROUND_CLOSEST(cvb->c2 * speedo, s_scale);
515 mv = DIV_ROUND_CLOSEST((mv + cvb->c1) * speedo, s_scale) + cvb->c0;
519 static inline int round_cvb_voltage(int mv, int v_scale)
521 /* combined: apply voltage scale and round to cvb alignment step */
522 int cvb_align_step_uv = tegra_get_cvb_alignment_uV();
524 return DIV_ROUND_UP(mv * 1000, v_scale * cvb_align_step_uv) *
525 cvb_align_step_uv / 1000;
528 static int __init set_cpu_dvfs_data(
529 struct cpu_cvb_dvfs *d, struct dvfs *cpu_dvfs, int *max_freq_index)
531 int i, j, mv, dfll_mv, min_dfll_mv;
532 unsigned long fmax_at_vmin = 0;
533 unsigned long fmax_pll_mode = 0;
534 unsigned long fmin_use_dfll = 0;
535 struct cpu_cvb_dvfs_table *table = NULL;
536 int speedo = tegra_cpu_speedo_value();
538 min_dfll_mv = d->dfll_tune_data.min_millivolts;
539 BUG_ON(min_dfll_mv < tegra11_dvfs_rail_vdd_cpu.min_millivolts);
542 * Use CVB table to fill in CPU dvfs frequencies and voltages. Each
543 * CVB entry specifies CPU frequency and CVB coefficients to calculate
544 * the respective voltage when either DFLL or PLL is used as CPU clock
547 * Minimum voltage limit is applied only to DFLL source. For PLL source
548 * voltage can go as low as table specifies. Maximum voltage limit is
549 * applied to both sources, but differently: directly clip voltage for
550 * DFLL, and limit maximum frequency for PLL.
552 for (i = 0, j = 0; i < MAX_DVFS_FREQS; i++) {
553 table = &d->cvb_table[i];
557 dfll_mv = get_cvb_voltage(
558 speedo, d->speedo_scale, &table->cvb_dfll_param);
559 dfll_mv = round_cvb_voltage(dfll_mv, d->voltage_scale);
561 mv = get_cvb_voltage(
562 speedo, d->speedo_scale, &table->cvb_pll_param);
563 mv = round_cvb_voltage(mv, d->voltage_scale);
565 /* Check maximum frequency at minimum voltage for dfll source */
566 dfll_mv = max(dfll_mv, min_dfll_mv);
567 if (dfll_mv > min_dfll_mv) {
569 break; /* 1st entry already above Vmin */
571 fmax_at_vmin = cpu_dvfs->freqs[j - 1];
574 /* Clip maximum frequency at maximum voltage for pll source */
575 if (mv > d->max_mv) {
577 break; /* 1st entry already above Vmax */
579 fmax_pll_mode = cpu_dvfs->freqs[j - 1];
582 /* Minimum rate with pll source voltage above dfll Vmin */
583 if ((mv >= min_dfll_mv) && (!fmin_use_dfll))
584 fmin_use_dfll = table->freq;
586 /* fill in dvfs tables */
587 cpu_dvfs->freqs[j] = table->freq;
588 cpu_dfll_millivolts[j] = min(dfll_mv, d->max_mv);
589 cpu_millivolts[j] = mv;
593 * "Round-up" frequency list cut-off (keep first entry that
594 * exceeds max voltage - the voltage limit will be enforced
595 * anyway, so when requested this frequency dfll will settle
596 * at whatever high frequency it can on the particular chip)
598 if (dfll_mv > d->max_mv)
601 /* Table must not be empty and must have and at least one entry below,
602 and one entry above Vmin */
603 if (!i || !j || !fmax_at_vmin) {
604 pr_err("tegra11_dvfs: invalid cpu dvfs table\n");
608 /* Must have crossover between dfll and pll operating ranges */
609 if (!fmin_use_dfll || (fmin_use_dfll > fmax_at_vmin)) {
610 pr_err("tegra11_dvfs: no crossover of dfll and pll voltages\n");
614 /* dvfs tables are successfully populated - fill in the rest */
615 cpu_dvfs->speedo_id = d->speedo_id;
616 cpu_dvfs->process_id = d->process_id;
617 cpu_dvfs->freqs_mult = d->freqs_mult;
618 cpu_dvfs->dvfs_rail->nominal_millivolts = min(d->max_mv,
619 max(cpu_millivolts[j - 1], cpu_dfll_millivolts[j - 1]));
620 *max_freq_index = j - 1;
622 cpu_dvfs->dfll_data = d->dfll_tune_data;
623 cpu_dvfs->dfll_data.max_rate_boost = fmax_pll_mode ?
624 (cpu_dvfs->freqs[j - 1] - fmax_pll_mode) * d->freqs_mult : 0;
625 cpu_dvfs->dfll_data.out_rate_min = fmax_at_vmin * d->freqs_mult;
626 cpu_dvfs->dfll_data.use_dfll_rate_min = fmin_use_dfll * d->freqs_mult;
627 cpu_dvfs->dfll_data.min_millivolts = min_dfll_mv;
631 static int __init get_core_nominal_mv_index(int speedo_id)
634 int mv = tegra_core_speedo_mv();
635 int core_edp_voltage = get_core_edp();
638 * Start with nominal level for the chips with this speedo_id. Then,
639 * make sure core nominal voltage is below edp limit for the board
640 * (if edp limit is set).
642 if (!core_edp_voltage)
643 core_edp_voltage = 1100; /* default 1.1V EDP limit */
645 mv = min(mv, core_edp_voltage);
647 /* Round nominal level down to the nearest core scaling step */
648 for (i = 0; i < MAX_DVFS_FREQS; i++) {
649 if ((core_millivolts[i] == 0) || (mv < core_millivolts[i]))
654 pr_err("tegra11_dvfs: unable to adjust core dvfs table to"
655 " nominal voltage %d\n", mv);
661 int tegra_cpu_dvfs_alter(int edp_thermal_index, const cpumask_t *cpus,
662 bool before_clk_update, int cpu_event)
664 /* empty definition for tegra11 */
668 void __init tegra11x_init_dvfs(void)
670 int cpu_speedo_id = tegra_cpu_speedo_id();
671 int cpu_process_id = tegra_cpu_process_id();
672 int soc_speedo_id = tegra_soc_speedo_id();
673 int core_process_id = tegra_core_process_id();
676 int core_nominal_mv_index;
677 int cpu_max_freq_index = 0;
679 #ifndef CONFIG_TEGRA_CORE_DVFS
680 tegra_dvfs_core_disabled = true;
682 #ifndef CONFIG_TEGRA_CPU_DVFS
683 tegra_dvfs_cpu_disabled = true;
685 /* Setup rail bins */
686 tegra11_dvfs_rail_vdd_cpu.stats.bin_uV = tegra_get_cvb_alignment_uV();
687 tegra11_dvfs_rail_vdd_core.stats.bin_uV = tegra_get_cvb_alignment_uV();
690 * Find nominal voltages for core (1st) and cpu rails before rail
691 * init. Nominal voltage index in core scaling ladder can also be
692 * used to determine max dvfs frequencies for all core clocks. In
693 * case of error disable core scaling and set index to 0, so that
694 * core clocks would not exceed rates allowed at minimum voltage.
696 core_nominal_mv_index = get_core_nominal_mv_index(soc_speedo_id);
697 if (core_nominal_mv_index < 0) {
698 tegra11_dvfs_rail_vdd_core.disabled = true;
699 tegra_dvfs_core_disabled = true;
700 core_nominal_mv_index = 0;
702 tegra11_dvfs_rail_vdd_core.nominal_millivolts =
703 core_millivolts[core_nominal_mv_index];
706 * Setup cpu dvfs and dfll tables from cvb data, determine nominal
707 * voltage for cpu rail, and cpu maximum frequency. Note that entire
708 * frequency range is guaranteed only when dfll is used as cpu clock
709 * source. Reaching maximum frequency with pll as cpu clock source
710 * may not be possible within nominal voltage range (dvfs mechanism
711 * would automatically fail frequency request in this case, so that
712 * voltage limit is not violated). Error when cpu dvfs table can not
713 * be constructed must never happen.
715 for (ret = 0, i = 0; i < ARRAY_SIZE(cpu_cvb_dvfs_table); i++) {
716 struct cpu_cvb_dvfs *d = &cpu_cvb_dvfs_table[i];
717 if (match_cpu_cvb_one(d, cpu_speedo_id, cpu_process_id)) {
718 ret = set_cpu_dvfs_data(
719 d, &cpu_dvfs, &cpu_max_freq_index);
723 BUG_ON((i == ARRAY_SIZE(cpu_cvb_dvfs_table)) || ret);
725 /* Init rail structures and dependencies */
726 tegra_dvfs_init_rails(tegra11_dvfs_rails,
727 ARRAY_SIZE(tegra11_dvfs_rails));
729 /* Search core dvfs table for speedo/process matching entries and
730 initialize dvfs-ed clocks */
731 for (i = 0; i < ARRAY_SIZE(core_dvfs_table); i++) {
732 struct dvfs *d = &core_dvfs_table[i];
733 if (!match_dvfs_one(d, soc_speedo_id, core_process_id))
735 init_dvfs_one(d, core_nominal_mv_index);
738 /* Initialize matching cpu dvfs entry already found when nominal
739 voltage was determined */
740 init_dvfs_one(&cpu_dvfs, cpu_max_freq_index);
742 /* Finally disable dvfs on rails if necessary */
743 if (tegra_dvfs_core_disabled)
744 tegra_dvfs_rail_disable(&tegra11_dvfs_rail_vdd_core);
745 if (tegra_dvfs_cpu_disabled)
746 tegra_dvfs_rail_disable(&tegra11_dvfs_rail_vdd_cpu);
748 pr_info("tegra dvfs: VDD_CPU nominal %dmV, scaling %s\n",
749 tegra11_dvfs_rail_vdd_cpu.nominal_millivolts,
750 tegra_dvfs_cpu_disabled ? "disabled" : "enabled");
751 pr_info("tegra dvfs: VDD_CORE nominal %dmV, scaling %s\n",
752 tegra11_dvfs_rail_vdd_core.nominal_millivolts,
753 tegra_dvfs_core_disabled ? "disabled" : "enabled");
756 int tegra_dvfs_rail_disable_prepare(struct dvfs_rail *rail)
761 int tegra_dvfs_rail_post_enable(struct dvfs_rail *rail)
767 * sysfs and dvfs interfaces to cap tegra core domains frequencies
769 static DEFINE_MUTEX(core_cap_lock);
775 static struct core_cap core_buses_cap;
776 static struct core_cap kdvfs_core_cap;
777 static struct core_cap user_core_cap;
779 static struct kobject *cap_kobj;
781 /* Arranged in order required for enabling/lowering the cap */
783 const char *cap_name;
785 unsigned long freqs[MAX_DVFS_FREQS];
786 } core_cap_table[] = {
787 #ifdef CONFIG_TEGRA_DUAL_CBUS
788 { .cap_name = "cap.c2bus" },
789 { .cap_name = "cap.c3bus" },
791 { .cap_name = "cap.cbus" },
793 { .cap_name = "cap.sclk" },
794 { .cap_name = "cap.emc" },
798 static void core_cap_level_set(int level)
802 for (j = 0; j < ARRAY_SIZE(core_millivolts); j++) {
803 int v = core_millivolts[j];
804 if ((v == 0) || (level < v))
807 j = (j == 0) ? 0 : j - 1;
808 level = core_millivolts[j];
810 if (level < core_buses_cap.level) {
811 for (i = 0; i < ARRAY_SIZE(core_cap_table); i++)
812 if (core_cap_table[i].cap_clk)
813 clk_set_rate(core_cap_table[i].cap_clk,
814 core_cap_table[i].freqs[j]);
815 } else if (level > core_buses_cap.level) {
816 for (i = ARRAY_SIZE(core_cap_table) - 1; i >= 0; i--)
817 if (core_cap_table[i].cap_clk)
818 clk_set_rate(core_cap_table[i].cap_clk,
819 core_cap_table[i].freqs[j]);
821 core_buses_cap.level = level;
824 static void core_cap_update(void)
826 int new_level = tegra11_dvfs_rail_vdd_core.max_millivolts;
828 if (kdvfs_core_cap.refcnt)
829 new_level = min(new_level, kdvfs_core_cap.level);
830 if (user_core_cap.refcnt)
831 new_level = min(new_level, user_core_cap.level);
833 if (core_buses_cap.level != new_level)
834 core_cap_level_set(new_level);
837 static void core_cap_enable(bool enable)
840 core_buses_cap.refcnt++;
841 else if (core_buses_cap.refcnt)
842 core_buses_cap.refcnt--;
848 core_cap_state_show(struct kobject *kobj, struct kobj_attribute *attr,
851 return sprintf(buf, "%d (%d)\n", core_buses_cap.refcnt ? 1 : 0,
852 user_core_cap.refcnt ? 1 : 0);
855 core_cap_state_store(struct kobject *kobj, struct kobj_attribute *attr,
856 const char *buf, size_t count)
860 if (sscanf(buf, "%d", &state) != 1)
863 mutex_lock(&core_cap_lock);
866 user_core_cap.refcnt++;
867 if (user_core_cap.refcnt == 1)
868 core_cap_enable(true);
869 } else if (user_core_cap.refcnt) {
870 user_core_cap.refcnt--;
871 if (user_core_cap.refcnt == 0)
872 core_cap_enable(false);
875 mutex_unlock(&core_cap_lock);
880 core_cap_level_show(struct kobject *kobj, struct kobj_attribute *attr,
883 return sprintf(buf, "%d (%d)\n", core_buses_cap.level,
884 user_core_cap.level);
887 core_cap_level_store(struct kobject *kobj, struct kobj_attribute *attr,
888 const char *buf, size_t count)
892 if (sscanf(buf, "%d", &level) != 1)
895 mutex_lock(&core_cap_lock);
896 user_core_cap.level = level;
898 mutex_unlock(&core_cap_lock);
902 static struct kobj_attribute cap_state_attribute =
903 __ATTR(core_cap_state, 0644, core_cap_state_show, core_cap_state_store);
904 static struct kobj_attribute cap_level_attribute =
905 __ATTR(core_cap_level, 0644, core_cap_level_show, core_cap_level_store);
907 const struct attribute *cap_attributes[] = {
908 &cap_state_attribute.attr,
909 &cap_level_attribute.attr,
913 void tegra_dvfs_core_cap_enable(bool enable)
915 mutex_lock(&core_cap_lock);
918 kdvfs_core_cap.refcnt++;
919 if (kdvfs_core_cap.refcnt == 1)
920 core_cap_enable(true);
921 } else if (kdvfs_core_cap.refcnt) {
922 kdvfs_core_cap.refcnt--;
923 if (kdvfs_core_cap.refcnt == 0)
924 core_cap_enable(false);
926 mutex_unlock(&core_cap_lock);
929 void tegra_dvfs_core_cap_level_set(int level)
931 mutex_lock(&core_cap_lock);
932 kdvfs_core_cap.level = level;
934 mutex_unlock(&core_cap_lock);
937 static int __init init_core_cap_one(struct clk *c, unsigned long *freqs)
939 int i, v, next_v = 0;
940 unsigned long rate, next_rate = 0;
942 for (i = 0; i < ARRAY_SIZE(core_millivolts); i++) {
943 v = core_millivolts[i];
949 next_rate = clk_round_rate(c->parent, rate + 1000);
950 if (IS_ERR_VALUE(next_rate)) {
951 pr_debug("tegra11_dvfs: failed to round %s rate %lu\n",
955 if (rate == next_rate)
958 next_v = tegra_dvfs_predict_millivolts(
959 c->parent, next_rate);
960 if (IS_ERR_VALUE(next_v)) {
961 pr_debug("tegra11_dvfs: failed to predict %s mV for rate %lu\n",
971 pr_warn("tegra11_dvfs: minimum %s rate %lu requires %d mV\n",
972 c->name, rate, next_v);
980 static int __init tegra_dvfs_init_core_cap(void)
983 struct clk *c = NULL;
985 core_buses_cap.level = kdvfs_core_cap.level = user_core_cap.level =
986 tegra11_dvfs_rail_vdd_core.max_millivolts;
988 for (i = 0; i < ARRAY_SIZE(core_cap_table); i++) {
989 c = tegra_get_clock_by_name(core_cap_table[i].cap_name);
990 if (!c || !c->parent ||
991 init_core_cap_one(c, core_cap_table[i].freqs)) {
992 pr_err("tegra11_dvfs: failed to initialize %s table\n",
993 core_cap_table[i].cap_name);
996 core_cap_table[i].cap_clk = c;
999 cap_kobj = kobject_create_and_add("tegra_cap", kernel_kobj);
1001 pr_err("tegra11_dvfs: failed to create sysfs cap object\n");
1005 if (sysfs_create_files(cap_kobj, cap_attributes)) {
1006 pr_err("tegra11_dvfs: failed to create sysfs cap interface\n");
1009 pr_info("tegra dvfs: tegra sysfs cap interface is initialized\n");
1013 late_initcall(tegra_dvfs_init_core_cap);