/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: sakamoto $
 * $Date: 2017/10/16 $
 * $RCSfile: aud_cust_amp_5538.c,v $
 * $Revision: #3 $
 *
 *---------------------------------------------------------------------------*/

//---------------------------------------------------------------------------
// Include files
//---------------------------------------------------------------------------

/* =======================================================
 [**CAUTION**] 
 You can only include header files in 
 \target\mtxxxx\xxxx_driver\drv_inc\  
 or files in \vm_linux\output\sysbuild\xxxx\rel or debug\inc\drv_inc\
 or files in the same directory.
========================================================= */
#include "aud_cust_amp_if.h"
#include "sif_if.h"
#include "aud_if.h"
#include "drvcust_if.h"
#include "sakura_aud_aq_data.h"

//---------------------------------------------------------------------------
// Configurations
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Constant definitions
//---------------------------------------------------------------------------
#define GEN_CONFIG_NUM          45
#define AMP_MAX_NUM             7
#define MUX_NUM                 8
#define VOL_NUM                 5
#define BQ_NUM                  7
#define BT_NUM                  4
#define NTFY_ERR_NUM_5538       352

//---------------------------------------------------------------------------
// Type definitions
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Macro definitions
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Imported variables
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Imported functions
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// Static function forward declarations
//---------------------------------------------------------------------------
static void AUD_CUST_AMP_5538_Init(AMP_DATA_T* pAmp);
static void AUD_CUST_AMP_Set_5538_Gen_Config(AMP_DATA_T* pAmp);
static void AUD_CUST_AMP_Set_5538_BQ(AMP_DATA_T* pAmp);
static void AUD_CUST_AMP_Set_5538_BassTreble(AMP_DATA_T* pAmp);
static void AUD_CUST_AMP_Set_5538_DRC(AMP_DATA_T* pAmp);
static void AUD_CUST_AMP_Set_5538_LOUD(AMP_DATA_T* pAmp);
static void AUD_CUST_AMP_Set_5538_Other(AMP_DATA_T* pAmp);
static void AUD_CUST_AMP_5538_Update_Data(void);
static void AUD_CUST_AMP_5538_Mute(AMP_DATA_T* pAmp, AUD_CUST_AMP_MUTE_T mute);
static void AUD_CUST_AMP_5538_Shutdown(AMP_DATA_T* pAmp, BOOL isShutdown);

//---------------------------------------------------------------------------
// Static variables
//---------------------------------------------------------------------------
static UINT8 COL_INDEX[MUX_NUM] = {0};
static UINT8 GEN_CONFIG[GEN_CONFIG_NUM]  = {0};
static UINT8 SLEW_RATE[4] = {0};
static UINT8 INPUT_MUX[MUX_NUM][32] = {0};
static UINT8 OUTPUT_MUX[MUX_NUM][8] = {0}; 
static UINT8 VOLUME [VOL_NUM][4] = {0};
static UINT8 BQ_CH12[BQ_NUM][20] = {0};
static UINT8 BQ_CH34[BQ_NUM][20] = {0};
static UINT8 BQ_CH56[BQ_NUM][20] = {0};
static UINT8 BQ_CH78[BQ_NUM][20] = {0};
static UINT8 BT_ENABLE[BT_NUM][8] = {0};
static UINT8 BASS_FILTER_FC[4] = {0};
static UINT8 BASS_FILTER_INDEX[4] = {0};
static UINT8 TREBLE_FILTER_FC[4] = {0};
static UINT8 TREBLE_FILTER_INDEX[4] = {0};
static UINT8 DRC1_CONTROL[4] = {0};
static UINT8 DRC2_CONTROL[4] = {0};
static UINT8 DRC1_K0K1K2[12] = {0};
static UINT8 DRC2_K0K1K2[12] = {0};
static UINT8 DRC1_T1T2[8] = {0};
static UINT8 DRC2_T1T2[8] = {0};
static UINT8 DRC1_O1O2[8] = {0};
static UINT8 DRC2_O1O2[8] = {0};
static UINT8 DRC1_EST_TIME[8] = {0};
static UINT8 DRC2_EST_TIME[8] = {0};
static UINT8 DRC1_ATK_REL_TIME[16] = {0};
static UINT8 DRC2_ATK_REL_TIME[16] = {0};
static UINT8 DRC_ENABLE[4][8] = {0};
static UINT8 LOUD_LG[4] = {0};
static UINT8 LOUD_LO[4] = {0};
static UINT8 LOUD_GAIN[4] = {0};
static UINT8 LOUD_OFFSET[4] = {0};
static UINT8 LOUD_BQ[20] = {0};
static UINT8 OSC_TRIM = 0;
static UINT8 BANK_SW[4] = {0};
static UINT8 AMP_FIXED_DATA[8][4] = {0};
static UINT8 GEN_CTRL[4] = {0};

static BOOL fgIs5538Shutdown = FALSE;

extern AQDataDa5760Config1 gDa5760Cfg1Data;
extern AQDataDa5760Config2 gDa5760Cfg2Data;
extern AQDataDa5538Config gDa5538CfgData;
extern AQDataDa5538Bq gDa5538BqData;
extern AQDataDa5538Bt gDa5538BtData;
extern AQDataDa5538Loud gDa5538LoudData;
extern AQDataDa5538Drc gDa5538DrcData;

//---------------------------------------------------------------------------
// Static functions
//---------------------------------------------------------------------------


