blob: 5c4305a418cc897e117b17ffbb8ba8d9053af76e [file] [log] [blame]
Tom Warrene3d95bc2013-01-28 13:32:10 +00001/*
2 * Copyright (c) 2010-2013, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/* Tegra114 Clock control functions */
18
19#include <common.h>
20#include <asm/io.h>
21#include <asm/arch/clock.h>
Tom Warrenfbef3552013-04-01 15:48:54 -070022#include <asm/arch/sysctr.h>
Tom Warrene3d95bc2013-01-28 13:32:10 +000023#include <asm/arch/tegra.h>
24#include <asm/arch-tegra/clk_rst.h>
25#include <asm/arch-tegra/timer.h>
26#include <div64.h>
27#include <fdtdec.h>
28
29/*
30 * Clock types that we can use as a source. The Tegra114 has muxes for the
31 * peripheral clocks, and in most cases there are four options for the clock
32 * source. This gives us a clock 'type' and exploits what commonality exists
33 * in the device.
34 *
35 * Letters are obvious, except for T which means CLK_M, and S which means the
36 * clock derived from 32KHz. Beware that CLK_M (also called OSC in the
37 * datasheet) and PLL_M are different things. The former is the basic
38 * clock supplied to the SOC from an external oscillator. The latter is the
39 * memory clock PLL.
40 *
41 * See definitions in clock_id in the header file.
42 */
43enum clock_type_id {
44 CLOCK_TYPE_AXPT, /* PLL_A, PLL_X, PLL_P, CLK_M */
45 CLOCK_TYPE_MCPA, /* and so on */
46 CLOCK_TYPE_MCPT,
47 CLOCK_TYPE_PCM,
48 CLOCK_TYPE_PCMT,
49 CLOCK_TYPE_PCMT16,
50 CLOCK_TYPE_PDCT,
51 CLOCK_TYPE_ACPT,
52 CLOCK_TYPE_ASPTE,
53 CLOCK_TYPE_PMDACD2T,
54 CLOCK_TYPE_PCST,
55
56 CLOCK_TYPE_COUNT,
57 CLOCK_TYPE_NONE = -1, /* invalid clock type */
58};
59
60enum {
61 CLOCK_MAX_MUX = 8 /* number of source options for each clock */
62};
63
64enum {
65 MASK_BITS_31_30 = 2, /* num of bits used to specify clock source */
66 MASK_BITS_31_29,
67 MASK_BITS_29_28,
68};
69
70/*
71 * Clock source mux for each clock type. This just converts our enum into
72 * a list of mux sources for use by the code.
73 *
74 * Note:
75 * The extra column in each clock source array is used to store the mask
76 * bits in its register for the source.
77 */
78#define CLK(x) CLOCK_ID_ ## x
79static enum clock_id clock_source[CLOCK_TYPE_COUNT][CLOCK_MAX_MUX+1] = {
80 { CLK(AUDIO), CLK(XCPU), CLK(PERIPH), CLK(OSC),
81 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
82 MASK_BITS_31_30},
83 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(AUDIO),
84 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
85 MASK_BITS_31_30},
86 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
87 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
88 MASK_BITS_31_30},
89 { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(NONE),
90 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
91 MASK_BITS_31_30},
92 { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC),
93 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
94 MASK_BITS_31_30},
95 { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC),
96 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
97 MASK_BITS_31_30},
98 { CLK(PERIPH), CLK(DISPLAY), CLK(CGENERAL), CLK(OSC),
99 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
100 MASK_BITS_31_30},
101 { CLK(AUDIO), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
102 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
103 MASK_BITS_31_30},
104 { CLK(AUDIO), CLK(SFROM32KHZ), CLK(PERIPH), CLK(OSC),
105 CLK(EPCI), CLK(NONE), CLK(NONE), CLK(NONE),
106 MASK_BITS_31_29},
107 { CLK(PERIPH), CLK(MEMORY), CLK(DISPLAY), CLK(AUDIO),
108 CLK(CGENERAL), CLK(DISPLAY2), CLK(OSC), CLK(NONE),
109 MASK_BITS_31_29},
110 { CLK(PERIPH), CLK(CGENERAL), CLK(SFROM32KHZ), CLK(OSC),
111 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
112 MASK_BITS_29_28}
113};
114
115/*
116 * Clock type for each peripheral clock source. We put the name in each
117 * record just so it is easy to match things up
118 */
119#define TYPE(name, type) type
120static enum clock_type_id clock_periph_type[PERIPHC_COUNT] = {
121 /* 0x00 */
122 TYPE(PERIPHC_I2S1, CLOCK_TYPE_AXPT),
123 TYPE(PERIPHC_I2S2, CLOCK_TYPE_AXPT),
124 TYPE(PERIPHC_SPDIF_OUT, CLOCK_TYPE_AXPT),
125 TYPE(PERIPHC_SPDIF_IN, CLOCK_TYPE_PCM),
126 TYPE(PERIPHC_PWM, CLOCK_TYPE_PCST), /* only PWM uses b29:28 */
127 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
128 TYPE(PERIPHC_SBC2, CLOCK_TYPE_PCMT),
129 TYPE(PERIPHC_SBC3, CLOCK_TYPE_PCMT),
130
131 /* 0x08 */
132 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
133 TYPE(PERIPHC_I2C1, CLOCK_TYPE_PCMT16),
134 TYPE(PERIPHC_I2C5, CLOCK_TYPE_PCMT16),
135 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
136 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
137 TYPE(PERIPHC_SBC1, CLOCK_TYPE_PCMT),
138 TYPE(PERIPHC_DISP1, CLOCK_TYPE_PMDACD2T),
139 TYPE(PERIPHC_DISP2, CLOCK_TYPE_PMDACD2T),
140
141 /* 0x10 */
142 TYPE(PERIPHC_CVE, CLOCK_TYPE_PDCT),
143 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
144 TYPE(PERIPHC_VI, CLOCK_TYPE_MCPA),
145 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
146 TYPE(PERIPHC_SDMMC1, CLOCK_TYPE_PCMT),
147 TYPE(PERIPHC_SDMMC2, CLOCK_TYPE_PCMT),
148 TYPE(PERIPHC_G3D, CLOCK_TYPE_MCPA),
149 TYPE(PERIPHC_G2D, CLOCK_TYPE_MCPA),
150
151 /* 0x18 */
152 TYPE(PERIPHC_NDFLASH, CLOCK_TYPE_PCMT),
153 TYPE(PERIPHC_SDMMC4, CLOCK_TYPE_PCMT),
154 TYPE(PERIPHC_VFIR, CLOCK_TYPE_PCMT),
155 TYPE(PERIPHC_EPP, CLOCK_TYPE_MCPA),
156 TYPE(PERIPHC_MPE, CLOCK_TYPE_MCPA),
157 TYPE(PERIPHC_MIPI, CLOCK_TYPE_PCMT), /* MIPI base-band HSI */
158 TYPE(PERIPHC_UART1, CLOCK_TYPE_PCMT),
159 TYPE(PERIPHC_UART2, CLOCK_TYPE_PCMT),
160
161 /* 0x20 */
162 TYPE(PERIPHC_HOST1X, CLOCK_TYPE_MCPA),
163 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
164 TYPE(PERIPHC_TVO, CLOCK_TYPE_PDCT),
165 TYPE(PERIPHC_HDMI, CLOCK_TYPE_PMDACD2T),
166 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
167 TYPE(PERIPHC_TVDAC, CLOCK_TYPE_PDCT),
168 TYPE(PERIPHC_I2C2, CLOCK_TYPE_PCMT16),
169 TYPE(PERIPHC_EMC, CLOCK_TYPE_MCPT),
170
171 /* 0x28 */
172 TYPE(PERIPHC_UART3, CLOCK_TYPE_PCMT),
173 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
174 TYPE(PERIPHC_VI, CLOCK_TYPE_MCPA),
175 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
176 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
177 TYPE(PERIPHC_SBC4, CLOCK_TYPE_PCMT),
178 TYPE(PERIPHC_I2C3, CLOCK_TYPE_PCMT16),
179 TYPE(PERIPHC_SDMMC3, CLOCK_TYPE_PCMT),
180
181 /* 0x30 */
182 TYPE(PERIPHC_UART4, CLOCK_TYPE_PCMT),
183 TYPE(PERIPHC_UART5, CLOCK_TYPE_PCMT),
184 TYPE(PERIPHC_VDE, CLOCK_TYPE_PCMT),
185 TYPE(PERIPHC_OWR, CLOCK_TYPE_PCMT),
186 TYPE(PERIPHC_NOR, CLOCK_TYPE_PCMT),
187 TYPE(PERIPHC_CSITE, CLOCK_TYPE_PCMT),
188 TYPE(PERIPHC_I2S0, CLOCK_TYPE_AXPT),
189 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
190
191 /* 0x38h */ /* Jumps to reg offset 0x3B0h */
192 TYPE(PERIPHC_G3D2, CLOCK_TYPE_MCPA),
193 TYPE(PERIPHC_MSELECT, CLOCK_TYPE_PCMT),
194 TYPE(PERIPHC_TSENSOR, CLOCK_TYPE_PCST), /* s/b PCTS */
195 TYPE(PERIPHC_I2S3, CLOCK_TYPE_AXPT),
196 TYPE(PERIPHC_I2S4, CLOCK_TYPE_AXPT),
197 TYPE(PERIPHC_I2C4, CLOCK_TYPE_PCMT16),
198 TYPE(PERIPHC_SBC5, CLOCK_TYPE_PCMT),
199 TYPE(PERIPHC_SBC6, CLOCK_TYPE_PCMT),
200
201 /* 0x40 */
202 TYPE(PERIPHC_AUDIO, CLOCK_TYPE_ACPT),
203 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
204 TYPE(PERIPHC_DAM0, CLOCK_TYPE_ACPT),
205 TYPE(PERIPHC_DAM1, CLOCK_TYPE_ACPT),
206 TYPE(PERIPHC_DAM2, CLOCK_TYPE_ACPT),
207 TYPE(PERIPHC_HDA2CODEC2X, CLOCK_TYPE_PCMT),
208 TYPE(PERIPHC_ACTMON, CLOCK_TYPE_PCST), /* MASK 31:30 */
209 TYPE(PERIPHC_EXTPERIPH1, CLOCK_TYPE_ASPTE),
210
211 /* 0x48 */
212 TYPE(PERIPHC_EXTPERIPH2, CLOCK_TYPE_ASPTE),
213 TYPE(PERIPHC_EXTPERIPH3, CLOCK_TYPE_ASPTE),
214 TYPE(PERIPHC_NANDSPEED, CLOCK_TYPE_PCMT),
215 TYPE(PERIPHC_I2CSLOW, CLOCK_TYPE_PCST), /* MASK 31:30 */
216 TYPE(PERIPHC_SYS, CLOCK_TYPE_NONE),
217 TYPE(PERIPHC_SPEEDO, CLOCK_TYPE_PCMT),
218 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
219 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
220
221 /* 0x50 */
222 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
223 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
224 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
225 TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE),
226 TYPE(PERIPHC_SATAOOB, CLOCK_TYPE_PCMT), /* offset 0x420h */
227 TYPE(PERIPHC_SATA, CLOCK_TYPE_PCMT),
228 TYPE(PERIPHC_HDA, CLOCK_TYPE_PCMT),
229};
230
231/*
232 * This array translates a periph_id to a periphc_internal_id
233 *
234 * Not present/matched up:
235 * uint vi_sensor; _VI_SENSOR_0, 0x1A8
236 * SPDIF - which is both 0x08 and 0x0c
237 *
238 */
239#define NONE(name) (-1)
240#define OFFSET(name, value) PERIPHC_ ## name
241static s8 periph_id_to_internal_id[PERIPH_ID_COUNT] = {
242 /* Low word: 31:0 */
243 NONE(CPU),
244 NONE(COP),
245 NONE(TRIGSYS),
246 NONE(RESERVED3),
247 NONE(RTC),
248 NONE(TMR),
249 PERIPHC_UART1,
250 PERIPHC_UART2, /* and vfir 0x68 */
251
252 /* 8 */
253 NONE(GPIO),
254 PERIPHC_SDMMC2,
255 NONE(SPDIF), /* 0x08 and 0x0c, unclear which to use */
256 PERIPHC_I2S1,
257 PERIPHC_I2C1,
258 PERIPHC_NDFLASH,
259 PERIPHC_SDMMC1,
260 PERIPHC_SDMMC4,
261
262 /* 16 */
263 NONE(RESERVED16),
264 PERIPHC_PWM,
265 PERIPHC_I2S2,
266 PERIPHC_EPP,
267 PERIPHC_VI,
268 PERIPHC_G2D,
269 NONE(USBD),
270 NONE(ISP),
271
272 /* 24 */
273 PERIPHC_G3D,
274 NONE(RESERVED25),
275 PERIPHC_DISP2,
276 PERIPHC_DISP1,
277 PERIPHC_HOST1X,
278 NONE(VCP),
279 PERIPHC_I2S0,
280 NONE(CACHE2),
281
282 /* Middle word: 63:32 */
283 NONE(MEM),
284 NONE(AHBDMA),
285 NONE(APBDMA),
286 NONE(RESERVED35),
287 NONE(RESERVED36),
288 NONE(STAT_MON),
289 NONE(RESERVED38),
290 NONE(RESERVED39),
291
292 /* 40 */
293 NONE(KFUSE),
294 NONE(SBC1), /* SBC1, 0x34, is this SPI1? */
295 PERIPHC_NOR,
296 NONE(RESERVED43),
297 PERIPHC_SBC2,
298 NONE(RESERVED45),
299 PERIPHC_SBC3,
300 PERIPHC_I2C5,
301
302 /* 48 */
303 NONE(DSI),
304 PERIPHC_TVO, /* also CVE 0x40 */
305 PERIPHC_MIPI,
306 PERIPHC_HDMI,
307 NONE(CSI),
308 PERIPHC_TVDAC,
309 PERIPHC_I2C2,
310 PERIPHC_UART3,
311
312 /* 56 */
313 NONE(RESERVED56),
314 PERIPHC_EMC,
315 NONE(USB2),
316 NONE(USB3),
317 PERIPHC_MPE,
318 PERIPHC_VDE,
319 NONE(BSEA),
320 NONE(BSEV),
321
322 /* Upper word 95:64 */
323 PERIPHC_SPEEDO,
324 PERIPHC_UART4,
325 PERIPHC_UART5,
326 PERIPHC_I2C3,
327 PERIPHC_SBC4,
328 PERIPHC_SDMMC3,
329 NONE(PCIE),
330 PERIPHC_OWR,
331
332 /* 72 */
333 NONE(AFI),
334 PERIPHC_CSITE,
335 NONE(PCIEXCLK),
336 NONE(AVPUCQ),
337 NONE(RESERVED76),
338 NONE(RESERVED77),
339 NONE(RESERVED78),
340 NONE(DTV),
341
342 /* 80 */
343 PERIPHC_NANDSPEED,
344 PERIPHC_I2CSLOW,
345 NONE(DSIB),
346 NONE(RESERVED83),
347 NONE(IRAMA),
348 NONE(IRAMB),
349 NONE(IRAMC),
350 NONE(IRAMD),
351
352 /* 88 */
353 NONE(CRAM2),
354 NONE(RESERVED89),
355 NONE(MDOUBLER),
356 NONE(RESERVED91),
357 NONE(SUSOUT),
358 NONE(RESERVED93),
359 NONE(RESERVED94),
360 NONE(RESERVED95),
361
362 /* V word: 31:0 */
363 NONE(CPUG),
364 NONE(CPULP),
365 PERIPHC_G3D2,
366 PERIPHC_MSELECT,
367 PERIPHC_TSENSOR,
368 PERIPHC_I2S3,
369 PERIPHC_I2S4,
370 PERIPHC_I2C4,
371
372 /* 08 */
373 PERIPHC_SBC5,
374 PERIPHC_SBC6,
375 PERIPHC_AUDIO,
376 NONE(APBIF),
377 PERIPHC_DAM0,
378 PERIPHC_DAM1,
379 PERIPHC_DAM2,
380 PERIPHC_HDA2CODEC2X,
381
382 /* 16 */
383 NONE(ATOMICS),
384 NONE(RESERVED17),
385 NONE(RESERVED18),
386 NONE(RESERVED19),
387 NONE(RESERVED20),
388 NONE(RESERVED21),
389 NONE(RESERVED22),
390 PERIPHC_ACTMON,
391
392 /* 24 */
393 NONE(RESERVED24),
394 NONE(RESERVED25),
395 NONE(RESERVED26),
396 NONE(RESERVED27),
397 PERIPHC_SATA,
398 PERIPHC_HDA,
399 NONE(RESERVED30),
400 NONE(RESERVED31),
401
402 /* W word: 31:0 */
403 NONE(HDA2HDMICODEC),
404 NONE(RESERVED1_SATACOLD),
405 NONE(RESERVED2_PCIERX0),
406 NONE(RESERVED3_PCIERX1),
407 NONE(RESERVED4_PCIERX2),
408 NONE(RESERVED5_PCIERX3),
409 NONE(RESERVED6_PCIERX4),
410 NONE(RESERVED7_PCIERX5),
411
412 /* 40 */
413 NONE(CEC),
414 NONE(PCIE2_IOBIST),
415 NONE(EMC_IOBIST),
416 NONE(HDMI_IOBIST),
417 NONE(SATA_IOBIST),
418 NONE(MIPI_IOBIST),
419 NONE(EMC1_IOBIST),
420 NONE(XUSB),
421
422 /* 48 */
423 NONE(CILAB),
424 NONE(CILCD),
425 NONE(CILE),
426 NONE(DSIA_LP),
427 NONE(DSIB_LP),
428 NONE(RESERVED21_ENTROPY),
429 NONE(RESERVED22_W),
430 NONE(RESERVED23_W),
431
432 /* 56 */
433 NONE(RESERVED24_W),
434 NONE(AMX0),
435 NONE(ADX0),
436 NONE(DVFS),
437 NONE(XUSB_SS),
438 NONE(EMC_DLL),
439 NONE(MC1),
440 NONE(EMC1),
441};
442
443/*
444 * Get the oscillator frequency, from the corresponding hardware configuration
445 * field. Note that T30/T114 support 3 new higher freqs, but we map back
446 * to the old T20 freqs. Support for the higher oscillators is TBD.
447 */
448enum clock_osc_freq clock_get_osc_freq(void)
449{
450 struct clk_rst_ctlr *clkrst =
451 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
452 u32 reg;
453
454 reg = readl(&clkrst->crc_osc_ctrl);
455 reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
456
457 if (reg & 1) /* one of the newer freqs */
458 printf("Warning: OSC_FREQ is unsupported! (%d)\n", reg);
459
460 return reg >> 2; /* Map to most common (T20) freqs */
461}
462
463/* Returns a pointer to the clock source register for a peripheral */
464u32 *get_periph_source_reg(enum periph_id periph_id)
465{
466 struct clk_rst_ctlr *clkrst =
467 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
468 enum periphc_internal_id internal_id;
469
470 /* Coresight is a special case */
471 if (periph_id == PERIPH_ID_CSI)
472 return &clkrst->crc_clk_src[PERIPH_ID_CSI+1];
473
474 assert(periph_id >= PERIPH_ID_FIRST && periph_id < PERIPH_ID_COUNT);
475 internal_id = periph_id_to_internal_id[periph_id];
476 assert(internal_id != -1);
477 if (internal_id >= PERIPHC_VW_FIRST) {
478 internal_id -= PERIPHC_VW_FIRST;
479 return &clkrst->crc_clk_src_vw[internal_id];
480 } else
481 return &clkrst->crc_clk_src[internal_id];
482}
483
484/**
485 * Given a peripheral ID and the required source clock, this returns which
486 * value should be programmed into the source mux for that peripheral.
487 *
488 * There is special code here to handle the one source type with 5 sources.
489 *
490 * @param periph_id peripheral to start
491 * @param source PLL id of required parent clock
492 * @param mux_bits Set to number of bits in mux register: 2 or 4
493 * @param divider_bits Set to number of divider bits (8 or 16)
494 * @return mux value (0-4, or -1 if not found)
495 */
496int get_periph_clock_source(enum periph_id periph_id,
497 enum clock_id parent, int *mux_bits, int *divider_bits)
498{
499 enum clock_type_id type;
500 enum periphc_internal_id internal_id;
501 int mux;
502
503 assert(clock_periph_id_isvalid(periph_id));
504
505 internal_id = periph_id_to_internal_id[periph_id];
506 assert(periphc_internal_id_isvalid(internal_id));
507
508 type = clock_periph_type[internal_id];
509 assert(clock_type_id_isvalid(type));
510
511 *mux_bits = clock_source[type][CLOCK_MAX_MUX];
512
513 if (type == CLOCK_TYPE_PCMT16)
514 *divider_bits = 16;
515 else
516 *divider_bits = 8;
517
518 for (mux = 0; mux < CLOCK_MAX_MUX; mux++)
519 if (clock_source[type][mux] == parent)
520 return mux;
521
522 /* if we get here, either us or the caller has made a mistake */
523 printf("Caller requested bad clock: periph=%d, parent=%d\n", periph_id,
524 parent);
525 return -1;
526}
527
528void clock_set_enable(enum periph_id periph_id, int enable)
529{
530 struct clk_rst_ctlr *clkrst =
531 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
532 u32 *clk;
533 u32 reg;
534
535 /* Enable/disable the clock to this peripheral */
536 assert(clock_periph_id_isvalid(periph_id));
537 if ((int)periph_id < (int)PERIPH_ID_VW_FIRST)
538 clk = &clkrst->crc_clk_out_enb[PERIPH_REG(periph_id)];
539 else
540 clk = &clkrst->crc_clk_out_enb_vw[PERIPH_REG(periph_id)];
541 reg = readl(clk);
542 if (enable)
543 reg |= PERIPH_MASK(periph_id);
544 else
545 reg &= ~PERIPH_MASK(periph_id);
546 writel(reg, clk);
547}
548
549void reset_set_enable(enum periph_id periph_id, int enable)
550{
551 struct clk_rst_ctlr *clkrst =
552 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
553 u32 *reset;
554 u32 reg;
555
556 /* Enable/disable reset to the peripheral */
557 assert(clock_periph_id_isvalid(periph_id));
558 if (periph_id < PERIPH_ID_VW_FIRST)
559 reset = &clkrst->crc_rst_dev[PERIPH_REG(periph_id)];
560 else
561 reset = &clkrst->crc_rst_dev_vw[PERIPH_REG(periph_id)];
562 reg = readl(reset);
563 if (enable)
564 reg |= PERIPH_MASK(periph_id);
565 else
566 reg &= ~PERIPH_MASK(periph_id);
567 writel(reg, reset);
568}
569
570#ifdef CONFIG_OF_CONTROL
571/*
572 * Convert a device tree clock ID to our peripheral ID. They are mostly
573 * the same but we are very cautious so we check that a valid clock ID is
574 * provided.
575 *
576 * @param clk_id Clock ID according to tegra114 device tree binding
577 * @return peripheral ID, or PERIPH_ID_NONE if the clock ID is invalid
578 */
579enum periph_id clk_id_to_periph_id(int clk_id)
580{
581 if (clk_id > PERIPH_ID_COUNT)
582 return PERIPH_ID_NONE;
583
584 switch (clk_id) {
585 case PERIPH_ID_RESERVED3:
586 case PERIPH_ID_RESERVED16:
587 case PERIPH_ID_RESERVED24:
588 case PERIPH_ID_RESERVED35:
589 case PERIPH_ID_RESERVED43:
590 case PERIPH_ID_RESERVED45:
591 case PERIPH_ID_RESERVED56:
592 case PERIPH_ID_RESERVED76:
593 case PERIPH_ID_RESERVED77:
594 case PERIPH_ID_RESERVED78:
595 case PERIPH_ID_RESERVED83:
596 case PERIPH_ID_RESERVED89:
597 case PERIPH_ID_RESERVED91:
598 case PERIPH_ID_RESERVED93:
599 case PERIPH_ID_RESERVED94:
600 case PERIPH_ID_RESERVED95:
601 return PERIPH_ID_NONE;
602 default:
603 return clk_id;
604 }
605}
606#endif /* CONFIG_OF_CONTROL */
607
608void clock_early_init(void)
609{
610 struct clk_rst_ctlr *clkrst =
611 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
612
613 /*
614 * PLLP output frequency set to 408Mhz
615 * PLLC output frequency set to 600Mhz
616 * PLLD output frequency set to 925Mhz
617 */
618 switch (clock_get_osc_freq()) {
619 case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
620 clock_set_rate(CLOCK_ID_PERIPH, 408, 12, 0, 8);
621 clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8);
622 clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12);
623 break;
624
625 case CLOCK_OSC_FREQ_26_0: /* OSC is 26Mhz */
626 clock_set_rate(CLOCK_ID_PERIPH, 408, 26, 0, 8);
627 clock_set_rate(CLOCK_ID_CGENERAL, 600, 26, 0, 8);
628 clock_set_rate(CLOCK_ID_DISPLAY, 925, 26, 0, 12);
629 break;
630
631 case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
632 clock_set_rate(CLOCK_ID_PERIPH, 408, 13, 0, 8);
633 clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
634 clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12);
635 break;
636 case CLOCK_OSC_FREQ_19_2:
637 default:
638 /*
639 * These are not supported. It is too early to print a
640 * message and the UART likely won't work anyway due to the
641 * oscillator being wrong.
642 */
643 break;
644 }
645
646 /* PLLC_MISC2: Set dynramp_stepA/B. MISC2 maps to pll_out[1] */
647 writel(0x00561600, &clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_out[1]);
648
649 /* PLLC_MISC: Set LOCK_ENABLE */
650 writel(0x01000000, &clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_misc);
651 udelay(2);
652
653 /* PLLD_MISC: Set CLKENABLE, CPCON 12, LFCON 1 */
654 writel(0x40000C10, &clkrst->crc_pll[CLOCK_ID_DISPLAY].pll_misc);
655 udelay(2);
656}
Tom Warrenfbef3552013-04-01 15:48:54 -0700657
658void arch_timer_init(void)
659{
660 struct sysctr_ctlr *sysctr = (struct sysctr_ctlr *)NV_PA_TSC_BASE;
661 u32 freq, val;
662
663 freq = clock_get_rate(CLOCK_ID_OSC);
664 debug("%s: osc freq is %dHz [0x%08X]\n", __func__, freq, freq);
665
666 /* ARM CNTFRQ */
667 asm("mcr p15, 0, %0, c14, c0, 0\n" : : "r" (freq));
668
669 /* Only T114 has the System Counter regs */
670 debug("%s: setting CNTFID0 to 0x%08X\n", __func__, freq);
671 writel(freq, &sysctr->cntfid0);
672
673 val = readl(&sysctr->cntcr);
674 val |= TSC_CNTCR_ENABLE | TSC_CNTCR_HDBG;
675 writel(val, &sysctr->cntcr);
676 debug("%s: TSC CNTCR = 0x%08X\n", __func__, val);
677}