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