Exemple #1
0
struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
                                      struct i2c_adapter* i2c_adap,
                                      u8 i2c_addr)
{
    struct microtune_priv *priv = NULL;
    char *name;
    unsigned char buf[21];
    int company_code;

    priv = kzalloc(sizeof(struct microtune_priv), GFP_KERNEL);
    if (priv == NULL)
        return NULL;
    fe->tuner_priv = priv;

    priv->i2c_props.addr = i2c_addr;
    priv->i2c_props.adap = i2c_adap;
    priv->i2c_props.name = "mt20xx";

    //priv->radio_if2 = 10700 * 1000;	/* 10.7MHz - FM radio */

    memset(buf,0,sizeof(buf));

    name = "unknown";

    tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
    tuner_i2c_xfer_recv(&priv->i2c_props,buf,21);
    if (debug)
        tuner_dbg("MT20xx hexdump: %*ph\n", 21, buf);

    company_code = buf[0x11] << 8 | buf[0x12];
    tuner_info("microtune: companycode=%04x part=%02x rev=%02x\n",
               company_code,buf[0x13],buf[0x14]);


    if (buf[0x13] < ARRAY_SIZE(microtune_part) &&
            NULL != microtune_part[buf[0x13]])
        name = microtune_part[buf[0x13]];
    switch (buf[0x13]) {
    case MT2032:
        mt2032_init(fe);
        break;
    case MT2050:
        mt2050_init(fe);
        break;
    default:
        tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n",
                   name);
        return NULL;
    }

    strlcpy(fe->ops.tuner_ops.info.name, name,
            sizeof(fe->ops.tuner_ops.info.name));
    tuner_info("microtune %s found, OK\n",name);
    return fe;
}
Exemple #2
0
int microtune_init(struct i2c_client *c)
{
	struct tuner *t = i2c_get_clientdata(c);
	char *name;
        unsigned char buf[21];
	int company_code;

	memset(buf,0,sizeof(buf));
	t->tv_freq    = NULL;
	t->radio_freq = NULL;
	t->standby    = NULL;
	name = "unknown";

        i2c_master_send(c,buf,1);
        i2c_master_recv(c,buf,21);
        if (tuner_debug) {
                int i;
		tuner_dbg("MT20xx hexdump:");
                for(i=0;i<21;i++) {
                        printk(" %02x",buf[i]);
                        if(((i+1)%8)==0) printk(" ");
                }
                printk("\n");
        }
	company_code = buf[0x11] << 8 | buf[0x12];
	tuner_info("microtune: companycode=%04x part=%02x rev=%02x\n",
		   company_code,buf[0x13],buf[0x14]);


	if (buf[0x13] < ARRAY_SIZE(microtune_part) &&
	    NULL != microtune_part[buf[0x13]])
		name = microtune_part[buf[0x13]];
	switch (buf[0x13]) {
	case MT2032:
		mt2032_init(c);
		break;
	case MT2050:
		mt2050_init(c);
		break;
	default:
		tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n",
			   name);
                return 0;
        }

	strlcpy(c->name, name, sizeof(c->name));
	tuner_info("microtune %s found, OK\n",name);
	return 0;
}
Exemple #3
0
static int mt2032_compute_freq(struct dvb_frontend *fe,
			       unsigned int rfin,
			       unsigned int if1, unsigned int if2,
			       unsigned int spectrum_from,
			       unsigned int spectrum_to,
			       unsigned char *buf,
			       int *ret_sel,
			       unsigned int xogc) //all in Hz
{
	struct microtune_priv *priv = fe->tuner_priv;
	unsigned int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1,
		desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq;

	fref= 5250 *1000; //5.25MHz
	desired_lo1=rfin+if1;

	lo1=(2*(desired_lo1/1000)+(fref/1000)) / (2*fref/1000);
	lo1n=lo1/8;
	lo1a=lo1-(lo1n*8);

	s=rfin/1000/1000+1090;

	if(optimize_vco) {
		if(s>1890) sel=0;
		else if(s>1720) sel=1;
		else if(s>1530) sel=2;
		else if(s>1370) sel=3;
		else sel=4; // >1090
	}
	else {
		if(s>1790) sel=0; // <1958
		else if(s>1617) sel=1;
		else if(s>1449) sel=2;
		else if(s>1291) sel=3;
		else sel=4; // >1090
	}
	*ret_sel=sel;

	lo1freq=(lo1a+8*lo1n)*fref;

	tuner_dbg("mt2032: rfin=%d lo1=%d lo1n=%d lo1a=%d sel=%d, lo1freq=%d\n",
		  rfin,lo1,lo1n,lo1a,sel,lo1freq);

	desired_lo2=lo1freq-rfin-if2;
	lo2=(desired_lo2)/fref;
	lo2n=lo2/8;
	lo2a=lo2-(lo2n*8);
	lo2num=((desired_lo2/1000)%(fref/1000))* 3780/(fref/1000); //scale to fit in 32bit arith
	lo2freq=(lo2a+8*lo2n)*fref + lo2num*(fref/1000)/3780*1000;

	tuner_dbg("mt2032: rfin=%d lo2=%d lo2n=%d lo2a=%d num=%d lo2freq=%d\n",
		  rfin,lo2,lo2n,lo2a,lo2num,lo2freq);

	if (lo1a > 7 || lo1n < 17 || lo1n > 48 || lo2a > 7 || lo2n < 17 ||
			lo2n > 30) {
		tuner_info("mt2032: frequency parameters out of range: %d %d %d %d\n",
			   lo1a, lo1n, lo2a,lo2n);
		return(-1);
	}

	mt2032_spurcheck(fe, lo1freq, desired_lo2,  spectrum_from, spectrum_to);
	// should recalculate lo1 (one step up/down)

	// set up MT2032 register map for transfer over i2c
	buf[0]=lo1n-1;
	buf[1]=lo1a | (sel<<4);
	buf[2]=0x86; // LOGC
	buf[3]=0x0f; //reserved
	buf[4]=0x1f;
	buf[5]=(lo2n-1) | (lo2a<<5);
	if(rfin >400*1000*1000)
		buf[6]=0xe4;
	else
		buf[6]=0xf4; // set PKEN per rev 1.2
	buf[7]=8+xogc;
	buf[8]=0xc3; //reserved
	buf[9]=0x4e; //reserved
	buf[10]=0xec; //reserved
	buf[11]=(lo2num&0xff);
	buf[12]=(lo2num>>8) |0x80; // Lo2RST

	return 0;
}
struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
				    struct i2c_adapter *i2c_adap, u8 i2c_addr,
				    struct tda829x_config *cfg)
{
	struct tda8290_priv *priv = NULL;
	char *name;

	priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
	if (priv == NULL)
		return NULL;
	fe->analog_demod_priv = priv;

	priv->i2c_props.addr     = i2c_addr;
	priv->i2c_props.adap     = i2c_adap;
	priv->i2c_props.name     = "tda829x";
	if (cfg)
		priv->cfg.config         = cfg->lna_cfg;

	if (tda8290_probe(&priv->i2c_props) == 0) {
		priv->ver = TDA8290;
		memcpy(&fe->ops.analog_ops, &tda8290_ops,
		       sizeof(struct analog_demod_ops));
	}

	if (tda8295_probe(&priv->i2c_props) == 0) {
		priv->ver = TDA8295;
		memcpy(&fe->ops.analog_ops, &tda8295_ops,
		       sizeof(struct analog_demod_ops));
	}

	if ((!(cfg) || (TDA829X_PROBE_TUNER == cfg->probe_tuner)) &&
	    (tda829x_find_tuner(fe) < 0))
		goto fail;

	switch (priv->ver) {
	case TDA8290:
		name = "tda8290";
		break;
	case TDA8295:
		name = "tda8295";
		break;
	case TDA8290 | TDA8275:
		name = "tda8290+75";
		break;
	case TDA8295 | TDA8275:
		name = "tda8295+75";
		break;
	case TDA8290 | TDA8275A:
		name = "tda8290+75a";
		break;
	case TDA8295 | TDA8275A:
		name = "tda8295+75a";
		break;
	case TDA8290 | TDA18271:
		name = "tda8290+18271";
		break;
	case TDA8295 | TDA18271:
		name = "tda8295+18271";
		break;
	default:
		goto fail;
	}
	tuner_info("type set to %s\n", name);

	fe->ops.analog_ops.info.name = name;

	if (priv->ver & TDA8290) {
		if (priv->ver & (TDA8275 | TDA8275A))
			tda8290_init_tuner(fe);
		tda8290_init_if(fe);
	} else if (priv->ver & TDA8295)
		tda8295_init_if(fe);

	return fe;

fail:
	tda829x_release(fe);
	return NULL;
}
static void tda8290_init_tuner(struct dvb_frontend *fe)
{
	struct tda8290_priv *priv = fe->analog_demod_priv;
	unsigned char tda8275_init[]  = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
					  0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
	unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
					  0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
	struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
			      .buf=tda8275_init, .len = 14};
	if (priv->ver & TDA8275A)
		msg.buf = tda8275a_init;

	tda8290_i2c_bridge(fe, 1);
	i2c_transfer(priv->i2c_props.adap, &msg, 1);
	tda8290_i2c_bridge(fe, 0);
}

