blob: 8d43efff6ca1cc550ffe39aeff1dad03c2dc01aa [file] [log] [blame]
Christophe Leroy069fa832017-07-06 10:23:22 +02001/*
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>
Christophe Leroy394f9b32017-07-06 10:33:13 +020011#include <asm/io.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020012
13DECLARE_GLOBAL_DATA_PTR;
14
15void get_brgclk(uint sccr)
16{
17 uint divider = 0;
18
Christophe Leroy48f896d2017-07-06 10:33:17 +020019 switch ((sccr & SCCR_DFBRG11) >> 11) {
20 case 0:
21 divider = 1;
22 break;
23 case 1:
24 divider = 4;
25 break;
26 case 2:
27 divider = 16;
28 break;
29 case 3:
30 divider = 64;
31 break;
Christophe Leroy069fa832017-07-06 10:23:22 +020032 }
Christophe Leroy48f896d2017-07-06 10:33:17 +020033 gd->arch.brg_clk = gd->cpu_clk / divider;
Christophe Leroy069fa832017-07-06 10:23:22 +020034}
35
36/*
37 * get_clocks() fills in gd->cpu_clock depending on CONFIG_8xx_GCLK_FREQ
38 */
Christophe Leroy48f896d2017-07-06 10:33:17 +020039int get_clocks(void)
Christophe Leroy069fa832017-07-06 10:23:22 +020040{
Christophe Leroy48f896d2017-07-06 10:33:17 +020041 uint immr = get_immr(0); /* Return full IMMR contents */
Christophe Leroy394f9b32017-07-06 10:33:13 +020042 immap_t __iomem *immap = (immap_t __iomem *)(immr & 0xFFFF0000);
43 uint sccr = in_be32(&immap->im_clkrst.car_sccr);
Christophe Leroy069fa832017-07-06 10:23:22 +020044 /*
45 * If for some reason measuring the gclk frequency won't
46 * work, we return the hardwired value.
47 * (For example, the cogent CMA286-60 CPU module has no
48 * separate oscillator for PITRTCLK)
49 */
50 gd->cpu_clk = CONFIG_8xx_GCLK_FREQ;
51
52 if ((sccr & SCCR_EBDF11) == 0) {
53 /* No Bus Divider active */
54 gd->bus_clk = gd->cpu_clk;
55 } else {
56 /* The MPC8xx has only one BDF: half clock speed */
57 gd->bus_clk = gd->cpu_clk / 2;
58 }
59
60 get_brgclk(sccr);
61
Christophe Leroy48f896d2017-07-06 10:33:17 +020062 return 0;
Christophe Leroy069fa832017-07-06 10:23:22 +020063}