V4L/DVB (5245): Dvb-ttpci: use i2c gate ctrl from stv0297 frontend driver
[pandora-kernel.git] / drivers / media / dvb / ttpci / av7110_v4l.c
index 6405546..cde5d3a 100644 (file)
  */
 
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/types.h>
 #include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/timer.h>
 #include <linux/poll.h>
-#include <linux/byteorder/swabb.h>
 #include <linux/smp_lock.h>
 
 #include "av7110.h"
@@ -142,17 +140,6 @@ static int ves1820_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data)
        return 0;
 }
 
-static int stv0297_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data)
-{
-       u8 buf [] = { reg, data };
-       struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 2 };
-
-       if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1))
-               return -1;
-       return 0;
-}
-
-
 static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4])
 {
        struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 };
@@ -195,6 +182,7 @@ static int ves1820_set_tv_freq(struct saa7146_dev *dev, u32 freq)
 
 static int stv0297_set_tv_freq(struct saa7146_dev *dev, u32 freq)
 {
+       struct av7110 *av7110 = (struct av7110*)dev->ext_priv;
        u32 div;
        u8 data[4];
 
@@ -215,8 +203,8 @@ static int stv0297_set_tv_freq(struct saa7146_dev *dev, u32 freq)
        else
                return -EINVAL;
 
-       stv0297_writereg(dev, 0x1C, 0x87, 0x78);
-       stv0297_writereg(dev, 0x1C, 0x86, 0xc8);
+       if (av7110->fe->ops.i2c_gate_ctrl)
+               av7110->fe->ops.i2c_gate_ctrl(av7110->fe, 1);
        return tuner_write(dev, 0x63, data);
 }
 
@@ -272,8 +260,8 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
                                if (ves1820_writereg(dev, 0x09, 0x0f, 0x60))
                                        dprintk(1, "setting band in demodulator failed.\n");
                        } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
-                               saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9198 pin9(STD)
-                               saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9198 pin30(VIF)
+                               saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9819 pin9(STD)
+                               saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9819 pin30(VIF)
                        }
                        if (i2c_writereg(av7110, 0x48, 0x02, 0xd0) != 1)
                                dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
@@ -308,8 +296,8 @@ static int av7110_dvb_c_switch(struct saa7146_fh *fh)
                        if (ves1820_writereg(dev, 0x09, 0x0f, 0x20))
                                dprintk(1, "setting band in demodulator failed.\n");
                } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
-                       saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); // TDA9198 pin9(STD)
-                       saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // TDA9198 pin30(VIF)
+                       saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
+                       saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
                }
        }
 
@@ -750,8 +738,8 @@ int av7110_init_analog_module(struct av7110 *av7110)
                        if (ves1820_writereg(av7110->dev, 0x09, 0x0f, 0x20))
                                dprintk(1, "setting band in demodulator failed.\n");
                } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
-                       saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9198 pin9(STD)
-                       saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9198 pin30(VIF)
+                       saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
+                       saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
                }
 
                /* init the saa7113 */
@@ -819,20 +807,20 @@ int av7110_init_v4l(struct av7110 *av7110)
                saa7146_vv_release(dev);
                return -ENODEV;
        }
-       if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI)) {
+       if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI))
                ERR(("cannot register vbi v4l2 device. skipping.\n"));
-       } else {
-               if (av7110->analog_tuner_flags)
-                       av7110->analog_tuner_flags |= ANALOG_TUNER_VBI;
-       }
        return 0;
 }
 
 int av7110_exit_v4l(struct av7110 *av7110)
 {
+       struct saa7146_dev* dev = av7110->dev;
+
        saa7146_unregister_device(&av7110->v4l_dev, av7110->dev);
-       if (av7110->analog_tuner_flags & ANALOG_TUNER_VBI)
-               saa7146_unregister_device(&av7110->vbi_dev, av7110->dev);
+       saa7146_unregister_device(&av7110->vbi_dev, av7110->dev);
+
+       saa7146_vv_release(dev);
+
        return 0;
 }
 
@@ -922,7 +910,7 @@ static struct saa7146_ext_vv av7110_vv_data_st = {
 static struct saa7146_ext_vv av7110_vv_data_c = {
        .inputs         = 1,
        .audios         = 1,
-       .capabilities   = V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_OUTPUT,
+       .capabilities   = V4L2_CAP_TUNER | V4L2_CAP_SLICED_VBI_OUTPUT,
        .flags          = SAA7146_USE_PORT_B_FOR_VBI,
 
        .stds           = &standard[0],