⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zr36120.c

📁 pxa270下的摄像头mtd91111的驱动
💻 C
📖 第 1 页 / 共 4 页
字号:
/*    zr36120.c - Zoran 36120/36125 based framegrabbers    Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>    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., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include <linux/module.h>#include <linux/delay.h>#include <linux/init.h>#include <linux/errno.h>#include <linux/fs.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/slab.h>#include <linux/vmalloc.h>#include <linux/mm.h>#include <linux/pci.h>#include <linux/signal.h>#include <asm/io.h>#include <asm/pgtable.h>#include <asm/page.h>#include <linux/sched.h>#include <linux/video_decoder.h>#include <asm/segment.h>#include <linux/version.h>#include <asm/uaccess.h>#include "tuner.h"#include "zr36120.h"#include "zr36120_mem.h"/* mark an required function argument unused - lintism */#define	UNUSED(x)	(void)(x)/* sensible default */#ifndef CARDTYPE#define CARDTYPE 0#endif/* Anybody who uses more than four? */#define ZORAN_MAX 4static unsigned int triton1=0;			/* triton1 chipset? */static unsigned int cardtype[ZORAN_MAX]={ [ 0 ... ZORAN_MAX-1 ] = CARDTYPE };static int video_nr = -1;static int vbi_nr = -1;static struct pci_device_id zr36120_pci_tbl[] = {	{ PCI_VENDOR_ID_ZORAN,PCI_DEVICE_ID_ZORAN_36120,	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },	{ 0 }};MODULE_DEVICE_TABLE(pci, zr36120_pci_tbl);MODULE_AUTHOR("Pauline Middelink <middelin@polyware.nl>");MODULE_DESCRIPTION("Zoran ZR36120 based framegrabber");MODULE_LICENSE("GPL");MODULE_PARM(triton1,"i");MODULE_PARM(cardtype,"1-" __MODULE_STRING(ZORAN_MAX) "i");MODULE_PARM(video_nr,"i");MODULE_PARM(vbi_nr,"i");static int zoran_cards;static struct zoran zorans[ZORAN_MAX];/* * the meaning of each element can be found in zr36120.h * Determining the value of gpdir/gpval can be tricky. The * best way is to run the card under the original software * and read the values from the general purpose registers * 0x28 and 0x2C. How you do that is left as an exercise * to the impatient reader :) */#define T 1	/* to seperate the bools from the ints */#define F 0static struct tvcard tvcards[] = {	/* reported working by <middelin@polyware.nl> *//*0*/	{ "Trust Victor II",	  2, 0, T, T, T, T, 0x7F, 0x80, { 1, SVHS(6) }, { 0 } },	/* reported working by <Michael.Paxton@aihw.gov.au>  *//*1*/   { "Aitech WaveWatcher TV-PCI",	  3, 0, T, F, T, T, 0x7F, 0x80, { 1, TUNER(3), SVHS(6) }, { 0 } },	/* reported working by ? *//*2*/	{ "Genius Video Wonder PCI Video Capture Card",	  2, 0, T, T, T, T, 0x7F, 0x80, { 1, SVHS(6) }, { 0 } },	/* reported working by <Pascal.Gabriel@wanadoo.fr> *//*3*/	{ "Guillemot Maxi-TV PCI",	  2, 0, T, T, T, T, 0x7F, 0x80, { 1, SVHS(6) }, { 0 } },	/* reported working by "Craig Whitmore <lennon@igrin.co.nz> *//*4*/	{ "Quadrant Buster",	  3, 3, T, F, T, T, 0x7F, 0x80, { SVHS(1), TUNER(2), 3 }, { 1, 2, 3 } },	/* a debug entry which has all inputs mapped *//*5*/	{ "ZR36120 based framegrabber (all inputs enabled)",	  6, 0, T, T, T, T, 0x7F, 0x80, { 1, 2, 3, 4, 5, 6 }, { 0 } }};#undef T#undef F#define NRTVCARDS (sizeof(tvcards)/sizeof(tvcards[0]))#ifdef __sparc__#define	ENDIANESS	0#else#define	ENDIANESS	ZORAN_VFEC_LE#endifstatic struct { const char name[8]; uint mode; uint bpp; } palette2fmt[] = {/* n/a     */	{ "n/a",     0, 0 },/* GREY    */	{ "GRAY",    0, 0 },/* HI240   */	{ "HI240",   0, 0 },/* RGB565  */	{ "RGB565",  ZORAN_VFEC_RGB_RGB565|ENDIANESS, 2 },/* RGB24   */	{ "RGB24",   ZORAN_VFEC_RGB_RGB888|ENDIANESS|ZORAN_VFEC_PACK24, 3 },/* RGB32   */	{ "RGB32",   ZORAN_VFEC_RGB_RGB888|ENDIANESS, 4 },/* RGB555  */	{ "RGB555",  ZORAN_VFEC_RGB_RGB555|ENDIANESS, 2 },/* YUV422  */	{ "YUV422",  ZORAN_VFEC_RGB_YUV422|ENDIANESS, 2 },/* YUYV    */	{ "YUYV",    0, 0 },/* UYVY    */	{ "UYVY",    0, 0 },/* YUV420  */	{ "YUV420",  0, 0 },/* YUV411  */	{ "YUV411",  0, 0 },/* RAW     */	{ "RAW",     0, 0 },/* YUV422P */	{ "YUV422P", 0, 0 },/* YUV411P */	{ "YUV411P", 0, 0 }};#define NRPALETTES (sizeof(palette2fmt)/sizeof(palette2fmt[0]))#undef ENDIANESS/* ----------------------------------------------------------------------- *//* ZORAN chipset detector                                                 *//* shamelessly stolen from bttv.c                                         *//* Reason for beeing here: we need to detect if we are running on a        *//* Triton based chipset, and if so, enable a certain bit                   *//* ----------------------------------------------------------------------- */staticvoid __init handle_chipset(void){	struct pci_dev *dev = NULL;	/* Just in case some nut set this to something dangerous */	if (triton1)		triton1 = ZORAN_VDC_TRICOM;	while ((dev = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437, dev)))	{		printk(KERN_INFO "zoran: Host bridge 82437FX Triton PIIX\n");		triton1 = ZORAN_VDC_TRICOM;	}}/* ----------------------------------------------------------------------- *//* ZORAN functions							   *//* ----------------------------------------------------------------------- */static void zoran_set_geo(struct zoran* ztv, struct vidinfo* i);#if 0 /* unused */staticvoid zoran_dump(struct zoran *ztv){	char	str[256];	char	*p=str; /* shut up, gcc! */	int	i;	for (i=0; i<0x60; i+=4) {		if ((i % 16) == 0) {			if (i) printk("%s\n",str);			p = str;			p+= sprintf(str, KERN_DEBUG "       %04x: ",i);		}		p += sprintf(p, "%08x ",zrread(i));	}}#endif /* unused */staticvoid reap_states(struct zoran* ztv){	/* count frames */	ztv->fieldnr++;	/*	 * Are we busy at all?	 * This depends on if there is a workqueue AND the	 * videotransfer is enabled on the chip...	 */	if (ztv->workqueue && (zrread(ZORAN_VDC) & ZORAN_VDC_VIDEN))	{		struct vidinfo* newitem;		/* did we get a complete frame? */		if (zrread(ZORAN_VSTR) & ZORAN_VSTR_GRAB)			return;DEBUG(printk(CARD_DEBUG "completed %s at %p\n",CARD,ztv->workqueue->kindof==FBUFFER_GRAB?"grab":"read",ztv->workqueue));		/* we are done with this buffer, tell everyone */		ztv->workqueue->status = FBUFFER_DONE;		ztv->workqueue->fieldnr = ztv->fieldnr;		/* not good, here for BTTV_FIELDNR reasons */		ztv->lastfieldnr = ztv->fieldnr;		switch (ztv->workqueue->kindof) {		 case FBUFFER_GRAB:			wake_up_interruptible(&ztv->grabq);			break;		 case FBUFFER_VBI:			wake_up_interruptible(&ztv->vbiq);			break;		 default:			printk(CARD_INFO "somebody killed the workqueue (kindof=%d)!\n",CARD,ztv->workqueue->kindof);		}		/* item completed, skip to next item in queue */		write_lock(&ztv->lock);		newitem = ztv->workqueue->next;		ztv->workqueue->next = 0;	/* mark completed */		ztv->workqueue = newitem;		write_unlock(&ztv->lock);	}	/*	 * ok, so it seems we have nothing in progress right now.	 * Lets see if we can find some work.	 */	if (ztv->workqueue)	{		struct vidinfo* newitem;again:DEBUG(printk(CARD_DEBUG "starting %s at %p\n",CARD,ztv->workqueue->kindof==FBUFFER_GRAB?"grab":"read",ztv->workqueue));		/* loadup the frame settings */		read_lock(&ztv->lock);		zoran_set_geo(ztv,ztv->workqueue);		read_unlock(&ztv->lock);		switch (ztv->workqueue->kindof) {		 case FBUFFER_GRAB:		 case FBUFFER_VBI:			zrand(~ZORAN_OCR_OVLEN, ZORAN_OCR);			zror(ZORAN_VSTR_SNAPSHOT,ZORAN_VSTR);			zror(ZORAN_VDC_VIDEN,ZORAN_VDC);			/* start single-shot grab */			zror(ZORAN_VSTR_GRAB, ZORAN_VSTR);			break;		 default:			printk(CARD_INFO "what is this doing on the queue? (kindof=%d)\n",CARD,ztv->workqueue->kindof);			write_lock(&ztv->lock);			newitem = ztv->workqueue->next;			ztv->workqueue->next = 0;			ztv->workqueue = newitem;			write_unlock(&ztv->lock);			if (newitem)				goto again;	/* yeah, sure.. */		}		/* bye for now */		return;	}DEBUG(printk(CARD_DEBUG "nothing in queue\n",CARD));	/*	 * What? Even the workqueue is empty? Am i really here	 * for nothing? Did i come all that way to... do nothing?	 */	/* do we need to overlay? */	if (test_bit(STATE_OVERLAY, &ztv->state))	{		/* are we already overlaying? */		if (!(zrread(ZORAN_OCR) & ZORAN_OCR_OVLEN) ||		    !(zrread(ZORAN_VDC) & ZORAN_VDC_VIDEN))		{DEBUG(printk(CARD_DEBUG "starting overlay\n",CARD));			read_lock(&ztv->lock);			zoran_set_geo(ztv,&ztv->overinfo);			read_unlock(&ztv->lock);			zror(ZORAN_OCR_OVLEN, ZORAN_OCR);			zrand(~ZORAN_VSTR_SNAPSHOT,ZORAN_VSTR);			zror(ZORAN_VDC_VIDEN,ZORAN_VDC);		}		/*		 * leave overlaying on, but turn interrupts off.		 */		zrand(~ZORAN_ICR_EN,ZORAN_ICR);		return;	}	/* do we have any VBI idle time processing? */	if (test_bit(STATE_VBI, &ztv->state))	{		struct vidinfo* item;		struct vidinfo* lastitem;		/* protect the workqueue */		write_lock(&ztv->lock);		lastitem = ztv->workqueue;		if (lastitem)			while (lastitem->next) lastitem = lastitem->next;		for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++)			if (item->next == 0 && item->status == FBUFFER_FREE)			{DEBUG(printk(CARD_DEBUG "%p added to queue\n",CARD,item));				item->status = FBUFFER_BUSY;				if (!lastitem)					ztv->workqueue = item;				else 					lastitem->next = item;				lastitem = item;			}		write_unlock(&ztv->lock);		if (ztv->workqueue)			goto again;	/* hey, _i_ graduated :) */	}	/*	 * Then we must be realy IDLE	 */DEBUG(printk(CARD_DEBUG "turning off\n",CARD));	/* nothing further to do, disable DMA and further IRQs */	zrand(~ZORAN_VDC_VIDEN,ZORAN_VDC);	zrand(~ZORAN_ICR_EN,ZORAN_ICR);}staticvoid zoran_irq(int irq, void *dev_id, struct pt_regs * regs){	u32 stat,estat;	int count = 0;	struct zoran *ztv = (struct zoran *)dev_id;	UNUSED(irq); UNUSED(regs);	for (;;) {		/* get/clear interrupt status bits */		stat=zrread(ZORAN_ISR);		estat=stat & zrread(ZORAN_ICR);		if (!estat)			return;		zrwrite(estat,ZORAN_ISR);		IDEBUG(printk(CARD_DEBUG "estat %08x\n",CARD,estat));		IDEBUG(printk(CARD_DEBUG " stat %08x\n",CARD,stat));		if (estat & ZORAN_ISR_CODE)		{			IDEBUG(printk(CARD_DEBUG "CodReplIRQ\n",CARD));		}		if (estat & ZORAN_ISR_GIRQ0)		{			IDEBUG(printk(CARD_DEBUG "GIRQ0\n",CARD));			if (!ztv->card->usegirq1)				reap_states(ztv);		}		if (estat & ZORAN_ISR_GIRQ1)		{			IDEBUG(printk(CARD_DEBUG "GIRQ1\n",CARD));			if (ztv->card->usegirq1)				reap_states(ztv);		}		count++;		if (count > 10)			printk(CARD_ERR "irq loop %d (%x)\n",CARD,count,estat);		if (count > 20)		{			zrwrite(0, ZORAN_ICR);			printk(CARD_ERR "IRQ lockup, cleared int mask\n",CARD);		}	}}staticint zoran_muxsel(struct zoran* ztv, int channel, int norm){	int	rv;	/* set the new video norm */	rv = i2c_control_device(&(ztv->i2c), I2C_DRIVERID_VIDEODECODER, DECODER_SET_NORM, &norm);	if (rv)		return rv;	ztv->norm = norm;	/* map the given channel to the cards decoder's channel */	channel = ztv->card->video_mux[channel] & CHANNEL_MASK;	/* set the new channel */	rv = i2c_control_device(&(ztv->i2c), I2C_DRIVERID_VIDEODECODER, DECODER_SET_INPUT, &channel);	return rv;}/* Tell the interrupt handler what to to.  */staticvoid zoran_cap(struct zoran* ztv, int on){DEBUG(printk(CARD_DEBUG "zoran_cap(%d) state=%x\n",CARD,on,ztv->state));	if (on) {		ztv->running = 1;		/*		 * turn interrupts (back) on. The DMA will be enabled		 * inside the irq handler when it detects a restart.		 */		zror(ZORAN_ICR_EN,ZORAN_ICR);	}	else {		/*		 * turn both interrupts and DMA off		 */		zrand(~ZORAN_VDC_VIDEN,ZORAN_VDC);		zrand(~ZORAN_ICR_EN,ZORAN_ICR);		ztv->running = 0;	}}static ulong dmask[] = {	0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFC, 0xFFFFFFF8,	0xFFFFFFF0, 0xFFFFFFE0, 0xFFFFFFC0, 0xFFFFFF80,	0xFFFFFF00, 0xFFFFFE00, 0xFFFFFC00, 0xFFFFF800,	0xFFFFF000, 0xFFFFE000, 0xFFFFC000, 0xFFFF8000,	0xFFFF0000, 0xFFFE0000, 0xFFFC0000, 0xFFF80000,	0xFFF00000, 0xFFE00000, 0xFFC00000, 0xFF800000,	0xFF000000, 0xFE000000, 0xFC000000, 0xF8000000,	0xF0000000, 0xE0000000, 0xC0000000, 0x80000000};staticvoid zoran_built_overlay(struct zoran* ztv, int count, struct video_clip *vcp){	ulong*	mtop;	int	ystep = (ztv->vidXshift + ztv->vidWidth+31)/32;	/* next DWORD */	int	i;DEBUG(printk(KERN_DEBUG "       overlay at %p, ystep=%d, clips=%d\n",ztv->overinfo.overlay,ystep,count));	for (i=0; i<count; i++) {		struct video_clip *vp = vcp+i;		UNUSED(vp);DEBUG(printk(KERN_DEBUG "       %d: clip(%d,%d,%d,%d)\n", i,vp->x,vp->y,vp->width,vp->height));	}	/*	 * activate the visible portion of the screen	 * Note we take some shortcuts here, because we	 * know the width can never be < 32. (I.e. a DWORD)	 * We also assume the overlay starts somewhere in	 * the FIRST dword.	 */	{		int start = ztv->vidXshift;		ulong firstd = dmask[start];		ulong lastd = ~dmask[(start + ztv->overinfo.w) & 31];		mtop = ztv->overinfo.overlay;		for (i=0; i<ztv->overinfo.h; i++) {			int w = ztv->vidWidth;			ulong* line = mtop;			if (start & 31) {				*line++ = firstd;				w -= 32-(start&31);			}			memset(line, ~0, w/8);			if (w & 31)				line[w/32] = lastd;			mtop += ystep;		}	}	/* process clipping regions */	for (i=0; i<count; i++) {		int h;		if (vcp->x < 0 || (uint)vcp->x > ztv->overinfo.w ||		    vcp->y < 0 || vcp->y > ztv->overinfo.h ||		    vcp->width < 0 || (uint)(vcp->x+vcp->width) > ztv->overinfo.w ||		    vcp->height < 0 || (vcp->y+vcp->height) > ztv->overinfo.h)		{			DEBUG(printk(CARD_DEBUG "illegal clipzone (%d,%d,%d,%d) not in (0,0,%d,%d), adapting\n",CARD,vcp->x,vcp->y,vcp->width,vcp->height,ztv->overinfo.w,ztv->overinfo.h));			if (vcp->x < 0) vcp->x = 0;			if ((uint)vcp->x > ztv->overinfo.w) vcp->x = ztv->overinfo.w;			if (vcp->y < 0) vcp->y = 0;			if (vcp->y > ztv->overinfo.h) vcp->y = ztv->overinfo.h;			if (vcp->width < 0) vcp->width = 0;			if ((uint)(vcp->x+vcp->width) > ztv->overinfo.w) vcp->width = ztv->overinfo.w - vcp->x;			if (vcp->height < 0) vcp->height = 0;			if (vcp->y+vcp->height > ztv->overinfo.h) vcp->height = ztv->overinfo.h - vcp->y;//			continue;		}		mtop = &ztv->overinfo.overlay[vcp->y*ystep];		for (h=0; h<=vcp->height; h++) {			int w;			int x = ztv->vidXshift + vcp->x;			for (w=0; w<=vcp->width; w++) {				clear_bit(x&31, &mtop[x/32]);				x++;			}			mtop += ystep;		}		++vcp;	}	mtop = ztv->overinfo.overlay;	zrwrite(virt_to_bus(mtop), ZORAN_MTOP);	zrwrite(virt_to_bus(mtop+ystep), ZORAN_MBOT);	zraor((ztv->vidInterlace*ystep)<<0,~ZORAN_OCR_MASKSTRIDE,ZORAN_OCR);}struct tvnorm 

⌨️ 快捷键说明

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