blob: 7e884f8e0142334c96bf15996199d1f6d75d2a76 [file] [log] [blame]
Jon Loeligerdebb7352006-04-26 17:58:56 -05001/*
2 * Copyright 2004 Freescale Semiconductor.
Jon Loeligerc934f652006-05-31 13:55:35 -05003 * Jeff Brown
Jon Loeligerdebb7352006-04-26 17:58:56 -05004 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
5 *
6 * (C) Copyright 2000-2002
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <mpc86xx.h>
30#include <asm/processor.h>
31
Wolfgang Denk1218abf2007-09-15 20:48:41 +020032DECLARE_GLOBAL_DATA_PTR;
Jon Loeligerdebb7352006-04-26 17:58:56 -050033
Wolfgang Denk409ecdc2007-11-18 16:36:27 +010034/* used in some defintiions of CONFIG_SYS_CLK_FREQ */
35extern unsigned long get_board_sys_clk(unsigned long dummy);
36
Jon Loeligerffff3ae2006-08-22 12:06:18 -050037void get_sys_info(sys_info_t *sysInfo)
Jon Loeligerdebb7352006-04-26 17:58:56 -050038{
Jon Loeligerffff3ae2006-08-22 12:06:18 -050039 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Jon Loeligerdebb7352006-04-26 17:58:56 -050040 volatile ccsr_gur_t *gur = &immap->im_gur;
41 uint plat_ratio, e600_ratio;
42
Jon Loeligerc934f652006-05-31 13:55:35 -050043 plat_ratio = (gur->porpllsr) & 0x0000003e;
Jon Loeligerdebb7352006-04-26 17:58:56 -050044 plat_ratio >>= 1;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050045
Jon Loeligerffff3ae2006-08-22 12:06:18 -050046 switch (plat_ratio) {
Jon Loeligerc934f652006-05-31 13:55:35 -050047 case 0x0:
Jon Loeligerdebb7352006-04-26 17:58:56 -050048 sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
49 break;
50 case 0x02:
51 case 0x03:
52 case 0x04:
53 case 0x05:
54 case 0x06:
55 case 0x08:
56 case 0x09:
57 case 0x0a:
58 case 0x0c:
Jon Loeligerc934f652006-05-31 13:55:35 -050059 case 0x10:
60 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
61 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050062 default:
Jon Loeligerffff3ae2006-08-22 12:06:18 -050063 sysInfo->freqSystemBus = 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -050064 break;
65 }
66
Jon Loeligerdebb7352006-04-26 17:58:56 -050067 e600_ratio = (gur->porpllsr) & 0x003f0000;
68 e600_ratio >>= 16;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050069
70 switch (e600_ratio) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050071 case 0x10:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050072 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050073 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050074 case 0x19:
Jon Loeligerffff3ae2006-08-22 12:06:18 -050075 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050076 break;
77 case 0x20:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050078 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050079 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050080 case 0x39:
Jon Loeligerffff3ae2006-08-22 12:06:18 -050081 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050082 break;
83 case 0x28:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050084 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050085 break;
86 case 0x1d:
Jon Loeligerffff3ae2006-08-22 12:06:18 -050087 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050088 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050089 default:
Jon Loeliger5c9efb32006-04-27 10:15:16 -050090 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050091 break;
92 }
Jon Loeligerdebb7352006-04-26 17:58:56 -050093}
94
95
Jon Loeligerdebb7352006-04-26 17:58:56 -050096/*
97 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeligerdebb7352006-04-26 17:58:56 -050098 * (Approx. GCLK frequency in Hz)
99 */
100
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500101int get_clocks(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500102{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500103 sys_info_t sys_info;
104
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500105 get_sys_info(&sys_info);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500106 gd->cpu_clk = sys_info.freqProcessor;
107 gd->bus_clk = sys_info.freqSystemBus;
Timur Tabi943afa22008-01-09 14:35:26 -0600108 gd->i2c1_clk = sys_info.freqSystemBus;
109 gd->i2c2_clk = sys_info.freqSystemBus;
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500110
111 if (gd->cpu_clk != 0)
112 return 0;
113 else
114 return 1;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500115}
116
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500117
118/*
Jon Loeligerdebb7352006-04-26 17:58:56 -0500119 * get_bus_freq
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500120 * Return system bus freq in Hz
121 */
Jon Loeligerc934f652006-05-31 13:55:35 -0500122
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500123ulong get_bus_freq(ulong dummy)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500124{
125 ulong val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500126 sys_info_t sys_info;
127
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500128 get_sys_info(&sys_info);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500129 val = sys_info.freqSystemBus;
130
131 return val;
132}