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

📄 saa7115.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
/* saa7115 - Philips SAA7114/SAA7115 video decoder driver * * Based on saa7114 driver by Maxim Yevtyushkin, which is based on * the saa7111 driver by Dave Perks. * * Copyright (C) 1998 Dave Perks <dperks@ibm.net> * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com> * * Slight changes for video timing and attachment output by * Wolfgang Scherr <scherr@net4you.net> * * Moved over to the linux >= 2.4.x i2c protocol (1/1/2003) * by Ronald Bultje <rbultje@ronald.bitfreak.net> * * Added saa7115 support by Kevin Thayer <nufan_wfk at yahoo.com> * (2/17/2003) * * VBI support (2004) and cleanups (2005) by Hans Verkuil <hverkuil@xs4all.nl> * * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. */#include <linux/kernel.h>#include <linux/module.h>#include <linux/slab.h>#include <linux/i2c.h>#include <linux/videodev2.h>#include <media/v4l2-common.h>MODULE_DESCRIPTION("Philips SAA7114/SAA7115 video decoder driver");MODULE_AUTHOR("Maxim Yevtyushkin, Kevin Thayer, Chris Kennedy, Hans Verkuil");MODULE_LICENSE("GPL");static int debug = 0;module_param(debug, int, 0644);MODULE_PARM_DESC(debug, "Debug level (0-1)");#define saa7115_dbg(fmt,arg...) \	do { \		if (debug) \			printk(KERN_INFO "%s debug %d-%04x: " fmt, client->driver->name, \			       i2c_adapter_id(client->adapter), client->addr , ## arg); \	} while (0)#define saa7115_err(fmt, arg...) do { \	printk(KERN_ERR "%s %d-%04x: " fmt, client->driver->name, \	       i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)#define saa7115_info(fmt, arg...) do { \	printk(KERN_INFO "%s %d-%04x: " fmt, client->driver->name, \	       i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)static unsigned short normal_i2c[] = { 0x42 >> 1, 0x40 >> 1, I2C_CLIENT_END };I2C_CLIENT_INSMOD;struct saa7115_state {	v4l2_std_id std;	int input;	int enable;	int bright;	int contrast;	int hue;	int sat;	enum v4l2_chip_ident ident;	enum v4l2_audio_clock_freq audclk_freq;};/* ----------------------------------------------------------------------- */static inline int saa7115_write(struct i2c_client *client, u8 reg, u8 value){	return i2c_smbus_write_byte_data(client, reg, value);}static int saa7115_writeregs(struct i2c_client *client, const unsigned char *regs){	unsigned char reg, data;	while (*regs != 0x00) {		reg = *(regs++);		data = *(regs++);		if (saa7115_write(client, reg, data) < 0)			return -1;	}	return 0;}static inline int saa7115_read(struct i2c_client *client, u8 reg){	return i2c_smbus_read_byte_data(client, reg);}/* ----------------------------------------------------------------------- *//* If a value differs from the Hauppauge driver values, then the comment starts with   'was 0xXX' to denote the Hauppauge value. Otherwise the value is identical to what the   Hauppauge driver sets. */static const unsigned char saa7115_init_auto_input[] = {	0x01, 0x48,		/* white peak control disabled */	0x03, 0x20,		/* was 0x30. 0x20: long vertical blanking */	0x04, 0x90,		/* analog gain set to 0 */	0x05, 0x90,		/* analog gain set to 0 */	0x06, 0xeb,		/* horiz sync begin = -21 */	0x07, 0xe0,		/* horiz sync stop = -17 */	0x0a, 0x80,		/* was 0x88. decoder brightness, 0x80 is itu standard */	0x0b, 0x44,		/* was 0x48. decoder contrast, 0x44 is itu standard */	0x0c, 0x40,		/* was 0x47. decoder saturation, 0x40 is itu standard */	0x0d, 0x00,		/* chrominance hue control */	0x0f, 0x00,		/* chrominance gain control: use automicatic mode */	0x10, 0x06,		/* chrominance/luminance control: active adaptive combfilter */	0x11, 0x00,		/* delay control */	0x12, 0x9d,		/* RTS0 output control: VGATE */	0x13, 0x80,		/* X-port output control: ITU656 standard mode, RTCO output enable RTCE */	0x14, 0x00,		/* analog/ADC/auto compatibility control */	0x18, 0x40,		/* raw data gain 0x00 = nominal */	0x19, 0x80,		/* raw data offset 0x80 = 0 LSB */	0x1a, 0x77,		/* color killer level control 0x77 = recommended */	0x1b, 0x42,		/* misc chroma control 0x42 = recommended */	0x1c, 0xa9,		/* combfilter control 0xA9 = recommended */	0x1d, 0x01,		/* combfilter control 0x01 = recommended */	0x88, 0xd0,		/* reset device */	0x88, 0xf0,		/* set device programmed, all in operational mode */	0x00, 0x00};static const unsigned char saa7115_cfg_reset_scaler[] = {	0x87, 0x00,		/* disable I-port output */	0x88, 0xd0,		/* reset scaler */	0x88, 0xf0,		/* activate scaler */	0x87, 0x01,		/* enable I-port output */	0x00, 0x00};/* ============== SAA7715 VIDEO templates =============  */static const unsigned char saa7115_cfg_60hz_fullres_x[] = {	0xcc, 0xd0,		/* hsize low (output), hor. output window size = 0x2d0 = 720 */	0xcd, 0x02,		/* hsize hi (output) */	/* Why not in 60hz-Land, too? */	0xd0, 0x01,		/* downscale = 1 */	0xd8, 0x00,		/* hor lum scaling 0x0400 = 1 */	0xd9, 0x04,	0xdc, 0x00,		/* hor chrom scaling 0x0200. must be hor lum scaling / 2 */	0xdd, 0x02,		/* H-scaling incr chroma */	0x00, 0x00};static const unsigned char saa7115_cfg_60hz_fullres_y[] = {	0xce, 0xf8,		/* vsize low (output), ver. output window size = 248 (but 60hz is 240?) */	0xcf, 0x00,		/* vsize hi (output) */	/* Why not in 60hz-Land, too? */	0xd5, 0x40,		/* Lum contrast, nominal value = 0x40 */	0xd6, 0x40,		/* Chroma satur. nominal value = 0x80 */	0xe0, 0x00,		/* V-scaling incr luma low */	0xe1, 0x04,		/* " hi */	0xe2, 0x00,		/* V-scaling incr chroma low */	0xe3, 0x04,		/* " hi */	0x00, 0x00};static const unsigned char saa7115_cfg_60hz_video[] = {	0x80, 0x00,		/* reset tasks */	0x88, 0xd0,		/* reset scaler */	0x15, 0x03,		/* VGATE pulse start */	0x16, 0x11,		/* VGATE pulse stop */	0x17, 0x9c,		/* VGATE MSB and other values */	0x08, 0x68,		/* 0xBO: auto detection, 0x68 = NTSC */	0x0e, 0x07,		/* lots of different stuff... video autodetection is on */	0x5a, 0x06,		/* Vertical offset, standard 60hz value for ITU656 line counting */	/* Task A */	0x90, 0x80,		/* Task Handling Control */	0x91, 0x48,		/* X-port formats/config */	0x92, 0x40,		/* Input Ref. signal Def. */	0x93, 0x84,		/* I-port config */	0x94, 0x01,		/* hoffset low (input), 0x0002 is minimum */	0x95, 0x00,		/* hoffset hi (input) */	0x96, 0xd0,		/* hsize low (input), 0x02d0 = 720 */	0x97, 0x02,		/* hsize hi (input) */	0x98, 0x05,		/* voffset low (input) */	0x99, 0x00,		/* voffset hi (input) */	0x9a, 0x0c,		/* vsize low (input), 0x0c = 12 */	0x9b, 0x00,		/* vsize hi (input) */	0x9c, 0xa0,		/* hsize low (output), 0x05a0 = 1440 */	0x9d, 0x05,		/* hsize hi (output) */	0x9e, 0x0c,		/* vsize low (output), 0x0c = 12 */	0x9f, 0x00,		/* vsize hi (output) */	/* Task B */	0xc0, 0x00,		/* Task Handling Control */	0xc1, 0x08,		/* X-port formats/config */	0xc2, 0x00,		/* Input Ref. signal Def. */	0xc3, 0x80,		/* I-port config */	0xc4, 0x02,		/* hoffset low (input), 0x0002 is minimum */	0xc5, 0x00,		/* hoffset hi (input) */	0xc6, 0xd0,		/* hsize low (input), 0x02d0 = 720 */	0xc7, 0x02,		/* hsize hi (input) */	0xc8, 0x12,		/* voffset low (input), 0x12 = 18 */	0xc9, 0x00,		/* voffset hi (input) */	0xca, 0xf8,		/* vsize low (input), 0xf8 = 248 */	0xcb, 0x00,		/* vsize hi (input) */	0xcc, 0xd0,		/* hsize low (output), 0x02d0 = 720 */	0xcd, 0x02,		/* hsize hi (output) */	0xf0, 0xad,		/* Set PLL Register. 60hz 525 lines per frame, 27 MHz */	0xf1, 0x05,		/* low bit with 0xF0 */	0xf5, 0xad,		/* Set pulse generator register */	0xf6, 0x01,	0x87, 0x00,		/* Disable I-port output */	0x88, 0xd0,		/* reset scaler */	0x80, 0x20,		/* Activate only task "B", continuous mode (was 0xA0) */	0x88, 0xf0,		/* activate scaler */	0x87, 0x01,		/* Enable I-port output */	0x00, 0x00};static const unsigned char saa7115_cfg_50hz_fullres_x[] = {	0xcc, 0xd0,		/* hsize low (output), 720 same as 60hz */	0xcd, 0x02,		/* hsize hi (output) */	0xd0, 0x01,		/* down scale = 1 */	0xd8, 0x00,		/* hor lum scaling 0x0400 = 1 */	0xd9, 0x04,	0xdc, 0x00,		/* hor chrom scaling 0x0200. must be hor lum scaling / 2 */	0xdd, 0x02,		/* H-scaling incr chroma */	0x00, 0x00};static const unsigned char saa7115_cfg_50hz_fullres_y[] = {	0xce, 0x20,		/* vsize low (output), 0x0120 = 288 */	0xcf, 0x01,		/* vsize hi (output) */	0xd5, 0x40,		/* Lum contrast, nominal value = 0x40 */	0xd6, 0x40,		/* Chroma satur. nominal value = 0x80 */	0xe0, 0x00,		/* V-scaling incr luma low */	0xe1, 0x04,		/* " hi */	0xe2, 0x00,		/* V-scaling incr chroma low */	0xe3, 0x04,		/* " hi */	0x00, 0x00};static const unsigned char saa7115_cfg_50hz_video[] = {	0x80, 0x00,		/* reset tasks */	0x88, 0xd0,		/* reset scaler */	0x15, 0x37,		/* VGATE start */	0x16, 0x16,		/* VGATE stop */	0x17, 0x99,		/* VGATE MSB and other values */	0x08, 0x28,		/* 0x28 = PAL */	0x0e, 0x07,		/* chrominance control 1 */	0x5a, 0x03,		/* Vertical offset, standard 50hz value */	/* Task A */	0x90, 0x81,		/* Task Handling Control */	0x91, 0x48,		/* X-port formats/config */	0x92, 0x40,		/* Input Ref. signal Def. */	0x93, 0x84,		/* I-port config */	/* This is weird: the datasheet says that you should use 2 as the minimum value, */	/* but Hauppauge uses 0, and changing that to 2 causes indeed problems (for 50hz) */	0x94, 0x00,		/* hoffset low (input), 0x0002 is minimum */	0x95, 0x00,		/* hoffset hi (input) */	0x96, 0xd0,		/* hsize low (input), 0x02d0 = 720 */	0x97, 0x02,		/* hsize hi (input) */	0x98, 0x03,		/* voffset low (input) */	0x99, 0x00,		/* voffset hi (input) */	0x9a, 0x12,		/* vsize low (input), 0x12 = 18 */	0x9b, 0x00,		/* vsize hi (input) */	0x9c, 0xa0,		/* hsize low (output), 0x05a0 = 1440 */	0x9d, 0x05,		/* hsize hi (output) */	0x9e, 0x12,		/* vsize low (output), 0x12 = 18 */	0x9f, 0x00,		/* vsize hi (output) */	/* Task B */	0xc0, 0x00,		/* Task Handling Control */	0xc1, 0x08,		/* X-port formats/config */	0xc2, 0x00,		/* Input Ref. signal Def. */	0xc3, 0x80,		/* I-port config */	0xc4, 0x00,		/* hoffset low (input), 0x0002 is minimum. See comment at 0x94 above. */	0xc5, 0x00,		/* hoffset hi (input) */	0xc6, 0xd0,		/* hsize low (input), 0x02d0 = 720 */	0xc7, 0x02,		/* hsize hi (input) */	0xc8, 0x16,		/* voffset low (input), 0x16 = 22 */	0xc9, 0x00,		/* voffset hi (input) */	0xca, 0x20,		/* vsize low (input), 0x0120 = 288 */	0xcb, 0x01,		/* vsize hi (input) */	0xcc, 0xd0,		/* hsize low (output), 0x02d0 = 720 */	0xcd, 0x02,		/* hsize hi (output) */	0xce, 0x20,		/* vsize low (output), 0x0120 = 288 */	0xcf, 0x01,		/* vsize hi (output) */	0xf0, 0xb0,		/* Set PLL Register. 50hz 625 lines per frame, 27 MHz */	0xf1, 0x05,		/* low bit with 0xF0, (was 0x05) */	0xf5, 0xb0,		/* Set pulse generator register */	0xf6, 0x01,	0x87, 0x00,		/* Disable I-port output */	0x88, 0xd0,		/* reset scaler (was 0xD0) */	0x80, 0x20,		/* Activate only task "B" */	0x88, 0xf0,		/* activate scaler */	0x87, 0x01,		/* Enable I-port output */	0x00, 0x00};/* ============== SAA7715 VIDEO templates (end) =======  */static const unsigned char saa7115_cfg_vbi_on[] = {	0x80, 0x00,		/* reset tasks */	0x88, 0xd0,		/* reset scaler */	0x80, 0x30,		/* Activate both tasks */	0x88, 0xf0,		/* activate scaler */	0x87, 0x01,		/* Enable I-port output */	0x00, 0x00};static const unsigned char saa7115_cfg_vbi_off[] = {	0x80, 0x00,		/* reset tasks */	0x88, 0xd0,		/* reset scaler */	0x80, 0x20,		/* Activate only task "B" */	0x88, 0xf0,		/* activate scaler */	0x87, 0x01,		/* Enable I-port output */	0x00, 0x00};static const unsigned char saa7115_init_misc[] = {	0x38, 0x03,		/* audio stuff */	0x39, 0x10,	0x3a, 0x08,	0x81, 0x01,		/* reg 0x15,0x16 define blanking window */	0x82, 0x00,	0x83, 0x01,		/* I port settings */	0x84, 0x20,	0x85, 0x21,	0x86, 0xc5,	0x87, 0x01,	/* Task A */	0xa0, 0x01,		/* down scale = 1 */	0xa1, 0x00,		/* prescale accumulation length = 1 */	0xa2, 0x00,		/* dc gain and fir prefilter control */	0xa4, 0x80,		/* Lum Brightness, nominal value = 0x80 */	0xa5, 0x40,		/* Lum contrast, nominal value = 0x40 */	0xa6, 0x40,		/* Chroma satur. nominal value = 0x80 */	0xa8, 0x00,		/* hor lum scaling 0x0200 = 2 zoom */	0xa9, 0x02,		/* note: 2 x zoom ensures that VBI lines have same length as video lines. */	0xaa, 0x00,		/* H-phase offset Luma = 0 */	0xac, 0x00,		/* hor chrom scaling 0x0200. must be hor lum scaling / 2 */	0xad, 0x01,		/* H-scaling incr chroma */	0xae, 0x00,		/* H-phase offset chroma. must be offset luma / 2 */	0xb0, 0x00,		/* V-scaling incr luma low */	0xb1, 0x04,		/* " hi */	0xb2, 0x00,		/* V-scaling incr chroma low */	0xb3, 0x04,		/* " hi */	0xb4, 0x01,		/* V-scaling mode control */	0xb8, 0x00,		/* V-phase offset chroma 00 */	0xb9, 0x00,		/* V-phase offset chroma 01 */	0xba, 0x00,		/* V-phase offset chroma 10 */	0xbb, 0x00,		/* V-phase offset chroma 11 */	0xbc, 0x00,		/* V-phase offset luma 00 */	0xbd, 0x00,		/* V-phase offset luma 01 */	0xbe, 0x00,		/* V-phase offset luma 10 */	0xbf, 0x00,		/* V-phase offset luma 11 */	/* Task B */	0xd0, 0x01,		/* down scale = 1 */	0xd1, 0x00,		/* prescale accumulation length = 1 */	0xd2, 0x00,		/* dc gain and fir prefilter control */	0xd4, 0x80,		/* Lum Brightness, nominal value = 0x80 */	0xd5, 0x40,		/* Lum contrast, nominal value = 0x40 */	0xd6, 0x40,		/* Chroma satur. nominal value = 0x80 */	0xd8, 0x00,		/* hor lum scaling 0x0400 = 1 */	0xd9, 0x04,	0xda, 0x00,		/* H-phase offset Luma = 0 */	0xdc, 0x00,		/* hor chrom scaling 0x0200. must be hor lum scaling / 2 */	0xdd, 0x02,		/* H-scaling incr chroma */	0xde, 0x00,		/* H-phase offset chroma. must be offset luma / 2 */	0xe0, 0x00,		/* V-scaling incr luma low */	0xe1, 0x04,		/* " hi */	0xe2, 0x00,		/* V-scaling incr chroma low */	0xe3, 0x04,		/* " hi */	0xe4, 0x01,		/* V-scaling mode control */	0xe8, 0x00,		/* V-phase offset chroma 00 */	0xe9, 0x00,		/* V-phase offset chroma 01 */	0xea, 0x00,		/* V-phase offset chroma 10 */	0xeb, 0x00,		/* V-phase offset chroma 11 */	0xec, 0x00,		/* V-phase offset luma 00 */	0xed, 0x00,		/* V-phase offset luma 01 */	0xee, 0x00,		/* V-phase offset luma 10 */	0xef, 0x00,		/* V-phase offset luma 11 */	0xf2, 0x50,		/* crystal clock = 24.576 MHz, target = 27MHz */	0xf3, 0x46,	0xf4, 0x00,	0xf7, 0x4b,		/* not the recommended settings! */	0xf8, 0x00,	0xf9, 0x4b,	0xfa, 0x00,	0xfb, 0x4b,	0xff, 0x88,		/* PLL2 lock detection settings: 71 lines 50% phase error */	/* Turn off VBI */	0x40, 0x20,             /* No framing code errors allowed. */	0x41, 0xff,	0x42, 0xff,	0x43, 0xff,	0x44, 0xff,	0x45, 0xff,	0x46, 0xff,	0x47, 0xff,	0x48, 0xff,	0x49, 0xff,	0x4a, 0xff,	0x4b, 0xff,	0x4c, 0xff,	0x4d, 0xff,	0x4e, 0xff,	0x4f, 0xff,	0x50, 0xff,	0x51, 0xff,	0x52, 0xff,	0x53, 0xff,	0x54, 0xff,	0x55, 0xff,	0x56, 0xff,	0x57, 0xff,	0x58, 0x40,	0x59, 0x47,	0x5b, 0x83,	0x5d, 0xbd,	0x5e, 0x35,

⌨️ 快捷键说明

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