Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
m920x.c
Go to the documentation of this file.
1 /* DVB USB compliant linux driver for MSI Mega Sky 580 DVB-T USB2.0 receiver
2  *
3  * Copyright (C) 2006 Aapo Tahkola ([email protected])
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation, version 2.
8  *
9  * see Documentation/dvb/README.dvb-usb for more information
10  */
11 
12 #include "m920x.h"
13 
14 #include "mt352.h"
15 #include "mt352_priv.h"
16 #include "qt1010.h"
17 #include "tda1004x.h"
18 #include "tda827x.h"
19 
20 #include <media/tuner.h>
21 #include "tuner-simple.h"
22 #include <asm/unaligned.h>
23 
24 /* debug */
25 static int dvb_usb_m920x_debug;
26 module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
27 MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
28 
30 
31 static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid);
32 
33 static inline int m920x_read(struct usb_device *udev, u8 request, u16 value,
34  u16 index, void *data, int size)
35 {
36  int ret;
37 
38  ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
39  request, USB_TYPE_VENDOR | USB_DIR_IN,
40  value, index, data, size, 2000);
41  if (ret < 0) {
42  printk(KERN_INFO "m920x_read = error: %d\n", ret);
43  return ret;
44  }
45 
46  if (ret != size) {
47  deb("m920x_read = no data\n");
48  return -EIO;
49  }
50 
51  return 0;
52 }
53 
54 static inline int m920x_write(struct usb_device *udev, u8 request,
55  u16 value, u16 index)
56 {
57  int ret;
58 
59  ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
60  request, USB_TYPE_VENDOR | USB_DIR_OUT,
61  value, index, NULL, 0, 2000);
62 
63  return ret;
64 }
65 
66 static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
67 {
68  int ret = 0, i, epi, flags = 0;
69  int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
70 
71  /* Remote controller init. */
72  if (d->props.rc.legacy.rc_query) {
73  deb("Initialising remote control\n");
74  while (rc_seq->address) {
75  if ((ret = m920x_write(d->udev, M9206_CORE,
76  rc_seq->data,
77  rc_seq->address)) != 0) {
78  deb("Initialising remote control failed\n");
79  return ret;
80  }
81 
82  rc_seq++;
83  }
84 
85  deb("Initialising remote control success\n");
86  }
87 
88  for (i = 0; i < d->props.num_adapters; i++)
89  flags |= d->adapter[i].props.fe[0].caps;
90 
91  /* Some devices(Dposh) might crash if we attempt touch at all. */
93  for (i = 0; i < d->props.num_adapters; i++) {
94  epi = d->adapter[i].props.fe[0].stream.endpoint - 0x81;
95 
96  if (epi < 0 || epi >= M9206_MAX_ADAPTERS) {
97  printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n");
98  return -EINVAL;
99  }
100 
101  adap_enabled[epi] = 1;
102  }
103 
104  for (i = 0; i < M9206_MAX_ADAPTERS; i++) {
105  if (adap_enabled[i])
106  continue;
107 
108  if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x0)) != 0)
109  return ret;
110 
111  if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x02f5)) != 0)
112  return ret;
113  }
114  }
115 
116  return ret;
117 }
118 
119 static int m920x_init_ep(struct usb_interface *intf)
120 {
121  struct usb_device *udev = interface_to_usbdev(intf);
122  struct usb_host_interface *alt;
123 
124  if ((alt = usb_altnum_to_altsetting(intf, 1)) == NULL) {
125  deb("No alt found!\n");
126  return -ENODEV;
127  }
128 
129  return usb_set_interface(udev, alt->desc.bInterfaceNumber,
130  alt->desc.bAlternateSetting);
131 }
132 
133 static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
134 {
135  struct m920x_state *m = d->priv;
136  int i, ret = 0;
137  u8 *rc_state;
138 
139  rc_state = kmalloc(2, GFP_KERNEL);
140  if (!rc_state)
141  return -ENOMEM;
142 
143  if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
144  goto out;
145 
146  if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
147  goto out;
148 
149  for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
150  if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
151  *event = d->props.rc.legacy.rc_map_table[i].keycode;
152 
153  switch(rc_state[0]) {
154  case 0x80:
155  *state = REMOTE_NO_KEY_PRESSED;
156  goto out;
157 
158  case 0x88: /* framing error or "invalid code" */
159  case 0x99:
160  case 0xc0:
161  case 0xd8:
162  *state = REMOTE_NO_KEY_PRESSED;
163  m->rep_count = 0;
164  goto out;
165 
166  case 0x93:
167  case 0x92:
168  case 0x83: /* pinnacle PCTV310e */
169  case 0x82:
170  m->rep_count = 0;
171  *state = REMOTE_KEY_PRESSED;
172  goto out;
173 
174  case 0x91:
175  case 0x81: /* pinnacle PCTV310e */
176  /* prevent immediate auto-repeat */
177  if (++m->rep_count > 2)
178  *state = REMOTE_KEY_REPEAT;
179  else
180  *state = REMOTE_NO_KEY_PRESSED;
181  goto out;
182 
183  default:
184  deb("Unexpected rc state %02x\n", rc_state[0]);
185  *state = REMOTE_NO_KEY_PRESSED;
186  goto out;
187  }
188  }
189 
190  if (rc_state[1] != 0)
191  deb("Unknown rc key %02x\n", rc_state[1]);
192 
193  *state = REMOTE_NO_KEY_PRESSED;
194 
195  out:
196  kfree(rc_state);
197  return ret;
198 }
199 
200 /* I2C */
201 static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
202 {
203  struct dvb_usb_device *d = i2c_get_adapdata(adap);
204  int i, j;
205  int ret = 0;
206 
207  if (!num)
208  return -EINVAL;
209 
210  if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
211  return -EAGAIN;
212 
213  for (i = 0; i < num; i++) {
214  if (msg[i].flags & (I2C_M_NO_RD_ACK | I2C_M_IGNORE_NAK | I2C_M_TEN) || msg[i].len == 0) {
215  /* For a 0 byte message, I think sending the address
216  * to index 0x80|0x40 would be the correct thing to
217  * do. However, zero byte messages are only used for
218  * probing, and since we don't know how to get the
219  * slave's ack, we can't probe. */
220  ret = -ENOTSUPP;
221  goto unlock;
222  }
223  /* Send START & address/RW bit */
224  if (!(msg[i].flags & I2C_M_NOSTART)) {
225  if ((ret = m920x_write(d->udev, M9206_I2C,
226  (msg[i].addr << 1) |
227  (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
228  goto unlock;
229  /* Should check for ack here, if we knew how. */
230  }
231  if (msg[i].flags & I2C_M_RD) {
232  for (j = 0; j < msg[i].len; j++) {
233  /* Last byte of transaction?
234  * Send STOP, otherwise send ACK. */
235  int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
236 
237  if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
238  0x20 | stop,
239  &msg[i].buf[j], 1)) != 0)
240  goto unlock;
241  }
242  } else {
243  for (j = 0; j < msg[i].len; j++) {
244  /* Last byte of transaction? Then send STOP. */
245  int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
246 
247  if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
248  goto unlock;
249  /* Should check for ack here too. */
250  }
251  }
252  }
253  ret = num;
254 
255  unlock:
256  mutex_unlock(&d->i2c_mutex);
257 
258  return ret;
259 }
260 
261 static u32 m920x_i2c_func(struct i2c_adapter *adapter)
262 {
263  return I2C_FUNC_I2C;
264 }
265 
266 static struct i2c_algorithm m920x_i2c_algo = {
267  .master_xfer = m920x_i2c_xfer,
268  .functionality = m920x_i2c_func,
269 };
270 
271 /* pid filter */
272 static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid)
273 {
274  int ret = 0;
275 
276  if (pid >= 0x8000)
277  return -EINVAL;
278 
279  pid |= 0x8000;
280 
281  if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
282  return ret;
283 
284  if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
285  return ret;
286 
287  return ret;
288 }
289 
290 static int m920x_update_filters(struct dvb_usb_adapter *adap)
291 {
292  struct m920x_state *m = adap->dev->priv;
293  int enabled = m->filtering_enabled[adap->id];
294  int i, ret = 0, filter = 0;
295  int ep = adap->props.fe[0].stream.endpoint;
296 
297  for (i = 0; i < M9206_MAX_FILTERS; i++)
298  if (m->filters[adap->id][i] == 8192)
299  enabled = 0;
300 
301  /* Disable all filters */
302  if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0)
303  return ret;
304 
305  for (i = 0; i < M9206_MAX_FILTERS; i++)
306  if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0)
307  return ret;
308 
309  /* Set */
310  if (enabled) {
311  for (i = 0; i < M9206_MAX_FILTERS; i++) {
312  if (m->filters[adap->id][i] == 0)
313  continue;
314 
315  if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0)
316  return ret;
317 
318  filter++;
319  }
320  }
321 
322  return ret;
323 }
324 
325 static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
326 {
327  struct m920x_state *m = adap->dev->priv;
328 
329  m->filtering_enabled[adap->id] = onoff ? 1 : 0;
330 
331  return m920x_update_filters(adap);
332 }
333 
334 static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
335 {
336  struct m920x_state *m = adap->dev->priv;
337 
338  m->filters[adap->id][index] = onoff ? pid : 0;
339 
340  return m920x_update_filters(adap);
341 }
342 
343 static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
344 {
345  u16 value, index, size;
346  u8 *read, *buff;
347  int i, pass, ret = 0;
348 
349  buff = kmalloc(65536, GFP_KERNEL);
350  if (buff == NULL)
351  return -ENOMEM;
352 
353  read = kmalloc(4, GFP_KERNEL);
354  if (!read) {
355  kfree(buff);
356  return -ENOMEM;
357  }
358 
359  if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
360  goto done;
361  deb("%*ph\n", 4, read);
362 
363  if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
364  goto done;
365  deb("%x\n", read[0]);
366 
367  for (pass = 0; pass < 2; pass++) {
368  for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
369  value = get_unaligned_le16(fw->data + i);
370  i += sizeof(u16);
371 
372  index = get_unaligned_le16(fw->data + i);
373  i += sizeof(u16);
374 
375  size = get_unaligned_le16(fw->data + i);
376  i += sizeof(u16);
377 
378  if (pass == 1) {
379  /* Will stall if using fw->data ... */
380  memcpy(buff, fw->data + i, size);
381 
382  ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
383  M9206_FW,
385  value, index, buff, size, 20);
386  if (ret != size) {
387  deb("error while uploading fw!\n");
388  ret = -EIO;
389  goto done;
390  }
391  msleep(3);
392  }
393  i += size;
394  }
395  if (i != fw->size) {
396  deb("bad firmware file!\n");
397  ret = -EINVAL;
398  goto done;
399  }
400  }
401 
402  msleep(36);
403 
404  /* m920x will disconnect itself from the bus after this. */
405  (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
406  deb("firmware uploaded!\n");
407 
408  done:
409  kfree(read);
410  kfree(buff);
411 
412  return ret;
413 }
414 
415 /* Callbacks for DVB USB */
416 static int m920x_identify_state(struct usb_device *udev,
417  struct dvb_usb_device_properties *props,
419  int *cold)
420 {
421  struct usb_host_interface *alt;
422 
423  alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
424  *cold = (alt == NULL) ? 1 : 0;
425 
426  return 0;
427 }
428 
429 /* demod configurations */
430 static int m920x_mt352_demod_init(struct dvb_frontend *fe)
431 {
432  int ret;
433  u8 config[] = { CONFIG, 0x3d };
434  u8 clock[] = { CLOCK_CTL, 0x30 };
435  u8 reset[] = { RESET, 0x80 };
436  u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
437  u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
438  u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
439  u8 unk1[] = { 0x93, 0x1a };
440  u8 unk2[] = { 0xb5, 0x7a };
441 
442  deb("Demod init!\n");
443 
444  if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
445  return ret;
446  if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
447  return ret;
448  if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
449  return ret;
450  if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
451  return ret;
452  if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
453  return ret;
454  if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
455  return ret;
456  if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
457  return ret;
458  if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
459  return ret;
460 
461  return 0;
462 }
463 
464 static struct mt352_config m920x_mt352_config = {
465  .demod_address = 0x0f,
466  .no_tuner = 1,
467  .demod_init = m920x_mt352_demod_init,
468 };
469 
470 static struct tda1004x_config m920x_tda10046_08_config = {
471  .demod_address = 0x08,
472  .invert = 0,
473  .invert_oclk = 0,
474  .ts_mode = TDA10046_TS_SERIAL,
475  .xtal_freq = TDA10046_XTAL_16M,
476  .if_freq = TDA10046_FREQ_045,
477  .agc_config = TDA10046_AGC_TDA827X,
478  .gpio_config = TDA10046_GPTRI,
479  .request_firmware = NULL,
480 };
481 
482 static struct tda1004x_config m920x_tda10046_0b_config = {
483  .demod_address = 0x0b,
484  .invert = 0,
485  .invert_oclk = 0,
486  .ts_mode = TDA10046_TS_SERIAL,
487  .xtal_freq = TDA10046_XTAL_16M,
488  .if_freq = TDA10046_FREQ_045,
489  .agc_config = TDA10046_AGC_TDA827X,
490  .gpio_config = TDA10046_GPTRI,
491  .request_firmware = NULL, /* uses firmware EEPROM */
492 };
493 
494 /* tuner configurations */
495 static struct qt1010_config m920x_qt1010_config = {
496  .i2c_address = 0x62
497 };
498 
499 /* Callbacks for DVB USB */
500 static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
501 {
502  deb("%s\n",__func__);
503 
504  adap->fe_adap[0].fe = dvb_attach(mt352_attach,
505  &m920x_mt352_config,
506  &adap->dev->i2c_adap);
507  if ((adap->fe_adap[0].fe) == NULL)
508  return -EIO;
509 
510  return 0;
511 }
512 
513 static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
514 {
515  deb("%s\n",__func__);
516 
517  adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
518  &m920x_tda10046_08_config,
519  &adap->dev->i2c_adap);
520  if ((adap->fe_adap[0].fe) == NULL)
521  return -EIO;
522 
523  return 0;
524 }
525 
526 static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
527 {
528  deb("%s\n",__func__);
529 
530  adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
531  &m920x_tda10046_0b_config,
532  &adap->dev->i2c_adap);
533  if ((adap->fe_adap[0].fe) == NULL)
534  return -EIO;
535 
536  return 0;
537 }
538 
539 static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
540 {
541  deb("%s\n",__func__);
542 
543  if (dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
544  return -ENODEV;
545 
546  return 0;
547 }
548 
549 static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
550 {
551  deb("%s\n",__func__);
552 
553  if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
554  return -ENODEV;
555 
556  return 0;
557 }
558 
559 static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
560 {
561  deb("%s\n",__func__);
562 
563  if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
564  return -ENODEV;
565 
566  return 0;
567 }
568 
569 static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
570 {
572  &adap->dev->i2c_adap, 0x61,
573  TUNER_PHILIPS_FMD1216ME_MK3);
574  return 0;
575 }
576 
577 /* device-specific initialization */
578 static struct m920x_inits megasky_rc_init [] = {
579  { M9206_RC_INIT2, 0xa8 },
580  { M9206_RC_INIT1, 0x51 },
581  { } /* terminating entry */
582 };
583 
584 static struct m920x_inits tvwalkertwin_rc_init [] = {
585  { M9206_RC_INIT2, 0x00 },
586  { M9206_RC_INIT1, 0xef },
587  { 0xff28, 0x00 },
588  { 0xff23, 0x00 },
589  { 0xff21, 0x30 },
590  { } /* terminating entry */
591 };
592 
593 static struct m920x_inits pinnacle310e_init[] = {
594  /* without these the tuner don't work */
595  { 0xff20, 0x9b },
596  { 0xff22, 0x70 },
597 
598  /* rc settings */
599  { 0xff50, 0x80 },
600  { M9206_RC_INIT1, 0x00 },
601  { M9206_RC_INIT2, 0xff },
602  { } /* terminating entry */
603 };
604 
605 /* ir keymaps */
606 static struct rc_map_table rc_map_megasky_table[] = {
607  { 0x0012, KEY_POWER },
608  { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
609  { 0x0002, KEY_CHANNELUP },
610  { 0x0005, KEY_CHANNELDOWN },
611  { 0x0003, KEY_VOLUMEUP },
612  { 0x0006, KEY_VOLUMEDOWN },
613  { 0x0004, KEY_MUTE },
614  { 0x0007, KEY_OK }, /* TS */
615  { 0x0008, KEY_STOP },
616  { 0x0009, KEY_MENU }, /* swap */
617  { 0x000a, KEY_REWIND },
618  { 0x001b, KEY_PAUSE },
619  { 0x001f, KEY_FASTFORWARD },
620  { 0x000c, KEY_RECORD },
621  { 0x000d, KEY_CAMERA }, /* screenshot */
622  { 0x000e, KEY_COFFEE }, /* "MTS" */
623 };
624 
625 static struct rc_map_table rc_map_tvwalkertwin_table[] = {
626  { 0x0001, KEY_ZOOM }, /* Full Screen */
627  { 0x0002, KEY_CAMERA }, /* snapshot */
628  { 0x0003, KEY_MUTE },
629  { 0x0004, KEY_REWIND },
630  { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */
631  { 0x0006, KEY_FASTFORWARD },
632  { 0x0007, KEY_RECORD },
633  { 0x0008, KEY_STOP },
634  { 0x0009, KEY_TIME }, /* Timeshift */
635  { 0x000c, KEY_COFFEE }, /* Recall */
636  { 0x000e, KEY_CHANNELUP },
637  { 0x0012, KEY_POWER },
638  { 0x0015, KEY_MENU }, /* source */
639  { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */
640  { 0x001a, KEY_CHANNELDOWN },
641  { 0x001b, KEY_VOLUMEDOWN },
642  { 0x001e, KEY_VOLUMEUP },
643 };
644 
645 static struct rc_map_table rc_map_pinnacle310e_table[] = {
646  { 0x16, KEY_POWER },
647  { 0x17, KEY_FAVORITES },
648  { 0x0f, KEY_TEXT },
649  { 0x48, KEY_PROGRAM }, /* preview */
650  { 0x1c, KEY_EPG },
651  { 0x04, KEY_LIST }, /* record list */
652  { 0x03, KEY_1 },
653  { 0x01, KEY_2 },
654  { 0x06, KEY_3 },
655  { 0x09, KEY_4 },
656  { 0x1d, KEY_5 },
657  { 0x1f, KEY_6 },
658  { 0x0d, KEY_7 },
659  { 0x19, KEY_8 },
660  { 0x1b, KEY_9 },
661  { 0x15, KEY_0 },
662  { 0x0c, KEY_CANCEL },
663  { 0x4a, KEY_CLEAR },
664  { 0x13, KEY_BACK },
665  { 0x00, KEY_TAB },
666  { 0x4b, KEY_UP },
667  { 0x4e, KEY_LEFT },
668  { 0x52, KEY_RIGHT },
669  { 0x51, KEY_DOWN },
670  { 0x4f, KEY_ENTER }, /* could also be KEY_OK */
671  { 0x1e, KEY_VOLUMEUP },
672  { 0x0a, KEY_VOLUMEDOWN },
673  { 0x05, KEY_CHANNELUP },
674  { 0x02, KEY_CHANNELDOWN },
675  { 0x11, KEY_RECORD },
676  { 0x14, KEY_PLAY },
677  { 0x4c, KEY_PAUSE },
678  { 0x1a, KEY_STOP },
679  { 0x40, KEY_REWIND },
680  { 0x12, KEY_FASTFORWARD },
681  { 0x41, KEY_PREVIOUSSONG }, /* Replay */
682  { 0x42, KEY_NEXTSONG }, /* Skip */
683  { 0x54, KEY_CAMERA }, /* Capture */
684 /* { 0x50, KEY_SAP }, */ /* Sap */
685  { 0x47, KEY_CYCLEWINDOWS }, /* Pip */
686  { 0x4d, KEY_SCREEN }, /* FullScreen */
687  { 0x08, KEY_SUBTITLE },
688  { 0x0e, KEY_MUTE },
689 /* { 0x49, KEY_LR }, */ /* L/R */
690  { 0x07, KEY_SLEEP }, /* Hibernate */
691  { 0x08, KEY_VIDEO }, /* A/V */
692  { 0x0e, KEY_MENU }, /* Recall */
693  { 0x45, KEY_ZOOMIN },
694  { 0x46, KEY_ZOOMOUT },
695  { 0x18, KEY_RED }, /* Red */
696  { 0x53, KEY_GREEN }, /* Green */
697  { 0x5e, KEY_YELLOW }, /* Yellow */
698  { 0x5f, KEY_BLUE }, /* Blue */
699 };
700 
701 /* DVB USB Driver stuff */
702 static struct dvb_usb_device_properties megasky_properties;
703 static struct dvb_usb_device_properties digivox_mini_ii_properties;
704 static struct dvb_usb_device_properties tvwalkertwin_properties;
705 static struct dvb_usb_device_properties dposh_properties;
706 static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
707 
708 static int m920x_probe(struct usb_interface *intf,
709  const struct usb_device_id *id)
710 {
711  struct dvb_usb_device *d = NULL;
712  int ret;
713  struct m920x_inits *rc_init_seq = NULL;
714  int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
715 
716  deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
717 
718  if (bInterfaceNumber == 0) {
719  /* Single-tuner device, or first interface on
720  * multi-tuner device
721  */
722 
723  ret = dvb_usb_device_init(intf, &megasky_properties,
724  THIS_MODULE, &d, adapter_nr);
725  if (ret == 0) {
726  rc_init_seq = megasky_rc_init;
727  goto found;
728  }
729 
730  ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
731  THIS_MODULE, &d, adapter_nr);
732  if (ret == 0) {
733  /* No remote control, so no rc_init_seq */
734  goto found;
735  }
736 
737  /* This configures both tuners on the TV Walker Twin */
738  ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
739  THIS_MODULE, &d, adapter_nr);
740  if (ret == 0) {
741  rc_init_seq = tvwalkertwin_rc_init;
742  goto found;
743  }
744 
745  ret = dvb_usb_device_init(intf, &dposh_properties,
746  THIS_MODULE, &d, adapter_nr);
747  if (ret == 0) {
748  /* Remote controller not supported yet. */
749  goto found;
750  }
751 
752  ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties,
753  THIS_MODULE, &d, adapter_nr);
754  if (ret == 0) {
755  rc_init_seq = pinnacle310e_init;
756  goto found;
757  }
758 
759  return ret;
760  } else {
761  /* Another interface on a multi-tuner device */
762 
763  /* The LifeView TV Walker Twin gets here, but struct
764  * tvwalkertwin_properties already configured both
765  * tuners, so there is nothing for us to do here
766  */
767  }
768 
769  found:
770  if ((ret = m920x_init_ep(intf)) < 0)
771  return ret;
772 
773  if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
774  return ret;
775 
776  return ret;
777 }
778 
779 static struct usb_device_id m920x_table [] = {
780  { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
781  { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
783  { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
785  { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
787  { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
788  { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
790  { } /* Terminating entry */
791 };
792 MODULE_DEVICE_TABLE (usb, m920x_table);
793 
794 static struct dvb_usb_device_properties megasky_properties = {
796 
797  .usb_ctrl = DEVICE_SPECIFIC,
798  .firmware = "dvb-usb-megasky-02.fw",
799  .download_firmware = m920x_firmware_download,
800 
801  .rc.legacy = {
802  .rc_interval = 100,
803  .rc_map_table = rc_map_megasky_table,
804  .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
805  .rc_query = m920x_rc_query,
806  },
807 
808  .size_of_priv = sizeof(struct m920x_state),
809 
810  .identify_state = m920x_identify_state,
811  .num_adapters = 1,
812  .adapter = {{
813  .num_frontends = 1,
814  .fe = {{
815 
816  .caps = DVB_USB_ADAP_HAS_PID_FILTER |
818 
819  .pid_filter_count = 8,
820  .pid_filter = m920x_pid_filter,
821  .pid_filter_ctrl = m920x_pid_filter_ctrl,
822 
823  .frontend_attach = m920x_mt352_frontend_attach,
824  .tuner_attach = m920x_qt1010_tuner_attach,
825 
826  .stream = {
827  .type = USB_BULK,
828  .count = 8,
829  .endpoint = 0x81,
830  .u = {
831  .bulk = {
832  .buffersize = 512,
833  }
834  }
835  },
836  }},
837  }},
838  .i2c_algo = &m920x_i2c_algo,
839 
840  .num_device_descs = 1,
841  .devices = {
842  { "MSI Mega Sky 580 DVB-T USB2.0",
843  { &m920x_table[0], NULL },
844  { NULL },
845  }
846  }
847 };
848 
849 static struct dvb_usb_device_properties digivox_mini_ii_properties = {
851 
852  .usb_ctrl = DEVICE_SPECIFIC,
853  .firmware = "dvb-usb-digivox-02.fw",
854  .download_firmware = m920x_firmware_download,
855 
856  .size_of_priv = sizeof(struct m920x_state),
857 
858  .identify_state = m920x_identify_state,
859  .num_adapters = 1,
860  .adapter = {{
861  .num_frontends = 1,
862  .fe = {{
863 
864  .caps = DVB_USB_ADAP_HAS_PID_FILTER |
866 
867  .pid_filter_count = 8,
868  .pid_filter = m920x_pid_filter,
869  .pid_filter_ctrl = m920x_pid_filter_ctrl,
870 
871  .frontend_attach = m920x_tda10046_08_frontend_attach,
872  .tuner_attach = m920x_tda8275_60_tuner_attach,
873 
874  .stream = {
875  .type = USB_BULK,
876  .count = 8,
877  .endpoint = 0x81,
878  .u = {
879  .bulk = {
880  .buffersize = 0x4000,
881  }
882  }
883  },
884  }},
885  }},
886  .i2c_algo = &m920x_i2c_algo,
887 
888  .num_device_descs = 1,
889  .devices = {
890  { "MSI DIGI VOX mini II DVB-T USB2.0",
891  { &m920x_table[1], NULL },
892  { NULL },
893  },
894  }
895 };
896 
897 /* LifeView TV Walker Twin support by Nick Andrew <[email protected]>
898  *
899  * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
900  * TDA10046 #0 is located at i2c address 0x08
901  * TDA10046 #1 is located at i2c address 0x0b
902  * TDA8275A #0 is located at i2c address 0x60
903  * TDA8275A #1 is located at i2c address 0x61
904  */
905 static struct dvb_usb_device_properties tvwalkertwin_properties = {
907 
908  .usb_ctrl = DEVICE_SPECIFIC,
909  .firmware = "dvb-usb-tvwalkert.fw",
910  .download_firmware = m920x_firmware_download,
911 
912  .rc.legacy = {
913  .rc_interval = 100,
914  .rc_map_table = rc_map_tvwalkertwin_table,
915  .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
916  .rc_query = m920x_rc_query,
917  },
918 
919  .size_of_priv = sizeof(struct m920x_state),
920 
921  .identify_state = m920x_identify_state,
922  .num_adapters = 2,
923  .adapter = {{
924  .num_frontends = 1,
925  .fe = {{
926 
927  .caps = DVB_USB_ADAP_HAS_PID_FILTER |
929 
930  .pid_filter_count = 8,
931  .pid_filter = m920x_pid_filter,
932  .pid_filter_ctrl = m920x_pid_filter_ctrl,
933 
934  .frontend_attach = m920x_tda10046_08_frontend_attach,
935  .tuner_attach = m920x_tda8275_60_tuner_attach,
936 
937  .stream = {
938  .type = USB_BULK,
939  .count = 8,
940  .endpoint = 0x81,
941  .u = {
942  .bulk = {
943  .buffersize = 512,
944  }
945  }
946  }},
947  }},{
948  .num_frontends = 1,
949  .fe = {{
950 
951  .caps = DVB_USB_ADAP_HAS_PID_FILTER |
953 
954  .pid_filter_count = 8,
955  .pid_filter = m920x_pid_filter,
956  .pid_filter_ctrl = m920x_pid_filter_ctrl,
957 
958  .frontend_attach = m920x_tda10046_0b_frontend_attach,
959  .tuner_attach = m920x_tda8275_61_tuner_attach,
960 
961  .stream = {
962  .type = USB_BULK,
963  .count = 8,
964  .endpoint = 0x82,
965  .u = {
966  .bulk = {
967  .buffersize = 512,
968  }
969  }
970  }},
971  },
972  }},
973  .i2c_algo = &m920x_i2c_algo,
974 
975  .num_device_descs = 1,
976  .devices = {
977  { .name = "LifeView TV Walker Twin DVB-T USB2.0",
978  .cold_ids = { &m920x_table[2], NULL },
979  .warm_ids = { &m920x_table[3], NULL },
980  },
981  }
982 };
983 
984 static struct dvb_usb_device_properties dposh_properties = {
986 
987  .usb_ctrl = DEVICE_SPECIFIC,
988  .firmware = "dvb-usb-dposh-01.fw",
989  .download_firmware = m920x_firmware_download,
990 
991  .size_of_priv = sizeof(struct m920x_state),
992 
993  .identify_state = m920x_identify_state,
994  .num_adapters = 1,
995  .adapter = {{
996  .num_frontends = 1,
997  .fe = {{
998  /* Hardware pid filters don't work with this device/firmware */
999 
1000  .frontend_attach = m920x_mt352_frontend_attach,
1001  .tuner_attach = m920x_qt1010_tuner_attach,
1002 
1003  .stream = {
1004  .type = USB_BULK,
1005  .count = 8,
1006  .endpoint = 0x81,
1007  .u = {
1008  .bulk = {
1009  .buffersize = 512,
1010  }
1011  }
1012  },
1013  }},
1014  }},
1015  .i2c_algo = &m920x_i2c_algo,
1016 
1017  .num_device_descs = 1,
1018  .devices = {
1019  { .name = "Dposh DVB-T USB2.0",
1020  .cold_ids = { &m920x_table[4], NULL },
1021  .warm_ids = { &m920x_table[5], NULL },
1022  },
1023  }
1024 };
1025 
1026 static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
1027  .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1028 
1029  .usb_ctrl = DEVICE_SPECIFIC,
1030  .download_firmware = NULL,
1031 
1032  .rc.legacy = {
1033  .rc_interval = 100,
1034  .rc_map_table = rc_map_pinnacle310e_table,
1035  .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
1036  .rc_query = m920x_rc_query,
1037  },
1038 
1039  .size_of_priv = sizeof(struct m920x_state),
1040 
1041  .identify_state = m920x_identify_state,
1042  .num_adapters = 1,
1043  .adapter = {{
1044  .num_frontends = 1,
1045  .fe = {{
1046 
1047  .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1049 
1050  .pid_filter_count = 8,
1051  .pid_filter = m920x_pid_filter,
1052  .pid_filter_ctrl = m920x_pid_filter_ctrl,
1053 
1054  .frontend_attach = m920x_mt352_frontend_attach,
1055  .tuner_attach = m920x_fmd1216me_tuner_attach,
1056 
1057  .stream = {
1058  .type = USB_ISOC,
1059  .count = 5,
1060  .endpoint = 0x84,
1061  .u = {
1062  .isoc = {
1063  .framesperurb = 128,
1064  .framesize = 564,
1065  .interval = 1,
1066  }
1067  }
1068  },
1069  }},
1070  } },
1071  .i2c_algo = &m920x_i2c_algo,
1072 
1073  .num_device_descs = 1,
1074  .devices = {
1075  { "Pinnacle PCTV 310e",
1076  { &m920x_table[6], NULL },
1077  { NULL },
1078  }
1079  }
1080 };
1081 
1082 static struct usb_driver m920x_driver = {
1083  .name = "dvb_usb_m920x",
1084  .probe = m920x_probe,
1085  .disconnect = dvb_usb_device_exit,
1086  .id_table = m920x_table,
1087 };
1088 
1089 module_usb_driver(m920x_driver);
1090 
1091 MODULE_AUTHOR("Aapo Tahkola <[email protected]>");
1092 MODULE_DESCRIPTION("DVB Driver for ULI M920x");
1093 MODULE_VERSION("0.1");
1094 MODULE_LICENSE("GPL");
1095 
1096 /*
1097  * Local variables:
1098  * c-basic-offset: 8
1099  */