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

📄 bttv-driver.c

📁 h内核
💻 C
📖 第 1 页 / 共 5 页
字号:
/*    $Id: bttv-driver.c,v 1.34 2005/01/07 13:11:19 kraxel Exp $    bttv - Bt848 frame grabber driver    Copyright (C) 1996,97,98 Ralph  Metzler <rjkm@thp.uni-koeln.de>                           & Marcus Metzler <mocm@thp.uni-koeln.de>    (c) 1999-2002 Gerd Knorr <kraxel@bytesex.org>    some v4l2 code lines are taken from Justin's bttv2 driver which is    (c) 2000 Justin Schoeman <justin@suntiger.ee.up.ac.za>    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/module.h>#include <linux/moduleparam.h>#include <linux/delay.h>#include <linux/errno.h>#include <linux/fs.h>#include <linux/kernel.h>#include <linux/sched.h>#include <linux/interrupt.h>#include <linux/kdev_t.h>#include <asm/io.h>#include <asm/byteorder.h>#include "bttvp.h"unsigned int bttv_num;			/* number of Bt848s in use */struct bttv bttvs[BTTV_MAX];unsigned int bttv_debug = 0;unsigned int bttv_verbose = 1;unsigned int bttv_gpio = 0;/* config variables */#ifdef __BIG_ENDIANstatic unsigned int bigendian=1;#elsestatic unsigned int bigendian=0;#endifstatic unsigned int radio[BTTV_MAX];static unsigned int irq_debug = 0;static unsigned int gbuffers = 8;static unsigned int gbufsize = 0x208000;static int video_nr = -1;static int radio_nr = -1;static int vbi_nr = -1;static int debug_latency = 0;static unsigned int fdsr = 0;/* options */static unsigned int combfilter  = 0;static unsigned int lumafilter  = 0;static unsigned int automute    = 1;static unsigned int chroma_agc  = 0;static unsigned int adc_crush   = 1;static unsigned int whitecrush_upper = 0xCF;static unsigned int whitecrush_lower = 0x7F;static unsigned int vcr_hack    = 0;static unsigned int irq_iswitch = 0;/* API features (turn on/off stuff for testing) */static unsigned int v4l2        = 1;/* insmod args */module_param(bttv_verbose,      int, 0644);module_param(bttv_gpio,         int, 0644);module_param(bttv_debug,        int, 0644);module_param(irq_debug,         int, 0644);module_param(debug_latency,     int, 0644);module_param(fdsr,              int, 0444);module_param(video_nr,          int, 0444);module_param(radio_nr,          int, 0444);module_param(vbi_nr,            int, 0444);module_param(gbuffers,          int, 0444);module_param(gbufsize,          int, 0444);module_param(v4l2,              int, 0644);module_param(bigendian,         int, 0644);module_param(irq_iswitch,       int, 0644);module_param(combfilter,        int, 0444);module_param(lumafilter,        int, 0444);module_param(automute,          int, 0444);module_param(chroma_agc,        int, 0444);module_param(adc_crush,         int, 0444);module_param(whitecrush_upper,  int, 0444);module_param(whitecrush_lower,  int, 0444);module_param(vcr_hack,          int, 0444);module_param_array(radio, int, NULL, 0444);MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)");MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian");MODULE_PARM_DESC(bttv_verbose,"verbose startup messages, default is 1 (yes)");MODULE_PARM_DESC(bttv_gpio,"log gpio changes, default is 0 (no)");MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)");MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)");MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8");MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000");MODULE_PARM_DESC(automute,"mute audio on bad/missing video signal, default is 1 (yes)");MODULE_PARM_DESC(chroma_agc,"enables the AGC of chroma signal, default is 0 (no)");MODULE_PARM_DESC(adc_crush,"enables the luminance ADC crush, default is 1 (yes)");MODULE_PARM_DESC(whitecrush_upper,"sets the white crush upper value, default is 207");MODULE_PARM_DESC(whitecrush_lower,"sets the white crush lower value, default is 127");MODULE_PARM_DESC(vcr_hack,"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)");MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler");MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");MODULE_LICENSE("GPL");/* ----------------------------------------------------------------------- *//* sysfs                                                                   */static ssize_t show_card(struct class_device *cd, char *buf){	struct video_device *vfd = to_video_device(cd);	struct bttv *btv = dev_get_drvdata(vfd->dev);	return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);}static CLASS_DEVICE_ATTR(card, S_IRUGO, show_card, NULL);/* ----------------------------------------------------------------------- *//* static data                                                             *//* special timing tables from conexant... */static u8 SRAM_Table[][60] ={	/* PAL digital input over GPIO[7:0] */	{		45, // 45 bytes following		0x36,0x11,0x01,0x00,0x90,0x02,0x05,0x10,0x04,0x16,		0x12,0x05,0x11,0x00,0x04,0x12,0xC0,0x00,0x31,0x00,		0x06,0x51,0x08,0x03,0x89,0x08,0x07,0xC0,0x44,0x00,		0x81,0x01,0x01,0xA9,0x0D,0x02,0x02,0x50,0x03,0x37,		0x37,0x00,0xAF,0x21,0x00	},	/* NTSC digital input over GPIO[7:0] */	{		51, // 51 bytes following		0x0C,0xC0,0x00,0x00,0x90,0x02,0x03,0x10,0x03,0x06,		0x10,0x04,0x12,0x12,0x05,0x02,0x13,0x04,0x19,0x00,		0x04,0x39,0x00,0x06,0x59,0x08,0x03,0x83,0x08,0x07,		0x03,0x50,0x00,0xC0,0x40,0x00,0x86,0x01,0x01,0xA6,		0x0D,0x02,0x03,0x11,0x01,0x05,0x37,0x00,0xAC,0x21,		0x00,	},	// TGB_NTSC392 // quartzsight	// This table has been modified to be used for Fusion Rev D	{		0x2A, // size of table = 42		0x06, 0x08, 0x04, 0x0a, 0xc0, 0x00, 0x18, 0x08, 0x03, 0x24,		0x08, 0x07, 0x02, 0x90, 0x02, 0x08, 0x10, 0x04, 0x0c, 0x10,		0x05, 0x2c, 0x11, 0x04, 0x55, 0x48, 0x00, 0x05, 0x50, 0x00,		0xbf, 0x0c, 0x02, 0x2f, 0x3d, 0x00, 0x2f, 0x3f, 0x00, 0xc3,		0x20, 0x00	}};const struct bttv_tvnorm bttv_tvnorms[] = {	/* PAL-BDGHI */        /* max. active video is actually 922, but 924 is divisible by 4 and 3! */ 	/* actually, max active PAL with HSCALE=0 is 948, NTSC is 768 - nil */	{		.v4l2_id        = V4L2_STD_PAL,		.name           = "PAL",		.Fsc            = 35468950,		.swidth         = 924,		.sheight        = 576,		.totalwidth     = 1135,		.adelay         = 0x7f,		.bdelay         = 0x72,		.iform          = (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1),		.scaledtwidth   = 1135,		.hdelayx1       = 186,		.hactivex1      = 924,		.vdelay         = 0x20,		.vbipack        = 255,		.sram           = 0,	},{		.v4l2_id        = V4L2_STD_NTSC_M,		.name           = "NTSC",		.Fsc            = 28636363,		.swidth         = 768,		.sheight        = 480,		.totalwidth     = 910,		.adelay         = 0x68,		.bdelay         = 0x5d,		.iform          = (BT848_IFORM_NTSC|BT848_IFORM_XT0),		.scaledtwidth   = 910,		.hdelayx1       = 128,		.hactivex1      = 910,		.vdelay         = 0x1a,		.vbipack        = 144,		.sram           = 1,	},{		.v4l2_id        = V4L2_STD_SECAM,		.name           = "SECAM",		.Fsc            = 35468950,		.swidth         = 924,		.sheight        = 576,		.totalwidth     = 1135,		.adelay         = 0x7f,		.bdelay         = 0xb0,		.iform          = (BT848_IFORM_SECAM|BT848_IFORM_XT1),		.scaledtwidth   = 1135,		.hdelayx1       = 186,		.hactivex1      = 922,		.vdelay         = 0x20,		.vbipack        = 255,		.sram           = 0, /* like PAL, correct? */	},{		.v4l2_id        = V4L2_STD_PAL_Nc,		.name           = "PAL-Nc",		.Fsc            = 28636363,		.swidth         = 640,		.sheight        = 576,		.totalwidth     = 910,		.adelay         = 0x68,		.bdelay         = 0x5d,		.iform          = (BT848_IFORM_PAL_NC|BT848_IFORM_XT0),		.scaledtwidth   = 780,		.hdelayx1       = 130,		.hactivex1      = 734,		.vdelay         = 0x1a,		.vbipack        = 144,		.sram           = -1,	},{		.v4l2_id        = V4L2_STD_PAL_M,		.name           = "PAL-M",		.Fsc            = 28636363,		.swidth         = 640,		.sheight        = 480,		.totalwidth     = 910,		.adelay         = 0x68,		.bdelay         = 0x5d,		.iform          = (BT848_IFORM_PAL_M|BT848_IFORM_XT0),		.scaledtwidth   = 780,		.hdelayx1       = 135,		.hactivex1      = 754,		.vdelay         = 0x1a,		.vbipack        = 144,		.sram           = -1,	},{		.v4l2_id        = V4L2_STD_PAL_N,		.name           = "PAL-N",		.Fsc            = 35468950,		.swidth         = 768,		.sheight        = 576,		.totalwidth     = 1135,		.adelay         = 0x7f,		.bdelay         = 0x72,		.iform          = (BT848_IFORM_PAL_N|BT848_IFORM_XT1),		.scaledtwidth   = 944,		.hdelayx1       = 186,		.hactivex1      = 922,		.vdelay         = 0x20,		.vbipack        = 144,		.sram           = -1,	},{		.v4l2_id        = V4L2_STD_NTSC_M_JP,		.name           = "NTSC-JP",		.Fsc            = 28636363,		.swidth         = 640,		.sheight        = 480,		.totalwidth     = 910,		.adelay         = 0x68,		.bdelay         = 0x5d,		.iform          = (BT848_IFORM_NTSC_J|BT848_IFORM_XT0),		.scaledtwidth   = 780,		.hdelayx1       = 135,		.hactivex1      = 754,		.vdelay         = 0x16,		.vbipack        = 144,		.sram           = -1,	},{		/* that one hopefully works with the strange timing		 * which video recorders produce when playing a NTSC		 * tape on a PAL TV ... */		.v4l2_id        = V4L2_STD_PAL_60,		.name           = "PAL-60",		.Fsc            = 35468950,		.swidth         = 924,		.sheight        = 480,		.totalwidth     = 1135,		.adelay         = 0x7f,		.bdelay         = 0x72,		.iform          = (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1),		.scaledtwidth   = 1135,		.hdelayx1       = 186,		.hactivex1      = 924,		.vdelay         = 0x1a,		.vbipack        = 255,		.vtotal         = 524,		.sram           = -1,	}};static const unsigned int BTTV_TVNORMS = ARRAY_SIZE(bttv_tvnorms);/* ----------------------------------------------------------------------- *//* bttv format list   packed pixel formats must come first */static const struct bttv_format bttv_formats[] = {	{		.name     = "8 bpp, gray",		.palette  = VIDEO_PALETTE_GREY,		.fourcc   = V4L2_PIX_FMT_GREY,		.btformat = BT848_COLOR_FMT_Y8,		.depth    = 8,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "8 bpp, dithered color",		.palette  = VIDEO_PALETTE_HI240,		.fourcc   = V4L2_PIX_FMT_HI240,		.btformat = BT848_COLOR_FMT_RGB8,		.depth    = 8,		.flags    = FORMAT_FLAGS_PACKED | FORMAT_FLAGS_DITHER,	},{		.name     = "15 bpp RGB, le",		.palette  = VIDEO_PALETTE_RGB555,		.fourcc   = V4L2_PIX_FMT_RGB555,		.btformat = BT848_COLOR_FMT_RGB15,		.depth    = 16,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "15 bpp RGB, be",		.palette  = -1,		.fourcc   = V4L2_PIX_FMT_RGB555X,		.btformat = BT848_COLOR_FMT_RGB15,		.btswap   = 0x03, /* byteswap */		.depth    = 16,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "16 bpp RGB, le",		.palette  = VIDEO_PALETTE_RGB565,		.fourcc   = V4L2_PIX_FMT_RGB565,		.btformat = BT848_COLOR_FMT_RGB16,		.depth    = 16,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "16 bpp RGB, be",		.palette  = -1,		.fourcc   = V4L2_PIX_FMT_RGB565X,		.btformat = BT848_COLOR_FMT_RGB16,		.btswap   = 0x03, /* byteswap */		.depth    = 16,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "24 bpp RGB, le",		.palette  = VIDEO_PALETTE_RGB24,		.fourcc   = V4L2_PIX_FMT_BGR24,		.btformat = BT848_COLOR_FMT_RGB24,		.depth    = 24,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "32 bpp RGB, le",		.palette  = VIDEO_PALETTE_RGB32,		.fourcc   = V4L2_PIX_FMT_BGR32,		.btformat = BT848_COLOR_FMT_RGB32,		.depth    = 32,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "32 bpp RGB, be",		.palette  = -1,		.fourcc   = V4L2_PIX_FMT_RGB32,		.btformat = BT848_COLOR_FMT_RGB32,		.btswap   = 0x0f, /* byte+word swap */		.depth    = 32,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "4:2:2, packed, YUYV",		.palette  = VIDEO_PALETTE_YUV422,		.fourcc   = V4L2_PIX_FMT_YUYV,		.btformat = BT848_COLOR_FMT_YUY2,		.depth    = 16,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "4:2:2, packed, YUYV",		.palette  = VIDEO_PALETTE_YUYV,		.fourcc   = V4L2_PIX_FMT_YUYV,		.btformat = BT848_COLOR_FMT_YUY2,		.depth    = 16,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "4:2:2, packed, UYVY",		.palette  = VIDEO_PALETTE_UYVY,		.fourcc   = V4L2_PIX_FMT_UYVY,		.btformat = BT848_COLOR_FMT_YUY2,		.btswap   = 0x03, /* byteswap */		.depth    = 16,		.flags    = FORMAT_FLAGS_PACKED,	},{		.name     = "4:2:2, planar, Y-Cb-Cr",		.palette  = VIDEO_PALETTE_YUV422P,		.fourcc   = V4L2_PIX_FMT_YUV422P,		.btformat = BT848_COLOR_FMT_YCrCb422,		.depth    = 16,		.flags    = FORMAT_FLAGS_PLANAR,		.hshift   = 1,		.vshift   = 0,	},{		.name     = "4:2:0, planar, Y-Cb-Cr",		.palette  = VIDEO_PALETTE_YUV420P,		.fourcc   = V4L2_PIX_FMT_YUV420,		.btformat = BT848_COLOR_FMT_YCrCb422,		.depth    = 12,		.flags    = FORMAT_FLAGS_PLANAR,		.hshift   = 1,		.vshift   = 1,	},{		.name     = "4:2:0, planar, Y-Cr-Cb",		.palette  = -1,		.fourcc   = V4L2_PIX_FMT_YVU420,		.btformat = BT848_COLOR_FMT_YCrCb422,		.depth    = 12,		.flags    = FORMAT_FLAGS_PLANAR | FORMAT_FLAGS_CrCb,		.hshift   = 1,		.vshift   = 1,	},{		.name     = "4:1:1, planar, Y-Cb-Cr",		.palette  = VIDEO_PALETTE_YUV411P,		.fourcc   = V4L2_PIX_FMT_YUV411P,		.btformat = BT848_COLOR_FMT_YCrCb411,		.depth    = 12,		.flags    = FORMAT_FLAGS_PLANAR,		.hshift   = 2,		.vshift   = 0,	},{		.name     = "4:1:0, planar, Y-Cb-Cr",		.palette  = VIDEO_PALETTE_YUV410P,		.fourcc   = V4L2_PIX_FMT_YUV410,		.btformat = BT848_COLOR_FMT_YCrCb411,		.depth    = 9,		.flags    = FORMAT_FLAGS_PLANAR,		.hshift   = 2,		.vshift   = 2,	},{		.name     = "4:1:0, planar, Y-Cr-Cb",		.palette  = -1,		.fourcc   = V4L2_PIX_FMT_YVU410,		.btformat = BT848_COLOR_FMT_YCrCb411,		.depth    = 9,		.flags    = FORMAT_FLAGS_PLANAR | FORMAT_FLAGS_CrCb,		.hshift   = 2,		.vshift   = 2,	},{		.name     = "raw scanlines",		.palette  = VIDEO_PALETTE_RAW,		.fourcc   = -1,		.btformat = BT848_COLOR_FMT_RAW,		.depth    = 8,		.flags    = FORMAT_FLAGS_RAW,	}};static const unsigned int BTTV_FORMATS = ARRAY_SIZE(bttv_formats);/* ----------------------------------------------------------------------- */#define V4L2_CID_PRIVATE_CHROMA_AGC  (V4L2_CID_PRIVATE_BASE + 0)#define V4L2_CID_PRIVATE_COMBFILTER  (V4L2_CID_PRIVATE_BASE + 1)#define V4L2_CID_PRIVATE_AUTOMUTE    (V4L2_CID_PRIVATE_BASE + 2)#define V4L2_CID_PRIVATE_LUMAFILTER  (V4L2_CID_PRIVATE_BASE + 3)#define V4L2_CID_PRIVATE_AGC_CRUSH   (V4L2_CID_PRIVATE_BASE + 4)#define V4L2_CID_PRIVATE_VCR_HACK    (V4L2_CID_PRIVATE_BASE + 5)#define V4L2_CID_PRIVATE_WHITECRUSH_UPPER   (V4L2_CID_PRIVATE_BASE + 6)#define V4L2_CID_PRIVATE_WHITECRUSH_LOWER   (V4L2_CID_PRIVATE_BASE + 7)#define V4L2_CID_PRIVATE_LASTP1      (V4L2_CID_PRIVATE_BASE + 8)static const struct v4l2_queryctrl no_ctl = {	.name  = "42",	.flags = V4L2_CTRL_FLAG_DISABLED,};static const struct v4l2_queryctrl bttv_ctls[] = {	/* --- video --- */	{		.id            = V4L2_CID_BRIGHTNESS,		.name          = "Brightness",		.minimum       = 0,		.maximum       = 65535,		.step          = 256,		.default_value = 32768,		.type          = V4L2_CTRL_TYPE_INTEGER,	},{		.id            = V4L2_CID_CONTRAST,		.name          = "Contrast",		.minimum       = 0,		.maximum       = 65535,

⌨️ 快捷键说明

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