[media] dvb-usb: add ATSC support for the Hauppauge WinTV-Aero-M
[deliverable/linux.git] / drivers / media / dvb / dvb-usb / ttusb2.c
CommitLineData
bc2e3913
PB
1/* DVB USB compliant linux driver for Technotrend DVB USB boxes and clones
2 * (e.g. Pinnacle 400e DVB-S USB2.0).
3 *
4 * The Pinnacle 400e uses the same protocol as the Technotrend USB1.1 boxes.
5 *
6 * TDA8263 + TDA10086
7 *
8 * I2C addresses:
9 * 0x08 - LNBP21PD - LNB power supply
10 * 0x0e - TDA10086 - Demodulator
11 * 0x50 - FX2 eeprom
12 * 0x60 - TDA8263 - Tuner
13 * 0x78 ???
14 *
15 * Copyright (c) 2002 Holger Waechtler <holger@convergence.de>
16 * Copyright (c) 2003 Felix Domke <tmbinc@elitedvb.net>
17 * Copyright (C) 2005-6 Patrick Boettcher <pb@linuxtv.org>
18 *
19 * This program is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by the Free
21 * Software Foundation, version 2.
22 *
23 * see Documentation/dvb/README.dvb-usb for more information
24 */
25#define DVB_USB_LOG_PREFIX "ttusb2"
26#include "dvb-usb.h"
27
28#include "ttusb2.h"
29
30#include "tda826x.h"
31#include "tda10086.h"
76952c7e 32#include "tda1002x.h"
c9f88aa9 33#include "tda10048.h"
76952c7e 34#include "tda827x.h"
bc2e3913
PB
35#include "lnbp21.h"
36
37/* debug */
38static int dvb_usb_ttusb2_debug;
39#define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args)
40module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
41MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
42
78e92006
JG
43DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44
bc2e3913
PB
45struct ttusb2_state {
46 u8 id;
9d1da730 47 u16 last_rc_key;
bc2e3913
PB
48};
49
50static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
51 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
52{
53 struct ttusb2_state *st = d->priv;
54 u8 s[wlen+4],r[64] = { 0 };
55 int ret = 0;
56
57 memset(s,0,wlen+4);
58
59 s[0] = 0xaa;
60 s[1] = ++st->id;
61 s[2] = cmd;
62 s[3] = wlen;
63 memcpy(&s[4],wbuf,wlen);
64
65 ret = dvb_usb_generic_rw(d, s, wlen+4, r, 64, 0);
66
67 if (ret != 0 ||
68 r[0] != 0x55 ||
69 r[1] != s[1] ||
70 r[2] != cmd ||
71 (rlen > 0 && r[3] != rlen)) {
72 warn("there might have been an error during control message transfer. (rlen = %d, was %d)",rlen,r[3]);
73 return -EIO;
74 }
75
76 if (rlen > 0)
77 memcpy(rbuf, &r[4], rlen);
78
79 return 0;
80}
81
82static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
83{
84 struct dvb_usb_device *d = i2c_get_adapdata(adap);
85 static u8 obuf[60], ibuf[60];
c9f88aa9 86 int i, write_read, read;
bc2e3913
PB
87
88 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
89 return -EAGAIN;
90
91 if (num > 2)
92 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
93
94 for (i = 0; i < num; i++) {
c9f88aa9
JAR
95 write_read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
96 read = msg[i].flags & I2C_M_RD;
bc2e3913 97
c9f88aa9
JAR
98 obuf[0] = (msg[i].addr << 1) | (write_read | read);
99 if (read)
100 obuf[1] = 0;
101 else
102 obuf[1] = msg[i].len;
bc2e3913
PB
103
104 /* read request */
c9f88aa9 105 if (write_read)
bc2e3913 106 obuf[2] = msg[i+1].len;
c9f88aa9
JAR
107 else if (read)
108 obuf[2] = msg[i].len;
bc2e3913
PB
109 else
110 obuf[2] = 0;
111
c9f88aa9 112 memcpy(&obuf[3], msg[i].buf, msg[i].len);
bc2e3913
PB
113
114 if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) {
115 err("i2c transfer failed.");
116 break;
117 }
118
c9f88aa9
JAR
119 if (write_read) {
120 memcpy(msg[i+1].buf, &ibuf[3], msg[i+1].len);
bc2e3913 121 i++;
c9f88aa9
JAR
122 } else if (read)
123 memcpy(msg[i].buf, &ibuf[3], msg[i].len);
bc2e3913
PB
124 }
125
126 mutex_unlock(&d->i2c_mutex);
127 return i;
128}
129
130static u32 ttusb2_i2c_func(struct i2c_adapter *adapter)
131{
132 return I2C_FUNC_I2C;
133}
134
135static struct i2c_algorithm ttusb2_i2c_algo = {
136 .master_xfer = ttusb2_i2c_xfer,
137 .functionality = ttusb2_i2c_func,
138};
139
9d1da730
DH
140/* command to poll IR receiver (copied from pctv452e.c) */
141#define CMD_GET_IR_CODE 0x1b
142
143/* IR */
144static int tt3650_rc_query(struct dvb_usb_device *d)
145{
146 int ret;
147 u8 rx[9]; /* A CMD_GET_IR_CODE reply is 9 bytes long */
148 struct ttusb2_state *st = d->priv;
149 ret = ttusb2_msg(d, CMD_GET_IR_CODE, NULL, 0, rx, sizeof(rx));
150 if (ret != 0)
151 return ret;
152
153 if (rx[8] & 0x01) {
154 /* got a "press" event */
155 st->last_rc_key = (rx[3] << 8) | rx[2];
156 deb_info("%s: cmd=0x%02x sys=0x%02x\n", __func__, rx[2], rx[3]);
157 rc_keydown(d->rc_dev, st->last_rc_key, 0);
158 } else if (st->last_rc_key) {
159 rc_keyup(d->rc_dev);
160 st->last_rc_key = 0;
161 }
162
163 return 0;
164}
165
166
bc2e3913
PB
167/* Callbacks for DVB USB */
168static int ttusb2_identify_state (struct usb_device *udev, struct
169 dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,
170 int *cold)
171{
172 *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;
173 return 0;
174}
175
176static int ttusb2_power_ctrl(struct dvb_usb_device *d, int onoff)
177{
178 u8 b = onoff;
179 ttusb2_msg(d, CMD_POWER, &b, 0, NULL, 0);
180 return ttusb2_msg(d, CMD_POWER, &b, 1, NULL, 0);
181}
182
183
184static struct tda10086_config tda10086_config = {
185 .demod_address = 0x0e,
186 .invert = 0,
ea75baf4 187 .diseqc_tone = 1,
9a1b04e4 188 .xtal_freq = TDA10086_XTAL_16M,
bc2e3913
PB
189};
190
76952c7e
GM
191static struct tda10023_config tda10023_config = {
192 .demod_address = 0x0c,
193 .invert = 0,
194 .xtal = 16000000,
195 .pll_m = 11,
196 .pll_p = 3,
197 .pll_n = 1,
198 .deltaf = 0xa511,
199};
200
c9f88aa9
JAR
201static struct tda10048_config tda10048_config = {
202 .demod_address = 0x10 >> 1,
203 .output_mode = TDA10048_PARALLEL_OUTPUT,
204 .inversion = TDA10048_INVERSION_ON,
205 .dtv6_if_freq_khz = TDA10048_IF_4000,
206 .dtv7_if_freq_khz = TDA10048_IF_4500,
207 .dtv8_if_freq_khz = TDA10048_IF_5000,
208 .clk_freq_khz = TDA10048_CLK_16000,
209 .no_firmware = 1,
210 .set_pll = true ,
211 .pll_m = 5,
212 .pll_n = 3,
213 .pll_p = 0,
214};
215
216static struct tda827x_config tda827x_config = {
217 .config = 0,
218};
219
76952c7e 220static int ttusb2_frontend_tda10086_attach(struct dvb_usb_adapter *adap)
bc2e3913
PB
221{
222 if (usb_set_interface(adap->dev->udev,0,3) < 0)
223 err("set interface to alts=3 failed");
224
bfd4500c 225 if ((adap->fe[0] = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
bc2e3913
PB
226 deb_info("TDA10086 attach failed\n");
227 return -ENODEV;
228 }
229
230 return 0;
231}
232
c9f88aa9
JAR
233static int ttusb2_ct3650_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
234{
235 struct dvb_usb_adapter *adap = fe->dvb->priv;
236
237 return adap->fe[0]->ops.i2c_gate_ctrl(adap->fe[0], enable);
238}
239
76952c7e
GM
240static int ttusb2_frontend_tda10023_attach(struct dvb_usb_adapter *adap)
241{
242 if (usb_set_interface(adap->dev->udev, 0, 3) < 0)
243 err("set interface to alts=3 failed");
c9f88aa9
JAR
244
245 if (adap->fe[0] == NULL) {
246 /* FE 0 DVB-C */
247 adap->fe[0] = dvb_attach(tda10023_attach,
248 &tda10023_config, &adap->dev->i2c_adap, 0x48);
249
250 if (adap->fe[0] == NULL) {
251 deb_info("TDA10023 attach failed\n");
252 return -ENODEV;
253 }
254 } else {
255 adap->fe[1] = dvb_attach(tda10048_attach,
256 &tda10048_config, &adap->dev->i2c_adap);
257
258 if (adap->fe[1] == NULL) {
259 deb_info("TDA10048 attach failed\n");
260 return -ENODEV;
261 }
262
263 /* tuner is behind TDA10023 I2C-gate */
264 adap->fe[1]->ops.i2c_gate_ctrl = ttusb2_ct3650_i2c_gate_ctrl;
265
76952c7e 266 }
c9f88aa9 267
76952c7e
GM
268 return 0;
269}
270
271static int ttusb2_tuner_tda827x_attach(struct dvb_usb_adapter *adap)
272{
c9f88aa9
JAR
273 struct dvb_frontend *fe;
274
275 /* MFE: select correct FE to attach tuner since that's called twice */
276 if (adap->fe[1] == NULL)
277 fe = adap->fe[0];
278 else
279 fe = adap->fe[1];
280
281 /* attach tuner */
282 if (dvb_attach(tda827x_attach, fe, 0x61, &adap->dev->i2c_adap, &tda827x_config) == NULL) {
76952c7e
GM
283 printk(KERN_ERR "%s: No tda827x found!\n", __func__);
284 return -ENODEV;
285 }
286 return 0;
287}
288
289static int ttusb2_tuner_tda826x_attach(struct dvb_usb_adapter *adap)
bc2e3913 290{
bfd4500c 291 if (dvb_attach(tda826x_attach, adap->fe[0], 0x60, &adap->dev->i2c_adap, 0) == NULL) {
bc2e3913
PB
292 deb_info("TDA8263 attach failed\n");
293 return -ENODEV;
294 }
295
bfd4500c 296 if (dvb_attach(lnbp21_attach, adap->fe[0], &adap->dev->i2c_adap, 0, 0) == NULL) {
bc2e3913
PB
297 deb_info("LNBP21 attach failed\n");
298 return -ENODEV;
299 }
300 return 0;
301}
302
303/* DVB USB Driver stuff */
304static struct dvb_usb_device_properties ttusb2_properties;
8c899bce 305static struct dvb_usb_device_properties ttusb2_properties_s2400;
76952c7e 306static struct dvb_usb_device_properties ttusb2_properties_ct3650;
bc2e3913
PB
307
308static int ttusb2_probe(struct usb_interface *intf,
309 const struct usb_device_id *id)
310{
78e92006
JG
311 if (0 == dvb_usb_device_init(intf, &ttusb2_properties,
312 THIS_MODULE, NULL, adapter_nr) ||
313 0 == dvb_usb_device_init(intf, &ttusb2_properties_s2400,
76952c7e
GM
314 THIS_MODULE, NULL, adapter_nr) ||
315 0 == dvb_usb_device_init(intf, &ttusb2_properties_ct3650,
78e92006 316 THIS_MODULE, NULL, adapter_nr))
8c899bce
AW
317 return 0;
318 return -ENODEV;
bc2e3913
PB
319}
320
321static struct usb_device_id ttusb2_table [] = {
8c899bce
AW
322 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) },
323 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) },
324 { USB_DEVICE(USB_VID_TECHNOTREND,
325 USB_PID_TECHNOTREND_CONNECT_S2400) },
76952c7e
GM
326 { USB_DEVICE(USB_VID_TECHNOTREND,
327 USB_PID_TECHNOTREND_CONNECT_CT3650) },
8c899bce 328 {} /* Terminating entry */
bc2e3913
PB
329};
330MODULE_DEVICE_TABLE (usb, ttusb2_table);
331
332static struct dvb_usb_device_properties ttusb2_properties = {
333 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
334
335 .usb_ctrl = CYPRESS_FX2,
336 .firmware = "dvb-usb-pctv-400e-01.fw",
337
338 .size_of_priv = sizeof(struct ttusb2_state),
339
340 .num_adapters = 1,
341 .adapter = {
342 {
343 .streaming_ctrl = NULL, // ttusb2_streaming_ctrl,
344
76952c7e
GM
345 .frontend_attach = ttusb2_frontend_tda10086_attach,
346 .tuner_attach = ttusb2_tuner_tda826x_attach,
bc2e3913
PB
347
348 /* parameter for the MPEG2-data transfer */
349 .stream = {
350 .type = USB_ISOC,
351 .count = 5,
352 .endpoint = 0x02,
353 .u = {
354 .isoc = {
355 .framesperurb = 4,
356 .framesize = 940,
357 .interval = 1,
358 }
359 }
360 }
361 }
362 },
363
364 .power_ctrl = ttusb2_power_ctrl,
365 .identify_state = ttusb2_identify_state,
366
367 .i2c_algo = &ttusb2_i2c_algo,
368
369 .generic_bulk_ctrl_endpoint = 0x01,
370
ddc9ece8 371 .num_device_descs = 2,
bc2e3913
PB
372 .devices = {
373 { "Pinnacle 400e DVB-S USB2.0",
374 { &ttusb2_table[0], NULL },
375 { NULL },
376 },
ddc9ece8
CC
377 { "Pinnacle 450e DVB-S USB2.0",
378 { &ttusb2_table[1], NULL },
379 { NULL },
380 },
bc2e3913
PB
381 }
382};
383
8c899bce
AW
384static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
385 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
386
387 .usb_ctrl = CYPRESS_FX2,
388 .firmware = "dvb-usb-tt-s2400-01.fw",
389
390 .size_of_priv = sizeof(struct ttusb2_state),
391
392 .num_adapters = 1,
393 .adapter = {
394 {
395 .streaming_ctrl = NULL,
396
76952c7e
GM
397 .frontend_attach = ttusb2_frontend_tda10086_attach,
398 .tuner_attach = ttusb2_tuner_tda826x_attach,
8c899bce
AW
399
400 /* parameter for the MPEG2-data transfer */
401 .stream = {
402 .type = USB_ISOC,
403 .count = 5,
404 .endpoint = 0x02,
405 .u = {
406 .isoc = {
407 .framesperurb = 4,
408 .framesize = 940,
409 .interval = 1,
410 }
411 }
412 }
413 }
414 },
415
416 .power_ctrl = ttusb2_power_ctrl,
417 .identify_state = ttusb2_identify_state,
418
419 .i2c_algo = &ttusb2_i2c_algo,
420
421 .generic_bulk_ctrl_endpoint = 0x01,
422
423 .num_device_descs = 1,
424 .devices = {
425 { "Technotrend TT-connect S-2400",
426 { &ttusb2_table[2], NULL },
427 { NULL },
428 },
429 }
430};
431
76952c7e
GM
432static struct dvb_usb_device_properties ttusb2_properties_ct3650 = {
433 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
434
435 .usb_ctrl = CYPRESS_FX2,
436
437 .size_of_priv = sizeof(struct ttusb2_state),
438
9d1da730
DH
439 .rc.core = {
440 .rc_interval = 150, /* Less than IR_KEYPRESS_TIMEOUT */
441 .rc_codes = RC_MAP_TT_1500,
442 .rc_query = tt3650_rc_query,
443 .allowed_protos = RC_TYPE_UNKNOWN,
444 },
445
76952c7e
GM
446 .num_adapters = 1,
447 .adapter = {
448 {
449 .streaming_ctrl = NULL,
450
c9f88aa9 451 .num_frontends = 2,
76952c7e
GM
452 .frontend_attach = ttusb2_frontend_tda10023_attach,
453 .tuner_attach = ttusb2_tuner_tda827x_attach,
454
455 /* parameter for the MPEG2-data transfer */
456 .stream = {
457 .type = USB_ISOC,
458 .count = 5,
459 .endpoint = 0x02,
460 .u = {
461 .isoc = {
462 .framesperurb = 4,
463 .framesize = 940,
464 .interval = 1,
465 }
466 }
467 }
468 },
469 },
470
471 .power_ctrl = ttusb2_power_ctrl,
472 .identify_state = ttusb2_identify_state,
473
474 .i2c_algo = &ttusb2_i2c_algo,
475
476 .generic_bulk_ctrl_endpoint = 0x01,
477
478 .num_device_descs = 1,
479 .devices = {
480 { "Technotrend TT-connect CT-3650",
481 .warm_ids = { &ttusb2_table[3], NULL },
482 },
483 }
484};
485
bc2e3913
PB
486static struct usb_driver ttusb2_driver = {
487 .name = "dvb_usb_ttusb2",
488 .probe = ttusb2_probe,
489 .disconnect = dvb_usb_device_exit,
490 .id_table = ttusb2_table,
491};
492
493/* module stuff */
494static int __init ttusb2_module_init(void)
495{
496 int result;
497 if ((result = usb_register(&ttusb2_driver))) {
498 err("usb_register failed. Error number %d",result);
499 return result;
500 }
501
502 return 0;
503}
504
505static void __exit ttusb2_module_exit(void)
506{
507 /* deregister this driver from the USB subsystem */
508 usb_deregister(&ttusb2_driver);
509}
510
511module_init (ttusb2_module_init);
512module_exit (ttusb2_module_exit);
513
514MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
515MODULE_DESCRIPTION("Driver for Pinnacle PCTV 400e DVB-S USB2.0");
516MODULE_VERSION("1.0");
517MODULE_LICENSE("GPL");
This page took 0.929101 seconds and 5 git commands to generate.