Ejemplo n.º 1
0
static HAL_Status
RtkI2SPinMuxDeInit(
    IN  PHAL_I2S_ADAPTER pI2SAdapter
)
{
    if (pI2SAdapter->DevNum > I2S_MAX_ID) {
        DBG_I2S_ERR("RtkI2SPinMuxDeInit: Invalid I2S Index(&d)\r\n", pI2SAdapter->DevNum);
        return HAL_ERR_PARA;
    }

    switch (pI2SAdapter->DevNum){
        case I2S0_SEL:
            /*I2S0 Pin Mux Setting*/
            //ACTCK_I2C0_CCTRL(OFF);
            PinCtrl(I2S0, pI2SAdapter->PinMux, OFF);
            I2S0_MCK_CTRL(OFF);
            I2S0_PIN_CTRL(OFF);
            //I2S0_FCTRL(OFF);
            
            break;
        case I2S1_SEL:
            /*I2S1 Pin Mux Setting*/
            //ACTCK_I2C1_CCTRL(OFF);
            PinCtrl(I2S1, pI2SAdapter->PinMux, OFF);
            I2S1_MCK_CTRL(OFF);
            I2S1_PIN_CTRL(OFF);
            //I2S1_FCTRL(OFF);
            break;
        default:
            return HAL_ERR_PARA;
    }
    
    return HAL_OK;
}
Ejemplo n.º 2
0
static HAL_Status
RtkI2SPinMuxInit(
    IN  PHAL_I2S_ADAPTER pI2SAdapter
)
{
    u32 I2Stemp;

    if (pI2SAdapter->DevNum > I2S_MAX_ID) {
        DBG_I2S_ERR("RtkI2SPinMuxInit: Invalid I2S Index(&d)\r\n", pI2SAdapter->DevNum);
        return HAL_ERR_PARA;
    }

    // enable system pll
    I2Stemp = HAL_READ32(SYSTEM_CTRL_BASE, REG_SYS_SYSPLL_CTRL1) | (1<<9) | (1<<10);
    HAL_WRITE32(SYSTEM_CTRL_BASE, REG_SYS_SYSPLL_CTRL1, I2Stemp);

    switch (pI2SAdapter->DevNum){
        case I2S0_SEL:
            ACTCK_I2S_CCTRL(ON);
            SLPCK_I2S_CCTRL(ON);
            LXBUS_FCTRL(ON); // enable lx bus for i2s
            
            /*I2S0 Pin Mux Setting*/
            PinCtrl(I2S0, pI2SAdapter->PinMux, ON);
            if (pI2SAdapter->PinMux == I2S_S0) {
                DBG_I2S_WARN(ANSI_COLOR_MAGENTA"I2S0 Pin may conflict with JTAG\r\n"ANSI_COLOR_RESET);
            }
            I2S0_MCK_CTRL(ON);
            I2S0_PIN_CTRL(ON);
            I2S0_FCTRL(ON);
            
            break;
        case I2S1_SEL:
            ACTCK_I2S_CCTRL(ON);
            SLPCK_I2S_CCTRL(ON);
            LXBUS_FCTRL(ON); // enable lx bus for i2s
            
            /*I2S1 Pin Mux Setting*/
            PinCtrl(I2S1, pI2SAdapter->PinMux, ON);
            if (pI2SAdapter->PinMux == I2S_S2) {
                DBG_I2S_WARN(ANSI_COLOR_MAGENTA"I2S1 Pin may conflict with JTAG\r\n"ANSI_COLOR_RESET);
            }
            I2S1_MCK_CTRL(ON);
            I2S1_PIN_CTRL(ON);
            I2S0_FCTRL(ON); //i2s 1 is control by bit 24 BIT_PERI_I2S0_EN
            I2S1_FCTRL(ON);
            break;
        default:
            return HAL_ERR_PARA;
    }
    
    return HAL_OK;
}
Ejemplo n.º 3
0
HAL_Status 
HalRuartInitRtl8195a_Patch(
        IN VOID *Data  ///< RUART Adapter
        )
{
    /* DBG_ENTRANCE; */
    u32 RegValue;
    u32 Divisor;
    u32 Dll;
    u32 Dlm;
    u8 UartIndex;
    s32 ElementIndex;
    RUART_SPEED_SETTING RuartSpeedSetting;
    u8 PinmuxSelect;

    PHAL_RUART_ADAPTER pHalRuartAdapter = (PHAL_RUART_ADAPTER) Data;

    UartIndex = pHalRuartAdapter->UartIndex;
    PinmuxSelect = pHalRuartAdapter->PinmuxSelect;

    if (UartIndex > 2) {
        DBG_UART_ERR(ANSI_COLOR_MAGENTA"HalRuartInitRtl8195a: Invalid UART Index\n"ANSI_COLOR_RESET);
        return HAL_ERR_PARA;
    }

    DBG_UART_INFO("%s==>\n", __FUNCTION__);
    DBG_UART_INFO("HalRuartInitRtl8195a: [UART %d] PinSel=%d\n", UartIndex, PinmuxSelect);
    if(( PinmuxSelect == RUART0_MUX_TO_GPIOE ) && ((UartIndex == 0) || (UartIndex == 1))) {
        // confict with J-Teg pin, so we disable the J-Teg
        DBG_UART_WARN(ANSI_COLOR_MAGENTA"Disable JTAG function due to pin conflict\n"ANSI_COLOR_RESET);
        JTAG_PIN_FCTRL(OFF);
    }

    // switch Pin from EEPROM to UART0
    if(( PinmuxSelect == RUART0_MUX_TO_GPIOC ) && (UartIndex == 0)) {
        RegValue = HAL_READ32(SYSTEM_CTRL_BASE, 0xa4);
        if (RegValue & 0x10) {
            DBG_UART_WARN("Disable EEPROM Pin for UART 0\n");
            HAL_WRITE32(SYSTEM_CTRL_BASE, 0xa4, (RegValue & (~0x10)));
        }
    }

    switch (UartIndex) {
        case 0:
            /* UART 0 */
            ACTCK_UART0_CCTRL(ON);
            SLPCK_UART0_CCTRL(ON);
            PinCtrl(UART0, PinmuxSelect, ON);
            UART0_FCTRL(ON);
            UART0_BD_FCTRL(ON);
            break;

        case 1:
            /* UART 1 */
            ACTCK_UART1_CCTRL(ON);
            SLPCK_UART1_CCTRL(ON);
            PinCtrl(UART1, PinmuxSelect, ON);
            UART1_FCTRL(ON);
            UART1_BD_FCTRL(ON);
            break;

        case 2:
            /* UART 1 */
            ACTCK_UART2_CCTRL(ON);
            SLPCK_UART2_CCTRL(ON);
            PinCtrl(UART2, PinmuxSelect, ON);
            UART2_FCTRL(ON);
            UART2_BD_FCTRL(ON);
            break;

        default:
            DBG_UART_ERR("Invalid UART Index(%d)\n", UartIndex);
            return HAL_ERR_PARA;
    }

    /* Reset RX FIFO */
    HalRuartResetRxFifoRtl8195a(Data);
    DBG_UART_INFO(ANSI_COLOR_CYAN"HAL UART Init[UART %d]\n"ANSI_COLOR_RESET, UartIndex);

    /* Disable all interrupts */
    HAL_RUART_WRITE32(UartIndex, RUART_INTERRUPT_EN_REG_OFF, 0x00);

    /* Set DLAB bit to 1 to access DLL/DLM */
    RegValue = HAL_RUART_READ32(UartIndex, RUART_LINE_CTL_REG_OFF);
    RegValue |= RUART_LINE_CTL_REG_DLAB_ENABLE;
    HAL_RUART_WRITE32(UartIndex, RUART_LINE_CTL_REG_OFF, RegValue);
    DBG_UART_INFO("[R] RUART_LINE_CTL_REG_OFF(0x0C) = %x\n", HAL_RUART_READ32(UartIndex, RUART_LINE_CTL_REG_OFF));

    /* Set Baudrate Division */
#if 1
    ElementIndex = FindElementIndex(pHalRuartAdapter->BaudRate, BAUDRATE);
    if (ElementIndex < 0) {
        ElementIndex = 5;
        DBG_UART_ERR("Invalid BaudRate(%d), Force it as default(%d)\n", pHalRuartAdapter->BaudRate, BAUDRATE[ElementIndex]);
    }

    RuartSpeedSetting.BaudRate = BAUDRATE[ElementIndex];
    RuartSpeedSetting.Ovsr     =     OVSR_PATCH[ElementIndex];
    RuartSpeedSetting.Div      =      DIV_PATCH[ElementIndex];
    RuartSpeedSetting.Ovsr_adj = OVSR_ADJ_PATCH[ElementIndex];
#else
    RuartSpeedSetting.BaudRate = 38400;
    RuartSpeedSetting.Ovsr     = 10;
    RuartSpeedSetting.Div      = 217;
    RuartSpeedSetting.Ovsr_adj = 0x0;
#endif

    DBG_UART_INFO("Baud %d, Ovsr %d, Div %d, OvsrAdj 0x%X\n",
            RuartSpeedSetting.BaudRate,
            RuartSpeedSetting.Ovsr,
            RuartSpeedSetting.Div,
            RuartSpeedSetting.Ovsr_adj
            );
    /* Divisor = (SYSTEM_CLK / ((ovsr + 5 + ovsr_adj/11) * (UartAdapter.BaudRate))); */

    /* Set Divisor */
    Divisor = RuartSpeedSetting.Div;

    Dll = Divisor & 0xFF;
    Dlm = (Divisor & 0xFF00) >> 8;

    DBG_UART_INFO("Calculated Dll, Dlm = %02x, %02x\n", Dll, Dlm);
    DBG_UART_INFO("---- Before setting baud rate ----\n");
    DBG_UART_INFO("  [R] RUART_DLL_OFF(0x00) = %x\n", HAL_RUART_READ32(UartIndex, RUART_DLL_OFF));
    DBG_UART_INFO("  [R] RUART_DLM_OFF(0x04) = %x\n", HAL_RUART_READ32(UartIndex, RUART_DLM_OFF));

    HAL_RUART_WRITE32(UartIndex, RUART_DLL_OFF, Dll);
    HAL_RUART_WRITE32(UartIndex, RUART_DLM_OFF, Dlm);

    DBG_UART_INFO("---- After setting baud rate ----\n");
    DBG_UART_INFO("  [R] RUART_DLL_OFF(0x00) = %x\n", HAL_RUART_READ32(UartIndex, RUART_DLL_OFF));
    DBG_UART_INFO("  [R] RUART_DLM_OFF(0x04) = %x\n", HAL_RUART_READ32(UartIndex, RUART_DLM_OFF));

    DBG_UART_INFO(ANSI_COLOR_CYAN"---- Befor OVSR & OVSR_ADJ ----\n"ANSI_COLOR_RESET);
    RegValue = HAL_RUART_READ32(UartIndex, RUART_SCRATCH_PAD_REG_OFF);
    DBG_UART_INFO("UART%d SPR(0x1C) = %X\n", UartIndex, RegValue);
    RegValue = HAL_RUART_READ32(UartIndex, RUART_STS_REG_OFF);
    DBG_UART_INFO("UART%d SIS(0x20) = %X\n", UartIndex, RegValue);

    /**
      * Clean Rx break signal interrupt status at initial stage.
      */
    RegValue = HAL_RUART_READ32(UartIndex, RUART_SCRATCH_PAD_REG_OFF);
    RegValue |= RUART_SP_REG_RXBREAK_INT_STATUS;
    HAL_RUART_WRITE32(UartIndex, RUART_SCRATCH_PAD_REG_OFF, RegValue);

    /* Set OVSR(xfactor) */
    RegValue = HAL_RUART_READ32(UartIndex, RUART_STS_REG_OFF);
    RegValue &= ~(RUART_STS_REG_XFACTOR);
    RegValue |= (((RuartSpeedSetting.Ovsr - 5) << 4) & RUART_STS_REG_XFACTOR);
    HAL_RUART_WRITE32(UartIndex, RUART_STS_REG_OFF, RegValue);

    /* Set OVSR_ADJ[10:0] (xfactor_adj[26:16]) */
    RegValue = HAL_RUART_READ32(UartIndex, RUART_SCRATCH_PAD_REG_OFF);
    RegValue &= ~(RUART_SP_REG_XFACTOR_ADJ);
    RegValue |= ((RuartSpeedSetting.Ovsr_adj << 16) & RUART_SP_REG_XFACTOR_ADJ);
    HAL_RUART_WRITE32(UartIndex, RUART_SCRATCH_PAD_REG_OFF, RegValue);

    DBG_UART_INFO(ANSI_COLOR_CYAN"---- After OVSR & OVSR_ADJ ----\n"ANSI_COLOR_RESET);
    RegValue = HAL_RUART_READ32(UartIndex, RUART_SCRATCH_PAD_REG_OFF);
    DBG_UART_INFO("UART%d SPR(0x1C) = %X\n", UartIndex, RegValue);
    RegValue = HAL_RUART_READ32(UartIndex, RUART_STS_REG_OFF);
    DBG_UART_INFO("UART%d SIS(0x20) = %X\n", UartIndex, RegValue);

    /* clear DLAB bit */
    RegValue = HAL_RUART_READ32(UartIndex, RUART_LINE_CTL_REG_OFF);
    RegValue &= ~(RUART_LINE_CTL_REG_DLAB_ENABLE);
    HAL_RUART_WRITE32(UartIndex, RUART_LINE_CTL_REG_OFF, RegValue);
    DBG_UART_INFO("[R] RUART_LINE_CTL_REG_OFF(0x0C) = %x\n", HAL_RUART_READ32(UartIndex, RUART_LINE_CTL_REG_OFF));
    DBG_UART_INFO("[R] UART%d INT_EN(0x04) = %x\n", UartIndex, pHalRuartAdapter->Interrupts);
    RegValue = ((pHalRuartAdapter->Interrupts) & 0xFF);
    HAL_RUART_WRITE32(UartIndex, RUART_INTERRUPT_EN_REG_OFF, RegValue);
    DBG_UART_INFO("[W] UART%d INT_EN(0x04) = %x\n", UartIndex, RegValue);

    /* Configure FlowControl */
    if (pHalRuartAdapter->FlowControl == AUTOFLOW_ENABLE) {
        RegValue = HAL_RUART_READ32(UartIndex, RUART_MODEM_CTL_REG_OFF);
        RegValue |= RUART_MCL_AUTOFLOW_ENABLE;
        HAL_RUART_WRITE32(UartIndex, RUART_MODEM_CTL_REG_OFF, RegValue);
    }

    /* RUART DMA Initialization */
    HalRuartDmaInitRtl8195a(pHalRuartAdapter);

    DBG_UART_INFO("[R] UART%d LCR(0x%02X): %X\n", UartIndex, RUART_LINE_CTL_REG_OFF, HAL_RUART_READ32(UartIndex, RUART_LINE_CTL_REG_OFF));
    RegValue = HAL_RUART_READ32(UartIndex, RUART_LINE_CTL_REG_OFF);

    /* PARITY CONTROL */
    RegValue &= BIT_CLR_LCR_WLS;
    RegValue |= BIT_LCR_WLS(pHalRuartAdapter->WordLen);

    RegValue &= BIT_INVC_LCR_STB_EN;
    RegValue |= BIT_LCR_STB_EN(pHalRuartAdapter->StopBit);

    RegValue &= BIT_INVC_LCR_PARITY_EN;
    RegValue |= BIT_LCR_PARITY_EN(pHalRuartAdapter->Parity);

    /* PARITY TYPE SELECT */
    RegValue &= BIT_INVC_LCR_PARITY_TYPE;
    RegValue |= BIT_LCR_PARITY_TYPE(pHalRuartAdapter->ParityType);

    /* STICK PARITY CONTROL */
    RegValue &= BIT_INVC_LCR_STICK_PARITY_EN;
    RegValue |= BIT_LCR_STICK_PARITY_EN(pHalRuartAdapter->StickParity);

    HAL_RUART_WRITE32(UartIndex, RUART_LINE_CTL_REG_OFF, RegValue);
    DBG_UART_INFO("[W] UART%d LCR(0x%02X): %X\n", UartIndex, RUART_LINE_CTL_REG_OFF, HAL_RUART_READ32(UartIndex, RUART_LINE_CTL_REG_OFF));

    /* Need to assert RTS during initial stage. */
    if (pHalRuartAdapter->FlowControl == AUTOFLOW_ENABLE) {
        HalRuartRTSCtrlRtl8195a(Data, 1);
    }
    pHalRuartAdapter->State = HAL_UART_STATE_READY;

	return HAL_OK;
}