comparison vidix/drivers/mga_vid.c @ 4326:870cec859f92

upgraded to newest vidix interface. in eq: return if g200 moved to the beginning of seteq
author alex
date Wed, 23 Jan 2002 19:34:33 +0000
parents 693e4cfd2b84
children 9c6ab57cfdde
comparison
equal deleted inserted replaced
4325:6b685da4e0c8 4326:870cec859f92
8 8
9 Brightness/contrast support by Nick Kurshev 9 Brightness/contrast support by Nick Kurshev
10 10
11 TODO: 11 TODO:
12 * fix doublebuffering for vidix 12 * fix doublebuffering for vidix
13 * fix pci_config_read for option word (memory size detection) 13 * fix memory size detection (current reading pci userconfig isn't
14 working as requested - returns the max avail. ram on arch?)
14 * fix/complete brightness/contrast handling (Nick) 15 * fix/complete brightness/contrast handling (Nick)
16 MGA users: please test this! (#define MGA_EQUALIZER)
15 * translate all non-english comments to english 17 * translate all non-english comments to english
16 */ 18 */
17 19
18 /* 20 /*
19 * Original copyright: 21 * Original copyright:
36 //#define CRTC2 38 //#define CRTC2
37 39
38 // Set this value, if autodetection fails! (video ram size in megabytes) 40 // Set this value, if autodetection fails! (video ram size in megabytes)
39 // #define MGA_MEMORY_SIZE 16 41 // #define MGA_MEMORY_SIZE 16
40 42
43 /* No irq support in userspace implemented yet, do not enable this! */
41 /* disable irq */ 44 /* disable irq */
42 #undef MGA_ALLOW_IRQ 45 #undef MGA_ALLOW_IRQ
43 46
44 #define MGA_VSYNC_POS 2 47 #define MGA_VSYNC_POS 2
45 48
46 #undef MGA_EQUALIZER 49 #undef MGA_EQUALIZER
47 50
48 #undef MGA_PCICONFIG_MEMDETECT 51 #undef MGA_PCICONFIG_MEMDETECT
52
53 #define MGA_DEFAULT_FRAMES 1
49 54
50 #include <errno.h> 55 #include <errno.h>
51 #include <stdio.h> 56 #include <stdio.h>
52 #include <stdlib.h> 57 #include <stdlib.h>
53 #include <string.h> 58 #include <string.h>
54 #include <math.h> 59 #include <math.h>
55 #include <inttypes.h> 60 #include <inttypes.h>
56 61
57 //#include "../../libvo/fastmemcpy.h"
58
59 #include "../vidix.h" 62 #include "../vidix.h"
60 #include "../fourcc.h" 63 #include "../fourcc.h"
61 #include "../../libdha/libdha.h" 64 #include "../../libdha/libdha.h"
62 #include "../../libdha/pci_ids.h" 65 #include "../../libdha/pci_ids.h"
63 #include "../../libdha/pci_names.h" 66 #include "../../libdha/pci_names.h"
80 /* for device detection */ 83 /* for device detection */
81 static int probed = 0; 84 static int probed = 0;
82 static pciinfo_t pci_info; 85 static pciinfo_t pci_info;
83 86
84 /* internal booleans */ 87 /* internal booleans */
85 static uint32_t mga_vid_in_use = 0; 88 static int mga_vid_in_use = 0;
86 static uint32_t is_g400 = 0; 89 static int is_g400 = 0;
87 static uint32_t vid_src_ready = 0; 90 static int vid_src_ready = 0;
88 static uint32_t vid_overlay_on = 0; 91 static int vid_overlay_on = 0;
89 92
90 /* mapped physical addresses */ 93 /* mapped physical addresses */
91 static uint8_t *mga_mmio_base = 0; 94 static uint8_t *mga_mmio_base = 0;
92 static uint32_t mga_mem_base = 0; 95 static uint32_t mga_mem_base = 0;
93 96
109 static int mga_next_frame = 0; 112 static int mga_next_frame = 0;
110 113
111 static vidix_capability_t mga_cap = 114 static vidix_capability_t mga_cap =
112 { 115 {
113 "Matrox MGA G200/G400 YUV Video", 116 "Matrox MGA G200/G400 YUV Video",
117 "Aaron Holtzman, Arpad Gereoffy, Alex Beregszaszi, Nick Kurshev",
114 TYPE_OUTPUT, 118 TYPE_OUTPUT,
115 { 0, 0, 0, 0 }, 119 { 0, 0, 0, 0 },
116 1600, /* 2048x2048 is supported if Pontscho is right */ 120 1600, /* 2048x2048 is supported if Pontscho is right */
117 1200, 121 1200,
118 4, 122 4,
122 #ifdef MGA_EQUALIZER 126 #ifdef MGA_EQUALIZER
123 | FLAG_EQUALIZER 127 | FLAG_EQUALIZER
124 #endif 128 #endif
125 , 129 ,
126 VENDOR_MATROX, 130 VENDOR_MATROX,
127 0, 131 -1, /* will be set in vixProbe */
128 { 0, 0, 0, 0} 132 { 0, 0, 0, 0}
129 }; 133 };
130 134
131 /* MATROX BES registers */ 135 /* MATROX BES registers */
132 typedef struct bes_registers_s 136 typedef struct bes_registers_s
712 unsigned int vtotal = vsyncend + upper_margin; 716 unsigned int vtotal = vsyncend + upper_margin;
713 #endif 717 #endif
714 718
715 if ((config->num_frames < 1) || (config->num_frames > 4)) 719 if ((config->num_frames < 1) || (config->num_frames > 4))
716 { 720 {
717 printf("[mga] illegal num_frames: %d, setting to 1\n", config->num_frames); 721 printf("[mga] illegal num_frames: %d, setting to %d\n",
718 config->num_frames = 1; 722 config->num_frames, MGA_DEFAULT_FRAMES);
723 config->num_frames = MGA_DEFAULT_FRAMES;
719 // return(EINVAL); 724 // return(EINVAL);
720 } 725 }
721 726
722 x = config->dest.x; 727 x = config->dest.x;
723 y = config->dest.y; 728 y = config->dest.y;
732 printf("[mga] Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n", 737 printf("[mga] Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n",
733 dw, dh, x, y, sw, sh, config->fourcc); 738 dw, dh, x, y, sw, sh, config->fourcc);
734 739
735 if ((sw < 4) || (sh < 4) || (dw < 4) || (dh < 4)) 740 if ((sw < 4) || (sh < 4) || (dw < 4) || (dh < 4))
736 { 741 {
737 printf("[mga] Invalid src/dest dimenstions\n"); 742 printf("[mga] Invalid src/dest dimensions\n");
738 return(EINVAL); 743 return(EINVAL);
739 } 744 }
740 745
741 //FIXME check that window is valid and inside desktop 746 //FIXME check that window is valid and inside desktop
742 747
743 // printf("[mga] vcount = %d\n", readl(mga_mmio_base + VCOUNT)); 748 // printf("[mga] vcount = %d\n", readl(mga_mmio_base + VCOUNT));
744 printf("[mga] mga_mmio_base = %p\n",mga_mmio_base);
745 printf("[mga] mga_mem_base = %08x\n",mga_mem_base);
746 749
747 config->offsets[0] = 0; 750 config->offsets[0] = 0;
748 config->offsets[1] = config->frame_size; 751 config->offsets[1] = config->frame_size;
749 config->offsets[2] = 2*config->frame_size; 752 config->offsets[2] = 2*config->frame_size;
750 config->offsets[3] = 3*config->frame_size; 753 config->offsets[3] = 3*config->frame_size;
762 break; 765 break;
763 case IMGFMT_YUY2: 766 case IMGFMT_YUY2:
764 case IMGFMT_UYVY: 767 case IMGFMT_UYVY:
765 config->frame_size = ((sw + 31) & ~31) * sh * 2; 768 config->frame_size = ((sw + 31) & ~31) * sh * 2;
766 break; 769 break;
770 default:
771 printf("[mga] Unsupported pixel format: %x\n", config->fourcc);
772 return(ENOTSUP);
767 } 773 }
768 774
769 // config->frame_size = config->src.h*config->src.w+(config->src.w*config->src.h)/2; 775 // config->frame_size = config->src.h*config->src.w+(config->src.w*config->src.h)/2;
770 776
771 //FIXME figure out a better way to allocate memory on card 777 //FIXME figure out a better way to allocate memory on card
782 mga_src_base &= (~0xFFFF); /* 64k boundary */ 788 mga_src_base &= (~0xFFFF); /* 64k boundary */
783 printf("[mga] YUV buffer base: %p\n", mga_src_base); 789 printf("[mga] YUV buffer base: %p\n", mga_src_base);
784 790
785 config->dga_addr = mga_mem_base + mga_src_base; 791 config->dga_addr = mga_mem_base + mga_src_base;
786 792
793 /* for G200 set Interleaved UV planes */
794 if (!is_g400)
795 config->flags = VID_PLAY_INTERLEAVED_UV | INTERLEAVING_UV;
787 796
788 //Setup the BES registers for a three plane 4:2:0 video source 797 //Setup the BES registers for a three plane 4:2:0 video source
789 798
790 regs.besglobctl = 0; 799 regs.besglobctl = 0;
791 800
839 + (1<<18); // dither enabled 848 + (1<<18); // dither enabled
840 849
841 regs.besglobctl = 1<<6; // UYVY format selected 850 regs.besglobctl = 1<<6; // UYVY format selected
842 break; 851 break;
843 852
844 default:
845 printf("[mga] Unsupported pixel format: %x\n", config->fourcc);
846 return(ENOTSUP);
847 } 853 }
848 854
849 855
850 //Disable contrast and brightness control 856 //Disable contrast and brightness control
851 regs.besglobctl |= (1<<5) + (1<<7); 857 regs.besglobctl |= (1<<5) + (1<<7);
1094 + (0<<26) // static subpicture key 1100 + (0<<26) // static subpicture key
1095 + (0<<27) // static subpicture key 1101 + (0<<27) // static subpicture key
1096 + (0<<28) // static subpicture key 1102 + (0<<28) // static subpicture key
1097 */ ; 1103 */ ;
1098 break; 1104 break;
1099
1100 default:
1101 printf("[mga] Unsupported pixel format: %x\n",config->fourcc);
1102 return(ENOTSUP);
1103 } 1105 }
1104 1106
1105 cregs.c2hparam=((hdispend - 8) << 16) | (htotal - 8); 1107 cregs.c2hparam=((hdispend - 8) << 16) | (htotal - 8);
1106 cregs.c2hsync=((hsyncend - 8) << 16) | (hsyncstart - 8); 1108 cregs.c2hsync=((hsyncend - 8) << 16) | (hsyncstart - 8);
1107 1109
1447 0, 0, 0, 0, 0, 0, 0, 0 }; 1449 0, 0, 0, 0, 0, 0, 0, 0 };
1448 int vixPlaybackSetEq( const vidix_video_eq_t * eq) 1450 int vixPlaybackSetEq( const vidix_video_eq_t * eq)
1449 { 1451 {
1450 uint32_t beslumactl; 1452 uint32_t beslumactl;
1451 int brightness,contrast; 1453 int brightness,contrast;
1454
1455 /* contrast and brightness control isn't supported with G200,
1456 don't enable c/b control and set values, just return error -- alex */
1457 if (!is_g400)
1458 {
1459 if (mga_verbose > 1)
1460 printf("[mga] equalizer isn't supported with G200\n");
1461 return ENOSYS;
1462 }
1463
1452 if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness; 1464 if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness;
1453 if(eq->cap & VEQ_CAP_CONTRAST) equal.contrast = eq->contrast; 1465 if(eq->cap & VEQ_CAP_CONTRAST) equal.contrast = eq->contrast;
1454 equal.flags = eq->flags; 1466 equal.flags = eq->flags;
1467
1455 //Enable contrast and brightness control 1468 //Enable contrast and brightness control
1456 writel(readl(mga_mmio_base + BESGLOBCTL) & ~((1<<5) + (1<<7)),mga_mmio_base + BESGLOBCTL); 1469 writel(readl(mga_mmio_base + BESGLOBCTL) & ~((1<<5) + (1<<7)),mga_mmio_base + BESGLOBCTL);
1457 brightness = (equal.brightness * 128) / 1000; 1470 brightness = (equal.brightness * 128) / 1000;
1458 if(brightness < -128) brightness = -128; 1471 if(brightness < -128) brightness = -128;
1459 if(brightness > 127) brightness = 127; 1472 if(brightness > 127) brightness = 127;
1460 contrast = ((equal.contrast + 1000) * 128) / 1000; 1473 contrast = ((equal.contrast + 1000) * 128) / 1000;
1461 if(contrast < 0) contrast = 0; 1474 if(contrast < 0) contrast = 0;
1462 if(contrast > 255) contrast = 255; 1475 if(contrast > 255) contrast = 255;
1463 beslumactl = ((brightness & 0xff) << 16) | (contrast & 0xff); 1476 beslumactl = ((brightness & 0xff) << 16) | (contrast & 0xff);
1464 1477
1465 if (is_g400) 1478 writel(beslumactl,mga_mmio_base + BESLUMACTL);
1466 writel(beslumactl,mga_mmio_base + BESLUMACTL);
1467 else
1468 if (mga_verbose > 1)
1469 printf("[mga] equalizer isn't supported with G200\n");
1470 return 0; 1479 return 0;
1471 } 1480 }
1472 1481
1473 int vixPlaybackGetEq( vidix_video_eq_t * eq) 1482 int vixPlaybackGetEq( vidix_video_eq_t * eq)
1474 { 1483 {