/*
 *            Copyright (c) 1998-2002 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 227                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************
 *
 *     Module Name: devices.c
 *         Version: 1.00
 *   Original Date: 09/20/99
 *	    	Author: Charles Gordon
 *        Language: Ansi C
 * Compile Options:
 * Compile defines:
 *       Libraries:
 *    Link Options:
 *
 *    Entry Points:	DDIFirstLevelInitialize ()
 *					DDISecondLevelInitialize ()
 *
 * Description.
 * =======================================================================
 * This file contains the declaration for deviceTable.  This array
 * contains a list of all NET+OS devices.
 *
 *
 * Edit Date/Ver   Edit Description
 * ==============  =======================================================
 * NGUR 03/27/01   Add support for "Serila perepheral Interface" (SPI)
 *                 You can specify ether RS-232 driver or SPI driver
 *                 but not both.
 *
 * DXL	04/16/02   Cleaned up variable declared but never reference warnings generated by new compiler
 * DXL	08/14/02 	Relocated DDIFirstLevelInitialize () and DDISecondLevelInitialize () here
 * JZW  02/23/04   In the array of devices moves the comma from
 *                 the beginning of each element to the end. Thus
 *                 if an element is excluded, will not cause
 *                 a compiler error
 *
 */

#include <ddi.h>
#include <serlDev.h>
#include <spiDev.h>
#include <nuldev.h>
#include <lpbkdev.h>
#include <paradev.h>
#include <stddef.h>
#include "bsp.h"
#include "udpdb.h"


/*
 * This table lists all the devices in the system.  New devices can be added by
 * editing this table.  All BSP_INCLUDE_xxx_DRIVER are defined in bsp_api.h file
 * Each device has its own enter, init, open, close, read, write and ioctl functions
 * to be implemented when needed.
 */

deviceInfo deviceTable[] =
{
#if BSP_INCLUDE_NUL_DRIVER
    {                                       /* the NULL device */
        "/nul/0",
        0,
        nul_enter,
        nul_init,
        nul_open,
        nul_close,
        NULL,
        nul_read,
        nul_write,
        nul_ioctl,
        (unsigned)-1
    }
    ,
#endif
#if BSP_INCLUDE_LOOPBACK_DRIVER
    {
        "/loopback/0",                      /* the loopback device */
        0,
        loopback_enter,
        loopback_init,
        loopback_open,
        loopback_close,
        NULL,
        loopback_read,
        loopback_write,
        loopback_ioctl,
        (unsigned)-1
    }
    ,
#endif
#if (BSP_SERIAL_PORT_1 == BSP_SERIAL_UART_DRIVER)
    {
        "/com/0",                           /* serial port 1 */
        0,
        netos_serlenter,
        netos_serlinit,
        netos_serlopen,
        netos_serlclose,
        NULL,
#if (BSP_SERIAL_PORT_API == BSP_SERIAL_API_TERMIOS)
        netos_serlread,
#else
	oldapi_serlread,
#endif
        netos_serlwrite,
#if (BSP_SERIAL_PORT_API == BSP_SERIAL_API_TERMIOS)
        netos_serlioctl,
#else
	oldapi_serlioctl,
#endif
        (unsigned)-1
    }
    ,
#elif (BSP_SERIAL_PORT_1 == BSP_SERIAL_SPI_DRIVER)
    {
        "/com/0",                           /* SPI port 1 */
        0,
        netos_spienter,
        netos_spiinit,
        netos_spiopen,
        netos_spiclose,
        NULL,
        netos_spiread,
        netos_spiwrite,
        netos_spiioctl,
        (unsigned)-1
    }
    ,
#endif
     
#if (BSP_SERIAL_PORT_2 == BSP_SERIAL_UART_DRIVER)
    {
        "/com/1",                           /* serial port 2 */
        1,
        netos_serlenter,
        netos_serlinit,
        netos_serlopen,
        netos_serlclose,
        NULL,
#if (BSP_SERIAL_PORT_API == BSP_SERIAL_API_TERMIOS)
        netos_serlread,
#else
	oldapi_serlread,
#endif
        netos_serlwrite,
#if (BSP_SERIAL_PORT_API == BSP_SERIAL_API_TERMIOS)
        netos_serlioctl,
#else
	oldapi_serlioctl,
#endif
        (unsigned)-1
    } 
    ,
#elif (BSP_SERIAL_PORT_2 == BSP_SERIAL_SPI_DRIVER)

    {
        "/com/1",                           /* SPI port 2 */
        1,
        netos_spienter,
        netos_spiinit,
        netos_spiopen,
        netos_spiclose,
        NULL,
        netos_spiread,
        netos_spiwrite,
        netos_spiioctl,
        (unsigned)-1
    }
    ,
#endif /* Serial or SPI driver */
#if BSP_INCLUDE_PARALLEL_DRIVER
    {
        "/lpt/0",                           /* parallel port 1 */
        0,
        para_enter,
        para_init,
        para_open,
        para_close,
        NULL,
        para_read,
        para_write,
        para_ioctl,
        (unsigned)-1
    },
    {
        "/lpt/1",                           /* parallel port 2 */
        1,
        para_enter,
        para_init,
        para_open,
        para_close,
        NULL,
        para_read,
        para_write,
        para_ioctl,
        (unsigned)-1
    }
    ,
#endif
#if BSP_INCLUDE_UDP_DEBUG_DRIVER
    {
        UDPDB_DEV,
        0,
        udpdb_enter,
        udpdb_init,
        udpdb_open,
        udpdb_close,
        NULL,
        udpdb_read,
        udpdb_write,
        udpdb_ioctl,
        (unsigned)-1
    }
#endif
};


int MAX_DEV = (sizeof (deviceTable) / sizeof (deviceInfo));


/*
 *
 *  Function: void DDIFirstLevelInitialize(void)
 *
 *  Description:
 *
 *      This routine is called just after a reset has been completed
 *      and the ASIC hardware is initialized to call the device
 *      driver initialization routines.  No kernel services will be
 *      available at this point.  The only thing the device drivers
 *      normally do is to initialize some hardware (if necessary).
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void DDIFirstLevelInitialize(void)
{
	int i;

    NAT2Init();                         /* setup AUX clock used by some drivers*/

	for (i=0; i < MAX_DEV; i++)         /* walk through the device table*/
	{
		if (deviceTable[i].enter)       /* if an enter routine is defined*/
		{                               /* call it*/
			(*deviceTable[i].enter)(deviceTable[i].channel);
		}
	}
}

/*
 *
 *  Function: void DDISecondLevelInitialize(void)
 *
 *  Description:
 *
 *      This routine is called after the kernel scheduler has loaded
 *      to call each device driver's initialization routines.  At this
 *      point all kernel services (except other device drivers) are
 *      available.
 *
 *  Parameters:
 *
 *      none
 *
 *  Return Values:
 *
 *      none
 *
 */

void DDISecondLevelInitialize(void)
{
	int i;
	for (i=0; i < MAX_DEV; i++)             /* walk through the device table*/
	{
		if (deviceTable[i].init)            /* if device has init routine*/
		{                                   /* call it*/
			(*deviceTable[i].init)(deviceTable[i].channel);
		}
	}
}
