/******************************************************************************
 *
 *                                    GX32ED (LX32)
 *
 * This module contains the constants which define the GX32ED board.
 *
 * NOTE: It should not contain definition of any variables, since it is 
 *       included by the drivers too!
 *
 * History:
 *   +----------+------------+------------------------------------------------+
 *   |   Date   |     by     |     Description                                |
 *   +----------+------------+------------------------------------------------+
 *   |          | Coby       | Written                                        |
 *   +----------+------------+------------------------------------------------+
 *
 *****************************************************************************/




/*-----------------------------------------------------------------------------
 * 
 *  The following definition are used in CMON.
 *  They MUST apear in any board definition file.
 *
 *---------------------------------------------------------------------------*/
 
#define CPU_TYPE NS32GX32
#define FPU_TYPE NS32381
#define MMU_TYPE NS32082
#define ICU_TYPE NS32202
#   define BUSWIDTH     4           /* bytes */
#   define ROM_BUSWIDTH 1
#define MON_NAME "CMONGX32E"
#define VERSION  "4"
#define REVISION "4"
#   define BOARD GX32ED

#define UART_TYPE      NS16550
#define UART_0_ADDR    0xFF300008
#define UART_1_ADDR    0xFF300000
#   define UART0_INT       9
#   define UART1_INT       10
#define SERIAL_FILE    "ns16550.h"

#   define ICU_ADDR       0xFFFFFE00

#define LAN_IOBASE  0xA2000300
#define MAXRETRY    160000	    /* Max retries for packet reception */



#define   ROM_START 0x10000000  /* begin address of rom */
#   define   ROM_SIZE  0x8000


/*----------------------------------------------------------------------------
 * C macroes
 *--------------------------------------------------------------------------*/

/*
 * Usage of dip switch for burned monitor according to the monitor manual
 * for debuged monitor switch D8  == ON SERIAL  9600
 *                            D8  == OFF THICK ETHERNET
 */


#ifndef	DEBUG
#   define BOARD_COM_MODE  ((((DIP_VAL & 0xe0) == 0) OR \
			     ((DIP_VAL & 0xe0) == 0x80)) ?  LAN : RS232)
#else
#   define BOARD_COM_MODE  ((DIP_VAL & 1) ? LAN : RS232)
#endif 


#ifndef	DEBUG
#   define ETHERNET_TYPE    (NOT (DIP_VAL & 0x80))
#else
#   define ETHERNET_TYPE   1
#endif


#   define DEMO_ON          (0)  /* Temporary */
#   define DEMO_ADDR        0x10008000



/*-----------------------------------------------------------------------------
 *  Assembly macroes
 *---------------------------------------------------------------------------*/
 
#define TURN_OFF_SHADOW	    movd	$BD_CTRL_ADD, r0;	\
			    cbitb	$0, 0(r0);      \
			    cbitb	$0,@MIO_OUT_ADD;


#define JMP_TO_DIAGNOS	bne _start_pu__


/*
 *  Baud rate conversion table.  Setting of SW1 bits 0-3 serve
 *  as index into table.  Table holds value to be loaded into 
 *  divisor latches.  UART master clock =       MHz.
 *  divisor # = (Frequency input) / baud-rate * 16
 *
 *  The setting of '0000' in the least significant bits of the
 *  configuration switch is a special case.  This will indicate
 *  that the ethernet board is active and the two serial channels
 *  are set for 9600 baud operation.
 */

#   define UART_INIT_TABLE const uart_table_entry uart_table[] = \
                            { {9600,  120} \
                            ,  {9600,  120} \
                            ,  {38400,  30}\
                            ,  {2400,  480}\
                            ,  {9600,  120} \
                            ,  {4800,  240}\
                            ,  {19200,  60}\
                            ,  {1200,  920}\
                            ,  {0,  0} };
#ifndef	DEBUG
#   define UART_DIVISOR  uart_table[ \
                            ((((unsigned int) DIP_VAL) & 0xe0) >> 5)].divisor
#else
#   define UART_DIVISOR  120
#endif
				   

/****************************************************************************
 *
 * Diagnostic macros and definitions 
 *  This part is  ifdefed DIAG 
 *
 ****************************************************************************/

#       define INIT_LCD
#       define PRINT_LCD(str)     /* macro to output string to LCD or alike. */

/**************************************************************************
 *
 * initialized const data definitions
 *
 *************************************************************************/
/*-----------------------------------------------------------------------------
 * Diagnostic macros and definitions 
 *  This part is  ifdefed DIAG 
 *---------------------------------------------------------------------------*/
#ifdef DIAG_MAIN

extern  char *test_cpu__(),  *test_16550__(),  *test_eprom__(),  
             *test_dram__(), *test_icu__(),  *test_fpu__(),  
             *test_led__();

