1 //<MStar Software> 2 //****************************************************************************** 3 // MStar Software 4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. 5 // All software, firmware and related documentation herein ("MStar Software") are 6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by 7 // law, including, but not limited to, copyright law and international treaties. 8 // Any use, modification, reproduction, retransmission, or republication of all 9 // or part of MStar Software is expressly prohibited, unless prior written 10 // permission has been granted by MStar. 11 // 12 // By accessing, browsing and/or using MStar Software, you acknowledge that you 13 // have read, understood, and agree, to be bound by below terms ("Terms") and to 14 // comply with all applicable laws and regulations: 15 // 16 // 1. MStar shall retain any and all right, ownership and interest to MStar 17 // Software and any modification/derivatives thereof. 18 // No right, ownership, or interest to MStar Software and any 19 // modification/derivatives thereof is transferred to you under Terms. 20 // 21 // 2. You understand that MStar Software might include, incorporate or be 22 // supplied together with third party`s software and the use of MStar 23 // Software may require additional licenses from third parties. 24 // Therefore, you hereby agree it is your sole responsibility to separately 25 // obtain any and all third party right and license necessary for your use of 26 // such third party`s software. 27 // 28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as 29 // MStar`s confidential information and you agree to keep MStar`s 30 // confidential information in strictest confidence and not disclose to any 31 // third party. 32 // 33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any 34 // kind. Any warranties are hereby expressly disclaimed by MStar, including 35 // without limitation, any warranties of merchantability, non-infringement of 36 // intellectual property rights, fitness for a particular purpose, error free 37 // and in conformity with any international standard. You agree to waive any 38 // claim against MStar for any loss, damage, cost or expense that you may 39 // incur related to your use of MStar Software. 40 // In no event shall MStar be liable for any direct, indirect, incidental or 41 // consequential damages, including without limitation, lost of profit or 42 // revenues, lost or damage of data, and unauthorized system use. 43 // You agree that this Section 4 shall still apply without being affected 44 // even if MStar Software has been modified by MStar in accordance with your 45 // request or instruction for your use, except otherwise agreed by both 46 // parties in writing. 47 // 48 // 5. If requested, MStar may from time to time provide technical supports or 49 // services in relation with MStar Software to you for your use of 50 // MStar Software in conjunction with your or your customer`s product 51 // ("Services"). 52 // You understand and agree that, except otherwise agreed by both parties in 53 // writing, Services are provided on an "AS IS" basis and the warranty 54 // disclaimer set forth in Section 4 above shall apply. 55 // 56 // 6. Nothing contained herein shall be construed as by implication, estoppels 57 // or otherwise: 58 // (a) conferring any license or right to use MStar name, trademark, service 59 // mark, symbol or any other identification; 60 // (b) obligating MStar or any of its affiliates to furnish any person, 61 // including without limitation, you and your customers, any assistance 62 // of any kind whatsoever, or any information; or 63 // (c) conferring any license or right under any intellectual property right. 64 // 65 // 7. These terms shall be governed by and construed in accordance with the laws 66 // of Taiwan, R.O.C., excluding its conflict of law rules. 67 // Any and all dispute arising out hereof or related hereto shall be finally 68 // settled by arbitration referred to the Chinese Arbitration Association, 69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration 70 // Rules of the Association by three (3) arbitrators appointed in accordance 71 // with the said Rules. 72 // The place of arbitration shall be in Taipei, Taiwan and the language shall 73 // be English. 74 // The arbitration award shall be final and binding to both parties. 75 // 76 //****************************************************************************** 77 //<MStar Software> 78 //////////////////////////////////////////////////////////////////////////////// 79 // 80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc. 81 // All rights reserved. 82 // 83 // Unless otherwise stipulated in writing, any and all information contained 84 // herein regardless in any format shall remain the sole proprietary of 85 // MStar Semiconductor Inc. and be kept in strict confidence 86 // ("MStar Confidential Information") by the recipient. 87 // Any unauthorized act including without limitation unauthorized disclosure, 88 // copying, use, reproduction, sale, distribution, modification, disassembling, 89 // reverse engineering and compiling of the contents of MStar Confidential 90 // Information is unlawful and strictly prohibited. MStar hereby reserves the 91 // rights to any and all damages, losses, costs and expenses resulting therefrom. 92 // 93 /// @file drvAUDIO.h 94 /// @author MStar Semiconductor Inc. 95 /// @brief Audio common driver 96 // 97 /////////////////////////////////////////////////////////////////////////////// 98 //////////////////////////////////////////////////////////////////////////////// 99 100 #ifndef _DRVAUDIO_H_ 101 #define _DRVAUDIO_H_ 102 103 //////////////////////////////////////////////////////////////////////////////// 104 // Header Files 105 //////////////////////////////////////////////////////////////////////////////// 106 #include "MsTypes.h" 107 #include "drvAUDIO_if.h" 108 109 #ifdef __cplusplus 110 extern "C" 111 { 112 #endif 113 114 //////////////////////////////////////////////////////////////////////////////// 115 // Define & data type 116 //////////////////////////////////////////////////////////////////////////////// 117 /// Version string. 118 #define MSIF_AUDIO_LIB_CODE {'A','U','D','-'} //Lib code 119 #define MSIF_AUDIO_LIBVER {'0','0'} //LIB version 120 #define MSIF_AUDIO_BUILDNUM {'5','B'} //Build Number 121 #define MSIF_AUDIO_CHANGELIST {'0','0','0','0','0','0','0','0'} //P4 ChangeList Number 122 123 #define AUD_DRV_VERSION /* Character String for DRV/API version */ \ 124 MSIF_TAG, /* 'MSIF' */ \ 125 MSIF_CLASS, /* '00' */ \ 126 MSIF_CUS, /* 0x0000 */ \ 127 MSIF_MOD, /* 0x0000 */ \ 128 MSIF_CHIP, \ 129 MSIF_CPU, \ 130 MSIF_AUDIO_LIB_CODE, /* IP__ */ \ 131 MSIF_AUDIO_LIBVER, /* 0.0 ~ Z.Z */ \ 132 MSIF_AUDIO_BUILDNUM, /* 00 ~ 99 */ \ 133 MSIF_AUDIO_CHANGELIST, /* CL# */ \ 134 MSIF_OS 135 136 #if defined(UFO_PUBLIC_HEADER_300) || defined(UFO_PUBLIC_HEADER_212) 137 138 #define AU_memcpy( pDstAddr, pSrcAddr, u32Size) \ 139 do { \ 140 register unsigned long u32I=0; \ 141 register unsigned long u32Dst = (unsigned long)pDstAddr; \ 142 void * pSrc = (void *)pSrcAddr; \ 143 if( (u32Dst % 4) || ((unsigned long)pSrc % 4) ) \ 144 { \ 145 for( u32I=0; u32I< (unsigned long)(u32Size); u32I++) \ 146 { \ 147 ((volatile unsigned char *)u32Dst)[u32I] = ((volatile unsigned char *)pSrc)[u32I]; \ 148 } \ 149 } \ 150 else \ 151 { \ 152 for( u32I=0; u32I < ((unsigned long)(u32Size)/4); u32I++) \ 153 { \ 154 ((volatile unsigned long *)u32Dst)[u32I] = ((volatile unsigned long *)pSrc)[u32I]; \ 155 } \ 156 u32Dst += u32I*4; \ 157 pSrc = (void *)((unsigned long)pSrc + u32I*4); \ 158 if((u32Size)%4) \ 159 { \ 160 for( u32I=0; u32I<((unsigned long)(u32Size)%4); u32I++) \ 161 { \ 162 ((volatile unsigned char *)u32Dst)[u32I] = ((volatile unsigned char *)pSrc)[u32I]; \ 163 } \ 164 } \ 165 } \ 166 }while(0) 167 168 #else 169 170 #define AU_memcpy( pDstAddr, pSrcAddr, u32Size) \ 171 do { \ 172 register MS_U32 u32I=0; \ 173 register MS_VIRT virtDst = (MS_VIRT)pDstAddr; \ 174 void * pSrc = (void *)pSrcAddr; \ 175 if( (virtDst % 4) || ((MS_VIRT)pSrc % 4) ) \ 176 { \ 177 for( u32I=0; u32I< (MS_U32)(u32Size); u32I++) \ 178 { \ 179 ((volatile MS_U8 *)virtDst)[u32I] = ((volatile MS_U8 *)pSrc)[u32I]; \ 180 } \ 181 } \ 182 else \ 183 { \ 184 for( u32I=0; u32I < ((MS_U32)(u32Size)/4); u32I++) \ 185 { \ 186 ((volatile MS_U32 *)virtDst)[u32I] = ((volatile MS_U32 *)pSrc)[u32I]; \ 187 } \ 188 virtDst += u32I*4; \ 189 pSrc = (void *)((MS_VIRT)pSrc + u32I*4); \ 190 if((u32Size)%4) \ 191 { \ 192 for( u32I=0; u32I<((MS_U32)(u32Size)%4); u32I++) \ 193 { \ 194 ((volatile MS_U8 *)virtDst)[u32I] = ((volatile MS_U8 *)pSrc)[u32I]; \ 195 } \ 196 } \ 197 } \ 198 }while(0) 199 200 #endif 201 202 #define AU_Memset(pDstAddr, u8value, u32Size) \ 203 do { \ 204 MS_U32 i = 0; \ 205 volatile MS_U8 *dst = (volatile MS_U8 *)(pDstAddr); \ 206 for (i = 0; i < (u32Size); i++) \ 207 { \ 208 dst[i] = (u8value); \ 209 } \ 210 } while (0) 211 212 #define HDMI_NonPCM_Mask 0x01 213 #define HDMI_Input_Path_Mask 0x10 214 215 typedef enum 216 { 217 Hdmi_Input_Main = 0x00, 218 Hdmi_Input_Sub = 0x10, 219 220 } Hdmi_Input_Path; 221 222 //================================================================ 223 // AUDIO version informtion functions 224 //================================================================ 225 extern MS_BOOL MDrv_AUD_GetLibVer(const MSIF_Version **ppVersion); 226 227 //================================================================ 228 // Basic Register read/write function 229 //================================================================ 230 MS_U16 MDrv_AUDIO_ReadReg(MS_U32 u32RegAddr); 231 void MDrv_AUDIO_WriteReg(MS_U32 u32RegAddr, MS_U16 u16Val); 232 void MDrv_AUDIO_WriteMaskReg(MS_U32 u32RegAddr, MS_U16 u16Mask, MS_U16 u16Val); 233 234 MS_U8 MDrv_AUDIO_ReadByte(MS_U32 addr); 235 MS_U8 MDrv_AUDIO_DecReadByte(MS_U32 addr); 236 MS_U8 MDrv_AUDIO_SeReadByte(MS_U32 addr); 237 238 void MDrv_AUDIO_WriteByte(MS_U32 addr, MS_U8 value); 239 void MDrv_AUDIO_DecWriteByte(MS_U32 addr, MS_U8 value); 240 void MDrv_AUDIO_SeWriteByte(MS_U32 addr, MS_U8 value); 241 242 void MDrv_AUDIO_WriteMaskByte(MS_U32 u32RegAddr, MS_U8 u8Mask, MS_U8 u8Val); 243 void MDrv_AUDIO_DecWriteMaskByte(MS_U32 u32RegAddr, MS_U8 u8Mask, MS_U8 u8Val); 244 void MDrv_AUDIO_SeWriteMaskByte(MS_U32 u32RegAddr, MS_U8 u8Mask, MS_U8 u8Val); 245 246 MS_U16 MDrv_AUDIO_ReadDecMailBox(MS_U8 paramNum); 247 void MDrv_AUDIO_WriteDecMailBox(MS_U8 paramNum, MS_U16 data1); 248 MS_U16 MDrv_AUDIO_ReadSeMailBox(MS_U8 paramNum); 249 void MDrv_AUDIO_WriteSeMailBox(MS_U8 paramNum, MS_U16 data1); 250 251 //================================================================ 252 // For Audio initialize 253 //================================================================ 254 void MDrv_AUDIO_InitMMIO(void); 255 MS_BOOL MDrv_AUDIO_AttachInterrupt(MS_BOOL bEnable); 256 MS_BOOL MDrv_AUDIO_Mutex_Init(void); 257 MS_BOOL MDrv_AUDIO_SHM_Init(void); 258 MS_BOOL MDrv_AUDIO_Init(void); 259 MS_BOOL MDrv_AUDIO_Close(void); 260 MS_BOOL MDrv_AUDIO_Open(void); 261 void MDrv_AUDIO_WriteInitTable(void); 262 void MDrv_AUDIO_WritePreInitTable(void); //Refine power on sequence for earphone & DAC pop noise issue 263 void MDrv_AUDIO_EnaEarphone_LowPower_Stage(void); //Refine power on sequence for earphone & DAC pop noise issue 264 void MDrv_AUDIO_EnaEarphone_HighDriving_Stage(void); //Refine power on sequence for earphone & DAC pop noise issue 265 void MDrv_AUDIO_SwResetMAD(void); 266 #if defined(UFO_PUBLIC_HEADER_300) || defined(UFO_PUBLIC_HEADER_212) 267 void MDrv_AUDIO_SetDspBaseAddr(MS_U8 u8Index, MS_U32 u32Bin_Base_Address, MS_U32 u32Mad_Base_Buffer_Adr); 268 #else 269 void MDrv_AUDIO_SetDspBaseAddr(MS_U8 u8Index, MS_PHY phyBin_Base_Address, MS_PHY phyMad_Base_Buffer_Adr); 270 #endif 271 MS_PHY MDrv_AUDIO_GetDspBinBaseAddr(MS_U8 u8Iindex); 272 MS_PHY MDrv_AUDIO_GetDspMadBaseAddr(MS_U8 u8Index) ; 273 void MDrv_AUDIO_DspBootOnDDR(MS_BOOL bEnable); 274 MS_BOOL MDrv_AUDIO_DecoderLoadCode(void); 275 MS_BOOL MDrv_AUDIO_SeSystemLoadCode(void); 276 void MDrv_AUDIO_DspReboot(MS_U8 param); 277 void MDrv_AUDIO_RebootDecDSP(void); 278 void MDrv_AUDIO_TriggerSifPLL(void); 279 void MDrv_AUDIO_SetPlayFileFlag(MS_BOOL bDspType, MS_BOOL bSet); 280 MS_BOOL MDrv_AUDIO_GetPlayFileFlag(MS_BOOL bDspType); 281 MS_BOOL MDrv_AUDIO_InitialVars(void); 282 void MDrv_AUDIO_SET_INIT_FLAG(MS_BOOL bSet); 283 MS_BOOL MDrv_AUDIO_GET_INIT_FLAG(void); 284 void MDrv_AUDIO_ResetDspCodeType(void); 285 286 //================================================================ 287 // Audio I/O Config. function 288 //================================================================ 289 AUDIO_PATH_GROUP_TYPE MDrv_AUDIO_GetPathGroup(void); 290 void MDrv_AUDIO_SetNormalPath(AUDIO_PATH_TYPE u8Path, AUDIO_INPUT_TYPE u8Input, AUDIO_OUTPUT_TYPE output); 291 void MDrv_AUDIO_SetInputPath( AUDIO_INPUT_TYPE u8Input, AUDIO_PATH_TYPE u8Path); 292 void MDrv_AUDIO_SetOutputPath( AUDIO_PATH_TYPE u8Path, AUDIO_OUTPUT_TYPE u8Output); 293 void MDrv_AUDIO_SetInternalPath(AUDIO_INTERNAL_PATH_TYPE u8Path, AUDIO_OUTPUT_TYPE u8Output); 294 295 MS_U8 MDrv_AUDIO_ReadDspCodeType(void); 296 297 void MDrv_AUDIO_BT_SetUploadRate(MS_BOOL bEnable, MS_U8 u8Samprate); 298 void MDrv_AUDIO_BT_SetBufferCounter(MS_U32 u32Counter); 299 300 MS_U8 MDrv_AUDIO_ReadDspCounter(AUDIO_DSP_COUNTER_TYPE CounterType); 301 void MDrv_AUDIO_SetPowerDownWait(MS_BOOL bEnable); 302 MS_BOOL MDrv_AUDIO_IsDTV(void); 303 void MDrv_AUDIO_SetFading(MS_U32 u32VolFading); 304 305 //===================================================== 306 // AUDIO SPDIF Relational Hal Function 307 //===================================================== 308 void MDrv_AUDIO_SPDIF_SetMute(MS_U8 mute_en); 309 void MDrv_AUDIO_SPDIF_SetMode(MS_U8 spdif_mode, MS_U8 input_src); 310 void MDrv_AUDIO_SPDIF_ByPassChannel(MS_BOOL u8Enable); 311 void MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CS_MODE_TYPE eType, SPDIF_CS_MODE_VALUE eValue); 312 void MDrv_AUDIO_SPDIF_Monitor_SamplingRate(void); 313 //===================================================== 314 // AUDIO HDMI Relational Hal Function 315 //===================================================== 316 void MDrv_AUDIO_HDMI_Tx_GetStatus(MS_BOOL *onOff, AUDIO_FS_TYPE *hdmi_SmpFreq, HDMI_TX_OUTPUT_TYPE *outType ); 317 MS_U8 MDrv_AUDIO_HDMI_DolbyMonitor(void); 318 void MDrv_AUDIO_HDMI_AC3_PathCFG(MS_U8 u8Ctrl); 319 void MDrv_AUDIO_HDMI_TX_SetMode(HDMI_TX_OUTPUT_TYPE outType, AUDIO_SOURCE_INFO_TYPE eSource); 320 //================================================================ 321 // for audio driver internal use function 322 //================================================================ 323 void MDrv_AUDIO_AdcInit(void); 324 MS_U8 MDrv_AUDIO_GetDecoderStatus(void); 325 326 MS_U16 MDrv_AUDIO_GetUniDecodeDoneTag(void); 327 328 void MDrv_AUDIO_update_DspUsage(AUDIO_SOURCE_INFO_TYPE eSourceType); 329 //================================================================ 330 // Audio ALSA Interface Relational Function 331 //================================================================ 332 MS_BOOL MDrv_AUDIO_ALSA_Enable(MS_BOOL bEnable); 333 334 void MDrv_AUDIO_DumpDspInfo(void); 335 336 MS_U32 MDrv_AUDIO_GetCaps(AUDIO_DEC_ID DecId, MS_U32 *pCaps); 337 338 #ifdef __cplusplus 339 } 340 #endif 341 342 #endif 343 344