Commit | Line | Data |
---|---|---|
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 | |
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 | */ | |
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 | 21 | static int dvb_usb_m920x_debug; |
baa2ed09 | 22 | module_param_named(debug,dvb_usb_m920x_debug, int, 0644); |
5fecd9fd AT |
23 | MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); |
24 | ||
25 | static struct dvb_usb_rc_key megasky_rc_keys [] = { | |
26 | { 0x0, 0x12, KEY_POWER }, | |
27 | { 0x0, 0x1e, KEY_CYCLEWINDOWS }, /* min/max */ | |
28 | { 0x0, 0x02, KEY_CHANNELUP }, | |
29 | { 0x0, 0x05, KEY_CHANNELDOWN }, | |
30 | { 0x0, 0x03, KEY_VOLUMEUP }, | |
31 | { 0x0, 0x06, KEY_VOLUMEDOWN }, | |
32 | { 0x0, 0x04, KEY_MUTE }, | |
33 | { 0x0, 0x07, KEY_OK }, /* TS */ | |
34 | { 0x0, 0x08, KEY_STOP }, | |
35 | { 0x0, 0x09, KEY_MENU }, /* swap */ | |
36 | { 0x0, 0x0a, KEY_REWIND }, | |
37 | { 0x0, 0x1b, KEY_PAUSE }, | |
38 | { 0x0, 0x1f, KEY_FASTFORWARD }, | |
39 | { 0x0, 0x0c, KEY_RECORD }, | |
40 | { 0x0, 0x0d, KEY_CAMERA }, /* screenshot */ | |
41 | { 0x0, 0x0e, KEY_COFFEE }, /* "MTS" */ | |
42 | }; | |
43 | ||
aa50ec2b NA |
44 | static 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 | ||
fa94805d MK |
64 | static inline int m9206_read(struct usb_device *udev, u8 request, u16 value,\ |
65 | u16 index, void *data, int size) | |
5fecd9fd AT |
66 | { |
67 | int ret; | |
68 | ||
69 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | |
70 | request, USB_TYPE_VENDOR | USB_DIR_IN, | |
71 | value, index, data, size, 2000); | |
59069e53 PW |
72 | if (ret < 0) { |
73 | printk(KERN_INFO "m920x_read = error: %d\n", ret); | |
5fecd9fd | 74 | return ret; |
59069e53 | 75 | } |
5fecd9fd | 76 | |
59069e53 PW |
77 | if (ret != size) { |
78 | deb_rc("m920x_read = no data\n"); | |
5fecd9fd | 79 | return -EIO; |
59069e53 | 80 | } |
5fecd9fd AT |
81 | |
82 | return 0; | |
83 | } | |
84 | ||
fa94805d MK |
85 | static inline int m9206_write(struct usb_device *udev, u8 request, |
86 | u16 value, u16 index) | |
5fecd9fd AT |
87 | { |
88 | int ret; | |
89 | ||
90 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | |
91 | request, USB_TYPE_VENDOR | USB_DIR_OUT, | |
92 | value, index, NULL, 0, 2000); | |
59069e53 | 93 | |
e2adbecf AT |
94 | return ret; |
95 | } | |
96 | ||
aa50ec2b | 97 | static int m9206_init(struct dvb_usb_device *d, struct m9206_inits *rc_seq) |
e2adbecf AT |
98 | { |
99 | int ret = 0; | |
100 | ||
101 | /* Remote controller init. */ | |
480ac761 | 102 | if (d->props.rc_query) { |
aa50ec2b NA |
103 | deb_rc("Initialising remote control\n"); |
104 | while (rc_seq->address) { | |
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 | } | |
e2adbecf | 109 | |
aa50ec2b NA |
110 | rc_seq++; |
111 | } | |
112 | ||
113 | deb_rc("Initialising remote control success\n"); | |
480ac761 | 114 | } |
5fecd9fd AT |
115 | |
116 | return ret; | |
117 | } | |
118 | ||
119 | static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state) | |
120 | { | |
e2adbecf | 121 | struct m9206_state *m = d->priv; |
5fecd9fd AT |
122 | int i, ret = 0; |
123 | u8 rc_state[2]; | |
124 | ||
e2adbecf | 125 | if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0) |
5fecd9fd AT |
126 | goto unlock; |
127 | ||
e2adbecf | 128 | if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0) |
5fecd9fd AT |
129 | goto unlock; |
130 | ||
480ac761 AT |
131 | 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; | |
5fecd9fd AT |
134 | |
135 | switch(rc_state[0]) { | |
136 | case 0x80: | |
137 | *state = REMOTE_NO_KEY_PRESSED; | |
138 | goto unlock; | |
139 | ||
aa50ec2b NA |
140 | 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 | ||
5fecd9fd AT |
148 | case 0x93: |
149 | case 0x92: | |
e2adbecf | 150 | m->rep_count = 0; |
5fecd9fd AT |
151 | *state = REMOTE_KEY_PRESSED; |
152 | goto unlock; | |
153 | ||
154 | case 0x91: | |
aa50ec2b | 155 | /* prevent immediate auto-repeat */ |
e2adbecf AT |
156 | if (++m->rep_count > 2) |
157 | *state = REMOTE_KEY_REPEAT; | |
aa50ec2b NA |
158 | else |
159 | *state = REMOTE_NO_KEY_PRESSED; | |
5fecd9fd AT |
160 | goto unlock; |
161 | ||
162 | default: | |
aa50ec2b | 163 | deb_rc("Unexpected rc state %02x\n", rc_state[0]); |
5fecd9fd AT |
164 | *state = REMOTE_NO_KEY_PRESSED; |
165 | goto unlock; | |
166 | } | |
167 | } | |
168 | ||
169 | if (rc_state[1] != 0) | |
aa50ec2b | 170 | deb_rc("Unknown rc key %02x\n", rc_state[1]); |
5fecd9fd AT |
171 | |
172 | *state = REMOTE_NO_KEY_PRESSED; | |
173 | ||
174 | unlock: | |
5fecd9fd AT |
175 | |
176 | return ret; | |
177 | } | |
178 | ||
179 | /* I2C */ | |
fa94805d MK |
180 | static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], |
181 | int num) | |
5fecd9fd AT |
182 | { |
183 | struct dvb_usb_device *d = i2c_get_adapdata(adap); | |
26247018 | 184 | int i, j; |
5fecd9fd AT |
185 | int ret = 0; |
186 | ||
d40860f8 TP |
187 | if (!num) |
188 | return -EINVAL; | |
189 | ||
5fecd9fd AT |
190 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) |
191 | return -EAGAIN; | |
192 | ||
5fecd9fd | 193 | for (i = 0; i < num; i++) { |
57f8dcf9 TP |
194 | 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. */ | |
d40860f8 TP |
200 | ret = -ENOTSUPP; |
201 | goto unlock; | |
202 | } | |
203 | /* Send START & address/RW bit */ | |
204 | if (!(msg[i].flags & I2C_M_NOSTART)) { | |
57f8dcf9 | 205 | if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:0), 0x80)) != 0) |
84ad7574 | 206 | goto unlock; |
d40860f8 TP |
207 | /* Should check for ack here, if we knew how. */ |
208 | } | |
209 | if (msg[i].flags & I2C_M_RD) { | |
210 | 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; | |
84ad7574 | 215 | } |
26247018 | 216 | } else { |
d40860f8 TP |
217 | 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. */ | |
26247018 | 223 | } |
5fecd9fd AT |
224 | } |
225 | } | |
26247018 | 226 | ret = num; |
d40860f8 TP |
227 | |
228 | unlock: | |
5fecd9fd AT |
229 | mutex_unlock(&d->i2c_mutex); |
230 | ||
231 | return ret; | |
232 | } | |
233 | ||
234 | static u32 m9206_i2c_func(struct i2c_adapter *adapter) | |
235 | { | |
236 | return I2C_FUNC_I2C; | |
237 | } | |
238 | ||
239 | static struct i2c_algorithm m9206_i2c_algo = { | |
240 | .master_xfer = m9206_i2c_xfer, | |
241 | .functionality = m9206_i2c_func, | |
242 | }; | |
243 | ||
5fecd9fd | 244 | |
fa94805d MK |
245 | static int m9206_set_filter(struct dvb_usb_adapter *adap, int type, int idx, |
246 | int pid) | |
5fecd9fd AT |
247 | { |
248 | int ret = 0; | |
249 | ||
250 | if (pid >= 0x8000) | |
251 | return -EINVAL; | |
252 | ||
253 | pid |= 0x8000; | |
254 | ||
e2adbecf | 255 | if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0) |
5fecd9fd AT |
256 | return ret; |
257 | ||
e2adbecf | 258 | if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0) |
5fecd9fd AT |
259 | return ret; |
260 | ||
261 | return ret; | |
262 | } | |
263 | ||
e2adbecf | 264 | static int m9206_update_filters(struct dvb_usb_adapter *adap) |
5fecd9fd | 265 | { |
e2adbecf AT |
266 | struct m9206_state *m = adap->dev->priv; |
267 | int enabled = m->filtering_enabled; | |
268 | int i, ret = 0, filter = 0; | |
5fecd9fd | 269 | |
e2adbecf AT |
270 | for (i = 0; i < M9206_MAX_FILTERS; i++) |
271 | if (m->filters[i] == 8192) | |
272 | enabled = 0; | |
5fecd9fd | 273 | |
e2adbecf | 274 | /* Disable all filters */ |
26f48eaa | 275 | if ((ret = m9206_set_filter(adap, 0x81, 1, enabled)) != 0) |
e2adbecf | 276 | return ret; |
5fecd9fd | 277 | |
e2adbecf | 278 | for (i = 0; i < M9206_MAX_FILTERS; i++) |
26f48eaa | 279 | if ((ret = m9206_set_filter(adap, 0x81, i + 2, 0)) != 0) |
e2adbecf AT |
280 | return ret; |
281 | ||
26f48eaa | 282 | if ((ret = m9206_set_filter(adap, 0x82, 0, 0x0)) != 0) |
e2adbecf AT |
283 | 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 | ||
26f48eaa | 291 | if ((ret = m9206_set_filter(adap, 0x81, filter + 2, m->filters[i])) != 0) |
e2adbecf AT |
292 | return ret; |
293 | ||
294 | filter++; | |
295 | } | |
5fecd9fd | 296 | } |
e2adbecf | 297 | |
26f48eaa | 298 | if ((ret = m9206_set_filter(adap, 0x82, 0, 0x02f5)) != 0) |
e2adbecf | 299 | return ret; |
5fecd9fd AT |
300 | |
301 | return ret; | |
302 | } | |
303 | ||
e2adbecf | 304 | static int m9206_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) |
5fecd9fd | 305 | { |
e2adbecf | 306 | struct m9206_state *m = adap->dev->priv; |
5fecd9fd | 307 | |
e2adbecf | 308 | m->filtering_enabled = onoff ? 1 : 0; |
5fecd9fd | 309 | |
e2adbecf AT |
310 | return m9206_update_filters(adap); |
311 | } | |
5fecd9fd | 312 | |
fa94805d MK |
313 | static int m9206_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, |
314 | int onoff) | |
e2adbecf AT |
315 | { |
316 | struct m9206_state *m = adap->dev->priv; | |
5fecd9fd | 317 | |
e2adbecf | 318 | m->filters[index] = onoff ? pid : 0; |
5fecd9fd | 319 | |
e2adbecf | 320 | return m9206_update_filters(adap); |
5fecd9fd AT |
321 | } |
322 | ||
fa94805d MK |
323 | static int m9206_firmware_download(struct usb_device *udev, |
324 | const struct firmware *fw) | |
5fecd9fd AT |
325 | { |
326 | u16 value, index, size; | |
327 | u8 read[4], *buff; | |
328 | int i, pass, ret = 0; | |
329 | ||
330 | buff = kmalloc(65536, GFP_KERNEL); | |
331 | ||
e2adbecf | 332 | if ((ret = m9206_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0) |
5fecd9fd AT |
333 | goto done; |
334 | deb_rc("%x %x %x %x\n", read[0], read[1], read[2], read[3]); | |
335 | ||
e2adbecf | 336 | if ((ret = m9206_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0) |
5fecd9fd AT |
337 | 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), | |
e2adbecf AT |
356 | M9206_FW, |
357 | USB_TYPE_VENDOR | USB_DIR_OUT, | |
5fecd9fd AT |
358 | 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) { | |
59069e53 | 369 | deb_rc("bad firmware file!\n"); |
5fecd9fd AT |
370 | ret = -EINVAL; |
371 | goto done; | |
372 | } | |
373 | } | |
374 | ||
375 | msleep(36); | |
376 | ||
377 | /* m9206 will disconnect itself from the bus after this. */ | |
e2adbecf | 378 | (void) m9206_write(udev, M9206_CORE, 0x01, M9206_FW_GO); |
5fecd9fd AT |
379 | deb_rc("firmware uploaded!\n"); |
380 | ||
381 | done: | |
382 | kfree(buff); | |
383 | ||
384 | return ret; | |
385 | } | |
386 | ||
e16c1f55 | 387 | /* Callbacks for DVB USB */ |
7d1d4e6c AT |
388 | static 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) | |
e16c1f55 MK |
392 | { |
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 | ||
401 | static 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 | ||
426 | static struct mt352_config megasky_mt352_config = { | |
26247018 | 427 | .demod_address = 0x0f, |
e16c1f55 MK |
428 | .no_tuner = 1, |
429 | .demod_init = megasky_mt352_demod_init, | |
430 | }; | |
431 | ||
432 | static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap) | |
433 | { | |
e16c1f55 MK |
434 | deb_rc("megasky_frontend_attach!\n"); |
435 | ||
e16c1f55 MK |
436 | if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL) |
437 | return -EIO; | |
438 | ||
439 | return 0; | |
440 | } | |
441 | ||
cbdc80ed | 442 | static struct qt1010_config megasky_qt1010_config = { |
26247018 | 443 | .i2c_address = 0x62 |
cbdc80ed AP |
444 | }; |
445 | ||
e16c1f55 | 446 | static int megasky_qt1010_tuner_attach(struct dvb_usb_adapter *adap) |
cbdc80ed | 447 | { |
84ad7574 AT |
448 | if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, |
449 | &megasky_qt1010_config) == NULL) | |
450 | return -ENODEV; | |
451 | ||
452 | return 0; | |
cbdc80ed AP |
453 | } |
454 | ||
aa50ec2b NA |
455 | static struct m9206_inits megasky_rc_init [] = { |
456 | { M9206_RC_INIT2, 0xa8 }, | |
457 | { M9206_RC_INIT1, 0x51 }, | |
458 | { } /* terminating entry */ | |
459 | }; | |
460 | ||
d4ca23b1 PW |
461 | static 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 | ||
473 | static 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 | ||
484 | static 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 | ||
aa50ec2b NA |
492 | /* 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 | ||
499 | static 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 | ||
511 | static 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 | ||
523 | static 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 | ||
535 | static 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 | ||
547 | static 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 | ||
562 | static 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 | ||
577 | static 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 | ||
26f48eaa MK |
586 | /* DVB USB Driver stuff */ |
587 | static struct dvb_usb_device_properties megasky_properties; | |
d4ca23b1 | 588 | static struct dvb_usb_device_properties digivox_mini_ii_properties; |
aa50ec2b NA |
589 | static struct dvb_usb_device_properties tvwalkertwin_properties; |
590 | static struct m9206_inits megasky_rc_init []; | |
591 | static struct m9206_inits tvwalkertwin_rc_init []; | |
26f48eaa | 592 | |
fa94805d MK |
593 | static int m920x_probe(struct usb_interface *intf, |
594 | const struct usb_device_id *id) | |
26f48eaa MK |
595 | { |
596 | struct dvb_usb_device *d; | |
597 | struct usb_host_interface *alt; | |
598 | int ret; | |
aa50ec2b NA |
599 | struct m9206_inits *rc_init_seq = NULL; |
600 | int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber; | |
26f48eaa | 601 | |
aa50ec2b | 602 | deb_rc("Probing for m920x device at interface %d\n", bInterfaceNumber); |
26f48eaa | 603 | |
aa50ec2b NA |
604 | if (bInterfaceNumber == 0) { |
605 | /* Single-tuner device, or first interface on | |
606 | * multi-tuner device | |
607 | */ | |
26f48eaa | 608 | |
aa50ec2b NA |
609 | if ((ret = dvb_usb_device_init(intf, &megasky_properties, |
610 | THIS_MODULE, &d)) == 0) { | |
611 | rc_init_seq = megasky_rc_init; | |
612 | goto found; | |
613 | } | |
614 | ||
615 | if ((ret = dvb_usb_device_init(intf, | |
616 | &digivox_mini_ii_properties, THIS_MODULE, &d)) == 0) { | |
617 | /* No remote control, so no rc_init_seq */ | |
618 | goto found; | |
619 | } | |
620 | ||
621 | /* This configures both tuners on the TV Walker Twin */ | |
622 | if ((ret = dvb_usb_device_init(intf, &tvwalkertwin_properties, | |
623 | THIS_MODULE, &d)) == 0) { | |
624 | rc_init_seq = tvwalkertwin_rc_init; | |
625 | goto found; | |
626 | } | |
627 | ||
628 | return ret; | |
629 | } else { | |
630 | /* Another interface on a multi-tuner device */ | |
631 | ||
632 | /* The LifeView TV Walker Twin gets here, but struct | |
633 | * tvwalkertwin_properties already configured both | |
634 | * tuners, so there is nothing for us to do here | |
635 | */ | |
636 | ||
637 | return -ENODEV; | |
638 | } | |
26f48eaa | 639 | |
480ac761 AT |
640 | found: |
641 | alt = usb_altnum_to_altsetting(intf, 1); | |
642 | if (alt == NULL) { | |
643 | deb_rc("No alt found!\n"); | |
644 | return -ENODEV; | |
26f48eaa | 645 | } |
480ac761 AT |
646 | |
647 | ret = usb_set_interface(d->udev, alt->desc.bInterfaceNumber, | |
648 | alt->desc.bAlternateSetting); | |
649 | if (ret < 0) | |
650 | return ret; | |
651 | ||
aa50ec2b | 652 | if ((ret = m9206_init(d, rc_init_seq)) != 0) |
480ac761 AT |
653 | return ret; |
654 | ||
26f48eaa MK |
655 | return ret; |
656 | } | |
657 | ||
658 | static struct usb_device_id m920x_table [] = { | |
659 | { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) }, | |
d4ca23b1 PW |
660 | { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC, |
661 | USB_PID_MSI_DIGI_VOX_MINI_II) }, | |
aa50ec2b NA |
662 | { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC, |
663 | USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) }, | |
664 | { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC, | |
665 | USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) }, | |
26f48eaa MK |
666 | { } /* Terminating entry */ |
667 | }; | |
668 | MODULE_DEVICE_TABLE (usb, m920x_table); | |
669 | ||
01cb34db | 670 | static struct dvb_usb_device_properties megasky_properties = { |
758117c2 | 671 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, |
1f61f3ba | 672 | |
5fecd9fd AT |
673 | .usb_ctrl = DEVICE_SPECIFIC, |
674 | .firmware = "dvb-usb-megasky-02.fw", | |
675 | .download_firmware = m9206_firmware_download, | |
676 | ||
e2adbecf | 677 | .rc_interval = 100, |
5fecd9fd AT |
678 | .rc_key_map = megasky_rc_keys, |
679 | .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys), | |
680 | .rc_query = m9206_rc_query, | |
681 | ||
e2adbecf | 682 | .size_of_priv = sizeof(struct m9206_state), |
5fecd9fd | 683 | |
7d1d4e6c | 684 | .identify_state = m920x_identify_state, |
01cb34db MK |
685 | .num_adapters = 1, |
686 | .adapter = {{ | |
758117c2 MK |
687 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | |
688 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, | |
689 | ||
01cb34db MK |
690 | .pid_filter_count = 8, |
691 | .pid_filter = m9206_pid_filter, | |
692 | .pid_filter_ctrl = m9206_pid_filter_ctrl, | |
693 | ||
e16c1f55 MK |
694 | .frontend_attach = megasky_mt352_frontend_attach, |
695 | .tuner_attach = megasky_qt1010_tuner_attach, | |
01cb34db MK |
696 | |
697 | .stream = { | |
698 | .type = USB_BULK, | |
699 | .count = 8, | |
700 | .endpoint = 0x81, | |
701 | .u = { | |
702 | .bulk = { | |
703 | .buffersize = 512, | |
704 | } | |
705 | } | |
706 | }, | |
707 | }}, | |
5fecd9fd AT |
708 | .i2c_algo = &m9206_i2c_algo, |
709 | ||
5fecd9fd AT |
710 | .num_device_descs = 1, |
711 | .devices = { | |
712 | { "MSI Mega Sky 580 DVB-T USB2.0", | |
baa2ed09 | 713 | { &m920x_table[0], NULL }, |
5fecd9fd | 714 | { NULL }, |
d4ca23b1 PW |
715 | } |
716 | } | |
717 | }; | |
718 | ||
719 | static struct dvb_usb_device_properties digivox_mini_ii_properties = { | |
720 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | |
721 | ||
722 | .usb_ctrl = DEVICE_SPECIFIC, | |
723 | .firmware = "dvb-usb-digivox-02.fw", | |
724 | .download_firmware = m9206_firmware_download, | |
725 | ||
726 | .size_of_priv = sizeof(struct m9206_state), | |
727 | ||
728 | .identify_state = m920x_identify_state, | |
729 | .num_adapters = 1, | |
730 | .adapter = {{ | |
731 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | | |
732 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, | |
733 | ||
734 | .pid_filter_count = 8, | |
735 | .pid_filter = m9206_pid_filter, | |
736 | .pid_filter_ctrl = m9206_pid_filter_ctrl, | |
737 | ||
738 | .frontend_attach = digivox_tda10046_frontend_attach, | |
739 | .tuner_attach = digivox_tda8275_tuner_attach, | |
740 | ||
741 | .stream = { | |
742 | .type = USB_BULK, | |
743 | .count = 8, | |
744 | .endpoint = 0x81, | |
745 | .u = { | |
746 | .bulk = { | |
747 | .buffersize = 0x4000, | |
748 | } | |
749 | } | |
750 | }, | |
751 | }}, | |
752 | .i2c_algo = &m9206_i2c_algo, | |
753 | ||
754 | .num_device_descs = 1, | |
755 | .devices = { | |
756 | { "MSI DIGI VOX mini II DVB-T USB2.0", | |
757 | { &m920x_table[1], NULL }, | |
758 | { NULL }, | |
5fecd9fd | 759 | }, |
5fecd9fd AT |
760 | } |
761 | }; | |
762 | ||
aa50ec2b NA |
763 | /* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net> */ |
764 | ||
765 | static struct dvb_usb_device_properties tvwalkertwin_properties = { | |
766 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | |
767 | ||
768 | .usb_ctrl = DEVICE_SPECIFIC, | |
769 | .firmware = "dvb-usb-tvwalkert.fw", | |
770 | .download_firmware = m9206_firmware_download, | |
771 | ||
772 | .rc_interval = 100, | |
773 | .rc_key_map = tvwalkertwin_rc_keys, | |
774 | .rc_key_map_size = ARRAY_SIZE(tvwalkertwin_rc_keys), | |
775 | .rc_query = m9206_rc_query, | |
776 | ||
777 | .size_of_priv = sizeof(struct m9206_state), | |
778 | ||
779 | .identify_state = m920x_identify_state, | |
780 | .num_adapters = 2, | |
781 | .adapter = { | |
782 | { | |
783 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | | |
784 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, | |
785 | ||
786 | .pid_filter_count = 8, | |
787 | .pid_filter = m9206_pid_filter, | |
788 | .pid_filter_ctrl = m9206_pid_filter_ctrl, | |
789 | ||
790 | .frontend_attach = tvwalkertwin_0_tda10046_frontend_attach, | |
791 | .tuner_attach = tvwalkertwin_0_tda8275_tuner_attach, | |
792 | ||
793 | .stream = { | |
794 | .type = USB_BULK, | |
795 | .count = 8, | |
796 | .endpoint = 0x81, | |
797 | .u = { | |
798 | .bulk = { | |
799 | .buffersize = 512, | |
800 | } | |
801 | } | |
802 | }, | |
803 | }, | |
804 | { | |
805 | .caps = DVB_USB_ADAP_HAS_PID_FILTER | | |
806 | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, | |
807 | ||
808 | .pid_filter_count = 8, | |
809 | .pid_filter = m9206_pid_filter, | |
810 | .pid_filter_ctrl = m9206_pid_filter_ctrl, | |
811 | ||
812 | .frontend_attach = tvwalkertwin_1_tda10046_frontend_attach, | |
813 | .tuner_attach = tvwalkertwin_1_tda8275_tuner_attach, | |
814 | ||
815 | .stream = { | |
816 | .type = USB_BULK, | |
817 | .count = 8, | |
818 | .endpoint = 0x82, | |
819 | .u = { | |
820 | .bulk = { | |
821 | .buffersize = 512, | |
822 | } | |
823 | } | |
824 | }, | |
825 | } | |
826 | }, | |
827 | .i2c_algo = &m9206_i2c_algo, | |
828 | ||
829 | .num_device_descs = 1, | |
830 | .devices = { | |
831 | { .name = "LifeView TV Walker Twin DVB-T USB2.0", | |
832 | .cold_ids = { &m920x_table[2], NULL }, | |
833 | .warm_ids = { &m920x_table[3], NULL }, | |
834 | }, | |
835 | } | |
836 | }; | |
837 | ||
baa2ed09 MK |
838 | static struct usb_driver m920x_driver = { |
839 | .name = "dvb_usb_m920x", | |
2a2bfa7d | 840 | .probe = m920x_probe, |
5fecd9fd | 841 | .disconnect = dvb_usb_device_exit, |
baa2ed09 | 842 | .id_table = m920x_table, |
5fecd9fd AT |
843 | }; |
844 | ||
845 | /* module stuff */ | |
baa2ed09 | 846 | static int __init m920x_module_init(void) |
5fecd9fd AT |
847 | { |
848 | int ret; | |
849 | ||
baa2ed09 | 850 | if ((ret = usb_register(&m920x_driver))) { |
5fecd9fd AT |
851 | err("usb_register failed. Error number %d", ret); |
852 | return ret; | |
853 | } | |
854 | ||
855 | return 0; | |
856 | } | |
857 | ||
baa2ed09 | 858 | static void __exit m920x_module_exit(void) |
5fecd9fd AT |
859 | { |
860 | /* deregister this driver from the USB subsystem */ | |
baa2ed09 | 861 | usb_deregister(&m920x_driver); |
5fecd9fd AT |
862 | } |
863 | ||
baa2ed09 MK |
864 | module_init (m920x_module_init); |
865 | module_exit (m920x_module_exit); | |
5fecd9fd AT |
866 | |
867 | MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>"); | |
aa50ec2b | 868 | MODULE_DESCRIPTION("DVB Driver for ULI M920x"); |
5fecd9fd AT |
869 | MODULE_VERSION("0.1"); |
870 | MODULE_LICENSE("GPL"); | |
ce9c2750 MK |
871 | |
872 | /* | |
873 | * Local variables: | |
874 | * c-basic-offset: 8 | |
875 | */ |