V4L/DVB (3313): codingstyle cleanups & restore some wrongfully deleted dvb-usb-ids
[cascardo/linux.git] / drivers / media / dvb / dvb-usb / cxusb.c
index c3e1b66..3100ce9 100644 (file)
@@ -15,6 +15,8 @@
  * part
  *
  * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
+ * Copyright (C) 2005 Michael Krufky (mkrufky@m1k.net)
+ * Copyright (C) 2006 Chris Pascoe (c.pascoe@itee.uq.edu.au)
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License as published by the Free
@@ -25,6 +27,9 @@
 #include "cxusb.h"
 
 #include "cx22702.h"
+#include "lgdt330x.h"
+#include "mt352.h"
+#include "mt352_priv.h"
 
 /* debug */
 int dvb_usb_cxusb_debug;
@@ -48,35 +53,26 @@ static int cxusb_ctrl_msg(struct dvb_usb_device *d,
        return 0;
 }
 
-/* I2C */
-static void cxusb_set_i2c_path(struct dvb_usb_device *d, enum cxusb_i2c_pathes path)
+/* GPIO */
+static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
 {
        struct cxusb_state *st = d->priv;
        u8 o[2],i;
 
-       if (path == st->cur_i2c_path)
+       if (st->gpio_write_state[GPIO_TUNER] == onoff)
                return;
 
-       o[0] = IOCTL_SET_I2C_PATH;
-       switch (path) {
-               case PATH_CX22702:
-                       o[1] = 0;
-                       break;
-               case PATH_TUNER_OTHER:
-                       o[1] = 1;
-                       break;
-               default:
-                       err("unkown i2c path");
-                       return;
-       }
-       cxusb_ctrl_msg(d,CMD_IOCTL,o,2,&i,1);
+       o[0] = GPIO_TUNER;
+       o[1] = onoff;
+       cxusb_ctrl_msg(d,CMD_GPIO_WRITE,o,2,&i,1);
 
        if (i != 0x01)
-               deb_info("i2c_path setting failed.\n");
+               deb_info("gpio_write failed.\n");
 
-       st->cur_i2c_path = path;
+       st->gpio_write_state[GPIO_TUNER] = onoff;
 }
 
