Mercurial > mplayer.hg
annotate vidix/unichrome_vid.c @ 22939:1f15b1ed55b1
r22916: Ability to specify video and audio capture device names
r22948: documented -mpegopts :interleaving2
r22949: more human description of -mpegopts :interleaving2
author | voroshil |
---|---|
date | Mon, 09 Apr 2007 16:44:23 +0000 |
parents | f34e5d778267 |
children | 82216ef041e0 |
rev | line source |
---|---|
22850 | 1 /* |
2 Driver for VIA CLE266 Unichrome - Version 0.1.0 | |
3 | |
4 Copyright (C) 2004 by Timothy Lee | |
5 | |
6 Based on Cyberblade/i driver by Alastair M. Robison. | |
7 | |
8 Thanks to Gilles Frattini for bugfixes | |
9 | |
10 This program is free software; you can redistribute it and/or modify | |
11 it under the terms of the GNU General Public License as published by | |
12 the Free Software Foundation; either version 2 of the License, or | |
13 (at your option) any later version. | |
14 | |
15 This program is distributed in the hope that it will be useful, | |
16 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 GNU General Public License for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
21 along with this program; if not, write to the Free Software | |
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
23 | |
24 Changes: | |
25 2004-03-10 | |
26 Initial version | |
27 2004-10-09 | |
28 Added Doxygen documentation (Benjamin Zores <ben@geexbox.org>) | |
29 2004-11-08 | |
30 Added h/w revision detection (Timothy Lee <timothy.lee@siriushk.com>) | |
31 | |
32 To Do: | |
33 */ | |
34 | |
35 #include <errno.h> | |
36 #include <stdio.h> | |
37 #include <stdlib.h> | |
38 #include <string.h> | |
39 #include <inttypes.h> | |
40 #include <unistd.h> | |
41 | |
42 #include "vidix.h" | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
43 #include "vidixlib.h" |
22850 | 44 #include "fourcc.h" |
22901 | 45 #include "dha.h" |
22900
a9e111b88c4a
merged libdha and libvidix, moved all files from libdha to vidix directory
ben
parents:
22874
diff
changeset
|
46 #include "pci_ids.h" |
a9e111b88c4a
merged libdha and libvidix, moved all files from libdha to vidix directory
ben
parents:
22874
diff
changeset
|
47 #include "pci_names.h" |
22905 | 48 #include "config.h" |
22850 | 49 |
50 #include "unichrome_regs.h" | |
51 | |
52 /** | |
53 * @brief Information on PCI device. | |
54 */ | |
55 pciinfo_t pci_info; | |
56 | |
57 /** | |
58 * @brief Unichrome driver colorkey settings. | |
59 */ | |
60 static vidix_grkey_t uc_grkey; | |
61 | |
62 static int frames[VID_PLAY_MAXFRAMES]; | |
63 uint8_t *vio; | |
64 uint8_t *uc_mem; | |
65 uint8_t mclk_save[3]; | |
66 uint8_t hwrev; | |
67 | |
68 #define VIA_OUT(hwregs, reg, val) *(volatile uint32_t *)((hwregs) + (reg)) = (val) | |
69 #define VIA_IN(hwregs, reg) *(volatile uint32_t *)((hwregs) + (reg)) | |
70 #define VGA_OUT8(hwregs, reg, val) *(volatile uint8_t *)((hwregs) + (reg) + 0x8000) = (val) | |
71 #define VGA_IN8(hwregs, reg) *(volatile uint8_t *)((hwregs) + (reg) + 0x8000) | |
72 #define VIDEO_OUT(hwregs, reg, val) VIA_OUT((hwregs)+0x200, reg, val) | |
73 #define VIDEO_IN(hwregs, reg) VIA_IN((hwregs)+0x200, reg) | |
74 | |
75 #define outb(val,reg) OUTPORT8(reg,val) | |
76 #define inb(reg) INPORT8(reg) | |
77 | |
78 #define ALIGN_TO(v, n) (((v) + (n-1)) & ~(n-1)) | |
79 #define UC_MAP_V1_FIFO_CONTROL(depth, pre_thr, thr) \ | |
80 (((depth)-1) | ((thr) << 8) | ((pre_thr) << 24)) | |
81 | |
82 #define VIDEOMEMORY_SIZE (8 * 1024 * 1024) | |
83 #define FRAMEBUFFER_SIZE 0x200000 | |
84 #define FRAMEBUFFER_START (VIDEOMEMORY_SIZE - FRAMEBUFFER_SIZE) | |
85 | |
86 #ifdef DEBUG_LOGFILE | |
87 FILE *logfile = 0; | |
88 #define LOGWRITE(x) {if(logfile) fprintf(logfile,x);} | |
89 #else | |
90 #define LOGWRITE(x) | |
91 #endif | |
92 | |
93 /** | |
94 * @brief Unichrome driver vidix capabilities. | |
95 */ | |
96 static vidix_capability_t uc_cap = { | |
97 "VIA CLE266 Unichrome driver", | |
98 "Timothy Lee <timothy@siriushk.com>", | |
99 TYPE_OUTPUT, | |
100 {0, 0, 0, 0}, | |
101 4096, | |
102 4096, | |
103 4, | |
104 4, | |
105 -1, | |
106 FLAG_UPSCALER | FLAG_DOWNSCALER, | |
107 VENDOR_VIA2, | |
108 -1, | |
109 {0, 0, 0, 0} | |
110 }; | |
111 | |
112 /** | |
113 * @brief list of card IDs compliant with the Unichrome driver . | |
114 */ | |
115 static unsigned short uc_card_ids[] = { | |
22874
9a8f6901e888
updated pci ids list, fixed vidix drivers compilation and added nearly exhaustive pci ids for nvidia driver
ben
parents:
22866
diff
changeset
|
116 DEVICE_VIA2_VT8623_APOLLO_CLE266, |
9a8f6901e888
updated pci ids list, fixed vidix drivers compilation and added nearly exhaustive pci ids for nvidia driver
ben
parents:
22866
diff
changeset
|
117 DEVICE_VIA2_VT8378_S3_UNICHROME |
22850 | 118 }; |
119 | |
120 /** | |
121 * @brief Find chip index in Unichrome compliant devices list. | |
122 * | |
123 * @param chip_id PCI device ID. | |
124 * | |
125 * @returns index position in uc_card_ids if successful. | |
126 * -1 if chip_id is not a compliant chipset ID. | |
127 */ | |
128 static int | |
129 find_chip (unsigned chip_id) | |
130 { | |
131 unsigned i; | |
132 for (i = 0; i < sizeof (uc_card_ids) / sizeof (unsigned short); i++) | |
133 { | |
134 if (chip_id == uc_card_ids[i]) | |
135 return i; | |
136 } | |
137 return -1; | |
138 } | |
139 | |
140 /** | |
141 * @brief Map hardware settings for vertical scaling. | |
142 * | |
143 * @param sh source height. | |
144 * @param dh destination height. | |
145 * @param zoom will hold vertical setting of zoom register. | |
146 * @param mini will hold vertical setting of mini register. | |
147 * | |
148 * @returns 1 if successful. | |
149 * 0 if the zooming factor is too large or small. | |
150 * | |
151 * @note Derived from VIA's V4L driver. | |
152 * See ddover.c, DDOVER_HQVCalcZoomHeight() | |
153 */ | |
154 static int | |
22866 | 155 uc_ovl_map_vzoom (uint32_t sh, uint32_t dh, uint32_t * zoom, uint32_t * mini) |
22850 | 156 { |
157 uint32_t sh1, tmp, d; | |
158 int zoom_ok = 1; | |
159 | |
160 if (sh == dh) /* No zoom */ | |
161 { | |
162 /* Do nothing */ | |
163 } | |
164 else if (sh < dh) /* Zoom in */ | |
165 { | |
166 tmp = (sh * 0x0400) / dh; | |
167 zoom_ok = !(tmp > 0x3ff); | |
168 | |
169 *zoom |= (tmp & 0x3ff) | V1_Y_ZOOM_ENABLE; | |
170 *mini |= V1_Y_INTERPOLY | V1_YCBCR_INTERPOLY; | |
171 } | |
172 else /* sw > dh - Zoom out */ | |
173 { | |
174 /* Find a suitable divider (1 << d) = {2, 4, 8 or 16} */ | |
175 sh1 = sh; | |
176 for (d = 1; d < 5; d++) | |
177 { | |
178 sh1 >>= 1; | |
179 if (sh1 <= dh) | |
180 break; | |
181 } | |
182 if (d == 5) /* too small */ | |
183 { | |
184 d = 4; | |
185 zoom_ok = 0; | |
186 } | |
187 | |
188 *mini |= ((d << 1) - 1) << 16; /* <= {1,3,5,7} << 16 */ | |
189 | |
190 /* Add scaling */ | |
191 if (sh1 < dh) | |
192 { | |
193 tmp = (sh1 * 0x400) / dh; | |
194 *zoom |= ((tmp & 0x3ff) | V1_Y_ZOOM_ENABLE); | |
195 *mini |= V1_Y_INTERPOLY | V1_YCBCR_INTERPOLY; | |
196 } | |
197 } | |
198 | |
199 return zoom_ok; | |
200 } | |
201 | |
202 /** | |
203 * @brief Map hardware settings for horizontal scaling. | |
204 * | |
205 * @param sw source width. | |
206 * @param dw destination width. | |
207 * @param zoom will hold horizontal setting of zoom register. | |
208 * @param mini will hold horizontal setting of mini register. | |
209 * @param falign will hold fetch aligment. | |
210 * @param dcount will hold display count. | |
211 * | |
212 * @returns 1 if successful. | |
213 * 0 if the zooming factor is too large or small. | |
214 * | |
215 * @note Derived from VIA's V4L driver. | |
216 * See ddover.c, DDOVER_HQVCalcZoomWidth() and DDOver_GetDisplayCount() | |
217 */ | |
218 static int | |
22866 | 219 uc_ovl_map_hzoom (uint32_t sw, uint32_t dw, uint32_t * zoom, uint32_t * mini, |
22850 | 220 int *falign, int *dcount) |
221 { | |
222 uint32_t tmp, sw1, d; | |
223 int md; /* Minify-divider */ | |
224 int zoom_ok = 1; | |
225 | |
226 md = 1; | |
227 *falign = 0; | |
228 | |
229 if (sw == dw) /* no zoom */ | |
230 { | |
231 /* Do nothing */ | |
232 } | |
233 else if (sw < dw) /* zoom in */ | |
234 { | |
235 tmp = (sw * 0x0800) / dw; | |
236 zoom_ok = !(tmp > 0x7ff); | |
237 | |
238 *zoom |= ((tmp & 0x7ff) << 16) | V1_X_ZOOM_ENABLE; | |
239 *mini |= V1_X_INTERPOLY; | |
240 } | |
241 else /* sw > dw - Zoom out */ | |
242 { | |
243 /* Find a suitable divider (1 << d) = {2, 4, 8 or 16} */ | |
244 sw1 = sw; | |
245 for (d = 1; d < 5; d++) | |
246 { | |
247 sw1 >>= 1; | |
248 if (sw1 <= dw) | |
249 break; | |
250 } | |
251 if (d == 5) /* too small */ | |
252 { | |
253 d = 4; | |
254 zoom_ok = 0; | |
255 } | |
256 | |
257 md = 1 << d; /* <= {2,4,8,16} */ | |
258 *falign = ((md << 1) - 1) & 0xf; /* <= {3,7,15,15} */ | |
259 *mini |= V1_X_INTERPOLY; | |
260 *mini |= ((d << 1) - 1) << 24; /* <= {1,3,5,7} << 24 */ | |
261 | |
262 /* Add scaling */ | |
263 if (sw1 < dw) | |
264 { | |
265 /* CLE bug */ | |
266 /* tmp = sw1*0x0800 / dw; */ | |
267 tmp = (sw1 - 2) * 0x0800 / dw; | |
268 *zoom |= ((tmp & 0x7ff) << 16) | V1_X_ZOOM_ENABLE; | |
269 } | |
270 } | |
271 | |
272 *dcount = sw - md; | |
273 return zoom_ok; | |
274 } | |
275 | |
276 /** | |
277 * @brief qword fetch register setting. | |
278 * | |
279 * @param format overlay pixel format. | |
280 * @param sw source width. | |
281 * | |
282 * @return qword fetch register setting | |
283 * | |
284 * @note Derived from VIA's V4L driver. See ddover.c, DDOver_GetFetch() | |
285 * @note Only call after uc_ovl_map_hzoom() | |
286 */ | |
287 static uint32_t | |
288 uc_ovl_map_qwfetch (uint32_t format, int sw) | |
289 { | |
290 uint32_t fetch = 0; | |
291 | |
292 switch (format) | |
293 { | |
294 case IMGFMT_YV12: | |
295 case IMGFMT_I420: | |
296 fetch = ALIGN_TO (sw, 32) >> 4; | |
297 break; | |
298 case IMGFMT_UYVY: | |
299 case IMGFMT_YVYU: | |
300 case IMGFMT_YUY2: | |
301 fetch = (ALIGN_TO (sw << 1, 16) >> 4) + 1; | |
302 break; | |
303 case IMGFMT_BGR15: | |
304 case IMGFMT_BGR16: | |
305 fetch = (ALIGN_TO (sw << 1, 16) >> 4) + 1; | |
306 break; | |
307 case IMGFMT_BGR32: | |
308 fetch = (ALIGN_TO (sw << 2, 16) >> 4) + 1; | |
309 break; | |
310 default: | |
311 printf ("[unichrome] Unexpected pixelformat!"); | |
312 break; | |
313 } | |
314 | |
315 if (fetch < 4) | |
316 fetch = 4; | |
317 | |
318 return fetch; | |
319 } | |
320 | |
321 /** | |
322 * @brief Map pixel format. | |
323 * | |
324 * @param format pixel format. | |
325 * | |
326 * @return the mapped pixel format. | |
327 * | |
328 * @note Derived from VIA's V4L driver. See ddover.c, DDOver_GetV1Format() | |
329 */ | |
330 static uint32_t | |
331 uc_ovl_map_format (uint32_t format) | |
332 { | |
333 switch (format) | |
334 { | |
335 case IMGFMT_UYVY: | |
336 case IMGFMT_YVYU: | |
337 case IMGFMT_YUY2: | |
338 return V1_COLORSPACE_SIGN | V1_YUV422; | |
339 case IMGFMT_IYUV: | |
340 return V1_COLORSPACE_SIGN | V1_YCbCr420 | V1_SWAP_SW; | |
341 case IMGFMT_YV12: | |
342 case IMGFMT_I420: | |
343 return V1_COLORSPACE_SIGN | V1_YCbCr420; | |
344 case IMGFMT_BGR15: | |
345 return V1_RGB15; | |
346 case IMGFMT_BGR16: | |
347 return V1_RGB16; | |
348 case IMGFMT_BGR32: | |
349 return V1_RGB32; | |
350 default: | |
351 printf ("[unichrome] Unexpected pixelformat!"); | |
352 return V1_YUV422; | |
353 } | |
354 } | |
355 | |
356 /** | |
357 * @brief Calculate V1 control and fifo-control register values. | |
358 * | |
359 * @param format pixel format. | |
360 * @param sw source width. | |
361 * @param hwrev CLE266 hardware revision. | |
362 * @param extfifo_on set this 1 if the extended FIFO is enabled. | |
363 * @param control will hold value for V1_CONTROL. | |
364 * @param fifo will hold value for V1_FIFO_CONTROL. | |
365 */ | |
366 static void | |
367 uc_ovl_map_v1_control (uint32_t format, int sw, | |
368 int hwrev, int extfifo_on, | |
369 uint32_t * control, uint32_t * fifo) | |
370 { | |
371 *control = V1_BOB_ENABLE | uc_ovl_map_format (format); | |
372 | |
373 if (hwrev == 0x10) | |
374 { | |
375 *control |= V1_EXPIRE_NUM_F; | |
376 } | |
377 else | |
378 { | |
379 if (extfifo_on) | |
380 { | |
381 *control |= V1_EXPIRE_NUM_A | V1_FIFO_EXTENDED; | |
382 } | |
383 else | |
384 { | |
385 *control |= V1_EXPIRE_NUM; | |
386 } | |
387 } | |
388 | |
389 if ((format == IMGFMT_YV12) || (format == IMGFMT_I420)) | |
390 { | |
391 /* Minified video will be skewed without this workaround. */ | |
392 if (sw <= 80) /* Fetch count <= 5 */ | |
393 { | |
394 *fifo = UC_MAP_V1_FIFO_CONTROL (16, 0, 0); | |
395 } | |
396 else | |
397 { | |
398 if (hwrev == 0x10) | |
399 *fifo = UC_MAP_V1_FIFO_CONTROL (64, 56, 56); | |
400 else | |
401 *fifo = UC_MAP_V1_FIFO_CONTROL (16, 12, 8); | |
402 } | |
403 } | |
404 else | |
405 { | |
406 if (hwrev == 0x10) | |
407 { | |
408 *fifo = UC_MAP_V1_FIFO_CONTROL (64, 56, 56); /* Default rev 0x10 */ | |
409 } | |
410 else | |
411 { | |
412 if (extfifo_on) | |
413 *fifo = UC_MAP_V1_FIFO_CONTROL (48, 40, 40); | |
414 else | |
415 *fifo = UC_MAP_V1_FIFO_CONTROL (32, 29, 16); /* Default */ | |
416 } | |
417 } | |
418 } | |
419 | |
420 /** | |
421 * @brief Setup extended FIFO. | |
422 * | |
423 * @param extfifo_on pointer determining if extended fifo is enable or not. | |
424 * @param dst_w destination width. | |
425 */ | |
426 static void | |
427 uc_ovl_setup_fifo (int *extfifo_on, int dst_w) | |
428 { | |
429 if (dst_w <= 1024) /* Disable extended FIFO */ | |
430 { | |
431 outb (0x16, 0x3c4); | |
432 outb (mclk_save[0], 0x3c5); | |
433 outb (0x17, 0x3c4); | |
434 outb (mclk_save[1], 0x3c5); | |
435 outb (0x18, 0x3c4); | |
436 outb (mclk_save[2], 0x3c5); | |
437 *extfifo_on = 0; | |
438 } | |
439 else /* Enable extended FIFO */ | |
440 { | |
441 outb (0x17, 0x3c4); | |
442 outb (0x2f, 0x3c5); | |
443 outb (0x16, 0x3c4); | |
444 outb ((mclk_save[0] & 0xf0) | 0x14, 0x3c5); | |
445 outb (0x18, 0x3c4); | |
446 outb (0x56, 0x3c5); | |
447 *extfifo_on = 1; | |
448 } | |
449 } | |
450 | |
451 static void | |
452 uc_ovl_vcmd_wait (volatile uint8_t * vio) | |
453 { | |
454 while ((VIDEO_IN (vio, V_COMPOSE_MODE) | |
455 & (V1_COMMAND_FIRE | V3_COMMAND_FIRE))); | |
456 } | |
457 | |
458 /** | |
459 * @brief Probe hardware to find some useable chipset. | |
460 * | |
461 * @param verbose specifies verbose level. | |
462 * @param force specifies force mode : driver should ignore | |
463 * device_id (danger but useful for new devices) | |
464 * | |
465 * @returns 0 if it can handle something in PC. | |
466 * a negative error code otherwise. | |
467 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
468 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
469 unichrome_probe (int verbose, int force) |
22850 | 470 { |
471 pciinfo_t lst[MAX_PCI_DEVICES]; | |
472 unsigned i, num_pci; | |
473 int err; | |
474 err = pci_scan (lst, &num_pci); | |
475 if (err) | |
476 { | |
477 printf ("[unichrome] Error occurred during pci scan: %s\n", | |
478 strerror (err)); | |
479 return err; | |
480 } | |
481 else | |
482 { | |
483 err = ENXIO; | |
484 for (i = 0; i < num_pci; i++) | |
485 { | |
486 if (lst[i].vendor == VENDOR_VIA2) | |
487 { | |
488 int idx; | |
489 const char *dname; | |
490 idx = find_chip (lst[i].device); | |
491 if (idx == -1) | |
492 continue; | |
493 dname = pci_device_name (VENDOR_VIA2, lst[i].device); | |
494 dname = dname ? dname : "Unknown chip"; | |
495 printf ("[unichrome] Found chip: %s\n", dname); | |
496 if ((lst[i].command & PCI_COMMAND_IO) == 0) | |
497 { | |
498 printf ("[unichrome] Device is disabled, ignoring\n"); | |
499 continue; | |
500 } | |
501 uc_cap.device_id = lst[i].device; | |
502 err = 0; | |
503 memcpy (&pci_info, &lst[i], sizeof (pciinfo_t)); | |
504 break; | |
505 } | |
506 } | |
507 } | |
508 | |
509 if (err && verbose) | |
510 printf ("[unichrome] Can't find chip\n"); | |
511 return err; | |
512 } | |
513 | |
514 /** | |
515 * @brief Initializes driver. | |
516 * | |
517 * @returns 0 if ok. | |
518 * a negative error code otherwise. | |
519 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
520 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
521 unichrome_init (void) |
22850 | 522 { |
523 long tmp; | |
524 uc_mem = map_phys_mem (pci_info.base0, VIDEOMEMORY_SIZE); | |
525 enable_app_io (); | |
526 | |
527 outb (0x2f, 0x3c4); | |
528 tmp = inb (0x3c5) << 0x18; | |
529 vio = map_phys_mem (tmp, 0x1000); | |
530 | |
531 outb (0x16, 0x3c4); | |
532 mclk_save[0] = inb (0x3c5); | |
533 outb (0x17, 0x3c4); | |
534 mclk_save[1] = inb (0x3c5); | |
535 outb (0x18, 0x3c4); | |
536 mclk_save[2] = inb (0x3c5); | |
537 | |
538 uc_grkey.ckey.blue = 0x00; | |
539 uc_grkey.ckey.green = 0x00; | |
540 uc_grkey.ckey.red = 0x00; | |
541 | |
542 /* Detect whether we have a CLE266Ax or CLE266Cx */ | |
543 outb (0x4f, 0x3d4); | |
544 tmp = inb (0x3d5); | |
545 outb (0x4f, 0x3d4); | |
546 outb (0x55, 0x3d5); | |
547 outb (0x4f, 0x3d4); | |
548 if (0x55 == inb (0x3d5)) | |
549 { | |
550 /* Only CLE266Cx supports CR4F */ | |
551 hwrev = 0x11; | |
552 } | |
553 else | |
554 { | |
555 /* Otherwise assume to be a CLE266Ax */ | |
556 hwrev = 0x00; | |
557 } | |
558 outb (0x4f, 0x3d4); | |
559 outb (tmp, 0x3d5); | |
560 | |
561 #ifdef DEBUG_LOGFILE | |
562 logfile = fopen ("/tmp/uc_vidix.log", "w"); | |
563 #endif | |
564 return 0; | |
565 } | |
566 | |
567 /** | |
568 * @brief Destroys driver. | |
569 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
570 static void |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
571 unichrome_destroy (void) |
22850 | 572 { |
573 #ifdef DEBUG_LOGFILE | |
574 if (logfile) | |
575 fclose (logfile); | |
576 #endif | |
577 outb (0x16, 0x3c4); | |
578 outb (mclk_save[0], 0x3c5); | |
579 outb (0x17, 0x3c4); | |
580 outb (mclk_save[1], 0x3c5); | |
581 outb (0x18, 0x3c4); | |
582 outb (mclk_save[2], 0x3c5); | |
583 | |
584 disable_app_io (); | |
585 unmap_phys_mem (uc_mem, VIDEOMEMORY_SIZE); | |
586 unmap_phys_mem (vio, 0x1000); | |
587 } | |
588 | |
589 /** | |
590 * @brief Get chipset's hardware capabilities. | |
591 * | |
592 * @param to Pointer to the vidix_capability_t structure to be filled. | |
593 * | |
594 * @returns 0. | |
595 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
596 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
597 unichrome_get_caps (vidix_capability_t * to) |
22850 | 598 { |
599 memcpy (to, &uc_cap, sizeof (vidix_capability_t)); | |
600 return 0; | |
601 } | |
602 | |
603 /** | |
604 * @brief Report if the video FourCC is supported by hardware. | |
605 * | |
606 * @param fourcc input image format. | |
607 * | |
608 * @returns 1 if the fourcc is supported. | |
609 * 0 otherwise. | |
610 */ | |
611 static int | |
612 is_supported_fourcc (uint32_t fourcc) | |
613 { | |
614 switch (fourcc) | |
615 { | |
616 case IMGFMT_YV12: | |
617 case IMGFMT_I420: | |
618 case IMGFMT_UYVY: | |
619 case IMGFMT_YVYU: | |
620 case IMGFMT_YUY2: | |
621 case IMGFMT_BGR15: | |
622 case IMGFMT_BGR16: | |
623 case IMGFMT_BGR32: | |
624 return 1; | |
625 default: | |
626 return 0; | |
627 } | |
628 } | |
629 | |
630 /** | |
631 * @brief Try to configure video memory for given fourcc. | |
632 * | |
633 * @param to Pointer to the vidix_fourcc_t structure to be filled. | |
634 * | |
635 * @returns 0 if ok. | |
636 * errno otherwise. | |
637 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
638 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
639 unichrome_query_fourcc (vidix_fourcc_t * to) |
22850 | 640 { |
641 if (is_supported_fourcc (to->fourcc)) | |
642 { | |
643 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
644 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
645 VID_DEPTH_12BPP | VID_DEPTH_15BPP | | |
646 VID_DEPTH_16BPP | VID_DEPTH_24BPP | VID_DEPTH_32BPP; | |
647 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; | |
648 return 0; | |
649 } | |
650 else | |
651 to->depth = to->flags = 0; | |
652 return ENOSYS; | |
653 } | |
654 | |
655 /** | |
656 * @brief Get the GrKeys | |
657 * | |
658 * @param grkey Pointer to the vidix_grkey_t structure to be filled by driver. | |
659 * | |
660 * @return 0. | |
661 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
662 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
663 unichrome_get_gkey (vidix_grkey_t * grkey) |
22850 | 664 { |
665 memcpy (grkey, &uc_grkey, sizeof (vidix_grkey_t)); | |
666 return (0); | |
667 } | |
668 | |
669 /** | |
670 * @brief Set the GrKeys | |
671 * | |
672 * @param grkey Colorkey to be set. | |
673 * | |
674 * @return 0. | |
675 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
676 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
677 unichrome_set_gkey (const vidix_grkey_t * grkey) |
22850 | 678 { |
679 unsigned long dwCompose = VIDEO_IN (vio, V_COMPOSE_MODE) & ~0x0f; | |
680 memcpy (&uc_grkey, grkey, sizeof (vidix_grkey_t)); | |
681 if (uc_grkey.ckey.op != CKEY_FALSE) | |
682 { | |
683 /* Set colorkey (how do I detect BPP in hardware ??) */ | |
684 unsigned long ckey; | |
685 if (1) /* Assume 16-bit graphics */ | |
686 { | |
687 ckey = (grkey->ckey.blue & 0x1f) | |
688 | ((grkey->ckey.green & 0x3f) << 5) | |
689 | ((grkey->ckey.red & 0x1f) << 11); | |
690 } | |
691 else | |
692 { | |
693 ckey = (grkey->ckey.blue) | |
694 | (grkey->ckey.green << 8) | (grkey->ckey.red << 16); | |
695 } | |
696 VIDEO_OUT (vio, V_COLOR_KEY, ckey); | |
697 dwCompose |= SELECT_VIDEO_IF_COLOR_KEY; | |
698 } | |
699 | |
700 /* Execute the changes */ | |
701 VIDEO_OUT (vio, V_COMPOSE_MODE, dwCompose | V1_COMMAND_FIRE); | |
702 return (0); | |
703 } | |
704 | |
705 /** | |
706 * @brief Unichrome driver equalizer capabilities. | |
707 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
708 static vidix_video_eq_t equal = { |
22850 | 709 VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | VEQ_CAP_HUE, |
710 300, 100, 0, 0, 0, 0, 0, 0 | |
711 }; | |
712 | |
713 | |
714 /** | |
715 * @brief Get the equalizer capabilities. | |
716 * | |
717 * @param eq Pointer to the vidix_video_eq_t structure to be filled by driver. | |
718 * | |
719 * @return 0. | |
720 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
721 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
722 unichrome_get_eq (vidix_video_eq_t * eq) |
22850 | 723 { |
724 memcpy (eq, &equal, sizeof (vidix_video_eq_t)); | |
725 return 0; | |
726 } | |
727 | |
728 /** | |
729 * @brief Set the equalizer capabilities for color correction | |
730 * | |
731 * @param eq equalizer capabilities to be set. | |
732 * | |
733 * @return 0. | |
734 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
735 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
736 unichrome_set_eq (const vidix_video_eq_t * eq) |
22850 | 737 { |
738 return 0; | |
739 } | |
740 | |
741 /** | |
742 * @brief Y, U, V offsets. | |
743 */ | |
744 static int YOffs, UOffs, VOffs; | |
745 | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
746 static int unichrome_frame_select (unsigned int frame); |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
747 |
22850 | 748 /** |
749 * @brief Configure driver for playback. Driver should prepare BES. | |
750 * | |
751 * @param info configuration description for playback. | |
752 * | |
753 * @returns 0 in case of success. | |
754 * -1 otherwise. | |
755 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
756 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
757 unichrome_config_playback (vidix_playback_t * info) |
22850 | 758 { |
759 int src_w, drw_w; | |
760 int src_h, drw_h; | |
22866 | 761 long base0, pitch = 0; |
762 int uv_size = 0, swap_uv; | |
22850 | 763 unsigned int i; |
764 int extfifo_on; | |
765 | |
766 /* Overlay register settings */ | |
767 uint32_t win_start, win_end; | |
768 uint32_t zoom, mini; | |
769 uint32_t dcount, falign, qwfetch; | |
770 uint32_t v_ctrl, fifo_ctrl; | |
771 | |
772 if (!is_supported_fourcc (info->fourcc)) | |
773 return -1; | |
774 | |
775 src_w = info->src.w; | |
776 src_h = info->src.h; | |
777 | |
778 drw_w = info->dest.w; | |
779 drw_h = info->dest.h; | |
780 | |
781 /* Setup FIFO */ | |
782 uc_ovl_setup_fifo (&extfifo_on, src_w); | |
783 | |
784 /* Get image format, FIFO size, etc. */ | |
785 uc_ovl_map_v1_control (info->fourcc, src_w, hwrev, extfifo_on, | |
786 &v_ctrl, &fifo_ctrl); | |
787 | |
788 /* Setup layer window */ | |
789 win_start = (info->dest.x << 16) | info->dest.y; | |
790 win_end = ((info->dest.x + drw_w - 1) << 16) | (info->dest.y + drw_h - 1); | |
791 | |
792 /* Get scaling and data-fetch parameters */ | |
793 zoom = 0; | |
794 mini = 0; | |
795 uc_ovl_map_vzoom (src_h, drw_h, &zoom, &mini); | |
22866 | 796 uc_ovl_map_hzoom (src_w, drw_w, &zoom, &mini, (int *) &falign, (int *) &dcount); |
22850 | 797 qwfetch = uc_ovl_map_qwfetch (info->fourcc, src_w); |
798 | |
799 /* Calculate buffer sizes */ | |
800 swap_uv = 0; | |
801 switch (info->fourcc) | |
802 { | |
803 case IMGFMT_YV12: | |
804 swap_uv = 1; | |
805 case IMGFMT_I420: | |
806 case IMGFMT_UYVY: | |
807 case IMGFMT_YVYU: | |
808 pitch = ALIGN_TO (src_w, 32); | |
809 uv_size = (pitch >> 1) * (src_h >> 1); | |
810 break; | |
811 | |
812 case IMGFMT_YUY2: | |
813 case IMGFMT_BGR15: | |
814 case IMGFMT_BGR16: | |
815 pitch = ALIGN_TO (src_w << 1, 32); | |
816 uv_size = 0; | |
817 break; | |
818 | |
819 case IMGFMT_BGR32: | |
820 pitch = ALIGN_TO (src_w << 2, 32); | |
821 uv_size = 0; | |
822 break; | |
823 } | |
824 if ((src_w > 4096) || (src_h > 4096) || | |
825 (src_w < 32) || (src_h < 1) || (pitch > 0x1fff)) | |
826 { | |
827 printf ("[unichrome] Layer size out of bounds\n"); | |
828 } | |
829 | |
830 /* Calculate offsets */ | |
831 info->offset.y = 0; | |
832 info->offset.v = info->offset.y + pitch * src_h; | |
833 info->offset.u = info->offset.v + uv_size; | |
834 info->frame_size = info->offset.u + uv_size; | |
835 YOffs = info->offset.y; | |
836 UOffs = (swap_uv ? info->offset.v : info->offset.u); | |
837 VOffs = (swap_uv ? info->offset.u : info->offset.v); | |
838 | |
839 /* Assume we have 2 MB to play with */ | |
840 info->num_frames = FRAMEBUFFER_SIZE / info->frame_size; | |
841 if (info->num_frames > VID_PLAY_MAXFRAMES) | |
842 info->num_frames = VID_PLAY_MAXFRAMES; | |
843 | |
844 /* Start at 6 MB. Let's hope it's not in use. */ | |
845 base0 = FRAMEBUFFER_START; | |
846 info->dga_addr = uc_mem + base0; | |
847 | |
848 info->dest.pitch.y = 32; | |
849 info->dest.pitch.u = 32; | |
850 info->dest.pitch.v = 32; | |
851 | |
852 for (i = 0; i < info->num_frames; i++) | |
853 { | |
854 info->offsets[i] = info->frame_size * i; | |
855 frames[i] = base0 + info->offsets[i]; | |
856 } | |
857 | |
858 /* Write to the hardware */ | |
859 uc_ovl_vcmd_wait (vio); | |
860 | |
861 /* Configure diy_pitchlay parameters now */ | |
862 if (v_ctrl & V1_COLORSPACE_SIGN) | |
863 { | |
864 if (hwrev >= 0x10) | |
865 { | |
866 VIDEO_OUT (vio, V1_ColorSpaceReg_2, ColorSpaceValue_2_3123C0); | |
867 VIDEO_OUT (vio, V1_ColorSpaceReg_1, ColorSpaceValue_1_3123C0); | |
868 } | |
869 else | |
870 { | |
871 VIDEO_OUT (vio, V1_ColorSpaceReg_2, ColorSpaceValue_2); | |
872 VIDEO_OUT (vio, V1_ColorSpaceReg_1, ColorSpaceValue_1); | |
873 } | |
874 } | |
875 | |
876 VIDEO_OUT (vio, V1_CONTROL, v_ctrl); | |
877 VIDEO_OUT (vio, V_FIFO_CONTROL, fifo_ctrl); | |
878 | |
879 VIDEO_OUT (vio, V1_WIN_START_Y, win_start); | |
880 VIDEO_OUT (vio, V1_WIN_END_Y, win_end); | |
881 | |
882 VIDEO_OUT (vio, V1_SOURCE_HEIGHT, (src_h << 16) | dcount); | |
883 | |
884 VIDEO_OUT (vio, V12_QWORD_PER_LINE, qwfetch << 20); | |
885 VIDEO_OUT (vio, V1_STRIDE, pitch | ((pitch >> 1) << 16)); | |
886 | |
887 VIDEO_OUT (vio, V1_MINI_CONTROL, mini); | |
888 VIDEO_OUT (vio, V1_ZOOM_CONTROL, zoom); | |
889 | |
890 /* Configure buffer address and execute the changes now! */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
891 unichrome_frame_select (0); |
22850 | 892 |
893 return 0; | |
894 } | |
895 | |
896 /** | |
897 * @brief Set playback on : driver should activate BES on this call. | |
898 * | |
899 * @return 0. | |
900 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
901 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
902 unichrome_playback_on (void) |
22850 | 903 { |
904 LOGWRITE ("Enable overlay\n"); | |
905 | |
906 /* Turn on overlay */ | |
907 VIDEO_OUT (vio, V1_CONTROL, VIDEO_IN (vio, V1_CONTROL) | V1_ENABLE); | |
908 | |
909 /* Execute the changes */ | |
910 VIDEO_OUT (vio, V_COMPOSE_MODE, | |
911 VIDEO_IN (vio, V_COMPOSE_MODE) | V1_COMMAND_FIRE); | |
912 | |
913 return 0; | |
914 } | |
915 | |
916 /** | |
917 * @brief Set playback off : driver should deactivate BES on this call. | |
918 * | |
919 * @return 0. | |
920 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
921 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
922 unichrome_playback_off (void) |
22850 | 923 { |
924 LOGWRITE ("Disable overlay\n"); | |
925 | |
926 uc_ovl_vcmd_wait (vio); | |
927 | |
928 /* Restore FIFO */ | |
929 VIDEO_OUT (vio, V_FIFO_CONTROL, UC_MAP_V1_FIFO_CONTROL (16, 12, 8)); | |
930 | |
931 /* Turn off overlay */ | |
932 VIDEO_OUT (vio, V1_CONTROL, VIDEO_IN (vio, V1_CONTROL) & ~V1_ENABLE); | |
933 | |
934 /* Execute the changes */ | |
935 VIDEO_OUT (vio, V_COMPOSE_MODE, | |
936 VIDEO_IN (vio, V_COMPOSE_MODE) | V1_COMMAND_FIRE); | |
937 | |
938 return 0; | |
939 } | |
940 | |
941 /** | |
942 * @brief Driver should prepare and activate corresponded frame. | |
943 * | |
944 * @param frame the frame index. | |
945 * | |
946 * @return 0. | |
947 * | |
948 * @note This function is used only for double and triple buffering | |
949 * and never used for single buffering playback. | |
950 */ | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
951 static int |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
952 unichrome_frame_select (unsigned int frame) |
22850 | 953 { |
954 LOGWRITE ("Frame select\n"); | |
955 | |
956 uc_ovl_vcmd_wait (vio); | |
957 | |
958 /* Configure buffer address */ | |
959 VIDEO_OUT (vio, V1_STARTADDR_Y0, frames[frame] + YOffs); | |
960 VIDEO_OUT (vio, V1_STARTADDR_CB0, frames[frame] + UOffs); | |
961 VIDEO_OUT (vio, V1_STARTADDR_CR0, frames[frame] + VOffs); | |
962 | |
963 /* Execute the changes */ | |
964 VIDEO_OUT (vio, V_COMPOSE_MODE, | |
965 VIDEO_IN (vio, V_COMPOSE_MODE) | V1_COMMAND_FIRE); | |
966 | |
967 return 0; | |
968 } | |
22857
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
969 |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
970 VDXDriver unichrome_drv = { |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
971 "unichrome", |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
972 NULL, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
973 .probe = unichrome_probe, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
974 .get_caps = unichrome_get_caps, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
975 .query_fourcc = unichrome_query_fourcc, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
976 .init = unichrome_init, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
977 .destroy = unichrome_destroy, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
978 .config_playback = unichrome_config_playback, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
979 .playback_on = unichrome_playback_on, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
980 .playback_off = unichrome_playback_off, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
981 .frame_sel = unichrome_frame_select, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
982 .get_eq = unichrome_get_eq, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
983 .set_eq = unichrome_set_eq, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
984 .get_gkey = unichrome_get_gkey, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
985 .set_gkey = unichrome_set_gkey, |
77def5093daf
switch to new internal vidix API, no more dlopen/dlsym, libvidix is now a fully static library with all drivers built-in
ben
parents:
22850
diff
changeset
|
986 }; |