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