2870
|
1 /*
|
|
2 *
|
|
3 * radeon_vid.c
|
|
4 *
|
|
5 * Copyright (C) 2001 Nick Kurshev
|
|
6 *
|
|
7 * BES YUV Framebuffer driver for Radeon cards
|
|
8 *
|
|
9 * This software has been released under the terms of the GNU Public
|
|
10 * license. See http://www.gnu.org/copyleft/gpl.html for details.
|
|
11 *
|
|
12 * This file is partly based on mga_vid and sis_vid stuff from
|
|
13 * mplayer's package.
|
2917
|
14 * Also here was used code from CVS of GATOS project and X11 trees.
|
2870
|
15 */
|
|
16
|
2951
|
17 #define RADEON_VID_VERSION "0.9.9"
|
|
18
|
2870
|
19 /*
|
|
20 It's entirely possible this major conflicts with something else
|
|
21 mknod /dev/radeon_vid c 178 0
|
|
22 */
|
|
23
|
|
24 /*
|
|
25 TODO:
|
|
26 OV0_COLOUR_CNTL brightness saturation
|
|
27 SCALER_GAMMA_SEL_BRIGHT gamma correction ???
|
|
28 OV0_GRAPHICS_KEY_CLR color key
|
|
29 OV0_AUTO_FLIP_CNTL
|
|
30 OV0_FILTER_CNTL
|
|
31 OV0_VIDEO_KEY_CLR
|
|
32 OV0_KEY_CNTL
|
|
33
|
|
34 BPP should be known
|
|
35 */
|
|
36
|
|
37 #include <linux/config.h>
|
|
38 #include <linux/version.h>
|
|
39 #include <linux/module.h>
|
|
40 #include <linux/types.h>
|
|
41 #include <linux/kernel.h>
|
|
42 #include <linux/sched.h>
|
|
43 #include <linux/mm.h>
|
|
44 #include <linux/string.h>
|
|
45 #include <linux/errno.h>
|
|
46 #include <linux/slab.h>
|
|
47 #include <linux/pci.h>
|
|
48 #include <linux/ioport.h>
|
|
49 #include <linux/init.h>
|
|
50
|
|
51 #include "radeon_vid.h"
|
|
52 #include "radeon.h"
|
|
53
|
|
54 #ifdef CONFIG_MTRR
|
|
55 #include <asm/mtrr.h>
|
|
56 #endif
|
|
57
|
|
58 #include <asm/uaccess.h>
|
|
59 #include <asm/system.h>
|
|
60 #include <asm/io.h>
|
|
61
|
|
62 #define TRUE 1
|
|
63 #define FALSE 0
|
|
64
|
|
65 #define RADEON_VID_MAJOR 178
|
|
66
|
|
67
|
|
68 MODULE_AUTHOR("Nick Kurshev <nickols_k@mail.ru>");
|
2951
|
69 MODULE_DESCRIPTION("Accelerated YUV BES driver for Radeons. Version: "RADEON_VID_VERSION);
|
2965
|
70 #ifdef MODULE_LICENSE
|
2870
|
71 MODULE_LICENSE("GPL");
|
2965
|
72 #endif
|
2870
|
73
|
|
74 typedef struct bes_registers_s
|
|
75 {
|
|
76 /* base address of yuv framebuffer */
|
|
77 uint32_t yuv_base;
|
|
78 uint32_t fourcc;
|
|
79 /* YUV BES registers */
|
|
80 uint32_t reg_load_cntl;
|
|
81 uint32_t h_inc;
|
|
82 uint32_t step_by;
|
|
83 uint32_t y_x_start;
|
|
84 uint32_t y_x_end;
|
|
85 uint32_t v_inc;
|
|
86 uint32_t p1_blank_lines_at_top;
|
|
87 uint32_t vid_buf_pitch0_value;
|
2944
|
88 uint32_t vid_buf_pitch1_value;
|
2870
|
89 uint32_t p1_x_start_end;
|
|
90 uint32_t p2_x_start_end;
|
|
91 uint32_t p3_x_start_end;
|
|
92 uint32_t vid_buf0_base_adrs;
|
|
93 /* These ones are for auto flip: maybe in the future */
|
|
94 uint32_t vid_buf1_base_adrs;
|
|
95 uint32_t vid_buf2_base_adrs;
|
|
96 uint32_t vid_buf3_base_adrs;
|
|
97 uint32_t vid_buf4_base_adrs;
|
|
98 uint32_t vid_buf5_base_adrs;
|
|
99
|
|
100 uint32_t p1_v_accum_init;
|
|
101 uint32_t p1_h_accum_init;
|
|
102 uint32_t p23_h_accum_init;
|
|
103 uint32_t scale_cntl;
|
|
104 uint32_t exclusive_horz;
|
|
105 uint32_t auto_flip_cntl;
|
|
106 uint32_t filter_cntl;
|
|
107 uint32_t colour_cntl;
|
|
108 uint32_t graphics_key_msk;
|
|
109 uint32_t graphics_key_clr;
|
|
110 uint32_t key_cntl;
|
|
111 uint32_t test;
|
|
112 } bes_registers_t;
|
|
113
|
|
114 typedef struct video_registers_s
|
|
115 {
|
|
116 uint32_t name;
|
|
117 uint32_t value;
|
|
118 }video_registers_t;
|
|
119
|
|
120 static bes_registers_t besr;
|
|
121 static video_registers_t vregs[] =
|
|
122 {
|
|
123 { OV0_REG_LOAD_CNTL, 0 },
|
|
124 { OV0_H_INC, 0 },
|
|
125 { OV0_STEP_BY, 0 },
|
|
126 { OV0_Y_X_START, 0 },
|
|
127 { OV0_Y_X_END, 0 },
|
|
128 { OV0_V_INC, 0 },
|
|
129 { OV0_P1_BLANK_LINES_AT_TOP, 0 },
|
|
130 { OV0_VID_BUF_PITCH0_VALUE, 0 },
|
2944
|
131 { OV0_VID_BUF_PITCH1_VALUE, 0 },
|
2870
|
132 { OV0_P1_X_START_END, 0 },
|
|
133 { OV0_P2_X_START_END, 0 },
|
|
134 { OV0_P3_X_START_END, 0 },
|
|
135 { OV0_VID_BUF0_BASE_ADRS, 0 },
|
|
136 { OV0_VID_BUF1_BASE_ADRS, 0 },
|
|
137 { OV0_VID_BUF2_BASE_ADRS, 0 },
|
|
138 { OV0_VID_BUF3_BASE_ADRS, 0 },
|
|
139 { OV0_VID_BUF4_BASE_ADRS, 0 },
|
|
140 { OV0_VID_BUF5_BASE_ADRS, 0 },
|
|
141 { OV0_P1_V_ACCUM_INIT, 0 },
|
|
142 { OV0_P1_H_ACCUM_INIT, 0 },
|
|
143 { OV0_P23_H_ACCUM_INIT, 0 },
|
|
144 { OV0_SCALE_CNTL, 0 },
|
|
145 { OV0_EXCLUSIVE_HORZ, 0 },
|
|
146 { OV0_AUTO_FLIP_CNTL, 0 },
|
|
147 { OV0_FILTER_CNTL, 0 },
|
|
148 { OV0_COLOUR_CNTL, 0 },
|
|
149 { OV0_GRAPHICS_KEY_MSK, 0 },
|
|
150 { OV0_GRAPHICS_KEY_CLR, 0 },
|
|
151 { OV0_KEY_CNTL, 0 },
|
|
152 { OV0_TEST, 0 }
|
|
153 };
|
|
154
|
|
155 static uint32_t radeon_vid_in_use = 0;
|
|
156
|
|
157 static uint8_t *radeon_mmio_base = 0;
|
|
158 static uint32_t radeon_mem_base = 0;
|
2951
|
159 #define RADEON_SRC_BASE 0x1000000ULL /* this driver uses all video memory */
|
2870
|
160
|
|
161 static uint32_t radeon_ram_size = 0;
|
|
162
|
|
163 //static struct video_window radeon_win;
|
|
164 static mga_vid_config_t radeon_config;
|
|
165
|
2951
|
166 #undef DEBUG
|
2870
|
167 #if DEBUG
|
|
168 #define RTRACE printk
|
|
169 #else
|
|
170 #define RTRACE(...) ((void)0)
|
|
171 #endif
|
|
172
|
|
173
|
|
174 /*
|
|
175 * IO macros
|
|
176 */
|
|
177
|
|
178 #define INREG8(addr) readb((radeon_mmio_base)+addr)
|
|
179 #define OUTREG8(addr,val) writeb(val, (radeon_mmio_base)+addr)
|
|
180 #define INREG(addr) readl((radeon_mmio_base)+addr)
|
|
181 #define OUTREG(addr,val) writel(val, (radeon_mmio_base)+addr)
|
|
182
|
|
183 static void radeon_vid_save_state( void )
|
|
184 {
|
|
185 size_t i;
|
|
186 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++)
|
|
187 vregs[i].value = INREG(vregs[i].name);
|
|
188 }
|
|
189
|
|
190 static void radeon_vid_restore_state( void )
|
|
191 {
|
|
192 size_t i;
|
|
193 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++)
|
|
194 OUTREG(vregs[i].name,vregs[i].value);
|
|
195 }
|
|
196
|
|
197 static void radeon_vid_stop_video( void )
|
|
198 {
|
|
199 OUTREG(OV0_SCALE_CNTL, SCALER_SOFT_RESET);
|
|
200 OUTREG(OV0_EXCLUSIVE_HORZ, 0);
|
|
201 OUTREG(OV0_AUTO_FLIP_CNTL, 0); /* maybe */
|
|
202 OUTREG(OV0_FILTER_CNTL, 0x0000000f);
|
|
203 /*
|
|
204 OUTREG(OV0_COLOUR_CNTL, (brightness & 0x7f) |
|
|
205 (saturation << 8) |
|
|
206 (saturation << 16));
|
|
207 OUTREG(OV0_GRAPHICS_KEY_MSK, (1 << depth) - 1);
|
|
208 OUTREG(OV0_GRAPHICS_KEY_CLR, colorKey);
|
|
209 */
|
|
210 OUTREG(OV0_KEY_CNTL, GRAPHIC_KEY_FN_NE);
|
|
211 OUTREG(OV0_TEST, 0);
|
|
212 }
|
|
213
|
|
214 static void radeon_vid_display_video( void )
|
|
215 {
|
|
216 int bes_flags;
|
2925
|
217 RTRACE("radeon_vid: OV0: v_inc=%x h_inc=%x step_by=%x\n",besr.v_inc,besr.h_inc,besr.step_by);
|
2951
|
218 RTRACE("radeon_vid: OV0: vid_buf0_base=%x\n",besr.vid_buf0_base_adrs);
|
2925
|
219 RTRACE("radeon_vid: OV0: y_x_start=%x y_x_end=%x blank_at_top=%x pitch0_value=%x\n"
|
|
220 ,besr.y_x_start,besr.y_x_end,besr.p1_blank_lines_at_top,besr.vid_buf_pitch0_value);
|
2951
|
221 RTRACE("radeon_vid: OV0: p1_x_start_end=%x p2_x_start_end=%x p3_x_start-end=%x\n"
|
|
222 ,besr.p1_x_start_end,besr.p2_x_start_end,besr.p2_x_start_end);
|
|
223 RTRACE("radeon_vid: OV0: p1_v_accum_init=%x p1_h_accum_init=%x p23_h_accum_init=%x\n"
|
|
224 ,besr.p1_v_accum_init,besr.p1_h_accum_init,besr.p23_h_accum_init);
|
2870
|
225 OUTREG(OV0_REG_LOAD_CNTL, REG_LD_CTL_LOCK);
|
|
226 while(!(INREG(OV0_REG_LOAD_CNTL)®_LD_CTL_LOCK_READBACK));
|
2965
|
227
|
2870
|
228 OUTREG(OV0_AUTO_FLIP_CNTL,OV0_AUTO_FLIP_CNTL_SOFT_BUF_ODD);
|
|
229
|
2917
|
230 OUTREG(OV0_DEINTERLACE_PATTERN,0xAAAAAAAA);
|
2870
|
231
|
|
232 OUTREG(OV0_AUTO_FLIP_CNTL,(INREG(OV0_AUTO_FLIP_CNTL)^OV0_AUTO_FLIP_CNTL_SOFT_EOF_TOGGLE));
|
|
233 OUTREG(OV0_AUTO_FLIP_CNTL,(INREG(OV0_AUTO_FLIP_CNTL)^OV0_AUTO_FLIP_CNTL_SOFT_EOF_TOGGLE));
|
2965
|
234
|
2870
|
235 OUTREG(OV0_H_INC, besr.h_inc);
|
|
236 OUTREG(OV0_STEP_BY, besr.step_by);
|
|
237 OUTREG(OV0_Y_X_START, besr.y_x_start);
|
|
238 OUTREG(OV0_Y_X_END, besr.y_x_end);
|
|
239 OUTREG(OV0_V_INC, besr.v_inc);
|
|
240 OUTREG(OV0_P1_BLANK_LINES_AT_TOP, besr.p1_blank_lines_at_top);
|
|
241 OUTREG(OV0_VID_BUF_PITCH0_VALUE, besr.vid_buf_pitch0_value);
|
2944
|
242 OUTREG(OV0_VID_BUF_PITCH1_VALUE, besr.vid_buf_pitch1_value);
|
2870
|
243 OUTREG(OV0_P1_X_START_END, besr.p1_x_start_end);
|
|
244 OUTREG(OV0_P2_X_START_END, besr.p2_x_start_end);
|
|
245 OUTREG(OV0_P3_X_START_END, besr.p3_x_start_end);
|
|
246 OUTREG(OV0_VID_BUF0_BASE_ADRS, besr.vid_buf0_base_adrs);
|
|
247 OUTREG(OV0_VID_BUF1_BASE_ADRS, besr.vid_buf1_base_adrs);
|
|
248 OUTREG(OV0_VID_BUF2_BASE_ADRS, besr.vid_buf2_base_adrs);
|
|
249 OUTREG(OV0_VID_BUF3_BASE_ADRS, besr.vid_buf3_base_adrs);
|
|
250 OUTREG(OV0_VID_BUF4_BASE_ADRS, besr.vid_buf4_base_adrs);
|
|
251 OUTREG(OV0_VID_BUF5_BASE_ADRS, besr.vid_buf5_base_adrs);
|
|
252 OUTREG(OV0_P1_V_ACCUM_INIT, besr.p1_v_accum_init);
|
|
253 OUTREG(OV0_P1_H_ACCUM_INIT, besr.p1_h_accum_init);
|
|
254 OUTREG(OV0_P23_H_ACCUM_INIT, besr.p23_h_accum_init);
|
|
255
|
|
256 bes_flags = SCALER_ENABLE |
|
|
257 SCALER_DOUBLE_BUFFER |
|
2965
|
258 SCALER_ADAPTIVE_DEINT |
|
2870
|
259 SCALER_SMART_SWITCH |
|
|
260 SCALER_HORZ_PICK_NEAREST;
|
|
261 switch(besr.fourcc)
|
|
262 {
|
|
263 case IMGFMT_RGB15:
|
|
264 case IMGFMT_BGR15: bes_flags |= SCALER_SOURCE_15BPP; break;
|
|
265 case IMGFMT_RGB16:
|
|
266 case IMGFMT_BGR16: bes_flags |= SCALER_SOURCE_16BPP; break;
|
|
267 case IMGFMT_RGB24:
|
|
268 case IMGFMT_BGR24: bes_flags |= SCALER_SOURCE_24BPP; break;
|
|
269 case IMGFMT_RGB32:
|
|
270 case IMGFMT_BGR32: bes_flags |= SCALER_SOURCE_32BPP; break;
|
|
271
|
2925
|
272 case IMGFMT_UYVY: bes_flags |= SCALER_SOURCE_YVYU422; break;
|
2870
|
273 case IMGFMT_YVU9: bes_flags |= SCALER_SOURCE_YUV9; break;
|
|
274 case IMGFMT_IYUV: bes_flags |= SCALER_SOURCE_YUV12; break;
|
|
275
|
|
276 case IMGFMT_YV12:
|
|
277 case IMGFMT_I420:
|
|
278 case IMGFMT_YUY2:
|
|
279 default: bes_flags |= SCALER_SOURCE_VYUY422; break;
|
|
280 }
|
2951
|
281 RTRACE("radeon_vid: OV0: SCALER=%x\n",bes_flags);
|
2870
|
282 OUTREG(OV0_SCALE_CNTL, bes_flags);
|
|
283 /*
|
|
284 TODO:
|
|
285 brightness: -64 : +63
|
|
286 saturation: 0 : 31
|
|
287 OUTREG(OV0_COLOUR_CNTL, (brightness & 0x7f) |
|
|
288 (saturation << 8) |
|
|
289 (saturation << 16));
|
|
290 OUTREG(OV0_GRAPHICS_KEY_CLR, colkey_red | colkey_green << 8 | colkey_blue << 16);
|
|
291
|
|
292 */
|
|
293 OUTREG(OV0_REG_LOAD_CNTL, 0);
|
|
294 }
|
|
295
|
|
296 static void radeon_vid_start_video( void )
|
|
297 {
|
2925
|
298 radeon_vid_display_video();
|
2870
|
299 }
|
|
300
|
2951
|
301 #define XXX_SRC_X 0
|
|
302 #define XXX_SRC_Y 0
|
2870
|
303
|
2944
|
304 #define XXX_WIDTH config->src_width
|
|
305 #define XXX_HEIGHT config->src_height
|
2870
|
306
|
2951
|
307 #define XXX_DRW_W config->dest_width
|
|
308 #define XXX_DRW_H config->dest_height
|
2925
|
309
|
2870
|
310 static int radeon_vid_init_video( mga_vid_config_t *config )
|
|
311 {
|
2951
|
312 uint32_t tmp,src_w,pitch,h_inc,step_by,left,top;
|
2870
|
313
|
2951
|
314 RTRACE("radeon_vid: usr_config: version = %x format=%x card=%x ram=%u src(%ux%u) dest(%u:%ux%u:%u) frame_size=%u num_frames=%u\n"
|
2870
|
315 ,(uint32_t)config->version
|
2951
|
316 ,(uint32_t)config->format
|
2870
|
317 ,(uint32_t)config->card_type
|
|
318 ,(uint32_t)config->ram_size
|
|
319 ,(uint32_t)config->src_width
|
|
320 ,(uint32_t)config->src_height
|
|
321 ,(uint32_t)config->x_org
|
|
322 ,(uint32_t)config->y_org
|
|
323 ,(uint32_t)config->dest_width
|
|
324 ,(uint32_t)config->dest_height
|
|
325 ,(uint32_t)config->frame_size
|
|
326 ,(uint32_t)config->num_frames);
|
2917
|
327 radeon_vid_stop_video();
|
2870
|
328 switch(config->format)
|
|
329 {
|
|
330 case IMGFMT_RGB15:
|
|
331 case IMGFMT_BGR15:
|
|
332 case IMGFMT_RGB16:
|
|
333 case IMGFMT_BGR16:
|
|
334 case IMGFMT_RGB24:
|
|
335 case IMGFMT_BGR24:
|
|
336 case IMGFMT_RGB32:
|
|
337 case IMGFMT_BGR32:
|
|
338
|
|
339 case IMGFMT_YVU9:
|
|
340 case IMGFMT_IYUV:
|
|
341 case IMGFMT_UYVY:
|
|
342
|
|
343 case IMGFMT_YV12:
|
|
344 case IMGFMT_I420:
|
|
345 case IMGFMT_YUY2:
|
|
346 break;
|
|
347 default:
|
|
348 printk( "radeon_vid: Unsupported pixel format: 0x%X\n",config->format);
|
|
349 return -1;
|
|
350 }
|
2951
|
351 switch(config->format)
|
|
352 {
|
|
353 default:
|
|
354 case IMGFMT_YVU9:
|
|
355 case IMGFMT_IYUV:
|
|
356 case IMGFMT_UYVY:
|
|
357 case IMGFMT_YV12:
|
|
358 case IMGFMT_I420:
|
|
359 case IMGFMT_YUY2:
|
|
360 case IMGFMT_RGB15:
|
|
361 case IMGFMT_BGR15:
|
|
362 case IMGFMT_RGB16:
|
|
363 case IMGFMT_BGR16: pitch = ((XXX_WIDTH*2) + 15) & ~15; break;
|
|
364 case IMGFMT_RGB24:
|
|
365 case IMGFMT_BGR24: pitch = ((XXX_WIDTH*3) + 15) & ~15; break;
|
|
366 case IMGFMT_RGB32:
|
|
367 case IMGFMT_BGR32: pitch = ((XXX_WIDTH*4) + 15) & ~15; break;
|
|
368 }
|
|
369 /*pitch 9c0 ->4e0 */
|
|
370
|
|
371 left = XXX_SRC_X << 16;
|
|
372 top = XXX_SRC_Y << 16;
|
|
373
|
2870
|
374 besr.fourcc = config->format;
|
|
375
|
2951
|
376 besr.v_inc = (config->src_height << 20) / XXX_DRW_H; /*9c0e0 -> 9c528*/
|
2944
|
377 h_inc = (config->src_width << 12) / XXX_DRW_W;
|
|
378 step_by = 1;
|
2870
|
379
|
2944
|
380 while(h_inc >= (2 << 12)) {
|
|
381 step_by++;
|
|
382 h_inc >>= 1;
|
2870
|
383 }
|
|
384
|
|
385 /* keep everything in 16.16 */
|
|
386
|
|
387 besr.vid_buf0_base_adrs = RADEON_SRC_BASE; /* I guess that offset 0 is o'k */
|
2951
|
388 besr.vid_buf0_base_adrs += ((left & ~7) << 1)&0xfffffff0;
|
2870
|
389 besr.vid_buf1_base_adrs = besr.vid_buf0_base_adrs + config->frame_size;
|
|
390 besr.vid_buf2_base_adrs = besr.vid_buf0_base_adrs;
|
|
391 besr.vid_buf3_base_adrs = besr.vid_buf0_base_adrs + config->frame_size;
|
|
392 besr.vid_buf4_base_adrs = besr.vid_buf0_base_adrs;
|
|
393 besr.vid_buf5_base_adrs = besr.vid_buf0_base_adrs + config->frame_size;
|
|
394
|
2951
|
395 tmp = (left & 0x0003ffff) + 0x00028000 + (h_inc << 3);
|
2870
|
396 besr.p1_h_accum_init = ((tmp << 4) & 0x000f8000) |
|
2951
|
397 ((tmp << 12) & 0xf0000000);
|
2870
|
398
|
2951
|
399 tmp = ((left >> 1) & 0x0001ffff) + 0x00028000 + (h_inc << 2);
|
2870
|
400 besr.p23_h_accum_init = ((tmp << 4) & 0x000f8000) |
|
2951
|
401 ((tmp << 12) & 0x70000000);
|
2870
|
402
|
2951
|
403 tmp = (top & 0x0000ffff) + 0x00018000;
|
2870
|
404 besr.p1_v_accum_init = ((tmp << 4) & 0x03ff8000) | 0x00000001;
|
|
405
|
2951
|
406 left = (left >> 16) & 7;
|
2944
|
407 besr.h_inc = h_inc | ((h_inc >> 1) << 16);
|
|
408 besr.step_by = step_by | (step_by << 8);
|
2951
|
409 besr.y_x_start = (config->x_org+8) | (config->y_org << 16); /*5c008->5d009*/
|
2925
|
410 besr.y_x_end = (config->x_org + config->dest_width+8) | ((config->y_org + config->dest_height) << 16);
|
2870
|
411 besr.p1_blank_lines_at_top = 0x00000fff | ((config->src_height - 1) << 16);
|
|
412 besr.vid_buf_pitch0_value = pitch;
|
2944
|
413 besr.vid_buf_pitch1_value = pitch;
|
2925
|
414 RTRACE("radeon_vid: BES: v_inc=%x h_inc=%x step_by=%x\n",besr.v_inc,besr.h_inc,besr.step_by);
|
|
415 RTRACE("radeon_vid: BES: vid_buf0_basey=%x\n",besr.vid_buf0_base_adrs);
|
2870
|
416 RTRACE("radeon_vid: BES: y_x_start=%x y_x_end=%x blank_at_top=%x pitch0_value=%x\n"
|
2925
|
417 ,besr.y_x_start,besr.y_x_end,besr.p1_blank_lines_at_top,besr.vid_buf_pitch0_value);
|
2870
|
418 besr.p1_x_start_end = (config->src_width + left - 1) | (left << 16);
|
|
419 left >>= 1; src_w=config->src_width >> 1;
|
|
420 besr.p2_x_start_end = (src_w + left - 1) | (left << 16);
|
|
421 besr.p3_x_start_end = besr.p2_x_start_end;
|
|
422 return 0;
|
|
423 }
|
|
424
|
|
425 static void radeon_vid_frame_sel(int frame)
|
|
426 {
|
2917
|
427 uint32_t off;
|
|
428 switch(frame)
|
|
429 {
|
|
430 default:
|
|
431 case 0: off = besr.vid_buf0_base_adrs; break;
|
|
432 case 1: off = besr.vid_buf1_base_adrs; break;
|
|
433 case 2: off = besr.vid_buf2_base_adrs; break;
|
|
434 case 3: off = besr.vid_buf3_base_adrs; break;
|
|
435 case 4: off = besr.vid_buf4_base_adrs; break;
|
|
436 case 5: off = besr.vid_buf5_base_adrs; break;
|
|
437 }
|
|
438 OUTREG(OV0_REG_LOAD_CNTL, REG_LD_CTL_LOCK);
|
|
439 while(!(INREG(OV0_REG_LOAD_CNTL)®_LD_CTL_LOCK_READBACK));
|
|
440 OUTREG(OV0_VID_BUF0_BASE_ADRS, off);
|
|
441 OUTREG(OV0_REG_LOAD_CNTL, 0);
|
|
442
|
2870
|
443 }
|
|
444
|
2951
|
445 static int video_on = 0;
|
|
446
|
2870
|
447 static int radeon_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
|
|
448 {
|
|
449 int frame;
|
|
450
|
|
451 switch(cmd)
|
|
452 {
|
|
453 case MGA_VID_CONFIG:
|
|
454 RTRACE( "radeon_mmio_base = %p\n",radeon_mmio_base);
|
|
455 RTRACE( "radeon_mem_base = %08x\n",radeon_mem_base);
|
|
456 RTRACE( "radeon_vid: Received configuration\n");
|
|
457
|
|
458 if(copy_from_user(&radeon_config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t)))
|
|
459 {
|
|
460 printk( "radeon_vid: failed copy from userspace\n");
|
|
461 return(-EFAULT);
|
|
462 }
|
|
463 if(radeon_config.version != MGA_VID_VERSION){
|
|
464 printk( "radeon_vid: incompatible version! driver: %X requested: %X\n",MGA_VID_VERSION,radeon_config.version);
|
|
465 return(-EFAULT);
|
|
466 }
|
|
467
|
|
468 if(radeon_config.frame_size==0 || radeon_config.frame_size>1024*768*2){
|
|
469 printk( "radeon_vid: illegal frame_size: %d\n",radeon_config.frame_size);
|
|
470 return(-EFAULT);
|
|
471 }
|
|
472
|
|
473 if(radeon_config.num_frames<1 || radeon_config.num_frames>4){
|
|
474 printk( "radeon_vid: illegal num_frames: %d\n",radeon_config.num_frames);
|
|
475 return(-EFAULT);
|
|
476 }
|
|
477
|
|
478 /* FIXME: Fake of G400 ;) or would be better G200 ??? */
|
|
479 radeon_config.card_type = 0;
|
|
480 radeon_config.ram_size = radeon_ram_size;
|
|
481
|
|
482 if (copy_to_user((mga_vid_config_t *) arg, &radeon_config, sizeof(mga_vid_config_t)))
|
|
483 {
|
|
484 printk( "radeon_vid: failed copy to userspace\n");
|
|
485 return(-EFAULT);
|
|
486 }
|
|
487 return radeon_vid_init_video(&radeon_config);
|
|
488 break;
|
|
489
|
|
490 case MGA_VID_ON:
|
|
491 RTRACE( "radeon_vid: Video ON (ioctl)\n");
|
2925
|
492 radeon_vid_start_video();
|
2951
|
493 video_on = 1;
|
2870
|
494 break;
|
|
495
|
|
496 case MGA_VID_OFF:
|
|
497 RTRACE( "radeon_vid: Video OFF (ioctl)\n");
|
2951
|
498 if(video_on) radeon_vid_stop_video();
|
|
499 video_on = 0;
|
2870
|
500 break;
|
|
501
|
|
502 case MGA_VID_FSEL:
|
|
503 if(copy_from_user(&frame,(int *) arg,sizeof(int)))
|
|
504 {
|
|
505 printk("radeon_vid: FSEL failed copy from userspace\n");
|
|
506 return(-EFAULT);
|
|
507 }
|
|
508 radeon_vid_frame_sel(frame);
|
|
509 break;
|
|
510
|
|
511 default:
|
|
512 printk( "radeon_vid: Invalid ioctl\n");
|
|
513 return (-EINVAL);
|
|
514 }
|
|
515
|
|
516 return 0;
|
|
517 }
|
|
518
|
|
519 struct ati_card_id_s
|
|
520 {
|
|
521 int id;
|
|
522 char name[17];
|
|
523 }ati_card_ids[]=
|
|
524 {
|
|
525 { PCI_DEVICE_ID_RADEON_QD, "Radeon QD " },
|
|
526 { PCI_DEVICE_ID_RADEON_QE, "Radeon QE " },
|
|
527 { PCI_DEVICE_ID_RADEON_QF, "Radeon QF " },
|
|
528 { PCI_DEVICE_ID_RADEON_QG, "Radeon QG " },
|
|
529 { PCI_DEVICE_ID_RADEON_QY, "Radeon VE QY " },
|
|
530 { PCI_DEVICE_ID_RADEON_QZ, "Radeon VE QZ " },
|
|
531 { PCI_DEVICE_ID_RADEON_LY, "Radeon M6 LY " },
|
|
532 { PCI_DEVICE_ID_RADEON_LZ, "Radeon M6 LZ " },
|
|
533 { PCI_DEVICE_ID_RADEON_LW, "Radeon M7 LW " },
|
|
534 { PCI_DEVICE_ID_R200_QL, "Radeon2 8500 QL " },
|
|
535 { PCI_DEVICE_ID_RV200_QW, "Radeon2 7500 QW " }
|
|
536 };
|
|
537
|
|
538 static int radeon_vid_config_card(void)
|
|
539 {
|
|
540 struct pci_dev *dev = NULL;
|
|
541 size_t i;
|
|
542
|
|
543 for(i=0;i<sizeof(ati_card_ids)/sizeof(struct ati_card_id_s);i++)
|
|
544 if((dev=pci_find_device(PCI_VENDOR_ID_ATI, ati_card_ids[i].id, NULL)))
|
|
545 break;
|
|
546 if(dev)
|
|
547 printk("radeon_vid: Found %s\n",ati_card_ids[i].name);
|
|
548 else
|
|
549 {
|
|
550 printk("radeon_vid: No supported cards found\n");
|
|
551 return FALSE;
|
|
552 }
|
|
553
|
|
554 radeon_mmio_base = ioremap_nocache(pci_resource_start (dev, 2),RADEON_REGSIZE);
|
|
555 radeon_mem_base = dev->resource[0].start;
|
|
556
|
|
557 RTRACE( "radeon_vid: MMIO at 0x%p\n", radeon_mmio_base);
|
|
558 RTRACE( "radeon_vid: Frame Buffer at 0x%08x\n", radeon_mem_base);
|
|
559
|
|
560 radeon_ram_size = pci_resource_len(dev, 0)/0x100000;
|
|
561
|
|
562 return TRUE;
|
|
563 }
|
|
564
|
|
565
|
|
566 static ssize_t radeon_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos)
|
|
567 {
|
|
568 return -EINVAL;
|
|
569 }
|
|
570
|
|
571 static ssize_t radeon_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
|
|
572 {
|
|
573 return -EINVAL;
|
|
574 }
|
|
575
|
|
576 static int radeon_vid_mmap(struct file *file, struct vm_area_struct *vma)
|
|
577 {
|
|
578
|
|
579 RTRACE( "radeon_vid: mapping video memory into userspace\n");
|
|
580 if(remap_page_range(vma->vm_start, radeon_mem_base + RADEON_SRC_BASE,
|
|
581 vma->vm_end - vma->vm_start, vma->vm_page_prot))
|
|
582 {
|
|
583 printk( "radeon_vid: error mapping video memory\n");
|
|
584 return(-EAGAIN);
|
|
585 }
|
|
586
|
|
587 return(0);
|
|
588 }
|
|
589
|
|
590 static int radeon_vid_release(struct inode *inode, struct file *file)
|
|
591 {
|
|
592 //Close the window just in case
|
|
593 radeon_vid_in_use = 0;
|
|
594 radeon_vid_stop_video();
|
|
595
|
|
596 MOD_DEC_USE_COUNT;
|
|
597 return 0;
|
|
598 }
|
|
599
|
|
600 static long long radeon_vid_lseek(struct file *file, long long offset, int origin)
|
|
601 {
|
|
602 return -ESPIPE;
|
|
603 }
|
|
604
|
|
605 static int radeon_vid_open(struct inode *inode, struct file *file)
|
|
606 {
|
|
607 int minor = MINOR(inode->i_rdev);
|
|
608
|
|
609 if(minor != 0)
|
|
610 return(-ENXIO);
|
|
611
|
|
612 if(radeon_vid_in_use == 1)
|
|
613 return(-EBUSY);
|
|
614
|
|
615 radeon_vid_in_use = 1;
|
|
616 MOD_INC_USE_COUNT;
|
|
617 return(0);
|
|
618 }
|
|
619
|
|
620 #if LINUX_VERSION_CODE >= 0x020400
|
|
621 static struct file_operations radeon_vid_fops =
|
|
622 {
|
|
623 llseek: radeon_vid_lseek,
|
|
624 read: radeon_vid_read,
|
|
625 write: radeon_vid_write,
|
|
626 ioctl: radeon_vid_ioctl,
|
|
627 mmap: radeon_vid_mmap,
|
|
628 open: radeon_vid_open,
|
|
629 release: radeon_vid_release
|
|
630 };
|
|
631 #else
|
|
632 static struct file_operations radeon_vid_fops =
|
|
633 {
|
|
634 radeon_vid_lseek,
|
|
635 radeon_vid_read,
|
|
636 radeon_vid_write,
|
|
637 NULL,
|
|
638 NULL,
|
|
639 radeon_vid_ioctl,
|
|
640 radeon_vid_mmap,
|
|
641 radeon_vid_open,
|
|
642 NULL,
|
|
643 radeon_vid_release
|
|
644 };
|
|
645 #endif
|
|
646
|
|
647 /*
|
|
648 * Main Initialization Function
|
|
649 */
|
|
650
|
|
651
|
|
652 static int radeon_vid_initialize(void)
|
|
653 {
|
|
654 radeon_vid_in_use = 0;
|
|
655
|
|
656 RTRACE( "Radeon BES YUV Video interface v0.01 (c) Nick Kurshev\n");
|
|
657 if(register_chrdev(RADEON_VID_MAJOR, "radeon_vid", &radeon_vid_fops))
|
|
658 {
|
|
659 printk( "radeon_vid: unable to get major: %d\n", RADEON_VID_MAJOR);
|
|
660 return -EIO;
|
|
661 }
|
|
662
|
|
663 if (!radeon_vid_config_card())
|
|
664 {
|
|
665 printk("radeon_vid: can't configure this card\n");
|
|
666 unregister_chrdev(RADEON_VID_MAJOR, "radeon_vid");
|
|
667 return -EINVAL;
|
|
668 }
|
|
669 radeon_vid_save_state();
|
|
670 return(0);
|
|
671 }
|
|
672
|
|
673 int init_module(void)
|
|
674 {
|
|
675 return radeon_vid_initialize();
|
|
676 }
|
|
677
|
|
678 void cleanup_module(void)
|
|
679 {
|
|
680 radeon_vid_restore_state();
|
|
681 if(radeon_mmio_base)
|
|
682 iounmap(radeon_mmio_base);
|
|
683
|
|
684 RTRACE( "radeon_vid: Cleaning up module\n");
|
|
685 unregister_chrdev(RADEON_VID_MAJOR, "radeon_vid");
|
|
686 }
|
|
687
|