Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af9015.c
Go to the documentation of this file.
1 /*
2  * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
3  *
4  * Copyright (C) 2007 Antti Palosaari <[email protected]>
5  *
6  * Thanks to Afatech who kindly provided information.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */
23 
24 #include "af9015.h"
25 
26 static int dvb_usb_af9015_remote;
27 module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
28 MODULE_PARM_DESC(remote, "select remote");
30 
31 static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
32 {
33 #define BUF_LEN 63
34 #define REQ_HDR_LEN 8 /* send header size */
35 #define ACK_HDR_LEN 2 /* rece header size */
36  struct af9015_state *state = d_to_priv(d);
37  int ret, wlen, rlen;
38  u8 buf[BUF_LEN];
39  u8 write = 1;
40 
41  buf[0] = req->cmd;
42  buf[1] = state->seq++;
43  buf[2] = req->i2c_addr;
44  buf[3] = req->addr >> 8;
45  buf[4] = req->addr & 0xff;
46  buf[5] = req->mbox;
47  buf[6] = req->addr_len;
48  buf[7] = req->data_len;
49 
50  switch (req->cmd) {
51  case GET_CONFIG:
52  case READ_MEMORY:
53  case RECONNECT_USB:
54  write = 0;
55  break;
56  case READ_I2C:
57  write = 0;
58  buf[2] |= 0x01; /* set I2C direction */
59  case WRITE_I2C:
60  buf[0] = READ_WRITE_I2C;
61  break;
62  case WRITE_MEMORY:
63  if (((req->addr & 0xff00) == 0xff00) ||
64  ((req->addr & 0xff00) == 0xae00))
65  buf[0] = WRITE_VIRTUAL_MEMORY;
67  case COPY_FIRMWARE:
68  case DOWNLOAD_FIRMWARE:
69  case BOOT:
70  break;
71  default:
72  dev_err(&d->udev->dev, "%s: unknown command=%d\n",
73  KBUILD_MODNAME, req->cmd);
74  ret = -EIO;
75  goto error;
76  }
77 
78  /* buffer overflow check */
79  if ((write && (req->data_len > BUF_LEN - REQ_HDR_LEN)) ||
80  (!write && (req->data_len > BUF_LEN - ACK_HDR_LEN))) {
81  dev_err(&d->udev->dev, "%s: too much data; cmd=%d len=%d\n",
82  KBUILD_MODNAME, req->cmd, req->data_len);
83  ret = -EINVAL;
84  goto error;
85  }
86 
87  /* write receives seq + status = 2 bytes
88  read receives seq + status + data = 2 + N bytes */
89  wlen = REQ_HDR_LEN;
90  rlen = ACK_HDR_LEN;
91  if (write) {
92  wlen += req->data_len;
93  memcpy(&buf[REQ_HDR_LEN], req->data, req->data_len);
94  } else {
95  rlen += req->data_len;
96  }
97 
98  /* no ack for these packets */
99  if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
100  rlen = 0;
101 
102  ret = dvb_usbv2_generic_rw(d, buf, wlen, buf, rlen);
103  if (ret)
104  goto error;
105 
106  /* check status */
107  if (rlen && buf[1]) {
108  dev_err(&d->udev->dev, "%s: command failed=%d\n",
109  KBUILD_MODNAME, buf[1]);
110  ret = -EIO;
111  goto error;
112  }
113 
114  /* read request, copy returned data to return buf */
115  if (!write)
116  memcpy(req->data, &buf[ACK_HDR_LEN], req->data_len);
117 error:
118  return ret;
119 }
120 
121 static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val,
122  u8 len)
123 {
124  struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
125  val};
126  return af9015_ctrl_msg(d, &req);
127 }
128 
129 static int af9015_read_regs(struct dvb_usb_device *d, u16 addr, u8 *val, u8 len)
130 {
131  struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
132  val};
133  return af9015_ctrl_msg(d, &req);
134 }
135 
136 static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)
137 {
138  return af9015_write_regs(d, addr, &val, 1);
139 }
140 
141 static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)
142 {
143  return af9015_read_regs(d, addr, val, 1);
144 }
145 
146 static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
147  u8 val)
148 {
149  struct af9015_state *state = d_to_priv(d);
150  struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
151 
152  if (addr == state->af9013_config[0].i2c_addr ||
153  addr == state->af9013_config[1].i2c_addr)
154  req.addr_len = 3;
155 
156  return af9015_ctrl_msg(d, &req);
157 }
158 
159 static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
160  u8 *val)
161 {
162  struct af9015_state *state = d_to_priv(d);
163  struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
164 
165  if (addr == state->af9013_config[0].i2c_addr ||
166  addr == state->af9013_config[1].i2c_addr)
167  req.addr_len = 3;
168 
169  return af9015_ctrl_msg(d, &req);
170 }
171 
172 static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op)
173 {
174  int ret;
175  u8 val, mask = 0x01;
176 
177  ret = af9015_read_reg(d, addr, &val);
178  if (ret)
179  return ret;
180 
181  mask <<= bit;
182  if (op) {
183  /* set bit */
184  val |= mask;
185  } else {
186  /* clear bit */
187  mask ^= 0xff;
188  val &= mask;
189  }
190 
191  return af9015_write_reg(d, addr, val);
192 }
193 
194 static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
195 {
196  return af9015_do_reg_bit(d, addr, bit, 1);
197 }
198 
199 static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
200 {
201  return af9015_do_reg_bit(d, addr, bit, 0);
202 }
203 
204 static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
205  int num)
206 {
207  struct dvb_usb_device *d = i2c_get_adapdata(adap);
208  struct af9015_state *state = d_to_priv(d);
209  int ret = 0, i = 0;
210  u16 addr;
211  u8 uninitialized_var(mbox), addr_len;
212  struct req_t req;
213 
214 /*
215 The bus lock is needed because there is two tuners both using same I2C-address.
216 Due to that the only way to select correct tuner is use demodulator I2C-gate.
217 
218 ................................................
219 . AF9015 includes integrated AF9013 demodulator.
220 . ____________ ____________ . ____________
221 .| uC | | demod | . | tuner |
222 .|------------| |------------| . |------------|
223 .| AF9015 | | AF9013/5 | . | MXL5003 |
224 .| |--+----I2C-------|-----/ -----|-.-----I2C-------| |
225 .| | | | addr 0x38 | . | addr 0xc6 |
226 .|____________| | |____________| . |____________|
227 .................|..............................
228  | ____________ ____________
229  | | demod | | tuner |
230  | |------------| |------------|
231  | | AF9013 | | MXL5003 |
232  +----I2C-------|-----/ -----|-------I2C-------| |
233  | addr 0x3a | | addr 0xc6 |
234  |____________| |____________|
235 */
236  if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
237  return -EAGAIN;
238 
239  while (i < num) {
240  if (msg[i].addr == state->af9013_config[0].i2c_addr ||
241  msg[i].addr == state->af9013_config[1].i2c_addr) {
242  addr = msg[i].buf[0] << 8;
243  addr += msg[i].buf[1];
244  mbox = msg[i].buf[2];
245  addr_len = 3;
246  } else {
247  addr = msg[i].buf[0];
248  addr_len = 1;
249  /* mbox is don't care in that case */
250  }
251 
252  if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
253  if (msg[i].len > 3 || msg[i+1].len > 61) {
254  ret = -EOPNOTSUPP;
255  goto error;
256  }
257  if (msg[i].addr == state->af9013_config[0].i2c_addr)
258  req.cmd = READ_MEMORY;
259  else
260  req.cmd = READ_I2C;
261  req.i2c_addr = msg[i].addr;
262  req.addr = addr;
263  req.mbox = mbox;
264  req.addr_len = addr_len;
265  req.data_len = msg[i+1].len;
266  req.data = &msg[i+1].buf[0];
267  ret = af9015_ctrl_msg(d, &req);
268  i += 2;
269  } else if (msg[i].flags & I2C_M_RD) {
270  if (msg[i].len > 61) {
271  ret = -EOPNOTSUPP;
272  goto error;
273  }
274  if (msg[i].addr == state->af9013_config[0].i2c_addr) {
275  ret = -EINVAL;
276  goto error;
277  }
278  req.cmd = READ_I2C;
279  req.i2c_addr = msg[i].addr;
280  req.addr = addr;
281  req.mbox = mbox;
282  req.addr_len = addr_len;
283  req.data_len = msg[i].len;
284  req.data = &msg[i].buf[0];
285  ret = af9015_ctrl_msg(d, &req);
286  i += 1;
287  } else {
288  if (msg[i].len > 21) {
289  ret = -EOPNOTSUPP;
290  goto error;
291  }
292  if (msg[i].addr == state->af9013_config[0].i2c_addr)
293  req.cmd = WRITE_MEMORY;
294  else
295  req.cmd = WRITE_I2C;
296  req.i2c_addr = msg[i].addr;
297  req.addr = addr;
298  req.mbox = mbox;
299  req.addr_len = addr_len;
300  req.data_len = msg[i].len-addr_len;
301  req.data = &msg[i].buf[addr_len];
302  ret = af9015_ctrl_msg(d, &req);
303  i += 1;
304  }
305  if (ret)
306  goto error;
307 
308  }
309  ret = i;
310 
311 error:
312  mutex_unlock(&d->i2c_mutex);
313 
314  return ret;
315 }
316 
317 static u32 af9015_i2c_func(struct i2c_adapter *adapter)
318 {
319  return I2C_FUNC_I2C;
320 }
321 
322 static struct i2c_algorithm af9015_i2c_algo = {
323  .master_xfer = af9015_i2c_xfer,
324  .functionality = af9015_i2c_func,
325 };
326 
327 static int af9015_identify_state(struct dvb_usb_device *d, const char **name)
328 {
329  int ret;
330  u8 reply;
331  struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};
332 
333  ret = af9015_ctrl_msg(d, &req);
334  if (ret)
335  return ret;
336 
337  dev_dbg(&d->udev->dev, "%s: reply=%02x\n", __func__, reply);
338 
339  if (reply == 0x02)
340  ret = WARM;
341  else
342  ret = COLD;
343 
344  return ret;
345 }
346 
347 static int af9015_download_firmware(struct dvb_usb_device *d,
348  const struct firmware *fw)
349 {
350  struct af9015_state *state = d_to_priv(d);
351  int i, len, remaining, ret;
352  struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
353  u16 checksum = 0;
354  dev_dbg(&d->udev->dev, "%s:\n", __func__);
355 
356  /* calc checksum */
357  for (i = 0; i < fw->size; i++)
358  checksum += fw->data[i];
359 
360  state->firmware_size = fw->size;
361  state->firmware_checksum = checksum;
362 
363  #define FW_ADDR 0x5100 /* firmware start address */
364  #define LEN_MAX 55 /* max packet size */
365  for (remaining = fw->size; remaining > 0; remaining -= LEN_MAX) {
366  len = remaining;
367  if (len > LEN_MAX)
368  len = LEN_MAX;
369 
370  req.data_len = len;
371  req.data = (u8 *) &fw->data[fw->size - remaining];
372  req.addr = FW_ADDR + fw->size - remaining;
373 
374  ret = af9015_ctrl_msg(d, &req);
375  if (ret) {
376  dev_err(&d->udev->dev,
377  "%s: firmware download failed=%d\n",
378  KBUILD_MODNAME, ret);
379  goto error;
380  }
381  }
382 
383  /* firmware loaded, request boot */
384  req.cmd = BOOT;
385  req.data_len = 0;
386  ret = af9015_ctrl_msg(d, &req);
387  if (ret) {
388  dev_err(&d->udev->dev, "%s: firmware boot failed=%d\n",
389  KBUILD_MODNAME, ret);
390  goto error;
391  }
392 
393 error:
394  return ret;
395 }
396 
397 /* hash (and dump) eeprom */
398 static int af9015_eeprom_hash(struct dvb_usb_device *d)
399 {
400  struct af9015_state *state = d_to_priv(d);
401  int ret, i;
402  static const unsigned int AF9015_EEPROM_SIZE = 256;
403  u8 buf[AF9015_EEPROM_SIZE];
404  struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, NULL};
405 
406  /* read eeprom */
407  for (i = 0; i < AF9015_EEPROM_SIZE; i++) {
408  req.addr = i;
409  req.data = &buf[i];
410  ret = af9015_ctrl_msg(d, &req);
411  if (ret < 0)
412  goto err;
413  }
414 
415  /* calculate checksum */
416  for (i = 0; i < AF9015_EEPROM_SIZE / sizeof(u32); i++) {
418  state->eeprom_sum += le32_to_cpu(((u32 *)buf)[i]);
419  }
420 
421  for (i = 0; i < AF9015_EEPROM_SIZE; i += 16)
422  dev_dbg(&d->udev->dev, "%s: %*ph\n", __func__, 16, buf + i);
423 
424  dev_dbg(&d->udev->dev, "%s: eeprom sum=%.8x\n",
425  __func__, state->eeprom_sum);
426  return 0;
427 err:
428  dev_err(&d->udev->dev, "%s: eeprom failed=%d\n", KBUILD_MODNAME, ret);
429  return ret;
430 }
431 
432 static int af9015_read_config(struct dvb_usb_device *d)
433 {
434  struct af9015_state *state = d_to_priv(d);
435  int ret;
436  u8 val, i, offset = 0;
437  struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
438 
439  dev_dbg(&d->udev->dev, "%s:\n", __func__);
440 
441  /* IR remote controller */
443  /* first message will timeout often due to possible hw bug */
444  for (i = 0; i < 4; i++) {
445  ret = af9015_ctrl_msg(d, &req);
446  if (!ret)
447  break;
448  }
449  if (ret)
450  goto error;
451 
452  ret = af9015_eeprom_hash(d);
453  if (ret)
454  goto error;
455 
456  state->ir_mode = val;
457  dev_dbg(&d->udev->dev, "%s: IR mode=%d\n", __func__, val);
458 
459  /* TS mode - one or two receivers */
461  ret = af9015_ctrl_msg(d, &req);
462  if (ret)
463  goto error;
464 
465  state->dual_mode = val;
466  dev_dbg(&d->udev->dev, "%s: TS mode=%d\n", __func__, state->dual_mode);
467 
468  /* disable 2nd adapter because we don't have PID-filters */
469  if (d->udev->speed == USB_SPEED_FULL)
470  state->dual_mode = 0;
471 
472  if (state->dual_mode) {
473  /* read 2nd demodulator I2C address */
475  ret = af9015_ctrl_msg(d, &req);
476  if (ret)
477  goto error;
478 
479  state->af9013_config[1].i2c_addr = val;
480  }
481 
482  for (i = 0; i < state->dual_mode + 1; i++) {
483  if (i == 1)
484  offset = AF9015_EEPROM_OFFSET;
485  /* xtal */
487  ret = af9015_ctrl_msg(d, &req);
488  if (ret)
489  goto error;
490  switch (val) {
491  case 0:
492  state->af9013_config[i].clock = 28800000;
493  break;
494  case 1:
495  state->af9013_config[i].clock = 20480000;
496  break;
497  case 2:
498  state->af9013_config[i].clock = 28000000;
499  break;
500  case 3:
501  state->af9013_config[i].clock = 25000000;
502  break;
503  }
504  dev_dbg(&d->udev->dev, "%s: [%d] xtal=%d set clock=%d\n",
505  __func__, i, val,
506  state->af9013_config[i].clock);
507 
508  /* IF frequency */
510  ret = af9015_ctrl_msg(d, &req);
511  if (ret)
512  goto error;
513 
514  state->af9013_config[i].if_frequency = val << 8;
515 
517  ret = af9015_ctrl_msg(d, &req);
518  if (ret)
519  goto error;
520 
521  state->af9013_config[i].if_frequency += val;
522  state->af9013_config[i].if_frequency *= 1000;
523  dev_dbg(&d->udev->dev, "%s: [%d] IF frequency=%d\n", __func__,
524  i, state->af9013_config[i].if_frequency);
525 
526  /* MT2060 IF1 */
528  ret = af9015_ctrl_msg(d, &req);
529  if (ret)
530  goto error;
531  state->mt2060_if1[i] = val << 8;
533  ret = af9015_ctrl_msg(d, &req);
534  if (ret)
535  goto error;
536  state->mt2060_if1[i] += val;
537  dev_dbg(&d->udev->dev, "%s: [%d] MT2060 IF1=%d\n", __func__, i,
538  state->mt2060_if1[i]);
539 
540  /* tuner */
542  ret = af9015_ctrl_msg(d, &req);
543  if (ret)
544  goto error;
545  switch (val) {
547  case AF9013_TUNER_MT2060:
548  case AF9013_TUNER_QT1010:
554  state->af9013_config[i].spec_inv = 1;
555  break;
560  state->af9013_config[i].spec_inv = 0;
561  break;
563  state->af9013_config[i].gpio[1] = AF9013_GPIO_LO;
564  state->af9013_config[i].spec_inv = 1;
565  break;
566  default:
567  dev_err(&d->udev->dev, "%s: tuner id=%d not " \
568  "supported, please report!\n",
569  KBUILD_MODNAME, val);
570  return -ENODEV;
571  }
572 
573  state->af9013_config[i].tuner = val;
574  dev_dbg(&d->udev->dev, "%s: [%d] tuner id=%d\n",
575  __func__, i, val);
576  }
577 
578 error:
579  if (ret)
580  dev_err(&d->udev->dev, "%s: eeprom read failed=%d\n",
581  KBUILD_MODNAME, ret);
582 
583  /* AverMedia AVerTV Volar Black HD (A850) device have bad EEPROM
584  content :-( Override some wrong values here. Ditto for the
585  AVerTV Red HD+ (A850T) device. */
586  if (le16_to_cpu(d->udev->descriptor.idVendor) == USB_VID_AVERMEDIA &&
587  ((le16_to_cpu(d->udev->descriptor.idProduct) ==
589  (le16_to_cpu(d->udev->descriptor.idProduct) ==
591  dev_dbg(&d->udev->dev,
592  "%s: AverMedia A850: overriding config\n",
593  __func__);
594  /* disable dual mode */
595  state->dual_mode = 0;
596 
597  /* set correct IF */
598  state->af9013_config[0].if_frequency = 4570000;
599  }
600 
601  return ret;
602 }
603 
604 static int af9015_get_stream_config(struct dvb_frontend *fe, u8 *ts_type,
605  struct usb_data_stream_properties *stream)
606 {
607  struct dvb_usb_device *d = fe_to_d(fe);
608  dev_dbg(&d->udev->dev, "%s: adap=%d\n", __func__, fe_to_adap(fe)->id);
609 
610  if (d->udev->speed == USB_SPEED_FULL)
611  stream->u.bulk.buffersize = TS_USB11_FRAME_SIZE;
612 
613  return 0;
614 }
615 
616 static int af9015_get_adapter_count(struct dvb_usb_device *d)
617 {
618  struct af9015_state *state = d_to_priv(d);
619  return state->dual_mode + 1;
620 }
621 
622 /* override demod callbacks for resource locking */
623 static int af9015_af9013_set_frontend(struct dvb_frontend *fe)
624 {
625  int ret;
626  struct af9015_state *state = fe_to_priv(fe);
627 
628  if (mutex_lock_interruptible(&state->fe_mutex))
629  return -EAGAIN;
630 
631  ret = state->set_frontend[fe_to_adap(fe)->id](fe);
632 
633  mutex_unlock(&state->fe_mutex);
634 
635  return ret;
636 }
637 
638 /* override demod callbacks for resource locking */
639 static int af9015_af9013_read_status(struct dvb_frontend *fe,
641 {
642  int ret;
643  struct af9015_state *state = fe_to_priv(fe);
644 
645  if (mutex_lock_interruptible(&state->fe_mutex))
646  return -EAGAIN;
647 
648  ret = state->read_status[fe_to_adap(fe)->id](fe, status);
649 
650  mutex_unlock(&state->fe_mutex);
651 
652  return ret;
653 }
654 
655 /* override demod callbacks for resource locking */
656 static int af9015_af9013_init(struct dvb_frontend *fe)
657 {
658  int ret;
659  struct af9015_state *state = fe_to_priv(fe);
660 
661  if (mutex_lock_interruptible(&state->fe_mutex))
662  return -EAGAIN;
663 
664  ret = state->init[fe_to_adap(fe)->id](fe);
665 
666  mutex_unlock(&state->fe_mutex);
667 
668  return ret;
669 }
670 
671 /* override demod callbacks for resource locking */
672 static int af9015_af9013_sleep(struct dvb_frontend *fe)
673 {
674  int ret;
675  struct af9015_state *state = fe_to_priv(fe);
676 
677  if (mutex_lock_interruptible(&state->fe_mutex))
678  return -EAGAIN;
679 
680  ret = state->sleep[fe_to_adap(fe)->id](fe);
681 
682  mutex_unlock(&state->fe_mutex);
683 
684  return ret;
685 }
686 
687 /* override tuner callbacks for resource locking */
688 static int af9015_tuner_init(struct dvb_frontend *fe)
689 {
690  int ret;
691  struct af9015_state *state = fe_to_priv(fe);
692 
693  if (mutex_lock_interruptible(&state->fe_mutex))
694  return -EAGAIN;
695 
696  ret = state->tuner_init[fe_to_adap(fe)->id](fe);
697 
698  mutex_unlock(&state->fe_mutex);
699 
700  return ret;
701 }
702 
703 /* override tuner callbacks for resource locking */
704 static int af9015_tuner_sleep(struct dvb_frontend *fe)
705 {
706  int ret;
707  struct af9015_state *state = fe_to_priv(fe);
708 
709  if (mutex_lock_interruptible(&state->fe_mutex))
710  return -EAGAIN;
711 
712  ret = state->tuner_sleep[fe_to_adap(fe)->id](fe);
713 
714  mutex_unlock(&state->fe_mutex);
715 
716  return ret;
717 }
718 
719 static int af9015_copy_firmware(struct dvb_usb_device *d)
720 {
721  struct af9015_state *state = d_to_priv(d);
722  int ret;
723  u8 fw_params[4];
724  u8 val, i;
725  struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
726  fw_params };
727  dev_dbg(&d->udev->dev, "%s:\n", __func__);
728 
729  fw_params[0] = state->firmware_size >> 8;
730  fw_params[1] = state->firmware_size & 0xff;
731  fw_params[2] = state->firmware_checksum >> 8;
732  fw_params[3] = state->firmware_checksum & 0xff;
733 
734  /* wait 2nd demodulator ready */
735  msleep(100);
736 
737  ret = af9015_read_reg_i2c(d, state->af9013_config[1].i2c_addr,
738  0x98be, &val);
739  if (ret)
740  goto error;
741  else
742  dev_dbg(&d->udev->dev, "%s: firmware status=%02x\n",
743  __func__, val);
744 
745  if (val == 0x0c) /* fw is running, no need for download */
746  goto exit;
747 
748  /* set I2C master clock to fast (to speed up firmware copy) */
749  ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
750  if (ret)
751  goto error;
752 
753  msleep(50);
754 
755  /* copy firmware */
756  ret = af9015_ctrl_msg(d, &req);
757  if (ret)
758  dev_err(&d->udev->dev, "%s: firmware copy cmd failed=%d\n",
759  KBUILD_MODNAME, ret);
760 
761  dev_dbg(&d->udev->dev, "%s: firmware copy done\n", __func__);
762 
763  /* set I2C master clock back to normal */
764  ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
765  if (ret)
766  goto error;
767 
768  /* request boot firmware */
769  ret = af9015_write_reg_i2c(d, state->af9013_config[1].i2c_addr,
770  0xe205, 1);
771  dev_dbg(&d->udev->dev, "%s: firmware boot cmd status=%d\n",
772  __func__, ret);
773  if (ret)
774  goto error;
775 
776  for (i = 0; i < 15; i++) {
777  msleep(100);
778 
779  /* check firmware status */
780  ret = af9015_read_reg_i2c(d, state->af9013_config[1].i2c_addr,
781  0x98be, &val);
782  dev_dbg(&d->udev->dev, "%s: firmware status cmd status=%d " \
783  "firmware status=%02x\n", __func__, ret, val);
784  if (ret)
785  goto error;
786 
787  if (val == 0x0c || val == 0x04) /* success or fail */
788  break;
789  }
790 
791  if (val == 0x04) {
792  dev_err(&d->udev->dev, "%s: firmware did not run\n",
793  KBUILD_MODNAME);
794  ret = -ETIMEDOUT;
795  } else if (val != 0x0c) {
796  dev_err(&d->udev->dev, "%s: firmware boot timeout\n",
797  KBUILD_MODNAME);
798  ret = -ETIMEDOUT;
799  }
800 
801 error:
802 exit:
803  return ret;
804 }
805 
806 static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
807 {
808  int ret;
809  struct af9015_state *state = adap_to_priv(adap);
810 
811  if (adap->id == 0) {
812  state->af9013_config[0].ts_mode = AF9013_TS_USB;
813  memcpy(state->af9013_config[0].api_version, "\x0\x1\x9\x0", 4);
814  state->af9013_config[0].gpio[0] = AF9013_GPIO_HI;
815  state->af9013_config[0].gpio[3] = AF9013_GPIO_TUNER_ON;
816  } else if (adap->id == 1) {
817  state->af9013_config[1].ts_mode = AF9013_TS_SERIAL;
818  memcpy(state->af9013_config[1].api_version, "\x0\x1\x9\x0", 4);
819  state->af9013_config[1].gpio[0] = AF9013_GPIO_TUNER_ON;
820  state->af9013_config[1].gpio[1] = AF9013_GPIO_LO;
821 
822  /* copy firmware to 2nd demodulator */
823  if (state->dual_mode) {
824  ret = af9015_copy_firmware(adap_to_d(adap));
825  if (ret) {
826  dev_err(&adap_to_d(adap)->udev->dev,
827  "%s: firmware copy to 2nd " \
828  "frontend failed, will " \
829  "disable it\n", KBUILD_MODNAME);
830  state->dual_mode = 0;
831  return -ENODEV;
832  }
833  } else {
834  return -ENODEV;
835  }
836  }
837 
838  /* attach demodulator */
839  adap->fe[0] = dvb_attach(af9013_attach,
840  &state->af9013_config[adap->id], &adap_to_d(adap)->i2c_adap);
841 
842  /*
843  * AF9015 firmware does not like if it gets interrupted by I2C adapter
844  * request on some critical phases. During normal operation I2C adapter
845  * is used only 2nd demodulator and tuner on dual tuner devices.
846  * Override demodulator callbacks and use mutex for limit access to
847  * those "critical" paths to keep AF9015 happy.
848  */
849  if (adap->fe[0]) {
850  state->set_frontend[adap->id] =
851  adap->fe[0]->ops.set_frontend;
852  adap->fe[0]->ops.set_frontend =
853  af9015_af9013_set_frontend;
854 
855  state->read_status[adap->id] =
856  adap->fe[0]->ops.read_status;
857  adap->fe[0]->ops.read_status =
858  af9015_af9013_read_status;
859 
860  state->init[adap->id] = adap->fe[0]->ops.init;
861  adap->fe[0]->ops.init = af9015_af9013_init;
862 
863  state->sleep[adap->id] = adap->fe[0]->ops.sleep;
864  adap->fe[0]->ops.sleep = af9015_af9013_sleep;
865  }
866 
867  return adap->fe[0] == NULL ? -ENODEV : 0;
868 }
869 
870 static struct mt2060_config af9015_mt2060_config = {
871  .i2c_address = 0xc0,
872  .clock_out = 0,
873 };
874 
875 static struct qt1010_config af9015_qt1010_config = {
876  .i2c_address = 0xc4,
877 };
878 
879 static struct tda18271_config af9015_tda18271_config = {
880  .gate = TDA18271_GATE_DIGITAL,
881  .small_i2c = TDA18271_16_BYTE_CHUNK_INIT,
882 };
883 
884 static struct mxl5005s_config af9015_mxl5003_config = {
885  .i2c_address = 0xc6,
886  .if_freq = IF_FREQ_4570000HZ,
887  .xtal_freq = CRYSTAL_FREQ_16000000HZ,
888  .agc_mode = MXL_SINGLE_AGC,
889  .tracking_filter = MXL_TF_DEFAULT,
890  .rssi_enable = MXL_RSSI_ENABLE,
891  .cap_select = MXL_CAP_SEL_ENABLE,
892  .div_out = MXL_DIV_OUT_4,
893  .clock_out = MXL_CLOCK_OUT_DISABLE,
894  .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
895  .top = MXL5005S_TOP_25P2,
896  .mod_mode = MXL_DIGITAL_MODE,
897  .if_mode = MXL_ZERO_IF,
898  .AgcMasterByte = 0x00,
899 };
900 
901 static struct mxl5005s_config af9015_mxl5005_config = {
902  .i2c_address = 0xc6,
903  .if_freq = IF_FREQ_4570000HZ,
904  .xtal_freq = CRYSTAL_FREQ_16000000HZ,
905  .agc_mode = MXL_SINGLE_AGC,
906  .tracking_filter = MXL_TF_OFF,
907  .rssi_enable = MXL_RSSI_ENABLE,
908  .cap_select = MXL_CAP_SEL_ENABLE,
909  .div_out = MXL_DIV_OUT_4,
910  .clock_out = MXL_CLOCK_OUT_DISABLE,
911  .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
912  .top = MXL5005S_TOP_25P2,
913  .mod_mode = MXL_DIGITAL_MODE,
914  .if_mode = MXL_ZERO_IF,
915  .AgcMasterByte = 0x00,
916 };
917 
918 static struct mc44s803_config af9015_mc44s803_config = {
919  .i2c_address = 0xc0,
920  .dig_out = 1,
921 };
922 
923 static struct tda18218_config af9015_tda18218_config = {
924  .i2c_address = 0xc0,
925  .i2c_wr_max = 21, /* max wr bytes AF9015 I2C adap can handle at once */
926 };
927 
928 static struct mxl5007t_config af9015_mxl5007t_config = {
929  .xtal_freq_hz = MxL_XTAL_24_MHZ,
930  .if_freq_hz = MxL_IF_4_57_MHZ,
931 };
932 
933 static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
934 {
935  struct dvb_usb_device *d = adap_to_d(adap);
936  struct af9015_state *state = d_to_priv(d);
937  int ret;
938  dev_dbg(&d->udev->dev, "%s:\n", __func__);
939 
940  switch (state->af9013_config[adap->id].tuner) {
941  case AF9013_TUNER_MT2060:
943  ret = dvb_attach(mt2060_attach, adap->fe[0],
944  &adap_to_d(adap)->i2c_adap, &af9015_mt2060_config,
945  state->mt2060_if1[adap->id])
946  == NULL ? -ENODEV : 0;
947  break;
948  case AF9013_TUNER_QT1010:
950  ret = dvb_attach(qt1010_attach, adap->fe[0],
951  &adap_to_d(adap)->i2c_adap,
952  &af9015_qt1010_config) == NULL ? -ENODEV : 0;
953  break;
955  ret = dvb_attach(tda18271_attach, adap->fe[0], 0xc0,
956  &adap_to_d(adap)->i2c_adap,
957  &af9015_tda18271_config) == NULL ? -ENODEV : 0;
958  break;
960  ret = dvb_attach(tda18218_attach, adap->fe[0],
961  &adap_to_d(adap)->i2c_adap,
962  &af9015_tda18218_config) == NULL ? -ENODEV : 0;
963  break;
965  ret = dvb_attach(mxl5005s_attach, adap->fe[0],
966  &adap_to_d(adap)->i2c_adap,
967  &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
968  break;
971  ret = dvb_attach(mxl5005s_attach, adap->fe[0],
972  &adap_to_d(adap)->i2c_adap,
973  &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
974  break;
976  ret = dvb_attach(dvb_pll_attach, adap->fe[0], 0xc0,
977  &adap_to_d(adap)->i2c_adap,
978  DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
979  break;
981  ret = dvb_attach(mc44s803_attach, adap->fe[0],
982  &adap_to_d(adap)->i2c_adap,
983  &af9015_mc44s803_config) == NULL ? -ENODEV : 0;
984  break;
986  ret = dvb_attach(mxl5007t_attach, adap->fe[0],
987  &adap_to_d(adap)->i2c_adap,
988  0xc0, &af9015_mxl5007t_config) == NULL ? -ENODEV : 0;
989  break;
991  default:
992  dev_err(&d->udev->dev, "%s: unknown tuner id=%d\n",
993  KBUILD_MODNAME,
994  state->af9013_config[adap->id].tuner);
995  ret = -ENODEV;
996  }
997 
998  if (adap->fe[0]->ops.tuner_ops.init) {
999  state->tuner_init[adap->id] =
1000  adap->fe[0]->ops.tuner_ops.init;
1001  adap->fe[0]->ops.tuner_ops.init = af9015_tuner_init;
1002  }
1003 
1004  if (adap->fe[0]->ops.tuner_ops.sleep) {
1005  state->tuner_sleep[adap->id] =
1006  adap->fe[0]->ops.tuner_ops.sleep;
1007  adap->fe[0]->ops.tuner_ops.sleep = af9015_tuner_sleep;
1008  }
1009 
1010  return ret;
1011 }
1012 
1013 static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
1014 {
1015  struct dvb_usb_device *d = adap_to_d(adap);
1016  int ret;
1017  dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
1018 
1019  if (onoff)
1020  ret = af9015_set_reg_bit(d, 0xd503, 0);
1021  else
1022  ret = af9015_clear_reg_bit(d, 0xd503, 0);
1023 
1024  return ret;
1025 }
1026 
1027 static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
1028  int onoff)
1029 {
1030  struct dvb_usb_device *d = adap_to_d(adap);
1031  int ret;
1032  u8 idx;
1033  dev_dbg(&d->udev->dev, "%s: index=%d pid=%04x onoff=%d\n",
1034  __func__, index, pid, onoff);
1035 
1036  ret = af9015_write_reg(d, 0xd505, (pid & 0xff));
1037  if (ret)
1038  goto error;
1039 
1040  ret = af9015_write_reg(d, 0xd506, (pid >> 8));
1041  if (ret)
1042  goto error;
1043 
1044  idx = ((index & 0x1f) | (1 << 5));
1045  ret = af9015_write_reg(d, 0xd504, idx);
1046 
1047 error:
1048  return ret;
1049 }
1050 
1051 static int af9015_init_endpoint(struct dvb_usb_device *d)
1052 {
1053  struct af9015_state *state = d_to_priv(d);
1054  int ret;
1055  u16 frame_size;
1056  u8 packet_size;
1057  dev_dbg(&d->udev->dev, "%s: USB speed=%d\n", __func__, d->udev->speed);
1058 
1059  if (d->udev->speed == USB_SPEED_FULL) {
1060  frame_size = TS_USB11_FRAME_SIZE/4;
1061  packet_size = TS_USB11_MAX_PACKET_SIZE/4;
1062  } else {
1063  frame_size = TS_USB20_FRAME_SIZE/4;
1064  packet_size = TS_USB20_MAX_PACKET_SIZE/4;
1065  }
1066 
1067  ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */
1068  if (ret)
1069  goto error;
1070  ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */
1071  if (ret)
1072  goto error;
1073  ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */
1074  if (ret)
1075  goto error;
1076  ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */
1077  if (ret)
1078  goto error;
1079  ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */
1080  if (ret)
1081  goto error;
1082  if (state->dual_mode) {
1083  ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */
1084  if (ret)
1085  goto error;
1086  }
1087  ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */
1088  if (ret)
1089  goto error;
1090  if (state->dual_mode) {
1091  ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */
1092  if (ret)
1093  goto error;
1094  }
1095  /* EP4 xfer length */
1096  ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);
1097  if (ret)
1098  goto error;
1099  ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);
1100  if (ret)
1101  goto error;
1102  /* EP5 xfer length */
1103  ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);
1104  if (ret)
1105  goto error;
1106  ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);
1107  if (ret)
1108  goto error;
1109  ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */
1110  if (ret)
1111  goto error;
1112  ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */
1113  if (ret)
1114  goto error;
1115  ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */
1116  if (ret)
1117  goto error;
1118  if (state->dual_mode) {
1119  ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */
1120  if (ret)
1121  goto error;
1122  }
1123 
1124  /* enable / disable mp2if2 */
1125  if (state->dual_mode)
1126  ret = af9015_set_reg_bit(d, 0xd50b, 0);
1127  else
1128  ret = af9015_clear_reg_bit(d, 0xd50b, 0);
1129 
1130 error:
1131  if (ret)
1132  dev_err(&d->udev->dev, "%s: endpoint init failed=%d\n",
1133  KBUILD_MODNAME, ret);
1134 
1135  return ret;
1136 }
1137 
1138 static int af9015_init(struct dvb_usb_device *d)
1139 {
1140  struct af9015_state *state = d_to_priv(d);
1141  int ret;
1142  dev_dbg(&d->udev->dev, "%s:\n", __func__);
1143 
1144  mutex_init(&state->fe_mutex);
1145 
1146  /* init RC canary */
1147  ret = af9015_write_reg(d, 0x98e9, 0xff);
1148  if (ret)
1149  goto error;
1150 
1151  ret = af9015_init_endpoint(d);
1152  if (ret)
1153  goto error;
1154 
1155 error:
1156  return ret;
1157 }
1158 
1160  unsigned int id;
1161  char *rc_codes;
1162 };
1163 
1164 static char *af9015_rc_setup_match(unsigned int id,
1165  const struct af9015_rc_setup *table)
1166 {
1167  for (; table->rc_codes; table++)
1168  if (table->id == id)
1169  return table->rc_codes;
1170  return NULL;
1171 }
1172 
1173 static const struct af9015_rc_setup af9015_rc_setup_modparam[] = {
1179  { }
1180 };
1181 
1182 static const struct af9015_rc_setup af9015_rc_setup_hashes[] = {
1183  { 0xb8feb708, RC_MAP_MSI_DIGIVOX_II },
1184  { 0xa3703d00, RC_MAP_ALINK_DTU_M },
1185  { 0x9b7dc64e, RC_MAP_TOTAL_MEDIA_IN_HAND }, /* MYGICTV U718 */
1186  { 0x5d49e3db, RC_MAP_DIGITTRADE }, /* LC-Power LC-USB-DVBT */
1187  { }
1188 };
1189 
1190 static int af9015_rc_query(struct dvb_usb_device *d)
1191 {
1192  struct af9015_state *state = d_to_priv(d);
1193  int ret;
1194  u8 buf[17];
1195 
1196  /* read registers needed to detect remote controller code */
1197  ret = af9015_read_regs(d, 0x98d9, buf, sizeof(buf));
1198  if (ret)
1199  goto error;
1200 
1201  /* If any of these are non-zero, assume invalid data */
1202  if (buf[1] || buf[2] || buf[3]) {
1203  dev_dbg(&d->udev->dev, "%s: invalid data\n", __func__);
1204  return ret;
1205  }
1206 
1207  /* Check for repeat of previous code */
1208  if ((state->rc_repeat != buf[6] || buf[0]) &&
1209  !memcmp(&buf[12], state->rc_last, 4)) {
1210  dev_dbg(&d->udev->dev, "%s: key repeated\n", __func__);
1211  rc_keydown(d->rc_dev, state->rc_keycode, 0);
1212  state->rc_repeat = buf[6];
1213  return ret;
1214  }
1215 
1216  /* Only process key if canary killed */
1217  if (buf[16] != 0xff && buf[0] != 0x01) {
1218  dev_dbg(&d->udev->dev, "%s: key pressed %*ph\n",
1219  __func__, 4, buf + 12);
1220 
1221  /* Reset the canary */
1222  ret = af9015_write_reg(d, 0x98e9, 0xff);
1223  if (ret)
1224  goto error;
1225 
1226  /* Remember this key */
1227  memcpy(state->rc_last, &buf[12], 4);
1228  if (buf[14] == (u8) ~buf[15]) {
1229  if (buf[12] == (u8) ~buf[13]) {
1230  /* NEC */
1231  state->rc_keycode = buf[12] << 8 | buf[14];
1232  } else {
1233  /* NEC extended*/
1234  state->rc_keycode = buf[12] << 16 |
1235  buf[13] << 8 | buf[14];
1236  }
1237  } else {
1238  /* 32 bit NEC */
1239  state->rc_keycode = buf[12] << 24 | buf[13] << 16 |
1240  buf[14] << 8 | buf[15];
1241  }
1242  rc_keydown(d->rc_dev, state->rc_keycode, 0);
1243  } else {
1244  dev_dbg(&d->udev->dev, "%s: no key press\n", __func__);
1245  /* Invalidate last keypress */
1246  /* Not really needed, but helps with debug */
1247  state->rc_last[2] = state->rc_last[3];
1248  }
1249 
1250  state->rc_repeat = buf[6];
1251  state->rc_failed = false;
1252 
1253 error:
1254  if (ret) {
1255  dev_warn(&d->udev->dev, "%s: rc query failed=%d\n",
1256  KBUILD_MODNAME, ret);
1257 
1258  /* allow random errors as dvb-usb will stop polling on error */
1259  if (!state->rc_failed)
1260  ret = 0;
1261 
1262  state->rc_failed = true;
1263  }
1264 
1265  return ret;
1266 }
1267 
1268 static int af9015_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1269 {
1270  struct af9015_state *state = d_to_priv(d);
1271  u16 vid = le16_to_cpu(d->udev->descriptor.idVendor);
1272 
1273  if (state->ir_mode == AF9015_IR_MODE_DISABLED)
1274  return 0;
1275 
1276  /* try to load remote based module param */
1277  if (!rc->map_name)
1278  rc->map_name = af9015_rc_setup_match(dvb_usb_af9015_remote,
1279  af9015_rc_setup_modparam);
1280 
1281  /* try to load remote based eeprom hash */
1282  if (!rc->map_name)
1283  rc->map_name = af9015_rc_setup_match(state->eeprom_sum,
1284  af9015_rc_setup_hashes);
1285 
1286  /* try to load remote based USB iManufacturer string */
1287  if (!rc->map_name && vid == USB_VID_AFATECH) {
1288  /* Check USB manufacturer and product strings and try
1289  to determine correct remote in case of chip vendor
1290  reference IDs are used.
1291  DO NOT ADD ANYTHING NEW HERE. Use hashes instead. */
1292  char manufacturer[10];
1293  memset(manufacturer, 0, sizeof(manufacturer));
1294  usb_string(d->udev, d->udev->descriptor.iManufacturer,
1295  manufacturer, sizeof(manufacturer));
1296  if (!strcmp("MSI", manufacturer)) {
1297  /* iManufacturer 1 MSI
1298  iProduct 2 MSI K-VOX */
1299  rc->map_name = af9015_rc_setup_match(
1301  af9015_rc_setup_modparam);
1302  }
1303  }
1304 
1305  /* load empty to enable rc */
1306  if (!rc->map_name)
1307  rc->map_name = RC_MAP_EMPTY;
1308 
1310  rc->query = af9015_rc_query;
1311  rc->interval = 500;
1312 
1313  return 0;
1314 }
1315 
1316 /* interface 0 is used by DVB-T receiver and
1317  interface 1 is for remote controller (HID) */
1318 static struct dvb_usb_device_properties af9015_props = {
1319  .driver_name = KBUILD_MODNAME,
1320  .owner = THIS_MODULE,
1321  .adapter_nr = adapter_nr,
1322  .size_of_priv = sizeof(struct af9015_state),
1323 
1324  .generic_bulk_ctrl_endpoint = 0x02,
1325  .generic_bulk_ctrl_endpoint_response = 0x81,
1326 
1327  .identify_state = af9015_identify_state,
1328  .firmware = AF9015_FIRMWARE,
1329  .download_firmware = af9015_download_firmware,
1330 
1331  .i2c_algo = &af9015_i2c_algo,
1332  .read_config = af9015_read_config,
1333  .frontend_attach = af9015_af9013_frontend_attach,
1334  .tuner_attach = af9015_tuner_attach,
1335  .init = af9015_init,
1336  .get_rc_config = af9015_get_rc_config,
1337  .get_stream_config = af9015_get_stream_config,
1338 
1339  .get_adapter_count = af9015_get_adapter_count,
1340  .adapter = {
1341  {
1342  .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1344  .pid_filter_count = 32,
1345  .pid_filter = af9015_pid_filter,
1346  .pid_filter_ctrl = af9015_pid_filter_ctrl,
1347 
1348  .stream = DVB_USB_STREAM_BULK(0x84, 8, TS_USB20_FRAME_SIZE),
1349  }, {
1350  .stream = DVB_USB_STREAM_BULK(0x85, 8, TS_USB20_FRAME_SIZE),
1351  },
1352  },
1353 };
1354 
1355 static const struct usb_device_id af9015_id_table[] = {
1357  &af9015_props, "Afatech AF9015 reference design", NULL) },
1359  &af9015_props, "Afatech AF9015 reference design", NULL) },
1361  &af9015_props, "Leadtek WinFast DTV Dongle Gold", RC_MAP_LEADTEK_Y04G0051) },
1363  &af9015_props, "Pinnacle PCTV 71e", NULL) },
1365  &af9015_props, "KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)", NULL) },
1367  &af9015_props, "DigitalNow TinyTwin", RC_MAP_AZUREWAVE_AD_TU700) },
1369  &af9015_props, "TwinHan AzureWave AD-TU700(704J)", RC_MAP_AZUREWAVE_AD_TU700) },
1371  &af9015_props, "TerraTec Cinergy T USB XE", NULL) },
1373  &af9015_props, "KWorld PlusTV Dual DVB-T PCI (DVB-T PC160-2T)", NULL) },
1375  &af9015_props, "AVerMedia AVerTV DVB-T Volar X", RC_MAP_AVERMEDIA_M135A) },
1377  &af9015_props, "Xtensions XD-380", NULL) },
1379  &af9015_props, "MSI DIGIVOX Duo", RC_MAP_MSI_DIGIVOX_III) },
1381  &af9015_props, "Fujitsu-Siemens Slim Mobile USB DVB-T", NULL) },
1383  &af9015_props, "Telestar Starstick 2", NULL) },
1385  &af9015_props, "AVerMedia A309", NULL) },
1387  &af9015_props, "MSI Digi VOX mini III", RC_MAP_MSI_DIGIVOX_III) },
1389  &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
1391  &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
1393  &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
1395  &af9015_props, "TrekStor DVB-T USB Stick", RC_MAP_TREKSTOR) },
1397  &af9015_props, "AverMedia AVerTV Volar Black HD (A850)", NULL) },
1399  &af9015_props, "AverMedia AVerTV Volar GPS 805 (A805)", NULL) },
1401  &af9015_props, "Conceptronic USB2.0 DVB-T CTVDIGRCU V3.0", NULL) },
1403  &af9015_props, "KWorld Digial MC-810", NULL) },
1405  &af9015_props, "Genius TVGo DVB-T03", NULL) },
1407  &af9015_props, "KWorld PlusTV Dual DVB-T Stick (DVB-T 399U)", NULL) },
1409  &af9015_props, "KWorld PlusTV DVB-T PCI Pro Card (DVB-T PC160-T)", NULL) },
1411  &af9015_props, "Sveon STV20 Tuner USB DVB-T HDTV", NULL) },
1413  &af9015_props, "DigitalNow TinyTwin v2", RC_MAP_DIGITALNOW_TINYTWIN) },
1415  &af9015_props, "Leadtek WinFast DTV2000DS", RC_MAP_LEADTEK_Y04G0051) },
1417  &af9015_props, "KWorld USB DVB-T Stick Mobile (UB383-T)", NULL) },
1419  &af9015_props, "KWorld USB DVB-T TV Stick II (VS-DVB-T 395U)", NULL) },
1421  &af9015_props, "AverMedia AVerTV Volar M (A815Mac)", NULL) },
1423  &af9015_props, "TerraTec Cinergy T Stick RC", RC_MAP_TERRATEC_SLIM_2) },
1425  &af9015_props, "TerraTec Cinergy T Stick Dual RC", RC_MAP_TERRATEC_SLIM) },
1427  &af9015_props, "AverMedia AVerTV Red HD+ (A850T)", NULL) },
1429  &af9015_props, "DigitalNow TinyTwin v3", RC_MAP_DIGITALNOW_TINYTWIN) },
1431  &af9015_props, "Sveon STV22 Dual USB DVB-T Tuner HDTV", RC_MAP_MSI_DIGIVOX_III) },
1432  { }
1433 };
1434 MODULE_DEVICE_TABLE(usb, af9015_id_table);
1435 
1436 /* usb specific object needed to register this driver with the usb subsystem */
1437 static struct usb_driver af9015_usb_driver = {
1438  .name = KBUILD_MODNAME,
1439  .id_table = af9015_id_table,
1440  .probe = dvb_usbv2_probe,
1441  .disconnect = dvb_usbv2_disconnect,
1442  .suspend = dvb_usbv2_suspend,
1443  .resume = dvb_usbv2_resume,
1444  .reset_resume = dvb_usbv2_reset_resume,
1445  .no_dynamic_id = 1,
1446  .soft_unbind = 1,
1447 };
1448 
1449 module_usb_driver(af9015_usb_driver);
1450 
1451 MODULE_AUTHOR("Antti Palosaari <[email protected]>");
1452 MODULE_DESCRIPTION("Afatech AF9015 driver");
1453 MODULE_LICENSE("GPL");