static void AUD_CUST_AMP_5538_Init(AMP_DATA_T* pAmp)
{
    UINT32 i, j;
    UINT8 S_Data;
    UINT8 readData;
    
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_GEN_CFG, 0, 0, _gu4CurrentAqKey/*key*/, 0);    
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_CFG, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_BQ, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_BT, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_LOUD, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_DRC, 0, 0, _gu4CurrentAqKey, 0);    

    AUD_CUST_AMP_5538_Update_Data();
    
    x_thread_delay(15); // wait 15ms before powersequence setting 1
    
    UINT32 num = 0;
    while(1){
        LOG(1, "read %dst time\n", num);
        if(AUD_CUST_AMP_RegRead(pAmp, 0x01, &readData) != 0 && readData == 0x03){
            x_os_drv_set_timestamp("AUD_CUST_AMP_READ_AMP5538_OK");
            break;
        }
        
        x_thread_delay(50);
        num++;
    }
        

    AUD_CUST_AMP_RegWrite(pAmp, 0x12, &OSC_TRIM, 1);
    
    x_thread_delay(50); // wait 50ms before powersequence setting 2
    
    AUD_CUST_AMP_5538_Mute(pAmp, AUD_CUST_AMP_MUTE);
    S_Data = 0xB0;
    AUD_CUST_AMP_RegWrite(pAmp, 0x03, &S_Data, 1);
    
    AUD_CUST_AMP_Set_5538_Gen_Config(pAmp);
    AUD_CUST_AMP_Set_5538_BQ(pAmp);
    //AUD_CUST_AMP_Set_5538_BassTreble(pAmp);

    // Stop white-noize by this logic.
    // ChannelShutdown ->Enable->Shutdown
    S_Data = gDa5538CfgData.m_DaSystemControl1 & ~(0x10);
    AUD_CUST_AMP_RegWrite(pAmp, 0x03, &S_Data, 1);
    S_Data = gDa5538CfgData.m_DaSystemControl1 | 0x10;
    AUD_CUST_AMP_RegWrite(pAmp, 0x03, &S_Data, 1);
}

static void AUD_CUST_AMP_Set_5538_Gen_Config(AMP_DATA_T* pAmp){
    
    AUD_CUST_AMP_RegWrite(pAmp, 0x03, &GEN_CONFIG[0], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x04, &GEN_CONFIG[1], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x05, &GEN_CONFIG[2], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x06, &GEN_CONFIG[3], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x07, &GEN_CONFIG[4], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x08, &GEN_CONFIG[5], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x09, &GEN_CONFIG[6], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x0A, &GEN_CONFIG[7], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x0B, &GEN_CONFIG[8], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x0C, &GEN_CONFIG[9], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x0E, &GEN_CONFIG[10], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x14, &GEN_CONFIG[11], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x15, &GEN_CONFIG[12], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x16, &GEN_CONFIG[13], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x17, &GEN_CONFIG[14], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x18, &GEN_CONFIG[15], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x19, &GEN_CONFIG[16], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x1B, &GEN_CONFIG[17], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x1C, &GEN_CONFIG[18], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x1D, &GEN_CONFIG[19], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x1E, &GEN_CONFIG[20], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x1F, &GEN_CONFIG[21], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x20, &GEN_CONFIG[22], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x21, &GEN_CONFIG[23], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x22, &GEN_CONFIG[24], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x23, &GEN_CONFIG[25], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x24, &GEN_CONFIG[26], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x25, &GEN_CONFIG[27], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x27, &GEN_CONFIG[28], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x30, &GEN_CONFIG[29], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x31, &GEN_CONFIG[30], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x32, &GEN_CONFIG[31], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x33, &GEN_CONFIG[32], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x34, &GEN_CONFIG[33], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x35, &GEN_CONFIG[34], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x36, &GEN_CONFIG[35], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x37, &GEN_CONFIG[36], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x38, &GEN_CONFIG[37], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x39, &GEN_CONFIG[38], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x3A, &GEN_CONFIG[39], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x3B, &GEN_CONFIG[40], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x3C, &GEN_CONFIG[41], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x3D, &GEN_CONFIG[42], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x3E, &GEN_CONFIG[43], 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x3F, &GEN_CONFIG[44], 1);

    AUD_CUST_AMP_RegWrite(pAmp, 0x41, INPUT_MUX[0], 32);
    AUD_CUST_AMP_RegWrite(pAmp, 0x42, INPUT_MUX[1], 32);
    AUD_CUST_AMP_RegWrite(pAmp, 0x43, INPUT_MUX[2], 32);
    AUD_CUST_AMP_RegWrite(pAmp, 0x44, INPUT_MUX[3], 32);
    AUD_CUST_AMP_RegWrite(pAmp, 0x45, INPUT_MUX[4], 32);
    AUD_CUST_AMP_RegWrite(pAmp, 0x46, INPUT_MUX[5], 32);
    AUD_CUST_AMP_RegWrite(pAmp, 0x47, INPUT_MUX[6], 32);
    AUD_CUST_AMP_RegWrite(pAmp, 0x48, INPUT_MUX[7], 32);
    
    AUD_CUST_AMP_RegWrite(pAmp, 0xAA, OUTPUT_MUX[0], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xAB, OUTPUT_MUX[1], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xAC, OUTPUT_MUX[2], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xAD, OUTPUT_MUX[3], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xAE, OUTPUT_MUX[4], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xAF, OUTPUT_MUX[5], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xB0, OUTPUT_MUX[6], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xB1, OUTPUT_MUX[7], 8);
 
    AUD_CUST_AMP_RegWrite(pAmp, 0xD0, SLEW_RATE, 4); 
    
    AUD_CUST_AMP_RegWrite(pAmp, 0xD1, VOLUME[0], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD2, VOLUME[0], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD3, VOLUME[1], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD4, VOLUME[1], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD5, VOLUME[2], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD6, VOLUME[2], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD7, VOLUME[3], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD8, VOLUME[3], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xD9, VOLUME[4], 4);
}

static void AUD_CUST_AMP_Set_5538_BQ(AMP_DATA_T* pAmp){
    
    UINT32 i;
    
    for(i=0; i<BQ_NUM; i++){
        AUD_CUST_AMP_RegWrite(pAmp, 0x51+i, BQ_CH12[i], 20);
        AUD_CUST_AMP_RegWrite(pAmp, 0x58+i, BQ_CH12[i], 20);
        AUD_CUST_AMP_RegWrite(pAmp, 0x5F+i, BQ_CH34[i], 20);
        AUD_CUST_AMP_RegWrite(pAmp, 0x66+i, BQ_CH34[i], 20);
        AUD_CUST_AMP_RegWrite(pAmp, 0x6D+i, BQ_CH56[i], 20);
        AUD_CUST_AMP_RegWrite(pAmp, 0x74+i, BQ_CH56[i], 20);
        AUD_CUST_AMP_RegWrite(pAmp, 0x7B+i, BQ_CH78[i], 20);
        AUD_CUST_AMP_RegWrite(pAmp, 0x82+i, BQ_CH78[i], 20);
    }
    
}

