xref: /utopia/UTPA2-700.0.x/modules/mfc/hal/M7821/mfc/mdrv_mfc_film.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 #define _MDRV_MFC_FILM_C_
79 #include "mdrv_mfc_platform.h"
80 #include "mdrv_mfc.h"
81 #include "mdrv_mfc_fb.h"
82 
83 #if(CODESIZE_SEL == CODESIZE_ALL)
84 #define FILM_UNMATCH_THRESHOLD 0x20
85 #define FILM_SAME_UPPERBOUND_L 0x80 //0x80 //0x00
86 #define FILM_SAME_UPPERBOUND_H 0x01 //0x81 //0x03
87 #define FILM_CLIP_THR 0x0c
88 
89 code MST_MFC_RegUnitType_t tInitializeFilmMode[]=
90 {
91     {0x2052, 0x01},
92     #if 0
93     {0x2054, 0xFF},
94     {0x2055, 0x01},
95     #endif
96     {0x2080, 0x07},
97     {0x2081, 0x01},
98     {0x2082, FILM_UNMATCH_THRESHOLD},
99     {0x2083, 0x01},
100     {0x2084, 0x18},
101     {0x2085, 0x28},
102     {0x2086, FILM_SAME_UPPERBOUND_L},
103     {0x2087, FILM_SAME_UPPERBOUND_H},
104     {0x2088, 0x20},
105     {0x2089, 0x00},
106     {0x208A, 0x00},
107     {0x208B, 0x18},
108     {0x208C, 0x00},
109     {0x208D, 0x00},
110     {0x208E, 0x68},
111     {0x208F, 0x00},
112     {0x2090, 0x58},
113     {0x2091, 0x4a},
114     {0x2093, 0x01},
115     {0x2094, 0x00},
116     {0x2095, 0x00},
117 
118     {0x209E, 0x28},
119     {0x209F, 0x18},
120 
121     {0x20A2, FILM_CLIP_THR},
122     {0x20A3, 0x45},
123     {0x20A4, 0x10},
124     {0x20A5, 0x10},
125     {0x20A6, 0x00},
126     {0x20A7, 0x00},
127     {0x20A8, 0x00},
128     {0x20A9, 0x00},
129     {0x20AA, 0x00},
130     {0x20AB, 0x00},
131     {0x20AC, 0x00},
132     {0x20AD, 0x00},
133     {0x20AE, 0x00},
134     {0x20AF, 0x00},
135     {0x2004, 0X36},
136     {_END_OF_TBL_, _END_OF_TBL_},
137 };
138 
139 code MST_MFC_RegUnitType_t tInitializeMfc26_Common[]=
140 {
141     {0x2616, 0x12},
142     {0x2617, 0x81},
143     {0x2618, 0X20},
144     {0x2619, 0X80},
145     {0x261B, 0X14},
146     {0x261D, 0X08},
147     {0x261E, 0x02},
148 
149     {0x2622, 0x00},
150     {0x2625, 0X80},
151     {0x2628, 0x40},
152     {0x2629, 0x12},
153     {0x262A, 0X00},
154     {0x262B, 0X00},
155     {0x262C, 0X41},
156     {0x262D, 0X81},
157 
158     {0x2638, 0X00},
159     {0x2639, 0X61},
160     {0x263A, 0X80},
161     {0x263B, 0X60},
162     {0x263E, 0x80},
163     {0x263F, 0x00},
164     {0x2642, 0x05},
165     {0x2643, 0x05},
166     {0x2644, 0x42},
167     {0x2645, 0x00},
168     {0x2646, 0x10},
169     {0x2647, 0xD0},
170     {0x2648, 0x38},
171     {0x2649, 0x02},
172     {0x264A, 0x08},
173     {0x264B, 0x00},
174 
175     {0x264C, 0X00},
176     {0x264D, 0x51},
177     {0x264E, 0X08},
178     {0x264F, 0X00},
179     {0x2659, 0X00},
180     {0x2660, 0X10}, //[7]=0 090820
181     {0x2661, 0X63},
182     {0x2662, 0X1D},
183     {0x2663, 0X9E},
184     {0x2664, 0X01},
185     {0x2665, 0X01},
186     {0x2666, 0X70},
187     {0x2667, 0X01},
188     {0x2668, 0XBB},
189     {0x2669, 0X26},
190     {0x266A, 0X08},
191     {0x266B, 0X87},
192     {0x266C, 0X00},
193     {0x266D, 0X10},
194 
195     {0x2674, 0X80},
196     {0x2676, 0X08},
197     {0x2677, 0X00},
198     {0x2678, 0X00},
199     {0x2679, 0X02},
200     {0x267A, 0X88},
201     {0x267B, 0X09},
202     {0x267C, 0X3F},
203     {0x267D, 0X00},
204     {0x267E, 0X40},
205 
206     {0x2680, 0X32},
207     {0x2681, 0X02},
208     {0x2682, 0X18},
209     {0x2683, 0x03},
210     {0x2684, 0X18},
211     {0x2685, 0X30},
212     {0x2686, 0X00},
213     {0x2687, 0X20},
214     {0x2688, 0X10},
215     {0x2689, 0X10},
216     {0x268A, 0X20},
217     {0x268B, 0X10},
218     {0x268C, 0X98},
219     {0x268D, 0x20},
220     {0x268E, 0X00},
221     {0x268F, 0x00},
222     {0x2690, 0X08},
223     {0x2691, 0X20},
224     {0x2692, 0X10},
225     {0x2693, 0XF3},
226     {0x2694, 0XC0},
227     {0x2695, 0X00},
228     {0x2696, 0X40},
229     {0x2697, 0X04},
230     {0x2698, 0X40},
231     {0x2699, 0X20},
232     {0x269A, 0X3c},
233     {0x269B, 0X98},
234     {0x269C, 0X10},
235     {0x269D, 0X10},
236     {0x269E, 0X40},
237     {0x269F, 0X00},
238 
239     {0x26A0, 0X00},
240     {0x26A1, 0X40},
241     {0x26B6, 0X02},
242     {0x26B7, 0X00},
243     {0x26BC, 0XFF},
244     {0x26BD, 0X28},
245     {0x26BF, 0X01},
246     {0x26E0, 0X00},
247     {0x26E1, 0X00},
248     {0x26E2, 0X00},
249     {0x26E3, 0X00},
250     {0x26E4, 0X04},
251     {0x26E5, 0X04},
252     {0x26E6, 0XFF},
253     {0x26E7, 0X0F},
254 
255     {0x26EA, 0X00},
256     {0x26EB, 0X00},
257     {0x26EC, 0X48},
258     {0x26ED, 0X80},
259     {0x26EE, 0XF0},
260     {0x26EF, 0X01},
261     {0x26F0, 0XF4},
262     {0x26F1, 0X01},
263 
264     {0x26FC, 0X69},
265     {0x26FD, 0XD1},
266     {0x26FE, 0X80},
267     {0x26FF, 0X80},
268     {_END_OF_TBL_, _END_OF_TBL_},
269 };
270 
271 code MST_MFC_RegUnitType_t tInitializeMfc26_U01[]=
272 {
273     {0x261A, 0x00},
274     {0x261C, 0x00},
275     {_END_OF_TBL_, _END_OF_TBL_},
276 };
277 
278 code MST_MFC_RegUnitType_t tInitializeMfc26_U02[]=
279 {
280 #if 1
281     {0x261A, 0x00},
282     {0x261C, 0x00},
283     {0x266F, 0x01},
284 #else
285     {0x261A, 0x02},
286     {0x261C, 0x02},
287     {0x266F, 0X01},
288     {0x26F2, 0XFF},
289     {0x26F3, 0XFF},
290     {0x26F8, 0XFF},
291     {0x26F9, 0XFF},
292 #endif
293     {_END_OF_TBL_, _END_OF_TBL_},
294 };
295 
296 
297 #define DEFAULT_KEEP_ZERO 0x80
298 #define DEFAULT_MV0_PENALTY 0x0a
299 #define MFC_DEBUG_BLK 0    //0~7  0x290A[2:0]  --> move to
300 code MST_MFC_RegUnitType_t tInitializeMfc_Common[]=
301 {
302     // MC Settings
303     {0x2900, 0x00},
304     {0x2901, 0x00},
305     {0x2902, 0x41},
306     {0x2903, 0x38},
307 
308     // MC SETTINGS
309     {0x2908, 0XA0},
310     {0x2909, 0X03},
311     {0x290A, MFC_DEBUG_BLK},
312     {0x290B, 0X08},
313     {0x290C, 0X00},
314     {0x290D, 0X00},
315     {0x290E, 0X2F},
316     {0x290F, 0X1D},
317     {0x2910, 0XF7},
318     {0x2911, 0X13},
319     {0x2912, 0X10},
320     {0x2913, 0X0C},
321     {0x2914, 0X20},
322     {0x2915, 0XF0},
323     {0x2916, 0x10},
324     {0x2917, 0x10},
325     // GMV
326     {0x2918, 0x38},
327     {0x291A, 0x00},
328     {0x291B, 0xff},
329     {0x291E, 0x00},
330     {0x291F, 0x00},
331 
332     {0x2920, 0x00},
333     {0x2921, 0x00},
334     {0x2922, 0x00},
335     {0x2923, 0xe8},
336     {0x2924, 0x00},
337     {0x2925, 0x00},
338     {0x2926, 0x00},
339     {0x2927, 0x00},
340 
341     //{0x2928, 0X30},
342     //{0x2929, 0x1E},
343 
344     {0x292E, 0x00},
345     {0x292F, 0x08},
346     {0x292D, 0x08},
347 
348     {0x2930, 0xB3},
349     {0x2931, 0x00},
350 
351     {0x2932, 0xc2},
352     {0x2933, 0x4c},
353     {0x2934, 0x10},
354     {0x2935, 0xfe},
355     {0x2936, 0x08},
356     {0x2937, 0x08},
357     {0x2938, 0x02},
358     {0x2939, 0x04},
359 
360     {0x293A, 0XFE},
361     {0x293B, 0X7C},
362     {0x293F, 0X06},
363 
364     {0x2940, 0x40},
365     {0x2941, 0x81},
366     {0x2942, 0x10},
367     {0x2943, 0x40},
368     {0x2944, 0x01},
369     {0x2945, 0x00},
370     {0x2946, 0xff},
371     {0x2947, 0xff},
372     {0x2948, 0xff},
373     {0x2949, 0xff},
374     {0x294A, 0x77},
375     {0x294B, 0x60},
376     {0x294C, 0x02},
377     {0x294D, 0x02},
378     {0x294E, 0xB3},
379     {0x2950, 0xFF},
380     {0x2951, 0xFF},
381     {0x2953, DEFAULT_KEEP_ZERO},
382     {0x2954, 0x10},
383     {0x2955, 0x08},
384     {0x2958, 0x0c},
385     {0x2959, 0x7c},
386     {0x295A, 0x15},
387     {0x295B, 0x0c},
388     {0x295C, 0x02},
389     {0x295D, 0x80},
390     {0x295E, 0x04},
391     {0x295F, 0x04},
392 
393     {0x2960, 0x80},
394     {0x2961, 0x66},
395     {0x2962, 0x10},
396     {0x2963, 0x43},
397     {0x2964, 0x03},
398     {0x2965, 0x05},
399     {0x2966, 0x00},
400     {0x2967, DEFAULT_MV0_PENALTY},
401     {0x2968, 0x42},
402     {0x2969, 0x42},
403     {0x296C, 0x63},
404     {0x296D, 0x46},
405     {0x296E, 0x23},
406     {0x296F, 0x03},
407 
408     {0x2970, 0X03},
409     {0x2971, 0X03},
410     {0x2972, 0X08},
411     {0x2973, 0X08},
412     {0x2974, 0X14},
413     {0x2975, 0X04},
414     {0x2976, 0X06},
415     {0x2977, 0X00},
416 
417     {0x2978, 0X03},
418     {0x2979, 0X80},
419     {0x297A, 0X03},
420     {0x297B, 0X00},
421     {0x297C, 0X00},
422     {0x297D, 0X00},
423     {0x297E, 0X1F},
424     {0x297F, 0X7F},
425 
426     {0x2980, 0X02},
427     {0x2981, 0x00},
428     {0x2982, 0XF4},
429     {0x2983, 0X03},
430     {0x2984, 0X80},
431     {0x2985, 0X40},
432     {0x2988, 0X00},
433     {0x2989, 0X80},
434     {0x298C, 0x25},
435     {0x298D, 0x25},
436     {0x298E, 0x10},
437 
438     {0x2994, 0X00},
439     {0x2995, 0X00},
440     {0x2996, 0x00},
441     {0x2997, 0x00},
442     {0x2998, 0x6A},
443     {0x2999, 0X52},
444     {0x299A, 0X04},
445     {0x299B, 0X00},
446     {0x299C, 0X40},
447     {0x299D, 0XC0},
448     {0x299E, 0X2C},
449     {0x299F, 0X14},
450 
451     // MC2D_SKIP
452     {0x29A0, 0x00},
453     {0x29A1, 0xff},
454     {0x29A2, 0x00},
455     {0x29A3, 0xff},
456     {0x29A4, 0X21},
457     {0x29A5, 0XA3},
458     {0x29A6, 0X00},
459     {0x29A7, 0X00},
460     {0x29A8, 0X00},
461     {0x29A9, 0X0F},
462     {0x29AA, 0X01},
463     {0x29AB, 0X66},
464     {0x29AC, 0X80},
465     {0x29AD, 0XC2},
466     {0x29AE, 0X00},
467     {0x29AF, 0X38},
468 
469     {0x29B0, 0X30},
470     {0x29B1, 0X8E},
471     {0x29B2, 0X88},
472     {0x29B3, 0XB7},
473     {0x29B4, 0X13},
474     {0x29B5, 0X40},
475     {0x29B6, 0X09},
476     {0x29B7, 0X82},
477     {0x29B8, 0X19},
478     {0x29B9, 0X40},
479     {0x29BA, 0X00},
480     {0x29BB, 0X00},
481     {0x29BC, 0X00},
482     {0x29BD, 0X00},
483     {0x29BE, 0X00},
484     {0x29BF, 0X00},
485 
486 
487     {_END_OF_TBL_, _END_OF_TBL_},
488 };
489 code MST_MFC_RegUnitType_t tInitializeMfc_U01[]=
490 {
491     {0x293C, 0x00},
492     {0x293D, 0x00},
493     {0x294F, 0xFE},
494     {0x2956, 0x7c},
495     {0x2957, 0x3c},
496     {0x296A, 0x01},
497     {0x296B, 0x01},
498 
499 
500 
501     {_END_OF_TBL_, _END_OF_TBL_},
502 };
503 code MST_MFC_RegUnitType_t tInitializeMfc_U02[]=
504 {
505 #if 1
506     {0x293C, 0x00},
507     {0x293D, 0x00},
508 	{0x294F, 0xFF},
509     {0x2956, 0x7c},
510     {0x2957, 0x3c},
511     {0x296A, 0x01},
512     {0x296B, 0x01},
513 #else
514     {0x293C, 0xFF},
515     {0x293D, 0x5F},
516     {0x294F, 0xFF},
517     {0x2956, 0x10},
518     {0x2957, 0x08},
519     {0x296A, 0x00},
520     {0x296B, 0x00},
521 #endif
522 
523     {_END_OF_TBL_, _END_OF_TBL_},
524 };
525 
526 code MST_MFC_RegUnitType_t tInitializeMFC2C[]=
527 {
528     {0x2C12, 0x7F},
529     {0x2C13, 0xFF},
530 
531     {0x2C20, 0X32},
532     {0x2C21, 0X0A},
533     {0x2C22, 0X18},
534     {0x2C23, 0X01},
535     {0x2C2C, 0X8C},
536     {0x2C2D, 0X00},
537     {0x2C2E, 0X18},
538     {0x2C2F, 0X00},
539 
540     {0x2C30, 0X00},
541     {0x2C31, 0X40},
542     {0x2C32, 0X10},
543     {0x2C33, 0XA3},
544     {0x2C34, 0XC0},
545     {0x2C35, 0X00},
546     {0x2C36, 0X40},
547     {0x2C37, 0X07},
548     {0x2C38, 0X40},
549     {0x2C39, 0X20},
550     {0x2C3A, 0X30},
551     {0x2C3B, 0X0C},
552     {0x2C3E, 0X77},
553     {0x2C3F, 0X22},
554     {0x2C43, 0x66},
555 
556     {_END_OF_TBL_, _END_OF_TBL_},
557 };
558 
559 #define TwoChip_GarBand_H 128
560 #define MFC_H ((LimitCheck(gmfcSysInfo.u16Width, 64)/16)/2)
MDrv_MFC_InitializeMfc(void)561 void MDrv_MFC_InitializeMfc(void)
562 {
563     // Enable MR history mode & Write history MR weighting
564     MDrv_MFC_WriteByte(0x2002, 0x17 ); //[7] suchiun 090820 for OSD edge color issue
565 
566     // Pseudo Buffer Request Size and Base
567     MDrv_MFC_WriteByte(0x292A, (gmfcMiuBaseAddr.u32MfcBase>>4));     // Low byte base address
568     MDrv_MFC_WriteByte(0x292B, (gmfcMiuBaseAddr.u32MfcBase>>4)>>8);  // Mid byte base address
569     MDrv_MFC_WriteByte(0x2928, (gmfcMiuBaseAddr.u32MfcBase>>4)>>16); // High byte base address
570      #if( TwoChip_Func != TwoChip_OFF )
571            MDrv_MFC_Write2Bytes(0x2904, LimitCheck(gmfcSysInfo.u16Width/2, 64)+ TwoChip_GarBand_H); //ME
572      #else
573         MDrv_MFC_Write2Bytes(0x2904, LimitCheck(gmfcSysInfo.u16Width, 64));
574     #endif
575     MDrv_MFC_Write2Bytes(0x2906, LimitCheck(gmfcSysInfo.u16Height, 16));
576     if (gmfcSysInfo.u16Width > 1400 )
577         MDrv_MFC_WriteByte(0x2919, 0x25);
578     else
579         MDrv_MFC_WriteByte(0x2919, 0x24);
580     MDrv_MFC_WriteByte(0x291C, 0x10);
581     MDrv_MFC_WriteByte(0x291D, (gmfcSysInfo.u16Height>>3)-0x10);
582     MDrv_MFC_WriteByte(0x293E, 0x28 |(((LimitCheck(gmfcSysInfo.u16Width, 64) - gmfcSysInfo.u16Width)/16)&0x3));
583 
584     if (gmfcSysInfo.u16Width == 1920 )
585         MDrv_MFC_WriteByte(0x2952, 0x4F);
586     else // 1366, 1680
587         MDrv_MFC_WriteByte(0x2952, 0x5F);
588 
589      #if( TwoChip_Func != TwoChip_OFF )
590         MDrv_MFC_Write2Bytes(0x2990, gmfcSysInfo.u16Width/2 + TwoChip_GarBand_H); //MI
591      #else
592         MDrv_MFC_Write2Bytes(0x2990, gmfcSysInfo.u16Width);
593     #endif
594     MDrv_MFC_Write2Bytes(0x2992, gmfcSysInfo.u16Height);
595     MDrv_MFC_WriteRegsTbl(0x2900, tInitializeMfc_Common);
596     MDrv_MFC_WriteRegsTbl(0x2600, tInitializeMfc26_Common);
597     MDrv_MFC_WriteRegsTbl(0x2C00, tInitializeMFC2C);
598     if(gmfcSysInfo.u8ChipRevision==1)
599     {
600         MDrv_MFC_WriteRegsTbl(0x2900, tInitializeMfc_U02);
601         MDrv_MFC_WriteRegsTbl(0x2600, tInitializeMfc26_U02);
602     }
603     else// if(gmfcSysInfo.u8ChipRevision==U01)
604     {
605         MDrv_MFC_WriteRegsTbl(0x2900, tInitializeMfc_U01);
606         MDrv_MFC_WriteRegsTbl(0x2600, tInitializeMfc26_U01);
607     }
608 
609     #if( TwoChip_Func != TwoChip_OFF ) //j090609
610         MDrv_MFC_WriteByte(0x2929, MFC_H|_BIT6);
611     #else
612         MDrv_MFC_WriteByte(0x2929, MFC_H/2);
613     #endif
614 }
615 
MDrv_MFC_InitializeFilmMode(void)616 void MDrv_MFC_InitializeFilmMode(void)
617 {
618     MDrv_MFC_WriteRegsTbl(0x2000, tInitializeFilmMode); // initialize all of bank
619     #if 0
620     if(gmfcSysInfo.u8ChipRevision == 1)
621     {
622         MDrv_MFC_WriteByte(0x2092, 0x66);  // U02 new setting, U01 can not apply this.
623     }
624     #endif
625     MDrv_MFC_InitializeMfc();
626 }
627 #endif
628 
629 
630