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

📄 saa7134-core.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * * device driver for philips saa7134 based TV cards * driver core * * (c) 2001-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] * *  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/config.h>#include <linux/init.h>#include <linux/list.h>#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/kernel.h>#include <linux/slab.h>#include <linux/kmod.h>#include <linux/sound.h>#include <linux/interrupt.h>#include <linux/delay.h>#include "saa7134-reg.h"#include "saa7134.h"MODULE_DESCRIPTION("v4l2 driver module for saa7130/34 based TV cards");MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");MODULE_LICENSE("GPL");/* ------------------------------------------------------------------ */static unsigned int irq_debug = 0;module_param(irq_debug, int, 0644);MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");static unsigned int core_debug = 0;module_param(core_debug, int, 0644);MODULE_PARM_DESC(core_debug,"enable debug messages [core]");static unsigned int gpio_tracking = 0;module_param(gpio_tracking, int, 0644);MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]");static unsigned int alsa = 0;module_param(alsa, int, 0644);MODULE_PARM_DESC(alsa,"enable ALSA DMA sound [dmasound]");static unsigned int oss = 0;module_param(oss, int, 0644);MODULE_PARM_DESC(oss,"enable OSS DMA sound [dmasound]");static unsigned int latency = UNSET;module_param(latency, int, 0444);MODULE_PARM_DESC(latency,"pci latency timer");static unsigned int video_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };static unsigned int vbi_nr[]   = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };static unsigned int radio_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };static unsigned int tuner[]    = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };static unsigned int card[]     = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };module_param_array(video_nr, int, NULL, 0444);module_param_array(vbi_nr,   int, NULL, 0444);module_param_array(radio_nr, int, NULL, 0444);module_param_array(tuner,    int, NULL, 0444);module_param_array(card,     int, NULL, 0444);MODULE_PARM_DESC(video_nr, "video device number");MODULE_PARM_DESC(vbi_nr,   "vbi device number");MODULE_PARM_DESC(radio_nr, "radio device number");MODULE_PARM_DESC(tuner,    "tuner type");MODULE_PARM_DESC(card,     "card type");static DECLARE_MUTEX(devlist_lock);LIST_HEAD(saa7134_devlist);static LIST_HEAD(mops_list);static unsigned int saa7134_devcount;int (*dmasound_init)(struct saa7134_dev *dev);int (*dmasound_exit)(struct saa7134_dev *dev);#define dprintk(fmt, arg...)	if (core_debug) \	printk(KERN_DEBUG "%s/core: " fmt, dev->name , ## arg)/* ------------------------------------------------------------------ *//* debug help functions                                               */static const char *v4l1_ioctls[] = {	"0", "GCAP", "GCHAN", "SCHAN", "GTUNER", "STUNER", "GPICT", "SPICT",	"CCAPTURE", "GWIN", "SWIN", "GFBUF", "SFBUF", "KEY", "GFREQ",	"SFREQ", "GAUDIO", "SAUDIO", "SYNC", "MCAPTURE", "GMBUF", "GUNIT",	"GCAPTURE", "SCAPTURE", "SPLAYMODE", "SWRITEMODE", "GPLAYINFO",	"SMICROCODE", "GVBIFMT", "SVBIFMT" };#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)static const char *v4l2_ioctls[] = {	"QUERYCAP", "1", "ENUM_PIXFMT", "ENUM_FBUFFMT", "G_FMT", "S_FMT",	"G_COMP", "S_COMP", "REQBUFS", "QUERYBUF", "G_FBUF", "S_FBUF",	"G_WIN", "S_WIN", "PREVIEW", "QBUF", "16", "DQBUF", "STREAMON",	"STREAMOFF", "G_PERF", "G_PARM", "S_PARM", "G_STD", "S_STD",	"ENUMSTD", "ENUMINPUT", "G_CTRL", "S_CTRL", "G_TUNER", "S_TUNER",	"G_FREQ", "S_FREQ", "G_AUDIO", "S_AUDIO", "35", "QUERYCTRL",	"QUERYMENU", "G_INPUT", "S_INPUT", "ENUMCVT", "41", "42", "43",	"44", "45",  "G_OUTPUT", "S_OUTPUT", "ENUMOUTPUT", "G_AUDOUT",	"S_AUDOUT", "ENUMFX", "G_EFFECT", "S_EFFECT", "G_MODULATOR",	"S_MODULATOR"};#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)static const char *osspcm_ioctls[] = {	"RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT",	"CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS",	"GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER",	"GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO",	"SETDUPLEX", "GETODELAY"};#define OSSPCM_IOCTLS ARRAY_SIZE(v4l2_ioctls)void saa7134_print_ioctl(char *name, unsigned int cmd){	char *dir;	switch (_IOC_DIR(cmd)) {	case _IOC_NONE:              dir = "--"; break;	case _IOC_READ:              dir = "r-"; break;	case _IOC_WRITE:             dir = "-w"; break;	case _IOC_READ | _IOC_WRITE: dir = "rw"; break;	default:                     dir = "??"; break;	}	switch (_IOC_TYPE(cmd)) {	case 'v':		printk(KERN_DEBUG "%s: ioctl 0x%08x (v4l1, %s, VIDIOC%s)\n",		       name, cmd, dir, (_IOC_NR(cmd) < V4L1_IOCTLS) ?		       v4l1_ioctls[_IOC_NR(cmd)] : "???");		break;	case 'V':		printk(KERN_DEBUG "%s: ioctl 0x%08x (v4l2, %s, VIDIOC_%s)\n",		       name, cmd, dir, (_IOC_NR(cmd) < V4L2_IOCTLS) ?		       v4l2_ioctls[_IOC_NR(cmd)] : "???");		break;	case 'P':		printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n",		       name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ?		       osspcm_ioctls[_IOC_NR(cmd)] : "???");		break;	case 'M':		printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n",		       name, cmd, dir, _IOC_NR(cmd));		break;	default:		printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",		       name, cmd, dir, _IOC_NR(cmd));	}}void saa7134_track_gpio(struct saa7134_dev *dev, char *msg){	unsigned long mode,status;	if (!gpio_tracking)		return;	/* rising SAA7134_GPIO_GPRESCAN reads the status */	saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,0);	saa_andorb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN,SAA7134_GPIO_GPRESCAN);	mode   = saa_readl(SAA7134_GPIO_GPMODE0   >> 2) & 0xfffffff;	status = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & 0xfffffff;	printk(KERN_DEBUG	       "%s: gpio: mode=0x%07lx in=0x%07lx out=0x%07lx [%s]\n",	       dev->name, mode, (~mode) & status, mode & status, msg);}/* ------------------------------------------------------------------ *//* ----------------------------------------------------------- *//* delayed request_module                                      */#if defined(CONFIG_MODULES) && defined(MODULE)static int need_empress;static int need_dvb;static int need_alsa;static int need_oss;static int pending_call(struct notifier_block *self, unsigned long state,			void *module){	if (module != THIS_MODULE || state != MODULE_STATE_LIVE)		return NOTIFY_DONE;	if (need_empress)		request_module("saa7134-empress");	if (need_dvb)		request_module("saa7134-dvb");	if (need_alsa)		request_module("saa7134-alsa");	if (need_oss)		request_module("saa7134-oss");	return NOTIFY_DONE;}static int pending_registered;static struct notifier_block pending_notifier = {	.notifier_call = pending_call,};static void request_module_depend(char *name, int *flag){	int err;	switch (THIS_MODULE->state) {	case MODULE_STATE_COMING:		if (!pending_registered) {			err = register_module_notifier(&pending_notifier);			pending_registered = 1;		}		*flag = 1;		break;	case MODULE_STATE_LIVE:		request_module(name);		break;	default:		/* nothing */;		break;	}}#else#define request_module_depend(name,flag)#endif /* CONFIG_MODULES *//* ------------------------------------------------------------------ *//* nr of (saa7134-)pages for the given buffer size */static int saa7134_buffer_pages(int size){	size  = PAGE_ALIGN(size);	size += PAGE_SIZE; /* for non-page-aligned buffers */	size /= 4096;	return size;}/* calc max # of buffers from size (must not exceed the 4MB virtual * address space per DMA channel) */int saa7134_buffer_count(unsigned int size, unsigned int count){	unsigned int maxcount;	maxcount = 1024 / saa7134_buffer_pages(size);	if (count > maxcount)		count = maxcount;	return count;}int saa7134_buffer_startpage(struct saa7134_buf *buf){	return saa7134_buffer_pages(buf->vb.bsize) * buf->vb.i;}unsigned long saa7134_buffer_base(struct saa7134_buf *buf){	unsigned long base;	base  = saa7134_buffer_startpage(buf) * 4096;	base += buf->vb.dma.sglist[0].offset;	return base;}/* ------------------------------------------------------------------ */int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt){	__le32       *cpu;	dma_addr_t   dma_addr;	cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr);	if (NULL == cpu)		return -ENOMEM;	pt->size = SAA7134_PGTABLE_SIZE;	pt->cpu  = cpu;	pt->dma  = dma_addr;	return 0;}int saa7134_pgtable_build(struct pci_dev *pci, struct saa7134_pgtable *pt,			  struct scatterlist *list, unsigned int length,			  unsigned int startpage){	__le32        *ptr;	unsigned int  i,p;	BUG_ON(NULL == pt || NULL == pt->cpu);	ptr = pt->cpu + startpage;	for (i = 0; i < length; i++, list++)		for (p = 0; p * 4096 < list->length; p++, ptr++)			*ptr = cpu_to_le32(sg_dma_address(list) - list->offset);	return 0;}void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt){	if (NULL == pt->cpu)		return;	pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);	pt->cpu = NULL;}/* ------------------------------------------------------------------ */void saa7134_dma_free(struct saa7134_dev *dev,struct saa7134_buf *buf){	if (in_interrupt())		BUG();	videobuf_waiton(&buf->vb,0,0);	videobuf_dma_pci_unmap(dev->pci, &buf->vb.dma);	videobuf_dma_free(&buf->vb.dma);	buf->vb.state = STATE_NEEDS_INIT;}/* ------------------------------------------------------------------ */int saa7134_buffer_queue(struct saa7134_dev *dev,			 struct saa7134_dmaqueue *q,			 struct saa7134_buf *buf){	struct saa7134_buf *next = NULL;	assert_spin_locked(&dev->slock);	dprintk("buffer_queue %p\n",buf);	if (NULL == q->curr) {		if (!q->need_two) {			q->curr = buf;			buf->activate(dev,buf,NULL);		} else if (list_empty(&q->queue)) {			list_add_tail(&buf->vb.queue,&q->queue);			buf->vb.state = STATE_QUEUED;		} else {			next = list_entry(q->queue.next,struct saa7134_buf,					  vb.queue);			q->curr = buf;			buf->activate(dev,buf,next);		}	} else {		list_add_tail(&buf->vb.queue,&q->queue);		buf->vb.state = STATE_QUEUED;	}	return 0;}void saa7134_buffer_finish(struct saa7134_dev *dev,			   struct saa7134_dmaqueue *q,			   unsigned int state){	assert_spin_locked(&dev->slock);	dprintk("buffer_finish %p\n",q->curr);	/* finish current buffer */	q->curr->vb.state = state;	do_gettimeofday(&q->curr->vb.ts);	wake_up(&q->curr->vb.done);	q->curr = NULL;}void saa7134_buffer_next(struct saa7134_dev *dev,			 struct saa7134_dmaqueue *q){	struct saa7134_buf *buf,*next = NULL;	assert_spin_locked(&dev->slock);	BUG_ON(NULL != q->curr);	if (!list_empty(&q->queue)) {		/* activate next one from queue */		buf = list_entry(q->queue.next,struct saa7134_buf,vb.queue);		dprintk("buffer_next %p [prev=%p/next=%p]\n",			buf,q->queue.prev,q->queue.next);		list_del(&buf->vb.queue);		if (!list_empty(&q->queue))			next = list_entry(q->queue.next,struct saa7134_buf,					  vb.queue);		q->curr = buf;		buf->activate(dev,buf,next);		dprintk("buffer_next #2 prev=%p/next=%p\n",			q->queue.prev,q->queue.next);	} else {		/* nothing to do -- just stop DMA */

⌨️ 快捷键说明

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