+/* I2C */
 static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
 {
        struct dvb_usb_device *d = i2c_get_adapdata(adap);
@@ -92,10 +88,10 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
 
                switch (msg[i].addr) {
                        case 0x63:
-                               cxusb_set_i2c_path(d,PATH_CX22702);
+                               cxusb_gpio_tuner(d,0);
                                break;
                        default:
-                               cxusb_set_i2c_path(d,PATH_TUNER_OTHER);
+                               cxusb_gpio_tuner(d,1);
                                break;
                }
 
@@ -141,24 +137,119 @@ static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
 }
 
 static struct i2c_algorithm cxusb_i2c_algo = {
-       .name          = "Conexant USB I2C algorithm",
-       .id            = I2C_ALGO_BIT,
        .master_xfer   = cxusb_i2c_xfer,
        .functionality = cxusb_i2c_func,
 };
 
 static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
 {
-       return 0;
+       u8 b = 0;
+       if (onoff)
+               return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
+       else
+               return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
 }
 
 static int cxusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
 {
        u8 buf[2] = { 0x03, 0x00 };
        if (onoff)
-               cxusb_ctrl_msg(d,0x36, buf, 2, NULL, 0);
+               cxusb_ctrl_msg(d,CMD_STREAMING_ON, buf, 2, NULL, 0);
        else
-               cxusb_ctrl_msg(d,0x37, NULL, 0, NULL, 0);
+               cxusb_ctrl_msg(d,CMD_STREAMING_OFF, NULL, 0, NULL, 0);
+
+       return 0;
+}
+
+static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
+{
+       struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
+       u8 ircode[4];
+       int i;
+
+       cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);
+
+       *event = 0;
+       *state = REMOTE_NO_KEY_PRESSED;
+
+       for (i = 0; i < d->props.rc_key_map_size; i++) {
+               if (keymap[i].custom == ircode[2] &&
+                   keymap[i].data == ircode[3]) {
+                       *event = keymap[i].event;
+                       *state = REMOTE_KEY_PRESSED;
+
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+
+struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
+       { 0xfe, 0x02, KEY_TV },
+       { 0xfe, 0x0e, KEY_MP3 },
+       { 0xfe, 0x1a, KEY_DVD },
+       { 0xfe, 0x1e, KEY_FAVORITES },
+       { 0xfe, 0x16, KEY_SETUP },
+       { 0xfe, 0x46, KEY_POWER2 },
+       { 0xfe, 0x0a, KEY_EPG },
+       { 0xfe, 0x49, KEY_BACK },
+       { 0xfe, 0x4d, KEY_MENU },
+       { 0xfe, 0x51, KEY_UP },
+       { 0xfe, 0x5b, KEY_LEFT },
+       { 0xfe, 0x5f, KEY_RIGHT },
+       { 0xfe, 0x53, KEY_DOWN },
+       { 0xfe, 0x5e, KEY_OK },
+       { 0xfe, 0x59, KEY_INFO },
+       { 0xfe, 0x55, KEY_TAB },
+       { 0xfe, 0x0f, KEY_PREVIOUSSONG },/* Replay */
+       { 0xfe, 0x12, KEY_NEXTSONG },   /* Skip */
+       { 0xfe, 0x42, KEY_ENTER  },     /* Windows/Start */
+       { 0xfe, 0x15, KEY_VOLUMEUP },
+       { 0xfe, 0x05, KEY_VOLUMEDOWN },
+       { 0xfe, 0x11, KEY_CHANNELUP },
+       { 0xfe, 0x09, KEY_CHANNELDOWN },
+       { 0xfe, 0x52, KEY_CAMERA },
+       { 0xfe, 0x5a, KEY_TUNER },      /* Live */
+       { 0xfe, 0x19, KEY_OPEN },
+       { 0xfe, 0x0b, KEY_1 },
+       { 0xfe, 0x17, KEY_2 },
+       { 0xfe, 0x1b, KEY_3 },
+       { 0xfe, 0x07, KEY_4 },
+       { 0xfe, 0x50, KEY_5 },
+       { 0xfe, 0x54, KEY_6 },
+       { 0xfe, 0x48, KEY_7 },
+       { 0xfe, 0x4c, KEY_8 },
+       { 0xfe, 0x58, KEY_9 },
+       { 0xfe, 0x13, KEY_ANGLE },      /* Aspect */
+       { 0xfe, 0x03, KEY_0 },
+       { 0xfe, 0x1f, KEY_ZOOM },
+       { 0xfe, 0x43, KEY_REWIND },
+       { 0xfe, 0x47, KEY_PLAYPAUSE },
+       { 0xfe, 0x4f, KEY_FASTFORWARD },
+       { 0xfe, 0x57, KEY_MUTE },
+       { 0xfe, 0x0d, KEY_STOP },
+       { 0xfe, 0x01, KEY_RECORD },
+       { 0xfe, 0x4e, KEY_POWER },
+};
+
+static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
+{
+       static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x38 };
+       static u8 reset []         = { RESET,      0x80 };
+       static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
+       static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0x20 };
+       static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
+       static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
+
+       mt352_write(fe, clock_config,   sizeof(clock_config));
+       udelay(200);
+       mt352_write(fe, reset,          sizeof(reset));
+       mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));
+
+       mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
+       mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
+       mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
 
        return 0;
 }
@@ -172,34 +263,53 @@ struct cx22702_config cxusb_cx22702_config = {
        .pll_set  = dvb_usb_pll_set_i2c,
 };
 
