blob: af4aca5c343aca32029a0280756d35cc6a373a85 [file] [log] [blame]
wdenk4a9cbbe2002-08-27 09:48:53 +00001/*
2 * (C) Copyright 2000-2002
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
wdenk3a473b22004-01-03 00:43:19 +000015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk4a9cbbe2002-08-27 09:48:53 +000016 * 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 <74xx_7xx.h>
26#include <asm/processor.h>
27
wdenkc7de8292002-11-19 11:04:11 +000028#ifdef CONFIG_AMIGAONEG3SE
29#include "../board/MAI/AmigaOneG3SE/via686.h"
30#endif
31
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
33
roy zangee311212006-12-01 11:47:36 +080034extern unsigned long get_board_bus_clk (void);
roy zang4c527832006-11-02 18:49:51 +080035
wdenk4a9cbbe2002-08-27 09:48:53 +000036static const int hid1_multipliers_x_10[] = {
37 25, /* 0000 - 2.5x */
38 75, /* 0001 - 7.5x */
39 70, /* 0010 - 7x */
40 10, /* 0011 - bypass */
41 20, /* 0100 - 2x */
42 65, /* 0101 - 6.5x */
43 100, /* 0110 - 10x */
44 45, /* 0111 - 4.5x */
45 30, /* 1000 - 3x */
46 55, /* 1001 - 5.5x */
47 40, /* 1010 - 4x */
48 50, /* 1011 - 5x */
49 80, /* 1100 - 8x */
50 60, /* 1101 - 6x */
51 35, /* 1110 - 3.5x */
52 0 /* 1111 - off */
53};
54
roy zang4c527832006-11-02 18:49:51 +080055static const int hid1_7447A_multipliers_x_10[] = {
roy zangee311212006-12-01 11:47:36 +080056 115, /* 00000 - 11.5x */
57 170, /* 00001 - 17x */
58 75, /* 00010 - 7.5x */
59 150, /* 00011 - 15x */
60 70, /* 00100 - 7x */
61 180, /* 00101 - 18x */
62 10, /* 00110 - bypass */
63 200, /* 00111 - 20x */
64 20, /* 01000 - 2x */
65 210, /* 01001 - 21x */
66 65, /* 01010 - 6.5x */
67 130, /* 01011 - 13x */
68 85, /* 01100 - 8.5x */
69 240, /* 01101 - 13x */
70 95, /* 01110 - 9.5x */
71 90, /* 01111 - 9x */
72 30, /* 10000 - 3x */
73 105, /* 10001 - 10.5x */
74 55, /* 10010 - 5.5x */
75 110, /* 10011 - 11x */
76 40, /* 10100 - 4x */
77 100, /* 10101 - 10x */
78 50, /* 10110 - 5x */
79 120, /* 10111 - 12x */
80 80, /* 11000 - 8x */
81 140, /* 11001 - 14x */
82 60, /* 11010 - 6x */
83 160, /* 11011 - 16x */
84 135, /* 11100 - 13.5x */
85 280, /* 11101 - 28x */
86 0, /* 11110 - off */
87 125 /* 11111 - 12.5x */
roy zang4c527832006-11-02 18:49:51 +080088};
89
wdenk72755c72003-06-20 23:10:58 +000090static const int hid1_fx_multipliers_x_10[] = {
wdenk3a473b22004-01-03 00:43:19 +000091 00, /* 0000 - off */
92 00, /* 0001 - off */
93 10, /* 0010 - bypass */
94 10, /* 0011 - bypass */
95 20, /* 0100 - 2x */
96 25, /* 0101 - 2.5x */
97 30, /* 0110 - 3x */
98 35, /* 0111 - 3.5x */
99 40, /* 1000 - 4x */
100 45, /* 1001 - 4.5x */
101 50, /* 1010 - 5x */
102 55, /* 1011 - 5.5x */
103 60, /* 1100 - 6x */
104 65, /* 1101 - 6.5x */
105 70, /* 1110 - 7x */
106 75, /* 1111 - 7.5 */
107 80, /* 10000 - 8x */
108 85, /* 10001 - 8.5x */
109 90, /* 10010 - 9x */
110 95, /* 10011 - 9.5x */
111 100, /* 10100 - 10x */
112 110, /* 10101 - 11x */
113 120, /* 10110 - 12x */
wdenk72755c72003-06-20 23:10:58 +0000114};
115
116
wdenk4a9cbbe2002-08-27 09:48:53 +0000117/* ------------------------------------------------------------------------- */
118
119/*
120 * Measure CPU clock speed (core clock GCLK1, GCLK2)
121 *
122 * (Approx. GCLK frequency in Hz)
123 */
124
125int get_clocks (void)
126{
wdenk3a473b22004-01-03 00:43:19 +0000127 ulong clock = 0;
128
roy zang4c527832006-11-02 18:49:51 +0800129#ifdef CFG_CONFIG_BUS_CLK
roy zangee311212006-12-01 11:47:36 +0800130 gd->bus_clk = get_board_bus_clk (); /* bus clock is configurable */
roy zang4c527832006-11-02 18:49:51 +0800131#else
roy zangee311212006-12-01 11:47:36 +0800132 gd->bus_clk = CFG_BUS_CLK; /* bus clock is a fixed frequency */
roy zang4c527832006-11-02 18:49:51 +0800133#endif
134
wdenk3a473b22004-01-03 00:43:19 +0000135 /* calculate the clock frequency based upon the CPU type */
136 switch (get_cpu_type()) {
roy zang4c527832006-11-02 18:49:51 +0800137 case CPU_7447A:
138 case CPU_7448:
roy zangee311212006-12-01 11:47:36 +0800139 clock = (gd->bus_clk / 10) *
140 hid1_7447A_multipliers_x_10[(get_hid1 () >> 12) & 0x1F];
roy zang4c527832006-11-02 18:49:51 +0800141 break;
142
wdenk3a473b22004-01-03 00:43:19 +0000143 case CPU_7455:
144 case CPU_7457:
145 /*
146 * It is assumed that the PLL_EXT line is zero.
147 * Make sure division is done before multiplication to prevent 32-bit
148 * arithmetic overflows which will cause a negative number
149 */
roy zangee311212006-12-01 11:47:36 +0800150 clock = (gd->bus_clk / 10) *
151 hid1_multipliers_x_10[(get_hid1 () >> 13) & 0xF];
wdenk3a473b22004-01-03 00:43:19 +0000152 break;
153
154 case CPU_750GX:
155 case CPU_750FX:
roy zangee311212006-12-01 11:47:36 +0800156 clock = gd->bus_clk *
157 hid1_fx_multipliers_x_10[get_hid1 () >> 27] / 10;
wdenk3a473b22004-01-03 00:43:19 +0000158 break;
159
160 case CPU_7450:
161 case CPU_740:
162 case CPU_740P:
163 case CPU_745:
164 case CPU_750CX:
165 case CPU_750:
166 case CPU_750P:
167 case CPU_755:
168 case CPU_7400:
169 case CPU_7410:
170 /*
171 * Make sure division is done before multiplication to prevent 32-bit
172 * arithmetic overflows which will cause a negative number
173 */
roy zangee311212006-12-01 11:47:36 +0800174 clock = (gd->bus_clk / 10) *
175 hid1_multipliers_x_10[get_hid1 () >> 28];
wdenk3a473b22004-01-03 00:43:19 +0000176 break;
177
178 case CPU_UNKNOWN:
179 printf ("get_gclk_freq(): unknown CPU type\n");
180 clock = 0;
181 return (1);
182 }
183
wdenk4a9cbbe2002-08-27 09:48:53 +0000184 gd->cpu_clk = clock;
wdenk4a9cbbe2002-08-27 09:48:53 +0000185
186 return (0);
187}
188
189/* ------------------------------------------------------------------------- */