/* 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.
 *
 *****************************************************************************/

#ifndef MUSTANG_AUD_H
#define MUSTANG_AUD_H

#include "aud_if.h"

static const AUD_INPUT_MUX_SEL_T _armtMustangAudInputMux[] = 
{   // Input ID                 AdcMuxSel,  SwGpio1,    SwGpio2,    SwGpio3,    SwGpio4
    ///Mustang M1V1
    {AUD_INPUT_ID_COMP_VID_0,   0,    	    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_COMP_VID_1,   1,          SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_COMP_VID_2,   1,    		SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_COMP_VID_3,   1, 			SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_S_VID_0,      NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},  
    {AUD_INPUT_ID_S_VID_1,      NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_S_VID_2,      NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_YPBPR_0,      0,          SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},    /// The same with SCART2
    {AUD_INPUT_ID_YPBPR_1,      1,    		SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},            
    {AUD_INPUT_ID_YPBPR_2,    	1, 			SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_VGA_0,        2,          SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},    /// The same with DVI
    {AUD_INPUT_ID_VGA_1,        2, 			SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_HDMI_0,       2,    		SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},  
    {AUD_INPUT_ID_HDMI_1,       2,    		SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_HDMI_2,       2,    		SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_HDMI_3,       1,    		SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_HDMI_4,       2,    		SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_DVI_0,        NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},    /// The same with VGA
    {AUD_INPUT_ID_DVI_1,        NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_DVI_2,        NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},   
    {AUD_INPUT_ID_DVI_3,        NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_DVI_4,        NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_SCART_0,      1, 		    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_SCART_1,      1, 		    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},    /// The same with YCbCr
    {AUD_INPUT_ID_SCART_2,      NO_USED, 	SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_SCART_3,      NO_USED, 	SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_AUXIN_0,      NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED},
    {AUD_INPUT_ID_AUXIN_1,      NO_USED,    SW_NO_USED, SW_NO_USED, SW_NO_USED, SW_NO_USED}
};

static const AUD_MTS_FAC_T _arSonyMtsFactoryBrLa =
{
    50,                                // numers of check
    //****** stereo detection  **********************//
    35,                                // numers of pilot
    155,                               // higher threshold of pilot detection
    112,                               // lower threshold of pilot detection
    //****** SAP detection  *************************//
    30,                                // numers of SAP
    144,                               // higher threshold of SAP detection
    106,                               // lower threshold of SAP detection
    //****** high deviation mode  *******************//
    FALSE,                             // enable/disable of high deviation mode
    //****** carrier shift mode  ********************//
    TRUE,                              // enable/disable of carrier shift mode
    //****** FM saturation mute mode  ***************//
    FALSE,                             // enable/disable of saturation mute mode
    69,                                // higher threshold of saturation mute
    16,                                // lower threshold of saturation mute
    //****** FM carrier mute mode  ******************//
    FALSE,                             // enable/disable of FM carrier mute mode
    180,                               // higher threshold of FM carrier mute
    120,                               // lower threshold of FM carrier mute
    //****** prescale  ******************************//
    21,                                //mono and stereo prescale
    24,                                //SAP prescale
    //****** pilot offset calibration mode  *********//
    TRUE,                             // enable/disable of pilot calibration mode
    //****** SAP noise mute  ************************//
    10,                                 //  (higher threshold - lower threshold )of SAP noise mute
    12,                                // lower threshold of SAP noise mute
    //****** SAP filter selection   ************************//
    1,                                 //[0:auto/1:manual]
    1                                  // [0:big/1:small]
};

static const AUD_MTS_FAC_T _arSonyMtsFactory =
{
    50,                                // numers of check
    //****** stereo detection  **********************//
    35,                                // numers of pilot
    155,                               // higher threshold of pilot detection
    112,                               // lower threshold of pilot detection
    //****** SAP detection  *************************//
    30,                                // numers of SAP
    144,                               // higher threshold of SAP detection
    106,                               // lower threshold of SAP detection
    //****** high deviation mode  *******************//
    FALSE,                             // enable/disable of high deviation mode
    //****** carrier shift mode  ********************//
    TRUE,                              // enable/disable of carrier shift mode
    //****** FM saturation mute mode  ***************//
    FALSE,                             // enable/disable of saturation mute mode
    69,                                // higher threshold of saturation mute
    16,                                // lower threshold of saturation mute
    //****** FM carrier mute mode  ******************//
    FALSE,                             // enable/disable of FM carrier mute mode
    180,                               // higher threshold of FM carrier mute
    120,                               // lower threshold of FM carrier mute
    //****** prescale  ******************************//
    21,                                //mono and stereo prescale
    24,                                //SAP prescale
    //****** pilot offset calibration mode  *********//
    FALSE,                             // enable/disable of pilot calibration mode
    //****** SAP noise mute  ************************//
    10,                                 //  (higher threshold - lower threshold )of SAP noise mute
    12,                                // lower threshold of SAP noise mute
    //****** SAP filter selection   ************************//
    1,                                 //[0:auto/1:manual]
    1                                  // [0:big/1:small]
};

