blob: fa8f87cbc5ea2302437a8d4ef1835d7d2011eb9f [file] [log] [blame]
Christophe Leroy907208c2017-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 Leroyba3da732017-07-06 10:33:13 +020011#include <asm/io.h>
Christophe Leroy907208c2017-07-06 10:23:22 +020012
13DECLARE_GLOBAL_DATA_PTR;
14
Christophe Leroy907208c2017-07-06 10:23:22 +020015/*
16 * get_clocks() fills in gd->cpu_clock depending on CONFIG_8xx_GCLK_FREQ
17 */
Christophe Leroy70fd0712017-07-06 10:33:17 +020018int get_clocks(void)
Christophe Leroy907208c2017-07-06 10:23:22 +020019{
Christophe Leroy70fd0712017-07-06 10:33:17 +020020 uint immr = get_immr(0); /* Return full IMMR contents */
Christophe Leroyba3da732017-07-06 10:33:13 +020021 immap_t __iomem *immap = (immap_t __iomem *)(immr & 0xFFFF0000);
22 uint sccr = in_be32(&immap->im_clkrst.car_sccr);
Christophe Leroy7a0a5502017-07-13 15:09:44 +020023 uint divider = 1 << (((sccr & SCCR_DFBRG11) >> 11) * 2);
24
Christophe Leroy907208c2017-07-06 10:23:22 +020025 /*
26 * If for some reason measuring the gclk frequency won't
27 * work, we return the hardwired value.
28 * (For example, the cogent CMA286-60 CPU module has no
29 * separate oscillator for PITRTCLK)
30 */
31 gd->cpu_clk = CONFIG_8xx_GCLK_FREQ;
32
33 if ((sccr & SCCR_EBDF11) == 0) {
34 /* No Bus Divider active */
35 gd->bus_clk = gd->cpu_clk;
36 } else {
37 /* The MPC8xx has only one BDF: half clock speed */
38 gd->bus_clk = gd->cpu_clk / 2;
39 }
40
Christophe Leroy7a0a5502017-07-13 15:09:44 +020041 gd->arch.brg_clk = gd->cpu_clk / divider;
Christophe Leroy907208c2017-07-06 10:23:22 +020042
Christophe Leroy70fd0712017-07-06 10:33:17 +020043 return 0;
Christophe Leroy907208c2017-07-06 10:23:22 +020044}