Mercurial > mplayer.hg
annotate vidix/drivers/mach64_vid.c @ 7222:81f720e51821
added LCL decoder by Roberto Togni <r_togni@libero.it>, removed my old vd_zlib
author | alex |
---|---|
date | Sun, 01 Sep 2002 15:10:01 +0000 |
parents | d2aec12937f8 |
children | 52818222a8be |
rev | line source |
---|---|
4691 | 1 /* |
2 mach64_vid - VIDIX based video driver for Mach64 and 3DRage chips | |
3 Copyrights 2002 Nick Kurshev. This file is based on sources from | |
4 GATOS (gatos.sf.net) and X11 (www.xfree86.org) | |
5 Licence: GPL | |
4866 | 6 WARNING: THIS DRIVER IS IN BETTA STAGE |
4691 | 7 */ |
8 #include <errno.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <math.h> | |
13 #include <inttypes.h> | |
14 #include <fcntl.h> | |
15 | |
16 #include "../vidix.h" | |
17 #include "../fourcc.h" | |
18 #include "../../libdha/libdha.h" | |
19 #include "../../libdha/pci_ids.h" | |
20 #include "../../libdha/pci_names.h" | |
21 | |
22 #include "mach64.h" | |
5641
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
23 #include "../../version.h" |
4691 | 24 |
25 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */ | |
26 | |
27 static void *mach64_mmio_base = 0; | |
28 static void *mach64_mem_base = 0; | |
4721 | 29 static int32_t mach64_overlay_offset = 0; |
4691 | 30 static uint32_t mach64_ram_size = 0; |
4866 | 31 static uint32_t mach64_buffer_base[10][3]; |
32 static int num_mach64_buffers=-1; | |
4876 | 33 static int supports_planar=0; |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
34 static int supports_lcd_v_stretch=0; |
4691 | 35 |
36 pciinfo_t pci_info; | |
37 static int probed = 0; | |
38 static int __verbose = 0; | |
4721 | 39 |
4758 | 40 #define VERBOSE_LEVEL 1 |
41 | |
4721 | 42 typedef struct bes_registers_s |
43 { | |
44 /* base address of yuv framebuffer */ | |
45 uint32_t yuv_base; | |
46 uint32_t fourcc; | |
47 /* YUV BES registers */ | |
48 uint32_t reg_load_cntl; | |
49 uint32_t scale_inc; | |
50 uint32_t y_x_start; | |
51 uint32_t y_x_end; | |
52 uint32_t vid_buf_pitch; | |
53 uint32_t height_width; | |
54 | |
55 uint32_t scale_cntl; | |
56 uint32_t exclusive_horz; | |
57 uint32_t auto_flip_cntl; | |
58 uint32_t filter_cntl; | |
59 uint32_t key_cntl; | |
60 uint32_t test; | |
61 /* Configurable stuff */ | |
62 | |
63 int brightness; | |
64 int saturation; | |
65 | |
66 int ckey_on; | |
67 uint32_t graphics_key_clr; | |
68 uint32_t graphics_key_msk; | |
69 | |
70 int deinterlace_on; | |
71 uint32_t deinterlace_pattern; | |
72 | |
73 } bes_registers_t; | |
74 | |
75 static bes_registers_t besr; | |
76 | |
77 typedef struct video_registers_s | |
78 { | |
79 const char * sname; | |
80 uint32_t name; | |
81 uint32_t value; | |
82 }video_registers_t; | |
83 | |
84 static bes_registers_t besr; | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
85 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
86 /* Graphic keys */ |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
87 static vidix_grkey_t mach64_grkey; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
88 |
4721 | 89 #define DECLARE_VREG(name) { #name, name, 0 } |
90 static video_registers_t vregs[] = | |
91 { | |
92 DECLARE_VREG(OVERLAY_SCALE_INC), | |
93 DECLARE_VREG(OVERLAY_Y_X_START), | |
94 DECLARE_VREG(OVERLAY_Y_X_END), | |
95 DECLARE_VREG(OVERLAY_SCALE_CNTL), | |
96 DECLARE_VREG(OVERLAY_EXCLUSIVE_HORZ), | |
97 DECLARE_VREG(OVERLAY_EXCLUSIVE_VERT), | |
98 DECLARE_VREG(OVERLAY_TEST), | |
99 DECLARE_VREG(SCALER_BUF_PITCH), | |
100 DECLARE_VREG(SCALER_HEIGHT_WIDTH), | |
101 DECLARE_VREG(SCALER_BUF0_OFFSET), | |
102 DECLARE_VREG(SCALER_BUF0_OFFSET_U), | |
103 DECLARE_VREG(SCALER_BUF0_OFFSET_V), | |
104 DECLARE_VREG(SCALER_BUF1_OFFSET), | |
105 DECLARE_VREG(SCALER_BUF1_OFFSET_U), | |
106 DECLARE_VREG(SCALER_BUF1_OFFSET_V), | |
107 DECLARE_VREG(SCALER_H_COEFF0), | |
108 DECLARE_VREG(SCALER_H_COEFF1), | |
109 DECLARE_VREG(SCALER_H_COEFF2), | |
110 DECLARE_VREG(SCALER_H_COEFF3), | |
111 DECLARE_VREG(SCALER_H_COEFF4), | |
112 DECLARE_VREG(SCALER_COLOUR_CNTL), | |
113 DECLARE_VREG(SCALER_THRESHOLD), | |
114 DECLARE_VREG(VIDEO_FORMAT), | |
115 DECLARE_VREG(VIDEO_CONFIG), | |
116 DECLARE_VREG(VIDEO_SYNC_TEST), | |
117 DECLARE_VREG(VIDEO_SYNC_TEST_B) | |
118 }; | |
119 | |
4691 | 120 /* VIDIX exports */ |
121 | |
122 /* MMIO space*/ | |
123 #define GETREG(TYPE,PTR,OFFZ) (*((volatile TYPE*)((PTR)+(OFFZ)))) | |
124 #define SETREG(TYPE,PTR,OFFZ,VAL) (*((volatile TYPE*)((PTR)+(OFFZ))))=VAL | |
125 | |
4721 | 126 #define INREG8(addr) GETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2) |
127 #define OUTREG8(addr,val) SETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val) | |
128 #define INREG(addr) GETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2) | |
129 #define OUTREG(addr,val) SETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val) | |
4691 | 130 |
131 #define OUTREGP(addr,val,mask) \ | |
132 do { \ | |
133 unsigned int _tmp = INREG(addr); \ | |
134 _tmp &= (mask); \ | |
135 _tmp |= (val); \ | |
136 OUTREG(addr, _tmp); \ | |
137 } while (0) | |
138 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
139 static __inline__ int ATIGetMach64LCDReg(int _Index) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
140 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
141 OUTREG8(LCD_INDEX, _Index); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
142 return INREG(LCD_DATA); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
143 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
144 |
4691 | 145 static __inline__ uint32_t INPLL(uint32_t addr) |
146 { | |
4721 | 147 uint32_t res; |
5731 | 148 uint32_t in; |
149 | |
5792 | 150 in= INREG(CLOCK_CNTL); |
151 in &= ~((PLL_WR_EN | PLL_ADDR)); //clean some stuff | |
152 OUTREG(CLOCK_CNTL, in | (addr<<10)); | |
5731 | 153 |
4721 | 154 /* read the register value */ |
5792 | 155 res = (INREG(CLOCK_CNTL)>>16)&0xFF; |
4721 | 156 return res; |
4691 | 157 } |
158 | |
4721 | 159 static __inline__ void OUTPLL(uint32_t addr,uint32_t val) |
160 { | |
5792 | 161 //FIXME buggy but its not used |
4721 | 162 /* write addr byte */ |
163 OUTREG8(CLOCK_CNTL + 1, (addr << 2) | PLL_WR_EN); | |
164 /* write the register value */ | |
165 OUTREG(CLOCK_CNTL + 2, val); | |
166 OUTREG8(CLOCK_CNTL + 1, (addr << 2) & ~PLL_WR_EN); | |
167 } | |
168 | |
4691 | 169 #define OUTPLLP(addr,val,mask) \ |
170 do { \ | |
171 unsigned int _tmp = INPLL(addr); \ | |
172 _tmp &= (mask); \ | |
173 _tmp |= (val); \ | |
174 OUTPLL(addr, _tmp); \ | |
175 } while (0) | |
176 | |
4721 | 177 static void mach64_fifo_wait(unsigned n) |
178 { | |
179 while ((INREG(FIFO_STAT) & 0xffff) > ((uint32_t)(0x8000 >> n))); | |
180 } | |
181 | |
182 static void mach64_wait_for_idle( void ) | |
183 { | |
184 mach64_fifo_wait(16); | |
185 while ((INREG(GUI_STAT) & 1)!= 0); | |
186 } | |
187 | |
4876 | 188 static void mach64_wait_vsync( void ) |
189 { | |
190 int i; | |
191 | |
192 for(i=0; i<2000000; i++) | |
193 if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK)==0 ) break; | |
194 for(i=0; i<2000000; i++) | |
195 if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK) ) break; | |
196 | |
197 } | |
198 | |
4691 | 199 static vidix_capability_t mach64_cap = |
200 { | |
201 "BES driver for Mach64/3DRage cards", | |
4872 | 202 "Nick Kurshev and Michael Niedermayer", |
4691 | 203 TYPE_OUTPUT, |
204 { 0, 0, 0, 0 }, | |
205 2048, | |
206 2048, | |
207 4, | |
208 4, | |
209 -1, | |
210 FLAG_UPSCALER|FLAG_DOWNSCALER, | |
211 VENDOR_ATI, | |
212 -1, | |
213 { 0, 0, 0, 0 } | |
214 }; | |
215 | |
4721 | 216 static uint32_t mach64_vid_get_dbpp( void ) |
217 { | |
218 uint32_t dbpp,retval; | |
219 dbpp = (INREG(CRTC_GEN_CNTL)>>8)& 0x7; | |
220 switch(dbpp) | |
221 { | |
222 case 1: retval = 4; break; | |
223 case 2: retval = 8; break; | |
224 case 3: retval = 15; break; | |
225 case 4: retval = 16; break; | |
226 case 5: retval = 24; break; | |
227 default: retval=32; break; | |
228 } | |
229 return retval; | |
230 } | |
231 | |
232 static int mach64_is_dbl_scan( void ) | |
233 { | |
234 return INREG(CRTC_GEN_CNTL) & CRTC_DBL_SCAN_EN; | |
235 } | |
236 | |
237 static int mach64_is_interlace( void ) | |
238 { | |
239 return INREG(CRTC_GEN_CNTL) & CRTC_INTERLACE_EN; | |
240 } | |
241 | |
242 static uint32_t mach64_get_xres( void ) | |
243 { | |
244 /* FIXME: currently we extract that from CRTC!!!*/ | |
245 uint32_t xres,h_total; | |
246 h_total = INREG(CRTC_H_TOTAL_DISP); | |
247 xres = (h_total >> 16) & 0xffff; | |
248 return (xres + 1)*8; | |
249 } | |
250 | |
251 static uint32_t mach64_get_yres( void ) | |
252 { | |
253 /* FIXME: currently we extract that from CRTC!!!*/ | |
254 uint32_t yres,v_total; | |
255 v_total = INREG(CRTC_V_TOTAL_DISP); | |
256 yres = (v_total >> 16) & 0xffff; | |
257 return yres + 1; | |
258 } | |
259 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
260 // returns the verical stretch factor in 16.16 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
261 static int mach64_get_vert_stretch(void) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
262 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
263 int lcd_index; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
264 int vert_stretching; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
265 int ext_vert_stretch; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
266 int ret; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
267 int yres= mach64_get_yres(); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
268 |
5641
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
269 if(!supports_lcd_v_stretch){ |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
270 if(__verbose>0) printf("[mach64] vertical stretching not supported\n"); |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
271 return 1<<16; |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
272 } |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
273 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
274 lcd_index= INREG(LCD_INDEX); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
275 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
276 vert_stretching= ATIGetMach64LCDReg(LCD_VERT_STRETCHING); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
277 if(!(vert_stretching&VERT_STRETCH_EN)) ret= 1<<16; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
278 else |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
279 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
280 int panel_size; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
281 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
282 ext_vert_stretch= ATIGetMach64LCDReg(LCD_EXT_VERT_STRETCH); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
283 panel_size= (ext_vert_stretch&VERT_PANEL_SIZE)>>11; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
284 panel_size++; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
285 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
286 ret= ((yres<<16) + (panel_size>>1))/panel_size; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
287 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
288 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
289 // lcd_gen_ctrl = ATIGetMach64LCDReg(LCD_GEN_CNTL); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
290 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
291 OUTREG(LCD_INDEX, lcd_index); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
292 |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
293 if(__verbose>0) printf("[mach64] vertical stretching factor= %d\n", ret); |
4872 | 294 |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
295 return ret; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
296 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
297 |
4721 | 298 static void mach64_vid_make_default() |
299 { | |
4872 | 300 mach64_fifo_wait(5); |
4761 | 301 OUTREG(SCALER_COLOUR_CNTL,0x00101000); |
4872 | 302 |
303 besr.ckey_on=0; | |
304 besr.graphics_key_msk=0; | |
305 besr.graphics_key_clr=0; | |
306 | |
307 OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk); | |
308 OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr); | |
309 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND); | |
310 | |
4721 | 311 } |
312 | |
313 static void mach64_vid_dump_regs( void ) | |
314 { | |
315 size_t i; | |
316 printf("[mach64] *** Begin of DRIVER variables dump ***\n"); | |
317 printf("[mach64] mach64_mmio_base=%p\n",mach64_mmio_base); | |
318 printf("[mach64] mach64_mem_base=%p\n",mach64_mem_base); | |
319 printf("[mach64] mach64_overlay_off=%08X\n",mach64_overlay_offset); | |
320 printf("[mach64] mach64_ram_size=%08X\n",mach64_ram_size); | |
321 printf("[mach64] video mode: %ux%u@%u\n",mach64_get_xres(),mach64_get_yres(),mach64_vid_get_dbpp()); | |
322 printf("[mach64] *** Begin of OV0 registers dump ***\n"); | |
323 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++) | |
324 { | |
325 mach64_wait_for_idle(); | |
326 printf("[mach64] %s = %08X\n",vregs[i].sname,INREG(vregs[i].name)); | |
327 } | |
328 printf("[mach64] *** End of OV0 registers dump ***\n"); | |
329 } | |
330 | |
331 | |
4691 | 332 unsigned int vixGetVersion(void) |
333 { | |
334 return(VIDIX_VERSION); | |
335 } | |
336 | |
337 static unsigned short ati_card_ids[] = | |
338 { | |
339 DEVICE_ATI_215CT_MACH64_CT, | |
340 DEVICE_ATI_210888CX_MACH64_CX, | |
341 DEVICE_ATI_210888ET_MACH64_ET, | |
342 DEVICE_ATI_MACH64_VT, | |
343 DEVICE_ATI_210888GX_MACH64_GX, | |
344 DEVICE_ATI_264LT_MACH64_LT, | |
345 DEVICE_ATI_264VT_MACH64_VT, | |
346 DEVICE_ATI_264VT3_MACH64_VT3, | |
347 DEVICE_ATI_264VT4_MACH64_VT4, | |
348 /**/ | |
349 DEVICE_ATI_3D_RAGE_PRO, | |
350 DEVICE_ATI_3D_RAGE_PRO2, | |
351 DEVICE_ATI_3D_RAGE_PRO3, | |
352 DEVICE_ATI_3D_RAGE_PRO4, | |
353 DEVICE_ATI_RAGE_XC, | |
354 DEVICE_ATI_RAGE_XL_AGP, | |
355 DEVICE_ATI_RAGE_XC_AGP, | |
356 DEVICE_ATI_RAGE_XL, | |
357 DEVICE_ATI_3D_RAGE_PRO5, | |
358 DEVICE_ATI_3D_RAGE_PRO6, | |
359 DEVICE_ATI_RAGE_XL2, | |
360 DEVICE_ATI_RAGE_XC2, | |
361 DEVICE_ATI_3D_RAGE_I_II, | |
362 DEVICE_ATI_3D_RAGE_II, | |
363 DEVICE_ATI_3D_RAGE_IIC, | |
364 DEVICE_ATI_3D_RAGE_IIC2, | |
365 DEVICE_ATI_3D_RAGE_IIC3, | |
366 DEVICE_ATI_3D_RAGE_IIC4, | |
367 DEVICE_ATI_3D_RAGE_LT, | |
368 DEVICE_ATI_3D_RAGE_LT2, | |
369 DEVICE_ATI_3D_RAGE_LT_G, | |
370 DEVICE_ATI_3D_RAGE_LT3, | |
371 DEVICE_ATI_RAGE_MOBILITY_P_M, | |
372 DEVICE_ATI_RAGE_MOBILITY_L, | |
373 DEVICE_ATI_3D_RAGE_LT4, | |
374 DEVICE_ATI_3D_RAGE_LT5, | |
375 DEVICE_ATI_RAGE_MOBILITY_P_M2, | |
376 DEVICE_ATI_RAGE_MOBILITY_L2 | |
377 }; | |
378 | |
379 static int find_chip(unsigned chip_id) | |
380 { | |
381 unsigned i; | |
382 for(i = 0;i < sizeof(ati_card_ids)/sizeof(unsigned short);i++) | |
383 { | |
384 if(chip_id == ati_card_ids[i]) return i; | |
385 } | |
386 return -1; | |
387 } | |
388 | |
389 int vixProbe(int verbose,int force) | |
390 { | |
391 pciinfo_t lst[MAX_PCI_DEVICES]; | |
392 unsigned i,num_pci; | |
393 int err; | |
394 __verbose = verbose; | |
395 err = pci_scan(lst,&num_pci); | |
396 if(err) | |
397 { | |
398 printf("[mach64] Error occured during pci scan: %s\n",strerror(err)); | |
399 return err; | |
400 } | |
401 else | |
402 { | |
403 err = ENXIO; | |
404 for(i=0;i<num_pci;i++) | |
405 { | |
406 if(lst[i].vendor == VENDOR_ATI) | |
407 { | |
408 int idx; | |
409 const char *dname; | |
410 idx = find_chip(lst[i].device); | |
411 if(idx == -1 && force == PROBE_NORMAL) continue; | |
412 dname = pci_device_name(VENDOR_ATI,lst[i].device); | |
413 dname = dname ? dname : "Unknown chip"; | |
414 printf("[mach64] Found chip: %s\n",dname); | |
415 if(force > PROBE_NORMAL) | |
416 { | |
417 printf("[mach64] Driver was forced. Was found %sknown chip\n",idx == -1 ? "un" : ""); | |
418 if(idx == -1) | |
419 printf("[mach64] Assuming it as Mach64\n"); | |
420 } | |
421 mach64_cap.device_id = lst[i].device; | |
422 err = 0; | |
423 memcpy(&pci_info,&lst[i],sizeof(pciinfo_t)); | |
424 probed=1; | |
425 break; | |
426 } | |
427 } | |
428 } | |
429 if(err && verbose) printf("[mach64] Can't find chip\n"); | |
430 return err; | |
431 } | |
432 | |
4721 | 433 static void reset_regs( void ) |
434 { | |
435 size_t i; | |
436 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++) | |
437 { | |
438 mach64_fifo_wait(2); | |
4758 | 439 OUTREG(vregs[i].name,0); |
4721 | 440 } |
441 } | |
442 | |
443 | |
4691 | 444 int vixInit(void) |
445 { | |
446 int err; | |
447 if(!probed) | |
448 { | |
449 printf("[mach64] Driver was not probed but is being initializing\n"); | |
450 return EINTR; | |
451 } | |
5641
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
452 if(__verbose>0) printf("[mach64] version %s\n", VERSION); |
85df37cde3d3
print version number, so we know if the user forgot to copy/install the driver
michael
parents:
5589
diff
changeset
|
453 |
4721 | 454 if((mach64_mmio_base = map_phys_mem(pci_info.base2,0x4000))==(void *)-1) return ENOMEM; |
455 mach64_wait_for_idle(); | |
4691 | 456 mach64_ram_size = INREG(MEM_CNTL) & CTL_MEM_SIZEB; |
457 if (mach64_ram_size < 8) mach64_ram_size = (mach64_ram_size + 1) * 512; | |
458 else if (mach64_ram_size < 12) mach64_ram_size = (mach64_ram_size - 3) * 1024; | |
459 else mach64_ram_size = (mach64_ram_size - 7) * 2048; | |
460 mach64_ram_size *= 0x400; /* KB -> bytes */ | |
461 if((mach64_mem_base = map_phys_mem(pci_info.base0,mach64_ram_size))==(void *)-1) return ENOMEM; | |
4758 | 462 memset(&besr,0,sizeof(bes_registers_t)); |
4691 | 463 printf("[mach64] Video memory = %uMb\n",mach64_ram_size/0x100000); |
464 err = mtrr_set_type(pci_info.base0,mach64_ram_size,MTRR_TYPE_WRCOMB); | |
465 if(!err) printf("[mach64] Set write-combining type of video memory\n"); | |
4876 | 466 |
467 /* check if planar formats are supported */ | |
468 supports_planar=0; | |
469 mach64_wait_for_idle(); | |
470 mach64_fifo_wait(2); | |
471 if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1; | |
472 else | |
473 { | |
474 OUTREG(SCALER_BUF0_OFFSET_U, -1); | |
475 | |
476 mach64_wait_vsync(); | |
477 mach64_wait_for_idle(); | |
478 mach64_fifo_wait(2); | |
479 | |
480 if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1; | |
481 } | |
482 if(supports_planar) printf("[mach64] Planar YUV formats are supported :)\n"); | |
483 else printf("[mach64] Planar YUV formats are not supported :(\n"); | |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
484 |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
485 if( mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_P_M |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
486 || mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_P_M2 |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
487 || mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_L |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
488 || mach64_cap.device_id==DEVICE_ATI_RAGE_MOBILITY_L2) |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
489 supports_lcd_v_stretch=1; |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
490 else |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
491 supports_lcd_v_stretch=0; |
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
492 |
4721 | 493 reset_regs(); |
4761 | 494 mach64_vid_make_default(); |
4876 | 495 |
4758 | 496 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4691 | 497 return 0; |
498 } | |
499 | |
500 void vixDestroy(void) | |
501 { | |
502 unmap_phys_mem(mach64_mem_base,mach64_ram_size); | |
4721 | 503 unmap_phys_mem(mach64_mmio_base,0x4000); |
4691 | 504 } |
505 | |
506 int vixGetCapability(vidix_capability_t *to) | |
507 { | |
508 memcpy(to, &mach64_cap, sizeof(vidix_capability_t)); | |
509 return 0; | |
510 } | |
511 | |
4721 | 512 static unsigned mach64_query_pitch(unsigned fourcc,const vidix_yuv_t *spitch) |
513 { | |
514 unsigned pitch,spy,spv,spu; | |
515 spy = spv = spu = 0; | |
516 switch(spitch->y) | |
517 { | |
518 case 16: | |
519 case 32: | |
520 case 64: | |
521 case 128: | |
522 case 256: spy = spitch->y; break; | |
523 default: break; | |
524 } | |
525 switch(spitch->u) | |
526 { | |
527 case 16: | |
528 case 32: | |
529 case 64: | |
530 case 128: | |
531 case 256: spu = spitch->u; break; | |
532 default: break; | |
533 } | |
534 switch(spitch->v) | |
535 { | |
536 case 16: | |
537 case 32: | |
538 case 64: | |
539 case 128: | |
540 case 256: spv = spitch->v; break; | |
541 default: break; | |
542 } | |
543 switch(fourcc) | |
544 { | |
545 /* 4:2:0 */ | |
546 case IMGFMT_IYUV: | |
547 case IMGFMT_YV12: | |
548 case IMGFMT_I420: | |
549 if(spy > 16 && spu == spy/2 && spv == spy/2) pitch = spy; | |
550 else pitch = 32; | |
551 break; | |
4872 | 552 case IMGFMT_YVU9: |
553 if(spy > 32 && spu == spy/4 && spv == spy/4) pitch = spy; | |
554 else pitch = 64; | |
555 break; | |
4721 | 556 default: |
4722
39f3bfae472c
Direct rendering with dshow codecs support. (Was untested but should work)
nick
parents:
4721
diff
changeset
|
557 if(spy >= 16) pitch = spy; |
39f3bfae472c
Direct rendering with dshow codecs support. (Was untested but should work)
nick
parents:
4721
diff
changeset
|
558 else pitch = 16; |
4721 | 559 break; |
560 } | |
561 return pitch; | |
562 } | |
563 | |
564 static void mach64_compute_framesize(vidix_playback_t *info) | |
565 { | |
566 unsigned pitch,awidth; | |
567 pitch = mach64_query_pitch(info->fourcc,&info->src.pitch); | |
568 switch(info->fourcc) | |
569 { | |
570 case IMGFMT_I420: | |
571 case IMGFMT_YV12: | |
572 case IMGFMT_IYUV: | |
573 awidth = (info->src.w + (pitch-1)) & ~(pitch-1); | |
574 info->frame_size = awidth*(info->src.h+info->src.h/2); | |
575 break; | |
4872 | 576 case IMGFMT_YVU9: |
577 awidth = (info->src.w + (pitch-1)) & ~(pitch-1); | |
578 info->frame_size = awidth*(info->src.h+info->src.h/8); | |
579 break; | |
580 // case IMGFMT_RGB32: | |
4721 | 581 case IMGFMT_BGR32: |
582 awidth = (info->src.w*4 + (pitch-1)) & ~(pitch-1); | |
583 info->frame_size = (awidth*info->src.h); | |
584 break; | |
585 /* YUY2 YVYU, RGB15, RGB16 */ | |
586 default: | |
587 awidth = (info->src.w*2 + (pitch-1)) & ~(pitch-1); | |
588 info->frame_size = (awidth*info->src.h); | |
589 break; | |
590 } | |
4872 | 591 info->frame_size+=256; // so we have some space for alignment & such |
592 info->frame_size&=~16; | |
4721 | 593 } |
594 | |
595 static void mach64_vid_stop_video( void ) | |
596 { | |
597 mach64_fifo_wait(14); | |
598 OUTREG(OVERLAY_SCALE_CNTL, 0x80000000); | |
599 OUTREG(OVERLAY_EXCLUSIVE_HORZ, 0); | |
600 OUTREG(OVERLAY_EXCLUSIVE_VERT, 0); | |
601 OUTREG(SCALER_H_COEFF0, 0x00002000); | |
602 OUTREG(SCALER_H_COEFF1, 0x0D06200D); | |
603 OUTREG(SCALER_H_COEFF2, 0x0D0A1C0D); | |
604 OUTREG(SCALER_H_COEFF3, 0x0C0E1A0C); | |
605 OUTREG(SCALER_H_COEFF4, 0x0C14140C); | |
606 OUTREG(VIDEO_FORMAT, 0xB000B); | |
607 OUTREG(OVERLAY_TEST, 0x0); | |
608 } | |
609 | |
610 static void mach64_vid_display_video( void ) | |
611 { | |
612 uint32_t vf; | |
613 mach64_fifo_wait(14); | |
614 | |
615 OUTREG(OVERLAY_Y_X_START, besr.y_x_start); | |
616 OUTREG(OVERLAY_Y_X_END, besr.y_x_end); | |
617 OUTREG(OVERLAY_SCALE_INC, besr.scale_inc); | |
618 OUTREG(SCALER_BUF_PITCH, besr.vid_buf_pitch); | |
619 OUTREG(SCALER_HEIGHT_WIDTH, besr.height_width); | |
4866 | 620 OUTREG(SCALER_BUF0_OFFSET, mach64_buffer_base[0][0]); |
621 OUTREG(SCALER_BUF0_OFFSET_U, mach64_buffer_base[0][1]); | |
622 OUTREG(SCALER_BUF0_OFFSET_V, mach64_buffer_base[0][2]); | |
623 OUTREG(SCALER_BUF1_OFFSET, mach64_buffer_base[0][0]); | |
624 OUTREG(SCALER_BUF1_OFFSET_U, mach64_buffer_base[0][1]); | |
625 OUTREG(SCALER_BUF1_OFFSET_V, mach64_buffer_base[0][2]); | |
4876 | 626 mach64_wait_vsync(); |
627 | |
628 mach64_fifo_wait(4); | |
4758 | 629 OUTREG(OVERLAY_SCALE_CNTL, 0xC4000003); |
4760 | 630 // OVERLAY_SCALE_CNTL bits & what they seem to affect |
631 // bit 0 no effect | |
632 // bit 1 yuv2rgb coeff related | |
633 // bit 2 horizontal interpolation if 0 | |
634 // bit 3 vertical interpolation if 0 | |
4847 | 635 // bit 4 chroma encoding (0-> 128=neutral / 1-> 0->neutral) |
4760 | 636 // bit 5-6 gamma correction |
637 // bit 7 nothing visible if set | |
638 // bit 8-27 no effect | |
639 // bit 28-31 nothing interresting just crashed my system when i played with them :( | |
4847 | 640 |
4721 | 641 mach64_wait_for_idle(); |
642 vf = INREG(VIDEO_FORMAT); | |
4751 | 643 |
644 // Bits 16-19 seem to select the format | |
4769 | 645 // 0x0 dunno behaves strange |
646 // 0x1 dunno behaves strange | |
647 // 0x2 dunno behaves strange | |
648 // 0x3 BGR15 | |
649 // 0x4 BGR16 | |
650 // 0x5 BGR16 (hmm, that need investigation, 2 BGR16 formats, i guess 1 will have only 5bits for green) | |
651 // 0x6 BGR32 | |
652 // 0x7 BGR32 with somehow mixed even / odd pixels ? | |
653 // 0x8 YYYYUVUV | |
654 // 0x9 YVU9 | |
655 // 0xA YV12 | |
656 // 0xB YUY2 | |
657 // 0xC UYVY | |
4847 | 658 // 0xD UYVY (no difference is visible if i switch between C/D for every even/odd frame) |
4769 | 659 // 0xE dunno behaves strange |
660 // 0xF dunno behaves strange | |
661 // Bit 28 all values are assumed to be 7 bit with chroma=64 for black (tested with YV12 & YUY2) | |
4751 | 662 // the remaining bits seem to have no effect |
663 | |
4769 | 664 |
4721 | 665 switch(besr.fourcc) |
666 { | |
4769 | 667 /* BGR formats */ |
668 case IMGFMT_BGR15: OUTREG(VIDEO_FORMAT, 0x00030000); break; | |
669 case IMGFMT_BGR16: OUTREG(VIDEO_FORMAT, 0x00040000); break; | |
670 case IMGFMT_BGR32: OUTREG(VIDEO_FORMAT, 0x00060000); break; | |
4721 | 671 /* 4:2:0 */ |
672 case IMGFMT_IYUV: | |
673 case IMGFMT_I420: | |
4769 | 674 case IMGFMT_YV12: OUTREG(VIDEO_FORMAT, 0x000A0000); break; |
4872 | 675 |
676 case IMGFMT_YVU9: OUTREG(VIDEO_FORMAT, 0x00090000); break; | |
4721 | 677 /* 4:2:2 */ |
678 case IMGFMT_YVYU: | |
4769 | 679 case IMGFMT_UYVY: OUTREG(VIDEO_FORMAT, 0x000C0000); break; |
4721 | 680 case IMGFMT_YUY2: |
4769 | 681 default: OUTREG(VIDEO_FORMAT, 0x000B0000); break; |
4721 | 682 } |
4758 | 683 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4721 | 684 } |
685 | |
686 static int mach64_vid_init_video( vidix_playback_t *config ) | |
687 { | |
4758 | 688 uint32_t src_w,src_h,dest_w,dest_h,pitch,h_inc,v_inc,left,leftUV,top,ecp,y_pos; |
4721 | 689 int is_420,best_pitch,mpitch; |
4866 | 690 int src_offset_y, src_offset_u, src_offset_v; |
691 unsigned int i; | |
4872 | 692 |
4721 | 693 mach64_vid_stop_video(); |
4866 | 694 /* warning, if left or top are != 0 this will fail, as the framesize is too small then */ |
695 left = config->src.x; | |
696 top = config->src.y; | |
4721 | 697 src_h = config->src.h; |
698 src_w = config->src.w; | |
699 is_420 = 0; | |
700 if(config->fourcc == IMGFMT_YV12 || | |
701 config->fourcc == IMGFMT_I420 || | |
702 config->fourcc == IMGFMT_IYUV) is_420 = 1; | |
703 best_pitch = mach64_query_pitch(config->fourcc,&config->src.pitch); | |
704 mpitch = best_pitch-1; | |
705 switch(config->fourcc) | |
706 { | |
4872 | 707 case IMGFMT_YVU9: |
4721 | 708 /* 4:2:0 */ |
709 case IMGFMT_IYUV: | |
710 case IMGFMT_YV12: | |
711 case IMGFMT_I420: pitch = (src_w + mpitch) & ~mpitch; | |
712 config->dest.pitch.y = | |
713 config->dest.pitch.u = | |
714 config->dest.pitch.v = best_pitch; | |
4769 | 715 besr.vid_buf_pitch= pitch; |
4721 | 716 break; |
717 /* RGB 4:4:4:4 */ | |
718 case IMGFMT_RGB32: | |
719 case IMGFMT_BGR32: pitch = (src_w*4 + mpitch) & ~mpitch; | |
720 config->dest.pitch.y = | |
721 config->dest.pitch.u = | |
722 config->dest.pitch.v = best_pitch; | |
4769 | 723 besr.vid_buf_pitch= pitch>>2; |
4721 | 724 break; |
725 /* 4:2:2 */ | |
726 default: /* RGB15, RGB16, YVYU, UYVY, YUY2 */ | |
727 pitch = ((src_w*2) + mpitch) & ~mpitch; | |
728 config->dest.pitch.y = | |
729 config->dest.pitch.u = | |
730 config->dest.pitch.v = best_pitch; | |
4769 | 731 besr.vid_buf_pitch= pitch>>1; |
4721 | 732 break; |
733 } | |
734 dest_w = config->dest.w; | |
735 dest_h = config->dest.h; | |
736 besr.fourcc = config->fourcc; | |
737 ecp = (INPLL(PLL_VCLK_CNTL) & PLL_ECP_DIV) >> 4; | |
5792 | 738 #if 0 |
739 { | |
740 int i; | |
741 for(i=0; i<32; i++){ | |
742 printf("%X ", INPLL(i)); | |
743 } | |
744 } | |
745 #endif | |
5574
bdfd4b72244a
fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
michael
parents:
5165
diff
changeset
|
746 if(__verbose>0) printf("[mach64] ecp: %d\n", ecp); |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
747 v_inc = src_h * mach64_get_vert_stretch(); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
748 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
749 if(mach64_is_interlace()) v_inc<<=1; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
750 if(mach64_is_dbl_scan() ) v_inc>>=1; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
751 v_inc>>=4; // convert 16.16 -> 20.12 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
752 v_inc/= dest_h; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
753 |
5731 | 754 h_inc = (src_w << (12+ecp)) / dest_w; |
4721 | 755 /* keep everything in 16.16 */ |
756 config->offsets[0] = 0; | |
4866 | 757 for(i=1; i<config->num_frames; i++) |
758 config->offsets[i] = config->offsets[i-1] + config->frame_size; | |
759 | |
4872 | 760 /*FIXME the left / top stuff is broken (= zoom a src rectangle from a larger one) |
761 1. the framesize isnt known as the outer src rectangle dimensions arent known | |
762 2. the mach64 needs aligned addresses so it cant work anyway | |
763 -> so we could shift the outer buffer to compensate that but that would mean | |
764 alignment problems for the code which writes into it | |
765 */ | |
766 | |
4721 | 767 if(is_420) |
768 { | |
4866 | 769 config->offset.y= 0; |
4872 | 770 config->offset.u= (pitch*src_h + 15)&~15; |
771 config->offset.v= (config->offset.u + (pitch*src_h>>2) + 15)&~15; | |
772 | |
4866 | 773 src_offset_y= config->offset.y + top*pitch + left; |
774 src_offset_u= config->offset.u + (top*pitch>>2) + (left>>1); | |
775 src_offset_v= config->offset.v + (top*pitch>>2) + (left>>1); | |
4872 | 776 |
4721 | 777 if(besr.fourcc == IMGFMT_I420 || besr.fourcc == IMGFMT_IYUV) |
778 { | |
779 uint32_t tmp; | |
780 tmp = config->offset.u; | |
781 config->offset.u = config->offset.v; | |
782 config->offset.v = tmp; | |
783 } | |
784 } | |
4872 | 785 else if(besr.fourcc == IMGFMT_YVU9) |
786 { | |
787 config->offset.y= 0; | |
788 config->offset.u= (pitch*src_h + 15)&~15; | |
789 config->offset.v= (config->offset.u + (pitch*src_h>>4) + 15)&~15; | |
790 | |
791 src_offset_y= config->offset.y + top*pitch + left; | |
792 src_offset_u= config->offset.u + (top*pitch>>4) + (left>>1); | |
793 src_offset_v= config->offset.v + (top*pitch>>4) + (left>>1); | |
794 } | |
4866 | 795 else if(besr.fourcc == IMGFMT_BGR32) |
796 { | |
797 config->offset.y = config->offset.u = config->offset.v = 0; | |
4872 | 798 src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 2); |
4866 | 799 } |
4721 | 800 else |
801 { | |
4866 | 802 config->offset.y = config->offset.u = config->offset.v = 0; |
4872 | 803 src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 1); |
4866 | 804 } |
805 | |
806 num_mach64_buffers= config->num_frames; | |
807 for(i=0; i<config->num_frames; i++) | |
808 { | |
809 mach64_buffer_base[i][0]= (mach64_overlay_offset + config->offsets[i] + src_offset_y)&~15; | |
810 mach64_buffer_base[i][1]= (mach64_overlay_offset + config->offsets[i] + src_offset_u)&~15; | |
811 mach64_buffer_base[i][2]= (mach64_overlay_offset + config->offsets[i] + src_offset_v)&~15; | |
4721 | 812 } |
813 | |
814 leftUV = (left >> 17) & 15; | |
815 left = (left >> 16) & 15; | |
816 besr.scale_inc = ( h_inc << 16 ) | v_inc; | |
4758 | 817 y_pos = config->dest.y; |
818 if(mach64_is_dbl_scan()) y_pos*=2; | |
819 else | |
820 if(mach64_is_interlace()) y_pos/=2; | |
821 besr.y_x_start = y_pos | (config->dest.x << 16); | |
822 y_pos =config->dest.y + dest_h; | |
823 if(mach64_is_dbl_scan()) y_pos*=2; | |
824 else | |
825 if(mach64_is_interlace()) y_pos/=2; | |
826 besr.y_x_end = y_pos | ((config->dest.x + dest_w) << 16); | |
4721 | 827 besr.height_width = ((src_w - left)<<16) | (src_h - top); |
4769 | 828 |
4721 | 829 return 0; |
830 } | |
831 | |
4876 | 832 static int is_supported_fourcc(uint32_t fourcc) |
4721 | 833 { |
4876 | 834 switch(fourcc) |
835 { | |
836 case IMGFMT_YV12: | |
837 case IMGFMT_I420: | |
838 case IMGFMT_YVU9: | |
839 case IMGFMT_IYUV: | |
840 return supports_planar; | |
841 case IMGFMT_YUY2: | |
842 case IMGFMT_UYVY: | |
843 case IMGFMT_BGR15: | |
844 case IMGFMT_BGR16: | |
845 case IMGFMT_BGR32: | |
846 return 1; | |
847 default: | |
848 return 0; | |
849 } | |
4721 | 850 } |
851 | |
4691 | 852 int vixQueryFourcc(vidix_fourcc_t *to) |
853 { | |
4721 | 854 if(is_supported_fourcc(to->fourcc)) |
855 { | |
856 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
857 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
858 VID_DEPTH_12BPP| VID_DEPTH_15BPP| | |
859 VID_DEPTH_16BPP| VID_DEPTH_24BPP| | |
860 VID_DEPTH_32BPP; | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
861 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; |
4721 | 862 return 0; |
863 } | |
864 else to->depth = to->flags = 0; | |
4691 | 865 return ENOSYS; |
866 } | |
867 | |
868 int vixConfigPlayback(vidix_playback_t *info) | |
869 { | |
4721 | 870 if(!is_supported_fourcc(info->fourcc)) return ENOSYS; |
4866 | 871 |
4721 | 872 mach64_compute_framesize(info); |
4894
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
873 |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
874 if(info->num_frames>4) info->num_frames=4; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
875 for(;info->num_frames>0; info->num_frames--) |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
876 { |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
877 mach64_overlay_offset = mach64_ram_size - info->frame_size*info->num_frames; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
878 mach64_overlay_offset &= 0xffff0000; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
879 if(mach64_overlay_offset>0) break; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
880 } |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
881 if(info->num_frames <= 0) return EINVAL; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
882 |
4721 | 883 info->dga_addr = (char *)mach64_mem_base + mach64_overlay_offset; |
884 mach64_vid_init_video(info); | |
885 return 0; | |
4691 | 886 } |
887 | |
888 int vixPlaybackOn(void) | |
889 { | |
4721 | 890 mach64_vid_display_video(); |
891 return 0; | |
4691 | 892 } |
893 | |
894 int vixPlaybackOff(void) | |
895 { | |
4721 | 896 mach64_vid_stop_video(); |
897 return 0; | |
898 } | |
899 | |
4691 | 900 int vixPlaybackFrameSelect(unsigned int frame) |
901 { | |
4721 | 902 uint32_t off[6]; |
4866 | 903 int i; |
904 int last_frame= (frame-1+num_mach64_buffers) % num_mach64_buffers; | |
905 //printf("Selecting frame %d\n", frame); | |
4721 | 906 /* |
907 buf3-5 always should point onto second buffer for better | |
908 deinterlacing and TV-in | |
909 */ | |
4866 | 910 if(num_mach64_buffers==1) return 0; |
911 | |
912 for(i=0; i<3; i++) | |
4721 | 913 { |
4866 | 914 off[i] = mach64_buffer_base[frame][i]; |
915 off[i+3]= mach64_buffer_base[last_frame][i]; | |
916 } | |
4769 | 917 |
4847 | 918 #if 0 // delay routine so the individual frames can be ssen better |
919 { | |
920 volatile int i=0; | |
921 for(i=0; i<10000000; i++); | |
922 } | |
923 #endif | |
4721 | 924 |
925 mach64_wait_for_idle(); | |
926 mach64_fifo_wait(7); | |
4847 | 927 |
4721 | 928 OUTREG(SCALER_BUF0_OFFSET, off[0]); |
929 OUTREG(SCALER_BUF0_OFFSET_U, off[1]); | |
930 OUTREG(SCALER_BUF0_OFFSET_V, off[2]); | |
931 OUTREG(SCALER_BUF1_OFFSET, off[3]); | |
932 OUTREG(SCALER_BUF1_OFFSET_U, off[4]); | |
933 OUTREG(SCALER_BUF1_OFFSET_V, off[5]); | |
4866 | 934 if(num_mach64_buffers==2) mach64_wait_vsync(); //only wait for vsync if we do double buffering |
935 | |
4758 | 936 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4721 | 937 return 0; |
4691 | 938 } |
4721 | 939 |
940 vidix_video_eq_t equal = | |
941 { | |
942 VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | |
943 , | |
944 0, 0, 0, 0, 0, 0, 0, 0 }; | |
945 | |
946 int vixPlaybackGetEq( vidix_video_eq_t * eq) | |
947 { | |
948 memcpy(eq,&equal,sizeof(vidix_video_eq_t)); | |
949 return 0; | |
950 } | |
951 | |
952 int vixPlaybackSetEq( const vidix_video_eq_t * eq) | |
953 { | |
954 int br,sat; | |
955 if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness; | |
956 if(eq->cap & VEQ_CAP_CONTRAST) equal.contrast = eq->contrast; | |
957 if(eq->cap & VEQ_CAP_SATURATION) equal.saturation = eq->saturation; | |
958 if(eq->cap & VEQ_CAP_HUE) equal.hue = eq->hue; | |
959 if(eq->cap & VEQ_CAP_RGB_INTENSITY) | |
960 { | |
961 equal.red_intensity = eq->red_intensity; | |
962 equal.green_intensity = eq->green_intensity; | |
963 equal.blue_intensity = eq->blue_intensity; | |
964 } | |
965 equal.flags = eq->flags; | |
966 br = equal.brightness * 64 / 1000; | |
967 if(br < -64) br = -64; if(br > 63) br = 63; | |
968 sat = (equal.saturation + 1000) * 16 / 1000; | |
969 if(sat < 0) sat = 0; if(sat > 31) sat = 31; | |
970 OUTREG(SCALER_COLOUR_CNTL, (br & 0x7f) | (sat << 8) | (sat << 16)); | |
971 return 0; | |
972 } | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
973 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
974 int vixGetGrKeys(vidix_grkey_t *grkey) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
975 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
976 memcpy(grkey, &mach64_grkey, sizeof(vidix_grkey_t)); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
977 return(0); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
978 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
979 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
980 int vixSetGrKeys(const vidix_grkey_t *grkey) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
981 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
982 memcpy(&mach64_grkey, grkey, sizeof(vidix_grkey_t)); |
4872 | 983 |
984 if(mach64_grkey.ckey.op == CKEY_TRUE) | |
985 { | |
986 besr.ckey_on=1; | |
987 | |
988 switch(mach64_vid_get_dbpp()) | |
989 { | |
990 case 15: | |
991 besr.graphics_key_msk=0x7FFF; | |
992 besr.graphics_key_clr= | |
993 ((mach64_grkey.ckey.blue &0xF8)>>3) | |
994 | ((mach64_grkey.ckey.green&0xF8)<<2) | |
995 | ((mach64_grkey.ckey.red &0xF8)<<7); | |
996 break; | |
997 case 16: | |
998 besr.graphics_key_msk=0xFFFF; | |
999 besr.graphics_key_clr= | |
1000 ((mach64_grkey.ckey.blue &0xF8)>>3) | |
1001 | ((mach64_grkey.ckey.green&0xFC)<<3) | |
1002 | ((mach64_grkey.ckey.red &0xF8)<<8); | |
1003 break; | |
1004 case 24: | |
1005 besr.graphics_key_msk=0xFFFFFF; | |
1006 besr.graphics_key_clr= | |
1007 ((mach64_grkey.ckey.blue &0xFF)) | |
1008 | ((mach64_grkey.ckey.green&0xFF)<<8) | |
1009 | ((mach64_grkey.ckey.red &0xFF)<<16); | |
1010 break; | |
1011 case 32: | |
1012 besr.graphics_key_msk=0xFFFFFF; | |
1013 besr.graphics_key_clr= | |
1014 ((mach64_grkey.ckey.blue &0xFF)) | |
1015 | ((mach64_grkey.ckey.green&0xFF)<<8) | |
1016 | ((mach64_grkey.ckey.red &0xFF)<<16); | |
1017 break; | |
1018 default: | |
1019 besr.ckey_on=0; | |
1020 besr.graphics_key_msk=0; | |
1021 besr.graphics_key_clr=0; | |
1022 } | |
1023 } | |
1024 else | |
1025 { | |
1026 besr.ckey_on=0; | |
1027 besr.graphics_key_msk=0; | |
1028 besr.graphics_key_clr=0; | |
1029 } | |
1030 | |
1031 mach64_fifo_wait(4); | |
1032 OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk); | |
1033 OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr); | |
1034 // OUTREG(OVERLAY_VIDEO_KEY_MSK, 0); | |
1035 // OUTREG(OVERLAY_VIDEO_KEY_CLR, 0); | |
1036 if(besr.ckey_on) | |
1037 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND); | |
1038 else | |
1039 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_TRUE|CMP_MIX_AND); | |
1040 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
1041 return(0); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
1042 } |