static const AUD_A2_FAC_T _arSonyA2Factory =
{
    //******  detection  ****************************//
    7,                                // numers of check
    10,                                // numers of double check
    1,                                 // mono weight
    1,                                 // stereo weight
    1,                                 // dual weight
    //****** high deviation mode  *******************//
    FALSE,                             // enable/disable of high deviation mode
    //****** carrier shift mode  ********************//
    FALSE,                             // enable/disable of carrier shift mode
    //****** FM carrier mute mode  ******************//
    FALSE,                             // enable/disable of FM carrier mute mode
    34,                                // higher threshold of FM carrier mute
    32,                                // lower threshold of FM carrier mute
    //****** prescale  ******************************//
    21,                                //A2 prescale
    //****** FM saturation mute mode  ***************//
    FALSE,                             // enable/disable of saturation mute mode
    //****** non-EU mode  ***************************//
    FALSE,                             // enable/disable of non-EU mode
    //****** stereo/dual detection threshold  *******************//
    128,                               // mono 2 stereo threshold for EU model
    64,                                // stereo 2 mono threshold for EU model
    112,                               // mono 2 stereo threshold for Korea model
    80,                                // stereo 2 mono threshold for Korea model
    656,                               // mono 2 stereo threshold for EU model
    896                                // stereo 2 mono threshold for EU model
};

static const AUD_PAL_FAC_T _arSonyPalFactory =
{
    //******  detection  ****************************//
    6,                                 // correction threshold
    63,                                // total sync loop
    8,                                 // error threshold
    1056,                              // parity error threshold
    512,                               // every number frames
    //****** high deviation mode  *******************//
    TRUE,                              // enable/disable of high deviation mode
    //****** AM mute mode  ******************//
    FALSE,                             // enable/disable of AM mute mode
    53,                                // higher threshold of AM mute
    37,                                // lower threshold of AM mute
    //****** carrier shift mode  ********************//
    FALSE,                             // enable/disable of carrier shift mode
    //****** FM carrier mute mode  ******************//
    FALSE,                             // enable/disable of FM carrier mute mode
    32,                                // higher threshold of FM carrier mute
    16,                                // lower threshold of FM carrier mute
    //****** prescale  ******************************//
    21,                                //PAL prescale
    24,                                //AM prescale
    19,                                //NICAM prescale
    //****** FM saturation mute mode  ***************//
    FALSE,                             // enable/disable of saturation mute mode
    //****** non-EU mode  ***************************//
    FALSE,                       // enable/disable of non-EU mode
     //****** not to boost NICAM I ? ********************//
    FALSE                              // False :to boost nicam I by 4dB, True: not to boost NICAM I for 4dB
};

static const AUD_INPUT_MUX_SEL_TABLE_T _rMustangAudInputMuxTable = 
{
    (sizeof(_armtMustangAudInputMux)/sizeof(AUD_INPUT_MUX_SEL_T)),
    _armtMustangAudInputMux   
};
//-----------------------------------------------------------------------------
// Internal DAC channel config
//-----------------------------------------------------------------------------
static const AUD_INTER_DAC_CFG_T _arMustangMapleInterDacUsage = 
{
    AUD_CHL_DOWNMIX,    // AL0,AR0: Headphone
    AUD_CHL_BYPASS,     // AL1,AR1: SCART1-Lineout
    AUD_CHL_AUX,        // AL2,AR2: SCART2-TV Bypass
    AUD_CHL_L_R
};
/*
//-----------------------------------------------------------------------------
// Internal DAC channel config
//-----------------------------------------------------------------------------
static const AUD_INTER_DAC_CFG_T _arMustangInterDacUsage = 
{
    AUD_CHL_L_R,
    AUD_CHL_AUX, 
    AUD_CHL_L_R,
    AUD_CHL_BYPASS
};

static const AUD_ADAC_USAGE_T _arMustangAdacUsage = 
{
    AUD_ADAC_NULL,
    AUD_ADAC_NULL,
    AUD_ADAC_NULL,
    AUD_ADAC_NULL,
    AUD_CODEC_MT5365,
    AUD_CODEC_NULL,
    AUD_AMP_NULL,
    AUD_AMP_NULL
};
*/
static const AUD_ADAC_USAGE_T _arSakuraAdacUsage =
{
    AUD_ADAC_NULL,
    AUD_ADAC_NULL,
    AUD_ADAC_NULL,
    AUD_ADAC_NULL,
    AUD_CODEC_MT5398,
    AUD_CODEC_NULL,
    AUD_AMP_NULL,
    AUD_AMP_NULL
};

