/*
 * Copyright (c) 1997-2003 MIPS Technologies, Inc.
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * sbd.h: cpu board definitions for Galileo-9
 */


#ifndef MHZ
/* fastest possible pipeline clock */
#define MHZ		100
#endif

/* FIXME These timings are completely fictional */
#define RAMCYCLE	60			/* 60ns dram cycle */
#define ROMCYCLE	750			/* ~750ns rom cycle */
#define CACHECYCLE	(1000/MHZ) 		/* internal clock */
#define CYCLETIME	CACHECYCLE
#define CACHEMISS	(CYCLETIME * 6)

/*
 * rough scaling factors for 2 instruction DELAY loop to get 1ms and 1us delays
 */
#define ASMDELAY(ns,icycle)	\
	(((ns) + (icycle)) / ((icycle) * 2))

#define CACHENS(ns)	ASMDELAY((ns), CACHECYCLE)
#define RAMNS(ns)	ASMDELAY((ns), CACHEMISS+RAMCYCLE)
#define ROMNS(ns)	ASMDELAY((ns), CACHEMISS+ROMCYCLE)
#define CACHEUS(us)	ASMDELAY((us)*1000, CACHECYCLE)
#define RAMUS(us)	ASMDELAY((us)*1000, CACHEMISS+RAMCYCLE)
#define ROMUS(us)	ASMDELAY((us)*1000, CACHEMISS+ROMCYCLE)
#define CACHEMS(ms)	((ms) * ASMDELAY(1000000, CACHECYCLE))
#define RAMMS(ms)	((ms) * ASMDELAY(1000000, CACHEMISS+RAMCYCLE))
#define ROMMS(ms)	((ms) * ASMDELAY(1000000, CACHEMISS+ROMCYCLE))

#ifndef __ASSEMBLER__
#define nsdelay(ns)	mips_cycle (ASMDELAY (ns, CACHECYCLE))
#define usdelay(us)	mips_cycle (ASMDELAY ((us)*1000, CACHECYCLE))
#endif

#define DRAM_BASE		0x00000000
#define PCI_IO_BASE		0x10000000
#define PCI_IO_SIZE		0x02000000
#define PCI_MEM_BASE		0x12000000
#define PCI_MEM_SIZE		0x02000000
#define GT64011_BASE		0x14000000
#define DUART_BASE		0x1c000000
#define FLASH_BASE		0x1c800000
#define PROM_BASE		0x1fc00000


#define LOCAL_MEM		DRAM_BASE
#define LOCAL_MEM_SIZE		(32*1024*1024)		/* DRAM size (32Mb) */

#define BOOTPROM_BASE		PROM_BASE


/* 
 * Define the Z8530 duart parameters
 */

#define Z8530CLOCK		3686400		/* baud rate clock */
#define Z8530DELAY		2		/* 2us recovery time */

/* uart register layout offsets; data is on 31:24 */
#define Z8530_CHB	0
#define Z8530_CHA	8
#ifdef __ASSEMBLER__
# if #endian(big)
#  define Z8530_CMD	0
#  define Z8530_DATA	4
# endif
# if #endian(little)
#  define Z8530_CMD	3
#  define Z8530_DATA	7
# endif
#else
# if #endian(big)
#  define z8530reg0	unsigned cmd:8; unsigned :24
#  define z8530reg1	unsigned data:8; unsigned :24
# endif
# if #endian(little)
#  define z8530reg0	unsigned :24; unsigned cmd:8
#  define z8530reg1	unsigned :24; unsigned data:8
# endif
#endif
