V4L/DVB (5607): M920x: Initial support for devices likely manufactured by Dposh
[safe/jmp/linux-2.6] / drivers / media / dvb / dvb-usb / m920x.c
1 /* DVB USB compliant linux driver for MSI Mega Sky 580 DVB-T USB2.0 receiver
2  *
3  * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org)
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 Free
7  *      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 /* debug */
21 static int dvb_usb_m920x_debug;
22 module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
23 MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
24
25 static struct dvb_usb_rc_key megasky_rc_keys [] = {
26         { 0x0, 0x12, KEY_POWER },
27         { 0x0, 0x1e, KEY_CYCLEWINDOWS }, /* min/max */
28         { 0x0, 0x02, KEY_CHANNELUP },
29         { 0x0, 0x05, KEY_CHANNELDOWN },
30         { 0x0, 0x03, KEY_VOLUMEUP },
31         { 0x0, 0x06, KEY_VOLUMEDOWN },
32         { 0x0, 0x04, KEY_MUTE },
33         { 0x0, 0x07, KEY_OK }, /* TS */
34         { 0x0, 0x08, KEY_STOP },
35         { 0x0, 0x09, KEY_MENU }, /* swap */
36         { 0x0, 0x0a, KEY_REWIND },
37         { 0x0, 0x1b, KEY_PAUSE },
38         { 0x0, 0x1f, KEY_FASTFORWARD },
39         { 0x0, 0x0c, KEY_RECORD },
40         { 0x0, 0x0d, KEY_CAMERA }, /* screenshot */
41         { 0x0, 0x0e, KEY_COFFEE }, /* "MTS" */
42 };
43
44 static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
45         { 0x0, 0x01, KEY_ZOOM }, /* Full Screen */
46         { 0x0, 0x02, KEY_CAMERA }, /* snapshot */
47         { 0x0, 0x03, KEY_MUTE },
48         { 0x0, 0x04, KEY_REWIND },
49         { 0x0, 0x05, KEY_PLAYPAUSE }, /* Play/Pause */
50         { 0x0, 0x06, KEY_FASTFORWARD },
51         { 0x0, 0x07, KEY_RECORD },
52         { 0x0, 0x08, KEY_STOP },
53         { 0x0, 0x09, KEY_TIME }, /* Timeshift */
54         { 0x0, 0x0c, KEY_COFFEE }, /* Recall */
55         { 0x0, 0x0e, KEY_CHANNELUP },
56         { 0x0, 0x12, KEY_POWER },
57         { 0x0, 0x15, KEY_MENU }, /* source */
58         { 0x0, 0x18, KEY_CYCLEWINDOWS }, /* TWIN PIP */
59         { 0x0, 0x1a, KEY_CHANNELDOWN },
60         { 0x0, 0x1b, KEY_VOLUMEDOWN },
61         { 0x0, 0x1e, KEY_VOLUMEUP },
62 };
63
64 static inline int m9206_read(struct usb_device *udev, u8 request, u16 value,\
65                              u16 index, void *data, int size)
66 {
67         int ret;
68
69         ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
70                               request, USB_TYPE_VENDOR | USB_DIR_IN,
71                               value, index, data, size, 2000);
72         if (ret < 0) {
73                 printk(KERN_INFO "m920x_read = error: %d\n", ret);
74                 return ret;
75         }
76
77         if (ret != size) {
78                 deb_rc("m920x_read = no data\n");
79                 return -EIO;
80         }
81
82         return 0;
83 }
84
85 static inline int m9206_write(struct usb_device *udev, u8 request,
86                               u16 value, u16 index)
87 {
88         int ret;
89
90         ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
91                               request, USB_TYPE_VENDOR | USB_DIR_OUT,
92                               value, index, NULL, 0, 2000);
93
94         return ret;
95 }
96
97 static int m9206_init(struct dvb_usb_device *d, struct m9206_inits *rc_seq)
98 {
99         int ret = 0;
100
101         /* Remote controller init. */
102         if (d->props.rc_query) {
103                 deb_rc("Initialising remote control\n");
104                 while (rc_seq->address) {
105                         if ((ret = m9206_write(d->udev, M9206_CORE, rc_seq->data, rc_seq->address)) != 0) {
106                                 deb_rc("Initialising remote control failed\n");
107                                 return ret;
108                         }
109
110                         rc_seq++;
111                 }
112
113                 deb_rc("Initialising remote control success\n");
114         }
115
116         return ret;
117 }
118
119 static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
120 {
121         struct m9206_state *m = d->priv;
122         int i, ret = 0;
123         u8 rc_state[2];
124
125         if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
126                 goto unlock;
127
128         if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
129                 goto unlock;
130
131         for (i = 0; i < d->props.rc_key_map_size; i++)
132                 if (d->props.rc_key_map[i].data == rc_state[1]) {
133                         *event = d->props.rc_key_map[i].event;
134
135                         switch(rc_state[0]) {
136                         case 0x80:
137                                 *state = REMOTE_NO_KEY_PRESSED;
138                                 goto unlock;
139
140                         case 0x88: /* framing error or "invalid code" */
141                         case 0x99:
142                         case 0xc0:
143                         case 0xd8:
144                                 *state = REMOTE_NO_KEY_PRESSED;
145                                 m->rep_count = 0;
146                                 goto unlock;
147
148                         case 0x93:
149                         case 0x92:
150                                 m->rep_count = 0;
151                                 *state = REMOTE_KEY_PRESSED;
152                                 goto unlock;
153
154                         case 0x91:
155                                 /* prevent immediate auto-repeat */
156                                 if (++m->rep_count > 2)
157                                         *state = REMOTE_KEY_REPEAT;
158                                 else
159                                         *state = REMOTE_NO_KEY_PRESSED;
160                                 goto unlock;
161
162                         default:
163                                 deb_rc("Unexpected rc state %02x\n", rc_state[0]);
164                                 *state = REMOTE_NO_KEY_PRESSED;
165                                 goto unlock;
166                         }
167                 }
168
169         if (rc_state[1] != 0)
170                 deb_rc("Unknown rc key %02x\n", rc_state[1]);
171
172         *state = REMOTE_NO_KEY_PRESSED;
173
174         unlock:
175
176         return ret;
177 }
178
179 /* I2C */
180 static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
181                           int num)
182 {
183         struct dvb_usb_device *d = i2c_get_adapdata(adap);
184         int i, j;
185         int ret = 0;
186
187         if (!num)
188                 return -EINVAL;
189
190         if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
191                 return -EAGAIN;
192
193         for (i = 0; i < num; i++) {
194                 if (msg[i].flags & (I2C_M_NO_RD_ACK|I2C_M_IGNORE_NAK|I2C_M_TEN) ||
195                     msg[i].len == 0) {
196                         /* For a 0 byte message, I think sending the address to index 0x80|0x40
197                          * would be the correct thing to do.  However, zero byte messages are
198                          * only used for probing, and since we don't know how to get the slave's
199                          * ack, we can't probe. */
200                         ret = -ENOTSUPP;
201                         goto unlock;
202                 }
203                 /* Send START & address/RW bit */
204                 if (!(msg[i].flags & I2C_M_NOSTART)) {
205                         if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:0), 0x80)) != 0)
206                                 goto unlock;
207                         /* Should check for ack here, if we knew how. */
208                 }
209                 if (msg[i].flags & I2C_M_RD) {
210                         for (j = 0; j < msg[i].len; j++) {
211                                 /* Last byte of transaction? Send STOP, otherwise send ACK. */
212                                 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x01;
213                                 if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x20|stop, &msg[i].buf[j], 1)) != 0)
214                                         goto unlock;
215                         }
216                 } else {
217                         for (j = 0; j < msg[i].len; j++) {
218                                 /* Last byte of transaction? Then send STOP. */
219                                 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x00;
220                                 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
221                                         goto unlock;
222                                 /* Should check for ack here too. */
223                         }
224                 }
225         }
226         ret = num;
227
228 unlock:
229         mutex_unlock(&d->i2c_mutex);
230
231         return ret;
232 }
233
234 static u32 m9206_i2c_func(struct i2c_adapter *adapter)
235 {
236         return I2C_FUNC_I2C;
237 }
238
239 static struct i2c_algorithm m9206_i2c_algo = {
240         .master_xfer   = m9206_i2c_xfer,
241         .functionality = m9206_i2c_func,
242 };
243
244
245 static int m9206_set_filter(struct dvb_usb_adapter *adap, int type, int idx,
246                             int pid)
247 {
248         int ret = 0;
249
250         if (pid >= 0x8000)
251                 return -EINVAL;
252
253         pid |= 0x8000;
254
255         if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
256                 return ret;
257
258         if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
259                 return ret;
260
261         return ret;
262 }
263
264 static int m9206_update_filters(struct dvb_usb_adapter *adap)
265 {
266         struct m9206_state *m = adap->dev->priv;
267         int enabled = m->filtering_enabled;
268         int i, ret = 0, filter = 0;
269
270         for (i = 0; i < M9206_MAX_FILTERS; i++)
271                 if (m->filters[i] == 8192)
272                         enabled = 0;
273
274         /* Disable all filters */
275         if ((ret = m9206_set_filter(adap, 0x81, 1, enabled)) != 0)
276                 return ret;
277
278         for (i = 0; i < M9206_MAX_FILTERS; i++)
279                 if ((ret = m9206_set_filter(adap, 0x81, i + 2, 0)) != 0)
280                         return ret;
281
282         if ((ret = m9206_set_filter(adap, 0x82, 0, 0x0)) != 0)
283                 return ret;
284
285         /* Set */
286         if (enabled) {
287                 for (i = 0; i < M9206_MAX_FILTERS; i++) {
288                         if (m->filters[i] == 0)
289                                 continue;
290
291                         if ((ret = m9206_set_filter(adap, 0x81, filter + 2, m->filters[i])) != 0)
292                                 return ret;
293
294                         filter++;
295                 }
296         }
297
298         if ((ret = m9206_set_filter(adap, 0x82, 0, 0x02f5)) != 0)
299                 return ret;
300
301         return ret;
302 }
303
304 static int m9206_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
305 {
306         struct m9206_state *m = adap->dev->priv;
307
308         m->filtering_enabled = onoff ? 1 : 0;
309
310         return m9206_update_filters(adap);
311 }
312
313 static int m9206_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
314                             int onoff)
315 {
316         struct m9206_state *m = adap->dev->priv;
317
318         m->filters[index] = onoff ? pid : 0;
319
320         return m9206_update_filters(adap);
321 }
322
323 static int m9206_firmware_download(struct usb_device *udev,
324                                    const struct firmware *fw)
325 {
326         u16 value, index, size;
327         u8 read[4], *buff;
328         int i, pass, ret = 0;
329
330         buff = kmalloc(65536, GFP_KERNEL);
331
332         if ((ret = m9206_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
333                 goto done;
334         deb_rc("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
335
336         if ((ret = m9206_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
337                 goto done;
338         deb_rc("%x\n", read[0]);
339
340         for (pass = 0; pass < 2; pass++) {
341                 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
342                         value = le16_to_cpu(*(u16 *)(fw->data + i));
343                         i += sizeof(u16);
344
345                         index = le16_to_cpu(*(u16 *)(fw->data + i));
346                         i += sizeof(u16);
347
348                         size = le16_to_cpu(*(u16 *)(fw->data + i));
349                         i += sizeof(u16);
350
351                         if (pass == 1) {
352                                 /* Will stall if using fw->data ... */
353                                 memcpy(buff, fw->data + i, size);
354
355                                 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
356                                             M9206_FW,
357                                             USB_TYPE_VENDOR | USB_DIR_OUT,
358                                             value, index, buff, size, 20);
359                                 if (ret != size) {
360                                         deb_rc("error while uploading fw!\n");
361                                         ret = -EIO;
362                                         goto done;
363                                 }
364                                 msleep(3);
365                         }
366                         i += size;
367                 }
368                 if (i != fw->size) {
369                         deb_rc("bad firmware file!\n");
370                         ret = -EINVAL;
371                         goto done;
372                 }
373         }
374
375         msleep(36);
376
377         /* m9206 will disconnect itself from the bus after this. */
378         (void) m9206_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
379         deb_rc("firmware uploaded!\n");
380
381         done:
382         kfree(buff);
383
384         return ret;
385 }
386
387 /* Callbacks for DVB USB */
388 static int m920x_identify_state(struct usb_device *udev,
389                                 struct dvb_usb_device_properties *props,
390                                 struct dvb_usb_device_description **desc,
391                                 int *cold)
392 {
393         struct usb_host_interface *alt;
394
395         alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
396         *cold = (alt == NULL) ? 1 : 0;
397
398         return 0;
399 }
400
401 static int megasky_mt352_demod_init(struct dvb_frontend *fe)
402 {
403         u8 config[] = { CONFIG, 0x3d };
404         u8 clock[] = { CLOCK_CTL, 0x30 };
405         u8 reset[] = { RESET, 0x80 };
406         u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
407         u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
408         u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
409         u8 unk1[] = { 0x93, 0x1a };
410         u8 unk2[] = { 0xb5, 0x7a };
411
412         mt352_write(fe, config, ARRAY_SIZE(config));
413         mt352_write(fe, clock, ARRAY_SIZE(clock));
414         mt352_write(fe, reset, ARRAY_SIZE(reset));
415         mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl));
416         mt352_write(fe, agc, ARRAY_SIZE(agc));
417         mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc));
418         mt352_write(fe, unk1, ARRAY_SIZE(unk1));
419         mt352_write(fe, unk2, ARRAY_SIZE(unk2));
420
421         deb_rc("Demod init!\n");
422
423         return 0;
424 }
425
426 static struct mt352_config megasky_mt352_config = {
427         .demod_address = 0x0f,
428         .no_tuner = 1,
429         .demod_init = megasky_mt352_demod_init,
430 };
431
432 static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap)
433 {
434         deb_rc("megasky_frontend_attach!\n");
435
436         if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL)
437                 return -EIO;
438
439         return 0;
440 }
441
442 static struct qt1010_config megasky_qt1010_config = {
443         .i2c_address = 0x62
444 };
445
446 static int megasky_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
447 {
448         if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap,
449                        &megasky_qt1010_config) == NULL)
450                 return -ENODEV;
451
452         return 0;
453 }
454
455 static struct m9206_inits megasky_rc_init [] = {
456         { M9206_RC_INIT2, 0xa8 },
457         { M9206_RC_INIT1, 0x51 },
458         { } /* terminating entry */
459 };
460
461 static struct tda1004x_config digivox_tda10046_config = {
462         .demod_address = 0x08,
463         .invert = 0,
464         .invert_oclk = 0,
465         .ts_mode = TDA10046_TS_SERIAL,
466         .xtal_freq = TDA10046_XTAL_16M,
467         .if_freq = TDA10046_FREQ_045,
468         .agc_config = TDA10046_AGC_TDA827X,
469         .gpio_config = TDA10046_GPTRI,
470         .request_firmware = NULL,
471 };
472
473 static int digivox_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
474 {
475         deb_rc("digivox_tda10046_frontend_attach!\n");
476
477         if ((adap->fe = dvb_attach(tda10046_attach, &digivox_tda10046_config,
478                                    &adap->dev->i2c_adap)) == NULL)
479                 return -EIO;
480
481         return 0;
482 }
483
484 static int digivox_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
485 {
486         if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap,
487                        NULL) == NULL)
488                 return -ENODEV;
489         return 0;
490 }
491
492 /* LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
493  * TDA10046 #0 is located at i2c address 0x08
494  * TDA10046 #1 is located at i2c address 0x0b
495  * TDA8275A #0 is located at i2c address 0x60
496  * TDA8275A #1 is located at i2c address 0x61
497  */
498
499 static struct tda1004x_config tvwalkertwin_0_tda10046_config = {
500         .demod_address = 0x08,
501         .invert = 0,
502         .invert_oclk = 0,
503         .ts_mode = TDA10046_TS_SERIAL,
504         .xtal_freq = TDA10046_XTAL_16M,
505         .if_freq = TDA10046_FREQ_045,
506         .agc_config = TDA10046_AGC_TDA827X,
507         .gpio_config = TDA10046_GPTRI,
508         .request_firmware = NULL, /* uses firmware EEPROM */
509 };
510
511 static struct tda1004x_config tvwalkertwin_1_tda10046_config = {
512         .demod_address = 0x0b,
513         .invert = 0,
514         .invert_oclk = 0,
515         .ts_mode = TDA10046_TS_SERIAL,
516         .xtal_freq = TDA10046_XTAL_16M,
517         .if_freq = TDA10046_FREQ_045,
518         .agc_config = TDA10046_AGC_TDA827X,
519         .gpio_config = TDA10046_GPTRI,
520         .request_firmware = NULL, /* uses firmware EEPROM */
521 };
522
523 static int tvwalkertwin_0_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
524 {
525         deb_rc("tvwalkertwin_0_tda10046_frontend_attach!\n");
526
527         if ((adap->fe = dvb_attach(tda10046_attach, &tvwalkertwin_0_tda10046_config, &adap->dev->i2c_adap)) == NULL)
528                 return -EIO;
529
530         deb_rc("Attached demod 0 at address %02x\n", tvwalkertwin_0_tda10046_config.demod_address);
531
532         return 0;
533 }
534
535 static int tvwalkertwin_1_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
536 {
537         deb_rc("tvwalkertwin_1_tda10046_frontend_attach!\n");
538
539         if ((adap->fe = dvb_attach(tda10046_attach, &tvwalkertwin_1_tda10046_config, &adap->dev->i2c_adap)) == NULL)
540                 return -EIO;
541
542         deb_rc("Attached demod 1 at address %02x\n", tvwalkertwin_1_tda10046_config.demod_address);
543
544         return 0;
545 }
546
547 static int tvwalkertwin_0_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
548 {
549         int address = 0x60;
550
551         deb_rc("tvwalkertwin_0_tda8275_tuner_attach!\n");
552
553         if (dvb_attach(tda827x_attach, adap->fe, address, &adap->dev->i2c_adap,
554                        NULL) == NULL)
555                 return -ENODEV;
556
557         deb_rc("Attached tuner 0 at address %02x\n", address);
558
559         return 0;
560 }
561
562 static int tvwalkertwin_1_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
563 {
564         int address = 0x61;
565
566         deb_rc("tvwalkertwin_1_tda8275_tuner_attach!\n");
567
568         if (dvb_attach(tda827x_attach, adap->fe, address, &adap->dev->i2c_adap,
569                        NULL) == NULL)
570                 return -ENODEV;
571
572         deb_rc("Attached tuner 1 at address %02x\n", address);
573
574         return 0;
575 }
576
577 static struct m9206_inits tvwalkertwin_rc_init [] = {
578         { M9206_RC_INIT2, 0x00 },
579         { M9206_RC_INIT1, 0xef },
580         { 0xff28,         0x00 },
581         { 0xff23,         0x00 },
582         { 0xff21,         0x30 },
583         { } /* terminating entry */
584 };
585
586 /* DVB USB Driver stuff */
587 static struct dvb_usb_device_properties megasky_properties;
588 static struct dvb_usb_device_properties digivox_mini_ii_properties;
589 static struct dvb_usb_device_properties tvwalkertwin_properties;
590 static struct dvb_usb_device_properties dposh_properties;
591 static struct m9206_inits megasky_rc_init [];
592 static struct m9206_inits tvwalkertwin_rc_init [];
593
594 static int m920x_probe(struct usb_interface *intf,
595                        const struct usb_device_id *id)
596 {
597         struct dvb_usb_device *d;
598         struct usb_host_interface *alt;
599         int ret;
600         struct m9206_inits *rc_init_seq = NULL;
601         int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
602
603         deb_rc("Probing for m920x device at interface %d\n", bInterfaceNumber);
604
605         if (bInterfaceNumber == 0) {
606                 /* Single-tuner device, or first interface on
607                  * multi-tuner device
608                  */
609
610                 if ((ret = dvb_usb_device_init(intf, &megasky_properties,
611                         THIS_MODULE, &d)) == 0) {
612                         rc_init_seq = megasky_rc_init;
613                         goto found;
614                 }
615
616                 if ((ret = dvb_usb_device_init(intf,
617                         &digivox_mini_ii_properties, THIS_MODULE, &d)) == 0) {
618                         /* No remote control, so no rc_init_seq */
619                         goto found;
620                 }
621
622                 /* This configures both tuners on the TV Walker Twin */
623                 if ((ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
624                         THIS_MODULE, &d)) == 0) {
625                         rc_init_seq = tvwalkertwin_rc_init;
626                         goto found;
627                 }
628
629                 if ((ret = dvb_usb_device_init(intf, &dposh_properties, THIS_MODULE, &d)) == 0) {
630                         /* Remote controller not supported yet. */
631                         goto found;
632                 }
633
634                 return ret;
635         } else {
636                 /* Another interface on a multi-tuner device */
637
638                 /* The LifeView TV Walker Twin gets here, but struct
639                  * tvwalkertwin_properties already configured both
640                  * tuners, so there is nothing for us to do here
641                  */
642
643                 return -ENODEV;
644         }
645
646 found:
647         alt = usb_altnum_to_altsetting(intf, 1);
648         if (alt == NULL) {
649                 deb_rc("No alt found!\n");
650                 return -ENODEV;
651         }
652
653         ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
654                                 alt->desc.bAlternateSetting);
655         if (ret < 0)
656                 return ret;
657
658         if ((ret = m9206_init(d, rc_init_seq)) != 0)
659                 return ret;
660
661         return ret;
662 }
663
664 static struct usb_device_id m920x_table [] = {
665                 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
666                 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
667                              USB_PID_MSI_DIGI_VOX_MINI_II) },
668                 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
669                              USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
670                 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
671                              USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
672                 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
673                 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
674                 { }             /* Terminating entry */
675 };
676 MODULE_DEVICE_TABLE (usb, m920x_table);
677
678 static struct dvb_usb_device_properties megasky_properties = {
679         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
680
681         .usb_ctrl = DEVICE_SPECIFIC,
682         .firmware = "dvb-usb-megasky-02.fw",
683         .download_firmware = m9206_firmware_download,
684
685         .rc_interval      = 100,
686         .rc_key_map       = megasky_rc_keys,
687         .rc_key_map_size  = ARRAY_SIZE(megasky_rc_keys),
688         .rc_query         = m9206_rc_query,
689
690         .size_of_priv     = sizeof(struct m9206_state),
691
692         .identify_state   = m920x_identify_state,
693         .num_adapters = 1,
694         .adapter = {{
695                 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
696                         DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
697
698                 .pid_filter_count = 8,
699                 .pid_filter       = m9206_pid_filter,
700                 .pid_filter_ctrl  = m9206_pid_filter_ctrl,
701
702                 .frontend_attach  = megasky_mt352_frontend_attach,
703                 .tuner_attach     = megasky_qt1010_tuner_attach,
704
705                 .stream = {
706                         .type = USB_BULK,
707                         .count = 8,
708                         .endpoint = 0x81,
709                         .u = {
710                                 .bulk = {
711                                         .buffersize = 512,
712                                 }
713                         }
714                 },
715         }},
716         .i2c_algo         = &m9206_i2c_algo,
717
718         .num_device_descs = 1,
719         .devices = {
720                 {   "MSI Mega Sky 580 DVB-T USB2.0",
721                         { &m920x_table[0], NULL },
722                         { NULL },
723                 }
724         }
725 };
726
727 static struct dvb_usb_device_properties digivox_mini_ii_properties = {
728         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
729
730         .usb_ctrl = DEVICE_SPECIFIC,
731         .firmware = "dvb-usb-digivox-02.fw",
732         .download_firmware = m9206_firmware_download,
733
734         .size_of_priv     = sizeof(struct m9206_state),
735
736         .identify_state   = m920x_identify_state,
737         .num_adapters = 1,
738         .adapter = {{
739                 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
740                 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
741
742                 .pid_filter_count = 8,
743                 .pid_filter       = m9206_pid_filter,
744                 .pid_filter_ctrl  = m9206_pid_filter_ctrl,
745
746                 .frontend_attach  = digivox_tda10046_frontend_attach,
747                 .tuner_attach     = digivox_tda8275_tuner_attach,
748
749                 .stream = {
750                         .type = USB_BULK,
751                         .count = 8,
752                         .endpoint = 0x81,
753                         .u = {
754                                 .bulk = {
755                                         .buffersize = 0x4000,
756                                 }
757                         }
758                 },
759         }},
760         .i2c_algo         = &m9206_i2c_algo,
761
762         .num_device_descs = 1,
763         .devices = {
764                 {   "MSI DIGI VOX mini II DVB-T USB2.0",
765                         { &m920x_table[1], NULL },
766                         { NULL },
767                 },
768         }
769 };
770
771 /* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net> */
772
773 static struct dvb_usb_device_properties tvwalkertwin_properties = {
774         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
775
776         .usb_ctrl = DEVICE_SPECIFIC,
777         .firmware = "dvb-usb-tvwalkert.fw",
778         .download_firmware = m9206_firmware_download,
779
780         .rc_interval      = 100,
781         .rc_key_map       = tvwalkertwin_rc_keys,
782         .rc_key_map_size  = ARRAY_SIZE(tvwalkertwin_rc_keys),
783         .rc_query         = m9206_rc_query,
784
785         .size_of_priv     = sizeof(struct m9206_state),
786
787         .identify_state   = m920x_identify_state,
788         .num_adapters = 2,
789         .adapter = {
790                 {
791                         .caps = DVB_USB_ADAP_HAS_PID_FILTER |
792                                 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
793
794                         .pid_filter_count = 8,
795                         .pid_filter       = m9206_pid_filter,
796                         .pid_filter_ctrl  = m9206_pid_filter_ctrl,
797
798                         .frontend_attach  = tvwalkertwin_0_tda10046_frontend_attach,
799                         .tuner_attach     = tvwalkertwin_0_tda8275_tuner_attach,
800
801                         .stream = {
802                                 .type = USB_BULK,
803                                 .count = 8,
804                                 .endpoint = 0x81,
805                                 .u = {
806                                         .bulk = {
807                                                 .buffersize = 512,
808                                         }
809                                 }
810                         },
811                 },
812                 {
813                         .caps = DVB_USB_ADAP_HAS_PID_FILTER |
814                                 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
815
816                         .pid_filter_count = 8,
817                         .pid_filter       = m9206_pid_filter,
818                         .pid_filter_ctrl  = m9206_pid_filter_ctrl,
819
820                         .frontend_attach  = tvwalkertwin_1_tda10046_frontend_attach,
821                         .tuner_attach     = tvwalkertwin_1_tda8275_tuner_attach,
822
823                         .stream = {
824                                 .type = USB_BULK,
825                                 .count = 8,
826                                 .endpoint = 0x82,
827                                 .u = {
828                                         .bulk = {
829                                                 .buffersize = 512,
830                                         }
831                                 }
832                         },
833                 }
834         },
835         .i2c_algo         = &m9206_i2c_algo,
836
837         .num_device_descs = 1,
838         .devices = {
839                 {   .name = "LifeView TV Walker Twin DVB-T USB2.0",
840                     .cold_ids = { &m920x_table[2], NULL },
841                     .warm_ids = { &m920x_table[3], NULL },
842                 },
843         }
844 };
845
846 static struct dvb_usb_device_properties dposh_properties = {
847         .caps = DVB_USB_IS_AN_I2C_ADAPTER,
848
849         .usb_ctrl = DEVICE_SPECIFIC,
850         .firmware = "dvb-usb-dposh-01.fw",
851         .download_firmware = m9206_firmware_download,
852
853         /* Remote controller not supported yet. */
854
855         .size_of_priv     = sizeof(struct m9206_state),
856
857         .identify_state   = m920x_identify_state,
858         .num_adapters = 1,
859         .adapter = {{
860                          /* Nardware pid filters don't work with this device/firmware. */
861
862                          .frontend_attach  = megasky_mt352_frontend_attach,
863                          .tuner_attach     = megasky_qt1010_tuner_attach,
864
865                          .stream = {
866                                  .type = USB_BULK,
867                                  .count = 8,
868                                  .endpoint = 0x81,
869                                  .u = {
870                                           .bulk = {
871                                                   .buffersize = 512,
872                                           }
873                                   }
874                          },
875                  }},
876         .i2c_algo         = &m9206_i2c_algo,
877
878         .num_device_descs = 1,
879         .devices = {
880                  {   .name = "Dposh DVB-T USB2.0",
881                      .cold_ids = { &m920x_table[4], NULL },
882                      .warm_ids = { &m920x_table[5], NULL },
883                  },
884          }
885 };
886
887 static struct usb_driver m920x_driver = {
888         .name           = "dvb_usb_m920x",
889         .probe          = m920x_probe,
890         .disconnect     = dvb_usb_device_exit,
891         .id_table       = m920x_table,
892 };
893
894 /* module stuff */
895 static int __init m920x_module_init(void)
896 {
897         int ret;
898
899         if ((ret = usb_register(&m920x_driver))) {
900                 err("usb_register failed. Error number %d", ret);
901                 return ret;
902         }
903
904         return 0;
905 }
906
907 static void __exit m920x_module_exit(void)
908 {
909         /* deregister this driver from the USB subsystem */
910         usb_deregister(&m920x_driver);
911 }
912
913 module_init (m920x_module_init);
914 module_exit (m920x_module_exit);
915
916 MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
917 MODULE_DESCRIPTION("DVB Driver for ULI M920x");
918 MODULE_VERSION("0.1");
919 MODULE_LICENSE("GPL");
920
921 /*
922  * Local variables:
923  * c-basic-offset: 8
924  */