V4L/DVB (6196): cx23885: add support for DViCO FusionHDTV 5 Express
[safe/jmp/linux-2.6] / drivers / media / video / tuner-core.c
index 848ee64..9484308 100644 (file)
 #include <linux/init.h>
 #include <linux/videodev.h>
 #include <media/tuner.h>
+#include <media/tuner-types.h>
 #include <media/v4l2-common.h>
 #include "tuner-driver.h"
 #include "mt20xx.h"
 #include "tda8290.h"
 #include "tea5761.h"
+#include "tea5767.h"
+#include "tuner-simple.h"
 
 #define UNSET (-1U)
 
@@ -107,6 +110,17 @@ static void fe_standby(struct tuner *t)
                fe_tuner_ops->sleep(&t->fe);
 }
 
+static int fe_has_signal(struct tuner *t)
+{
+       struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
+       u16 strength;
+
+       if (fe_tuner_ops->get_rf_strength)
+               fe_tuner_ops->get_rf_strength(&t->fe, &strength);
+
+       return strength;
+}
+
 /* Set tuner frequency,  freq in Units of 62.5kHz = 1/16MHz */
 static void set_tv_freq(struct i2c_client *c, unsigned int freq)
 {
@@ -212,6 +226,15 @@ static void attach_tda8290(struct tuner *t)
        tda8290_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg);
 }
 
+static void attach_simple_tuner(struct tuner *t)
+{
+       struct simple_tuner_config cfg = {
+               .type = t->type,
+               .tun  = &tuners[t->type]
+       };
+       simple_tuner_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg);
+}
+
 static void set_type(struct i2c_client *c, unsigned int type,
                     unsigned int new_mode_mask, unsigned int new_config,
                     int (*tuner_callback) (void *dev, int command,int arg))
@@ -262,7 +285,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
                break;
        }
        case TUNER_TEA5767:
-               if (tea5767_tuner_init(t) == EINVAL) {
+               if (tea5767_attach(&t->fe, t->i2c.adapter, t->i2c.addr) == NULL) {
                        t->type = TUNER_ABSENT;
                        t->mode_mask = T_UNINITIALIZED;
                        return;
@@ -289,7 +312,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
                buffer[2] = 0x86;
                buffer[3] = 0x54;
                i2c_master_send(c, buffer, 4);
-               default_tuner_init(t);
+               attach_simple_tuner(t);
                break;
        case TUNER_PHILIPS_TD1316:
                buffer[0] = 0x0b;
@@ -297,13 +320,13 @@ static void set_type(struct i2c_client *c, unsigned int type,
                buffer[2] = 0x86;
                buffer[3] = 0xa4;
                i2c_master_send(c,buffer,4);
-               default_tuner_init(t);
+               attach_simple_tuner(t);
                break;
        case TUNER_TDA9887:
                tda9887_tuner_init(t);
                break;
        default:
-               default_tuner_init(t);
+               attach_simple_tuner(t);
                break;
        }
 
@@ -314,6 +337,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
                t->ops.set_radio_freq = fe_set_freq;
                t->ops.standby        = fe_standby;
                t->ops.release        = fe_release;
+               t->ops.has_signal     = fe_has_signal;
        }
 
        tuner_info("type set to %s\n", t->i2c.name);
@@ -600,7 +624,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
                        }
                        break;
                case 0x60:
-                       if (tea5767_autodetection(t) != EINVAL) {
+                       if (tea5767_autodetection(t->i2c.adapter, t->i2c.addr) != EINVAL) {
                                t->type = TUNER_TEA5767;
                                t->mode_mask = T_RADIO;
                                t->mode = T_STANDBY;
@@ -637,6 +661,28 @@ static int tuner_probe(struct i2c_adapter *adap)
                normal_i2c[1] = I2C_CLIENT_END;
        }
 
+       /* HACK: Ignore 0x6b and 0x6f on cx88 boards.
+        * FusionHDTV5 RT Gold has an ir receiver at 0x6b
+        * and an RTC at 0x6f which can get corrupted if probed.
+        */
+       if ((adap->id == I2C_HW_B_CX2388x) ||
+           (adap->id == I2C_HW_B_CX23885)) {
+               unsigned int i = 0;
+
+               while (i < I2C_CLIENT_MAX_OPTS && ignore[i] != I2C_CLIENT_END)
+                       i += 2;
+               if (i + 4 < I2C_CLIENT_MAX_OPTS) {
+                       ignore[i+0] = adap->nr;
+                       ignore[i+1] = 0x6b;
+                       ignore[i+2] = adap->nr;
+                       ignore[i+3] = 0x6f;
+                       ignore[i+4] = I2C_CLIENT_END;
+               } else
+                       printk(KERN_WARNING "tuner: "
+                              "too many options specified "
+                              "in i2c probe ignore list!\n");
+       }
+
        default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
 
        if (adap->class & I2C_CLASS_TV_ANALOG)
@@ -795,12 +841,10 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
                                        u32 tuner_status;
 
                                        fe_tuner_ops->get_status(&t->fe, &tuner_status);
-                                               if (tuner_status & TUNER_STATUS_STEREO)
-                                                       vt->flags |= VIDEO_TUNER_STEREO_ON;
-                                               else
-                                                       vt->flags &= ~VIDEO_TUNER_STEREO_ON;
-                                               vt->signal = tuner_status & TUNER_STATUS_LOCKED
-                                                       ? 65535 : 0;
+                                       if (tuner_status & TUNER_STATUS_STEREO)
+                                               vt->flags |= VIDEO_TUNER_STEREO_ON;
+                                       else
+                                               vt->flags &= ~VIDEO_TUNER_STEREO_ON;
                                } else {
                                        if (t->ops.is_stereo) {
                                                if (t->ops.is_stereo(t))
@@ -810,9 +854,10 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
                                                        vt->flags &=
                                                                ~VIDEO_TUNER_STEREO_ON;
                                        }
-                                       if (t->ops.has_signal)
-                                               vt->signal = t->ops.has_signal(t);
                                }
+                               if (t->ops.has_signal)
+                                       vt->signal = t->ops.has_signal(t);
+
                                vt->flags |= VIDEO_TUNER_LOW;   /* Allow freqs at 62.5 Hz */
 
                                vt->rangelow = radio_range[0] * 16000;
@@ -936,15 +981,14 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
                                fe_tuner_ops->get_status(&t->fe, &tuner_status);
                                tuner->rxsubchans = (tuner_status & TUNER_STATUS_STEREO) ?
                                        V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
-                               tuner->signal = tuner_status & TUNER_STATUS_LOCKED ? 65535 : 0;
                        } else {
                                if (t->ops.is_stereo) {
                                        tuner->rxsubchans = t->ops.is_stereo(t) ?
                                                V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
                                }
-                               if (t->ops.has_signal)
-                                       tuner->signal = t->ops.has_signal(t);
                        }
+                       if (t->ops.has_signal)
+                               tuner->signal = t->ops.has_signal(t);
                        tuner->capability |=
                            V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
                        tuner->audmode = t->audmode;