uboot/arch/powerpc/cpu/mpc5xx/speed.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2003
   3 * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
   4 *
   5 * SPDX-License-Identifier:     GPL-2.0+
   6 */
   7
   8/*
   9 * File:                speed.c
  10 *
  11 * Discription:         Provides cpu speed calculation
  12 *
  13 */
  14
  15#include <common.h>
  16#include <mpc5xx.h>
  17#include <asm/processor.h>
  18
  19DECLARE_GLOBAL_DATA_PTR;
  20
  21/*
  22 * Get cpu and bus clock
  23 */
  24int get_clocks (void)
  25{
  26        volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  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
  33        vcoout = (CONFIG_SYS_OSC_CLK / (divf + 1)) * (mf + 1) * 2;
  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 {
  37                gd->cpu_clk = vcoout / (2^(immr->im_clkrst.car_sccr & SCCR_DFNH_MSK));
  38        }
  39
  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}
  53