diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/media/dvb/dvb-usb/ttusb2.c | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'drivers/media/dvb/dvb-usb/ttusb2.c')
-rw-r--r-- | drivers/media/dvb/dvb-usb/ttusb2.c | 453 |
1 files changed, 453 insertions, 0 deletions
diff --git a/drivers/media/dvb/dvb-usb/ttusb2.c b/drivers/media/dvb/dvb-usb/ttusb2.c new file mode 100644 index 00000000000..0d4709ff9cb --- /dev/null +++ b/drivers/media/dvb/dvb-usb/ttusb2.c | |||
@@ -0,0 +1,453 @@ | |||
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" | ||
32 | #include "tda1002x.h" | ||
33 | #include "tda827x.h" | ||
34 | #include "lnbp21.h" | ||
35 | |||
36 | /* debug */ | ||
37 | static int dvb_usb_ttusb2_debug; | ||
38 | #define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args) | ||
39 | module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644); | ||
40 | MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS); | ||
41 | |||
42 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); | ||
43 | |||
44 | struct ttusb2_state { | ||
45 | u8 id; | ||
46 | u16 last_rc_key; | ||
47 | }; | ||
48 | |||
49 | static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd, | ||
50 | u8 *wbuf, int wlen, u8 *rbuf, int rlen) | ||
51 | { | ||
52 | struct ttusb2_state *st = d->priv; | ||
53 | u8 s[wlen+4],r[64] = { 0 }; | ||
54 | int ret = 0; | ||
55 | |||
56 | memset(s,0,wlen+4); | ||
57 | |||
58 | s[0] = 0xaa; | ||
59 | s[1] = ++st->id; | ||
60 | s[2] = cmd; | ||
61 | s[3] = wlen; | ||
62 | memcpy(&s[4],wbuf,wlen); | ||
63 | |||
64 | ret = dvb_usb_generic_rw(d, s, wlen+4, r, 64, 0); | ||
65 | |||
66 | if (ret != 0 || | ||
67 | r[0] != 0x55 || | ||
68 | r[1] != s[1] || | ||
69 | r[2] != cmd || | ||
70 | (rlen > 0 && r[3] != rlen)) { | ||
71 | warn("there might have been an error during control message transfer. (rlen = %d, was %d)",rlen,r[3]); | ||
72 | return -EIO; | ||
73 | } | ||
74 | |||
75 | if (rlen > 0) | ||
76 | memcpy(rbuf, &r[4], rlen); | ||
77 | |||
78 | return 0; | ||
79 | } | ||
80 | |||
81 | static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num) | ||
82 | { | ||
83 | struct dvb_usb_device *d = i2c_get_adapdata(adap); | ||
84 | static u8 obuf[60], ibuf[60]; | ||
85 | int i,read; | ||
86 | |||
87 | if (mutex_lock_interruptible(&d->i2c_mutex) < 0) | ||
88 | return -EAGAIN; | ||
89 | |||
90 | if (num > 2) | ||
91 | warn("more than 2 i2c messages at a time is not handled yet. TODO."); | ||
92 | |||
93 | for (i = 0; i < num; i++) { | ||
94 | read = i+1 < num && (msg[i+1].flags & I2C_M_RD); | ||
95 | |||
96 | obuf[0] = (msg[i].addr << 1) | read; | ||
97 | obuf[1] = msg[i].len; | ||
98 | |||
99 | /* read request */ | ||
100 | if (read) | ||
101 | obuf[2] = msg[i+1].len; | ||
102 | else | ||
103 | obuf[2] = 0; | ||
104 | |||
105 | memcpy(&obuf[3],msg[i].buf,msg[i].len); | ||
106 | |||
107 | if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) { | ||
108 | err("i2c transfer failed."); | ||
109 | break; | ||
110 | } | ||
111 | |||
112 | if (read) { | ||
113 | memcpy(msg[i+1].buf,&ibuf[3],msg[i+1].len); | ||
114 | i++; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | mutex_unlock(&d->i2c_mutex); | ||
119 | return i; | ||
120 | } | ||
121 | |||
122 | static u32 ttusb2_i2c_func(struct i2c_adapter *adapter) | ||
123 | { | ||
124 | return I2C_FUNC_I2C; | ||
125 | } | ||
126 | |||
127 | static struct i2c_algorithm ttusb2_i2c_algo = { | ||
128 | .master_xfer = ttusb2_i2c_xfer, | ||
129 | .functionality = ttusb2_i2c_func, | ||
130 | }; | ||
131 | |||
132 | /* command to poll IR receiver (copied from pctv452e.c) */ | ||
133 | #define CMD_GET_IR_CODE 0x1b | ||
134 | |||
135 | /* IR */ | ||
136 | static int tt3650_rc_query(struct dvb_usb_device *d) | ||
137 | { | ||
138 | int ret; | ||
139 | u8 rx[9]; /* A CMD_GET_IR_CODE reply is 9 bytes long */ | ||
140 | struct ttusb2_state *st = d->priv; | ||
141 | ret = ttusb2_msg(d, CMD_GET_IR_CODE, NULL, 0, rx, sizeof(rx)); | ||
142 | if (ret != 0) | ||
143 | return ret; | ||
144 | |||
145 | if (rx[8] & 0x01) { | ||
146 | /* got a "press" event */ | ||
147 | st->last_rc_key = (rx[3] << 8) | rx[2]; | ||
148 | deb_info("%s: cmd=0x%02x sys=0x%02x\n", __func__, rx[2], rx[3]); | ||
149 | rc_keydown(d->rc_dev, st->last_rc_key, 0); | ||
150 | } else if (st->last_rc_key) { | ||
151 | rc_keyup(d->rc_dev); | ||
152 | st->last_rc_key = 0; | ||
153 | } | ||
154 | |||
155 | return 0; | ||
156 | } | ||
157 | |||
158 | |||
159 | /* Callbacks for DVB USB */ | ||
160 | static int ttusb2_identify_state (struct usb_device *udev, struct | ||
161 | dvb_usb_device_properties *props, struct dvb_usb_device_description **desc, | ||
162 | int *cold) | ||
163 | { | ||
164 | *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0; | ||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static int ttusb2_power_ctrl(struct dvb_usb_device *d, int onoff) | ||
169 | { | ||
170 | u8 b = onoff; | ||
171 | ttusb2_msg(d, CMD_POWER, &b, 0, NULL, 0); | ||
172 | return ttusb2_msg(d, CMD_POWER, &b, 1, NULL, 0); | ||
173 | } | ||
174 | |||
175 | |||
176 | static struct tda10086_config tda10086_config = { | ||
177 | .demod_address = 0x0e, | ||
178 | .invert = 0, | ||
179 | .diseqc_tone = 1, | ||
180 | .xtal_freq = TDA10086_XTAL_16M, | ||
181 | }; | ||
182 | |||
183 | static struct tda10023_config tda10023_config = { | ||
184 | .demod_address = 0x0c, | ||
185 | .invert = 0, | ||
186 | .xtal = 16000000, | ||
187 | .pll_m = 11, | ||
188 | .pll_p = 3, | ||
189 | .pll_n = 1, | ||
190 | .deltaf = 0xa511, | ||
191 | }; | ||
192 | |||
193 | static int ttusb2_frontend_tda10086_attach(struct dvb_usb_adapter *adap) | ||
194 | { | ||
195 | if (usb_set_interface(adap->dev->udev,0,3) < 0) | ||
196 | err("set interface to alts=3 failed"); | ||
197 | |||
198 | if ((adap->fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) { | ||
199 | deb_info("TDA10086 attach failed\n"); | ||
200 | return -ENODEV; | ||
201 | } | ||
202 | |||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | static int ttusb2_frontend_tda10023_attach(struct dvb_usb_adapter *adap) | ||
207 | { | ||
208 | if (usb_set_interface(adap->dev->udev, 0, 3) < 0) | ||
209 | err("set interface to alts=3 failed"); | ||
210 | if ((adap->fe = dvb_attach(tda10023_attach, &tda10023_config, &adap->dev->i2c_adap, 0x48)) == NULL) { | ||
211 | deb_info("TDA10023 attach failed\n"); | ||
212 | return -ENODEV; | ||
213 | } | ||
214 | return 0; | ||
215 | } | ||
216 | |||
217 | static int ttusb2_tuner_tda827x_attach(struct dvb_usb_adapter *adap) | ||
218 | { | ||
219 | if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL) { | ||
220 | printk(KERN_ERR "%s: No tda827x found!\n", __func__); | ||
221 | return -ENODEV; | ||
222 | } | ||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | static int ttusb2_tuner_tda826x_attach(struct dvb_usb_adapter *adap) | ||
227 | { | ||
228 | if (dvb_attach(tda826x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, 0) == NULL) { | ||
229 | deb_info("TDA8263 attach failed\n"); | ||
230 | return -ENODEV; | ||
231 | } | ||
232 | |||
233 | if (dvb_attach(lnbp21_attach, adap->fe, &adap->dev->i2c_adap, 0, 0) == NULL) { | ||
234 | deb_info("LNBP21 attach failed\n"); | ||
235 | return -ENODEV; | ||
236 | } | ||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | /* DVB USB Driver stuff */ | ||
241 | static struct dvb_usb_device_properties ttusb2_properties; | ||
242 | static struct dvb_usb_device_properties ttusb2_properties_s2400; | ||
243 | static struct dvb_usb_device_properties ttusb2_properties_ct3650; | ||
244 | |||
245 | static int ttusb2_probe(struct usb_interface *intf, | ||
246 | const struct usb_device_id *id) | ||
247 | { | ||
248 | if (0 == dvb_usb_device_init(intf, &ttusb2_properties, | ||
249 | THIS_MODULE, NULL, adapter_nr) || | ||
250 | 0 == dvb_usb_device_init(intf, &ttusb2_properties_s2400, | ||
251 | THIS_MODULE, NULL, adapter_nr) || | ||
252 | 0 == dvb_usb_device_init(intf, &ttusb2_properties_ct3650, | ||
253 | THIS_MODULE, NULL, adapter_nr)) | ||
254 | return 0; | ||
255 | return -ENODEV; | ||
256 | } | ||
257 | |||
258 | static struct usb_device_id ttusb2_table [] = { | ||
259 | { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) }, | ||
260 | { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) }, | ||
261 | { USB_DEVICE(USB_VID_TECHNOTREND, | ||
262 | USB_PID_TECHNOTREND_CONNECT_S2400) }, | ||
263 | { USB_DEVICE(USB_VID_TECHNOTREND, | ||
264 | USB_PID_TECHNOTREND_CONNECT_CT3650) }, | ||
265 | {} /* Terminating entry */ | ||
266 | }; | ||
267 | MODULE_DEVICE_TABLE (usb, ttusb2_table); | ||
268 | |||
269 | static struct dvb_usb_device_properties ttusb2_properties = { | ||
270 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | ||
271 | |||
272 | .usb_ctrl = CYPRESS_FX2, | ||
273 | .firmware = "dvb-usb-pctv-400e-01.fw", | ||
274 | |||
275 | .size_of_priv = sizeof(struct ttusb2_state), | ||
276 | |||
277 | .num_adapters = 1, | ||
278 | .adapter = { | ||
279 | { | ||
280 | .streaming_ctrl = NULL, // ttusb2_streaming_ctrl, | ||
281 | |||
282 | .frontend_attach = ttusb2_frontend_tda10086_attach, | ||
283 | .tuner_attach = ttusb2_tuner_tda826x_attach, | ||
284 | |||
285 | /* parameter for the MPEG2-data transfer */ | ||
286 | .stream = { | ||
287 | .type = USB_ISOC, | ||
288 | .count = 5, | ||
289 | .endpoint = 0x02, | ||
290 | .u = { | ||
291 | .isoc = { | ||
292 | .framesperurb = 4, | ||
293 | .framesize = 940, | ||
294 | .interval = 1, | ||
295 | } | ||
296 | } | ||
297 | } | ||
298 | } | ||
299 | }, | ||
300 | |||
301 | .power_ctrl = ttusb2_power_ctrl, | ||
302 | .identify_state = ttusb2_identify_state, | ||
303 | |||
304 | .i2c_algo = &ttusb2_i2c_algo, | ||
305 | |||
306 | .generic_bulk_ctrl_endpoint = 0x01, | ||
307 | |||
308 | .num_device_descs = 2, | ||
309 | .devices = { | ||
310 | { "Pinnacle 400e DVB-S USB2.0", | ||
311 | { &ttusb2_table[0], NULL }, | ||
312 | { NULL }, | ||
313 | }, | ||
314 | { "Pinnacle 450e DVB-S USB2.0", | ||
315 | { &ttusb2_table[1], NULL }, | ||
316 | { NULL }, | ||
317 | }, | ||
318 | } | ||
319 | }; | ||
320 | |||
321 | static struct dvb_usb_device_properties ttusb2_properties_s2400 = { | ||
322 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | ||
323 | |||
324 | .usb_ctrl = CYPRESS_FX2, | ||
325 | .firmware = "dvb-usb-tt-s2400-01.fw", | ||
326 | |||
327 | .size_of_priv = sizeof(struct ttusb2_state), | ||
328 | |||
329 | .num_adapters = 1, | ||
330 | .adapter = { | ||
331 | { | ||
332 | .streaming_ctrl = NULL, | ||
333 | |||
334 | .frontend_attach = ttusb2_frontend_tda10086_attach, | ||
335 | .tuner_attach = ttusb2_tuner_tda826x_attach, | ||
336 | |||
337 | /* parameter for the MPEG2-data transfer */ | ||
338 | .stream = { | ||
339 | .type = USB_ISOC, | ||
340 | .count = 5, | ||
341 | .endpoint = 0x02, | ||
342 | .u = { | ||
343 | .isoc = { | ||
344 | .framesperurb = 4, | ||
345 | .framesize = 940, | ||
346 | .interval = 1, | ||
347 | } | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | }, | ||
352 | |||
353 | .power_ctrl = ttusb2_power_ctrl, | ||
354 | .identify_state = ttusb2_identify_state, | ||
355 | |||
356 | .i2c_algo = &ttusb2_i2c_algo, | ||
357 | |||
358 | .generic_bulk_ctrl_endpoint = 0x01, | ||
359 | |||
360 | .num_device_descs = 1, | ||
361 | .devices = { | ||
362 | { "Technotrend TT-connect S-2400", | ||
363 | { &ttusb2_table[2], NULL }, | ||
364 | { NULL }, | ||
365 | }, | ||
366 | } | ||
367 | }; | ||
368 | |||
369 | static struct dvb_usb_device_properties ttusb2_properties_ct3650 = { | ||
370 | .caps = DVB_USB_IS_AN_I2C_ADAPTER, | ||
371 | |||
372 | .usb_ctrl = CYPRESS_FX2, | ||
373 | |||
374 | .size_of_priv = sizeof(struct ttusb2_state), | ||
375 | |||
376 | .rc.core = { | ||
377 | .rc_interval = 150, /* Less than IR_KEYPRESS_TIMEOUT */ | ||
378 | .rc_codes = RC_MAP_TT_1500, | ||
379 | .rc_query = tt3650_rc_query, | ||
380 | .allowed_protos = RC_TYPE_UNKNOWN, | ||
381 | }, | ||
382 | |||
383 | .num_adapters = 1, | ||
384 | .adapter = { | ||
385 | { | ||
386 | .streaming_ctrl = NULL, | ||
387 | |||
388 | .frontend_attach = ttusb2_frontend_tda10023_attach, | ||
389 | .tuner_attach = ttusb2_tuner_tda827x_attach, | ||
390 | |||
391 | /* parameter for the MPEG2-data transfer */ | ||
392 | .stream = { | ||
393 | .type = USB_ISOC, | ||
394 | .count = 5, | ||
395 | .endpoint = 0x02, | ||
396 | .u = { | ||
397 | .isoc = { | ||
398 | .framesperurb = 4, | ||
399 | .framesize = 940, | ||
400 | .interval = 1, | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | }, | ||
405 | }, | ||
406 | |||
407 | .power_ctrl = ttusb2_power_ctrl, | ||
408 | .identify_state = ttusb2_identify_state, | ||
409 | |||
410 | .i2c_algo = &ttusb2_i2c_algo, | ||
411 | |||
412 | .generic_bulk_ctrl_endpoint = 0x01, | ||
413 | |||
414 | .num_device_descs = 1, | ||
415 | .devices = { | ||
416 | { "Technotrend TT-connect CT-3650", | ||
417 | .warm_ids = { &ttusb2_table[3], NULL }, | ||
418 | }, | ||
419 | } | ||
420 | }; | ||
421 | |||
422 | static struct usb_driver ttusb2_driver = { | ||
423 | .name = "dvb_usb_ttusb2", | ||
424 | .probe = ttusb2_probe, | ||
425 | .disconnect = dvb_usb_device_exit, | ||
426 | .id_table = ttusb2_table, | ||
427 | }; | ||
428 | |||
429 | /* module stuff */ | ||
430 | static int __init ttusb2_module_init(void) | ||
431 | { | ||
432 | int result; | ||
433 | if ((result = usb_register(&ttusb2_driver))) { | ||
434 | err("usb_register failed. Error number %d",result); | ||
435 | return result; | ||
436 | } | ||
437 | |||
438 | return 0; | ||
439 | } | ||
440 | |||
441 | static void __exit ttusb2_module_exit(void) | ||
442 | { | ||
443 | /* deregister this driver from the USB subsystem */ | ||
444 | usb_deregister(&ttusb2_driver); | ||
445 | } | ||
446 | |||
447 | module_init (ttusb2_module_init); | ||
448 | module_exit (ttusb2_module_exit); | ||
449 | |||
450 | MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); | ||
451 | MODULE_DESCRIPTION("Driver for Pinnacle PCTV 400e DVB-S USB2.0"); | ||
452 | MODULE_VERSION("1.0"); | ||
453 | MODULE_LICENSE("GPL"); | ||