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

📄 cx88-video.c

📁 h内核
💻 C
📖 第 1 页 / 共 4 页
字号:
                t->rangehigh = (int)(108*16);#ifdef V4L2_I2C_CLIENTS		cx88_call_i2c_clients(dev->core,VIDIOC_G_TUNER,t);#else		{			struct video_tuner vt;			memset(&vt,0,sizeof(vt));			cx88_call_i2c_clients(dev,VIDIOCGTUNER,&vt);			t->signal = vt.signal;		}#endif		return 0;	}	case VIDIOC_ENUMINPUT:	{		struct v4l2_input *i = arg;		if (i->index != 0)			return -EINVAL;		strcpy(i->name,"Radio");		i->type = V4L2_INPUT_TYPE_TUNER;		return 0;	}	case VIDIOC_G_INPUT:	{		int *i = arg;		*i = 0;		return 0;	}	case VIDIOC_G_AUDIO:	{		struct v4l2_audio *a = arg;		memset(a,0,sizeof(*a));		strcpy(a->name,"Radio");		return 0;	}	case VIDIOC_G_STD:	{		v4l2_std_id *id = arg;		*id = 0;		return 0;	}	case VIDIOC_S_AUDIO:	case VIDIOC_S_TUNER:	case VIDIOC_S_INPUT:	case VIDIOC_S_STD:		return 0;	case VIDIOC_QUERYCTRL:	{		struct v4l2_queryctrl *c = arg;		int i;		if (c->id <  V4L2_CID_BASE ||		    c->id >= V4L2_CID_LASTP1)			return -EINVAL;		if (c->id == V4L2_CID_AUDIO_MUTE) {			for (i = 0; i < CX8800_CTLS; i++)				if (cx8800_ctls[i].v.id == c->id)					break;			*c = cx8800_ctls[i].v;		} else			*c = no_ctl;		return 0;	}	case VIDIOC_G_CTRL:	case VIDIOC_S_CTRL:	case VIDIOC_G_FREQUENCY:	case VIDIOC_S_FREQUENCY:		return video_do_ioctl(inode,file,cmd,arg);	default:		return v4l_compat_translate_ioctl(inode,file,cmd,arg,						  radio_do_ioctl);	}	return 0;};static int radio_ioctl(struct inode *inode, struct file *file,			unsigned int cmd, unsigned long arg){	return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);};/* ----------------------------------------------------------- */static void cx8800_vid_timeout(unsigned long data){	struct cx8800_dev *dev = (struct cx8800_dev*)data;	struct cx88_core *core = dev->core;	struct cx88_dmaqueue *q = &dev->vidq;	struct cx88_buffer *buf;	unsigned long flags;	cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH21]);	cx_clear(MO_VID_DMACNTRL, 0x11);	cx_clear(VID_CAPTURE_CONTROL, 0x06);	spin_lock_irqsave(&dev->slock,flags);	while (!list_empty(&q->active)) {		buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);		list_del(&buf->vb.queue);		buf->vb.state = STATE_ERROR;		wake_up(&buf->vb.done);		printk("%s/0: [%p/%d] timeout - dma=0x%08lx\n", core->name,		       buf, buf->vb.i, (unsigned long)buf->risc.dma);	}	restart_video_queue(dev,q);	spin_unlock_irqrestore(&dev->slock,flags);}static void cx8800_vid_irq(struct cx8800_dev *dev){	struct cx88_core *core = dev->core;	u32 status, mask, count;	status = cx_read(MO_VID_INTSTAT);	mask   = cx_read(MO_VID_INTMSK);	if (0 == (status & mask))		return;	cx_write(MO_VID_INTSTAT, status);	if (irq_debug  ||  (status & mask & ~0xff))		cx88_print_irqbits(core->name, "irq vid",				   cx88_vid_irqs, status, mask);	/* risc op code error */	if (status & (1 << 16)) {		printk(KERN_WARNING "%s/0: video risc op code error\n",core->name);		cx_clear(MO_VID_DMACNTRL, 0x11);		cx_clear(VID_CAPTURE_CONTROL, 0x06);		cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH21]);	}	/* risc1 y */	if (status & 0x01) {		spin_lock(&dev->slock);		count = cx_read(MO_VIDY_GPCNT);		cx88_wakeup(dev->core, &dev->vidq, count);		spin_unlock(&dev->slock);	}	/* risc1 vbi */	if (status & 0x08) {		spin_lock(&dev->slock);		count = cx_read(MO_VBI_GPCNT);		cx88_wakeup(dev->core, &dev->vbiq, count);		spin_unlock(&dev->slock);	}	/* risc2 y */	if (status & 0x10) {		dprintk(2,"stopper video\n");		spin_lock(&dev->slock);		restart_video_queue(dev,&dev->vidq);		spin_unlock(&dev->slock);	}	/* risc2 vbi */	if (status & 0x80) {		dprintk(2,"stopper vbi\n");		spin_lock(&dev->slock);		cx8800_restart_vbi_queue(dev,&dev->vbiq);		spin_unlock(&dev->slock);	}}static irqreturn_t cx8800_irq(int irq, void *dev_id, struct pt_regs *regs){	struct cx8800_dev *dev = dev_id;	struct cx88_core *core = dev->core;	u32 status, mask;	int loop, handled = 0;	for (loop = 0; loop < 10; loop++) {		status = cx_read(MO_PCI_INTSTAT) & (~0x1f | 0x01);		mask   = cx_read(MO_PCI_INTMSK);		if (0 == (status & mask))			goto out;		cx_write(MO_PCI_INTSTAT, status);		handled = 1;		if (status & mask & ~0x1f)			cx88_irq(core,status,mask);		if (status & 0x01)			cx8800_vid_irq(dev);	};	if (10 == loop) {		printk(KERN_WARNING "%s/0: irq loop -- clearing mask\n",		       core->name);		cx_write(MO_PCI_INTMSK,0);	} out:	return IRQ_RETVAL(handled);}/* ----------------------------------------------------------- *//* exported stuff                                              */static struct file_operations video_fops ={	.owner	       = THIS_MODULE,	.open	       = video_open,	.release       = video_release,	.read	       = video_read,	.poll          = video_poll,	.mmap	       = video_mmap,	.ioctl	       = video_ioctl,	.llseek        = no_llseek,};struct video_device cx8800_video_template ={	.name          = "cx8800-video",	.type          = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,	.hardware      = 0,	.fops          = &video_fops,	.minor         = -1,};struct video_device cx8800_vbi_template ={	.name          = "cx8800-vbi",	.type          = VID_TYPE_TELETEXT|VID_TYPE_TUNER,	.hardware      = 0,	.fops          = &video_fops,	.minor         = -1,};static struct file_operations radio_fops ={	.owner         = THIS_MODULE,	.open          = video_open,	.release       = video_release,	.ioctl         = radio_ioctl,	.llseek        = no_llseek,};struct video_device cx8800_radio_template ={	.name          = "cx8800-radio",	.type          = VID_TYPE_TUNER,	.hardware      = 0,	.fops          = &radio_fops,	.minor         = -1,};/* ----------------------------------------------------------- */static void cx8800_unregister_video(struct cx8800_dev *dev){	if (dev->radio_dev) {		if (-1 != dev->radio_dev->minor)			video_unregister_device(dev->radio_dev);		else			video_device_release(dev->radio_dev);		dev->radio_dev = NULL;	}	if (dev->vbi_dev) {		if (-1 != dev->vbi_dev->minor)			video_unregister_device(dev->vbi_dev);		else			video_device_release(dev->vbi_dev);		dev->vbi_dev = NULL;	}	if (dev->video_dev) {		if (-1 != dev->video_dev->minor)			video_unregister_device(dev->video_dev);		else			video_device_release(dev->video_dev);		dev->video_dev = NULL;	}}static int __devinit cx8800_initdev(struct pci_dev *pci_dev,				    const struct pci_device_id *pci_id){	struct cx8800_dev *dev;	struct cx88_core *core;	int err;	dev = kmalloc(sizeof(*dev),GFP_KERNEL);	if (NULL == dev)		return -ENOMEM;	memset(dev,0,sizeof(*dev));	/* pci init */	dev->pci = pci_dev;	if (pci_enable_device(pci_dev)) {		err = -EIO;		goto fail_free;	}	core = cx88_core_get(dev->pci);	if (NULL == core) {		err = -EINVAL;		goto fail_free;	}	dev->core = core;	/* print pci info */	pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);        pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER,  &dev->pci_lat);        printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "	       "latency: %d, mmio: 0x%lx\n", core->name,	       pci_name(pci_dev), dev->pci_rev, pci_dev->irq,	       dev->pci_lat,pci_resource_start(pci_dev,0));	pci_set_master(pci_dev);	if (!pci_dma_supported(pci_dev,0xffffffff)) {		printk("%s/0: Oops: no 32bit PCI DMA ???\n",core->name);		err = -EIO;		goto fail_core;	}	/* initialize driver struct */        init_MUTEX(&dev->lock);	spin_lock_init(&dev->slock);	core->tvnorm = tvnorms;	/* init video dma queues */	INIT_LIST_HEAD(&dev->vidq.active);	INIT_LIST_HEAD(&dev->vidq.queued);	dev->vidq.timeout.function = cx8800_vid_timeout;	dev->vidq.timeout.data     = (unsigned long)dev;	init_timer(&dev->vidq.timeout);	cx88_risc_stopper(dev->pci,&dev->vidq.stopper,			  MO_VID_DMACNTRL,0x11,0x00);	/* init vbi dma queues */	INIT_LIST_HEAD(&dev->vbiq.active);	INIT_LIST_HEAD(&dev->vbiq.queued);	dev->vbiq.timeout.function = cx8800_vbi_timeout;	dev->vbiq.timeout.data     = (unsigned long)dev;	init_timer(&dev->vbiq.timeout);	cx88_risc_stopper(dev->pci,&dev->vbiq.stopper,			  MO_VID_DMACNTRL,0x88,0x00);	/* get irq */	err = request_irq(pci_dev->irq, cx8800_irq,			  SA_SHIRQ | SA_INTERRUPT, core->name, dev);	if (err < 0) {		printk(KERN_ERR "%s: can't get IRQ %d\n",		       core->name,pci_dev->irq);		goto fail_core;	}	/* load and configure helper modules */	if (TUNER_ABSENT != core->tuner_type)		request_module("tuner");	if (core->tda9887_conf)		request_module("tda9887");	if (core->tuner_type != UNSET)		cx88_call_i2c_clients(dev->core,TUNER_SET_TYPE,&core->tuner_type);	if (core->tda9887_conf)		cx88_call_i2c_clients(dev->core,TDA9887_SET_CONFIG,&core->tda9887_conf);	/* register v4l devices */	dev->video_dev = cx88_vdev_init(core,dev->pci,					&cx8800_video_template,"video");	err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,				    video_nr[core->nr]);	if (err < 0) {		printk(KERN_INFO "%s: can't register video device\n",		       core->name);		goto fail_unreg;	}	printk(KERN_INFO "%s/0: registered device video%d [v4l2]\n",	       core->name,dev->video_dev->minor & 0x1f);	dev->vbi_dev = cx88_vdev_init(core,dev->pci,&cx8800_vbi_template,"vbi");	err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,				    vbi_nr[core->nr]);	if (err < 0) {		printk(KERN_INFO "%s/0: can't register vbi device\n",		       core->name);		goto fail_unreg;	}	printk(KERN_INFO "%s/0: registered device vbi%d\n",	       core->name,dev->vbi_dev->minor & 0x1f);	if (core->has_radio) {		dev->radio_dev = cx88_vdev_init(core,dev->pci,						&cx8800_radio_template,"radio");		err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,					    radio_nr[core->nr]);		if (err < 0) {			printk(KERN_INFO "%s/0: can't register radio device\n",			       core->name);			goto fail_unreg;		}		printk(KERN_INFO "%s/0: registered device radio%d\n",		       core->name,dev->radio_dev->minor & 0x1f);	}	/* everything worked */	list_add_tail(&dev->devlist,&cx8800_devlist);	pci_set_drvdata(pci_dev,dev);	/* initial device configuration */	down(&dev->lock);	init_controls(dev);	cx88_set_tvnorm(dev->core,tvnorms);	video_mux(dev,0);	up(&dev->lock);	/* start tvaudio thread */	if (core->tuner_type != TUNER_ABSENT)		core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");	return 0;fail_unreg:	cx8800_unregister_video(dev);	free_irq(pci_dev->irq, dev);fail_core:	cx88_core_put(core,dev->pci);fail_free:	kfree(dev);	return err;}static void __devexit cx8800_finidev(struct pci_dev *pci_dev){        struct cx8800_dev *dev = pci_get_drvdata(pci_dev);	/* stop thread */	if (dev->core->kthread) {		kthread_stop(dev->core->kthread);		dev->core->kthread = NULL;	}	cx88_shutdown(dev->core); /* FIXME */	pci_disable_device(pci_dev);	/* unregister stuff */	free_irq(pci_dev->irq, dev);	cx8800_unregister_video(dev);	pci_set_drvdata(pci_dev, NULL);	/* free memory */	btcx_riscmem_free(dev->pci,&dev->vidq.stopper);	list_del(&dev->devlist);	cx88_core_put(dev->core,dev->pci);	kfree(dev);}static int cx8800_suspend(struct pci_dev *pci_dev, u32 state){        struct cx8800_dev *dev = pci_get_drvdata(pci_dev);	struct cx88_core *core = dev->core;	/* stop video+vbi capture */	spin_lock(&dev->slock);	if (!list_empty(&dev->vidq.active)) {		printk("%s: suspend video\n", core->name);		stop_video_dma(dev);		del_timer(&dev->vidq.timeout);	}	if (!list_empty(&dev->vbiq.active)) {		printk("%s: suspend vbi\n", core->name);		cx8800_stop_vbi_dma(dev);		del_timer(&dev->vbiq.timeout);	}	spin_unlock(&dev->slock);#if 1	/* FIXME -- shutdown device */	cx88_shutdown(dev->core);#endif	pci_save_state(pci_dev);	if (0 != pci_set_power_state(pci_dev, state)) {		pci_disable_device(pci_dev);		dev->state.disabled = 1;	}	return 0;}static int cx8800_resume(struct pci_dev *pci_dev){        struct cx8800_dev *dev = pci_get_drvdata(pci_dev);	struct cx88_core *core = dev->core;	if (dev->state.disabled) {		pci_enable_device(pci_dev);		dev->state.disabled = 0;	}	pci_set_power_state(pci_dev, 0);	pci_restore_state(pci_dev);#if 1	/* FIXME: re-initialize hardware */	cx88_reset(dev->core);#endif	/* restart video+vbi capture */	spin_lock(&dev->slock);	if (!list_empty(&dev->vidq.active)) {		printk("%s: resume video\n", core->name);		restart_video_queue(dev,&dev->vidq);	}	if (!list_empty(&dev->vbiq.active)) {		printk("%s: resume vbi\n", core->name);		cx8800_restart_vbi_queue(dev,&dev->vbiq);	}	spin_unlock(&dev->slock);	return 0;}/* ----------------------------------------------------------- */struct pci_device_id cx8800_pci_tbl[] = {	{		.vendor       = 0x14f1,		.device       = 0x8800,                .subvendor    = PCI_ANY_ID,                .subdevice    = PCI_ANY_ID,	},{		/* --- end of list --- */	}};MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);static struct pci_driver cx8800_pci_driver = {        .name     = "cx8800",        .id_table = cx8800_pci_tbl,        .probe    = cx8800_initdev,        .remove   = __devexit_p(cx8800_finidev),	.suspend  = cx8800_suspend,	.resume   = cx8800_resume,};static int cx8800_init(void){	printk(KERN_INFO "cx2388x v4l2 driver version %d.%d.%d loaded\n",	       (CX88_VERSION_CODE >> 16) & 0xff,	       (CX88_VERSION_CODE >>  8) & 0xff,	       CX88_VERSION_CODE & 0xff);#ifdef SNAPSHOT	printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",	       SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);#endif	return pci_module_init(&cx8800_pci_driver);}static void cx8800_fini(void){	pci_unregister_driver(&cx8800_pci_driver);}module_init(cx8800_init);module_exit(cx8800_fini);/* ----------------------------------------------------------- *//* * Local variables: * c-basic-offset: 8 * End: */

⌨️ 快捷键说明

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