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