blob: 51b47b823bd6d68bab9bdd81a5c0dae3aa5d2f4f [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 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02009 * SPDX-License-Identifier: GPL-2.0+
Jon Loeligerdebb7352006-04-26 17:58:56 -050010 */
11
12#include <common.h>
13#include <mpc86xx.h>
14#include <asm/processor.h>
Trent Piephoada591d2008-12-03 15:16:37 -080015#include <asm/io.h>
Jon Loeligerdebb7352006-04-26 17:58:56 -050016
Wolfgang Denk1218abf2007-09-15 20:48:41 +020017DECLARE_GLOBAL_DATA_PTR;
Jon Loeligerdebb7352006-04-26 17:58:56 -050018
Wolfgang Denk409ecdc2007-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
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053022void get_sys_info(sys_info_t *sys_info)
Jon Loeligerdebb7352006-04-26 17:58:56 -050023{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020024 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeligerdebb7352006-04-26 17:58:56 -050025 volatile ccsr_gur_t *gur = &immap->im_gur;
26 uint plat_ratio, e600_ratio;
27
Jon Loeligerc934f652006-05-31 13:55:35 -050028 plat_ratio = (gur->porpllsr) & 0x0000003e;
Jon Loeligerdebb7352006-04-26 17:58:56 -050029 plat_ratio >>= 1;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050030
Jon Loeligerffff3ae2006-08-22 12:06:18 -050031 switch (plat_ratio) {
Jon Loeligerc934f652006-05-31 13:55:35 -050032 case 0x0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053033 sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ;
Jon Loeligerdebb7352006-04-26 17:58:56 -050034 break;
35 case 0x02:
36 case 0x03:
37 case 0x04:
38 case 0x05:
39 case 0x06:
40 case 0x08:
41 case 0x09:
42 case 0x0a:
43 case 0x0c:
Jon Loeligerc934f652006-05-31 13:55:35 -050044 case 0x10:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053045 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Jon Loeligerc934f652006-05-31 13:55:35 -050046 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050047 default:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053048 sys_info->freq_systembus = 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -050049 break;
50 }
51
Jon Loeligerdebb7352006-04-26 17:58:56 -050052 e600_ratio = (gur->porpllsr) & 0x003f0000;
53 e600_ratio >>= 16;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050054
55 switch (e600_ratio) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050056 case 0x10:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053057 sys_info->freq_processor = 2 * sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050058 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050059 case 0x19:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053060 sys_info->freq_processor = 5 * sys_info->freq_systembus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050061 break;
62 case 0x20:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053063 sys_info->freq_processor = 3 * sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050064 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050065 case 0x39:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053066 sys_info->freq_processor = 7 * sys_info->freq_systembus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050067 break;
68 case 0x28:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053069 sys_info->freq_processor = 4 * sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050070 break;
71 case 0x1d:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053072 sys_info->freq_processor = 9 * sys_info->freq_systembus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050073 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050074 default:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053075 sys_info->freq_processor = e600_ratio +
76 sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050077 break;
78 }
Trent Piephoada591d2008-12-03 15:16:37 -080079
Prabhakar Kushwahaadd63f92017-02-02 15:02:00 +053080 sys_info->freq_localbus = sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050081}
82
83
Jon Loeligerdebb7352006-04-26 17:58:56 -050084/*
85 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeligerdebb7352006-04-26 17:58:56 -050086 * (Approx. GCLK frequency in Hz)
87 */
88
Jon Loeliger5c9efb32006-04-27 10:15:16 -050089int get_clocks(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -050090{
Jon Loeligerdebb7352006-04-26 17:58:56 -050091 sys_info_t sys_info;
92
Jon Loeliger5c9efb32006-04-27 10:15:16 -050093 get_sys_info(&sys_info);
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053094 gd->cpu_clk = sys_info.freq_processor;
95 gd->bus_clk = sys_info.freq_systembus;
96 gd->arch.lbc_clk = sys_info.freq_localbus;
Timur Tabi1b9ed252008-04-04 11:16:11 -050097
98 /*
99 * The base clock for I2C depends on the actual SOC. Unfortunately,
100 * there is no pattern that can be used to determine the frequency, so
101 * the only choice is to look up the actual SOC number and use the value
102 * for that SOC. This information is taken from application note
103 * AN2919.
104 */
York Sun1425a872016-11-23 14:06:21 -0800105#ifdef CONFIG_ARCH_MPC8610
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530106 gd->arch.i2c1_clk = sys_info.freq_systembus;
Timur Tabi1b9ed252008-04-04 11:16:11 -0500107#else
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530108 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi1b9ed252008-04-04 11:16:11 -0500109#endif
Simon Glass609e6ec2012-12-13 20:48:49 +0000110 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500111
112 if (gd->cpu_clk != 0)
113 return 0;
114 else
115 return 1;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500116}
117
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500118
119/*
Jon Loeligerdebb7352006-04-26 17:58:56 -0500120 * get_bus_freq
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500121 * Return system bus freq in Hz
122 */
Jon Loeligerc934f652006-05-31 13:55:35 -0500123
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500124ulong get_bus_freq(ulong dummy)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500125{
126 ulong val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500127 sys_info_t sys_info;
128
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500129 get_sys_info(&sys_info);
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530130 val = sys_info.freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500131
132 return val;
133}