static const UINT8 _au1SakuraAudIecWordLength[AUD_STREAM_FROM_NUM] =
{
    IEC_WORD_LENGTH_24BIT,              // DVI
    IEC_WORD_LENGTH_24BIT,              // DIGITAL_TUNER
    IEC_WORD_LENGTH_24BIT,              // ANALOG_TUNER
    IEC_WORD_LENGTH_24BIT,              // SPDIF
    IEC_WORD_LENGTH_24BIT,              // LINE_IN
    IEC_WORD_LENGTH_16BIT,              // HDMI
    IEC_WORD_LENGTH_24BIT,              // MEMORY
    IEC_WORD_LENGTH_24BIT,              // BUF_AGT
    IEC_WORD_LENGTH_24BIT,              // FEEDER
    IEC_WORD_LENGTH_24BIT,              // MULTI_MEDIA
    IEC_WORD_LENGTH_24BIT,              // LINE_IN_2
    IEC_WORD_LENGTH_24BIT,              // LINE_IN_3
    IEC_WORD_LENGTH_24BIT,              // GST    
    IEC_WORD_LENGTH_24BIT               // I2S IN
};
static const UINT8 _au1SakuraEuAudIecCategory[AUD_STREAM_FROM_NUM] = 
{
    IEC_ORIGINAL_BROAD_CAST_EU,        // DVI
    IEC_ORIGINAL_BROAD_CAST_EU,        // DIGITAL_TUNER 
    IEC_ORIGINAL_GENERAL,               // ANALOG_TUNER
    IEC_ORIGINAL_GENERAL,               // SPDIF
    IEC_ORIGINAL_GENERAL,               // LINE_IN
    IEC_ORIGINAL_BROAD_CAST_EU,        // HDMI
    IEC_ORIGINAL_GENERAL,               // MEMORY
    IEC_ORIGINAL_GENERAL,               // BUF_AGT
    IEC_ORIGINAL_GENERAL,               // FEEDER
    IEC_ORIGINAL_BROAD_CAST_EU,         // MULTI_MEDIA   
    IEC_ORIGINAL_GENERAL,               // LINE_IN_2
    IEC_ORIGINAL_GENERAL,               // LINE_IN_3   
    IEC_ORIGINAL_GENERAL,               // GST  
    IEC_ORIGINAL_GENERAL                // I2S IN   
};
static const UINT8 _au1SakuraJpAudIecCategory[AUD_STREAM_FROM_NUM] = 
{
    IEC_ORIGINAL_BROAD_CAST_JP,        // DVI
    IEC_ORIGINAL_BROAD_CAST_JP,        // DIGITAL_TUNER 
    IEC_ORIGINAL_GENERAL,               // ANALOG_TUNER
    IEC_ORIGINAL_GENERAL,               // SPDIF
    IEC_ORIGINAL_GENERAL,               // LINE_IN
    IEC_ORIGINAL_BROAD_CAST_JP,        // HDMI
    IEC_ORIGINAL_GENERAL,               // MEMORY
    IEC_ORIGINAL_GENERAL,               // BUF_AGT
    IEC_ORIGINAL_GENERAL,               // FEEDER
    IEC_ORIGINAL_BROAD_CAST_JP,         // MULTI_MEDIA    
    IEC_ORIGINAL_GENERAL,               // LINE_IN_2 
    IEC_ORIGINAL_GENERAL,               // LINE_IN_3    
    IEC_ORIGINAL_GENERAL,               // GST    
    IEC_ORIGINAL_GENERAL                // I2S IN    
};

