blob: 706687c78506e8d34a7231671bf7107bac431b15 [file] [log] [blame]
Patrick Boettcherbc2e3912006-12-02 21:16:04 -02001/* 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 "lnbp21.h"
33
34/* debug */
35static int dvb_usb_ttusb2_debug;
36#define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args)
37module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
38MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
39
Janne Grunau78e92002008-04-09 19:13:13 -030040DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
41
Patrick Boettcherbc2e3912006-12-02 21:16:04 -020042struct ttusb2_state {
43 u8 id;
44};
45
46static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
47 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
48{
49 struct ttusb2_state *st = d->priv;
50 u8 s[wlen+4],r[64] = { 0 };
51 int ret = 0;
52
53 memset(s,0,wlen+4);
54
55 s[0] = 0xaa;
56 s[1] = ++st->id;
57 s[2] = cmd;
58 s[3] = wlen;
59 memcpy(&s[4],wbuf,wlen);
60
61 ret = dvb_usb_generic_rw(d, s, wlen+4, r, 64, 0);
62
63 if (ret != 0 ||
64 r[0] != 0x55 ||
65 r[1] != s[1] ||
66 r[2] != cmd ||
67 (rlen > 0 && r[3] != rlen)) {
68 warn("there might have been an error during control message transfer. (rlen = %d, was %d)",rlen,r[3]);
69 return -EIO;
70 }
71
72 if (rlen > 0)
73 memcpy(rbuf, &r[4], rlen);
74
75 return 0;
76}
77
78static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
79{
80 struct dvb_usb_device *d = i2c_get_adapdata(adap);
81 static u8 obuf[60], ibuf[60];
82 int i,read;
83
84 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
85 return -EAGAIN;
86
87 if (num > 2)
88 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
89
90 for (i = 0; i < num; i++) {
91 read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
92
93 obuf[0] = (msg[i].addr << 1) | read;
94 obuf[1] = msg[i].len;
95
96 /* read request */
97 if (read)
98 obuf[2] = msg[i+1].len;
99 else
100 obuf[2] = 0;
101
102 memcpy(&obuf[3],msg[i].buf,msg[i].len);
103
104 if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) {
105 err("i2c transfer failed.");
106 break;
107 }
108
109 if (read) {
110 memcpy(msg[i+1].buf,&ibuf[3],msg[i+1].len);
111 i++;
112 }
113 }
114
115 mutex_unlock(&d->i2c_mutex);
116 return i;
117}
118
119static u32 ttusb2_i2c_func(struct i2c_adapter *adapter)
120{
121 return I2C_FUNC_I2C;
122}
123
124static struct i2c_algorithm ttusb2_i2c_algo = {
125 .master_xfer = ttusb2_i2c_xfer,
126 .functionality = ttusb2_i2c_func,
127};
128
129/* Callbacks for DVB USB */
130static int ttusb2_identify_state (struct usb_device *udev, struct
131 dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,
132 int *cold)
133{
134 *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;
135 return 0;
136}
137
138static int ttusb2_power_ctrl(struct dvb_usb_device *d, int onoff)
139{
140 u8 b = onoff;
141 ttusb2_msg(d, CMD_POWER, &b, 0, NULL, 0);
142 return ttusb2_msg(d, CMD_POWER, &b, 1, NULL, 0);
143}
144
145
146static struct tda10086_config tda10086_config = {
147 .demod_address = 0x0e,
148 .invert = 0,
Hartmut Hackmannea75baf2008-02-09 23:54:24 -0300149 .diseqc_tone = 1,
Patrick Boettcherbc2e3912006-12-02 21:16:04 -0200150};
151
152static int ttusb2_frontend_attach(struct dvb_usb_adapter *adap)
153{
154 if (usb_set_interface(adap->dev->udev,0,3) < 0)
155 err("set interface to alts=3 failed");
156
157 if ((adap->fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
158 deb_info("TDA10086 attach failed\n");
159 return -ENODEV;
160 }
161
162 return 0;
163}
164
165static int ttusb2_tuner_attach(struct dvb_usb_adapter *adap)
166{
167 if (dvb_attach(tda826x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, 0) == NULL) {
168 deb_info("TDA8263 attach failed\n");
169 return -ENODEV;
170 }
171
172 if (dvb_attach(lnbp21_attach, adap->fe, &adap->dev->i2c_adap, 0, 0) == NULL) {
173 deb_info("LNBP21 attach failed\n");
174 return -ENODEV;
175 }
176 return 0;
177}
178
179/* DVB USB Driver stuff */
180static struct dvb_usb_device_properties ttusb2_properties;
Andre Weidemann8c899bc2008-03-29 21:30:49 -0300181static struct dvb_usb_device_properties ttusb2_properties_s2400;
Patrick Boettcherbc2e3912006-12-02 21:16:04 -0200182
183static int ttusb2_probe(struct usb_interface *intf,
184 const struct usb_device_id *id)
185{
Janne Grunau78e92002008-04-09 19:13:13 -0300186 if (0 == dvb_usb_device_init(intf, &ttusb2_properties,
187 THIS_MODULE, NULL, adapter_nr) ||
188 0 == dvb_usb_device_init(intf, &ttusb2_properties_s2400,
189 THIS_MODULE, NULL, adapter_nr))
Andre Weidemann8c899bc2008-03-29 21:30:49 -0300190 return 0;
191 return -ENODEV;
Patrick Boettcherbc2e3912006-12-02 21:16:04 -0200192}
193
194static struct usb_device_id ttusb2_table [] = {
Andre Weidemann8c899bc2008-03-29 21:30:49 -0300195 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) },
196 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) },
197 { USB_DEVICE(USB_VID_TECHNOTREND,
198 USB_PID_TECHNOTREND_CONNECT_S2400) },
199 {} /* Terminating entry */
Patrick Boettcherbc2e3912006-12-02 21:16:04 -0200200};
201MODULE_DEVICE_TABLE (usb, ttusb2_table);
202
203static struct dvb_usb_device_properties ttusb2_properties = {
204 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
205
206 .usb_ctrl = CYPRESS_FX2,
207 .firmware = "dvb-usb-pctv-400e-01.fw",
208
209 .size_of_priv = sizeof(struct ttusb2_state),
210
211 .num_adapters = 1,
212 .adapter = {
213 {
214 .streaming_ctrl = NULL, // ttusb2_streaming_ctrl,
215
216 .frontend_attach = ttusb2_frontend_attach,
217 .tuner_attach = ttusb2_tuner_attach,
218
219 /* parameter for the MPEG2-data transfer */
220 .stream = {
221 .type = USB_ISOC,
222 .count = 5,
223 .endpoint = 0x02,
224 .u = {
225 .isoc = {
226 .framesperurb = 4,
227 .framesize = 940,
228 .interval = 1,
229 }
230 }
231 }
232 }
233 },
234
235 .power_ctrl = ttusb2_power_ctrl,
236 .identify_state = ttusb2_identify_state,
237
238 .i2c_algo = &ttusb2_i2c_algo,
239
240 .generic_bulk_ctrl_endpoint = 0x01,
241
Christophe Cattelainddc9ece2007-04-27 12:31:32 -0300242 .num_device_descs = 2,
Patrick Boettcherbc2e3912006-12-02 21:16:04 -0200243 .devices = {
244 { "Pinnacle 400e DVB-S USB2.0",
245 { &ttusb2_table[0], NULL },
246 { NULL },
247 },
Christophe Cattelainddc9ece2007-04-27 12:31:32 -0300248 { "Pinnacle 450e DVB-S USB2.0",
249 { &ttusb2_table[1], NULL },
250 { NULL },
251 },
Patrick Boettcherbc2e3912006-12-02 21:16:04 -0200252 }
253};
254
Andre Weidemann8c899bc2008-03-29 21:30:49 -0300255static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
256 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
257
258 .usb_ctrl = CYPRESS_FX2,
259 .firmware = "dvb-usb-tt-s2400-01.fw",
260
261 .size_of_priv = sizeof(struct ttusb2_state),
262
263 .num_adapters = 1,
264 .adapter = {
265 {
266 .streaming_ctrl = NULL,
267
268 .frontend_attach = ttusb2_frontend_attach,
269 .tuner_attach = ttusb2_tuner_attach,
270
271 /* parameter for the MPEG2-data transfer */
272 .stream = {
273 .type = USB_ISOC,
274 .count = 5,
275 .endpoint = 0x02,
276 .u = {
277 .isoc = {
278 .framesperurb = 4,
279 .framesize = 940,
280 .interval = 1,
281 }
282 }
283 }
284 }
285 },
286
287 .power_ctrl = ttusb2_power_ctrl,
288 .identify_state = ttusb2_identify_state,
289
290 .i2c_algo = &ttusb2_i2c_algo,
291
292 .generic_bulk_ctrl_endpoint = 0x01,
293
294 .num_device_descs = 1,
295 .devices = {
296 { "Technotrend TT-connect S-2400",
297 { &ttusb2_table[2], NULL },
298 { NULL },
299 },
300 }
301};
302
Patrick Boettcherbc2e3912006-12-02 21:16:04 -0200303static struct usb_driver ttusb2_driver = {
304 .name = "dvb_usb_ttusb2",
305 .probe = ttusb2_probe,
306 .disconnect = dvb_usb_device_exit,
307 .id_table = ttusb2_table,
308};
309
310/* module stuff */
311static int __init ttusb2_module_init(void)
312{
313 int result;
314 if ((result = usb_register(&ttusb2_driver))) {
315 err("usb_register failed. Error number %d",result);
316 return result;
317 }
318
319 return 0;
320}
321
322static void __exit ttusb2_module_exit(void)
323{
324 /* deregister this driver from the USB subsystem */
325 usb_deregister(&ttusb2_driver);
326}
327
328module_init (ttusb2_module_init);
329module_exit (ttusb2_module_exit);
330
331MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
332MODULE_DESCRIPTION("Driver for Pinnacle PCTV 400e DVB-S USB2.0");
333MODULE_VERSION("1.0");
334MODULE_LICENSE("GPL");