Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* DVB USB framework compliant Linux driver for the
0003  *  DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
0004  *  TeVii S421, S480, S482, S600, S630, S632, S650, S660, S662,
0005  *  Prof 1100, 7500,
0006  *  Geniatech SU3000, T220,
0007  *  TechnoTrend S2-4600,
0008  *  Terratec Cinergy S2 cards
0009  * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
0010  *
0011  * see Documentation/driver-api/media/drivers/dvb-usb.rst for more information
0012  */
0013 #include <media/dvb-usb-ids.h>
0014 #include "dw2102.h"
0015 #include "si21xx.h"
0016 #include "stv0299.h"
0017 #include "z0194a.h"
0018 #include "stv0288.h"
0019 #include "stb6000.h"
0020 #include "eds1547.h"
0021 #include "cx24116.h"
0022 #include "tda1002x.h"
0023 #include "mt312.h"
0024 #include "zl10039.h"
0025 #include "ts2020.h"
0026 #include "ds3000.h"
0027 #include "stv0900.h"
0028 #include "stv6110.h"
0029 #include "stb6100.h"
0030 #include "stb6100_proc.h"
0031 #include "m88rs2000.h"
0032 #include "tda18271.h"
0033 #include "cxd2820r.h"
0034 #include "m88ds3103.h"
0035 
0036 /* Max transfer size done by I2C transfer functions */
0037 #define MAX_XFER_SIZE  64
0038 
0039 
0040 #define DW210X_READ_MSG 0
0041 #define DW210X_WRITE_MSG 1
0042 
0043 #define REG_1F_SYMBOLRATE_BYTE0 0x1f
0044 #define REG_20_SYMBOLRATE_BYTE1 0x20
0045 #define REG_21_SYMBOLRATE_BYTE2 0x21
0046 /* on my own*/
0047 #define DW2102_VOLTAGE_CTRL (0x1800)
0048 #define SU3000_STREAM_CTRL (0x1900)
0049 #define DW2102_RC_QUERY (0x1a00)
0050 #define DW2102_LED_CTRL (0x1b00)
0051 
0052 #define DW2101_FIRMWARE "dvb-usb-dw2101.fw"
0053 #define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
0054 #define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
0055 #define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
0056 #define S630_FIRMWARE   "dvb-usb-s630.fw"
0057 #define S660_FIRMWARE   "dvb-usb-s660.fw"
0058 #define P1100_FIRMWARE  "dvb-usb-p1100.fw"
0059 #define P7500_FIRMWARE  "dvb-usb-p7500.fw"
0060 
0061 #define err_str "did not find the firmware file '%s'. You can use <kernel_dir>/scripts/get_dvb_firmware to get the firmware"
0062 
0063 struct dw2102_state {
0064     u8 initialized;
0065     u8 last_lock;
0066     u8 data[MAX_XFER_SIZE + 4];
0067     struct i2c_client *i2c_client_demod;
0068     struct i2c_client *i2c_client_tuner;
0069 
0070     /* fe hook functions*/
0071     int (*old_set_voltage)(struct dvb_frontend *f, enum fe_sec_voltage v);
0072     int (*fe_read_status)(struct dvb_frontend *fe,
0073                   enum fe_status *status);
0074 };
0075 
0076 /* debug */
0077 static int dvb_usb_dw2102_debug;
0078 module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
0079 MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer 4=rc(or-able))."
0080                         DVB_USB_DEBUG_STATUS);
0081 
0082 /* demod probe */
0083 static int demod_probe = 1;
0084 module_param_named(demod, demod_probe, int, 0644);
0085 MODULE_PARM_DESC(demod, "demod to probe (1=cx24116 2=stv0903+stv6110 4=stv0903+stb6100(or-able)).");
0086 
0087 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
0088 
0089 static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
0090             u16 index, u8 * data, u16 len, int flags)
0091 {
0092     int ret;
0093     u8 *u8buf;
0094     unsigned int pipe = (flags == DW210X_READ_MSG) ?
0095                 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
0096     u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
0097 
0098     u8buf = kmalloc(len, GFP_KERNEL);
0099     if (!u8buf)
0100         return -ENOMEM;
0101 
0102 
0103     if (flags == DW210X_WRITE_MSG)
0104         memcpy(u8buf, data, len);
0105     ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
0106                 value, index , u8buf, len, 2000);
0107 
0108     if (flags == DW210X_READ_MSG)
0109         memcpy(data, u8buf, len);
0110 
0111     kfree(u8buf);
0112     return ret;
0113 }
0114 
0115 /* I2C */
0116 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
0117         int num)
0118 {
0119     struct dvb_usb_device *d = i2c_get_adapdata(adap);
0120     int i = 0;
0121     u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
0122     u16 value;
0123 
0124     if (!d)
0125         return -ENODEV;
0126     if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0127         return -EAGAIN;
0128 
0129     switch (num) {
0130     case 2:
0131         /* read stv0299 register */
0132         value = msg[0].buf[0];/* register */
0133         for (i = 0; i < msg[1].len; i++) {
0134             dw210x_op_rw(d->udev, 0xb5, value + i, 0,
0135                     buf6, 2, DW210X_READ_MSG);
0136             msg[1].buf[i] = buf6[0];
0137         }
0138         break;
0139     case 1:
0140         switch (msg[0].addr) {
0141         case 0x68:
0142             /* write to stv0299 register */
0143             buf6[0] = 0x2a;
0144             buf6[1] = msg[0].buf[0];
0145             buf6[2] = msg[0].buf[1];
0146             dw210x_op_rw(d->udev, 0xb2, 0, 0,
0147                     buf6, 3, DW210X_WRITE_MSG);
0148             break;
0149         case 0x60:
0150             if (msg[0].flags == 0) {
0151             /* write to tuner pll */
0152                 buf6[0] = 0x2c;
0153                 buf6[1] = 5;
0154                 buf6[2] = 0xc0;
0155                 buf6[3] = msg[0].buf[0];
0156                 buf6[4] = msg[0].buf[1];
0157                 buf6[5] = msg[0].buf[2];
0158                 buf6[6] = msg[0].buf[3];
0159                 dw210x_op_rw(d->udev, 0xb2, 0, 0,
0160                         buf6, 7, DW210X_WRITE_MSG);
0161             } else {
0162             /* read from tuner */
0163                 dw210x_op_rw(d->udev, 0xb5, 0, 0,
0164                         buf6, 1, DW210X_READ_MSG);
0165                 msg[0].buf[0] = buf6[0];
0166             }
0167             break;
0168         case (DW2102_RC_QUERY):
0169             dw210x_op_rw(d->udev, 0xb8, 0, 0,
0170                     buf6, 2, DW210X_READ_MSG);
0171             msg[0].buf[0] = buf6[0];
0172             msg[0].buf[1] = buf6[1];
0173             break;
0174         case (DW2102_VOLTAGE_CTRL):
0175             buf6[0] = 0x30;
0176             buf6[1] = msg[0].buf[0];
0177             dw210x_op_rw(d->udev, 0xb2, 0, 0,
0178                     buf6, 2, DW210X_WRITE_MSG);
0179             break;
0180         }
0181 
0182         break;
0183     }
0184 
0185     mutex_unlock(&d->i2c_mutex);
0186     return num;
0187 }
0188 
0189 static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
0190                         struct i2c_msg msg[], int num)
0191 {
0192     struct dvb_usb_device *d = i2c_get_adapdata(adap);
0193     u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
0194 
0195     if (!d)
0196         return -ENODEV;
0197     if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0198         return -EAGAIN;
0199 
0200     switch (num) {
0201     case 2:
0202         if (msg[0].len != 1) {
0203             warn("i2c rd: len=%d is not 1!\n",
0204                  msg[0].len);
0205             num = -EOPNOTSUPP;
0206             break;
0207         }
0208 
0209         if (2 + msg[1].len > sizeof(buf6)) {
0210             warn("i2c rd: len=%d is too big!\n",
0211                  msg[1].len);
0212             num = -EOPNOTSUPP;
0213             break;
0214         }
0215 
0216         /* read si2109 register by number */
0217         buf6[0] = msg[0].addr << 1;
0218         buf6[1] = msg[0].len;
0219         buf6[2] = msg[0].buf[0];
0220         dw210x_op_rw(d->udev, 0xc2, 0, 0,
0221                 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
0222         /* read si2109 register */
0223         dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
0224                 buf6, msg[1].len + 2, DW210X_READ_MSG);
0225         memcpy(msg[1].buf, buf6 + 2, msg[1].len);
0226 
0227         break;
0228     case 1:
0229         switch (msg[0].addr) {
0230         case 0x68:
0231             if (2 + msg[0].len > sizeof(buf6)) {
0232                 warn("i2c wr: len=%d is too big!\n",
0233                      msg[0].len);
0234                 num = -EOPNOTSUPP;
0235                 break;
0236             }
0237 
0238             /* write to si2109 register */
0239             buf6[0] = msg[0].addr << 1;
0240             buf6[1] = msg[0].len;
0241             memcpy(buf6 + 2, msg[0].buf, msg[0].len);
0242             dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
0243                     msg[0].len + 2, DW210X_WRITE_MSG);
0244             break;
0245         case(DW2102_RC_QUERY):
0246             dw210x_op_rw(d->udev, 0xb8, 0, 0,
0247                     buf6, 2, DW210X_READ_MSG);
0248             msg[0].buf[0] = buf6[0];
0249             msg[0].buf[1] = buf6[1];
0250             break;
0251         case(DW2102_VOLTAGE_CTRL):
0252             buf6[0] = 0x30;
0253             buf6[1] = msg[0].buf[0];
0254             dw210x_op_rw(d->udev, 0xb2, 0, 0,
0255                     buf6, 2, DW210X_WRITE_MSG);
0256             break;
0257         }
0258         break;
0259     }
0260 
0261     mutex_unlock(&d->i2c_mutex);
0262     return num;
0263 }
0264 
0265 static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
0266 {
0267     struct dvb_usb_device *d = i2c_get_adapdata(adap);
0268     int ret;
0269 
0270     if (!d)
0271         return -ENODEV;
0272     if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0273         return -EAGAIN;
0274 
0275     switch (num) {
0276     case 2: {
0277         /* read */
0278         /* first write first register number */
0279         u8 ibuf[MAX_XFER_SIZE], obuf[3];
0280 
0281         if (2 + msg[0].len != sizeof(obuf)) {
0282             warn("i2c rd: len=%d is not 1!\n",
0283                  msg[0].len);
0284             ret = -EOPNOTSUPP;
0285             goto unlock;
0286         }
0287 
0288         if (2 + msg[1].len > sizeof(ibuf)) {
0289             warn("i2c rd: len=%d is too big!\n",
0290                  msg[1].len);
0291             ret = -EOPNOTSUPP;
0292             goto unlock;
0293         }
0294 
0295         obuf[0] = msg[0].addr << 1;
0296         obuf[1] = msg[0].len;
0297         obuf[2] = msg[0].buf[0];
0298         dw210x_op_rw(d->udev, 0xc2, 0, 0,
0299                 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
0300         /* second read registers */
0301         dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
0302                 ibuf, msg[1].len + 2, DW210X_READ_MSG);
0303         memcpy(msg[1].buf, ibuf + 2, msg[1].len);
0304 
0305         break;
0306     }
0307     case 1:
0308         switch (msg[0].addr) {
0309         case 0x68: {
0310             /* write to register */
0311             u8 obuf[MAX_XFER_SIZE];
0312 
0313             if (2 + msg[0].len > sizeof(obuf)) {
0314                 warn("i2c wr: len=%d is too big!\n",
0315                      msg[1].len);
0316                 ret = -EOPNOTSUPP;
0317                 goto unlock;
0318             }
0319 
0320             obuf[0] = msg[0].addr << 1;
0321             obuf[1] = msg[0].len;
0322             memcpy(obuf + 2, msg[0].buf, msg[0].len);
0323             dw210x_op_rw(d->udev, 0xc2, 0, 0,
0324                     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
0325             break;
0326         }
0327         case 0x61: {
0328             /* write to tuner */
0329             u8 obuf[MAX_XFER_SIZE];
0330 
0331             if (2 + msg[0].len > sizeof(obuf)) {
0332                 warn("i2c wr: len=%d is too big!\n",
0333                      msg[1].len);
0334                 ret = -EOPNOTSUPP;
0335                 goto unlock;
0336             }
0337 
0338             obuf[0] = msg[0].addr << 1;
0339             obuf[1] = msg[0].len;
0340             memcpy(obuf + 2, msg[0].buf, msg[0].len);
0341             dw210x_op_rw(d->udev, 0xc2, 0, 0,
0342                     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
0343             break;
0344         }
0345         case(DW2102_RC_QUERY): {
0346             u8 ibuf[2];
0347             dw210x_op_rw(d->udev, 0xb8, 0, 0,
0348                     ibuf, 2, DW210X_READ_MSG);
0349             memcpy(msg[0].buf, ibuf , 2);
0350             break;
0351         }
0352         case(DW2102_VOLTAGE_CTRL): {
0353             u8 obuf[2];
0354             obuf[0] = 0x30;
0355             obuf[1] = msg[0].buf[0];
0356             dw210x_op_rw(d->udev, 0xb2, 0, 0,
0357                     obuf, 2, DW210X_WRITE_MSG);
0358             break;
0359         }
0360         }
0361 
0362         break;
0363     }
0364     ret = num;
0365 
0366 unlock:
0367     mutex_unlock(&d->i2c_mutex);
0368     return ret;
0369 }
0370 
0371 static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
0372 {
0373     struct dvb_usb_device *d = i2c_get_adapdata(adap);
0374     int len, i, j, ret;
0375 
0376     if (!d)
0377         return -ENODEV;
0378     if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0379         return -EAGAIN;
0380 
0381     for (j = 0; j < num; j++) {
0382         switch (msg[j].addr) {
0383         case(DW2102_RC_QUERY): {
0384             u8 ibuf[2];
0385             dw210x_op_rw(d->udev, 0xb8, 0, 0,
0386                     ibuf, 2, DW210X_READ_MSG);
0387             memcpy(msg[j].buf, ibuf , 2);
0388             break;
0389         }
0390         case(DW2102_VOLTAGE_CTRL): {
0391             u8 obuf[2];
0392             obuf[0] = 0x30;
0393             obuf[1] = msg[j].buf[0];
0394             dw210x_op_rw(d->udev, 0xb2, 0, 0,
0395                     obuf, 2, DW210X_WRITE_MSG);
0396             break;
0397         }
0398         /*case 0x55: cx24116
0399         case 0x6a: stv0903
0400         case 0x68: ds3000, stv0903
0401         case 0x60: ts2020, stv6110, stb6100 */
0402         default: {
0403             if (msg[j].flags == I2C_M_RD) {
0404                 /* read registers */
0405                 u8  ibuf[MAX_XFER_SIZE];
0406 
0407                 if (2 + msg[j].len > sizeof(ibuf)) {
0408                     warn("i2c rd: len=%d is too big!\n",
0409                          msg[j].len);
0410                     ret = -EOPNOTSUPP;
0411                     goto unlock;
0412                 }
0413 
0414                 dw210x_op_rw(d->udev, 0xc3,
0415                         (msg[j].addr << 1) + 1, 0,
0416                         ibuf, msg[j].len + 2,
0417                         DW210X_READ_MSG);
0418                 memcpy(msg[j].buf, ibuf + 2, msg[j].len);
0419                 mdelay(10);
0420             } else if (((msg[j].buf[0] == 0xb0) &&
0421                         (msg[j].addr == 0x68)) ||
0422                         ((msg[j].buf[0] == 0xf7) &&
0423                         (msg[j].addr == 0x55))) {
0424                 /* write firmware */
0425                 u8 obuf[19];
0426                 obuf[0] = msg[j].addr << 1;
0427                 obuf[1] = (msg[j].len > 15 ? 17 : msg[j].len);
0428                 obuf[2] = msg[j].buf[0];
0429                 len = msg[j].len - 1;
0430                 i = 1;
0431                 do {
0432                     memcpy(obuf + 3, msg[j].buf + i,
0433                             (len > 16 ? 16 : len));
0434                     dw210x_op_rw(d->udev, 0xc2, 0, 0,
0435                         obuf, (len > 16 ? 16 : len) + 3,
0436                         DW210X_WRITE_MSG);
0437                     i += 16;
0438                     len -= 16;
0439                 } while (len > 0);
0440             } else {
0441                 /* write registers */
0442                 u8 obuf[MAX_XFER_SIZE];
0443 
0444                 if (2 + msg[j].len > sizeof(obuf)) {
0445                     warn("i2c wr: len=%d is too big!\n",
0446                          msg[j].len);
0447                     ret = -EOPNOTSUPP;
0448                     goto unlock;
0449                 }
0450 
0451                 obuf[0] = msg[j].addr << 1;
0452                 obuf[1] = msg[j].len;
0453                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
0454                 dw210x_op_rw(d->udev, 0xc2, 0, 0,
0455                         obuf, msg[j].len + 2,
0456                         DW210X_WRITE_MSG);
0457             }
0458             break;
0459         }
0460         }
0461 
0462     }
0463     ret = num;
0464 
0465 unlock:
0466     mutex_unlock(&d->i2c_mutex);
0467     return ret;
0468 }
0469 
0470 static int dw3101_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
0471                                 int num)
0472 {
0473     struct dvb_usb_device *d = i2c_get_adapdata(adap);
0474     int ret;
0475     int i;
0476 
0477     if (!d)
0478         return -ENODEV;
0479     if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0480         return -EAGAIN;
0481 
0482     switch (num) {
0483     case 2: {
0484         /* read */
0485         /* first write first register number */
0486         u8 ibuf[MAX_XFER_SIZE], obuf[3];
0487 
0488         if (2 + msg[0].len != sizeof(obuf)) {
0489             warn("i2c rd: len=%d is not 1!\n",
0490                  msg[0].len);
0491             ret = -EOPNOTSUPP;
0492             goto unlock;
0493         }
0494         if (2 + msg[1].len > sizeof(ibuf)) {
0495             warn("i2c rd: len=%d is too big!\n",
0496                  msg[1].len);
0497             ret = -EOPNOTSUPP;
0498             goto unlock;
0499         }
0500         obuf[0] = msg[0].addr << 1;
0501         obuf[1] = msg[0].len;
0502         obuf[2] = msg[0].buf[0];
0503         dw210x_op_rw(d->udev, 0xc2, 0, 0,
0504                 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
0505         /* second read registers */
0506         dw210x_op_rw(d->udev, 0xc3, 0x19 , 0,
0507                 ibuf, msg[1].len + 2, DW210X_READ_MSG);
0508         memcpy(msg[1].buf, ibuf + 2, msg[1].len);
0509 
0510         break;
0511     }
0512     case 1:
0513         switch (msg[0].addr) {
0514         case 0x60:
0515         case 0x0c: {
0516             /* write to register */
0517             u8 obuf[MAX_XFER_SIZE];
0518 
0519             if (2 + msg[0].len > sizeof(obuf)) {
0520                 warn("i2c wr: len=%d is too big!\n",
0521                      msg[0].len);
0522                 ret = -EOPNOTSUPP;
0523                 goto unlock;
0524             }
0525             obuf[0] = msg[0].addr << 1;
0526             obuf[1] = msg[0].len;
0527             memcpy(obuf + 2, msg[0].buf, msg[0].len);
0528             dw210x_op_rw(d->udev, 0xc2, 0, 0,
0529                     obuf, msg[0].len + 2, DW210X_WRITE_MSG);
0530             break;
0531         }
0532         case(DW2102_RC_QUERY): {
0533             u8 ibuf[2];
0534             dw210x_op_rw(d->udev, 0xb8, 0, 0,
0535                     ibuf, 2, DW210X_READ_MSG);
0536             memcpy(msg[0].buf, ibuf , 2);
0537             break;
0538         }
0539         }
0540 
0541         break;
0542     }
0543 
0544     for (i = 0; i < num; i++) {
0545         deb_xfer("%02x:%02x: %s ", i, msg[i].addr,
0546                 msg[i].flags == 0 ? ">>>" : "<<<");
0547         debug_dump(msg[i].buf, msg[i].len, deb_xfer);
0548     }
0549     ret = num;
0550 
0551 unlock:
0552     mutex_unlock(&d->i2c_mutex);
0553     return ret;
0554 }
0555 
0556 static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
0557                                 int num)
0558 {
0559     struct dvb_usb_device *d = i2c_get_adapdata(adap);
0560     struct usb_device *udev;
0561     int len, i, j, ret;
0562 
0563     if (!d)
0564         return -ENODEV;
0565     udev = d->udev;
0566     if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0567         return -EAGAIN;
0568 
0569     for (j = 0; j < num; j++) {
0570         switch (msg[j].addr) {
0571         case (DW2102_RC_QUERY): {
0572             u8 ibuf[5];
0573             dw210x_op_rw(d->udev, 0xb8, 0, 0,
0574                     ibuf, 5, DW210X_READ_MSG);
0575             memcpy(msg[j].buf, ibuf + 3, 2);
0576             break;
0577         }
0578         case (DW2102_VOLTAGE_CTRL): {
0579             u8 obuf[2];
0580 
0581             obuf[0] = 1;
0582             obuf[1] = msg[j].buf[1];/* off-on */
0583             dw210x_op_rw(d->udev, 0x8a, 0, 0,
0584                     obuf, 2, DW210X_WRITE_MSG);
0585             obuf[0] = 3;
0586             obuf[1] = msg[j].buf[0];/* 13v-18v */
0587             dw210x_op_rw(d->udev, 0x8a, 0, 0,
0588                     obuf, 2, DW210X_WRITE_MSG);
0589             break;
0590         }
0591         case (DW2102_LED_CTRL): {
0592             u8 obuf[2];
0593 
0594             obuf[0] = 5;
0595             obuf[1] = msg[j].buf[0];
0596             dw210x_op_rw(d->udev, 0x8a, 0, 0,
0597                     obuf, 2, DW210X_WRITE_MSG);
0598             break;
0599         }
0600         /*case 0x55: cx24116
0601         case 0x6a: stv0903
0602         case 0x68: ds3000, stv0903, rs2000
0603         case 0x60: ts2020, stv6110, stb6100
0604         case 0xa0: eeprom */
0605         default: {
0606             if (msg[j].flags == I2C_M_RD) {
0607                 /* read registers */
0608                 u8 ibuf[MAX_XFER_SIZE];
0609 
0610                 if (msg[j].len > sizeof(ibuf)) {
0611                     warn("i2c rd: len=%d is too big!\n",
0612                          msg[j].len);
0613                     ret = -EOPNOTSUPP;
0614                     goto unlock;
0615                 }
0616 
0617                 dw210x_op_rw(d->udev, 0x91, 0, 0,
0618                         ibuf, msg[j].len,
0619                         DW210X_READ_MSG);
0620                 memcpy(msg[j].buf, ibuf, msg[j].len);
0621                 break;
0622             } else if ((msg[j].buf[0] == 0xb0) &&
0623                         (msg[j].addr == 0x68)) {
0624                 /* write firmware */
0625                 u8 obuf[19];
0626                 obuf[0] = (msg[j].len > 16 ?
0627                         18 : msg[j].len + 1);
0628                 obuf[1] = msg[j].addr << 1;
0629                 obuf[2] = msg[j].buf[0];
0630                 len = msg[j].len - 1;
0631                 i = 1;
0632                 do {
0633                     memcpy(obuf + 3, msg[j].buf + i,
0634                             (len > 16 ? 16 : len));
0635                     dw210x_op_rw(d->udev, 0x80, 0, 0,
0636                         obuf, (len > 16 ? 16 : len) + 3,
0637                         DW210X_WRITE_MSG);
0638                     i += 16;
0639                     len -= 16;
0640                 } while (len > 0);
0641             } else if (j < (num - 1)) {
0642                 /* write register addr before read */
0643                 u8 obuf[MAX_XFER_SIZE];
0644 
0645                 if (2 + msg[j].len > sizeof(obuf)) {
0646                     warn("i2c wr: len=%d is too big!\n",
0647                          msg[j].len);
0648                     ret = -EOPNOTSUPP;
0649                     goto unlock;
0650                 }
0651 
0652                 obuf[0] = msg[j + 1].len;
0653                 obuf[1] = (msg[j].addr << 1);
0654                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
0655                 dw210x_op_rw(d->udev,
0656                         le16_to_cpu(udev->descriptor.idProduct) ==
0657                         0x7500 ? 0x92 : 0x90, 0, 0,
0658                         obuf, msg[j].len + 2,
0659                         DW210X_WRITE_MSG);
0660                 break;
0661             } else {
0662                 /* write registers */
0663                 u8 obuf[MAX_XFER_SIZE];
0664 
0665                 if (2 + msg[j].len > sizeof(obuf)) {
0666                     warn("i2c wr: len=%d is too big!\n",
0667                          msg[j].len);
0668                     ret = -EOPNOTSUPP;
0669                     goto unlock;
0670                 }
0671                 obuf[0] = msg[j].len + 1;
0672                 obuf[1] = (msg[j].addr << 1);
0673                 memcpy(obuf + 2, msg[j].buf, msg[j].len);
0674                 dw210x_op_rw(d->udev, 0x80, 0, 0,
0675                         obuf, msg[j].len + 2,
0676                         DW210X_WRITE_MSG);
0677                 break;
0678             }
0679             break;
0680         }
0681         }
0682     }
0683     ret = num;
0684 
0685 unlock:
0686     mutex_unlock(&d->i2c_mutex);
0687     return ret;
0688 }
0689 
0690 static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
0691                                 int num)
0692 {
0693     struct dvb_usb_device *d = i2c_get_adapdata(adap);
0694     struct dw2102_state *state;
0695 
0696     if (!d)
0697         return -ENODEV;
0698 
0699     state = d->priv;
0700 
0701     if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
0702         return -EAGAIN;
0703     if (mutex_lock_interruptible(&d->data_mutex) < 0) {
0704         mutex_unlock(&d->i2c_mutex);
0705         return -EAGAIN;
0706     }
0707 
0708     switch (num) {
0709     case 1:
0710         switch (msg[0].addr) {
0711         case SU3000_STREAM_CTRL:
0712             state->data[0] = msg[0].buf[0] + 0x36;
0713             state->data[1] = 3;
0714             state->data[2] = 0;
0715             if (dvb_usb_generic_rw(d, state->data, 3,
0716                     state->data, 0, 0) < 0)
0717                 err("i2c transfer failed.");
0718             break;
0719         case DW2102_RC_QUERY:
0720             state->data[0] = 0x10;
0721             if (dvb_usb_generic_rw(d, state->data, 1,
0722                     state->data, 2, 0) < 0)
0723                 err("i2c transfer failed.");
0724             msg[0].buf[1] = state->data[0];
0725             msg[0].buf[0] = state->data[1];
0726             break;
0727         default:
0728             if (3 + msg[0].len > sizeof(state->data)) {
0729                 warn("i2c wr: len=%d is too big!\n",
0730                      msg[0].len);
0731                 num = -EOPNOTSUPP;
0732                 break;
0733             }
0734 
0735             /* always i2c write*/
0736             state->data[0] = 0x08;
0737             state->data[1] = msg[0].addr;
0738             state->data[2] = msg[0].len;
0739 
0740             memcpy(&state->data[3], msg[0].buf, msg[0].len);
0741 
0742             if (dvb_usb_generic_rw(d, state->data, msg[0].len + 3,
0743                         state->data, 1, 0) < 0)
0744                 err("i2c transfer failed.");
0745 
0746         }
0747         break;
0748     case 2:
0749         /* always i2c read */
0750         if (4 + msg[0].len > sizeof(state->data)) {
0751             warn("i2c rd: len=%d is too big!\n",
0752                  msg[0].len);
0753             num = -EOPNOTSUPP;
0754             break;
0755         }
0756         if (1 + msg[1].len > sizeof(state->data)) {
0757             warn("i2c rd: len=%d is too big!\n",
0758                  msg[1].len);
0759             num = -EOPNOTSUPP;
0760             break;
0761         }
0762 
0763         state->data[0] = 0x09;
0764         state->data[1] = msg[0].len;
0765         state->data[2] = msg[1].len;
0766         state->data[3] = msg[0].addr;
0767         memcpy(&state->data[4], msg[0].buf, msg[0].len);
0768 
0769         if (dvb_usb_generic_rw(d, state->data, msg[0].len + 4,
0770                     state->data, msg[1].len + 1, 0) < 0)
0771             err("i2c transfer failed.");
0772 
0773         memcpy(msg[1].buf, &state->data[1], msg[1].len);
0774         break;
0775     default:
0776         warn("more than 2 i2c messages at a time is not handled yet.");
0777         break;
0778     }
0779     mutex_unlock(&d->data_mutex);
0780     mutex_unlock(&d->i2c_mutex);
0781     return num;
0782 }
0783 
0784 static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
0785 {
0786     return I2C_FUNC_I2C;
0787 }
0788 
0789 static struct i2c_algorithm dw2102_i2c_algo = {
0790     .master_xfer = dw2102_i2c_transfer,
0791     .functionality = dw210x_i2c_func,
0792 };
0793 
0794 static struct i2c_algorithm dw2102_serit_i2c_algo = {
0795     .master_xfer = dw2102_serit_i2c_transfer,
0796     .functionality = dw210x_i2c_func,
0797 };
0798 
0799 static struct i2c_algorithm dw2102_earda_i2c_algo = {
0800     .master_xfer = dw2102_earda_i2c_transfer,
0801     .functionality = dw210x_i2c_func,
0802 };
0803 
0804 static struct i2c_algorithm dw2104_i2c_algo = {
0805     .master_xfer = dw2104_i2c_transfer,
0806     .functionality = dw210x_i2c_func,
0807 };
0808 
0809 static struct i2c_algorithm dw3101_i2c_algo = {
0810     .master_xfer = dw3101_i2c_transfer,
0811     .functionality = dw210x_i2c_func,
0812 };
0813 
0814 static struct i2c_algorithm s6x0_i2c_algo = {
0815     .master_xfer = s6x0_i2c_transfer,
0816     .functionality = dw210x_i2c_func,
0817 };
0818 
0819 static struct i2c_algorithm su3000_i2c_algo = {
0820     .master_xfer = su3000_i2c_transfer,
0821     .functionality = dw210x_i2c_func,
0822 };
0823 
0824 static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
0825 {
0826     int i;
0827     u8 ibuf[] = {0, 0};
0828     u8 eeprom[256], eepromline[16];
0829 
0830     for (i = 0; i < 256; i++) {
0831         if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
0832             err("read eeprom failed.");
0833             return -1;
0834         } else {
0835             eepromline[i%16] = ibuf[0];
0836             eeprom[i] = ibuf[0];
0837         }
0838         if ((i % 16) == 15) {
0839             deb_xfer("%02x: ", i - 15);
0840             debug_dump(eepromline, 16, deb_xfer);
0841         }
0842     }
0843 
0844     memcpy(mac, eeprom + 8, 6);
0845     return 0;
0846 };
0847 
0848 static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
0849 {
0850     int i, ret;
0851     u8 ibuf[] = { 0 }, obuf[] = { 0 };
0852     u8 eeprom[256], eepromline[16];
0853     struct i2c_msg msg[] = {
0854         {
0855             .addr = 0xa0 >> 1,
0856             .flags = 0,
0857             .buf = obuf,
0858             .len = 1,
0859         }, {
0860             .addr = 0xa0 >> 1,
0861             .flags = I2C_M_RD,
0862             .buf = ibuf,
0863             .len = 1,
0864         }
0865     };
0866 
0867     for (i = 0; i < 256; i++) {
0868         obuf[0] = i;
0869         ret = s6x0_i2c_transfer(&d->i2c_adap, msg, 2);
0870         if (ret != 2) {
0871             err("read eeprom failed.");
0872             return -1;
0873         } else {
0874             eepromline[i % 16] = ibuf[0];
0875             eeprom[i] = ibuf[0];
0876         }
0877 
0878         if ((i % 16) == 15) {
0879             deb_xfer("%02x: ", i - 15);
0880             debug_dump(eepromline, 16, deb_xfer);
0881         }
0882     }
0883 
0884     memcpy(mac, eeprom + 16, 6);
0885     return 0;
0886 };
0887 
0888 static int su3000_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
0889 {
0890     static u8 command_start[] = {0x00};
0891     static u8 command_stop[] = {0x01};
0892     struct i2c_msg msg = {
0893         .addr = SU3000_STREAM_CTRL,
0894         .flags = 0,
0895         .buf = onoff ? command_start : command_stop,
0896         .len = 1
0897     };
0898 
0899     i2c_transfer(&adap->dev->i2c_adap, &msg, 1);
0900 
0901     return 0;
0902 }
0903 
0904 static int su3000_power_ctrl(struct dvb_usb_device *d, int i)
0905 {
0906     struct dw2102_state *state = (struct dw2102_state *)d->priv;
0907     int ret = 0;
0908 
0909     info("%s: %d, initialized %d", __func__, i, state->initialized);
0910 
0911     if (i && !state->initialized) {
0912         mutex_lock(&d->data_mutex);
0913 
0914         state->data[0] = 0xde;
0915         state->data[1] = 0;
0916 
0917         state->initialized = 1;
0918         /* reset board */
0919         ret = dvb_usb_generic_rw(d, state->data, 2, NULL, 0, 0);
0920         mutex_unlock(&d->data_mutex);
0921     }
0922 
0923     return ret;
0924 }
0925 
0926 static int su3000_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
0927 {
0928     int i;
0929     u8 obuf[] = { 0x1f, 0xf0 };
0930     u8 ibuf[] = { 0 };
0931     struct i2c_msg msg[] = {
0932         {
0933             .addr = 0x51,
0934             .flags = 0,
0935             .buf = obuf,
0936             .len = 2,
0937         }, {
0938             .addr = 0x51,
0939             .flags = I2C_M_RD,
0940             .buf = ibuf,
0941             .len = 1,
0942 
0943         }
0944     };
0945 
0946     for (i = 0; i < 6; i++) {
0947         obuf[1] = 0xf0 + i;
0948         if (i2c_transfer(&d->i2c_adap, msg, 2) != 2)
0949             break;
0950         else
0951             mac[i] = ibuf[0];
0952     }
0953 
0954     return 0;
0955 }
0956 
0957 static int su3000_identify_state(struct usb_device *udev,
0958                  const struct dvb_usb_device_properties *props,
0959                  const struct dvb_usb_device_description **desc,
0960                  int *cold)
0961 {
0962     info("%s", __func__);
0963 
0964     *cold = 0;
0965     return 0;
0966 }
0967 
0968 static int dw210x_set_voltage(struct dvb_frontend *fe,
0969                   enum fe_sec_voltage voltage)
0970 {
0971     static u8 command_13v[] = {0x00, 0x01};
0972     static u8 command_18v[] = {0x01, 0x01};
0973     static u8 command_off[] = {0x00, 0x00};
0974     struct i2c_msg msg = {
0975         .addr = DW2102_VOLTAGE_CTRL,
0976         .flags = 0,
0977         .buf = command_off,
0978         .len = 2,
0979     };
0980 
0981     struct dvb_usb_adapter *udev_adap =
0982         (struct dvb_usb_adapter *)(fe->dvb->priv);
0983     if (voltage == SEC_VOLTAGE_18)
0984         msg.buf = command_18v;
0985     else if (voltage == SEC_VOLTAGE_13)
0986         msg.buf = command_13v;
0987 
0988     i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
0989 
0990     return 0;
0991 }
0992 
0993 static int s660_set_voltage(struct dvb_frontend *fe,
0994                 enum fe_sec_voltage voltage)
0995 {
0996     struct dvb_usb_adapter *d =
0997         (struct dvb_usb_adapter *)(fe->dvb->priv);
0998     struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
0999 
1000     dw210x_set_voltage(fe, voltage);
1001     if (st->old_set_voltage)
1002         st->old_set_voltage(fe, voltage);
1003 
1004     return 0;
1005 }
1006 
1007 static void dw210x_led_ctrl(struct dvb_frontend *fe, int offon)
1008 {
1009     static u8 led_off[] = { 0 };
1010     static u8 led_on[] = { 1 };
1011     struct i2c_msg msg = {
1012         .addr = DW2102_LED_CTRL,
1013         .flags = 0,
1014         .buf = led_off,
1015         .len = 1
1016     };
1017     struct dvb_usb_adapter *udev_adap =
1018         (struct dvb_usb_adapter *)(fe->dvb->priv);
1019 
1020     if (offon)
1021         msg.buf = led_on;
1022     i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
1023 }
1024 
1025 static int tt_s2_4600_read_status(struct dvb_frontend *fe,
1026                   enum fe_status *status)
1027 {
1028     struct dvb_usb_adapter *d =
1029         (struct dvb_usb_adapter *)(fe->dvb->priv);
1030     struct dw2102_state *st = (struct dw2102_state *)d->dev->priv;
1031     int ret;
1032 
1033     ret = st->fe_read_status(fe, status);
1034 
1035     /* resync slave fifo when signal change from unlock to lock */
1036     if ((*status & FE_HAS_LOCK) && (!st->last_lock))
1037         su3000_streaming_ctrl(d, 1);
1038 
1039     st->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
1040     return ret;
1041 }
1042 
1043 static struct stv0299_config sharp_z0194a_config = {
1044     .demod_address = 0x68,
1045     .inittab = sharp_z0194a_inittab,
1046     .mclk = 88000000UL,
1047     .invert = 1,
1048     .skip_reinit = 0,
1049     .lock_output = STV0299_LOCKOUTPUT_1,
1050     .volt13_op0_op1 = STV0299_VOLT13_OP1,
1051     .min_delay_ms = 100,
1052     .set_symbol_rate = sharp_z0194a_set_symbol_rate,
1053 };
1054 
1055 static struct cx24116_config dw2104_config = {
1056     .demod_address = 0x55,
1057     .mpg_clk_pos_pol = 0x01,
1058 };
1059 
1060 static struct si21xx_config serit_sp1511lhb_config = {
1061     .demod_address = 0x68,
1062     .min_delay_ms = 100,
1063 
1064 };
1065 
1066 static struct tda10023_config dw3101_tda10023_config = {
1067     .demod_address = 0x0c,
1068     .invert = 1,
1069 };
1070 
1071 static struct mt312_config zl313_config = {
1072     .demod_address = 0x0e,
1073 };
1074 
1075 static struct ds3000_config dw2104_ds3000_config = {
1076     .demod_address = 0x68,
1077 };
1078 
1079 static struct ts2020_config dw2104_ts2020_config = {
1080     .tuner_address = 0x60,
1081     .clk_out_div = 1,
1082     .frequency_div = 1060000,
1083 };
1084 
1085 static struct ds3000_config s660_ds3000_config = {
1086     .demod_address = 0x68,
1087     .ci_mode = 1,
1088     .set_lock_led = dw210x_led_ctrl,
1089 };
1090 
1091 static struct ts2020_config s660_ts2020_config = {
1092     .tuner_address = 0x60,
1093     .clk_out_div = 1,
1094     .frequency_div = 1146000,
1095 };
1096 
1097 static struct stv0900_config dw2104a_stv0900_config = {
1098     .demod_address = 0x6a,
1099     .demod_mode = 0,
1100     .xtal = 27000000,
1101     .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1102     .diseqc_mode = 2,/* 2/3 PWM */
1103     .tun1_maddress = 0,/* 0x60 */
1104     .tun1_adc = 0,/* 2 Vpp */
1105     .path1_mode = 3,
1106 };
1107 
1108 static struct stb6100_config dw2104a_stb6100_config = {
1109     .tuner_address = 0x60,
1110     .refclock = 27000000,
1111 };
1112 
1113 static struct stv0900_config dw2104_stv0900_config = {
1114     .demod_address = 0x68,
1115     .demod_mode = 0,
1116     .xtal = 8000000,
1117     .clkmode = 3,
1118     .diseqc_mode = 2,
1119     .tun1_maddress = 0,
1120     .tun1_adc = 1,/* 1 Vpp */
1121     .path1_mode = 3,
1122 };
1123 
1124 static struct stv6110_config dw2104_stv6110_config = {
1125     .i2c_address = 0x60,
1126     .mclk = 16000000,
1127     .clk_div = 1,
1128 };
1129 
1130 static struct stv0900_config prof_7500_stv0900_config = {
1131     .demod_address = 0x6a,
1132     .demod_mode = 0,
1133     .xtal = 27000000,
1134     .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
1135     .diseqc_mode = 2,/* 2/3 PWM */
1136     .tun1_maddress = 0,/* 0x60 */
1137     .tun1_adc = 0,/* 2 Vpp */
1138     .path1_mode = 3,
1139     .tun1_type = 3,
1140     .set_lock_led = dw210x_led_ctrl,
1141 };
1142 
1143 static struct ds3000_config su3000_ds3000_config = {
1144     .demod_address = 0x68,
1145     .ci_mode = 1,
1146     .set_lock_led = dw210x_led_ctrl,
1147 };
1148 
1149 static struct cxd2820r_config cxd2820r_config = {
1150     .i2c_address = 0x6c, /* (0xd8 >> 1) */
1151     .ts_mode = 0x38,
1152     .ts_clock_inv = 1,
1153 };
1154 
1155 static struct tda18271_config tda18271_config = {
1156     .output_opt = TDA18271_OUTPUT_LT_OFF,
1157     .gate = TDA18271_GATE_DIGITAL,
1158 };
1159 
1160 static u8 m88rs2000_inittab[] = {
1161     DEMOD_WRITE, 0x9a, 0x30,
1162     DEMOD_WRITE, 0x00, 0x01,
1163     WRITE_DELAY, 0x19, 0x00,
1164     DEMOD_WRITE, 0x00, 0x00,
1165     DEMOD_WRITE, 0x9a, 0xb0,
1166     DEMOD_WRITE, 0x81, 0xc1,
1167     DEMOD_WRITE, 0x81, 0x81,
1168     DEMOD_WRITE, 0x86, 0xc6,
1169     DEMOD_WRITE, 0x9a, 0x30,
1170     DEMOD_WRITE, 0xf0, 0x80,
1171     DEMOD_WRITE, 0xf1, 0xbf,
1172     DEMOD_WRITE, 0xb0, 0x45,
1173     DEMOD_WRITE, 0xb2, 0x01,
1174     DEMOD_WRITE, 0x9a, 0xb0,
1175     0xff, 0xaa, 0xff
1176 };
1177 
1178 static struct m88rs2000_config s421_m88rs2000_config = {
1179     .demod_addr = 0x68,
1180     .inittab = m88rs2000_inittab,
1181 };
1182 
1183 static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1184 {
1185     struct dvb_tuner_ops *tuner_ops = NULL;
1186 
1187     if (demod_probe & 4) {
1188         d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104a_stv0900_config,
1189                 &d->dev->i2c_adap, 0);
1190         if (d->fe_adap[0].fe != NULL) {
1191             if (dvb_attach(stb6100_attach, d->fe_adap[0].fe,
1192                     &dw2104a_stb6100_config,
1193                     &d->dev->i2c_adap)) {
1194                 tuner_ops = &d->fe_adap[0].fe->ops.tuner_ops;
1195                 tuner_ops->set_frequency = stb6100_set_freq;
1196                 tuner_ops->get_frequency = stb6100_get_freq;
1197                 tuner_ops->set_bandwidth = stb6100_set_bandw;
1198                 tuner_ops->get_bandwidth = stb6100_get_bandw;
1199                 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1200                 info("Attached STV0900+STB6100!");
1201                 return 0;
1202             }
1203         }
1204     }
1205 
1206     if (demod_probe & 2) {
1207         d->fe_adap[0].fe = dvb_attach(stv0900_attach, &dw2104_stv0900_config,
1208                 &d->dev->i2c_adap, 0);
1209         if (d->fe_adap[0].fe != NULL) {
1210             if (dvb_attach(stv6110_attach, d->fe_adap[0].fe,
1211                     &dw2104_stv6110_config,
1212                     &d->dev->i2c_adap)) {
1213                 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1214                 info("Attached STV0900+STV6110A!");
1215                 return 0;
1216             }
1217         }
1218     }
1219 
1220     if (demod_probe & 1) {
1221         d->fe_adap[0].fe = dvb_attach(cx24116_attach, &dw2104_config,
1222                 &d->dev->i2c_adap);
1223         if (d->fe_adap[0].fe != NULL) {
1224             d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1225             info("Attached cx24116!");
1226             return 0;
1227         }
1228     }
1229 
1230     d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1231             &d->dev->i2c_adap);
1232     if (d->fe_adap[0].fe != NULL) {
1233         dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1234             &dw2104_ts2020_config, &d->dev->i2c_adap);
1235         d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1236         info("Attached DS3000!");
1237         return 0;
1238     }
1239 
1240     return -EIO;
1241 }
1242 
1243 static struct dvb_usb_device_properties dw2102_properties;
1244 static struct dvb_usb_device_properties dw2104_properties;
1245 static struct dvb_usb_device_properties s6x0_properties;
1246 
1247 static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
1248 {
1249     if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
1250         /*dw2102_properties.adapter->tuner_attach = NULL;*/
1251         d->fe_adap[0].fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
1252                     &d->dev->i2c_adap);
1253         if (d->fe_adap[0].fe != NULL) {
1254             d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1255             info("Attached si21xx!");
1256             return 0;
1257         }
1258     }
1259 
1260     if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
1261         d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1262                     &d->dev->i2c_adap);
1263         if (d->fe_adap[0].fe != NULL) {
1264             if (dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61,
1265                     &d->dev->i2c_adap)) {
1266                 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1267                 info("Attached stv0288!");
1268                 return 0;
1269             }
1270         }
1271     }
1272 
1273     if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
1274         /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
1275         d->fe_adap[0].fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
1276                     &d->dev->i2c_adap);
1277         if (d->fe_adap[0].fe != NULL) {
1278             d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1279             info("Attached stv0299!");
1280             return 0;
1281         }
1282     }
1283     return -EIO;
1284 }
1285 
1286 static int dw3101_frontend_attach(struct dvb_usb_adapter *d)
1287 {
1288     d->fe_adap[0].fe = dvb_attach(tda10023_attach, &dw3101_tda10023_config,
1289                 &d->dev->i2c_adap, 0x48);
1290     if (d->fe_adap[0].fe != NULL) {
1291         info("Attached tda10023!");
1292         return 0;
1293     }
1294     return -EIO;
1295 }
1296 
1297 static int zl100313_frontend_attach(struct dvb_usb_adapter *d)
1298 {
1299     d->fe_adap[0].fe = dvb_attach(mt312_attach, &zl313_config,
1300             &d->dev->i2c_adap);
1301     if (d->fe_adap[0].fe != NULL) {
1302         if (dvb_attach(zl10039_attach, d->fe_adap[0].fe, 0x60,
1303                 &d->dev->i2c_adap)) {
1304             d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1305             info("Attached zl100313+zl10039!");
1306             return 0;
1307         }
1308     }
1309 
1310     return -EIO;
1311 }
1312 
1313 static int stv0288_frontend_attach(struct dvb_usb_adapter *d)
1314 {
1315     u8 obuf[] = {7, 1};
1316 
1317     d->fe_adap[0].fe = dvb_attach(stv0288_attach, &earda_config,
1318             &d->dev->i2c_adap);
1319 
1320     if (d->fe_adap[0].fe == NULL)
1321         return -EIO;
1322 
1323     if (NULL == dvb_attach(stb6000_attach, d->fe_adap[0].fe, 0x61, &d->dev->i2c_adap))
1324         return -EIO;
1325 
1326     d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1327 
1328     dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1329 
1330     info("Attached stv0288+stb6000!");
1331 
1332     return 0;
1333 
1334 }
1335 
1336 static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1337 {
1338     struct dw2102_state *st = d->dev->priv;
1339     u8 obuf[] = {7, 1};
1340 
1341     d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1342             &d->dev->i2c_adap);
1343 
1344     if (d->fe_adap[0].fe == NULL)
1345         return -EIO;
1346 
1347     dvb_attach(ts2020_attach, d->fe_adap[0].fe, &s660_ts2020_config,
1348         &d->dev->i2c_adap);
1349 
1350     st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1351     d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1352 
1353     dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1354 
1355     info("Attached ds3000+ts2020!");
1356 
1357     return 0;
1358 }
1359 
1360 static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
1361 {
1362     u8 obuf[] = {7, 1};
1363 
1364     d->fe_adap[0].fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
1365                     &d->dev->i2c_adap, 0);
1366     if (d->fe_adap[0].fe == NULL)
1367         return -EIO;
1368 
1369     d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1370 
1371     dw210x_op_rw(d->dev->udev, 0x8a, 0, 0, obuf, 2, DW210X_WRITE_MSG);
1372 
1373     info("Attached STV0900+STB6100A!");
1374 
1375     return 0;
1376 }
1377 
1378 static int su3000_frontend_attach(struct dvb_usb_adapter *adap)
1379 {
1380     struct dvb_usb_device *d = adap->dev;
1381     struct dw2102_state *state = d->priv;
1382 
1383     mutex_lock(&d->data_mutex);
1384 
1385     state->data[0] = 0xe;
1386     state->data[1] = 0x80;
1387     state->data[2] = 0;
1388 
1389     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1390         err("command 0x0e transfer failed.");
1391 
1392     state->data[0] = 0xe;
1393     state->data[1] = 0x02;
1394     state->data[2] = 1;
1395 
1396     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1397         err("command 0x0e transfer failed.");
1398     msleep(300);
1399 
1400     state->data[0] = 0xe;
1401     state->data[1] = 0x83;
1402     state->data[2] = 0;
1403 
1404     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1405         err("command 0x0e transfer failed.");
1406 
1407     state->data[0] = 0xe;
1408     state->data[1] = 0x83;
1409     state->data[2] = 1;
1410 
1411     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1412         err("command 0x0e transfer failed.");
1413 
1414     state->data[0] = 0x51;
1415 
1416     if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1417         err("command 0x51 transfer failed.");
1418 
1419     mutex_unlock(&d->data_mutex);
1420 
1421     adap->fe_adap[0].fe = dvb_attach(ds3000_attach, &su3000_ds3000_config,
1422                     &d->i2c_adap);
1423     if (adap->fe_adap[0].fe == NULL)
1424         return -EIO;
1425 
1426     if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1427                 &dw2104_ts2020_config,
1428                 &d->i2c_adap)) {
1429         info("Attached DS3000/TS2020!");
1430         return 0;
1431     }
1432 
1433     info("Failed to attach DS3000/TS2020!");
1434     return -EIO;
1435 }
1436 
1437 static int t220_frontend_attach(struct dvb_usb_adapter *adap)
1438 {
1439     struct dvb_usb_device *d = adap->dev;
1440     struct dw2102_state *state = d->priv;
1441 
1442     mutex_lock(&d->data_mutex);
1443 
1444     state->data[0] = 0xe;
1445     state->data[1] = 0x87;
1446     state->data[2] = 0x0;
1447 
1448     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1449         err("command 0x0e transfer failed.");
1450 
1451     state->data[0] = 0xe;
1452     state->data[1] = 0x86;
1453     state->data[2] = 1;
1454 
1455     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1456         err("command 0x0e transfer failed.");
1457 
1458     state->data[0] = 0xe;
1459     state->data[1] = 0x80;
1460     state->data[2] = 0;
1461 
1462     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1463         err("command 0x0e transfer failed.");
1464 
1465     msleep(50);
1466 
1467     state->data[0] = 0xe;
1468     state->data[1] = 0x80;
1469     state->data[2] = 1;
1470 
1471     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1472         err("command 0x0e transfer failed.");
1473 
1474     state->data[0] = 0x51;
1475 
1476     if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1477         err("command 0x51 transfer failed.");
1478 
1479     mutex_unlock(&d->data_mutex);
1480 
1481     adap->fe_adap[0].fe = dvb_attach(cxd2820r_attach, &cxd2820r_config,
1482                     &d->i2c_adap, NULL);
1483     if (adap->fe_adap[0].fe != NULL) {
1484         if (dvb_attach(tda18271_attach, adap->fe_adap[0].fe, 0x60,
1485                     &d->i2c_adap, &tda18271_config)) {
1486             info("Attached TDA18271HD/CXD2820R!");
1487             return 0;
1488         }
1489     }
1490 
1491     info("Failed to attach TDA18271HD/CXD2820R!");
1492     return -EIO;
1493 }
1494 
1495 static int m88rs2000_frontend_attach(struct dvb_usb_adapter *adap)
1496 {
1497     struct dvb_usb_device *d = adap->dev;
1498     struct dw2102_state *state = d->priv;
1499 
1500     mutex_lock(&d->data_mutex);
1501 
1502     state->data[0] = 0x51;
1503 
1504     if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1505         err("command 0x51 transfer failed.");
1506 
1507     mutex_unlock(&d->data_mutex);
1508 
1509     adap->fe_adap[0].fe = dvb_attach(m88rs2000_attach,
1510                     &s421_m88rs2000_config,
1511                     &d->i2c_adap);
1512 
1513     if (adap->fe_adap[0].fe == NULL)
1514         return -EIO;
1515 
1516     if (dvb_attach(ts2020_attach, adap->fe_adap[0].fe,
1517                 &dw2104_ts2020_config,
1518                 &d->i2c_adap)) {
1519         info("Attached RS2000/TS2020!");
1520         return 0;
1521     }
1522 
1523     info("Failed to attach RS2000/TS2020!");
1524     return -EIO;
1525 }
1526 
1527 static int tt_s2_4600_frontend_attach_probe_demod(struct dvb_usb_device *d,
1528                           const int probe_addr)
1529 {
1530     struct dw2102_state *state = d->priv;
1531 
1532     state->data[0] = 0x9;
1533     state->data[1] = 0x1;
1534     state->data[2] = 0x1;
1535     state->data[3] = probe_addr;
1536     state->data[4] = 0x0;
1537 
1538     if (dvb_usb_generic_rw(d, state->data, 5, state->data, 2, 0) < 0) {
1539         err("i2c probe for address 0x%x failed.", probe_addr);
1540         return 0;
1541     }
1542 
1543     if (state->data[0] != 8) /* fail(7) or error, no device at address */
1544         return 0;
1545 
1546     /* probing successful */
1547     return 1;
1548 }
1549 
1550 static int tt_s2_4600_frontend_attach(struct dvb_usb_adapter *adap)
1551 {
1552     struct dvb_usb_device *d = adap->dev;
1553     struct dw2102_state *state = d->priv;
1554     struct i2c_adapter *i2c_adapter;
1555     struct i2c_client *client;
1556     struct i2c_board_info board_info;
1557     struct m88ds3103_platform_data m88ds3103_pdata = {};
1558     struct ts2020_config ts2020_config = {};
1559     int demod_addr;
1560 
1561     mutex_lock(&d->data_mutex);
1562 
1563     state->data[0] = 0xe;
1564     state->data[1] = 0x80;
1565     state->data[2] = 0x0;
1566 
1567     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1568         err("command 0x0e transfer failed.");
1569 
1570     state->data[0] = 0xe;
1571     state->data[1] = 0x02;
1572     state->data[2] = 1;
1573 
1574     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1575         err("command 0x0e transfer failed.");
1576     msleep(300);
1577 
1578     state->data[0] = 0xe;
1579     state->data[1] = 0x83;
1580     state->data[2] = 0;
1581 
1582     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1583         err("command 0x0e transfer failed.");
1584 
1585     state->data[0] = 0xe;
1586     state->data[1] = 0x83;
1587     state->data[2] = 1;
1588 
1589     if (dvb_usb_generic_rw(d, state->data, 3, state->data, 1, 0) < 0)
1590         err("command 0x0e transfer failed.");
1591 
1592     state->data[0] = 0x51;
1593 
1594     if (dvb_usb_generic_rw(d, state->data, 1, state->data, 1, 0) < 0)
1595         err("command 0x51 transfer failed.");
1596 
1597     /* probe for demodulator i2c address */
1598     demod_addr = -1;
1599     if (tt_s2_4600_frontend_attach_probe_demod(d, 0x68))
1600         demod_addr = 0x68;
1601     else if (tt_s2_4600_frontend_attach_probe_demod(d, 0x69))
1602         demod_addr = 0x69;
1603     else if (tt_s2_4600_frontend_attach_probe_demod(d, 0x6a))
1604         demod_addr = 0x6a;
1605 
1606     mutex_unlock(&d->data_mutex);
1607 
1608     if (demod_addr < 0) {
1609         err("probing for demodulator failed. Is the external power switched on?");
1610         return -ENODEV;
1611     }
1612 
1613     /* attach demod */
1614     m88ds3103_pdata.clk = 27000000;
1615     m88ds3103_pdata.i2c_wr_max = 33;
1616     m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
1617     m88ds3103_pdata.ts_clk = 16000;
1618     m88ds3103_pdata.ts_clk_pol = 0;
1619     m88ds3103_pdata.spec_inv = 0;
1620     m88ds3103_pdata.agc = 0x99;
1621     m88ds3103_pdata.agc_inv = 0;
1622     m88ds3103_pdata.clk_out = M88DS3103_CLOCK_OUT_ENABLED;
1623     m88ds3103_pdata.envelope_mode = 0;
1624     m88ds3103_pdata.lnb_hv_pol = 1;
1625     m88ds3103_pdata.lnb_en_pol = 0;
1626     memset(&board_info, 0, sizeof(board_info));
1627     if (demod_addr == 0x6a)
1628         strscpy(board_info.type, "m88ds3103b", I2C_NAME_SIZE);
1629     else
1630         strscpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1631     board_info.addr = demod_addr;
1632     board_info.platform_data = &m88ds3103_pdata;
1633     request_module("m88ds3103");
1634     client = i2c_new_client_device(&d->i2c_adap, &board_info);
1635     if (!i2c_client_has_driver(client))
1636         return -ENODEV;
1637     if (!try_module_get(client->dev.driver->owner)) {
1638         i2c_unregister_device(client);
1639         return -ENODEV;
1640     }
1641     adap->fe_adap[0].fe = m88ds3103_pdata.get_dvb_frontend(client);
1642     i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1643 
1644     state->i2c_client_demod = client;
1645 
1646     /* attach tuner */
1647     ts2020_config.fe = adap->fe_adap[0].fe;
1648     memset(&board_info, 0, sizeof(board_info));
1649     strscpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1650     board_info.addr = 0x60;
1651     board_info.platform_data = &ts2020_config;
1652     request_module("ts2020");
1653     client = i2c_new_client_device(i2c_adapter, &board_info);
1654 
1655     if (!i2c_client_has_driver(client)) {
1656         dvb_frontend_detach(adap->fe_adap[0].fe);
1657         return -ENODEV;
1658     }
1659 
1660     if (!try_module_get(client->dev.driver->owner)) {
1661         i2c_unregister_device(client);
1662         dvb_frontend_detach(adap->fe_adap[0].fe);
1663         return -ENODEV;
1664     }
1665 
1666     /* delegate signal strength measurement to tuner */
1667     adap->fe_adap[0].fe->ops.read_signal_strength =
1668             adap->fe_adap[0].fe->ops.tuner_ops.get_rf_strength;
1669 
1670     state->i2c_client_tuner = client;
1671 
1672     /* hook fe: need to resync the slave fifo when signal locks */
1673     state->fe_read_status = adap->fe_adap[0].fe->ops.read_status;
1674     adap->fe_adap[0].fe->ops.read_status = tt_s2_4600_read_status;
1675 
1676     state->last_lock = 0;
1677 
1678     return 0;
1679 }
1680 
1681 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
1682 {
1683     dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1684         &adap->dev->i2c_adap, DVB_PLL_OPERA1);
1685     return 0;
1686 }
1687 
1688 static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
1689 {
1690     dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
1691         &adap->dev->i2c_adap, DVB_PLL_TUA6034);
1692 
1693     return 0;
1694 }
1695 
1696 static int dw2102_rc_query(struct dvb_usb_device *d)
1697 {
1698     u8 key[2];
1699     struct i2c_msg msg = {
1700         .addr = DW2102_RC_QUERY,
1701         .flags = I2C_M_RD,
1702         .buf = key,
1703         .len = 2
1704     };
1705 
1706     if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1707         if (msg.buf[0] != 0xff) {
1708             deb_rc("%s: rc code: %x, %x\n",
1709                     __func__, key[0], key[1]);
1710             rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0], 0);
1711         }
1712     }
1713 
1714     return 0;
1715 }
1716 
1717 static int prof_rc_query(struct dvb_usb_device *d)
1718 {
1719     u8 key[2];
1720     struct i2c_msg msg = {
1721         .addr = DW2102_RC_QUERY,
1722         .flags = I2C_M_RD,
1723         .buf = key,
1724         .len = 2
1725     };
1726 
1727     if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1728         if (msg.buf[0] != 0xff) {
1729             deb_rc("%s: rc code: %x, %x\n",
1730                     __func__, key[0], key[1]);
1731             rc_keydown(d->rc_dev, RC_PROTO_UNKNOWN, key[0] ^ 0xff,
1732                    0);
1733         }
1734     }
1735 
1736     return 0;
1737 }
1738 
1739 static int su3000_rc_query(struct dvb_usb_device *d)
1740 {
1741     u8 key[2];
1742     struct i2c_msg msg = {
1743         .addr = DW2102_RC_QUERY,
1744         .flags = I2C_M_RD,
1745         .buf = key,
1746         .len = 2
1747     };
1748 
1749     if (d->props.i2c_algo->master_xfer(&d->i2c_adap, &msg, 1) == 1) {
1750         if (msg.buf[0] != 0xff) {
1751             deb_rc("%s: rc code: %x, %x\n",
1752                     __func__, key[0], key[1]);
1753             rc_keydown(d->rc_dev, RC_PROTO_RC5,
1754                    RC_SCANCODE_RC5(key[1], key[0]), 0);
1755         }
1756     }
1757 
1758     return 0;
1759 }
1760 
1761 enum dw2102_table_entry {
1762     CYPRESS_DW2102,
1763     CYPRESS_DW2101,
1764     CYPRESS_DW2104,
1765     TEVII_S650,
1766     TERRATEC_CINERGY_S,
1767     CYPRESS_DW3101,
1768     TEVII_S630,
1769     PROF_1100,
1770     TEVII_S660,
1771     PROF_7500,
1772     GENIATECH_SU3000,
1773     HAUPPAUGE_MAX_S2,
1774     TERRATEC_CINERGY_S2_R1,
1775     TEVII_S480_1,
1776     TEVII_S480_2,
1777     GENIATECH_X3M_SPC1400HD,
1778     TEVII_S421,
1779     TEVII_S632,
1780     TERRATEC_CINERGY_S2_R2,
1781     TERRATEC_CINERGY_S2_R3,
1782     TERRATEC_CINERGY_S2_R4,
1783     TERRATEC_CINERGY_S2_1,
1784     TERRATEC_CINERGY_S2_2,
1785     GOTVIEW_SAT_HD,
1786     GENIATECH_T220,
1787     TECHNOTREND_CONNECT_S2_4600,
1788     TEVII_S482_1,
1789     TEVII_S482_2,
1790     TERRATEC_CINERGY_S2_BOX,
1791     TEVII_S662
1792 };
1793 
1794 static struct usb_device_id dw2102_table[] = {
1795     DVB_USB_DEV(CYPRESS, CYPRESS_DW2102),
1796     DVB_USB_DEV(CYPRESS, CYPRESS_DW2101),
1797     DVB_USB_DEV(CYPRESS, CYPRESS_DW2104),
1798     DVB_USB_DEV(TEVII, TEVII_S650),
1799     DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S),
1800     DVB_USB_DEV(CYPRESS, CYPRESS_DW3101),
1801     DVB_USB_DEV(TEVII, TEVII_S630),
1802     DVB_USB_DEV(PROF_1, PROF_1100),
1803     DVB_USB_DEV(TEVII, TEVII_S660),
1804     DVB_USB_DEV(PROF_2, PROF_7500),
1805     DVB_USB_DEV(GTEK, GENIATECH_SU3000),
1806     DVB_USB_DEV(HAUPPAUGE, HAUPPAUGE_MAX_S2),
1807     DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R1),
1808     DVB_USB_DEV(TEVII, TEVII_S480_1),
1809     DVB_USB_DEV(TEVII, TEVII_S480_2),
1810     DVB_USB_DEV(GTEK, GENIATECH_X3M_SPC1400HD),
1811     DVB_USB_DEV(TEVII, TEVII_S421),
1812     DVB_USB_DEV(TEVII, TEVII_S632),
1813     DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R2),
1814     DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R3),
1815     DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_R4),
1816     DVB_USB_DEV(TERRATEC_2, TERRATEC_CINERGY_S2_1),
1817     DVB_USB_DEV(TERRATEC_2, TERRATEC_CINERGY_S2_2),
1818     DVB_USB_DEV(GOTVIEW, GOTVIEW_SAT_HD),
1819     DVB_USB_DEV(GTEK, GENIATECH_T220),
1820     DVB_USB_DEV(TECHNOTREND, TECHNOTREND_CONNECT_S2_4600),
1821     DVB_USB_DEV(TEVII, TEVII_S482_1),
1822     DVB_USB_DEV(TEVII, TEVII_S482_2),
1823     DVB_USB_DEV(TERRATEC, TERRATEC_CINERGY_S2_BOX),
1824     DVB_USB_DEV(TEVII, TEVII_S662),
1825     { }
1826 };
1827 
1828 MODULE_DEVICE_TABLE(usb, dw2102_table);
1829 
1830 static int dw2102_load_firmware(struct usb_device *dev,
1831             const struct firmware *frmwr)
1832 {
1833     u8 *b, *p;
1834     int ret = 0, i;
1835     u8 reset;
1836     u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1837     const struct firmware *fw;
1838 
1839     switch (le16_to_cpu(dev->descriptor.idProduct)) {
1840     case 0x2101:
1841         ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1842         if (ret != 0) {
1843             err(err_str, DW2101_FIRMWARE);
1844             return ret;
1845         }
1846         break;
1847     default:
1848         fw = frmwr;
1849         break;
1850     }
1851     info("start downloading DW210X firmware");
1852     p = kmalloc(fw->size, GFP_KERNEL);
1853     reset = 1;
1854     /*stop the CPU*/
1855     dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
1856     dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
1857 
1858     if (p != NULL) {
1859         memcpy(p, fw->data, fw->size);
1860         for (i = 0; i < fw->size; i += 0x40) {
1861             b = (u8 *) p + i;
1862             if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
1863                     DW210X_WRITE_MSG) != 0x40) {
1864                 err("error while transferring firmware");
1865                 ret = -EINVAL;
1866                 break;
1867             }
1868         }
1869         /* restart the CPU */
1870         reset = 0;
1871         if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
1872                     DW210X_WRITE_MSG) != 1) {
1873             err("could not restart the USB controller CPU.");
1874             ret = -EINVAL;
1875         }
1876         if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
1877                     DW210X_WRITE_MSG) != 1) {
1878             err("could not restart the USB controller CPU.");
1879             ret = -EINVAL;
1880         }
1881         /* init registers */
1882         switch (le16_to_cpu(dev->descriptor.idProduct)) {
1883         case USB_PID_TEVII_S650:
1884             dw2104_properties.rc.core.rc_codes = RC_MAP_TEVII_NEC;
1885             fallthrough;
1886         case USB_PID_CYPRESS_DW2104:
1887             reset = 1;
1888             dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
1889                     DW210X_WRITE_MSG);
1890             fallthrough;
1891         case USB_PID_CYPRESS_DW3101:
1892             reset = 0;
1893             dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1894                     DW210X_WRITE_MSG);
1895             break;
1896         case USB_PID_TERRATEC_CINERGY_S:
1897         case USB_PID_CYPRESS_DW2102:
1898             dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
1899                     DW210X_WRITE_MSG);
1900             dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1901                     DW210X_READ_MSG);
1902             /* check STV0299 frontend  */
1903             dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
1904                     DW210X_READ_MSG);
1905             if ((reset16[0] == 0xa1) || (reset16[0] == 0x80)) {
1906                 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
1907                 dw2102_properties.adapter->fe[0].tuner_attach = &dw2102_tuner_attach;
1908                 break;
1909             } else {
1910                 /* check STV0288 frontend  */
1911                 reset16[0] = 0xd0;
1912                 reset16[1] = 1;
1913                 reset16[2] = 0;
1914                 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
1915                         DW210X_WRITE_MSG);
1916                 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
1917                         DW210X_READ_MSG);
1918                 if (reset16[2] == 0x11) {
1919                     dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
1920                     break;
1921                 }
1922             }
1923             fallthrough;
1924         case 0x2101:
1925             dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
1926                     DW210X_READ_MSG);
1927             dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1928                     DW210X_READ_MSG);
1929             dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
1930                     DW210X_READ_MSG);
1931             dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
1932                     DW210X_READ_MSG);
1933             break;
1934         }
1935 
1936         msleep(100);
1937         kfree(p);
1938     }
1939 
1940     if (le16_to_cpu(dev->descriptor.idProduct) == 0x2101)
1941         release_firmware(fw);
1942     return ret;
1943 }
1944 
1945 static struct dvb_usb_device_properties dw2102_properties = {
1946     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1947     .usb_ctrl = DEVICE_SPECIFIC,
1948     .firmware = DW2102_FIRMWARE,
1949     .no_reconnect = 1,
1950 
1951     .i2c_algo = &dw2102_serit_i2c_algo,
1952 
1953     .rc.core = {
1954         .rc_interval = 150,
1955         .rc_codes = RC_MAP_DM1105_NEC,
1956         .module_name = "dw2102",
1957         .allowed_protos   = RC_PROTO_BIT_NEC,
1958         .rc_query = dw2102_rc_query,
1959     },
1960 
1961     .generic_bulk_ctrl_endpoint = 0x81,
1962     /* parameter for the MPEG2-data transfer */
1963     .num_adapters = 1,
1964     .download_firmware = dw2102_load_firmware,
1965     .read_mac_address = dw210x_read_mac_address,
1966     .adapter = {
1967         {
1968         .num_frontends = 1,
1969         .fe = {{
1970             .frontend_attach = dw2102_frontend_attach,
1971             .stream = {
1972                 .type = USB_BULK,
1973                 .count = 8,
1974                 .endpoint = 0x82,
1975                 .u = {
1976                     .bulk = {
1977                         .buffersize = 4096,
1978                     }
1979                 }
1980             },
1981         }},
1982         }
1983     },
1984     .num_device_descs = 3,
1985     .devices = {
1986         {"DVBWorld DVB-S 2102 USB2.0",
1987             {&dw2102_table[CYPRESS_DW2102], NULL},
1988             {NULL},
1989         },
1990         {"DVBWorld DVB-S 2101 USB2.0",
1991             {&dw2102_table[CYPRESS_DW2101], NULL},
1992             {NULL},
1993         },
1994         {"TerraTec Cinergy S USB",
1995             {&dw2102_table[TERRATEC_CINERGY_S], NULL},
1996             {NULL},
1997         },
1998     }
1999 };
2000 
2001 static struct dvb_usb_device_properties dw2104_properties = {
2002     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2003     .usb_ctrl = DEVICE_SPECIFIC,
2004     .firmware = DW2104_FIRMWARE,
2005     .no_reconnect = 1,
2006 
2007     .i2c_algo = &dw2104_i2c_algo,
2008     .rc.core = {
2009         .rc_interval = 150,
2010         .rc_codes = RC_MAP_DM1105_NEC,
2011         .module_name = "dw2102",
2012         .allowed_protos   = RC_PROTO_BIT_NEC,
2013         .rc_query = dw2102_rc_query,
2014     },
2015 
2016     .generic_bulk_ctrl_endpoint = 0x81,
2017     /* parameter for the MPEG2-data transfer */
2018     .num_adapters = 1,
2019     .download_firmware = dw2102_load_firmware,
2020     .read_mac_address = dw210x_read_mac_address,
2021     .adapter = {
2022         {
2023         .num_frontends = 1,
2024         .fe = {{
2025             .frontend_attach = dw2104_frontend_attach,
2026             .stream = {
2027                 .type = USB_BULK,
2028                 .count = 8,
2029                 .endpoint = 0x82,
2030                 .u = {
2031                     .bulk = {
2032                         .buffersize = 4096,
2033                     }
2034                 }
2035             },
2036         }},
2037         }
2038     },
2039     .num_device_descs = 2,
2040     .devices = {
2041         { "DVBWorld DW2104 USB2.0",
2042             {&dw2102_table[CYPRESS_DW2104], NULL},
2043             {NULL},
2044         },
2045         { "TeVii S650 USB2.0",
2046             {&dw2102_table[TEVII_S650], NULL},
2047             {NULL},
2048         },
2049     }
2050 };
2051 
2052 static struct dvb_usb_device_properties dw3101_properties = {
2053     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2054     .usb_ctrl = DEVICE_SPECIFIC,
2055     .firmware = DW3101_FIRMWARE,
2056     .no_reconnect = 1,
2057 
2058     .i2c_algo = &dw3101_i2c_algo,
2059     .rc.core = {
2060         .rc_interval = 150,
2061         .rc_codes = RC_MAP_DM1105_NEC,
2062         .module_name = "dw2102",
2063         .allowed_protos   = RC_PROTO_BIT_NEC,
2064         .rc_query = dw2102_rc_query,
2065     },
2066 
2067     .generic_bulk_ctrl_endpoint = 0x81,
2068     /* parameter for the MPEG2-data transfer */
2069     .num_adapters = 1,
2070     .download_firmware = dw2102_load_firmware,
2071     .read_mac_address = dw210x_read_mac_address,
2072     .adapter = {
2073         {
2074         .num_frontends = 1,
2075         .fe = {{
2076             .frontend_attach = dw3101_frontend_attach,
2077             .tuner_attach = dw3101_tuner_attach,
2078             .stream = {
2079                 .type = USB_BULK,
2080                 .count = 8,
2081                 .endpoint = 0x82,
2082                 .u = {
2083                     .bulk = {
2084                         .buffersize = 4096,
2085                     }
2086                 }
2087             },
2088         }},
2089         }
2090     },
2091     .num_device_descs = 1,
2092     .devices = {
2093         { "DVBWorld DVB-C 3101 USB2.0",
2094             {&dw2102_table[CYPRESS_DW3101], NULL},
2095             {NULL},
2096         },
2097     }
2098 };
2099 
2100 static struct dvb_usb_device_properties s6x0_properties = {
2101     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2102     .usb_ctrl = DEVICE_SPECIFIC,
2103     .size_of_priv = sizeof(struct dw2102_state),
2104     .firmware = S630_FIRMWARE,
2105     .no_reconnect = 1,
2106 
2107     .i2c_algo = &s6x0_i2c_algo,
2108     .rc.core = {
2109         .rc_interval = 150,
2110         .rc_codes = RC_MAP_TEVII_NEC,
2111         .module_name = "dw2102",
2112         .allowed_protos   = RC_PROTO_BIT_NEC,
2113         .rc_query = dw2102_rc_query,
2114     },
2115 
2116     .generic_bulk_ctrl_endpoint = 0x81,
2117     .num_adapters = 1,
2118     .download_firmware = dw2102_load_firmware,
2119     .read_mac_address = s6x0_read_mac_address,
2120     .adapter = {
2121         {
2122         .num_frontends = 1,
2123         .fe = {{
2124             .frontend_attach = zl100313_frontend_attach,
2125             .stream = {
2126                 .type = USB_BULK,
2127                 .count = 8,
2128                 .endpoint = 0x82,
2129                 .u = {
2130                     .bulk = {
2131                         .buffersize = 4096,
2132                     }
2133                 }
2134             },
2135         }},
2136         }
2137     },
2138     .num_device_descs = 1,
2139     .devices = {
2140         {"TeVii S630 USB",
2141             {&dw2102_table[TEVII_S630], NULL},
2142             {NULL},
2143         },
2144     }
2145 };
2146 
2147 static struct dvb_usb_device_properties p1100_properties = {
2148     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2149     .usb_ctrl = DEVICE_SPECIFIC,
2150     .size_of_priv = sizeof(struct dw2102_state),
2151     .firmware = P1100_FIRMWARE,
2152     .no_reconnect = 1,
2153 
2154     .i2c_algo = &s6x0_i2c_algo,
2155     .rc.core = {
2156         .rc_interval = 150,
2157         .rc_codes = RC_MAP_TBS_NEC,
2158         .module_name = "dw2102",
2159         .allowed_protos   = RC_PROTO_BIT_NEC,
2160         .rc_query = prof_rc_query,
2161     },
2162 
2163     .generic_bulk_ctrl_endpoint = 0x81,
2164     .num_adapters = 1,
2165     .download_firmware = dw2102_load_firmware,
2166     .read_mac_address = s6x0_read_mac_address,
2167     .adapter = {
2168         {
2169             .num_frontends = 1,
2170             .fe = {{
2171                 .frontend_attach = stv0288_frontend_attach,
2172                 .stream = {
2173                     .type = USB_BULK,
2174                     .count = 8,
2175                     .endpoint = 0x82,
2176                     .u = {
2177                         .bulk = {
2178                             .buffersize = 4096,
2179                         }
2180                     }
2181                 },
2182             } },
2183         }
2184     },
2185     .num_device_descs = 1,
2186     .devices = {
2187         {"Prof 1100 USB ",
2188             {&dw2102_table[PROF_1100], NULL},
2189             {NULL},
2190         },
2191     }
2192 };
2193 
2194 static struct dvb_usb_device_properties s660_properties = {
2195     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2196     .usb_ctrl = DEVICE_SPECIFIC,
2197     .size_of_priv = sizeof(struct dw2102_state),
2198     .firmware = S660_FIRMWARE,
2199     .no_reconnect = 1,
2200 
2201     .i2c_algo = &s6x0_i2c_algo,
2202     .rc.core = {
2203         .rc_interval = 150,
2204         .rc_codes = RC_MAP_TEVII_NEC,
2205         .module_name = "dw2102",
2206         .allowed_protos   = RC_PROTO_BIT_NEC,
2207         .rc_query = dw2102_rc_query,
2208     },
2209 
2210     .generic_bulk_ctrl_endpoint = 0x81,
2211     .num_adapters = 1,
2212     .download_firmware = dw2102_load_firmware,
2213     .read_mac_address = s6x0_read_mac_address,
2214     .adapter = {
2215         {
2216             .num_frontends = 1,
2217             .fe = {{
2218                 .frontend_attach = ds3000_frontend_attach,
2219                 .stream = {
2220                     .type = USB_BULK,
2221                     .count = 8,
2222                     .endpoint = 0x82,
2223                     .u = {
2224                         .bulk = {
2225                             .buffersize = 4096,
2226                         }
2227                     }
2228                 },
2229             } },
2230         }
2231     },
2232     .num_device_descs = 3,
2233     .devices = {
2234         {"TeVii S660 USB",
2235             {&dw2102_table[TEVII_S660], NULL},
2236             {NULL},
2237         },
2238         {"TeVii S480.1 USB",
2239             {&dw2102_table[TEVII_S480_1], NULL},
2240             {NULL},
2241         },
2242         {"TeVii S480.2 USB",
2243             {&dw2102_table[TEVII_S480_2], NULL},
2244             {NULL},
2245         },
2246     }
2247 };
2248 
2249 static struct dvb_usb_device_properties p7500_properties = {
2250     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2251     .usb_ctrl = DEVICE_SPECIFIC,
2252     .size_of_priv = sizeof(struct dw2102_state),
2253     .firmware = P7500_FIRMWARE,
2254     .no_reconnect = 1,
2255 
2256     .i2c_algo = &s6x0_i2c_algo,
2257     .rc.core = {
2258         .rc_interval = 150,
2259         .rc_codes = RC_MAP_TBS_NEC,
2260         .module_name = "dw2102",
2261         .allowed_protos   = RC_PROTO_BIT_NEC,
2262         .rc_query = prof_rc_query,
2263     },
2264 
2265     .generic_bulk_ctrl_endpoint = 0x81,
2266     .num_adapters = 1,
2267     .download_firmware = dw2102_load_firmware,
2268     .read_mac_address = s6x0_read_mac_address,
2269     .adapter = {
2270         {
2271             .num_frontends = 1,
2272             .fe = {{
2273                 .frontend_attach = prof_7500_frontend_attach,
2274                 .stream = {
2275                     .type = USB_BULK,
2276                     .count = 8,
2277                     .endpoint = 0x82,
2278                     .u = {
2279                         .bulk = {
2280                             .buffersize = 4096,
2281                         }
2282                     }
2283                 },
2284             } },
2285         }
2286     },
2287     .num_device_descs = 1,
2288     .devices = {
2289         {"Prof 7500 USB DVB-S2",
2290             {&dw2102_table[PROF_7500], NULL},
2291             {NULL},
2292         },
2293     }
2294 };
2295 
2296 static struct dvb_usb_device_properties su3000_properties = {
2297     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2298     .usb_ctrl = DEVICE_SPECIFIC,
2299     .size_of_priv = sizeof(struct dw2102_state),
2300     .power_ctrl = su3000_power_ctrl,
2301     .num_adapters = 1,
2302     .identify_state = su3000_identify_state,
2303     .i2c_algo = &su3000_i2c_algo,
2304 
2305     .rc.core = {
2306         .rc_interval = 150,
2307         .rc_codes = RC_MAP_SU3000,
2308         .module_name = "dw2102",
2309         .allowed_protos   = RC_PROTO_BIT_RC5,
2310         .rc_query = su3000_rc_query,
2311     },
2312 
2313     .read_mac_address = su3000_read_mac_address,
2314 
2315     .generic_bulk_ctrl_endpoint = 0x01,
2316 
2317     .adapter = {
2318         {
2319         .num_frontends = 1,
2320         .fe = {{
2321             .streaming_ctrl   = su3000_streaming_ctrl,
2322             .frontend_attach  = su3000_frontend_attach,
2323             .stream = {
2324                 .type = USB_BULK,
2325                 .count = 8,
2326                 .endpoint = 0x82,
2327                 .u = {
2328                     .bulk = {
2329                         .buffersize = 4096,
2330                     }
2331                 }
2332             }
2333         }},
2334         }
2335     },
2336     .num_device_descs = 9,
2337     .devices = {
2338         { "SU3000HD DVB-S USB2.0",
2339             { &dw2102_table[GENIATECH_SU3000], NULL },
2340             { NULL },
2341         },
2342         { "Hauppauge MAX S2 or WinTV NOVA HD USB2.0",
2343             { &dw2102_table[HAUPPAUGE_MAX_S2], NULL },
2344             { NULL },
2345         },
2346         { "Terratec Cinergy S2 USB HD",
2347             { &dw2102_table[TERRATEC_CINERGY_S2_R1], NULL },
2348             { NULL },
2349         },
2350         { "X3M TV SPC1400HD PCI",
2351             { &dw2102_table[GENIATECH_X3M_SPC1400HD], NULL },
2352             { NULL },
2353         },
2354         { "Terratec Cinergy S2 USB HD Rev.2",
2355             { &dw2102_table[TERRATEC_CINERGY_S2_R2], NULL },
2356             { NULL },
2357         },
2358         { "Terratec Cinergy S2 USB HD Rev.3",
2359             { &dw2102_table[TERRATEC_CINERGY_S2_R3], NULL },
2360             { NULL },
2361         },
2362         { "Terratec Cinergy S2 PCIe Dual Port 1",
2363             { &dw2102_table[TERRATEC_CINERGY_S2_1], NULL },
2364             { NULL },
2365         },
2366         { "Terratec Cinergy S2 PCIe Dual Port 2",
2367             { &dw2102_table[TERRATEC_CINERGY_S2_2], NULL },
2368             { NULL },
2369         },
2370         { "GOTVIEW Satellite HD",
2371             { &dw2102_table[GOTVIEW_SAT_HD], NULL },
2372             { NULL },
2373         },
2374     }
2375 };
2376 
2377 static struct dvb_usb_device_properties s421_properties = {
2378     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2379     .usb_ctrl = DEVICE_SPECIFIC,
2380     .size_of_priv = sizeof(struct dw2102_state),
2381     .power_ctrl = su3000_power_ctrl,
2382     .num_adapters = 1,
2383     .identify_state = su3000_identify_state,
2384     .i2c_algo = &su3000_i2c_algo,
2385 
2386     .rc.core = {
2387         .rc_interval = 150,
2388         .rc_codes = RC_MAP_SU3000,
2389         .module_name = "dw2102",
2390         .allowed_protos   = RC_PROTO_BIT_RC5,
2391         .rc_query = su3000_rc_query,
2392     },
2393 
2394     .read_mac_address = su3000_read_mac_address,
2395 
2396     .generic_bulk_ctrl_endpoint = 0x01,
2397 
2398     .adapter = {
2399         {
2400         .num_frontends = 1,
2401         .fe = {{
2402             .streaming_ctrl   = su3000_streaming_ctrl,
2403             .frontend_attach  = m88rs2000_frontend_attach,
2404             .stream = {
2405                 .type = USB_BULK,
2406                 .count = 8,
2407                 .endpoint = 0x82,
2408                 .u = {
2409                     .bulk = {
2410                         .buffersize = 4096,
2411                     }
2412                 }
2413             }
2414         } },
2415         }
2416     },
2417     .num_device_descs = 2,
2418     .devices = {
2419         { "TeVii S421 PCI",
2420             { &dw2102_table[TEVII_S421], NULL },
2421             { NULL },
2422         },
2423         { "TeVii S632 USB",
2424             { &dw2102_table[TEVII_S632], NULL },
2425             { NULL },
2426         },
2427     }
2428 };
2429 
2430 static struct dvb_usb_device_properties t220_properties = {
2431     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2432     .usb_ctrl = DEVICE_SPECIFIC,
2433     .size_of_priv = sizeof(struct dw2102_state),
2434     .power_ctrl = su3000_power_ctrl,
2435     .num_adapters = 1,
2436     .identify_state = su3000_identify_state,
2437     .i2c_algo = &su3000_i2c_algo,
2438 
2439     .rc.core = {
2440         .rc_interval = 150,
2441         .rc_codes = RC_MAP_SU3000,
2442         .module_name = "dw2102",
2443         .allowed_protos   = RC_PROTO_BIT_RC5,
2444         .rc_query = su3000_rc_query,
2445     },
2446 
2447     .read_mac_address = su3000_read_mac_address,
2448 
2449     .generic_bulk_ctrl_endpoint = 0x01,
2450 
2451     .adapter = {
2452         {
2453         .num_frontends = 1,
2454         .fe = { {
2455             .streaming_ctrl   = su3000_streaming_ctrl,
2456             .frontend_attach  = t220_frontend_attach,
2457             .stream = {
2458                 .type = USB_BULK,
2459                 .count = 8,
2460                 .endpoint = 0x82,
2461                 .u = {
2462                     .bulk = {
2463                         .buffersize = 4096,
2464                     }
2465                 }
2466             }
2467         } },
2468         }
2469     },
2470     .num_device_descs = 1,
2471     .devices = {
2472         { "Geniatech T220 DVB-T/T2 USB2.0",
2473             { &dw2102_table[GENIATECH_T220], NULL },
2474             { NULL },
2475         },
2476     }
2477 };
2478 
2479 static struct dvb_usb_device_properties tt_s2_4600_properties = {
2480     .caps = DVB_USB_IS_AN_I2C_ADAPTER,
2481     .usb_ctrl = DEVICE_SPECIFIC,
2482     .size_of_priv = sizeof(struct dw2102_state),
2483     .power_ctrl = su3000_power_ctrl,
2484     .num_adapters = 1,
2485     .identify_state = su3000_identify_state,
2486     .i2c_algo = &su3000_i2c_algo,
2487 
2488     .rc.core = {
2489         .rc_interval = 250,
2490         .rc_codes = RC_MAP_TT_1500,
2491         .module_name = "dw2102",
2492         .allowed_protos   = RC_PROTO_BIT_RC5,
2493         .rc_query = su3000_rc_query,
2494     },
2495 
2496     .read_mac_address = su3000_read_mac_address,
2497 
2498     .generic_bulk_ctrl_endpoint = 0x01,
2499 
2500     .adapter = {
2501         {
2502         .num_frontends = 1,
2503         .fe = {{
2504             .streaming_ctrl   = su3000_streaming_ctrl,
2505             .frontend_attach  = tt_s2_4600_frontend_attach,
2506             .stream = {
2507                 .type = USB_BULK,
2508                 .count = 8,
2509                 .endpoint = 0x82,
2510                 .u = {
2511                     .bulk = {
2512                         .buffersize = 4096,
2513                     }
2514                 }
2515             }
2516         } },
2517         }
2518     },
2519     .num_device_descs = 5,
2520     .devices = {
2521         { "TechnoTrend TT-connect S2-4600",
2522             { &dw2102_table[TECHNOTREND_CONNECT_S2_4600], NULL },
2523             { NULL },
2524         },
2525         { "TeVii S482 (tuner 1)",
2526             { &dw2102_table[TEVII_S482_1], NULL },
2527             { NULL },
2528         },
2529         { "TeVii S482 (tuner 2)",
2530             { &dw2102_table[TEVII_S482_2], NULL },
2531             { NULL },
2532         },
2533         { "Terratec Cinergy S2 USB BOX",
2534             { &dw2102_table[TERRATEC_CINERGY_S2_BOX], NULL },
2535             { NULL },
2536         },
2537         { "TeVii S662",
2538             { &dw2102_table[TEVII_S662], NULL },
2539             { NULL },
2540         },
2541     }
2542 };
2543 
2544 static int dw2102_probe(struct usb_interface *intf,
2545         const struct usb_device_id *id)
2546 {
2547     if (!(dvb_usb_device_init(intf, &dw2102_properties,
2548                       THIS_MODULE, NULL, adapter_nr) &&
2549           dvb_usb_device_init(intf, &dw2104_properties,
2550                   THIS_MODULE, NULL, adapter_nr) &&
2551           dvb_usb_device_init(intf, &dw3101_properties,
2552                       THIS_MODULE, NULL, adapter_nr) &&
2553           dvb_usb_device_init(intf, &s6x0_properties,
2554                       THIS_MODULE, NULL, adapter_nr) &&
2555           dvb_usb_device_init(intf, &p1100_properties,
2556                       THIS_MODULE, NULL, adapter_nr) &&
2557           dvb_usb_device_init(intf, &s660_properties,
2558                   THIS_MODULE, NULL, adapter_nr) &&
2559           dvb_usb_device_init(intf, &p7500_properties,
2560                   THIS_MODULE, NULL, adapter_nr) &&
2561           dvb_usb_device_init(intf, &s421_properties,
2562                   THIS_MODULE, NULL, adapter_nr) &&
2563           dvb_usb_device_init(intf, &su3000_properties,
2564                   THIS_MODULE, NULL, adapter_nr) &&
2565           dvb_usb_device_init(intf, &t220_properties,
2566                   THIS_MODULE, NULL, adapter_nr) &&
2567           dvb_usb_device_init(intf, &tt_s2_4600_properties,
2568                   THIS_MODULE, NULL, adapter_nr))) {
2569 
2570         return 0;
2571     }
2572 
2573     return -ENODEV;
2574 }
2575 
2576 static void dw2102_disconnect(struct usb_interface *intf)
2577 {
2578     struct dvb_usb_device *d = usb_get_intfdata(intf);
2579     struct dw2102_state *st = (struct dw2102_state *)d->priv;
2580     struct i2c_client *client;
2581 
2582     /* remove I2C client for tuner */
2583     client = st->i2c_client_tuner;
2584     if (client) {
2585         module_put(client->dev.driver->owner);
2586         i2c_unregister_device(client);
2587     }
2588 
2589     /* remove I2C client for demodulator */
2590     client = st->i2c_client_demod;
2591     if (client) {
2592         module_put(client->dev.driver->owner);
2593         i2c_unregister_device(client);
2594     }
2595 
2596     dvb_usb_device_exit(intf);
2597 }
2598 
2599 static struct usb_driver dw2102_driver = {
2600     .name = "dw2102",
2601     .probe = dw2102_probe,
2602     .disconnect = dw2102_disconnect,
2603     .id_table = dw2102_table,
2604 };
2605 
2606 module_usb_driver(dw2102_driver);
2607 
2608 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
2609 MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101 USB2.0, TeVii S421, S480, S482, S600, S630, S632, S650, TeVii S660, S662, Prof 1100, 7500 USB2.0, Geniatech SU3000, T220, TechnoTrend S2-4600, Terratec Cinergy S2 devices");
2610 MODULE_VERSION("0.1");
2611 MODULE_LICENSE("GPL");
2612 MODULE_FIRMWARE(DW2101_FIRMWARE);
2613 MODULE_FIRMWARE(DW2102_FIRMWARE);
2614 MODULE_FIRMWARE(DW2104_FIRMWARE);
2615 MODULE_FIRMWARE(DW3101_FIRMWARE);
2616 MODULE_FIRMWARE(S630_FIRMWARE);
2617 MODULE_FIRMWARE(S660_FIRMWARE);
2618 MODULE_FIRMWARE(P1100_FIRMWARE);
2619 MODULE_FIRMWARE(P7500_FIRMWARE);