cyberblade_vid.c
来自「linux下的MPEG1」· C语言 代码 · 共 650 行 · 第 1/2 页
C
650 行
/* Driver for CyberBlade/i1 - Version 0.1.4 Copyright (C) 2002 by Alastair M. Robinson. Official homepage: http://www.blackfiveservices.co.uk/EPIAVidix.shtml Based on Permedia 3 driver by Måns Rullgård Thanks to Gilles Frattini for bugfixes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Changes: 18/01/03 MMIO is no longer used, sidestepping cache issues on EPIA-800 TV-Out modes are now better supported - this should be the end of the magenta stripes :) Brightness/Contrast controls disabled for the time being - they were seriously degrading picture quality, especially with TV-Out. To Do: Implement Hue/Saturation controls Support / Test multiple frames Test colour-key code more extensively*/#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <inttypes.h>#include <unistd.h>#include "vidix.h"#include "fourcc.h"#include "libdha.h"#include "pci_ids.h"#include "pci_names.h"#include "cyberblade_regs.h"pciinfo_t pci_info;char save_colourkey[6];char *cyberblade_mem;#ifdef DEBUG_LOGFILEFILE *logfile=0;#define LOGWRITE(x) {if(logfile) fprintf(logfile,x);}#else#define LOGWRITE(x)#endif/* Helper functions for reading registers. */ #if 0 /* unused */static int CRINW(int reg){ int result; result=CRINB(reg); result|=CRINB(reg+1)<<8; return(result);}#endifstatic void CROUTW(int reg,int val){ CROUTB(reg,val&255); CROUTB(reg+1,(val>>8)&255);}#if 0 /* unused */static int SRINW(int reg){ int result; result=SRINB(reg); result|=SRINB(reg+1)<<8; return(result);}#endifstatic void SROUTW(int reg,int val){ SROUTB(reg,val&255); SROUTB(reg+1,(val>>8)&255);}#if 0 /* unused */static void DumpRegisters(void){#ifdef DEBUG_LOGFILE int reg,val; if(logfile) { LOGWRITE("CRTC Register Dump:\n") for(reg=0;reg<256;++reg) { val=CRINB(reg); fprintf(logfile,"CR0x%2x: 0x%2x\n",reg,val); } LOGWRITE("SR Register Dump:\n") for(reg=0;reg<256;++reg) { val=SRINB(reg); fprintf(logfile,"SR0x%2x: 0x%2x\n",reg,val); } }#endif}#endif/* --- */static vidix_capability_t cyberblade_cap ={ "Trident CyberBlade i1 driver", "Alastair M. Robinson <blackfive@fakenhamweb.co.uk>", TYPE_OUTPUT, { 0, 0, 0, 0 }, 1024, 1024, 4, 4, -1, FLAG_UPSCALER|FLAG_DOWNSCALER, VENDOR_TRIDENT, -1, { 0, 0, 0, 0 }};unsigned int vixGetVersion(void){ return(VIDIX_VERSION);}static unsigned short cyberblade_card_ids[] ={ DEVICE_TRIDENT_CYBERBLADE_I7, DEVICE_TRIDENT_CYBERBLADE_I7D, DEVICE_TRIDENT_CYBERBLADE_I1, DEVICE_TRIDENT_CYBERBLADE_I12, DEVICE_TRIDENT_CYBERBLADE_I13, DEVICE_TRIDENT_CYBERBLADE_XPAI1};static int find_chip(unsigned chip_id){ unsigned i; for(i = 0;i < sizeof(cyberblade_card_ids)/sizeof(unsigned short);i++) { if(chip_id == cyberblade_card_ids[i]) return i; } return -1;}int vixProbe(int verbose, int force){ pciinfo_t lst[MAX_PCI_DEVICES]; unsigned i,num_pci; int err; err = pci_scan(lst,&num_pci); if(err) { printf("[cyberblade] Error occurred during pci scan: %s\n",strerror(err)); return err; } else { err = ENXIO; for(i=0; i < num_pci; i++) { if(lst[i].vendor == VENDOR_TRIDENT) { int idx; const char *dname; idx = find_chip(lst[i].device); if(idx == -1) continue; dname = pci_device_name(VENDOR_TRIDENT, lst[i].device); dname = dname ? dname : "Unknown chip"; printf("[cyberblade] Found chip: %s\n", dname); cyberblade_cap.device_id = lst[i].device; err = 0; memcpy(&pci_info, &lst[i], sizeof(pciinfo_t)); break; } } } if(err && verbose) printf("[cyberblade] Can't find chip\n"); return err;}int vixInit(const char *args){ cyberblade_mem = map_phys_mem(pci_info.base0, 0x800000); enable_app_io(); save_colourkey[0]=SRINB(0x50); save_colourkey[1]=SRINB(0x51); save_colourkey[2]=SRINB(0x52); save_colourkey[3]=SRINB(0x54); save_colourkey[4]=SRINB(0x55); save_colourkey[5]=SRINB(0x56);#ifdef DEBUG_LOGFILE logfile=fopen("/tmp/cyberblade_vidix.log","w");#endif return 0;}void vixDestroy(void){ int protect;#ifdef DEBUG_LOGFILE if(logfile) fclose(logfile);#endif protect=SRINB(0x11); SROUTB(0x11, 0x92); CROUTB(0x8E, 0xc4); /* Disable overlay */ SROUTB(0x50,save_colourkey[0]); SROUTB(0x51,save_colourkey[1]); SROUTB(0x52,save_colourkey[2]); SROUTB(0x54,save_colourkey[3]); SROUTB(0x55,save_colourkey[4]); SROUTB(0x56,save_colourkey[5]); SROUTB(0x11, protect); disable_app_io(); unmap_phys_mem(cyberblade_mem, 0x800000); }int vixGetCapability(vidix_capability_t *to){ memcpy(to, &cyberblade_cap, sizeof(vidix_capability_t)); return 0;}static int is_supported_fourcc(uint32_t fourcc){ switch(fourcc) { case IMGFMT_YUY2: case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9: case IMGFMT_BGR16: return 1; default: return 0; }}int vixQueryFourcc(vidix_fourcc_t *to){ if(is_supported_fourcc(to->fourcc)) { to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | VID_DEPTH_4BPP | VID_DEPTH_8BPP | 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; } else to->depth = to->flags = 0; return ENOSYS;}static int frames[VID_PLAY_MAXFRAMES];static vidix_grkey_t cyberblade_grkey;int vixGetGrKeys(vidix_grkey_t *grkey){ memcpy(grkey, &cyberblade_grkey, sizeof(vidix_grkey_t)); return(0);}int vixSetGrKeys(const vidix_grkey_t *grkey){ int pixfmt=CRINB(0x38); int protect; memcpy(&cyberblade_grkey, grkey, sizeof(vidix_grkey_t)); protect=SRINB(0x11); SROUTB(0x11, 0x92); if(pixfmt&0x28) /* 32 or 24 bpp */ { SROUTB(0x50, cyberblade_grkey.ckey.blue); /* Colour Key */ SROUTB(0x51, cyberblade_grkey.ckey.green); /* Colour Key */ SROUTB(0x52, cyberblade_grkey.ckey.red); /* Colour Key */ SROUTB(0x54, 0xff); /* Colour Key Mask */ SROUTB(0x55, 0xff); /* Colour Key Mask */ SROUTB(0x56, 0xff); /* Colour Key Mask */ } else { int tmp=((cyberblade_grkey.ckey.blue & 0xF8)>>3) | ((cyberblade_grkey.ckey.green & 0xfc)<<3) | ((cyberblade_grkey.ckey.red & 0xf8)<<8); SROUTB(0x50, tmp&0xff); /* Colour Key */ SROUTB(0x51, (tmp>>8)&0xff); /* Colour Key */ SROUTB(0x52, 0); /* Colour Key */ SROUTB(0x54, 0xff); /* Colour Key Mask */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?