+struct lgdt330x_config cxusb_lgdt330x_config = {
+       .demod_address = 0x0e,
+       .demod_chip    = LGDT3303,
+       .pll_set       = dvb_usb_pll_set_i2c,
+};
+
+struct mt352_config cxusb_dee1601_config = {
+       .demod_address = 0x0f,
+       .demod_init    = cxusb_dee1601_demod_init,
+       .pll_set       = dvb_usb_pll_set,
+};
+
 /* Callbacks for DVB USB */
-static int cxusb_tuner_attach(struct dvb_usb_device *d)
+static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_device *d)
 {
        u8 bpll[4] = { 0x0b, 0xdc, 0x9c, 0xa0 };
        d->pll_addr = 0x61;
-       memcpy(d->pll_init,bpll,4);
+       memcpy(d->pll_init, bpll, 4);
        d->pll_desc = &dvb_pll_fmd1216me;
        return 0;
 }
 
-static int cxusb_frontend_attach(struct dvb_usb_device *d)
+static int cxusb_lgh064f_tuner_attach(struct dvb_usb_device *d)
 {
-       u8 buf[2] = { 0x03, 0x00 };
-       u8 b = 0;
-
-       if (usb_set_interface(d->udev,0,0) < 0)
-               err("set interface to alts=0 failed");
+       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;
+       return 0;
+}
 
-       cxusb_ctrl_msg(d,0xde,&b,0,NULL,0);
-       cxusb_set_i2c_path(d,PATH_TUNER_OTHER);
-       cxusb_ctrl_msg(d,CMD_POWER_OFF, NULL, 0, &b, 1);
+static int cxusb_dee1601_tuner_attach(struct dvb_usb_device *d)
+{
+       d->pll_addr = 0x61;
+       d->pll_desc = &dvb_pll_thomson_dtt7579;
+       return 0;
+}
 
+static int cxusb_cx22702_frontend_attach(struct dvb_usb_device *d)
+{
+       u8 b;
        if (usb_set_interface(d->udev,0,6) < 0)
                err("set interface failed");
 
-       cxusb_ctrl_msg(d,0x36, buf, 2, NULL, 0);
-       cxusb_set_i2c_path(d,PATH_CX22702);
-       cxusb_ctrl_msg(d,CMD_POWER_ON, NULL, 0, &b, 1);
+       cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, &b, 1);
 
        if ((d->fe = cx22702_attach(&cxusb_cx22702_config, &d->i2c_adap)) != NULL)
                return 0;
@@ -207,22 +317,60 @@ static int cxusb_frontend_attach(struct dvb_usb_device *d)
        return -EIO;
 }
 
+static int cxusb_lgdt330x_frontend_attach(struct dvb_usb_device *d)
+{
+       if (usb_set_interface(d->udev,0,7) < 0)
+               err("set interface failed");
+
+       cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
+
+       if ((d->fe = lgdt330x_attach(&cxusb_lgdt330x_config, &d->i2c_adap)) != NULL)
+               return 0;
+
+       return -EIO;
+}
+
+static int cxusb_dee1601_frontend_attach(struct dvb_usb_device *d)
+{
+       if (usb_set_interface(d->udev,0,0) < 0)
+               err("set interface failed");
+
+       cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
+
+       if ((d->fe = mt352_attach(&cxusb_dee1601_config, &d->i2c_adap)) != NULL)
+               return 0;
+
+       return -EIO;
+}
+
 /* DVB USB Driver stuff */
-static struct dvb_usb_properties cxusb_properties;
+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 int cxusb_probe(struct usb_interface *intf,
                const struct usb_device_id *id)
 {
-       return dvb_usb_device_init(intf,&cxusb_properties,THIS_MODULE);
+       if (dvb_usb_device_init(intf,&cxusb_medion_properties,THIS_MODULE,NULL) == 0 ||
+               dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 ||
+               dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0) {
+               return 0;
+       }
+
+       return -EINVAL;
 }
 
 static struct usb_device_id cxusb_table [] = {
                { USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) },
