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 //-------------------------------------------------------------------------------------------------
96 // Include Files
97 //-------------------------------------------------------------------------------------------------
98 // Common Definition
99 #ifdef MSOS_TYPE_LINUX_KERNEL
100 #include <linux/string.h>
101 #else
102 #include <string.h>
103 #endif
104
105 #include "MsCommon.h"
106 #include "MsIRQ.h"
107 #include "MsOS.h"
108 #include "MsTypes.h"
109
110 #include "drvBDMA.h"
111 #include "drvSERFLASH.h"
112
113 #include "regCHIP.h"
114
115 #include "halAUDSP.h"
116 #include "drvAUDIO.h"
117 #include "regAUDIO.h"
118 #include "halAUDIO.h"
119 #include "halMAD2.h"
120 #include "halSIF.h"
121 #include "halADVAUDIO.h"
122 #include "ddr_config.h"
123 #include "r2_shm_comm.h"
124 #include "decR2_shm.h"
125
126 #ifdef CONFIG_MBOOT//Mboot Mini system
127 #include "dspcode_s/aucode_mboot_r2.c"
128 #else
129 #include "dspcode_s/aucode_adec_r2.c"
130 #endif
131
132
133
134 #if defined(MSOS_TYPE_NUTTX)
135 extern int lib_lowprintf(const char *format, ...);
136 #define DBG_PREFIX lib_lowprintf
137 #else
138 #define DBG_PREFIX printf
139 #endif
140
141 #if (defined ANDROID)
142 #include <sys/mman.h>
143 #include <cutils/ashmem.h>
144 #include <cutils/log.h>
145
146 #ifndef LOGI // android 4.1 rename LOGx to ALOGx
147 #define LOGI ALOGI
148 #endif
149
150 #ifndef LOGE // android 4.1 rename LOGx to ALOGx
151 #define LOGE ALOGE
152 #endif
153
154 #define HALAUDSP_PRINT(fmt, args...) LOGI("<<android>> " fmt, ## args)
155 #define HALAUDSP_ERROR(fmt, args...) LOGE("<<android>> " fmt, ## args)
156 #else
157 #define HALAUDSP_PRINT(fmt, args...) DBG_PREFIX("[[utopia]] " fmt, ## args)
158 #define HALAUDSP_ERROR(fmt, args...) DBG_PREFIX("[[utopia]] " fmt, ## args)
159 #endif
160
161 #define HALAUDSP_CHECK_SHM_INIT \
162 do { \
163 if (g_AudioVars2 == NULL) \
164 { \
165 HALAUDSP_ERROR("%s() : Warning! g_AudioVars2 should not be NULL !!!\n", __FUNCTION__); \
166 HALAUDSP_ERROR("%s() : Perform SHM Init here !!!\n", __FUNCTION__); \
167 if (HAL_AUDIO_InitialVars() == FALSE) \
168 { \
169 MS_ASSERT(0); \
170 } \
171 } \
172 } while(0)
173
174 //-------------------------------------------------------------------------------------------------
175 // Driver Compiler Options
176 //-------------------------------------------------------------------------------------------------
177
178 #define DBG_AUDSP_LOAD(args...) //DBG_PREFIX(args)
179 #define DBG_AUDSP(args...) //DBG_PREFIX(args)
180 #define DBG_AUDSP_ERROR(args...) //DBG_PREFIX(args);
181
182 #ifdef CONFIG_MBOOT //mboot Speed up
183 #define DSP_VERIFY_DSP_CODE 0 // 0: don't verify dsp code (for speed)
184 // 1: verify dsp code (for debug)
185 #define DSP_IDMA_CHK_READY 1 // 0: don't check IDMA ready (for speed)
186 // 1: check IDMA ready (for debug)
187 #else
188 #define DSP_VERIFY_DSP_CODE 1 // 0: don't verify dsp code (for speed)
189 // 1: verify dsp code (for debug)
190 #define DSP_IDMA_CHK_READY 1 // 0: don't check IDMA ready (for speed)
191 // 1: check IDMA ready (for debug)
192 #endif
193
194 #define AU_NULL 0
195
196 #ifdef CONFIG_MBOOT
197 #define FLASH_COPY(x,y,z,i,j) TRUE
198 #define FLASH_CHKDONE() TRUE
199 #else
200 #define FLASH_COPY(x,y,z,i,j) MDrv_SERFLASH_CopyHnd(x,y,z,i,j)
201 #define FLASH_CHKDONE() MDrv_FLASH_CheckWriteDone()
202 #endif
203
204 LOAD_CODE_INFO g_loadcodeinfo;
205 MS_BOOL g_bDSPLoadCode = FALSE;
206
207 #ifndef MSOS_TYPE_NOS
208 void* MDrv_MPool_PA2KSEG1(void* pAddrPhys);
209 #endif
210 //-------------------------------------------------------------------------------------------------
211 // Local Defines
212 //-------------------------------------------------------------------------------------------------
213 #define AUDIO_HAL_ERR(x, args...) //{printf(x, ##args);}
214 #define LOU8(MS_U16Val) ( (MS_U8)(MS_U16Val) )
215 #define HIU8(MS_U16Val) ( (MS_U8)((MS_U16Val) >> 8) )
216
217 //-------------------------------------------------------------------------------------------------
218 // Local Structures
219 //-------------------------------------------------------------------------------------------------
220
221
222 //-------------------------------------------------------------------------------------------------
223 // Global Variables
224 //-------------------------------------------------------------------------------------------------
225 extern MS_BOOL g_bAudio_loadcode_from_dram;
226 extern AUDIO_SHARED_VARS2 * g_AudioVars2;
227
228 extern MS_S32 _s32AUDIOMutexIDMA;
229
230 #ifndef MSOS_TYPE_NUTTX
231 extern AUDIO_TEE_INFO_SHARE_MEM *pAudioTeeInfoShm;
232 #endif
233
234
235 //-------------------------------------------------------------------------------------------------
236 // Local Variables
237 //-------------------------------------------------------------------------------------------------
238 static AUDIO_DSP_CODE_TYPE g_DspCodeTypeLoaded = AU_DVB_NONE;
239
240
241 //-------------------------------------------------------------------------------------------------
242 // Debug Functions
243 //-------------------------------------------------------------------------------------------------
244
245
246 //-------------------------------------------------------------------------------------------------
247 // Local Functions
248 //-------------------------------------------------------------------------------------------------
249
250
251 //-------------------------------------------------------------------------------------------------
252 // Global Functions
253 //-------------------------------------------------------------------------------------------------
254 ////////////////////////////////////////////////////////////////////////////////
255 /// @brief \b Function \b Name: MDrv_AUDIO_DspLoadCodeKernel()
256 /// @brief \b Function \b Description: load CM/PM/cache/prefetch DSP code
257 /// @param <IN> \b \b u8Type : -- DSP load code type
258 /// DSP_segment -- select DSP load code seg
259 /// DSP_select -- select DSP1 or DSP2
260 /// @param <OUT> \b NONE :
261 /// @param <RET> \b NONE :
262 /// @param <GLOBAL> \b NONE :
263 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_DspLoadCode(AUDIO_DSP_CODE_TYPE dspCodeType)264 MS_BOOL HAL_AUDSP_DspLoadCode(AUDIO_DSP_CODE_TYPE dspCodeType)
265 {
266 #ifndef MSOS_TYPE_NUTTX
267 REE_TO_TEE_MBX_MSG_TYPE msg_type = REE_TO_TEE_MBX_MSG_NULL;
268 #endif
269 MS_U8 DSP_select= DSP_SE;
270 //MS_U32 DEC_R2_ADDR, SND_R2_ADDR;
271 MS_U32 MIU_addr;
272
273 HALAUDSP_CHECK_SHM_INIT;
274
275 DBG_AUDSP_LOAD("@@@@@@@@@@ ====== HAL_AUDSP_DspLoadCode: 0x%x ======\r\n",u8Type);
276
277 if (IS_AUDIO_DSP_CODE_TYPE_DEC1_SYSTEM(dspCodeType))
278 {
279 return TRUE; // Decoder in DEC-R2
280 }
281 else if (IS_AUDIO_DSP_CODE_TYPE_DEC_SYSTEM(dspCodeType)) //AU_DEC_SYSTEM
282 {
283 return TRUE; // Decoder in DEC-R2
284 }
285 else if ((!IS_AUDIO_DSP_CODE_TYPE_DEC2_SYSTEM(dspCodeType)) ||
286 (!IS_AUDIO_DSP_CODE_TYPE_SE_SYSTEM(dspCodeType)) ||
287 (!IS_AUDIO_DSP_CODE_TYPE_SIF(dspCodeType)) ||
288 (!IS_AUDIO_DSP_CODE_TYPE_ADVSND(dspCodeType)) ||
289 (!IS_AUDIO_DSP_CODE_TYPE_SE_ENC(dspCodeType)))
290 {
291
292 }
293 else
294 {
295 DBG_AUDSP_ERROR(AUDIO_DEBUG_LEVEL_ERROR, " [HAL_AUDSP_DspLoadCode]:====== Loading the wrong DSP code type!======\r\n");
296 return FALSE;
297 }
298
299 #ifndef MSOS_TYPE_NUTTX
300 AUDIO_TEE_INFO_SHM_CHECK_NULL;
301 REE_TO_TEE_MBX_MSG_SET_PARAM(0, (dspCodeType&0xFF));
302 REE_TO_TEE_MBX_MSG_SET_PARAM_COUNT(1);
303 msg_type = REE_TO_TEE_MBX_MSG_HAL_AUDSP_DspLoadCode;
304 if (DSP_select == DSP_DEC)
305 {
306 msg_type = msg_type | REE_TO_TEE_MBX_MSG_TYPE_DEC;
307 }
308 else if (DSP_select == DSP_SE)
309 {
310 msg_type = msg_type | REE_TO_TEE_MBX_MSG_TYPE_SE;
311 }
312
313 if ( TEE_TO_REE_MBX_ACK_MSG_NO_TEE != (mbx_msg_ack_status = HAL_AUDIO_SendMBXMsg(msg_type)))
314 {
315 if (mbx_msg_ack_status != TEE_TO_REE_MBX_ACK_MSG_ACTION_SUCCESS)
316 return FALSE;
317 HAL_AUDSP_SetDspCodeTypeLoaded(dspCodeType);
318 return TRUE;
319 }
320 #endif
321
322
323 // Load SE-DSP system code
324 if (IS_AUDIO_DSP_CODE_TYPE_SE_SYSTEM(dspCodeType))
325 {
326 HAL_AUR2_WriteByte(REG_DECR2_RESET_CTRL, 0x00); // STOP DEC-R2
327 HAL_AUR2_WriteMaskReg(REG_DECR2_SYSTEM_START, 0xFFFF, 0x0000); // clear DEC-R2 start cmd register
328 HAL_AUDIO_WriteMaskReg(0x2DDC, 0xFFFF, 0x0000); //clear SE-DSP start cmd register
329 AUDIO_DELAY1MS(1);
330
331 HAL_AUR2_WriteMaskReg(REG_SDR_SWITCH_CTRL, 0xFFFF, 0x3213); //use SDR2 address
332
333 #ifdef CONFIG_MBOOT
334 //============ Load R2 code ===============
335 // Memory sequence : Mboot-R2(DEC-R2)
336 //====================================
337 MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(DSP_ADV);
338
339 memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((mst_codec_r2)), DEC_R2_SHM_DDR_OFFSET);
340 memset((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE), 0, ADEC__R2_DDR_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
341 memcpy((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
342 (void*)(mst_codec_r2+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
343 MST_CODEC_R2_AUDIO_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
344 HAL_DEC_R2_init_SHM_param();
345 AUDIO_DELAY1MS(1);
346 MsOS_FlushMemory();
347
348 HAL_DEC_R2_EnableR2(TRUE); // Enable DEC-R2 after load R2 code
349 #else
350 //============ Load R2 code ===============
351 // Memory sequence : DEC-R2 ==> SND-R2 ==> SE-DSP
352 //====================================
353
354 // Load DEC-R2
355 MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(DSP_ADV);
356
357 memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((mst_codec_r2)), DEC_R2_SHM_DDR_OFFSET);
358 memset((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE), 0, ADEC__R2_DDR_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
359 memcpy((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
360 (void*)(mst_codec_r2+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
361 MST_CODEC_R2_AUDIO_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
362 HAL_DEC_R2_init_SHM_param();
363 AUDIO_DELAY1MS(1);
364 MsOS_FlushMemory();
365
366 #if ASND_R2_SUPPORT
367 // Load SND-R2
368 MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(DSP_ADV)+ADEC__R2_DDR_SIZE;
369 memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((mst_snd_r2)), SND_R2_SHM_DDR_OFFSET);
370 memset((void*)(MS_PA2KSEG1(MIU_addr)+SND_R2_SHM_DDR_OFFSET+SND_R2_SHM_DDR_SIZE), 0, ASND__R2_DDR_SIZE - SND_R2_SHM_DDR_OFFSET - SND_R2_SHM_DDR_SIZE);
371 memcpy((void*)(MS_PA2KSEG1(MIU_addr)+SND_R2_SHM_DDR_OFFSET+SND_R2_SHM_DDR_SIZE),
372 (void*)(mst_snd_r2+SND_R2_SHM_DDR_OFFSET+SND_R2_SHM_DDR_SIZE),
373 MST_SND_R2_AUDIO_SIZE - SND_R2_SHM_DDR_OFFSET - SND_R2_SHM_DDR_SIZE);
374 AUDIO_DELAY1MS(1);
375 MsOS_FlushMemory();
376 HAL_SND_R2_EnableR2(TRUE); // Enable SND-R2 after load R2 code
377 #endif
378
379 HAL_DEC_R2_EnableR2(TRUE); // Enable DEC-R2 after load R2 code
380 #endif
381
382 #if 0 //secure boot(Reserved)
383 HAL_AUR2_WriteMaskReg(REG_SDR_SWITCH_CTRL, 0xFFFF, 0x3210); //use SDR1 address
384
385 #ifdef CONFIG_MBOOT
386 //============ Load R2 code ===============
387 // Memory sequence : Mboot-R2(DEC-R2)
388 //====================================
389 DEC_R2_ADDR = (MS_U32) MsOS_MPool_VA2PA((MS_VIRT) &mst_codec_r2);
390
391 HAL_AUR2_WriteReg(REG_DECR2_ICMEM_BASE_LO, (MS_U16)(DEC_R2_ADDR & 0xFFFF));
392 HAL_AUR2_WriteReg(REG_DECR2_ICMEM_BASE_HI, (MS_U16)((DEC_R2_ADDR >> 16) & 0xFFFF));
393 HAL_AUR2_WriteReg(REG_DECR2_DCMEM_BASE_LO, (MS_U16)(DEC_R2_ADDR & 0xFFFF));
394 HAL_AUR2_WriteReg(REG_DECR2_DCMEM_BASE_HI, (MS_U16)((DEC_R2_ADDR >> 16) & 0xFFFF));
395 AUDIO_DELAY1MS(1);
396 HAL_DEC_R2_EnableR2(TRUE); // Enable DEC-R2 after load R2 code
397 #else
398 //============ Load R2 code ===============
399 // Memory sequence : DEC-R2 ==> SND-R2 ==> SE-DSP
400 //====================================
401 DEC_R2_ADDR = (MS_U32) MsOS_MPool_VA2PA((MS_VIRT) &mst_codec_r2);
402 SND_R2_ADDR = (MS_U32) MsOS_MPool_VA2PA((MS_VIRT) &mst_snd_r2);
403
404 HAL_AUR2_WriteReg(REG_DECR2_ICMEM_BASE_LO, (MS_U16)(DEC_R2_ADDR & 0xFFFF));
405 HAL_AUR2_WriteReg(REG_DECR2_ICMEM_BASE_HI, (MS_U16)((DEC_R2_ADDR >> 16) & 0xFFFF));
406 HAL_AUR2_WriteReg(REG_DECR2_DCMEM_BASE_LO, (MS_U16)(DEC_R2_ADDR & 0xFFFF));
407 HAL_AUR2_WriteReg(REG_DECR2_DCMEM_BASE_HI, (MS_U16)((DEC_R2_ADDR >> 16) & 0xFFFF));
408 HAL_AUR2_WriteReg(REG_SNDR2_ICMEM_BASE_LO, (MS_U16)(SND_R2_ADDR & 0xFFFF));
409 HAL_AUR2_WriteReg(REG_SNDR2_ICMEM_BASE_HI, (MS_U16)((SND_R2_ADDR >> 16) & 0xFFFF));
410 HAL_AUR2_WriteReg(REG_SNDR2_DCMEM_BASE_LO, (MS_U16)(SND_R2_ADDR & 0xFFFF));
411 HAL_AUR2_WriteReg(REG_SNDR2_DCMEM_BASE_HI, (MS_U16)((SND_R2_ADDR >> 16) & 0xFFFF));
412 AUDIO_DELAY1MS(1);
413 HAL_SND_R2_EnableR2(TRUE); // Enable SND-R2 after load R2 code
414 HAL_DEC_R2_EnableR2(TRUE); // Enable DEC-R2 after load R2 code
415 #endif
416 #endif
417 }
418
419 HAL_AUDSP_SetDspCodeTypeLoaded(dspCodeType);
420 DBG_AUDSP_LOAD("HAL_AUDSP_DspLoadCode finished(type=(0x%x))\r\n" , dspCodeType);
421
422 return TRUE;
423 }
424
HAL_AUDSP_DspLoadCode2(MS_U8 DSP_select,void * info)425 MS_BOOL HAL_AUDSP_DspLoadCode2(MS_U8 DSP_select, void * info)
426 {
427 return TRUE;
428 }
429
HAL_AUDSP_DspLoadSystemCode2(MS_U8 DSP_select,AUDIO_ALG_INFO * pau_info)430 MS_BOOL HAL_AUDSP_DspLoadSystemCode2(MS_U8 DSP_select, AUDIO_ALG_INFO * pau_info)
431 {
432 return TRUE;
433 }
434
435 ////////////////////////////////////////////////////////////////////////////////
436 /// @brief \b Function \b Name: HAL_AUDIO_DspLoadCodeSegment()
437 /// @brief \b Function \b Description: This routine is used to load DSP code
438 /// @param <IN> \b dsp_addr :
439 /// @param <IN> \b dspCode_buf :
440 /// @param <IN> \b dspCode_buflen :
441 /// @param <OUT> \b NONE :
442 /// @param <RET> \b BOOL : TRUE --DSP Load code okay
443 /// FALSE--DSP Load code fail
444 /// @param <GLOBAL> \b NONE :
445 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_DspLoadCodeSegment(MS_U32 dsp_addr,MS_U8 * dspCode_buf,MS_U32 dspCode_buflen,MS_U8 DSP_select)446 MS_BOOL HAL_AUDSP_DspLoadCodeSegment(MS_U32 dsp_addr, MS_U8 *dspCode_buf, MS_U32 dspCode_buflen, MS_U8 DSP_select)
447 {
448 g_bDSPLoadCode = TRUE;
449 return TRUE; // secure boot: MCU can't use IDMA
450 }
451
HAL_AUDSP_DspVerifySegmentCode(MS_U32 dsp_addr,MS_U8 * dspCode_buf,MS_U32 dspCode_buflen,MS_U8 DSP_select)452 MS_BOOL HAL_AUDSP_DspVerifySegmentCode(MS_U32 dsp_addr, MS_U8 *dspCode_buf, MS_U32 dspCode_buflen, MS_U8 DSP_select)
453 {
454 g_bDSPLoadCode = TRUE;
455 return TRUE; // secure boot: MCU can't use IDMA
456 }
457
458 ////////////////////////////////////////////////////////////////////////////////
459 /// @brief \b Function \b Name: HAL_AUDSP_CheckDecIdmaReady()
460 /// @brief \b Function \b Description: This routine is used to check if the Dec-DSP IDMA is ready or not.
461 /// @param <IN> \b IdmaChk_type :
462 /// 0x10 : check write ready
463 /// 0x80 : check read ready
464 /// @param <OUT> \b NONE :
465 /// @param <RET> \b MS_BOOL : TRUE--IDMA is ready
466 /// FALSE--IDMA not ready
467 /// @param <GLOBAL> \b NONE :
468 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_CheckDecIdmaReady(MS_U8 u8IdmaChk_type)469 MS_BOOL HAL_AUDSP_CheckDecIdmaReady(MS_U8 u8IdmaChk_type )
470 {
471 return FALSE; // secure boot: MCU can't use IDMA
472 }
473
474 ////////////////////////////////////////////////////////////////////////////////
475 /// @brief \b Function \b Name: HAL_AUDIO_CheckSeIdmaReady()
476 /// @brief \b Function \b Description: This routine is used to check if the Se-DSP IDMA is ready or not.
477 /// @param <IN> \b IdmaChk_type :
478 /// 0x10 : check write ready
479 /// 0x80 : check read ready
480 /// @param <OUT> \b NONE :
481 /// @param <RET> \b MS_BOOL : TRUE--IDMA is ready
482 /// FALSE--IDMA not ready
483 /// @param <GLOBAL> \b NONE :
484 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_CheckSeIdmaReady(MS_U8 u8IdmaChk_type)485 MS_BOOL HAL_AUDSP_CheckSeIdmaReady(MS_U8 u8IdmaChk_type)
486 {
487 return FALSE; // secure boot: MCU can't use IDMA
488 }
489
490 ////////////////////////////////////////////////////////////////////////////////
491 /// @brief \b Function \b Name: HAL_AUDSP_CheckDecIdmaReady()
492 /// @brief \b Function \b Description: This routine is used to check if the XBox data transport is ready or not.
493 /// @param <OUT> \b NONE :
494 /// @param <RET> \b MS_BOOL : TRUE--IDMA is ready
495 /// FALSE--IDMA not ready
496 /// @param <GLOBAL> \b NONE :
497 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_Check_XBox_TransData_Ready(void)498 MS_BOOL HAL_AUDSP_Check_XBox_TransData_Ready(void)
499 {
500 MS_U8 j = 0;
501
502 while(j<200)
503 {
504 j++;
505 if( (HAL_AUDIO_ReadByte(REG_DSP_XBOX_MISC)& 0x08) == 0x00 ) //bit[3] = 1 ,busy
506 return TRUE;
507 }
508
509 DBG_AUDSP_ERROR("XBox check data trans fail!(%d)\r\n",j);
510 return FALSE;
511 }
512
513 ////////////////////////////////////////////////////////////////////////////////
514 /// @brief \b Function \b Name: HAL_AUDSP_SetDspCodeTypeLoaded()
515 /// @brief \b Function \b Description: This function is used to set the DSP code type.
516 /// @param <IN> \b NONE :
517 /// @param <OUT> \b NONE :
518 /// @param <RET> \b MS_U8: DSP code type.
519 /// @param <GLOBAL> \b NONE :
520 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_SetDspCodeTypeLoaded(AUDIO_DSP_CODE_TYPE dspCodeType)521 void HAL_AUDSP_SetDspCodeTypeLoaded(AUDIO_DSP_CODE_TYPE dspCodeType)
522 {
523 g_DspCodeTypeLoaded = dspCodeType;
524 }
525
526 ////////////////////////////////////////////////////////////////////////////////
527 /// @brief \b Function \b Name: HAL_AUDSP_GetDspCodeTypeLoaded()
528 /// @brief \b Function \b Description: This function is used to get the MAD base address.
529 /// @param <IN> \b NONE :
530 /// @param <OUT> \b NONE :
531 /// @param <RET> \b MS_U8: DSP code type.
532 /// @param <GLOBAL> \b NONE :
533 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_GetDspCodeTypeLoaded(void)534 AUDIO_DSP_CODE_TYPE HAL_AUDSP_GetDspCodeTypeLoaded(void)
535 {
536 return g_DspCodeTypeLoaded;
537 }
538
HAL_AUDSP_SetDspLoadCodeInfo(AUDIO_ALG_INFO * pau_info,MS_U8 DSP_select)539 void HAL_AUDSP_SetDspLoadCodeInfo(AUDIO_ALG_INFO *pau_info, MS_U8 DSP_select)
540 {
541 g_loadcodeinfo.pau_info = pau_info;
542 g_loadcodeinfo.DSP_select= DSP_select;
543 }
544
545 ////////////////////////////////////////////////////////////////////////////////
546 /// @brief \b Function \b Name: HAL_AUDSP_GetDspCodeTypeLoaded()
547 /// @brief \b Function \b Description: This function is used to get the MAD base address.
548 /// @param <IN> \b NONE :
549 /// @param <OUT> \b NONE :
550 /// @param <RET> \b MS_U8: DSP code type.
551 /// @param <GLOBAL> \b NONE :
552 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_GetDspLoadCodeInfo(void)553 LOAD_CODE_INFO* HAL_AUDSP_GetDspLoadCodeInfo(void)
554 {
555 return &g_loadcodeinfo;
556 }
557 ////////////////////////////////////////////////////////////////////////////////
558 /// @brief \b Function \b Name: HAL_AUDSP_DECR2LoadCode()
559 /// @brief \b Function \b Description: Load DEC-R2 code to DDR
560 /// @param <IN> \b NONE :
561 /// @param <OUT> \b NONE :
562 /// @param <RET> \b NONE :
563 /// @param <GLOBAL> \b NONE :
564 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_DECR2LoadCode(void)565 void HAL_AUDSP_DECR2LoadCode(void)
566 {
567 MS_U32 MIU_addr;
568
569 printf("======audio: start DEC-R2 load code======\n");
570
571 HAL_AUR2_WriteByte(REG_DECR2_RESET_CTRL, 0x00); // STOP DEC-R2
572 HAL_AUR2_WriteMaskReg(REG_DECR2_SYSTEM_START, 0xFFFF, 0x0000); //clear DEC-R2 start cmd register
573 AUDIO_DELAY1MS(1);
574
575 //============ Load R2 code ===============
576 // Memory sequence : DEC-R2 ==> SND-R2 ==> SE-DSP
577 //====================================
578
579 // Load DEC-R2
580 MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(DSP_ADV);
581
582 memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((mst_codec_r2)), DEC_R2_SHM_DDR_OFFSET);
583 memset((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE), 0, ADEC__R2_DDR_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
584 memcpy((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
585 (void*)(mst_codec_r2+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
586 MST_CODEC_R2_AUDIO_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
587 HAL_DEC_R2_init_SHM_param();
588 AUDIO_DELAY1MS(1);
589 MsOS_FlushMemory();
590
591 HAL_DEC_R2_EnableR2(TRUE); // Enable DEC-R2 after load R2 code
592 HAL_MAD2_SetMcuCmd(0xF3);
593
594 printf("======audio: end DEC-R2 load code======\n");
595 }
596