V4L/DVB (5609): M920x: group like functions together
[deliverable/linux.git] / drivers / media / dvb / dvb-usb / m920x.c
CommitLineData
5fecd9fd
AT
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
d3911eaa
MK
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation, version 2.
5fecd9fd
AT
8 *
9 * see Documentation/dvb/README.dvb-usb for more information
10 */
baa2ed09 11
2aef7d0f 12#include "m920x.h"
5fecd9fd
AT
13
14#include "mt352.h"
15#include "mt352_priv.h"
017cf012 16#include "qt1010.h"
d4ca23b1
PW
17#include "tda1004x.h"
18#include "tda827x.h"
5fecd9fd
AT
19
20/* debug */
26f48eaa 21static int dvb_usb_m920x_debug;
baa2ed09 22module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
5fecd9fd
AT
23MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
24
d3911eaa 25static inline int m9206_read(struct usb_device *udev, u8 request, u16 value,
fa94805d 26 u16 index, void *data, int size)
5fecd9fd
AT
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);
59069e53
PW
33 if (ret < 0) {
34 printk(KERN_INFO "m920x_read = error: %d\n", ret);
5fecd9fd 35 return ret;
59069e53 36 }
5fecd9fd 37
59069e53
PW
38 if (ret != size) {
39 deb_rc("m920x_read = no data\n");
5fecd9fd 40 return -EIO;
59069e53 41 }
5fecd9fd
AT
42
43 return 0;
44}
45
fa94805d
MK
46static inline int m9206_write(struct usb_device *udev, u8 request,
47 u16 value, u16 index)
5fecd9fd
AT
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);
59069e53 54
e2adbecf
AT
55 return ret;
56}
57
aa50ec2b 58static int m9206_init(struct dvb_usb_device *d, struct m9206_inits *rc_seq)
e2adbecf
AT
59{
60 int ret = 0;
61
62 /* Remote controller init. */
480ac761 63 if (d->props.rc_query) {
aa50ec2b
NA
64 deb_rc("Initialising remote control\n");
65 while (rc_seq->address) {
d3911eaa
MK
66 if ((ret = m9206_write(d->udev, M9206_CORE,
67 rc_seq->data,
68 rc_seq->address)) != 0) {
aa50ec2b
NA
69 deb_rc("Initialising remote control failed\n");
70 return ret;
71 }
e2adbecf 72
aa50ec2b
NA
73 rc_seq++;
74 }
75
76 deb_rc("Initialising remote control success\n");
480ac761 77 }
5fecd9fd
AT
78
79 return ret;
80}
81
82static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
83{
e2adbecf 84 struct m9206_state *m = d->priv;
5fecd9fd
AT
85 int i, ret = 0;
86 u8 rc_state[2];
87
d3911eaa
MK
88 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE,
89 rc_state, 1)) != 0)
5fecd9fd
AT
90 goto unlock;
91
d3911eaa
MK
92 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY,
93 rc_state + 1, 1)) != 0)
5fecd9fd
AT
94 goto unlock;
95
480ac761
AT
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;
5fecd9fd
AT
99
100 switch(rc_state[0]) {
101 case 0x80:
102 *state = REMOTE_NO_KEY_PRESSED;
103 goto unlock;
104
aa50ec2b
NA
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
5fecd9fd
AT
113 case 0x93:
114 case 0x92:
e2adbecf 115 m->rep_count = 0;
5fecd9fd
AT
116 *state = REMOTE_KEY_PRESSED;
117 goto unlock;
118
119 case 0x91:
aa50ec2b 120 /* prevent immediate auto-repeat */
e2adbecf
AT
121 if (++m->rep_count > 2)
122 *state = REMOTE_KEY_REPEAT;
aa50ec2b
NA
123 else
124 *state = REMOTE_NO_KEY_PRESSED;
5fecd9fd
AT
125 goto unlock;
126
127 default:
d3911eaa
MK
128 deb_rc("Unexpected rc state %02x\n",
129 rc_state[0]);
5fecd9fd
AT
130 *state = REMOTE_NO_KEY_PRESSED;
131 goto unlock;
132 }
133 }
134
135 if (rc_state[1] != 0)
aa50ec2b 136 deb_rc("Unknown rc key %02x\n", rc_state[1]);
5fecd9fd
AT
137
138 *state = REMOTE_NO_KEY_PRESSED;
139
d3911eaa 140 unlock:
5fecd9fd
AT
141
142 return ret;
143}
144
145/* I2C */
fa94805d
MK
146static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
147 int num)
5fecd9fd
AT
148{
149 struct dvb_usb_device *d = i2c_get_adapdata(adap);
26247018 150 int i, j;
5fecd9fd
AT
151 int ret = 0;
152
d40860f8
TP
153 if (!num)
154 return -EINVAL;
155
5fecd9fd
AT
156 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
157 return -EAGAIN;
158
5fecd9fd 159 for (i = 0; i < num; i++) {
d3911eaa
MK
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. */
d40860f8
TP
167 ret = -ENOTSUPP;
168 goto unlock;
169 }
170 /* Send START & address/RW bit */
171 if (!(msg[i].flags & I2C_M_NOSTART)) {
d3911eaa
MK
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)
84ad7574 176 goto unlock;
d40860f8
TP
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++) {
d3911eaa
MK
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)
d40860f8 189 goto unlock;
84ad7574 190 }
26247018 191 } else {
d40860f8
TP
192 for (j = 0; j < msg[i].len; j++) {
193 /* Last byte of transaction? Then send STOP. */
d3911eaa
MK
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)
d40860f8
TP
200 goto unlock;
201 /* Should check for ack here too. */
26247018 202 }
5fecd9fd
AT
203 }
204 }
26247018 205 ret = num;
d40860f8 206
d3911eaa 207 unlock:
5fecd9fd
AT
208 mutex_unlock(&d->i2c_mutex);
209
210 return ret;
211}
212
213static u32 m9206_i2c_func(struct i2c_adapter *adapter)
214{
215 return I2C_FUNC_I2C;
216}
217
218static struct i2c_algorithm m9206_i2c_algo = {
219 .master_xfer = m9206_i2c_xfer,
220 .functionality = m9206_i2c_func,
221};
222
5afb7071 223/* pid filter */
d3911eaa
MK
224static int m9206_set_filter(struct dvb_usb_adapter *adap,
225 int type, int idx, int pid)
5fecd9fd
AT
226{
227 int ret = 0;
228
229 if (pid >= 0x8000)
230 return -EINVAL;
231
232 pid |= 0x8000;
233
d3911eaa
MK
234 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, pid,
235 (type << 8) | (idx * 4) )) != 0)
5fecd9fd
AT
236 return ret;
237
d3911eaa
MK
238 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, 0,
239 (type << 8) | (idx * 4) )) != 0)
5fecd9fd
AT
240 return ret;
241
242 return ret;
243}
244
e2adbecf 245static int m9206_update_filters(struct dvb_usb_adapter *adap)
5fecd9fd 246{
e2adbecf
AT
247 struct m9206_state *m = adap->dev->priv;
248 int enabled = m->filtering_enabled;
249 int i, ret = 0, filter = 0;
5fecd9fd 250
e2adbecf
AT
251 for (i = 0; i < M9206_MAX_FILTERS; i++)
252 if (m->filters[i] == 8192)
253 enabled = 0;
5fecd9fd 254
e2adbecf 255 /* Disable all filters */
26f48eaa 256 if ((ret = m9206_set_filter(adap, 0x81, 1, enabled)) != 0)
e2adbecf 257 return ret;
5fecd9fd 258
e2adbecf 259 for (i = 0; i < M9206_MAX_FILTERS; i++)
26f48eaa 260 if ((ret = m9206_set_filter(adap, 0x81, i + 2, 0)) != 0)
e2adbecf
AT
261 return ret;
262
26f48eaa 263 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x0)) != 0)
e2adbecf
AT
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
d3911eaa
MK
272 if ((ret = m9206_set_filter(adap, 0x81, filter + 2,
273 m->filters[i])) != 0)
e2adbecf
AT
274 return ret;
275
276 filter++;
277 }
5fecd9fd 278 }
e2adbecf 279
26f48eaa 280 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x02f5)) != 0)
e2adbecf 281 return ret;
5fecd9fd
AT
282
283 return ret;
284}
285
e2adbecf 286static int m9206_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
5fecd9fd 287{
e2adbecf 288 struct m9206_state *m = adap->dev->priv;
5fecd9fd 289
e2adbecf 290 m->filtering_enabled = onoff ? 1 : 0;
5fecd9fd 291
e2adbecf
AT
292 return m9206_update_filters(adap);
293}
5fecd9fd 294
d3911eaa
MK
295static int m9206_pid_filter(struct dvb_usb_adapter *adap,
296 int index, u16 pid, int onoff)
e2adbecf
AT
297{
298 struct m9206_state *m = adap->dev->priv;
5fecd9fd 299
e2adbecf 300 m->filters[index] = onoff ? pid : 0;
5fecd9fd 301
e2adbecf 302 return m9206_update_filters(adap);
5fecd9fd
AT
303}
304
fa94805d
MK
305static int m9206_firmware_download(struct usb_device *udev,
306 const struct firmware *fw)
5fecd9fd
AT
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
e2adbecf 314 if ((ret = m9206_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
5fecd9fd
AT
315 goto done;
316 deb_rc("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
317
e2adbecf 318 if ((ret = m9206_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
5fecd9fd
AT
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),
e2adbecf
AT
338 M9206_FW,
339 USB_TYPE_VENDOR | USB_DIR_OUT,
5fecd9fd
AT
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) {
59069e53 351 deb_rc("bad firmware file!\n");
5fecd9fd
AT
352 ret = -EINVAL;
353 goto done;
354 }
355 }
356
357 msleep(36);
358
359 /* m9206 will disconnect itself from the bus after this. */
e2adbecf 360 (void) m9206_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
5fecd9fd
AT
361 deb_rc("firmware uploaded!\n");
362
d3911eaa 363 done:
5fecd9fd
AT
364 kfree(buff);
365
366 return ret;
367}
368
e16c1f55 369/* Callbacks for DVB USB */
7d1d4e6c
AT
370static 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)
e16c1f55
MK
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
5afb7071 383/* demod configurations */
e16c1f55
MK
384static int megasky_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
409static struct mt352_config megasky_mt352_config = {
26247018 410 .demod_address = 0x0f,
e16c1f55
MK
411 .no_tuner = 1,
412 .demod_init = megasky_mt352_demod_init,
413};
414
d4ca23b1
PW
415static struct tda1004x_config digivox_tda10046_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
aa50ec2b
NA
427static struct tda1004x_config tvwalkertwin_0_tda10046_config = {
428 .demod_address = 0x08,
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
439static struct tda1004x_config tvwalkertwin_1_tda10046_config = {
440 .demod_address = 0x0b,
441 .invert = 0,
442 .invert_oclk = 0,
443 .ts_mode = TDA10046_TS_SERIAL,
444 .xtal_freq = TDA10046_XTAL_16M,
445 .if_freq = TDA10046_FREQ_045,
446 .agc_config = TDA10046_AGC_TDA827X,
447 .gpio_config = TDA10046_GPTRI,
448 .request_firmware = NULL, /* uses firmware EEPROM */
449};
450
5afb7071
MK
451/* tuner configurations */
452static struct qt1010_config megasky_qt1010_config = {
453 .i2c_address = 0x62
454};
455
456/* Callbacks for DVB USB */
457static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap)
458{
459 deb_rc("megasky_frontend_attach!\n");
460
461 if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config,
462 &adap->dev->i2c_adap)) == NULL)
463 return -EIO;
464
465 return 0;
466}
467
468static int digivox_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
469{
470 deb_rc("digivox_tda10046_frontend_attach!\n");
471
472 if ((adap->fe = dvb_attach(tda10046_attach, &digivox_tda10046_config,
473 &adap->dev->i2c_adap)) == NULL)
474 return -EIO;
475
476 return 0;
477}
478
479/* LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
480 * TDA10046 #0 is located at i2c address 0x08
481 * TDA10046 #1 is located at i2c address 0x0b
482 * TDA8275A #0 is located at i2c address 0x60
483 * TDA8275A #1 is located at i2c address 0x61
484 */
485
aa50ec2b
NA
486static int tvwalkertwin_0_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
487{
488 deb_rc("tvwalkertwin_0_tda10046_frontend_attach!\n");
489
d3911eaa
MK
490 if ((adap->fe = dvb_attach(tda10046_attach,
491 &tvwalkertwin_0_tda10046_config,
492 &adap->dev->i2c_adap)) == NULL)
aa50ec2b
NA
493 return -EIO;
494
d3911eaa
MK
495 deb_rc("Attached demod 0 at address %02x\n",
496 tvwalkertwin_0_tda10046_config.demod_address);
aa50ec2b
NA
497
498 return 0;
499}
500
501static int tvwalkertwin_1_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
502{
503 deb_rc("tvwalkertwin_1_tda10046_frontend_attach!\n");
504
d3911eaa
MK
505 if ((adap->fe = dvb_attach(tda10046_attach,
506 &tvwalkertwin_1_tda10046_config,
507 &adap->dev->i2c_adap)) == NULL)
aa50ec2b
NA
508 return -EIO;
509
d3911eaa
MK
510 deb_rc("Attached demod 1 at address %02x\n",
511 tvwalkertwin_1_tda10046_config.demod_address);
aa50ec2b
NA
512
513 return 0;
514}
515
5afb7071
MK
516static int megasky_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
517{
518 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap,
519 &megasky_qt1010_config) == NULL)
520 return -ENODEV;
521
522 return 0;
523}
524
525static int digivox_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
526{
527 if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap,
528 NULL) == NULL)
529 return -ENODEV;
530 return 0;
531}
532
aa50ec2b
NA
533static int tvwalkertwin_0_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
534{
535 int address = 0x60;
536
537 deb_rc("tvwalkertwin_0_tda8275_tuner_attach!\n");
538
539 if (dvb_attach(tda827x_attach, adap->fe, address, &adap->dev->i2c_adap,
540 NULL) == NULL)
541 return -ENODEV;
542
543 deb_rc("Attached tuner 0 at address %02x\n", address);
544
545 return 0;
546}
547
548static int tvwalkertwin_1_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
549{
550 int address = 0x61;
551
552 deb_rc("tvwalkertwin_1_tda8275_tuner_attach!\n");
553
554 if (dvb_attach(tda827x_attach, adap->fe, address, &adap->dev->i2c_adap,
555 NULL) == NULL)
556 return -ENODEV;
557
558 deb_rc("Attached tuner 1 at address %02x\n", address);
559
560 return 0;
561}
562
5afb7071
MK
563/* device-specific initialization */
564static struct m9206_inits megasky_rc_init [] = {
565 { M9206_RC_INIT2, 0xa8 },
566 { M9206_RC_INIT1, 0x51 },
567 { } /* terminating entry */
568};
569
aa50ec2b
NA
570static struct m9206_inits tvwalkertwin_rc_init [] = {
571 { M9206_RC_INIT2, 0x00 },
572 { M9206_RC_INIT1, 0xef },
573 { 0xff28, 0x00 },
574 { 0xff23, 0x00 },
575 { 0xff21, 0x30 },
576 { } /* terminating entry */
577};
578
5afb7071
MK
579/* ir keymaps */
580static struct dvb_usb_rc_key megasky_rc_keys [] = {
581 { 0x0, 0x12, KEY_POWER },
582 { 0x0, 0x1e, KEY_CYCLEWINDOWS }, /* min/max */
583 { 0x0, 0x02, KEY_CHANNELUP },
584 { 0x0, 0x05, KEY_CHANNELDOWN },
585 { 0x0, 0x03, KEY_VOLUMEUP },
586 { 0x0, 0x06, KEY_VOLUMEDOWN },
587 { 0x0, 0x04, KEY_MUTE },
588 { 0x0, 0x07, KEY_OK }, /* TS */
589 { 0x0, 0x08, KEY_STOP },
590 { 0x0, 0x09, KEY_MENU }, /* swap */
591 { 0x0, 0x0a, KEY_REWIND },
592 { 0x0, 0x1b, KEY_PAUSE },
593 { 0x0, 0x1f, KEY_FASTFORWARD },
594 { 0x0, 0x0c, KEY_RECORD },
595 { 0x0, 0x0d, KEY_CAMERA }, /* screenshot */
596 { 0x0, 0x0e, KEY_COFFEE }, /* "MTS" */
597};
598
599static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
600 { 0x0, 0x01, KEY_ZOOM }, /* Full Screen */
601 { 0x0, 0x02, KEY_CAMERA }, /* snapshot */
602 { 0x0, 0x03, KEY_MUTE },
603 { 0x0, 0x04, KEY_REWIND },
604 { 0x0, 0x05, KEY_PLAYPAUSE }, /* Play/Pause */
605 { 0x0, 0x06, KEY_FASTFORWARD },
606 { 0x0, 0x07, KEY_RECORD },
607 { 0x0, 0x08, KEY_STOP },
608 { 0x0, 0x09, KEY_TIME }, /* Timeshift */
609 { 0x0, 0x0c, KEY_COFFEE }, /* Recall */
610 { 0x0, 0x0e, KEY_CHANNELUP },
611 { 0x0, 0x12, KEY_POWER },
612 { 0x0, 0x15, KEY_MENU }, /* source */
613 { 0x0, 0x18, KEY_CYCLEWINDOWS }, /* TWIN PIP */
614 { 0x0, 0x1a, KEY_CHANNELDOWN },
615 { 0x0, 0x1b, KEY_VOLUMEDOWN },
616 { 0x0, 0x1e, KEY_VOLUMEUP },
617};
618
26f48eaa
MK
619/* DVB USB Driver stuff */
620static struct dvb_usb_device_properties megasky_properties;
d4ca23b1 621static struct dvb_usb_device_properties digivox_mini_ii_properties;
aa50ec2b 622static struct dvb_usb_device_properties tvwalkertwin_properties;
f8e0bd5d 623static struct dvb_usb_device_properties dposh_properties;
d3911eaa 624
fa94805d
MK
625static int m920x_probe(struct usb_interface *intf,
626 const struct usb_device_id *id)
26f48eaa
MK
627{
628 struct dvb_usb_device *d;
629 struct usb_host_interface *alt;
630 int ret;
aa50ec2b
NA
631 struct m9206_inits *rc_init_seq = NULL;
632 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
26f48eaa 633
aa50ec2b 634 deb_rc("Probing for m920x device at interface %d\n", bInterfaceNumber);
26f48eaa 635
aa50ec2b
NA
636 if (bInterfaceNumber == 0) {
637 /* Single-tuner device, or first interface on
638 * multi-tuner device
639 */
26f48eaa 640
aa50ec2b 641 if ((ret = dvb_usb_device_init(intf, &megasky_properties,
d3911eaa 642 THIS_MODULE, &d)) == 0) {
aa50ec2b
NA
643 rc_init_seq = megasky_rc_init;
644 goto found;
645 }
646
647 if ((ret = dvb_usb_device_init(intf,
d3911eaa
MK
648 &digivox_mini_ii_properties,
649 THIS_MODULE, &d)) == 0) {
aa50ec2b
NA
650 /* No remote control, so no rc_init_seq */
651 goto found;
652 }
653
654 /* This configures both tuners on the TV Walker Twin */
655 if ((ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
d3911eaa 656 THIS_MODULE, &d)) == 0) {
aa50ec2b
NA
657 rc_init_seq = tvwalkertwin_rc_init;
658 goto found;
659 }
660
d3911eaa
MK
661 if ((ret = dvb_usb_device_init(intf, &dposh_properties,
662 THIS_MODULE, &d)) == 0) {
f8e0bd5d
AT
663 /* Remote controller not supported yet. */
664 goto found;
665 }
666
aa50ec2b
NA
667 return ret;
668 } else {
669 /* Another interface on a multi-tuner device */
670
671 /* The LifeView TV Walker Twin gets here, but struct
672 * tvwalkertwin_properties already configured both
673 * tuners, so there is nothing for us to do here
674 */
675
676 return -ENODEV;
677 }
26f48eaa 678
480ac761
AT
679found:
680 alt = usb_altnum_to_altsetting(intf, 1);
681 if (alt == NULL) {
682 deb_rc("No alt found!\n");
683 return -ENODEV;
26f48eaa 684 }
480ac761
AT
685
686 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
687 alt->desc.bAlternateSetting);
688 if (ret < 0)
689 return ret;
690
aa50ec2b 691 if ((ret = m9206_init(d, rc_init_seq)) != 0)
480ac761
AT
692 return ret;
693
26f48eaa
MK
694 return ret;
695}
696
697static struct usb_device_id m920x_table [] = {
698 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
d4ca23b1
PW
699 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
700 USB_PID_MSI_DIGI_VOX_MINI_II) },
aa50ec2b
NA
701 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
702 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
703 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
704 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
f8e0bd5d
AT
705 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
706 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
26f48eaa
MK
707 { } /* Terminating entry */
708};
709MODULE_DEVICE_TABLE (usb, m920x_table);
710
01cb34db 711static struct dvb_usb_device_properties megasky_properties = {
758117c2 712 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1f61f3ba 713
5fecd9fd
AT
714 .usb_ctrl = DEVICE_SPECIFIC,
715 .firmware = "dvb-usb-megasky-02.fw",
716 .download_firmware = m9206_firmware_download,
717
e2adbecf 718 .rc_interval = 100,
5fecd9fd
AT
719 .rc_key_map = megasky_rc_keys,
720 .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys),
721 .rc_query = m9206_rc_query,
722
e2adbecf 723 .size_of_priv = sizeof(struct m9206_state),
5fecd9fd 724
7d1d4e6c 725 .identify_state = m920x_identify_state,
01cb34db
MK
726 .num_adapters = 1,
727 .adapter = {{
758117c2
MK
728 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
729 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
730
01cb34db
MK
731 .pid_filter_count = 8,
732 .pid_filter = m9206_pid_filter,
733 .pid_filter_ctrl = m9206_pid_filter_ctrl,
734
e16c1f55
MK
735 .frontend_attach = megasky_mt352_frontend_attach,
736 .tuner_attach = megasky_qt1010_tuner_attach,
01cb34db
MK
737
738 .stream = {
739 .type = USB_BULK,
740 .count = 8,
741 .endpoint = 0x81,
742 .u = {
743 .bulk = {
744 .buffersize = 512,
745 }
746 }
747 },
748 }},
5fecd9fd
AT
749 .i2c_algo = &m9206_i2c_algo,
750
5fecd9fd
AT
751 .num_device_descs = 1,
752 .devices = {
753 { "MSI Mega Sky 580 DVB-T USB2.0",
baa2ed09 754 { &m920x_table[0], NULL },
5fecd9fd 755 { NULL },
d4ca23b1
PW
756 }
757 }
758};
759
760static struct dvb_usb_device_properties digivox_mini_ii_properties = {
761 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
762
763 .usb_ctrl = DEVICE_SPECIFIC,
764 .firmware = "dvb-usb-digivox-02.fw",
765 .download_firmware = m9206_firmware_download,
766
767 .size_of_priv = sizeof(struct m9206_state),
768
769 .identify_state = m920x_identify_state,
770 .num_adapters = 1,
771 .adapter = {{
772 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
d3911eaa 773 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
d4ca23b1
PW
774
775 .pid_filter_count = 8,
776 .pid_filter = m9206_pid_filter,
777 .pid_filter_ctrl = m9206_pid_filter_ctrl,
778
779 .frontend_attach = digivox_tda10046_frontend_attach,
780 .tuner_attach = digivox_tda8275_tuner_attach,
781
782 .stream = {
783 .type = USB_BULK,
784 .count = 8,
785 .endpoint = 0x81,
786 .u = {
787 .bulk = {
788 .buffersize = 0x4000,
789 }
790 }
791 },
792 }},
793 .i2c_algo = &m9206_i2c_algo,
794
795 .num_device_descs = 1,
796 .devices = {
797 { "MSI DIGI VOX mini II DVB-T USB2.0",
798 { &m920x_table[1], NULL },
799 { NULL },
5fecd9fd 800 },
5fecd9fd
AT
801 }
802};
803
aa50ec2b 804/* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net> */
aa50ec2b
NA
805static struct dvb_usb_device_properties tvwalkertwin_properties = {
806 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
807
808 .usb_ctrl = DEVICE_SPECIFIC,
809 .firmware = "dvb-usb-tvwalkert.fw",
810 .download_firmware = m9206_firmware_download,
811
812 .rc_interval = 100,
813 .rc_key_map = tvwalkertwin_rc_keys,
814 .rc_key_map_size = ARRAY_SIZE(tvwalkertwin_rc_keys),
815 .rc_query = m9206_rc_query,
816
817 .size_of_priv = sizeof(struct m9206_state),
818
819 .identify_state = m920x_identify_state,
820 .num_adapters = 2,
d3911eaa
MK
821 .adapter = {{
822 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
823 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
824
825 .pid_filter_count = 8,
826 .pid_filter = m9206_pid_filter,
827 .pid_filter_ctrl = m9206_pid_filter_ctrl,
828
829 .frontend_attach = tvwalkertwin_0_tda10046_frontend_attach,
830 .tuner_attach = tvwalkertwin_0_tda8275_tuner_attach,
831
832 .stream = {
833 .type = USB_BULK,
834 .count = 8,
835 .endpoint = 0x81,
836 .u = {
837 .bulk = {
838 .buffersize = 512,
839 }
840 }
841 }},{
842 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
843 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
844
845 .pid_filter_count = 8,
846 .pid_filter = m9206_pid_filter,
847 .pid_filter_ctrl = m9206_pid_filter_ctrl,
848
849 .frontend_attach = tvwalkertwin_1_tda10046_frontend_attach,
850 .tuner_attach = tvwalkertwin_1_tda8275_tuner_attach,
851
852 .stream = {
853 .type = USB_BULK,
854 .count = 8,
855 .endpoint = 0x82,
856 .u = {
857 .bulk = {
858 .buffersize = 512,
859 }
860 }
aa50ec2b 861 },
d3911eaa 862 }},
aa50ec2b
NA
863 .i2c_algo = &m9206_i2c_algo,
864
865 .num_device_descs = 1,
866 .devices = {
867 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
868 .cold_ids = { &m920x_table[2], NULL },
869 .warm_ids = { &m920x_table[3], NULL },
870 },
871 }
872};
873
f8e0bd5d
AT
874static struct dvb_usb_device_properties dposh_properties = {
875 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
876
877 .usb_ctrl = DEVICE_SPECIFIC,
878 .firmware = "dvb-usb-dposh-01.fw",
879 .download_firmware = m9206_firmware_download,
880
f8e0bd5d
AT
881 .size_of_priv = sizeof(struct m9206_state),
882
883 .identify_state = m920x_identify_state,
884 .num_adapters = 1,
885 .adapter = {{
d3911eaa
MK
886 /* Hardware pid filters don't work with this device/firmware */
887
888 .frontend_attach = megasky_mt352_frontend_attach,
889 .tuner_attach = megasky_qt1010_tuner_attach,
890
891 .stream = {
892 .type = USB_BULK,
893 .count = 8,
894 .endpoint = 0x81,
895 .u = {
896 .bulk = {
897 .buffersize = 512,
898 }
899 }
900 },
901 }},
f8e0bd5d
AT
902 .i2c_algo = &m9206_i2c_algo,
903
904 .num_device_descs = 1,
905 .devices = {
906 { .name = "Dposh DVB-T USB2.0",
907 .cold_ids = { &m920x_table[4], NULL },
908 .warm_ids = { &m920x_table[5], NULL },
909 },
910 }
911};
912
baa2ed09
MK
913static struct usb_driver m920x_driver = {
914 .name = "dvb_usb_m920x",
2a2bfa7d 915 .probe = m920x_probe,
5fecd9fd 916 .disconnect = dvb_usb_device_exit,
baa2ed09 917 .id_table = m920x_table,
5fecd9fd
AT
918};
919
920/* module stuff */
baa2ed09 921static int __init m920x_module_init(void)
5fecd9fd
AT
922{
923 int ret;
924
baa2ed09 925 if ((ret = usb_register(&m920x_driver))) {
5fecd9fd
AT
926 err("usb_register failed. Error number %d", ret);
927 return ret;
928 }
929
930 return 0;
931}
932
baa2ed09 933static void __exit m920x_module_exit(void)
5fecd9fd
AT
934{
935 /* deregister this driver from the USB subsystem */
baa2ed09 936 usb_deregister(&m920x_driver);
5fecd9fd
AT
937}
938
baa2ed09
MK
939module_init (m920x_module_init);
940module_exit (m920x_module_exit);
5fecd9fd
AT
941
942MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
aa50ec2b 943MODULE_DESCRIPTION("DVB Driver for ULI M920x");
5fecd9fd
AT
944MODULE_VERSION("0.1");
945MODULE_LICENSE("GPL");
ce9c2750
MK
946
947/*
948 * Local variables:
949 * c-basic-offset: 8
950 */
This page took 0.117053 seconds and 5 git commands to generate.