#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 <media/dvb_frontend.h>
#include "mxl5005s.h"
static int debug;
#define dprintk(level, arg...) …
#define TUNER_REGS_NUM …
#define INITCTRL_NUM …
#ifdef _MXL_PRODUCTION
#define CHCTRL_NUM …
#else
#define CHCTRL_NUM …
#endif
#define MXLCTRL_NUM …
#define MASTER_CONTROL_ADDR …
enum master_control_state { … };
enum { … };
struct TunerReg { … };
enum { … };
#define MXL5005S_REG_WRITING_TABLE_LEN_MAX …
#define MXL5005S_LATCH_BYTE …
#define MXL5005S_BB_IQSWAP_ADDR …
#define MXL5005S_BB_IQSWAP_MSB …
#define MXL5005S_BB_IQSWAP_LSB …
#define MXL5005S_BB_DLPF_BANDSEL_ADDR …
#define MXL5005S_BB_DLPF_BANDSEL_MSB …
#define MXL5005S_BB_DLPF_BANDSEL_LSB …
enum { … };
#define MXL5005S_STANDARD_MODE_NUM …
enum { … };
#define MXL5005S_BANDWIDTH_MODE_NUM …
struct TunerControl { … };
struct mxl5005s_state { … };
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 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);
static int mxl5005s_SetRfFreqHz(struct dvb_frontend *fe, unsigned long RfFreqHz)
{ … }
static u16 MXL5005_RegisterInit(struct dvb_frontend *fe)
{ … }
static u16 MXL5005_ControlInit(struct dvb_frontend *fe)
{ … }
static void InitTunerControls(struct dvb_frontend *fe)
{ … }
static u16 MXL5005_TunerConfig(struct dvb_frontend *fe,
u8 Mode,
u8 IF_mode,
u32 Bandwidth,
u32 IF_out,
u32 Fxtal,
u8 AGC_Mode,
u16 TOP,
u16 IF_OUT_LOAD,
u8 CLOCK_OUT,
u8 DIV_OUT,
u8 CAPSELECT,
u8 EN_RSSI,
u8 Mod_Type,
u8 TF_Type
)
{ … }
static void MXL_SynthIFLO_Calc(struct dvb_frontend *fe)
{ … }
static void MXL_SynthRFTGLO_Calc(struct dvb_frontend *fe)
{ … }
static u16 MXL_OverwriteICDefault(struct dvb_frontend *fe)
{ … }
static u16 MXL_BlockInit(struct dvb_frontend *fe)
{ … }
static u16 MXL_IFSynthInit(struct dvb_frontend *fe)
{ … }
static u16 MXL_TuneRF(struct dvb_frontend *fe, u32 RF_Freq)
{ … }
static u16 MXL_SetGPIO(struct dvb_frontend *fe, u8 GPIO_Num, u8 GPIO_Val)
{ … }
static u16 MXL_ControlWrite(struct dvb_frontend *fe, u16 ControlNum, u32 value)
{ … }
static u16 MXL_ControlWrite_Group(struct dvb_frontend *fe, u16 controlNum,
u32 value, u16 controlGroup)
{ … }
static u16 MXL_RegRead(struct dvb_frontend *fe, u8 RegNum, u8 *RegVal)
{ … }
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 u32 MXL_Ceiling(u32 value, u32 resolution)
{ … }
static u16 MXL_GetInitRegister(struct dvb_frontend *fe, u8 *RegNum,
u8 *RegVal, int *count)
{ … }
static u16 MXL_GetCHRegister(struct dvb_frontend *fe, u8 *RegNum, u8 *RegVal,
int *count)
{ … }
static u16 MXL_GetCHRegister_ZeroIF(struct dvb_frontend *fe, u8 *RegNum,
u8 *RegVal, int *count)
{ … }
static u16 MXL_GetMasterControl(u8 *MasterReg, int state)
{ … }
#ifdef _MXL_PRODUCTION
static u16 MXL_VCORange_Test(struct dvb_frontend *fe, int VCO_Range)
{
struct mxl5005s_state *state = fe->tuner_priv;
u16 status = 0 ;
if (VCO_Range == 1) {
status += MXL_ControlWrite(fe, RFSYN_EN_DIV, 1);
status += MXL_ControlWrite(fe, RFSYN_EN_OUTMUX, 0);
status += MXL_ControlWrite(fe, RFSYN_SEL_DIVM, 0);
status += MXL_ControlWrite(fe, RFSYN_DIVM, 1);
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_OUT, 1);
status += MXL_ControlWrite(fe, RFSYN_RF_DIV_BIAS, 1);
status += MXL_ControlWrite(fe, DN_SEL_FREQ, 0);
if (state->Mode == 0 && state->IF_Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 1);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 8);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 56);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 180224);
}
if (state->Mode == 0 && state->IF_Mode == 0) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 1);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 8);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 56);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 222822);
}
if (state->Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 1);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 8);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 56);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 229376);
}
}
if (VCO_Range == 2) {
status += MXL_ControlWrite(fe, RFSYN_EN_DIV, 1);
status += MXL_ControlWrite(fe, RFSYN_EN_OUTMUX, 0);
status += MXL_ControlWrite(fe, RFSYN_SEL_DIVM, 0);
status += MXL_ControlWrite(fe, RFSYN_DIVM, 1);
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_OUT, 1);
status += MXL_ControlWrite(fe, RFSYN_RF_DIV_BIAS, 1);
status += MXL_ControlWrite(fe, DN_SEL_FREQ, 0);
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 1);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 41);
if (state->Mode == 0 && state->IF_Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 1);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 42);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 206438);
}
if (state->Mode == 0 && state->IF_Mode == 0) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 1);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 42);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 206438);
}
if (state->Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 1);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 41);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 16384);
}
}
if (VCO_Range == 3) {
status += MXL_ControlWrite(fe, RFSYN_EN_DIV, 1);
status += MXL_ControlWrite(fe, RFSYN_EN_OUTMUX, 0);
status += MXL_ControlWrite(fe, RFSYN_SEL_DIVM, 0);
status += MXL_ControlWrite(fe, RFSYN_DIVM, 1);
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_OUT, 1);
status += MXL_ControlWrite(fe, RFSYN_RF_DIV_BIAS, 1);
status += MXL_ControlWrite(fe, DN_SEL_FREQ, 0);
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 8);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 42);
if (state->Mode == 0 && state->IF_Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 8);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 44);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 173670);
}
if (state->Mode == 0 && state->IF_Mode == 0) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 8);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 44);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 173670);
}
if (state->Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 8);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 42);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 245760);
}
}
if (VCO_Range == 4) {
status += MXL_ControlWrite(fe, RFSYN_EN_DIV, 1);
status += MXL_ControlWrite(fe, RFSYN_EN_OUTMUX, 0);
status += MXL_ControlWrite(fe, RFSYN_SEL_DIVM, 0);
status += MXL_ControlWrite(fe, RFSYN_DIVM, 1);
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_OUT, 1);
status += MXL_ControlWrite(fe, RFSYN_RF_DIV_BIAS, 1);
status += MXL_ControlWrite(fe, DN_SEL_FREQ, 0);
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 27);
if (state->Mode == 0 && state->IF_Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 27);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 206438);
}
if (state->Mode == 0 && state->IF_Mode == 0) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 27);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 206438);
}
if (state->Mode == 1) {
status += MXL_ControlWrite(fe, RFSYN_SEL_VCO_HI, 0);
status += MXL_ControlWrite(fe, RFSYN_VCO_BIAS, 40);
status += MXL_ControlWrite(fe, CHCAL_INT_MOD_RF, 27);
status += MXL_ControlWrite(fe,
CHCAL_FRAC_MOD_RF, 212992);
}
}
return status;
}
static u16 MXL_Hystersis_Test(struct dvb_frontend *fe, int Hystersis)
{
struct mxl5005s_state *state = fe->tuner_priv;
u16 status = 0;
if (Hystersis == 1)
status += MXL_ControlWrite(fe, DN_BYPASS_AGC_I2C, 1);
return status;
}
#endif
static int mxl5005s_reset(struct dvb_frontend *fe)
{ … }
static int mxl5005s_writereg(struct dvb_frontend *fe, u8 reg, u8 val, int latch)
{ … }
static int mxl5005s_writeregs(struct dvb_frontend *fe, u8 *addrtable,
u8 *datatable, u8 len)
{ … }
static int mxl5005s_init(struct dvb_frontend *fe)
{ … }
static int mxl5005s_reconfigure(struct dvb_frontend *fe, u32 mod_type,
u32 bandwidth)
{ … }
static int mxl5005s_AssignTunerMode(struct dvb_frontend *fe, u32 mod_type,
u32 bandwidth)
{ … }
static int mxl5005s_set_params(struct dvb_frontend *fe)
{ … }
static int mxl5005s_get_frequency(struct dvb_frontend *fe, u32 *frequency)
{ … }
static int mxl5005s_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
{ … }
static int mxl5005s_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
{ … }
static void mxl5005s_release(struct dvb_frontend *fe)
{ … }
static const struct dvb_tuner_ops mxl5005s_tuner_ops = …;
struct dvb_frontend *mxl5005s_attach(struct dvb_frontend *fe,
struct i2c_adapter *i2c,
struct mxl5005s_config *config)
{ … }
EXPORT_SYMBOL_GPL(…);
MODULE_DESCRIPTION(…) …;
MODULE_AUTHOR(…) …;
MODULE_LICENSE(…) …;