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