
/*****************************************************************************
* Copyright (c) 2004 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
*
*****************************************************************************/


#include <assert.h>
#include <fwtypes.h>
#include <nagpio.h>
#include <gpioplatform.h>
#include <processorgpio.h>
#include <i2c_gpio.h>
#include <i2c_rawapi.h>
#include "serialgpio.h"
#include <gpiomux_def.h>
#include "gpio.h"

NASerialGpioTable_t naSerialGpioTable = {
    // FOR PROCESSOR_GPIO: pin, serial_mode, gpio_type
    { // UART A
      // This port is not used on this platform
      // Refer to this line in gpio.h:
      //#define BSP_GPIO_MUX_SERIAL_A                       BSP_GPIO_MUX_INTERNAL_USE_ONLY
#if IS_2_WIRE_UART(BSP_GPIO_MUX_SERIAL_A)
        {  7, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // TXD
        {  3, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RXD
#else
        {  0, 0, GPIO_TYPE_NONE },   // TXD
        {  0, 0, GPIO_TYPE_NONE },   // RXD
#endif
#if IS_4_WIRE_UART(BSP_GPIO_MUX_SERIAL_A)
        {  5, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RTS
        {  1, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // CTS
#else
        {  0, 0, GPIO_TYPE_NONE },   // RTS
        {  0, 0, GPIO_TYPE_NONE },   // CTS
#endif
#if IS_6_WIRE_UART(BSP_GPIO_MUX_SERIAL_A)
        {  6, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DTR
        {  2, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DSR
#else
        {  0, 0, GPIO_TYPE_NONE },   // DTR
        {  0, 0, GPIO_TYPE_NONE },   // DSR
#endif
#if IS_8_WIRE_UART(BSP_GPIO_MUX_SERIAL_A)
        {  0, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DCD
        {  4, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RI
#else
        {  0, 0, GPIO_TYPE_NONE },   // DCD
        {  0, 0, GPIO_TYPE_NONE },   // RI
#endif
    },
    { // UART B
      // Refer to this line in gpio.h:
      //#define BSP_GPIO_MUX_SERIAL_B                          BSP_GPIO_MUX_SERIAL_8_WIRE_UART_USE_ALTERNATE_PATH
#if IS_2_WIRE_UART(BSP_GPIO_MUX_SERIAL_B)
        { 23, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // TXD
        { 19, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RXD
#elif IS_2_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_B)
        { 58, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // TXD
        { 54, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RXD
#else
        {  0, 0, GPIO_TYPE_NONE },   // TXD
        {  0, 0, GPIO_TYPE_NONE },   // RXD
#endif
#if IS_4_WIRE_UART(BSP_GPIO_MUX_SERIAL_B)
        { 21, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RTS
        { 17, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // CTS
#elif IS_4_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_B)
        { 56, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RTS
        { 52, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // CTS
#else
        {  0, 0, GPIO_TYPE_NONE },   // RTS
        {  0, 0, GPIO_TYPE_NONE },   // CTS
#endif
#if IS_6_WIRE_UART(BSP_GPIO_MUX_SERIAL_B)
        { 22, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DTR
        { 18, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DSR
#elif IS_6_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_B)
        { 57, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DTR
        { 53, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DSR
#else
        {  0, 0, GPIO_TYPE_NONE },   // DTR
        {  0, 0, GPIO_TYPE_NONE },   // DSR
#endif
#if IS_8_WIRE_UART(BSP_GPIO_MUX_SERIAL_B)
        { 24, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DCD
        { 20, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RI
#elif IS_8_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_B)
        { 51, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DCD
        { 55, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RI
#else
        {  0, 0, GPIO_TYPE_NONE },   // DCD
        {  0, 0, GPIO_TYPE_NONE },   // RI
#endif
    },
    { // UART C
      // This port is not used on this platform
      // Refer to this line in gpio.h:
      //#define BSP_GPIO_MUX_SERIAL_C                BSP_GPIO_MUX_INTERNAL_USE_ONLY
#if IS_2_WIRE_UART(BSP_GPIO_MUX_SERIAL_C)
        {  15, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // TXD
        {  11, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RXD
#else
        {  0, 0, GPIO_TYPE_NONE },   // TXD
        {  0, 0, GPIO_TYPE_NONE },   // RXD
#endif
#if IS_4_WIRE_UART(BSP_GPIO_MUX_SERIAL_C)
        {  13, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RTS
        {  9, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // CTS
#else
        {  0, 0, GPIO_TYPE_NONE },   // RTS
        {  0, 0, GPIO_TYPE_NONE },   // CTS
#endif
#if IS_6_WIRE_UART(BSP_GPIO_MUX_SERIAL_C)
        {  14, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DTR
        {  10, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DSR
#else
        {  0, 0, GPIO_TYPE_NONE },   // DTR
        {  0, 0, GPIO_TYPE_NONE },   // DSR
#endif
#if IS_8_WIRE_UART(BSP_GPIO_MUX_SERIAL_C)
        {  8, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DCD
        {  12, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RI
#else
        {  0, 0, GPIO_TYPE_NONE },   // DCD
        {  0, 0, GPIO_TYPE_NONE },   // RI
#endif
    },
    { // UART D
      // Refer to this line in gpio.h:
      //#define BSP_GPIO_MUX_SERIAL_D                          BSP_GPIO_MUX_SERIAL_8_WIRE_UART_USE_ALTERNATE_PATH
#if IS_2_WIRE_UART(BSP_GPIO_MUX_SERIAL_D)
        { 31, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // TXD
        { 27, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RXD
#elif IS_2_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_D)
        { 66, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // TXD
        { 62, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RXD
#else
        {  0, 0, GPIO_TYPE_NONE },   // TXD
        {  0, 0, GPIO_TYPE_NONE },   // RXD
#endif
#if IS_4_WIRE_UART(BSP_GPIO_MUX_SERIAL_D)
    #if (BSP_GPIO_MUX_DATA_BUS_WIDTH == BSP_GPIO_MUX_DATA_BUS_WIDTH_32)
        #error GPIO pin 28 has been configured for more than one function.
        #error (BSP_GPIO_MUX_DATA_BUS_WIDTH == BSP_GPIO_MUX_DATA_BUS_WIDTH_32) and (IS_4_WIRE_UART(BSP_GPIO_MUX_SERIAL_D)) cannot both be true in gpio.h.
    #endif
    #if (BSP_GPIO_MUX_IOP_1_GEN_IO_2 == BSP_GPIO_MUX_USE_PRIMARY_PATH)
        #error GPIO pin 28 has been configured for more than one function.
        #error (IS_4_WIRE_UART(BSP_GPIO_MUX_SERIAL_D) and (BSP_GPIO_MUX_IOP_1_GEN_IO_2 == BSP_GPIO_MUX_USE_PRIMARY_PATH) cannot both be true in gpio.h.
    #endif
        { 29, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RTS
        { 24, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // CTS
#elif IS_4_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_D)
        { 64, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RTS
        { 60, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // CTS
#else
        {  0, 0, GPIO_TYPE_NONE },   // RTS
        {  0, 0, GPIO_TYPE_NONE },   // CTS
#endif
#if IS_6_WIRE_UART(BSP_GPIO_MUX_SERIAL_D)
        { 30, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DTR
        { 26, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DSR
#elif IS_6_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_D)
        { 65, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DTR
        { 61, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DSR
#else
        {  0, 0, GPIO_TYPE_NONE },   // DTR
        {  0, 0, GPIO_TYPE_NONE },   // DSR
#endif
#if IS_8_WIRE_UART(BSP_GPIO_MUX_SERIAL_D)
        { 24, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DCD
        { 28, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RI
#elif IS_8_WIRE_UART_USE_ALTERNATE_PATH(BSP_GPIO_MUX_SERIAL_D)
        { 59, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // DCD
        { 63, NA_GPIO_FUNC0_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RI
#else
        {  0, 0, GPIO_TYPE_NONE },   // DCD
        {  0, 0, GPIO_TYPE_NONE },   // RI
#endif
#if (IS_8_WIRE_UART(BSP_GPIO_MUX_SERIAL_D) || IS_6_WIRE_UART(BSP_GPIO_MUX_SERIAL_D) || IS_4_WIRE_UART(BSP_GPIO_MUX_SERIAL_D))
        { 28, NA_GPIO_FUNC1_STATE, GPIO_TYPE_PROCESSOR_PIN },   // RTS_FIX
#else
        {  0, 0, GPIO_TYPE_NONE },   // RTS_FIX
#endif
    },
};
