#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/int_log.h>
#include "stv0367.h"
#include "stv0367_defs.h"
#include "stv0367_regs.h"
#include "stv0367_priv.h"
#define MAX_XFER_SIZE …
static int stvdebug;
module_param_named(debug, stvdebug, int, 0644);
static int i2cdebug;
module_param_named(i2c_debug, i2cdebug, int, 0644);
#define dprintk(args...) …
enum active_demod_state { … };
struct stv0367cab_state { … };
struct stv0367ter_state { … };
struct stv0367_state { … };
#define RF_LOOKUP_TABLE_SIZE …
#define RF_LOOKUP_TABLE2_SIZE …
static const s32 stv0367cab_RF_LookUp1[RF_LOOKUP_TABLE_SIZE][RF_LOOKUP_TABLE_SIZE] = …;
static const s32 stv0367cab_RF_LookUp2[RF_LOOKUP_TABLE2_SIZE][RF_LOOKUP_TABLE2_SIZE] = …;
static noinline_for_stack
int stv0367_writereg(struct stv0367_state *state, u16 reg, u8 data)
{ … }
static noinline_for_stack
u8 stv0367_readreg(struct stv0367_state *state, u16 reg)
{ … }
static void extract_mask_pos(u32 label, u8 *mask, u8 *pos)
{ … }
static void stv0367_writebits(struct stv0367_state *state, u32 label, u8 val)
{ … }
static void stv0367_setbits(u8 *reg, u32 label, u8 val)
{ … }
static u8 stv0367_readbits(struct stv0367_state *state, u32 label)
{ … }
#if 0
static u8 stv0367_getbits(u8 reg, u32 label)
{
u8 mask, pos;
extract_mask_pos(label, &mask, &pos);
return (reg & mask) >> pos;
}
#endif
static void stv0367_write_table(struct stv0367_state *state,
const struct st_register *deftab)
{ … }
static void stv0367_pll_setup(struct stv0367_state *state,
u32 icspeed, u32 xtal)
{ … }
static int stv0367_get_if_khz(struct stv0367_state *state, u32 *ifkhz)
{ … }
static int stv0367ter_gate_ctrl(struct dvb_frontend *fe, int enable)
{ … }
static u32 stv0367_get_tuner_freq(struct dvb_frontend *fe)
{ … }
static u16 CellsCoeffs_8MHz_367cofdm[3][6][5] = …;
static u16 CellsCoeffs_7MHz_367cofdm[3][6][5] = …;
static u16 CellsCoeffs_6MHz_367cofdm[3][6][5] = …;
static u32 stv0367ter_get_mclk(struct stv0367_state *state, u32 ExtClk_Hz)
{ … }
static int stv0367ter_filt_coeff_init(struct stv0367_state *state,
u16 CellsCoeffs[3][6][5], u32 DemodXtal)
{ … }
static void stv0367ter_agc_iir_lock_detect_set(struct stv0367_state *state)
{ … }
static int stv0367_iir_filt_init(struct stv0367_state *state, u8 Bandwidth,
u32 DemodXtalValue)
{ … }
static void stv0367ter_agc_iir_rst(struct stv0367_state *state)
{ … }
static int stv0367ter_duration(s32 mode, int tempo1, int tempo2, int tempo3)
{ … }
static enum
stv0367_ter_signal_type stv0367ter_check_syr(struct stv0367_state *state)
{ … }
static enum
stv0367_ter_signal_type stv0367ter_check_cpamp(struct stv0367_state *state,
s32 FFTmode)
{ … }
static enum stv0367_ter_signal_type
stv0367ter_lock_algo(struct stv0367_state *state)
{ … }
static void stv0367ter_set_ts_mode(struct stv0367_state *state,
enum stv0367_ts_mode PathTS)
{ … }
static void stv0367ter_set_clk_pol(struct stv0367_state *state,
enum stv0367_clk_pol clock)
{ … }
#if 0
static void stv0367ter_core_sw(struct stv0367_state *state)
{
dprintk("%s:\n", __func__);
stv0367_writebits(state, F367TER_CORE_ACTIVE, 0);
stv0367_writebits(state, F367TER_CORE_ACTIVE, 1);
msleep(350);
}
#endif
static int stv0367ter_standby(struct dvb_frontend *fe, u8 standby_on)
{ … }
static int stv0367ter_sleep(struct dvb_frontend *fe)
{ … }
static int stv0367ter_init(struct dvb_frontend *fe)
{ … }
static int stv0367ter_algo(struct dvb_frontend *fe)
{ … }
static int stv0367ter_set_frontend(struct dvb_frontend *fe)
{ … }
static int stv0367ter_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
{ … }
static int stv0367ter_get_frontend(struct dvb_frontend *fe,
struct dtv_frontend_properties *p)
{ … }
static u32 stv0367ter_snr_readreg(struct dvb_frontend *fe)
{ … }
static int stv0367ter_read_snr(struct dvb_frontend *fe, u16 *snr)
{ … }
#if 0
static int stv0367ter_status(struct dvb_frontend *fe)
{
struct stv0367_state *state = fe->demodulator_priv;
struct stv0367ter_state *ter_state = state->ter_state;
int locked = FALSE;
locked = (stv0367_readbits(state, F367TER_LK));
if (!locked)
ter_state->unlock_counter += 1;
else
ter_state->unlock_counter = 0;
if (ter_state->unlock_counter > 2) {
if (!stv0367_readbits(state, F367TER_TPS_LOCK) ||
(!stv0367_readbits(state, F367TER_LK))) {
stv0367_writebits(state, F367TER_CORE_ACTIVE, 0);
usleep_range(2000, 3000);
stv0367_writebits(state, F367TER_CORE_ACTIVE, 1);
msleep(350);
locked = (stv0367_readbits(state, F367TER_TPS_LOCK)) &&
(stv0367_readbits(state, F367TER_LK));
}
}
return locked;
}
#endif
static int stv0367ter_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{ … }
static int stv0367ter_read_ber(struct dvb_frontend *fe, u32 *ber)
{ … }
#if 0
static u32 stv0367ter_get_per(struct stv0367_state *state)
{
struct stv0367ter_state *ter_state = state->ter_state;
u32 Errors = 0, Per = 0, temporary = 0;
int abc = 0, def = 0, cpt = 0;
while (((stv0367_readbits(state, F367TER_SFERRC_OLDVALUE) == 1) &&
(cpt < 400)) || ((Errors == 0) && (cpt < 400))) {
usleep_range(1000, 2000);
Errors = ((u32)stv0367_readbits(state, F367TER_ERR_CNT1)
* (1 << 16))
+ ((u32)stv0367_readbits(state, F367TER_ERR_CNT1_HI)
* (1 << 8))
+ ((u32)stv0367_readbits(state, F367TER_ERR_CNT1_LO));
cpt++;
}
abc = stv0367_readbits(state, F367TER_ERR_SRC1);
def = stv0367_readbits(state, F367TER_NUM_EVT1);
if (Errors == 0)
Per = 0;
else if (abc == 0x9) {
if (Errors <= 4) {
temporary = (Errors * 1000000000) / (8 * (1 << 8));
} else if (Errors <= 42) {
temporary = (Errors * 100000000) / (8 * (1 << 8));
temporary = temporary * 10;
} else if (Errors <= 429) {
temporary = (Errors * 10000000) / (8 * (1 << 8));
temporary = temporary * 100;
} else if (Errors <= 4294) {
temporary = (Errors * 1000000) / (8 * (1 << 8));
temporary = temporary * 1000;
} else if (Errors <= 42949) {
temporary = (Errors * 100000) / (8 * (1 << 8));
temporary = temporary * 10000;
} else {
temporary = (Errors * 10000) / (8 * (1 << 8));
temporary = temporary * 100000;
}
if (def == 2)
Per = temporary;
else if (def == 3)
Per = temporary / 4;
else if (def == 4)
Per = temporary / 16;
else if (def == 5)
Per = temporary / 64;
else if (def == 6)
Per = temporary / 256;
else
Per = 0;
}
ter_state->pPER = Per;
return Per;
}
#endif
static int stv0367_get_tune_settings(struct dvb_frontend *fe,
struct dvb_frontend_tune_settings
*fe_tune_settings)
{ … }
static void stv0367_release(struct dvb_frontend *fe)
{ … }
static const struct dvb_frontend_ops stv0367ter_ops = …;
struct dvb_frontend *stv0367ter_attach(const struct stv0367_config *config,
struct i2c_adapter *i2c)
{ … }
EXPORT_SYMBOL_GPL(…);
static int stv0367cab_gate_ctrl(struct dvb_frontend *fe, int enable)
{ … }
static u32 stv0367cab_get_mclk(struct dvb_frontend *fe, u32 ExtClk_Hz)
{ … }
static u32 stv0367cab_get_adc_freq(struct dvb_frontend *fe, u32 ExtClk_Hz)
{ … }
static enum stv0367cab_mod stv0367cab_SetQamSize(struct stv0367_state *state,
u32 SymbolRate,
enum stv0367cab_mod QAMSize)
{ … }
static u32 stv0367cab_set_derot_freq(struct stv0367_state *state,
u32 adc_hz, s32 derot_hz)
{ … }
static u32 stv0367cab_get_derot_freq(struct stv0367_state *state, u32 adc_hz)
{ … }
static u32 stv0367cab_set_srate(struct stv0367_state *state, u32 adc_hz,
u32 mclk_hz, u32 SymbolRate,
enum stv0367cab_mod QAMSize)
{ … }
static u32 stv0367cab_GetSymbolRate(struct stv0367_state *state, u32 mclk_hz)
{ … }
static u32 stv0367cab_fsm_status(struct stv0367_state *state)
{ … }
static u32 stv0367cab_qamfec_lock(struct stv0367_state *state)
{ … }
static
enum stv0367_cab_signal_type stv0367cab_fsm_signaltype(u32 qam_fsm_status)
{ … }
static int stv0367cab_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{ … }
static int stv0367cab_standby(struct dvb_frontend *fe, u8 standby_on)
{ … }
static int stv0367cab_sleep(struct dvb_frontend *fe)
{ … }
static int stv0367cab_init(struct dvb_frontend *fe)
{ … }
static
enum stv0367_cab_signal_type stv0367cab_algo(struct stv0367_state *state,
struct dtv_frontend_properties *p)
{ … }
static int stv0367cab_set_frontend(struct dvb_frontend *fe)
{ … }
static int stv0367cab_get_frontend(struct dvb_frontend *fe,
struct dtv_frontend_properties *p)
{ … }
#if 0
void stv0367cab_GetErrorCount(state, enum stv0367cab_mod QAMSize,
u32 symbol_rate, FE_367qam_Monitor *Monitor_results)
{
stv0367cab_OptimiseNByteAndGetBER(state, QAMSize, symbol_rate, Monitor_results);
stv0367cab_GetPacketsCount(state, Monitor_results);
return;
}
static int stv0367cab_read_ber(struct dvb_frontend *fe, u32 *ber)
{
struct stv0367_state *state = fe->demodulator_priv;
return 0;
}
#endif
static s32 stv0367cab_get_rf_lvl(struct stv0367_state *state)
{ … }
static int stv0367cab_read_strength(struct dvb_frontend *fe, u16 *strength)
{ … }
static int stv0367cab_snr_power(struct dvb_frontend *fe)
{ … }
static int stv0367cab_snr_readreg(struct dvb_frontend *fe, int avgdiv)
{ … }
static int stv0367cab_read_snr(struct dvb_frontend *fe, u16 *snr)
{ … }
static int stv0367cab_read_ucblcks(struct dvb_frontend *fe, u32 *ucblocks)
{
struct stv0367_state *state = fe->demodulator_priv;
int corrected, tscount;
*ucblocks = (stv0367_readreg(state, R367CAB_RS_COUNTER_5) << 8)
| stv0367_readreg(state, R367CAB_RS_COUNTER_4);
corrected = (stv0367_readreg(state, R367CAB_RS_COUNTER_3) << 8)
| stv0367_readreg(state, R367CAB_RS_COUNTER_2);
tscount = (stv0367_readreg(state, R367CAB_RS_COUNTER_2) << 8)
| stv0367_readreg(state, R367CAB_RS_COUNTER_1);
dprintk("%s: uncorrected blocks=%d corrected blocks=%d tscount=%d\n",
__func__, *ucblocks, corrected, tscount);
return 0;
};
static const struct dvb_frontend_ops stv0367cab_ops = …;
struct dvb_frontend *stv0367cab_attach(const struct stv0367_config *config,
struct i2c_adapter *i2c)
{ … }
EXPORT_SYMBOL_GPL(…);
static void stv0367ddb_setup_ter(struct stv0367_state *state)
{ … }
static void stv0367ddb_setup_cab(struct stv0367_state *state)
{ … }
static int stv0367ddb_set_frontend(struct dvb_frontend *fe)
{ … }
static void stv0367ddb_read_signal_strength(struct dvb_frontend *fe)
{ … }
static void stv0367ddb_read_snr(struct dvb_frontend *fe)
{ … }
static void stv0367ddb_read_ucblocks(struct dvb_frontend *fe)
{ … }
static int stv0367ddb_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{ … }
static int stv0367ddb_get_frontend(struct dvb_frontend *fe,
struct dtv_frontend_properties *p)
{ … }
static int stv0367ddb_sleep(struct dvb_frontend *fe)
{ … }
static int stv0367ddb_init(struct stv0367_state *state)
{ … }
static const struct dvb_frontend_ops stv0367ddb_ops = …;
struct dvb_frontend *stv0367ddb_attach(const struct stv0367_config *config,
struct i2c_adapter *i2c)
{ … }
EXPORT_SYMBOL_GPL(…);
MODULE_PARM_DESC(…) …;
MODULE_PARM_DESC(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;