/*
 * (C) Copyright 2001
 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
 *
 * 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
 */

/*
 * cpu.c
 *
 * CPU specific code
 *
 * written or collected and sometimes rewritten by
 * Magnus Damm <damm@bitsmart.com>
 *
 * minor modifications by
 * Wolfgang Denk <wd@denx.de>
 *
 * more modifications by
 * Josh Huber <huber@mclx.com>
 * mostly removing functionality we don't need quite yet.
 */

#include <ppcboot.h>
#include <command.h>
#include <mpc74xx.h>
#include <asm/cache.h>

#if defined(CONFIG_74xx)
static int
check_CPU(long clock, uint pvr)
{
	switch (PVR_VER(pvr)) {
	case 0x000c:
		puts("MPC7400 ");
#ifdef CONFIG_ALTIVEC
		puts("(altivec enabled) ");
#endif
		printf("v%d.%d\n", (pvr >> 8) & 0xFF, pvr & 0xFF);
		break;

	default:
		puts("Unknown CPU -- configuration error!\n");
		return -1;
		break;
	}

	return 0;
}
#else
#error CPU undefined
#endif
/* ------------------------------------------------------------------------- */

int
checkcpu(long clock)
{
	uint pvr = get_pvr();

	return check_CPU(clock, pvr);
}

/* these two functions are unimplemented currently [josh] */

/* ------------------------------------------------------------------------- */
/* L1 i-cache                                                                */

int
checkicache(void)
{
	return 0; /* XXX */
}

/* ------------------------------------------------------------------------- */
/* L1 d-cache                                                                */

int
checkdcache(void)
{
	return 0; /* XXX */
}

/* ------------------------------------------------------------------------- */

/* note: this does NOT work.  Using the RTC to reset the system
 * didn't seem to work either.  so, currently there is no way to
 * software reset the galileo eval board. [josh] */

void
do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
{
	ulong msr, addr;

	/* XXX */
	puts("do_reset unimplemented\n");
	return;

	/* Interrupts and MMU off */
	__asm__ __volatile__ ("mfmsr    %0" : "=r"(msr) : );
	msr &= ~(MSR_ME|MSR_EE|MSR_IR|MSR_DR);
	__asm__ __volatile__ ("mtmsr    %0" : : "r"(msr) );

	/*
	 * Trying to execute the next instruction at a non-existing address
	 * should cause a machine check, resulting in reset
	 */
#ifdef CFG_RESET_ADDRESS
	addr = CFG_RESET_ADDRESS;
#else
	/*
	 * note: when CFG_MONITOR_BASE points to a RAM address,
	 * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
	 * address. Better pick an address known to be invalid on your
	 * system and assign it to CFG_RESET_ADDRESS.
	 */
	addr = CFG_MONITOR_BASE - sizeof (ulong);
#endif
	((void (*)(void ))addr)();
}

/* ------------------------------------------------------------------------- */

/*
 * For the 7400 the TB clock runs at 1/4 the cpu bus speed.
 */
unsigned long
get_tbclk (void)
{
	return CFG_BUS_HZ / 4;
}

/* ------------------------------------------------------------------------- */

#if defined(CONFIG_WATCHDOG)
void
watchdog_reset(void)
{

}
#endif	/* CONFIG_WATCHDOG */

/* ------------------------------------------------------------------------- */
