]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/dvb/frontends/tda827x.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-2.6-omap-h63xx.git] / drivers / media / dvb / frontends / tda827x.c
index 6de1aea02d5148f4c1b340141305eed68170c191..229b11987a589fed652c00934c91101f59867eeb 100644 (file)
@@ -38,10 +38,57 @@ struct tda827x_priv {
        int i2c_addr;
        struct i2c_adapter *i2c_adap;
        struct tda827x_config *cfg;
+
+       unsigned int sgIF;
+       unsigned char lpsel;
+
        u32 frequency;
        u32 bandwidth;
 };
 
+static void tda827x_set_std(struct dvb_frontend *fe,
+                           struct analog_parameters *params)
+{
+       struct tda827x_priv *priv = fe->tuner_priv;
+       char *mode;
+
+       priv->lpsel = 0;
+       if (params->std & V4L2_STD_MN) {
+               priv->sgIF = 92;
+               priv->lpsel = 1;
+               mode = "MN";
+       } else if (params->std & V4L2_STD_B) {
+               priv->sgIF = 108;
+               mode = "B";
+       } else if (params->std & V4L2_STD_GH) {
+               priv->sgIF = 124;
+               mode = "GH";
+       } else if (params->std & V4L2_STD_PAL_I) {
+               priv->sgIF = 124;
+               mode = "I";
+       } else if (params->std & V4L2_STD_DK) {
+               priv->sgIF = 124;
+               mode = "DK";
+       } else if (params->std & V4L2_STD_SECAM_L) {
+               priv->sgIF = 124;
+               mode = "L";
+       } else if (params->std & V4L2_STD_SECAM_LC) {
+               priv->sgIF = 20;
+               mode = "LC";
+       } else {
+               priv->sgIF = 124;
+               mode = "xx";
+       }
+
+       if (params->mode == V4L2_TUNER_RADIO)
+               priv->sgIF = 88; /* if frequency is 5.5 MHz */
+
+       dprintk("setting tda827x to system %s\n", mode);
+}
+
+
+/* ------------------------------------------------------------------ */
+
 struct tda827x_data {
        u32 lomax;
        u8  spd;
@@ -189,10 +236,12 @@ static int tda827xo_set_analog_params(struct dvb_frontend *fe,
        struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0 };
        unsigned int freq = params->frequency;
 
+       tda827x_set_std(fe, params);
+
        if (params->mode == V4L2_TUNER_RADIO)
                freq = freq / 1000;
 
-       N = freq + priv->cfg->sgIF;
+       N = freq + priv->sgIF;
 
        i = 0;
        while (tda827x_table[i].lomax < N * 62500) {
@@ -207,7 +256,7 @@ static int tda827xo_set_analog_params(struct dvb_frontend *fe,
        tuner_reg[1] = (unsigned char)(N>>8);
        tuner_reg[2] = (unsigned char) N;
        tuner_reg[3] = 0x40;
-       tuner_reg[4] = 0x52 + (priv->cfg->tda827x_lpsel << 5);
+       tuner_reg[4] = 0x52 + (priv->lpsel << 5);
        tuner_reg[5] = (tda827x_table[i].spd    << 6) +
                       (tda827x_table[i].div1p5 << 5) +
                       (tda827x_table[i].bs     << 3) + tda827x_table[i].bp;
@@ -507,6 +556,11 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
        struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
                               .buf = buf, .len = sizeof(buf) };
 
+       if (NULL == priv->cfg) {
+               dprintk("tda827x_config not defined, cannot set LNA gain!\n");
+               return;
+       }
+
        if (priv->cfg->config) {
                if (high)
                        dprintk("setting LNA to high gain\n");
@@ -550,13 +604,15 @@ static int tda827xa_set_analog_params(struct dvb_frontend *fe,
                               .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->cfg->sgIF;
+       N = freq + priv->sgIF;
 
        i = 0;
        while (tda827xa_analog[i].lomax < N * 62500) {
@@ -587,7 +643,7 @@ static int tda827xa_set_analog_params(struct dvb_frontend *fe,
        tuner_reg[1] = 0xff;
        tuner_reg[2] = 0xe0;
        tuner_reg[3] = 0;
-       tuner_reg[4] = 0x99 + (priv->cfg->tda827x_lpsel << 1);
+       tuner_reg[4] = 0x99 + (priv->lpsel << 1);
        msg.len = 5;
        i2c_transfer(priv->i2c_adap, &msg, 1);
 
@@ -627,7 +683,7 @@ static int tda827xa_set_analog_params(struct dvb_frontend *fe,
        i2c_transfer(priv->i2c_adap, &msg, 1);
 
        tuner_reg[0] = 0xc0;
-       tuner_reg[1] = 0x19 + (priv->cfg->tda827x_lpsel << 1);
+       tuner_reg[1] = 0x19 + (priv->lpsel << 1);
        i2c_transfer(priv->i2c_adap, &msg, 1);
 
        priv->frequency = freq * 62500;
@@ -745,11 +801,13 @@ static int tda827x_probe_version(struct dvb_frontend *fe)
                dprintk("tda827x tuner found\n");
                fe->ops.tuner_ops.init  = tda827x_init;
                fe->ops.tuner_ops.sleep = tda827xo_sleep;
-               priv->cfg->agcf = tda827xo_agcf;
+               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));
-               priv->cfg->agcf = tda827xa_agcf;
+               if (priv->cfg)
+                       priv->cfg->agcf = tda827xa_agcf;
        }
        return 0;
 }