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