xref: /utopia/UTPA2-700.0.x/modules/audio/hal/M7821/audsp/halAUDSP.c (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 //-------------------------------------------------------------------------------------------------
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 "../audio/regAUDIO.h"
118 #include "../audio/halAUDIO.h"
119 #include "../audio/halSIF.h"
120 #include "../audio/halADVAUDIO.h"
121 #include "../audio/ddr_config.h"
122 #include "../audio/r2_shm_comm.h"
123 #include "../audio/decR2_shm.h"
124 #if ASND_R2_SUPPORT
125 #include "../audio/sndR2_shm.h"
126 #endif
127 
128 #ifdef CONFIG_MBOOT//Mboot Mini system
129     #include "dspcode_s/aucode_s.c"
130     #include "dspcode_s/aucode_dec.c"
131     #include "dspcode_s/aucode_mboot_r2.c"
132 #else
133     #include "dspcode_s/aucode_palsum.c"
134     #include "dspcode_s/aucode_btsc.c"
135     #include "dspcode_s/aucode_s.c"
136     #include "dspcode_s/aucode_dec.c"
137     #include "dspcode_s/aucode_adec_r2.c"
138 #if ASND_R2_SUPPORT
139     #include "dspcode_s/aucode_asnd_r2.c"
140 #endif
141     #include "dspcode_s/aucode_dde.c"
142     #include "dspcode_s/aucode_ms10_dde.c"
143 
144     #include "dspcode_adv/aucode_puresnd.c"
145     #include "dspcode_adv/aucode_dps.c"
146     #include "dspcode_adv/aucode_dbx.c"
147 #endif
148 
149 #define HALAUDSP_CHECK_SHM_INIT \
150     do { \
151         if (g_AudioVars2 == NULL) \
152         { \
153             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Warning! g_AudioVars2 should not be NULL !!!\n", __FUNCTION__); \
154             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Perform SHM Init here !!!\n", __FUNCTION__); \
155             if (HAL_AUDIO_InitialVars() == FALSE) \
156             { \
157                 MS_ASSERT(0); \
158             } \
159         } \
160     } while(0)
161 
162 //-------------------------------------------------------------------------------------------------
163 //  Driver Compiler Options
164 //-------------------------------------------------------------------------------------------------
165 #ifdef CONFIG_MBOOT //mboot Speed up
166   #define DSP_VERIFY_DSP_CODE     0   // 0: don't verify dsp code (for speed)
167                                     // 1: verify dsp code (for debug)
168   #define DSP_IDMA_CHK_READY      1   // 0: don't check IDMA ready (for speed)
169                                     // 1: check IDMA ready (for debug)
170 #else
171   #define DSP_VERIFY_DSP_CODE     1   // 0: don't verify dsp code (for speed)
172                                     // 1: verify dsp code (for debug)
173   #define DSP_IDMA_CHK_READY      1   // 0: don't check IDMA ready (for speed)
174                                     // 1: check IDMA ready (for debug)
175 #endif
176 
177 #define AU_NULL  0
178 
179 #ifdef CONFIG_MBOOT
180     #define FLASH_COPY(x,y,z,i,j)   TRUE
181     #define FLASH_CHKDONE()         TRUE
182 #else
183     #define FLASH_COPY(x,y,z,i,j)   MDrv_SERFLASH_CopyHnd(x,y,z,i,j)
184     #define FLASH_CHKDONE()         MDrv_FLASH_CheckWriteDone()
185 #endif
186 
187 LOAD_CODE_INFO g_loadcodeinfo;
188 MS_BOOL        g_bDSPLoadCode = FALSE;
189 
190 #ifndef CONFIG_MBOOT
191 AUDIO_ALG_INFO dsp_info[]=
192 {
193     // ---------- Decoder2 DSP Code ----------
194     //AU_DVB_SYS_NONE[0]
195     {
196         MST_CODEC_DEC_PM1_ADDR, MST_CODEC_DEC_PM1_SIZE, mst_codec_dec_pm1 + 6,
197         MST_CODEC_DEC_PM2_ADDR, MST_CODEC_DEC_PM2_SIZE, mst_codec_dec_pm2 + 6,
198         MST_CODEC_DEC_PM3_ADDR, MST_CODEC_DEC_PM3_SIZE, mst_codec_dec_pm3 + 6,
199         AU_NULL, AU_NULL, AU_NULL,
200         "DVB2_NONE",
201         AU_DVB2_NONE,
202     },
203     // SE System
204     {
205         MST_CODEC_PM1_ADDR, MST_CODEC_PM1_SIZE, mst_codec_pm1 + 6,
206         MST_CODEC_PM2_ADDR, MST_CODEC_PM2_SIZE, mst_codec_pm2 + 6,
207         MST_CODEC_PM3_ADDR, MST_CODEC_PM3_SIZE, mst_codec_pm3 + 6,
208         MST_CODEC_PM4_ADDR, MST_CODEC_PM4_SIZE, mst_codec_pm4 + 6,
209         "SE SYSTEM",
210         AU_SE_SYSTEM,
211     },
212     //DDE
213     {
214         MST_CODEC_DDE_PM1_ADDR, MST_CODEC_DDE_PM1_SIZE, mst_codec_dde_pm1 + 6,
215         MST_CODEC_DDE_PM2_ADDR, MST_CODEC_DDE_PM2_SIZE, mst_codec_dde_pm2 + 6,
216         MST_CODEC_DDE_PM3_ADDR, MST_CODEC_DDE_PM3_SIZE, mst_codec_dde_pm3 + 6,
217         MST_CODEC_DDE_PM4_ADDR, MST_CODEC_DDE_PM4_SIZE, mst_codec_dde_pm4 + 6,
218         "dde",
219         AU_DVB2_STANDARD_DDE,
220     },
221     //BTSC
222     {
223         MST_CODEC_SIF_BTSC_PM1_ADDR, MST_CODEC_SIF_BTSC_PM1_SIZE, mst_codec_sif_btsc_pm1 + 6,
224         MST_CODEC_SIF_BTSC_PM2_ADDR, MST_CODEC_SIF_BTSC_PM2_SIZE, mst_codec_sif_btsc_pm2 + 6,
225         MST_CODEC_SIF_BTSC_PM3_ADDR, MST_CODEC_SIF_BTSC_PM3_SIZE, mst_codec_sif_btsc_pm3 + 6,
226         AU_NULL, AU_NULL, AU_NULL,
227         "SIF BTSC",
228         AU_SIF_BTSC,
229     },
230     // PALSUM
231     {
232         MST_CODEC_SIF_PALSUM_PM1_ADDR, MST_CODEC_SIF_PALSUM_PM1_SIZE, mst_codec_sif_palsum_pm1 + 6,
233         MST_CODEC_SIF_PALSUM_PM2_ADDR, MST_CODEC_SIF_PALSUM_PM2_SIZE, mst_codec_sif_palsum_pm2 + 6,
234         MST_CODEC_SIF_PALSUM_PM3_ADDR, MST_CODEC_SIF_PALSUM_PM3_SIZE, mst_codec_sif_palsum_pm3 + 6,
235         AU_NULL, AU_NULL, AU_NULL,
236         "SIF PALSUM",
237         AU_SIF_PALSUM,
238     },
239     // audio_adv_sndeff_info
240     //DBX
241     {
242         MST_CODEC_DBX_PM1_ADDR, MST_CODEC_DBX_PM1_SIZE, mst_codec_dbx_pm1 + 6,
243         AU_NULL, AU_NULL, AU_NULL,
244         AU_NULL, AU_NULL, AU_NULL,
245         AU_NULL, AU_NULL, AU_NULL,
246         "ADVSND DBX",
247         AU_DVB2_ADVSND_DBX,
248     },
249      //PURESND
250     {
251         MST_CODEC_PURESND_PM1_ADDR, MST_CODEC_PURESND_PM1_SIZE, mst_codec_puresnd_pm1 + 6,
252         AU_NULL, AU_NULL, AU_NULL,
253         MST_CODEC_PURESND_PM3_ADDR, MST_CODEC_PURESND_PM3_SIZE, mst_codec_puresnd_pm3 +  6,
254         MST_CODEC_PURESND_PM4_ADDR, MST_CODEC_PURESND_PM4_SIZE, mst_codec_puresnd_pm4 +  6,
255         "ADVSND PURESND",
256         AU_DVB2_ADVSND_PURESND,
257     },
258     //DPS
259     {
260         MST_CODEC_DPS_PM1_ADDR, MST_CODEC_DPS_PM1_SIZE, mst_codec_dps_pm1 + 6,
261         AU_NULL, AU_NULL, AU_NULL,
262         MST_CODEC_DPS_PM3_ADDR, MST_CODEC_DPS_PM3_SIZE, mst_codec_dps_pm3 + 6,
263         AU_NULL, AU_NULL, AU_NULL,
264         "ADVSND BONGIOVI_DPS",
265         AU_DVB2_ADVSND_BONGIOVI_DPS,
266     },
267     //DTSE
268     {
269         AU_NULL, AU_NULL, AU_NULL,
270         AU_NULL, AU_NULL, AU_NULL,
271         AU_NULL, AU_NULL, AU_NULL,
272         AU_NULL, AU_NULL, AU_NULL,
273         "DTSE",
274         AU_DVB2_ENCODE_DTSE,
275     },
276     //DDE
277     {
278         MST_CODEC_DDE_PM1_ADDR, MST_CODEC_DDE_PM1_SIZE, mst_codec_dde_pm1 + 6,
279         MST_CODEC_DDE_PM2_ADDR, MST_CODEC_DDE_PM2_SIZE, mst_codec_dde_pm2 + 6,
280         MST_CODEC_DDE_PM3_ADDR, MST_CODEC_DDE_PM3_SIZE, mst_codec_dde_pm3 + 6,
281         MST_CODEC_DDE_PM4_ADDR, MST_CODEC_DDE_PM4_SIZE, mst_codec_dde_pm4 + 6,
282         "DDE",
283         AU_DVB2_ENCODE_DDE,
284     },
285     //MS10-DDE
286     {
287         MST_CODEC_MS10_DDE_PM1_ADDR, MST_CODEC_MS10_DDE_PM1_SIZE, mst_codec_ms10_dde_pm1 + 6,
288         MST_CODEC_MS10_DDE_PM2_ADDR, MST_CODEC_MS10_DDE_PM2_SIZE, mst_codec_ms10_dde_pm2 + 6,
289         MST_CODEC_MS10_DDE_PM3_ADDR, MST_CODEC_MS10_DDE_PM3_SIZE, mst_codec_ms10_dde_pm3 + 6,
290         MST_CODEC_MS10_DDE_PM4_ADDR, MST_CODEC_MS10_DDE_PM4_SIZE, mst_codec_ms10_dde_pm4 + 6,
291         "MS10-DDE",
292         AU_DVB2_ENCODE_MS10_DDE,
293     },
294 
295 };
296 #else //=======================CONFIG_MBOOT=========================================//
297 AUDIO_ALG_INFO dsp_info[]=
298 {
299     // ---------- Decoder2 DSP Code ----------
300     //AU_DVB_SYS_NONE[0]
301     {
302         MST_CODEC_DEC_PM1_ADDR, MST_CODEC_DEC_PM1_SIZE, mst_codec_dec_pm1 + 6,
303         MST_CODEC_DEC_PM2_ADDR, MST_CODEC_DEC_PM2_SIZE, mst_codec_dec_pm2 + 6,
304         MST_CODEC_DEC_PM3_ADDR, MST_CODEC_DEC_PM3_SIZE, mst_codec_dec_pm3 + 6,
305         AU_NULL, AU_NULL, AU_NULL,
306         "DVB2_NONE",
307         AU_DVB2_NONE,
308     },
309     // SE System
310     {
311         MST_CODEC_PM1_ADDR, MST_CODEC_PM1_SIZE, mst_codec_pm1 + 6,
312         MST_CODEC_PM2_ADDR, MST_CODEC_PM2_SIZE, mst_codec_pm2 + 6,
313         MST_CODEC_PM3_ADDR, MST_CODEC_PM3_SIZE, mst_codec_pm3 + 6,
314         MST_CODEC_PM4_ADDR, MST_CODEC_PM4_SIZE, mst_codec_pm4 + 6,
315         "SE SYSTEM",
316         AU_SE_SYSTEM,
317     },
318 };
319 #endif
320 
321 
322 #ifndef MSOS_TYPE_NOS
323 void* MDrv_MPool_PA2KSEG1(void* pAddrPhys);
324 #endif
325 //-------------------------------------------------------------------------------------------------
326 //  Local Defines
327 //-------------------------------------------------------------------------------------------------
328 #define LOU8(MS_U16Val)  ( (MS_U8)(MS_U16Val) )
329 #define HIU8(MS_U16Val)  ( (MS_U8)((MS_U16Val) >> 8) )
330 
331 //-------------------------------------------------------------------------------------------------
332 //  Local Structures
333 //-------------------------------------------------------------------------------------------------
334 
335 
336 //-------------------------------------------------------------------------------------------------
337 //  Global Variables
338 //-------------------------------------------------------------------------------------------------
339 extern MS_BOOL g_bAudio_loadcode_from_dram;
340 extern AUDIO_SHARED_VARS2 * g_AudioVars2;
341 
342 extern MS_S32  _s32AUDIOMutexIDMA;
343 
344 #ifndef MSOS_TYPE_NUTTX
345 extern AUDIO_TEE_INFO_SHARE_MEM   *pAudioTeeInfoShm;
346 #endif
347 
348 
349 //-------------------------------------------------------------------------------------------------
350 //  Local Variables
351 //-------------------------------------------------------------------------------------------------
352 static AUDIO_DSP_CODE_TYPE g_DspCodeTypeLoaded = AU_DVB_NONE;
353 
354 //-------------------------------------------------------------------------------------------------
355 //  Debug Functions
356 //-------------------------------------------------------------------------------------------------
357 
358 
359 //-------------------------------------------------------------------------------------------------
360 //  Local Functions
361 //-------------------------------------------------------------------------------------------------
362 
363 
364 //-------------------------------------------------------------------------------------------------
365 //  Global Functions
366 //-------------------------------------------------------------------------------------------------
367 ////////////////////////////////////////////////////////////////////////////////
368 /// @brief \b Function \b Name: MDrv_AUDIO_DspLoadCodeKernel()
369 /// @brief \b Function \b Description:  load CM/PM/cache/prefetch DSP code
370 /// @param <IN>        \b \b u8Type    :      -- DSP load code type
371 ///                                        DSP_segment -- select DSP load code seg
372 ///                                     DSP_select -- select DSP1 or DSP2
373 /// @param <OUT>       \b NONE    :
374 /// @param <RET>       \b NONE    :
375 /// @param <GLOBAL>    \b NONE    :
376 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_DspLoadCode(AUDIO_DSP_CODE_TYPE dspCodeType)377 MS_BOOL HAL_AUDSP_DspLoadCode(AUDIO_DSP_CODE_TYPE dspCodeType)
378 {
379 #ifndef MSOS_TYPE_NUTTX
380    REE_TO_TEE_MBX_MSG_TYPE msg_type = REE_TO_TEE_MBX_MSG_NULL;
381 #endif
382     MS_PHY MIU_addr;
383     AUDIO_ALG_INFO *pau_info=NULL;
384     MS_U8   DSP_select=0;
385     int ii;
386 
387    HALAUDSP_CHECK_SHM_INIT;
388 
389     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "@@@@@@@@@@    ====== HAL_AUDSP_DspLoadCode: 0x%x ======\r\n",dspCodeType);
390 
391     if (IS_AUDIO_DSP_CODE_TYPE_DEC1_SYSTEM(dspCodeType))
392     {
393         return  TRUE;    // Decoder in DEC-R2
394     }
395     else if (IS_AUDIO_DSP_CODE_TYPE_DEC_SYSTEM(dspCodeType)) //AU_DEC_SYSTEM
396     {
397         return  TRUE;    // Decoder in DEC-R2
398     }
399     else if ((IS_AUDIO_DSP_CODE_TYPE_DEC2_SYSTEM(dspCodeType)) ||
400              (IS_AUDIO_DSP_CODE_TYPE_SE_SYSTEM(dspCodeType)) ||
401              (IS_AUDIO_DSP_CODE_TYPE_SIF(dspCodeType)) ||
402              (IS_AUDIO_DSP_CODE_TYPE_ADVSND(dspCodeType)) ||
403              (IS_AUDIO_DSP_CODE_TYPE_SE_ENC(dspCodeType)))
404     {
405         for (ii=0; ii< sizeof(dsp_info)/sizeof(AUDIO_ALG_INFO);ii++)
406         {
407             if (dspCodeType == dsp_info[ii].dspCodeType)
408                 break;
409         }
410         if (ii < (sizeof(dsp_info)/sizeof(AUDIO_ALG_INFO)))
411         {
412             pau_info = &dsp_info[ii];
413             DSP_select = DSP_SE;
414         }
415         else
416         {
417             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "    [dsp_info]:decoder type not found.\r\n");
418             return FALSE;
419         }
420     }
421     else
422     {
423         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "    [HAL_AUDSP_DspLoadCode]:======  Loading the wrong DSP code type!======\r\n");
424         return FALSE;
425     }
426 
427 #ifndef MSOS_TYPE_NUTTX
428     AUDIO_TEE_INFO_SHM_CHECK_NULL;
429     REE_TO_TEE_MBX_MSG_SET_PARAM(0, (dspCodeType&0xFF));
430     REE_TO_TEE_MBX_MSG_SET_PARAM(1, ((dspCodeType&0xFF00)>>8));
431     REE_TO_TEE_MBX_MSG_SET_PARAM_COUNT(2);
432     msg_type = REE_TO_TEE_MBX_MSG_HAL_AUDSP_DspLoadCode;
433     if (DSP_select == DSP_DEC)
434     {
435         msg_type = msg_type | REE_TO_TEE_MBX_MSG_TYPE_DEC;
436     }
437     else if (DSP_select == DSP_SE)
438     {
439         msg_type = msg_type | REE_TO_TEE_MBX_MSG_TYPE_SE;
440     }
441 
442     if ( TEE_TO_REE_MBX_ACK_MSG_NO_TEE != (mbx_msg_ack_status = HAL_AUDIO_SendMBXMsg(msg_type)))
443     {
444         if (mbx_msg_ack_status != TEE_TO_REE_MBX_ACK_MSG_ACTION_SUCCESS)
445             return FALSE;
446         HAL_AUDSP_SetDspCodeTypeLoaded(dspCodeType);
447         return TRUE;
448     }
449 #endif
450 
451     if(pau_info->cm_len == 0)
452         return TRUE;                 // Return if CM length = 0 (BDMA can't support 0 length)
453     HAL_AUDSP_SetDspLoadCodeInfo(pau_info, DSP_select);
454 
455     if(DSP_select == DSP_DEC) // IDMA switch
456     {
457         HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x00);
458     }
459     else
460     {
461         HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x01);
462     }
463 
464     if (IS_AUDIO_DSP_CODE_TYPE_SE_SYSTEM(dspCodeType))
465     {
466         pau_info->cm_addr = 0x0008;
467         pau_info->cm_len = (MST_CODEC_PM1_SIZE - 24);
468         pau_info->cm_buf = (mst_codec_pm1+ 30);
469     }
470 
471      // Download PM of Algorithm
472     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM addr: 0x%x\r\n", (unsigned int)pau_info->pm_addr);
473 #if defined (__aarch64__)
474     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM buf addr: 0x%lx\r\n", (MS_VIRT)pau_info->pm_buf);
475 #else
476     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM buf addr: 0x%x\r\n", (unsigned int)pau_info->pm_buf);
477 #endif
478     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM size: 0x%x\r\n",(unsigned int)pau_info->pm_len);
479 
480     if(!HAL_AUDSP_DspLoadCodeSegment(pau_info->pm_addr, pau_info->pm_buf, pau_info->pm_len, DSP_select))
481         return FALSE;
482     if(!HAL_AUDSP_DspVerifySegmentCode(pau_info->pm_addr, pau_info->pm_buf, pau_info->pm_len, DSP_select))
483         return FALSE;
484 
485     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM addr: 0x%x\r\n", (unsigned int)pau_info->cm_addr);
486 #if defined (__aarch64__)
487     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM buf addr: 0x%lx\r\n", (MS_VIRT)pau_info->cm_buf);
488 #else
489     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM buf addr: 0x%x\r\n", (unsigned int)pau_info->cm_buf);
490 #endif
491     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM size: 0x%x\r\n", (unsigned int)pau_info->cm_len);
492 
493     if(!HAL_AUDSP_DspLoadCodeSegment(pau_info->cm_addr, pau_info->cm_buf, pau_info->cm_len, DSP_select))
494        return FALSE;
495     if(!HAL_AUDSP_DspVerifySegmentCode(pau_info->cm_addr, pau_info->cm_buf, pau_info->cm_len, DSP_select))
496        return FALSE;
497 
498     // Download PM of PreFetch
499     if(pau_info->prefetch_len != 0)
500     {
501         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM addr: 0x%x\r\n", (unsigned int)pau_info->prefetch_addr);
502 #if defined (__aarch64__)
503         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM buf addr: 0x%lx\r\n", (MS_VIRT)pau_info->prefetch_buf);
504 #else
505         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM buf addr: 0x%x\r\n", (unsigned int)pau_info->prefetch_buf);
506 #endif
507         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM size: 0x%x\r\n", (unsigned int)pau_info->prefetch_len);
508 
509         MIU_addr = pau_info->prefetch_addr * 3 + HAL_AUDIO_GetDspMadBaseAddr(DSP_select);
510         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    MIU of PreFetch: 0x%08X\r\n", (unsigned int)MIU_addr);
511         memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((pau_info->prefetch_buf)), pau_info->prefetch_len);
512     }
513 
514     // Download PM of Cache
515     if(pau_info->cache_len != 0)
516     {
517         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM addr: 0x%x\r\n", (unsigned int)pau_info->cache_addr);
518 #if defined (__aarch64__)
519         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM buf addr: 0x%lx\r\n", (MS_VIRT)pau_info->cache_buf);
520 #else
521         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM buf addr: 0x%x\r\n", (unsigned int)pau_info->cache_buf);
522 #endif
523         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM size: 0x%x\r\n", (unsigned int)pau_info->cache_len);
524 
525         MIU_addr = pau_info->cache_addr * 3 + HAL_AUDIO_GetDspMadBaseAddr(DSP_select);
526         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    MIU of Cache: 0x%08X\r\n", (unsigned int)MIU_addr);
527         memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((pau_info->cache_buf)), pau_info->cache_len);
528     }
529 
530   // Load  SE-DSP  system code
531     if (IS_AUDIO_DSP_CODE_TYPE_SE_SYSTEM(dspCodeType))
532     {
533 #if ASND_R2_SUPPORT
534         HAL_AUR2_WriteByte(REG_SNDR2_RESET_CTRL, 0x00);               // STOP SND-R2
535         HAL_AUR2_WriteMaskReg(REG_SNDR2_SYSTEM_START, 0xFFFF, 0x0000); //clear SND-R2 start cmd register
536 #endif
537         HAL_AUDIO_WriteMaskReg(0x2DDC, 0xFFFF, 0x0000); //clear  SE-DSP start cmd register
538         AUDIO_DELAY1MS(1);
539 
540       #ifdef  CONFIG_MBOOT
541       //============ Load R2 code ===============
542       // Memory sequence : Mboot-R2(DEC-R2)
543       //====================================
544 
545       // Load DEC-R2
546         MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(DSP_ADV);
547 
548         memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((mst_codec_r2)), DEC_R2_SHM_DDR_OFFSET);
549         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);
550         memcpy((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
551                       (void*)(mst_codec_r2+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
552                       MST_CODEC_R2_AUDIO_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
553         HAL_DEC_R2_init_SHM_param();
554         AUDIO_DELAY1MS(1);
555         MsOS_FlushMemory();
556 
557         HAL_DEC_R2_EnableR2(TRUE);               // Enable DEC-R2 after load R2 code
558       #else
559       //============ Load R2 code ===============
560       // Memory sequence : DEC-R2 ==> SND-R2 ==> SE-DSP
561       //====================================
562 
563       // Load DEC-R2
564         MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(DSP_ADV);
565 
566         memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((mst_codec_r2)), DEC_R2_SHM_DDR_OFFSET);
567         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);
568         memcpy((void*)(MS_PA2KSEG1(MIU_addr)+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
569                       (void*)(mst_codec_r2+DEC_R2_SHM_DDR_OFFSET+DEC_R2_SHM_DDR_SIZE),
570                       MST_CODEC_R2_AUDIO_SIZE - DEC_R2_SHM_DDR_OFFSET - DEC_R2_SHM_DDR_SIZE);
571         HAL_DEC_R2_init_SHM_param();
572         AUDIO_DELAY1MS(1);
573         MsOS_FlushMemory();
574 #if ASND_R2_SUPPORT
575      // Load SND-R2
576         MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(DSP_ADV)+ADEC__R2_DDR_SIZE;
577         memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((mst_snd_r2)), SND_R2_SHM_DDR_OFFSET);
578         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);
579         memcpy((void*)(MS_PA2KSEG1(MIU_addr)+SND_R2_SHM_DDR_OFFSET+SND_R2_SHM_DDR_SIZE),
580                       (void*)(mst_snd_r2+SND_R2_SHM_DDR_OFFSET+SND_R2_SHM_DDR_SIZE),
581                       MST_SND_R2_AUDIO_SIZE - SND_R2_SHM_DDR_OFFSET - SND_R2_SHM_DDR_SIZE);
582         AUDIO_DELAY1MS(1);
583         MsOS_FlushMemory();
584 
585         HAL_SND_R2_EnableR2(TRUE);               // Enable SND-R2 after load R2 code
586 #endif
587         HAL_DEC_R2_EnableR2(TRUE);               // Enable DEC-R2 after load R2 code
588       #endif
589 
590         if(!HAL_AUDSP_DspLoadCodeSegment(0x0001,  mst_codec_pm1+6+3, 21, DSP_select)) return FALSE;
591         if(!HAL_AUDSP_DspVerifySegmentCode(0x0001,  mst_codec_pm1+6+3, 21, DSP_select)) return FALSE;
592         if(!HAL_AUDSP_DspLoadCodeSegment(0x0000,  mst_codec_pm1+6, 3, DSP_select)) return FALSE;
593         if(!HAL_AUDSP_DspVerifySegmentCode(0x0000,  mst_codec_pm1+6, 3, DSP_select)) return FALSE;
594     }
595 
596     MsOS_FlushMemory();
597 
598     HAL_AUDSP_SetDspCodeTypeLoaded(dspCodeType);
599     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "HAL_AUDSP_DspLoadCode finished(type=%s(0x%x))\r\n", pau_info->AlgName, dspCodeType);
600 
601     return TRUE;
602 }
603 
HAL_AUDSP_DspLoadCode2(MS_U8 DSP_select,void * info)604 MS_BOOL HAL_AUDSP_DspLoadCode2(MS_U8 DSP_select, void * info)
605 {
606     MS_PHY MIU_addr;
607     AUDIO_ALG_INFO * pau_info = (AUDIO_ALG_INFO *) info;
608 
609     if ( pau_info->cm_len == 0 )
610         return TRUE;                 // Return if CM length = 0 (BDMA can't support 0 length)
611 
612 //    AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "@@@@@@@@@@    ====== %s: %s start ======\r\n", __FUNCTION__, pau_info->AlgName);
613 
614     //HAL_AUDSP_SetDspLoadCodeInfo(pau_info, DSP_select);
615 
616     HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, ((DSP_select == DSP_DEC) ? 0x00 : 0x01));
617 
618     /* Download PM of Algorithm */
619     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM addr:     0x%x\r\n", (unsigned int)pau_info->pm_addr);
620 #if defined (__aarch64__)
621     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM buf addr: 0x%lx\r\n", (MS_VIRT)pau_info->pm_buf);
622 #else
623     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM buf addr: 0x%x\r\n", (unsigned int)pau_info->pm_buf);
624 #endif
625     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PM size:     0x%x\r\n", (unsigned int)pau_info->pm_len);
626 
627     if ( !HAL_AUDSP_DspLoadCodeSegment(pau_info->pm_addr, pau_info->pm_buf, pau_info->pm_len, DSP_select) )
628     {
629         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "Dsp ReLoad Code PM Segment Fail !!\r\n");
630         return FALSE;
631     }
632 
633     if ( !HAL_AUDSP_DspVerifySegmentCode(pau_info->pm_addr, pau_info->pm_buf, pau_info->pm_len, DSP_select) )
634     {
635         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "Dsp ReLoad Code PM Segment Verify Fail !!\r\n");
636         return FALSE;
637     }
638 
639     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM addr:     0x%x\r\n", (unsigned int)pau_info->cm_addr);
640 #if defined (__aarch64__)
641     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM buf addr: 0x%lx\r\n",  (MS_VIRT)pau_info->cm_buf);
642 #else
643     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM buf addr: 0x%x\r\n",  (unsigned int)pau_info->cm_buf);
644 #endif
645     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    CM size:     0x%x\r\n", (unsigned int)pau_info->cm_len);
646 
647     if ( !HAL_AUDSP_DspLoadCodeSegment(pau_info->cm_addr, pau_info->cm_buf, pau_info->cm_len, DSP_select) )
648     {
649         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "Dsp ReLoad Code CM Segment Fail !!\r\n");
650         return FALSE;
651     }
652 
653     if ( !HAL_AUDSP_DspVerifySegmentCode(pau_info->cm_addr, pau_info->cm_buf, pau_info->cm_len, DSP_select) )
654     {
655         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "Dsp ReLoad Code CM Segment Verify Fail !!\r\n");
656         return FALSE;
657     }
658 
659     /* Download PM of PreFetch */
660     if ( pau_info->prefetch_len != 0 )
661     {
662         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM addr: 0x%x\r\n", (unsigned int)pau_info->prefetch_addr);
663 #if defined (__aarch64__)
664         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM buf addr: 0x%lx\r\n", (MS_VIRT)pau_info->prefetch_buf);
665 #else
666         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM buf addr: 0x%x\r\n", (unsigned int)pau_info->prefetch_buf);
667 #endif
668         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    PreFetch PM size: 0x%x\r\n", (unsigned int)pau_info->prefetch_len);
669 
670         MIU_addr = (MS_PHY) pau_info->prefetch_addr * 3 + HAL_AUDIO_GetDspMadBaseAddr(DSP_select);
671         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    MIU of PreFetch: 0x%X\r\n", (unsigned int) MIU_addr);
672 
673         memcpy((void *)(MS_PA2KSEG1(MIU_addr)), (void *)((pau_info->prefetch_buf)), pau_info->prefetch_len);
674     }
675 
676     /* Download PM of Cache */
677     if ( pau_info->cache_len != 0 )
678     {
679         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM addr: 0x%x\r\n", (unsigned int)pau_info->cache_addr);
680 #if defined (__aarch64__)
681         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM buf addr: 0x%lx\r\n", (MS_VIRT)pau_info->cache_buf);
682 #else
683         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM buf addr: 0x%x\r\n", (unsigned int)pau_info->cache_buf);
684 #endif
685         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    Cache PM size: 0x%x\r\n", (unsigned int)pau_info->cache_len);
686 
687         MIU_addr = (MS_U32)pau_info->cache_addr * 3 + HAL_AUDIO_GetDspMadBaseAddr(DSP_select);
688         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "    MIU of Cache: 0x%X\r\n", (unsigned int)MIU_addr);
689 
690         memcpy((void *)(MS_PA2KSEG1(MIU_addr)), (void *)((pau_info->cache_buf)), pau_info->cache_len);
691     }
692 
693     MsOS_FlushMemory();
694 
695     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "DSP %s finished (type=%s)\r\n", ((DSP_select == DSP_DEC) ? "DEC" : "SND"), pau_info->AlgName);
696 
697     return TRUE;
698 }
699 
HAL_AUDSP_DspLoadSystemCode2(MS_U8 DSP_select,AUDIO_ALG_INFO * pau_info)700 MS_BOOL HAL_AUDSP_DspLoadSystemCode2(MS_U8 DSP_select, AUDIO_ALG_INFO * pau_info)
701 {
702     MS_U8  * dsp_bootcode;
703  #ifndef  CONFIG_MBOOT
704     MS_PHY   MIU_addr;
705  #endif
706 
707     if ( pau_info->cm_len == 0 )
708     {
709         return TRUE;                 // Return if CM length = 0 (BDMA can't support 0 length)
710     }
711 
712     dsp_bootcode = pau_info->cm_buf;
713 
714     pau_info->cm_addr = 0x0008;
715     pau_info->cm_len = (MST_CODEC_PM1_SIZE - 24);
716     pau_info->cm_buf = (mst_codec_pm1 + 30);
717 
718     if ( !HAL_AUDSP_DspLoadCode2(DSP_select, pau_info) )
719     {
720         return FALSE;
721     }
722 
723     if ( DSP_select == DSP_SE )
724     {
725         HAL_AUDIO_WriteMaskReg(0x2E9E, 0xFFFF, 0x0000);
726         HAL_AUDIO_WriteMaskByte(REG_DECR2_RESET_CTRL, 0xFF, 0x00);                //Stop R2
727         HAL_AUDIO_WriteMaskReg(0x2E9E, 0xFFFF, 0x0000); //clear R2 & SE-DSP start cmd register
728         HAL_AUDIO_WriteMaskReg(0x2DDC, 0xFFFF, 0x0000); //clear R2 & SE-DSP start cmd register
729         AUDIO_DELAY1MS(1);
730 #ifndef  CONFIG_MBOOT
731         MIU_addr = HAL_AUDIO_GetDspMadBaseAddr(2);
732         memcpy((void *) (MS_PA2KSEG1 (MIU_addr)), (void *) ((mst_codec_r2)), MST_CODEC_R2_AUDIO_SIZE);
733 #endif
734         HAL_AUDIO_WriteMaskByte(REG_DECR2_RESET_CTRL, 0xFF, 0x27);                 //Eanble R2
735     }
736 
737 
738     if ( !HAL_AUDSP_DspLoadCodeSegment(0x0001, dsp_bootcode + 3, 21, DSP_select) )
739     {
740          return FALSE;
741     }
742 
743     if ( !HAL_AUDSP_DspVerifySegmentCode(0x0001, dsp_bootcode + 3, 21, DSP_select) )
744     {
745          return FALSE;
746     }
747 
748     if ( !HAL_AUDSP_DspLoadCodeSegment(0x0000, dsp_bootcode, 3, DSP_select) )
749     {
750          return FALSE;
751     }
752 
753     if ( !HAL_AUDSP_DspVerifySegmentCode(0x0000, dsp_bootcode, 3, DSP_select) )
754     {
755          return FALSE;
756     }
757 
758 
759     MsOS_FlushMemory();
760 
761     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "HAL_AUDSP_DspLoadSystemCode2 finished(type=%s)\r\n", pau_info->AlgName);
762     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "HAL_AUDSP_DspLoadSystemCode2 finished(type=%s)\r\n", pau_info->AlgName);
763 
764     return TRUE;
765 }
766 
767 ////////////////////////////////////////////////////////////////////////////////
768 /// @brief \b Function \b Name: HAL_AUDIO_DspLoadCodeSegment()
769 /// @brief \b Function \b Description: This routine is used to load DSP code
770 /// @param <IN>        \b dsp_addr    :
771 /// @param <IN>        \b dspCode_buf    :
772 /// @param <IN>        \b dspCode_buflen    :
773 /// @param <OUT>       \b NONE    :
774 /// @param <RET>       \b  BOOL    :    TRUE --DSP Load code okay
775 ///                                    FALSE--DSP Load code fail
776 /// @param <GLOBAL>    \b NONE    :
777 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_DspLoadCodeSegment(MS_U32 dsp_addr,MS_U8 * dspCode_buf,MS_U32 dspCode_buflen,MS_U8 DSP_select)778 MS_BOOL HAL_AUDSP_DspLoadCodeSegment(MS_U32 dsp_addr, MS_U8  *dspCode_buf, MS_U32 dspCode_buflen, MS_U8 DSP_select)
779 {
780     MS_U32 i,j;
781     MS_U32 idma_wrbase_addr_l, dsp_brg_data_l, dsp_brg_data_h, bdma_mode_addr;
782 
783     HALAUDSP_CHECK_SHM_INIT;
784 
785     OS_OBTAIN_MUTEX(_s32AUDIOMutexIDMA, MSOS_WAIT_FOREVER);
786 
787     g_bDSPLoadCode = TRUE;
788 
789     if(DSP_select == DSP_DEC)
790     {
791         idma_wrbase_addr_l = REG_DEC_IDMA_WRBASE_ADDR_L;
792         dsp_brg_data_l = REG_DEC_DSP_BRG_DATA_L;
793         dsp_brg_data_h = REG_DEC_DSP_BRG_DATA_H;
794         bdma_mode_addr = REG_DEC_BDMA_CFG;
795         HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x00);
796     }
797     else
798     {
799         idma_wrbase_addr_l = REG_SE_IDMA_WRBASE_ADDR_L;
800         dsp_brg_data_l = REG_SE_DSP_BRG_DATA_L;
801         dsp_brg_data_h = REG_SE_DSP_BRG_DATA_H;
802         bdma_mode_addr = REG_SE_BDMA_CFG;
803         HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x01);
804     }
805 
806     HAL_AUDIO_WriteMaskReg(bdma_mode_addr, 0x8080, 0x0000); // disable bdma
807 
808     if(dspCode_buflen>0)
809     {
810         /* set iDMA addr */
811 
812         HAL_AUDIO_WriteReg(idma_wrbase_addr_l, dsp_addr);
813 
814         AUDIO_DELAY1MS(1);
815 
816         for( i=0; i<dspCode_buflen; i+=3)
817         {
818             HAL_AUDIO_WriteByte(dsp_brg_data_l,*(dspCode_buf+i+1));
819             HAL_AUDIO_WriteByte(dsp_brg_data_h,*(dspCode_buf+i+2));
820 
821             for(j=0;j<2;j++);//for delay only
822 
823             HAL_AUDIO_WriteByte(dsp_brg_data_l,*(dspCode_buf+i));
824             HAL_AUDIO_WriteByte(dsp_brg_data_h,0x00);
825 
826             if(DSP_select == DSP_DEC)
827             {
828                 if (HAL_AUDSP_CheckDecIdmaReady(AUD_CHK_DSP_WRITE_RDY)==FALSE)
829                 {
830                     g_bDSPLoadCode = FALSE;
831 
832                     OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
833 
834                     return FALSE;
835                 }
836             }
837             else
838             {
839                 if (HAL_AUDSP_CheckSeIdmaReady(AUD_CHK_DSP_WRITE_RDY)==FALSE)
840                 {
841                     g_bDSPLoadCode = FALSE;
842 
843                     OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
844 
845                     return FALSE;
846                 }
847             }
848         }
849     }
850 
851     g_bDSPLoadCode = FALSE;
852 
853     OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
854 
855     return TRUE;
856 }
857 
HAL_AUDSP_DspVerifySegmentCode(MS_U32 dsp_addr,MS_U8 * dspCode_buf,MS_U32 dspCode_buflen,MS_U8 DSP_select)858 MS_BOOL HAL_AUDSP_DspVerifySegmentCode(MS_U32 dsp_addr, MS_U8 *dspCode_buf, MS_U32 dspCode_buflen, MS_U8 DSP_select)
859 {
860     MS_U32 i;
861     MS_U8 dat[3];
862     MS_U32 idma_rdbase_addr_l, idma_ctrl0, idma_rddata_h_0, idma_rddata_h_1, idma_rddata_l, bdma_mode_addr;
863 
864 #if (DSP_VERIFY_DSP_CODE==0)
865     return TRUE;                        //don't verify just return;
866 #endif
867 
868     HALAUDSP_CHECK_SHM_INIT;
869 
870     OS_OBTAIN_MUTEX(_s32AUDIOMutexIDMA, MSOS_WAIT_FOREVER);
871 
872     g_bDSPLoadCode = TRUE;
873 
874     if ( DSP_select == DSP_DEC )
875     {
876         idma_rdbase_addr_l = REG_DEC_IDMA_RDBASE_ADDR_L;
877         idma_ctrl0 = REG_DEC_IDMA_CTRL0;
878         idma_rddata_h_0 = REG_DEC_IDMA_RDDATA_H_0;
879         idma_rddata_h_1 = REG_DEC_IDMA_RDDATA_H_1;
880         idma_rddata_l = REG_DEC_IDMA_RDDATA_L;
881         bdma_mode_addr = REG_DEC_BDMA_CFG;
882         HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x00);
883     }
884     else
885     {
886         idma_rdbase_addr_l = REG_SE_IDMA_RDBASE_ADDR_L;
887         idma_ctrl0 = REG_SE_IDMA_CTRL0;
888         idma_rddata_h_0 = REG_SE_IDMA_RDDATA_H_0;
889         idma_rddata_h_1 = REG_SE_IDMA_RDDATA_H_1;
890         idma_rddata_l = REG_SE_IDMA_RDDATA_L;
891         bdma_mode_addr = REG_SE_BDMA_CFG;
892         HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x01);
893     }
894 
895     //HAL_AUDIO_WriteMaskByte(0x3CEC, 0x40, 0x00);
896     HAL_AUDIO_WriteMaskReg(bdma_mode_addr, 0x8080, 0x0000); // disable bdma (enable idma)
897     HAL_AUDIO_WriteReg(idma_rdbase_addr_l, dsp_addr);
898     AUDIO_DELAY1MS(1);
899 
900     for (i=0; i<dspCode_buflen; i+=3)
901     {
902         HAL_AUDIO_WriteMaskByte(idma_ctrl0, 0x08, 0x08 );
903 #if (DSP_IDMA_CHK_READY == 1)
904      if(DSP_select == DSP_DEC)
905         {
906          if (HAL_AUDSP_CheckDecIdmaReady(AUD_CHK_DSP_READ_RDY)==FALSE)
907              {
908                 g_bDSPLoadCode = FALSE;
909 
910                 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
911 
912                 return FALSE;
913              }
914         }
915         else
916         {
917             if (HAL_AUDSP_CheckSeIdmaReady(AUD_CHK_DSP_READ_RDY)==FALSE)
918             {
919                 g_bDSPLoadCode = FALSE;
920 
921                 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
922 
923                 return FALSE;
924             }
925         }
926 #endif
927         dat[1] = HAL_AUDIO_ReadByte(idma_rddata_h_0);
928         dat[2] = HAL_AUDIO_ReadByte(idma_rddata_h_1);
929         dat[0] = HAL_AUDIO_ReadByte(idma_rddata_l);
930 
931         //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "@@%x\n", (dat[2] << 16) | (dat[1] << 8) | (dat[0]));
932 
933         if ( (dat[0]!=dspCode_buf[i]) || (dat[1]!=dspCode_buf[i+1]) ||
934                 (dat[2]!=dspCode_buf[i+2]))
935         {
936             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "check data %x\n", (unsigned int)i);
937             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "dat0 %X <===> ",dspCode_buf[i]);
938             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "%x \n", dat[0]);
939             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "dat1 %X <===> ",dspCode_buf[i+1]);
940             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "%x \n", dat[1]);
941             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "dat2 %x <===> ",dspCode_buf[i+2]);
942             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "%X \n", dat[2]);
943             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "  Dsp code verify error!!\r\n");
944 
945             g_bDSPLoadCode = FALSE;
946 
947             OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
948 
949             return FALSE;
950         }
951     }
952 
953     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "  Dsp code verify ok!!\n\r");
954 
955     g_bDSPLoadCode = FALSE;
956 
957     OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
958 
959     return TRUE;
960 }
961 
962 ////////////////////////////////////////////////////////////////////////////////
963 /// @brief \b Function \b Name: HAL_AUDSP_CheckDecIdmaReady()
964 /// @brief \b Function \b Description:  This routine is used to check if the Dec-DSP IDMA is ready or not.
965 /// @param <IN>        \b IdmaChk_type    :
966 ///                                    0x10 : check write ready
967 ///                                    0x80 : check read  ready
968 /// @param <OUT>       \b NONE    :
969 /// @param <RET>       \b MS_BOOL    : TRUE--IDMA is ready
970 ///                                      FALSE--IDMA not ready
971 /// @param <GLOBAL>    \b NONE    :
972 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_CheckDecIdmaReady(MS_U8 u8IdmaChk_type)973 MS_BOOL HAL_AUDSP_CheckDecIdmaReady(MS_U8 u8IdmaChk_type )
974 {
975     MS_U8  j = 0;
976 
977     while(j<200)
978     {
979         j++;
980         if( (HAL_AUDIO_ReadByte(REG_DEC_IDMA_CTRL0)& u8IdmaChk_type) == 0 )
981             return TRUE;
982     }
983 
984     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "DSP DEC Idma check ready fail!(%d)\r\n",j);
985     return FALSE;
986 }
987 
988 ////////////////////////////////////////////////////////////////////////////////
989 /// @brief \b Function \b Name: HAL_AUDIO_CheckSeIdmaReady()
990 /// @brief \b Function \b Description:  This routine is used to check if the Se-DSP IDMA is ready or not.
991 /// @param <IN>        \b IdmaChk_type    :
992 ///                                    0x10 : check write ready
993 ///                                    0x80 : check read  ready
994 /// @param <OUT>       \b NONE    :
995 /// @param <RET>       \b MS_BOOL    : TRUE--IDMA is ready
996 ///                                      FALSE--IDMA not ready
997 /// @param <GLOBAL>    \b NONE    :
998 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_CheckSeIdmaReady(MS_U8 u8IdmaChk_type)999 MS_BOOL HAL_AUDSP_CheckSeIdmaReady(MS_U8 u8IdmaChk_type)
1000 {
1001     MS_U8  j = 0;
1002 
1003     while(j<200)
1004     {
1005         j++;
1006         if( (HAL_AUDIO_ReadByte(REG_SE_IDMA_CTRL0)& u8IdmaChk_type) == 0 )
1007             return TRUE;
1008     }
1009 
1010     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "DSP SE Idma check ready fail!(%d)\r\n",j);
1011     return FALSE;
1012 }
1013 
1014 ////////////////////////////////////////////////////////////////////////////////
1015 /// @brief \b Function \b Name: HAL_AUDSP_SetDspCodeTypeLoaded()
1016 /// @brief \b Function \b Description:  This function is used to set the DSP code type.
1017 /// @param <IN>        \b NONE    :
1018 /// @param <OUT>       \b NONE    :
1019 /// @param <RET>       \b MS_U8: DSP code type.
1020 /// @param <GLOBAL>    \b NONE    :
1021 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_SetDspCodeTypeLoaded(AUDIO_DSP_CODE_TYPE dspCodeType)1022 void HAL_AUDSP_SetDspCodeTypeLoaded(AUDIO_DSP_CODE_TYPE dspCodeType)
1023 {
1024     g_DspCodeTypeLoaded = dspCodeType;
1025 }
1026 
1027 ////////////////////////////////////////////////////////////////////////////////
1028 /// @brief \b Function \b Name: HAL_AUDSP_GetDspCodeTypeLoaded()
1029 /// @brief \b Function \b Description:  This function is used to get the MAD base address.
1030 /// @param <IN>        \b NONE    :
1031 /// @param <OUT>       \b NONE    :
1032 /// @param <RET>       \b MS_U8: DSP code type.
1033 /// @param <GLOBAL>    \b NONE    :
1034 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_GetDspCodeTypeLoaded(void)1035 AUDIO_DSP_CODE_TYPE HAL_AUDSP_GetDspCodeTypeLoaded(void)
1036 {
1037     return g_DspCodeTypeLoaded;
1038 }
1039 
HAL_AUDSP_SetDspLoadCodeInfo(AUDIO_ALG_INFO * pau_info,MS_U8 DSP_select)1040 void HAL_AUDSP_SetDspLoadCodeInfo(AUDIO_ALG_INFO *pau_info, MS_U8 DSP_select)
1041 {
1042     g_loadcodeinfo.pau_info = pau_info;
1043     g_loadcodeinfo.DSP_select= DSP_select;
1044 }
1045 
1046 ////////////////////////////////////////////////////////////////////////////////
1047 /// @brief \b Function \b Name: HAL_AUDSP_GetDspCodeTypeLoaded()
1048 /// @brief \b Function \b Description:  This function is used to get the MAD base address.
1049 /// @param <IN>        \b NONE    :
1050 /// @param <OUT>       \b NONE    :
1051 /// @param <RET>       \b MS_U8: DSP code type.
1052 /// @param <GLOBAL>    \b NONE    :
1053 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_GetDspLoadCodeInfo(void)1054 LOAD_CODE_INFO* HAL_AUDSP_GetDspLoadCodeInfo(void)
1055 {
1056     return &g_loadcodeinfo;
1057 }
1058