blob: 44e0d6e2c76b1ed14c4b1ee1dd2ea9d6981c8601 [file] [log] [blame]
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -03001/* 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
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation, version 2.
8 *
9 * see Documentation/dvb/README.dvb-usb for more information
10 */
Michael Krufkybaa2ed02006-09-23 20:01:29 -030011
Michael Krufky2aef7d02006-09-23 20:00:42 -030012#include "m920x.h"
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030013
14#include "mt352.h"
15#include "mt352_priv.h"
Michael Krufky017cf012006-09-23 20:40:20 -030016#include "qt1010.h"
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -030017#include "tda1004x.h"
18#include "tda827x.h"
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030019
20/* debug */
Michael Krufky26f48ea2006-09-28 01:46:49 -030021static int dvb_usb_m920x_debug;
Michael Krufkybaa2ed02006-09-23 20:01:29 -030022module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030023MODULE_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
Nick Andrewaa50ec22007-03-22 17:09:35 -030044static 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
Michael Krufkyfa948052007-01-21 15:57:48 -030064static inline int m9206_read(struct usb_device *udev, u8 request, u16 value,\
65 u16 index, void *data, int size)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030066{
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);
Pierre Willenbrock59069e52007-03-15 13:24:29 -030072 if (ret < 0) {
73 printk(KERN_INFO "m920x_read = error: %d\n", ret);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030074 return ret;
Pierre Willenbrock59069e52007-03-15 13:24:29 -030075 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030076
Pierre Willenbrock59069e52007-03-15 13:24:29 -030077 if (ret != size) {
78 deb_rc("m920x_read = no data\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030079 return -EIO;
Pierre Willenbrock59069e52007-03-15 13:24:29 -030080 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030081
82 return 0;
83}
84
Michael Krufkyfa948052007-01-21 15:57:48 -030085static inline int m9206_write(struct usb_device *udev, u8 request,
86 u16 value, u16 index)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -030087{
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);
Pierre Willenbrock59069e52007-03-15 13:24:29 -030093
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030094 return ret;
95}
96
Nick Andrewaa50ec22007-03-22 17:09:35 -030097static int m9206_init(struct dvb_usb_device *d, struct m9206_inits *rc_seq)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -030098{
99 int ret = 0;
100
101 /* Remote controller init. */
Aapo Tahkola480ac762007-03-05 18:54:27 -0300102 if (d->props.rc_query) {
Nick Andrewaa50ec22007-03-22 17:09:35 -0300103 deb_rc("Initialising remote control\n");
104 while (rc_seq->address) {
105 if ((ret = m9206_write(d->udev, M9206_CORE, rc_seq->data, rc_seq->address)) != 0) {
106 deb_rc("Initialising remote control failed\n");
107 return ret;
108 }
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300109
Nick Andrewaa50ec22007-03-22 17:09:35 -0300110 rc_seq++;
111 }
112
113 deb_rc("Initialising remote control success\n");
Aapo Tahkola480ac762007-03-05 18:54:27 -0300114 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300115
116 return ret;
117}
118
119static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
120{
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300121 struct m9206_state *m = d->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300122 int i, ret = 0;
123 u8 rc_state[2];
124
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300125 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300126 goto unlock;
127
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300128 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300129 goto unlock;
130
Aapo Tahkola480ac762007-03-05 18:54:27 -0300131 for (i = 0; i < d->props.rc_key_map_size; i++)
132 if (d->props.rc_key_map[i].data == rc_state[1]) {
133 *event = d->props.rc_key_map[i].event;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300134
135 switch(rc_state[0]) {
136 case 0x80:
137 *state = REMOTE_NO_KEY_PRESSED;
138 goto unlock;
139
Nick Andrewaa50ec22007-03-22 17:09:35 -0300140 case 0x88: /* framing error or "invalid code" */
141 case 0x99:
142 case 0xc0:
143 case 0xd8:
144 *state = REMOTE_NO_KEY_PRESSED;
145 m->rep_count = 0;
146 goto unlock;
147
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300148 case 0x93:
149 case 0x92:
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300150 m->rep_count = 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300151 *state = REMOTE_KEY_PRESSED;
152 goto unlock;
153
154 case 0x91:
Nick Andrewaa50ec22007-03-22 17:09:35 -0300155 /* prevent immediate auto-repeat */
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300156 if (++m->rep_count > 2)
157 *state = REMOTE_KEY_REPEAT;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300158 else
159 *state = REMOTE_NO_KEY_PRESSED;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300160 goto unlock;
161
162 default:
Nick Andrewaa50ec22007-03-22 17:09:35 -0300163 deb_rc("Unexpected rc state %02x\n", rc_state[0]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300164 *state = REMOTE_NO_KEY_PRESSED;
165 goto unlock;
166 }
167 }
168
169 if (rc_state[1] != 0)
Nick Andrewaa50ec22007-03-22 17:09:35 -0300170 deb_rc("Unknown rc key %02x\n", rc_state[1]);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300171
172 *state = REMOTE_NO_KEY_PRESSED;
173
174 unlock:
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300175
176 return ret;
177}
178
179/* I2C */
Michael Krufkyfa948052007-01-21 15:57:48 -0300180static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
181 int num)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300182{
183 struct dvb_usb_device *d = i2c_get_adapdata(adap);
Aapo Tahkola26247012007-03-05 18:23:19 -0300184 int i, j;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300185 int ret = 0;
186
Trent Piephod40860f2007-03-05 23:55:00 -0300187 if (!num)
188 return -EINVAL;
189
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300190 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
191 return -EAGAIN;
192
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300193 for (i = 0; i < num; i++) {
Trent Piepho57f8dcf2007-03-12 12:13:12 -0300194 if (msg[i].flags & (I2C_M_NO_RD_ACK|I2C_M_IGNORE_NAK|I2C_M_TEN) ||
195 msg[i].len == 0) {
196 /* For a 0 byte message, I think sending the address to index 0x80|0x40
197 * would be the correct thing to do. However, zero byte messages are
198 * only used for probing, and since we don't know how to get the slave's
199 * ack, we can't probe. */
Trent Piephod40860f2007-03-05 23:55:00 -0300200 ret = -ENOTSUPP;
201 goto unlock;
202 }
203 /* Send START & address/RW bit */
204 if (!(msg[i].flags & I2C_M_NOSTART)) {
Trent Piepho57f8dcf2007-03-12 12:13:12 -0300205 if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:0), 0x80)) != 0)
Trent Piephod40860f2007-03-05 23:55:00 -0300206 goto unlock;
207 /* Should check for ack here, if we knew how. */
208 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300209 if (msg[i].flags & I2C_M_RD) {
Trent Piephod40860f2007-03-05 23:55:00 -0300210 for (j = 0; j < msg[i].len; j++) {
211 /* Last byte of transaction? Send STOP, otherwise send ACK. */
212 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x01;
213 if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x20|stop, &msg[i].buf[j], 1)) != 0)
214 goto unlock;
Aapo Tahkola84ad7572007-01-21 15:57:20 -0300215 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300216 } else {
Trent Piephod40860f2007-03-05 23:55:00 -0300217 for (j = 0; j < msg[i].len; j++) {
218 /* Last byte of transaction? Then send STOP. */
219 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x00;
220 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
221 goto unlock;
222 /* Should check for ack here too. */
Aapo Tahkola26247012007-03-05 18:23:19 -0300223 }
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300224 }
225 }
Aapo Tahkola26247012007-03-05 18:23:19 -0300226 ret = num;
Trent Piephod40860f2007-03-05 23:55:00 -0300227
228unlock:
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300229 mutex_unlock(&d->i2c_mutex);
230
231 return ret;
232}
233
234static u32 m9206_i2c_func(struct i2c_adapter *adapter)
235{
236 return I2C_FUNC_I2C;
237}
238
239static struct i2c_algorithm m9206_i2c_algo = {
240 .master_xfer = m9206_i2c_xfer,
241 .functionality = m9206_i2c_func,
242};
243
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300244
Michael Krufkyfa948052007-01-21 15:57:48 -0300245static int m9206_set_filter(struct dvb_usb_adapter *adap, int type, int idx,
246 int pid)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300247{
248 int ret = 0;
249
250 if (pid >= 0x8000)
251 return -EINVAL;
252
253 pid |= 0x8000;
254
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300255 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300256 return ret;
257
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300258 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
259 return ret;
260
261 return ret;
262}
263
264static int m9206_update_filters(struct dvb_usb_adapter *adap)
265{
266 struct m9206_state *m = adap->dev->priv;
267 int enabled = m->filtering_enabled;
268 int i, ret = 0, filter = 0;
269
270 for (i = 0; i < M9206_MAX_FILTERS; i++)
271 if (m->filters[i] == 8192)
272 enabled = 0;
273
274 /* Disable all filters */
Michael Krufky26f48ea2006-09-28 01:46:49 -0300275 if ((ret = m9206_set_filter(adap, 0x81, 1, enabled)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300276 return ret;
277
278 for (i = 0; i < M9206_MAX_FILTERS; i++)
Michael Krufky26f48ea2006-09-28 01:46:49 -0300279 if ((ret = m9206_set_filter(adap, 0x81, i + 2, 0)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300280 return ret;
281
Michael Krufky26f48ea2006-09-28 01:46:49 -0300282 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x0)) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300283 return ret;
284
285 /* Set */
286 if (enabled) {
287 for (i = 0; i < M9206_MAX_FILTERS; i++) {
288 if (m->filters[i] == 0)
289 continue;
290
Michael Krufky26f48ea2006-09-28 01:46:49 -0300291 if ((ret = m9206_set_filter(adap, 0x81, filter + 2, m->filters[i])) != 0)
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300292 return ret;
293
294 filter++;
295 }
296 }
297
Michael Krufky26f48ea2006-09-28 01:46:49 -0300298 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x02f5)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300299 return ret;
300
301 return ret;
302}
303
Michael Krufky01cb34d2006-09-23 20:01:29 -0300304static int m9206_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300305{
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300306 struct m9206_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300307
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300308 m->filtering_enabled = onoff ? 1 : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300309
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300310 return m9206_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300311}
312
Michael Krufkyfa948052007-01-21 15:57:48 -0300313static int m9206_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
314 int onoff)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300315{
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300316 struct m9206_state *m = adap->dev->priv;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300317
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300318 m->filters[index] = onoff ? pid : 0;
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300319
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300320 return m9206_update_filters(adap);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300321}
322
Michael Krufkyfa948052007-01-21 15:57:48 -0300323static int m9206_firmware_download(struct usb_device *udev,
324 const struct firmware *fw)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300325{
326 u16 value, index, size;
327 u8 read[4], *buff;
328 int i, pass, ret = 0;
329
330 buff = kmalloc(65536, GFP_KERNEL);
331
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300332 if ((ret = m9206_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300333 goto done;
334 deb_rc("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
335
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300336 if ((ret = m9206_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300337 goto done;
338 deb_rc("%x\n", read[0]);
339
340 for (pass = 0; pass < 2; pass++) {
341 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
342 value = le16_to_cpu(*(u16 *)(fw->data + i));
343 i += sizeof(u16);
344
345 index = le16_to_cpu(*(u16 *)(fw->data + i));
346 i += sizeof(u16);
347
348 size = le16_to_cpu(*(u16 *)(fw->data + i));
349 i += sizeof(u16);
350
351 if (pass == 1) {
352 /* Will stall if using fw->data ... */
353 memcpy(buff, fw->data + i, size);
354
355 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300356 M9206_FW,
357 USB_TYPE_VENDOR | USB_DIR_OUT,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300358 value, index, buff, size, 20);
359 if (ret != size) {
360 deb_rc("error while uploading fw!\n");
361 ret = -EIO;
362 goto done;
363 }
364 msleep(3);
365 }
366 i += size;
367 }
368 if (i != fw->size) {
Pierre Willenbrock59069e52007-03-15 13:24:29 -0300369 deb_rc("bad firmware file!\n");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300370 ret = -EINVAL;
371 goto done;
372 }
373 }
374
375 msleep(36);
376
377 /* m9206 will disconnect itself from the bus after this. */
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300378 (void) m9206_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300379 deb_rc("firmware uploaded!\n");
380
381 done:
382 kfree(buff);
383
384 return ret;
385}
386
Michael Krufkye16c1f52007-01-23 15:00:42 -0300387/* Callbacks for DVB USB */
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300388static int m920x_identify_state(struct usb_device *udev,
389 struct dvb_usb_device_properties *props,
390 struct dvb_usb_device_description **desc,
391 int *cold)
Michael Krufkye16c1f52007-01-23 15:00:42 -0300392{
393 struct usb_host_interface *alt;
394
395 alt = usb_altnum_to_altsetting(usb_ifnum_to_if(udev, 0), 1);
396 *cold = (alt == NULL) ? 1 : 0;
397
398 return 0;
399}
400
401static int megasky_mt352_demod_init(struct dvb_frontend *fe)
402{
403 u8 config[] = { CONFIG, 0x3d };
404 u8 clock[] = { CLOCK_CTL, 0x30 };
405 u8 reset[] = { RESET, 0x80 };
406 u8 adc_ctl[] = { ADC_CTL_1, 0x40 };
407 u8 agc[] = { AGC_TARGET, 0x1c, 0x20 };
408 u8 sec_agc[] = { 0x69, 0x00, 0xff, 0xff, 0x40, 0xff, 0x00, 0x40, 0x40 };
409 u8 unk1[] = { 0x93, 0x1a };
410 u8 unk2[] = { 0xb5, 0x7a };
411
412 mt352_write(fe, config, ARRAY_SIZE(config));
413 mt352_write(fe, clock, ARRAY_SIZE(clock));
414 mt352_write(fe, reset, ARRAY_SIZE(reset));
415 mt352_write(fe, adc_ctl, ARRAY_SIZE(adc_ctl));
416 mt352_write(fe, agc, ARRAY_SIZE(agc));
417 mt352_write(fe, sec_agc, ARRAY_SIZE(sec_agc));
418 mt352_write(fe, unk1, ARRAY_SIZE(unk1));
419 mt352_write(fe, unk2, ARRAY_SIZE(unk2));
420
421 deb_rc("Demod init!\n");
422
423 return 0;
424}
425
426static struct mt352_config megasky_mt352_config = {
Aapo Tahkola26247012007-03-05 18:23:19 -0300427 .demod_address = 0x0f,
Michael Krufkye16c1f52007-01-23 15:00:42 -0300428 .no_tuner = 1,
429 .demod_init = megasky_mt352_demod_init,
430};
431
432static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap)
433{
Michael Krufkye16c1f52007-01-23 15:00:42 -0300434 deb_rc("megasky_frontend_attach!\n");
435
Michael Krufkye16c1f52007-01-23 15:00:42 -0300436 if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL)
437 return -EIO;
438
439 return 0;
440}
441
Antti Palosaaricbdc80e2007-01-21 15:56:10 -0300442static struct qt1010_config megasky_qt1010_config = {
Aapo Tahkola26247012007-03-05 18:23:19 -0300443 .i2c_address = 0x62
Antti Palosaaricbdc80e2007-01-21 15:56:10 -0300444};
445
Michael Krufkye16c1f52007-01-23 15:00:42 -0300446static int megasky_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
Antti Palosaaricbdc80e2007-01-21 15:56:10 -0300447{
Aapo Tahkola84ad7572007-01-21 15:57:20 -0300448 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap,
449 &megasky_qt1010_config) == NULL)
450 return -ENODEV;
451
452 return 0;
Antti Palosaaricbdc80e2007-01-21 15:56:10 -0300453}
454
Nick Andrewaa50ec22007-03-22 17:09:35 -0300455static struct m9206_inits megasky_rc_init [] = {
456 { M9206_RC_INIT2, 0xa8 },
457 { M9206_RC_INIT1, 0x51 },
458 { } /* terminating entry */
459};
460
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300461static struct tda1004x_config digivox_tda10046_config = {
462 .demod_address = 0x08,
463 .invert = 0,
464 .invert_oclk = 0,
465 .ts_mode = TDA10046_TS_SERIAL,
466 .xtal_freq = TDA10046_XTAL_16M,
467 .if_freq = TDA10046_FREQ_045,
468 .agc_config = TDA10046_AGC_TDA827X,
469 .gpio_config = TDA10046_GPTRI,
470 .request_firmware = NULL,
471};
472
473static int digivox_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
474{
475 deb_rc("digivox_tda10046_frontend_attach!\n");
476
477 if ((adap->fe = dvb_attach(tda10046_attach, &digivox_tda10046_config,
478 &adap->dev->i2c_adap)) == NULL)
479 return -EIO;
480
481 return 0;
482}
483
484static int digivox_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
485{
486 if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap,
487 NULL) == NULL)
488 return -ENODEV;
489 return 0;
490}
491
Nick Andrewaa50ec22007-03-22 17:09:35 -0300492/* LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
493 * TDA10046 #0 is located at i2c address 0x08
494 * TDA10046 #1 is located at i2c address 0x0b
495 * TDA8275A #0 is located at i2c address 0x60
496 * TDA8275A #1 is located at i2c address 0x61
497 */
498
499static struct tda1004x_config tvwalkertwin_0_tda10046_config = {
500 .demod_address = 0x08,
501 .invert = 0,
502 .invert_oclk = 0,
503 .ts_mode = TDA10046_TS_SERIAL,
504 .xtal_freq = TDA10046_XTAL_16M,
505 .if_freq = TDA10046_FREQ_045,
506 .agc_config = TDA10046_AGC_TDA827X,
507 .gpio_config = TDA10046_GPTRI,
508 .request_firmware = NULL, /* uses firmware EEPROM */
509};
510
511static struct tda1004x_config tvwalkertwin_1_tda10046_config = {
512 .demod_address = 0x0b,
513 .invert = 0,
514 .invert_oclk = 0,
515 .ts_mode = TDA10046_TS_SERIAL,
516 .xtal_freq = TDA10046_XTAL_16M,
517 .if_freq = TDA10046_FREQ_045,
518 .agc_config = TDA10046_AGC_TDA827X,
519 .gpio_config = TDA10046_GPTRI,
520 .request_firmware = NULL, /* uses firmware EEPROM */
521};
522
523static int tvwalkertwin_0_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
524{
525 deb_rc("tvwalkertwin_0_tda10046_frontend_attach!\n");
526
527 if ((adap->fe = dvb_attach(tda10046_attach, &tvwalkertwin_0_tda10046_config, &adap->dev->i2c_adap)) == NULL)
528 return -EIO;
529
530 deb_rc("Attached demod 0 at address %02x\n", tvwalkertwin_0_tda10046_config.demod_address);
531
532 return 0;
533}
534
535static int tvwalkertwin_1_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
536{
537 deb_rc("tvwalkertwin_1_tda10046_frontend_attach!\n");
538
539 if ((adap->fe = dvb_attach(tda10046_attach, &tvwalkertwin_1_tda10046_config, &adap->dev->i2c_adap)) == NULL)
540 return -EIO;
541
542 deb_rc("Attached demod 1 at address %02x\n", tvwalkertwin_1_tda10046_config.demod_address);
543
544 return 0;
545}
546
547static int tvwalkertwin_0_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
548{
549 int address = 0x60;
550
551 deb_rc("tvwalkertwin_0_tda8275_tuner_attach!\n");
552
553 if (dvb_attach(tda827x_attach, adap->fe, address, &adap->dev->i2c_adap,
554 NULL) == NULL)
555 return -ENODEV;
556
557 deb_rc("Attached tuner 0 at address %02x\n", address);
558
559 return 0;
560}
561
562static int tvwalkertwin_1_tda8275_tuner_attach(struct dvb_usb_adapter *adap)
563{
564 int address = 0x61;
565
566 deb_rc("tvwalkertwin_1_tda8275_tuner_attach!\n");
567
568 if (dvb_attach(tda827x_attach, adap->fe, address, &adap->dev->i2c_adap,
569 NULL) == NULL)
570 return -ENODEV;
571
572 deb_rc("Attached tuner 1 at address %02x\n", address);
573
574 return 0;
575}
576
577static struct m9206_inits tvwalkertwin_rc_init [] = {
578 { M9206_RC_INIT2, 0x00 },
579 { M9206_RC_INIT1, 0xef },
580 { 0xff28, 0x00 },
581 { 0xff23, 0x00 },
582 { 0xff21, 0x30 },
583 { } /* terminating entry */
584};
585
Michael Krufky26f48ea2006-09-28 01:46:49 -0300586/* DVB USB Driver stuff */
587static struct dvb_usb_device_properties megasky_properties;
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300588static struct dvb_usb_device_properties digivox_mini_ii_properties;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300589static struct dvb_usb_device_properties tvwalkertwin_properties;
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300590static struct dvb_usb_device_properties dposh_properties;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300591static struct m9206_inits megasky_rc_init [];
592static struct m9206_inits tvwalkertwin_rc_init [];
Michael Krufky26f48ea2006-09-28 01:46:49 -0300593
Michael Krufkyfa948052007-01-21 15:57:48 -0300594static int m920x_probe(struct usb_interface *intf,
595 const struct usb_device_id *id)
Michael Krufky26f48ea2006-09-28 01:46:49 -0300596{
597 struct dvb_usb_device *d;
598 struct usb_host_interface *alt;
599 int ret;
Nick Andrewaa50ec22007-03-22 17:09:35 -0300600 struct m9206_inits *rc_init_seq = NULL;
601 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300602
Nick Andrewaa50ec22007-03-22 17:09:35 -0300603 deb_rc("Probing for m920x device at interface %d\n", bInterfaceNumber);
Michael Krufky26f48ea2006-09-28 01:46:49 -0300604
Nick Andrewaa50ec22007-03-22 17:09:35 -0300605 if (bInterfaceNumber == 0) {
606 /* Single-tuner device, or first interface on
607 * multi-tuner device
608 */
Michael Krufky26f48ea2006-09-28 01:46:49 -0300609
Nick Andrewaa50ec22007-03-22 17:09:35 -0300610 if ((ret = dvb_usb_device_init(intf, &megasky_properties,
611 THIS_MODULE, &d)) == 0) {
612 rc_init_seq = megasky_rc_init;
613 goto found;
614 }
615
616 if ((ret = dvb_usb_device_init(intf,
617 &digivox_mini_ii_properties, THIS_MODULE, &d)) == 0) {
618 /* No remote control, so no rc_init_seq */
619 goto found;
620 }
621
622 /* This configures both tuners on the TV Walker Twin */
623 if ((ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
624 THIS_MODULE, &d)) == 0) {
625 rc_init_seq = tvwalkertwin_rc_init;
626 goto found;
627 }
628
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300629 if ((ret = dvb_usb_device_init(intf, &dposh_properties, THIS_MODULE, &d)) == 0) {
630 /* Remote controller not supported yet. */
631 goto found;
632 }
633
Nick Andrewaa50ec22007-03-22 17:09:35 -0300634 return ret;
635 } else {
636 /* Another interface on a multi-tuner device */
637
638 /* The LifeView TV Walker Twin gets here, but struct
639 * tvwalkertwin_properties already configured both
640 * tuners, so there is nothing for us to do here
641 */
642
643 return -ENODEV;
644 }
Michael Krufky26f48ea2006-09-28 01:46:49 -0300645
Aapo Tahkola480ac762007-03-05 18:54:27 -0300646found:
647 alt = usb_altnum_to_altsetting(intf, 1);
648 if (alt == NULL) {
649 deb_rc("No alt found!\n");
650 return -ENODEV;
Michael Krufky26f48ea2006-09-28 01:46:49 -0300651 }
Aapo Tahkola480ac762007-03-05 18:54:27 -0300652
653 ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber,
654 alt->desc.bAlternateSetting);
655 if (ret < 0)
656 return ret;
657
Nick Andrewaa50ec22007-03-22 17:09:35 -0300658 if ((ret = m9206_init(d, rc_init_seq)) != 0)
Aapo Tahkola480ac762007-03-05 18:54:27 -0300659 return ret;
660
Michael Krufky26f48ea2006-09-28 01:46:49 -0300661 return ret;
662}
663
664static struct usb_device_id m920x_table [] = {
665 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300666 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
667 USB_PID_MSI_DIGI_VOX_MINI_II) },
Nick Andrewaa50ec22007-03-22 17:09:35 -0300668 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
669 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
670 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
671 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300672 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
673 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
Michael Krufky26f48ea2006-09-28 01:46:49 -0300674 { } /* Terminating entry */
675};
676MODULE_DEVICE_TABLE (usb, m920x_table);
677
Michael Krufky01cb34d2006-09-23 20:01:29 -0300678static struct dvb_usb_device_properties megasky_properties = {
Michael Krufky758117c2007-01-23 15:34:10 -0300679 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
Michael Krufky1f61f3b2006-10-07 15:03:04 -0300680
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300681 .usb_ctrl = DEVICE_SPECIFIC,
682 .firmware = "dvb-usb-megasky-02.fw",
683 .download_firmware = m9206_firmware_download,
684
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300685 .rc_interval = 100,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300686 .rc_key_map = megasky_rc_keys,
687 .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys),
688 .rc_query = m9206_rc_query,
689
Aapo Tahkolae2adbecf72006-09-28 00:47:51 -0300690 .size_of_priv = sizeof(struct m9206_state),
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300691
Aapo Tahkola7d1d4e62007-03-15 13:01:46 -0300692 .identify_state = m920x_identify_state,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300693 .num_adapters = 1,
694 .adapter = {{
Michael Krufky758117c2007-01-23 15:34:10 -0300695 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
696 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
697
Michael Krufky01cb34d2006-09-23 20:01:29 -0300698 .pid_filter_count = 8,
699 .pid_filter = m9206_pid_filter,
700 .pid_filter_ctrl = m9206_pid_filter_ctrl,
701
Michael Krufkye16c1f52007-01-23 15:00:42 -0300702 .frontend_attach = megasky_mt352_frontend_attach,
703 .tuner_attach = megasky_qt1010_tuner_attach,
Michael Krufky01cb34d2006-09-23 20:01:29 -0300704
705 .stream = {
706 .type = USB_BULK,
707 .count = 8,
708 .endpoint = 0x81,
709 .u = {
710 .bulk = {
711 .buffersize = 512,
712 }
713 }
714 },
715 }},
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300716 .i2c_algo = &m9206_i2c_algo,
717
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300718 .num_device_descs = 1,
719 .devices = {
720 { "MSI Mega Sky 580 DVB-T USB2.0",
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300721 { &m920x_table[0], NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300722 { NULL },
Pierre Willenbrockd4ca23b2007-03-18 19:54:07 -0300723 }
724 }
725};
726
727static struct dvb_usb_device_properties digivox_mini_ii_properties = {
728 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
729
730 .usb_ctrl = DEVICE_SPECIFIC,
731 .firmware = "dvb-usb-digivox-02.fw",
732 .download_firmware = m9206_firmware_download,
733
734 .size_of_priv = sizeof(struct m9206_state),
735
736 .identify_state = m920x_identify_state,
737 .num_adapters = 1,
738 .adapter = {{
739 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
740 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
741
742 .pid_filter_count = 8,
743 .pid_filter = m9206_pid_filter,
744 .pid_filter_ctrl = m9206_pid_filter_ctrl,
745
746 .frontend_attach = digivox_tda10046_frontend_attach,
747 .tuner_attach = digivox_tda8275_tuner_attach,
748
749 .stream = {
750 .type = USB_BULK,
751 .count = 8,
752 .endpoint = 0x81,
753 .u = {
754 .bulk = {
755 .buffersize = 0x4000,
756 }
757 }
758 },
759 }},
760 .i2c_algo = &m9206_i2c_algo,
761
762 .num_device_descs = 1,
763 .devices = {
764 { "MSI DIGI VOX mini II DVB-T USB2.0",
765 { &m920x_table[1], NULL },
766 { NULL },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300767 },
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300768 }
769};
770
Nick Andrewaa50ec22007-03-22 17:09:35 -0300771/* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net> */
772
773static struct dvb_usb_device_properties tvwalkertwin_properties = {
774 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
775
776 .usb_ctrl = DEVICE_SPECIFIC,
777 .firmware = "dvb-usb-tvwalkert.fw",
778 .download_firmware = m9206_firmware_download,
779
780 .rc_interval = 100,
781 .rc_key_map = tvwalkertwin_rc_keys,
782 .rc_key_map_size = ARRAY_SIZE(tvwalkertwin_rc_keys),
783 .rc_query = m9206_rc_query,
784
785 .size_of_priv = sizeof(struct m9206_state),
786
787 .identify_state = m920x_identify_state,
788 .num_adapters = 2,
789 .adapter = {
790 {
791 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
792 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
793
794 .pid_filter_count = 8,
795 .pid_filter = m9206_pid_filter,
796 .pid_filter_ctrl = m9206_pid_filter_ctrl,
797
798 .frontend_attach = tvwalkertwin_0_tda10046_frontend_attach,
799 .tuner_attach = tvwalkertwin_0_tda8275_tuner_attach,
800
801 .stream = {
802 .type = USB_BULK,
803 .count = 8,
804 .endpoint = 0x81,
805 .u = {
806 .bulk = {
807 .buffersize = 512,
808 }
809 }
810 },
811 },
812 {
813 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
814 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
815
816 .pid_filter_count = 8,
817 .pid_filter = m9206_pid_filter,
818 .pid_filter_ctrl = m9206_pid_filter_ctrl,
819
820 .frontend_attach = tvwalkertwin_1_tda10046_frontend_attach,
821 .tuner_attach = tvwalkertwin_1_tda8275_tuner_attach,
822
823 .stream = {
824 .type = USB_BULK,
825 .count = 8,
826 .endpoint = 0x82,
827 .u = {
828 .bulk = {
829 .buffersize = 512,
830 }
831 }
832 },
833 }
834 },
835 .i2c_algo = &m9206_i2c_algo,
836
837 .num_device_descs = 1,
838 .devices = {
839 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
840 .cold_ids = { &m920x_table[2], NULL },
841 .warm_ids = { &m920x_table[3], NULL },
842 },
843 }
844};
845
Aapo Tahkolaf8e0bd52007-03-22 17:37:58 -0300846static struct dvb_usb_device_properties dposh_properties = {
847 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
848
849 .usb_ctrl = DEVICE_SPECIFIC,
850 .firmware = "dvb-usb-dposh-01.fw",
851 .download_firmware = m9206_firmware_download,
852
853 /* Remote controller not supported yet. */
854
855 .size_of_priv = sizeof(struct m9206_state),
856
857 .identify_state = m920x_identify_state,
858 .num_adapters = 1,
859 .adapter = {{
860 /* Nardware pid filters don't work with this device/firmware. */
861
862 .frontend_attach = megasky_mt352_frontend_attach,
863 .tuner_attach = megasky_qt1010_tuner_attach,
864
865 .stream = {
866 .type = USB_BULK,
867 .count = 8,
868 .endpoint = 0x81,
869 .u = {
870 .bulk = {
871 .buffersize = 512,
872 }
873 }
874 },
875 }},
876 .i2c_algo = &m9206_i2c_algo,
877
878 .num_device_descs = 1,
879 .devices = {
880 { .name = "Dposh DVB-T USB2.0",
881 .cold_ids = { &m920x_table[4], NULL },
882 .warm_ids = { &m920x_table[5], NULL },
883 },
884 }
885};
886
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300887static struct usb_driver m920x_driver = {
888 .name = "dvb_usb_m920x",
Michael Krufky2a2bfa72006-09-23 20:13:12 -0300889 .probe = m920x_probe,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300890 .disconnect = dvb_usb_device_exit,
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300891 .id_table = m920x_table,
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300892};
893
894/* module stuff */
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300895static int __init m920x_module_init(void)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300896{
897 int ret;
898
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300899 if ((ret = usb_register(&m920x_driver))) {
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300900 err("usb_register failed. Error number %d", ret);
901 return ret;
902 }
903
904 return 0;
905}
906
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300907static void __exit m920x_module_exit(void)
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300908{
909 /* deregister this driver from the USB subsystem */
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300910 usb_deregister(&m920x_driver);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300911}
912
Michael Krufkybaa2ed02006-09-23 20:01:29 -0300913module_init (m920x_module_init);
914module_exit (m920x_module_exit);
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300915
916MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
Nick Andrewaa50ec22007-03-22 17:09:35 -0300917MODULE_DESCRIPTION("DVB Driver for ULI M920x");
Aapo Tahkola5fecd9f2006-09-23 20:00:41 -0300918MODULE_VERSION("0.1");
919MODULE_LICENSE("GPL");
Michael Krufkyce9c2752007-03-22 17:18:26 -0300920
921/*
922 * Local variables:
923 * c-basic-offset: 8
924 */