xref: /utopia/UTPA2-700.0.x/modules/audio/hal/manhattan/audio/halAUDIO.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
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 ////////////////////////////////////////////////////////////////////////////////
94 
95 #ifndef _DEV_AUDIO_H_
96 #define _DEV_AUDIO_H_
97 #include "MsCommon.h"
98 #include "halAUR2.h"
99 
100 
101 #include "MsTypes.h"
102 #include "drvAUDIO_if.h"
103 #include "../../../drv/audio/internal/drvAUDIO_internal.h"
104 #include "../../drv/mbx/apiMBX_St.h"
105 #include "../../drv/mbx/apiMBX.h"
106 
107 #ifdef MSOS_TYPE_LINUX_KERNEL
108 #include <linux/delay.h>
109 #endif
110 
111 //-------------------------------------------------------------------------------------------------
112 //  Macro and Define
113 //-------------------------------------------------------------------------------------------------
114 
115 #define AUDIO_SHM_NAME    "Linux AUDIO driver"
116 #define AUDIO_TEE_INFO_SHM_NAME    "AUDIO TEE INFO SHM"
117 
118 #define AUD_CHK_DSP_READ_RDY            0x08
119 #define AUD_CHK_DSP_WRITE_RDY           0x10
120 
121 #define AUMASK_BIT0    0x0001
122 #define AUMASK_BIT1    0x0002
123 #define AUMASK_BIT2    0x0004
124 #define AUMASK_BIT3    0x0008
125 #define AUMASK_BIT4    0x0010
126 #define AUMASK_BIT5    0x0020
127 #define AUMASK_BIT6    0x0040
128 #define AUMASK_BIT7    0x0080
129 
130 #define au_bit0_(val)  ((MS_U8)(val & AUMASK_BIT0))
131 #define au_bit1_(val)  ((MS_U8)(val & AUMASK_BIT1))
132 #define au_bit2_(val)  ((MS_U8)(val & AUMASK_BIT2))
133 #define au_bit3_(val)  ((MS_U8)(val & AUMASK_BIT3))
134 #define au_bit4_(val)  ((MS_U8)(val & AUMASK_BIT4))
135 #define au_bit5_(val)  ((MS_U8)(val & AUMASK_BIT5))
136 #define au_bit6_(val)  ((MS_U8)(val & AUMASK_BIT6))
137 #define au_bit7_(val)  ((MS_U8)(val & AUMASK_BIT7))
138 
139 #define R1BYTE(u32Addr, u8mask) \
140     (READ_BYTE ((MS_VIRT)_gMIO_MapBase + ((u32Addr) << 1) - ((u32Addr) & 1)) & (u8mask))
141 
142 #define W1BYTE(u32Addr, u8Val, u8mask)      \
143     (WRITE_BYTE((MS_VIRT)_gMIO_MapBase + ((u32Addr) << 1) - ((u32Addr) & 1), (R1BYTE(u32Addr, 0xFF) & ~(u8mask)) | ((u8Val) & (u8mask))))
144 
145 // u32Addr must be 16bit aligned
146 #define R2BYTE(u32Addr, u16mask)  \
147     (READ_WORD ((MS_VIRT)_gMIO_MapBase + ((u32Addr) << 1)) & (u16mask))
148 
149 // u32Addr must be 16bit aligned
150 #define W2BYTE(u32Addr, u16Val, u16mask)    \
151     (WRITE_WORD((MS_VIRT)_gMIO_MapBase + ((u32Addr) << 1), (R2BYTE(u32Addr, 15:0) & ~(u16mask)) | ((u16Val) & (u16mask))))
152 
153 ///////////////////////////////////////////////////////////////
154 #define _AU_AbsWriteByte( u32Reg, u8Val )   \
155      do {   \
156      (WRITE_BYTE((MS_VIRT)_gMIO_MapBase + ((u32Reg) << 1) - ((u32Reg) & 1), u8Val)); \
157           }while(0)
158 
159 #define _AU_AbsWrite2Byte( u32Reg, u16Val ) \
160      do {   \
161      (WRITE_WORD((MS_VIRT)_gMIO_MapBase + ((u32Reg) << 1), u16Val)); \
162           }while(0)
163 
164 #define _AU_AbsWriteMaskByte( u32Reg, u8Mask, u8Val )   \
165     do {    \
166     (WRITE_BYTE((MS_VIRT)_gMIO_MapBase + ((u32Reg) << 1) - ((u32Reg) & 1), (R1BYTE((u32Reg), 0xFF) & ~(u8Mask)) | ((u8Val) & (u8Mask))));    \
167         }while(0)
168 
169 #define _AU_AbsReadByte( u32Reg) (READ_BYTE ((MS_VIRT)_gMIO_MapBase + ((u32Reg) << 1) - ((u32Reg) & 1)))
170 #define _AU_AbsRead2Byte( u32Reg)  (READ_WORD ((MS_VIRT)_gMIO_MapBase + ((u32Reg) << 1)) )
171 
172 #define HAL_AUDIO_DecReadReg    HAL_AUDIO_ReadReg
173 #define HAL_AUDIO_SeReadReg    HAL_AUDIO_ReadReg
174 #define HAL_AUDIO_DecReadByte   HAL_AUDIO_ReadByte
175 #define HAL_AUDIO_SeReadByte   HAL_AUDIO_ReadByte
176 #define HAL_AUDIO_DecWriteByte  HAL_AUDIO_WriteByte
177 #define HAL_AUDIO_SeWriteByte  HAL_AUDIO_WriteByte
178 #define HAL_AUDIO_DecWriteMaskByte  HAL_AUDIO_WriteMaskByte
179 #define HAL_AUDIO_SeWriteMaskByte  HAL_AUDIO_WriteMaskByte
180 #define HAL_AUDIO_DecWriteReg  HAL_AUDIO_WriteReg
181 #define HAL_AUDIO_SeWriteReg  HAL_AUDIO_WriteReg
182 #define HAL_AUDIO_DecWriteMaskReg  HAL_AUDIO_WriteMaskReg
183 #define HAL_AUDIO_SeWriteMaskReg  HAL_AUDIO_WriteMaskReg
184 
185 //Enable MS10 DDT Dual decode
186 #define MS10_DDT_DUAL
187 
188 #if (defined(CONFIG_MBOOT))
189     #define AUDIO_DELAY1US(x)                {int xxxx, jjjj, iiii=0; for(xxxx=0; xxxx<x; xxxx++) for(jjjj=0; jjjj<10; jjjj++) iiii++; }
190     #define AUDIO_DELAY1MS(x)                {int xxxx, jjjj, iiii=0; for(xxxx=0; xxxx<x; xxxx++) for(jjjj=0; jjjj<10000; jjjj++) iiii++; }
191 #elif (defined(MSOS_TYPE_LINUX_KERNEL))
192     #define AUDIO_DELAY1US(x)                udelay(x)
193     #define AUDIO_DELAY1MS(x)                mdelay(x)
194 #elif (defined(MCU_AEON))
195     #define AUDIO_DELAY1US(x)                MsOS_DelayTaskUs(x)
196     #define AUDIO_DELAY1MS(x)                AUDIO_DELAY1US(x*1000)
197 #else
198     #define AUDIO_DELAY1US(x)                MsOS_DelayTaskUs(x)
199     #define AUDIO_DELAY1MS(x)                MsOS_DelayTask(x)
200 #endif
201 
202 #define ASND_R2_SUPPORT    1
203 
204 //-------------------------------------------------------------------------------------------------
205 //  Type and Structure
206 //-------------------------------------------------------------------------------------------------
207 typedef struct
208 {
209     MS_S64 curPTS;
210     MS_U32 os_Time;
211     MS_BOOL set2Clr;
212 } AUDIO_PTS_INFO;
213 
214 typedef struct
215 {
216     MS_U32 Mem_addr;
217     MS_U32 Mem_size;
218 } AUDIO_RTSP_INFO;
219 
220 /// Audio register structure
221 typedef struct
222 {
223     MS_U32  u32Addr;                    ///< Reg address
224     MS_U8   u8Mask;                     ///<Reg Mask
225     MS_U8   u8Value;                    ///<Reg Value
226 }AUDIO_REG_TYPE, *PAUDIO_REG_TYPE;
227 
228 /// Audio register structure2
229 typedef struct
230 {
231     MS_U32   u32Addr;                    ///< Reg address2
232     MS_U16   u16Mask;                     ///<Reg Mask2
233     MS_U16   u16Value;                    ///<Reg Value2
234 }AUDIO_REG_TYPE2, *PAUDIO_REG_TYPE2;
235 
236 //================================================================
237 //  Structure
238 //================================================================
239 
240 //-------------------------------------------------------------------------------------------------
241 //  Function and Variable
242 //-------------------------------------------------------------------------------------------------
243 MS_BOOL HAL_AUDIO_InitialVars(void);
244 MS_BOOL HAL_AUDIO_DeInitialVars(void);
245 void HAL_AUDIO_SET_INIT_FLAG(MS_BOOL bSet);
246 MS_BOOL HAL_AUDIO_GET_INIT_FLAG(void);
247 MS_BOOL HAL_AUDIO_Mutex_Init(void);
248 MS_BOOL HAL_AUDIO_Mutex_DeInit(void);
249 void    HAL_AUDIO_Set_MMIO_BASE(MS_VIRT _MMIO_MapBase);
250 AU_CHIP_TYPE HAL_AUDIO_GetChipType(void);
251 void HAL_AUDIO_SET_IPAUTH(MS_U32 ip_auth);
252 
253 //================================================================
254 //  Basic Register read/write function
255 //================================================================
256 MS_U8   HAL_AUDIO_AbsReadByte(MS_U32 u32RegAddr);
257 MS_U8   HAL_AUDIO_ReadByte(MS_U32 u32RegAddr);
258 MS_U16  HAL_AUDIO_AbsReadReg(MS_U32 u32RegAddr);
259 MS_U16  HAL_AUDIO_ReadReg(MS_U32 u32RegAddr);
260 void    HAL_AUDIO_AbsWriteByte(MS_U32 u32RegAddr, MS_U8 u8Val);
261 void    HAL_AUDIO_WriteByte(MS_U32 u32RegAddr, MS_U8 u8Val);
262 void    HAL_AUDIO_AbsWriteReg(MS_U32 u32RegAddr, MS_U16 u16Val);
263 void    HAL_AUDIO_WriteReg(MS_U32 u32RegAddr, MS_U16 u16Val);
264 void    HAL_AUDIO_AbsWriteMaskReg(MS_U32 u32RegAddr, MS_U16 u16Mask, MS_U16 u16Val);
265 void    HAL_AUDIO_WriteMaskReg(MS_U32 u32RegAddr, MS_U16 u16Mask, MS_U16 u16Val);
266 void    HAL_AUDIO_AbsWriteMaskByte(MS_U32 u32RegAddr, MS_U8 u8Mask, MS_U8 u8Val);
267 void    HAL_AUDIO_WriteMaskByte(MS_U32 u32RegAddr, MS_U8 u8Mask, MS_U8 u8Val);
268 
269 void    _HAL_AUDIO_Write4Byte(MS_U32 u32RegAddr, MS_U32 u32Val);
270 
271 void    HAL_AUDIO_WriteMailBox(MS_BOOL bDspType, MS_U8 u8ParamNum, MS_U16 u16Data);
272 MS_U16  HAL_AUDIO_ReadMailBox(MS_BOOL bDspType, MS_U8 u8ParamNum);
273 void    HAL_AUDIO_DmaReader_AllInput_Init(void);
274 
275 //================================================================
276 //  For Audio initialize
277 //================================================================
278 MS_BOOL HAL_AUDIO_Init(MS_BOOL Initype);
279 void    HAL_AUDIO_WriteInitTable(void);
280 void    HAL_AUDIO_WritePreInitTable(void);                //Refine power on sequence for earphone & DAC pop noise issue
281 void    HAL_AUDIO_WriteStopDecTable(void);                //Set stop command to R2/DSP
282 void    HAL_AUDIO_EnaEarphone_LowPower_Stage(void);        //Refine power on sequence for earphone & DAC pop noise issue
283 void    HAL_AUDIO_EnaEarphone_HighDriving_Stage(void);    //Refine power on sequence for earphone & DAC pop noise issue
284 void    HAL_AUDIO_SetPowerOn(MS_BOOL bPower_on);
285 void    HAL_AUDIO_ADCInit(void);
286 void    HAL_AUDIO_SwResetMAD(void);
287 void    HAL_AUDIO_ResetDSP(void);
288 void    HAL_AUDIO_TriggerSifPLL(void);
289 
290 void    HAL_AUDIO_DecDspISR(void);
291 void    HAL_AUDIO_SeDspISR(void);
292 
293 void    HAL_AUDIO_SetPlayFileFlag(MS_BOOL bDspType, MS_BOOL bSet);
294 MS_BOOL HAL_AUDIO_GetPlayFileFlag(MS_BOOL bDspType);
295 void    HAL_AUDIO_SetEncodeDoneFlag(MS_BOOL bSet);
296 MS_BOOL HAL_AUDIO_GetEncodeDoneFlag(void);
297 void    HAL_AUDIO_DmaWriter_Init(void);
298 MS_BOOL HAL_AUDIO_DmaWriter_Read(void* buffer, MS_U32 bytes);
299 MS_BOOL HAL_AUDIO_CheckBootOnInitState(void);
300 
301 //================================================================
302 // Audio I/O Config. function
303 //================================================================
304 AUDIO_PATH_GROUP_TYPE HAL_AUDIO_GetPathGroup(void);
305 void    HAL_AUDIO_SetNormalPath(AUDIO_PATH_TYPE path, AUDIO_INPUT_TYPE input, AUDIO_OUTPUT_TYPE output);
306 void    HAL_AUDIO_SetInputPath(AUDIO_INPUT_TYPE u8Input, AUDIO_PATH_TYPE u8Path);
307 void    HAL_AUDIO_SetOutputPath(AUDIO_PATH_TYPE u8Path, AUDIO_OUTPUT_TYPE u8Output);
308 void    HAL_AUDIO_SetInternalPath(AUDIO_INTERNAL_PATH_TYPE u8Path,  AUDIO_OUTPUT_TYPE u8Output);
309 void    HAL_AUDIO_FwTriggerDSP(MS_U16 u16Cmd);
310 void    HAL_AUDIO_DspBootOnDDR(MS_BOOL bEnable);
311 MS_BOOL HAL_AUDIO_GetIsDtvFlag(void);
312 void    HAL_AUDIO_SetIsDtvFlag(MS_BOOL);
313 
314 MS_U8   HAL_AUDIO_ReadDspCodeType(void);
315 MS_U8   HAL_AUDIO_Dec_Status(void);
316 MS_U8   HAL_AUDIO_Se_Status(void);
317 void    HAL_AUDIO_Set_Fading(MS_U32 u32VolFading);
318 
319 void    HAL_AUDIO_BT_SetUploadRate(MS_BOOL bEnable,MS_U8 u8Samprate);
320 void    HAL_AUDIO_BT_SetBufferCounter(MS_U32 u32Counter);
321 void    HAL_AUDIO_USBPCM_Enable(MS_BOOL bEnable);
322 MS_BOOL HAL_AUDIO_USBPCM_GetFlag(void);
323 void    HAL_AUDIO_USBPCM_SetFlag(MS_BOOL bEnable);
324 void    HAL_AUDIO_USBPCM_GetMemInfo(AUDIO_UPLOAD_INFO *uploadInfo);
325 MS_BOOL HAL_AUDIO_SetDataCaptureSource(AUDIO_DEVICE_TYPE eID, AUDIO_CAPTURE_SOURCE_TYPE eSource);
326 MS_BOOL HAL_AUDIO_PCMCapture_Init(const AUDIO_DEVICE_TYPE eID, const AUDIO_CAPTURE_SOURCE_TYPE eSource);
327 MS_BOOL HAL_AUDIO_PCMCapture_Start(const AUDIO_DEVICE_TYPE eID);
328 MS_BOOL HAL_AUDIO_PCMCapture_Stop(const AUDIO_DEVICE_TYPE eID);
329 MS_BOOL HAL_AUDIO_PCMCapture_Read(const AUDIO_DEVICE_TYPE eID, void* buffer, const MS_U32 bytes);
330 
331 void    _HAL_AUDIO_I2S_SetMode(MS_U8 u8Mode, MS_U8 u8Val);
332 
333 //=====================================================
334 // AUDIO SPDIF Relational Hal Function
335 //=====================================================
336 void    _HAL_AUDIO_SPDIF_HWEN(MS_BOOL bEnable);
337 void    _HAL_AUDIO_SPDIF_SetMute(MS_BOOL bEnMute);
338 void    HAL_AUDIO_SPDIF_SetMode(MS_U8 u8Spdif_mode, MS_U8 u8Input_src);
339 MS_U8   _HAL_AUDIO_SPDIF_GetMode(void);
340 void    _HAL_AUDIO_SPDIF_ByPassChannel(MS_BOOL bEnable);
341 void    HAL_AUDIO_SPDIF_SetSCMS(MS_U8 C_bit_en, MS_U8 L_bit_en);
342 MS_U8   HAL_AUDIO_SPDIF_GetSCMS(void);
343 void    HAL_AUDIO_SetChannelStatus(SPDIF_CS_MODE_TYPE eType, SPDIF_CS_MODE_VALUE eValue);
344 MS_BOOL HAL_AUDIO_SPDIF_ChannelStatus_CTRL(AUDIO_SPDIF_CS_TYPE cs_mode, AUDIO_SPDIF_CS_TYPE_STATUS status);
345 void    HAL_AUDIO_SPDIF_Monitor_SamplingRate(void);
346 void    HAL_AUDIO_SPDIF_SetOutputType(AUDIO_SOURCE_INFO_TYPE eSource, AUDIO_SPDIF_OUTPUT_TYPE eType);
347 
348 void HAL_AUDIO_SetDigitalOut(DIGITAL_OUTPUT_TYPE ePath, AUDIO_DIGITAL_OUTPUT_TYPE eDigitalMode);
349 MS_BOOL HAL_AUDIO_DigitalOut_SetChannelStatus(DIGITAL_OUTPUT_TYPE ePath, Digital_Out_Channel_Status_t *stChannelStatus);
350 MS_BOOL HAL_AUDIO_DigitalOut_GetChannelStatus(DIGITAL_OUTPUT_TYPE ePath, Digital_Out_Channel_Status_t *stChannelStatus);
351 void  HAL_AUDIO_Set_DecimationMode(AUDIO_OUTPUT_TYPE Output_Type, Audio_id ID);
352 
353 //=====================================================
354 // AUDIO HDMI Relational Hal Function
355 //=====================================================
356 void    _HAL_AUDIO_HDMI_Tx_SetMute(MS_BOOL bEnMute);
357 MS_BOOL HAL_AUDIO_HDMI_NonpcmMonitor(void);
358 MS_U8   HAL_AUDIO_HDMI_NonpcmMonitor2(void);
359 MS_U8   HAL_AUDIO_HDMI_DolbyMonitor(void);
360 void    HAL_AUDIO_HDMI_SetNonpcm(MS_U8 u8NonPCM_en);
361 void    HAL_AUDIO_HDMI_AC3_PathCFG(MS_U8 u8Ctrl);
362 MS_U16  HAL_AUDIO_HDMI_Get_SYNTH_FREQ(void);
363 void    HAL_AUDIO_HDMI_Set_DwonSample(MS_U8 ratio);
364 void    HAL_AUDIO_HDMIAutoMute(MS_U8 ch, MS_U8 value);
365 void    HAL_AUDIO_HDMI_Tx_GetStatus(MS_BOOL *onOff, AUDIO_FS_TYPE *hdmi_SmpFreq, HDMI_TX_OUTPUT_TYPE *outType );
366 void    HAL_AUDIO_HDMI_TX_SetMode(HDMI_TX_OUTPUT_TYPE outType, AUDIO_SOURCE_INFO_TYPE eSource);
367 MS_BOOL HAL_AUDIO_HDMI_RX_GetHdmiInAudioStatus( ST_HDMI_AUDIO_STATUS *p_hdmiAudioSts);
368 //================================================================
369 // for audio driver internal use function
370 //================================================================
371 void    _HAL_AUDIO_InitStep1(void);
372 void    HAL_AUDIO_SetDspBaseAddr(MS_U8 u8Index, MS_PHY phyBin_Base_Address, MS_PHY phyMad_Base_Buffer_Adr);
373 MS_PHY  HAL_AUDIO_GetDspMadBaseAddr(MS_U8 u8Index);
374 MS_PHY  HAL_AUDIO_GetDspBinBaseAddr(MS_U8 u8Index);
375 void HAL_AUDIO_SetDspCodeType(AUDIO_DSP_CODE_TYPE dspCodeType, MS_BOOL bFlag);
376 AUDIO_DSP_CODE_TYPE   HAL_AUDIO_GetDspCodeType(void);
377 void HAL_AUDIO_SetDsp2CodeType(AUDIO_DSP_CODE_TYPE dspCodeType, MS_BOOL bFlag);
378 AUDIO_DSP_CODE_TYPE   HAL_AUDIO_GetDsp2CodeType(void);
379 MS_U8   HAL_AUDIO_GetDSPalive(void);
380 void    HAL_AUDIO_SetDSPalive(MS_U8 alive);
381 void    HAL_AUDIO_SetAdvSndEffDspCodeType(AUDIO_DSP_CODE_TYPE dspCodeType, MS_BOOL bFlag);
382 AUDIO_DSP_CODE_TYPE   HAL_AUDIO_GetAdvSndEffDspCodeType(void);
383 void    HAL_AUDIO_BackupMailbox(void);
384 void    HAL_AUDIO_RestoreMailbox(void);
385 MS_U8   HAL_AUDIO_Enc_Status(void);
386 void    HAL_AUDIO_DmaReader_Init(SAMPLE_RATE sampleRate);
387 void    HAL_AUDIO_DmaReader_AllInput_Init(void);
388 MS_BOOL HAL_AUDIO_DmaReader_WritePCM(void* buffer, MS_U32 bytes);
389 void    HAL_AUDIO_SetEntertainmentMode(AUDIO_ENTERTAINMENT_MODE eMode);
390 MS_BOOL HAL_AUDIO_AlgReloadCode(MS_U8 u8Type);
391 MS_BOOL HAL_AUDIO_Alg2ReloadCode(AUDIO_DSP_CODE_TYPE dspCodeType);
392 MS_BOOL HAL_AUDIO_SetSystem(En_DVB_decSystemType enDecSystem);
393 MS_BOOL HAL_AUDIO_GetDecSysSupportStatus(En_DVB_decSystemType enDecSystem);
394 
395 MS_U16  HAL_AUDIO_GetUniDecodeDoneTag(void);
396 MS_U16  HAL_AUDIO_GetUniDecodeFrameCnt(AUDIO_DEC_ID eDSPId);
397 void    HAL_AUDIO_PTS_info( MS_VIRT );
398 
399 void    HAL_AUDIO_RebootDecDSP(void);
400 MS_U8   HAL_AUDIO_ReadDspCounter(AUDIO_DSP_COUNTER_TYPE  CounterType);
401 void    HAL_AUDIO_DspReboot(MS_U8 alive);
402 void    HAL_AUDIO_SetPowerDownWait(MS_BOOL bEnable);
403 void    HAL_AUDIO_SendIntrupt(MS_BOOL bDspType,MS_U16 u8Cmd);
404 MS_BOOL HAL_AUDIO_SeSystemLoadCode(void);
405 MS_BOOL HAL_AUDIO_DecoderLoadCode(void);
406 
407 extern MS_BOOL HAL_AUDSP_DspLoadCode(AUDIO_DSP_CODE_TYPE dspCodeType);
408 void    HAL_AUDIO_update_DspUsage(AUDIO_SOURCE_INFO_TYPE eSourceType);
409 Audio_id HAL_AUDIO_Convert_DecId_to_ADECId(AUDIO_DEC_ID dec_id);
410 
411 MS_U32 HAL_AUDIO_GetCaps(AUDIO_DEC_ID DecId, MS_U32 *pCaps);
412 MS_BOOL HAL_AUDIO_CheckPlayDone(void);
413 
414 MS_S32 HAL_AUDIO_InputSwitch(AUDIO_SWITCH_GROUP enGroup);
415 
416 //================================================================
417 // Audio ALSA Interface Relational Function
418 //================================================================
419 MS_BOOL HAL_AUDIO_ALSA_Check(void);
420 MS_BOOL HAL_AUDIO_ALSA_Enable(MS_BOOL bEnable);
421 
422 MS_BOOL HAL_AUDIO_AlgReloadCode2(AUDIO_DSP_ID id, AUDIO_DSP_CODE_TYPE code_type, void * pau_info);
423 MS_BOOL HAL_AUDIO_SetSystem2(AUDIO_DEC_ID DecId, En_DVB_decSystemType Param);
424 MS_BOOL HAL_AUDIO_SetDecodeSystem(AUDIO_DEC_ID DecId, AudioDecStatus_t *p_AudioDecStatus);
425 
426 //================================================================
427 // Audio dump debug message
428 //================================================================
429 void HAL_AUDIO_DumpDspInfo(void);
430 AUDIO_DEC_ID HAL_AUDIO_OpenDecodeSystem(AudioDecStatus_t * p_AudioDecStatus);
431 MS_PHY HAL_AUDIO_GetDDRInfo(AUDIO_DEC_ID DecId, EN_AUDIO_DDRINFO DDRInfo);
432 MS_BOOL HAL_AUDIO_CheckVersionInfo(void);
433 
434 //================================================================
435 // Specific Definitions for Audio TEE
436 //================================================================
437 #define ree_to_tee_mbx_msg    pAudioTeeInfoShm->ReeToTeeMbxMsg
438 #define tee_to_ree_mbx_msg    pAudioTeeInfoShm->TeeToReeMbxMsg
439 #define tee_mbx_msg_class    pAudioTeeInfoShm->u8MbxMsgClass
440 #define audio_tee_enabled    pAudioTeeInfoShm->g_bAudioTeeEnabled
441 #define audio_tee_mbx_initialized    pAudioTeeInfoShm->g_bAudioTeeMbxInitialized
442 #define dec_dsp_secure_tee_accessed    pAudioTeeInfoShm->g_bDecDspSecureTeeAccessed
443 #define snd_dsp_secure_tee_accessed    pAudioTeeInfoShm->g_bSndDspSecureTeeAccessed
444 #define mbx_msg_ack_status    pAudioTeeInfoShm->ack_status
445 
446 //================================================================
447 // Audio Common PCM Interface
448 //================================================================
449 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader1_Init(void *pData);
450 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader1_Exit(void);
451 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader1_Start(void);
452 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader1_Stop(void);
453 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader1_Set(MS_U32 u32Cmd, const void *pData);
454 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader1_Get(MS_U32 u32Cmd, void *pData);
455 MS_U32 HAL_AUDIO_Pcm_HwDma_Reader1_Write(const void *pBuf, MS_U32 u32Size);
456 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader1_Flush(void);
457 
458 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader2_Init(void *pData);
459 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader2_Exit(void);
460 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader2_Start(void);
461 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader2_Stop(void);
462 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader2_Set(MS_U32 u32Cmd, const void *pData);
463 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader2_Get(MS_U32 u32Cmd, void *pData);
464 MS_U32 HAL_AUDIO_Pcm_HwDma_Reader2_Write(const void *pBuf, MS_U32 u32Size);
465 MS_S32 HAL_AUDIO_Pcm_HwDma_Reader2_Flush(void);
466 
467 MS_S32 HAL_AUDIO_Pcm_SwDma_Reader1_Init(void *pData);
468 MS_S32 HAL_AUDIO_Pcm_SwDma_Reader1_Exit(void);
469 MS_S32 HAL_AUDIO_Pcm_SwDma_Reader1_Start(void);
470 MS_S32 HAL_AUDIO_Pcm_SwDma_Reader1_Stop(void);
471 MS_S32 HAL_AUDIO_Pcm_SwDma_Reader1_Set(MS_U32 u32Cmd, const void *pData);
472 MS_S32 HAL_AUDIO_Pcm_SwDma_Reader1_Get(MS_U32 u32Cmd, void *pData);
473 MS_U32 HAL_AUDIO_Pcm_SwDma_Reader1_Write(const void *pBuf, MS_U32 u32Size);
474 MS_S32 HAL_AUDIO_Pcm_SwDma_Reader1_Flush(void);
475 
476 MS_S32 HAL_AUDIO_Pcm_Capture1_Init(void *pData);
477 MS_S32 HAL_AUDIO_Pcm_Capture1_Exit(void);
478 MS_S32 HAL_AUDIO_Pcm_Capture1_Start(void);
479 MS_S32 HAL_AUDIO_Pcm_Capture1_Stop(void);
480 MS_S32 HAL_AUDIO_Pcm_Capture1_Set(MS_U32 u32Cmd, const void *pData);
481 MS_S32 HAL_AUDIO_Pcm_Capture1_Get(MS_U32 u32Cmd, void *pData);
482 MS_U32 HAL_AUDIO_Pcm_Capture1_Read(void *pBuf, MS_U32 u32Size);
483 MS_S32 HAL_AUDIO_Pcm_Capture1_Flush(void);
484 
485 MS_S32 HAL_AUDIO_Pcm_Capture2_Init(void *pData);
486 MS_S32 HAL_AUDIO_Pcm_Capture2_Exit(void);
487 MS_S32 HAL_AUDIO_Pcm_Capture2_Start(void);
488 MS_S32 HAL_AUDIO_Pcm_Capture2_Stop(void);
489 MS_S32 HAL_AUDIO_Pcm_Capture2_Set(MS_U32 u32Cmd, const void *pData);
490 MS_S32 HAL_AUDIO_Pcm_Capture2_Get(MS_U32 u32Cmd, void *pData);
491 MS_U32 HAL_AUDIO_Pcm_Capture2_Read(void *pBuf, MS_U32 u32Size);
492 MS_S32 HAL_AUDIO_Pcm_Capture2_Flush(void);
493 
494 MS_S32 HAL_AUDIO_Pcm_HwDma_Writer1_Init(void *pData);
495 MS_S32 HAL_AUDIO_Pcm_HwDma_Writer1_Exit(void);
496 MS_S32 HAL_AUDIO_Pcm_HwDma_Writer1_Start(void);
497 MS_S32 HAL_AUDIO_Pcm_HwDma_Writer1_Stop(void);
498 MS_S32 HAL_AUDIO_Pcm_HwDma_Writer1_Set(MS_U32 u32Cmd, const void *pData);
499 MS_S32 HAL_AUDIO_Pcm_HwDma_Writer1_Get(MS_U32 u32Cmd, void *pData);
500 MS_U32 HAL_AUDIO_Pcm_HwDma_Writer1_Read(void *pBuf, MS_U32 u32Size);
501 MS_S32 HAL_AUDIO_Pcm_HwDma_Writer1_Flush(void);
502 
503 #define HALAUDIO_CHECK_TEE_INFO_SHM_INIT \
504     do { \
505         if (pAudioTeeInfoShm == NULL) \
506         { \
507             if (HAL_AUDIO_AllocateTeeInfoShm() == NULL) \
508             { \
509                 MS_ASSERT(0); \
510             } \
511         } \
512     } while(0)
513 
514 #define AUDIO_TEE_INFO_SHM_CHECK_NULL \
515     do { \
516         MS_ASSERT(pAudioTeeInfoShm != NULL); \
517     } while(0)
518 
519 #define REE_TO_TEE_MBX_MSG_SET_PARAM_COUNT(count) \
520     do { \
521         ree_to_tee_mbx_msg.u8ParameterCount = count; \
522     } while(0)
523 
524 #define REE_TO_TEE_MBX_MSG_SET_PARAM(index, parameter) \
525     do { \
526         ree_to_tee_mbx_msg.u8Parameters[index] = parameter; \
527     } while(0)
528 
529 #define REE_TO_TEE_MBX_MSG_INIT \
530     do{ \
531         ree_to_tee_mbx_msg.eRoleID=E_MBX_CPU_MIPS_VPE1; \
532         ree_to_tee_mbx_msg.u8Ctrl=0; \
533         ree_to_tee_mbx_msg.eMsgType=E_MBX_MSG_TYPE_INSTANT; \
534     }while(0)
535 
536 #define TEE_TO_REE_MBX_MSG_INIT(msg) \
537     do{ \
538         msg.eRoleID=E_MBX_CPU_MIPS; \
539         msg.u8Ctrl=0; \
540         msg.eMsgType=E_MBX_MSG_TYPE_INSTANT; \
541     }while(0)
542 
543 #define MBX_MSG_SET_CLASSID(msg,classID)\
544     do{ \
545         msg.u8MsgClass = classID; \
546     }while(0)
547 
548 #define MBX_MSG_SET_CMD(msg,cmd)\
549     do{ \
550         msg.u8Index = cmd; \
551     }while(0)
552 
553 #define TEE_MBX_MSG_CLASS_SET(class) \
554     do{ \
555         tee_mbx_msg_class = class;	\
556     }while(0)
557 
558 //================================================================
559 // Audio TEE MBX Message Enum Definitions (REE side to TEE siede)
560 //================================================================
561 typedef enum
562 {
563     REE_TO_TEE_MBX_MSG_NULL                     = 0x0000,
564 
565     REE_TO_TEE_MBX_MSG_TYPE_GENERAL = 0x20,
566     REE_TO_TEE_MBX_MSG_TYPE_DEC = 0x40,
567     REE_TO_TEE_MBX_MSG_TYPE_SE = 0x80,
568     // NonDSP Specific General MBX Command
569     REE_TO_TEE_MBX_MSG_HAL_AUDIO_SetDspBaseAddr = 0x01,
570     // DSP Specific MBX Command
571     REE_TO_TEE_MBX_MSG_HAL_AUDSP_DspLoadCode    = 0x11
572 } REE_TO_TEE_MBX_MSG_TYPE;
573 
574 //================================================================
575 // Audio TEE MBX Message Enum Definitions (TEE side to REE siede)
576 //================================================================
577 typedef enum
578 {
579    TEE_TO_REE_MBX_MSG_NULL                 = 0x00,
580    TEE_TO_REE_MBX_ACK_MSG_INVALID          = 0x80,
581    TEE_TO_REE_MBX_ACK_MSG_NO_TEE           = 0x81,
582    TEE_TO_REE_MBX_ACK_MSG_ACTION_SUCCESS   = 0x90,
583    TEE_TO_REE_MBX_ACK_MSG_ACTION_FAIL      = 0x91
584 } TEE_TO_REE_MBX_ACK_MSG_TYPE;
585 
586 typedef struct
587 {
588    MS_U32 g_ShmID;
589    MS_BOOL g_bAudioTeeEnabled;
590    MS_BOOL g_bAudioTeeMbxInitialized;
591 
592    MS_BOOL g_bDecDspSecureTeeAccessed;
593    MS_BOOL g_bSndDspSecureTeeAccessed;
594 
595    MBX_Msg ReeToTeeMbxMsg;
596    MBX_Msg TeeToReeMbxMsg;
597    MS_U8 u8MbxMsgClass;
598    MS_U32 g_u32ClientCounter;
599    TEE_TO_REE_MBX_ACK_MSG_TYPE ack_status;
600 } AUDIO_TEE_INFO_SHARE_MEM;
601 
602 #ifndef MSOS_TYPE_NUTTX
603 MS_BOOL HAL_AUDIO_ResetTeeInfoShmToDefault(void);
604 AUDIO_TEE_INFO_SHARE_MEM *HAL_AUDIO_AllocateTeeInfoShm(void);
605 MS_BOOL HAL_AUDIO_DeAllocateTeeInfoShm(void);
606 
607 //================================================================
608 // Audio Mailbox Relational Function
609 //================================================================
610 MS_BOOL HAL_AUDIO_RegisterMBX(void);
611 TEE_TO_REE_MBX_ACK_MSG_TYPE HAL_AUDIO_SendMBXMsg(REE_TO_TEE_MBX_MSG_TYPE msg_type);
612 #endif
613 
614 AUDIO_DSP_CODE_TYPE HAL_AUDIO_Convert_EnDVBdecSystemType_to_AudioDspCodeType(En_DVB_decSystemType enDecSystem);
615 void HAL_AUDIO_ResetDspCodeType(void);
616 #endif // _DEV_AUDIO_H_
617 
618