uboot/arch/powerpc/cpu/74xx_7xx/speed.c
<<
>>
Prefs
   1/*
   2 * (C) Copyright 2000-2002
   3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   4 *
   5 * See file CREDITS for list of people who contributed to this
   6 * project.
   7 *
   8 * This program is free software; you can redistribute it and/or
   9 * modify it under the terms of the GNU General Public License as
  10 * published by the Free Software Foundation; either version 2 of
  11 * the License, or (at your option) any later version.
  12 *
  13 * This program is distributed in the hope that it will be useful,
  14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16 * GNU General Public License for more details.
  17 *
  18 * You should have received a copy of the GNU General Public License
  19 * along with this program; if not, write to the Free Software
  20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21 * MA 02111-1307 USA
  22 */
  23
  24#include <common.h>
  25#include <74xx_7xx.h>
  26#include <asm/processor.h>
  27
  28DECLARE_GLOBAL_DATA_PTR;
  29
  30extern unsigned long get_board_bus_clk (void);
  31
  32static const int hid1_multipliers_x_10[] = {
  33        25,     /* 0000 - 2.5x */
  34        75,     /* 0001 - 7.5x */
  35        70,     /* 0010 - 7x */
  36        10,     /* 0011 - bypass */
  37        20,     /* 0100 - 2x */
  38        65,     /* 0101 - 6.5x */
  39        100,    /* 0110 - 10x */
  40        45,     /* 0111 - 4.5x */
  41        30,     /* 1000 - 3x */
  42        55,     /* 1001 - 5.5x */
  43        40,     /* 1010 - 4x */
  44        50,     /* 1011 - 5x */
  45        80,     /* 1100 - 8x */
  46        60,     /* 1101 - 6x */
  47        35,     /* 1110 - 3.5x */
  48        0       /* 1111 - off */
  49};
  50
  51/* PLL_CFG[0:4] table for cpu 7448/7447A/7455/7457 */
  52static const int hid1_74xx_multipliers_x_10[] = {
  53        115,    /* 00000 - 11.5x  */
  54        170,    /* 00001 - 17x    */
  55        75,     /* 00010 -  7.5x  */
  56        150,    /* 00011 - 15x    */
  57        70,     /* 00100 -  7x    */
  58        180,    /* 00101 - 18x    */
  59        10,     /* 00110 - bypass */
  60        200,    /* 00111 - 20x    */
  61        20,     /* 01000 -  2x    */
  62        210,    /* 01001 - 21x    */
  63        65,     /* 01010 -  6.5x  */
  64        130,    /* 01011 - 13x    */
  65        85,     /* 01100 -  8.5x  */
  66        240,    /* 01101 - 24x    */
  67        95,     /* 01110 -  9.5x  */
  68        90,     /* 01111 -  9x    */
  69        30,     /* 10000 -  3x    */
  70        105,    /* 10001 - 10.5x  */
  71        55,     /* 10010 -  5.5x  */
  72        110,    /* 10011 - 11x    */
  73        40,     /* 10100 -  4x    */
  74        100,    /* 10101 - 10x    */
  75        50,     /* 10110 -  5x    */
  76        120,    /* 10111 - 12x    */
  77        80,     /* 11000 -  8x    */
  78        140,    /* 11001 - 14x    */
  79        60,     /* 11010 -  6x    */
  80        160,    /* 11011 - 16x    */
  81        135,    /* 11100 - 13.5x  */
  82        280,    /* 11101 - 28x    */
  83        0,      /* 11110 - off    */
  84        125     /* 11111 - 12.5x  */
  85};
  86
  87static const int hid1_fx_multipliers_x_10[] = {
  88        00,     /* 0000 - off */
  89        00,     /* 0001 - off */
  90        10,     /* 0010 - bypass */
  91        10,     /* 0011 - bypass */
  92        20,     /* 0100 - 2x */
  93        25,     /* 0101 - 2.5x */
  94        30,     /* 0110 - 3x */
  95        35,     /* 0111 - 3.5x */
  96        40,     /* 1000 - 4x */
  97        45,     /* 1001 - 4.5x */
  98        50,     /* 1010 - 5x */
  99        55,     /* 1011 - 5.5x */
 100        60,     /* 1100 - 6x */
 101        65,     /* 1101 - 6.5x */
 102        70,     /* 1110 - 7x */
 103        75,     /* 1111 - 7.5 */
 104        80,     /* 10000 - 8x */
 105        85,     /* 10001 - 8.5x */
 106        90,     /* 10010 - 9x */
 107        95,     /* 10011 - 9.5x */
 108        100,    /* 10100 - 10x */
 109        110,    /* 10101 - 11x */
 110        120,    /* 10110 - 12x */
 111};
 112
 113
 114/* ------------------------------------------------------------------------- */
 115
 116/*
 117 * Measure CPU clock speed (core clock GCLK1, GCLK2)
 118 *
 119 * (Approx. GCLK frequency in Hz)
 120 */
 121
 122int get_clocks (void)
 123{
 124        ulong clock = 0;
 125
 126#ifdef CONFIG_SYS_BUS_CLK
 127        gd->bus_clk = CONFIG_SYS_BUS_CLK;       /* bus clock is a fixed frequency */
 128#else
 129        gd->bus_clk = get_board_bus_clk ();     /* bus clock is configurable */
 130#endif
 131
 132        /* calculate the clock frequency based upon the CPU type */
 133        switch (get_cpu_type()) {
 134        case CPU_7447A:
 135        case CPU_7448:
 136        case CPU_7455:
 137        case CPU_7457:
 138                /*
 139                 * Make sure division is done before multiplication to prevent 32-bit
 140                 * arithmetic overflows which will cause a negative number
 141                 */
 142                clock = (gd->bus_clk / 10) *
 143                        hid1_74xx_multipliers_x_10[(get_hid1 () >> 12) & 0x1F];
 144                break;
 145
 146        case CPU_750GX:
 147        case CPU_750FX:
 148                clock = (gd->bus_clk / 10) *
 149                        hid1_fx_multipliers_x_10[get_hid1 () >> 27];
 150                break;
 151
 152        case CPU_7450:
 153        case CPU_740:
 154        case CPU_740P:
 155        case CPU_745:
 156        case CPU_750CX:
 157        case CPU_750:
 158        case CPU_750P:
 159        case CPU_755:
 160        case CPU_7400:
 161        case CPU_7410:
 162                /*
 163                 * Make sure division is done before multiplication to prevent 32-bit
 164                 * arithmetic overflows which will cause a negative number
 165                 */
 166                clock = (gd->bus_clk / 10) *
 167                        hid1_multipliers_x_10[get_hid1 () >> 28];
 168                break;
 169
 170        case CPU_UNKNOWN:
 171               printf ("get_gclk_freq(): unknown CPU type\n");
 172               clock = 0;
 173               return (1);
 174        }
 175
 176        gd->cpu_clk = clock;
 177
 178        return (0);
 179}
 180
 181/* ------------------------------------------------------------------------- */
 182