blob: 05f23db457884edca6c05aee6b0a15f55ed6de76 [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;
Trent Piephoada591d2008-12-03 15:16:37 -080027 uint lcrr_div;
Jon Loeligerdebb7352006-04-26 17:58:56 -050028
Jon Loeligerc934f652006-05-31 13:55:35 -050029 plat_ratio = (gur->porpllsr) & 0x0000003e;
Jon Loeligerdebb7352006-04-26 17:58:56 -050030 plat_ratio >>= 1;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050031
Jon Loeligerffff3ae2006-08-22 12:06:18 -050032 switch (plat_ratio) {
Jon Loeligerc934f652006-05-31 13:55:35 -050033 case 0x0:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053034 sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ;
Jon Loeligerdebb7352006-04-26 17:58:56 -050035 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 Loeligerc934f652006-05-31 13:55:35 -050045 case 0x10:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053046 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Jon Loeligerc934f652006-05-31 13:55:35 -050047 break;
Jon Loeligerdebb7352006-04-26 17:58:56 -050048 default:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053049 sys_info->freq_systembus = 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -050050 break;
51 }
52
Jon Loeligerdebb7352006-04-26 17:58:56 -050053 e600_ratio = (gur->porpllsr) & 0x003f0000;
54 e600_ratio >>= 16;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050055
56 switch (e600_ratio) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050057 case 0x10:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053058 sys_info->freq_processor = 2 * sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050059 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050060 case 0x19:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053061 sys_info->freq_processor = 5 * sys_info->freq_systembus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050062 break;
63 case 0x20:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053064 sys_info->freq_processor = 3 * sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050065 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050066 case 0x39:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053067 sys_info->freq_processor = 7 * sys_info->freq_systembus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050068 break;
69 case 0x28:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053070 sys_info->freq_processor = 4 * sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050071 break;
72 case 0x1d:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053073 sys_info->freq_processor = 9 * sys_info->freq_systembus / 2;
Jon Loeligerdebb7352006-04-26 17:58:56 -050074 break;
Jon Loeligerc934f652006-05-31 13:55:35 -050075 default:
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053076 sys_info->freq_processor = e600_ratio +
77 sys_info->freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -050078 break;
79 }
Trent Piephoada591d2008-12-03 15:16:37 -080080
81#if defined(CONFIG_SYS_LBC_LCRR)
82 /* We will program LCRR to this value later */
83 lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
84#else
Becky Brucef51cdaf2010-06-17 11:37:20 -050085 lcrr_div = in_be32(&immap->im_lbc.lcrr) & LCRR_CLKDIV;
Trent Piephoada591d2008-12-03 15:16:37 -080086#endif
87 if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053088 sys_info->freq_localbus = sys_info->freq_systembus
89 / (lcrr_div * 2);
Trent Piephoada591d2008-12-03 15:16:37 -080090 } else {
91 /* In case anyone cares what the unknown value is */
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +053092 sys_info->freq_localbus = lcrr_div;
Trent Piephoada591d2008-12-03 15:16:37 -080093 }
Jon Loeligerdebb7352006-04-26 17:58:56 -050094}
95
96
Jon Loeligerdebb7352006-04-26 17:58:56 -050097/*
98 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeligerdebb7352006-04-26 17:58:56 -050099 * (Approx. GCLK frequency in Hz)
100 */
101
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500102int get_clocks(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500103{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500104 sys_info_t sys_info;
105
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500106 get_sys_info(&sys_info);
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530107 gd->cpu_clk = sys_info.freq_processor;
108 gd->bus_clk = sys_info.freq_systembus;
109 gd->arch.lbc_clk = sys_info.freq_localbus;
Timur Tabi1b9ed252008-04-04 11:16:11 -0500110
111 /*
112 * The base clock for I2C depends on the actual SOC. Unfortunately,
113 * there is no pattern that can be used to determine the frequency, so
114 * the only choice is to look up the actual SOC number and use the value
115 * for that SOC. This information is taken from application note
116 * AN2919.
117 */
York Sun1425a872016-11-23 14:06:21 -0800118#ifdef CONFIG_ARCH_MPC8610
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530119 gd->arch.i2c1_clk = sys_info.freq_systembus;
Timur Tabi1b9ed252008-04-04 11:16:11 -0500120#else
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530121 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabi1b9ed252008-04-04 11:16:11 -0500122#endif
Simon Glass609e6ec2012-12-13 20:48:49 +0000123 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500124
125 if (gd->cpu_clk != 0)
126 return 0;
127 else
128 return 1;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500129}
130
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500131
132/*
Jon Loeligerdebb7352006-04-26 17:58:56 -0500133 * get_bus_freq
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500134 * Return system bus freq in Hz
135 */
Jon Loeligerc934f652006-05-31 13:55:35 -0500136
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500137ulong get_bus_freq(ulong dummy)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500138{
139 ulong val;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500140 sys_info_t sys_info;
141
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500142 get_sys_info(&sys_info);
Prabhakar Kushwaha997399f2013-08-16 14:52:26 +0530143 val = sys_info.freq_systembus;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500144
145 return val;
146}