static void AUD_CUST_AMP_Set_5538_BassTreble(AMP_DATA_T* pAmp){
    
    UINT32 i;
    
    for(i=0; i<BT_NUM; i++){
        AUD_CUST_AMP_RegWrite(pAmp, 0x89+2*i, BT_ENABLE[i], 8);
        AUD_CUST_AMP_RegWrite(pAmp, 0x8A+2*i, BT_ENABLE[i], 8);
    }
    
    AUD_CUST_AMP_RegWrite(pAmp, 0xDA, BASS_FILTER_FC, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xDB, BASS_FILTER_INDEX, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xDC, TREBLE_FILTER_FC, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xDD, TREBLE_FILTER_INDEX, 4);
    
}

static void AUD_CUST_AMP_Set_5538_DRC(AMP_DATA_T* pAmp){
    
    AUD_CUST_AMP_RegWrite(pAmp, 0x96, DRC1_CONTROL, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x97, DRC2_CONTROL, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x98, DRC1_EST_TIME, 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0x99, DRC1_T1T2, 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0x9A, DRC1_K0K1K2, 12);
    AUD_CUST_AMP_RegWrite(pAmp, 0x9B, DRC1_O1O2, 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0x9C, DRC1_ATK_REL_TIME, 16);
    AUD_CUST_AMP_RegWrite(pAmp, 0x9D, DRC2_EST_TIME, 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0x9E, DRC2_T1T2, 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0x9F, DRC2_K0K1K2, 12);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA0, DRC2_O1O2, 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA1, DRC2_ATK_REL_TIME, 16);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA2, DRC_ENABLE[0], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA3, DRC_ENABLE[0], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA4, DRC_ENABLE[1], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA5, DRC_ENABLE[1], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA6, DRC_ENABLE[2], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA7, DRC_ENABLE[2], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA8, DRC_ENABLE[3], 8);
    AUD_CUST_AMP_RegWrite(pAmp, 0xA9, DRC_ENABLE[3], 8);
    
}

static void AUD_CUST_AMP_Set_5538_LOUD(AMP_DATA_T* pAmp){
    
    AUD_CUST_AMP_RegWrite(pAmp, 0x91, LOUD_LG, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x92, LOUD_LO, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x93, LOUD_GAIN, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x94, LOUD_OFFSET, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x95, LOUD_BQ, 20);
    
}

static void AUD_CUST_AMP_Set_5538_Other(AMP_DATA_T* pAmp){

    AUD_CUST_AMP_RegWrite(pAmp, 0x12, &OSC_TRIM, 1);
    AUD_CUST_AMP_RegWrite(pAmp, 0x40, BANK_SW, 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x49, AMP_FIXED_DATA[0], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x4A, AMP_FIXED_DATA[1], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x4B, AMP_FIXED_DATA[2], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x4C, AMP_FIXED_DATA[3], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x4D, AMP_FIXED_DATA[4], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x4E, AMP_FIXED_DATA[5], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x4F, AMP_FIXED_DATA[6], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0x50, AMP_FIXED_DATA[7], 4);
    AUD_CUST_AMP_RegWrite(pAmp, 0xE0, GEN_CTRL, 4);
}

