Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2004 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 8 | #include <clock_legacy.h> |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 9 | #include <mpc8xx.h> |
| 10 | #include <asm/processor.h> |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 11 | #include <asm/io.h> |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 15 | /* |
| 16 | * get_clocks() fills in gd->cpu_clock depending on CONFIG_8xx_GCLK_FREQ |
| 17 | */ |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 18 | int get_clocks(void) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 19 | { |
Christophe Leroy | 5c59bdf | 2018-03-16 17:20:33 +0100 | [diff] [blame] | 20 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 21 | uint sccr = in_be32(&immap->im_clkrst.car_sccr); |
Christophe Leroy | 297cbac | 2017-07-13 15:09:44 +0200 | [diff] [blame] | 22 | uint divider = 1 << (((sccr & SCCR_DFBRG11) >> 11) * 2); |
| 23 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 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 | |
Christophe Leroy | 297cbac | 2017-07-13 15:09:44 +0200 | [diff] [blame] | 40 | gd->arch.brg_clk = gd->cpu_clk / divider; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 41 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 42 | return 0; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 43 | } |