]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - arch/arm/mach-tegra/tegra11_dvfs.c
ARM: tegra11: dvfs: Add core rail thermal trip-point
[linux-3.10.git] / arch / arm / mach-tegra / tegra11_dvfs.c
1 /*
2  * arch/arm/mach-tegra/tegra11_dvfs.c
3  *
4  * Copyright (C) 2012 NVIDIA Corporation.
5  *
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.
9  *
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.
14  *
15  */
16
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
25 #include "clock.h"
26 #include "dvfs.h"
27 #include "fuse.h"
28 #include "board.h"
29 #include "tegra_cl_dvfs.h"
30
31 static bool tegra_dvfs_cpu_disabled;
32 static bool tegra_dvfs_core_disabled;
33
34 #define KHZ 1000
35 #define MHZ 1000000
36
37 /* FIXME: need tegra11 step */
38 #define VDD_SAFE_STEP                   100
39
40 static int dvfs_temperatures[] = { 20, };
41
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),
46 };
47
48 static struct tegra_cooling_device core_cdev = {
49         .cdev_type = "core",
50         .trip_temperatures = dvfs_temperatures,
51         .trip_temperatures_num = ARRAY_SIZE(dvfs_temperatures),
52 };
53
54 static struct dvfs_rail tegra11_dvfs_rail_vdd_cpu = {
55         .reg_id = "vdd_cpu",
56         .max_millivolts = 1400,
57         .min_millivolts = 800,
58         .step = VDD_SAFE_STEP,
59         .jmp_to_zero = true,
60         .min_millivolts_cold = 1000,
61         .dfll_mode_cdev = &cpu_dfll_cdev,
62 };
63
64 static struct dvfs_rail tegra11_dvfs_rail_vdd_core = {
65         .reg_id = "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,
71 };
72
73 static struct dvfs_rail *tegra11_dvfs_rails[] = {
74         &tegra11_dvfs_rail_vdd_cpu,
75         &tegra11_dvfs_rail_vdd_core,
76 };
77
78 /* default cvb alignment on Tegra11 - 10mV */
79 int __attribute__((weak)) tegra_get_cvb_alignment_uV(void)
80 {
81         return 10000;
82 }
83
84 /* CPU DVFS tables */
85 static struct cpu_cvb_dvfs cpu_cvb_dvfs_table[] = {
86         {
87                 .speedo_id = 0,
88                 .process_id = -1,
89                 .dfll_tune_data  = {
90                         .tune0          = 0x00b0019d,
91                         .tune0_high_mv  = 0x00b0019d,
92                         .tune1          = 0x0000001f,
93                         .droop_rate_min = 1000000,
94                         .min_millivolts = 1000,
95                 },
96                 .max_mv = 1250,
97                 .freqs_mult = KHZ,
98                 .speedo_scale = 100,
99                 .voltage_scale = 100,
100                 .cvb_table = {
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} },
121                 },
122         },
123         {
124                 .speedo_id = 1,
125                 .process_id = 0,
126                 .dfll_tune_data  = {
127                         .tune0          = 0x00b0039d,
128                         .tune0_high_mv  = 0x00b0009d,
129                         .tune1          = 0x0000001f,
130                         .droop_rate_min = 1000000,
131                         .tune_high_min_millivolts = 1000,
132                         .min_millivolts = 900,
133                 },
134                 .max_mv = 1350,
135                 .freqs_mult = KHZ,
136                 .speedo_scale = 100,
137                 .voltage_scale = 1000,
138                 .cvb_table = {
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} },
157                 },
158         },
159         {
160                 .speedo_id = 1,
161                 .process_id = 1,
162                 .dfll_tune_data  = {
163                         .tune0          = 0x00b0039d,
164                         .tune0_high_mv  = 0x00b0009d,
165                         .tune1          = 0x0000001f,
166                         .droop_rate_min = 1000000,
167                         .tune_high_min_millivolts = 1000,
168                         .min_millivolts = 900,
169                 },
170                 .max_mv = 1350,
171                 .freqs_mult = KHZ,
172                 .speedo_scale = 100,
173                 .voltage_scale = 1000,
174                 .cvb_table = {
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} },
193                 },
194         },
195         {
196                 .speedo_id = 2,
197                 .process_id = -1,
198                 .dfll_tune_data  = {
199                         .tune0          = 0x00b0039d,
200                         .tune0_high_mv  = 0x00b0009d,
201                         .tune1          = 0x0000001f,
202                         .droop_rate_min = 1000000,
203                         .tune_high_min_millivolts = 1000,
204                         .min_millivolts = 900,
205                 },
206                 .max_mv = 1350,
207                 .freqs_mult = KHZ,
208                 .speedo_scale = 100,
209                 .voltage_scale = 1000,
210                 .cvb_table = {
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} },
230                 },
231         },
232 };
233
234 static int cpu_millivolts[MAX_DVFS_FREQS];
235 static int cpu_dfll_millivolts[MAX_DVFS_FREQS];
236
237 static struct dvfs cpu_dvfs = {
238         .clk_name       = "cpu_g",
239         .millivolts     = cpu_millivolts,
240         .dfll_millivolts = cpu_dfll_millivolts,
241         .auto_dvfs      = true,
242         .dvfs_rail      = &tegra11_dvfs_rail_vdd_cpu,
243 };
244
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};
249
250 #define CORE_DVFS(_clk_name, _speedo_id, _process_id, _auto, _mult, _freqs...) \
251         {                                                       \
252                 .clk_name       = _clk_name,                    \
253                 .speedo_id      = _speedo_id,                   \
254                 .process_id     = _process_id,                  \
255                 .freqs          = {_freqs},                     \
256                 .freqs_mult     = _mult,                        \
257                 .millivolts     = core_millivolts,              \
258                 .auto_dvfs      = _auto,                        \
259                 .dvfs_rail      = &tegra11_dvfs_rail_vdd_core,  \
260         }
261
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),
267
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),
271
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),
275
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),
278
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),
282
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),
286
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),
291
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),
296
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),
301
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),
305
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),
312 #else
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),
316 #endif
317
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),
322
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),
331
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),
335
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),
340
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),
346
347         /*
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
352          */
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),
355
356         /* xusb clocks */
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),
363 #endif
364 };
365
366 int tegra_dvfs_disable_core_set(const char *arg, const struct kernel_param *kp)
367 {
368         int ret;
369
370         ret = param_set_bool(arg, kp);
371         if (ret)
372                 return ret;
373
374         if (tegra_dvfs_core_disabled)
375                 tegra_dvfs_rail_disable(&tegra11_dvfs_rail_vdd_core);
376         else
377                 tegra_dvfs_rail_enable(&tegra11_dvfs_rail_vdd_core);
378
379         return 0;
380 }
381
382 int tegra_dvfs_disable_cpu_set(const char *arg, const struct kernel_param *kp)
383 {
384         int ret;
385
386         ret = param_set_bool(arg, kp);
387         if (ret)
388                 return ret;
389
390         if (tegra_dvfs_cpu_disabled)
391                 tegra_dvfs_rail_disable(&tegra11_dvfs_rail_vdd_cpu);
392         else
393                 tegra_dvfs_rail_enable(&tegra11_dvfs_rail_vdd_cpu);
394
395         return 0;
396 }
397
398 int tegra_dvfs_disable_get(char *buffer, const struct kernel_param *kp)
399 {
400         return param_get_bool(buffer, kp);
401 }
402
403 static struct kernel_param_ops tegra_dvfs_disable_core_ops = {
404         .set = tegra_dvfs_disable_core_set,
405         .get = tegra_dvfs_disable_get,
406 };
407
408 static struct kernel_param_ops tegra_dvfs_disable_cpu_ops = {
409         .set = tegra_dvfs_disable_cpu_set,
410         .get = tegra_dvfs_disable_get,
411 };
412
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);
417
418
419 static bool __init can_update_max_rate(struct clk *c, struct dvfs *d)
420 {
421         /* Don't update manual dvfs clocks */
422         if (!d->auto_dvfs)
423                 return false;
424
425         /*
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).
432          */
433         if (c->ops->shared_bus_update && (c->flags & PERIPH_EMC_ENB))
434                 return false;
435
436         /*
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.
440          */
441         if (c->ops->shared_bus_update && (c->flags & PERIPH_ON_CBUS)) {
442                 struct clk *user;
443                 unsigned long rate;
444
445                 list_for_each_entry(
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;
451                         }
452                 }
453                 return false;
454         }
455
456         /* Other, than EMC and cbus, auto-dvfs clocks can be updated */
457         return true;
458 }
459
460 static void __init init_dvfs_one(struct dvfs *d, int max_freq_index)
461 {
462         int ret;
463         struct clk *c = tegra_get_clock_by_name(d->clk_name);
464
465         if (!c) {
466                 pr_debug("tegra11_dvfs: no clock found for %s\n",
467                         d->clk_name);
468                 return;
469         }
470
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]);
474                 tegra_init_max_rate(
475                         c, d->freqs[max_freq_index] * d->freqs_mult);
476         }
477         d->max_millivolts = d->dvfs_rail->nominal_millivolts;
478
479         ret = tegra_enable_dvfs_on_clk(c, d);
480         if (ret)
481                 pr_err("tegra11_dvfs: failed to enable dvfs on %s\n", c->name);
482 }
483
484 static bool __init match_dvfs_one(struct dvfs *d, int speedo_id, int process_id)
485 {
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,
490                         d->process_id);
491                 return false;
492         }
493         return true;
494 }
495
496 static bool __init match_cpu_cvb_one(struct cpu_cvb_dvfs *d,
497                                      int speedo_id, int process_id)
498 {
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);
503                 return false;
504         }
505         return true;
506 }
507
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)
511 {
512         /* apply only speedo scale: output mv = cvb_mv * v_scale */
513         int mv;
514         mv = DIV_ROUND_CLOSEST(cvb->c2 * speedo, s_scale);
515         mv = DIV_ROUND_CLOSEST((mv + cvb->c1) * speedo, s_scale) + cvb->c0;
516         return mv;
517 }
518
519 static inline int round_cvb_voltage(int mv, int v_scale)
520 {
521         /* combined: apply voltage scale and round to cvb alignment step */
522         int cvb_align_step_uv = tegra_get_cvb_alignment_uV();
523
524         return DIV_ROUND_UP(mv * 1000, v_scale * cvb_align_step_uv) *
525                 cvb_align_step_uv / 1000;
526 }
527
528 static int __init set_cpu_dvfs_data(
529         struct cpu_cvb_dvfs *d, struct dvfs *cpu_dvfs, int *max_freq_index)
530 {
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();
537
538         min_dfll_mv = d->dfll_tune_data.min_millivolts;
539         BUG_ON(min_dfll_mv < tegra11_dvfs_rail_vdd_cpu.min_millivolts);
540
541         /*
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
545          * source.
546          *
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.
551          */
552         for (i = 0, j = 0; i < MAX_DVFS_FREQS; i++) {
553                 table = &d->cvb_table[i];
554                 if (!table->freq)
555                         break;
556
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);
560
561                 mv = get_cvb_voltage(
562                         speedo, d->speedo_scale, &table->cvb_pll_param);
563                 mv = round_cvb_voltage(mv, d->voltage_scale);
564
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) {
568                         if (!j)
569                                 break;  /* 1st entry already above Vmin */
570                         if (!fmax_at_vmin)
571                                 fmax_at_vmin = cpu_dvfs->freqs[j - 1];
572                 }
573
574                 /* Clip maximum frequency at maximum voltage for pll source */
575                 if (mv > d->max_mv) {
576                         if (!j)
577                                 break;  /* 1st entry already above Vmax */
578                         if (!fmax_pll_mode)
579                                 fmax_pll_mode = cpu_dvfs->freqs[j - 1];
580                 }
581
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;
585
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;
590                 j++;
591
592                 /*
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)
597                  */
598                 if (dfll_mv > d->max_mv)
599                         break;
600         }
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");
605                 return -ENOENT;
606         }
607
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");
611                 return -EINVAL;
612         }
613
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;
621
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;
628         return 0;
629 }
630
631 static int __init get_core_nominal_mv_index(int speedo_id)
632 {
633         int i;
634         int mv = tegra_core_speedo_mv();
635         int core_edp_voltage = get_core_edp();
636
637         /*
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).
641          */
642         if (!core_edp_voltage)
643                 core_edp_voltage = 1100;        /* default 1.1V EDP limit */
644
645         mv = min(mv, core_edp_voltage);
646
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]))
650                         break;
651         }
652
653         if (i == 0) {
654                 pr_err("tegra11_dvfs: unable to adjust core dvfs table to"
655                        " nominal voltage %d\n", mv);
656                 return -ENOSYS;
657         }
658         return i - 1;
659 }
660
661 int tegra_cpu_dvfs_alter(int edp_thermal_index, const cpumask_t *cpus,
662                          bool before_clk_update, int cpu_event)
663 {
664         /* empty definition for tegra11 */
665         return 0;
666 }
667
668 void __init tegra11x_init_dvfs(void)
669 {
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();
674
675         int i, ret;
676         int core_nominal_mv_index;
677         int cpu_max_freq_index = 0;
678
679 #ifndef CONFIG_TEGRA_CORE_DVFS
680         tegra_dvfs_core_disabled = true;
681 #endif
682 #ifndef CONFIG_TEGRA_CPU_DVFS
683         tegra_dvfs_cpu_disabled = true;
684 #endif
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();
688
689         /*
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.
695          */
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;
701         }
702         tegra11_dvfs_rail_vdd_core.nominal_millivolts =
703                 core_millivolts[core_nominal_mv_index];
704
705         /*
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.
714          */
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);
720                         break;
721                 }
722         }
723         BUG_ON((i == ARRAY_SIZE(cpu_cvb_dvfs_table)) || ret);
724
725         /* Init rail structures and dependencies */
726         tegra_dvfs_init_rails(tegra11_dvfs_rails,
727                 ARRAY_SIZE(tegra11_dvfs_rails));
728
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))
734                         continue;
735                 init_dvfs_one(d, core_nominal_mv_index);
736         }
737
738         /* Initialize matching cpu dvfs entry already found when nominal
739            voltage was determined */
740         init_dvfs_one(&cpu_dvfs, cpu_max_freq_index);
741
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);
747
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");
754 }
755
756 int tegra_dvfs_rail_disable_prepare(struct dvfs_rail *rail)
757 {
758         return 0;
759 }
760
761 int tegra_dvfs_rail_post_enable(struct dvfs_rail *rail)
762 {
763         return 0;
764 }
765
766 /*
767  * sysfs and dvfs interfaces to cap tegra core domains frequencies
768  */
769 static DEFINE_MUTEX(core_cap_lock);
770
771 struct core_cap {
772         int refcnt;
773         int level;
774 };
775 static struct core_cap core_buses_cap;
776 static struct core_cap kdvfs_core_cap;
777 static struct core_cap user_core_cap;
778
779 static struct kobject *cap_kobj;
780
781 /* Arranged in order required for enabling/lowering the cap */
782 static struct {
783         const char *cap_name;
784         struct clk *cap_clk;
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" },
790 #else
791         { .cap_name = "cap.cbus" },
792 #endif
793         { .cap_name = "cap.sclk" },
794         { .cap_name = "cap.emc" },
795 };
796
797
798 static void core_cap_level_set(int level)
799 {
800         int i, j;
801
802         for (j = 0; j < ARRAY_SIZE(core_millivolts); j++) {
803                 int v = core_millivolts[j];
804                 if ((v == 0) || (level < v))
805                         break;
806         }
807         j = (j == 0) ? 0 : j - 1;
808         level = core_millivolts[j];
809
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]);
820         }
821         core_buses_cap.level = level;
822 }
823
824 static void core_cap_update(void)
825 {
826         int new_level = tegra11_dvfs_rail_vdd_core.max_millivolts;
827
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);
832
833         if (core_buses_cap.level != new_level)
834                 core_cap_level_set(new_level);
835 }
836
837 static void core_cap_enable(bool enable)
838 {
839         if (enable)
840                 core_buses_cap.refcnt++;
841         else if (core_buses_cap.refcnt)
842                 core_buses_cap.refcnt--;
843
844         core_cap_update();
845 }
846
847 static ssize_t
848 core_cap_state_show(struct kobject *kobj, struct kobj_attribute *attr,
849                     char *buf)
850 {
851         return sprintf(buf, "%d (%d)\n", core_buses_cap.refcnt ? 1 : 0,
852                         user_core_cap.refcnt ? 1 : 0);
853 }
854 static ssize_t
855 core_cap_state_store(struct kobject *kobj, struct kobj_attribute *attr,
856                      const char *buf, size_t count)
857 {
858         int state;
859
860         if (sscanf(buf, "%d", &state) != 1)
861                 return -1;
862
863         mutex_lock(&core_cap_lock);
864
865         if (state) {
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);
873         }
874
875         mutex_unlock(&core_cap_lock);
876         return count;
877 }
878
879 static ssize_t
880 core_cap_level_show(struct kobject *kobj, struct kobj_attribute *attr,
881                     char *buf)
882 {
883         return sprintf(buf, "%d (%d)\n", core_buses_cap.level,
884                         user_core_cap.level);
885 }
886 static ssize_t
887 core_cap_level_store(struct kobject *kobj, struct kobj_attribute *attr,
888                      const char *buf, size_t count)
889 {
890         int level;
891
892         if (sscanf(buf, "%d", &level) != 1)
893                 return -1;
894
895         mutex_lock(&core_cap_lock);
896         user_core_cap.level = level;
897         core_cap_update();
898         mutex_unlock(&core_cap_lock);
899         return count;
900 }
901
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);
906
907 const struct attribute *cap_attributes[] = {
908         &cap_state_attribute.attr,
909         &cap_level_attribute.attr,
910         NULL,
911 };
912
913 void tegra_dvfs_core_cap_enable(bool enable)
914 {
915         mutex_lock(&core_cap_lock);
916
917         if (enable) {
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);
925         }
926         mutex_unlock(&core_cap_lock);
927 }
928
929 void tegra_dvfs_core_cap_level_set(int level)
930 {
931         mutex_lock(&core_cap_lock);
932         kdvfs_core_cap.level = level;
933         core_cap_update();
934         mutex_unlock(&core_cap_lock);
935 }
936
937 static int __init init_core_cap_one(struct clk *c, unsigned long *freqs)
938 {
939         int i, v, next_v = 0;
940         unsigned long rate, next_rate = 0;
941
942         for (i = 0; i < ARRAY_SIZE(core_millivolts); i++) {
943                 v = core_millivolts[i];
944                 if (v == 0)
945                         break;
946
947                 for (;;) {
948                         rate = next_rate;
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",
952                                          c->name, rate);
953                                 return -EINVAL;
954                         }
955                         if (rate == next_rate)
956                                 break;
957
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",
962                                          c->name, next_rate);
963                                 return -EINVAL;
964                         }
965                         if (next_v > v)
966                                 break;
967                 }
968
969                 if (rate == 0) {
970                         rate = next_rate;
971                         pr_warn("tegra11_dvfs: minimum %s rate %lu requires %d mV\n",
972                                 c->name, rate, next_v);
973                 }
974                 freqs[i] = rate;
975                 next_rate = rate;
976         }
977         return 0;
978 }
979
980 static int __init tegra_dvfs_init_core_cap(void)
981 {
982         int i;
983         struct clk *c = NULL;
984
985         core_buses_cap.level = kdvfs_core_cap.level = user_core_cap.level =
986                 tegra11_dvfs_rail_vdd_core.max_millivolts;
987
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);
994                         continue;
995                 }
996                 core_cap_table[i].cap_clk = c;
997         }
998
999         cap_kobj = kobject_create_and_add("tegra_cap", kernel_kobj);
1000         if (!cap_kobj) {
1001                 pr_err("tegra11_dvfs: failed to create sysfs cap object\n");
1002                 return 0;
1003         }
1004
1005         if (sysfs_create_files(cap_kobj, cap_attributes)) {
1006                 pr_err("tegra11_dvfs: failed to create sysfs cap interface\n");
1007                 return 0;
1008         }
1009         pr_info("tegra dvfs: tegra sysfs cap interface is initialized\n");
1010
1011         return 0;
1012 }
1013 late_initcall(tegra_dvfs_init_core_cap);