xref: /rk3399_rockchip-uboot/arch/powerpc/cpu/mpc8xx/speed.c (revision ba3da7348ac9aaa1cc0a9ccbc8b3c9367d87ca4b)
1907208c4SChristophe Leroy /*
2907208c4SChristophe Leroy  * (C) Copyright 2000-2004
3907208c4SChristophe Leroy  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4907208c4SChristophe Leroy  *
5907208c4SChristophe Leroy  * SPDX-License-Identifier:	GPL-2.0+
6907208c4SChristophe Leroy  */
7907208c4SChristophe Leroy 
8907208c4SChristophe Leroy #include <common.h>
9907208c4SChristophe Leroy #include <mpc8xx.h>
10907208c4SChristophe Leroy #include <asm/processor.h>
11*ba3da734SChristophe Leroy #include <asm/io.h>
12907208c4SChristophe Leroy 
13907208c4SChristophe Leroy DECLARE_GLOBAL_DATA_PTR;
14907208c4SChristophe Leroy 
15907208c4SChristophe Leroy void get_brgclk(uint sccr)
16907208c4SChristophe Leroy {
17907208c4SChristophe Leroy 	uint divider = 0;
18907208c4SChristophe Leroy 
19907208c4SChristophe Leroy 	switch((sccr&SCCR_DFBRG11)>>11){
20907208c4SChristophe Leroy 		case 0:
21907208c4SChristophe Leroy 			divider = 1;
22907208c4SChristophe Leroy 			break;
23907208c4SChristophe Leroy 		case 1:
24907208c4SChristophe Leroy 			divider = 4;
25907208c4SChristophe Leroy 			break;
26907208c4SChristophe Leroy 		case 2:
27907208c4SChristophe Leroy 			divider = 16;
28907208c4SChristophe Leroy 			break;
29907208c4SChristophe Leroy 		case 3:
30907208c4SChristophe Leroy 			divider = 64;
31907208c4SChristophe Leroy 			break;
32907208c4SChristophe Leroy 	}
33907208c4SChristophe Leroy 	gd->arch.brg_clk = gd->cpu_clk/divider;
34907208c4SChristophe Leroy }
35907208c4SChristophe Leroy 
36907208c4SChristophe Leroy /*
37907208c4SChristophe Leroy  * get_clocks() fills in gd->cpu_clock depending on CONFIG_8xx_GCLK_FREQ
38907208c4SChristophe Leroy  */
39907208c4SChristophe Leroy int get_clocks (void)
40907208c4SChristophe Leroy {
41907208c4SChristophe Leroy 	uint immr = get_immr (0);	/* Return full IMMR contents */
42*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)(immr & 0xFFFF0000);
43*ba3da734SChristophe Leroy 	uint sccr = in_be32(&immap->im_clkrst.car_sccr);
44907208c4SChristophe Leroy 	/*
45907208c4SChristophe Leroy 	 * If for some reason measuring the gclk frequency won't
46907208c4SChristophe Leroy 	 * work, we return the hardwired value.
47907208c4SChristophe Leroy 	 * (For example, the cogent CMA286-60 CPU module has no
48907208c4SChristophe Leroy 	 * separate oscillator for PITRTCLK)
49907208c4SChristophe Leroy 	 */
50907208c4SChristophe Leroy 	gd->cpu_clk = CONFIG_8xx_GCLK_FREQ;
51907208c4SChristophe Leroy 
52907208c4SChristophe Leroy 	if ((sccr & SCCR_EBDF11) == 0) {
53907208c4SChristophe Leroy 		/* No Bus Divider active */
54907208c4SChristophe Leroy 		gd->bus_clk = gd->cpu_clk;
55907208c4SChristophe Leroy 	} else {
56907208c4SChristophe Leroy 		/* The MPC8xx has only one BDF: half clock speed */
57907208c4SChristophe Leroy 		gd->bus_clk = gd->cpu_clk / 2;
58907208c4SChristophe Leroy 	}
59907208c4SChristophe Leroy 
60907208c4SChristophe Leroy 	get_brgclk(sccr);
61907208c4SChristophe Leroy 
62907208c4SChristophe Leroy 	return (0);
63907208c4SChristophe Leroy }
64