1dfe64dd3Smacallan/* Copyright (C) 2003-2006 by XGI Technology, Taiwan.
2dfe64dd3Smacallan *
3dfe64dd3Smacallan * All Rights Reserved.
4dfe64dd3Smacallan *
5dfe64dd3Smacallan * Permission is hereby granted, free of charge, to any person obtaining
6dfe64dd3Smacallan * a copy of this software and associated documentation files (the
7dfe64dd3Smacallan * "Software"), to deal in the Software without restriction, including
8dfe64dd3Smacallan * without limitation on the rights to use, copy, modify, merge,
9dfe64dd3Smacallan * publish, distribute, sublicense, and/or sell copies of the Software,
10dfe64dd3Smacallan * and to permit persons to whom the Software is furnished to do so,
11dfe64dd3Smacallan * subject to the following conditions:
12dfe64dd3Smacallan *
13dfe64dd3Smacallan * The above copyright notice and this permission notice (including the
14dfe64dd3Smacallan * next paragraph) shall be included in all copies or substantial
15dfe64dd3Smacallan * portions of the Software.
16dfe64dd3Smacallan *
17dfe64dd3Smacallan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18dfe64dd3Smacallan * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19dfe64dd3Smacallan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20dfe64dd3Smacallan * NON-INFRINGEMENT.  IN NO EVENT SHALL XGI AND/OR
21dfe64dd3Smacallan *  ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22dfe64dd3Smacallan * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23dfe64dd3Smacallan * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24dfe64dd3Smacallan * DEALINGS IN THE SOFTWARE.
25dfe64dd3Smacallan */
26dfe64dd3Smacallan
27dfe64dd3Smacallan/****************************************************************************
28dfe64dd3Smacallan* raw register access : these routines directly interact with the xgi's
29dfe64dd3Smacallan*                       control aperature.  must not be called until after
30dfe64dd3Smacallan*                       the board's pci memory has been mapped.
31dfe64dd3Smacallan****************************************************************************/
32dfe64dd3Smacallan
33dfe64dd3Smacallan#ifdef HAVE_CONFIG_H
34dfe64dd3Smacallan#include "config.h"
35dfe64dd3Smacallan#endif
36dfe64dd3Smacallan
37dfe64dd3Smacallan#define XGI_VIDEO_HW /* avoid compile error in xgi.h; weird!  */
38dfe64dd3Smacallan#include "xgi.h"
39dfe64dd3Smacallan
40dfe64dd3Smacallan#include "xgi_videohw.h"
41dfe64dd3Smacallan#include "xgi_video.h"
42dfe64dd3Smacallan#include "fourcc.h"
43dfe64dd3Smacallan
44dfe64dd3Smacallan#define  CAPTURE_340A1
45dfe64dd3Smacallan/*
46dfe64dd3Smacallanstatic CARD32 _XGIRead(XGIPtr pXGI, CARD32 reg)
47dfe64dd3Smacallan{
48dfe64dd3Smacallan    return *(pXGI->IOBase + reg);
49dfe64dd3Smacallan}
50dfe64dd3Smacallan
51dfe64dd3Smacallanstatic void _XGIWrite(XGIPtr pXGI, CARD32 reg, CARD32 data)
52dfe64dd3Smacallan{
53dfe64dd3Smacallan    *(pXGI->IOBase + reg) = data;
54dfe64dd3Smacallan}
55dfe64dd3Smacallan*/
56dfe64dd3Smacallanstatic CARD8 GetVideoReg(XGIPtr pXGI, CARD8 reg)
57dfe64dd3Smacallan{
58dfe64dd3Smacallan    outb (pXGI->RelIO + vi_index_offset, reg);
59dfe64dd3Smacallan    return inb(pXGI->RelIO + vi_data_offset);
60dfe64dd3Smacallan}
61dfe64dd3Smacallan
62dfe64dd3Smacallanstatic void SetVideoReg(XGIPtr pXGI, CARD8 reg, CARD8 data)
63dfe64dd3Smacallan{
64dfe64dd3Smacallan    outb (pXGI->RelIO + vi_index_offset, reg);
65dfe64dd3Smacallan    outb (pXGI->RelIO + vi_data_offset, data);
66dfe64dd3Smacallan}
67dfe64dd3Smacallan
68dfe64dd3Smacallanstatic void SetVideoRegMask(XGIPtr pXGI, CARD8 reg, CARD8 data, CARD8 mask)
69dfe64dd3Smacallan{
70dfe64dd3Smacallan    CARD8   old;
71dfe64dd3Smacallan
72dfe64dd3Smacallan    outb (pXGI->RelIO + vi_index_offset, reg);
73dfe64dd3Smacallan    old = inb(pXGI->RelIO + vi_data_offset);
74dfe64dd3Smacallan    data = (data & mask) | (old & (~mask));
75dfe64dd3Smacallan    outb (pXGI->RelIO + vi_data_offset, data);
76dfe64dd3Smacallan}
77dfe64dd3Smacallan
78dfe64dd3Smacallanstatic CARD8 GetSRReg(XGIPtr pXGI, CARD8 reg)
79dfe64dd3Smacallan{
80dfe64dd3Smacallan    outb (pXGI->RelIO + sr_index_offset, 0x05);
81dfe64dd3Smacallan    if (inb (pXGI->RelIO + sr_data_offset) != 0xa1)
82dfe64dd3Smacallan            outb (pXGI->RelIO + sr_data_offset, 0x86);
83dfe64dd3Smacallan    outb (pXGI->RelIO + sr_index_offset, reg);
84dfe64dd3Smacallan    return inb(pXGI->RelIO + sr_data_offset);
85dfe64dd3Smacallan}
86dfe64dd3Smacallan
87dfe64dd3Smacallanstatic void SetSRReg(XGIPtr pXGI, CARD8 reg, CARD8 data)
88dfe64dd3Smacallan{
89dfe64dd3Smacallan    outb (pXGI->RelIO + sr_index_offset, 0x05);
90dfe64dd3Smacallan    if (inb (pXGI->RelIO + sr_data_offset) != 0xa1)
91dfe64dd3Smacallan            outb (pXGI->RelIO + sr_data_offset, 0x86);
92dfe64dd3Smacallan    outb (pXGI->RelIO + sr_index_offset, reg);
93dfe64dd3Smacallan    outb (pXGI->RelIO + sr_data_offset, data);
94dfe64dd3Smacallan}
95dfe64dd3Smacallan
96dfe64dd3Smacallanvoid SetSRRegMask(XGIPtr pXGI, CARD8 reg, CARD8 data, CARD8 mask)
97dfe64dd3Smacallan{
98dfe64dd3Smacallan    CARD8   old;
99dfe64dd3Smacallan
100dfe64dd3Smacallan    outb (pXGI->RelIO + sr_index_offset, 0x05);
101dfe64dd3Smacallan    if (inb (pXGI->RelIO + sr_data_offset) != 0xa1)
102dfe64dd3Smacallan            outb (pXGI->RelIO + sr_data_offset, 0x86);
103dfe64dd3Smacallan    outb (pXGI->RelIO + sr_index_offset, reg);
104dfe64dd3Smacallan    old = inb(pXGI->RelIO + sr_data_offset);
105dfe64dd3Smacallan    data = (data & mask) | (old & (~mask));
106dfe64dd3Smacallan    outb (pXGI->RelIO + sr_data_offset, data);
107dfe64dd3Smacallan}
108dfe64dd3Smacallan/*
109dfe64dd3Smacallanstatic void SetVCReg(XGIPtr pXGI, CARD8 reg, CARD8 data)
110dfe64dd3Smacallan{
111dfe64dd3Smacallan    outb (pXGI->RelIO + vc_index_offset, reg);
112dfe64dd3Smacallan    outb (pXGI->RelIO + vc_data_offset, data);
113dfe64dd3Smacallan}
114dfe64dd3Smacallan*/
115dfe64dd3Smacallanstatic void SetVCRegMask(XGIPtr pXGI, CARD8 reg, CARD8 data, CARD8 mask)
116dfe64dd3Smacallan{
117dfe64dd3Smacallan    CARD8   old;
118dfe64dd3Smacallan
119dfe64dd3Smacallan    outb (pXGI->RelIO + vc_index_offset, reg);
120dfe64dd3Smacallan    old = inb(pXGI->RelIO + vc_data_offset);
121dfe64dd3Smacallan    data = (data & mask) | (old & (~mask));
122dfe64dd3Smacallan    outb (pXGI->RelIO + vc_data_offset, data);
123dfe64dd3Smacallan}
124dfe64dd3Smacallan/*
125dfe64dd3Smacallanstatic CARD8 GetXGIReg(XGIPtr pXGI, CARD8 index_offset, CARD8 reg)
126dfe64dd3Smacallan{
127dfe64dd3Smacallan    outb (pXGI->RelIO + index_offset, reg);
128dfe64dd3Smacallan    return inb(pXGI->RelIO + index_offset+1);
129dfe64dd3Smacallan}
130dfe64dd3Smacallan
131dfe64dd3Smacallanstatic void SetXGIReg(XGIPtr pXGI, CARD8 index_offset, CARD8 reg, CARD8 data)
132dfe64dd3Smacallan{
133dfe64dd3Smacallan    outb (pXGI->RelIO + index_offset, reg);
134dfe64dd3Smacallan    outb (pXGI->RelIO + index_offset+1, data);
135dfe64dd3Smacallan}
136dfe64dd3Smacallan*/
137dfe64dd3Smacallanstatic float tap_dda_func(float x)
138dfe64dd3Smacallan{
139dfe64dd3Smacallan    double pi = 3.14159265358979;
140dfe64dd3Smacallan    float r = 0.5;
141dfe64dd3Smacallan    float y;
142dfe64dd3Smacallan
143dfe64dd3Smacallan    if (x == 0)
144dfe64dd3Smacallan            y = 1.0;
145dfe64dd3Smacallan    else if ((x == -1.0/(2.0*r)) || (x == 1.0/(2.0*r)))
146dfe64dd3Smacallan            y = (float) (r/2.0 * sin(pi/(2.0*r)));
147dfe64dd3Smacallan    else
148dfe64dd3Smacallan            y = (float) (sin(pi*x)/(pi*x)*cos(r*pi*x)/(1-4*r*r*x*x));
149dfe64dd3Smacallan
150dfe64dd3Smacallan    return y;
151dfe64dd3Smacallan}
152dfe64dd3Smacallan
153dfe64dd3Smacallan/* ----------------T05_EnableCapture()---------------- */
154dfe64dd3Smacallan#ifdef CAPTURE_340A1
155dfe64dd3Smacallanvoid SetEnableCaptureReg(XGIPtr pXGI, Bool bEnable, Bool bFlip)
156dfe64dd3Smacallan{
157dfe64dd3Smacallan   if (bEnable)
158dfe64dd3Smacallan   {
159dfe64dd3Smacallan      SetVCRegMask(pXGI, Index_VC_Ver_Down_Scale_Factor_Over, 0x00, 0x10);
160dfe64dd3Smacallan
161dfe64dd3Smacallan      if (pXGI->Chipset == PCI_CHIP_XGIXG40)
162dfe64dd3Smacallan         SetVideoRegMask(pXGI, Index_VI_Key_Overlay_OP, 0x20, 0x20);
163dfe64dd3Smacallan      else
164dfe64dd3Smacallan         SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x01, 0x01);
165dfe64dd3Smacallan   }
166dfe64dd3Smacallan   else
167dfe64dd3Smacallan   {
168dfe64dd3Smacallan      SetVCRegMask(pXGI, Index_VC_Ver_Down_Scale_Factor_Over, 0x10, 0x10);
169dfe64dd3Smacallan
170dfe64dd3Smacallan      if (pXGI->Chipset == PCI_CHIP_XGIXG40)
171dfe64dd3Smacallan         SetVideoRegMask(pXGI, Index_VI_Key_Overlay_OP, 0x00, 0x20);
172dfe64dd3Smacallan      else
173dfe64dd3Smacallan         SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x00, 0x01);
174dfe64dd3Smacallan   }
175dfe64dd3Smacallan
176dfe64dd3Smacallan
177dfe64dd3Smacallan   if (pXGI->Chipset == PCI_CHIP_XGIXG40)
178dfe64dd3Smacallan   {
179dfe64dd3Smacallan      if(bFlip)
180dfe64dd3Smacallan         SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x01, 0x01);
181dfe64dd3Smacallan      else
182dfe64dd3Smacallan         SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x00, 0x01);
183dfe64dd3Smacallan   }
184dfe64dd3Smacallan}
185dfe64dd3Smacallan#else
186dfe64dd3Smacallanvoid T05_EnableCapture(XGIPtr pXGI, Bool bEnable)
187dfe64dd3Smacallan{
188dfe64dd3Smacallan   if (bEnable)
189dfe64dd3Smacallan   {
190dfe64dd3Smacallan      SetVCRegMask(pXGI, Index_VC_Ver_Down_Scale_Factor_Over, 0x00, 0x10);
191dfe64dd3Smacallan      SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x01, 0x01);
192dfe64dd3Smacallan   }
193dfe64dd3Smacallan   else
194dfe64dd3Smacallan   {
195dfe64dd3Smacallan      SetVCRegMask(pXGI, Index_VC_Ver_Down_Scale_Factor_Over, 0x10, 0x10);
196dfe64dd3Smacallan      SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x00, 0x01);
197dfe64dd3Smacallan   }
198dfe64dd3Smacallan}
199dfe64dd3Smacallan#endif
200dfe64dd3Smacallan
201dfe64dd3Smacallanstatic void
202dfe64dd3SmacallanXGIComputeXvGamma(XGIPtr pXGI)
203dfe64dd3Smacallan{
204dfe64dd3Smacallan    int num = 255, i;
205dfe64dd3Smacallan    double red = 1.0 / (double)((double)pXGI->XvGammaRed / 1000);
206dfe64dd3Smacallan    double green = 1.0 / (double)((double)pXGI->XvGammaGreen / 1000);
207dfe64dd3Smacallan    double blue = 1.0 / (double)((double)pXGI->XvGammaBlue / 1000);
208dfe64dd3Smacallan
209dfe64dd3Smacallan    for(i = 0; i <= num; i++) {
210dfe64dd3Smacallan        pXGI->XvGammaRampRed[i] =
211dfe64dd3Smacallan	    (red == 1.0) ? i : (CARD8)(pow((double)i / (double)num, red) * (double)num + 0.5);
212dfe64dd3Smacallan
213dfe64dd3Smacallan		pXGI->XvGammaRampGreen[i] =
214dfe64dd3Smacallan	    (green == 1.0) ? i : (CARD8)(pow((double)i / (double)num, green) * (double)num + 0.5);
215dfe64dd3Smacallan
216dfe64dd3Smacallan		pXGI->XvGammaRampBlue[i] =
217dfe64dd3Smacallan	    (blue == 1.0) ? i : (CARD8)(pow((double)i / (double)num, blue) * (double)num + 0.5);
218dfe64dd3Smacallan    }
219dfe64dd3Smacallan}
220dfe64dd3Smacallan
221dfe64dd3Smacallanstatic void
222dfe64dd3SmacallanXGISetXvGamma(XGIPtr pXGI)
223dfe64dd3Smacallan{
224dfe64dd3Smacallan    int i;
225dfe64dd3Smacallan    unsigned char backup = GetSRReg(pXGI, Index_SR_Power_Management);
226dfe64dd3Smacallan	/* SR1F[4:3]
227dfe64dd3Smacallan	 * 10: disable gamma1, enable gamma0
228dfe64dd3Smacallan	 */
229dfe64dd3Smacallan    SetSRRegMask(pXGI, Index_SR_Power_Management, 0x08, 0x18);
230dfe64dd3Smacallan    for(i = 0; i <= 255; i++) {
231dfe64dd3Smacallan       MMIO_OUT32(pXGI->IOBase, REG_GAMMA_PALETTE,
232dfe64dd3Smacallan       			(i << 24)     |
233dfe64dd3Smacallan			(pXGI->XvGammaRampBlue[i] << 16) |
234dfe64dd3Smacallan			(pXGI->XvGammaRampGreen[i] << 8) |
235dfe64dd3Smacallan			pXGI->XvGammaRampRed[i]);
236dfe64dd3Smacallan    }
237dfe64dd3Smacallan    SetSRRegMask(pXGI, Index_SR_Power_Management, backup, 0xff);
238dfe64dd3Smacallan}
239dfe64dd3Smacallan
240dfe64dd3Smacallanvoid
241dfe64dd3SmacallanXGIUpdateXvGamma(XGIPtr pXGI, XGIPortPrivPtr pPriv)
242dfe64dd3Smacallan{
243dfe64dd3Smacallan    unsigned char sr7 = GetSRReg(pXGI, Index_SR_RAMDAC_Ctrl);
244dfe64dd3Smacallan
245dfe64dd3Smacallan    /* SR7 [2]: 24-bit palette RAM and Gamma correction enable */
246dfe64dd3Smacallan    if(!(sr7 & 0x04)) return;
247dfe64dd3Smacallan
248dfe64dd3Smacallan    XGIComputeXvGamma(pXGI);
249dfe64dd3Smacallan    XGISetXvGamma(pXGI);
250dfe64dd3Smacallan}
251dfe64dd3Smacallan
252dfe64dd3Smacallan/* ----------------SetDDAReg()------------------------------------ */
253dfe64dd3SmacallanVOID SetDDAReg (XGIPtr pXGI, float scale)
254dfe64dd3Smacallan{
255dfe64dd3Smacallan    float WW, W[4], tempW[4];
256dfe64dd3Smacallan    int i, j, w, WeightMat[16][4];
257dfe64dd3Smacallan    int *wm1, *wm2, *wm3, *wm4, *temp1, *temp2, *temp3, *temp4;
258dfe64dd3Smacallan
259dfe64dd3Smacallan    for (i=0; i<16; i++)
260dfe64dd3Smacallan    {
261dfe64dd3Smacallan            /* The order of weights are inversed for convolution */
262dfe64dd3Smacallan            W[0] = tap_dda_func((float)((1.0+(i/16.0))/scale));
263dfe64dd3Smacallan            W[1] = tap_dda_func((float)((0.0+(i/16.0))/scale));
264dfe64dd3Smacallan            W[2] = tap_dda_func((float)((-1.0+(i/16.0))/scale));
265dfe64dd3Smacallan            W[3] = tap_dda_func((float)((-2.0+(i/16.0))/scale));
266dfe64dd3Smacallan
267dfe64dd3Smacallan            /* Normalize the weights */
268dfe64dd3Smacallan            WW = W[0]+W[1]+W[2]+W[3];
269dfe64dd3Smacallan
270dfe64dd3Smacallan            /* for rouding */
271dfe64dd3Smacallan            for(j=0; j<4; j++)
272dfe64dd3Smacallan                    tempW[j] = (float)((W[j]/WW*16)+0.5);
273dfe64dd3Smacallan
274dfe64dd3Smacallan            WeightMat[i][0] = (int) tempW[0];
275dfe64dd3Smacallan            WeightMat[i][1] = (int) tempW[1];
276dfe64dd3Smacallan            WeightMat[i][2] = (int) tempW[2];
277dfe64dd3Smacallan            WeightMat[i][3] = (int) tempW[3];
278dfe64dd3Smacallan
279dfe64dd3Smacallan            /* check for display abnormal caused by rounding */
280dfe64dd3Smacallan            w = WeightMat[i][0] + WeightMat[i][1] + WeightMat[i][2] + WeightMat[i][3];
281dfe64dd3Smacallan            if( w != 16 )
282dfe64dd3Smacallan            {
283dfe64dd3Smacallan                    temp1 = ( WeightMat[i][0] > WeightMat[i][1] ) ? &WeightMat[i][0] : &WeightMat[i][1];
284dfe64dd3Smacallan                    temp2 = ( WeightMat[i][0] > WeightMat[i][1] ) ? &WeightMat[i][1] : &WeightMat[i][0];
285dfe64dd3Smacallan                    temp3 = ( WeightMat[i][2] > WeightMat[i][3] ) ? &WeightMat[i][2] : &WeightMat[i][3];
286dfe64dd3Smacallan                    temp4 = ( WeightMat[i][2] > WeightMat[i][3] ) ? &WeightMat[i][3] : &WeightMat[i][2];
287dfe64dd3Smacallan                    wm1 = ( *temp1 > *temp3) ? temp1 : temp3;
288dfe64dd3Smacallan                    wm4 = ( *temp2 > *temp4) ? temp4 : temp2;
289dfe64dd3Smacallan                    wm2 = ( wm1 == temp1 ) ? temp3 : temp1;
290dfe64dd3Smacallan                    wm3 = ( wm4 == temp2 ) ? temp4 : temp2;
291dfe64dd3Smacallan
292dfe64dd3Smacallan                switch(w)
293dfe64dd3Smacallan                {
294dfe64dd3Smacallan                    case 12:
295dfe64dd3Smacallan                        WeightMat[i][0]++;
296dfe64dd3Smacallan                        WeightMat[i][1]++;
297dfe64dd3Smacallan                        WeightMat[i][2]++;
298dfe64dd3Smacallan                        WeightMat[i][3]++;
299dfe64dd3Smacallan                        break;
300dfe64dd3Smacallan
301dfe64dd3Smacallan                    case 13:
302dfe64dd3Smacallan                        (*wm1)++;
303dfe64dd3Smacallan                        (*wm4)++;
304dfe64dd3Smacallan                        if( *wm2 > *wm3 )
305dfe64dd3Smacallan                            (*wm2)++;
306dfe64dd3Smacallan                        else
307dfe64dd3Smacallan                            (*wm3)++;
308dfe64dd3Smacallan                        break;
309dfe64dd3Smacallan
310dfe64dd3Smacallan                    case 14:
311dfe64dd3Smacallan                        (*wm1)++;
312dfe64dd3Smacallan                        (*wm4)++;
313dfe64dd3Smacallan                        break;
314dfe64dd3Smacallan
315dfe64dd3Smacallan                    case 15:
316dfe64dd3Smacallan                        (*wm1)++;
317dfe64dd3Smacallan                        break;
318dfe64dd3Smacallan
319dfe64dd3Smacallan                    case 17:
320dfe64dd3Smacallan                            (*wm4)--;
321dfe64dd3Smacallan                            break;
322dfe64dd3Smacallan
323dfe64dd3Smacallan                    case 18:
324dfe64dd3Smacallan                        (*wm1)--;
325dfe64dd3Smacallan                        (*wm4)--;
326dfe64dd3Smacallan                        break;
327dfe64dd3Smacallan
328dfe64dd3Smacallan                    case 19:
329dfe64dd3Smacallan                        (*wm1)--;
330dfe64dd3Smacallan                        (*wm4)--;
331dfe64dd3Smacallan                        if( *wm2 > *wm3 )
332dfe64dd3Smacallan                            (*wm3)--;
333dfe64dd3Smacallan                        else
334dfe64dd3Smacallan                            (*wm2)--;
335dfe64dd3Smacallan                        break;
336dfe64dd3Smacallan                    case 20:
337dfe64dd3Smacallan                        WeightMat[i][0]--;
338dfe64dd3Smacallan                        WeightMat[i][1]--;
339dfe64dd3Smacallan                        WeightMat[i][2]--;
340dfe64dd3Smacallan                        WeightMat[i][3]--;
341dfe64dd3Smacallan                        break;
342dfe64dd3Smacallan                    default:
343dfe64dd3Smacallan                        /* ErrorF("Invalid WeightMat value!\n"); */
344dfe64dd3Smacallan                        break;
345dfe64dd3Smacallan                }
346dfe64dd3Smacallan            }
347dfe64dd3Smacallan    }
348dfe64dd3Smacallan
349dfe64dd3Smacallan    /* set DDA registers */
350dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_A0, WeightMat[0][0], 0x3F);
351dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_A1, WeightMat[0][1], 0x3F);
352dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_A2, WeightMat[0][2], 0x3F);
353dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_A3, WeightMat[0][3], 0x3F);
354dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_B0, WeightMat[1][0], 0x3F);
355dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_B1, WeightMat[1][1], 0x3F);
356dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_B2, WeightMat[1][2], 0x3F);
357dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_B3, WeightMat[1][3], 0x3F);
358dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_C0, WeightMat[2][0], 0x3F);
359dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_C1, WeightMat[2][1], 0x3F);
360dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_C2, WeightMat[2][2], 0x3F);
361dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_C3, WeightMat[2][3], 0x3F);
362dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_D0, WeightMat[3][0], 0x3F);
363dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_D1, WeightMat[3][1], 0x3F);
364dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_D2, WeightMat[3][2], 0x3F);
365dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_D3, WeightMat[3][3], 0x3F);
366dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_E0, WeightMat[4][0], 0x3F);
367dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_E1, WeightMat[4][1], 0x3F);
368dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_E2, WeightMat[4][2], 0x3F);
369dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_E3, WeightMat[4][3], 0x3F);
370dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_F0, WeightMat[5][0], 0x3F);
371dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_F1, WeightMat[5][1], 0x3F);
372dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_F2, WeightMat[5][2], 0x3F);
373dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_F3, WeightMat[5][3], 0x3F);
374dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_G0, WeightMat[6][0], 0x3F);
375dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_G1, WeightMat[6][1], 0x3F);
376dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_G2, WeightMat[6][2], 0x3F);
377dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_G3, WeightMat[6][3], 0x3F);
378dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_H0, WeightMat[7][0], 0x3F);
379dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_H1, WeightMat[7][1], 0x3F);
380dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_H2, WeightMat[7][2], 0x3F);
381dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_H3, WeightMat[7][3], 0x3F);
382dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_I0, WeightMat[8][0], 0x3F);
383dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_I1, WeightMat[8][1], 0x3F);
384dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_I2, WeightMat[8][2], 0x3F);
385dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_I3, WeightMat[8][3], 0x3F);
386dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_J0, WeightMat[9][0], 0x3F);
387dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_J1, WeightMat[9][1], 0x3F);
388dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_J2, WeightMat[9][2], 0x3F);
389dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_J3, WeightMat[9][3], 0x3F);
390dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_K0, WeightMat[10][0], 0x3F);
391dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_K1, WeightMat[10][1], 0x3F);
392dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_K2, WeightMat[10][2], 0x3F);
393dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_K3, WeightMat[10][3], 0x3F);
394dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_L0, WeightMat[11][0], 0x3F);
395dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_L1, WeightMat[11][1], 0x3F);
396dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_L2, WeightMat[11][2], 0x3F);
397dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_L3, WeightMat[11][3], 0x3F);
398dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_M0, WeightMat[12][0], 0x3F);
399dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_M1, WeightMat[12][1], 0x3F);
400dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_M2, WeightMat[12][2], 0x3F);
401dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_M3, WeightMat[12][3], 0x3F);
402dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_N0, WeightMat[13][0], 0x3F);
403dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_N1, WeightMat[13][1], 0x3F);
404dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_N2, WeightMat[13][2], 0x3F);
405dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_N3, WeightMat[13][3], 0x3F);
406dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_O0, WeightMat[14][0], 0x3F);
407dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_O1, WeightMat[14][1], 0x3F);
408dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_O2, WeightMat[14][2], 0x3F);
409dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_O3, WeightMat[14][3], 0x3F);
410dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_P0, WeightMat[15][0], 0x3F);
411dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_P1, WeightMat[15][1], 0x3F);
412dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_P2, WeightMat[15][2], 0x3F);
413dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_DDA_Weighting_Matrix_P3, WeightMat[15][3], 0x3F);
414dfe64dd3Smacallan}
415dfe64dd3Smacallan
416dfe64dd3Smacallanvoid
417dfe64dd3SmacallanXGIResetVideo(ScrnInfoPtr pScrn)
418dfe64dd3Smacallan{
419dfe64dd3Smacallan    XGIPtr pXGI = XGIPTR(pScrn);
420dfe64dd3Smacallan    XGIPortPrivPtr pPriv = GET_PORT_PRIVATE(pScrn);
421dfe64dd3Smacallan
422dfe64dd3Smacallan    /* Reset Xv gamma correction */
423dfe64dd3Smacallan    XGIUpdateXvGamma(pXGI, pPriv);
424dfe64dd3Smacallan
425dfe64dd3Smacallan    if (GetSRReg (pXGI, 0x05) != 0xa1)
426dfe64dd3Smacallan    {
427dfe64dd3Smacallan            SetSRReg (pXGI, 0x05, 0x86);
428dfe64dd3Smacallan            if (GetSRReg (pXGI, 0x05) != 0xa1)
429dfe64dd3Smacallan	    {}
430dfe64dd3Smacallan                    /* xf86DrvMsg(pScrn->scrnIndex, X_ERROR, */
431dfe64dd3Smacallan                    /* "Standard password not initialize\n"); */
432dfe64dd3Smacallan    }
433dfe64dd3Smacallan    if (GetVideoReg (pXGI, Index_VI_Passwd) != 0xa1)
434dfe64dd3Smacallan    {
435dfe64dd3Smacallan            SetVideoReg (pXGI, Index_VI_Passwd, 0x86);
436dfe64dd3Smacallan            if (GetVideoReg (pXGI, Index_VI_Passwd) != 0xa1)
437dfe64dd3Smacallan	    {}
438dfe64dd3Smacallan                    /* xf86DrvMsg(pScrn->scrnIndex, X_ERROR, */
439dfe64dd3Smacallan                    /* "Video password not initialize\n"); */
440dfe64dd3Smacallan    }
441dfe64dd3Smacallan
442dfe64dd3Smacallan    /* Initial Overlay 1 */
443dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Control_Misc2, 0x00, 0x81);
444dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x00, 0x03);
445dfe64dd3Smacallan    /* Turn on Bob mode and digital video data transform bit */
446dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Control_Misc1, 0x82, 0x82);
447dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Scale_Control, 0x60, 0x60);
448dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Contrast_Enh_Ctrl, 0x04, 0x1F);
449dfe64dd3Smacallan
450dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Disp_Y_Buf_Preset_Low,     0x00);
451dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Disp_Y_Buf_Preset_Middle,  0x00);
452dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Disp_UV_Buf_Preset_Low,    0x00);
453dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Disp_UV_Buf_Preset_Middle, 0x00);
454dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Disp_Y_UV_Buf_Preset_High, 0x00);
455dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Play_Threshold_Low,        0x00);
456dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Play_Threshold_Low_Ext, 0x00, 0x01);
457dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Play_Threshold_High,       0x00);
458dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Play_Threshold_High_Ext, 0x00, 0x01);
459dfe64dd3Smacallan
460dfe64dd3Smacallan    /* Disable fast page flip */
461dfe64dd3Smacallan    SetSRRegMask(pXGI, Index_SR_CRT_Misc_Ctrl,    0x00,  0x02);
462dfe64dd3Smacallan
463dfe64dd3Smacallan    #ifdef CAPTURE_340A1
464dfe64dd3Smacallan       SetEnableCaptureReg(pXGI, FALSE, FALSE);
465dfe64dd3Smacallan    #else
466dfe64dd3Smacallan       SetEnableCaptureReg(pXGI, FALSE);
467dfe64dd3Smacallan    #endif
468dfe64dd3Smacallan
469dfe64dd3Smacallan    /* Disable video processor */
470dfe64dd3Smacallan    SetSRRegMask(pXGI, Index_Video_Process,        0x00, 0x02);
471dfe64dd3Smacallan
472dfe64dd3Smacallan        /* Enable Horizontal 4-tap DDA mode */
473dfe64dd3Smacallan        SetVideoRegMask(pXGI, Index_VI_Key_Overlay_OP, 0x40, 0x40);
474dfe64dd3Smacallan        /* Disable Vertical 4-tap DDA mode -- not surport not */
475dfe64dd3Smacallan        SetVideoRegMask(pXGI, Index_VI_Key_Overlay_OP, 0x00, 0x80);
476dfe64dd3Smacallan        /* The DDA registers should set scale to 1 as default */
477dfe64dd3Smacallan    SetDDAReg (pXGI, 1.0);
478dfe64dd3Smacallan
479dfe64dd3Smacallan        /*for 341, Init VR 2F [D5] to be 1,to set software flip as default*/
480dfe64dd3Smacallan        SetVideoRegMask(pXGI, Index_VI_Key_Overlay_OP, 0x20, 0x20);
481dfe64dd3Smacallan
482dfe64dd3Smacallan   /*Disable Contrast enhancement*/
483dfe64dd3Smacallan   SetVideoRegMask(pXGI, Index_VI_Key_Overlay_OP, 0x00, 0x10);
484dfe64dd3Smacallan
485dfe64dd3Smacallan   /* Default Color */
486dfe64dd3Smacallan   SetVideoReg(pXGI, Index_VI_Brightness, Default_Brightness);
487dfe64dd3Smacallan   SetVideoRegMask(pXGI, Index_VI_Contrast_Enh_Ctrl, Default_Contrast, 0x07);
488dfe64dd3Smacallan   SetVideoReg(pXGI, Index_VI_Saturation, Default_Saturation);
489dfe64dd3Smacallan   SetVideoRegMask(pXGI, Index_VI_Hue, Default_Hue, 0x07);
490dfe64dd3Smacallan}
491dfe64dd3Smacallan
492dfe64dd3Smacallanvoid
493dfe64dd3SmacallanSetMergeLineBufReg(XGIPtr pXGI, Bool enable)
494dfe64dd3Smacallan{
495dfe64dd3Smacallan  if (enable) {
496dfe64dd3Smacallan          /* select video 1 and disable All line buffer Merge */
497dfe64dd3Smacallan     SetVideoRegMask(pXGI, Index_VI_Control_Misc2, 0x00, 0x11);
498dfe64dd3Smacallan          /* set Individual Line buffer Merge */
499dfe64dd3Smacallan     SetVideoRegMask(pXGI, Index_VI_Control_Misc1, 0x04, 0x04);
500dfe64dd3Smacallan  }
501dfe64dd3Smacallan  else {
502dfe64dd3Smacallan          /* select video 1 and disable All line buffer Merge */
503dfe64dd3Smacallan          SetVideoRegMask(pXGI, Index_VI_Control_Misc2, 0x00, 0x11);
504dfe64dd3Smacallan          /* disable Individual Line buffer Merge */
505dfe64dd3Smacallan          SetVideoRegMask(pXGI, Index_VI_Control_Misc1, 0x00, 0x04);
506dfe64dd3Smacallan  }
507dfe64dd3Smacallan}
508dfe64dd3Smacallan
509dfe64dd3Smacallanvoid
510dfe64dd3SmacallanSetVideoFormatReg(XGIPtr pXGI, int format)
511dfe64dd3Smacallan{
512dfe64dd3Smacallan    CARD8 fmt;
513dfe64dd3Smacallan
514dfe64dd3Smacallan    switch (format)
515dfe64dd3Smacallan    {
516dfe64dd3Smacallan       case PIXEL_FMT_YV12:
517dfe64dd3Smacallan            fmt = 0x0c;
518dfe64dd3Smacallan            break;
519dfe64dd3Smacallan
520dfe64dd3Smacallan       case PIXEL_FMT_YUY2:
521dfe64dd3Smacallan            fmt = 0x28;
522dfe64dd3Smacallan            break;
523dfe64dd3Smacallan
524dfe64dd3Smacallan       case PIXEL_FMT_UYVY:
525dfe64dd3Smacallan            fmt = 0x08;
526dfe64dd3Smacallan            break;
527dfe64dd3Smacallan
528dfe64dd3Smacallan	   case PIXEL_FMT_YVYU:
529dfe64dd3Smacallan	   		fmt = 0x38;
530dfe64dd3Smacallan		    break;
531dfe64dd3Smacallan
532dfe64dd3Smacallan	   case PIXEL_FMT_NV12:
533dfe64dd3Smacallan	        fmt = 0x4c;
534dfe64dd3Smacallan		    break;
535dfe64dd3Smacallan
536dfe64dd3Smacallan	   case PIXEL_FMT_NV21:
537dfe64dd3Smacallan	        fmt = 0x5c;
538dfe64dd3Smacallan		    break;
539dfe64dd3Smacallan
540dfe64dd3Smacallan	   case PIXEL_FMT_RGB5:   /* D[5:4] : 00 RGB555, 01 RGB 565 */
541dfe64dd3Smacallan	        fmt = 0x00;
542dfe64dd3Smacallan		    break;
543dfe64dd3Smacallan
544dfe64dd3Smacallan	   case PIXEL_FMT_RGB6:
545dfe64dd3Smacallan	        fmt = 0x10;
546dfe64dd3Smacallan		    break;
547dfe64dd3Smacallan
548dfe64dd3Smacallan       default:
549dfe64dd3Smacallan            fmt = 0x00;
550dfe64dd3Smacallan            break;
551dfe64dd3Smacallan    }
552dfe64dd3Smacallan
553dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Control_Misc0, fmt, 0x7c);
554dfe64dd3Smacallan}
555dfe64dd3Smacallan
556dfe64dd3Smacallanvoid
557dfe64dd3SmacallanSetColorkeyReg(XGIPtr pXGI, CARD32 colorkey)
558dfe64dd3Smacallan{
559dfe64dd3Smacallan    CARD8 r, g, b;
560dfe64dd3Smacallan
561dfe64dd3Smacallan    b = LOBYTE(LOWORD(colorkey));
562dfe64dd3Smacallan    g = HIBYTE(LOWORD(colorkey));
563dfe64dd3Smacallan    r = LOBYTE(HIWORD(colorkey));
564dfe64dd3Smacallan
565dfe64dd3Smacallan   /* Activate the colorkey mode */
566dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Overlay_ColorKey_Blue_Min  , b);
567dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Overlay_ColorKey_Green_Min , g);
568dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Overlay_ColorKey_Red_Min   , r);
569dfe64dd3Smacallan
570dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Overlay_ColorKey_Blue_Max  , b);
571dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Overlay_ColorKey_Green_Max , g);
572dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Overlay_ColorKey_Red_Max   , r);
573dfe64dd3Smacallan}
574dfe64dd3Smacallan
575dfe64dd3Smacallanvoid
576dfe64dd3SmacallanSetVideoBrightnessReg(XGIPtr pXGI, INT32 value)
577dfe64dd3Smacallan{
578dfe64dd3Smacallan    CARD8   brightness;
579dfe64dd3Smacallan
580dfe64dd3Smacallan    brightness = LOBYTE(value);
581dfe64dd3Smacallan
582dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Brightness  ,brightness);
583dfe64dd3Smacallan}
584dfe64dd3Smacallan
585dfe64dd3Smacallanvoid
586dfe64dd3SmacallanSetVideoContrastReg(XGIPtr pXGI, INT32 value)
587dfe64dd3Smacallan{
588dfe64dd3Smacallan    CARD8   contrast;
589dfe64dd3Smacallan
590dfe64dd3Smacallan    contrast = (CARD8)(((value * 7) / 255) & 0x000F);
591dfe64dd3Smacallan
592dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Contrast_Enh_Ctrl, contrast, 0x07);
593dfe64dd3Smacallan}
594dfe64dd3Smacallan
595dfe64dd3Smacallanvoid
596dfe64dd3SmacallanSetVideoHueReg(XGIPtr pXGI, INT32 value)
597dfe64dd3Smacallan{
598dfe64dd3Smacallan    CARD8   hue;
599dfe64dd3Smacallan
600dfe64dd3Smacallan    if ( value > 0 )
601dfe64dd3Smacallan    {
602dfe64dd3Smacallan       SetVideoRegMask(pXGI, Index_VI_Hue, 0x00, 0x08);
603dfe64dd3Smacallan    }
604dfe64dd3Smacallan    else
605dfe64dd3Smacallan    {
606dfe64dd3Smacallan       SetVideoRegMask(pXGI, Index_VI_Hue, 0x08, 0x08);
607dfe64dd3Smacallan
608dfe64dd3Smacallan       value = -value;
609dfe64dd3Smacallan    }
610dfe64dd3Smacallan
611dfe64dd3Smacallan    hue = (CARD8)(((value * 7) / 180) & 0x0007);
612dfe64dd3Smacallan
613dfe64dd3Smacallan
614dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Hue, hue, 0x07);
615dfe64dd3Smacallan}
616dfe64dd3Smacallan
617dfe64dd3Smacallanvoid
618dfe64dd3SmacallanSetVideoSaturationReg(XGIPtr pXGI, INT32 value)
619dfe64dd3Smacallan{
620dfe64dd3Smacallan    CARD8   saturation;
621dfe64dd3Smacallan
622dfe64dd3Smacallan    if ( value > 0 )
623dfe64dd3Smacallan    {
624dfe64dd3Smacallan       SetVideoRegMask(pXGI, Index_VI_Saturation, 0x00, 0x08);
625dfe64dd3Smacallan       SetVideoRegMask(pXGI, Index_VI_Saturation, 0x00, 0x80);
626dfe64dd3Smacallan    }
627dfe64dd3Smacallan    else
628dfe64dd3Smacallan    {
629dfe64dd3Smacallan       SetVideoRegMask(pXGI, Index_VI_Saturation, 0x08, 0x08);
630dfe64dd3Smacallan       SetVideoRegMask(pXGI, Index_VI_Saturation, 0x80, 0x80);
631dfe64dd3Smacallan
632dfe64dd3Smacallan       value = -value;
633dfe64dd3Smacallan    }
634dfe64dd3Smacallan
635dfe64dd3Smacallan    saturation = (CARD8)(((value * 7) / 180) & 0x000F);
636dfe64dd3Smacallan
637dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Saturation, saturation, 0x07);
638dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Saturation, saturation << 4, 0x70);
639dfe64dd3Smacallan}
640dfe64dd3Smacallan
641dfe64dd3Smacallanvoid
642dfe64dd3SmacallanSetOverlayReg(XGIPtr pXGI, XGIOverlayPtr pOverlay)
643dfe64dd3Smacallan{
644dfe64dd3Smacallan
645dfe64dd3Smacallan    ScrnInfoPtr pScrn = pXGI->pScrn;
646dfe64dd3Smacallan	XGIPortPrivPtr pPriv = GET_PORT_PRIVATE(pScrn);
647dfe64dd3Smacallan
648dfe64dd3Smacallan    CARD32 tmpYPitch;
649dfe64dd3Smacallan    CARD16 top, left;
650dfe64dd3Smacallan    CARD16 bottom, right;
651dfe64dd3Smacallan    CARD32 PSY, PSU, PSV;
652dfe64dd3Smacallan    CARD16 screenX = pScrn->currentMode->HDisplay;
653dfe64dd3Smacallan    CARD16 screenY = pScrn->currentMode->VDisplay;
654dfe64dd3Smacallan
655dfe64dd3Smacallan    top    = pOverlay->dstBox.y1;
656dfe64dd3Smacallan    bottom = pOverlay->dstBox.y2;
657dfe64dd3Smacallan
658dfe64dd3Smacallan    if (bottom > screenY)
659dfe64dd3Smacallan        bottom = screenY;
660dfe64dd3Smacallan
661dfe64dd3Smacallan    left  = pOverlay->dstBox.x1;
662dfe64dd3Smacallan    right = pOverlay->dstBox.x2;
663dfe64dd3Smacallan
664dfe64dd3Smacallan    if (right > screenX)
665dfe64dd3Smacallan        right = screenX;
666dfe64dd3Smacallan
667dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Win_Hor_Disp_Start_Low, LOBYTE(left));
668dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Win_Hor_Disp_End_Low, LOBYTE(right));
669dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Win_Hor_Over, (HIBYTE(right)<<4)|HIBYTE(left));
670dfe64dd3Smacallan
671dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Win_Ver_Disp_Start_Low, LOBYTE(top));
672dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Win_Ver_Disp_End_Low, LOBYTE(bottom));
673dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Win_Ver_Over, (HIBYTE(bottom)<<4)|HIBYTE(top));
674dfe64dd3Smacallan
675dfe64dd3Smacallan    /*  Set ContrastFactor */
676dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Contrast_Enh_Ctrl, pOverlay->dwContrastFactor << 6, 0xc0);
677dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Contrast_Factor, pOverlay->SamplePixel);
678dfe64dd3Smacallan
679dfe64dd3Smacallan	/* SetVideoRegMask(pXGI, Index_VI_Control_Misc3, 0x00, 0x03); */
680dfe64dd3Smacallan
681dfe64dd3Smacallan	/* Does need to merge line buffer*/
682dfe64dd3Smacallan	SetMergeLineBufReg(pXGI, pOverlay->pitch > pPriv->linebufMergeLimit);
683dfe64dd3Smacallan
684dfe64dd3Smacallan	/* set video format */
685dfe64dd3Smacallan	SetVideoFormatReg(pXGI, pOverlay->pixelFormat);
686dfe64dd3Smacallan
687dfe64dd3Smacallan	/* set line buffer size */
688dfe64dd3Smacallan	SetVideoReg(pXGI, Index_VI_Line_Buffer_Size, LOBYTE(LOWORD(pOverlay->lineBufSize)));
689dfe64dd3Smacallan	SetVideoReg(pXGI, Index_VI_Line_Buffer_Size_Ext, HIBYTE(LOWORD(pOverlay->lineBufSize)));
690dfe64dd3Smacallan
691dfe64dd3Smacallan	/* set Key Overlay Operation Mode */
692dfe64dd3Smacallan	SetVideoRegMask (pXGI, Index_VI_Key_Overlay_OP, pOverlay->keyOP, 0x0f);
693dfe64dd3Smacallan
694dfe64dd3Smacallan
695dfe64dd3Smacallan    /* set scale factor */
696dfe64dd3Smacallan    SetVideoReg (pXGI, Index_VI_Hor_Post_Up_Scale_Low, LOBYTE(pOverlay->HUSF));
697dfe64dd3Smacallan    SetVideoReg (pXGI, Index_VI_Hor_Post_Up_Scale_High, HIBYTE(pOverlay->HUSF));
698dfe64dd3Smacallan
699dfe64dd3Smacallan    SetVideoReg (pXGI, Index_VI_Ver_Up_Scale_Low, LOBYTE(pOverlay->VUSF));
700dfe64dd3Smacallan    SetVideoReg (pXGI, Index_VI_Ver_Up_Scale_High, HIBYTE(pOverlay->VUSF));
701dfe64dd3Smacallan
702dfe64dd3Smacallan    SetVideoRegMask (pXGI, Index_VI_Scale_Control, (pOverlay->IntBit << 3)|(pOverlay->wHPre), 0x7f);
703dfe64dd3Smacallan
704dfe64dd3Smacallan    /* for 340 4-tap DDA */
705dfe64dd3Smacallan    SetDDAReg(pXGI, pOverlay->f_scale);
706dfe64dd3Smacallan
707dfe64dd3Smacallan    /* set frame or field mode */
708dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Control_Misc1, pOverlay->bobEnable, 0x1a);
709dfe64dd3Smacallan
710dfe64dd3Smacallan    /* set Y start address */
711dfe64dd3Smacallan    PSY = pOverlay->PSY >>1;        /* in unit of word */
712dfe64dd3Smacallan
713dfe64dd3Smacallan    SetVideoReg (pXGI, Index_VI_Disp_Y_Buf_Start_Low, LOBYTE(LOWORD(PSY)));
714dfe64dd3Smacallan    SetVideoReg (pXGI, Index_VI_Disp_Y_Buf_Start_Middle, HIBYTE(LOWORD(PSY)));
715dfe64dd3Smacallan    SetVideoReg (pXGI, Index_VI_Disp_Y_Buf_Start_High, LOBYTE(HIWORD(PSY)));
716dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Disp_Y_Buf_EXT_High, HIBYTE(HIWORD(PSY)), 0x03);
717dfe64dd3Smacallan    tmpYPitch = pOverlay->pitch >> 1 ; /* in unit of word */
718dfe64dd3Smacallan
719dfe64dd3Smacallan    if ((pOverlay->pixelFormat == PIXEL_FMT_YV12) ||
720dfe64dd3Smacallan		(pOverlay->pixelFormat == PIXEL_FMT_NV12) ||
721dfe64dd3Smacallan		(pOverlay->pixelFormat == PIXEL_FMT_NV21))
722dfe64dd3Smacallan    {
723dfe64dd3Smacallan        /* set UV pitch */
724dfe64dd3Smacallan		CARD32  uvpitch = tmpYPitch;
725dfe64dd3Smacallan        BYTE    bYUV_Pitch_High;
726dfe64dd3Smacallan
727dfe64dd3Smacallan		if(pOverlay->pixelFormat == PIXEL_FMT_YV12)
728dfe64dd3Smacallan	    	uvpitch >>= 1;
729dfe64dd3Smacallan/*
730dfe64dd3Smacallan        bYUV_Pitch_High = (HIBYTE(LOWORD(uvpitch))<<4) & 0xf0 |
731dfe64dd3Smacallan                        (HIBYTE(LOWORD(tmpYPitch))) & 0x0f;  */
732dfe64dd3Smacallan        bYUV_Pitch_High = ((HIBYTE(LOWORD(uvpitch))<<4) & 0xf0) | ((HIBYTE(LOWORD(tmpYPitch))) & 0x0f);
733dfe64dd3Smacallan        SetVideoReg    (pXGI, Index_VI_Disp_UV_Buf_Pitch_Low,         LOBYTE(LOWORD(uvpitch)));
734dfe64dd3Smacallan        SetVideoReg    (pXGI, Index_VI_Disp_Y_UV_Buf_Pitch_High, bYUV_Pitch_High);
735dfe64dd3Smacallan        SetVideoRegMask(pXGI, Index_VI_Disp_UV_Buf_Pitch_EXT_High,        uvpitch >> 12, 0x1f);
736dfe64dd3Smacallan
737dfe64dd3Smacallan        /* set U/V start address */
738dfe64dd3Smacallan        PSU = pOverlay->PSU >> 1; /* in unit of word; */
739dfe64dd3Smacallan        PSV = pOverlay->PSV >> 1; /* in unit of word;; */
740dfe64dd3Smacallan
741dfe64dd3Smacallan        SetVideoReg(pXGI, Index_VI_Disp_U_Buf_Start_Low, LOBYTE(LOWORD(PSU)));
742dfe64dd3Smacallan        SetVideoReg(pXGI, Index_VI_Disp_U_Buf_Start_Middle, HIBYTE(LOWORD(PSU)));
743dfe64dd3Smacallan        SetVideoReg(pXGI, Index_VI_Disp_U_Buf_Start_High, LOBYTE(HIWORD(PSU)));
744dfe64dd3Smacallan        /* [26:24] save in the D[2:0] */
745dfe64dd3Smacallan        SetVideoRegMask(pXGI, Index_VI_Disp_U_Buf_EXT_High, HIBYTE(HIWORD(PSU)), 0x03);
746dfe64dd3Smacallan
747dfe64dd3Smacallan        SetVideoReg(pXGI, Index_VI_Disp_V_Buf_Start_Low, LOBYTE(LOWORD(PSV)));
748dfe64dd3Smacallan        SetVideoReg(pXGI, Index_VI_Disp_V_Buf_Start_Middle, HIBYTE(LOWORD(PSV)));
749dfe64dd3Smacallan        SetVideoReg(pXGI, Index_VI_Disp_V_Buf_Start_High, LOBYTE(HIWORD(PSV)));
750dfe64dd3Smacallan        /* [26:24] save in the D[2:0] */
751dfe64dd3Smacallan        SetVideoRegMask(pXGI, Index_VI_Disp_V_Buf_EXT_High, HIBYTE(HIWORD(PSV)), 0x03);
752dfe64dd3Smacallan        tmpYPitch = pOverlay->pitch >> 1; /* in unit of word */
753dfe64dd3Smacallan    }
754dfe64dd3Smacallan    else
755dfe64dd3Smacallan        SetVideoRegMask(pXGI, Index_VI_Disp_Y_UV_Buf_Pitch_High, HIBYTE(LOWORD(tmpYPitch)), 0x0f);
756dfe64dd3Smacallan
757dfe64dd3Smacallan    /* set Y pitch */
758dfe64dd3Smacallan
759dfe64dd3Smacallan    SetVideoReg(pXGI, Index_VI_Disp_Y_Buf_Pitch_Low, LOBYTE(LOWORD(tmpYPitch)));
760dfe64dd3Smacallan    /* [16:12] save in the D[4:0] */
761dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Disp_Y_Buf_Pitch_EXT_High, (tmpYPitch>>12)&0x1f , 0x1f);
762dfe64dd3Smacallan
763dfe64dd3Smacallan
764dfe64dd3Smacallan     /* start address ready */
765dfe64dd3Smacallan    SetVideoRegMask(pXGI, Index_VI_Control_Misc3, 0x03, 0x03);
766dfe64dd3Smacallan
767dfe64dd3Smacallan    /* set contrast factor */
768dfe64dd3Smacallan    /* SetVideoRegMask(pXGI, Index_VI_Contrast_Enh_Ctrl, pOverlay->contrastCtrl<<6, 0xc0); */
769dfe64dd3Smacallan    /* SetVideoReg (pXGI, Index_VI_Contrast_Factor, pOverlay->contrastFactor); */
770dfe64dd3Smacallan}
771dfe64dd3Smacallan
772dfe64dd3Smacallanvoid
773dfe64dd3SmacallanSetCloseOverlayReg(XGIPtr pXGI)
774dfe64dd3Smacallan{
775dfe64dd3Smacallan  SetVideoRegMask (pXGI, Index_VI_Control_Misc2, 0x00, 0x01);
776dfe64dd3Smacallan  SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x00, 0x02);
777dfe64dd3Smacallan}
778dfe64dd3Smacallan
779dfe64dd3Smacallanvoid
780dfe64dd3SmacallanSetSelectOverlayReg(XGIPtr pXGI, CARD8 index)
781dfe64dd3Smacallan{
782dfe64dd3Smacallan  SetVideoRegMask(pXGI, Index_VI_Control_Misc2, index, 0x01);
783dfe64dd3Smacallan}
784dfe64dd3Smacallan
785dfe64dd3Smacallanvoid
786dfe64dd3SmacallanSetEnableOverlayReg(XGIPtr pXGI, Bool bEnable)
787dfe64dd3Smacallan{
788dfe64dd3Smacallan        if (bEnable)
789dfe64dd3Smacallan                SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x02, 0x02);
790dfe64dd3Smacallan        else
791dfe64dd3Smacallan                SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x00, 0x02);
792dfe64dd3Smacallan}
793dfe64dd3Smacallan
794dfe64dd3Smacallanvoid
795dfe64dd3SmacallanEnableCaptureAutoFlip(XGIPtr pXGI, Bool bEnable)
796dfe64dd3Smacallan{
797dfe64dd3Smacallan   if (bEnable)
798dfe64dd3Smacallan      SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x01, 0x01);
799dfe64dd3Smacallan   else
800dfe64dd3Smacallan      SetVideoRegMask(pXGI, Index_VI_Control_Misc0, 0x00, 0x01);
801dfe64dd3Smacallan}
802