V4L/DVB (4643): Multi-input patch for DVB-USB device
[powerpc.git] / drivers / media / dvb / dvb-usb / cxusb.c
index 1f0d3e9..5ebfa3f 100644 (file)
 
 #include "cx22702.h"
 #include "lgdt330x.h"
+#include "lg_h06xf.h"
 #include "mt352.h"
 #include "mt352_priv.h"
+#include "zl10353.h"
 
 /* debug */
 int dvb_usb_cxusb_debug;
@@ -159,13 +161,13 @@ static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
                return 0;
 }
 
-static int cxusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
+static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
        u8 buf[2] = { 0x03, 0x00 };
        if (onoff)
-               cxusb_ctrl_msg(d,CMD_STREAMING_ON, buf, 2, NULL, 0);
+               cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON, buf, 2, NULL, 0);
        else
-               cxusb_ctrl_msg(d,CMD_STREAMING_OFF, NULL, 0, NULL, 0);
+               cxusb_ctrl_msg(adap->dev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
 
        return 0;
 }
@@ -322,124 +324,134 @@ static int cxusb_mt352_demod_init(struct dvb_frontend* fe)
        return 0;
 }
 
+static int cxusb_lgh064f_tuner_set_params(struct dvb_frontend *fe,
+                                         struct dvb_frontend_parameters *fep)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+       return lg_h06xf_pll_set(fe, &adap->dev->i2c_adap, fep);
+}
+
 static struct cx22702_config cxusb_cx22702_config = {
        .demod_address = 0x63,
 
        .output_mode = CX22702_PARALLEL_OUTPUT,
-
-       .pll_init = dvb_usb_pll_init_i2c,
-       .pll_set  = dvb_usb_pll_set_i2c,
 };
 
 static struct lgdt330x_config cxusb_lgdt3303_config = {
        .demod_address = 0x0e,
        .demod_chip    = LGDT3303,
-       .pll_set       = dvb_usb_pll_set_i2c,
 };
 
 static struct mt352_config cxusb_dee1601_config = {
        .demod_address = 0x0f,
        .demod_init    = cxusb_dee1601_demod_init,
-       .pll_set       = dvb_usb_pll_set,
 };
 
-struct mt352_config cxusb_mt352_config = {
+static struct zl10353_config cxusb_zl10353_dee1601_config = {
+       .demod_address = 0x0f,
+       .parallel_ts = 1,
+};
+
+static struct mt352_config cxusb_mt352_config = {
        /* used in both lgz201 and th7579 */
        .demod_address = 0x0f,
        .demod_init    = cxusb_mt352_demod_init,
-       .pll_set       = dvb_usb_pll_set,
 };
 
 /* Callbacks for DVB USB */
-static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_device *d)
+static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
 {
        u8 bpll[4] = { 0x0b, 0xdc, 0x9c, 0xa0 };
-       d->pll_addr = 0x61;
-       memcpy(d->pll_init, bpll, 4);
-       d->pll_desc = &dvb_pll_fmd1216me;
+       adap->pll_addr = 0x61;
+       memcpy(adap->pll_init, bpll, 4);
+       adap->pll_desc = &dvb_pll_fmd1216me;
+
+       adap->fe->ops.tuner_ops.init = dvb_usb_tuner_init_i2c;
+       adap->fe->ops.tuner_ops.set_params = dvb_usb_tuner_set_params_i2c;
+
        return 0;
 }
 
-static int cxusb_lgh064f_tuner_attach(struct dvb_usb_device *d)
+static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       u8 bpll[4] = { 0x00, 0x00, 0x18, 0x50 };
-       /* bpll[2] : unset bit 3, set bits 4&5
-          bpll[3] : 0x50 - digital, 0x20 - analog */
-       d->pll_addr = 0x61;
-       memcpy(d->pll_init, bpll, 4);
-       d->pll_desc = &dvb_pll_tdvs_tua6034;
+       adap->pll_addr = 0x61;
+       adap->pll_desc = &dvb_pll_thomson_dtt7579;
+       adap->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs;
        return 0;
 }
 
-static int cxusb_dee1601_tuner_attach(struct dvb_usb_device *d)
+static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       d->pll_addr = 0x61;
-       d->pll_desc = &dvb_pll_thomson_dtt7579;
+       adap->pll_addr = 0x61;
+       adap->pll_desc = &dvb_pll_lg_z201;
+       adap->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs;
        return 0;
 }
 
