📄 mga_vid.c
字号:
+ (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) // 420 mode + (1<<22) // 420 mode + (1<<23) // 420 mode + (0<<24) // single chroma line for 420 mode - need to be corrected + (0<<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 ; card->cregs.c2datactl = 1 // disable 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) + (0<<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; case MGA_VID_FORMAT_YUY2: card->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 - acc to spec + (1<<5) // high prioryty req + (0<<6) // high prioryty req // 7 reserved + (1<<8) // high prioryty req max + (0<<9) // high prioryty req max + (0<<10) // high prioryty req max // 11-19 reserved + (0<<20) // CRTC1 to DAC + (1<<21) // 422 mode + (0<<22) // 422 mode + (1<<23) // 422 mode + (0<<24) // single chroma line for 420 mode - need to be corrected + (0<<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 ; card->cregs.c2datactl = 1 // disable 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) + (0<<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; case MGA_VID_FORMAT_UYVY: card->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 ; card->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; default: printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format); return -1; } card->cregs.c2hparam = ( (hdispend - 8) << 16) | (htotal - 8); card->cregs.c2hsync = ( (hsyncend - 8) << 16) | (hsyncstart - 8); card->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 ; card->cregs.c2offset=(card->regs.bespitch << 1); card->cregs.c2pl2startadd0=card->regs.besa1corg;// card->cregs.c2pl2startadd1=card->regs.besa2corg; card->cregs.c2pl3startadd0=card->regs.besa1c3org;// card->cregs.c2pl3startadd1=card->regs.besa2c3org; card->cregs.c2preload=(vsyncstart << 16) | (hsyncstart); // from card->cregs.c2spicstartadd0=0; // not used// card->cregs.c2spicstartadd1=0; // not used card->cregs.c2startadd0=card->regs.besa1org;// card->cregs.c2startadd1=card->regs.besa2org; card->cregs.c2subpiclut=0; //not used card->cregs.c2vparam = ( (vdispend - 1) << 16) | (vtotal - 1); card->cregs.c2vsync = ( (vsyncend - 1) << 16) | (vsyncstart - 1); #endif mga_vid_write_regs(card, 0); return 0;}#ifdef MGA_ALLOW_IRQstatic void enable_irq(mga_card_t * card){ long int cc; cc = readl(card->mmio_base + IEN);// printk(KERN_ALERT "*** !!! IRQREG = %d\n", (int)(cc&0xff)); writeb(0x11, card->mmio_base + CRTCX); writeb(0x20, card->mmio_base + CRTCD); /* clear 0, enable off */ writeb(0x00, card->mmio_base + CRTCD); /* enable on */ writeb(0x10, card->mmio_base + CRTCD); /* clear = 1 */ writel(card->regs.besglobctl , card->mmio_base + BESGLOBCTL);}static void disable_irq(mga_card_t * card){ writeb(0x11, card->mmio_base + CRTCX); writeb(0x20, card->mmio_base + CRTCD); /* clear 0, enable off */}static void mga_handle_irq(int irq, void *dev_id, struct pt_regs *pregs) {// static int frame=0;// static int counter=0; long int cc; mga_card_t * card = dev_id;// printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT)); //printk("mga_interrupt #%d\n", irq); // check whether the interrupt is really for us (irq sharing) if ( irq != -1 ) { cc = readl(card->mmio_base + STATUS); if ( ! (cc & 0x10) ) return; /* vsyncpen */// debug_irqcnt++; } // if ( debug_irqignore ) {// debug_irqignore = 0;// frame=(frame+1)&1; card->regs.besctl = (card->regs.besctl & ~0x07000000) + (card->next_frame << 25); writel( card->regs.besctl, card->mmio_base + BESCTL ); #ifdef CRTC2// sem pridat vyber obrazku !!!! // i han echt kei ahnig was das obe heisse söll crtc2_frame_sel(card->next_frame);#endif #if 0 ++counter; if(!(counter&63)){ printk("mga irq counter = %d\n",counter); }#endif// } else {// debug_irqignore = 1;// } if ( irq != -1 ) { writeb( 0x11, card->mmio_base + CRTCX); writeb( 0, card->mmio_base + CRTCD ); writeb( 0x10, card->mmio_base + CRTCD ); }// writel( card->regs.besglobctl, card->mmio_base + BESGLOBCTL); return;}#endifstatic int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ int frame, result; uint32_t tmp; mga_card_t * card = (mga_card_t *) file->private_data; switch(cmd) { case MGA_VID_CONFIG: //FIXME remove// printk(KERN_DEBUG "mga_vid: vcount = %d\n",readl(card->mmio_base + VCOUNT));#ifdef MP_DEBUG printk(KERN_DEBUG "mga_vid: mmio_base = %p\n",card->mmio_base); printk(KERN_DEBUG "mga_vid: mem_base = %08x\n",card->mem_base); //FIXME remove printk(KERN_DEBUG "mga_vid: Received configuration\n");#endif if(copy_from_user(&card->config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t))) { printk(KERN_ERR "mga_vid: failed copy from userspace\n"); return(-EFAULT); } if(card->config.version != MGA_VID_VERSION){ printk(KERN_ERR "mga_vid: incompatible version! driver: %X requested: %X\n",MGA_VID_VERSION,card->config.version); return(-EFAULT); } if(card->config.frame_size==0 || card->config.frame_size>1024*768*2){ printk(KERN_ERR "mga_vid: illegal frame_size: %d\n",card->config.frame_size); return(-EFAULT); } if(card->config.num_frames<1 || card->config.num_frames>4){ printk(KERN_ERR "mga_vid: illegal num_frames: %d\n",card->config.num_frames); return(-EFAULT); } card->src_base = (card->ram_size * 0x100000 - card->config.num_frames * card->config.frame_size - card->top_reserved); if(card->src_base<0){ printk(KERN_ERR "mga_vid: not enough memory for frames!\n"); return(-EFAULT); } card->src_base &= (~0xFFFF); // 64k boundary#ifdef MP_DEBUG printk(KERN_DEBUG "mga YUV buffer base: 0x%X\n", card->src_base);#endif if (card->is_g400) card->config.card_type = MGA_G400; else card->config.card_type = MGA_G200; card->config.ram_size = card->ram_size; if (copy_to_user((mga_vid_config_t *) arg, &card->config, sizeof(mga_vid_config_t))) { printk(KERN_ERR "mga_vid: failed copy to userspace\n"); return(-EFAULT); } result = mga_vid_set_config(card); if(!result) card->configured=1; return result; break; case MGA_VID_ON:#ifdef MP_DEBUG printk(KERN_DEBUG "mga_vid: Video ON\n");#endif card->vid_src_ready = 1; if(card->vid_overlay_on) { card->regs.besctl |= 1; mga_vid_write_regs(card, 0); }#ifdef MGA_ALLOW_IRQ if ( card->irq != -1 ) enable_irq(card);#endif card->next_frame=0; break; case MGA_VID_OFF:#ifdef MP_DEBUG printk(KERN_DEBUG "mga_vid: Video OFF (ioctl)\n");#endif card->vid_src_ready = 0; #ifdef MGA_ALLOW_IRQ if ( card->irq != -1 ) disable_irq(card);#endif card->regs.besctl &= ~1; card->regs.besglobctl &= ~(1<<6); // UYVY format selected mga_vid_write_regs(card, 0); break; case MGA_VID_FSEL: if(copy_from_user(&frame,(int *) arg,sizeof(int))) { printk(KERN_ERR "mga_vid: FSEL failed copy from userspace\n"); return(-EFAULT); } mga_vid_frame_sel(card, frame); break; case MGA_VID_GET_LUMA: //tmp = card->regs.beslumactl; //tmp = (tmp&0xFFFF0000) | (((tmp&0xFFFF) - 0x80)&0xFFFF); tmp = (card->brightness << 16) | (card->contrast&0xFFFF); if (copy_to_user((uint32_t *) arg, &tmp, sizeof(uint32_t))) { printk(KERN_ERR "mga_vid: failed copy %p to userspace %p\n", &tmp, (uint32_t *) arg); return(-EFAULT); } break; case MGA_VID_SET_LUMA: tmp = arg; card->brightness=tmp>>16; card->contrast=tmp&0xFFFF; //card->regs.beslumactl = (tmp&0xFFFF0000) | ((tmp + 0x80)&0xFFFF); card->regs.beslumactl = (card->brightness << 16) | ((card->contrast+0x80)&0xFFFF); mga_vid_write_regs(card, 0); break; default: printk(KERN_ERR "mga_vid: Invalid ioctl\n"); return (-EINVAL); } return 0;}static void cards_init(mga_card_t * card, struct pci_dev * dev, int card_number, int is_g400);// returns the number of found cardsstatic int mga_vid_find_card(void){ struct pci_dev *dev = NULL; char *mga_dev_name; mga_card_t * card; while((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_ANY_ID, dev))) { mga_dev_name = ""; mga_cards_num++; if(mga_cards_num == MGA_MAX_CARDS) { printk(KERN_WARNING "mga_vid: Trying to initialize more than %d cards\n",MGA_MAX_CARDS); mga_cards_num--; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -