]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/dvb/frontends/tda826x.c
Merge branch 'for-2.6.27' of git://linux-nfs.org/~bfields/linux
[linux-2.6-omap-h63xx.git] / drivers / media / dvb / frontends / tda826x.c
index 34815b0b97e486964641d0337567bda932d691b8..a051554b5e2589aeb32060ebb0a41c1c38b65e84 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "tda826x.h"
 
-static int debug = 0;
+static int debug;
 #define dprintk(args...) \
        do { \
                if (debug) printk(KERN_DEBUG "tda826x: " args); \
@@ -42,8 +42,7 @@ struct tda826x_priv {
 
 static int tda826x_release(struct dvb_frontend *fe)
 {
-       if (fe->tuner_priv)
-               kfree(fe->tuner_priv);
+       kfree(fe->tuner_priv);
        fe->tuner_priv = NULL;
        return 0;
 }
@@ -55,7 +54,7 @@ static int tda826x_sleep(struct dvb_frontend *fe)
        u8 buf [] = { 0x00, 0x8d };
        struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 };
 
-       dprintk("%s:\n", __FUNCTION__);
+       dprintk("%s:\n", __func__);
 
        if (!priv->has_loopthrough)
                buf[1] = 0xad;
@@ -63,7 +62,7 @@ static int tda826x_sleep(struct dvb_frontend *fe)
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 1);
        if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
-               dprintk("%s: i2c error\n", __FUNCTION__);
+               dprintk("%s: i2c error\n", __func__);
        }
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 0);
@@ -76,13 +75,24 @@ static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
        struct tda826x_priv *priv = fe->tuner_priv;
        int ret;
        u32 div;
+       u32 ksyms;
+       u32 bandwidth;
        u8 buf [11];
        struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 };
 
-       dprintk("%s:\n", __FUNCTION__);
+       dprintk("%s:\n", __func__);
 
        div = (params->frequency + (1000-1)) / 1000;
 
+       /* BW = ((1 + RO) * SR/2 + 5) * 1.3      [SR in MSPS, BW in MHz] */
+       /* with R0 = 0.35 and some transformations: */
+       ksyms = params->u.qpsk.symbol_rate / 1000;
+       bandwidth = (878 * ksyms + 6500000) / 1000000 + 1;
+       if (bandwidth < 5)
+               bandwidth = 5;
+       else if (bandwidth > 36)
+               bandwidth = 36;
+
        buf[0] = 0x00; // subaddress
        buf[1] = 0x09; // powerdown RSSI + the magic value 1
        if (!priv->has_loopthrough)
@@ -90,8 +100,8 @@ static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
        buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
        buf[3] = div >> 7;
        buf[4] = div << 1;
-       buf[5] = 0xff; // basedband filter to max
-       buf[6] = 0xfe; // gains at max + no RF attenuation
+       buf[5] = ((bandwidth - 5) << 3) | 7; /* baseband cut-off */
+       buf[6] = 0xfe; // baseband gain 9 db + no RF attenuation
        buf[7] = 0x83; // charge pumps at high, tests off
        buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
        buf[9] = 0x1a; // normal caltime + recommended values for SELTH + SELVTL
@@ -100,7 +110,7 @@ static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 1);
        if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
-               dprintk("%s: i2c error\n", __FUNCTION__);
+               dprintk("%s: i2c error\n", __func__);
        }
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 0);
@@ -133,18 +143,21 @@ struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2
 {
        struct tda826x_priv *priv = NULL;
        u8 b1 [] = { 0, 0 };
-       struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 };
+       struct i2c_msg msg[2] = {
+               { .addr = addr, .flags = 0,        .buf = NULL, .len = 0 },
+               { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 }
+       };
        int ret;
 
-       dprintk("%s:\n", __FUNCTION__);
+       dprintk("%s:\n", __func__);
 
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 1);
-       ret = i2c_transfer (i2c, &msg, 1);
+       ret = i2c_transfer (i2c, msg, 2);
        if (fe->ops.i2c_gate_ctrl)
                fe->ops.i2c_gate_ctrl(fe, 0);
 
-       if (ret != 1)
+       if (ret != 2)
                return NULL;
        if (!(b1[1] & 0x80))
                return NULL;