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 ////////////////////////////////////////////////////////////////////////////////#include <stdio.h>
94 #define DRV_GOPSC_EX_C
95
96 #include "MsCommon.h"
97 #include "MsOS.h"
98
99 #include "drvGOPSCD.h"
100 #include "halGOPSCD.h"
101 #include "regGOPSCD.h"
102
103 #ifdef MSOS_TYPE_LINUX_KERNEL
104 #include <linux/string.h>
105 #include <asm/div64.h>
106 #else
107 #include <string.h>
108 //#define do_div(x,y) ((x)/=(y))
109 #endif
110
111
112 //-------------------------------------------------------------------------------------------------
113 // Local Defines
114 //-------------------------------------------------------------------------------------------------
115
116 typedef struct
117 {
118 MS_U16 xSkipStart;
119 MS_U16 xSkipEnd;
120 MS_U16 ySkipStart;
121 MS_U16 ySkipEnd;
122 MS_U16 srcWidth;
123 MS_U16 destWidth;
124 MS_U16 srcHeight;
125 MS_U16 destHeight;
126 MS_BOOL bSkipX;
127 MS_BOOL bSkipY;
128 MS_BOOL bScalingX;
129 MS_BOOL bScalingY;
130 }Drv_GOPSC_SizeInfo;
131
132 Drv_GOPSC_SizeInfo dataGOPSC_SizeInfo;
133 static MS_U8 u8formula = 1; //0 - Not P2I formula, 1 - P2I formula
134
_HalDrvResultConvert(GOPSC_Hal_Result halRet)135 static GOPSC_Drv_Result _HalDrvResultConvert(GOPSC_Hal_Result halRet)
136 {
137 GOPSC_Drv_Result drvRet = En_Drv_GOPSC_FAIL;
138 switch(halRet)
139 {
140 case En_Hal_GOPSC_OK:
141 drvRet = En_Drv_GOPSC_OK;
142 break;
143 case En_Hal_GOPSC_INVALID_PARAM:
144 drvRet = En_Drv_GOPSC_INVALID_PARAM;
145 break;
146 case En_Hal_GOPSC_NotSupport:
147 drvRet = En_Drv_GOPSC_NotSupport;
148 break;
149 case En_Hal_GOPSC_FAIL:
150 default:
151 drvRet = En_Drv_GOPSC_FAIL;
152 }
153 return drvRet;
154 }
155
MDrv_GOPSC_Init_riu_base(MS_U32 DeviceId,MS_VIRT virtriu_base)156 GOPSC_Drv_Result MDrv_GOPSC_Init_riu_base(MS_U32 DeviceId, MS_VIRT virtriu_base)
157 {
158 return _HalDrvResultConvert(HAL_GOPSC_Init_riu_base(virtriu_base));
159 }
160
MDrv_GOPSC_Init(MS_U32 DeviceId)161 GOPSC_Drv_Result MDrv_GOPSC_Init(MS_U32 DeviceId)
162 {
163 //Initial Local Variable
164 //memset(&gGopSC_Ref, 0 , sizeof(GOP_SC_REF) );
165 //memset(&gGopSC_Info, 0 , sizeof(DRV_GOP_SC_INFO) );
166
167 //GOP_Rdy reg always trigger
168 MS_U16 value = HAL_GOPSC_Read2Byte(REG_GOP_SC_00_L);
169 value |= 0x40;
170 HAL_GOPSC_Write2Byte(REG_GOP_SC_00_L,value);
171 //No matter Cubic mode or bilinear mode, always set PQ table in initial phase
172 HAL_GOPSC_InitTable();
173 //Default scaling mode is cubic
174 HAL_GOPSC_SetVScalingMode(CUBIC); //init use cubic mode
175 //source 0 is GOP, 1 is OP.
176 HAL_GOPSC_MuxSel(0); //init source is GOP
177 memset(&dataGOPSC_SizeInfo,0,sizeof(dataGOPSC_SizeInfo));
178 return En_Drv_GOPSC_OK;
179 }
180
MDrv_GOPSC_Enable(MS_U32 DeviceId,MS_BOOL enable)181 GOPSC_Drv_Result MDrv_GOPSC_Enable(MS_U32 DeviceId, MS_BOOL enable)
182 {
183 MS_U16 value = HAL_GOPSC_Read2Byte(REG_GOP_SC_00_L);
184 if(TRUE == enable)
185 {
186 value |= 0x8000;
187 }
188 else
189 {
190 value &= ~0x8000;
191 }
192 HAL_GOPSC_Write2Byte(REG_GOP_SC_00_L,value);
193 return En_Drv_GOPSC_OK;
194 }
195
MDrv_GOPSC_SetSource(MS_U32 DeviceId,MS_U8 u8SelSrc)196 GOPSC_Drv_Result MDrv_GOPSC_SetSource(MS_U32 DeviceId, MS_U8 u8SelSrc)
197 {
198 return _HalDrvResultConvert(HAL_GOPSC_MuxSel(u8SelSrc));
199 }
200
MDrv_GOPSC_SetVScalingMode(MS_U32 DeviceId,MS_U8 mode)201 GOPSC_Drv_Result MDrv_GOPSC_SetVScalingMode(MS_U32 DeviceId, MS_U8 mode)
202 {
203 //Initial Local Variable
204 return _HalDrvResultConvert(HAL_GOPSC_SetVScalingMode(mode));
205 }
206
MDrv_GOPSC_SetHVSP(MS_U32 DeviceId,MS_BOOL bHspEnable,MS_BOOL bVspEnable,MS_U16 srcWidth,MS_U16 srcHeight,MS_U16 destWidth,MS_U16 destHeight)207 GOPSC_Drv_Result MDrv_GOPSC_SetHVSP(MS_U32 DeviceId, MS_BOOL bHspEnable, MS_BOOL bVspEnable, MS_U16 srcWidth, MS_U16 srcHeight,MS_U16 destWidth, MS_U16 destHeight)
208 {
209 //while driver change size, enter scaling factor also
210 //H factor = (output * 1048576 / input) +1
211 //V factor = ((input-1) * 1048576 / (output-1)) +1
212
213 //V factor = (input) * 1048576 / (output) if GOP use GOPSC result and do P2I
214 MS_U32 HScaleFac = (bHspEnable)? (destWidth * 1048576 / srcWidth) + 1 : 0;
215 MS_U32 VScaleFac = 0x100000;
216 if(bVspEnable)
217 {
218 if(u8formula == 1)
219 {
220 VScaleFac = ((srcHeight) * 1048576 / (destHeight));
221 }
222 else
223 {
224 VScaleFac = (((srcHeight - 1) * 1048576 / (destHeight - 1)) + 1);
225 }
226 }
227 if(destWidth == srcWidth)
228 {
229 HScaleFac = 0;
230 }
231 if(srcHeight == destHeight)
232 {
233 if(u8formula == 1)
234 {
235 VScaleFac = 0x100000;
236 }
237 else
238 {
239 VScaleFac = 0x100001;
240 }
241 }
242 if(HScaleFac != 0)
243 {
244 HAL_GOPSC_Write2Byte(REG_GOP_SC_38_L,destWidth);
245 }
246 else
247 {
248 HAL_GOPSC_Write2Byte(REG_GOP_SC_38_L,srcWidth);
249 }
250
251 if(VScaleFac != 0)
252 {
253 HAL_GOPSC_Write2Byte(REG_GOP_SC_52_L,destHeight);
254 }
255 else
256 {
257 HAL_GOPSC_Write2Byte(REG_GOP_SC_52_L,srcHeight);
258 }
259
260 GOPSC_Hal_Result ret = HAL_GOPSC_SetHVSP(srcWidth,srcHeight,destWidth,destHeight);
261
262 if(En_Hal_GOPSC_OK != ret)
263 {
264 return _HalDrvResultConvert(ret);
265 }
266
267 return _HalDrvResultConvert(HAL_GOPSC_Set_ScalingFactor(VScaleFac,HScaleFac));
268 }
269
MDrv_GOPSC_SetSkipPixel(MS_U32 DeviceId,MS_U8 bSkipX,MS_U8 bSkipY,MS_U16 xStart,MS_U16 xEnd,MS_U16 yStart,MS_U16 yEnd)270 GOPSC_Drv_Result MDrv_GOPSC_SetSkipPixel(MS_U32 DeviceId, MS_U8 bSkipX, MS_U8 bSkipY,
271 MS_U16 xStart, MS_U16 xEnd,MS_U16 yStart, MS_U16 yEnd)
272 {
273 return _HalDrvResultConvert(HAL_GOPSC_SetSkipPixel(bSkipX, bSkipY, xStart, xEnd, yStart, yEnd));
274 }
275
MDrv_GOPSC_SetFieldStartPosition(MS_U32 DeviceId,MS_BOOL bEnable,MS_U16 topFieldOffset,MS_U16 bottomFieldOffset)276 GOPSC_Drv_Result MDrv_GOPSC_SetFieldStartPosition(MS_U32 DeviceId, MS_BOOL bEnable,
277 MS_U16 topFieldOffset, MS_U16 bottomFieldOffset)
278 {
279 //FieldOffset register is 8 bits in K3. for feature extension, use MS_U16
280 return _HalDrvResultConvert(HAL_GOPSC_Set_FieldStartPosition(bEnable,topFieldOffset,bottomFieldOffset));
281 }
282
MDrv_GOPSC_SetDelayLineNumber(MS_U32 DeviceId,MS_U16 dlyLine)283 GOPSC_Drv_Result MDrv_GOPSC_SetDelayLineNumber(MS_U32 DeviceId, MS_U16 dlyLine)
284 {
285 MS_U16 value = HAL_GOPSC_Read2Byte(REG_GOP_SC_3F_L);
286 value &= ~0xff;
287 value |= (dlyLine & 0xff);
288 HAL_GOPSC_Write2Byte(REG_GOP_SC_3F_L,value);
289 return En_Drv_GOPSC_OK;
290 }
291
MDrv_GOPSC_P2IEnable(MS_U32 DeviceId,MS_BOOL enable)292 GOPSC_Drv_Result MDrv_GOPSC_P2IEnable(MS_U32 DeviceId, MS_BOOL enable)
293 {
294 return _HalDrvResultConvert(HAL_GOPSC_P2I(enable));
295 }
296
MDrv_GOPSC_HalfMode(MS_U32 DeviceId,MS_BOOL enable)297 GOPSC_Drv_Result MDrv_GOPSC_HalfMode(MS_U32 DeviceId, MS_BOOL enable)
298 {
299 MS_U16 value = HAL_GOPSC_Read2Byte(REG_GOP_SC_00_L);
300 if(TRUE == enable)
301 {
302 value |= 0x4000;
303 }
304 else
305 {
306 value &= ~0x4000;
307 }
308 HAL_GOPSC_Write2Byte(REG_GOP_SC_00_L,value);
309 return En_Drv_GOPSC_OK;
310 }
311
MDrv_GOPSC_TriggerOnce(MS_U32 DeviceId,MS_U8 FrameNum)312 GOPSC_Drv_Result MDrv_GOPSC_TriggerOnce(MS_U32 DeviceId, MS_U8 FrameNum)
313 {
314 return _HalDrvResultConvert(HAL_GOPSC_TriggerOnce(FrameNum));
315 }
316
MDrv_GOPSC_SetOutputControlRate(MS_U32 DeviceId,MS_BOOL bEnable,MS_U16 SrcWidth,MS_U16 SrcHeight,MS_U16 DestWidth,MS_U16 DestHeight,MS_BOOL bInterlace)317 GOPSC_Drv_Result MDrv_GOPSC_SetOutputControlRate(MS_U32 DeviceId, MS_BOOL bEnable,
318 MS_U16 SrcWidth, MS_U16 SrcHeight, MS_U16 DestWidth, MS_U16 DestHeight, MS_BOOL bInterlace)
319 {
320 //FieldOffset register is 8 bits in K3. for feature extension, use MS_U16
321 MS_U16 value = HAL_GOPSC_Read2Byte(REG_GOP_SC_55_L);
322 if(bEnable)
323 {
324 //OUT_RATE = DST_HSIZE*(DST_VSIZE>>P2I)*256/SRC_HSIZE/SRC_VSIZE;
325 MS_U32 OutRate = (((MS_U32)DestWidth*((MS_U32)DestHeight>>(bInterlace)? 1 : 0)*256)/(MS_U32)SrcWidth)/(MS_U32)SrcHeight;
326 value &= ~0xff;
327 value |= (OutRate & 0xff);
328 }
329 else
330 {
331 value &= ~0xff;
332 value |= 0x0;
333 }
334 HAL_GOPSC_Write2Byte(REG_GOP_SC_55_L,value);
335 return En_Drv_GOPSC_OK;
336 }
337
MDrv_GOPSC_SetScalingFormula(MS_U32 DeviceId,MS_U8 Formula)338 GOPSC_Drv_Result MDrv_GOPSC_SetScalingFormula(MS_U32 DeviceId, MS_U8 Formula)
339 {
340 u8formula = Formula;
341 return En_Drv_GOPSC_OK;
342 }
343
344
345