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

📄 mxl5005s.c

📁 trident tm5600的linux驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/*    MaxLinear MXL5005S VSB/QAM/DVBT tuner driver    Copyright (C) 2008 MaxLinear    Copyright (C) 2006 Steven Toth <stoth@linuxtv.org>      Functions:	mxl5005s_reset()	mxl5005s_writereg()	mxl5005s_writeregs()	mxl5005s_init()	mxl5005s_reconfigure()	mxl5005s_AssignTunerMode()	mxl5005s_set_params()	mxl5005s_get_frequency()	mxl5005s_get_bandwidth()	mxl5005s_release()	mxl5005s_attach()    Copyright (C) 2008 Realtek    Copyright (C) 2008 Jan Hoogenraad      Functions:	mxl5005s_SetRfFreqHz()    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.*//*    History of this driver (Steven Toth):      I was given a public release of a linux driver that included      support for the MaxLinear MXL5005S silicon tuner. Analysis of      the tuner driver showed clearly three things.      1. The tuner driver didn't support the LinuxTV tuner API	 so the code Realtek added had to be removed.      2. A significant amount of the driver is reference driver code	 from MaxLinear, I felt it was important to identify and	 preserve this.      3. New code has to be added to interface correctly with the	 LinuxTV API, as a regular kernel module.      Other than the reference driver enum's, I've clearly marked      sections of the code and retained the copyright of the      respective owners.*/#include <linux/kernel.h>#include <linux/init.h>#include <linux/module.h>#include <linux/string.h>#include <linux/slab.h>#include <linux/delay.h>#include "dvb_frontend.h"#include "mxl5005s.h"static int debug;#define dprintk(level, arg...) do {    \	if (level <= debug)            \		printk(arg);    \	} while (0)#define TUNER_REGS_NUM          104#define INITCTRL_NUM            40#ifdef _MXL_PRODUCTION#define CHCTRL_NUM              39#else#define CHCTRL_NUM              36#endif#define MXLCTRL_NUM             189#define MASTER_CONTROL_ADDR     9/* Enumeration of Master Control Register State */enum master_control_state {	MC_LOAD_START = 1,	MC_POWER_DOWN,	MC_SYNTH_RESET,	MC_SEQ_OFF};/* Enumeration of MXL5005 Tuner Modulation Type */enum {	MXL_DEFAULT_MODULATION = 0,	MXL_DVBT,	MXL_ATSC,	MXL_QAM,	MXL_ANALOG_CABLE,	MXL_ANALOG_OTA};/* MXL5005 Tuner Register Struct */struct TunerReg {	u16 Reg_Num;	/* Tuner Register Address */	u16 Reg_Val;	/* Current sw programmed value waiting to be writen */};enum {	/* Initialization Control Names */	DN_IQTN_AMP_CUT = 1,       /* 1 */	BB_MODE,                   /* 2 */	BB_BUF,                    /* 3 */	BB_BUF_OA,                 /* 4 */	BB_ALPF_BANDSELECT,        /* 5 */	BB_IQSWAP,                 /* 6 */	BB_DLPF_BANDSEL,           /* 7 */	RFSYN_CHP_GAIN,            /* 8 */	RFSYN_EN_CHP_HIGAIN,       /* 9 */	AGC_IF,                    /* 10 */	AGC_RF,                    /* 11 */	IF_DIVVAL,                 /* 12 */	IF_VCO_BIAS,               /* 13 */	CHCAL_INT_MOD_IF,          /* 14 */	CHCAL_FRAC_MOD_IF,         /* 15 */	DRV_RES_SEL,               /* 16 */	I_DRIVER,                  /* 17 */	EN_AAF,                    /* 18 */	EN_3P,                     /* 19 */	EN_AUX_3P,                 /* 20 */	SEL_AAF_BAND,              /* 21 */	SEQ_ENCLK16_CLK_OUT,       /* 22 */	SEQ_SEL4_16B,              /* 23 */	XTAL_CAPSELECT,            /* 24 */	IF_SEL_DBL,                /* 25 */	RFSYN_R_DIV,               /* 26 */	SEQ_EXTSYNTHCALIF,         /* 27 */	SEQ_EXTDCCAL,              /* 28 */	AGC_EN_RSSI,               /* 29 */	RFA_ENCLKRFAGC,            /* 30 */	RFA_RSSI_REFH,             /* 31 */	RFA_RSSI_REF,              /* 32 */	RFA_RSSI_REFL,             /* 33 */	RFA_FLR,                   /* 34 */	RFA_CEIL,                  /* 35 */	SEQ_EXTIQFSMPULSE,         /* 36 */	OVERRIDE_1,                /* 37 */	BB_INITSTATE_DLPF_TUNE,    /* 38 */	TG_R_DIV,                  /* 39 */	EN_CHP_LIN_B,              /* 40 */	/* Channel Change Control Names */	DN_POLY = 51,              /* 51 */	DN_RFGAIN,                 /* 52 */	DN_CAP_RFLPF,              /* 53 */	DN_EN_VHFUHFBAR,           /* 54 */	DN_GAIN_ADJUST,            /* 55 */	DN_IQTNBUF_AMP,            /* 56 */	DN_IQTNGNBFBIAS_BST,       /* 57 */	RFSYN_EN_OUTMUX,           /* 58 */	RFSYN_SEL_VCO_OUT,         /* 59 */	RFSYN_SEL_VCO_HI,          /* 60 */	RFSYN_SEL_DIVM,            /* 61 */	RFSYN_RF_DIV_BIAS,         /* 62 */	DN_SEL_FREQ,               /* 63 */	RFSYN_VCO_BIAS,            /* 64 */	CHCAL_INT_MOD_RF,          /* 65 */	CHCAL_FRAC_MOD_RF,         /* 66 */	RFSYN_LPF_R,               /* 67 */	CHCAL_EN_INT_RF,           /* 68 */	TG_LO_DIVVAL,              /* 69 */	TG_LO_SELVAL,              /* 70 */	TG_DIV_VAL,                /* 71 */	TG_VCO_BIAS,               /* 72 */	SEQ_EXTPOWERUP,            /* 73 */	OVERRIDE_2,                /* 74 */	OVERRIDE_3,                /* 75 */	OVERRIDE_4,                /* 76 */	SEQ_FSM_PULSE,             /* 77 */	GPIO_4B,                   /* 78 */	GPIO_3B,                   /* 79 */	GPIO_4,                    /* 80 */	GPIO_3,                    /* 81 */	GPIO_1B,                   /* 82 */	DAC_A_ENABLE,              /* 83 */	DAC_B_ENABLE,              /* 84 */	DAC_DIN_A,                 /* 85 */	DAC_DIN_B,                 /* 86 */#ifdef _MXL_PRODUCTION	RFSYN_EN_DIV,              /* 87 */	RFSYN_DIVM,                /* 88 */	DN_BYPASS_AGC_I2C          /* 89 */#endif};/* * The following context is source code provided by MaxLinear. * MaxLinear source code - Common_MXL.h (?) *//* Constants */#define MXL5005S_REG_WRITING_TABLE_LEN_MAX	104#define MXL5005S_LATCH_BYTE			0xfe/* Register address, MSB, and LSB */#define MXL5005S_BB_IQSWAP_ADDR			59#define MXL5005S_BB_IQSWAP_MSB			0#define MXL5005S_BB_IQSWAP_LSB			0#define MXL5005S_BB_DLPF_BANDSEL_ADDR		53#define MXL5005S_BB_DLPF_BANDSEL_MSB		4#define MXL5005S_BB_DLPF_BANDSEL_LSB		3/* Standard modes */enum {	MXL5005S_STANDARD_DVBT,	MXL5005S_STANDARD_ATSC,};#define MXL5005S_STANDARD_MODE_NUM		2/* Bandwidth modes */enum {	MXL5005S_BANDWIDTH_6MHZ = 6000000,	MXL5005S_BANDWIDTH_7MHZ = 7000000,	MXL5005S_BANDWIDTH_8MHZ = 8000000,};#define MXL5005S_BANDWIDTH_MODE_NUM		3/* MXL5005 Tuner Control Struct */struct TunerControl {	u16 Ctrl_Num;	/* Control Number */	u16 size;	/* Number of bits to represent Value */	u16 addr[25];	/* Array of Tuner Register Address for each bit pos */	u16 bit[25];	/* Array of bit pos in Reg Addr for each bit pos */	u16 val[25];	/* Binary representation of Value */};/* MXL5005 Tuner Struct */struct mxl5005s_state {	u8	Mode;		/* 0: Analog Mode ; 1: Digital Mode */	u8	IF_Mode;	/* for Analog Mode, 0: zero IF; 1: low IF */	u32	Chan_Bandwidth;	/* filter  channel bandwidth (6, 7, 8) */	u32	IF_OUT;		/* Desired IF Out Frequency */	u16	IF_OUT_LOAD;	/* IF Out Load Resistor (200/300 Ohms) */	u32	RF_IN;		/* RF Input Frequency */	u32	Fxtal;		/* XTAL Frequency */	u8	AGC_Mode;	/* AGC Mode 0: Dual AGC; 1: Single AGC */	u16	TOP;		/* Value: take over point */	u8	CLOCK_OUT;	/* 0: turn off clk out; 1: turn on clock out */	u8	DIV_OUT;	/* 4MHz or 16MHz */	u8	CAPSELECT;	/* 0: disable On-Chip pulling cap; 1: enable */	u8	EN_RSSI;	/* 0: disable RSSI; 1: enable RSSI */	/* Modulation Type; */	/* 0 - Default;	1 - DVB-T; 2 - ATSC; 3 - QAM; 4 - Analog Cable */	u8	Mod_Type;	/* Tracking Filter Type */	/* 0 - Default; 1 - Off; 2 - Type C; 3 - Type C-H */	u8	TF_Type;	/* Calculated Settings */	u32	RF_LO;		/* Synth RF LO Frequency */	u32	IF_LO;		/* Synth IF LO Frequency */	u32	TG_LO;		/* Synth TG_LO Frequency */	/* Pointers to ControlName Arrays */	u16	Init_Ctrl_Num;		/* Number of INIT Control Names */	struct TunerControl		Init_Ctrl[INITCTRL_NUM]; /* INIT Control Names Array Pointer */	u16	CH_Ctrl_Num;		/* Number of CH Control Names */	struct TunerControl		CH_Ctrl[CHCTRL_NUM];	/* CH Control Name Array Pointer */	u16	MXL_Ctrl_Num;		/* Number of MXL Control Names */	struct TunerControl		MXL_Ctrl[MXLCTRL_NUM];	/* MXL Control Name Array Pointer */	/* Pointer to Tuner Register Array */	u16	TunerRegs_Num;		/* Number of Tuner Registers */	struct TunerReg		TunerRegs[TUNER_REGS_NUM]; /* Tuner Register Array Pointer */	/* Linux driver framework specific */	struct mxl5005s_config *config;	struct dvb_frontend *frontend;	struct i2c_adapter *i2c;	/* Cache values */	u32 current_mode;};static u16 MXL_GetMasterControl(u8 *MasterReg, int state);static u16 MXL_ControlWrite(struct dvb_frontend *fe, u16 ControlNum, u32 value);static u16 MXL_ControlRead(struct dvb_frontend *fe, u16 controlNum, u32 *value);static void MXL_RegWriteBit(struct dvb_frontend *fe, u8 address, u8 bit,	u8 bitVal);static u16 MXL_GetCHRegister(struct dvb_frontend *fe, u8 *RegNum,	u8 *RegVal, int *count);static u32 MXL_Ceiling(u32 value, u32 resolution);static u16 MXL_RegRead(struct dvb_frontend *fe, u8 RegNum, u8 *RegVal);static u16 MXL_ControlWrite_Group(struct dvb_frontend *fe, u16 controlNum,	u32 value, u16 controlGroup);static u16 MXL_SetGPIO(struct dvb_frontend *fe, u8 GPIO_Num, u8 GPIO_Val);static u16 MXL_GetInitRegister(struct dvb_frontend *fe, u8 *RegNum,	u8 *RegVal, int *count);static u32 MXL_GetXtalInt(u32 Xtal_Freq);static u16 MXL_TuneRF(struct dvb_frontend *fe, u32 RF_Freq);static void MXL_SynthIFLO_Calc(struct dvb_frontend *fe);static void MXL_SynthRFTGLO_Calc(struct dvb_frontend *fe);static u16 MXL_GetCHRegister_ZeroIF(struct dvb_frontend *fe, u8 *RegNum,	u8 *RegVal, int *count);static int mxl5005s_writeregs(struct dvb_frontend *fe, u8 *addrtable,	u8 *datatable, u8 len);static u16 MXL_IFSynthInit(struct dvb_frontend *fe);static int mxl5005s_AssignTunerMode(struct dvb_frontend *fe, u32 mod_type,	u32 bandwidth);static int mxl5005s_reconfigure(struct dvb_frontend *fe, u32 mod_type,	u32 bandwidth);/* ---------------------------------------------------------------- * Begin: Custom code salvaged from the Realtek driver. * Copyright (C) 2008 Realtek * Copyright (C) 2008 Jan Hoogenraad * This code is placed under the terms of the GNU General Public License * * Released by Realtek under GPLv2. * Thanks to Realtek for a lot of support we received ! * *  Revision: 080314 - original version */static int mxl5005s_SetRfFreqHz(struct dvb_frontend *fe, unsigned long RfFreqHz){	struct mxl5005s_state *state = fe->tuner_priv;	unsigned char AddrTable[MXL5005S_REG_WRITING_TABLE_LEN_MAX];	unsigned char ByteTable[MXL5005S_REG_WRITING_TABLE_LEN_MAX];	int TableLen;	u32 IfDivval = 0;	unsigned char MasterControlByte;	dprintk(1, "%s() freq=%ld\n", __func__, RfFreqHz);	/* Set MxL5005S tuner RF frequency according to example code. */	/* Tuner RF frequency setting stage 0 */	MXL_GetMasterControl(ByteTable, MC_SYNTH_RESET);	AddrTable[0] = MASTER_CONTROL_ADDR;	ByteTable[0] |= state->config->AgcMasterByte;	mxl5005s_writeregs(fe, AddrTable, ByteTable, 1);	/* Tuner RF frequency setting stage 1 */	MXL_TuneRF(fe, RfFreqHz);	MXL_ControlRead(fe, IF_DIVVAL, &IfDivval);	MXL_ControlWrite(fe, SEQ_FSM_PULSE, 0);	MXL_ControlWrite(fe, SEQ_EXTPOWERUP, 1);	MXL_ControlWrite(fe, IF_DIVVAL, 8);	MXL_GetCHRegister(fe, AddrTable, ByteTable, &TableLen);	MXL_GetMasterControl(&MasterControlByte, MC_LOAD_START);	AddrTable[TableLen] = MASTER_CONTROL_ADDR ;	ByteTable[TableLen] = MasterControlByte |		state->config->AgcMasterByte;	TableLen += 1;	mxl5005s_writeregs(fe, AddrTable, ByteTable, TableLen);	/* Wait 30 ms. */	msleep(150);	/* Tuner RF frequency setting stage 2 */	MXL_ControlWrite(fe, SEQ_FSM_PULSE, 1);	MXL_ControlWrite(fe, IF_DIVVAL, IfDivval);	MXL_GetCHRegister_ZeroIF(fe, AddrTable, ByteTable, &TableLen);	MXL_GetMasterControl(&MasterControlByte, MC_LOAD_START);	AddrTable[TableLen] = MASTER_CONTROL_ADDR ;	ByteTable[TableLen] = MasterControlByte |		state->config->AgcMasterByte ;	TableLen += 1;	mxl5005s_writeregs(fe, AddrTable, ByteTable, TableLen);	msleep(100);	return 0;}/* End: Custom code taken from the Realtek driver *//* ---------------------------------------------------------------- * Begin: Reference driver code found in the Realtek driver. * Copyright (C) 2008 MaxLinear */static u16 MXL5005_RegisterInit(struct dvb_frontend *fe){	struct mxl5005s_state *state = fe->tuner_priv;	state->TunerRegs_Num = TUNER_REGS_NUM ;	state->TunerRegs[0].Reg_Num = 9 ;	state->TunerRegs[0].Reg_Val = 0x40 ;	state->TunerRegs[1].Reg_Num = 11 ;	state->TunerRegs[1].Reg_Val = 0x19 ;	state->TunerRegs[2].Reg_Num = 12 ;	state->TunerRegs[2].Reg_Val = 0x60 ;	state->TunerRegs[3].Reg_Num = 13 ;	state->TunerRegs[3].Reg_Val = 0x00 ;	state->TunerRegs[4].Reg_Num = 14 ;	state->TunerRegs[4].Reg_Val = 0x00 ;	state->TunerRegs[5].Reg_Num = 15 ;	state->TunerRegs[5].Reg_Val = 0xC0 ;	state->TunerRegs[6].Reg_Num = 16 ;

⌨️ 快捷键说明

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