blob: 9622a79d6e6846de6ec071c024db4a40199279f3 [file] [log] [blame]
Patrick Boettcher22c6d932005-07-07 17:58:10 -07001/* DVB USB compliant linux driver for Conexant USB reference design.
2 *
3 * The Conexant reference design I saw on their website was only for analogue
4 * capturing (using the cx25842). The box I took to write this driver (reverse
5 * engineered) is the one labeled Medion MD95700. In addition to the cx25842
6 * for analogue capturing it also has a cx22702 DVB-T demodulator on the main
7 * board. Besides it has a atiremote (X10) and a USB2.0 hub onboard.
8 *
9 * Maybe it is a little bit premature to call this driver cxusb, but I assume
10 * the USB protocol is identical or at least inherited from the reference
11 * design, so it can be reused for the "analogue-only" device (if it will
12 * appear at all).
13 *
14 * TODO: check if the cx25840-driver (from ivtv) can be used for the analogue
15 * part
16 *
Patrick Boettcher22c6d932005-07-07 17:58:10 -070017 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
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#include "cxusb.h"
26
27#include "cx22702.h"
Michael Krufkyeffee032006-01-09 15:25:47 -020028#include "lgdt330x.h"
Chris Pascoe0029ee12006-01-09 18:21:28 -020029#include "mt352.h"
30#include "mt352_priv.h"
Patrick Boettcher22c6d932005-07-07 17:58:10 -070031
32/* debug */
33int dvb_usb_cxusb_debug;
34module_param_named(debug,dvb_usb_cxusb_debug, int, 0644);
35MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
36
37static int cxusb_ctrl_msg(struct dvb_usb_device *d,
38 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
39{
40 int wo = (rbuf == NULL || rlen == 0); /* write-only */
41 u8 sndbuf[1+wlen];
42 memset(sndbuf,0,1+wlen);
43
44 sndbuf[0] = cmd;
45 memcpy(&sndbuf[1],wbuf,wlen);
46 if (wo)
47 dvb_usb_generic_write(d,sndbuf,1+wlen);
48 else
49 dvb_usb_generic_rw(d,sndbuf,1+wlen,rbuf,rlen,0);
50
51 return 0;
52}
53
Patrick Boettchere2efeab2005-09-09 13:02:51 -070054/* GPIO */
55static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
Patrick Boettcher22c6d932005-07-07 17:58:10 -070056{
57 struct cxusb_state *st = d->priv;
58 u8 o[2],i;
59
Patrick Boettchere2efeab2005-09-09 13:02:51 -070060 if (st->gpio_write_state[GPIO_TUNER] == onoff)
Patrick Boettcher22c6d932005-07-07 17:58:10 -070061 return;
62
Patrick Boettchere2efeab2005-09-09 13:02:51 -070063 o[0] = GPIO_TUNER;
64 o[1] = onoff;
65 cxusb_ctrl_msg(d,CMD_GPIO_WRITE,o,2,&i,1);
Patrick Boettcher22c6d932005-07-07 17:58:10 -070066
67 if (i != 0x01)
Patrick Boettchere2efeab2005-09-09 13:02:51 -070068 deb_info("gpio_write failed.\n");
Patrick Boettcher22c6d932005-07-07 17:58:10 -070069
Patrick Boettchere2efeab2005-09-09 13:02:51 -070070 st->gpio_write_state[GPIO_TUNER] = onoff;
Patrick Boettcher22c6d932005-07-07 17:58:10 -070071}
72
Patrick Boettchere2efeab2005-09-09 13:02:51 -070073/* I2C */
Patrick Boettcher22c6d932005-07-07 17:58:10 -070074static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
75{
76 struct dvb_usb_device *d = i2c_get_adapdata(adap);
77 int i;
78
79 if (down_interruptible(&d->i2c_sem) < 0)
80 return -EAGAIN;
81
82 if (num > 2)
83 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
84
85 for (i = 0; i < num; i++) {
86
87 switch (msg[i].addr) {
88 case 0x63:
Patrick Boettchere2efeab2005-09-09 13:02:51 -070089 cxusb_gpio_tuner(d,0);
Patrick Boettcher22c6d932005-07-07 17:58:10 -070090 break;
91 default:
Patrick Boettchere2efeab2005-09-09 13:02:51 -070092 cxusb_gpio_tuner(d,1);
Patrick Boettcher22c6d932005-07-07 17:58:10 -070093 break;
94 }
95
96 /* read request */
97 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
98 u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];
99 obuf[0] = msg[i].len;
100 obuf[1] = msg[i+1].len;
101 obuf[2] = msg[i].addr;
102 memcpy(&obuf[3],msg[i].buf,msg[i].len);
103
104 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
105 obuf, 3+msg[i].len,
106 ibuf, 1+msg[i+1].len) < 0)
107 break;
108
109 if (ibuf[0] != 0x08)
110 deb_info("i2c read could have been failed\n");
111
112 memcpy(msg[i+1].buf,&ibuf[1],msg[i+1].len);
113
114 i++;
115 } else { /* write */
116 u8 obuf[2+msg[i].len], ibuf;
117 obuf[0] = msg[i].addr;
118 obuf[1] = msg[i].len;
119 memcpy(&obuf[2],msg[i].buf,msg[i].len);
120
121 if (cxusb_ctrl_msg(d,CMD_I2C_WRITE, obuf, 2+msg[i].len, &ibuf,1) < 0)
122 break;
123 if (ibuf != 0x08)
124 deb_info("i2c write could have been failed\n");
125 }
126 }
127
128 up(&d->i2c_sem);
129 return i;
130}
131
132static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
133{
134 return I2C_FUNC_I2C;
135}
136
137static struct i2c_algorithm cxusb_i2c_algo = {
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700138 .master_xfer = cxusb_i2c_xfer,
139 .functionality = cxusb_i2c_func,
140};
141
142static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
143{
Patrick Boettchere2efeab2005-09-09 13:02:51 -0700144 u8 b = 0;
145 if (onoff)
146 return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
147 else
148 return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700149}
150
151static int cxusb_streaming_ctrl(struct dvb_usb_device *d, int onoff)
152{
Patrick Boettcher8257e8a2005-07-07 17:58:15 -0700153 u8 buf[2] = { 0x03, 0x00 };
154 if (onoff)
Patrick Boettchere2efeab2005-09-09 13:02:51 -0700155 cxusb_ctrl_msg(d,CMD_STREAMING_ON, buf, 2, NULL, 0);
Patrick Boettcher8257e8a2005-07-07 17:58:15 -0700156 else
Patrick Boettchere2efeab2005-09-09 13:02:51 -0700157 cxusb_ctrl_msg(d,CMD_STREAMING_OFF, NULL, 0, NULL, 0);
Patrick Boettcher8257e8a2005-07-07 17:58:15 -0700158
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700159 return 0;
160}
161
Chris Pascoe0029ee12006-01-09 18:21:28 -0200162static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
163{
164 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x38 };
165 static u8 reset [] = { RESET, 0x80 };
166 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
167 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0x20 };
168 static u8 gpp_ctl_cfg [] = { GPP_CTL, 0x33 };
169 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
170
171 mt352_write(fe, clock_config, sizeof(clock_config));
172 udelay(200);
173 mt352_write(fe, reset, sizeof(reset));
174 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
175
176 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
177 mt352_write(fe, gpp_ctl_cfg, sizeof(gpp_ctl_cfg));
178 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
179
180 return 0;
181}
182
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700183struct cx22702_config cxusb_cx22702_config = {
184 .demod_address = 0x63,
185
Patrick Boettcher8257e8a2005-07-07 17:58:15 -0700186 .output_mode = CX22702_PARALLEL_OUTPUT,
187
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700188 .pll_init = dvb_usb_pll_init_i2c,
189 .pll_set = dvb_usb_pll_set_i2c,
190};
191
Michael Krufkyeffee032006-01-09 15:25:47 -0200192struct lgdt330x_config cxusb_lgdt330x_config = {
193 .demod_address = 0x0e,
194 .demod_chip = LGDT3303,
195 .pll_set = dvb_usb_pll_set_i2c,
196};
197
Chris Pascoe0029ee12006-01-09 18:21:28 -0200198struct mt352_config cxusb_dee1601_config = {
199 .demod_address = 0x0f,
200 .demod_init = cxusb_dee1601_demod_init,
201 .pll_set = dvb_usb_pll_set,
202};
203
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700204/* Callbacks for DVB USB */
Michael Krufkyeffee032006-01-09 15:25:47 -0200205static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_device *d)
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700206{
207 u8 bpll[4] = { 0x0b, 0xdc, 0x9c, 0xa0 };
208 d->pll_addr = 0x61;
Michael Krufkyeffee032006-01-09 15:25:47 -0200209 memcpy(d->pll_init, bpll, 4);
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700210 d->pll_desc = &dvb_pll_fmd1216me;
211 return 0;
212}
213
Michael Krufkyeffee032006-01-09 15:25:47 -0200214static int cxusb_lgh064f_tuner_attach(struct dvb_usb_device *d)
215{
216 u8 bpll[4] = { 0x00, 0x00, 0x18, 0x50 };
217 /* bpll[2] : unset bit 3, set bits 4&5
218 bpll[3] : 0x50 - digital, 0x20 - analog */
219 d->pll_addr = 0x61;
220 memcpy(d->pll_init, bpll, 4);
221 d->pll_desc = &dvb_pll_tdvs_tua6034;
222 return 0;
223}
224
Chris Pascoe0029ee12006-01-09 18:21:28 -0200225static int cxusb_dee1601_tuner_attach(struct dvb_usb_device *d)
226{
227 d->pll_addr = 0x61;
228 d->pll_desc = &dvb_pll_thomson_dtt7579;
229 return 0;
230}
231
Michael Krufkyeffee032006-01-09 15:25:47 -0200232static int cxusb_cx22702_frontend_attach(struct dvb_usb_device *d)
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700233{
Patrick Boettchere2efeab2005-09-09 13:02:51 -0700234 u8 b;
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700235 if (usb_set_interface(d->udev,0,6) < 0)
Patrick Boettcher8257e8a2005-07-07 17:58:15 -0700236 err("set interface failed");
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700237
Patrick Boettchere2efeab2005-09-09 13:02:51 -0700238 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, &b, 1);
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700239
240 if ((d->fe = cx22702_attach(&cxusb_cx22702_config, &d->i2c_adap)) != NULL)
241 return 0;
242
243 return -EIO;
244}
245
Michael Krufkyeffee032006-01-09 15:25:47 -0200246static int cxusb_lgdt330x_frontend_attach(struct dvb_usb_device *d)
247{
Michael Krufky37bdfa02006-01-09 15:25:47 -0200248 if (usb_set_interface(d->udev,0,7) < 0)
Michael Krufkyeffee032006-01-09 15:25:47 -0200249 err("set interface failed");
250
251 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
252
253 if ((d->fe = lgdt330x_attach(&cxusb_lgdt330x_config, &d->i2c_adap)) != NULL)
254 return 0;
255
256 return -EIO;
257}
258
Chris Pascoe0029ee12006-01-09 18:21:28 -0200259static int cxusb_dee1601_frontend_attach(struct dvb_usb_device *d)
260{
261 if (usb_set_interface(d->udev,0,0) < 0)
262 err("set interface failed");
263
264 cxusb_ctrl_msg(d,CMD_DIGITAL, NULL, 0, NULL, 0);
265
266 if ((d->fe = mt352_attach(&cxusb_dee1601_config, &d->i2c_adap)) != NULL)
267 return 0;
268
269 return -EIO;
270}
271
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700272/* DVB USB Driver stuff */
Michael Krufkyeffee032006-01-09 15:25:47 -0200273static struct dvb_usb_properties cxusb_medion_properties;
Michael Krufkye71bb542006-01-09 15:32:42 -0200274static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties;
Chris Pascoe0029ee12006-01-09 18:21:28 -0200275static struct dvb_usb_properties cxusb_bluebird_dee1601_properties;
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700276
277static int cxusb_probe(struct usb_interface *intf,
278 const struct usb_device_id *id)
279{
Michael Krufkyeffee032006-01-09 15:25:47 -0200280 if (dvb_usb_device_init(intf,&cxusb_medion_properties,THIS_MODULE,NULL) == 0 ||
Chris Pascoe0029ee12006-01-09 18:21:28 -0200281 dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 ||
282 dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0
283 ){
Michael Krufkyeffee032006-01-09 15:25:47 -0200284 return 0;
285 }
286
287 return -EINVAL;
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700288}
289
290static struct usb_device_id cxusb_table [] = {
291 { USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) },
Michael Krufkyeffee032006-01-09 15:25:47 -0200292 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD) },
293 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) },
Chris Pascoe0029ee12006-01-09 18:21:28 -0200294 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DEE1601_COLD) },
295 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DEE1601_WARM) },
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700296 {} /* Terminating entry */
297};
298MODULE_DEVICE_TABLE (usb, cxusb_table);
299
Michael Krufkyeffee032006-01-09 15:25:47 -0200300static struct dvb_usb_properties cxusb_medion_properties = {
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700301 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
302
303 .usb_ctrl = CYPRESS_FX2,
304
305 .size_of_priv = sizeof(struct cxusb_state),
306
307 .streaming_ctrl = cxusb_streaming_ctrl,
308 .power_ctrl = cxusb_power_ctrl,
Michael Krufkyeffee032006-01-09 15:25:47 -0200309 .frontend_attach = cxusb_cx22702_frontend_attach,
310 .tuner_attach = cxusb_fmd1216me_tuner_attach,
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700311
312 .i2c_algo = &cxusb_i2c_algo,
313
314 .generic_bulk_ctrl_endpoint = 0x01,
315 /* parameter for the MPEG2-data transfer */
316 .urb = {
Patrick Boettchere2efeab2005-09-09 13:02:51 -0700317 .type = DVB_USB_BULK,
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700318 .count = 5,
319 .endpoint = 0x02,
320 .u = {
Patrick Boettchere2efeab2005-09-09 13:02:51 -0700321 .bulk = {
322 .buffersize = 8192,
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700323 }
324 }
325 },
326
327 .num_device_descs = 1,
328 .devices = {
329 { "Medion MD95700 (MDUSBTV-HYBRID)",
330 { NULL },
331 { &cxusb_table[0], NULL },
332 },
333 }
334};
335
Michael Krufkye71bb542006-01-09 15:32:42 -0200336static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties = {
Michael Krufkyeffee032006-01-09 15:25:47 -0200337 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
338
339 .usb_ctrl = CYPRESS_FX2,
Michael Krufky37bdfa02006-01-09 15:25:47 -0200340 .firmware = "dvb-usb-bluebird-01.fw",
341 /* use usb alt setting 0 for EP4 transfer (dvb-t),
342 use usb alt setting 7 for EP2 transfer (atsc) */
Michael Krufkyeffee032006-01-09 15:25:47 -0200343
344 .size_of_priv = sizeof(struct cxusb_state),
345
346 .streaming_ctrl = cxusb_streaming_ctrl,
347 .power_ctrl = cxusb_power_ctrl,
348 .frontend_attach = cxusb_lgdt330x_frontend_attach,
349 .tuner_attach = cxusb_lgh064f_tuner_attach,
350
351 .i2c_algo = &cxusb_i2c_algo,
352
353 .generic_bulk_ctrl_endpoint = 0x01,
354 /* parameter for the MPEG2-data transfer */
355 .urb = {
356 .type = DVB_USB_BULK,
357 .count = 5,
358 .endpoint = 0x02,
359 .u = {
360 .bulk = {
361 .buffersize = 8192,
362 }
363 }
364 },
365
366 .num_device_descs = 1,
367 .devices = {
368 { "DViCO FusionHDTV5 USB Gold",
369 { &cxusb_table[1], NULL },
370 { &cxusb_table[2], NULL },
371 },
372 }
373};
374
Chris Pascoe0029ee12006-01-09 18:21:28 -0200375static struct dvb_usb_properties cxusb_bluebird_dee1601_properties = {
376 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
377
378 .usb_ctrl = CYPRESS_FX2,
379 .firmware = "dvb-usb-bluebird-01.fw",
380 /* use usb alt setting 0 for EP4 transfer (dvb-t),
381 use usb alt setting 7 for EP2 transfer (atsc) */
382
383 .size_of_priv = sizeof(struct cxusb_state),
384
385 .streaming_ctrl = cxusb_streaming_ctrl,
386 .power_ctrl = cxusb_power_ctrl,
387 .frontend_attach = cxusb_dee1601_frontend_attach,
388 .tuner_attach = cxusb_dee1601_tuner_attach,
389
390 .i2c_algo = &cxusb_i2c_algo,
391
392 .generic_bulk_ctrl_endpoint = 0x01,
393 /* parameter for the MPEG2-data transfer */
394 .urb = {
395 .type = DVB_USB_BULK,
396 .count = 5,
397 .endpoint = 0x04,
398 .u = {
399 .bulk = {
400 .buffersize = 8192,
401 }
402 }
403 },
404
405 .num_device_descs = 1,
406 .devices = {
407 { "DViCO FusionHDTV DVB-T Dual USB",
408 { &cxusb_table[3], NULL },
409 { &cxusb_table[4], NULL },
410 },
411 }
412};
413
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700414static struct usb_driver cxusb_driver = {
Patrick Boettcher63b5c1c2005-07-07 17:58:30 -0700415 .name = "dvb_usb_cxusb",
Patrick Boettcher22c6d932005-07-07 17:58:10 -0700416 .probe = cxusb_probe,
417 .disconnect = dvb_usb_device_exit,
418 .id_table = cxusb_table,
419};
420
421/* module stuff */
422static int __init cxusb_module_init(void)
423{
424 int result;
425 if ((result = usb_register(&cxusb_driver))) {
426 err("usb_register failed. Error number %d",result);
427 return result;
428 }
429
430 return 0;
431}
432
433static void __exit cxusb_module_exit(void)
434{
435 /* deregister this driver from the USB subsystem */
436 usb_deregister(&cxusb_driver);
437}
438
439module_init (cxusb_module_init);
440module_exit (cxusb_module_exit);
441
442MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
443MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
444MODULE_VERSION("1.0-alpha");
445MODULE_LICENSE("GPL");