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