tda827x.c

来自「linux 内核源代码」· C语言 代码 · 共 513 行 · 第 1/2 页

C
513
字号
	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",		       __FUNCTION__, 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) {		if (priv->cfg && priv->cfg->lna_gain)			priv->cfg->lna_gain(fe, 0);		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_sleep(struct dvb_frontend *fe){	struct tda827x_priv *priv = fe->tuner_priv;	static u8 buf[] = { 0x30, 0x90 };	struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,			       .buf = buf, .len = sizeof(buf) };	dprintk("%s:\n", __FUNCTION__);	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 1);	i2c_transfer(priv->i2c_adap, &msg, 1);	if (fe->ops.i2c_gate_ctrl)		fe->ops.i2c_gate_ctrl(fe, 0);	if (priv->cfg && priv->cfg->sleep)		priv->cfg->sleep(fe);	return 0;}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", __FUNCTION__);	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,	.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,	.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",		       __FUNCTION__, 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;	} else {		dprintk("tda827xa tuner found\n");		memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));	}	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", __FUNCTION__);	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;	return fe;}EXPORT_SYMBOL(tda827x_attach);module_param(debug, int, 0644);MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");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 + -
显示快捷键?