blob: 1a882a38820dfd5742b72f3fdb12fca71adea4e8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy907208c2017-07-06 10:23:22 +02002/*
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Christophe Leroy907208c2017-07-06 10:23:22 +02005 */
6
7#include <common.h>
Simon Glassd96c2602019-12-28 10:44:58 -07008#include <clock_legacy.h>
Christophe Leroy907208c2017-07-06 10:23:22 +02009#include <mpc8xx.h>
Simon Glass401d1c42020-10-30 21:38:53 -060010#include <asm/global_data.h>
Christophe Leroy907208c2017-07-06 10:23:22 +020011#include <asm/processor.h>
Christophe Leroyba3da732017-07-06 10:33:13 +020012#include <asm/io.h>
Christophe Leroy907208c2017-07-06 10:23:22 +020013
14DECLARE_GLOBAL_DATA_PTR;
15
Christophe Leroy907208c2017-07-06 10:23:22 +020016/*
Christophe Leroy9750a242023-04-04 10:14:33 +020017 * get_clocks() fills in gd->cpu_clk depending on CONFIG_SYS_CLK_FREQ
Christophe Leroy907208c2017-07-06 10:23:22 +020018 */
Christophe Leroy70fd0712017-07-06 10:33:17 +020019int get_clocks(void)
Christophe Leroy907208c2017-07-06 10:23:22 +020020{
Christophe Leroy374a0e32018-03-16 17:20:33 +010021 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
Christophe Leroyba3da732017-07-06 10:33:13 +020022 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 */
Christophe Leroy9750a242023-04-04 10:14:33 +020031 gd->cpu_clk = CONFIG_SYS_CLK_FREQ;
Christophe Leroy907208c2017-07-06 10:23:22 +020032
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}