cx88-core.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 601 行 · 第 1/2 页

C
601
字号
/* * device driver for Conexant 2388x based TV cards * driver core * * (c) 2003 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/init.h>#include <linux/list.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/slab.h>#include <linux/kmod.h>#include <linux/sound.h>#include <linux/interrupt.h>#include <linux/pci.h>#include <linux/videodev.h>#include "cx88.h"MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");MODULE_LICENSE("GPL");/* ------------------------------------------------------------------ */#if 0static unsigned int gpio_tracking = 0;MODULE_PARM(gpio_tracking,"i");MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]");static unsigned int ts_nr = -1;MODULE_PARM(ts_nr,"i");MODULE_PARM_DESC(ts_nr,"ts device number");static unsigned int vbi_nr = -1;MODULE_PARM(vbi_nr,"i");MODULE_PARM_DESC(vbi_nr,"vbi device number");static unsigned int radio_nr = -1;MODULE_PARM(radio_nr,"i");MODULE_PARM_DESC(radio_nr,"radio device number");static unsigned int oss = 0;MODULE_PARM(oss,"i");MODULE_PARM_DESC(oss,"register oss devices (default: no)");static unsigned int dsp_nr = -1;MODULE_PARM(dsp_nr,"i");MODULE_PARM_DESC(dsp_nr,"oss dsp device number");static unsigned int mixer_nr = -1;MODULE_PARM(mixer_nr,"i");MODULE_PARM_DESC(mixer_nr,"oss mixer device number");#endifstatic unsigned int core_debug = 0;MODULE_PARM(core_debug,"i");MODULE_PARM_DESC(core_debug,"enable debug messages [core]");#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", "CGAP", "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)void cx88_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;	default:		printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n",		       name, cmd, dir, _IOC_NR(cmd));	}}/* ------------------------------------------------------------------ */static u32* cx88_risc_field(u32 *rp, struct scatterlist *sglist,			    unsigned int offset, u32 sync_line,			    unsigned int bpl, unsigned int padding,			    unsigned int lines){	struct scatterlist *sg;	unsigned int line,todo;	/* sync instruction */	*(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);		/* scan lines */	sg = sglist;	for (line = 0; line < lines; line++) {		while (offset && offset >= sg_dma_len(sg)) {			offset -= sg_dma_len(sg);			sg++;		}		if (bpl <= sg_dma_len(sg)-offset) {			/* fits into current chunk */                        *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl);                        *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);                        offset+=bpl;		} else {			/* scanline needs to be splitted */                        todo = bpl;                        *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|					    (sg_dma_len(sg)-offset));                        *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);                        todo -= (sg_dma_len(sg)-offset);                        offset = 0;                        sg++;                        while (todo > sg_dma_len(sg)) {                                *(rp++)=cpu_to_le32(RISC_WRITE|						    sg_dma_len(sg));                                *(rp++)=cpu_to_le32(sg_dma_address(sg));				todo -= sg_dma_len(sg);				sg++;			}                        *(rp++)=cpu_to_le32(RISC_WRITE|RISC_EOL|todo);			*(rp++)=cpu_to_le32(sg_dma_address(sg));			offset += todo;		}		offset += padding;	}	return rp;}int cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,		     struct scatterlist *sglist,		     unsigned int top_offset, unsigned int bottom_offset,		     unsigned int bpl, unsigned int padding, unsigned int lines){	u32 instructions,fields;	u32 *rp;	int rc;	fields = 0;	if (UNSET != top_offset)		fields++;	if (UNSET != bottom_offset)		fields++;	/* estimate risc mem: worst case is one write per page border +	   one write per scan line + syncs + jump (all 2 dwords) */	instructions  = (bpl * lines * fields) / PAGE_SIZE + lines * fields;	instructions += 3 + 4;	if ((rc = btcx_riscmem_alloc(pci,risc,instructions*8)) < 0)		return rc;	/* write risc instructions */	rp = risc->cpu;	if (UNSET != top_offset)		rp = cx88_risc_field(rp, sglist, top_offset, 0,				     bpl, padding, lines);	if (UNSET != bottom_offset)		rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200,				     bpl, padding, lines);	/* save pointer to jmp instruction address */	risc->jmp = rp;	return 0;}int cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,		      u32 reg, u32 mask, u32 value){	u32 *rp;	int rc;	if ((rc = btcx_riscmem_alloc(pci, risc, 4*16)) < 0)		return rc;	/* write risc instructions */	rp = risc->cpu;	*(rp++) = cpu_to_le32(RISC_WRITECR  | RISC_IRQ2 | RISC_IMM);	*(rp++) = cpu_to_le32(reg);	*(rp++) = cpu_to_le32(value);	*(rp++) = cpu_to_le32(mask);	*(rp++) = cpu_to_le32(RISC_JUMP);	*(rp++) = cpu_to_le32(risc->dma);	return 0;}voidcx88_free_buffer(struct pci_dev *pci, struct cx88_buffer *buf){	if (in_interrupt())		BUG();	videobuf_waiton(&buf->vb,0,0);	videobuf_dma_pci_unmap(pci, &buf->vb.dma);	videobuf_dma_free(&buf->vb.dma);	btcx_riscmem_free(pci, &buf->risc);	buf->vb.state = STATE_NEEDS_INIT;}/* ------------------------------------------------------------------ *//* our SRAM memory layout                                             *//* we are going to put all thr risc programs into host memory, so we * can use the whole SDRAM for the DMA fifos.  To simplify things, we * use a static memory layout.  That surely will waste memory in case * we don't use all DMA channels at the same time (which will be the * case most of the time).  But that still gives us enougth FIFO space * to be able to deal with insane long pci latencies ... * * FIFO space allocations: *    channel  21    (y video)  - 10.0k *    channel  24    (vbi)      -  4.0k *    channels 25+26 (audio)    -  0.5k *    everything else           -  2.0k *    TOTAL                     = 29.0k * * Every channel has 160 bytes control data (64 bytes instruction * queue and 6 CDT entries), which is close to 2k total. *  * Address layout: *    0x0000 - 0x03ff    CMDs / reserved *    0x0400 - 0x0bff    instruction queues + CDs *    0x0c00 -           FIFOs */struct sram_channel cx88_sram_channels[] = {	[SRAM_CH21] = {		.name       = "video y / packed",		.cmds_start = 0x180040,		.ctrl_start = 0x180400,	        .cdt        = 0x180400 + 64,		.fifo_start = 0x180c00,		.fifo_size  = 0x002800,		.ptr1_reg   = MO_DMA21_PTR1,		.ptr2_reg   = MO_DMA21_PTR2,		.cnt1_reg   = MO_DMA21_CNT1,		.cnt2_reg   = MO_DMA21_CNT2,	},	[SRAM_CH22] = {		.name       = "video u",		.cmds_start = 0x180080,		.ctrl_start = 0x1804a0,	        .cdt        = 0x1804a0 + 64,		.fifo_start = 0x183400,		.fifo_size  = 0x000800,		.ptr1_reg   = MO_DMA22_PTR1,		.ptr2_reg   = MO_DMA22_PTR2,		.cnt1_reg   = MO_DMA22_CNT1,		.cnt2_reg   = MO_DMA22_CNT2,	},	[SRAM_CH23] = {

⌨️ 快捷键说明

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