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