blob: 64a3479d7e51dc56fd52c194b98c91b7833ed1f9 [file] [log] [blame]
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001/*
2 * Copyright 2004 Freescale Semiconductor.
Jon Loeliger8827a732006-05-31 13:55:35 -05003 * Jeff Brown
Jon Loeliger5c8aa972006-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>
Trent Piepho0b691fc2008-12-03 15:16:37 -080031#include <asm/io.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050032
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020033DECLARE_GLOBAL_DATA_PTR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050034
Wolfgang Denk92254112007-11-18 16:36:27 +010035/* used in some defintiions of CONFIG_SYS_CLK_FREQ */
36extern unsigned long get_board_sys_clk(unsigned long dummy);
37
Jon Loeligera1295442006-08-22 12:06:18 -050038void get_sys_info(sys_info_t *sysInfo)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050039{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050041 volatile ccsr_gur_t *gur = &immap->im_gur;
42 uint plat_ratio, e600_ratio;
Trent Piepho0b691fc2008-12-03 15:16:37 -080043 uint lcrr_div;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050044
Jon Loeliger8827a732006-05-31 13:55:35 -050045 plat_ratio = (gur->porpllsr) & 0x0000003e;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050046 plat_ratio >>= 1;
Jon Loeliger465b9d82006-04-27 10:15:16 -050047
Jon Loeligera1295442006-08-22 12:06:18 -050048 switch (plat_ratio) {
Jon Loeliger8827a732006-05-31 13:55:35 -050049 case 0x0:
Jon Loeliger5c8aa972006-04-26 17:58:56 -050050 sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
51 break;
52 case 0x02:
53 case 0x03:
54 case 0x04:
55 case 0x05:
56 case 0x06:
57 case 0x08:
58 case 0x09:
59 case 0x0a:
60 case 0x0c:
Jon Loeliger8827a732006-05-31 13:55:35 -050061 case 0x10:
62 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
63 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050064 default:
Jon Loeligera1295442006-08-22 12:06:18 -050065 sysInfo->freqSystemBus = 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050066 break;
67 }
68
Jon Loeliger5c8aa972006-04-26 17:58:56 -050069 e600_ratio = (gur->porpllsr) & 0x003f0000;
70 e600_ratio >>= 16;
Jon Loeliger465b9d82006-04-27 10:15:16 -050071
72 switch (e600_ratio) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -050073 case 0x10:
Jon Loeliger465b9d82006-04-27 10:15:16 -050074 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050075 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050076 case 0x19:
Jon Loeligera1295442006-08-22 12:06:18 -050077 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050078 break;
79 case 0x20:
Jon Loeliger465b9d82006-04-27 10:15:16 -050080 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050081 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050082 case 0x39:
Jon Loeligera1295442006-08-22 12:06:18 -050083 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050084 break;
85 case 0x28:
Jon Loeliger465b9d82006-04-27 10:15:16 -050086 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050087 break;
88 case 0x1d:
Jon Loeligera1295442006-08-22 12:06:18 -050089 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050090 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050091 default:
Jon Loeliger465b9d82006-04-27 10:15:16 -050092 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050093 break;
94 }
Trent Piepho0b691fc2008-12-03 15:16:37 -080095
96#if defined(CONFIG_SYS_LBC_LCRR)
97 /* We will program LCRR to this value later */
98 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
99#else
100 {
101 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
102 lcrr_div = in_be32(&lbc->lcrr) & LCRR_CLKDIV;
103 }
104#endif
105 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
106 sysInfo->freqLocalBus = sysInfo->freqSystemBus / (lcrr_div * 2);
107 } else {
108 /* In case anyone cares what the unknown value is */
109 sysInfo->freqLocalBus = lcrr_div;
110 }
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500111}
112
113
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500114/*
115 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500116 * (Approx. GCLK frequency in Hz)
117 */
118
Jon Loeliger465b9d82006-04-27 10:15:16 -0500119int get_clocks(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500120{
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500121 sys_info_t sys_info;
122
Jon Loeliger465b9d82006-04-27 10:15:16 -0500123 get_sys_info(&sys_info);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500124 gd->cpu_clk = sys_info.freqProcessor;
125 gd->bus_clk = sys_info.freqSystemBus;
Trent Piepho0b691fc2008-12-03 15:16:37 -0800126 gd->lbc_clk = sys_info.freqLocalBus;
Timur Tabid93136b2008-04-04 11:16:11 -0500127
128 /*
129 * The base clock for I2C depends on the actual SOC. Unfortunately,
130 * there is no pattern that can be used to determine the frequency, so
131 * the only choice is to look up the actual SOC number and use the value
132 * for that SOC. This information is taken from application note
133 * AN2919.
134 */
135#ifdef CONFIG_MPC8610
Timur Tabic1499f482008-01-09 14:35:26 -0600136 gd->i2c1_clk = sys_info.freqSystemBus;
Timur Tabid93136b2008-04-04 11:16:11 -0500137#else
138 gd->i2c1_clk = sys_info.freqSystemBus / 2;
139#endif
140 gd->i2c2_clk = gd->i2c1_clk;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500141
142 if (gd->cpu_clk != 0)
143 return 0;
144 else
145 return 1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500146}
147
Jon Loeliger465b9d82006-04-27 10:15:16 -0500148
149/*
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500150 * get_bus_freq
Jon Loeliger465b9d82006-04-27 10:15:16 -0500151 * Return system bus freq in Hz
152 */
Jon Loeliger8827a732006-05-31 13:55:35 -0500153
Jon Loeliger465b9d82006-04-27 10:15:16 -0500154ulong get_bus_freq(ulong dummy)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500155{
156 ulong val;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500157 sys_info_t sys_info;
158
Jon Loeliger465b9d82006-04-27 10:15:16 -0500159 get_sys_info(&sys_info);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500160 val = sys_info.freqSystemBus;
161
162 return val;
163}