wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <asm/inca-ip.h> |
| 26 | |
| 27 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 28 | /******************************************************************************* |
| 29 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 30 | * get_cpuclk - returns the frequency of the CPU. |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 31 | * |
| 32 | * Gets the value directly from the INCA-IP hardware. |
| 33 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 34 | * RETURNS: |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 35 | * 150.000.000 for 150 MHz |
wdenk | 398eeff | 2004-01-21 20:46:28 +0000 | [diff] [blame] | 36 | * 133.333.333 for 133 Mhz (= 400MHz/3) |
| 37 | * 100.000.000 for 100 Mhz (= 400MHz/4) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 38 | * NOTE: |
| 39 | * This functions should be used by the hardware driver to get the correct |
| 40 | * frequency of the CPU. Don't use the macros, which are set to init the CPU |
| 41 | * frequency in the ROM code. |
| 42 | */ |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 43 | uint incaip_get_cpuclk (void) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 44 | { |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 45 | /*-------------------------------------------------------------------------*/ |
| 46 | /* CPU Clock Input Multiplexer (MUX I) */ |
| 47 | /* Multiplexer MUX I selects the maximum input clock to the CPU. */ |
| 48 | /*-------------------------------------------------------------------------*/ |
| 49 | if (*((volatile ulong *) INCA_IP_CGU_CGU_MUXCR) & |
| 50 | INCA_IP_CGU_CGU_MUXCR_MUXI) { |
| 51 | /* MUX I set to 150 MHz clock */ |
| 52 | return 150000000; |
| 53 | } else { |
| 54 | /* MUX I set to 100/133 MHz clock */ |
| 55 | if (*((volatile ulong *) INCA_IP_CGU_CGU_DIVCR) & 0x40) { |
| 56 | /* Division value is 1/3, maximum CPU operating */ |
| 57 | /* frequency is 133.3 MHz */ |
wdenk | 398eeff | 2004-01-21 20:46:28 +0000 | [diff] [blame] | 58 | return 133333333; |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 59 | } else { |
| 60 | /* Division value is 1/4, maximum CPU operating */ |
| 61 | /* frequency is 100 MHz */ |
| 62 | return 100000000; |
| 63 | } |
| 64 | } |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /******************************************************************************* |
| 68 | * |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 69 | * get_fpiclk - returns the frequency of the FPI bus. |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 70 | * |
| 71 | * Gets the value directly from the INCA-IP hardware. |
| 72 | * |
| 73 | * RETURNS: Frquency in Hz |
| 74 | * |
| 75 | * NOTE: |
| 76 | * This functions should be used by the hardware driver to get the correct |
| 77 | * frequency of the CPU. Don't use the macros, which are set to init the CPU |
| 78 | * frequency in the ROM code. |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 79 | * The calculation for the |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 80 | */ |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 81 | uint incaip_get_fpiclk (void) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 82 | { |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 83 | uint clkCPU; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 84 | |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 85 | clkCPU = incaip_get_cpuclk (); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 87 | switch (*((volatile ulong *) INCA_IP_CGU_CGU_DIVCR) & 0xC) { |
| 88 | case 0x4: |
| 89 | return clkCPU >> 1; /* devided by 2 */ |
| 90 | break; |
| 91 | case 0x8: |
| 92 | return clkCPU >> 2; /* devided by 4 */ |
| 93 | break; |
| 94 | default: |
| 95 | return clkCPU; |
| 96 | break; |
| 97 | } |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 98 | } |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 99 | |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 100 | int incaip_set_cpuclk (void) |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 101 | { |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 102 | extern void ebu_init(long); |
| 103 | extern void cgu_init(long); |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 104 | extern void sdram_init(long); |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 105 | uchar tmp[64]; |
| 106 | ulong cpuclk; |
| 107 | |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 108 | if (getenv_r ("cpuclk", tmp, sizeof (tmp)) > 0) { |
| 109 | cpuclk = simple_strtoul (tmp, NULL, 10) * 1000000; |
wdenk | aeae3a1 | 2003-12-27 19:29:48 +0000 | [diff] [blame] | 110 | cgu_init (cpuclk); |
wdenk | 433feff | 2004-01-29 09:22:58 +0000 | [diff] [blame] | 111 | ebu_init (cpuclk); |
| 112 | sdram_init (cpuclk); |
wdenk | 67f1336 | 2003-12-27 19:24:54 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |