xref: /utopia/UTPA2-700.0.x/modules/ojpd_vdec_v2/drv/jpd_ex/drvJPD.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file    drvJPD.c
98 /// @brief  JPD Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 
103 //-------------------------------------------------------------------------------------------------
104 //  Include Files
105 //-------------------------------------------------------------------------------------------------
106 // Common Definition
107 #include <string.h>
108 #include "MsCommon.h"
109 #include "MsVersion.h"
110 #include "MsOS.h"
111 #include "halCHIP.h"
112 // Internal Definition
113 //#include "regCHIP.h"
114 #include "jpeg_def.h"
115 #include "osalJPD.h"
116 #include "drvJPD.h"
117 #include "regJPD.h"
118 #include "halJPD.h"
119 #include "drvMIU.h"
120 #include "halCHIP.h"
121 
122 
123 //-------------------------------------------------------------------------------------------------
124 //  Driver Compiler Options
125 //-------------------------------------------------------------------------------------------------
126 
127 //-------------------------------------------------------------------------------------------------
128 //  Local Defines
129 //-------------------------------------------------------------------------------------------------
130 //JPD driver debug macro
131 
132 #ifndef ANDROID
133 #define JPD_DEBUG_DRV_MSG(format, args...)  do{if(u8JPD_DrvDbgLevel & E_JPD_DEBUG_DRV_MSG) printf(format, ##args);}while(0)
134 #define JPD_DEBUG_DRV_ERR(format, args...)  do{if(u8JPD_DrvDbgLevel & E_JPD_DEBUG_DRV_ERR) printf(format, ##args);}while(0)
135 #else
136 #define LOG_TAG "DRV_JPD"
137 #include <cutils/log.h>
138 #ifndef LOGD
139 #define JPD_DEBUG_DRV_MSG(format, args...)  do{if(u8JPD_DrvDbgLevel & E_JPD_DEBUG_DRV_MSG) ALOGI(format, ##args);}while(0)
140 #define JPD_DEBUG_DRV_ERR(format, args...)  do{if(u8JPD_DrvDbgLevel & E_JPD_DEBUG_DRV_ERR) ALOGE(format, ##args);}while(0)
141 #else
142 #define JPD_DEBUG_DRV_MSG(format, args...)  do{if(u8JPD_DrvDbgLevel & E_JPD_DEBUG_DRV_MSG) LOGI(format, ##args);}while(0)
143 #define JPD_DEBUG_DRV_ERR(format, args...)  do{if(u8JPD_DrvDbgLevel & E_JPD_DEBUG_DRV_ERR) LOGE(format, ##args);}while(0)
144 #endif
145 
146 #endif
147 
148 #ifndef UNUSED
149 #define UNUSED(x) ((x)=(x))
150 #endif
151 
152 #define HVD_FW_MEM_OFFSET           0x100000UL  // 1M
153 //-------------------------------------------------------------------------------------------------
154 //  Local Structurs
155 //-------------------------------------------------------------------------------------------------
156 
157 
158 //-------------------------------------------------------------------------------------------------
159 //  Global Variables
160 //-------------------------------------------------------------------------------------------------
161 MS_BOOL gbEnableTurboFWMode = FALSE;
162 
163 //-------------------------------------------------------------------------------------------------
164 //  Local Variables
165 //-------------------------------------------------------------------------------------------------
166 static MSIF_Version _drv_jpd_version =
167 {
168     .DDI = { JPD_DRV_VERSION },
169 };
170 
171 /* capability */
172 static JPD_Cap _stJPD_Cap = {
173                                 TRUE, //support baseline
174                                 TRUE, //support progressive
175                                 TRUE  //support MJPEG
176                             };
177 
178 static JPD_Status _stJPD_Status = {
179                                       0,        //Current MRC address
180                                       0,        //Current decoded Vidx
181                                       0,        //Current decoded Row
182                                       0,        //Current decoded Col
183                                       FALSE,    //busy or not
184                                       FALSE     //Isr is enabled or not
185                                   };
186 
187 static MS_U8 u8JPD_DrvDbgLevel = E_JPD_DEBUG_DRV_NONE;
188 
189 
190 static JPD_IsrFuncCb _pJPDIsrCb = NULL;
191 
192 
193 #define MJPEG_MAX_SUPPORT_STREAM_NUM 2
194 
195 
196 static const MS_U8 _u8Jpeg_zigzag_order[64] =
197 {
198     0, 1, 5, 6, 14, 15, 27, 28,
199     2, 4, 7, 13, 16, 26, 29, 42,
200     3, 8, 12, 17, 25, 30, 41, 43,
201     9, 11, 18, 24, 31, 40, 44, 53,
202     10, 19, 23, 32, 39, 45, 52, 54,
203     20, 22, 33, 38, 46, 51, 55, 60,
204     21, 34, 37, 47, 50, 56, 59, 61,
205     35, 36, 48, 49, 57, 58, 62, 63
206 };
207 
208 // Default Table for JPEG
209 static const MS_U16 g16GRPINFO_TBL[128]=
210 {
211 0x0000,
212 0x0000,
213 0x0000,
214 0x0100,
215 0x0010,
216 0x0140,
217 0x0060,
218 0x01e0,
219 0x0070,
220 0x01f0,
221 0x0080,
222 0x01f8,
223 0x0090,
224 0x01fc,
225 0x00a0,
226 0x01fe,
227 0x00b0,
228 0x01ff,
229 0x0000,
230 0x0000,
231 0x0000,
232 0x0000,
233 0x0000,
234 0x0000,
235 0x0000,
236 0x0000,
237 0x0000,
238 0x0000,
239 0x0000,
240 0x0000,
241 0x0000,
242 0x0000,
243 0x0000,
244 0x0000,
245 0x0000,
246 0x0100,
247 0x0030,
248 0x01c0,
249 0x0040,
250 0x01e0,
251 0x0050,
252 0x01f0,
253 0x0060,
254 0x01f8,
255 0x0070,
256 0x01fc,
257 0x0080,
258 0x01fe,
259 0x0090,
260 0x01ff,
261 0x80a0,
262 0x01ff,
263 0xc0b0,
264 0x01ff,
265 0x0000,
266 0x0000,
267 0x0000,
268 0x0000,
269 0x0000,
270 0x0000,
271 0x0000,
272 0x0000,
273 0x0000,
274 0x0000,
275 0x0000,
276 0x0000,
277 0x0000,
278 0x0100,
279 0x0002,
280 0x0180,
281 0x0003,
282 0x01a0,
283 0x0006,
284 0x01d0,
285 0x0009,
286 0x01e8,
287 0x000b,
288 0x01f0,
289 0x000f,
290 0x01f8,
291 0x0012,
292 0x01fb,
293 0x8017,
294 0x01fd,
295 0xc01c,
296 0x01fe,
297 0x4020,
298 0x01ff,
299 0x0000,
300 0x0000,
301 0x0000,
302 0x0000,
303 0x8024,
304 0x01ff,
305 0x8225,
306 0x01ff,
307 0x0000,
308 0x0000,
309 0x0000,
310 0x0100,
311 0x0002,
312 0x0180,
313 0x0003,
314 0x01a0,
315 0x0005,
316 0x01c0,
317 0x0009,
318 0x01e0,
319 0x000d,
320 0x01f0,
321 0x0010,
322 0x01f6,
323 0x0014,
324 0x01fa,
325 0x801b,
326 0x01fd,
327 0xc020,
328 0x01fe,
329 0x4024,
330 0x01ff,
331 0x0000,
332 0x0000,
333 0x8028,
334 0x01ff,
335 0x8429,
336 0x01ff,
337 0x882b,
338 0x01ff
339 };
340 
341 static const MS_U16 g16SYMIDX_TBL[]=
342 {
343 0x0001,
344 0x0102,
345 0x0203,
346 0x0300,
347 0x1104,
348 0x0411,
349 0x0505,
350 0x2112,
351 0x3121,
352 0x0631,
353 0x1241,
354 0x4106,
355 0x5113,
356 0x0751,
357 0x6161,
358 0x7107,
359 0x1322,
360 0x2271,
361 0x3214,
362 0x8132,
363 0x0881,
364 0x1491,
365 0x42a1,
366 0x9108,
367 0xa123,
368 0xb142,
369 0xc1b1,
370 0x09c1,
371 0x2315,
372 0x3352,
373 0x52d1,
374 0xf0f0,
375 0x1524,
376 0x6233,
377 0x7262,
378 0xd172,
379 0x0a82,
380 0x1609,
381 0x240a,
382 0x3416,
383 0xe117,
384 0x2518,
385 0xf119,
386 0x171a,
387 0x1825,
388 0x1926,
389 0x1a27,
390 0x2628,
391 0x2729,
392 0x282a,
393 0x2934,
394 0x2a35,
395 0x3536,
396 0x3637,
397 0x3738,
398 0x3839,
399 0x393a,
400 0x3a43,
401 0x4344,
402 0x4445,
403 0x4546,
404 0x4647,
405 0x4748,
406 0x4849,
407 0x494a,
408 0x4a53,
409 0x5354,
410 0x5455,
411 0x5556,
412 0x5657,
413 0x5758,
414 0x5859,
415 0x595a,
416 0x5a63,
417 0x6364,
418 0x6465,
419 0x6566,
420 0x6667,
421 0x6768,
422 0x6869,
423 0x696a,
424 0x6a73,
425 0x7374,
426 0x7475,
427 0x7576,
428 0x7677,
429 0x7778,
430 0x7879,
431 0x797a,
432 0x7a83,
433 0x8284,
434 0x8385,
435 0x8486,
436 0x8587,
437 0x8688,
438 0x8789,
439 0x888a,
440 0x8992,
441 0x8a93,
442 0x9294,
443 0x9395,
444 0x9496,
445 0x9597,
446 0x9698,
447 0x9799,
448 0x989a,
449 0x99a2,
450 0x9aa3,
451 0xa2a4,
452 0xa3a5,
453 0xa4a6,
454 0xa5a7,
455 0xa6a8,
456 0xa7a9,
457 0xa8aa,
458 0xa9b2,
459 0xaab3,
460 0xb2b4,
461 0xb3b5,
462 0xb4b6,
463 0xb5b7,
464 0xb6b8,
465 0xb7b9,
466 0xb8ba,
467 0xb9c2,
468 0xbac3,
469 0xc2c4,
470 0xc3c5,
471 0xc4c6,
472 0xc5c7,
473 0xc6c8,
474 0xc7c9,
475 0xc8ca,
476 0xc9d2,
477 0xcad3,
478 0xd2d4,
479 0xd3d5,
480 0xd4d6,
481 0xd5d7,
482 0xd6d8,
483 0xd7d9,
484 0xd8da,
485 0xd9e1,
486 0xdae2,
487 0xe2e3,
488 0xe3e4,
489 0xe4e5,
490 0xe5e6,
491 0xe6e7,
492 0xe7e8,
493 0xe8e9,
494 0xe9ea,
495 0xeaf1,
496 0xf2f2,
497 0xf3f3,
498 0xf4f4,
499 0xf5f5,
500 0xf6f6,
501 0xf7f7,
502 0xf8f8,
503 0xf9f9,
504 0xfafa,
505 0x0000,
506 0x0000,
507 0x0000,
508 0x0000,
509 0x0000,
510 0x0000,
511 0x0000,
512 0x0000,
513 0x0000,
514 0x0000,
515 0x0000,
516 0x0000,
517 0x0000,
518 0x0000,
519 0x0000,
520 0x0000,
521 0x0000,
522 0x0000,
523 0x0000,
524 0x0000,
525 0x0000,
526 0x0000,
527 0x0000,
528 0x0000,
529 0x0000,
530 0x0000,
531 0x0000,
532 0x0000,
533 0x0000,
534 0x0000,
535 0x0000,
536 0x0000,
537 0x0000,
538 0x0000,
539 0x0000,
540 0x0000,
541 0x0000,
542 0x0000,
543 0x0000,
544 0x0000,
545 0x0000,
546 0x0000,
547 0x0000,
548 0x0000,
549 0x0000,
550 0x0000,
551 0x0000,
552 0x0000,
553 0x0000,
554 0x0000,
555 0x0000,
556 0x0000,
557 0x0000,
558 0x0000,
559 0x0000,
560 0x0000,
561 0x0000,
562 0x0000,
563 0x0000,
564 0x0000,
565 0x0000,
566 0x0000,
567 0x0000,
568 0x0000,
569 0x0000,
570 0x0000,
571 0x0000,
572 0x0000,
573 0x0000,
574 0x0000,
575 0x0000,
576 0x0000,
577 0x0000,
578 0x0000,
579 0x0000,
580 0x0000,
581 0x0000,
582 0x0000,
583 0x0000,
584 0x0000,
585 0x0000,
586 0x0000,
587 0x0000,
588 0x0000,
589 0x0000,
590 0x0000,
591 0x0000,
592 0x0000,
593 0x0000,
594 0x0000,
595 0x0000,
596 0x0000,
597 0x0000,
598 0x0000,
599 0x0000,
600 0x0101,
601 0x0202,
602 0x0303,
603 0x0404,
604 0x0505,
605 0x0606,
606 0x0707,
607 0x0808,
608 0x0909,
609 0x0a0a,
610 0x0b0b,
611 0x0000,
612 0x0000,
613 0x0000,
614 0x0000
615 };
616 
617 static const MS_U16 g16IQ_TBL[128]=
618 {
619 0x0010,
620 0x000b,
621 0x000a,
622 0x0010,
623 0x0018,
624 0x0028,
625 0x0033,
626 0x003d,
627 0x000c,
628 0x000c,
629 0x000e,
630 0x0013,
631 0x001a,
632 0x003a,
633 0x003c,
634 0x0037,
635 0x000e,
636 0x000d,
637 0x0010,
638 0x0018,
639 0x0028,
640 0x0039,
641 0x0045,
642 0x0038,
643 0x000e,
644 0x0011,
645 0x0016,
646 0x001d,
647 0x0033,
648 0x0057,
649 0x0050,
650 0x003e,
651 0x0012,
652 0x0016,
653 0x0025,
654 0x0038,
655 0x0044,
656 0x006d,
657 0x0067,
658 0x004d,
659 0x0018,
660 0x0023,
661 0x0037,
662 0x0040,
663 0x0051,
664 0x0068,
665 0x0071,
666 0x005c,
667 0x0031,
668 0x0040,
669 0x004e,
670 0x0057,
671 0x0067,
672 0x0079,
673 0x0078,
674 0x0065,
675 0x0048,
676 0x005c,
677 0x005f,
678 0x0062,
679 0x0070,
680 0x0064,
681 0x0067,
682 0x0063,
683 0x0011,
684 0x0012,
685 0x0018,
686 0x002f,
687 0x0063,
688 0x0063,
689 0x0063,
690 0x0063,
691 0x0012,
692 0x0015,
693 0x001a,
694 0x0042,
695 0x0063,
696 0x0063,
697 0x0063,
698 0x0063,
699 0x0018,
700 0x001a,
701 0x0038,
702 0x0063,
703 0x0063,
704 0x0063,
705 0x0063,
706 0x0063,
707 0x002f,
708 0x0042,
709 0x0063,
710 0x0063,
711 0x0063,
712 0x0063,
713 0x0063,
714 0x0063,
715 0x0063,
716 0x0063,
717 0x0063,
718 0x0063,
719 0x0063,
720 0x0063,
721 0x0063,
722 0x0063,
723 0x0063,
724 0x0063,
725 0x0063,
726 0x0063,
727 0x0063,
728 0x0063,
729 0x0063,
730 0x0063,
731 0x0063,
732 0x0063,
733 0x0063,
734 0x0063,
735 0x0063,
736 0x0063,
737 0x0063,
738 0x0063,
739 0x0063,
740 0x0063,
741 0x0063,
742 0x0063,
743 0x0063,
744 0x0063,
745 0x0063,
746 0x0063
747 };
748 
749 //-------------------------------------------------------------------------------------------------
750 //  Debug Functions
751 //-------------------------------------------------------------------------------------------------
752 
753 
754 //-------------------------------------------------------------------------------------------------
755 //  Local Functions
756 //-------------------------------------------------------------------------------------------------
_JPD_ISRHandler(MS_U32 IsrNum)757 static void _JPD_ISRHandler(MS_U32 IsrNum)
758 {
759     JPD_DEBUG_DRV_MSG("_JPD_ISRHandler: IsrNum = %ld\n", IsrNum);
760     if(_pJPDIsrCb)
761     {
762         _pJPDIsrCb();
763     }
764 }
765 
766 
767 //-------------------------------------------------------------------------------------------------
768 //  Global Functions
769 //-------------------------------------------------------------------------------------------------
770 
771 /********************************************************************/
772 ///Reset JPD -- Reset must be called before trigger JPD
773 ///@param NULL
774 ///@return none
775 /********************************************************************/
MDrv_JPD_Rst(void)776 void MDrv_JPD_Rst(void)
777 {
778     HAL_JPD_Rst();
779 }
780 
MDrv_JPD_Rst_SVLD(void)781 void MDrv_JPD_Rst_SVLD(void)
782 {
783     HAL_JPD_Rst_SVLD();
784 }
785 
786 /******************************************************************************/
787 ///
788 ///@param value \b IN
789 ///@param value \b OUT
790 ///@return status
791 /******************************************************************************/
MDrv_JPD_SetMIU(MS_U32 u32Addr)792 MS_U32 MDrv_JPD_SetMIU(MS_U32 u32Addr)
793 {
794     MS_U8 u8MiuSel;
795     MS_U32 u32Offset;
796     _phy_to_miu_offset(u8MiuSel, u32Offset, u32Addr);
797 
798     switch(u8MiuSel)
799     {
800         case 0:
801         JPD_DEBUG_DRV_MSG ("   JPD on MIU 0 !!!\n");
802             MDrv_MIU_SelMIU(MIU_CLIENT_JPD_RW, MIU_SELTYPE_MIU0);
803             break;
804         case 1:
805             JPD_DEBUG_DRV_MSG ("   JPD on MIU 1 !!!\n");
806             MDrv_MIU_SelMIU(MIU_CLIENT_JPD_RW, MIU_SELTYPE_MIU1);
807             break;
808         case 2:
809             JPD_DEBUG_DRV_MSG ("   JPD on MIU 2 !!!\n");
810             MDrv_MIU_SelMIU(MIU_CLIENT_JPD_RW, MIU_SELTYPE_MIU2);
811             break;
812         case 3:
813             JPD_DEBUG_DRV_MSG ("   JPD on MIU 3 !!!\n");
814             MDrv_MIU_SelMIU(MIU_CLIENT_JPD_RW, MIU_SELTYPE_MIU3);
815             break;
816         default:
817             JPD_DEBUG_DRV_MSG ("   JPD on MIU 0 !!!@\n");
818             MDrv_MIU_SelMIU(MIU_CLIENT_JPD_RW, MIU_SELTYPE_MIU0);
819             break;
820     }
821 
822     return u32Offset;
823 }
824 
825 /******************************************************************************/
826 ///Set RCReadBuffer for JPD
827 ///@param u32BufAddr \b IN Read buffer linear address in memory
828 ///@param u16BufSize \b IN Read buffer size
829 ///@return none
830 /******************************************************************************/
MDrv_JPD_SetReadBuffer(MS_PHYADDR u32BufAddr,MS_U32 u32BufSize)831 void MDrv_JPD_SetReadBuffer(MS_PHYADDR u32BufAddr, MS_U32 u32BufSize)
832 {
833 
834     u32BufAddr = MDrv_JPD_SetMIU(u32BufAddr);
835 
836     // set start address of read buffer
837     HAL_JPD_SetMRCBufFloorLow(( u32BufAddr >> 3 ) & 0xffff);
838     HAL_JPD_SetMRCBufFloorHigh(( u32BufAddr >> 3 ) >> 16);
839 
840     // set end address of read buffer
841     HAL_JPD_SetMRCBufCeilLow((( ( u32BufAddr + u32BufSize ) >> 3 ) - 1)& 0xffff);
842     HAL_JPD_SetMRCBufCeilHigh((( ( u32BufAddr + u32BufSize ) >> 3 ) - 1) >> 16);
843 
844     //JPD_DEBUG_DRV_MSG("BK_JPD_RBUF_FLOOR_L = %08lX\n",( u32BufAddr >> 3 ) & 0xffff);
845     //JPD_DEBUG_DRV_MSG("BK_JPD_RBUF_FLOOR_H = %08lX\n",( u32BufAddr >> 3 ) >> 16);
846     //JPD_DEBUG_DRV_MSG("BK_JPD_RBUF_CEIL_L = %08lX\n",((( u32BufAddr + u32BufSize ) >> 3) - 1) & 0xffff);
847     //JPD_DEBUG_DRV_MSG("BK_JPD_RBUF_CEIL_H = %08lX\n",((( u32BufAddr + u32BufSize ) >> 3) - 1) >> 16);
848 }
849 
850 /******************************************************************************/
851 ///Set MRC start address for JPD
852 ///@param u32ByteOffset \b IN Start address for JPD reading in MRC buffer
853 ///@return none
854 /******************************************************************************/
MDrv_JPD_SetMRCStartAddr(MS_PHYADDR u32ByteOffset)855 void MDrv_JPD_SetMRCStartAddr(MS_PHYADDR u32ByteOffset)
856 {
857     MS_U8 u8MiuSel;
858     _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
859 
860     HAL_JPD_SetRCSMAddrLow((u32ByteOffset & 0xffff));
861     HAL_JPD_SetRCSMAddrHigh((u32ByteOffset >> 16));
862     //JPD_DEBUG_DRV_MSG("BK_JPD_RCSMADR_L = %08lX\n",(u32ByteOffset & 0xffff));
863     //JPD_DEBUG_DRV_MSG("BK_JPD_RCSMADR_H = %08lX\n",(u32ByteOffset >> 16));
864 }
865 
866 /******************************************************************************/
867 ///Set output frame buffer address for JPD writing JPEG uncompressed data
868 ///@param u32BufAddr \b IN Start address for JPD reading in MRC buffer
869 ///@return none
870 /******************************************************************************/
MDrv_JPD_SetOutputFrameBuffer(MS_PHYADDR u32BufAddr,MS_U16 u16LineNum)871 void MDrv_JPD_SetOutputFrameBuffer(MS_PHYADDR u32BufAddr, MS_U16 u16LineNum)
872 {
873     MS_U8 u8MiuSel;
874     _phy_to_miu_offset(u8MiuSel, u32BufAddr, u32BufAddr);
875 
876     HAL_JPD_SetMWCBufStAddrLow(( u32BufAddr >> 3 ) & 0xffff);
877     HAL_JPD_SetMWCBufStAddrHigh(( u32BufAddr >> 3 ) >> 16);
878     //JPD_DEBUG_DRV_MSG("BK_JPD_MWBF_SADR_L = %08lX\n",( u32BufAddr >> 3 ) & 0xffff);
879     //JPD_DEBUG_DRV_MSG("BK_JPD_MWBF_SADR_H = %08lX\n",( u32BufAddr >> 3 ) >> 16);
880 
881 #if 1//defined(CHIP_T3) || defined(CHIP_T4) || defined(CHIP_T7) || defined(CHIP_JANUS) || defined(CHIP_U4) || defined(CHIP_T8) || defined(CHIP_J2)
882     HAL_JPD_SetMWBuffLineNum(u16LineNum);
883 #else
884     UNUSED(u16LineNum);
885 #endif
886 }
887 
888 /******************************************************************************/
889 ///Setting the address of JPD MRC, MWC buffer
890 ///@param JPD_BufCfg \b IN
891 /// structure {
892 ///     MS_U32 u32ThumbnailBufAddr; \b IN Thumbnail buffer address
893 ///     MS_U32 u32ThumbnailBufSize; \b IN Thumbnail buffer size
894 ///     MS_U32 u32ThumbnailBufOffset; \b IN Access byte address offset in
895 ///                                         Thumbnail buffer relative to
896 ///                                         Thumbnail start address
897 ///     MS_U32 u32MRCBufAddr; \b IN MRC buffer address
898 ///     MS_U32 u32MRCBufSize; \b IN MRC buffer size
899 ///     MS_U32 u32MRCBufOffset; \b IN Access byte address offset in MRC buffer
900 ///                                   relative to MRC start address
901 ///     MS_U32 u32MWCBufAddr; \b IN MWC buffer address
902 ///     MS_BOOL bProgressive;
903 ///     MS_BOOL bThumbnailAccessMode;
904 ///           };
905 ///@return none
906 /******************************************************************************/
MDrv_JPD_InitBuf(JPD_BufCfg in)907 void MDrv_JPD_InitBuf(JPD_BufCfg in)
908 {
909     if(in.bThumbnailAccessMode)
910     {
911         // Set MRC buffer for JPD
912         MDrv_JPD_SetReadBuffer(in.u32ThumbnailBufAddr, in.u32ThumbnailBufSize);
913         // Set MRC start access byte address
914         MDrv_JPD_SetMRCStartAddr(in.u32ThumbnailBufAddr + in.u32ThumbnailBufOffset);
915     }
916     else
917     {
918         if(in.bProgressive)
919         {
920             // Set MRC buffer for JPD
921             MDrv_JPD_SetReadBuffer(in.u32MRCBufAddr, in.u32MRCBufSize);
922             // Set MRC start access byte address
923             MDrv_JPD_SetMRCStartAddr(in.u32MRCBufAddr);
924         }
925         else
926         {
927             // Set MRC buffer for JPD
928             MDrv_JPD_SetReadBuffer(in.u32MRCBufAddr, in.u32MRCBufSize);
929             // Set MRC start access byte address
930             MDrv_JPD_SetMRCStartAddr(in.u32MRCBufAddr + in.u32MRCBufOffset);
931         }
932     }
933 
934     // Set MWC buffer for JPD
935     MDrv_JPD_SetOutputFrameBuffer(in.u32MWCBufAddr, in.u16MWCBufLineNum);
936 }
937 
938 /******************************************************************************/
939 ///Set width and height of picture
940 ///@param u16Width \b IN picture width
941 ///@param u16Height \b IN picture height
942 ///@return none
943 /******************************************************************************/
MDrv_JPD_SetPicDimension(MS_U16 u16PicWidth,MS_U16 u16PicHeight)944 void MDrv_JPD_SetPicDimension(MS_U16 u16PicWidth, MS_U16 u16PicHeight)
945 {
946     HAL_JPD_SetPic_H(( u16PicWidth >> 3 ) );
947     HAL_JPD_SetPic_V(( u16PicHeight >> 3 ) );
948 }
949 
950 /******************************************************************************/
951 ///Get JPD Event Flag
952 ///@return EventFlag
953 /******************************************************************************/
MDrv_JPD_GetEventFlag(void)954 MS_U16 MDrv_JPD_GetEventFlag(void)
955 {
956     return HAL_JPD_GetEventFlag();
957 }
958 
959 /******************************************************************************/
960 ///Set JPD Event Flag
961 ///@param u16Value \n IN EventFlag value
962 ///@return none
963 /******************************************************************************/
MDrv_JPD_SetEventFlag(MS_U16 u16Value)964 void MDrv_JPD_SetEventFlag(MS_U16 u16Value)
965 {
966     // clear by write
967     HAL_JPD_SetEventFlag(u16Value);
968 }
969 
970 /******************************************************************************/
971 ///Set ROI region
972 ///@param start_x \n IN start X position
973 ///@param start_y \n IN start Y position
974 ///@param width \n IN width
975 ///@param height \n IN height
976 ///@return none
977 /******************************************************************************/
MDrv_JPD_SetROI(MS_U16 start_x,MS_U16 start_y,MS_U16 width,MS_U16 height)978 void MDrv_JPD_SetROI(MS_U16 start_x, MS_U16 start_y, MS_U16 width, MS_U16 height)
979 {
980 //    MS_U16 reg_val;
981 
982 //    reg_val = HAL_JPD_Get_S_Config();
983 
984     HAL_JPD_SetROI_H(start_x);
985     HAL_JPD_SetROI_V(start_y);
986     HAL_JPD_SetROIWidth(width);
987     HAL_JPD_SetROIHeight(height);
988 }
989 
990 /********************************************************************/
991 ///Power On JPD
992 ///@param NULL
993 ///@return none
994 /********************************************************************/
MDrv_JPD_PowerOn(void)995 void MDrv_JPD_PowerOn(void)
996 {
997     HAL_JPD_InitRegBase();
998     HAL_JPD_PowerOn();
999     _stJPD_Status.bIsBusy = TRUE;
1000 }
1001 
1002 /********************************************************************/
1003 ///Power Off JPD
1004 ///@param NULL
1005 ///@return none
1006 /********************************************************************/
MDrv_JPD_PowerOff(void)1007 void MDrv_JPD_PowerOff(void)
1008 {
1009     HAL_JPD_PowerOff();
1010     _stJPD_Status.bIsBusy = FALSE;
1011 }
1012 
1013 /********************************************************************/
1014 ///Set RSTIntv
1015 ///@param u16Value \n IN register RSTIntv
1016 ///@return none
1017 /********************************************************************/
MDrv_JPD_SetRSTIntv(MS_U16 u16Value)1018 void MDrv_JPD_SetRSTIntv(MS_U16 u16Value)
1019 {
1020     HAL_JPD_SetRSTIntv(u16Value);
1021 }
1022 
1023 /********************************************************************/
1024 ///Get current vertical line index written to memory
1025 ///@return current vertical line index written to memory
1026 /********************************************************************/
MDrv_JPD_GetCurVidx(void)1027 MS_U16 MDrv_JPD_GetCurVidx(void)
1028 {
1029     return HAL_JPD_GetCurVidx();
1030 }
1031 
1032 #if (JPD_SUPPORT_3_HUFFMAN_TABLE==true)
1033 /********************************************************************/
1034 ///Write Grpinf of Table IndirectAccess
1035 ///@param in \b IN structure for Grpinf of Table IndirectAccess
1036 ///@return none
1037 /********************************************************************/
MDrv_JPD_WriteGrpinf(JPD_Grpinf in)1038 void MDrv_JPD_WriteGrpinf(JPD_Grpinf in)
1039 {
1040     MS_U32 reg_value;
1041     MS_U16 i, valid;
1042 
1043     HAL_JPD_Set_TID_Addr(JPD_MEM_SCWGIF_BASE);
1044 
1045     if (in.DHT)
1046     {
1047         // DC Luma
1048         for ( i = 1; i <= 16; i++ )
1049         {
1050             if(in.u8DcLumaSymbol[i] == 0xFF)
1051                 valid = 0;
1052             else
1053                 valid = 1;
1054 
1055             if ( valid )
1056             {
1057                 reg_value = ( valid << 24 ) | ( in.u16DcLumaCode[i] << 8 ) | ( in.u8DcLumaSymbol[i] << 4 );
1058             }
1059             else
1060             {
1061                 reg_value = 0;
1062             }
1063 
1064             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1065             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1066         }
1067 
1068         // AC Luma
1069         for ( i = 1; i <= 16; i++ )
1070         {
1071             if(in.u8AcLumaSymbol[i] == 0xFF)
1072                 valid = 0;
1073             else
1074                 valid = 1;
1075 
1076             if ( valid )
1077             {
1078                 reg_value = ( valid << 24 ) | ( in.u16AcLumaCode[i] << 8 ) | ( in.u8AcLumaSymbol[i] );
1079             }
1080             else
1081             {
1082                 reg_value = 0;
1083             }
1084 
1085             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1086             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1087         }
1088 
1089         // DC Chroma
1090         for ( i = 1; i <= 16; i++ )
1091         {
1092             if(in.u8DcChromaSymbol[i] == 0xFF)
1093                 valid = 0;
1094             else
1095                 valid = 1;
1096 
1097             if ( valid )
1098             {
1099                 reg_value = ( valid << 24 ) | ( in.u16DcChromaCode[i] << 8 ) | ( in.u8DcChromaSymbol[i] << 4 );
1100             }
1101             else
1102             {
1103                 reg_value = 0;
1104             }
1105 
1106             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1107             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1108         }
1109 
1110         // AC Chroma
1111         for ( i = 1; i <= 16; i++ )
1112         {
1113             if(in.u8AcChromaSymbol[i] == 0xFF)
1114                 valid = 0;
1115             else
1116                 valid = 1;
1117 
1118             if ( valid )
1119             {
1120                 reg_value = ( valid << 24 ) | ( in.u16AcChromaCode[i] << 8 ) | ( in.u8AcChromaSymbol[i] );
1121             }
1122             else
1123             {
1124                 reg_value = 0;
1125             }
1126 
1127             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1128             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1129         }
1130 
1131         if(TRUE == in.bUVHuffman)
1132         {
1133             // DC Chroma2
1134             for ( i = 1; i <= 16; i++ )
1135             {
1136                 if(in.u8DcChroma2Symbol[i] == 0xFF)
1137                     valid = 0;
1138                 else
1139                     valid = 1;
1140 
1141                 if ( valid )
1142                 {
1143                     reg_value = ( valid << 24 ) | ( in.u16DcChroma2Code[i] << 8 ) | ( in.u8DcChroma2Symbol[i] << 4 );
1144                 }
1145                 else
1146                 {
1147                     reg_value = 0;
1148                 }
1149 
1150                 HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1151                 HAL_JPD_Set_TID_Dat(reg_value >> 16);
1152             }
1153 
1154             // AC Chroma2
1155             for ( i = 1; i <= 16; i++ )
1156             {
1157                 if(in.u8AcChroma2Symbol[i] == 0xFF)
1158                     valid = 0;
1159                 else
1160                     valid = 1;
1161 
1162                 if ( valid )
1163                 {
1164                     reg_value = ( valid << 24 ) | ( in.u16AcChroma2Code[i] << 8 ) | ( in.u8AcChroma2Symbol[i] );
1165                 }
1166                 else
1167                 {
1168                     reg_value = 0;
1169                 }
1170 
1171                 HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1172                 HAL_JPD_Set_TID_Dat(reg_value >> 16);
1173             }
1174         }//if(TRUE == in.bUVHuffman)
1175     }
1176     else//if (in.DHT)
1177     {
1178         JPD_DEBUG_DRV_MSG("MDrv_JPD_WriteGrpinf : Not Support NULL huffman table!!\n");
1179     }
1180 }
1181 
1182 /********************************************************************/
1183 ///Write Symidx of Table Indirect Access
1184 ///@param in \b IN structure for Symidx of Table Indirect Access
1185 ///@return none
1186 /********************************************************************/
MDrv_JPD_WriteSymidx(JPD_Symidx in)1187 void MDrv_JPD_WriteSymidx(JPD_Symidx in)
1188 {
1189     MS_U16 i = 0;
1190     MS_U32 reg_value;
1191 
1192     HAL_JPD_Set_TID_Addr(JPD_MEM_SYMIDX_BASE);
1193 
1194     if(FALSE == in.bUVHuffman)
1195     {
1196         if (in.DHT)
1197         {
1198             for ( i = 0; i < 256; i++ )
1199             {
1200                 reg_value = ((MS_U32)(in.u8AcChromaHuffVal[i]) << 8) | (in.u8AcLumaHuffVal[i]);
1201                 HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1202                 HAL_JPD_Set_TID_Dat(0);
1203             }
1204 
1205             for ( i = 0; i < 16; i++ )
1206             {
1207                 reg_value = ((MS_U32)(in.u8DcChromaHuffVal[i]) << 8) | (in.u8DcLumaHuffVal[i]) ;
1208                 HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1209                 HAL_JPD_Set_TID_Dat(0);
1210             }
1211         }
1212         else
1213         {
1214             for(i=0;i<272;i++)
1215             {
1216                 HAL_JPD_Set_TID_Dat(g16SYMIDX_TBL[i]);
1217                 HAL_JPD_Set_TID_Dat(0);
1218             }
1219         }
1220     }
1221     else
1222     {
1223         if (in.DHT)
1224         {
1225             for ( i = 0; i < 256; i++ )
1226             {
1227                 reg_value = ((MS_U32)(in.u8AcChroma2HuffVal[i]) << 16) | ((MS_U32)(in.u8AcChromaHuffVal[i]) << 8) | (in.u8AcLumaHuffVal[i]) ;
1228                 HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1229                 HAL_JPD_Set_TID_Dat(reg_value >> 16);
1230             }
1231 
1232             for ( i = 0; i < 16; i++ )
1233             {
1234                 reg_value = ((MS_U32)(in.u8DcChroma2HuffVal[i]) << 16) | ((MS_U32)(in.u8DcChromaHuffVal[i]) << 8) | (in.u8DcLumaHuffVal[i]) ;
1235                 HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1236                 HAL_JPD_Set_TID_Dat(reg_value >> 16);
1237             }
1238         }
1239         else
1240         {
1241             JPD_DEBUG_DRV_MSG("MDrv_JPD_WriteSymidx : Not Support NULL huffman table!!\n");
1242         }
1243     }
1244 }
1245 #else
1246 /********************************************************************/
1247 ///Write Grpinf of Table IndirectAccess
1248 ///@param in \b IN structure for Grpinf of Table IndirectAccess
1249 ///@return none
1250 /********************************************************************/
MDrv_JPD_WriteGrpinf(JPD_Grpinf in)1251 void MDrv_JPD_WriteGrpinf(JPD_Grpinf in)
1252 {
1253     MS_U32 reg_value;
1254     MS_U16 i, valid;
1255 
1256     HAL_JPD_Set_TID_Addr(JPD_MEM_SCWGIF_BASE);
1257     if (in.DHT)
1258     {
1259         // DC
1260         for ( i = 1; i <= 16; i++ )
1261         {
1262             if(in.u8DcLumaSymbol[i] == 0xFF)
1263                 valid = 0;
1264             else
1265                 valid = 1;
1266 
1267             if ( valid )
1268             {
1269                 reg_value = ( valid << 24 ) | ( in.u16DcLumaCode[i] << 8 ) | ( in.u8DcLumaSymbol[i] << 4 );
1270             }
1271             else
1272             {
1273                 reg_value = 0;
1274             }
1275 
1276             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1277             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1278         }
1279 
1280         for ( i = 1; i <= 16; i++ )
1281         {
1282             if(in.u8DcChromaSymbol[i] == 0xFF)
1283                 valid = 0;
1284             else
1285                 valid = 1;
1286 
1287             if ( valid )
1288             {
1289                 reg_value = ( valid << 24 ) | ( in.u16DcChromaCode[i] << 8 ) | ( in.u8DcChromaSymbol[i] << 4 );
1290             }
1291             else
1292             {
1293                 reg_value = 0;
1294             }
1295 
1296             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1297             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1298         }
1299 
1300         // AC
1301         for ( i = 1; i <= 16; i++ )
1302         {
1303             if(in.u8AcLumaSymbol[i] == 0xFF)
1304                 valid = 0;
1305             else
1306                 valid = 1;
1307 
1308             if ( valid )
1309             {
1310                 reg_value = ( valid << 24 ) | ( in.u16AcLumaCode[i] << 8 ) | ( in.u8AcLumaSymbol[i] );
1311             }
1312             else
1313             {
1314                 reg_value = 0;
1315             }
1316 
1317             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1318             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1319         }
1320 
1321         for ( i = 1; i <= 16; i++ )
1322         {
1323             if(in.u8AcChromaSymbol[i] == 0xFF)
1324                 valid = 0;
1325             else
1326                 valid = 1;
1327 
1328             if ( valid )
1329             {
1330                 reg_value = ( valid << 24 ) | ( in.u16AcChromaCode[i] << 8 ) | ( in.u8AcChromaSymbol[i] );
1331             }
1332             else
1333             {
1334                 reg_value = 0;
1335             }
1336 
1337             HAL_JPD_Set_TID_Dat(reg_value & 0xffff);
1338             HAL_JPD_Set_TID_Dat(reg_value >> 16);
1339         }
1340 
1341     }
1342     else
1343     {
1344         for( i = 0; i < 128; i++ )
1345             HAL_JPD_Set_TID_Dat(g16GRPINFO_TBL[i]);
1346     }
1347 }
1348 
1349 /********************************************************************/
1350 ///Write Symidx of Table Indirect Access
1351 ///@param in \b IN structure for Symidx of Table Indirect Access
1352 ///@return none
1353 /********************************************************************/
MDrv_JPD_WriteSymidx(JPD_Symidx in)1354 void MDrv_JPD_WriteSymidx(JPD_Symidx in)
1355 {
1356     MS_U16 i = 0;
1357 
1358     HAL_JPD_Set_TID_Addr(JPD_MEM_SYMIDX_BASE);
1359 
1360     if (in.DHT)
1361     {
1362         for ( i = 0; i < 256; i++ )
1363         {
1364             HAL_JPD_Set_TID_Dat( (in.u8AcChromaHuffVal[i] << 8) | (in.u8AcLumaHuffVal[i]) );
1365         }
1366 
1367         for ( i = 0; i < 16; i++ )
1368         {
1369             HAL_JPD_Set_TID_Dat( (in.u8DcChromaHuffVal[i] << 8) | (in.u8DcLumaHuffVal[i]) );
1370         }
1371     }
1372     else
1373     {
1374         for(i=0;i<272;i++)
1375             HAL_JPD_Set_TID_Dat(g16SYMIDX_TBL[i]);
1376     }
1377 }
1378 #endif
1379 /********************************************************************/
1380 ///Write IQtbl of Table Indirect Access
1381 ///@param in \b IN structure for IQtbl of Table Indirect Access
1382 ///@return none
1383 /********************************************************************/
MDrv_JPD_WriteIQTbl(JPD_IQTbl in)1384 void MDrv_JPD_WriteIQTbl(JPD_IQTbl in)
1385 {
1386     MS_U8 i, j;
1387 
1388     HAL_JPD_Set_TID_Addr(JPD_MEM_QTBL_BASE);
1389 
1390     if (in.DQT)
1391     {
1392         for ( i = 0; i < in.u8CompNum; i++ )
1393         {
1394             for(j = 0; j<64; j++)
1395             {
1396                 HAL_JPD_Set_TID_Dat(in.QuantTables[in.u8CompQuant[i]].s16Value[_u8Jpeg_zigzag_order[j]]);
1397             }
1398         }
1399 
1400         // if all compoents refer to the same Qtable, need to write Qtable twice
1401         if (in.u8CompNum == 1)
1402         {
1403             //for ( i = 0; i < in.u8CompNum; i++ )
1404             {
1405                 for(j = 0; j<64; j++)
1406                 {
1407                     HAL_JPD_Set_TID_Dat(in.QuantTables[in.u8CompQuant[i]].s16Value[_u8Jpeg_zigzag_order[j]]);
1408                 }
1409             }
1410         }
1411     }
1412     else
1413     {
1414         for (i=0; i<128; i++)
1415             HAL_JPD_Set_TID_Dat(g16IQ_TBL[i]);
1416     }
1417 }
1418 
1419 /********************************************************************/
1420 ///Set MCONFIG
1421 ///@param u16Value \n IN register MCONFIG
1422 ///@return none
1423 /********************************************************************/
MDrv_JPD_Set_M_Config(MS_U16 u16Value)1424 void MDrv_JPD_Set_M_Config(MS_U16 u16Value)
1425 {
1426     HAL_JPD_Set_M_Config(u16Value);
1427 }
1428 
1429 /********************************************************************/
1430 ///Get MCONFIG
1431 ///@return MCONFIG
1432 /********************************************************************/
MDrv_JPD_Get_M_Config(void)1433 MS_U16 MDrv_JPD_Get_M_Config(void)
1434 {
1435     return HAL_JPD_Get_M_Config();
1436 }
1437 
1438 /********************************************************************/
1439 ///Set SCONFIG
1440 ///@param u16Value \n IN register SCONFIG
1441 ///@return none
1442 /********************************************************************/
MDrv_JPD_Set_S_Config(MS_U16 u16Value)1443 void MDrv_JPD_Set_S_Config(MS_U16 u16Value)
1444 {
1445     HAL_JPD_Set_S_Config(u16Value);
1446 }
1447 
1448 /********************************************************************/
1449 ///Get SCONFIG
1450 ///@return SCONFIG
1451 /********************************************************************/
MDrv_JPD_Get_S_Config(void)1452 MS_U16 MDrv_JPD_Get_S_Config(void)
1453 {
1454     return HAL_JPD_Get_S_Config();
1455 }
1456 
1457 /********************************************************************/
1458 ///Set JPD Debug level
1459 ///@para MS_U8 u8DbgLevel \b IN The JPD debug level
1460 ///@return none
1461 /********************************************************************/
MDrv_JPD_SetDbgLevel(MS_U8 u8DbgLevel)1462 void MDrv_JPD_SetDbgLevel(MS_U8 u8DbgLevel)
1463 {
1464     u8JPD_DrvDbgLevel = u8DbgLevel;
1465     HAL_JPD_SetDbgLevel(u8DbgLevel);
1466 }
1467 
1468 /********************************************************************/
1469 ///Get JPD driver information
1470 ///@param const JPD_Info *pJPD_Inf \b OUT The pointer of JPD info.
1471 ///@return none
1472 /********************************************************************/
MDrv_JPD_GetInfo(JPD_Info * pJPD_Info)1473 void MDrv_JPD_GetInfo(JPD_Info *pJPD_Info)
1474 {
1475     JPD_HAL_Version HalVer;
1476     HAL_JPD_GetLibVer(&HalVer);
1477     pJPD_Info->pu8HalVer = HalVer.pu8HalVer;
1478     pJPD_Info->pu8FwVer = HalVer.pu8FwVer;
1479     pJPD_Info->stCap = _stJPD_Cap;
1480 }
1481 
1482 /********************************************************************/
1483 ///Get JPD driver status
1484 ///@param none
1485 ///@return the pointer of JPD_Status
1486 /********************************************************************/
MDrv_JPD_GetStatus(void)1487 JPD_Status* MDrv_JPD_GetStatus(void)
1488 {
1489     _stJPD_Status.u32CurMRCAddr = HAL_JPD_GetCurMRCAddr();
1490     _stJPD_Status.u16CurVidx = HAL_JPD_GetCurVidx();
1491     _stJPD_Status.u16CurRow = HAL_JPD_GetCurRow();
1492     _stJPD_Status.u16CurCol = HAL_JPD_GetCurCol();
1493     return &_stJPD_Status;
1494 }
1495 
1496 /********************************************************************/
1497 ///Get JPD driver version
1498 ///@param MS_U8 **pVerString \b OUT JPD version
1499 ///@return TRUE/FALSE
1500 /********************************************************************/
MDrv_JPD_GetLibVer(const MSIF_Version ** ppVersion)1501 MS_BOOL MDrv_JPD_GetLibVer(const MSIF_Version **ppVersion)
1502 {
1503     if (!ppVersion)
1504     {
1505         return FALSE;
1506     }
1507     *ppVersion = &_drv_jpd_version;
1508     return TRUE;
1509 }
1510 
1511 /********************************************************************/
1512 ///Enable JPD ISR and register callback function.
1513 ///@param JPD_IsrFunc IsrCb \b IN Interrupt callback function
1514 ///@return TRUE/FALSE
1515 /********************************************************************/
MDrv_JPD_EnableISR(JPD_IsrFuncCb IsrCb)1516 MS_BOOL MDrv_JPD_EnableISR(JPD_IsrFuncCb IsrCb)
1517 {
1518     if(TRUE == _stJPD_Status.bIsrEnable)
1519     {
1520         JPD_DEBUG_DRV_MSG("JPD ISR has been enabled!!\n");
1521         return FALSE;
1522     }
1523 
1524     if(TRUE == OSAL_JPD_ISR_Attach((OSAL_JPD_IsrFuncCb)_JPD_ISRHandler))
1525     {
1526         JPD_DEBUG_DRV_MSG("Attach JPD ISR Success!!\n");
1527         if(TRUE == OSAL_JPD_ISR_Enable())
1528         {
1529             JPD_DEBUG_DRV_MSG("MDrv_JPD_EnableISR : Success!!\n");
1530             _stJPD_Status.bIsrEnable = TRUE;
1531             if(IsrCb)
1532             {
1533                 _pJPDIsrCb = IsrCb;
1534             }
1535             return TRUE;
1536         }
1537     }
1538     JPD_DEBUG_DRV_MSG("MDrv_JPD_EnableISR Failed!!\n");
1539     return FALSE;
1540 }
1541 
1542 /********************************************************************/
1543 ///Disable JPD ISR and unregister callback function.
1544 ///@param JPD_IsrFunc IsrCb \b IN Interrupt callback function
1545 ///@return TRUE/FALSE
1546 /********************************************************************/
MDrv_JPD_DisableISR(void)1547 MS_BOOL MDrv_JPD_DisableISR(void)
1548 {
1549     if(FALSE == _stJPD_Status.bIsrEnable)
1550     {
1551         JPD_DEBUG_DRV_MSG("JPD ISR has been disabled!!\n");
1552         return FALSE;
1553     }
1554 
1555     if(TRUE == OSAL_JPD_ISR_Disable())
1556     {
1557         JPD_DEBUG_DRV_MSG("Disable JPD ISR Success!!\n");
1558         if(TRUE == OSAL_JPD_ISR_Detach())
1559         {
1560             JPD_DEBUG_DRV_MSG("MDrv_JPD_DisableISR : Success!!\n");
1561             _stJPD_Status.bIsrEnable = FALSE;
1562             _pJPDIsrCb = NULL;
1563             return TRUE;
1564         }
1565     }
1566     return FALSE;
1567 }
1568 
1569 /********************************************************************/
1570 ///Get current vertical line index written to memory
1571 ///@return current vertical line index written to memory
1572 /********************************************************************/
MDrv_JPD_GetCurMRCAddr(void)1573 MS_U32 MDrv_JPD_GetCurMRCAddr(void)
1574 {
1575     return HAL_JPD_GetCurMRCAddr();
1576 }
1577 
1578 /********************************************************************/
1579 ///Get current vertical line index written to memory
1580 ///@return current vertical line index written to memory
1581 /********************************************************************/
MDrv_JPD_GetCurRow(void)1582 MS_U16 MDrv_JPD_GetCurRow(void)
1583 {
1584     return HAL_JPD_GetCurRow();
1585 }
1586 
1587 /********************************************************************/
1588 ///Get current vertical line index written to memory
1589 ///@return current vertical line index written to memory
1590 /********************************************************************/
MDrv_JPD_GetCurCol(void)1591 MS_U16 MDrv_JPD_GetCurCol(void)
1592 {
1593     return HAL_JPD_GetCurCol();
1594 }
1595 #if (JPD_SUPPORT_AUTO_PROTECT==true)
1596 /********************************************************************/
1597 ///Set write protect flag
1598 ///@return none
1599 /********************************************************************/
MDrv_JPD_SetAutoProtect(MS_BOOL enable)1600 void MDrv_JPD_SetAutoProtect(MS_BOOL enable)
1601 {
1602     HAL_JPD_SetAutoProtect(enable);
1603 }
1604 
1605 /******************************************************************************/
1606 ///Set WPEN end address for JPD
1607 ///@param u32ByteOffset \b IN End address for JPD writing to MWC buffer
1608 ///@return none
1609 /******************************************************************************/
MDrv_JPD_SetWPENEndAddr(MS_PHYADDR u32ByteOffset)1610 void MDrv_JPD_SetWPENEndAddr(MS_PHYADDR u32ByteOffset)
1611 {
1612     MS_U8 u8MiuSel;
1613     _phy_to_miu_offset(u8MiuSel, u32ByteOffset, u32ByteOffset);
1614 
1615     HAL_JPD_SetWPENAddrLow(( u32ByteOffset >> 3 ) & 0xffff);
1616     HAL_JPD_SetWPENAddrHigh(( u32ByteOffset >> 3 ) >> 16);
1617     //JPD_DEBUG_DRV_MSG("BK_JPD_MWC_WPEN_L = %08lX\n",(u32ByteOffset & 0xffff));
1618     //JPD_DEBUG_DRV_MSG("BK_JPD_MWC_WPEN_H = %08lX\n",(u32ByteOffset >> 16));
1619 }
1620 
1621 #else
1622 #if 1//defined(CHIP_T3) || defined(CHIP_T4) || defined(CHIP_T7) || defined(CHIP_JANUS) || defined(CHIP_U4) || defined(CHIP_T8) || defined(CHIP_J2)
1623 /********************************************************************/
1624 ///Set write protect flag
1625 ///@return none
1626 /********************************************************************/
MDrv_JPD_SetWriteProtect(MS_BOOL enable)1627 void MDrv_JPD_SetWriteProtect(MS_BOOL enable)
1628 {
1629     HAL_JPD_SetWriteProtect(enable);
1630 }
1631 #endif
1632 #endif
1633 /********************************************************************/
1634 ///Set Spare Register
1635 ///@param u16Value \n IN register SCONFIG
1636 ///@return none
1637 /********************************************************************/
MDrv_JPD_SetSpare(MS_U16 u16Value)1638 void MDrv_JPD_SetSpare(MS_U16 u16Value)
1639 {
1640     HAL_JPD_SetSpare(u16Value);
1641 }
1642 
1643 /********************************************************************/
1644 ///Get Spare Register
1645 ///@return Spare Register
1646 /********************************************************************/
MDrv_JPD_GetSpare(void)1647 MS_U16 MDrv_JPD_GetSpare(void)
1648 {
1649     return HAL_JPD_GetSpare();
1650 }
1651 
MDrv_JPD_PrintGTable(void)1652 void MDrv_JPD_PrintGTable(void)
1653 {
1654        MS_U16 u16Cnt;
1655        printf("====================================================================\n");
1656        printf("Print the G table..........\n");
1657        printf("====================================================================\n");
1658        MDrv_JPD_Set_S_Config(MDrv_JPD_Get_S_Config() & ~JPD_TBL_RDY);
1659         HAL_JPD_Set_TID_Addr(JPD_MEM_SCWGIF_BASE);
1660         for(u16Cnt=0; u16Cnt<128; u16Cnt++)
1661         {
1662             printf("%03d ", (MS_U8)HAL_JPD_Get_TID_Dat());
1663             if(u16Cnt%16==15)
1664             {
1665                 printf("\n");
1666             }
1667         }
1668        printf("====================================================================\n");
1669 
1670 }
1671 
MDrv_JPD_PrintHTable(void)1672 void MDrv_JPD_PrintHTable(void)
1673 {
1674        MS_U16 u16Cnt;
1675        printf("====================================================================\n");
1676        printf("Print the H table..........\n");
1677        printf("====================================================================\n");
1678        MDrv_JPD_Set_S_Config(MDrv_JPD_Get_S_Config() & ~JPD_TBL_RDY);
1679         HAL_JPD_Set_TID_Addr(JPD_MEM_SYMIDX_BASE);
1680         for(u16Cnt=0; u16Cnt<272; u16Cnt++)
1681         {
1682             printf("%03d ", (MS_U8)HAL_JPD_Get_TID_Dat());
1683             if(u16Cnt%16==15)
1684             {
1685                 printf("\n");
1686             }
1687         }
1688        printf("====================================================================\n");
1689 
1690 }
1691 
MDrv_JPD_PrintQTable(void)1692 void MDrv_JPD_PrintQTable(void)
1693 {
1694        MS_U16 u16Cnt;
1695        printf("====================================================================\n");
1696        printf("Print the Q table..........\n");
1697        printf("====================================================================\n");
1698        MDrv_JPD_Set_S_Config(MDrv_JPD_Get_S_Config() & ~JPD_TBL_RDY);
1699         HAL_JPD_Set_TID_Addr(JPD_MEM_QTBL_BASE);
1700         for(u16Cnt=0; u16Cnt<192; u16Cnt++)
1701         {
1702             printf("%03d ", (MS_U8)HAL_JPD_Get_TID_Dat());
1703             if(u16Cnt%16==15)
1704             {
1705                 printf("\n");
1706             }
1707         }
1708        printf("====================================================================\n");
1709 
1710 }
MDrv_JPD_Debug(void)1711 void MDrv_JPD_Debug(void)
1712 {
1713 //    HAL_JPD_Debug();
1714     MDrv_JPD_PrintGTable();
1715     MDrv_JPD_PrintHTable();
1716     MDrv_JPD_PrintQTable();
1717 }
1718 
1719 
1720