static const UINT8 _au1UroborosUsAudIecCategory[AUD_STREAM_FROM_NUM] =
{
    IEC_ORIGINAL_BROAD_CAST,                               // DVI
    IEC_ORIGINAL_BROAD_CAST,                               // DIGITAL_TUNER
    IEC_ORIGINAL_GENERAL,                                  // ANALOG_TUNER
    IEC_ORIGINAL_GENERAL,                                  // SPDIF
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN
    IEC_ORIGINAL_BROAD_CAST | IEC_CATEGORY_LBIT,           // HDMI
    IEC_ORIGINAL_GENERAL,                                  // MEMORY
    IEC_ORIGINAL_GENERAL,                                  // BUF_AGT
    IEC_ORIGINAL_GENERAL,                                  // FEEDER
    IEC_ORIGINAL_BROAD_CAST,                               // MULTI_MEDIA
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN_2
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN_3
    IEC_ORIGINAL_GENERAL,                                  // GST
    IEC_ORIGINAL_GENERAL                                   // I2S IN
};
static const UINT8 _au1UroborosEuAudIecCategory[AUD_STREAM_FROM_NUM] =
{
    IEC_ORIGINAL_BROAD_CAST_EU,                            // DVI
    IEC_ORIGINAL_BROAD_CAST_EU,                            // DIGITAL_TUNER
    IEC_ORIGINAL_GENERAL,                                  // ANALOG_TUNER
    IEC_ORIGINAL_GENERAL,                                  // SPDIF
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN
    IEC_ORIGINAL_BROAD_CAST_EU | IEC_CATEGORY_LBIT,        // HDMI
    IEC_ORIGINAL_GENERAL,                                  // MEMORY
    IEC_ORIGINAL_GENERAL,                                  // BUF_AGT
    IEC_ORIGINAL_GENERAL,                                  // FEEDER
    IEC_ORIGINAL_BROAD_CAST_EU,                            // MULTI_MEDIA
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN_2
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN_3
    IEC_ORIGINAL_GENERAL,                                  // GST
    IEC_ORIGINAL_GENERAL                                   // I2S IN
};
static const UINT8 _au1UroborosJpAudIecCategory[AUD_STREAM_FROM_NUM] =
{
    IEC_ORIGINAL_BROAD_CAST_JP,                            // DVI
    IEC_ORIGINAL_BROAD_CAST_JP,                            // DIGITAL_TUNER
    IEC_ORIGINAL_GENERAL,                                  // ANALOG_TUNER
    IEC_ORIGINAL_GENERAL,                                  // SPDIF
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN
    IEC_ORIGINAL_BROAD_CAST_JP | IEC_CATEGORY_LBIT,        // HDMI
    IEC_ORIGINAL_GENERAL,                                  // MEMORY
    IEC_ORIGINAL_GENERAL,                                  // BUF_AGT
    IEC_ORIGINAL_GENERAL,                                  // FEEDER
    IEC_ORIGINAL_BROAD_CAST_JP,                            // MULTI_MEDIA
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN_2
    IEC_ORIGINAL_GENERAL,                                  // LINE_IN_3
    IEC_ORIGINAL_GENERAL,                                  // GST
    IEC_ORIGINAL_GENERAL                                   // I2S IN
};


static const AUD_AOUT_PAD_CFG_T _arSonyAoutPadTable =
{
    AUD_CH_FRONT_LEFT,  //AOSDATA0 ==> L/R
    AUD_CH_FRONT_LEFT,  //NA
    AUD_CH_REAR_LEFT,   //AOSDATA2 ==> LS/ RS
    AUD_CH_CENTER,      //AOSDATA3 ==> C/ SW
    AUD_CH_FRONT_LEFT,  //NA
    AUD_CH_FRONT_LEFT,  //NA
};

static const UINT32 _arSonyEuHeaacDefaultDialnormTable[3] =
{
    92, // -23db
    92, // -23db
    92, // -23db
};

static const UINT32 _arSonyUsHeaacDefaultDialnormTable[3] =
{
    96, // -24db
    96, // -24db
    96, // -24db
};

static const UINT32 _arSonyAribHeaacDefaultDialnormTable[3] =
{
    80, // -20db
    80, // -20db
    80, // -20db
};

static const UINT32 _arSonyJpHeaacDefaultDialnormTable[3] =
{
    124, // -31db
    124, // -31db
    124, // -31db
};

#endif /* MUSTANG_AUD_H */