-static int cxusb_lgz201_tuner_attach(struct dvb_usb_device *d)
+static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       d->pll_addr = 0x61;
-       d->pll_desc = &dvb_pll_lg_z201;
+       adap->pll_addr = 0x60;
+       adap->pll_desc = &dvb_pll_thomson_dtt7579;
+       adap->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs;
        return 0;
 }
 
-static int cxusb_dtt7579_tuner_attach(struct dvb_usb_device *d)
+static int cxusb_lgdt3303_tuner_attach(struct dvb_usb_adapter *adap)
 {
-       d->pll_addr = 0x60;
-       d->pll_desc = &dvb_pll_thomson_dtt7579;
+       adap->fe->ops.tuner_ops.set_params = cxusb_lgh064f_tuner_set_params;
        return 0;
 }
 
-static int cxusb_cx22702_frontend_attach(struct dvb_usb_device *d)
+static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
 {
        u8 b;
-       if (usb_set_interface(d->udev,0,6) < 0)
+       if (usb_set_interface(adap->dev->udev, 0, 6) < 0)
                err("set interface failed");
 
-       cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, &b, 1);
+       cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);
 
-       if ((d->fe = cx22702_attach(&cxusb_cx22702_config, &d->i2c_adap)) != NULL)
+       if ((adap->fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config, &adap->dev->i2c_adap)) != NULL)
                return 0;
 
        return -EIO;
 }
 
-static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_device *d)
+static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
 {
-       if (usb_set_interface(d->udev,0,7) < 0)
+       if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
                err("set interface failed");
 
-       cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
+       cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
 
-       if ((d->fe = lgdt330x_attach(&cxusb_lgdt3303_config, &d->i2c_adap)) != NULL)
+       if ((adap->fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config, &adap->dev->i2c_adap)) != NULL)
                return 0;
 
        return -EIO;
 }
 
-static int cxusb_mt352_frontend_attach(struct dvb_usb_device *d)
-{      /* used in both lgz201 and th7579 */
-       if (usb_set_interface(d->udev,0,0) < 0)
+static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       /* used in both lgz201 and th7579 */
+       if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
                err("set interface failed");
 
-       cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
+       cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
 
-       if ((d->fe = mt352_attach(&cxusb_mt352_config, &d->i2c_adap)) != NULL)
+       if ((adap->fe = dvb_attach(mt352_attach, &cxusb_mt352_config, &adap->dev->i2c_adap)) != NULL)
                return 0;
 
        return -EIO;
 }
 
