blob: ea366ab9e4c18dd7163ad1e2a681a434e67c8823 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Jon Loeliger5c8aa972006-04-26 17:58:56 -050010 */
11
12#include <common.h>
13#include <mpc86xx.h>
14#include <asm/processor.h>
Trent Piepho0b691fc2008-12-03 15:16:37 -080015#include <asm/io.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050016
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020017DECLARE_GLOBAL_DATA_PTR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050018
Wolfgang Denk92254112007-11-18 16:36:27 +010019/* used in some defintiions of CONFIG_SYS_CLK_FREQ */
20extern unsigned long get_board_sys_clk(unsigned long dummy);
21
Jon Loeligera1295442006-08-22 12:06:18 -050022void get_sys_info(sys_info_t *sysInfo)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050023{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020024 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050025 volatile ccsr_gur_t *gur = &immap->im_gur;
26 uint plat_ratio, e600_ratio;
Trent Piepho0b691fc2008-12-03 15:16:37 -080027 uint lcrr_div;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050028
Jon Loeliger8827a732006-05-31 13:55:35 -050029 plat_ratio = (gur->porpllsr) & 0x0000003e;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050030 plat_ratio >>= 1;
Jon Loeliger465b9d82006-04-27 10:15:16 -050031
Jon Loeligera1295442006-08-22 12:06:18 -050032 switch (plat_ratio) {
Jon Loeliger8827a732006-05-31 13:55:35 -050033 case 0x0:
Jon Loeliger5c8aa972006-04-26 17:58:56 -050034 sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
35 break;
36 case 0x02:
37 case 0x03:
38 case 0x04:
39 case 0x05:
40 case 0x06:
41 case 0x08:
42 case 0x09:
43 case 0x0a:
44 case 0x0c:
Jon Loeliger8827a732006-05-31 13:55:35 -050045 case 0x10:
46 sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
47 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050048 default:
Jon Loeligera1295442006-08-22 12:06:18 -050049 sysInfo->freqSystemBus = 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050050 break;
51 }
52
Jon Loeliger5c8aa972006-04-26 17:58:56 -050053 e600_ratio = (gur->porpllsr) & 0x003f0000;
54 e600_ratio >>= 16;
Jon Loeliger465b9d82006-04-27 10:15:16 -050055
56 switch (e600_ratio) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -050057 case 0x10:
Jon Loeliger465b9d82006-04-27 10:15:16 -050058 sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050059 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050060 case 0x19:
Jon Loeligera1295442006-08-22 12:06:18 -050061 sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050062 break;
63 case 0x20:
Jon Loeliger465b9d82006-04-27 10:15:16 -050064 sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050065 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050066 case 0x39:
Jon Loeligera1295442006-08-22 12:06:18 -050067 sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050068 break;
69 case 0x28:
Jon Loeliger465b9d82006-04-27 10:15:16 -050070 sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050071 break;
72 case 0x1d:
Jon Loeligera1295442006-08-22 12:06:18 -050073 sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050074 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050075 default:
Jon Loeliger465b9d82006-04-27 10:15:16 -050076 sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050077 break;
78 }
Trent Piepho0b691fc2008-12-03 15:16:37 -080079
80#if defined(CONFIG_SYS_LBC_LCRR)
81 /* We will program LCRR to this value later */
82 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
83#else
Becky Bruce0d4cee12010-06-17 11:37:20 -050084 lcrr_div = in_be32(&immap->im_lbc.lcrr) & LCRR_CLKDIV;
Trent Piepho0b691fc2008-12-03 15:16:37 -080085#endif
86 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
87 sysInfo->freqLocalBus = sysInfo->freqSystemBus / (lcrr_div * 2);
88 } else {
89 /* In case anyone cares what the unknown value is */
90 sysInfo->freqLocalBus = lcrr_div;
91 }
Jon Loeliger5c8aa972006-04-26 17:58:56 -050092}
93
94
Jon Loeliger5c8aa972006-04-26 17:58:56 -050095/*
96 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050097 * (Approx. GCLK frequency in Hz)
98 */
99
Jon Loeliger465b9d82006-04-27 10:15:16 -0500100int get_clocks(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500101{
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500102 sys_info_t sys_info;
103
Jon Loeliger465b9d82006-04-27 10:15:16 -0500104 get_sys_info(&sys_info);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500105 gd->cpu_clk = sys_info.freqProcessor;
106 gd->bus_clk = sys_info.freqSystemBus;
Simon Glassa8b57392012-12-13 20:48:48 +0000107 gd->arch.lbc_clk = sys_info.freqLocalBus;
Timur Tabid93136b2008-04-04 11:16:11 -0500108
109 /*
110 * The base clock for I2C depends on the actual SOC. Unfortunately,
111 * there is no pattern that can be used to determine the frequency, so
112 * the only choice is to look up the actual SOC number and use the value
113 * for that SOC. This information is taken from application note
114 * AN2919.
115 */
116#ifdef CONFIG_MPC8610
Simon Glassc2baaec2012-12-13 20:48:49 +0000117 gd->arch.i2c1_clk = sys_info.freqSystemBus;
Timur Tabid93136b2008-04-04 11:16:11 -0500118#else
Simon Glassc2baaec2012-12-13 20:48:49 +0000119 gd->arch.i2c1_clk = sys_info.freqSystemBus / 2;
Timur Tabid93136b2008-04-04 11:16:11 -0500120#endif
Simon Glassc2baaec2012-12-13 20:48:49 +0000121 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500122
123 if (gd->cpu_clk != 0)
124 return 0;
125 else
126 return 1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500127}
128
Jon Loeliger465b9d82006-04-27 10:15:16 -0500129
130/*
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500131 * get_bus_freq
Jon Loeliger465b9d82006-04-27 10:15:16 -0500132 * Return system bus freq in Hz
133 */
Jon Loeliger8827a732006-05-31 13:55:35 -0500134
Jon Loeliger465b9d82006-04-27 10:15:16 -0500135ulong get_bus_freq(ulong dummy)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500136{
137 ulong val;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500138 sys_info_t sys_info;
139
Jon Loeliger465b9d82006-04-27 10:15:16 -0500140 get_sys_info(&sys_info);
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500141 val = sys_info.freqSystemBus;
142
143 return val;
144}