static void AUD_CUST_AMP_5538_Update_Data(void)
{
    UINT32 i;
    
    if(fgIs5538Shutdown == FALSE)
    {
        // All Channel Shutdown BIT OFF.
        GEN_CONFIG[0] = gDa5538CfgData.m_DaSystemControl1 & ~(0x10);
    }
    else
    {
        // All Channel Shutdown BIT ON.
        GEN_CONFIG[0] = gDa5538CfgData.m_DaSystemControl1 | 0x10;
    }
    GEN_CONFIG[1] = gDa5538CfgData.m_DaSystemControl2;
    GEN_CONFIG[2] = gDa5538CfgData.m_DaChannelConfigCh1;
    GEN_CONFIG[3] = gDa5538CfgData.m_DaChannelConfigCh2;
    GEN_CONFIG[4] = gDa5538CfgData.m_DaChannelConfigCh3;
    GEN_CONFIG[5] = gDa5538CfgData.m_DaChannelConfigCh4;
    GEN_CONFIG[6] = gDa5538CfgData.m_DaChannelConfigCh5;
    GEN_CONFIG[7] = gDa5538CfgData.m_DaChannelConfigCh6;
    GEN_CONFIG[8] = gDa5538CfgData.m_DaChannelConfigCh7;
    GEN_CONFIG[9] = gDa5538CfgData.m_DaChannelConfigCh8;
    GEN_CONFIG[10] = gDa5538CfgData.m_DaSerialDataFormat;
    GEN_CONFIG[11] = gDa5538CfgData.m_DaAutomuteControl;
    GEN_CONFIG[12] = gDa5538CfgData.m_DaAutomutePwmTh;
    GEN_CONFIG[13] = gDa5538CfgData.m_DaModLimitCh12;
    GEN_CONFIG[14] = gDa5538CfgData.m_DaModLimitCh34;
    GEN_CONFIG[15] = gDa5538CfgData.m_DaModLimitCh56;
    GEN_CONFIG[16] = gDa5538CfgData.m_DaModLimitCh78;
    GEN_CONFIG[17] = gDa5538CfgData.m_DaIcDelayCh1;
    GEN_CONFIG[18] = gDa5538CfgData.m_DaIcDelayCh2;
    GEN_CONFIG[19] = gDa5538CfgData.m_DaIcDelayCh3;
    GEN_CONFIG[20] = gDa5538CfgData.m_DaIcDelayCh4;
    GEN_CONFIG[21] = gDa5538CfgData.m_DaIcDelayCh5;
    GEN_CONFIG[22] = gDa5538CfgData.m_DaIcDelayCh6;
    GEN_CONFIG[23] = gDa5538CfgData.m_DaIcDelayCh7;
    GEN_CONFIG[24] = gDa5538CfgData.m_DaIcDelayCh8;
    GEN_CONFIG[25] = gDa5538CfgData.m_DaIcOffsetDelay;
    GEN_CONFIG[26] = gDa5538CfgData.m_DaPwmSeqTiming; 
    GEN_CONFIG[27] = gDa5538CfgData.m_DaPwmControl;
    GEN_CONFIG[28] = gDa5538CfgData.m_DaIndividualChShutdown;
    GEN_CONFIG[29] = gDa5538CfgData.m_DaInputMuxCh12;
    GEN_CONFIG[30] = gDa5538CfgData.m_DaInputMuxCh34;
    GEN_CONFIG[31] = gDa5538CfgData.m_DaInputMuxCh56;
    GEN_CONFIG[32] = gDa5538CfgData.m_DaInputMuxCh78;
    GEN_CONFIG[33] = gDa5538CfgData.m_DaPwmMuxCh12;
    GEN_CONFIG[34] = gDa5538CfgData.m_DaPwmMuxCh34;
    GEN_CONFIG[35] = gDa5538CfgData.m_DaPwmMuxCh56;
    GEN_CONFIG[36] = gDa5538CfgData.m_DaPwmMuxCh78;
    GEN_CONFIG[37] = gDa5538CfgData.m_DaIcDelayBdmCh1;
    GEN_CONFIG[38] = gDa5538CfgData.m_DaIcDelayBdmCh2;
    GEN_CONFIG[39] = gDa5538CfgData.m_DaIcDelayBdmCh3;
    GEN_CONFIG[40] = gDa5538CfgData.m_DaIcDelayBdmCh4;
    GEN_CONFIG[41] = gDa5538CfgData.m_DaIcDelayBdmCh5;
    GEN_CONFIG[42] = gDa5538CfgData.m_DaIcDelayBdmCh6;
    GEN_CONFIG[43] = gDa5538CfgData.m_DaIcDelayBdmCh7;
    GEN_CONFIG[44] = gDa5538CfgData.m_DaIcDelayBdmCh8;
    
    COL_INDEX[0] = ((gDa5538CfgData.m_DaInputMux1 & 0xFF000000) >> 28) * 4;
    COL_INDEX[1] = ((gDa5538CfgData.m_DaInputMux2 & 0xFF000000) >> 28) * 4;
    COL_INDEX[2] = ((gDa5538CfgData.m_DaInputMux3 & 0xFF000000) >> 28) * 4;
    COL_INDEX[3] = ((gDa5538CfgData.m_DaInputMux4 & 0xFF000000) >> 28) * 4;    
    COL_INDEX[4] = ((gDa5538CfgData.m_DaInputMux5 & 0xFF000000) >> 28) * 4;
    COL_INDEX[5] = ((gDa5538CfgData.m_DaInputMux6 & 0xFF000000) >> 28) * 4;
    COL_INDEX[6] = ((gDa5538CfgData.m_DaInputMux7 & 0xFF000000) >> 28) * 4;
    COL_INDEX[7] = ((gDa5538CfgData.m_DaInputMux8 & 0xFF000000) >> 28) * 4;

    for( i=0; i<MUX_NUM; i++){
        if(COL_INDEX[i] > 28){
            COL_INDEX[i] = 0;
            Printf("Input Mux Data is wrong!\n");
        }
    }
    
    // Input Mux Data Input
    // To ignore first 4bit this process can't use AUD_CUST_AMP_DataCopy
    INPUT_MUX[0][COL_INDEX[0]]  =((gDa5538CfgData.m_DaInputMux1 & 0x0F000000) >> 24);
    INPUT_MUX[0][COL_INDEX[0]+1]=((gDa5538CfgData.m_DaInputMux1 & 0xFF0000) >> 16);
    INPUT_MUX[0][COL_INDEX[0]+2]=((gDa5538CfgData.m_DaInputMux1 & 0xFF00) >> 8);
    INPUT_MUX[0][COL_INDEX[0]+3]=((gDa5538CfgData.m_DaInputMux1 & 0xFF));
    INPUT_MUX[1][COL_INDEX[1]]  =((gDa5538CfgData.m_DaInputMux2 & 0x0F000000) >> 24);
    INPUT_MUX[1][COL_INDEX[1]+1]=((gDa5538CfgData.m_DaInputMux2 & 0xFF0000) >> 16);
    INPUT_MUX[1][COL_INDEX[1]+2]=((gDa5538CfgData.m_DaInputMux2 & 0xFF00) >> 8);
    INPUT_MUX[1][COL_INDEX[1]+3]=((gDa5538CfgData.m_DaInputMux2 & 0xFF));
    INPUT_MUX[2][COL_INDEX[2]]  =((gDa5538CfgData.m_DaInputMux3 & 0x0F000000) >> 24);
    INPUT_MUX[2][COL_INDEX[2]+1]=((gDa5538CfgData.m_DaInputMux3 & 0xFF0000) >> 16);
    INPUT_MUX[2][COL_INDEX[2]+2]=((gDa5538CfgData.m_DaInputMux3 & 0xFF00) >> 8);
    INPUT_MUX[2][COL_INDEX[2]+3]=((gDa5538CfgData.m_DaInputMux3 & 0xFF));
    INPUT_MUX[3][COL_INDEX[3]]  =((gDa5538CfgData.m_DaInputMux4 & 0x0F000000) >> 24);
    INPUT_MUX[3][COL_INDEX[3]+1]=((gDa5538CfgData.m_DaInputMux4 & 0xFF0000) >> 16);
    INPUT_MUX[3][COL_INDEX[3]+2]=((gDa5538CfgData.m_DaInputMux4 & 0xFF00) >> 8);
    INPUT_MUX[3][COL_INDEX[3]+3]=((gDa5538CfgData.m_DaInputMux4 & 0xFF));
    INPUT_MUX[4][COL_INDEX[4]]  =((gDa5538CfgData.m_DaInputMux5 & 0x0F000000) >> 24);
    INPUT_MUX[4][COL_INDEX[4]+1]=((gDa5538CfgData.m_DaInputMux5 & 0xFF0000) >> 16);
    INPUT_MUX[4][COL_INDEX[4]+2]=((gDa5538CfgData.m_DaInputMux5 & 0xFF00) >> 8);
    INPUT_MUX[4][COL_INDEX[4]+3]=((gDa5538CfgData.m_DaInputMux5 & 0xFF));
    INPUT_MUX[5][COL_INDEX[5]]  =((gDa5538CfgData.m_DaInputMux6 & 0x0F000000) >> 24);
    INPUT_MUX[5][COL_INDEX[5]+1]=((gDa5538CfgData.m_DaInputMux6 & 0xFF0000) >> 16);
    INPUT_MUX[5][COL_INDEX[5]+2]=((gDa5538CfgData.m_DaInputMux6 & 0xFF00) >> 8);
    INPUT_MUX[5][COL_INDEX[5]+3]=((gDa5538CfgData.m_DaInputMux6 & 0xFF));
    INPUT_MUX[6][COL_INDEX[6]]  =((gDa5538CfgData.m_DaInputMux7 & 0x0F000000) >> 24);
    INPUT_MUX[6][COL_INDEX[6]+1]=((gDa5538CfgData.m_DaInputMux7 & 0xFF0000) >> 16);
    INPUT_MUX[6][COL_INDEX[6]+2]=((gDa5538CfgData.m_DaInputMux7 & 0xFF00) >> 8);
    INPUT_MUX[6][COL_INDEX[6]+3]=((gDa5538CfgData.m_DaInputMux7 & 0xFF));
    INPUT_MUX[7][COL_INDEX[7]]  =((gDa5538CfgData.m_DaInputMux8 & 0x0F000000) >> 24);
    INPUT_MUX[7][COL_INDEX[7]+1]=((gDa5538CfgData.m_DaInputMux8 & 0xFF0000) >> 16); 
    INPUT_MUX[7][COL_INDEX[7]+2]=((gDa5538CfgData.m_DaInputMux8 & 0xFF00) >> 8);
    INPUT_MUX[7][COL_INDEX[7]+3]=((gDa5538CfgData.m_DaInputMux8 & 0xFF));
    
    //Output Mux Data
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[0], gDa5538CfgData.m_DaOutputMuxPwm1, 4);
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[1], gDa5538CfgData.m_DaOutputMuxPwm2, 4);
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[2], gDa5538CfgData.m_DaOutputMuxPwm3, 4);
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[3], gDa5538CfgData.m_DaOutputMuxPwm4, 4);
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[4], gDa5538CfgData.m_DaOutputMuxPwm5, 4);
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[5], gDa5538CfgData.m_DaOutputMuxPwm6, 4);
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[6], gDa5538CfgData.m_DaOutputMuxPwm7, 4);
    AUD_CUST_AMP_DataCopy(OUTPUT_MUX[7], gDa5538CfgData.m_DaOutputMuxPwm8, 4);
    
    //Slew Rate
    SLEW_RATE[2]=(gDa5538CfgData.m_DaVolumeSlewRate);
    SLEW_RATE[3]=(gDa5538CfgData.m_DaBassTrebleSlewRate);
    
    //Volume
    AUD_CUST_AMP_DataCopy(&VOLUME[0][2], gDa5538CfgData.m_DaVolumeCh12, 2);
    AUD_CUST_AMP_DataCopy(&VOLUME[1][2], gDa5538CfgData.m_DaVolumeCh34, 2);
    AUD_CUST_AMP_DataCopy(&VOLUME[2][2], gDa5538CfgData.m_DaVolumeCh56, 2);
    AUD_CUST_AMP_DataCopy(&VOLUME[3][2], gDa5538CfgData.m_DaVolumeCh78, 2);
    AUD_CUST_AMP_DataCopy(&VOLUME[4][2], gDa5538CfgData.m_DaMasterVolume, 2);

    //BQ CH12
    AUD_CUST_AMP_DataCopy(&BQ_CH12[0][0], gDa5538BqData.m_DaCh12Bq1B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[0][4], gDa5538BqData.m_DaCh12Bq1B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[0][8], gDa5538BqData.m_DaCh12Bq1B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[0][12],gDa5538BqData.m_DaCh12Bq1A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[0][16],gDa5538BqData.m_DaCh12Bq1A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[1][0], gDa5538BqData.m_DaCh12Bq2B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[1][4], gDa5538BqData.m_DaCh12Bq2B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[1][8], gDa5538BqData.m_DaCh12Bq2B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[1][12],gDa5538BqData.m_DaCh12Bq2A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[1][16],gDa5538BqData.m_DaCh12Bq2A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[2][0], gDa5538BqData.m_DaCh12Bq3B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[2][4], gDa5538BqData.m_DaCh12Bq3B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[2][8], gDa5538BqData.m_DaCh12Bq3B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[2][12],gDa5538BqData.m_DaCh12Bq3A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[2][16],gDa5538BqData.m_DaCh12Bq3A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[3][0], gDa5538BqData.m_DaCh12Bq4B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[3][4], gDa5538BqData.m_DaCh12Bq4B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[3][8], gDa5538BqData.m_DaCh12Bq4B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[3][12],gDa5538BqData.m_DaCh12Bq4A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[3][16],gDa5538BqData.m_DaCh12Bq4A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[4][0], gDa5538BqData.m_DaCh12Bq5B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[4][4], gDa5538BqData.m_DaCh12Bq5B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[4][8], gDa5538BqData.m_DaCh12Bq5B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[4][12],gDa5538BqData.m_DaCh12Bq5A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[4][16],gDa5538BqData.m_DaCh12Bq5A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[5][0], gDa5538BqData.m_DaCh12Bq6B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[5][4], gDa5538BqData.m_DaCh12Bq6B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[5][8], gDa5538BqData.m_DaCh12Bq6B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[5][12],gDa5538BqData.m_DaCh12Bq6A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[5][16],gDa5538BqData.m_DaCh12Bq6A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[6][0], gDa5538BqData.m_DaCh12Bq7B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[6][4], gDa5538BqData.m_DaCh12Bq7B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[6][8], gDa5538BqData.m_DaCh12Bq7B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[6][12],gDa5538BqData.m_DaCh12Bq7A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH12[6][16],gDa5538BqData.m_DaCh12Bq7A2, 4);
    
    //BQ CH34
    AUD_CUST_AMP_DataCopy(&BQ_CH34[0][0], gDa5538BqData.m_DaCh34Bq1B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[0][4], gDa5538BqData.m_DaCh34Bq1B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[0][8], gDa5538BqData.m_DaCh34Bq1B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[0][12],gDa5538BqData.m_DaCh34Bq1A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[0][16],gDa5538BqData.m_DaCh34Bq1A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[1][0], gDa5538BqData.m_DaCh34Bq2B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[1][4], gDa5538BqData.m_DaCh34Bq2B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[1][8], gDa5538BqData.m_DaCh34Bq2B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[1][12],gDa5538BqData.m_DaCh34Bq2A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[1][16],gDa5538BqData.m_DaCh34Bq2A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[2][0], gDa5538BqData.m_DaCh34Bq3B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[2][4], gDa5538BqData.m_DaCh34Bq3B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[2][8], gDa5538BqData.m_DaCh34Bq3B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[2][12],gDa5538BqData.m_DaCh34Bq3A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[2][16],gDa5538BqData.m_DaCh34Bq3A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[3][0], gDa5538BqData.m_DaCh34Bq4B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[3][4], gDa5538BqData.m_DaCh34Bq4B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[3][8], gDa5538BqData.m_DaCh34Bq4B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[3][12],gDa5538BqData.m_DaCh34Bq4A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[3][16],gDa5538BqData.m_DaCh34Bq4A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[4][0], gDa5538BqData.m_DaCh34Bq5B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[4][4], gDa5538BqData.m_DaCh34Bq5B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[4][8], gDa5538BqData.m_DaCh34Bq5B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[4][12],gDa5538BqData.m_DaCh34Bq5A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[4][16],gDa5538BqData.m_DaCh34Bq5A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[5][0], gDa5538BqData.m_DaCh34Bq6B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[5][4], gDa5538BqData.m_DaCh34Bq6B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[5][8], gDa5538BqData.m_DaCh34Bq6B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[5][12],gDa5538BqData.m_DaCh34Bq6A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[5][16],gDa5538BqData.m_DaCh34Bq6A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[6][0], gDa5538BqData.m_DaCh34Bq7B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[6][4], gDa5538BqData.m_DaCh34Bq7B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[6][8], gDa5538BqData.m_DaCh34Bq7B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[6][12],gDa5538BqData.m_DaCh34Bq7A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH34[6][16],gDa5538BqData.m_DaCh34Bq7A2, 4);
    
    //BQ CH56
    AUD_CUST_AMP_DataCopy(&BQ_CH56[0][0], gDa5538BqData.m_DaCh56Bq1B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[0][4], gDa5538BqData.m_DaCh56Bq1B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[0][8], gDa5538BqData.m_DaCh56Bq1B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[0][12],gDa5538BqData.m_DaCh56Bq1A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[0][16],gDa5538BqData.m_DaCh56Bq1A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[1][0], gDa5538BqData.m_DaCh56Bq2B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[1][4], gDa5538BqData.m_DaCh56Bq2B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[1][8], gDa5538BqData.m_DaCh56Bq2B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[1][12],gDa5538BqData.m_DaCh56Bq2A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[1][16],gDa5538BqData.m_DaCh56Bq2A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[2][0], gDa5538BqData.m_DaCh56Bq3B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[2][4], gDa5538BqData.m_DaCh56Bq3B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[2][8], gDa5538BqData.m_DaCh56Bq3B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[2][12],gDa5538BqData.m_DaCh56Bq3A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[2][16],gDa5538BqData.m_DaCh56Bq3A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[3][0], gDa5538BqData.m_DaCh56Bq4B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[3][4], gDa5538BqData.m_DaCh56Bq4B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[3][8], gDa5538BqData.m_DaCh56Bq4B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[3][12],gDa5538BqData.m_DaCh56Bq4A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[3][16],gDa5538BqData.m_DaCh56Bq4A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[4][0], gDa5538BqData.m_DaCh56Bq5B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[4][4], gDa5538BqData.m_DaCh56Bq5B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[4][8], gDa5538BqData.m_DaCh56Bq5B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[4][12],gDa5538BqData.m_DaCh56Bq5A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[4][16],gDa5538BqData.m_DaCh56Bq5A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[5][0], gDa5538BqData.m_DaCh56Bq6B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[5][4], gDa5538BqData.m_DaCh56Bq6B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[5][8], gDa5538BqData.m_DaCh56Bq6B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[5][12],gDa5538BqData.m_DaCh56Bq6A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[5][16],gDa5538BqData.m_DaCh56Bq6A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[6][0], gDa5538BqData.m_DaCh56Bq7B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[6][4], gDa5538BqData.m_DaCh56Bq7B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[6][8], gDa5538BqData.m_DaCh56Bq7B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[6][12],gDa5538BqData.m_DaCh56Bq7A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH56[6][16],gDa5538BqData.m_DaCh56Bq7A2, 4);
    
    //BQ CH78
    AUD_CUST_AMP_DataCopy(&BQ_CH78[0][0], gDa5538BqData.m_DaCh78Bq1B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[0][4], gDa5538BqData.m_DaCh78Bq1B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[0][8], gDa5538BqData.m_DaCh78Bq1B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[0][12],gDa5538BqData.m_DaCh78Bq1A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[0][16],gDa5538BqData.m_DaCh78Bq1A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[1][0], gDa5538BqData.m_DaCh78Bq2B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[1][4], gDa5538BqData.m_DaCh78Bq2B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[1][8], gDa5538BqData.m_DaCh78Bq2B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[1][12],gDa5538BqData.m_DaCh78Bq2A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[1][16],gDa5538BqData.m_DaCh78Bq2A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[2][0], gDa5538BqData.m_DaCh78Bq3B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[2][4], gDa5538BqData.m_DaCh78Bq3B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[2][8], gDa5538BqData.m_DaCh78Bq3B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[2][12],gDa5538BqData.m_DaCh78Bq3A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[2][16],gDa5538BqData.m_DaCh78Bq3A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[3][0], gDa5538BqData.m_DaCh78Bq4B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[3][4], gDa5538BqData.m_DaCh78Bq4B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[3][8], gDa5538BqData.m_DaCh78Bq4B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[3][12],gDa5538BqData.m_DaCh78Bq4A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[3][16],gDa5538BqData.m_DaCh78Bq4A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[4][0], gDa5538BqData.m_DaCh78Bq5B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[4][4], gDa5538BqData.m_DaCh78Bq5B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[4][8], gDa5538BqData.m_DaCh78Bq5B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[4][12],gDa5538BqData.m_DaCh78Bq5A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[4][16],gDa5538BqData.m_DaCh78Bq5A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[5][0], gDa5538BqData.m_DaCh78Bq6B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[5][4], gDa5538BqData.m_DaCh78Bq6B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[5][8], gDa5538BqData.m_DaCh78Bq6B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[5][12],gDa5538BqData.m_DaCh78Bq6A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[5][16],gDa5538BqData.m_DaCh78Bq6A2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[6][0], gDa5538BqData.m_DaCh78Bq7B0, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[6][4], gDa5538BqData.m_DaCh78Bq7B1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[6][8], gDa5538BqData.m_DaCh78Bq7B2, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[6][12],gDa5538BqData.m_DaCh78Bq7A1, 4);
    AUD_CUST_AMP_DataCopy(&BQ_CH78[6][16],gDa5538BqData.m_DaCh78Bq7A2, 4);
    
    //BassTreble
    if( gDa5538BtData.m_DaBassTrebleEnableCh12 <= 1){
        BT_ENABLE[0][(4 * gDa5538BtData.m_DaBassTrebleEnableCh12) + 1] = 0x80;
    }
    else{
        BT_ENABLE[0][1] = 0x80;
    }
    if( gDa5538BtData.m_DaBassTrebleEnableCh34 <= 1){
        BT_ENABLE[1][(4 * gDa5538BtData.m_DaBassTrebleEnableCh34) + 1] = 0x80;
    }
    else{
        BT_ENABLE[1][1] = 0x80;
    }
    if( gDa5538BtData.m_DaBassTrebleEnableCh56 <= 1){
        BT_ENABLE[2][(4 * gDa5538BtData.m_DaBassTrebleEnableCh56) + 1] = 0x80;
    }
    else{
        BT_ENABLE[2][1] = 0x80;
    }
    if( gDa5538BtData.m_DaBassTrebleEnableCh78 <= 1){
        BT_ENABLE[3][(4 * gDa5538BtData.m_DaBassTrebleEnableCh78) + 1] = 0x80;
    }
    else{
        BT_ENABLE[3][1] = 0x80;
    }
    
    
    BASS_FILTER_FC[0] = gDa5538BtData.m_DaBassFilterSetCh127;
    BASS_FILTER_FC[1] = gDa5538BtData.m_DaBassFilterSetCh34;
    BASS_FILTER_FC[2] = gDa5538BtData.m_DaBassFilterSetCh56;
    BASS_FILTER_FC[3] = gDa5538BtData.m_DaBassFilterSetCh8;
    
    BASS_FILTER_INDEX[0] = gDa5538BtData.m_DaBassFilterIndexCh127;
    BASS_FILTER_INDEX[1] = gDa5538BtData.m_DaBassFilterIndexCh34;
    BASS_FILTER_INDEX[2] = gDa5538BtData.m_DaBassFilterIndexCh56;
    BASS_FILTER_INDEX[3] = gDa5538BtData.m_DaBassFilterIndexCh8;
    
    TREBLE_FILTER_FC[0] = gDa5538BtData.m_DaTrebleFilterSetCh127;
    TREBLE_FILTER_FC[1] = gDa5538BtData.m_DaTrebleFilterSetCh34;
    TREBLE_FILTER_FC[2] = gDa5538BtData.m_DaTrebleFilterSetCh56;
    TREBLE_FILTER_FC[3] = gDa5538BtData.m_DaTrebleFilterSetCh8;
    
    TREBLE_FILTER_INDEX[0] = gDa5538BtData.m_DaTrebleFilterIndexCh127;
    TREBLE_FILTER_INDEX[1] = gDa5538BtData.m_DaTrebleFilterIndexCh34;
    TREBLE_FILTER_INDEX[2] = gDa5538BtData.m_DaTrebleFilterIndexCh56;
    TREBLE_FILTER_INDEX[3] = gDa5538BtData.m_DaTrebleFilterIndexCh8;
    
    BASS_FILTER_FC[0] = gDa5538BtData.m_DaBassFilterSetCh127;
    BASS_FILTER_FC[1] = gDa5538BtData.m_DaBassFilterSetCh34;
    
    //DRC
    AUD_CUST_AMP_DataCopy(&DRC1_CONTROL[2], gDa5538DrcData.m_DaDrc1Control, 2);
    AUD_CUST_AMP_DataCopy(&DRC2_CONTROL[3], gDa5538DrcData.m_DaDrc2Control, 1);
    
    AUD_CUST_AMP_DataCopy(&DRC1_K0K1K2[0], gDa5538DrcData.m_DaDrc1K0, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_K0K1K2[4], gDa5538DrcData.m_DaDrc1K1, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_K0K1K2[8], gDa5538DrcData.m_DaDrc1K2, 4);
    
    AUD_CUST_AMP_DataCopy(&DRC2_K0K1K2[0], gDa5538DrcData.m_DaDrc2K0, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_K0K1K2[4], gDa5538DrcData.m_DaDrc2K1, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_K0K1K2[8], gDa5538DrcData.m_DaDrc2K2, 4);
    
    AUD_CUST_AMP_DataCopy(&DRC1_T1T2[0], gDa5538DrcData.m_DaDrc1T1, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_T1T2[4], gDa5538DrcData.m_DaDrc1T2, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_T1T2[0], gDa5538DrcData.m_DaDrc2T1, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_T1T2[4], gDa5538DrcData.m_DaDrc2T2, 4);
    
    AUD_CUST_AMP_DataCopy(&DRC1_O1O2[0], gDa5538DrcData.m_DaDrc1O1, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_O1O2[4], gDa5538DrcData.m_DaDrc1O2, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_O1O2[0], gDa5538DrcData.m_DaDrc2O1, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_O1O2[4], gDa5538DrcData.m_DaDrc2O2, 4);
    
    AUD_CUST_AMP_DataCopy(&DRC1_EST_TIME[0], gDa5538DrcData.m_DaDrc1EstTime1, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_EST_TIME[4], gDa5538DrcData.m_DaDrc1EstTime2, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_EST_TIME[0], gDa5538DrcData.m_DaDrc2EstTime1, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_EST_TIME[4], gDa5538DrcData.m_DaDrc2EstTime2, 4);
    
    AUD_CUST_AMP_DataCopy(&DRC1_ATK_REL_TIME[0], gDa5538DrcData.m_DaDrc1EstTime1, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_ATK_REL_TIME[4], gDa5538DrcData.m_DaDrc1AtkTime2, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_ATK_REL_TIME[8], gDa5538DrcData.m_DaDrc1RelTime1, 4);
    AUD_CUST_AMP_DataCopy(&DRC1_ATK_REL_TIME[12], gDa5538DrcData.m_DaDrc1RelTime2, 4);
    
    AUD_CUST_AMP_DataCopy(&DRC2_ATK_REL_TIME[0], gDa5538DrcData.m_DaDrc2EstTime1, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_ATK_REL_TIME[4], gDa5538DrcData.m_DaDrc2AtkTime2, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_ATK_REL_TIME[8], gDa5538DrcData.m_DaDrc2RelTime1, 4);
    AUD_CUST_AMP_DataCopy(&DRC2_ATK_REL_TIME[12], gDa5538DrcData.m_DaDrc2RelTime2, 4);
    
    if(gDa5538DrcData.m_DaDrcEnableCh12 == 0){
        DRC_ENABLE[0][1] = 0x80;
    }
    else{
        DRC_ENABLE[0][5] = 0x80;
    }
    if(gDa5538DrcData.m_DaDrcEnableCh34 == 0){
        DRC_ENABLE[1][1] = 0x80;
    }
    else{
        DRC_ENABLE[1][5] = 0x80;
    }
    if(gDa5538DrcData.m_DaDrcEnableCh56 == 0){
        DRC_ENABLE[2][1] = 0x80;
    }
    else{
        DRC_ENABLE[2][5] = 0x80;
    }
    if(gDa5538DrcData.m_DaDrcEnableCh78 == 0){
        DRC_ENABLE[3][1] = 0x80;
    }
    else{
        DRC_ENABLE[3][5] = 0x80;
    }
    
    AUD_CUST_AMP_DataCopy(LOUD_LG, gDa5538LoudData.m_DaLoudLg, 4);
    AUD_CUST_AMP_DataCopy(LOUD_LO, gDa5538LoudData.m_DaLoudLo, 4);
    AUD_CUST_AMP_DataCopy(LOUD_GAIN, gDa5538LoudData.m_DaLoudGain, 4);
    AUD_CUST_AMP_DataCopy(LOUD_OFFSET, gDa5538LoudData.m_DaLoudOffset, 4);
    AUD_CUST_AMP_DataCopy(&LOUD_BQ[0], gDa5538LoudData.m_DaLoudBqB0, 4);
    AUD_CUST_AMP_DataCopy(&LOUD_BQ[4], gDa5538LoudData.m_DaLoudBqB1, 4);
    AUD_CUST_AMP_DataCopy(&LOUD_BQ[8], gDa5538LoudData.m_DaLoudBqB2, 4);
    AUD_CUST_AMP_DataCopy(&LOUD_BQ[12], gDa5538LoudData.m_DaLoudBqA1, 4);
    AUD_CUST_AMP_DataCopy(&LOUD_BQ[16], gDa5538LoudData.m_DaLoudBqA2, 4);    

    //Fixed Data
    OSC_TRIM = 0xC0;
    AUD_CUST_AMP_DataCopy(BANK_SW, 0x0000FF00, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[0], 0x00000000, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[1], 0x00000000, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[2], 0x00000000, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[3], 0x00000000, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[4], 0x00800000, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[5], 0x00000000, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[6], 0x00000000, 4);
    AUD_CUST_AMP_DataCopy(&AMP_FIXED_DATA[7], 0x00800000, 4);
    AUD_CUST_AMP_DataCopy(GEN_CTRL, 0x00000000, 4);
}


