/*
 * (C) Copyright 2003
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <asm/inca-ip.h>



/*******************************************************************************
*
* get_cpuclk - returns the frequency of the CPU. 
*
* Gets the value directly from the INCA-IP hardware.
*
* RETURNS: 
*          150.000.000 for 150 MHz
*          130.000.000. for 130 Mhz
*          100.000.000. for 100 Mhz
* NOTE:
*   This functions should be used by the hardware driver to get the correct
*   frequency of the CPU. Don't use the macros, which are set to init the CPU
*   frequency in the ROM code.
*/
uint incaip_get_cpuclk(void)
{
   /*-------------------------------------------------------------------------*/
   /* CPU Clock Input Multiplexer (MUX I)                                     */
   /* Multiplexer MUX I selects the maximum input clock to the CPU.           */
   /*-------------------------------------------------------------------------*/
   if (*((volatile ulong*)INCA_IP_CGU_CGU_MUXCR) & INCA_IP_CGU_CGU_MUXCR_MUXI)
   {
      /* MUX I set to 150 MHz clock */
      return 150000000;
   }
   else
   {
      /* MUX I set to 100/133 MHz clock */
      if (*((volatile ulong*)INCA_IP_CGU_CGU_DIVCR) & 0x40) 
      {
         /* Division value is 1/3, maximum CPU operating */
         /* frequency is 133.3 MHz                       */
         return 130000000;
      }
      else
      {
         /* Division value is 1/4, maximum CPU operating */
         /* frequency is 100 MHz                         */
         return 100000000;
      }
   }
}

/*******************************************************************************
*
* get_fpiclk - returns the frequency of the FPI bus. 
*
* Gets the value directly from the INCA-IP hardware.
*
* RETURNS: Frquency in Hz
*
* NOTE:
*   This functions should be used by the hardware driver to get the correct
*   frequency of the CPU. Don't use the macros, which are set to init the CPU
*   frequency in the ROM code.
*   The calculation for the 
*/
uint incaip_get_fpiclk(void)
{
   uint  clkCPU;
   
   clkCPU = incaip_get_cpuclk();
   
   switch (*((volatile ulong*)INCA_IP_CGU_CGU_DIVCR) & 0xC)
   {
      case 0x4:
         return clkCPU >> 1; /* devided by 2 */
         break;
      case 0x8:
         return clkCPU >> 2; /* devided by 4 */
         break;
      default:
         return clkCPU;
         break;
   }
}


