]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/mips/cpu/mips32/incaip/incaip_clock.c
karo: tx51: justify and adjust the delay required before releasing the ETN PHY strap...
[karo-tx-uboot.git] / arch / mips / cpu / mips32 / incaip / incaip_clock.c
1 /*
2  * (C) Copyright 2003
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <asm/inca-ip.h>
10
11
12 /*******************************************************************************
13 *
14 * get_cpuclk - returns the frequency of the CPU.
15 *
16 * Gets the value directly from the INCA-IP hardware.
17 *
18 * RETURNS:
19 *          150.000.000 for 150 MHz
20 *          133.333.333 for 133 MHz (= 400MHz/3)
21 *          100.000.000 for 100 MHz (= 400MHz/4)
22 * NOTE:
23 *   This functions should be used by the hardware driver to get the correct
24 *   frequency of the CPU. Don't use the macros, which are set to init the CPU
25 *   frequency in the ROM code.
26 */
27 uint incaip_get_cpuclk (void)
28 {
29         /*-------------------------------------------------------------------------*/
30         /* CPU Clock Input Multiplexer (MUX I)                                     */
31         /* Multiplexer MUX I selects the maximum input clock to the CPU.           */
32         /*-------------------------------------------------------------------------*/
33         if (*((volatile ulong *) INCA_IP_CGU_CGU_MUXCR) &
34             INCA_IP_CGU_CGU_MUXCR_MUXI) {
35                 /* MUX I set to 150 MHz clock */
36                 return 150000000;
37         } else {
38                 /* MUX I set to 100/133 MHz clock */
39                 if (*((volatile ulong *) INCA_IP_CGU_CGU_DIVCR) & 0x40) {
40                         /* Division value is 1/3, maximum CPU operating */
41                         /* frequency is 133.3 MHz                       */
42                         return 133333333;
43                 } else {
44                         /* Division value is 1/4, maximum CPU operating */
45                         /* frequency is 100 MHz                         */
46                         return 100000000;
47                 }
48         }
49 }
50
51 /*******************************************************************************
52 *
53 * get_fpiclk - returns the frequency of the FPI bus.
54 *
55 * Gets the value directly from the INCA-IP hardware.
56 *
57 * RETURNS: Frquency in Hz
58 *
59 * NOTE:
60 *   This functions should be used by the hardware driver to get the correct
61 *   frequency of the CPU. Don't use the macros, which are set to init the CPU
62 *   frequency in the ROM code.
63 *   The calculation for the
64 */
65 uint incaip_get_fpiclk (void)
66 {
67         uint clkCPU;
68
69         clkCPU = incaip_get_cpuclk ();
70
71         switch (*((volatile ulong *) INCA_IP_CGU_CGU_DIVCR) & 0xC) {
72         case 0x4:
73                 return clkCPU >> 1;     /* devided by 2 */
74                 break;
75         case 0x8:
76                 return clkCPU >> 2;     /* devided by 4 */
77                 break;
78         default:
79                 return clkCPU;
80                 break;
81         }
82 }
83
84 int incaip_set_cpuclk (void)
85 {
86         extern void ebu_init(long);
87         extern void cgu_init(long);
88         extern void sdram_init(long);
89         char tmp[64];
90         ulong cpuclk;
91
92         if (getenv_f("cpuclk", tmp, sizeof (tmp)) > 0) {
93                 cpuclk = simple_strtoul (tmp, NULL, 10) * 1000000;
94                 cgu_init (cpuclk);
95                 ebu_init (cpuclk);
96                 sdram_init (cpuclk);
97         }
98
99         return 0;
100 }