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

📄 saa7134-dvb.c

📁 trident tm5600的linux驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] * *  Extended 3 / 2005 by Hartmut Hackmann to support various *  cards with the tda10046 DVB-T channel decoder * *  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/delay.h>#include <linux/kthread.h>#include <linux/suspend.h>#include "saa7134-reg.h"#include "saa7134.h"#include <media/v4l2-common.h>#include "dvb-pll.h"#include <dvb_frontend.h>#include "mt352.h"#include "mt352_priv.h" /* FIXME */#include "tda1004x.h"#include "nxt200x.h"#include "tuner-xc2028.h"#include "tda10086.h"#include "tda826x.h"#include "tda827x.h"#include "isl6421.h"#include "isl6405.h"#include "lnbp21.h"#include "tuner-simple.h"MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");MODULE_LICENSE("GPL");static unsigned int antenna_pwr;module_param(antenna_pwr, int, 0444);MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");static int use_frontend;module_param(use_frontend, int, 0644);MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");static int debug;module_param(debug, int, 0644);MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);#define dprintk(fmt, arg...)	do { if (debug) \	printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)/* Print a warning */#define wprintk(fmt, arg...) \	printk(KERN_WARNING "%s/dvb: " fmt, dev->name, ## arg)/* ------------------------------------------------------------------ * mt352 based DVB-T cards */static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on){	u32 ok;	if (!on) {		saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));		saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));		return 0;	}	saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 26));	saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));	udelay(10);	saa_setl(SAA7134_GPIO_GPMODE0 >> 2,     (1 << 28));	saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));	udelay(10);	saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 28));	udelay(10);	ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);	dprintk("%s %s\n", __func__, ok ? "on" : "off");	if (!ok)		saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2,   (1 << 26));	return ok;}static int mt352_pinnacle_init(struct dvb_frontend* fe){	static u8 clock_config []  = { CLOCK_CTL,  0x3d, 0x28 };	static u8 reset []         = { RESET,      0x80 };	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };	static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x31 };	static u8 fsm_ctl_cfg[]    = { 0x7b,       0x04 };	static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x0f };	static u8 scan_ctl_cfg []  = { SCAN_CTL,   0x0d };	static u8 irq_cfg []       = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };	struct saa7134_dev *dev= fe->dvb->priv;	dprintk("%s called\n", __func__);	mt352_write(fe, clock_config,   sizeof(clock_config));	udelay(200);	mt352_write(fe, reset,          sizeof(reset));	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));	mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));	mt352_write(fe, fsm_ctl_cfg,    sizeof(fsm_ctl_cfg));	mt352_write(fe, scan_ctl_cfg,   sizeof(scan_ctl_cfg));	mt352_write(fe, irq_cfg,        sizeof(irq_cfg));	return 0;}static int mt352_aver777_init(struct dvb_frontend* fe){	static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x2d };	static u8 reset []         = { RESET,      0x80 };	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };	static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0xa0 };	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };	mt352_write(fe, clock_config,   sizeof(clock_config));	udelay(200);	mt352_write(fe, reset,          sizeof(reset));	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));	return 0;}static int mt352_avermedia_xc3028_init(struct dvb_frontend *fe){	static u8 clock_config []  = { CLOCK_CTL, 0x38, 0x2d };	static u8 reset []         = { RESET, 0x80 };	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };	static u8 agc_cfg []       = { AGC_TARGET, 0xe };	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };	mt352_write(fe, clock_config,   sizeof(clock_config));	udelay(200);	mt352_write(fe, reset,          sizeof(reset));	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));	return 0;}static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,					   struct dvb_frontend_parameters* params){	u8 off[] = { 0x00, 0xf1};	u8 on[]  = { 0x00, 0x71};	struct i2c_msg msg = {.addr=0x43, .flags=0, .buf=off, .len = sizeof(off)};	struct saa7134_dev *dev = fe->dvb->priv;	struct v4l2_frequency f;	/* set frequency (mt2050) */	f.tuner     = 0;	f.type      = V4L2_TUNER_DIGITAL_TV;	f.frequency = params->frequency / 1000 * 16 / 1000;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(&dev->i2c_adap, &msg, 1);	saa7134_i2c_call_clients(dev,VIDIOC_S_FREQUENCY,&f);	msg.buf = on;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(&dev->i2c_adap, &msg, 1);	pinnacle_antenna_pwr(dev, antenna_pwr);	/* mt352 setup */	return mt352_pinnacle_init(fe);}static struct mt352_config pinnacle_300i = {	.demod_address = 0x3c >> 1,	.adc_clock     = 20333,	.if2           = 36150,	.no_tuner      = 1,	.demod_init    = mt352_pinnacle_init,};static struct mt352_config avermedia_777 = {	.demod_address = 0xf,	.demod_init    = mt352_aver777_init,};static struct mt352_config avermedia_xc3028_mt352_dev = {	.demod_address   = (0x1e >> 1),	.no_tuner        = 1,	.demod_init      = mt352_avermedia_xc3028_init,};/* ================================================================== * tda1004x based DVB-T cards, helper functions */static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,					   const struct firmware **fw, char *name){	struct saa7134_dev *dev = fe->dvb->priv;	return request_firmware(fw, name, &dev->pci->dev);}/* ------------------------------------------------------------------ * these tuners are tu1216, td1316(a) */static int philips_tda6651_pll_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params){	struct saa7134_dev *dev = fe->dvb->priv;	struct tda1004x_state *state = fe->demodulator_priv;	u8 addr = state->config->tuner_address;	u8 tuner_buf[4];	struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tuner_buf,.len =			sizeof(tuner_buf) };	int tuner_frequency = 0;	u8 band, cp, filter;	/* determine charge pump */	tuner_frequency = params->frequency + 36166000;	if (tuner_frequency < 87000000)		return -EINVAL;	else if (tuner_frequency < 130000000)		cp = 3;	else if (tuner_frequency < 160000000)		cp = 5;	else if (tuner_frequency < 200000000)		cp = 6;	else if (tuner_frequency < 290000000)		cp = 3;	else if (tuner_frequency < 420000000)		cp = 5;	else if (tuner_frequency < 480000000)		cp = 6;	else if (tuner_frequency < 620000000)		cp = 3;	else if (tuner_frequency < 830000000)		cp = 5;	else if (tuner_frequency < 895000000)		cp = 7;	else		return -EINVAL;	/* determine band */	if (params->frequency < 49000000)		return -EINVAL;	else if (params->frequency < 161000000)		band = 1;	else if (params->frequency < 444000000)		band = 2;	else if (params->frequency < 861000000)		band = 4;	else		return -EINVAL;	/* setup PLL filter */	switch (params->u.ofdm.bandwidth) {	case BANDWIDTH_6_MHZ:		filter = 0;		break;	case BANDWIDTH_7_MHZ:		filter = 0;		break;	case BANDWIDTH_8_MHZ:		filter = 1;		break;	default:		return -EINVAL;	}	/* calculate divisor	 * ((36166000+((1000000/6)/2)) + Finput)/(1000000/6)	 */	tuner_frequency = (((params->frequency / 1000) * 6) + 217496) / 1000;	/* setup tuner buffer */	tuner_buf[0] = (tuner_frequency >> 8) & 0x7f;	tuner_buf[1] = tuner_frequency & 0xff;	tuner_buf[2] = 0xca;	tuner_buf[3] = (cp << 5) | (filter << 3) | band;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1) {		wprintk("could not write to tuner at addr: 0x%02x\n",			addr << 1);		return -EIO;	}	msleep(1);	return 0;}static int philips_tu1216_init(struct dvb_frontend *fe){	struct saa7134_dev *dev = fe->dvb->priv;	struct tda1004x_state *state = fe->demodulator_priv;	u8 addr = state->config->tuner_address;	static u8 tu1216_init[] = { 0x0b, 0xf5, 0x85, 0xab };	struct i2c_msg tuner_msg = {.addr = addr,.flags = 0,.buf = tu1216_init,.len = sizeof(tu1216_init) };	/* setup PLL configuration */	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	if (i2c_transfer(&dev->i2c_adap, &tuner_msg, 1) != 1)		return -EIO;	msleep(1);	return 0;}/* ------------------------------------------------------------------ */static struct tda1004x_config philips_tu1216_60_config = {	.demod_address = 0x8,	.invert        = 1,	.invert_oclk   = 0,	.xtal_freq     = TDA10046_XTAL_4M,	.agc_config    = TDA10046_AGC_DEFAULT,	.if_freq       = TDA10046_FREQ_3617,	.tuner_address = 0x60,	.request_firmware = philips_tda1004x_request_firmware};static struct tda1004x_config philips_tu1216_61_config = {	.demod_address = 0x8,	.invert        = 1,	.invert_oclk   = 0,	.xtal_freq     = TDA10046_XTAL_4M,	.agc_config    = TDA10046_AGC_DEFAULT,	.if_freq       = TDA10046_FREQ_3617,	.tuner_address = 0x61,	.request_firmware = philips_tda1004x_request_firmware};/* ------------------------------------------------------------------ */static int philips_td1316_tuner_init(struct dvb_frontend *fe){	struct saa7134_dev *dev = fe->dvb->priv;	struct tda1004x_state *state = fe->demodulator_priv;	u8 addr = state->config->tuner_address;	static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };	struct i2c_msg init_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };	/* setup PLL configuration */	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)		return -EIO;	return 0;}static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params){	return philips_tda6651_pll_set(fe, params);}static int philips_td1316_tuner_sleep(struct dvb_frontend *fe){	struct saa7134_dev *dev = fe->dvb->priv;	struct tda1004x_state *state = fe->demodulator_priv;	u8 addr = state->config->tuner_address;	static u8 msg[] = { 0x0b, 0xdc, 0x86, 0xa4 };	struct i2c_msg analog_msg = {.addr = addr,.flags = 0,.buf = msg,.len = sizeof(msg) };	/* switch the tuner to analog mode */	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	if (i2c_transfer(&dev->i2c_adap, &analog_msg, 1) != 1)		return -EIO;	return 0;}/* ------------------------------------------------------------------ */static int philips_europa_tuner_init(struct dvb_frontend *fe){	struct saa7134_dev *dev = fe->dvb->priv;	static u8 msg[] = { 0x00, 0x40};	struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };	if (philips_td1316_tuner_init(fe))		return -EIO;	msleep(1);	if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)		return -EIO;	return 0;}static int philips_europa_tuner_sleep(struct dvb_frontend *fe){	struct saa7134_dev *dev = fe->dvb->priv;	static u8 msg[] = { 0x00, 0x14 };	struct i2c_msg analog_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };	if (philips_td1316_tuner_sleep(fe))		return -EIO;	/* switch the board to analog mode */	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(&dev->i2c_adap, &analog_msg, 1);	return 0;}static int philips_europa_demod_sleep(struct dvb_frontend *fe){	struct saa7134_dev *dev = fe->dvb->priv;	if (dev->original_demod_sleep)		dev->original_demod_sleep(fe);	fe->ops.i2c_gate_ctrl(fe, 1);	return 0;}static struct tda1004x_config philips_europa_config = {	.demod_address = 0x8,	.invert        = 0,	.invert_oclk   = 0,	.xtal_freq     = TDA10046_XTAL_4M,	.agc_config    = TDA10046_AGC_IFO_AUTO_POS,	.if_freq       = TDA10046_FREQ_052,	.tuner_address = 0x61,	.request_firmware = philips_tda1004x_request_firmware};static struct tda1004x_config medion_cardbus = {	.demod_address = 0x08,	.invert        = 1,	.invert_oclk   = 0,	.xtal_freq     = TDA10046_XTAL_16M,	.agc_config    = TDA10046_AGC_IFO_AUTO_NEG,	.if_freq       = TDA10046_FREQ_3613,	.tuner_address = 0x61,	.request_firmware = philips_tda1004x_request_firmware};/* ------------------------------------------------------------------ * tda 1004x based cards with philips silicon tuner */static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable){	struct tda1004x_state *state = fe->demodulator_priv;	u8 addr = state->config->i2c_gate;	static u8 tda8290_close[] = { 0x21, 0xc0};	static u8 tda8290_open[]  = { 0x21, 0x80};	struct i2c_msg tda8290_msg = {.addr = addr,.flags = 0, .len = 2};	if (enable) {		tda8290_msg.buf = tda8290_close;	} else {		tda8290_msg.buf = tda8290_open;	}	if (i2c_transfer(state->i2c, &tda8290_msg, 1) != 1) {		struct saa7134_dev *dev = fe->dvb->priv;		wprintk("could not access tda8290 I2C gate\n");		return -EIO;	}	msleep(20);	return 0;

⌨️ 快捷键说明

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