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

📄 tda10023.c

📁 trident tm5600的linux驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    TDA10023  - DVB-C decoder    (as used in Philips CU1216-3 NIM and the Reelbox DVB-C tuner card)    Copyright (C) 2005 Georg Acher, BayCom GmbH (acher at baycom dot de)    Copyright (c) 2006 Hartmut Birr (e9hack at gmail dot com)    Remotely based on tda10021.c    Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de>    Copyright (C) 2004 Markus Schulz <msc@antzsystem.de>		   Support for TDA10021    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/delay.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/string.h>#include <linux/slab.h>#include <asm/div64.h>#include "dvb_frontend.h"#include "tda1002x.h"#define REG0_INIT_VAL 0x23struct tda10023_state {	struct i2c_adapter* i2c;	/* configuration settings */	const struct tda10023_config *config;	struct dvb_frontend frontend;	u8 pwm;	u8 reg0;	/* clock settings */	u32 xtal;	u8 pll_m;	u8 pll_p;	u8 pll_n;	u32 sysclk;};#if 0#define dprintk(x...) printk(x)#else#define dprintk(x...)#endifstatic int verbose;static u8 tda10023_readreg (struct tda10023_state* state, u8 reg){	u8 b0 [] = { reg };	u8 b1 [] = { 0 };	struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 },				  { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } };	int ret;	ret = i2c_transfer (state->i2c, msg, 2);	if (ret != 2) {		int num = state->frontend.dvb ? state->frontend.dvb->num : -1;		printk(KERN_ERR "DVB: TDA10023(%d): %s: readreg error "			"(reg == 0x%02x, ret == %i)\n",			num, __func__, reg, ret);	}	return b1[0];}static int tda10023_writereg (struct tda10023_state* state, u8 reg, u8 data){	u8 buf[] = { reg, data };	struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 };	int ret;	ret = i2c_transfer (state->i2c, &msg, 1);	if (ret != 1) {		int num = state->frontend.dvb ? state->frontend.dvb->num : -1;		printk(KERN_ERR "DVB: TDA10023(%d): %s, writereg error "			"(reg == 0x%02x, val == 0x%02x, ret == %i)\n",			num, __func__, reg, data, ret);	}	return (ret != 1) ? -EREMOTEIO : 0;}static int tda10023_writebit (struct tda10023_state* state, u8 reg, u8 mask,u8 data){	if (mask==0xff)		return tda10023_writereg(state, reg, data);	else {		u8 val;		val=tda10023_readreg(state,reg);		val&=~mask;		val|=(data&mask);		return tda10023_writereg(state, reg, val);	}}static void tda10023_writetab(struct tda10023_state* state, u8* tab){	u8 r,m,v;	while (1) {		r=*tab++;		m=*tab++;		v=*tab++;		if (r==0xff) {			if (m==0xff)				break;			else				msleep(m);		}		else			tda10023_writebit(state,r,m,v);	}}//get access to tunerstatic int lock_tuner(struct tda10023_state* state){	u8 buf[2] = { 0x0f, 0xc0 };	struct i2c_msg msg = {.addr=state->config->demod_address, .flags=0, .buf=buf, .len=2};	if(i2c_transfer(state->i2c, &msg, 1) != 1)	{		printk("tda10023: lock tuner fails\n");		return -EREMOTEIO;	}	return 0;}//release access from tunerstatic int unlock_tuner(struct tda10023_state* state){	u8 buf[2] = { 0x0f, 0x40 };	struct i2c_msg msg_post={.addr=state->config->demod_address, .flags=0, .buf=buf, .len=2};	if(i2c_transfer(state->i2c, &msg_post, 1) != 1)	{		printk("tda10023: unlock tuner fails\n");		return -EREMOTEIO;	}	return 0;}static int tda10023_setup_reg0 (struct tda10023_state* state, u8 reg0){	reg0 |= state->reg0 & 0x63;	tda10023_writereg (state, 0x00, reg0 & 0xfe);	tda10023_writereg (state, 0x00, reg0 | 0x01);	state->reg0 = reg0;	return 0;}static int tda10023_set_symbolrate (struct tda10023_state* state, u32 sr){	s32 BDR;	s32 BDRI;	s16 SFIL=0;	u16 NDEC = 0;	/* avoid floating point operations multiplying syscloc and divider	   by 10 */	u32 sysclk_x_10 = state->sysclk * 10;	if (sr < (u32)(sysclk_x_10/984)) {		NDEC=3;		SFIL=1;	} else if (sr < (u32)(sysclk_x_10/640)) {		NDEC=3;		SFIL=0;	} else if (sr < (u32)(sysclk_x_10/492)) {		NDEC=2;		SFIL=1;	} else if (sr < (u32)(sysclk_x_10/320)) {		NDEC=2;		SFIL=0;	} else if (sr < (u32)(sysclk_x_10/246)) {		NDEC=1;		SFIL=1;	} else if (sr < (u32)(sysclk_x_10/160)) {		NDEC=1;		SFIL=0;	} else if (sr < (u32)(sysclk_x_10/123)) {		NDEC=0;		SFIL=1;	}	BDRI = (state->sysclk)*16;	BDRI>>=NDEC;	BDRI +=sr/2;	BDRI /=sr;	if (BDRI>255)		BDRI=255;	{		u64 BDRX;		BDRX=1<<(24+NDEC);		BDRX*=sr;		do_div(BDRX, state->sysclk); 	/* BDRX/=SYSCLK; */		BDR=(s32)BDRX;	}	dprintk("Symbolrate %i, BDR %i BDRI %i, NDEC %i\n",		sr, BDR, BDRI, NDEC);	tda10023_writebit (state, 0x03, 0xc0, NDEC<<6);	tda10023_writereg (state, 0x0a, BDR&255);	tda10023_writereg (state, 0x0b, (BDR>>8)&255);	tda10023_writereg (state, 0x0c, (BDR>>16)&31);	tda10023_writereg (state, 0x0d, BDRI);	tda10023_writereg (state, 0x3d, (SFIL<<7));	return 0;}static int tda10023_init (struct dvb_frontend *fe){	struct tda10023_state* state = fe->demodulator_priv;	u8 tda10023_inittab[] = {/*        reg  mask val *//* 000 */ 0x2a, 0xff, 0x02,  /* PLL3, Bypass, Power Down *//* 003 */ 0xff, 0x64, 0x00,  /* Sleep 100ms *//* 006 */ 0x2a, 0xff, 0x03,  /* PLL3, Bypass, Power Down *//* 009 */ 0xff, 0x64, 0x00,  /* Sleep 100ms */			   /* PLL1 *//* 012 */ 0x28, 0xff, (state->pll_m-1),			   /* PLL2 *//* 015 */ 0x29, 0xff, ((state->pll_p-1)<<6)|(state->pll_n-1),			   /* GPR FSAMPLING=1 *//* 018 */ 0x00, 0xff, REG0_INIT_VAL,/* 021 */ 0x2a, 0xff, 0x08,  /* PLL3 PSACLK=1 *//* 024 */ 0xff, 0x64, 0x00,  /* Sleep 100ms *//* 027 */ 0x1f, 0xff, 0x00,  /* RESET *//* 030 */ 0xff, 0x64, 0x00,  /* Sleep 100ms *//* 033 */ 0xe6, 0x0c, 0x04,  /* RSCFG_IND *//* 036 */ 0x10, 0xc0, 0x80,  /* DECDVBCFG1 PBER=1 *//* 039 */ 0x0e, 0xff, 0x82,  /* GAIN1 *//* 042 */ 0x03, 0x08, 0x08,  /* CLKCONF DYN=1 *//* 045 */ 0x2e, 0xbf, 0x30,  /* AGCCONF2 TRIAGC=0,POSAGC=ENAGCIF=1				       PPWMTUN=0 PPWMIF=0 *//* 048 */ 0x01, 0xff, 0x30,  /* AGCREF *//* 051 */ 0x1e, 0x84, 0x84,  /* CONTROL SACLK_ON=1 *//* 054 */ 0x1b, 0xff, 0xc8,  /* ADC TWOS=1 *//* 057 */ 0x3b, 0xff, 0xff,  /* IFMAX *//* 060 */ 0x3c, 0xff, 0x00,  /* IFMIN *//* 063 */ 0x34, 0xff, 0x00,  /* PWMREF *//* 066 */ 0x35, 0xff, 0xff,  /* TUNMAX *//* 069 */ 0x36, 0xff, 0x00,  /* TUNMIN *//* 072 */ 0x06, 0xff, 0x7f,  /* EQCONF1 POSI=7 ENADAPT=ENEQUAL=DFE=1 *//* 075 */ 0x1c, 0x30, 0x30,  /* EQCONF2 STEPALGO=SGNALGO=1 *//* 078 */ 0x37, 0xff, 0xf6,  /* DELTAF_LSB *//* 081 */ 0x38, 0xff, 0xff,  /* DELTAF_MSB *//* 084 */ 0x02, 0xff, 0x93,  /* AGCCONF1  IFS=1 KAGCIF=2 KAGCTUN=3 *//* 087 */ 0x2d, 0xff, 0xf6,  /* SWEEP SWPOS=1 SWDYN=7 SWSTEP=1 SWLEN=2 *//* 090 */ 0x04, 0x10, 0x00,  /* SWRAMP=1 *//* 093 */ 0x12, 0xff, TDA10023_OUTPUT_MODE_PARALLEL_B, /*				INTP1 POCLKP=1 FEL=1 MFS=0 *//* 096 */ 0x2b, 0x01, 0xa1,  /* INTS1 *//* 099 */ 0x20, 0xff, 0x04,  /* INTP2 SWAPP=? MSBFIRSTP=? INTPSEL=? *//* 102 */ 0x2c, 0xff, 0x0d,  /* INTP/S TRIP=0 TRIS=0 *//* 105 */ 0xc4, 0xff, 0x00,/* 108 */ 0xc3, 0x30, 0x00,/* 111 */ 0xb5, 0xff, 0x19,  /* ERAGC_THD *//* 114 */ 0x00, 0x03, 0x01,  /* GPR, CLBS soft reset *//* 117 */ 0x00, 0x03, 0x03,  /* GPR, CLBS soft reset *//* 120 */ 0xff, 0x64, 0x00,  /* Sleep 100ms *//* 123 */ 0xff, 0xff, 0xff};	dprintk("DVB: TDA10023(%d): init chip\n", fe->dvb->num);	/* override default values if set in config */

⌨️ 快捷键说明

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