linux/drivers/media/usb/dvb-usb-v2/dvbsky.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*
   3 * Driver for DVBSky USB2.0 receiver
   4 *
   5 * Copyright (C) 2013 Max nibble <nibble.max@gmail.com>
   6 */
   7
   8#include "dvb_usb.h"
   9#include "m88ds3103.h"
  10#include "ts2020.h"
  11#include "sp2.h"
  12#include "si2168.h"
  13#include "si2157.h"
  14
  15#define DVBSKY_MSG_DELAY        0/*2000*/
  16#define DVBSKY_BUF_LEN  64
  17
  18static int dvb_usb_dvbsky_disable_rc;
  19module_param_named(disable_rc, dvb_usb_dvbsky_disable_rc, int, 0644);
  20MODULE_PARM_DESC(disable_rc, "Disable inbuilt IR receiver.");
  21
  22DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  23
  24struct dvbsky_state {
  25        struct mutex stream_mutex;
  26        u8 ibuf[DVBSKY_BUF_LEN];
  27        u8 obuf[DVBSKY_BUF_LEN];
  28        u8 last_lock;
  29        struct i2c_client *i2c_client_demod;
  30        struct i2c_client *i2c_client_tuner;
  31        struct i2c_client *i2c_client_ci;
  32
  33        /* fe hook functions*/
  34        int (*fe_set_voltage)(struct dvb_frontend *fe,
  35                enum fe_sec_voltage voltage);
  36        int (*fe_read_status)(struct dvb_frontend *fe,
  37                enum fe_status *status);
  38};
  39
  40static int dvbsky_usb_generic_rw(struct dvb_usb_device *d,
  41                u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
  42{
  43        int ret;
  44        struct dvbsky_state *state = d_to_priv(d);
  45
  46        mutex_lock(&d->usb_mutex);
  47        if (wlen != 0)
  48                memcpy(state->obuf, wbuf, wlen);
  49
  50        ret = dvb_usbv2_generic_rw_locked(d, state->obuf, wlen,
  51                        state->ibuf, rlen);
  52
  53        if (!ret && (rlen != 0))
  54                memcpy(rbuf, state->ibuf, rlen);
  55
  56        mutex_unlock(&d->usb_mutex);
  57        return ret;
  58}
  59
  60static int dvbsky_stream_ctrl(struct dvb_usb_device *d, u8 onoff)
  61{
  62        struct dvbsky_state *state = d_to_priv(d);
  63        int ret;
  64        u8 obuf_pre[3] = { 0x37, 0, 0 };
  65        u8 obuf_post[3] = { 0x36, 3, 0 };
  66
  67        mutex_lock(&state->stream_mutex);
  68        ret = dvbsky_usb_generic_rw(d, obuf_pre, 3, NULL, 0);
  69        if (!ret && onoff) {
  70                msleep(20);
  71                ret = dvbsky_usb_generic_rw(d, obuf_post, 3, NULL, 0);
  72        }
  73        mutex_unlock(&state->stream_mutex);
  74        return ret;
  75}
  76
  77static int dvbsky_streaming_ctrl(struct dvb_frontend *fe, int onoff)
  78{
  79        struct dvb_usb_device *d = fe_to_d(fe);
  80
  81        return dvbsky_stream_ctrl(d, (onoff == 0) ? 0 : 1);
  82}
  83
  84/* GPIO */
  85static int dvbsky_gpio_ctrl(struct dvb_usb_device *d, u8 gport, u8 value)
  86{
  87        int ret;
  88        u8 obuf[3], ibuf[2];
  89
  90        obuf[0] = 0x0e;
  91        obuf[1] = gport;
  92        obuf[2] = value;
  93        ret = dvbsky_usb_generic_rw(d, obuf, 3, ibuf, 1);
  94        return ret;
  95}
  96
  97/* I2C */
  98static int dvbsky_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
  99        int num)
 100{
 101        struct dvb_usb_device *d = i2c_get_adapdata(adap);
 102        int ret = 0;
 103        u8 ibuf[64], obuf[64];
 104
 105        if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
 106                return -EAGAIN;
 107
 108        if (num > 2) {
 109                dev_err(&d->udev->dev,
 110                "too many i2c messages[%d], max 2.", num);
 111                ret = -EOPNOTSUPP;
 112                goto i2c_error;
 113        }
 114
 115        if (num == 1) {
 116                if (msg[0].len > 60) {
 117                        dev_err(&d->udev->dev,
 118                        "too many i2c bytes[%d], max 60.",
 119                        msg[0].len);
 120                        ret = -EOPNOTSUPP;
 121                        goto i2c_error;
 122                }
 123                if (msg[0].flags & I2C_M_RD) {
 124                        /* single read */
 125                        obuf[0] = 0x09;
 126                        obuf[1] = 0;
 127                        obuf[2] = msg[0].len;
 128                        obuf[3] = msg[0].addr;
 129                        ret = dvbsky_usb_generic_rw(d, obuf, 4,
 130                                        ibuf, msg[0].len + 1);
 131                        if (!ret)
 132                                memcpy(msg[0].buf, &ibuf[1], msg[0].len);
 133                } else {
 134                        /* write */
 135                        obuf[0] = 0x08;
 136                        obuf[1] = msg[0].addr;
 137                        obuf[2] = msg[0].len;
 138                        memcpy(&obuf[3], msg[0].buf, msg[0].len);
 139                        ret = dvbsky_usb_generic_rw(d, obuf,
 140                                        msg[0].len + 3, ibuf, 1);
 141                }
 142        } else {
 143                if ((msg[0].len > 60) || (msg[1].len > 60)) {
 144                        dev_err(&d->udev->dev,
 145                        "too many i2c bytes[w-%d][r-%d], max 60.",
 146                        msg[0].len, msg[1].len);
 147                        ret = -EOPNOTSUPP;
 148                        goto i2c_error;
 149                }
 150                /* write then read */
 151                obuf[0] = 0x09;
 152                obuf[1] = msg[0].len;
 153                obuf[2] = msg[1].len;
 154                obuf[3] = msg[0].addr;
 155                memcpy(&obuf[4], msg[0].buf, msg[0].len);
 156                ret = dvbsky_usb_generic_rw(d, obuf,
 157                        msg[0].len + 4, ibuf, msg[1].len + 1);
 158                if (!ret)
 159                        memcpy(msg[1].buf, &ibuf[1], msg[1].len);
 160        }
 161i2c_error:
 162        mutex_unlock(&d->i2c_mutex);
 163        return (ret) ? ret : num;
 164}
 165
 166static u32 dvbsky_i2c_func(struct i2c_adapter *adapter)
 167{
 168        return I2C_FUNC_I2C;
 169}
 170
 171static struct i2c_algorithm dvbsky_i2c_algo = {
 172        .master_xfer   = dvbsky_i2c_xfer,
 173        .functionality = dvbsky_i2c_func,
 174};
 175
 176#if IS_ENABLED(CONFIG_RC_CORE)
 177static int dvbsky_rc_query(struct dvb_usb_device *d)
 178{
 179        u32 code = 0xffff, scancode;
 180        u8 rc5_command, rc5_system;
 181        u8 obuf[2], ibuf[2], toggle;
 182        int ret;
 183
 184        obuf[0] = 0x10;
 185        ret = dvbsky_usb_generic_rw(d, obuf, 1, ibuf, 2);
 186        if (ret == 0)
 187                code = (ibuf[0] << 8) | ibuf[1];
 188        if (code != 0xffff) {
 189                dev_dbg(&d->udev->dev, "rc code: %x\n", code);
 190                rc5_command = code & 0x3F;
 191                rc5_system = (code & 0x7C0) >> 6;
 192                toggle = (code & 0x800) ? 1 : 0;
 193                scancode = rc5_system << 8 | rc5_command;
 194                rc_keydown(d->rc_dev, RC_PROTO_RC5, scancode, toggle);
 195        }
 196        return 0;
 197}
 198
 199static int dvbsky_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
 200{
 201        if (dvb_usb_dvbsky_disable_rc) {
 202                rc->map_name = NULL;
 203                return 0;
 204        }
 205
 206        rc->allowed_protos = RC_PROTO_BIT_RC5;
 207        rc->query          = dvbsky_rc_query;
 208        rc->interval       = 300;
 209        return 0;
 210}
 211#else
 212        #define dvbsky_get_rc_config NULL
 213#endif
 214
 215static int dvbsky_usb_set_voltage(struct dvb_frontend *fe,
 216        enum fe_sec_voltage voltage)
 217{
 218        struct dvb_usb_device *d = fe_to_d(fe);
 219        struct dvbsky_state *state = d_to_priv(d);
 220        u8 value;
 221
 222        if (voltage == SEC_VOLTAGE_OFF)
 223                value = 0;
 224        else
 225                value = 1;
 226        dvbsky_gpio_ctrl(d, 0x80, value);
 227
 228        return state->fe_set_voltage(fe, voltage);
 229}
 230
 231static int dvbsky_read_mac_addr(struct dvb_usb_adapter *adap, u8 mac[6])
 232{
 233        struct dvb_usb_device *d = adap_to_d(adap);
 234        u8 obuf[] = { 0x1e, 0x00 };
 235        u8 ibuf[6] = { 0 };
 236        struct i2c_msg msg[] = {
 237                {
 238                        .addr = 0x51,
 239                        .flags = 0,
 240                        .buf = obuf,
 241                        .len = 2,
 242                }, {
 243                        .addr = 0x51,
 244                        .flags = I2C_M_RD,
 245                        .buf = ibuf,
 246                        .len = 6,
 247                }
 248        };
 249
 250        if (i2c_transfer(&d->i2c_adap, msg, 2) == 2)
 251                memcpy(mac, ibuf, 6);
 252
 253        return 0;
 254}
 255
 256static int dvbsky_usb_read_status(struct dvb_frontend *fe,
 257                                  enum fe_status *status)
 258{
 259        struct dvb_usb_device *d = fe_to_d(fe);
 260        struct dvbsky_state *state = d_to_priv(d);
 261        int ret;
 262
 263        ret = state->fe_read_status(fe, status);
 264
 265        /* it need resync slave fifo when signal change from unlock to lock.*/
 266        if ((*status & FE_HAS_LOCK) && (!state->last_lock))
 267                dvbsky_stream_ctrl(d, 1);
 268
 269        state->last_lock = (*status & FE_HAS_LOCK) ? 1 : 0;
 270        return ret;
 271}
 272
 273static int dvbsky_s960_attach(struct dvb_usb_adapter *adap)
 274{
 275        struct dvbsky_state *state = adap_to_priv(adap);
 276        struct dvb_usb_device *d = adap_to_d(adap);
 277        struct i2c_adapter *i2c_adapter;
 278        struct m88ds3103_platform_data m88ds3103_pdata = {};
 279        struct ts2020_config ts2020_config = {};
 280
 281        /* attach demod */
 282        m88ds3103_pdata.clk = 27000000;
 283        m88ds3103_pdata.i2c_wr_max = 33;
 284        m88ds3103_pdata.clk_out = 0;
 285        m88ds3103_pdata.ts_mode = M88DS3103_TS_CI;
 286        m88ds3103_pdata.ts_clk = 16000;
 287        m88ds3103_pdata.ts_clk_pol = 0;
 288        m88ds3103_pdata.agc = 0x99;
 289        m88ds3103_pdata.lnb_hv_pol = 1,
 290        m88ds3103_pdata.lnb_en_pol = 1,
 291
 292        state->i2c_client_demod = dvb_module_probe("m88ds3103", NULL,
 293                                                   &d->i2c_adap,
 294                                                   0x68, &m88ds3103_pdata);
 295        if (!state->i2c_client_demod)
 296                return -ENODEV;
 297
 298        adap->fe[0] = m88ds3103_pdata.get_dvb_frontend(state->i2c_client_demod);
 299        i2c_adapter = m88ds3103_pdata.get_i2c_adapter(state->i2c_client_demod);
 300
 301        /* attach tuner */
 302        ts2020_config.fe = adap->fe[0];
 303        ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
 304
 305        state->i2c_client_tuner = dvb_module_probe("ts2020", NULL,
 306                                                   i2c_adapter,
 307                                                   0x60, &ts2020_config);
 308        if (!state->i2c_client_tuner) {
 309                dvb_module_release(state->i2c_client_demod);
 310                return -ENODEV;
 311        }
 312
 313        /* delegate signal strength measurement to tuner */
 314        adap->fe[0]->ops.read_signal_strength =
 315                        adap->fe[0]->ops.tuner_ops.get_rf_strength;
 316
 317        /* hook fe: need to resync the slave fifo when signal locks. */
 318        state->fe_read_status = adap->fe[0]->ops.read_status;
 319        adap->fe[0]->ops.read_status = dvbsky_usb_read_status;
 320
 321        /* hook fe: LNB off/on is control by Cypress usb chip. */
 322        state->fe_set_voltage = adap->fe[0]->ops.set_voltage;
 323        adap->fe[0]->ops.set_voltage = dvbsky_usb_set_voltage;
 324
 325        return 0;
 326}
 327
 328static int dvbsky_usb_ci_set_voltage(struct dvb_frontend *fe,
 329        enum fe_sec_voltage voltage)
 330{
 331        struct dvb_usb_device *d = fe_to_d(fe);
 332        struct dvbsky_state *state = d_to_priv(d);
 333        u8 value;
 334
 335        if (voltage == SEC_VOLTAGE_OFF)
 336                value = 0;
 337        else
 338                value = 1;
 339        dvbsky_gpio_ctrl(d, 0x00, value);
 340
 341        return state->fe_set_voltage(fe, voltage);
 342}
 343
 344static int dvbsky_ci_ctrl(void *priv, u8 read, int addr,
 345                                        u8 data, int *mem)
 346{
 347        struct dvb_usb_device *d = priv;
 348        int ret = 0;
 349        u8 command[4], respond[2], command_size, respond_size;
 350
 351        command[1] = (u8)((addr >> 8) & 0xff); /*high part of address*/
 352        command[2] = (u8)(addr & 0xff); /*low part of address*/
 353        if (read) {
 354                command[0] = 0x71;
 355                command_size = 3;
 356                respond_size = 2;
 357        } else {
 358                command[0] = 0x70;
 359                command[3] = data;
 360                command_size = 4;
 361                respond_size = 1;
 362        }
 363        ret = dvbsky_usb_generic_rw(d, command, command_size,
 364                        respond, respond_size);
 365        if (ret)
 366                goto err;
 367        if (read)
 368                *mem = respond[1];
 369        return ret;
 370err:
 371        dev_err(&d->udev->dev, "ci control failed=%d\n", ret);
 372        return ret;
 373}
 374
 375static int dvbsky_s960c_attach(struct dvb_usb_adapter *adap)
 376{
 377        struct dvbsky_state *state = adap_to_priv(adap);
 378        struct dvb_usb_device *d = adap_to_d(adap);
 379        struct i2c_adapter *i2c_adapter;
 380        struct m88ds3103_platform_data m88ds3103_pdata = {};
 381        struct ts2020_config ts2020_config = {};
 382        struct sp2_config sp2_config = {};
 383
 384        /* attach demod */
 385        m88ds3103_pdata.clk = 27000000,
 386        m88ds3103_pdata.i2c_wr_max = 33,
 387        m88ds3103_pdata.clk_out = 0,
 388        m88ds3103_pdata.ts_mode = M88DS3103_TS_CI,
 389        m88ds3103_pdata.ts_clk = 10000,
 390        m88ds3103_pdata.ts_clk_pol = 1,
 391        m88ds3103_pdata.agc = 0x99,
 392        m88ds3103_pdata.lnb_hv_pol = 0,
 393        m88ds3103_pdata.lnb_en_pol = 1,
 394
 395        state->i2c_client_demod = dvb_module_probe("m88ds3103", NULL,
 396                                                   &d->i2c_adap,
 397                                                   0x68, &m88ds3103_pdata);
 398        if (!state->i2c_client_demod)
 399                return -ENODEV;
 400
 401        adap->fe[0] = m88ds3103_pdata.get_dvb_frontend(state->i2c_client_demod);
 402        i2c_adapter = m88ds3103_pdata.get_i2c_adapter(state->i2c_client_demod);
 403
 404        /* attach tuner */
 405        ts2020_config.fe = adap->fe[0];
 406        ts2020_config.get_agc_pwm = m88ds3103_get_agc_pwm;
 407
 408        state->i2c_client_tuner = dvb_module_probe("ts2020", NULL,
 409                                                   i2c_adapter,
 410                                                   0x60, &ts2020_config);
 411        if (!state->i2c_client_tuner) {
 412                dvb_module_release(state->i2c_client_demod);
 413                return -ENODEV;
 414        }
 415
 416        /* attach ci controller */
 417        sp2_config.dvb_adap = &adap->dvb_adap;
 418        sp2_config.priv = d;
 419        sp2_config.ci_control = dvbsky_ci_ctrl;
 420
 421        state->i2c_client_ci = dvb_module_probe("sp2", NULL,
 422                                                &d->i2c_adap,
 423                                                0x40, &sp2_config);
 424
 425        if (!state->i2c_client_ci) {
 426                dvb_module_release(state->i2c_client_tuner);
 427                dvb_module_release(state->i2c_client_demod);
 428                return -ENODEV;
 429        }
 430
 431        /* delegate signal strength measurement to tuner */
 432        adap->fe[0]->ops.read_signal_strength =
 433                        adap->fe[0]->ops.tuner_ops.get_rf_strength;
 434
 435        /* hook fe: need to resync the slave fifo when signal locks. */
 436        state->fe_read_status = adap->fe[0]->ops.read_status;
 437        adap->fe[0]->ops.read_status = dvbsky_usb_read_status;
 438
 439        /* hook fe: LNB off/on is control by Cypress usb chip. */
 440        state->fe_set_voltage = adap->fe[0]->ops.set_voltage;
 441        adap->fe[0]->ops.set_voltage = dvbsky_usb_ci_set_voltage;
 442
 443        return 0;
 444}
 445
 446static int dvbsky_t680c_attach(struct dvb_usb_adapter *adap)
 447{
 448        struct dvbsky_state *state = adap_to_priv(adap);
 449        struct dvb_usb_device *d = adap_to_d(adap);
 450        struct i2c_adapter *i2c_adapter;
 451        struct si2168_config si2168_config = {};
 452        struct si2157_config si2157_config = {};
 453        struct sp2_config sp2_config = {};
 454
 455        /* attach demod */
 456        si2168_config.i2c_adapter = &i2c_adapter;
 457        si2168_config.fe = &adap->fe[0];
 458        si2168_config.ts_mode = SI2168_TS_PARALLEL;
 459
 460        state->i2c_client_demod = dvb_module_probe("si2168", NULL,
 461                                                   &d->i2c_adap,
 462                                                   0x64, &si2168_config);
 463        if (!state->i2c_client_demod)
 464                return -ENODEV;
 465
 466        /* attach tuner */
 467        si2157_config.fe = adap->fe[0];
 468        si2157_config.if_port = 1;
 469
 470        state->i2c_client_tuner = dvb_module_probe("si2157", NULL,
 471                                                   i2c_adapter,
 472                                                   0x60, &si2157_config);
 473        if (!state->i2c_client_tuner) {
 474                dvb_module_release(state->i2c_client_demod);
 475                return -ENODEV;
 476        }
 477
 478        /* attach ci controller */
 479        sp2_config.dvb_adap = &adap->dvb_adap;
 480        sp2_config.priv = d;
 481        sp2_config.ci_control = dvbsky_ci_ctrl;
 482
 483        state->i2c_client_ci = dvb_module_probe("sp2", NULL,
 484                                                &d->i2c_adap,
 485                                                0x40, &sp2_config);
 486
 487        if (!state->i2c_client_ci) {
 488                dvb_module_release(state->i2c_client_tuner);
 489                dvb_module_release(state->i2c_client_demod);
 490                return -ENODEV;
 491        }
 492
 493        return 0;
 494}
 495
 496static int dvbsky_t330_attach(struct dvb_usb_adapter *adap)
 497{
 498        struct dvbsky_state *state = adap_to_priv(adap);
 499        struct dvb_usb_device *d = adap_to_d(adap);
 500        struct i2c_adapter *i2c_adapter;
 501        struct si2168_config si2168_config = {};
 502        struct si2157_config si2157_config = {};
 503
 504        /* attach demod */
 505        si2168_config.i2c_adapter = &i2c_adapter;
 506        si2168_config.fe = &adap->fe[0];
 507        si2168_config.ts_mode = SI2168_TS_PARALLEL;
 508        si2168_config.ts_clock_gapped = true;
 509
 510        state->i2c_client_demod = dvb_module_probe("si2168", NULL,
 511                                                   &d->i2c_adap,
 512                                                   0x64, &si2168_config);
 513        if (!state->i2c_client_demod)
 514                return -ENODEV;
 515
 516        /* attach tuner */
 517        si2157_config.fe = adap->fe[0];
 518        si2157_config.if_port = 1;
 519
 520        state->i2c_client_tuner = dvb_module_probe("si2157", NULL,
 521                                                   i2c_adapter,
 522                                                   0x60, &si2157_config);
 523        if (!state->i2c_client_tuner) {
 524                dvb_module_release(state->i2c_client_demod);
 525                return -ENODEV;
 526        }
 527
 528        return 0;
 529}
 530
 531static int dvbsky_mygica_t230c_attach(struct dvb_usb_adapter *adap)
 532{
 533        struct dvbsky_state *state = adap_to_priv(adap);
 534        struct dvb_usb_device *d = adap_to_d(adap);
 535        struct i2c_adapter *i2c_adapter;
 536        struct si2168_config si2168_config = {};
 537        struct si2157_config si2157_config = {};
 538
 539        /* attach demod */
 540        si2168_config.i2c_adapter = &i2c_adapter;
 541        si2168_config.fe = &adap->fe[0];
 542        si2168_config.ts_mode = SI2168_TS_PARALLEL;
 543        if (le16_to_cpu(d->udev->descriptor.idProduct) == USB_PID_MYGICA_T230C2)
 544                si2168_config.ts_mode |= SI2168_TS_CLK_MANUAL;
 545        si2168_config.ts_clock_inv = 1;
 546
 547        state->i2c_client_demod = dvb_module_probe("si2168", NULL,
 548                                                   &d->i2c_adap,
 549                                                   0x64, &si2168_config);
 550        if (!state->i2c_client_demod)
 551                return -ENODEV;
 552
 553        /* attach tuner */
 554        si2157_config.fe = adap->fe[0];
 555        if (le16_to_cpu(d->udev->descriptor.idProduct) == USB_PID_MYGICA_T230) {
 556                si2157_config.if_port = 1;
 557                state->i2c_client_tuner = dvb_module_probe("si2157", NULL,
 558                                                           i2c_adapter,
 559                                                           0x60,
 560                                                           &si2157_config);
 561        } else {
 562                si2157_config.if_port = 0;
 563                state->i2c_client_tuner = dvb_module_probe("si2157", "si2141",
 564                                                           i2c_adapter,
 565                                                           0x60,
 566                                                           &si2157_config);
 567        }
 568        if (!state->i2c_client_tuner) {
 569                dvb_module_release(state->i2c_client_demod);
 570                return -ENODEV;
 571        }
 572
 573        return 0;
 574}
 575
 576
 577static int dvbsky_identify_state(struct dvb_usb_device *d, const char **name)
 578{
 579        dvbsky_gpio_ctrl(d, 0x04, 1);
 580        msleep(20);
 581        dvbsky_gpio_ctrl(d, 0x83, 0);
 582        dvbsky_gpio_ctrl(d, 0xc0, 1);
 583        msleep(100);
 584        dvbsky_gpio_ctrl(d, 0x83, 1);
 585        dvbsky_gpio_ctrl(d, 0xc0, 0);
 586        msleep(50);
 587
 588        return WARM;
 589}
 590
 591static int dvbsky_init(struct dvb_usb_device *d)
 592{
 593        struct dvbsky_state *state = d_to_priv(d);
 594
 595        /* use default interface */
 596        /*
 597        ret = usb_set_interface(d->udev, 0, 0);
 598        if (ret)
 599                return ret;
 600        */
 601        mutex_init(&state->stream_mutex);
 602
 603        state->last_lock = 0;
 604
 605        return 0;
 606}
 607
 608static int dvbsky_frontend_detach(struct dvb_usb_adapter *adap)
 609{
 610        struct dvb_usb_device *d = adap_to_d(adap);
 611        struct dvbsky_state *state = d_to_priv(d);
 612
 613        dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, adap->id);
 614
 615        dvb_module_release(state->i2c_client_tuner);
 616        dvb_module_release(state->i2c_client_demod);
 617        dvb_module_release(state->i2c_client_ci);
 618
 619        return 0;
 620}
 621
 622/* DVB USB Driver stuff */
 623static struct dvb_usb_device_properties dvbsky_s960_props = {
 624        .driver_name = KBUILD_MODNAME,
 625        .owner = THIS_MODULE,
 626        .adapter_nr = adapter_nr,
 627        .size_of_priv = sizeof(struct dvbsky_state),
 628
 629        .generic_bulk_ctrl_endpoint = 0x01,
 630        .generic_bulk_ctrl_endpoint_response = 0x81,
 631        .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
 632
 633        .i2c_algo         = &dvbsky_i2c_algo,
 634        .frontend_attach  = dvbsky_s960_attach,
 635        .frontend_detach  = dvbsky_frontend_detach,
 636        .init             = dvbsky_init,
 637        .get_rc_config    = dvbsky_get_rc_config,
 638        .streaming_ctrl   = dvbsky_streaming_ctrl,
 639        .identify_state   = dvbsky_identify_state,
 640        .read_mac_address = dvbsky_read_mac_addr,
 641
 642        .num_adapters = 1,
 643        .adapter = {
 644                {
 645                        .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
 646                }
 647        }
 648};
 649
 650static struct dvb_usb_device_properties dvbsky_s960c_props = {
 651        .driver_name = KBUILD_MODNAME,
 652        .owner = THIS_MODULE,
 653        .adapter_nr = adapter_nr,
 654        .size_of_priv = sizeof(struct dvbsky_state),
 655
 656        .generic_bulk_ctrl_endpoint = 0x01,
 657        .generic_bulk_ctrl_endpoint_response = 0x81,
 658        .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
 659
 660        .i2c_algo         = &dvbsky_i2c_algo,
 661        .frontend_attach  = dvbsky_s960c_attach,
 662        .frontend_detach  = dvbsky_frontend_detach,
 663        .init             = dvbsky_init,
 664        .get_rc_config    = dvbsky_get_rc_config,
 665        .streaming_ctrl   = dvbsky_streaming_ctrl,
 666        .identify_state   = dvbsky_identify_state,
 667        .read_mac_address = dvbsky_read_mac_addr,
 668
 669        .num_adapters = 1,
 670        .adapter = {
 671                {
 672                        .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
 673                }
 674        }
 675};
 676
 677static struct dvb_usb_device_properties dvbsky_t680c_props = {
 678        .driver_name = KBUILD_MODNAME,
 679        .owner = THIS_MODULE,
 680        .adapter_nr = adapter_nr,
 681        .size_of_priv = sizeof(struct dvbsky_state),
 682
 683        .generic_bulk_ctrl_endpoint = 0x01,
 684        .generic_bulk_ctrl_endpoint_response = 0x81,
 685        .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
 686
 687        .i2c_algo         = &dvbsky_i2c_algo,
 688        .frontend_attach  = dvbsky_t680c_attach,
 689        .frontend_detach  = dvbsky_frontend_detach,
 690        .init             = dvbsky_init,
 691        .get_rc_config    = dvbsky_get_rc_config,
 692        .streaming_ctrl   = dvbsky_streaming_ctrl,
 693        .identify_state   = dvbsky_identify_state,
 694        .read_mac_address = dvbsky_read_mac_addr,
 695
 696        .num_adapters = 1,
 697        .adapter = {
 698                {
 699                        .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
 700                }
 701        }
 702};
 703
 704static struct dvb_usb_device_properties dvbsky_t330_props = {
 705        .driver_name = KBUILD_MODNAME,
 706        .owner = THIS_MODULE,
 707        .adapter_nr = adapter_nr,
 708        .size_of_priv = sizeof(struct dvbsky_state),
 709
 710        .generic_bulk_ctrl_endpoint = 0x01,
 711        .generic_bulk_ctrl_endpoint_response = 0x81,
 712        .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
 713
 714        .i2c_algo         = &dvbsky_i2c_algo,
 715        .frontend_attach  = dvbsky_t330_attach,
 716        .frontend_detach  = dvbsky_frontend_detach,
 717        .init             = dvbsky_init,
 718        .get_rc_config    = dvbsky_get_rc_config,
 719        .streaming_ctrl   = dvbsky_streaming_ctrl,
 720        .identify_state   = dvbsky_identify_state,
 721        .read_mac_address = dvbsky_read_mac_addr,
 722
 723        .num_adapters = 1,
 724        .adapter = {
 725                {
 726                        .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
 727                }
 728        }
 729};
 730
 731static struct dvb_usb_device_properties mygica_t230c_props = {
 732        .driver_name = KBUILD_MODNAME,
 733        .owner = THIS_MODULE,
 734        .adapter_nr = adapter_nr,
 735        .size_of_priv = sizeof(struct dvbsky_state),
 736
 737        .generic_bulk_ctrl_endpoint = 0x01,
 738        .generic_bulk_ctrl_endpoint_response = 0x81,
 739        .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
 740
 741        .i2c_algo         = &dvbsky_i2c_algo,
 742        .frontend_attach  = dvbsky_mygica_t230c_attach,
 743        .frontend_detach  = dvbsky_frontend_detach,
 744        .init             = dvbsky_init,
 745        .get_rc_config    = dvbsky_get_rc_config,
 746        .streaming_ctrl   = dvbsky_streaming_ctrl,
 747        .identify_state   = dvbsky_identify_state,
 748
 749        .num_adapters = 1,
 750        .adapter = {
 751                {
 752                        .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
 753                }
 754        }
 755};
 756
 757static const struct usb_device_id dvbsky_id_table[] = {
 758        { DVB_USB_DEVICE(0x0572, 0x6831,
 759                &dvbsky_s960_props, "DVBSky S960/S860", RC_MAP_DVBSKY) },
 760        { DVB_USB_DEVICE(0x0572, 0x960c,
 761                &dvbsky_s960c_props, "DVBSky S960CI", RC_MAP_DVBSKY) },
 762        { DVB_USB_DEVICE(0x0572, 0x680c,
 763                &dvbsky_t680c_props, "DVBSky T680CI", RC_MAP_DVBSKY) },
 764        { DVB_USB_DEVICE(0x0572, 0x0320,
 765                &dvbsky_t330_props, "DVBSky T330", RC_MAP_DVBSKY) },
 766        { DVB_USB_DEVICE(USB_VID_TECHNOTREND,
 767                USB_PID_TECHNOTREND_TVSTICK_CT2_4400,
 768                &dvbsky_t330_props, "TechnoTrend TVStick CT2-4400",
 769                RC_MAP_TT_1500) },
 770        { DVB_USB_DEVICE(USB_VID_TECHNOTREND,
 771                USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI,
 772                &dvbsky_t680c_props, "TechnoTrend TT-connect CT2-4650 CI",
 773                RC_MAP_TT_1500) },
 774        { DVB_USB_DEVICE(USB_VID_TECHNOTREND,
 775                USB_PID_TECHNOTREND_CONNECT_CT2_4650_CI_2,
 776                &dvbsky_t680c_props, "TechnoTrend TT-connect CT2-4650 CI v1.1",
 777                RC_MAP_TT_1500) },
 778        { DVB_USB_DEVICE(USB_VID_TECHNOTREND,
 779                USB_PID_TECHNOTREND_CONNECT_S2_4650_CI,
 780                &dvbsky_s960c_props, "TechnoTrend TT-connect S2-4650 CI",
 781                RC_MAP_TT_1500) },
 782        { DVB_USB_DEVICE(USB_VID_TERRATEC,
 783                USB_PID_TERRATEC_H7_3,
 784                &dvbsky_t680c_props, "Terratec H7 Rev.4",
 785                RC_MAP_TT_1500) },
 786        { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_S2_R4,
 787                &dvbsky_s960_props, "Terratec Cinergy S2 Rev.4",
 788                RC_MAP_DVBSKY) },
 789        { DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230,
 790                &mygica_t230c_props, "MyGica Mini DVB-T2 USB Stick T230",
 791                RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
 792        { DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C,
 793                &mygica_t230c_props, "MyGica Mini DVB-T2 USB Stick T230C",
 794                RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
 795        { DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C2,
 796                &mygica_t230c_props, "MyGica Mini DVB-T2 USB Stick T230C v2",
 797                RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
 798        { }
 799};
 800MODULE_DEVICE_TABLE(usb, dvbsky_id_table);
 801
 802static struct usb_driver dvbsky_usb_driver = {
 803        .name = KBUILD_MODNAME,
 804        .id_table = dvbsky_id_table,
 805        .probe = dvb_usbv2_probe,
 806        .disconnect = dvb_usbv2_disconnect,
 807        .suspend = dvb_usbv2_suspend,
 808        .resume = dvb_usbv2_resume,
 809        .reset_resume = dvb_usbv2_reset_resume,
 810        .no_dynamic_id = 1,
 811        .soft_unbind = 1,
 812};
 813
 814module_usb_driver(dvbsky_usb_driver);
 815
 816MODULE_AUTHOR("Max nibble <nibble.max@gmail.com>");
 817MODULE_DESCRIPTION("Driver for DVBSky USB");
 818MODULE_LICENSE("GPL");
 819