void AUD_CUST_AMP_5538_Mute(AMP_DATA_T* pAmp, AUD_CUST_AMP_MUTE_T mute)
{
    UINT8 S_Data = 0;
    
    if( mute == AUD_CUST_AMP_MUTE ){
        S_Data = 0xFF;
        AUD_CUST_AMP_RegWrite(pAmp, 0x0F, &S_Data, 1);
        AUD_CUST_AMP_5538_Shutdown(pAmp, TRUE);
    }
    else if( mute == AUD_CUST_AMP_UNMUTE ){//Unmute
        S_Data = 0x0;
        AUD_CUST_AMP_RegWrite(pAmp, 0x0F, &S_Data, 1);
        AUD_CUST_AMP_5538_Shutdown(pAmp, FALSE);
    }
    else{
        LOG(0, "Nothing done. Pass Mute or Unmute value!\n");
    }
}

void AUD_CUST_AMP_5538_Shutdown(AMP_DATA_T* pAmp, BOOL isShutdown) {
    UINT8 S_Data;

    AUD_CUST_AMP_RegRead(pAmp, 0x03, &S_Data);
    if( isShutdown == FALSE ) {
        S_Data &= ~(0x10); // bit4
        fgIs5538Shutdown = FALSE;
    }
    else{
        S_Data |= 0x10; // bit4
        fgIs5538Shutdown = TRUE;
    }
    AUD_CUST_AMP_RegWrite(pAmp, 0x03, &S_Data, 1);
}

