blob: 86c1709c4ca2d1a862e11e1f2f1ea92491fee139 [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>
Simon Glass85d65312019-12-28 10:44:58 -070012#include <clock_legacy.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050013#include <mpc86xx.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050015#include <asm/processor.h>
Trent Piepho0b691fc2008-12-03 15:16:37 -080016#include <asm/io.h>
Jon Loeliger5c8aa972006-04-26 17:58:56 -050017
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020018DECLARE_GLOBAL_DATA_PTR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050019
Wolfgang Denk92254112007-11-18 16:36:27 +010020/* used in some defintiions of CONFIG_SYS_CLK_FREQ */
21extern unsigned long get_board_sys_clk(unsigned long dummy);
22
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053023void get_sys_info(sys_info_t *sys_info)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050024{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020025 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050026 volatile ccsr_gur_t *gur = &immap->im_gur;
27 uint plat_ratio, e600_ratio;
28
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:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053034 sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ;
Jon Loeliger5c8aa972006-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 Loeliger8827a732006-05-31 13:55:35 -050045 case 0x10:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053046 sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
Jon Loeliger8827a732006-05-31 13:55:35 -050047 break;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050048 default:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053049 sys_info->freq_systembus = 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:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053058 sys_info->freq_processor = 2 * sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050059 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050060 case 0x19:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053061 sys_info->freq_processor = 5 * sys_info->freq_systembus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050062 break;
63 case 0x20:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053064 sys_info->freq_processor = 3 * sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050065 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050066 case 0x39:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053067 sys_info->freq_processor = 7 * sys_info->freq_systembus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050068 break;
69 case 0x28:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053070 sys_info->freq_processor = 4 * sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050071 break;
72 case 0x1d:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053073 sys_info->freq_processor = 9 * sys_info->freq_systembus / 2;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050074 break;
Jon Loeliger8827a732006-05-31 13:55:35 -050075 default:
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053076 sys_info->freq_processor = e600_ratio +
77 sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050078 break;
79 }
Trent Piepho0b691fc2008-12-03 15:16:37 -080080
Prabhakar Kushwahabedc5622017-02-02 15:02:00 +053081 sys_info->freq_localbus = sys_info->freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -050082}
83
84
Jon Loeliger5c8aa972006-04-26 17:58:56 -050085/*
86 * Measure CPU clock speed (core clock GCLK1, GCLK2)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050087 * (Approx. GCLK frequency in Hz)
88 */
89
Jon Loeliger465b9d82006-04-27 10:15:16 -050090int get_clocks(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -050091{
Jon Loeliger5c8aa972006-04-26 17:58:56 -050092 sys_info_t sys_info;
93
Jon Loeliger465b9d82006-04-27 10:15:16 -050094 get_sys_info(&sys_info);
Prabhakar Kushwahad1698082013-08-16 14:52:26 +053095 gd->cpu_clk = sys_info.freq_processor;
96 gd->bus_clk = sys_info.freq_systembus;
97 gd->arch.lbc_clk = sys_info.freq_localbus;
Timur Tabid93136b2008-04-04 11:16:11 -050098
99 /*
100 * The base clock for I2C depends on the actual SOC. Unfortunately,
101 * there is no pattern that can be used to determine the frequency, so
102 * the only choice is to look up the actual SOC number and use the value
103 * for that SOC. This information is taken from application note
104 * AN2919.
105 */
York Sunf48436a2016-11-23 14:06:21 -0800106#ifdef CONFIG_ARCH_MPC8610
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530107 gd->arch.i2c1_clk = sys_info.freq_systembus;
Timur Tabid93136b2008-04-04 11:16:11 -0500108#else
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530109 gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
Timur Tabid93136b2008-04-04 11:16:11 -0500110#endif
Simon Glassc2baaec2012-12-13 20:48:49 +0000111 gd->arch.i2c2_clk = gd->arch.i2c1_clk;
Jon Loeliger465b9d82006-04-27 10:15:16 -0500112
113 if (gd->cpu_clk != 0)
114 return 0;
115 else
116 return 1;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500117}
118
Jon Loeliger465b9d82006-04-27 10:15:16 -0500119
120/*
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500121 * get_bus_freq
Jon Loeliger465b9d82006-04-27 10:15:16 -0500122 * Return system bus freq in Hz
123 */
Jon Loeliger8827a732006-05-31 13:55:35 -0500124
Jon Loeliger465b9d82006-04-27 10:15:16 -0500125ulong get_bus_freq(ulong dummy)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500126{
127 ulong val;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500128 sys_info_t sys_info;
129
Jon Loeliger465b9d82006-04-27 10:15:16 -0500130 get_sys_info(&sys_info);
Prabhakar Kushwahad1698082013-08-16 14:52:26 +0530131 val = sys_info.freq_systembus;
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500132
133 return val;
134}