/*
 *  Copyright (c) 1996-2007 Digi International Inc., All Rights Reserved
 *
 *  This software contains proprietary and confidential information of Digi
 *  International Inc.  By accepting transfer of this copy, Recipient agrees
 *  to retain this software in confidence, to prevent disclosure to others,
 *  and to make no use of this software other than that for which it was
 *  delivered.  This is an unpublished copyrighted work of Digi International
 *  Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 *  prohibited.
 *
 *  Restricted Rights Legend
 *
 *  Use, duplication, or disclosure by the Government is subject to
 *  restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 *  Technical Data and Computer Software clause at DFARS 252.227-7031 or
 *  subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 *  Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 *  Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
 *
 * 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
 *
 */

#include <ddi.h>
#include <serlDev.h>
#include <spiDev.h>
#include <nuldev.h>
#include <lpbkdev.h>
#include <paradev.h>
#include <stddef.h>
#include <narmbrd.h>
#include <bsp_drivers.h>
#include <bsp_serial.h>
#include <bsp_iop.h>
#include <udpdb.h>
#include <gdb.h>
#include <onewire_api.h>

#ifdef BSP_ARM9
#if BSP_INCLUDE_PCI_DRIVER
#include <pcidev.h>
#endif
#if BSP_INCLUDE_LCD_DRIVER
#include <lcd.h>
#endif
#if BSP_INCLUDE_USB_DRIVER
#include <usb_ddi.h>
#endif
#ifdef ONET9701
#if BSP_INCLUDE_PRINT_ENGINE_DRIVER
#include <pedev.h>
#endif
#endif
#endif

#if (BSP_SERIAL_PORT_API == BSP_SERIAL_API_TERMIOS)
#define uart_serlopen   netos_serlopen
#define uart_serlioctl  netos_serlioctl
#define uart_serlread   netos_serlread
#else
#define uart_serlopen   oldapi_serlopen
#define uart_serlioctl  oldapi_serlioctl
#define uart_serlread   oldapi_serlread
#endif


/*
 * 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.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,
        (unsigned long)-1,
        FALSE,
        NULL
    },
#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,
        (unsigned long)-1,
        FALSE,
        NULL
    },
#endif

#if (BSP_SERIAL_PORT_1 == BSP_SERIAL_UART_DRIVER)
    {
        "/com/0",                           /* serial port 1 */
        0,
        netos_serlenter,
        netos_serlinit,
        uart_serlopen,
        netos_serlclose,
        NULL,
        uart_serlread,
        netos_serlwrite,
        uart_serlioctl,
        (unsigned)-1,
        (unsigned long)-1,
        TRUE,
        netos_serlpoll
    },
#endif /* Serial or SPI driver */

#if (BSP_SERIAL_PORT_3 == BSP_SERIAL_UART_DRIVER)
    {
        "/com/2",                           /* serial port 3 */
        2,
        netos_serlenter,
        netos_serlinit,
        uart_serlopen,
        netos_serlclose,
        NULL,
        uart_serlread,
        netos_serlwrite,
        uart_serlioctl,
        (unsigned)-1,
        (unsigned long)-1,
        TRUE,
        netos_serlpoll
    },
#endif /* Serial or SPI driver */

    {
        "/com/4",           /* serial port 5, FIM0 */
        0,
        NULL,
        iop_serlinit,
        iop_serlopen,
        iop_serlclose,
        NULL,
        iop_serlread,
        iop_serlwrite,
        iop_serlioctl,
        (unsigned)-1,
        (unsigned long)-1,
        TRUE,
        iop_serlpoll
    },

    {
        "/1-wire/0",
        0,
        NULL,
        NULL,
        na1wireOpen,
        na1wireClose,
        NULL,
        na1wireRead,
        na1wireWrite,
        na1wireIoctl,
        (unsigned)-1,
        (unsigned long)-1,
        TRUE,
        NULL
    },

    {
        "/1-wire/1",
        1,
        NULL,
        NULL,
        na1wireOpen,
        na1wireClose,
        NULL,
        na1wireRead,
        na1wireWrite,
        na1wireIoctl,
        (unsigned)-1,
        (unsigned long)-1,
        TRUE,
        NULL
    },

#if (BSP_INCLUDE_UDP_DEBUG_DRIVER == TRUE)
    {
        UDPDB_DEV,
        0,
        udpdb_enter,
        udpdb_init,
        udpdb_open,
        udpdb_close,
        NULL,
        udpdb_read,
        udpdb_write,
        udpdb_ioctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
#endif

#ifdef BSP_ARM9
#if BSP_INCLUDE_LCD_DRIVER
	{
        "/display/0",                           /* display 0 */
        0,
        NULL,
        NULL,
        lcd_dev_open,
        lcd_dev_close,
        NULL,
        lcd_dev_read,
        lcd_dev_write,
        lcd_dev_ioctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },

#endif

#if BSP_INCLUDE_USB_DRIVER
    {
        "/usb/0",                           /* usb dev dma0 */
        0,
        usb_dev_enter,
        usb_dev_init,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        usb_dev_ioctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/1",                           /* usb dev dma1 */
        1,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        usb_dev_ioctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/2",                           /* usb dev dma 2 */
        2,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/3",                           /* usb dev dma 3 */
        3,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/4",                           /* usb dev dma 4 */
        4,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/5",                           /* usb dev dma 5 */
        5,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/6",                           /* usb dev dma 6 */
        6,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/7",                           /* usb dev dma 7 */
        7,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/8",                           /* usb dev dma 8 */
        8,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/9",                           /* usb dev dma 9 */
        9,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/10",                           /* usb dev dma 10 */
        10,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/11",                           /* usb dev dma 11 */
        11,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/usb/12",                           /* usb dev dma 12 */
        12,
        NULL,
        NULL,
        usb_dev_open,
        usb_dev_close,
        NULL,
        usb_dev_read,
        usb_dev_write,
        NULL,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
#endif
#if BSP_INCLUDE_PCI_DRIVER
    {
        "/pci/0",                           /* local AHB-to-PCI Bridge Device   */
        0,
        NULL,
        pciInit,
        pciLocalOpen,
        pciClose,
        NULL,
        pciRead,
        pciWrite,
        pciIoctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/pci/1",                           /* external pci device #1 */
        1,
        NULL,
        NULL,
        pciRemoteOpen,
        pciClose,
        NULL,
        pciRead,
        pciWrite,
        pciIoctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/pci/2",                           /* external pci device #1 */
        2,
        NULL,
        NULL,
        pciRemoteOpen,
        pciClose,
        NULL,
        pciRead,
        pciWrite,
        pciIoctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
    {
        "/pci/3",                           /* external pci device #1 */
        3,
        NULL,
        NULL,
        pciRemoteOpen,
        pciClose,
        NULL,
        pciRead,
        pciWrite,
        pciIoctl,
        (unsigned)-1,
        (unsigned long)-1,
        FALSE,
        NULL
    },
#endif
#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);
		}
	}
}
