/******************************************************************************
 *
 *	CG16ED  DEFINTION FILE
 *
 * @(#)Copyright (C) 1991 National Semiconductor Corp.
 *
 * This module contains the constants which define the CG16ED board.
 *
 * NOTE: It should not contain definition of any variables, since it is 
 *       included by the drivers too!
 *
 * History:
 *   +----------+------------+------------------------------------------------+
 *   |   Date   |     by     |     Description                                |
 *   +----------+------------+------------------------------------------------+
 *   |          | Lior       | Written                                        |
 *   +----------+------------+------------------------------------------------+
 *
 *****************************************************************************/



/****************************************************************************
 *
 *  The following definition are used in CMON.
 *  They MUST apear in any board definition file.
 *
 ****************************************************************************/
 
#   define CPU_TYPE NS32CG16
#   define FPU_TYPE NS32381
#   define ICU_TYPE NS32202
#   define BUSWIDTH	2	    /* 16 bytes */
#   define ROM_BUSWIDTH	2
#   define MON_NAME "CMONCG16"
#   define VERSION  "4"
#   define REVISION "4"
#   undef  BOARD
#   define BOARD CG16ED


#   define UART_TYPE      NS16550
#   define UART_0_ADDR    0xF40020
#   define UART_1_ADDR    0xC003F8
#   define UART0_INT       4
#   define SERIAL_FILE    "ns16550.h"
#   define ICU_ADDR       0xFFFE00
#   define ICU_BUS_WIDTH     2
#   define ONE_UART
#   define UART_BUS_OFFSET   2

#define LAN_IOBASE  0xc00300
#define MAXRETRY    40000          /* Max retries for packet reception */

#   define   ROM_START 0x800000  /* begin address of rom */
#   define   ROM_SIZE  0x8000	   /*  for 32k EPROMs  */


#   define DEMO_ON          (DIP_SWITCH_EXIST && BIT_ON(6, DIP_SWITCH)) 
#   define DEMO_ADDR        0x820000

#   define   STATUS_JUMPER_ADD	0xF40060
#   define   CTLL	0xf400e0	/* Control latch register */
/****************************************************************************
 *
 *  Assembly macroes
 *
 ****************************************************************************/

#ifdef ASEM
.macro TURN_OFF_SHADOW
 #
 #      Control latch (CTLL) Bit definitions
 #
 #      All CTTL bits are cleared by hardware reset to the ASSERTED
 #      state.  Writing to 1 to a bit location DE-ASSERTs that function
 #
        .set    DRAM_ML , b'000001
        .set    SHADOW  , b'000010
        .set    DS5     , b'000100
        .set    DS4     , b'001000
        .set    DS3     , b'010000
        .set    DS2     , b'100000

 #
 #      CG821 DRAM Controller programming words
 #
        .set    M256K0W , 0x4F501C       #256K Sticks,  0 wait RAM
        .set    M256K1W , 0x4F50BC       #256K Sticks,  1 wait RAM
        .set    M1M0W   , 0x37501C       #1M Sticks,  0 wait RAM
        .set    M1M1W   , 0x3750BC       #1M Sticks,  1 wait RAM
        .set    CG821   , M1M0W


reset:  br      reset1
dramtbl:
        .double M256K0W, M1M0W, M256K1W, M1M1W	
reset1:	
        movb    $(DS2 + SHADOW), @CTLL   #Turn off DS2 and Shadowing
        movzbd  @STATUS_JUMPER_ADD, r0   #Get the jumper setting
        andb    $3, r0                   #mask off unwanted bits
        movd    dramtbl[r0:d], r0        #get the CG821 setup from dramtbl
        movqb   $0, 0(r0)                #Program CG821 DRAM Controller
        movb    $(DS2 + SHADOW + DRAM_ML), @CTLL
        addr    2000, r0         # wait for 2 milliseconds
        acbd    -1, r0, .        # to allow dram to stabilize
        addr    1000, r0         # do 1000 reads and writes
rlp1:   movw    0(r0), 0(r0)     # do the operation
        acbd    -1, r0, rlp1     # to get the ram going

.endm

#endif

#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 DIP_SWITCH_EXIST	((STATUS_JUMPER & 0xc) == 4)

#ifndef DEBUG
#   define BOARD_COM_MODE  (DIP_SWITCH_EXIST ? ( ((DIP_SWITCH & 0x7) <= 0x1) ? LAN : RS232) :	((STATUS_JUMPER & 0xc) != 0xc) ? LAN : RS232)

#   define ETHERNET_TYPE    (DIP_SWITCH_EXIST ? (NOT (DIP_SWITCH & 0x1)) : \
				(STATUS_JUMPER & 0xc) == 0 ? 0 : 1)
#   define UART_DIVISOR  (  DIP_SWITCH_EXIST ? uart_table[ \
                            ((unsigned int) DIP_SWITCH) & 0x7].divisor : \
			    BAUD_9600)
#else
#   define BOARD_COM_MODE  (DIP_SWITCH_EXIST ? ((DIP_SWITCH & 0x1) == 0x1) ? LAN : RS232 :	RS232)
#   define ETHERNET_TYPE   1
#   define UART_DIVISOR   52
#endif
 
#   define UART_INIT_TABLE const uart_table_entry uart_table[] = \
                            { {9600, 52} \
			    , {9600, 52} \
			    , {38400, 13}\
			    , {19200, 26}\
			    , {9600, 52} \
			    , {4800, 104}\
			    , {2400, 208}\
			    , {1200, 417}\
			    , {0, 0} }; 

#define BAUD_9600 52
/****************************************************************************
 *
 * Diagnostic macros and definitions 
 *  This part is  ifdefed DIAG 
 *
 ****************************************************************************/


#	define INIT_LCD
#	define PRINT_LCD(str)     /* macro to output string to LCD or alike. */
#	define PRINT_LED(num)     /* macro to output number to 7-SEGMENT-LED */
                                  /* or a like				     */


/**************************************************************************
 *
 * initialized const data definitions
 *
 *************************************************************************/
 
#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 /* DIAG_MAIN */

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

#   define   DIP_SWITCH_ADD	0xF40100 	/* configuration dip switch */
#   define   DIP_SWITCH         (*((volatile byte *) DIP_SWITCH_ADD))	

#   define   STATUS_JUMPER      (*((volatile byte *) STATUS_JUMPER_ADD))

#   define   LED_PORT_ADD	CTLL 	/* five lights LED	    */ 
#   define   LED_PORT           (*((volatile byte *) LED_PORT_ADD))	
    
#   define   IMASK_ADD	        0xF80200    
#   define   IMASK		(* ((volatile byte  *) IMASK_ADD))


/****************************************************************************
 *
 * 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	0x3c            /*       0	*/
#   define    LED_1	0x38            /*       1	*/
#   define    LED_2	0x34            /*       2	*/
#   define    LED_3	0x30            /*       3	*/
#   define    LED_4	0x2c            /*       4	*/
#   define    LED_5	0x28            /*       5	*/
#   define    LED_6	0x24            /*       6	*/
#   define    LED_7	0x20            /*       7	*/
#   define    LED_8	0x1c            /*       8	*/
#   define    LED_9	0x18            /*       9	*/
#   define    LED_A	0x14            /*       A	*/
#   define    LED_B	0x10            /*       B	*/
#   define    LED_C	0x0c            /*       C	*/
#   define    LED_D	0x08            /*       D	*/
#   define    LED_E	0x04            /*       E	*/
#   define    LED_F	0x00            /*       F	*/
#   define    LED_P	0x00            /*       P	*/

