/*
 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Andreas Heppel <aheppel@sysgo.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 <ppcboot.h>
#include <watchdog.h>
#include <command.h>
#include <config.h>
#include <mpc106.h>
#include <mk48t59.h>


int checkboard (void)
{
    printf("BAB 750\n");
    return 0;
}

int checkflash (void)
{
    /* TODO: XXX XXX XXX */
    printf ("2 MB ## Test not implemented yet ##\n");

    return (0);
}

long int dram_size (int board_type)
{
    /* No actual initialisation to do - done when setting up PICRs MCCRs ME/SARs etc
     * in ram_init.S.
     */
     #if defined(CFG_MEMTEST)

     register unsigned long reg;

     printf("Testing DRAM\n");
     
     /* write each mem addr with it's address */
     for (reg = CFG_MEMTEST_START; reg < CFG_MEMTEST_END; reg+=4
         *reg = reg;

     for (reg = CFG_MEMTEST_START; reg < CFG_MEMTEST_END; reg+=4
     {
         if (*reg != reg)
           return -1;
     }
     #endif

     /* TODO: calculate amount of dram..for now just return MEMTEST_END */
     return CFG_MEMTEST_END;

}

long int initdram(int board_type)
{
	return dram_size(board_type);
}
/* ------------------------------------------------------------------------- */

/*
 * do_reset is done here because in this case it is board specific, since the
 * 7xx CPUs can only be reset by external HW (the RTC in this case).
 */
void
do_reset (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
{
#if defined(CONFIG_RTC_MK48T59)
	/* trigger watchdog immediately */
	rtc_set_watchdog(1, RTC_WD_RB_16TH);
#else
	#error "You must define the macro CONFIG_RTC_MK48T59."
#endif
}

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

#if defined(CONFIG_WATCHDOG)

/*
 * Since the 7xx CPUs don't have an internal watchdog, this function is board specific.
 * We use the RTC here.
 */
void watchdog_reset(void)
{
#if defined(CONFIG_RTC_MK48T59)
	/* we use a 32 sec watchdog timer */
	rtc_set_watchdog(8, RTC_WD_RB_4);
#else
	#error "You must define the macro CONFIG_RTC_MK48T59."
#endif
}
#endif	/* CONFIG_WATCHDOG */


