tda827x.c

来自「trident tm5600的linux驱动」· C语言 代码 · 共 856 行 · 第 1/2 页

C
856
字号
	if (priv->cfg->config) {		if (high)			dprintk("setting LNA to high gain\n");		else			dprintk("setting LNA to low gain\n");	}	switch (priv->cfg->config) {	case 0: /* no LNA */		break;	case 1: /* switch is GPIO 0 of tda8290 */	case 2:		if (params == NULL) {			gp_func = 0;			arg  = 0;		} else {			/* turn Vsync on */			gp_func = 1;			if (params->std & V4L2_STD_MN)				arg = 1;			else				arg = 0;		}		if (fe->callback)			fe->callback(priv->i2c_adap->algo_data,				     DVB_FRONTEND_COMPONENT_TUNER,				     gp_func, arg);		buf[1] = high ? 0 : 1;		if (priv->cfg->config == 2)			buf[1] = high ? 1 : 0;		i2c_transfer(priv->i2c_adap, &msg, 1);		break;	case 3: /* switch with GPIO of saa713x */		if (fe->callback)			fe->callback(priv->i2c_adap->algo_data,				     DVB_FRONTEND_COMPONENT_TUNER, 0, high);		break;	}}static int tda827xa_set_params(struct dvb_frontend *fe,			       struct dvb_frontend_parameters *params){	struct tda827x_priv *priv = fe->tuner_priv;	u8 buf[11];	struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,			       .buf = buf, .len = sizeof(buf) };	int i, tuner_freq, if_freq;	u32 N;	dprintk("%s:\n", __func__);	tda827xa_lna_gain(fe, 1, NULL);	msleep(20);	switch (params->u.ofdm.bandwidth) {	case BANDWIDTH_6_MHZ:		if_freq = 4000000;		break;	case BANDWIDTH_7_MHZ:		if_freq = 4500000;		break;	default:		   /* 8 MHz or Auto */		if_freq = 5000000;		break;	}	tuner_freq = params->frequency + if_freq;	i = 0;	while (tda827xa_dvbt[i].lomax < tuner_freq) {		if(tda827xa_dvbt[i + 1].lomax == 0)			break;		i++;	}	N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;	buf[0] = 0;            // subaddress	buf[1] = N >> 8;	buf[2] = N & 0xff;	buf[3] = 0;	buf[4] = 0x16;	buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +			tda827xa_dvbt[i].sbs;	buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);	buf[7] = 0x1c;	buf[8] = 0x06;	buf[9] = 0x24;	buf[10] = 0x00;	msg.len = 11;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {		printk("%s: could not write to tuner at addr: 0x%02x\n",		       __func__, priv->i2c_addr << 1);		return -EIO;	}	buf[0] = 0x90;	buf[1] = 0xff;	buf[2] = 0x60;	buf[3] = 0x00;	buf[4] = 0x59;  // lpsel, for 6MHz + 2	msg.len = 5;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	buf[0] = 0xa0;	buf[1] = 0x40;	msg.len = 2;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	msleep(11);	msg.flags = I2C_M_RD;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	msg.flags = 0;	buf[1] >>= 4;	dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);	if ((buf[1]) < 2) {		tda827xa_lna_gain(fe, 0, NULL);		buf[0] = 0x60;		buf[1] = 0x0c;		if (fe->ops.i2c_gate_ctrl)			fe->ops.i2c_gate_ctrl(fe, 1);		i2c_transfer(priv->i2c_adap, &msg, 1);	}	buf[0] = 0xc0;	buf[1] = 0x99;    // lpsel, for 6MHz + 2	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	buf[0] = 0x60;	buf[1] = 0x3c;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	/* correct CP value */	buf[0] = 0x30;	buf[1] = 0x10 + tda827xa_dvbt[i].scr;	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	msleep(163);	buf[0] = 0xc0;	buf[1] = 0x39;  // lpsel, for 6MHz + 2	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	msleep(3);	/* freeze AGC1 */	buf[0] = 0x50;	buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	priv->frequency = tuner_freq - if_freq; // FIXME	priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;	return 0;}static int tda827xa_set_analog_params(struct dvb_frontend *fe,				      struct analog_parameters *params){	unsigned char tuner_reg[11];	u32 N;	int i;	struct tda827x_priv *priv = fe->tuner_priv;	struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,			       .buf = tuner_reg, .len = sizeof(tuner_reg) };	unsigned int freq = params->frequency;	tda827x_set_std(fe, params);	tda827xa_lna_gain(fe, 1, params);	msleep(10);	if (params->mode == V4L2_TUNER_RADIO)		freq = freq / 1000;	N = freq + priv->sgIF;	i = 0;	while (tda827xa_analog[i].lomax < N * 62500) {		if (tda827xa_analog[i + 1].lomax == 0)			break;		i++;	}	N = N << tda827xa_analog[i].spd;	tuner_reg[0] = 0;	tuner_reg[1] = (unsigned char)(N>>8);	tuner_reg[2] = (unsigned char) N;	tuner_reg[3] = 0;	tuner_reg[4] = 0x16;	tuner_reg[5] = (tda827xa_analog[i].spd << 5) +		       (tda827xa_analog[i].svco << 3) +			tda827xa_analog[i].sbs;	tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);	tuner_reg[7] = 0x1c;	tuner_reg[8] = 4;	tuner_reg[9] = 0x20;	tuner_reg[10] = 0x00;	msg.len = 11;	i2c_transfer(priv->i2c_adap, &msg, 1);	tuner_reg[0] = 0x90;	tuner_reg[1] = 0xff;	tuner_reg[2] = 0xe0;	tuner_reg[3] = 0;	tuner_reg[4] = 0x99 + (priv->lpsel << 1);	msg.len = 5;	i2c_transfer(priv->i2c_adap, &msg, 1);	tuner_reg[0] = 0xa0;	tuner_reg[1] = 0xc0;	msg.len = 2;	i2c_transfer(priv->i2c_adap, &msg, 1);	tuner_reg[0] = 0x30;	tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;	i2c_transfer(priv->i2c_adap, &msg, 1);	msg.flags = I2C_M_RD;	i2c_transfer(priv->i2c_adap, &msg, 1);	msg.flags = 0;	tuner_reg[1] >>= 4;	dprintk("AGC2 gain is: %d\n", tuner_reg[1]);	if (tuner_reg[1] < 1)		tda827xa_lna_gain(fe, 0, params);	msleep(100);	tuner_reg[0] = 0x60;	tuner_reg[1] = 0x3c;	i2c_transfer(priv->i2c_adap, &msg, 1);	msleep(163);	tuner_reg[0] = 0x50;	tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);	i2c_transfer(priv->i2c_adap, &msg, 1);	tuner_reg[0] = 0x80;	tuner_reg[1] = 0x28;	i2c_transfer(priv->i2c_adap, &msg, 1);	tuner_reg[0] = 0xb0;	tuner_reg[1] = 0x01;	i2c_transfer(priv->i2c_adap, &msg, 1);	tuner_reg[0] = 0xc0;	tuner_reg[1] = 0x19 + (priv->lpsel << 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	priv->frequency = freq * 62500;	return 0;}static void tda827xa_agcf(struct dvb_frontend *fe){	struct tda827x_priv *priv = fe->tuner_priv;	unsigned char data[] = {0x80, 0x2c};	struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,			      .buf = data, .len = 2};	i2c_transfer(priv->i2c_adap, &msg, 1);}/* ------------------------------------------------------------------ */static int tda827x_release(struct dvb_frontend *fe){	kfree(fe->tuner_priv);	fe->tuner_priv = NULL;	return 0;}static int tda827x_get_frequency(struct dvb_frontend *fe, u32 *frequency){	struct tda827x_priv *priv = fe->tuner_priv;	*frequency = priv->frequency;	return 0;}static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth){	struct tda827x_priv *priv = fe->tuner_priv;	*bandwidth = priv->bandwidth;	return 0;}static int tda827x_init(struct dvb_frontend *fe){	struct tda827x_priv *priv = fe->tuner_priv;	dprintk("%s:\n", __func__);	if (priv->cfg && priv->cfg->init)		priv->cfg->init(fe);	return 0;}static int tda827x_probe_version(struct dvb_frontend *fe);static int tda827x_initial_init(struct dvb_frontend *fe){	int ret;	ret = tda827x_probe_version(fe);	if (ret)		return ret;	return fe->ops.tuner_ops.init(fe);}static int tda827x_initial_sleep(struct dvb_frontend *fe){	int ret;	ret = tda827x_probe_version(fe);	if (ret)		return ret;	return fe->ops.tuner_ops.sleep(fe);}static struct dvb_tuner_ops tda827xo_tuner_ops = {	.info = {		.name = "Philips TDA827X",		.frequency_min  =  55000000,		.frequency_max  = 860000000,		.frequency_step =    250000	},	.release = tda827x_release,	.init = tda827x_initial_init,	.sleep = tda827x_initial_sleep,	.set_params = tda827xo_set_params,	.set_analog_params = tda827xo_set_analog_params,	.get_frequency = tda827x_get_frequency,	.get_bandwidth = tda827x_get_bandwidth,};static struct dvb_tuner_ops tda827xa_tuner_ops = {	.info = {		.name = "Philips TDA827XA",		.frequency_min  =  44000000,		.frequency_max  = 906000000,		.frequency_step =     62500	},	.release = tda827x_release,	.init = tda827x_init,	.sleep = tda827xa_sleep,	.set_params = tda827xa_set_params,	.set_analog_params = tda827xa_set_analog_params,	.get_frequency = tda827x_get_frequency,	.get_bandwidth = tda827x_get_bandwidth,};static int tda827x_probe_version(struct dvb_frontend *fe){	u8 data;	struct tda827x_priv *priv = fe->tuner_priv;	struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,			       .buf = &data, .len = 1 };	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {		printk("%s: could not read from tuner at addr: 0x%02x\n",		       __func__, msg.addr << 1);		return -EIO;	}	if ((data & 0x3c) == 0) {		dprintk("tda827x tuner found\n");		fe->ops.tuner_ops.init  = tda827x_init;		fe->ops.tuner_ops.sleep = tda827xo_sleep;		if (priv->cfg)			priv->cfg->agcf = tda827xo_agcf;	} else {		dprintk("tda827xa tuner found\n");		memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));		if (priv->cfg)			priv->cfg->agcf = tda827xa_agcf;	}	return 0;}struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,				    struct i2c_adapter *i2c,				    struct tda827x_config *cfg){	struct tda827x_priv *priv = NULL;	dprintk("%s:\n", __func__);	priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);	if (priv == NULL)		return NULL;	priv->i2c_addr = addr;	priv->i2c_adap = i2c;	priv->cfg = cfg;	memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops));	fe->tuner_priv = priv;	dprintk("type set to %s\n", fe->ops.tuner_ops.info.name);	return fe;}EXPORT_SYMBOL_GPL(tda827x_attach);MODULE_DESCRIPTION("DVB TDA827x driver");MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");MODULE_LICENSE("GPL");/* * Overrides for Emacs so that we follow Linus's tabbing style. * --------------------------------------------------------------------------- * Local variables: * c-basic-offset: 8 * End: */

⌨️ 快捷键说明

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