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

📄 av7110_v4l.c

📁 linux_dvb的驱动程序:linuxtv-dvb-1.1.1.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * av7110_v4l.c: av7110 video4linux interface for DVB and Siemens DVB-C analog module * * Copyright (C) 1999-2002 Ralph  Metzler *                       & Marcus Metzler for convergence integrated media GmbH * * originally based on code by: * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de> * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html * * the project's page is at http://www.linuxtv.org/dvb/ */#include <linux/kernel.h>#include <linux/sched.h>#include <linux/types.h>#include <linux/delay.h>#include <linux/fs.h>#include <linux/timer.h>#include <linux/poll.h>#include <linux/byteorder/swabb.h>#include <linux/smp_lock.h>#define DEBUG_VARIABLE av7110_debugextern int av7110_debug;#include "dvb_i2c.h"#include "av7110.h"#include "av7110_hw.h"#include "av7110_av.h"#include "dvb_functions.h"int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val){	u8 msg[5] = { dev, reg >> 8, reg & 0xff, val >> 8 , val & 0xff };	struct dvb_i2c_bus *i2c = av7110->i2c_bus;	struct i2c_msg msgs = { .flags = 0, .addr = 0x40, .len = 5, .buf = msg };	if (i2c->xfer(i2c, &msgs, 1) != 1) {		printk("av7110(%d): %s(%u = %u) failed\n",		       av7110->dvb_adapter->num, __FUNCTION__, reg, val);		return -EIO;	}	return 0;}int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val){	u8 msg1[3] = { dev, reg >> 8, reg & 0xff };	u8 msg2[2];	struct dvb_i2c_bus *i2c = av7110->i2c_bus;	struct i2c_msg msgs[2] = {		{ .flags = 0,	     .addr = 0x40, .len = 3, .buf = msg1 },		{ .flags = I2C_M_RD, .addr = 0x40, .len = 2, .buf = msg2 }	};	if (i2c->xfer(i2c, msgs, 2) != 2) {		printk("av7110(%d): %s(%u) failed\n",		       av7110->dvb_adapter->num, __FUNCTION__, reg);		return -EIO;	}	*val = (msg2[0] << 8) | msg2[1];	return 0;}static struct v4l2_input inputs[2] = {	{		.index		= 0,		.name		= "DVB",		.type		= V4L2_INPUT_TYPE_CAMERA,		.audioset	= 1,		.tuner		= 0, /* ignored */		.std		= V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,		.status		= 0,	}, {		.index		= 1,		.name		= "Television",		.type		= V4L2_INPUT_TYPE_TUNER,		.audioset	= 2,		.tuner		= 0,		.std		= V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,		.status		= 0,	}};/* for Siemens DVB-C analog module: (taken from ves1820.c) */static int ves1820_writereg(struct saa7146_dev *dev, u8 reg, u8 data){	u8 addr = 0x09;	u8 buf[] = { 0x00, reg, data };	struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 3 };	DEB_EE(("av7710: dev: %p\n", dev));	if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1))		return -1;	return 0;}static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4]){	struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 };	DEB_EE(("av7710: dev: %p\n", dev));	if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1))		return -1;	return 0;}/** *   set up the downconverter frequency divisor for a *   reference clock comparision frequency of 62.5 kHz. */static int tuner_set_tv_freq(struct saa7146_dev *dev, u32 freq){	u32 div;	u8 config;	u8 buf[4];	DEB_EE(("av7710: freq: 0x%08x\n", freq));	/* magic number: 614. tuning with the frequency given by v4l2	   is always off by 614*62.5 = 38375 kHz...*/	div = freq + 614;	buf[0] = (div >> 8) & 0x7f;	buf[1] = div & 0xff;	buf[2] = 0x8e;	if (freq < (u32) (16 * 168.25))		config = 0xa0;	else if (freq < (u32) (16 * 447.25))		config = 0x90;	else		config = 0x30;	config &= ~0x02;	buf[3] = config;	return tuner_write(dev, 0x61, buf);}static struct saa7146_standard analog_standard[];static struct saa7146_standard dvb_standard[];static struct saa7146_standard standard[];static struct v4l2_audio msp3400_v4l2_audio = {	.index = 0,	.name = "Television",	.capability = V4L2_AUDCAP_STEREO};int av7110_dvb_c_switch(struct saa7146_fh *fh){	struct saa7146_dev *dev = fh->dev;	struct saa7146_vv *vv = dev->vv_data;	struct av7110 *av7110 = (struct av7110*)dev->ext_priv;	u16 adswitch;	u8 band = 0;	int source, sync;	struct saa7146_fh *ov_fh = NULL;	int restart_overlay = 0;	DEB_EE(("av7110: %p\n", av7110));	if (vv->ov_data != NULL) {		ov_fh = vv->ov_data->fh;		saa7146_stop_preview(ov_fh);		restart_overlay = 1;	}	if (0 != av7110->current_input) {		adswitch = 1;		band = 0x60; /* analog band */		source = SAA7146_HPS_SOURCE_PORT_B;		sync = SAA7146_HPS_SYNC_PORT_B;		memcpy(standard, analog_standard, sizeof(struct saa7146_standard) * 2);		printk("av7110: switching to analog TV\n");		msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0000); // loudspeaker source		msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0000); // headphone source		msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0000); // SCART 1 source		msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono		msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone		msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume	} else {		adswitch = 0;		band = 0x20; /* digital band */		source = SAA7146_HPS_SOURCE_PORT_A;		sync = SAA7146_HPS_SYNC_PORT_A;		memcpy(standard, dvb_standard, sizeof(struct saa7146_standard) * 2);		printk("av7110: switching DVB mode\n");		msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source		msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0220); // headphone source		msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0220); // SCART 1 source		msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono		msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone		msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x7f00); // SCART 1 volume	}	/* hmm, this does not do anything!? */	if (av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, adswitch))		printk("ADSwitch error\n");	if (ves1820_writereg(dev, 0x0f, band))		printk("setting band in demodulator failed.\n");	saa7146_set_hps_source_and_sync(dev, source, sync);	if (restart_overlay)		saa7146_start_preview(ov_fh);	return 0;}int av7110_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg){	struct saa7146_dev *dev = fh->dev;	struct av7110 *av7110 = (struct av7110*) dev->ext_priv;	DEB_EE(("saa7146_dev: %p\n", dev));	switch (cmd) {	case VIDIOC_G_TUNER:	{		struct v4l2_tuner *t = arg;		u16 stereo_det;		s8 stereo;		DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));		if (!av7110->has_analog_tuner || t->index != 0)			return -EINVAL;		memset(t, 0, sizeof(*t));		strcpy(t->name, "Television");		t->type = V4L2_TUNER_ANALOG_TV;		t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |			V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;		t->rangelow = 772;	/* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */		t->rangehigh = 13684;	/* 855.25 MHz / 62.5 kHz = 13684 */		/* FIXME: add the real signal strength here */		t->signal = 0xffff;		t->afc = 0;// FIXME: standard / stereo detection is still brokenmsp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det);printk("VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det);		msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det);		printk("VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det);		stereo = (s8)(stereo_det >> 8);		if (stereo > 0x10) {			/* stereo */			t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;			t->audmode = V4L2_TUNER_MODE_STEREO;		}		else if (stereo < -0x10) {			/* bilingual*/			t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;			t->audmode = V4L2_TUNER_MODE_LANG1;		}		else /* mono */			t->rxsubchans = V4L2_TUNER_SUB_MONO;		return 0;	}	case VIDIOC_S_TUNER:	{		struct v4l2_tuner *t = arg;		u16 fm_matrix, src;		DEB_EE(("VIDIOC_S_TUNER: %d\n", t->index));		if (!av7110->has_analog_tuner || av7110->current_input != 1)			return -EINVAL;		switch (t->audmode) {		case V4L2_TUNER_MODE_STEREO:			DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n"));			fm_matrix = 0x3001; // stereo			src = 0x0020;			break;		case V4L2_TUNER_MODE_LANG1:			DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n"));			fm_matrix = 0x3000; // mono			src = 0x0000;			break;		case V4L2_TUNER_MODE_LANG2:			DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n"));			fm_matrix = 0x3000; // mono			src = 0x0010;			break;		default: /* case V4L2_TUNER_MODE_MONO: {*/			DEB_D(("VIDIOC_S_TUNER: TDA9840_SET_MONO\n"));			fm_matrix = 0x3000; // mono			src = 0x0030;			break;		}		msp_writereg(av7110, MSP_WR_DSP, 0x000e, fm_matrix);		msp_writereg(av7110, MSP_WR_DSP, 0x0008, src);		msp_writereg(av7110, MSP_WR_DSP, 0x0009, src);		msp_writereg(av7110, MSP_WR_DSP, 0x000a, src);		return 0;	}	case VIDIOC_G_FREQUENCY:	{		struct v4l2_frequency *f = arg;		DEB_EE(("VIDIOC_G_FREQ: freq:0x%08x.\n", f->frequency));		if (!av7110->has_analog_tuner || av7110->current_input != 1)			return -EINVAL;		memset(f, 0, sizeof(*f));		f->type = V4L2_TUNER_ANALOG_TV;		f->frequency =	av7110->current_freq;		return 0;	}	case VIDIOC_S_FREQUENCY:	{		struct v4l2_frequency *f = arg;		DEB_EE(("VIDIOC_S_FREQUENCY: freq:0x%08x.\n", f->frequency));		if (!av7110->has_analog_tuner || av7110->current_input != 1)			return -EINVAL;		if (V4L2_TUNER_ANALOG_TV != f->type)			return -EINVAL;		msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0xffe0); // fast mute		msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0xffe0);		/* tune in desired frequency */		tuner_set_tv_freq(dev, f->frequency);		av7110->current_freq = f->frequency;		msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x003f); // start stereo detection		msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x0000);

⌨️ 快捷键说明

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