-static int cxusb_dee1601_frontend_attach(struct dvb_usb_device *d)
+static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
 {
-       if (usb_set_interface(d->udev,0,0) < 0)
+       if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
                err("set interface failed");
 
-       cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
+       cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
 
-       if ((d->fe = mt352_attach(&cxusb_dee1601_config, &d->i2c_adap)) != NULL)
+       if (((adap->fe = dvb_attach(mt352_attach, &cxusb_dee1601_config, &adap->dev->i2c_adap)) != NULL) ||
+               ((adap->fe = dvb_attach(zl10353_attach, &cxusb_zl10353_dee1601_config, &adap->dev->i2c_adap)) != NULL))
                return 0;
 
        return -EIO;
@@ -469,11 +481,11 @@ static int bluebird_patch_dvico_firmware_download(struct usb_device *udev, const
 }
 
 /* DVB USB Driver stuff */
-static struct dvb_usb_properties cxusb_medion_properties;
-static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties;
-static struct dvb_usb_properties cxusb_bluebird_dee1601_properties;
-static struct dvb_usb_properties cxusb_bluebird_lgz201_properties;
-static struct dvb_usb_properties cxusb_bluebird_dtt7579_properties;
+static struct dvb_usb_device_properties cxusb_medion_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
 
 static int cxusb_probe(struct usb_interface *intf,
                const struct usb_device_id *id)
@@ -505,24 +517,22 @@ static struct usb_device_id cxusb_table [] = {
 };
 MODULE_DEVICE_TABLE (usb, cxusb_table);
 
-static struct dvb_usb_properties cxusb_medion_properties = {
+static struct dvb_usb_device_properties cxusb_medion_properties = {
        .caps = DVB_USB_IS_AN_I2C_ADAPTER,
 
        .usb_ctrl = CYPRESS_FX2,
 
        .size_of_priv     = sizeof(struct cxusb_state),
 
+       .num_adapters = 1,
+       .adapter = {
+               {
        .streaming_ctrl   = cxusb_streaming_ctrl,
-       .power_ctrl       = cxusb_power_ctrl,
        .frontend_attach  = cxusb_cx22702_frontend_attach,
        .tuner_attach     = cxusb_fmd1216me_tuner_attach,
-
-       .i2c_algo         = &cxusb_i2c_algo,
-
-       .generic_bulk_ctrl_endpoint = 0x01,
        /* parameter for the MPEG2-data transfer */
-       .urb = {
-               .type = DVB_USB_BULK,
+                       .stream = {
+                               .type = USB_BULK,
                .count = 5,
                .endpoint = 0x02,
                .u = {
@@ -532,6 +542,14 @@ static struct dvb_usb_properties cxusb_medion_properties = {
                }
        },
 
+               },
+       },
+       .power_ctrl       = cxusb_power_ctrl,
+
+       .i2c_algo         = &cxusb_i2c_algo,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
+
        .num_device_descs = 1,
        .devices = {
                {   "Medion MD95700 (MDUSBTV-HYBRID)",
@@ -541,7 +559,7 @@ static struct dvb_usb_properties cxusb_medion_properties = {
        }
 };
 
-static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties = {
+static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
        .caps = DVB_USB_IS_AN_I2C_ADAPTER,
 
        .usb_ctrl          = DEVICE_SPECIFIC,
@@ -552,22 +570,16 @@ static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties = {
 
        .size_of_priv     = sizeof(struct cxusb_state),
 
+       .num_adapters = 1,
+       .adapter = {
+               {
        .streaming_ctrl   = cxusb_streaming_ctrl,
-       .power_ctrl       = cxusb_bluebird_power_ctrl,
        .frontend_attach  = cxusb_lgdt3303_frontend_attach,
-       .tuner_attach     = cxusb_lgh064f_tuner_attach,
-
-       .i2c_algo         = &cxusb_i2c_algo,
+       .tuner_attach     = cxusb_lgdt3303_tuner_attach,
 
-       .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
-       .rc_query         = cxusb_rc_query,
-
-       .generic_bulk_ctrl_endpoint = 0x01,
        /* parameter for the MPEG2-data transfer */
-       .urb = {
-               .type = DVB_USB_BULK,
+                       .stream = {
+                               .type = USB_BULK,
                .count = 5,
                .endpoint = 0x02,
                .u = {
@@ -576,6 +588,19 @@ static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties = {
                        }
                }
        },
+               },
+       },
+
+       .power_ctrl       = cxusb_bluebird_power_ctrl,
+
+       .i2c_algo         = &cxusb_i2c_algo,
+
+       .rc_interval      = 100,
+       .rc_key_map       = dvico_portable_rc_keys,
+       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_query         = cxusb_rc_query,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
 
        .num_device_descs = 1,
        .devices = {
@@ -586,7 +611,7 @@ static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties = {
        }
 };
 
-static struct dvb_usb_properties cxusb_bluebird_dee1601_properties = {
+static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
        .caps = DVB_USB_IS_AN_I2C_ADAPTER,
 
        .usb_ctrl          = DEVICE_SPECIFIC,
@@ -597,22 +622,15 @@ static struct dvb_usb_properties cxusb_bluebird_dee1601_properties = {
 
        .size_of_priv     = sizeof(struct cxusb_state),
 
+       .num_adapters = 1,
+       .adapter = {
+               {
        .streaming_ctrl   = cxusb_streaming_ctrl,
-       .power_ctrl       = cxusb_bluebird_power_ctrl,
        .frontend_attach  = cxusb_dee1601_frontend_attach,
        .tuner_attach     = cxusb_dee1601_tuner_attach,
-
-       .i2c_algo         = &cxusb_i2c_algo,
-
-       .rc_interval      = 150,
-       .rc_key_map       = dvico_mce_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
-       .rc_query         = cxusb_rc_query,
-
-       .generic_bulk_ctrl_endpoint = 0x01,
        /* parameter for the MPEG2-data transfer */
-       .urb = {
-               .type = DVB_USB_BULK,
+                       .stream = {
+                               .type = USB_BULK,
                .count = 5,
                .endpoint = 0x04,
                .u = {
@@ -621,6 +639,19 @@ static struct dvb_usb_properties cxusb_bluebird_dee1601_properties = {
                        }
                }
        },
+               },
+       },
+
+       .power_ctrl       = cxusb_bluebird_power_ctrl,
+
+       .i2c_algo         = &cxusb_i2c_algo,
+
+       .rc_interval      = 150,
+       .rc_key_map       = dvico_mce_rc_keys,
+       .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
+       .rc_query         = cxusb_rc_query,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
 
        .num_device_descs = 2,
        .devices = {
@@ -635,7 +666,7 @@ static struct dvb_usb_properties cxusb_bluebird_dee1601_properties = {
        }
 };
 
-static struct dvb_usb_properties cxusb_bluebird_lgz201_properties = {
+static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
        .caps = DVB_USB_IS_AN_I2C_ADAPTER,
 
        .usb_ctrl          = DEVICE_SPECIFIC,
@@ -646,22 +677,16 @@ static struct dvb_usb_properties cxusb_bluebird_lgz201_properties = {
 
        .size_of_priv     = sizeof(struct cxusb_state),
 
+       .num_adapters = 2,
+       .adapter = {
+               {
        .streaming_ctrl   = cxusb_streaming_ctrl,
-       .power_ctrl       = cxusb_bluebird_power_ctrl,
        .frontend_attach  = cxusb_mt352_frontend_attach,
        .tuner_attach     = cxusb_lgz201_tuner_attach,
 
-       .i2c_algo         = &cxusb_i2c_algo,
-
-       .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
-       .rc_query         = cxusb_rc_query,
-
-       .generic_bulk_ctrl_endpoint = 0x01,
        /* parameter for the MPEG2-data transfer */
-       .urb = {
-               .type = DVB_USB_BULK,
+                       .stream = {
+                               .type = USB_BULK,
                .count = 5,
                .endpoint = 0x04,
                .u = {
@@ -670,7 +695,18 @@ static struct dvb_usb_properties cxusb_bluebird_lgz201_properties = {
                        }
                }
        },
+               },
+       },
+       .power_ctrl       = cxusb_bluebird_power_ctrl,
+
+       .i2c_algo         = &cxusb_i2c_algo,
 
+       .rc_interval      = 100,
+       .rc_key_map       = dvico_portable_rc_keys,
+       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_query         = cxusb_rc_query,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
        .num_device_descs = 1,
        .devices = {
                {   "DViCO FusionHDTV DVB-T USB (LGZ201)",
@@ -680,7 +716,7 @@ static struct dvb_usb_properties cxusb_bluebird_lgz201_properties = {
        }
 };
 
-static struct dvb_usb_properties cxusb_bluebird_dtt7579_properties = {
+static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
        .caps = DVB_USB_IS_AN_I2C_ADAPTER,
 
        .usb_ctrl          = DEVICE_SPECIFIC,
@@ -691,22 +727,16 @@ static struct dvb_usb_properties cxusb_bluebird_dtt7579_properties = {
 
        .size_of_priv     = sizeof(struct cxusb_state),
 
+       .num_adapters = 1,
+       .adapter = {
+               {
        .streaming_ctrl   = cxusb_streaming_ctrl,
-       .power_ctrl       = cxusb_bluebird_power_ctrl,
        .frontend_attach  = cxusb_mt352_frontend_attach,
        .tuner_attach     = cxusb_dtt7579_tuner_attach,
 
-       .i2c_algo         = &cxusb_i2c_algo,
-
-       .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
-       .rc_query         = cxusb_rc_query,
-
-       .generic_bulk_ctrl_endpoint = 0x01,
        /* parameter for the MPEG2-data transfer */
-       .urb = {
-               .type = DVB_USB_BULK,
+                       .stream = {
+                               .type = USB_BULK,
                .count = 5,
                .endpoint = 0x04,
                .u = {
@@ -715,6 +745,18 @@ static struct dvb_usb_properties cxusb_bluebird_dtt7579_properties = {
                        }
                }
        },
+               },
+       },
+       .power_ctrl       = cxusb_bluebird_power_ctrl,
+
+       .i2c_algo         = &cxusb_i2c_algo,
+
+       .rc_interval      = 100,
+       .rc_key_map       = dvico_portable_rc_keys,
+       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_query         = cxusb_rc_query,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
 
        .num_device_descs = 1,
        .devices = {