void AUD_CUST_AMP_5538_Refresh(AMP_DATA_T* pAmp)
{
    UINT32 Index;
    UINT8 S_Data = 0;
    UINT8 readData;
    
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_CFG, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_BQ, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_BT, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_LOUD, 0, 0, _gu4CurrentAqKey, 0);
    DrvCust_AQ_SetGet(AUD_DrvCust_AQ_Get_DA_5538_DRC, 0, 0, _gu4CurrentAqKey, 0);

    AUD_CUST_AMP_5538_Update_Data();
    
    LOG(1, "Amp type is 5538\n");
    AUD_CUST_AMP_Set_5538_Gen_Config(pAmp);
    AUD_CUST_AMP_Set_5538_BQ(pAmp);
    AUD_CUST_AMP_Set_5538_BassTreble(pAmp);
    AUD_CUST_AMP_Set_5538_DRC(pAmp);
    AUD_CUST_AMP_Set_5538_LOUD(pAmp);
    AUD_CUST_AMP_Set_5538_Other(pAmp);
}

static struct aud_cust_amp_func_tbl _r5538Funcs = 
{
    AUD_CUST_AMP_5538_Init,     //pfnCustInit;
    NULL,                       //pfnCustSuspend;
    NULL,                       //pfnCustResume;
    AUD_CUST_AMP_5538_Mute,     //pfnCustMute;
    AUD_CUST_AMP_5538_Refresh,  //pfnCustRefresh
};

void AUD_CUST_AMP_RegistAmp_5538(AMP_DATA_T* pAmp)
{
    strncpy(pAmp->name,"T5538", sizeof(pAmp->name)-1);
    pAmp->u4NotifyErrThreshold = NTFY_ERR_NUM_5538;

    pAmp->funcTbl = &_r5538Funcs;
}
