powerpc/mm/4k: don't allocate larger pmd page table for 4k
[linux/fpc-iii.git] / drivers / media / usb / dvb-usb / m920x.c
blob70672e1e5ec7d56569c10aa97247a6b009a1bcbd
1 /* DVB USB compliant linux driver for MSI Mega Sky 580 DVB-T USB2.0 receiver
3 * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org)
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.
9 * see Documentation/dvb/README.dvb-usb for more information
12 #include "m920x.h"
14 #include "mt352.h"
15 #include "mt352_priv.h"
16 #include "qt1010.h"
17 #include "tda1004x.h"
18 #include "tda827x.h"
19 #include "mt2060.h"
21 #include <media/tuner.h>
22 #include "tuner-simple.h"
23 #include <asm/unaligned.h>
25 /* debug */
26 static int dvb_usb_m920x_debug;
27 module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
28 MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
30 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
32 static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid);
34 static inline int m920x_read(struct usb_device *udev, u8 request, u16 value,
35 u16 index, void *data, int size)
37 int ret;
39 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
40 request, USB_TYPE_VENDOR | USB_DIR_IN,
41 value, index, data, size, 2000);
42 if (ret < 0) {
43 printk(KERN_INFO "m920x_read = error: %d\n", ret);
44 return ret;
47 if (ret != size) {
48 deb("m920x_read = no data\n");
49 return -EIO;
52 return 0;
55 static inline int m920x_write(struct usb_device *udev, u8 request,
56 u16 value, u16 index)
58 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), request,
59 USB_TYPE_VENDOR | USB_DIR_OUT, value, index,
60 NULL, 0, 2000);
63 static inline int m920x_write_seq(struct usb_device *udev, u8 request,
64 struct m920x_inits *seq)
66 int ret;
67 do {
68 ret = m920x_write(udev, request, seq->data, seq->address);
69 if (ret != 0)
70 return ret;
72 seq++;
73 } while (seq->address);
75 return 0;
78 static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
80 int ret, i, epi, flags = 0;
81 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
83 /* Remote controller init. */
84 if (d->props.rc.legacy.rc_query || d->props.rc.core.rc_query) {
85 deb("Initialising remote control\n");
86 ret = m920x_write_seq(d->udev, M9206_CORE, rc_seq);
87 if (ret != 0) {
88 deb("Initialising remote control failed\n");
89 return ret;
92 deb("Initialising remote control success\n");
95 for (i = 0; i < d->props.num_adapters; i++)
96 flags |= d->adapter[i].props.fe[0].caps;
98 /* Some devices(Dposh) might crash if we attempt touch at all. */
99 if (flags & DVB_USB_ADAP_HAS_PID_FILTER) {
100 for (i = 0; i < d->props.num_adapters; i++) {
101 epi = d->adapter[i].props.fe[0].stream.endpoint - 0x81;
103 if (epi < 0 || epi >= M9206_MAX_ADAPTERS) {
104 printk(KERN_INFO "m920x: Unexpected adapter endpoint!\n");
105 return -EINVAL;
108 adap_enabled[epi] = 1;
111 for (i = 0; i < M9206_MAX_ADAPTERS; i++) {
112 if (adap_enabled[i])
113 continue;
115 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x0)) != 0)
116 return ret;
118 if ((ret = m920x_set_filter(d, 0x81 + i, 0, 0x02f5)) != 0)
119 return ret;
123 return 0;
126 static int m920x_init_ep(struct usb_interface *intf)
128 struct usb_device *udev = interface_to_usbdev(intf);
129 struct usb_host_interface *alt;
131 if ((alt = usb_altnum_to_altsetting(intf, 1)) == NULL) {
132 deb("No alt found!\n");
133 return -ENODEV;
136 return usb_set_interface(udev, alt->desc.bInterfaceNumber,
137 alt->desc.bAlternateSetting);
140 static inline void m920x_parse_rc_state(struct dvb_usb_device *d, u8 rc_state,
141 int *state)
143 struct m920x_state *m = d->priv;
145 switch (rc_state) {
146 case 0x80:
147 *state = REMOTE_NO_KEY_PRESSED;
148 break;
150 case 0x88: /* framing error or "invalid code" */
151 case 0x99:
152 case 0xc0:
153 case 0xd8:
154 *state = REMOTE_NO_KEY_PRESSED;
155 m->rep_count = 0;
156 break;
158 case 0x93:
159 case 0x92:
160 case 0x83: /* pinnacle PCTV310e */
161 case 0x82:
162 m->rep_count = 0;
163 *state = REMOTE_KEY_PRESSED;
164 break;
166 case 0x91:
167 case 0x81: /* pinnacle PCTV310e */
168 /* prevent immediate auto-repeat */
169 if (++m->rep_count > 2)
170 *state = REMOTE_KEY_REPEAT;
171 else
172 *state = REMOTE_NO_KEY_PRESSED;
173 break;
175 default:
176 deb("Unexpected rc state %02x\n", rc_state);
177 *state = REMOTE_NO_KEY_PRESSED;
178 break;
182 static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
184 int i, ret = 0;
185 u8 *rc_state;
187 rc_state = kmalloc(2, GFP_KERNEL);
188 if (!rc_state)
189 return -ENOMEM;
191 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE,
192 rc_state, 1);
193 if (ret != 0)
194 goto out;
196 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY,
197 rc_state + 1, 1);
198 if (ret != 0)
199 goto out;
201 m920x_parse_rc_state(d, rc_state[0], state);
203 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
204 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
205 *event = d->props.rc.legacy.rc_map_table[i].keycode;
206 goto out;
209 if (rc_state[1] != 0)
210 deb("Unknown rc key %02x\n", rc_state[1]);
212 *state = REMOTE_NO_KEY_PRESSED;
214 out:
215 kfree(rc_state);
216 return ret;
219 static int m920x_rc_core_query(struct dvb_usb_device *d)
221 int ret = 0;
222 u8 *rc_state;
223 int state;
225 rc_state = kmalloc(2, GFP_KERNEL);
226 if (!rc_state)
227 return -ENOMEM;
229 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, &rc_state[0], 1)) != 0)
230 goto out;
232 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, &rc_state[1], 1)) != 0)
233 goto out;
235 deb("state=0x%02x keycode=0x%02x\n", rc_state[0], rc_state[1]);
237 m920x_parse_rc_state(d, rc_state[0], &state);
239 if (state == REMOTE_NO_KEY_PRESSED)
240 rc_keyup(d->rc_dev);
241 else if (state == REMOTE_KEY_REPEAT)
242 rc_repeat(d->rc_dev);
243 else
244 rc_keydown(d->rc_dev, RC_TYPE_UNKNOWN, rc_state[1], 0);
246 out:
247 kfree(rc_state);
248 return ret;
251 /* I2C */
252 static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
254 struct dvb_usb_device *d = i2c_get_adapdata(adap);
255 int i, j;
256 int ret = 0;
258 if (!num)
259 return -EINVAL;
261 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
262 return -EAGAIN;
264 for (i = 0; i < num; i++) {
265 if (msg[i].flags & (I2C_M_NO_RD_ACK | I2C_M_IGNORE_NAK | I2C_M_TEN) || msg[i].len == 0) {
266 /* For a 0 byte message, I think sending the address
267 * to index 0x80|0x40 would be the correct thing to
268 * do. However, zero byte messages are only used for
269 * probing, and since we don't know how to get the
270 * slave's ack, we can't probe. */
271 ret = -ENOTSUPP;
272 goto unlock;
274 /* Send START & address/RW bit */
275 if (!(msg[i].flags & I2C_M_NOSTART)) {
276 if ((ret = m920x_write(d->udev, M9206_I2C,
277 (msg[i].addr << 1) |
278 (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
279 goto unlock;
280 /* Should check for ack here, if we knew how. */
282 if (msg[i].flags & I2C_M_RD) {
283 for (j = 0; j < msg[i].len; j++) {
284 /* Last byte of transaction?
285 * Send STOP, otherwise send ACK. */
286 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
288 if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
289 0x20 | stop,
290 &msg[i].buf[j], 1)) != 0)
291 goto unlock;
293 } else {
294 for (j = 0; j < msg[i].len; j++) {
295 /* Last byte of transaction? Then send STOP. */
296 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
298 if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
299 goto unlock;
300 /* Should check for ack here too. */
304 ret = num;
306 unlock:
307 mutex_unlock(&d->i2c_mutex);
309 return ret;
312 static u32 m920x_i2c_func(struct i2c_adapter *adapter)
314 return I2C_FUNC_I2C;
317 static struct i2c_algorithm m920x_i2c_algo = {
318 .master_xfer = m920x_i2c_xfer,
319 .functionality = m920x_i2c_func,
322 /* pid filter */
323 static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid)
325 int ret = 0;
327 if (pid >= 0x8000)
328 return -EINVAL;
330 pid |= 0x8000;
332 if ((ret = m920x_write(d->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
333 return ret;
335 if ((ret = m920x_write(d->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
336 return ret;
338 return ret;
341 static int m920x_update_filters(struct dvb_usb_adapter *adap)
343 struct m920x_state *m = adap->dev->priv;
344 int enabled = m->filtering_enabled[adap->id];
345 int i, ret = 0, filter = 0;
346 int ep = adap->props.fe[0].stream.endpoint;
348 for (i = 0; i < M9206_MAX_FILTERS; i++)
349 if (m->filters[adap->id][i] == 8192)
350 enabled = 0;
352 /* Disable all filters */
353 if ((ret = m920x_set_filter(adap->dev, ep, 1, enabled)) != 0)
354 return ret;
356 for (i = 0; i < M9206_MAX_FILTERS; i++)
357 if ((ret = m920x_set_filter(adap->dev, ep, i + 2, 0)) != 0)
358 return ret;
360 /* Set */
361 if (enabled) {
362 for (i = 0; i < M9206_MAX_FILTERS; i++) {
363 if (m->filters[adap->id][i] == 0)
364 continue;
366 if ((ret = m920x_set_filter(adap->dev, ep, filter + 2, m->filters[adap->id][i])) != 0)
367 return ret;
369 filter++;
373 return ret;
376 static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
378 struct m920x_state *m = adap->dev->priv;
380 m->filtering_enabled[adap->id] = onoff ? 1 : 0;
382 return m920x_update_filters(adap);
385 static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
387 struct m920x_state *m = adap->dev->priv;
389 m->filters[adap->id][index] = onoff ? pid : 0;
391 return m920x_update_filters(adap);
394 static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
396 u16 value, index, size;
397 u8 *read, *buff;
398 int i, pass, ret = 0;
400 buff = kmalloc(65536, GFP_KERNEL);
401 if (buff == NULL)
402 return -ENOMEM;
404 read = kmalloc(4, GFP_KERNEL);
405 if (!read) {
406 kfree(buff);
407 return -ENOMEM;
410 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
411 goto done;
412 deb("%*ph\n", 4, read);
414 if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
415 goto done;
416 deb("%x\n", read[0]);
418 for (pass = 0; pass < 2; pass++) {
419 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
420 value = get_unaligned_le16(fw->data + i);
421 i += sizeof(u16);
423 index = get_unaligned_le16(fw->data + i);
424 i += sizeof(u16);
426 size = get_unaligned_le16(fw->data + i);
427 i += sizeof(u16);
429 if (pass == 1) {
430 /* Will stall if using fw->data ... */
431 memcpy(buff, fw->data + i, size);
433 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
434 M9206_FW,
435 USB_TYPE_VENDOR | USB_DIR_OUT,
436 value, index, buff, size, 20);
437 if (ret != size) {
438 deb("error while uploading fw!\n");
439 ret = -EIO;
440 goto done;
442 msleep(3);
444 i += size;
446 if (i != fw->size) {
447 deb("bad firmware file!\n");
448 ret = -EINVAL;
449 goto done;
453 msleep(36);
455 /* m920x will disconnect itself from the bus after this. */
456 (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
457 deb("firmware uploaded!\n");
459 done:
460 kfree(read);
461 kfree(buff);
463 return ret;
466 /* Callbacks for DVB USB */
467 static int m920x_identify_state(struct usb_device *udev,
468 struct dvb_usb_device_properties *props,
469 struct dvb_usb_device_description **desc,
470 int *cold)
472 struct usb_host_interface *alt;
474 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
475 *cold = (alt == NULL) ? 1 : 0;
477 return 0;
480 /* demod configurations */
481 static int m920x_mt352_demod_init(struct dvb_frontend *fe)
483 int ret;
484 u8 config[] = { CONFIG, 0x3d };
485 u8 clock[] = { CLOCK_CTL, 0x30 };
486 u8 reset[] = { RESET, 0x80 };
487 u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
488 u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
489 u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
490 u8 unk1[] = { 0x93, 0x1a };
491 u8 unk2[] = { 0xb5, 0x7a };
493 deb("Demod init!\n");
495 if ((ret = mt352_write(fe, config, ARRAY_SIZE(config))) != 0)
496 return ret;
497 if ((ret = mt352_write(fe, clock, ARRAY_SIZE(clock))) != 0)
498 return ret;
499 if ((ret = mt352_write(fe, reset, ARRAY_SIZE(reset))) != 0)
500 return ret;
501 if ((ret = mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl))) != 0)
502 return ret;
503 if ((ret = mt352_write(fe, agc, ARRAY_SIZE(agc))) != 0)
504 return ret;
505 if ((ret = mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc))) != 0)
506 return ret;
507 if ((ret = mt352_write(fe, unk1, ARRAY_SIZE(unk1))) != 0)
508 return ret;
509 if ((ret = mt352_write(fe, unk2, ARRAY_SIZE(unk2))) != 0)
510 return ret;
512 return 0;
515 static struct mt352_config m920x_mt352_config = {
516 .demod_address = 0x0f,
517 .no_tuner = 1,
518 .demod_init = m920x_mt352_demod_init,
521 static struct tda1004x_config m920x_tda10046_08_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,
533 static struct tda1004x_config m920x_tda10046_0b_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 */
545 /* tuner configurations */
546 static struct qt1010_config m920x_qt1010_config = {
547 .i2c_address = 0x62
550 static struct mt2060_config m920x_mt2060_config = {
551 .i2c_address = 0x60, /* 0xc0 */
552 .clock_out = 0,
556 /* Callbacks for DVB USB */
557 static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
559 deb("%s\n",__func__);
561 adap->fe_adap[0].fe = dvb_attach(mt352_attach,
562 &m920x_mt352_config,
563 &adap->dev->i2c_adap);
564 if ((adap->fe_adap[0].fe) == NULL)
565 return -EIO;
567 return 0;
570 static int m920x_mt352_frontend_attach_vp7049(struct dvb_usb_adapter *adap)
572 struct m920x_inits vp7049_fe_init_seq[] = {
573 /* XXX without these commands the frontend cannot be detected,
574 * they must be sent BEFORE the frontend is attached */
575 { 0xff28, 0x00 },
576 { 0xff23, 0x00 },
577 { 0xff28, 0x00 },
578 { 0xff23, 0x00 },
579 { 0xff21, 0x20 },
580 { 0xff21, 0x60 },
581 { 0xff28, 0x00 },
582 { 0xff22, 0x00 },
583 { 0xff20, 0x30 },
584 { 0xff20, 0x20 },
585 { 0xff20, 0x30 },
586 { } /* terminating entry */
588 int ret;
590 deb("%s\n", __func__);
592 ret = m920x_write_seq(adap->dev->udev, M9206_CORE, vp7049_fe_init_seq);
593 if (ret != 0) {
594 deb("Initialization of vp7049 frontend failed.");
595 return ret;
598 return m920x_mt352_frontend_attach(adap);
601 static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
603 deb("%s\n",__func__);
605 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
606 &m920x_tda10046_08_config,
607 &adap->dev->i2c_adap);
608 if ((adap->fe_adap[0].fe) == NULL)
609 return -EIO;
611 return 0;
614 static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
616 deb("%s\n",__func__);
618 adap->fe_adap[0].fe = dvb_attach(tda10046_attach,
619 &m920x_tda10046_0b_config,
620 &adap->dev->i2c_adap);
621 if ((adap->fe_adap[0].fe) == NULL)
622 return -EIO;
624 return 0;
627 static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
629 deb("%s\n",__func__);
631 if (dvb_attach(qt1010_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
632 return -ENODEV;
634 return 0;
637 static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
639 deb("%s\n",__func__);
641 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
642 return -ENODEV;
644 return 0;
647 static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
649 deb("%s\n",__func__);
651 if (dvb_attach(tda827x_attach, adap->fe_adap[0].fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
652 return -ENODEV;
654 return 0;
657 static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
659 dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
660 &adap->dev->i2c_adap, 0x61,
661 TUNER_PHILIPS_FMD1216ME_MK3);
662 return 0;
665 static int m920x_mt2060_tuner_attach(struct dvb_usb_adapter *adap)
667 deb("%s\n", __func__);
669 if (dvb_attach(mt2060_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
670 &m920x_mt2060_config, 1220) == NULL)
671 return -ENODEV;
673 return 0;
677 /* device-specific initialization */
678 static struct m920x_inits megasky_rc_init [] = {
679 { M9206_RC_INIT2, 0xa8 },
680 { M9206_RC_INIT1, 0x51 },
681 { } /* terminating entry */
684 static struct m920x_inits tvwalkertwin_rc_init [] = {
685 { M9206_RC_INIT2, 0x00 },
686 { M9206_RC_INIT1, 0xef },
687 { 0xff28, 0x00 },
688 { 0xff23, 0x00 },
689 { 0xff21, 0x30 },
690 { } /* terminating entry */
693 static struct m920x_inits pinnacle310e_init[] = {
694 /* without these the tuner doesn't work */
695 { 0xff20, 0x9b },
696 { 0xff22, 0x70 },
698 /* rc settings */
699 { 0xff50, 0x80 },
700 { M9206_RC_INIT1, 0x00 },
701 { M9206_RC_INIT2, 0xff },
702 { } /* terminating entry */
705 static struct m920x_inits vp7049_rc_init[] = {
706 { 0xff28, 0x00 },
707 { 0xff23, 0x00 },
708 { 0xff21, 0x70 },
709 { M9206_RC_INIT2, 0x00 },
710 { M9206_RC_INIT1, 0xff },
711 { } /* terminating entry */
714 /* ir keymaps */
715 static struct rc_map_table rc_map_megasky_table[] = {
716 { 0x0012, KEY_POWER },
717 { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
718 { 0x0002, KEY_CHANNELUP },
719 { 0x0005, KEY_CHANNELDOWN },
720 { 0x0003, KEY_VOLUMEUP },
721 { 0x0006, KEY_VOLUMEDOWN },
722 { 0x0004, KEY_MUTE },
723 { 0x0007, KEY_OK }, /* TS */
724 { 0x0008, KEY_STOP },
725 { 0x0009, KEY_MENU }, /* swap */
726 { 0x000a, KEY_REWIND },
727 { 0x001b, KEY_PAUSE },
728 { 0x001f, KEY_FASTFORWARD },
729 { 0x000c, KEY_RECORD },
730 { 0x000d, KEY_CAMERA }, /* screenshot */
731 { 0x000e, KEY_COFFEE }, /* "MTS" */
734 static struct rc_map_table rc_map_tvwalkertwin_table[] = {
735 { 0x0001, KEY_ZOOM }, /* Full Screen */
736 { 0x0002, KEY_CAMERA }, /* snapshot */
737 { 0x0003, KEY_MUTE },
738 { 0x0004, KEY_REWIND },
739 { 0x0005, KEY_PLAYPAUSE }, /* Play/Pause */
740 { 0x0006, KEY_FASTFORWARD },
741 { 0x0007, KEY_RECORD },
742 { 0x0008, KEY_STOP },
743 { 0x0009, KEY_TIME }, /* Timeshift */
744 { 0x000c, KEY_COFFEE }, /* Recall */
745 { 0x000e, KEY_CHANNELUP },
746 { 0x0012, KEY_POWER },
747 { 0x0015, KEY_MENU }, /* source */
748 { 0x0018, KEY_CYCLEWINDOWS }, /* TWIN PIP */
749 { 0x001a, KEY_CHANNELDOWN },
750 { 0x001b, KEY_VOLUMEDOWN },
751 { 0x001e, KEY_VOLUMEUP },
754 static struct rc_map_table rc_map_pinnacle310e_table[] = {
755 { 0x16, KEY_POWER },
756 { 0x17, KEY_FAVORITES },
757 { 0x0f, KEY_TEXT },
758 { 0x48, KEY_PROGRAM }, /* preview */
759 { 0x1c, KEY_EPG },
760 { 0x04, KEY_LIST }, /* record list */
761 { 0x03, KEY_1 },
762 { 0x01, KEY_2 },
763 { 0x06, KEY_3 },
764 { 0x09, KEY_4 },
765 { 0x1d, KEY_5 },
766 { 0x1f, KEY_6 },
767 { 0x0d, KEY_7 },
768 { 0x19, KEY_8 },
769 { 0x1b, KEY_9 },
770 { 0x15, KEY_0 },
771 { 0x0c, KEY_CANCEL },
772 { 0x4a, KEY_CLEAR },
773 { 0x13, KEY_BACK },
774 { 0x00, KEY_TAB },
775 { 0x4b, KEY_UP },
776 { 0x4e, KEY_LEFT },
777 { 0x52, KEY_RIGHT },
778 { 0x51, KEY_DOWN },
779 { 0x4f, KEY_ENTER }, /* could also be KEY_OK */
780 { 0x1e, KEY_VOLUMEUP },
781 { 0x0a, KEY_VOLUMEDOWN },
782 { 0x05, KEY_CHANNELUP },
783 { 0x02, KEY_CHANNELDOWN },
784 { 0x11, KEY_RECORD },
785 { 0x14, KEY_PLAY },
786 { 0x4c, KEY_PAUSE },
787 { 0x1a, KEY_STOP },
788 { 0x40, KEY_REWIND },
789 { 0x12, KEY_FASTFORWARD },
790 { 0x41, KEY_PREVIOUSSONG }, /* Replay */
791 { 0x42, KEY_NEXTSONG }, /* Skip */
792 { 0x54, KEY_CAMERA }, /* Capture */
793 /* { 0x50, KEY_SAP }, */ /* Sap */
794 { 0x47, KEY_CYCLEWINDOWS }, /* Pip */
795 { 0x4d, KEY_SCREEN }, /* FullScreen */
796 { 0x08, KEY_SUBTITLE },
797 { 0x0e, KEY_MUTE },
798 /* { 0x49, KEY_LR }, */ /* L/R */
799 { 0x07, KEY_SLEEP }, /* Hibernate */
800 { 0x08, KEY_VIDEO }, /* A/V */
801 { 0x0e, KEY_MENU }, /* Recall */
802 { 0x45, KEY_ZOOMIN },
803 { 0x46, KEY_ZOOMOUT },
804 { 0x18, KEY_RED }, /* Red */
805 { 0x53, KEY_GREEN }, /* Green */
806 { 0x5e, KEY_YELLOW }, /* Yellow */
807 { 0x5f, KEY_BLUE }, /* Blue */
810 /* DVB USB Driver stuff */
811 static struct dvb_usb_device_properties megasky_properties;
812 static struct dvb_usb_device_properties digivox_mini_ii_properties;
813 static struct dvb_usb_device_properties tvwalkertwin_properties;
814 static struct dvb_usb_device_properties dposh_properties;
815 static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
816 static struct dvb_usb_device_properties vp7049_properties;
818 static int m920x_probe(struct usb_interface *intf,
819 const struct usb_device_id *id)
821 struct dvb_usb_device *d = NULL;
822 int ret;
823 struct m920x_inits *rc_init_seq = NULL;
824 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
826 deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
828 if (bInterfaceNumber == 0) {
829 /* Single-tuner device, or first interface on
830 * multi-tuner device
833 ret = dvb_usb_device_init(intf, &megasky_properties,
834 THIS_MODULE, &d, adapter_nr);
835 if (ret == 0) {
836 rc_init_seq = megasky_rc_init;
837 goto found;
840 ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
841 THIS_MODULE, &d, adapter_nr);
842 if (ret == 0) {
843 /* No remote control, so no rc_init_seq */
844 goto found;
847 /* This configures both tuners on the TV Walker Twin */
848 ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
849 THIS_MODULE, &d, adapter_nr);
850 if (ret == 0) {
851 rc_init_seq = tvwalkertwin_rc_init;
852 goto found;
855 ret = dvb_usb_device_init(intf, &dposh_properties,
856 THIS_MODULE, &d, adapter_nr);
857 if (ret == 0) {
858 /* Remote controller not supported yet. */
859 goto found;
862 ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties,
863 THIS_MODULE, &d, adapter_nr);
864 if (ret == 0) {
865 rc_init_seq = pinnacle310e_init;
866 goto found;
869 ret = dvb_usb_device_init(intf, &vp7049_properties,
870 THIS_MODULE, &d, adapter_nr);
871 if (ret == 0) {
872 rc_init_seq = vp7049_rc_init;
873 goto found;
876 return ret;
877 } else {
878 /* Another interface on a multi-tuner device */
880 /* The LifeView TV Walker Twin gets here, but struct
881 * tvwalkertwin_properties already configured both
882 * tuners, so there is nothing for us to do here
886 found:
887 if ((ret = m920x_init_ep(intf)) < 0)
888 return ret;
890 if (d && (ret = m920x_init(d, rc_init_seq)) != 0)
891 return ret;
893 return ret;
896 static struct usb_device_id m920x_table [] = {
897 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
898 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
899 USB_PID_MSI_DIGI_VOX_MINI_II) },
900 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
901 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
902 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
903 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
904 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
905 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
906 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) },
907 { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_TWINHAN_VP7049) },
908 { } /* Terminating entry */
910 MODULE_DEVICE_TABLE (usb, m920x_table);
912 static struct dvb_usb_device_properties megasky_properties = {
913 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
915 .usb_ctrl = DEVICE_SPECIFIC,
916 .firmware = "dvb-usb-megasky-02.fw",
917 .download_firmware = m920x_firmware_download,
919 .rc.legacy = {
920 .rc_interval = 100,
921 .rc_map_table = rc_map_megasky_table,
922 .rc_map_size = ARRAY_SIZE(rc_map_megasky_table),
923 .rc_query = m920x_rc_query,
926 .size_of_priv = sizeof(struct m920x_state),
928 .identify_state = m920x_identify_state,
929 .num_adapters = 1,
930 .adapter = {{
931 .num_frontends = 1,
932 .fe = {{
934 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
935 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
937 .pid_filter_count = 8,
938 .pid_filter = m920x_pid_filter,
939 .pid_filter_ctrl = m920x_pid_filter_ctrl,
941 .frontend_attach = m920x_mt352_frontend_attach,
942 .tuner_attach = m920x_qt1010_tuner_attach,
944 .stream = {
945 .type = USB_BULK,
946 .count = 8,
947 .endpoint = 0x81,
948 .u = {
949 .bulk = {
950 .buffersize = 512,
956 .i2c_algo = &m920x_i2c_algo,
958 .num_device_descs = 1,
959 .devices = {
960 { "MSI Mega Sky 580 DVB-T USB2.0",
961 { &m920x_table[0], NULL },
962 { NULL },
967 static struct dvb_usb_device_properties digivox_mini_ii_properties = {
968 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
970 .usb_ctrl = DEVICE_SPECIFIC,
971 .firmware = "dvb-usb-digivox-02.fw",
972 .download_firmware = m920x_firmware_download,
974 .size_of_priv = sizeof(struct m920x_state),
976 .identify_state = m920x_identify_state,
977 .num_adapters = 1,
978 .adapter = {{
979 .num_frontends = 1,
980 .fe = {{
982 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
983 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
985 .pid_filter_count = 8,
986 .pid_filter = m920x_pid_filter,
987 .pid_filter_ctrl = m920x_pid_filter_ctrl,
989 .frontend_attach = m920x_tda10046_08_frontend_attach,
990 .tuner_attach = m920x_tda8275_60_tuner_attach,
992 .stream = {
993 .type = USB_BULK,
994 .count = 8,
995 .endpoint = 0x81,
996 .u = {
997 .bulk = {
998 .buffersize = 0x4000,
1004 .i2c_algo = &m920x_i2c_algo,
1006 .num_device_descs = 1,
1007 .devices = {
1008 { "MSI DIGI VOX mini II DVB-T USB2.0",
1009 { &m920x_table[1], NULL },
1010 { NULL },
1015 /* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
1017 * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
1018 * TDA10046 #0 is located at i2c address 0x08
1019 * TDA10046 #1 is located at i2c address 0x0b
1020 * TDA8275A #0 is located at i2c address 0x60
1021 * TDA8275A #1 is located at i2c address 0x61
1023 static struct dvb_usb_device_properties tvwalkertwin_properties = {
1024 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1026 .usb_ctrl = DEVICE_SPECIFIC,
1027 .firmware = "dvb-usb-tvwalkert.fw",
1028 .download_firmware = m920x_firmware_download,
1030 .rc.legacy = {
1031 .rc_interval = 100,
1032 .rc_map_table = rc_map_tvwalkertwin_table,
1033 .rc_map_size = ARRAY_SIZE(rc_map_tvwalkertwin_table),
1034 .rc_query = m920x_rc_query,
1037 .size_of_priv = sizeof(struct m920x_state),
1039 .identify_state = m920x_identify_state,
1040 .num_adapters = 2,
1041 .adapter = {{
1042 .num_frontends = 1,
1043 .fe = {{
1045 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1046 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1048 .pid_filter_count = 8,
1049 .pid_filter = m920x_pid_filter,
1050 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1052 .frontend_attach = m920x_tda10046_08_frontend_attach,
1053 .tuner_attach = m920x_tda8275_60_tuner_attach,
1055 .stream = {
1056 .type = USB_BULK,
1057 .count = 8,
1058 .endpoint = 0x81,
1059 .u = {
1060 .bulk = {
1061 .buffersize = 512,
1065 }},{
1066 .num_frontends = 1,
1067 .fe = {{
1069 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1070 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1072 .pid_filter_count = 8,
1073 .pid_filter = m920x_pid_filter,
1074 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1076 .frontend_attach = m920x_tda10046_0b_frontend_attach,
1077 .tuner_attach = m920x_tda8275_61_tuner_attach,
1079 .stream = {
1080 .type = USB_BULK,
1081 .count = 8,
1082 .endpoint = 0x82,
1083 .u = {
1084 .bulk = {
1085 .buffersize = 512,
1091 .i2c_algo = &m920x_i2c_algo,
1093 .num_device_descs = 1,
1094 .devices = {
1095 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
1096 .cold_ids = { &m920x_table[2], NULL },
1097 .warm_ids = { &m920x_table[3], NULL },
1102 static struct dvb_usb_device_properties dposh_properties = {
1103 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1105 .usb_ctrl = DEVICE_SPECIFIC,
1106 .firmware = "dvb-usb-dposh-01.fw",
1107 .download_firmware = m920x_firmware_download,
1109 .size_of_priv = sizeof(struct m920x_state),
1111 .identify_state = m920x_identify_state,
1112 .num_adapters = 1,
1113 .adapter = {{
1114 .num_frontends = 1,
1115 .fe = {{
1116 /* Hardware pid filters don't work with this device/firmware */
1118 .frontend_attach = m920x_mt352_frontend_attach,
1119 .tuner_attach = m920x_qt1010_tuner_attach,
1121 .stream = {
1122 .type = USB_BULK,
1123 .count = 8,
1124 .endpoint = 0x81,
1125 .u = {
1126 .bulk = {
1127 .buffersize = 512,
1133 .i2c_algo = &m920x_i2c_algo,
1135 .num_device_descs = 1,
1136 .devices = {
1137 { .name = "Dposh DVB-T USB2.0",
1138 .cold_ids = { &m920x_table[4], NULL },
1139 .warm_ids = { &m920x_table[5], NULL },
1144 static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
1145 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1147 .usb_ctrl = DEVICE_SPECIFIC,
1148 .download_firmware = NULL,
1150 .rc.legacy = {
1151 .rc_interval = 100,
1152 .rc_map_table = rc_map_pinnacle310e_table,
1153 .rc_map_size = ARRAY_SIZE(rc_map_pinnacle310e_table),
1154 .rc_query = m920x_rc_query,
1157 .size_of_priv = sizeof(struct m920x_state),
1159 .identify_state = m920x_identify_state,
1160 .num_adapters = 1,
1161 .adapter = {{
1162 .num_frontends = 1,
1163 .fe = {{
1165 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1166 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1168 .pid_filter_count = 8,
1169 .pid_filter = m920x_pid_filter,
1170 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1172 .frontend_attach = m920x_mt352_frontend_attach,
1173 .tuner_attach = m920x_fmd1216me_tuner_attach,
1175 .stream = {
1176 .type = USB_ISOC,
1177 .count = 5,
1178 .endpoint = 0x84,
1179 .u = {
1180 .isoc = {
1181 .framesperurb = 128,
1182 .framesize = 564,
1183 .interval = 1,
1188 } },
1189 .i2c_algo = &m920x_i2c_algo,
1191 .num_device_descs = 1,
1192 .devices = {
1193 { "Pinnacle PCTV 310e",
1194 { &m920x_table[6], NULL },
1195 { NULL },
1200 static struct dvb_usb_device_properties vp7049_properties = {
1201 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1203 .usb_ctrl = DEVICE_SPECIFIC,
1204 .firmware = "dvb-usb-vp7049-0.95.fw",
1205 .download_firmware = m920x_firmware_download,
1207 .rc.core = {
1208 .rc_interval = 150,
1209 .rc_codes = RC_MAP_TWINHAN_VP1027_DVBS,
1210 .rc_query = m920x_rc_core_query,
1211 .allowed_protos = RC_BIT_UNKNOWN,
1214 .size_of_priv = sizeof(struct m920x_state),
1216 .identify_state = m920x_identify_state,
1217 .num_adapters = 1,
1218 .adapter = {{
1219 .num_frontends = 1,
1220 .fe = {{
1222 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1223 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1225 .pid_filter_count = 8,
1226 .pid_filter = m920x_pid_filter,
1227 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1229 .frontend_attach = m920x_mt352_frontend_attach_vp7049,
1230 .tuner_attach = m920x_mt2060_tuner_attach,
1232 .stream = {
1233 .type = USB_BULK,
1234 .count = 8,
1235 .endpoint = 0x81,
1236 .u = {
1237 .bulk = {
1238 .buffersize = 512,
1242 } },
1243 } },
1244 .i2c_algo = &m920x_i2c_algo,
1246 .num_device_descs = 1,
1247 .devices = {
1248 { "DTV-DVB UDTT7049",
1249 { &m920x_table[7], NULL },
1250 { NULL },
1255 static struct usb_driver m920x_driver = {
1256 .name = "dvb_usb_m920x",
1257 .probe = m920x_probe,
1258 .disconnect = dvb_usb_device_exit,
1259 .id_table = m920x_table,
1262 module_usb_driver(m920x_driver);
1264 MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
1265 MODULE_DESCRIPTION("DVB Driver for ULI M920x");
1266 MODULE_VERSION("0.1");
1267 MODULE_LICENSE("GPL");