xref: /openbmc/u-boot/arch/powerpc/cpu/mpc8xx/speed.c (revision 30754ef7)
1 /*
2  * (C) Copyright 2000-2004
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <mpc8xx.h>
10 #include <asm/processor.h>
11 #include <asm/io.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 /*
16  * get_clocks() fills in gd->cpu_clock depending on CONFIG_8xx_GCLK_FREQ
17  */
18 int get_clocks(void)
19 {
20 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
21 	uint sccr = in_be32(&immap->im_clkrst.car_sccr);
22 	uint divider = 1 << (((sccr & SCCR_DFBRG11) >> 11) * 2);
23 
24 	/*
25 	 * If for some reason measuring the gclk frequency won't
26 	 * work, we return the hardwired value.
27 	 * (For example, the cogent CMA286-60 CPU module has no
28 	 * separate oscillator for PITRTCLK)
29 	 */
30 	gd->cpu_clk = CONFIG_8xx_GCLK_FREQ;
31 
32 	if ((sccr & SCCR_EBDF11) == 0) {
33 		/* No Bus Divider active */
34 		gd->bus_clk = gd->cpu_clk;
35 	} else {
36 		/* The MPC8xx has only one BDF: half clock speed */
37 		gd->bus_clk = gd->cpu_clk / 2;
38 	}
39 
40 	gd->arch.brg_clk = gd->cpu_clk / divider;
41 
42 	return 0;
43 }
44