mga_vid.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 1,405 行 · 第 1/3 页

C
1,405
字号
		    + (0<<12)	// 15 bpp high alpha		    + (0<<13)	// 15 bpp high alpha		    + (0<<14)	// 15 bpp high alpha		    + (0<<15)	// 15 bpp high alpha		    + (0<<16)	// 15 bpp low alpha		    + (0<<17)	// 15 bpp low alpha		    + (0<<18)	// 15 bpp low alpha		    + (0<<19)	// 15 bpp low alpha		    + (0<<20)	// 15 bpp low alpha		    + (0<<21)	// 15 bpp low alpha		    + (0<<22)	// 15 bpp low alpha		    + (0<<23)	// 15 bpp low alpha		    + (0<<24)	// static subpicture key		    + (0<<25)	// static subpicture key		    + (0<<26)	// static subpicture key		    + (0<<27)	// static subpicture key		    + (0<<28)	// static subpicture key*/			;          break;    case IMGFMT_UYVY:		cregs.c2ctl = 1         // CRTC2 enabled		    + (1<<1)	// external clock		    + (0<<2)	// external clock		    + (1<<3)	// pixel clock enable - not needed ???		    + (0<<4)	// high prioryty req		    + (1<<5)	// high prioryty req		    + (0<<6)	// high prioryty req		    + (1<<8)	// high prioryty req max		    + (0<<9)	// high prioryty req max		    + (0<<10)	// high prioryty req max                    + (0<<20)   // CRTC1 to DAC                    + (1<<21)   // 422 mode                    + (0<<22)   // 422 mode                    + (1<<23)   // 422 mode                    + (1<<24)   // single chroma line for 420 mode - need to be corrected                    + (1<<25)   /*/ interlace mode - need to be corrected*/                    + (0<<26)   // field legth polariry                    + (0<<27)   // field identification polariry                    + (1<<28)   // VIDRST detection mode                    + (0<<29)   // VIDRST detection mode                    + (1<<30)   // Horizontal counter preload                    + (1<<31)   // Vertical counter preload		    ;	cregs.c2datactl = 0         // enable dither - propably not needed, we are already in YUV mode		    + (1<<1)	// Y filter enable		    + (1<<2)	// CbCr filter enable		    + (0<<3)	// subpicture enable (disabled)		    + (0<<4)	// NTSC enable (disabled - PAL)		    + (0<<5)	// C2 static subpicture enable (disabled)		    + (0<<6)	// C2 subpicture offset division (disabled)		    + (1<<7)	// 422 subformat selection !/*		    + (0<<8)	// 15 bpp high alpha		    + (0<<9)	// 15 bpp high alpha		    + (0<<10)	// 15 bpp high alpha		    + (0<<11)	// 15 bpp high alpha		    + (0<<12)	// 15 bpp high alpha		    + (0<<13)	// 15 bpp high alpha		    + (0<<14)	// 15 bpp high alpha		    + (0<<15)	// 15 bpp high alpha		    + (0<<16)	// 15 bpp low alpha		    + (0<<17)	// 15 bpp low alpha		    + (0<<18)	// 15 bpp low alpha		    + (0<<19)	// 15 bpp low alpha		    + (0<<20)	// 15 bpp low alpha		    + (0<<21)	// 15 bpp low alpha		    + (0<<22)	// 15 bpp low alpha		    + (0<<23)	// 15 bpp low alpha		    + (0<<24)	// static subpicture key		    + (0<<25)	// static subpicture key		    + (0<<26)	// static subpicture key		    + (0<<27)	// static subpicture key		    + (0<<28)	// static subpicture key*/		    ;        break;    }	cregs.c2hparam=((hdispend - 8) << 16) | (htotal - 8);	cregs.c2hsync=((hsyncend - 8) << 16) | (hsyncstart - 8);		cregs.c2misc=0	// CRTCV2 656 togg f0		    +(0<<1) // CRTCV2 656 togg f0		    +(0<<2) // CRTCV2 656 togg f0		    +(0<<4) // CRTCV2 656 togg f1		    +(0<<5) // CRTCV2 656 togg f1		    +(0<<6) // CRTCV2 656 togg f1		    +(0<<8) // Hsync active high		    +(0<<9) // Vsync active high		    // 16-27 c2vlinecomp - nevim co tam dat		    ;	cregs.c2offset=(regs.bespitch << 1);	cregs.c2pl2startadd0=regs.besa1corg;	cregs.c2pl3startadd0=regs.besa1c3org;		    	cregs.c2preload=(vsyncstart << 16) | (hsyncstart); // from 		cregs.c2spicstartadd0=0; // not used	    cregs.c2startadd0=regs.besa1org;	    cregs.c2subpiclut=0; //not used	    cregs.c2vparam=((vdispend - 1) << 16) | (vtotal - 1);    cregs.c2vsync=((vsyncend - 1) << 16) | (vsyncstart - 1);#endif /* CRTC2 */    mga_vid_write_regs(0);    return(0);}static int mga_playback_on(void){    if (mga_verbose) printf("[mga] playback on\n");    vid_src_ready = 1;    if(vid_overlay_on)    {	regs.besctl |= 1;    	mga_vid_write_regs(0);    }#ifdef MGA_ALLOW_IRQ    if (mga_irq != -1)	enable_irq();#endif    mga_next_frame=0;    return(0);}static int mga_playback_off(void){    if (mga_verbose) printf("[mga] playback off\n");    vid_src_ready = 0;   #ifdef MGA_ALLOW_IRQ    if (mga_irq != -1)	disable_irq();#endif    regs.besctl &= ~1;    regs.besglobctl &= ~(1<<6); /* UYVY format selected */    mga_vid_write_regs(0);    return(0);}static int mga_probe(int verbose,int force){	pciinfo_t lst[MAX_PCI_DEVICES];	unsigned int i, num_pci;	int err;	if (verbose) printf("[mga] probe\n");	mga_verbose = verbose;	is_g400 = -1;	err = pci_scan(lst, &num_pci);	if (err)	{	    printf("[mga] Error occurred during pci scan: %s\n", strerror(err));	    return(err);	}	if (mga_verbose)	    printf("[mga] found %d pci devices\n", num_pci);		for (i = 0; i < num_pci; i++)	{	    if (mga_verbose > 1)		printf("[mga] pci[%d] vendor: %d device: %d\n",		    i, lst[i].vendor, lst[i].device);	    if (lst[i].vendor == VENDOR_MATROX)	    {#if 0		if ((lst[i].command & PCI_COMMAND_IO) == 0)		{			printf("[mga] Device is disabled, ignoring\n");			continue;		}#endif		switch(lst[i].device)		{		    case DEVICE_MATROX_MGA_G550_AGP:			printf("[mga] Found MGA G550\n");			is_g400 = 1;			goto card_found;		    case DEVICE_MATROX_MGA_G400_G450:			printf("[mga] Found MGA G400/G450\n");			is_g400 = 1;			goto card_found;		    case DEVICE_MATROX_MGA_G200_AGP:			printf("[mga] Found MGA G200 AGP\n");			is_g400 = 0;			goto card_found;		    case DEVICE_MATROX_MGA_G200:			printf("[mga] Found MGA G200 PCI\n");			is_g400 = 0;			goto card_found;		}	    }	}	if (is_g400 == -1)	{		if (verbose) printf("[mga] Can't find chip\n");		return(ENXIO);	}card_found:	probed = 1;	memcpy(&pci_info, &lst[i], sizeof(pciinfo_t));	mga_cap.device_id = pci_info.device; /* set device id in capabilites */	return(0);}static int mga_init(void){    unsigned int card_option = 0;    int err;        if (mga_verbose) printf("[mga] init\n");    mga_vid_in_use = 0;    printf("Matrox MGA G200/G400/G450 YUV Video interface v2.01 (c) Aaron Holtzman & A'rpi\n");#ifdef CRCT2    printf("Driver compiled with TV-out (second-head) support\n");#endif    if (!probed)    {	printf("[mga] driver was not probed but is being initializing\n");	return(EINTR);    }#ifdef MGA_PCICONFIG_MEMDETECT    pci_config_read(pci_info.bus, pci_info.card, pci_info.func,        0x40, 4, &card_option);    if (mga_verbose > 1) printf("[mga] OPTION word: 0x%08X  mem: 0x%02X  %s\n", card_option,    	(card_option>>10)&0x17, ((card_option>>14)&1)?"SGRAM":"SDRAM");#endif    if (mga_ram_size)    {    	printf("[mga] RAMSIZE forced to %d MB\n", mga_ram_size);    }    else    {#ifdef MGA_MEMORY_SIZE        mga_ram_size = MGA_MEMORY_SIZE;        printf("[mga] hard-coded RAMSIZE is %d MB\n", (unsigned int) mga_ram_size);#else        if (is_g400)	{	    switch((card_option>>10)&0x17)	    {	        // SDRAM:	        case 0x00:	        case 0x04:  mga_ram_size = 16; break;	        case 0x03:  mga_ram_size = 32; break;	        // SGRAM:	        case 0x10:	        case 0x14:  mga_ram_size = 32; break;	        case 0x11:	        case 0x12:  mga_ram_size = 16; break;	        default:	    	    mga_ram_size = 16;		    printf("[mga] Couldn't detect RAMSIZE, assuming 16MB!\n");	    }	}	else	{	    switch((card_option>>10)&0x17)	    {		default: mga_ram_size = 8;	    }	}         printf("[mga] detected RAMSIZE is %d MB\n", (unsigned int) mga_ram_size);#endif    }    if (mga_ram_size)    {	if ((mga_ram_size < 4) || (mga_ram_size > 64))	{	    printf("[mga] invalid RAMSIZE: %d MB\n", mga_ram_size);	    return(EINVAL);	}    }    if (mga_verbose > 1) printf("[mga] hardware addresses: mmio: %#x, framebuffer: %#x\n",        pci_info.base1, pci_info.base0);    mga_mmio_base = map_phys_mem(pci_info.base1,0x4000);    mga_mem_base = map_phys_mem(pci_info.base0,mga_ram_size*1024*1024);    if (mga_verbose > 1) printf("[mga] MMIO at %p, IRQ: %d, framebuffer: %p\n",        mga_mmio_base, mga_irq, mga_mem_base);    err = mtrr_set_type(pci_info.base0,mga_ram_size*1024*1024,MTRR_TYPE_WRCOMB);    if(!err) printf("[mga] Set write-combining type of video memory\n");#ifdef MGA_ALLOW_IRQ    if (mga_irq != -1)    {    	int tmp = request_irq(mga_irq, mga_handle_irq, SA_INTERRUPT | SA_SHIRQ, "Syncfb Time Base", &mga_irq);    	if (tmp)	{    	    printf("syncfb (mga): cannot register irq %d (Err: %d)\n", mga_irq, tmp);    	    mga_irq=-1;	}	else	{	    printf("syncfb (mga): registered irq %d\n", mga_irq);	}    }    else    {	printf("syncfb (mga): No valid irq was found\n");	mga_irq=-1;    }#else	printf("syncfb (mga): IRQ disabled in mga_vid.c\n");	mga_irq=-1;#endif    return(0);}static void mga_destroy(void){    if (mga_verbose) printf("[mga] destroy\n");    /* FIXME turn off BES */    vid_src_ready = 0;       regs.besctl &= ~1;    regs.besglobctl &= ~(1<<6);  // UYVY format selected    mga_vid_write_regs(1);    mga_vid_in_use = 0;#ifdef MGA_ALLOW_IRQ    if (mga_irq != -1)    	free_irq(mga_irq, &mga_irq);#endif    if (mga_mmio_base)        unmap_phys_mem(mga_mmio_base, 0x4000);    if (mga_mem_base)        unmap_phys_mem(mga_mem_base, mga_ram_size);    return;}static int mga_query_fourcc(vidix_fourcc_t *to){    if (mga_verbose) printf("[mga] query fourcc (%x)\n", to->fourcc);    switch(to->fourcc)    {	case IMGFMT_YV12:	case IMGFMT_IYUV:	case IMGFMT_I420:	case IMGFMT_YUY2:	case IMGFMT_UYVY:	    break;	default:	    to->depth = to->flags = 0;	    return(ENOTSUP);    }        to->depth = VID_DEPTH_12BPP |		VID_DEPTH_15BPP | VID_DEPTH_16BPP |		VID_DEPTH_24BPP | VID_DEPTH_32BPP;    to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY;    return(0);}static int mga_get_caps(vidix_capability_t *to){    memcpy(to, &mga_cap, sizeof(vidix_capability_t));    return(0);}static int mga_get_gkeys(vidix_grkey_t *grkey){    memcpy(grkey, &mga_grkey, sizeof(vidix_grkey_t));    return(0);}static int mga_set_gkeys(const vidix_grkey_t *grkey){    memcpy(&mga_grkey, grkey, sizeof(vidix_grkey_t));    mga_vid_write_regs(0);    return(0);}static int mga_set_eq( const vidix_video_eq_t * eq){    /* contrast and brightness control isn't supported on G200 - alex */    if (!is_g400)    {	if (mga_verbose) printf("[mga] equalizer isn't supported with G200\n");	return(ENOTSUP);    }    // only brightness&contrast are supported:    if(!(eq->cap & (VEQ_CAP_BRIGHTNESS|VEQ_CAP_CONTRAST)))	return(ENOTSUP);        //regs.beslumactl = readl(mga_mmio_base + BESLUMACTL);    if (eq->cap & VEQ_CAP_BRIGHTNESS) { 	regs.beslumactl &= 0xFFFF;	regs.beslumactl |= (eq->brightness*255/2000)<<16;    }    if (eq->cap & VEQ_CAP_CONTRAST) {	regs.beslumactl &= 0xFFFF0000;	regs.beslumactl |= (128+eq->contrast*255/2000)&0xFFFF;    }    writel(regs.beslumactl,mga_mmio_base + BESLUMACTL);    return(0);}static int mga_get_eq( vidix_video_eq_t * eq){    /* contrast and brightness control isn't supported on G200 - alex */    if (!is_g400)    {	if (mga_verbose) printf("[mga] equalizer isn't supported with G200\n");	return(ENOTSUP);    }    eq->brightness = (signed short int)(regs.beslumactl >> 16) * 1000 / 128;    eq->contrast = (signed short int)(regs.beslumactl & 0xFFFF) * 1000 / 128 - 1000;    eq->cap = VEQ_CAP_BRIGHTNESS | VEQ_CAP_CONTRAST;        printf("MGA GET_EQ: br=%d c=%d  \n",eq->brightness,eq->contrast);    return(0);}#ifndef CRTC2VDXDriver mga_drv = {  "mga",#elseVDXDriver mga_crtc2_drv = {  "mga_crtc2",#endif  NULL,      .probe = mga_probe,  .get_caps = mga_get_caps,  .query_fourcc = mga_query_fourcc,  .init = mga_init,  .destroy = mga_destroy,  .config_playback = mga_config_playback,  .playback_on = mga_playback_on,  .playback_off = mga_playback_off,  .frame_sel = mga_frame_select,  .get_eq = mga_get_eq,  .set_eq = mga_set_eq,  .get_gkey = mga_get_gkeys,  .set_gkey = mga_set_gkeys,};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?