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

📄 stv0299.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
	reg0x0c = stv0299_readreg (state, 0x0c);	/**	 *  H/V switching over OP0, OP1 and OP2 are LNB power enable bits	 */	reg0x0c &= 0x0f;	if (voltage == SEC_VOLTAGE_OFF) {		stv0299_writeregI (state, 0x0c, 0x00); /*	LNB power off! */		return stv0299_writeregI (state, 0x08, 0x00); /*	LNB power off! */	}	stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6));	switch (voltage) {	case SEC_VOLTAGE_13:		if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0) reg0x0c |= 0x10;		else reg0x0c |= 0x40;		return stv0299_writeregI(state, 0x0c, reg0x0c);	case SEC_VOLTAGE_18:		return stv0299_writeregI(state, 0x0c, reg0x0c | 0x50);	default:		return -EINVAL;	};}static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, u32 cmd){	struct stv0299_state* state = fe->demodulator_priv;	u8 reg0x08;	u8 reg0x0c;	u8 lv_mask = 0x40;	u8 last = 1;	int i;	struct timeval nexttime;	struct timeval tv[10];	reg0x08 = stv0299_readreg (state, 0x08);	reg0x0c = stv0299_readreg (state, 0x0c);	reg0x0c &= 0x0f;	stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6));	if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0)		lv_mask = 0x10;	cmd = cmd << 1;	if (debug_legacy_dish_switch)		printk ("%s switch command: 0x%04x\n",__FUNCTION__, cmd);	do_gettimeofday (&nexttime);	if (debug_legacy_dish_switch)		memcpy (&tv[0], &nexttime, sizeof (struct timeval));	stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */	dvb_frontend_sleep_until(&nexttime, 32000);	for (i=0; i<9; i++) {		if (debug_legacy_dish_switch)			do_gettimeofday (&tv[i+1]);		if((cmd & 0x01) != last) {			/* set voltage to (last ? 13V : 18V) */			stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50));			last = (last) ? 0 : 1;		}		cmd = cmd >> 1;		if (i != 8)			dvb_frontend_sleep_until(&nexttime, 8000);	}	if (debug_legacy_dish_switch) {		printk ("%s(%d): switch delay (should be 32k followed by all 8k\n",			__FUNCTION__, fe->dvb->num);		for (i = 1; i < 10; i++)			printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));	}	return 0;}static int stv0299_init (struct dvb_frontend* fe){	struct stv0299_state* state = fe->demodulator_priv;	int i;	dprintk("stv0299: init chip\n");	for (i=0; !(state->config->inittab[i] == 0xff && state->config->inittab[i+1] == 0xff); i+=2)		stv0299_writeregI(state, state->config->inittab[i], state->config->inittab[i+1]);	if (state->config->pll_init) {		stv0299_writeregI(state, 0x05, 0xb5);	/*  enable i2c repeater on stv0299  */		state->config->pll_init(fe, state->i2c);		stv0299_writeregI(state, 0x05, 0x35);	/*  disable i2c repeater on stv0299  */	}	return 0;}static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status){	struct stv0299_state* state = fe->demodulator_priv;	u8 signal = 0xff - stv0299_readreg (state, 0x18);	u8 sync = stv0299_readreg (state, 0x1b);	dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __FUNCTION__, sync);	*status = 0;	if (signal > 10)		*status |= FE_HAS_SIGNAL;	if (sync & 0x80)		*status |= FE_HAS_CARRIER;	if (sync & 0x10)		*status |= FE_HAS_VITERBI;	if (sync & 0x08)		*status |= FE_HAS_SYNC;	if ((sync & 0x98) == 0x98)		*status |= FE_HAS_LOCK;	return 0;}static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber){	struct stv0299_state* state = fe->demodulator_priv;	if (state->errmode != STATUS_BER) return 0;	*ber = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);	return 0;}static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength){	struct stv0299_state* state = fe->demodulator_priv;	s32 signal =  0xffff - ((stv0299_readreg (state, 0x18) << 8)			       | stv0299_readreg (state, 0x19));	dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __FUNCTION__,		 stv0299_readreg (state, 0x18),		 stv0299_readreg (state, 0x19), (int) signal);	signal = signal * 5 / 4;	*strength = (signal > 0xffff) ? 0xffff : (signal < 0) ? 0 : signal;	return 0;}static int stv0299_read_snr(struct dvb_frontend* fe, u16* snr){	struct stv0299_state* state = fe->demodulator_priv;	s32 xsnr = 0xffff - ((stv0299_readreg (state, 0x24) << 8)			   | stv0299_readreg (state, 0x25));	xsnr = 3 * (xsnr - 0xa100);	*snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr;	return 0;}static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks){	struct stv0299_state* state = fe->demodulator_priv;	if (state->errmode != STATUS_UCBLOCKS) *ucblocks = 0;	else *ucblocks = (stv0299_readreg (state, 0x1d) << 8) | stv0299_readreg (state, 0x1e);	return 0;}static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p){	struct stv0299_state* state = fe->demodulator_priv;	int invval = 0;	dprintk ("%s : FE_SET_FRONTEND\n", __FUNCTION__);	// set the inversion	if (p->inversion == INVERSION_OFF) invval = 0;	else if (p->inversion == INVERSION_ON) invval = 1;	else {		printk("stv0299 does not support auto-inversion\n");		return -EINVAL;	}	if (state->config->invert) invval = (~invval) & 1;	stv0299_writeregI(state, 0x0c, (stv0299_readreg(state, 0x0c) & 0xfe) | invval);	stv0299_writeregI(state, 0x05, 0xb5);	/*  enable i2c repeater on stv0299  */	state->config->pll_set(fe, state->i2c, p);	stv0299_writeregI(state, 0x05, 0x35);	/*  disable i2c repeater on stv0299  */	stv0299_set_FEC (state, p->u.qpsk.fec_inner);	stv0299_set_symbolrate (fe, p->u.qpsk.symbol_rate);	stv0299_writeregI(state, 0x22, 0x00);	stv0299_writeregI(state, 0x23, 0x00);	state->tuner_frequency = p->frequency;	state->fec_inner = p->u.qpsk.fec_inner;	state->symbol_rate = p->u.qpsk.symbol_rate;	return 0;}static int stv0299_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters * p){	struct stv0299_state* state = fe->demodulator_priv;	s32 derot_freq;	int invval;	derot_freq = (s32)(s16) ((stv0299_readreg (state, 0x22) << 8)				| stv0299_readreg (state, 0x23));	derot_freq *= (state->config->mclk >> 16);	derot_freq += 500;	derot_freq /= 1000;	p->frequency += derot_freq;	invval = stv0299_readreg (state, 0x0c) & 1;	if (state->config->invert) invval = (~invval) & 1;	p->inversion = invval ? INVERSION_ON : INVERSION_OFF;	p->u.qpsk.fec_inner = stv0299_get_fec (state);	p->u.qpsk.symbol_rate = stv0299_get_symbolrate (state);	return 0;}static int stv0299_sleep(struct dvb_frontend* fe){	struct stv0299_state* state = fe->demodulator_priv;	stv0299_writeregI(state, 0x02, 0x80);	state->initialised = 0;	return 0;}static int stv0299_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings){	struct stv0299_state* state = fe->demodulator_priv;	fesettings->min_delay_ms = state->config->min_delay_ms;	if (fesettings->parameters.u.qpsk.symbol_rate < 10000000) {		fesettings->step_size = fesettings->parameters.u.qpsk.symbol_rate / 32000;		fesettings->max_drift = 5000;	} else {		fesettings->step_size = fesettings->parameters.u.qpsk.symbol_rate / 16000;		fesettings->max_drift = fesettings->parameters.u.qpsk.symbol_rate / 2000;	}	return 0;}static void stv0299_release(struct dvb_frontend* fe){	struct stv0299_state* state = fe->demodulator_priv;	kfree(state);}static struct dvb_frontend_ops stv0299_ops;struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,				    struct i2c_adapter* i2c){	struct stv0299_state* state = NULL;	int id;	/* allocate memory for the internal state */	state = kmalloc(sizeof(struct stv0299_state), GFP_KERNEL);	if (state == NULL) goto error;	/* setup the state */	state->config = config;	state->i2c = i2c;	memcpy(&state->ops, &stv0299_ops, sizeof(struct dvb_frontend_ops));	state->initialised = 0;	state->tuner_frequency = 0;	state->symbol_rate = 0;	state->fec_inner = 0;	state->errmode = STATUS_BER;	/* check if the demod is there */	stv0299_writeregI(state, 0x02, 0x34); /* standby off */	msleep(200);	id = stv0299_readreg(state, 0x00);	/* register 0x00 contains 0xa1 for STV0299 and STV0299B */	/* register 0x00 might contain 0x80 when returning from standby */	if (id != 0xa1 && id != 0x80) goto error;	/* create dvb_frontend */	state->frontend.ops = &state->ops;	state->frontend.demodulator_priv = state;	return &state->frontend;error:	kfree(state);	return NULL;}static struct dvb_frontend_ops stv0299_ops = {	.info = {		.name			= "ST STV0299 DVB-S",		.type			= FE_QPSK,		.frequency_min		= 950000,		.frequency_max		= 2150000,		.frequency_stepsize	= 125,	 /* kHz for QPSK frontends */		.frequency_tolerance	= 0,		.symbol_rate_min	= 1000000,		.symbol_rate_max	= 45000000,		.symbol_rate_tolerance	= 500,	/* ppm */		.caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |		      FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |		      FE_CAN_QPSK |		      FE_CAN_FEC_AUTO	},	.release = stv0299_release,	.init = stv0299_init,	.sleep = stv0299_sleep,	.set_frontend = stv0299_set_frontend,	.get_frontend = stv0299_get_frontend,	.get_tune_settings = stv0299_get_tune_settings,	.read_status = stv0299_read_status,	.read_ber = stv0299_read_ber,	.read_signal_strength = stv0299_read_signal_strength,	.read_snr = stv0299_read_snr,	.read_ucblocks = stv0299_read_ucblocks,	.diseqc_send_master_cmd = stv0299_send_diseqc_msg,	.diseqc_send_burst = stv0299_send_diseqc_burst,	.set_tone = stv0299_set_tone,	.set_voltage = stv0299_set_voltage,	.dishnetwork_send_legacy_command = stv0299_send_legacy_dish_cmd,};module_param(debug_legacy_dish_switch, int, 0444);MODULE_PARM_DESC(debug_legacy_dish_switch, "Enable timing analysis for Dish Network legacy switches");module_param(debug, int, 0644);MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");MODULE_DESCRIPTION("ST STV0299 DVB Demodulator driver");MODULE_AUTHOR("Ralph Metzler, Holger Waechtler, Peter Schildmann, Felix Domke, "	      "Andreas Oberritter, Andrew de Quincey, Kenneth Aafl鴜");MODULE_LICENSE("GPL");EXPORT_SYMBOL(stv0299_writereg);EXPORT_SYMBOL(stv0299_attach);

⌨️ 快捷键说明

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