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