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