/*---------------------------------------------------------------------*/

static void tda829x_release(struct dvb_frontend *fe)
{
	struct tda8290_priv *priv = fe->analog_demod_priv;

	/* only try to release the tuner if we've
	 * attached it from within this module */
	if (priv->ver & (TDA18271 | TDA8275 | TDA8275A))
		if (fe->ops.tuner_ops.release)
			fe->ops.tuner_ops.release(fe);

	kfree(fe->analog_demod_priv);
	fe->analog_demod_priv = NULL;
}

static struct tda18271_config tda829x_tda18271_config = {
	.gate    = TDA18271_GATE_ANALOG,
};

static int tda829x_find_tuner(struct dvb_frontend *fe)
{
	struct tda8290_priv *priv = fe->analog_demod_priv;
	struct analog_demod_ops *analog_ops = &fe->ops.analog_ops;
	int i, ret, tuners_found;
	u32 tuner_addrs;
	u8 data;
	struct i2c_msg msg = { .flags = I2C_M_RD, .buf = &data, .len = 1 };

	if (!analog_ops->i2c_gate_ctrl) {
		printk(KERN_ERR "tda8290: no gate control were provided!\n");

		return -EINVAL;
	}

	analog_ops->i2c_gate_ctrl(fe, 1);

	/* probe for tuner chip */
	tuners_found = 0;
	tuner_addrs = 0;
	for (i = 0x60; i <= 0x63; i++) {
		msg.addr = i;
		ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
		if (ret == 1) {
			tuners_found++;
			tuner_addrs = (tuner_addrs << 8) + i;
		}
	}
	/* if there is more than one tuner, we expect the right one is
	   behind the bridge and we choose the highest address that doesn't
	   give a response now
	 */

	analog_ops->i2c_gate_ctrl(fe, 0);

	if (tuners_found > 1)
		for (i = 0; i < tuners_found; i++) {
			msg.addr = tuner_addrs  & 0xff;
			ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
			if (ret == 1)
				tuner_addrs = tuner_addrs >> 8;
			else
				break;
		}

	if (tuner_addrs == 0) {
		tuner_addrs = 0x60;
		tuner_info("could not clearly identify tuner address, "
			   "defaulting to %x\n", tuner_addrs);
	} else {
		tuner_addrs = tuner_addrs & 0xff;
		tuner_info("setting tuner address to %x\n", tuner_addrs);
	}
	priv->tda827x_addr = tuner_addrs;
	msg.addr = tuner_addrs;

	analog_ops->i2c_gate_ctrl(fe, 1);
	ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);

	if (ret != 1) {
		tuner_warn("tuner access failed!\n");
		analog_ops->i2c_gate_ctrl(fe, 0);
		return -EREMOTEIO;
	}

	if ((data == 0x83) || (data == 0x84)) {
		priv->ver |= TDA18271;
		tda829x_tda18271_config.config = priv->cfg.config;
		dvb_attach(tda18271_attach, fe, priv->tda827x_addr,
			   priv->i2c_props.adap, &tda829x_tda18271_config);
	} else {
		if ((data & 0x3c) == 0)
			priv->ver |= TDA8275;
		else
			priv->ver |= TDA8275A;

		dvb_attach(tda827x_attach, fe, priv->tda827x_addr,
			   priv->i2c_props.adap, &priv->cfg);
		priv->cfg.switch_addr = priv->i2c_props.addr;
	}
	if (fe->ops.tuner_ops.init)
		fe->ops.tuner_ops.init(fe);

	if (fe->ops.tuner_ops.sleep)
		fe->ops.tuner_ops.sleep(fe);

	analog_ops->i2c_gate_ctrl(fe, 0);

	return 0;
}

static int tda8290_probe(struct tuner_i2c_props *i2c_props)
{
#define TDA8290_ID 0x89
	unsigned char tda8290_id[] = { 0x1f, 0x00 };

	/* detect tda8290 */
	tuner_i2c_xfer_send(i2c_props, &tda8290_id[0], 1);
	tuner_i2c_xfer_recv(i2c_props, &tda8290_id[1], 1);

	if (tda8290_id[1] == TDA8290_ID) {
		if (debug)
			printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
			       __func__, i2c_adapter_id(i2c_props->adap),
			       i2c_props->addr);
		return 0;
	}

	return -ENODEV;
}