blob: 434c4f3f43bf953be468dc476ae9a2b70f4dd3e4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jon Loeliger5c8aa972006-04-26 17:58:56 -05002/*
3 * Copyright 2004 Freescale Semiconductor.
Jon Loeliger8827a732006-05-31 13:55:35 -05004 * Jeff Brown
Jon Loeliger5c8aa972006-04-26 17:58:56 -05005 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
6 *
7 * (C) Copyright 2000-2002
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Jon Loeliger5c8aa972006-04-26 17:58:56 -05009 */
10
11#include <common.h>
12#include <mpc86xx.h>
13#include <asm/processor.h>
Trent Piepho0b691fc2008-12-03 15:16:37 -080014#include <asm/io.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050015
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020016DECLARE_GLOBAL_DATA_PTR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050017
Wolfgang Denk92254112007-11-18 16:36:27 +010018/* used in some defintiions of CONFIG_SYS_CLK_FREQ */
19extern unsigned long get_board_sys_clk(unsigned long dummy);
20
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053021void get_sys_info(sys_info_t *sys_info)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050022{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050024 volatile ccsr_gur_t *gur = &immap->im_gur;
25 uint plat_ratio, e600_ratio;
26
Jon Loeliger8827a732006-05-31 13:55:35 -050027 plat_ratio = (gur->porpllsr) & 0x0000003e;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050028 plat_ratio >>= 1;
Jon Loeliger465b9d82006-04-27 10:15:16 -050029
Jon Loeligera1295442006-08-22 12:06:18 -050030 switch (plat_ratio) {
Jon Loeliger8827a732006-05-31 13:55:35 -050031 case 0x0:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053032 sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050033 break;
34 case 0x02:
35 case 0x03:
36 case 0x04:
37 case 0x05:
38 case 0x06:
39 case 0x08:
40 case 0x09:
41 case 0x0a:
42 case 0x0c:
Jon Loeliger8827a732006-05-31 13:55:35 -050043 case 0x10:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053044 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Jon Loeliger8827a732006-05-31 13:55:35 -050045 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050046 default:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053047 sys_info->freq_systembus = 0;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050048 break;
49 }
50
Jon Loeliger5c8aa972006-04-26 17:58:56 -050051 e600_ratio = (gur->porpllsr) & 0x003f0000;
52 e600_ratio >>= 16;
Jon Loeliger465b9d82006-04-27 10:15:16 -050053
54 switch (e600_ratio) {
Jon Loeliger5c8aa972006-04-26 17:58:56 -050055 case 0x10:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053056 sys_info->freq_processor = 2 * sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050057 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050058 case 0x19:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053059 sys_info->freq_processor = 5 * sys_info->freq_systembus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050060 break;
61 case 0x20:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053062 sys_info->freq_processor = 3 * sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050063 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050064 case 0x39:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053065 sys_info->freq_processor = 7 * sys_info->freq_systembus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050066 break;
67 case 0x28:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053068 sys_info->freq_processor = 4 * sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050069 break;
70 case 0x1d:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053071 sys_info->freq_processor = 9 * sys_info->freq_systembus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050072 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050073 default:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053074 sys_info->freq_processor = e600_ratio +
75 sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050076 break;
77 }
Trent Piepho0b691fc2008-12-03 15:16:37 -080078
Prabhakar Kushwahabedc5622017-02-02 15:02:00 +053079 sys_info->freq_localbus = sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050080}
81
82
Jon Loeliger5c8aa972006-04-26 17:58:56 -050083/*
84 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050085 * (Approx. GCLK frequency in Hz)
86 */
87
Jon Loeliger465b9d82006-04-27 10:15:16 -050088int get_clocks(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050089{
Jon Loeliger5c8aa972006-04-26 17:58:56 -050090 sys_info_t sys_info;
91
Jon Loeliger465b9d82006-04-27 10:15:16 -050092 get_sys_info(&sys_info);
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053093 gd->cpu_clk = sys_info.freq_processor;
94 gd->bus_clk = sys_info.freq_systembus;
95 gd->arch.lbc_clk = sys_info.freq_localbus;
Timur Tabid93136b2008-04-04 11:16:11 -050096
97 /*
98 * The base clock for I2C depends on the actual SOC. Unfortunately,
99 * there is no pattern that can be used to determine the frequency, so
100 * the only choice is to look up the actual SOC number and use the value
101 * for that SOC. This information is taken from application note
102 * AN2919.
103 */
York Sunf48436a2016-11-23 14:06:21 -0800104#ifdef CONFIG_ARCH_MPC8610
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530105 gd->arch.i2c1_clk = sys_info.freq_systembus;
Timur Tabid93136b2008-04-04 11:16:11 -0500106#else
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530107 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabid93136b2008-04-04 11:16:11 -0500108#endif
Simon Glassc2baaec2012-12-13 20:48:49 +0000109 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500110
111 if (gd->cpu_clk != 0)
112 return 0;
113 else
114 return 1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500115}
116
Jon Loeliger465b9d82006-04-27 10:15:16 -0500117
118/*
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500119 * get_bus_freq
Jon Loeliger465b9d82006-04-27 10:15:16 -0500120 * Return system bus freq in Hz
121 */
Jon Loeliger8827a732006-05-31 13:55:35 -0500122
Jon Loeliger465b9d82006-04-27 10:15:16 -0500123ulong get_bus_freq(ulong dummy)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500124{
125 ulong val;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500126 sys_info_t sys_info;
127
Jon Loeliger465b9d82006-04-27 10:15:16 -0500128 get_sys_info(&sys_info);
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530129 val = sys_info.freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500130
131 return val;
132}