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 #include "ULog.h"
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 "DecoderInfo.h"
119
120 #define LOAD_CODE_DEBUG 0
121
122 #define HALAUDSP_CHECK_SHM_INIT \
123 do { \
124 if (g_AudioVars2 == NULL) \
125 { \
126 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Warning! g_AudioVars2 should not be NULL !!!\n", __FUNCTION__); \
127 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Perform SHM Init here !!!\n", __FUNCTION__); \
128 if (HAL_AUDIO_InitialVars() == FALSE) \
129 { \
130 MS_ASSERT(0); \
131 } \
132 } \
133 } while(0)
134
135 //-------------------------------------------------------------------------------------------------
136 // Driver Compiler Options
137 //-------------------------------------------------------------------------------------------------
138 #ifdef CONFIG_MBOOT //mboot Speed up
139 #define DSP_VERIFY_DSP_CODE 0 // 0: don't verify dsp code (for speed)
140 // 1: verify dsp code (for debug)
141 #define DSP_IDMA_CHK_READY 1 // 0: don't check IDMA ready (for speed)
142 // 1: check IDMA ready (for debug)
143 #else
144 #define DSP_VERIFY_DSP_CODE 1 // 0: don't verify dsp code (for speed)
145 // 1: verify dsp code (for debug)
146 #define DSP_IDMA_CHK_READY 1 // 0: don't check IDMA ready (for speed)
147 // 1: check IDMA ready (for debug)
148 #endif
149
150 #define AU_NULL 0
151
152 LOAD_CODE_INFO g_loadcodeinfo;
153 MS_BOOL g_bDSPLoadCode = FALSE;
154
155 #ifndef MSOS_TYPE_NOS
156 void* MDrv_MPool_PA2KSEG1(void* pAddrPhys);
157 #endif
158 //-------------------------------------------------------------------------------------------------
159 // Local Defines
160 //-------------------------------------------------------------------------------------------------
161 #define LOU8(MS_U16Val) ( (MS_U8)(MS_U16Val) )
162 #define HIU8(MS_U16Val) ( (MS_U8)((MS_U16Val) >> 8) )
163
164 //-------------------------------------------------------------------------------------------------
165 // Local Structures
166 //-------------------------------------------------------------------------------------------------
167
168 //-------------------------------------------------------------------------------------------------
169 // Global Variables
170 //-------------------------------------------------------------------------------------------------
171 extern MS_BOOL g_bAudio_loadcode_from_dram;
172 extern AUDIO_SHARED_VARS2 * g_AudioVars2;
173
174 extern MS_S32 _s32AUDIOMutexIDMA;
175
176 #ifndef MSOS_TYPE_NUTTX
177 extern AUDIO_TEE_INFO_SHARE_MEM *pAudioTeeInfoShm;
178 #endif
179
180
181 //-------------------------------------------------------------------------------------------------
182 // Local Variables
183 //-------------------------------------------------------------------------------------------------
184 static MS_U8 g_u8DspCodeTypeLoaded = 0;
185
186
187 //-------------------------------------------------------------------------------------------------
188 // Debug Functions
189 //-------------------------------------------------------------------------------------------------
190
191
192 //-------------------------------------------------------------------------------------------------
193 // Local Functions
194 //-------------------------------------------------------------------------------------------------
195
196
197 //-------------------------------------------------------------------------------------------------
198 // Global Functions
199 //-------------------------------------------------------------------------------------------------
200 ////////////////////////////////////////////////////////////////////////////////
201 /// @brief \b Function \b Name: HAL_AUDSP_DspLoadCode()
202 /// @brief \b Function \b Description: load CM/PM/cache/prefetch DSP code
203 /// @param <IN> \b \b u8Type : -- DSP load code type
204 /// DSP_segment -- select DSP load code seg
205 /// @param <OUT> \b NONE :
206 /// @param <RET> \b NONE :
207 /// @param <GLOBAL> \b NONE :
208 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_DspLoadCode(MS_U8 u8Type)209 MS_BOOL HAL_AUDSP_DspLoadCode(MS_U8 u8Type)
210 {
211 #ifndef MSOS_TYPE_NUTTX
212 REE_TO_TEE_MBX_MSG_TYPE msg_type = REE_TO_TEE_MBX_MSG_NULL;
213 #endif
214 MS_PHY MIU_addr;
215 AUDIO_ALG_INFO *pCodeTableinfo=NULL;
216 LOAD_CODE_ARCH_TYPE eArchType = LOAD_INVALID;
217
218 HALAUDSP_CHECK_SHM_INIT;
219
220 switch(u8Type)
221 {
222
223 case AU_DEC_SYSTEM:
224 break;
225
226 case AU_SE_SYSTEM:
227 pCodeTableinfo = &SE_SYSTEM_LoadCodeTable[0];
228 eArchType = LOAD_SYSTEM;
229 break;
230
231 case AU_DVB_DEC_NONE:
232 case AU_DVB2_NONE:
233 pCodeTableinfo = &DEC_LoadCodeTable[0];
234 eArchType = LOAD_DECODER;
235 break;
236
237 case AU_DVB_STANDARD_MPEG:
238 case AU_DVB2_STANDARD_MPEG_AD:
239 pCodeTableinfo = &MPEG_LoadCodeTable[0];
240 eArchType = LOAD_DECODER;
241 break;
242
243 case AU_DVB_STANDARD_AAC:
244 case AU_DVB_STANDARD_MS10_DDT:
245 case AU_DVB2_STANDARD_GAAC_AD:
246 pCodeTableinfo = &GAAC_LoadCodeTable[0];
247 eArchType = LOAD_DECODER;
248 break;
249
250 case AU_DVB_STANDARD_MS10_DDC:
251 case AU_DVB_STANDARD_AC3:
252 case AU_DVB_STANDARD_AC3P:
253 case AU_DVB2_STANDARD_AC3_AD:
254 case AU_DVB2_STANDARD_AC3P_AD:
255 pCodeTableinfo = &AC3P_LoadCodeTable[0];
256 eArchType = LOAD_DECODER;
257 break;
258
259 case AU_DVB_STANDARD_MP3:
260 case AU_DVB2_STANDARD_MP3:
261 pCodeTableinfo = &MP3_LoadCodeTable[0];
262 eArchType = LOAD_DECODER;
263 break;
264
265 case AU_DVB_STANDARD_WMA:
266 case AU_DVB_STANDARD_WMA_PRO:
267 pCodeTableinfo = &WMA_PRO_LoadCodeTable[0];
268 eArchType = LOAD_DECODER;
269 break;
270
271 case AU_DVB_STANDARD_XPCM:
272 case AU_DVB2_STANDARD_XPCM:
273 pCodeTableinfo = &XPCM_LoadCodeTable[0];
274 eArchType = LOAD_DECODER;
275 break;
276
277 case AU_DVB_STANDARD_RA8LBR:
278 pCodeTableinfo = &RA8LBR_LoadCodeTable[0];
279 eArchType = LOAD_DECODER;
280 break;
281
282 case AU_DVB_STANDARD_FLAC:
283 pCodeTableinfo = &FLAC_LoadCodeTable[0];
284 eArchType = LOAD_DECODER;
285 break;
286
287 case AU_DVB_STANDARD_VORBIS:
288 pCodeTableinfo = &VORBIS_LoadCodeTable[0];
289 eArchType = LOAD_DECODER;
290 break;
291
292 case AU_DVB_STANDARD_DTS:
293 case AU_DVB2_STANDARD_DTS:
294 pCodeTableinfo = &DTS_DMP_LoadCodeTable[0];
295 eArchType = LOAD_DECODER;
296 break;
297
298 case AU_DVB_STANDARD_DTSLBR:
299 pCodeTableinfo = &DTS_LBR_LoadCodeTable[0];
300 eArchType = LOAD_DECODER;
301 break;
302
303 case AU_DVB_STANDARD_DRA:
304 pCodeTableinfo = &DRAD_LoadCodeTable[0];
305 eArchType = LOAD_DECODER;
306 break;
307
308 case AU_DVB_STANDARD_AMR_NB:
309 pCodeTableinfo = &AMR_NB_LoadCodeTable[0];
310 eArchType = LOAD_DECODER;
311 break;
312
313 case AU_DVB_STANDARD_AMR_WB:
314 pCodeTableinfo = &AMR_WB_LoadCodeTable[0];
315 eArchType = LOAD_DECODER;
316 break;
317
318 case AU_SIF_PALSUM:
319 pCodeTableinfo = &PALSUM_LoadCodeTable[0];
320 eArchType = LOAD_DECODER;
321 break;
322
323 case AU_SIF_BTSC:
324 pCodeTableinfo = &BTSC_LoadCodeTable[0];
325 eArchType = LOAD_DECODER;
326 break;
327
328 case AU_DVB2_ADVSND_TSHD:
329 pCodeTableinfo = &TSHD_LoadCodeTable[0];
330 eArchType = LOAD_ADVSOUND;
331 break;
332
333 case AU_DVB2_ADVSND_SRS:
334 pCodeTableinfo = &TSXT_LoadCodeTable[0];
335 eArchType = LOAD_ADVSOUND;
336 break;
337
338 case AU_DVB2_ADVSND_PURESND:
339 pCodeTableinfo = &PURESND_LoadCodeTable[0];
340 eArchType = LOAD_ADVSOUND;
341 break;
342
343 case AU_DVB2_ADVSND_DBX:
344 pCodeTableinfo = &DBX_LoadCodeTable[0];
345 eArchType = LOAD_ADVSOUND;
346 break;
347
348 default :
349 eArchType = LOAD_INVALID;
350 return FALSE;
351 };
352
353 #ifndef MSOS_TYPE_NUTTX
354 AUDIO_TEE_INFO_SHM_CHECK_NULL;
355 REE_TO_TEE_MBX_MSG_SET_PARAM(0, (MS_U8)u8Type);
356 REE_TO_TEE_MBX_MSG_SET_PARAM_COUNT(1);
357 msg_type = REE_TO_TEE_MBX_MSG_HAL_AUDSP_DspLoadCode;
358 msg_type = msg_type | REE_TO_TEE_MBX_MSG_TYPE_SE;
359
360 if ( TEE_TO_REE_MBX_ACK_MSG_NO_TEE != (mbx_msg_ack_status = HAL_AUDIO_SendMBXMsg(msg_type)))
361 {
362 if (mbx_msg_ack_status != TEE_TO_REE_MBX_ACK_MSG_ACTION_SUCCESS)
363 return FALSE;
364 HAL_AUDSP_SetDspCodeTypeLoaded(u8Type);
365 return TRUE;
366 }
367 #endif
368
369 if(pCodeTableinfo == NULL)
370 {
371 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "\r\n=======NULL return==========\r\n");
372 return FALSE;
373 }
374 else if(pCodeTableinfo->cm_len == 0)
375 {
376 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "\r\n========cm length =0=========\r\n");
377 return FALSE;
378 }
379
380 HAL_AUDSP_SetDspLoadCodeInfo(pCodeTableinfo, DSP_SE);
381 HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x01);
382
383 //======== Load DSP PM ========
384 #if(LOAD_CODE_DEBUG)
385 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PM addr: 0x%x\r\n", pCodeTableinfo->pm_addr);
386 #if defined (__aarch64__)
387 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PM buf addr: 0x%lx\r\n", (MS_VIRT)pCodeTableinfo->pm_buf);
388 #else
389 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PM buf addr: 0x%x\r\n", (MS_VIRT)pCodeTableinfo->pm_buf);
390 #endif
391 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PM size: 0x%x\r\n",pCodeTableinfo->pm_len);
392 #endif
393
394 if(!HAL_AUDSP_DspLoadCodeSegment(pCodeTableinfo->pm_addr, pCodeTableinfo->pm_buf+6, pCodeTableinfo->pm_len, DSP_SE))
395 return FALSE;
396 if(!HAL_AUDSP_DspVerifySegmentCode(pCodeTableinfo->pm_addr, pCodeTableinfo->pm_buf+6, pCodeTableinfo->pm_len, DSP_SE))
397 return FALSE;
398
399 //======== Load DSP Prefetch ========
400 #if(LOAD_CODE_DEBUG)
401 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PreFetch PM addr: 0x%x\r\n", pCodeTableinfo->prefetch_addr);
402 #if defined (__aarch64__)
403 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PreFetch PM buf addr: 0x%lx\r\n", (MS_VIRT)pCodeTableinfo->prefetch_buf);
404 #else
405 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PreFetch PM buf addr: 0x%x\r\n", (MS_VIRT)pCodeTableinfo->prefetch_buf);
406 #endif
407 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " PreFetch PM size: 0x%x\r\n", pCodeTableinfo->prefetch_len);
408 #endif
409
410 if(pCodeTableinfo->prefetch_len != 0)
411 {
412 MIU_addr = pCodeTableinfo->prefetch_addr * 3 + HAL_AUDIO_GetDspMadBaseAddr(DSP_SE);
413 #if defined (__aarch64__)
414 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " MIU of PreFetch: 0x%08lx\r\n", (unsigned int)(MS_VIRT)MIU_addr);
415 #else
416 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " MIU of PreFetch: 0x%08x\r\n", (unsigned int)(MS_VIRT)MIU_addr);
417 #endif
418 memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((pCodeTableinfo->prefetch_buf+6)), pCodeTableinfo->prefetch_len);
419 }
420
421 //======== Load DSP Cache ========
422 #if(LOAD_CODE_DEBUG)
423 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Cache PM addr: 0x%x\r\n", pCodeTableinfo->cache_addr);
424 #if defined (__aarch64__)
425 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Cache PM buf addr: 0x%lx\r\n", (MS_VIRT)pCodeTableinfo->cache_buf);
426 #else
427 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Cache PM buf addr: 0x%x\r\n", (MS_VIRT)pCodeTableinfo->cache_buf);
428 #endif
429 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Cache PM size: 0x%x\r\n", pCodeTableinfo->cache_len);
430 #endif
431
432 if(pCodeTableinfo->cache_len != 0)
433 {
434 MIU_addr = pCodeTableinfo->cache_addr * 3 + HAL_AUDIO_GetDspMadBaseAddr(DSP_SE);
435 #if defined (__aarch64__)
436 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " MIU of Cache: 0x%08lx\r\n", (unsigned int)(MS_VIRT)MIU_addr);
437 #else
438 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " MIU of Cache: 0x%08x\r\n", (unsigned int)(MS_VIRT)MIU_addr);
439 #endif
440 memcpy((void*)(MS_PA2KSEG1(MIU_addr)), (void*)((pCodeTableinfo->cache_buf+6)), pCodeTableinfo->cache_len);
441 }
442
443 //======== Load DSP CM ========
444 #if(LOAD_CODE_DEBUG)
445 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " CM addr: 0x%x\r\n", pCodeTableinfo->cm_addr);
446 #if defined (__aarch64__)
447 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " CM buf addr: 0x%lx\r\n", (MS_VIRT)pCodeTableinfo->cm_buf);
448 #else
449 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " CM buf addr: 0x%x\r\n", (MS_VIRT)pCodeTableinfo->cm_buf);
450 #endif
451 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " CM size: 0x%x\r\n", pCodeTableinfo->cm_len);
452 #endif
453
454 if(eArchType==LOAD_SYSTEM)
455 {
456 // First 2 words will be loaded later
457 if(!HAL_AUDSP_DspLoadCodeSegment(0x02, pCodeTableinfo->cm_buf+12, pCodeTableinfo->cm_len-6, DSP_SE))
458 return FALSE;
459 if(!HAL_AUDSP_DspVerifySegmentCode(0x02, pCodeTableinfo->cm_buf+12, pCodeTableinfo->cm_len-6, DSP_SE))
460 return FALSE;
461
462 // When Load SE-DSP system code , write address 0 to reset DSP
463 if(!HAL_AUDSP_DspLoadCodeSegment(0x0001, mst_codec_pm1+6+3, 21, DSP_SE)) return FALSE;
464 if(!HAL_AUDSP_DspVerifySegmentCode(0x0001, mst_codec_pm1+6+3, 21, DSP_SE)) return FALSE;
465 if(!HAL_AUDSP_DspLoadCodeSegment(0x0000, mst_codec_pm1+6, 3, DSP_SE)) return FALSE;
466 if(!HAL_AUDSP_DspVerifySegmentCode(0x0000, mst_codec_pm1+6, 3, DSP_SE)) return FALSE;
467 }
468 else
469 {
470 if(!HAL_AUDSP_DspLoadCodeSegment(pCodeTableinfo->cm_addr, pCodeTableinfo->cm_buf+6, pCodeTableinfo->cm_len, DSP_SE))
471 return FALSE;
472 if(!HAL_AUDSP_DspVerifySegmentCode(pCodeTableinfo->cm_addr, pCodeTableinfo->cm_buf+6, pCodeTableinfo->cm_len, DSP_SE))
473 return FALSE;
474 }
475
476 MsOS_FlushMemory();
477
478 HAL_AUDSP_SetDspCodeTypeLoaded(u8Type);
479 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "HAL_AUDSP_DspLoadCode finished(type=%s(0x%x))\r\n", pCodeTableinfo->AlgName, u8Type);
480 return TRUE;
481 }
482
483 ////////////////////////////////////////////////////////////////////////////////
484 /// @brief \b Function \b Name: HAL_AUDIO_DspLoadCodeSegment()
485 /// @brief \b Function \b Description: This routine is used to load DSP code
486 /// @param <IN> \b dsp_addr :
487 /// @param <IN> \b dspCode_buf :
488 /// @param <IN> \b dspCode_buflen :
489 /// @param <OUT> \b NONE :
490 /// @param <RET> \b BOOL : TRUE --DSP Load code okay
491 /// FALSE--DSP Load code fail
492 /// @param <GLOBAL> \b NONE :
493 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_DspLoadCodeSegment(MS_U32 dsp_addr,MS_U8 * dspCode_buf,MS_U32 dspCode_buflen,MS_U8 DSP_select)494 MS_BOOL HAL_AUDSP_DspLoadCodeSegment(MS_U32 dsp_addr, MS_U8 *dspCode_buf, MS_U32 dspCode_buflen, MS_U8 DSP_select)
495 {
496 MS_U32 i,j;
497 MS_U32 idma_wrbase_addr_l, dsp_brg_data_l, dsp_brg_data_h, bdma_mode_addr;
498
499 HALAUDSP_CHECK_SHM_INIT;
500
501 OS_OBTAIN_MUTEX(_s32AUDIOMutexIDMA, MSOS_WAIT_FOREVER);
502
503 g_bDSPLoadCode = TRUE;
504
505 if(DSP_select == DSP_DEC)
506 {
507 idma_wrbase_addr_l = REG_DEC_IDMA_WRBASE_ADDR_L;
508 dsp_brg_data_l = REG_DEC_DSP_BRG_DATA_L;
509 dsp_brg_data_h = REG_DEC_DSP_BRG_DATA_H;
510 bdma_mode_addr = REG_DEC_BDMA_CFG;
511 HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x00);
512 }
513 else
514 {
515 idma_wrbase_addr_l = REG_SE_IDMA_WRBASE_ADDR_L;
516 dsp_brg_data_l = REG_SE_DSP_BRG_DATA_L;
517 dsp_brg_data_h = REG_SE_DSP_BRG_DATA_H;
518 bdma_mode_addr = REG_SE_BDMA_CFG;
519 HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x01);
520 }
521
522 HAL_AUDIO_WriteMaskReg(bdma_mode_addr, 0x8080, 0x0000); // disable bdma
523
524 if(dspCode_buflen>0)
525 {
526 /* set iDMA addr */
527
528 HAL_AUDIO_WriteReg(idma_wrbase_addr_l, dsp_addr);
529
530 AUDIO_DELAY1MS(1);
531
532 for( i=0; i<dspCode_buflen; i+=3)
533 {
534 HAL_AUDIO_WriteByte(dsp_brg_data_l,*(dspCode_buf+i+1));
535 HAL_AUDIO_WriteByte(dsp_brg_data_h,*(dspCode_buf+i+2));
536
537 for(j=0;j<2;j++);//for delay only
538
539 HAL_AUDIO_WriteByte(dsp_brg_data_l,*(dspCode_buf+i));
540 HAL_AUDIO_WriteByte(dsp_brg_data_h,0x00);
541
542 if(DSP_select == DSP_DEC)
543 {
544 if (HAL_AUDSP_CheckDecIdmaReady(AUD_CHK_DSP_WRITE_RDY)==FALSE)
545 {
546 g_bDSPLoadCode = FALSE;
547 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
548 return FALSE;
549 }
550 }
551 else
552 {
553 if (HAL_AUDSP_CheckSeIdmaReady(AUD_CHK_DSP_WRITE_RDY)==FALSE)
554 {
555 g_bDSPLoadCode = FALSE;
556 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
557 return FALSE;
558 }
559 }
560 }
561 }
562
563 g_bDSPLoadCode = FALSE;
564
565 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
566
567 return TRUE;
568 }
569
HAL_AUDSP_DspVerifySegmentCode(MS_U32 dsp_addr,MS_U8 * dspCode_buf,MS_U32 dspCode_buflen,MS_U8 DSP_select)570 MS_BOOL HAL_AUDSP_DspVerifySegmentCode(MS_U32 dsp_addr, MS_U8 *dspCode_buf, MS_U32 dspCode_buflen, MS_U8 DSP_select)
571 {
572 MS_U32 i;
573 MS_U8 dat[3];
574 MS_U32 idma_rdbase_addr_l, idma_ctrl0, idma_rddata_h_0, idma_rddata_h_1, idma_rddata_l, bdma_mode_addr;
575
576 #if (DSP_VERIFY_DSP_CODE==0)
577 return TRUE; //don't verify just return;
578 #endif
579
580 HALAUDSP_CHECK_SHM_INIT;
581
582 OS_OBTAIN_MUTEX(_s32AUDIOMutexIDMA, MSOS_WAIT_FOREVER);
583
584 g_bDSPLoadCode = TRUE;
585
586 if ( DSP_select == DSP_DEC )
587 {
588 idma_rdbase_addr_l = REG_DEC_IDMA_RDBASE_ADDR_L;
589 idma_ctrl0 = REG_DEC_IDMA_CTRL0;
590 idma_rddata_h_0 = REG_DEC_IDMA_RDDATA_H_0;
591 idma_rddata_h_1 = REG_DEC_IDMA_RDDATA_H_1;
592 idma_rddata_l = REG_DEC_IDMA_RDDATA_L;
593 bdma_mode_addr = REG_DEC_BDMA_CFG;
594 HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x00);
595 }
596 else
597 {
598 idma_rdbase_addr_l = REG_SE_IDMA_RDBASE_ADDR_L;
599 idma_ctrl0 = REG_SE_IDMA_CTRL0;
600 idma_rddata_h_0 = REG_SE_IDMA_RDDATA_H_0;
601 idma_rddata_h_1 = REG_SE_IDMA_RDDATA_H_1;
602 idma_rddata_l = REG_SE_IDMA_RDDATA_L;
603 bdma_mode_addr = REG_SE_BDMA_CFG;
604 HAL_AUDIO_WriteMaskByte(REG_FD230_SELECT, 0x01, 0x01);
605 }
606
607 //HAL_AUDIO_WriteMaskByte(0x3CEC, 0x40, 0x00);
608 HAL_AUDIO_WriteMaskReg(bdma_mode_addr, 0x8080, 0x0000); // disable bdma (enable idma)
609 HAL_AUDIO_WriteReg(idma_rdbase_addr_l, dsp_addr);
610 AUDIO_DELAY1MS(1);
611
612 for (i=0; i<dspCode_buflen; i+=3)
613 {
614 HAL_AUDIO_WriteMaskByte(idma_ctrl0, 0x08, 0x08 );
615 #if (DSP_IDMA_CHK_READY == 1)
616 if(DSP_select == DSP_DEC)
617 {
618 if (HAL_AUDSP_CheckDecIdmaReady(AUD_CHK_DSP_READ_RDY)==FALSE)
619 {
620 g_bDSPLoadCode = FALSE;
621
622 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
623
624 return FALSE;
625 }
626 }
627 else
628 {
629 if (HAL_AUDSP_CheckSeIdmaReady(AUD_CHK_DSP_READ_RDY)==FALSE)
630 {
631 g_bDSPLoadCode = FALSE;
632
633 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
634
635 return FALSE;
636 }
637 }
638 #endif
639 dat[1] = HAL_AUDIO_ReadByte(idma_rddata_h_0);
640 dat[2] = HAL_AUDIO_ReadByte(idma_rddata_h_1);
641 dat[0] = HAL_AUDIO_ReadByte(idma_rddata_l);
642
643 //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "@@%x\n", (dat[2] << 16) | (dat[1] << 8) | (dat[0]));
644
645 if ( (dat[0]!=dspCode_buf[i]) || (dat[1]!=dspCode_buf[i+1]) ||
646 (dat[2]!=dspCode_buf[i+2]))
647 {
648 #if defined (CONFIG_UTOPIA_ANDROID_L)
649 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "check data %x\n", i);
650 #else
651 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "check data %x\n", (unsigned int)i);
652 #endif
653 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "dat0 %X <===> ",dspCode_buf[i]);
654 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "%x \n", dat[0]);
655 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "dat1 %X <===> ",dspCode_buf[i+1]);
656 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "%x \n", dat[1]);
657 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "dat2 %x <===> ",dspCode_buf[i+2]);
658 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "%X \n", dat[2]);
659 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Dsp code verify error!!\r\n");
660
661 g_bDSPLoadCode = FALSE;
662
663 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
664
665 return FALSE;
666 }
667 }
668
669 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, " Dsp code verify ok!!\n\r");
670
671 g_bDSPLoadCode = FALSE;
672
673 OS_RELEASE_MUTEX(_s32AUDIOMutexIDMA);
674
675 return TRUE;
676 }
677
678 ////////////////////////////////////////////////////////////////////////////////
679 /// @brief \b Function \b Name: HAL_AUDSP_CheckDecIdmaReady()
680 /// @brief \b Function \b Description: This routine is used to check if the Dec-DSP IDMA is ready or not.
681 /// @param <IN> \b IdmaChk_type :
682 /// 0x10 : check write ready
683 /// 0x80 : check read ready
684 /// @param <OUT> \b NONE :
685 /// @param <RET> \b MS_BOOL : TRUE--IDMA is ready
686 /// FALSE--IDMA not ready
687 /// @param <GLOBAL> \b NONE :
688 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_CheckDecIdmaReady(MS_U8 u8IdmaChk_type)689 MS_BOOL HAL_AUDSP_CheckDecIdmaReady(MS_U8 u8IdmaChk_type )
690 {
691 MS_U8 j = 0;
692
693 while(j<200)
694 {
695 j++;
696 if( (HAL_AUDIO_ReadByte(REG_DEC_IDMA_CTRL0)& u8IdmaChk_type) == 0 )
697 return TRUE;
698 }
699
700 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "DSP DEC Idma check ready fail!(%d)\r\n",j);
701 return FALSE;
702 }
703
704 ////////////////////////////////////////////////////////////////////////////////
705 /// @brief \b Function \b Name: HAL_AUDIO_CheckSeIdmaReady()
706 /// @brief \b Function \b Description: This routine is used to check if the Se-DSP IDMA is ready or not.
707 /// @param <IN> \b IdmaChk_type :
708 /// 0x10 : check write ready
709 /// 0x80 : check read ready
710 /// @param <OUT> \b NONE :
711 /// @param <RET> \b MS_BOOL : TRUE--IDMA is ready
712 /// FALSE--IDMA not ready
713 /// @param <GLOBAL> \b NONE :
714 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_CheckSeIdmaReady(MS_U8 u8IdmaChk_type)715 MS_BOOL HAL_AUDSP_CheckSeIdmaReady(MS_U8 u8IdmaChk_type)
716 {
717 MS_U8 j = 0;
718
719 while(j<200)
720 {
721 j++;
722 if( (HAL_AUDIO_ReadByte(REG_SE_IDMA_CTRL0)& u8IdmaChk_type) == 0 )
723 return TRUE;
724 }
725
726 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "DSP SE Idma check ready fail!(%d)\r\n",j);
727 return FALSE;
728 }
729
730 ////////////////////////////////////////////////////////////////////////////////
731 /// @brief \b Function \b Name: HAL_AUDSP_SetDspCodeTypeLoaded()
732 /// @brief \b Function \b Description: This function is used to set the DSP code type.
733 /// @param <IN> \b NONE :
734 /// @param <OUT> \b NONE :
735 /// @param <RET> \b MS_U8: DSP code type.
736 /// @param <GLOBAL> \b NONE :
737 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_SetDspCodeTypeLoaded(MS_U8 u8Type)738 void HAL_AUDSP_SetDspCodeTypeLoaded(MS_U8 u8Type)
739 {
740 g_u8DspCodeTypeLoaded=u8Type;
741 }
742
743 ////////////////////////////////////////////////////////////////////////////////
744 /// @brief \b Function \b Name: HAL_AUDSP_GetDspCodeTypeLoaded()
745 /// @brief \b Function \b Description: This function is used to get the MAD base address.
746 /// @param <IN> \b NONE :
747 /// @param <OUT> \b NONE :
748 /// @param <RET> \b MS_U8: DSP code type.
749 /// @param <GLOBAL> \b NONE :
750 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_GetDspCodeTypeLoaded(void)751 MS_U8 HAL_AUDSP_GetDspCodeTypeLoaded(void)
752 {
753 return g_u8DspCodeTypeLoaded;
754 }
755
HAL_AUDSP_SetDspLoadCodeInfo(AUDIO_ALG_INFO * pau_info,MS_U8 DSP_select)756 void HAL_AUDSP_SetDspLoadCodeInfo(AUDIO_ALG_INFO *pau_info, MS_U8 DSP_select)
757 {
758 g_loadcodeinfo.pau_info = pau_info;
759 g_loadcodeinfo.DSP_select= DSP_select;
760 }
761
762 ////////////////////////////////////////////////////////////////////////////////
763 /// @brief \b Function \b Name: HAL_AUDSP_GetDspCodeTypeLoaded()
764 /// @brief \b Function \b Description: This function is used to get the MAD base address.
765 /// @param <IN> \b NONE :
766 /// @param <OUT> \b NONE :
767 /// @param <RET> \b MS_U8: DSP code type.
768 /// @param <GLOBAL> \b NONE :
769 ////////////////////////////////////////////////////////////////////////////////
HAL_AUDSP_GetDspLoadCodeInfo(void)770 LOAD_CODE_INFO* HAL_AUDSP_GetDspLoadCodeInfo(void)
771 {
772 return &g_loadcodeinfo;
773 }
774