/*
 * Copyright 2001 MontaVista Software Inc.
 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
 *
 * arch/mips/aloha/setup.c
 *     The setup file for aloha.
 *
 * 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.
 *
 */

#include <linux/config.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/serial.h>
#include <linux/types.h>
#include <linux/string.h>	/* for memset */

#include <asm/reboot.h>
#include <asm/io.h>
#include <asm/time.h>
#include <asm/pgtable.h>
#include <asm/processor.h>
#include <asm/reboot.h>
#include <asm/system.h>

void aloha_restart(char *command)
{
        set_cp0_status(ST0_BEV | ST0_ERL);
        change_cp0_config(CONF_CM_CMASK, CONF_CM_UNCACHED);
        flush_cache_all();
        write_32bit_cp0_register(CP0_WIRED, 0);
        __asm__ __volatile__("jr\t%0"::"r"(0xbfc00000));
}

void aloha_halt(void)
{
        printk(KERN_NOTICE "\n** You can safely turn off the power\n");
        while (1);
}

void aloha_power_off(void)
{
        aloha_halt();
}

static void __init aloha_time_init(void)
{
	/* 100 (CPU clock) MHz divided by 8 */
        mips_counter_frequency = 100000000 / 8;
}

extern int setup_irq(unsigned int irq, struct irqaction *irqaction);
static void __init aloha_timer_setup(struct irqaction *irq)
{

        unsigned int count;

      	setup_irq(7, irq);

        /* to generate the first CPU timer interrupt */
        count = read_32bit_cp0_register(CP0_COUNT);
        write_32bit_cp0_register(CP0_COMPARE, count + 1000);
}


void __init aloha_setup(void)
{
	printk("aloha_setup() starts.\n");

        board_time_init = aloha_time_init;
        board_timer_setup = aloha_timer_setup;

        _machine_restart = aloha_restart;
        _machine_halt = aloha_halt;
        _machine_power_off = aloha_power_off;
}
