bttv-driver.c

来自「是关于linux2.5.1的完全源码」· C语言 代码 · 共 2,527 行 · 第 1/5 页

C
2,527
字号
/*    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/version.h>#include <linux/module.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 "bttvp.h"#include "tuner.h"/* 2.4 / 2.5 driver compatibility stuff */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 */#if defined(__sparc__) || defined(__powerpc__) || defined(__hppa__)static unsigned int bigendian=1;#elsestatic unsigned int bigendian=0;#endifstatic unsigned int radio[4];static unsigned int irq_debug = 0;static unsigned int gbuffers = 8;static unsigned int gbufsize = 0x208000;static unsigned int fdsr = 0;static unsigned int latency = -1;static int video_nr = -1;static int radio_nr = -1;static int vbi_nr = -1;/* 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;/* API features (turn on/off stuff for testing) */static unsigned int sloppy     = 0;static unsigned int mmap       = 1;#ifdef HAVE_V4L2static unsigned int v4l2       = 1;#endif/* insmod args */MODULE_PARM(radio,"1-4i");MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)");MODULE_PARM(bigendian,"i");MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian");MODULE_PARM(bttv_verbose,"i");MODULE_PARM_DESC(bttv_verbose,"verbose startup messages, default is 1 (yes)");MODULE_PARM(bttv_gpio,"i");MODULE_PARM_DESC(bttv_gpio,"log gpio changes, default is 0 (no)");MODULE_PARM(bttv_debug,"i");MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)");MODULE_PARM(irq_debug,"i");MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)");MODULE_PARM(gbuffers,"i");MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8");MODULE_PARM(gbufsize,"i");MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000");MODULE_PARM(fdsr,"i");MODULE_PARM(latency,"i");MODULE_PARM_DESC(latency,"pci latency timer");MODULE_PARM(video_nr,"i");MODULE_PARM(radio_nr,"i");MODULE_PARM(vbi_nr,"i");MODULE_PARM(combfilter,"i");MODULE_PARM(lumafilter,"i");MODULE_PARM(automute,"i");MODULE_PARM_DESC(automute,"mute audio on bad/missing video signal, default is 1 (yes)");MODULE_PARM(chroma_agc,"i");MODULE_PARM_DESC(chroma_agc,"enables the AGC of chroma signal, default is 0 (no)");MODULE_PARM(adc_crush,"i");MODULE_PARM_DESC(adc_crush,"enables the luminance ADC crush, default is 1 (yes)");MODULE_PARM(sloppy,"i");MODULE_PARM(mmap,"i");#ifdef HAVE_V4L2MODULE_PARM(v4l2,"i");#endifMODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");MODULE_LICENSE("GPL");/* kernel args */#ifndef MODULEstatic int __init p_radio(char *str) { return bttv_parse(str,BTTV_MAX,radio); }__setup("bttv.radio=", p_radio);#endif#ifndef HAVE_V4L2/* some dummy defines to avoid cluttering up the source code with   a huge number of ifdef's for V4L2 */# define V4L2_STD_PAL          -1# define V4L2_STD_NTSC         -1# define V4L2_STD_SECAM        -1# define V4L2_STD_PAL_60       -1# define V4L2_STD_PAL_M        -1# define V4L2_STD_PAL_N        -1# define V4L2_STD_NTSC_N       -1# define V4L2_PIX_FMT_GREY     -1# define V4L2_PIX_FMT_HI240    -1# define V4L2_PIX_FMT_RGB555   -1# define V4L2_PIX_FMT_RGB555X  -1# define V4L2_PIX_FMT_RGB565   -1# define V4L2_PIX_FMT_RGB565X  -1# define V4L2_PIX_FMT_BGR24    -1# define V4L2_PIX_FMT_BGR32    -1# define V4L2_PIX_FMT_RGB32    -1# define V4L2_PIX_FMT_YUYV     -1# define V4L2_PIX_FMT_UYVY     -1# define V4L2_PIX_FMT_YUV422P  -1# define V4L2_PIX_FMT_YUV420   -1# define V4L2_PIX_FMT_YVU420   -1# define V4L2_PIX_FMT_YUV411P  -1# define V4L2_PIX_FMT_YUV410   -1# define V4L2_PIX_FMT_YVU410   -1# define V4L2_BUF_TYPE_CAPTURE -1# define V4L2_BUF_TYPE_VBI     -1# define BTTV_APIS "[v4l]"#else# define BTTV_APIS "[v4l/v4l2]"#endif/* ----------------------------------------------------------------------- *//* static data                                                             */const struct bttv_tvnorm bttv_tvnorms[] = {	/* PAL-BDGHI */        { V4L2_STD_PAL, 35468950,          922, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_BDGHI|BT848_IFORM_XT1),          1135, 186, 922, 0x20, 255},	/* NTSC */	{ V4L2_STD_NTSC, 28636363,          754, 480,  910, 0x70, 0x5d, (BT848_IFORM_NTSC|BT848_IFORM_XT0),          910, 135, 754, 0x1a, 144},	/* SECAM */        { V4L2_STD_SECAM, 35468950,          922, 576, 1135, 0x7f, 0xa0, (BT848_IFORM_SECAM|BT848_IFORM_XT1),          1135, 186, 922, 0x20, 255},	/* these ones are bttv specific (for v4l1) */        /* PAL-NC */        { V4L2_STD_PAL_60, 28636363,          640, 576,  910, 0x7f, 0x72, (BT848_IFORM_PAL_NC|BT848_IFORM_XT0),          780, 130, 734, 0x1a, 144},	/* PAL-M */	{ V4L2_STD_PAL_M, 28636363,           640, 480, 910, 0x70, 0x5d, (BT848_IFORM_PAL_M|BT848_IFORM_XT0),	  780, 135, 754, 0x1a, 144},	/* PAL-N */	{ V4L2_STD_PAL_N, 35468950,           768, 576, 1135, 0x7f, 0x72, (BT848_IFORM_PAL_N|BT848_IFORM_XT0),	  944, 186, 922, 0x20, 144},	/* NTSC-Japan */	{ V4L2_STD_NTSC_N, 28636363,          640, 480,  910, 0x70, 0x5d, (BT848_IFORM_NTSC_J|BT848_IFORM_XT0),	  780, 135, 754, 0x16, 144},};const int BTTV_TVNORMS = (sizeof(bttv_tvnorms)/sizeof(struct bttv_tvnorm));/* ----------------------------------------------------------------------- *//* bttv format list   packed pixel formats must come first */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,	}};const int BTTV_FORMATS = (sizeof(bttv_formats)/sizeof(struct bttv_format));/* ----------------------------------------------------------------------- */#ifdef HAVE_V4L2#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_LASTP1      (V4L2_CID_PRIVATE_BASE + 5)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,		category:      V4L2_CTRL_CAT_VIDEO,		group:         "Video",	},{		id:            V4L2_CID_CONTRAST,		name:          "Contrast",		minimum:       0,		maximum:       65535,		step:          128,		default_value: 32768,		type:          V4L2_CTRL_TYPE_INTEGER,		category:      V4L2_CTRL_CAT_VIDEO,		group:         "Video",	},{		id:            V4L2_CID_SATURATION,		name:          "Saturation",		minimum:       0,		maximum:       65535,		step:          128,		default_value: 32768,		type:          V4L2_CTRL_TYPE_INTEGER,		category:      V4L2_CTRL_CAT_VIDEO,		group:         "Video",	},{		id:            V4L2_CID_HUE,		name:          "Hue",		minimum:       0,		maximum:       65535,		step:          256,		default_value: 32768,		type:          V4L2_CTRL_TYPE_INTEGER,		category:      V4L2_CTRL_CAT_VIDEO,		group:         "Video",	},	/* --- audio --- */	{		id:            V4L2_CID_AUDIO_MUTE,		name:          "Mute",		minimum:       0,		maximum:       1,		type:          V4L2_CTRL_TYPE_BOOLEAN,		category:      V4L2_CTRL_CAT_AUDIO,		group:         "Audio",	},{		id:            V4L2_CID_AUDIO_VOLUME,		name:          "Volume",		minimum:       0,		maximum:       65535,		step:          65535/100,		default_value: 65535,		type:          V4L2_CTRL_TYPE_INTEGER,		category:      V4L2_CTRL_CAT_AUDIO,		group:         "Audio",	},{		id:            V4L2_CID_AUDIO_BALANCE,		name:          "Balance",		minimum:       0,		maximum:       65535,		step:          65535/100,		default_value: 32768,		type:          V4L2_CTRL_TYPE_INTEGER,		category:      V4L2_CTRL_CAT_AUDIO,		group:         "Audio",	},{		id:            V4L2_CID_AUDIO_BASS,		name:          "Bass",		minimum:       0,		maximum:       65535,		step:          65535/100,		default_value: 32768,		type:          V4L2_CTRL_TYPE_INTEGER,		category:      V4L2_CTRL_CAT_AUDIO,		group:         "Audio",	},{		id:            V4L2_CID_AUDIO_TREBLE,		name:          "Treble",		minimum:       0,		maximum:       65535,		step:          65535/100,		default_value: 32768,		type:          V4L2_CTRL_TYPE_INTEGER,		category:      V4L2_CTRL_CAT_AUDIO,		group:         "Audio",	},	/* --- private --- */	{		id:            V4L2_CID_PRIVATE_CHROMA_AGC,		name:          "chroma agc",		minimum:       0,		maximum:       1,		type:          V4L2_CTRL_TYPE_BOOLEAN,		group:         "Private",	},{		id:            V4L2_CID_PRIVATE_COMBFILTER,		name:          "combfilter",		minimum:       0,		maximum:       1,		type:          V4L2_CTRL_TYPE_BOOLEAN,		group:         "Private",	},{		id:            V4L2_CID_PRIVATE_AUTOMUTE,		name:          "automute",		minimum:       0,		maximum:       1,		type:          V4L2_CTRL_TYPE_BOOLEAN,		group:         "Private",	},{		id:            V4L2_CID_PRIVATE_LUMAFILTER,		name:          "luma decimation filter",		minimum:       0,		maximum:       1,		type:          V4L2_CTRL_TYPE_BOOLEAN,		group:         "Private",	},{		id:            V4L2_CID_PRIVATE_AGC_CRUSH,		name:          "agc crush",		minimum:       0,		maximum:       1,		type:          V4L2_CTRL_TYPE_BOOLEAN,		group:         "Private",	}};const int BTTV_CTLS = (sizeof(bttv_ctls)/sizeof(struct v4l2_queryctrl));#endif /* HAVE_V4L2 */

⌨️ 快捷键说明

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