wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Martin Winistoerfer, martinwinistoerfer@gmx.ch. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * File: speed.c |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 10 | * |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 11 | * Discription: Provides cpu speed calculation |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 12 | * |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <common.h> |
| 16 | #include <mpc5xx.h> |
| 17 | #include <asm/processor.h> |
| 18 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 21 | /* |
| 22 | * Get cpu and bus clock |
| 23 | */ |
| 24 | int get_clocks (void) |
| 25 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 26 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 27 | |
| 28 | #ifndef CONFIG_5xx_GCLK_FREQ |
| 29 | uint divf = (immr->im_clkrst.car_plprcr & PLPRCR_DIVF_MSK); |
| 30 | uint mf = ((immr->im_clkrst.car_plprcr & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT); |
| 31 | ulong vcoout; |
| 32 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | vcoout = (CONFIG_SYS_OSC_CLK / (divf + 1)) * (mf + 1) * 2; |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 34 | if(immr->im_clkrst.car_plprcr & PLPRCR_CSRC_MSK) { |
| 35 | gd->cpu_clk = vcoout / (2^(((immr->im_clkrst.car_sccr & SCCR_DFNL_MSK) >> SCCR_DFNL_SHIFT) + 1)); |
| 36 | } else { |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 37 | gd->cpu_clk = vcoout / (2^(immr->im_clkrst.car_sccr & SCCR_DFNH_MSK)); |
| 38 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 39 | |
wdenk | 0db5bca | 2003-03-31 17:27:09 +0000 | [diff] [blame] | 40 | #else /* CONFIG_5xx_GCLK_FREQ */ |
| 41 | gd->bus_clk = CONFIG_5xx_GCLK_FREQ; |
| 42 | #endif /* CONFIG_5xx_GCLK_FREQ */ |
| 43 | |
| 44 | if ((immr->im_clkrst.car_sccr & SCCR_EBDF11) == 0) { |
| 45 | /* No Bus Divider active */ |
| 46 | gd->bus_clk = gd->cpu_clk; |
| 47 | } else { |
| 48 | /* CLKOUT is GCLK / 2 */ |
| 49 | gd->bus_clk = gd->cpu_clk / 2; |
| 50 | } |
| 51 | return (0); |
| 52 | } |