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