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 ///
97 /// file drvNJPD.c
98 /// @brief NJPD Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102
103 //-------------------------------------------------------------------------------------------------
104 // Include Files
105 //-------------------------------------------------------------------------------------------------
106 // Common Definition
107 #ifdef MSOS_TYPE_LINUX_KERNEL
108 #include <linux/string.h>
109 #else
110 #include <string.h>
111 #endif
112
113 #include "MsCommon.h"
114 #include "MsVersion.h"
115 #include "MsOS.h"
116 #include "halCHIP.h"
117 // Internal Definition
118 //#include "regCHIP.h"
119 #include "njpeg_def.h"
120 #include "osalNJPD.h"
121 #include "drvNJPD.h"
122 #include "regNJPD.h"
123 #include "halNJPD.h"
124
125 #if (defined CONFIG_MLOG)
126 #include "ULog.h"
127 #endif
128
129 //-------------------------------------------------------------------------------------------------
130 // Driver Compiler Options
131 //-------------------------------------------------------------------------------------------------
132
133 //-------------------------------------------------------------------------------------------------
134 // Local Defines
135 //-------------------------------------------------------------------------------------------------
136 //NJPD driver debug macro
137 #if (defined CONFIG_MLOG)
138 #define NJPD_DEBUG_DRV_MSG(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_MSG) ULOGI("NJPD", format, ##args);}while(0)
139 #define NJPD_DEBUG_DRV_ERR(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_ERR) ULOGE("NJPD", format, ##args);}while(0)
140
141 #else
142
143 #ifndef ANDROID
144 #define NJPD_DEBUG_DRV_MSG(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_MSG) printf(format, ##args);}while(0)
145 #define NJPD_DEBUG_DRV_ERR(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_ERR) printf(format, ##args);}while(0)
146 #else
147 #define LOG_TAG "DRV_JPD"
148 #include <cutils/log.h>
149 #ifndef LOGD
150 #define NJPD_DEBUG_DRV_MSG(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_MSG) ALOGI(format, ##args);}while(0)
151 #define NJPD_DEBUG_DRV_ERR(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_ERR) ALOGE(format, ##args);}while(0)
152 #else
153 #define NJPD_DEBUG_DRV_MSG(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_MSG) LOGI(format, ##args);}while(0)
154 #define NJPD_DEBUG_DRV_ERR(format, args...) do{if(u8NJPD_DrvDbgLevel & E_NJPD_DEBUG_DRV_ERR) LOGE(format, ##args);}while(0)
155 #endif
156
157 #endif
158 #endif
159
160 #ifndef UNUSED
161 #define UNUSED(x) ((x)=(x))
162 #endif
163
164 #define ENABLE_FF00FFD_TO_FFFFFFD FALSE
165
166 #if ENABLE_FF00FFD_TO_FFFFFFD
167 #include "../wdt/drvWDT.h"
168 #endif
169
170 #define HVD_FW_MEM_OFFSET 0x100000UL // 1M
171 //-------------------------------------------------------------------------------------------------
172 // Local Structurs
173 //-------------------------------------------------------------------------------------------------
174
175
176 //-------------------------------------------------------------------------------------------------
177 // Global Variables
178 //-------------------------------------------------------------------------------------------------
179 MS_BOOL gbEnableTurboFWMode = FALSE;
180 #ifdef MSOS_TYPE_LINUX_KERNEL
181 static MS_BOOL gbCallbackFlag = FALSE;
182 #endif
183 //-------------------------------------------------------------------------------------------------
184 // Local Variables
185 //-------------------------------------------------------------------------------------------------
186 static MSIF_Version _drv_jpd_version = {
187 .DDI = { NJPD_DRV_VERSION },
188 };
189
190 /* capability */
191 static NJPD_Cap _stNJPD_Cap = {
192 TRUE, //support baseline
193 TRUE, //support progressive
194 TRUE //support MJPEG
195 };
196
197 static NJPD_Status _stNJPD_Status = {
198 0, //Current MRC address
199 0, //Current decoded Vidx
200 0, //Current decoded Row
201 0, //Current decoded Col
202 FALSE, //busy or not
203 FALSE //Isr is enabled or not
204 };
205
206 static MS_U8 u8NJPD_DrvDbgLevel = E_NJPD_DEBUG_DRV_NONE;
207
208
209 static NJPD_IsrFuncCb _pNJPDIsrCb = NULL;
210
211 static MS_U32 u32TablePhyAddr[E_NJPD_NJPD_TOTAL];
212 static MS_BOOL bIs3HuffTbl[E_NJPD_NJPD_TOTAL];
213 static MS_U8 u8DcLumaCnt[E_NJPD_NJPD_TOTAL];
214 static MS_U8 u8DcChromaCnt[E_NJPD_NJPD_TOTAL];
215 static MS_U8 u8DcChroma2Cnt[E_NJPD_NJPD_TOTAL];
216 static MS_U8 u8AcLumaCnt[E_NJPD_NJPD_TOTAL];
217 static MS_U8 u8AcChromaCnt[E_NJPD_NJPD_TOTAL];
218 static MS_U8 u8AcChroma2Cnt[E_NJPD_NJPD_TOTAL];
219 static JPD_Number eNJPDNum = E_NJPD_NJPD1;
220
221
222 static MS_PHY u32MRC0_Start[E_NJPD_NJPD_TOTAL];
223 static MS_PHY u32MRC0_End[E_NJPD_NJPD_TOTAL];
224 static MS_PHY u32MRC1_Start[E_NJPD_NJPD_TOTAL];
225 static MS_PHY u32MRC1_End[E_NJPD_NJPD_TOTAL];
226 static MS_PHY u32READ_Start[E_NJPD_NJPD_TOTAL];
227
228
229 #if 1
230 // This is for zigzag inverse for njpd
231 static const MS_U8 _u8Jpeg_zigzag_order[64] =
232 {
233 0, 2, 3, 9, 10, 20, 21, 35,
234 1, 4, 8, 11, 19, 22, 34, 36,
235 5, 7, 12, 18, 23, 33, 37, 48,
236 6, 13, 17, 24, 32, 38, 47, 49,
237 14, 16, 25, 31, 39, 46, 50, 57,
238 15, 26, 30, 40, 45, 51, 56, 58,
239 27, 29, 41, 44, 52, 55, 59, 62,
240 28, 42, 43, 53, 54, 60, 61, 63
241 };
242
243 #else
244 static const MS_U8 _u8Jpeg_zigzag_order[64] =
245 {
246 0, 1, 5, 6, 14, 15, 27, 28,
247 2, 4, 7, 13, 16, 26, 29, 42,
248 3, 8, 12, 17, 25, 30, 41, 43,
249 9, 11, 18, 24, 31, 40, 44, 53,
250 10, 19, 23, 32, 39, 45, 52, 54,
251 20, 22, 33, 38, 46, 51, 55, 60,
252 21, 34, 37, 47, 50, 56, 59, 61,
253 35, 36, 48, 49, 57, 58, 62, 63
254 };
255 #endif
256
257 #if 0
258 static const MS_U16 g16IQ_TBL[128]=
259 {
260 0x0010,0x000b,0x000a,0x0010,0x0018,0x0028,0x0033,0x003d,
261 0x000c,0x000c,0x000e,0x0013,0x001a,0x003a,0x003c,0x0037,
262 0x000e,0x000d,0x0010,0x0018,0x0028,0x0039,0x0045,0x0038,
263 0x000e,0x0011,0x0016,0x001d,0x0033,0x0057,0x0050,0x003e,
264 0x0012,0x0016,0x0025,0x0038,0x0044,0x006d,0x0067,0x004d,
265 0x0018,0x0023,0x0037,0x0040,0x0051,0x0068,0x0071,0x005c,
266 0x0031,0x0040,0x004e,0x0057,0x0067,0x0079,0x0078,0x0065,
267 0x0048,0x005c,0x005f,0x0062,0x0070,0x0064,0x0067,0x0063,
268
269 0x0011,0x0012,0x0018,0x002f,0x0063,0x0063,0x0063,0x0063,
270 0x0012,0x0015,0x001a,0x0042,0x0063,0x0063,0x0063,0x0063,
271 0x0018,0x001a,0x0038,0x0063,0x0063,0x0063,0x0063,0x0063,
272 0x002f,0x0042,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
273 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
274 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
275 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
276 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063
277 };
278 #endif
279
280 static const MS_U16 g16IQ_TBL_NJPD[128]=
281 {
282 0x0010,0x000c,0x000e,0x000e,0x0012,0x0018,0x0031,0x0048,
283 0x000b,0x000c,0x000d,0x0011,0x0016,0x0023,0x0040,0x005c,
284 0x000a,0x000e,0x0010,0x0016,0x0025,0x0037,0x004e,0x005f,
285 0x0010,0x0013,0x0018,0x001d,0x0038,0x0040,0x0057,0x0062,
286 0x0018,0x001a,0x0028,0x0033,0x0044,0x0051,0x0067,0x0070,
287 0x0028,0x003a,0x0039,0x0057,0x006d,0x0068,0x0079,0x0064,
288 0x0033,0x003c,0x0045,0x0050,0x0067,0x0071,0x0078,0x0067,
289 0x003d,0x0037,0x0038,0x003e,0x004d,0x005c,0x0065,0x0063,
290
291 0x0011,0x0012,0x0018,0x002f,0x0063,0x0063,0x0063,0x0063,
292 0x0012,0x0015,0x001a,0x0042,0x0063,0x0063,0x0063,0x0063,
293 0x0018,0x001a,0x0038,0x0063,0x0063,0x0063,0x0063,0x0063,
294 0x002f,0x0042,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
295 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
296 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
297 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,
298 0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063,0x0063
299
300 };
301
302
303 //-------------------------------------------------------------------------------------------------
304 // Debug Functions
305 //-------------------------------------------------------------------------------------------------
306
307
308 //-------------------------------------------------------------------------------------------------
309 // Local Functions
310 //-------------------------------------------------------------------------------------------------
_NJPD_ISRHandler(MS_U32 IsrNum)311 static void _NJPD_ISRHandler(MS_U32 IsrNum)
312 {
313 NJPD_DEBUG_DRV_MSG("_NJPD_ISRHandler: IsrNum = %td\n", (ptrdiff_t)IsrNum);
314 #ifdef MSOS_TYPE_LINUX_KERNEL
315 gbCallbackFlag = TRUE;
316 #else
317 if(_pNJPDIsrCb)
318 {
319 _pNJPDIsrCb();
320 }
321 #endif
322 }
323
_NJPD_PrintMem(MS_VIRT u32Addr,MS_U32 u32Size)324 void _NJPD_PrintMem(MS_VIRT u32Addr, MS_U32 u32Size)
325 {
326 MS_U32 u32i;
327 NJPD_DEBUG_DRV_MSG("===========================================================\n");
328 NJPD_DEBUG_DRV_MSG("print memory addr=0x%tx, size=0x%tx\n", (ptrdiff_t)u32Addr, (ptrdiff_t)u32Size);
329 NJPD_DEBUG_DRV_MSG("===========================================================\n");
330 #if 1
331 for(u32i=0; u32i<u32Size/8+((u32Size%8)? 1:0); u32i++)
332 {
333 NJPD_DEBUG_DRV_MSG("%02x %02x %02x %02x %02x %02x %02x %02x \n",
334 *((MS_U8*)(u32Addr+u32i*8)), *((MS_U8*)(u32Addr+u32i*8+1)), *((MS_U8*)(u32Addr+u32i*8+2)), *((MS_U8*)(u32Addr+u32i*8+3)),
335 *((MS_U8*)(u32Addr+u32i*8+4)), *((MS_U8*)(u32Addr+u32i*8+5)), *((MS_U8*)(u32Addr+u32i*8+6)), *((MS_U8*)(u32Addr+u32i*8+7))
336 );
337 }
338 #else
339 for(u32i=0; u32i<u32Size/16+((u32Size%16)? 1:0); u32i++)
340 {
341 NJPD_DEBUG_DRV_MSG("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x \n",
342 *((MS_U8*)(u32Addr+u32i*16)), *((MS_U8*)(u32Addr+u32i*16+1)), *((MS_U8*)(u32Addr+u32i*16+2)), *((MS_U8*)(u32Addr+u32i*16+3)),
343 *((MS_U8*)(u32Addr+u32i*16+4)), *((MS_U8*)(u32Addr+u32i*16+5)), *((MS_U8*)(u32Addr+u32i*16+6)), *((MS_U8*)(u32Addr+u32i*16+7)),
344 *((MS_U8*)(u32Addr+u32i*16+8)), *((MS_U8*)(u32Addr+u32i*16+9)), *((MS_U8*)(u32Addr+u32i*16+10)), *((MS_U8*)(u32Addr+u32i*16+11)),
345 *((MS_U8*)(u32Addr+u32i*16+12)), *((MS_U8*)(u32Addr+u32i*16+13)), *((MS_U8*)(u32Addr+u32i*16+14)), *((MS_U8*)(u32Addr+u32i*16+15))
346 );
347 }
348 #endif
349 NJPD_DEBUG_DRV_MSG("===========================================================\n");
350 }
351
352 //-------------------------------------------------------------------------------------------------
353 // Global Functions
354 //-------------------------------------------------------------------------------------------------
355
356 /********************************************************************/
357 ///Reset NJPD -- Reset must be called before trigger NJPD
358 ///@param NULL
359 ///@return none
360 /********************************************************************/
MDrv_NJPD_Rst(void)361 void MDrv_NJPD_Rst(void)
362 {
363 HAL_NJPD_Rst();
364 }
365
366
MDrv_NJPD_SetReadBuffer0(MS_PHY u32BufAddr,MS_U32 u32BufSize)367 void MDrv_NJPD_SetReadBuffer0(MS_PHY u32BufAddr, MS_U32 u32BufSize)
368 {
369 MS_U8 u8MiuSel = 0;
370 _phy_to_miu_offset(u8MiuSel, u32BufAddr, u32BufAddr);
371 HAL_NJPD_SetMIU(u8MiuSel);
372
373 u32MRC0_Start[eNJPDNum] = u32BufAddr;
374
375 // set start address of read buffer
376 HAL_NJPD_SetMRCBuf0_StartLow(u32BufAddr & 0xffffUL);
377 HAL_NJPD_SetMRCBuf0_StartHigh(u32BufAddr >> 16);
378
379 u32MRC0_End[eNJPDNum] = (( u32BufAddr + u32BufSize ) - 1);
380 // set end address of read buffer
381 HAL_NJPD_SetMRCBuf0_EndLow((( u32BufAddr + u32BufSize ) - 1)& 0xffffUL);
382 HAL_NJPD_SetMRCBuf0_EndHigh((( u32BufAddr + u32BufSize ) - 1) >> 16);
383
384 }
385
MDrv_NJPD_SetReadBuffer1(MS_PHY u32BufAddr,MS_U32 u32BufSize)386 void MDrv_NJPD_SetReadBuffer1(MS_PHY u32BufAddr, MS_U32 u32BufSize)
387 {
388 MS_U8 u8MiuSel = 0;
389 _phy_to_miu_offset(u8MiuSel, u32BufAddr, u32BufAddr);
390 HAL_NJPD_SetMIU(u8MiuSel);
391
392 u32MRC1_Start[eNJPDNum] = u32BufAddr;
393
394 // set start address of read buffer
395 HAL_NJPD_SetMRCBuf1_StartLow(u32BufAddr & 0xffffUL);
396 HAL_NJPD_SetMRCBuf1_StartHigh(u32BufAddr >> 16);
397
398 u32MRC1_End[eNJPDNum] = (( u32BufAddr + u32BufSize ) - 1);
399 // set end address of read buffer
400 HAL_NJPD_SetMRCBuf1_EndLow((( u32BufAddr + u32BufSize ) - 1)& 0xffffUL);
401 HAL_NJPD_SetMRCBuf1_EndHigh((( u32BufAddr + u32BufSize ) - 1) >> 16);
402
403 }
404
405
MDrv_NJPD_SetMRCStartAddr(MS_PHY u32ByteOffset)406 void MDrv_NJPD_SetMRCStartAddr(MS_PHY u32ByteOffset)
407 {
408 MS_U8 u8MiuSel = 0;
409 _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
410 UNUSED(u8MiuSel);
411
412 u32READ_Start[eNJPDNum] =u32ByteOffset;
413
414 HAL_NJPD_SetMRCStart_Low((u32ByteOffset & 0xffffUL));
415 HAL_NJPD_SetMRCStart_High((u32ByteOffset >> 16));
416 }
417
MDrv_NJPD_GetMWCStartAddr(void)418 MS_U32 MDrv_NJPD_GetMWCStartAddr(void)
419 {
420 MS_U32 u32Addr;
421 u32Addr = (((MS_U32)HAL_NJPD_GetMWCBuf_StartHigh())<<16 | HAL_NJPD_GetMWCBuf_StartLow());
422 return u32Addr;
423 }
424
MDrv_NJPD_GetWritePtrAddr(void)425 MS_U32 MDrv_NJPD_GetWritePtrAddr(void)
426 {
427 MS_U32 u32Addr;
428 u32Addr = (((MS_U32)HAL_NJPD_GetMWCBuf_WritePtrHigh())<<16 | HAL_NJPD_GetMWCBuf_WritePtrLow());
429 return u32Addr;
430 }
431
432 #if SUPPORT_HIGH_LOW_REVERSE
MDrv_NJPD_SetReadBuffer_Patch(MS_PHY u32BufAddr,MS_U32 u32BufSize,MS_PHY u32BufStartAddr)433 MS_BOOL MDrv_NJPD_SetReadBuffer_Patch(MS_PHY u32BufAddr, MS_U32 u32BufSize, MS_PHY u32BufStartAddr)
434 {
435 MS_BOOL bHighLowReverse = FALSE;
436 MS_U8 u8i;
437 MS_U8 u8MiuSel = 0;
438 _phy_to_miu_offset(u8MiuSel, u32BufAddr, u32BufAddr);
439 HAL_NJPD_SetMIU(u8MiuSel);
440 _phy_to_miu_offset(u8MiuSel, u32BufStartAddr, u32BufStartAddr);
441
442 u32READ_Start[eNJPDNum] =u32BufStartAddr;
443
444 MDrv_NJPD_SetMRCStartAddr(u32READ_Start[eNJPDNum]);
445 if(u32BufStartAddr >= u32BufAddr+u32BufSize/2)
446 {
447 bHighLowReverse = TRUE;
448 u32MRC1_Start[eNJPDNum] = u32BufAddr;
449 u32MRC1_End[eNJPDNum] = (( u32BufAddr + u32BufSize/2 ) - 1);
450 u32MRC0_Start[eNJPDNum] = u32BufAddr + u32BufSize/2;
451 u32MRC0_End[eNJPDNum] = (( u32BufAddr + u32BufSize ) - 1);
452 for(u8i=0; u8i<16; u8i++)
453 {
454 if((( ( u32MRC1_End[eNJPDNum]/16 - u32READ_Start[eNJPDNum]/16 ) + 1 ) % 16 == 1) ||
455 (( ( u32MRC1_End[eNJPDNum]/16 - u32MRC1_Start[eNJPDNum] /16 ) + 1 ) % 16 == 1) ||
456 (( ( u32MRC0_End[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum] /16 ) + 1 ) % 16 == 1) )
457 {
458 u32MRC1_End[eNJPDNum] += 16;
459 u32MRC0_Start[eNJPDNum]+=16;
460 }
461 else
462 {
463 break;
464 }
465 }
466 }
467 else
468 {
469 u32MRC0_Start[eNJPDNum] = u32BufAddr;
470 u32MRC0_End[eNJPDNum] = (( u32BufAddr + u32BufSize/2 ) - 1);
471 u32MRC1_Start[eNJPDNum] = u32BufAddr + u32BufSize/2;
472 u32MRC1_End[eNJPDNum] = (( u32BufAddr + u32BufSize ) - 1);
473 for(u8i=0; u8i<16; u8i++)
474 {
475 if((( ( u32MRC0_End[eNJPDNum]/16 - u32READ_Start[eNJPDNum]/16 ) + 1 ) % 16 == 1) ||
476 (( ( u32MRC0_End[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum] /16 ) + 1 ) % 16 == 1) ||
477 (( ( u32MRC1_End[eNJPDNum]/16 - u32MRC1_Start[eNJPDNum] /16 ) + 1 ) % 16 == 1) )
478 {
479 u32MRC0_End[eNJPDNum] += 16;
480 u32MRC1_Start[eNJPDNum]+=16;
481 }
482 else
483 {
484 break;
485 }
486 }
487 }
488 HAL_NJPD_SetMRCBuf0_StartLow(u32MRC0_Start[eNJPDNum] & 0xffffUL);
489 HAL_NJPD_SetMRCBuf0_StartHigh(u32MRC0_Start[eNJPDNum] >> 16);
490 HAL_NJPD_SetMRCBuf0_EndLow(u32MRC0_End[eNJPDNum]& 0xffffUL);
491 HAL_NJPD_SetMRCBuf0_EndHigh(u32MRC0_End[eNJPDNum] >> 16);
492 HAL_NJPD_SetMRCBuf1_StartLow(u32MRC1_Start[eNJPDNum] & 0xffffUL);
493 HAL_NJPD_SetMRCBuf1_StartHigh(u32MRC1_Start[eNJPDNum] >> 16);
494 HAL_NJPD_SetMRCBuf1_EndLow(u32MRC1_End[eNJPDNum] & 0xffffUL);
495 HAL_NJPD_SetMRCBuf1_EndHigh(u32MRC1_End[eNJPDNum] >> 16);
496
497 NJPD_DEBUG_DRV_MSG("[offset: MRC0: MRC1]=[%ld, %ld, %ld], u8i=%d\n",
498 (u32READ_Start[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum]/16 +1)%16,
499 (u32MRC0_End[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum]/16 +1)%16,
500 (u32MRC1_End/16 - u32MRC1_Start/16 +1)%16, u8i
501 );
502 return bHighLowReverse;
503 }
504 #else
MDrv_NJPD_SetReadBuffer_New(MS_PHY u32BufAddr,MS_U32 u32BufSize,MS_PHY u32BufStartAddr)505 MS_BOOL MDrv_NJPD_SetReadBuffer_New(MS_PHY u32BufAddr, MS_U32 u32BufSize, MS_PHY u32BufStartAddr)
506 {
507 MS_BOOL bDifferentHL = FALSE;
508
509 MS_U8 u8MiuSel = 0;
510 _phy_to_miu_offset(u8MiuSel, u32BufAddr, u32BufAddr);
511 HAL_NJPD_SetMIU(u8MiuSel);
512 _phy_to_miu_offset(u8MiuSel, u32BufStartAddr, u32BufStartAddr);
513
514 u32READ_Start[eNJPDNum] =u32BufStartAddr;
515
516
517 u32MRC0_Start[eNJPDNum] = u32BufAddr;
518 u32MRC0_End[eNJPDNum] = (( u32BufAddr + u32BufSize/2 ) - 1);
519 u32MRC1_Start[eNJPDNum] = u32BufAddr + u32BufSize/2;
520 u32MRC1_End[eNJPDNum] = (( u32BufAddr + u32BufSize ) - 1);
521 if(u32READ_Start[eNJPDNum] > u32MRC0_End[eNJPDNum])
522 {
523 u32MRC0_End[eNJPDNum] = u32READ_Start[eNJPDNum] | 0xF;
524 u32MRC1_Start[eNJPDNum] = u32MRC0_End[eNJPDNum] + 1;
525 bDifferentHL = TRUE;
526 }
527
528 MDrv_NJPD_SetMRCStartAddr(u32READ_Start[eNJPDNum]);
529 if(MDrv_NJPD_IsNeedToPatch(E_NJPD_EAGLE_SW_PATCH))
530 {
531 MS_U8 u8i;
532 for(u8i=0; u8i<16; u8i++)
533 {
534 if((( ( u32MRC0_End[eNJPDNum]/16 - u32READ_Start[eNJPDNum]/16 ) + 1 ) % 16 == 1) ||
535 (( ( u32MRC0_End[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum] /16 ) + 1 ) % 16 == 1) ||
536 (( ( u32MRC1_End[eNJPDNum]/16 - u32MRC1_Start[eNJPDNum] /16 ) + 1 ) % 16 == 1) )
537 {
538 u32MRC0_End[eNJPDNum] += 16;
539 u32MRC1_Start[eNJPDNum]+=16;
540 bDifferentHL = TRUE;
541 }
542 else
543 {
544 break;
545 }
546 }
547 }
548
549 HAL_NJPD_SetMRCBuf0_StartLow(u32MRC0_Start[eNJPDNum] & 0xffffUL);
550 HAL_NJPD_SetMRCBuf0_StartHigh(u32MRC0_Start[eNJPDNum] >> 16);
551 HAL_NJPD_SetMRCBuf0_EndLow(u32MRC0_End[eNJPDNum] & 0xffffUL);
552 HAL_NJPD_SetMRCBuf0_EndHigh(u32MRC0_End[eNJPDNum] >> 16);
553 HAL_NJPD_SetMRCBuf1_StartLow(u32MRC1_Start[eNJPDNum] & 0xffffUL);
554 HAL_NJPD_SetMRCBuf1_StartHigh(u32MRC1_Start[eNJPDNum] >> 16);
555 HAL_NJPD_SetMRCBuf1_EndLow(u32MRC1_End[eNJPDNum] & 0xffffUL);
556 HAL_NJPD_SetMRCBuf1_EndHigh(u32MRC1_End[eNJPDNum] >> 16);
557
558 NJPD_DEBUG_DRV_MSG("MRC0 start:%tx, MRC0 end:%tx, Offset:%tx\n",
559 (ptrdiff_t)u32MRC0_Start[eNJPDNum], (ptrdiff_t)u32MRC0_End[eNJPDNum] , (ptrdiff_t)u32READ_Start[eNJPDNum]);
560 NJPD_DEBUG_DRV_MSG("[offset: MRC0: MRC1]=[%td, %td, %td]\n",
561 (ptrdiff_t)((u32READ_Start[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum]/16 +1)%16),
562 (ptrdiff_t)((u32MRC0_End[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum]/16 +1)%16),
563 (ptrdiff_t)((u32MRC1_End[eNJPDNum]/16 - u32MRC1_Start[eNJPDNum]/16 +1)%16)
564 );
565
566
567 return bDifferentHL;
568 }
569 #endif
570 /******************************************************************************/
571 ///Set output frame buffer address for NJPD writing NJPEG uncompressed data
572 ///@param u32BufAddr \b IN Start address for NJPD reading in MRC buffer
573 ///@return none
574 /******************************************************************************/
MDrv_NJPD_SetOutputFrameBuffer(MS_PHY u32BufAddr,MS_U16 u16LineNum)575 void MDrv_NJPD_SetOutputFrameBuffer(MS_PHY u32BufAddr, MS_U16 u16LineNum)
576 {
577
578 MS_U8 u8MiuSel = 0;
579 _phy_to_miu_offset(u8MiuSel, u32BufAddr, u32BufAddr);
580 UNUSED(u8MiuSel);
581
582 HAL_NJPD_SetMWCBuf_StartLow(u32BufAddr & 0xffffUL);
583 HAL_NJPD_SetMWCBuf_StartHigh(u32BufAddr >> 16);
584
585 UNUSED(u16LineNum);
586 }
587
588 /******************************************************************************/
589 ///Setting the address of NJPD MRC, MWC buffer
590 ///@param NJPD_BufCfg \b IN
591 /// structure {
592 /// MS_U32 u32ThumbnailBufAddr; \b IN Thumbnail buffer address
593 /// MS_U32 u32ThumbnailBufSize; \b IN Thumbnail buffer size
594 /// MS_U32 u32ThumbnailBufOffset; \b IN Access byte address offset in
595 /// Thumbnail buffer relative to
596 /// Thumbnail start address
597 /// MS_U32 u32MRCBufAddr; \b IN MRC buffer address
598 /// MS_U32 u32MRCBufSize; \b IN MRC buffer size
599 /// MS_U32 u32MRCBufOffset; \b IN Access byte address offset in MRC buffer
600 /// relative to MRC start address
601 /// MS_U32 u32MWCBufAddr; \b IN MWC buffer address
602 /// MS_BOOL bProgressive;
603 /// MS_BOOL bThumbnailAccessMode;
604 /// };
605 ///@return none
606 /******************************************************************************/
607 #if SUPPORT_HIGH_LOW_REVERSE
MDrv_NJPD_InitBuf(NJPD_BufCfg in,MS_BOOL bMJPEG)608 MS_BOOL MDrv_NJPD_InitBuf(NJPD_BufCfg in, MS_BOOL bMJPEG)
609 {
610 MS_BOOL bHighLowReverse = FALSE;
611 if(in.bThumbnailAccessMode)
612 {
613 if(MDrv_NJPD_IsNeedToPatch(E_NJPD_EAGLE_SW_PATCH))
614 {
615 bHighLowReverse = MDrv_NJPD_SetReadBuffer_Patch(in.u32ThumbnailBufAddr, in.u32ThumbnailBufSize, in.u32ThumbnailBufAddr + in.u32ThumbnailBufOffset);
616 }
617 else
618 {
619 // Set MRC start access byte address
620 MDrv_NJPD_SetMRCStartAddr(in.u32ThumbnailBufAddr + in.u32ThumbnailBufOffset);
621 // Set MRC buffer for NJPD
622 if(in.u32ThumbnailBufOffset < in.u32ThumbnailBufSize/2)
623 {
624 MDrv_NJPD_SetReadBuffer0(in.u32ThumbnailBufAddr, in.u32ThumbnailBufSize/2);
625 MDrv_NJPD_SetReadBuffer1(in.u32ThumbnailBufAddr+in.u32ThumbnailBufSize/2, in.u32ThumbnailBufSize/2);
626 bHighLowReverse = FALSE;
627 }
628 else
629 {
630 NJPD_DEBUG_DRV_MSG("Reverse the MRC High/Low buffer\n");
631 MDrv_NJPD_SetReadBuffer1(in.u32ThumbnailBufAddr, in.u32ThumbnailBufSize/2);
632 MDrv_NJPD_SetReadBuffer0(in.u32ThumbnailBufAddr+in.u32ThumbnailBufSize/2, in.u32ThumbnailBufSize/2);
633 bHighLowReverse = TRUE;
634 }
635 }
636 }
637 else
638 {
639 if(in.bProgressive)
640 {
641 if(MDrv_NJPD_IsNeedToPatch(E_NJPD_EAGLE_SW_PATCH))
642 {
643 bHighLowReverse = MDrv_NJPD_SetReadBuffer_Patch(in.u32MRCBufAddr, in.u32MRCBufSize, in.u32MRCBufAddr);
644 }
645 else
646 {
647 // Set MRC buffer for NJPD
648 MDrv_NJPD_SetReadBuffer0(in.u32MRCBufAddr, in.u32MRCBufSize/2);
649 MDrv_NJPD_SetReadBuffer1(in.u32MRCBufAddr+in.u32MRCBufSize/2, in.u32MRCBufSize/2);
650 // Set MRC start access byte address
651 MDrv_NJPD_SetMRCStartAddr(in.u32MRCBufAddr);
652 }
653 }
654 else
655 {
656 NJPD_DEBUG_DRV_MSG("%lx, %lx, %lx", in.u32MRCBufAddr, in.u32MRCBufAddr + in.u32MRCBufSize, in.u32MRCBufAddr + in.u32MRCBufOffset);
657 if(MDrv_NJPD_IsNeedToPatch(E_NJPD_EAGLE_SW_PATCH))
658 {
659 bHighLowReverse = MDrv_NJPD_SetReadBuffer_Patch(in.u32MRCBufAddr, in.u32MRCBufSize, in.u32MRCBufAddr + in.u32MRCBufOffset);
660 }
661 else
662 {
663 // Set MRC start access byte address
664 NJPD_DEBUG_DRV_MSG("in.u32MRCBufOffset=0x%lx\n", in.u32MRCBufOffset);
665 MDrv_NJPD_SetMRCStartAddr(in.u32MRCBufAddr + in.u32MRCBufOffset);
666 // Set MRC buffer for NJPD
667 if(in.u32MRCBufOffset < in.u32MRCBufSize/2)
668 {
669 MDrv_NJPD_SetReadBuffer0(in.u32MRCBufAddr, in.u32MRCBufSize/2);
670 MDrv_NJPD_SetReadBuffer1(in.u32MRCBufAddr+in.u32MRCBufSize/2, in.u32MRCBufSize/2);
671 bHighLowReverse = FALSE;
672 }
673 else
674 {
675 NJPD_DEBUG_DRV_MSG("Reverse the MRC High/Low buffer\n");
676 MDrv_NJPD_SetReadBuffer1(in.u32MRCBufAddr, in.u32MRCBufSize/2);
677 MDrv_NJPD_SetReadBuffer0(in.u32MRCBufAddr+in.u32MRCBufSize/2, in.u32MRCBufSize/2);
678 bHighLowReverse = TRUE;
679 }
680 }
681 }
682 }
683 MDrv_NJPD_SetOutputFrameBuffer(in.u32MWCBufAddr, in.u16MWCBufLineNum);
684
685 // Set the end of MWC buffer for NJPD to save the table
686 if(bMJPEG==FALSE)
687 {
688 u32TablePhyAddr[eNJPDNum] = in.u32MWCBufAddr;
689 }
690 else
691 {
692 u32TablePhyAddr[eNJPDNum] = in.u32ThumbnailBufAddr;
693 }
694 NJPD_DEBUG_DRV_MSG("u32TablePhyAddr[eNJPDNum]=0x%x, VA=0x%x\n", u32TablePhyAddr[eNJPDNum], MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]));
695
696 return bHighLowReverse;
697 }
698 #else
MDrv_NJPD_InitBuf(NJPD_BufCfg in,MS_BOOL bMJPEG)699 MS_BOOL MDrv_NJPD_InitBuf(NJPD_BufCfg in, MS_BOOL bMJPEG)
700 {
701 MS_BOOL bDifferentHL = FALSE;
702 if(in.bThumbnailAccessMode)
703 {
704 bDifferentHL = MDrv_NJPD_SetReadBuffer_New(in.u32ThumbnailBufAddr, in.u32ThumbnailBufSize, in.u32ThumbnailBufAddr + in.u32ThumbnailBufOffset);
705 }
706 else
707 {
708 if(in.bProgressive)
709 {
710 bDifferentHL = MDrv_NJPD_SetReadBuffer_New(in.u32MRCBufAddr, in.u32MRCBufSize, in.u32MRCBufAddr);
711 }
712 else
713 {
714 NJPD_DEBUG_DRV_MSG("MRC start:%tx, MRC end:%tx, Offset:%tx\n", (ptrdiff_t)in.u32MRCBufAddr, (ptrdiff_t)(in.u32MRCBufAddr + in.u32MRCBufSize), (ptrdiff_t)(in.u32MRCBufAddr + in.u32MRCBufOffset));
715 bDifferentHL = MDrv_NJPD_SetReadBuffer_New(in.u32MRCBufAddr, in.u32MRCBufSize, in.u32MRCBufAddr + in.u32MRCBufOffset);
716 }
717 }
718 MDrv_NJPD_SetOutputFrameBuffer(in.u32MWCBufAddr, in.u16MWCBufLineNum);
719
720 // Set the end of MWC buffer for NJPD to save the table
721 if(bMJPEG==FALSE)
722 {
723 u32TablePhyAddr[eNJPDNum] = in.u32MWCBufAddr;
724 }
725 else
726 {
727 u32TablePhyAddr[eNJPDNum] = in.u32ThumbnailBufAddr;
728 }
729 NJPD_DEBUG_DRV_MSG("u32TablePhyAddr[eNJPDNum]=0x%tx, VA=0x%tx\n", (ptrdiff_t)u32TablePhyAddr[eNJPDNum], (ptrdiff_t)MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]));
730 return bDifferentHL;
731 }
732 #endif
733
734 /******************************************************************************/
735 ///Set width and height of picture
736 ///@param u16Width \b IN picture width
737 ///@param u16Height \b IN picture height
738 ///@return none
739 /******************************************************************************/
MDrv_NJPD_SetPicDimension(MS_U16 u16PicWidth,MS_U16 u16PicHeight)740 void MDrv_NJPD_SetPicDimension(MS_U16 u16PicWidth, MS_U16 u16PicHeight)
741 {
742 HAL_NJPD_SetPic_H(( u16PicWidth >> 3 ) );
743 HAL_NJPD_SetPic_V(( u16PicHeight >> 3 ) );
744 }
745
746 /******************************************************************************/
747 ///Get NJPD Event Flag
748 ///@return EventFlag
749 /******************************************************************************/
MDrv_NJPD_GetEventFlag(void)750 MS_U16 MDrv_NJPD_GetEventFlag(void)
751 {
752 return HAL_NJPD_GetEventFlag();
753 }
754
755 /******************************************************************************/
756 ///Set NJPD Event Flag
757 ///@param u16Value \n IN EventFlag value
758 ///@return none
759 /******************************************************************************/
MDrv_NJPD_SetEventFlag(MS_U16 u16Value)760 void MDrv_NJPD_SetEventFlag(MS_U16 u16Value)
761 {
762 // clear by write
763 HAL_NJPD_ClearEventFlag(u16Value);
764 }
765
766 /******************************************************************************/
767 ///Set ROI region
768 ///@param start_x \n IN start X position
769 ///@param start_y \n IN start Y position
770 ///@param width \n IN width
771 ///@param height \n IN height
772 ///@return none
773 /******************************************************************************/
MDrv_NJPD_SetROI(MS_U16 start_x,MS_U16 start_y,MS_U16 width,MS_U16 height)774 void MDrv_NJPD_SetROI(MS_U16 start_x, MS_U16 start_y, MS_U16 width, MS_U16 height)
775 {
776 // MS_U16 reg_val;
777
778 // reg_val = HAL_NJPD_Get_S_Config();
779
780 HAL_NJPD_SetROI_H(start_x);
781 HAL_NJPD_SetROI_V(start_y);
782 HAL_NJPD_SetROIWidth(width);
783 HAL_NJPD_SetROIHeight(height);
784 }
785
786 /********************************************************************/
787 ///Power On NJPD
788 ///@param NULL
789 ///@return none
790 /********************************************************************/
MDrv_NJPD_PowerOn(void)791 void MDrv_NJPD_PowerOn(void)
792 {
793 HAL_NJPD_InitRegBase();
794 HAL_NJPD_PowerOn();
795 #if ENABLE_FF00FFD_TO_FFFFFFD
796 MDrv_WDT_Init((WDT_DbgLv)E_WDT_DBGLV_ERR_ONLY);
797 MDrv_TIMER_Count(E_TIMER_1, 1);
798 #endif
799 _stNJPD_Status.bIsBusy = TRUE;
800 }
801
802 /********************************************************************/
803 ///Power Off NJPD
804 ///@param NULL
805 ///@return none
806 /********************************************************************/
MDrv_NJPD_PowerOff(void)807 void MDrv_NJPD_PowerOff(void)
808 {
809 HAL_NJPD_PowerOff();
810 _stNJPD_Status.bIsBusy = FALSE;
811 }
812
813 /********************************************************************/
814 ///Set RSTIntv
815 ///@param u16Value \n IN register RSTIntv
816 ///@return none
817 /********************************************************************/
MDrv_NJPD_SetRSTIntv(MS_U16 u16Value)818 void MDrv_NJPD_SetRSTIntv(MS_U16 u16Value)
819 {
820 HAL_NJPD_SetRSTIntv(u16Value);
821 }
822
823 /********************************************************************/
824 ///Get current vertical line index written to memory
825 ///@return current vertical line index written to memory
826 /********************************************************************/
MDrv_NJPD_GetCurVidx(void)827 MS_U16 MDrv_NJPD_GetCurVidx(void)
828 {
829 NJPD_DEBUG_DRV_ERR("Error!!! Do not support %s() in NJPD!!!!!!!!!!!!!!!!\n", __FUNCTION__);
830 return 0;
831 }
832
833 /********************************************************************/
834 ///Write Grpinf of Table IndirectAccess
835 ///@param in \b IN structure for Grpinf of Table IndirectAccess
836 ///@return none
837 /********************************************************************/
MDrv_NJPD_WriteGrpinf(NJPD_Grpinf in)838 void MDrv_NJPD_WriteGrpinf(NJPD_Grpinf in)
839 {
840 MS_U16 i;
841
842 if (in.DHT)
843 {
844 u8DcLumaCnt[eNJPDNum] = in.u8DcLumaCnt;
845 u8DcChromaCnt[eNJPDNum] = in.u8DcChromaCnt;
846 u8DcChroma2Cnt[eNJPDNum] = in.u8DcChroma2Cnt;
847 u8AcLumaCnt[eNJPDNum] = in.u8AcLumaCnt;
848 u8AcChromaCnt[eNJPDNum] = in.u8AcChromaCnt;
849 u8AcChroma2Cnt[eNJPDNum] = in.u8AcChroma2Cnt;
850 //JPEG_memset((void *)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE)), 0, 0x400);
851 #if ENABLE_NJPD_DEBUG_MSG
852 for(i= 1; i<=16; i++)
853 {
854 NJPD_DEBUG_DRV_MSG("dc luma i=%d, [%02x %04x %02x]\n", i, in.u8DcLumaValid[i], in.u16DcLumaCode[i], in.u8DcLumaSymbol[i]);
855 }
856 for(i= 1; i<=16; i++)
857 {
858 NJPD_DEBUG_DRV_MSG("ac luma i=%d, [%02x %04x %02x]\n", i, in.u8AcLumaValid[i], in.u16AcLumaCode[i], in.u8AcLumaSymbol[i]);
859 }
860 for(i= 1; i<=16; i++)
861 {
862 NJPD_DEBUG_DRV_MSG("dc chroma i=%d, [%02x %04x %02x]\n", i, in.u8DcChromaValid[i], in.u16DcChromaCode[i], in.u8DcChromaSymbol[i]);
863 }
864 for(i= 1; i<=16; i++)
865 {
866 NJPD_DEBUG_DRV_MSG("ac chroma i=%d, [%02x %04x %02x]\n",i , in.u8AcChromaValid[i], in.u16AcChromaCode[i], in.u8AcChromaSymbol[i]);
867 }
868 if(bIs3HuffTbl[eNJPDNum])
869 {
870 for(i= 1; i<=16; i++)
871 {
872 NJPD_DEBUG_DRV_MSG("dc chroma2 i=%d, [%02x %04x %02x]\n", i, in.u8DcChroma2Valid[i], in.u16DcChroma2Code[i], in.u8DcChroma2Symbol[i]);
873 }
874 for(i= 1; i<=16; i++)
875 {
876 NJPD_DEBUG_DRV_MSG("ac chroma2 i=%d, [%02x %04x %02x]\n",i, in.u8AcChroma2Valid[i], in.u16AcChroma2Code[i], in.u8AcChroma2Symbol[i]);
877 }
878 }
879 #else
880 if(MDrv_NJPD_GetVerificationMode()==E_NJPD01_TABLE_READ_WRITE)
881 {
882 for(i= 1; i<=16; i++)
883 {
884 NJPD_DEBUG_DRV_MSG("dc luma i=%d, [%02x %04x %02x]\n", i, in.u8DcLumaValid[i], in.u16DcLumaCode[i], in.u8DcLumaSymbol[i]);
885 }
886 for(i= 1; i<=16; i++)
887 {
888 NJPD_DEBUG_DRV_MSG("ac luma i=%d, [%02x %04x %02x]\n", i, in.u8AcLumaValid[i], in.u16AcLumaCode[i], in.u8AcLumaSymbol[i]);
889 }
890 for(i= 1; i<=16; i++)
891 {
892 NJPD_DEBUG_DRV_MSG("dc chroma i=%d, [%02x %04x %02x]\n", i, in.u8DcChromaValid[i], in.u16DcChromaCode[i], in.u8DcChromaSymbol[i]);
893 }
894 for(i= 1; i<=16; i++)
895 {
896 NJPD_DEBUG_DRV_MSG("ac chroma i=%d, [%02x %04x %02x]\n",i , in.u8AcChromaValid[i], in.u16AcChromaCode[i], in.u8AcChromaSymbol[i]);
897 }
898 if(bIs3HuffTbl[eNJPDNum])
899 {
900 for(i= 1; i<=16; i++)
901 {
902 NJPD_DEBUG_DRV_MSG("dc chroma2 i=%d, [%02x %04x %02x]\n", i, in.u8DcChroma2Valid[i], in.u16DcChroma2Code[i], in.u8DcChroma2Symbol[i]);
903 }
904 for(i= 1; i<=16; i++)
905 {
906 NJPD_DEBUG_DRV_MSG("ac chroma2 i=%d, [%02x %04x %02x]\n",i, in.u8AcChroma2Valid[i], in.u16AcChroma2Code[i], in.u8AcChroma2Symbol[i]);
907 }
908 }
909 }
910 #endif
911 // DC
912 for ( i = 0; i < 16; i++ )
913 {
914 if(in.u8DcLumaValid[i+1])
915 {
916 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+i*4+0)) = in.u8DcLumaSymbol[i+1];
917 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+i*4+1)) = in.u16DcLumaCode[i+1]&0xff;
918 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+i*4+2)) = (in.u16DcLumaCode[i+1]>>8) &0xff;
919 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+i*4+3)) = in.u8DcLumaValid[i+1];
920 }
921 else
922 {
923 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+i*4+0)) = in.u8DcLumaSymbol[i+1];
924 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+i*4+3)) = in.u8DcLumaValid[i+1];
925 }
926 }
927
928 // AC
929 for ( i = 0; i < 16; i++ )
930 {
931 if(in.u8AcLumaValid[i+1])
932 {
933 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+16*4+i*4+0)) = ( in.u8AcLumaSymbol[i+1]+in.u8DcLumaCnt);
934 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+16*4+i*4+1)) = (in.u16AcLumaCode[i+1] & 0xff);
935 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+16*4+i*4+2)) = ((in.u16AcLumaCode[i+1]>>8) & 0xff);
936 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+16*4+i*4+3)) = in.u8AcLumaValid[i+1];
937 }
938 else
939 {
940 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+16*4+i*4+0)) = ( in.u8AcLumaSymbol[i+1]+in.u8DcLumaCnt);
941 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+16*4+i*4+3)) = in.u8AcLumaValid[i+1];
942 }
943 }
944
945 for ( i = 0; i < 16; i++ )
946 {
947 if(in.u8DcChromaValid[i+1])
948 {
949 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+32*4+i*4+0)) = in.u8DcChromaSymbol[i+1];
950 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+32*4+i*4+1)) = in.u16DcChromaCode[i+1] &0xff;
951 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+32*4+i*4+2)) = (in.u16DcChromaCode[i+1]>>8)&0xff;
952 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+32*4+i*4+3)) = in.u8DcChromaValid[i+1];
953 }
954 else
955 {
956 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+32*4+i*4+0)) = in.u8DcChromaSymbol[i+1];
957 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+32*4+i*4+3)) = in.u8DcChromaValid[i+1];
958 }
959 }
960
961 for ( i = 0; i < 16; i++ )
962 {
963 if(in.u8AcChromaValid[i+1])
964 {
965 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+48*4+i*4+0)) = ( in.u8AcChromaSymbol[i+1]+in.u8DcChromaCnt);
966 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+48*4+i*4+1)) = (in.u16AcChromaCode[i+1] & 0xff);
967 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+48*4+i*4+2)) = ((in.u16AcChromaCode[i+1]>>8) & 0xff);
968 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+48*4+i*4+3)) = in.u8AcChromaValid[i+1];
969 }
970 else
971 {
972 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+48*4+i*4+0)) = ( in.u8AcChromaSymbol[i+1]+in.u8DcChromaCnt);
973 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+48*4+i*4+3)) = in.u8AcChromaValid[i+1];
974 }
975 }
976
977 if(bIs3HuffTbl[eNJPDNum])
978 {
979 for ( i = 0; i < 16; i++ )
980 {
981 if(in.u8DcChroma2Valid[i+1])
982 {
983 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+64*4+i*4+0)) = in.u8DcChroma2Symbol[i+1];
984 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+64*4+i*4+1)) = in.u16DcChroma2Code[i+1]&0xff;
985 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+64*4+i*4+2)) = (in.u16DcChroma2Code[i+1]>>8) &0xff;
986 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+64*4+i*4+3)) = in.u8DcChroma2Valid[i+1];
987 }
988 else
989 {
990 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+64*4+i*4+0)) = in.u8DcChroma2Symbol[i+1];
991 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+64*4+i*4+3)) = in.u8DcChroma2Valid[i+1];
992 }
993 }
994
995 for ( i = 0; i < 16; i++ )
996 {
997 if(in.u8AcChroma2Valid[i+1])
998 {
999 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+80*4+i*4+0)) = ( in.u8AcChroma2Symbol[i+1]+in.u8DcChroma2Cnt );
1000 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+80*4+i*4+1)) = in.u16AcChroma2Code[i+1]&0xff;
1001 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+80*4+i*4+2)) = (in.u16AcChroma2Code[i+1]>>8)&0xff;
1002 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+80*4+i*4+3)) = in.u8AcChroma2Valid[i+1];
1003 }
1004 else
1005 {
1006 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+80*4+i*4+0)) = ( in.u8AcChroma2Symbol[i+1]+in.u8DcChroma2Cnt );
1007 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE+80*4+i*4+3)) = in.u8AcChroma2Valid[i+1];
1008 }
1009 }
1010 }
1011 }
1012
1013 MsOS_FlushMemory();
1014 MDrv_NJPD_GTable_Reload_Enable(ENABLE);
1015 #if ENABLE_NJPD_DEBUG_MSG
1016 NJPD_DEBUG_DRV_MSG("print the Group table!!!!!!!!!!!!!!!!\n");
1017 if(bIs3HuffTbl[eNJPDNum])
1018 {
1019 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE), 96*4);
1020 }
1021 else
1022 {
1023 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE), 64*4);
1024 }
1025 #else
1026 if(MDrv_NJPD_GetVerificationMode()==E_NJPD01_TABLE_READ_WRITE)
1027 {
1028 NJPD_DEBUG_DRV_MSG("print the Group table!!!!!!!!!!!!!!!!\n");
1029 if(bIs3HuffTbl[eNJPDNum])
1030 {
1031 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE), 96*4);
1032 }
1033 else
1034 {
1035 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE), 64*4);
1036 }
1037 }
1038 #endif
1039 MDrv_NJPD_SetGTableStartAddr(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE);
1040 }
1041 /********************************************************************/
1042 ///Write Symidx of Table Indirect Access
1043 ///@param in \b IN structure for Symidx of Table Indirect Access
1044 ///@return none
1045 /********************************************************************/
MDrv_NJPD_WriteSymidx(NJPD_Symidx in)1046 void MDrv_NJPD_WriteSymidx(NJPD_Symidx in)
1047 {
1048 MS_U16 i = 0;
1049 MS_U16 u16LumaCnt = 0;
1050 MS_U16 u16ChromaCnt = 0;
1051 MS_U16 u16Chroma2Cnt = 0;
1052 MS_U16 u16MaxCnt;
1053
1054 // JPEG_memset((void *)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE)), 0, 0x400);
1055 if (in.DHT)
1056 {
1057 // for ( i = 0; i < 16; i++ )
1058 for ( i = 0; i < 12; i++ )
1059 {
1060 if(i < u8DcLumaCnt[eNJPDNum])
1061 {
1062 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16LumaCnt*4+0)) = in.u8DcLumaHuffVal[i];
1063 u16LumaCnt++;
1064 }
1065 if(i < u8DcChromaCnt[eNJPDNum])
1066 {
1067 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16ChromaCnt*4+1)) = in.u8DcChromaHuffVal[i];
1068 u16ChromaCnt++;
1069 }
1070 if(bIs3HuffTbl[eNJPDNum] && i < u8DcChroma2Cnt[eNJPDNum])
1071 {
1072 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16Chroma2Cnt*4+2)) = in.u8DcChroma2HuffVal[i];
1073 u16Chroma2Cnt++;
1074 }
1075 else if(i < u8DcChromaCnt[eNJPDNum])
1076 {
1077 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16Chroma2Cnt*4+2)) = in.u8DcChromaHuffVal[i];
1078 u16Chroma2Cnt++;
1079 }
1080 }
1081
1082 // for ( i = 0; i < 240; i++ )
1083 for ( i = 0; i < 162; i++ )
1084 {
1085 if(i < u8AcLumaCnt[eNJPDNum])
1086 {
1087 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16LumaCnt*4+0)) = in.u8AcLumaHuffVal[i];
1088 u16LumaCnt++;
1089 }
1090 if(i < u8AcChromaCnt[eNJPDNum])
1091 {
1092 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16ChromaCnt*4+1)) = in.u8AcChromaHuffVal[i];
1093 u16ChromaCnt++;
1094 }
1095 if(bIs3HuffTbl[eNJPDNum] && i < u8AcChroma2Cnt[eNJPDNum])
1096 {
1097 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16Chroma2Cnt*4+2)) = in.u8AcChroma2HuffVal[i];
1098 u16Chroma2Cnt++;
1099 }
1100 else if(i < u8AcChromaCnt[eNJPDNum])
1101 {
1102 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+u16Chroma2Cnt*4+2)) = in.u8AcChromaHuffVal[i];
1103 u16Chroma2Cnt++;
1104 }
1105 }
1106 }
1107
1108 MsOS_FlushMemory();
1109 MDrv_NJPD_HTable_Reload_Enable(ENABLE);
1110 u16MaxCnt = (u16LumaCnt>u16ChromaCnt)? u16LumaCnt:u16ChromaCnt;
1111 u16MaxCnt = (u16MaxCnt>u16Chroma2Cnt)? u16MaxCnt:u16Chroma2Cnt;
1112 u16MaxCnt = ((u16MaxCnt%4)==2 || (u16MaxCnt%4)==3)? u16MaxCnt: ((u16MaxCnt/4)*4+2);
1113
1114 #if 0
1115 if(u16MaxCnt > u16LumaCnt)
1116 {
1117 for(i=u16LumaCnt; i<u16MaxCnt; i++)
1118 JPEG_memset((void*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+i*4+0)), 0, 1);
1119 }
1120 if(u16MaxCnt > u16ChromaCnt)
1121 {
1122 for(i=u16ChromaCnt; i<u16MaxCnt; i++)
1123 JPEG_memset((void*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+i*4+1)), 0, 1);
1124 }
1125 if(u16MaxCnt > u16Chroma2Cnt)
1126 {
1127 for(i=u16Chroma2Cnt; i<u16MaxCnt; i++)
1128 {
1129 JPEG_memset((void*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+i*4+2)), 0, 1);
1130 JPEG_memset((void*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE+i*4+3)), 0, 1);
1131 }
1132 }
1133 #endif
1134
1135 #if ENABLE_NJPD_DEBUG_MSG
1136 NJPD_DEBUG_DRV_MSG("print the Huffman table!!!!!!!!!!!!!!!!\n");
1137 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE), u16MaxCnt*4);
1138 #else
1139 if(MDrv_NJPD_GetVerificationMode()==E_NJPD01_TABLE_READ_WRITE)
1140 {
1141 NJPD_DEBUG_DRV_MSG("print the Huffman table!!!!!!!!!!!!!!!!\n");
1142 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE), u16MaxCnt*4);
1143 }
1144 #endif
1145 MDrv_NJPD_SetHTableStartAddr(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE);
1146
1147 if(MDrv_NJPD_IsNeedToPatch(E_NJPD_EAGLE_SW_PATCH))
1148 {
1149 HAL_NJPD_SetHTableSize(0xff);
1150 }
1151 else
1152 {
1153 HAL_NJPD_SetHTableSize(u16MaxCnt);
1154 }
1155
1156 }
1157 /********************************************************************/
1158 ///Write IQtbl of Table Indirect Access
1159 ///@param in \b IN structure for IQtbl of Table Indirect Access
1160 ///@return none
1161 /********************************************************************/
MDrv_NJPD_WriteIQTbl(NJPD_IQTbl in)1162 void MDrv_NJPD_WriteIQTbl(NJPD_IQTbl in)
1163 {
1164 MS_U8 i;
1165
1166 if (in.DQT)
1167 {
1168 for(i = 0; i<64; i++)
1169 {
1170 if(in.u8CompNum==1)
1171 {
1172 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+0)) = in.QuantTables[in.u8CompQuant[0]].s16Value[_u8Jpeg_zigzag_order[i]] & 0xff;
1173 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+1)) = in.QuantTables[in.u8CompQuant[0]].s16Value[_u8Jpeg_zigzag_order[i]] & 0xff;
1174 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+2)) = in.QuantTables[in.u8CompQuant[0]].s16Value[_u8Jpeg_zigzag_order[i]] & 0xff;
1175 }
1176 else if(in.u8CompNum==2)
1177 {
1178 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+0)) = (in.QuantTables[in.u8CompQuant[0]].s16Value[_u8Jpeg_zigzag_order[i]]) & 0xff;
1179 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+1)) = (in.QuantTables[in.u8CompQuant[1]].s16Value[_u8Jpeg_zigzag_order[i]]) & 0xff;
1180 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+2)) = (in.QuantTables[in.u8CompQuant[1]].s16Value[_u8Jpeg_zigzag_order[i]]) & 0xff;
1181 }
1182 else if(in.u8CompNum==3)
1183 {
1184 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+0)) = (in.QuantTables[in.u8CompQuant[0]].s16Value[_u8Jpeg_zigzag_order[i]]) & 0xff;
1185 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+1)) = (in.QuantTables[in.u8CompQuant[1]].s16Value[_u8Jpeg_zigzag_order[i]]) & 0xff;
1186 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+2)) = (in.QuantTables[in.u8CompQuant[2]].s16Value[_u8Jpeg_zigzag_order[i]]) & 0xff;
1187 }
1188 }
1189 }
1190 else
1191 {
1192 MS_U8 u8Value;
1193 for (i=0; i<64; i++)
1194 {
1195 u8Value = g16IQ_TBL_NJPD[i] & 0xff;
1196 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+i*4+0)) = u8Value;
1197 }
1198 for (i=64; i<128; i++)
1199 {
1200 u8Value = g16IQ_TBL_NJPD[i] & 0xff;
1201 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+(i-64)*4+1)) = u8Value;
1202 *(MS_U8*)(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE+(i-64)*4+2)) = u8Value;
1203 }
1204 }
1205
1206 if(in.u8CompNum==3)
1207 {
1208 MDrv_NJPD_SetDifferentQTable(ENABLE);
1209 }
1210 MsOS_FlushMemory();
1211 MDrv_NJPD_QTable_Reload_Enable(ENABLE);
1212 #if ENABLE_NJPD_DEBUG_MSG
1213 NJPD_DEBUG_DRV_MSG("print the Quantization table!!!!!!!!!!!!!!!!\n");
1214 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE), 64*4);
1215 #else
1216 if(MDrv_NJPD_GetVerificationMode()==E_NJPD01_TABLE_READ_WRITE)
1217 {
1218 NJPD_DEBUG_DRV_MSG("print the Quantization table!!!!!!!!!!!!!!!!\n");
1219 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE), 64*4);
1220 }
1221 #endif
1222 MDrv_NJPD_SetQTableStartAddr(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE);
1223 }
1224
MDrv_NJPD_TableRead(void)1225 void MDrv_NJPD_TableRead(void)
1226 {
1227 MS_U16 u16Value =0;
1228 MS_U8 u8Table;
1229 MS_U16 u16Addr;
1230 MS_U8 u8TableCnt;
1231 MS_U16 u16RIUValue = HAL_NJPD_GetRIUInterface();
1232
1233 HAL_NJPD_Set_GlobalSetting02(HAL_NJPD_Get_GlobalSetting02() & ~NJPD_TBC_MODE);
1234
1235 NJPD_DEBUG_DRV_MSG("\n%s(), read h table start================\n", __FUNCTION__);
1236 u8Table = 0; // 2'b00: h table, 2'b01: g table, 2'b10: q table
1237 u8TableCnt = HAL_NJPD_GetHTableSize();
1238 for(u16Addr=0; u16Addr<u8TableCnt; u16Addr++)
1239 {
1240 u16Value =NJPD_JPD_TBC_TABLE_READ | ((u8Table & 0x3)<<1 & NJPD_JPD_TBC_SEL) | u16Addr<<8;
1241 HAL_NJPD_SetRIUInterface(u16Value);
1242 HAL_NJPD_SetWriteOneClearReg_2(NJPD_TBC_EN);
1243 while(1)
1244 {
1245 if(HAL_NJPD_GetRIUInterface() & NJPD_JPD_TBC_TABLE_READ)
1246 {
1247 NJPD_DEBUG_DRV_MSG("%02x %02x %02x %02x ",
1248 HAL_NJPD_TBCReadData_L()&0xff,
1249 (HAL_NJPD_TBCReadData_L()&0xff00) >>8,
1250 HAL_NJPD_TBCReadData_H()&0xff,
1251 (HAL_NJPD_TBCReadData_H()&0xff00) >>8
1252 );
1253 if(u16Addr%2==1)
1254 {
1255 NJPD_DEBUG_DRV_MSG("\n");
1256 }
1257 break;
1258 }
1259 }
1260 }
1261 NJPD_DEBUG_DRV_MSG("%s(), read h table end ================\n", __FUNCTION__);
1262
1263 NJPD_DEBUG_DRV_MSG("\n%s(), read g table start================\n", __FUNCTION__);
1264 u8Table = 1; // 2'b00: h table, 2'b01: g table, 2'b10: q table
1265 if(bIs3HuffTbl[eNJPDNum])
1266 {
1267 u8TableCnt = 96;
1268 }
1269 else
1270 {
1271 u8TableCnt = 64;
1272 }
1273
1274 for(u16Addr=0; u16Addr<u8TableCnt; u16Addr++)
1275 {
1276 u16Value =NJPD_JPD_TBC_TABLE_READ | ((u8Table & 0x3)<<1 & NJPD_JPD_TBC_SEL) | u16Addr<<8;
1277 HAL_NJPD_SetRIUInterface(u16Value);
1278 HAL_NJPD_SetWriteOneClearReg_2(NJPD_TBC_EN);
1279 while(1)
1280 {
1281 if(HAL_NJPD_GetRIUInterface() & NJPD_JPD_TBC_TABLE_READ)
1282 {
1283 NJPD_DEBUG_DRV_MSG("%02x %02x %02x %02x ",
1284 HAL_NJPD_TBCReadData_L()&0xff,
1285 (HAL_NJPD_TBCReadData_L()&0xff00) >>8,
1286 HAL_NJPD_TBCReadData_H()&0xff,
1287 (HAL_NJPD_TBCReadData_H()&0xff00) >>8
1288 );
1289 if(u16Addr%2==1)
1290 {
1291 NJPD_DEBUG_DRV_MSG("\n");
1292 }
1293 break;
1294 }
1295 }
1296 }
1297 NJPD_DEBUG_DRV_MSG("%s(), read g table end ================\n", __FUNCTION__);
1298
1299 NJPD_DEBUG_DRV_MSG("\n%s(), read q table start================\n", __FUNCTION__);
1300 u8Table = 2; // 2'b00: h table, 2'b01: g table, 2'b10: q table
1301 u8TableCnt = 64;
1302 for(u16Addr=0; u16Addr<u8TableCnt; u16Addr++)
1303 {
1304 u16Value =NJPD_JPD_TBC_TABLE_READ | ((u8Table & 0x3)<<1 & NJPD_JPD_TBC_SEL) | u16Addr<<8;
1305 HAL_NJPD_SetRIUInterface(u16Value);
1306 HAL_NJPD_SetWriteOneClearReg_2(NJPD_TBC_EN);
1307 while(1)
1308 {
1309 if(HAL_NJPD_GetRIUInterface() & NJPD_JPD_TBC_TABLE_READ)
1310 {
1311 NJPD_DEBUG_DRV_MSG("%02x %02x %02x %02x ",
1312 HAL_NJPD_TBCReadData_L()&0xff,
1313 (HAL_NJPD_TBCReadData_L()&0xff00) >>8,
1314 HAL_NJPD_TBCReadData_H()&0xff,
1315 (HAL_NJPD_TBCReadData_H()&0xff00) >>8
1316 );
1317 if(u16Addr%2==1)
1318 {
1319 NJPD_DEBUG_DRV_MSG("\n");
1320 }
1321 break;
1322 }
1323 }
1324 }
1325 NJPD_DEBUG_DRV_MSG("%s(), read q table end ================\n", __FUNCTION__);
1326 HAL_NJPD_Set_GlobalSetting02(HAL_NJPD_Get_GlobalSetting02() | NJPD_TBC_MODE);
1327 HAL_NJPD_SetRIUInterface(u16RIUValue);
1328 }
1329
MDrv_NJPD_SetVerificationMode(NJPD_VerificationMode VerificationMode)1330 void MDrv_NJPD_SetVerificationMode(NJPD_VerificationMode VerificationMode)
1331 {
1332 HAL_NJPD_SetVerificationMode(VerificationMode);
1333 }
1334
MDrv_NJPD_GetVerificationMode(void)1335 NJPD_VerificationMode MDrv_NJPD_GetVerificationMode(void)
1336 {
1337 return HAL_NJPD_GetVerificationMode();
1338 }
1339
MDrv_NJPD_Debug()1340 void MDrv_NJPD_Debug()
1341 {
1342 #if (ENABLE_TEST_NJPD_01_table_read_write_test == TRUE)
1343 MDrv_NJPD_TableRead();
1344 #else
1345 if(HAL_NJPD_GetVerificationMode()==E_NJPD01_TABLE_READ_WRITE)
1346 {
1347 MDrv_NJPD_TableRead();
1348 }
1349 #endif
1350 HAL_NJPD_Debug();
1351
1352 NJPD_DEBUG_DRV_MSG("[offset: MRC0: MRC1]=[%td, %td, %td]\n",
1353 (ptrdiff_t)((u32READ_Start[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum]/16 +1)%16),
1354 (ptrdiff_t)((u32MRC0_End[eNJPDNum]/16 - u32MRC0_Start[eNJPDNum]/16 +1)%16),
1355 (ptrdiff_t)((u32MRC1_End[eNJPDNum]/16 - u32MRC1_Start[eNJPDNum]/16 +1)%16)
1356 );
1357
1358 //_NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]), 2048);
1359
1360 }
1361 /********************************************************************/
1362 ///Set NJPD Debug level
1363 ///@para MS_U8 u8DbgLevel \b IN The NJPD debug level
1364 ///@return none
1365 /********************************************************************/
MDrv_NJPD_SetDbgLevel(MS_U8 u8DbgLevel)1366 void MDrv_NJPD_SetDbgLevel(MS_U8 u8DbgLevel)
1367 {
1368 u8NJPD_DrvDbgLevel = u8DbgLevel;
1369 HAL_NJPD_SetDbgLevel(u8DbgLevel);
1370 }
1371
1372 /********************************************************************/
1373 ///Get NJPD driver information
1374 ///@param const NJPD_Info *pNJPD_Inf \b OUT The pointer of NJPD info.
1375 ///@return none
1376 /********************************************************************/
MDrv_NJPD_GetInfo(NJPD_Info * pNJPD_Info)1377 void MDrv_NJPD_GetInfo(NJPD_Info *pNJPD_Info)
1378 {
1379 NJPD_HAL_Version HalVer;
1380 HAL_NJPD_GetLibVer(&HalVer);
1381 pNJPD_Info->pu8HalVer = HalVer.pu8HalVer;
1382 pNJPD_Info->pu8FwVer = HalVer.pu8FwVer;
1383 pNJPD_Info->stCap = _stNJPD_Cap;
1384 }
1385
1386 /********************************************************************/
1387 ///Get NJPD driver status
1388 ///@param none
1389 ///@return the pointer of NJPD_Status
1390 /********************************************************************/
MDrv_NJPD_GetStatus(void)1391 NJPD_Status* MDrv_NJPD_GetStatus(void)
1392 {
1393 _stNJPD_Status.u32CurMRCAddr = HAL_NJPD_GetCurMRCAddr();
1394 _stNJPD_Status.u16CurVidx = 0;
1395 _stNJPD_Status.u16CurRow = HAL_NJPD_GetCurRow();
1396 _stNJPD_Status.u16CurCol = HAL_NJPD_GetCurCol();
1397 return &_stNJPD_Status;
1398 }
1399
1400 /********************************************************************/
1401 ///Get NJPD driver version
1402 ///@param MS_U8 **pVerString \b OUT NJPD version
1403 ///@return TRUE/FALSE
1404 /********************************************************************/
MDrv_NJPD_GetLibVer(const MSIF_Version ** ppVersion)1405 MS_BOOL MDrv_NJPD_GetLibVer(const MSIF_Version **ppVersion)
1406 {
1407 if (!ppVersion)
1408 {
1409 return FALSE;
1410 }
1411 *ppVersion = &_drv_jpd_version;
1412 return TRUE;
1413 }
1414
1415 /********************************************************************/
1416 ///Enable NJPD ISR and register callback function.
1417 ///@param NJPD_IsrFunc IsrCb \b IN Interrupt callback function
1418 ///@return TRUE/FALSE
1419 /********************************************************************/
MDrv_NJPD_EnableISR(NJPD_IsrFuncCb IsrCb)1420 MS_BOOL MDrv_NJPD_EnableISR(NJPD_IsrFuncCb IsrCb)
1421 {
1422 if(TRUE == _stNJPD_Status.bIsrEnable)
1423 {
1424 NJPD_DEBUG_DRV_MSG("NJPD ISR has been enabled!!\n");
1425 return FALSE;
1426 }
1427
1428 if(TRUE == OSAL_NJPD_ISR_Attach((OSAL_NJPD_IsrFuncCb)_NJPD_ISRHandler))
1429 {
1430 NJPD_DEBUG_DRV_MSG("Attach NJPD ISR Success!!\n");
1431 if(TRUE == OSAL_NJPD_ISR_Enable())
1432 {
1433 NJPD_DEBUG_DRV_MSG("MDrv_NJPD_EnableISR : Success!!\n");
1434 _stNJPD_Status.bIsrEnable = TRUE;
1435 if(IsrCb)
1436 {
1437 _pNJPDIsrCb = IsrCb;
1438 }
1439 return TRUE;
1440 }
1441 }
1442 NJPD_DEBUG_DRV_MSG("MDrv_NJPD_EnableISR Failed!!\n");
1443 return FALSE;
1444 }
1445
1446 /********************************************************************/
1447 ///Disable NJPD ISR and unregister callback function.
1448 ///@param NJPD_IsrFunc IsrCb \b IN Interrupt callback function
1449 ///@return TRUE/FALSE
1450 /********************************************************************/
MDrv_NJPD_DisableISR(void)1451 MS_BOOL MDrv_NJPD_DisableISR(void)
1452 {
1453 if(FALSE == _stNJPD_Status.bIsrEnable)
1454 {
1455 NJPD_DEBUG_DRV_MSG("NJPD ISR has been disabled!!\n");
1456 return FALSE;
1457 }
1458
1459 if(TRUE == OSAL_NJPD_ISR_Disable())
1460 {
1461 NJPD_DEBUG_DRV_MSG("Disable NJPD ISR Success!!\n");
1462 if(TRUE == OSAL_NJPD_ISR_Detach())
1463 {
1464 NJPD_DEBUG_DRV_MSG("MDrv_NJPD_DisableISR : Success!!\n");
1465 _stNJPD_Status.bIsrEnable = FALSE;
1466 _pNJPDIsrCb = NULL;
1467 return TRUE;
1468 }
1469 }
1470 return FALSE;
1471 }
1472
1473 /********************************************************************/
1474 ///Get current vertical line index written to memory
1475 ///@return current vertical line index written to memory
1476 /********************************************************************/
MDrv_NJPD_GetCurMRCAddr(void)1477 MS_U32 MDrv_NJPD_GetCurMRCAddr(void)
1478 {
1479 return HAL_NJPD_GetCurMRCAddr();
1480 }
1481
1482 /********************************************************************/
1483 ///Get current vertical line index written to memory
1484 ///@return current vertical line index written to memory
1485 /********************************************************************/
MDrv_NJPD_GetCurRow(void)1486 MS_U16 MDrv_NJPD_GetCurRow(void)
1487 {
1488 return HAL_NJPD_GetCurRow();
1489 }
1490
1491 /********************************************************************/
1492 ///Get current vertical line index written to memory
1493 ///@return current vertical line index written to memory
1494 /********************************************************************/
MDrv_NJPD_GetCurCol(void)1495 MS_U16 MDrv_NJPD_GetCurCol(void)
1496 {
1497 return HAL_NJPD_GetCurCol();
1498 }
1499 /********************************************************************/
1500 ///Set write protect flag
1501 ///@return none
1502 /********************************************************************/
MDrv_NJPD_SetAutoProtect(MS_BOOL enable)1503 void MDrv_NJPD_SetAutoProtect(MS_BOOL enable)
1504 {
1505 HAL_NJPD_SetAutoProtect(enable);
1506 }
1507
1508 /******************************************************************************/
1509 ///Set WPEN end address for NJPD
1510 ///@param u32ByteOffset \b IN End address for NJPD writing to MWC buffer
1511 ///@return none
1512 /******************************************************************************/
MDrv_NJPD_SetWPENEndAddr(MS_PHY u32ByteOffset)1513 void MDrv_NJPD_SetWPENEndAddr(MS_PHY u32ByteOffset)
1514 {
1515 MS_U8 u8MiuSel = 0;
1516 _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
1517 UNUSED(u8MiuSel);
1518
1519 NJPD_DEBUG_DRV_MSG("MDrv_NJPD_SetWPENEndAddr=0x%tx\n", (ptrdiff_t)u32ByteOffset);
1520 HAL_NJPD_SetWPENUBound_0_L(( u32ByteOffset >> 3 ) & 0xffffUL);
1521 HAL_NJPD_SetWPENUBound_0_H(( u32ByteOffset >> 3 ) >> 16);
1522 }
1523
MDrv_NJPD_SetWPENStartAddr(MS_PHY u32ByteOffset)1524 void MDrv_NJPD_SetWPENStartAddr(MS_PHY u32ByteOffset)
1525 {
1526 MS_U8 u8MiuSel = 0;
1527 _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
1528 UNUSED(u8MiuSel);
1529
1530 NJPD_DEBUG_DRV_MSG("MDrv_NJPD_SetWPENStartAddr=0x%tx\n", (ptrdiff_t)u32ByteOffset);
1531 HAL_NJPD_SetWPENLBound_0_L(( u32ByteOffset >> 3 ) & 0xffffUL);
1532 HAL_NJPD_SetWPENLBound_0_H(( u32ByteOffset >> 3 ) >> 16);
1533 }
1534
1535 /********************************************************************/
1536 ///Set Spare Register
1537 ///@param u16Value \n IN register SCONFIG
1538 ///@return none
1539 /********************************************************************/
MDrv_NJPD_SetSpare(MS_U16 u16Value)1540 void MDrv_NJPD_SetSpare(MS_U16 u16Value)
1541 {
1542 HAL_NJPD_SetSpare00(u16Value);
1543 }
1544
1545 /********************************************************************/
1546 ///Get Spare Register
1547 ///@return Spare Register
1548 /********************************************************************/
MDrv_NJPD_GetSpare(void)1549 MS_U16 MDrv_NJPD_GetSpare(void)
1550 {
1551 return HAL_NJPD_GetSpare00();
1552 }
1553
MDrv_NJPD_SetMRC_Valid(MS_U16 u16Value)1554 void MDrv_NJPD_SetMRC_Valid(MS_U16 u16Value)
1555 {
1556 NJPD_DEBUG_DRV_MSG("%s() with u16Value=0x%x\n", __FUNCTION__, u16Value);
1557 #if ENABLE_FF00FFD_TO_FFFFFFD
1558 MS_U32 u32Time =MDrv_TIMER_GetUs(E_TIMER_1);
1559 if(u16Value & NJPD_MRC0_VALID)
1560 {
1561 MS_U32 u32addr;
1562 for(u32addr=MS_PA2KSEG1(u32MRC0_Start[eNJPDNum]); u32addr<MS_PA2KSEG1(u32MRC0_End[eNJPDNum]); u32addr++)
1563 {
1564 if(((*(MS_U8 *)u32addr)==0xff )&& ((*(MS_U8 *)(u32addr+1))==0x00)
1565 &&((*(MS_U8 *)(u32addr+2))==0xff )&&(((*(MS_U8 *)(u32addr+3)) >>4)==0xd ))
1566 {
1567 (*(MS_U8 *)(u32addr+1)) = 0xff;
1568 }
1569 }
1570 }
1571 if(u16Value & NJPD_MRC1_VALID)
1572 {
1573 MS_U32 u32addr;
1574 for(u32addr=MS_PA2KSEG1(u32MRC1_Start[eNJPDNum]); u32addr<MS_PA2KSEG1(u32MRC1_End[eNJPDNum]); u32addr++)
1575 {
1576 if(((*(MS_U8 *)u32addr)==0xff )&& ((*(MS_U8 *)(u32addr+1))==0x00)
1577 &&((*(MS_U8 *)(u32addr+2))==0xff )&&(((*(MS_U8 *)(u32addr+3)) >>4)==0xd ))
1578 {
1579 (*(MS_U8 *)(u32addr+1)) = 0xff;
1580 }
1581 }
1582
1583 }
1584
1585 if(u16Value & NJPD_MRC0_VALID && u16Value & NJPD_MRC1_VALID)
1586 printf("[B]waste %ldus, size=%ld\n", MDrv_TIMER_GetUs(E_TIMER_1)-u32Time, u32MRC1_End[eNJPDNum]-u32MRC0_Start[eNJPDNum]);
1587 else if(u16Value & NJPD_MRC0_VALID)
1588 printf("[0]waste %ldus, size=%ld\n", MDrv_TIMER_GetUs(E_TIMER_1)-u32Time, u32MRC0_End[eNJPDNum]-u32MRC0_Start[eNJPDNum]);
1589 else if(u16Value & NJPD_MRC1_VALID)
1590 printf("[1]waste %ldus, size=%ld\n", MDrv_TIMER_GetUs(E_TIMER_1)-u32Time, u32MRC1_End[eNJPDNum]-u32MRC1_Start[eNJPDNum]);
1591 #endif
1592
1593 HAL_NJPD_SetWriteOneClearReg(u16Value);
1594 }
1595
MDrv_NJPD_DecodeEnable()1596 void MDrv_NJPD_DecodeEnable()
1597 {
1598
1599 #if 0
1600 MDrv_NJPD_TableRead();
1601 #if ENABLE_NJPD_DEBUG_MSG
1602 NJPD_DEBUG_DRV_MSG("print the Group table!!!!!!!!!!!!!!!!\n");
1603 if(bIs3HuffTbl[eNJPDNum])
1604 {
1605 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE), 96*4);
1606 }
1607 else
1608 {
1609 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SCWGIF_BASE), 64*4);
1610 }
1611 #endif
1612
1613 #if ENABLE_NJPD_DEBUG_MSG
1614 NJPD_DEBUG_DRV_MSG("print the Huffman table!!!!!!!!!!!!!!!!\n");
1615 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_SYMIDX_BASE), 0x2b8);
1616 #endif
1617
1618 #if ENABLE_NJPD_DEBUG_MSG
1619 NJPD_DEBUG_DRV_MSG("print the Quantization table!!!!!!!!!!!!!!!!\n");
1620 _NJPD_PrintMem(MS_PA2KSEG1(u32TablePhyAddr[eNJPDNum]+NJPD_MEM_QTBL_BASE), 64*4);
1621 #endif
1622 #endif
1623
1624 NJPD_DEBUG_DRV_MSG("%s().....\n", __FUNCTION__);
1625 HAL_NJPD_SetWriteOneClearReg(NJPD_DECODE_ENABLE);
1626 }
1627
1628
MDrv_NJPD_TableLoadingStart()1629 void MDrv_NJPD_TableLoadingStart()
1630 {
1631 NJPD_DEBUG_DRV_MSG("%s().....\n", __FUNCTION__);
1632 HAL_NJPD_SetWriteOneClearReg(NJPD_TABLE_LOADING_START);
1633 }
1634
1635
MDrv_NJPD_ReadLastBuffer()1636 void MDrv_NJPD_ReadLastBuffer()
1637 {
1638 NJPD_DEBUG_DRV_MSG("%s().....\n", __FUNCTION__);
1639 HAL_NJPD_SetWriteOneClearReg(NJPD_MRC_LAST);
1640 }
1641
MDrv_NJPD_SetScalingDownFactor(NJPD_SCALING_DOWN_FACTOR eScalingFactor)1642 void MDrv_NJPD_SetScalingDownFactor(NJPD_SCALING_DOWN_FACTOR eScalingFactor)
1643 {
1644 MS_U16 u16Value;
1645 u16Value = ((HAL_NJPD_Get_GlobalSetting01() & ~NJPD_DOWN_SCALE) | ((MS_U16)eScalingFactor<<0));
1646 HAL_NJPD_Set_GlobalSetting01(u16Value);
1647 }
1648
MDrv_NJPD_GTable_Rst(MS_BOOL bEnable)1649 void MDrv_NJPD_GTable_Rst(MS_BOOL bEnable)
1650 {
1651 MS_U16 u16Value;
1652 if(bEnable)
1653 {
1654 u16Value = (HAL_NJPD_Get_GlobalSetting01() & ~NJPD_GTABLE_RST);
1655 HAL_NJPD_Set_GlobalSetting01(u16Value);
1656 u16Value = ((HAL_NJPD_Get_GlobalSetting01() & ~NJPD_GTABLE_RST) | ((MS_U16)bEnable<<10));
1657 HAL_NJPD_Set_GlobalSetting01(u16Value);
1658 }
1659 }
1660
MDrv_NJPD_HTable_Reload_Enable(MS_BOOL bEnable)1661 void MDrv_NJPD_HTable_Reload_Enable(MS_BOOL bEnable)
1662 {
1663 MS_U16 u16Value;
1664 u16Value = ((HAL_NJPD_Get_GlobalSetting01() & ~NJPD_HTABLE_RELOAD_EN) | ((MS_U16)bEnable<<11));
1665 HAL_NJPD_Set_GlobalSetting01(u16Value);
1666 }
1667
MDrv_NJPD_GTable_Reload_Enable(MS_BOOL bEnable)1668 void MDrv_NJPD_GTable_Reload_Enable(MS_BOOL bEnable)
1669 {
1670 MS_U16 u16Value;
1671 u16Value = ((HAL_NJPD_Get_GlobalSetting01() & ~NJPD_GTABLE_RELOAD_EN) | ((MS_U16)bEnable<<12));
1672 HAL_NJPD_Set_GlobalSetting01(u16Value);
1673 }
1674
MDrv_NJPD_QTable_Reload_Enable(MS_BOOL bEnable)1675 void MDrv_NJPD_QTable_Reload_Enable(MS_BOOL bEnable)
1676 {
1677 MS_U16 u16Value;
1678 u16Value = ((HAL_NJPD_Get_GlobalSetting01() & ~NJPD_QTABLE_RELOAD_EN) | ((MS_U16)bEnable<<13));
1679 HAL_NJPD_Set_GlobalSetting01(u16Value);
1680 }
1681
MDrv_NJPD_SetSoftwareVLD(MS_BOOL bEnable)1682 void MDrv_NJPD_SetSoftwareVLD(MS_BOOL bEnable)
1683 {
1684 MS_U16 u16Value;
1685 u16Value = ((HAL_NJPD_Get_GlobalSetting02() & ~(NJPD_REMOVE_0xFF00 | NJPD_REMOVE_0xFFFF | NJPD_FFD9_EN)) | NJPD_BITSTREAM_LE);
1686 HAL_NJPD_Set_GlobalSetting02(u16Value);
1687 u16Value = ((HAL_NJPD_Get_GlobalSetting01() & ~NJPD_SVLD) | ((MS_U16)bEnable<<6));
1688 HAL_NJPD_Set_GlobalSetting01(u16Value);
1689 if(bEnable)
1690 {
1691 // 20120619, clear last bit when SVJD or NJPD_REMOVE_0xFFFF ==0
1692 HAL_NJPD_SetSpare00(HAL_NJPD_GetSpare00() & 0xfffeUL);
1693 }
1694 }
1695
MDrv_NJPD_SetDifferentQTable(MS_BOOL bEnable)1696 void MDrv_NJPD_SetDifferentQTable(MS_BOOL bEnable)
1697 {
1698 MS_U16 u16Value;
1699 u16Value = ((HAL_NJPD_Get_GlobalSetting00() & ~NJPD_SUVQ) | ((MS_U16)bEnable<<7));
1700 HAL_NJPD_Set_GlobalSetting00(u16Value);
1701 }
1702
MDrv_NJPD_SetDifferentHTable(MS_BOOL bEnable)1703 void MDrv_NJPD_SetDifferentHTable(MS_BOOL bEnable)
1704 {
1705 MS_U16 u16Value;
1706 bIs3HuffTbl[eNJPDNum] = bEnable;
1707 u16Value = ((HAL_NJPD_Get_GlobalSetting00() & ~NJPD_SUVH) | ((MS_U16)bEnable<<8));
1708 HAL_NJPD_Set_GlobalSetting00(u16Value);
1709 }
1710
MDrv_NJPD_Set_GlobalSetting00(MS_U16 u16Value)1711 void MDrv_NJPD_Set_GlobalSetting00(MS_U16 u16Value)
1712 {
1713 HAL_NJPD_Set_GlobalSetting00(u16Value);
1714 }
1715
MDrv_NJPD_Get_GlobalSetting00(void)1716 MS_U16 MDrv_NJPD_Get_GlobalSetting00(void)
1717 {
1718 return HAL_NJPD_Get_GlobalSetting00();
1719 }
1720
MDrv_NJPD_SetHTableStartAddr(MS_PHY u32ByteOffset)1721 void MDrv_NJPD_SetHTableStartAddr(MS_PHY u32ByteOffset)
1722 {
1723 MS_U8 u8MiuSel = 0;
1724 _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
1725 UNUSED(u8MiuSel);
1726
1727 HAL_NJPD_SetHTableStart_Low((u32ByteOffset & 0xffffUL));
1728 HAL_NJPD_SetHTableStart_High((u32ByteOffset >> 16));
1729 }
1730
MDrv_NJPD_SetQTableStartAddr(MS_PHY u32ByteOffset)1731 void MDrv_NJPD_SetQTableStartAddr(MS_PHY u32ByteOffset)
1732 {
1733 MS_U8 u8MiuSel = 0;
1734 _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
1735 UNUSED(u8MiuSel);
1736
1737 HAL_NJPD_SetQTableStart_Low((u32ByteOffset & 0xffffUL));
1738 HAL_NJPD_SetQTableStart_High((u32ByteOffset >> 16));
1739 }
1740
1741
MDrv_NJPD_SetGTableStartAddr(MS_PHY u32ByteOffset)1742 void MDrv_NJPD_SetGTableStartAddr(MS_PHY u32ByteOffset)
1743 {
1744 MS_U8 u8MiuSel = 0;
1745 _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
1746 UNUSED(u8MiuSel);
1747
1748 HAL_NJPD_SetGTableStart_Low((u32ByteOffset & 0xffffUL));
1749 HAL_NJPD_SetGTableStart_High((u32ByteOffset >> 16));
1750 }
1751
1752
MDrv_NJPD_EnablePowerSaving()1753 void MDrv_NJPD_EnablePowerSaving()
1754 {
1755 HAL_NJPD_SetClockGate(0xFF);
1756 }
1757
MDrv_NJPD_SetNJPDInstance(JPD_Number JPDNum)1758 void MDrv_NJPD_SetNJPDInstance(JPD_Number JPDNum)
1759 {
1760 eNJPDNum = JPDNum;
1761 HAL_NJPD_SetNJPDInstance(JPDNum);
1762 }
1763
MDrv_NJPD_IsNeedToPatch(NJPD_PATCH_INDEX eIndex)1764 MS_BOOL MDrv_NJPD_IsNeedToPatch(NJPD_PATCH_INDEX eIndex)
1765 {
1766 return HAL_NJPD_IsNeedToPatch(eIndex);
1767 }
1768
1769 #ifdef MSOS_TYPE_LINUX_KERNEL
MDrv_NJPD_Get_ISR(void)1770 MS_BOOL MDrv_NJPD_Get_ISR(void)
1771 {
1772 return gbCallbackFlag;
1773 }
1774
MDrv_NJPD_Set_ISR(MS_BOOL val)1775 void MDrv_NJPD_Set_ISR(MS_BOOL val)
1776 {
1777 gbCallbackFlag = val;
1778 }
1779 #endif
1780
MDrv_NJPD_JPDCount(void)1781 MS_U8 MDrv_NJPD_JPDCount(void)
1782 {
1783 return HAL_NJPD_JPDCount();
1784 }
1785
1786
1787