const struct diag_desc diag_test_list__[] = {
                        {" CPU TEST",          test_cpu__,	TRUE}, 
                        {" DRAM TEST",         test_dram__,	TRUE},
                        {" SERIAL I/O TEST",   test_16550__,	TRUE},
                        {" ICU TEST",          test_icu__,	TRUE}, 
                        {" FPU TEST",          test_fpu__,	TRUE}, 
                        {" EPROM TEST",        test_eprom__,	TRUE},
                        {" LED TEST",          test_led__,	FALSE}, 
                        {0,   0,   0}
                       };
#endif


/*----------------------------------------------------------------------------
 *
 * On board Address regions
 *
 *---------------------------------------------------------------------------*/
 
/*
 *  start of I/O 
 */
#define   S_IO       0xFF000000


/*
 *  start of engine I/O 
 */
#define   S_ENG      0xE8000000  


/*
 *  start of interrupt control 
 */
#define   S_INT_CTL  0xFFFFFE00


/*
 *  DMA controller register (8b),32bits 
 */
#define   DMA_CTRL  (*((volatile byte *) 0xB0000000))  


 
/*
 *  start of SCSI data reg. (1Mb) 
 */
#define   SCSI_D            0xFF000000


/*
 *  start of SCSI end-of-transfer 
 */
#define   SCSI_EOP           0xFF100000	


/*
 *  start of SCSI ctrl. reg. (8b) 
 */
#define   SCSI_C             0xFF180000	


/*
 *  start of RTC registers (32b) 
 */
#define   RTC                0xFF200000	


/*
 *  start of DUART registers (16b) 
 */
#define   MIO_IN             0xFF800000	



/*
 *  start of AT bus I/O space 
 */
#define   AT_BUS_IO          0xFF700000	


/*---------------------------------------------------------------------------
 *  misc. I/O in register 
 *--------------------------------------------------------------------------*/


#define	    DUART_ADD	    0xFF300000
#define   DUART             (*((volatile byte *) DUART_ADD))	       



/*
 *  misc. I/O out register 
 */
#define   MIO_OUT_ADD	    0xFF900000
#define   MIO_OUT           (*((volatile byte *) MIO_OUT_ADD))	


/*
 *  configuration dip switch 
 */
#define   DIP_SWITCH_ADD	0xFFA00000
#define   DIP_VAL        (*((volatile byte *) DIP_SWITCH_ADD))       
#ifdef DIAG
        /* Work around LX Dip-Switch BUG */
#define DIP_SWITCH (byte) reverse_bits((volatile byte *) DIP_SWITCH_ADD,  8)
#else     /* Cmon */
#define   DIP_SWITCH    DIP_VAL
#endif

/*
 *  Centronics status 
 */
#define   CENT_STATUS_ADD	0xFFB00000
#define   CENT_STATUS       (*((volatile byte *) CENT_STATUS_ADD))	


/*
 *  Centronics data 
 */
#define   CENT_DATA_ADD	    0xFFC00000
#define   CENT_DATA         (*((volatile byte *) CENT_DATA_ADD))	


/*
 *  Board Control Register 
 */
#define   BD_CTRL_ADD	    0xFFD00000
#define   BD_CTRL           (*((volatile byte *) BD_CTRL_ADD))	


/*
 *  seven segment LED 
 */
#define   LED_PORT_ADD	    0xFFE00000
#define   LED_PORT          (*((volatile byte *) LED_PORT_ADD))	


/*
 *  console (uart 1) 
 */
#define   UART0_ADD	0xFF300008


/*
 *  tty     (uart 2) 
 */
#define   UART1_ADD	0xFF300000



/*----------------------------------------------------------------------------
 *
 * Board intialization and interface  macros.
 *
 *---------------------------------------------------------------------------*/


#ifdef ASEM
#define LED(X)      movb        $(X),  @LED_PORT_ADD
#else
#define LED(X)	LED_PORT = (X)
#endif

#define  LED_0     0x81-0x80
#define  LED_1     0xCF-0x80
#define  LED_2     0x92-0x80
#define  LED_3     0x86-0x80
#define  LED_4     0xCC-0x80
#define  LED_5     0xA4-0x80
#define  LED_6     0xA0-0x80
#define  LED_7     0x8F-0x80
#define  LED_8     0x80-0x80
#define  LED_9     0x84-0x80
#define  LED_A     0x88-0x80
#define  LED_B     0xE0-0x80
#define  LED_C     0xB1-0x80
#define  LED_D     0xC2-0x80
#define  LED_E     0xB0-0x80
#define  LED_P     0x98-0x80
#define  LED_F     0xB8-0x80