+               { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD) },
+               { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) },
+               { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DEE1601_COLD) },
+               { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DEE1601_WARM) },
                {}              /* Terminating entry */
 };
 MODULE_DEVICE_TABLE (usb, cxusb_table);
 
-static struct dvb_usb_properties cxusb_properties = {
+static struct dvb_usb_properties cxusb_medion_properties = {
        .caps = DVB_USB_IS_AN_I2C_ADAPTER,
 
        .usb_ctrl = CYPRESS_FX2,
@@ -231,22 +379,20 @@ static struct dvb_usb_properties cxusb_properties = {
 
        .streaming_ctrl   = cxusb_streaming_ctrl,
        .power_ctrl       = cxusb_power_ctrl,
-       .frontend_attach  = cxusb_frontend_attach,
-       .tuner_attach     = cxusb_tuner_attach,
+       .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_ISOC,
+               .type = DVB_USB_BULK,
                .count = 5,
                .endpoint = 0x02,
                .u = {
-                       .isoc = {
-                               .framesperurb = 32,
-                               .framesize = 940,
-                               .interval = 5,
+                       .bulk = {
+                               .buffersize = 8192,
                        }
                }
        },
@@ -260,8 +406,90 @@ static struct dvb_usb_properties cxusb_properties = {
        }
 };
 
+static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+       .usb_ctrl         = CYPRESS_FX2,
+       .firmware         = "dvb-usb-bluebird-01.fw",
+       /* use usb alt setting 0 for EP4 transfer (dvb-t),
+          use usb alt setting 7 for EP2 transfer (atsc) */
+
+       .size_of_priv     = sizeof(struct cxusb_state),
+
+       .streaming_ctrl   = cxusb_streaming_ctrl,
+       .power_ctrl       = cxusb_power_ctrl,
+       .frontend_attach  = cxusb_lgdt330x_frontend_attach,
+       .tuner_attach     = cxusb_lgh064f_tuner_attach,
+
+       .i2c_algo         = &cxusb_i2c_algo,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
+       /* parameter for the MPEG2-data transfer */
+       .urb = {
+               .type = DVB_USB_BULK,
+               .count = 5,
+               .endpoint = 0x02,
+               .u = {
+                       .bulk = {
+                               .buffersize = 8192,
+                       }
+               }
+       },
+
+       .num_device_descs = 1,
+       .devices = {
+               {   "DViCO FusionHDTV5 USB Gold",
+                       { &cxusb_table[1], NULL },
+                       { &cxusb_table[2], NULL },
+               },
+       }
+};
+
+static struct dvb_usb_properties cxusb_bluebird_dee1601_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+       .usb_ctrl         = CYPRESS_FX2,
+       .firmware         = "dvb-usb-bluebird-01.fw",
+       /* use usb alt setting 0 for EP4 transfer (dvb-t),
+          use usb alt setting 7 for EP2 transfer (atsc) */
+
+       .size_of_priv     = sizeof(struct cxusb_state),
+
+       .streaming_ctrl   = cxusb_streaming_ctrl,
+       .power_ctrl       = cxusb_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,
+               .count = 5,
+               .endpoint = 0x04,
+               .u = {
+                       .bulk = {
+                               .buffersize = 8192,
+                       }
+               }
+       },
+
+       .num_device_descs = 1,
+       .devices = {
+               {   "DViCO FusionHDTV DVB-T Dual USB",
+                       { &cxusb_table[3], NULL },
+                       { &cxusb_table[4], NULL },
+               },
+       }
+};
+
 static struct usb_driver cxusb_driver = {
-       .owner          = THIS_MODULE,
        .name           = "dvb_usb_cxusb",
        .probe          = cxusb_probe,
        .disconnect = dvb_usb_device_exit,