cxusb.c 51.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/* DVB USB compliant linux driver for Conexant USB reference design.
 *
 * The Conexant reference design I saw on their website was only for analogue
 * capturing (using the cx25842). The box I took to write this driver (reverse
 * engineered) is the one labeled Medion MD95700. In addition to the cx25842
 * for analogue capturing it also has a cx22702 DVB-T demodulator on the main
 * board. Besides it has a atiremote (X10) and a USB2.0 hub onboard.
 *
 * Maybe it is a little bit premature to call this driver cxusb, but I assume
 * the USB protocol is identical or at least inherited from the reference
 * design, so it can be reused for the "analogue-only" device (if it will
 * appear at all).
 *
14
 * TODO: Use the cx25840-driver for the analogue part
15 16
 *
 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
17
 * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
18
 * Copyright (C) 2006, 2007 Chris Pascoe (c.pascoe@itee.uq.edu.au)
19
 *
20 21 22
 *   This program is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License as published by the Free
 *   Software Foundation, version 2.
23 24 25
 *
 * see Documentation/dvb/README.dvb-usb for more information
 */
26
#include <media/tuner.h>
27
#include <linux/vmalloc.h>
28
#include <linux/slab.h>
29

30 31 32
#include "cxusb.h"

#include "cx22702.h"
33
#include "lgdt330x.h"
34 35
#include "mt352.h"
#include "mt352_priv.h"
36
#include "zl10353.h"
37
#include "tuner-xc2028.h"
38
#include "tuner-simple.h"
39
#include "mxl5005s.h"
40
#include "max2165.h"
41 42
#include "dib7000p.h"
#include "dib0070.h"
43
#include "lgs8gxx.h"
44
#include "atbm8830.h"
45 46

/* debug */
47
static int dvb_usb_cxusb_debug;
48
module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
49
MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
50 51 52

DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);

53 54
#define deb_info(args...)   dprintk(dvb_usb_cxusb_debug, 0x03, args)
#define deb_i2c(args...)    dprintk(dvb_usb_cxusb_debug, 0x02, args)
55 56

static int cxusb_ctrl_msg(struct dvb_usb_device *d,
57
			  u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
58 59 60
{
	int wo = (rbuf == NULL || rlen == 0); /* write-only */
	u8 sndbuf[1+wlen];
61
	memset(sndbuf, 0, 1+wlen);
62 63

	sndbuf[0] = cmd;
64
	memcpy(&sndbuf[1], wbuf, wlen);
65
	if (wo)
66
		return dvb_usb_generic_write(d, sndbuf, 1+wlen);
67
	else
68
		return dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
69 70
}

71 72
/* GPIO */
static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
73 74
{
	struct cxusb_state *st = d->priv;
75
	u8 o[2], i;
76

77
	if (st->gpio_write_state[GPIO_TUNER] == onoff)
78 79
		return;

80 81
	o[0] = GPIO_TUNER;
	o[1] = onoff;
82
	cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
83 84

	if (i != 0x01)
85
		deb_info("gpio_write failed.\n");
86

87
	st->gpio_write_state[GPIO_TUNER] = onoff;
88 89
}

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
static int cxusb_bluebird_gpio_rw(struct dvb_usb_device *d, u8 changemask,
				 u8 newval)
{
	u8 o[2], gpio_state;
	int rc;

	o[0] = 0xff & ~changemask;	/* mask of bits to keep */
	o[1] = newval & changemask;	/* new values for bits  */

	rc = cxusb_ctrl_msg(d, CMD_BLUEBIRD_GPIO_RW, o, 2, &gpio_state, 1);
	if (rc < 0 || (gpio_state & changemask) != (newval & changemask))
		deb_info("bluebird_gpio_write failed.\n");

	return rc < 0 ? rc : gpio_state;
}

static void cxusb_bluebird_gpio_pulse(struct dvb_usb_device *d, u8 pin, int low)
{
	cxusb_bluebird_gpio_rw(d, pin, low ? 0 : pin);
	msleep(5);
	cxusb_bluebird_gpio_rw(d, pin, low ? pin : 0);
}

113 114 115 116 117
static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
{
	cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
}

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
		u8 addr, int onoff)
{
	u8  o[2] = {addr, onoff};
	u8  i;
	int rc;

	rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);

	if (rc < 0)
		return rc;
	if (i == 0x01)
		return 0;
	else {
		deb_info("gpio_write failed.\n");
		return -EIO;
	}
}

137
/* I2C */
138 139
static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
			  int num)
140 141 142 143
{
	struct dvb_usb_device *d = i2c_get_adapdata(adap);
	int i;

144
	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
145 146 147 148
		return -EAGAIN;

	for (i = 0; i < num; i++) {

149 150
		if (d->udev->descriptor.idVendor == USB_VID_MEDION)
			switch (msg[i].addr) {
151 152 153 154 155 156
			case 0x63:
				cxusb_gpio_tuner(d, 0);
				break;
			default:
				cxusb_gpio_tuner(d, 1);
				break;
157
			}
158

159 160 161 162 163 164 165 166 167 168 169 170 171
		if (msg[i].flags & I2C_M_RD) {
			/* read only */
			u8 obuf[3], ibuf[1+msg[i].len];
			obuf[0] = 0;
			obuf[1] = msg[i].len;
			obuf[2] = msg[i].addr;
			if (cxusb_ctrl_msg(d, CMD_I2C_READ,
					   obuf, 3,
					   ibuf, 1+msg[i].len) < 0) {
				warn("i2c read failed");
				break;
			}
			memcpy(msg[i].buf, &ibuf[1], msg[i].len);
172 173 174
		} else if (i+1 < num && (msg[i+1].flags & I2C_M_RD) &&
			   msg[i].addr == msg[i+1].addr) {
			/* write to then read from same address */
175 176 177 178
			u8 obuf[3+msg[i].len], ibuf[1+msg[i+1].len];
			obuf[0] = msg[i].len;
			obuf[1] = msg[i+1].len;
			obuf[2] = msg[i].addr;
179
			memcpy(&obuf[3], msg[i].buf, msg[i].len);
180 181

			if (cxusb_ctrl_msg(d, CMD_I2C_READ,
182 183
					   obuf, 3+msg[i].len,
					   ibuf, 1+msg[i+1].len) < 0)
184 185 186
				break;

			if (ibuf[0] != 0x08)
187
				deb_i2c("i2c read may have failed\n");
188

189
			memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
190 191

			i++;
192 193
		} else {
			/* write only */
194 195 196
			u8 obuf[2+msg[i].len], ibuf;
			obuf[0] = msg[i].addr;
			obuf[1] = msg[i].len;
197
			memcpy(&obuf[2], msg[i].buf, msg[i].len);
198

199 200
			if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,
					   2+msg[i].len, &ibuf,1) < 0)
201 202
				break;
			if (ibuf != 0x08)
203
				deb_i2c("i2c write may have failed\n");
204 205 206
		}
	}

207
	mutex_unlock(&d->i2c_mutex);
208
	return i == num ? num : -EREMOTEIO;
209 210 211 212 213 214 215 216 217 218 219 220 221 222
}

static u32 cxusb_i2c_func(struct i2c_adapter *adapter)
{
	return I2C_FUNC_I2C;
}

static struct i2c_algorithm cxusb_i2c_algo = {
	.master_xfer   = cxusb_i2c_xfer,
	.functionality = cxusb_i2c_func,
};

static int cxusb_power_ctrl(struct dvb_usb_device *d, int onoff)
{
223 224 225 226 227
	u8 b = 0;
	if (onoff)
		return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
	else
		return cxusb_ctrl_msg(d, CMD_POWER_OFF, &b, 1, NULL, 0);
228 229
}

230 231 232 233 234 235 236 237
static int cxusb_aver_power_ctrl(struct dvb_usb_device *d, int onoff)
{
	int ret;
	if (!onoff)
		return cxusb_ctrl_msg(d, CMD_POWER_OFF, NULL, 0, NULL, 0);
	if (d->state == DVB_USB_STATE_INIT &&
	    usb_set_interface(d->udev, 0, 0) < 0)
		err("set interface failed");
238
	do {} while (!(ret = cxusb_ctrl_msg(d, CMD_POWER_ON, NULL, 0, NULL, 0)) &&
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
		   !(ret = cxusb_ctrl_msg(d, 0x15, NULL, 0, NULL, 0)) &&
		   !(ret = cxusb_ctrl_msg(d, 0x17, NULL, 0, NULL, 0)) && 0);
	if (!ret) {
		/* FIXME: We don't know why, but we need to configure the
		 * lgdt3303 with the register settings below on resume */
		int i;
		u8 buf, bufs[] = {
			0x0e, 0x2, 0x00, 0x7f,
			0x0e, 0x2, 0x02, 0xfe,
			0x0e, 0x2, 0x02, 0x01,
			0x0e, 0x2, 0x00, 0x03,
			0x0e, 0x2, 0x0d, 0x40,
			0x0e, 0x2, 0x0e, 0x87,
			0x0e, 0x2, 0x0f, 0x8e,
			0x0e, 0x2, 0x10, 0x01,
			0x0e, 0x2, 0x14, 0xd7,
			0x0e, 0x2, 0x47, 0x88,
		};
		msleep(20);
		for (i = 0; i < sizeof(bufs)/sizeof(u8); i += 4/sizeof(u8)) {
			ret = cxusb_ctrl_msg(d, CMD_I2C_WRITE,
					     bufs+i, 4, &buf, 1);
			if (ret)
				break;
			if (buf != 0x8)
				return -EREMOTEIO;
		}
	}
	return ret;
}

270 271 272 273 274 275 276 277 278
static int cxusb_bluebird_power_ctrl(struct dvb_usb_device *d, int onoff)
{
	u8 b = 0;
	if (onoff)
		return cxusb_ctrl_msg(d, CMD_POWER_ON, &b, 1, NULL, 0);
	else
		return 0;
}

279 280 281 282 283 284 285 286 287 288 289
static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
{
	int rc = 0;

	rc = cxusb_power_ctrl(d, onoff);
	if (!onoff)
		cxusb_nano2_led(d, 0);

	return rc;
}

290 291 292 293 294 295 296 297 298 299 300 301 302 303
static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
{
	int ret;
	u8  b;
	ret = cxusb_power_ctrl(d, onoff);
	if (!onoff)
		return ret;

	msleep(128);
	cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
	msleep(100);
	return ret;
}

304
static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
305
{
306 307
	u8 buf[2] = { 0x03, 0x00 };
	if (onoff)
308
		cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON, buf, 2, NULL, 0);
309
	else
310
		cxusb_ctrl_msg(adap->dev, CMD_STREAMING_OFF, NULL, 0, NULL, 0);
311

312 313 314
	return 0;
}

315 316 317 318 319 320 321 322 323 324
static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
{
	if (onoff)
		cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_ON, NULL, 0, NULL, 0);
	else
		cxusb_ctrl_msg(adap->dev, CMD_AVER_STREAM_OFF,
			       NULL, 0, NULL, 0);
	return 0;
}

325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
{
	int       ep = d->props.generic_bulk_ctrl_endpoint;
	const int timeout = 100;
	const int junk_len = 32;
	u8        *junk;
	int       rd_count;

	/* Discard remaining data in video pipe */
	junk = kmalloc(junk_len, GFP_KERNEL);
	if (!junk)
		return;
	while (1) {
		if (usb_bulk_msg(d->udev,
			usb_rcvbulkpipe(d->udev, ep),
			junk, junk_len, &rd_count, timeout) < 0)
			break;
		if (!rd_count)
			break;
	}
	kfree(junk);
}

static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
{
350
	struct usb_data_stream_properties *p = &d->props.adapter[0].fe[0].stream;
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
	const int timeout = 100;
	const int junk_len = p->u.bulk.buffersize;
	u8        *junk;
	int       rd_count;

	/* Discard remaining data in video pipe */
	junk = kmalloc(junk_len, GFP_KERNEL);
	if (!junk)
		return;
	while (1) {
		if (usb_bulk_msg(d->udev,
			usb_rcvbulkpipe(d->udev, p->endpoint),
			junk, junk_len, &rd_count, timeout) < 0)
			break;
		if (!rd_count)
			break;
	}
	kfree(junk);
}

static int cxusb_d680_dmb_streaming_ctrl(
		struct dvb_usb_adapter *adap, int onoff)
{
	if (onoff) {
		u8 buf[2] = { 0x03, 0x00 };
		cxusb_d680_dmb_drain_video(adap->dev);
		return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
			buf, sizeof(buf), NULL, 0);
	} else {
		int ret = cxusb_ctrl_msg(adap->dev,
			CMD_STREAMING_OFF, NULL, 0, NULL, 0);
		return ret;
	}
}

386 387
static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
{
388
	struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
389
	u8 ircode[4];
390 391
	int i;

392
	cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);
393 394 395 396

	*event = 0;
	*state = REMOTE_NO_KEY_PRESSED;

397
	for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
398 399
		if (rc5_custom(&keymap[i]) == ircode[2] &&
		    rc5_data(&keymap[i]) == ircode[3]) {
400
			*event = keymap[i].keycode;
401 402 403 404 405 406 407 408 409
			*state = REMOTE_KEY_PRESSED;

			return 0;
		}
	}

	return 0;
}

410 411 412
static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
				    int *state)
{
413
	struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
414 415 416 417 418 419 420 421 422 423 424
	u8 ircode[4];
	int i;
	struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
			       .buf = ircode, .len = 4 };

	*event = 0;
	*state = REMOTE_NO_KEY_PRESSED;

	if (cxusb_i2c_xfer(&d->i2c_adap, &msg, 1) != 1)
		return 0;

425
	for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
426 427
		if (rc5_custom(&keymap[i]) == ircode[1] &&
		    rc5_data(&keymap[i]) == ircode[2]) {
428
			*event = keymap[i].keycode;
429 430 431 432 433 434 435 436 437
			*state = REMOTE_KEY_PRESSED;

			return 0;
		}
	}

	return 0;
}

438 439 440
static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
		int *state)
{
441
	struct rc_map_table *keymap = d->props.rc.legacy.rc_map_table;
442 443 444 445 446 447 448 449 450
	u8 ircode[2];
	int i;

	*event = 0;
	*state = REMOTE_NO_KEY_PRESSED;

	if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
		return 0;

451
	for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) {
452 453
		if (rc5_custom(&keymap[i]) == ircode[0] &&
		    rc5_data(&keymap[i]) == ircode[1]) {
454
			*event = keymap[i].keycode;
455 456 457 458 459 460 461 462 463
			*state = REMOTE_KEY_PRESSED;

			return 0;
		}
	}

	return 0;
}

464
static struct rc_map_table rc_map_dvico_mce_table[] = {
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
	{ 0xfe02, KEY_TV },
	{ 0xfe0e, KEY_MP3 },
	{ 0xfe1a, KEY_DVD },
	{ 0xfe1e, KEY_FAVORITES },
	{ 0xfe16, KEY_SETUP },
	{ 0xfe46, KEY_POWER2 },
	{ 0xfe0a, KEY_EPG },
	{ 0xfe49, KEY_BACK },
	{ 0xfe4d, KEY_MENU },
	{ 0xfe51, KEY_UP },
	{ 0xfe5b, KEY_LEFT },
	{ 0xfe5f, KEY_RIGHT },
	{ 0xfe53, KEY_DOWN },
	{ 0xfe5e, KEY_OK },
	{ 0xfe59, KEY_INFO },
	{ 0xfe55, KEY_TAB },
	{ 0xfe0f, KEY_PREVIOUSSONG },/* Replay */
	{ 0xfe12, KEY_NEXTSONG },	/* Skip */
	{ 0xfe42, KEY_ENTER	 },	/* Windows/Start */
	{ 0xfe15, KEY_VOLUMEUP },
	{ 0xfe05, KEY_VOLUMEDOWN },
	{ 0xfe11, KEY_CHANNELUP },
	{ 0xfe09, KEY_CHANNELDOWN },
	{ 0xfe52, KEY_CAMERA },
	{ 0xfe5a, KEY_TUNER },	/* Live */
	{ 0xfe19, KEY_OPEN },
	{ 0xfe0b, KEY_1 },
	{ 0xfe17, KEY_2 },
	{ 0xfe1b, KEY_3 },
	{ 0xfe07, KEY_4 },
	{ 0xfe50, KEY_5 },
	{ 0xfe54, KEY_6 },
	{ 0xfe48, KEY_7 },
	{ 0xfe4c, KEY_8 },
	{ 0xfe58, KEY_9 },
	{ 0xfe13, KEY_ANGLE },	/* Aspect */
	{ 0xfe03, KEY_0 },
	{ 0xfe1f, KEY_ZOOM },
	{ 0xfe43, KEY_REWIND },
	{ 0xfe47, KEY_PLAYPAUSE },
	{ 0xfe4f, KEY_FASTFORWARD },
	{ 0xfe57, KEY_MUTE },
	{ 0xfe0d, KEY_STOP },
	{ 0xfe01, KEY_RECORD },
	{ 0xfe4e, KEY_POWER },
510 511
};

512
static struct rc_map_table rc_map_dvico_portable_table[] = {
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
	{ 0xfc02, KEY_SETUP },       /* Profile */
	{ 0xfc43, KEY_POWER2 },
	{ 0xfc06, KEY_EPG },
	{ 0xfc5a, KEY_BACK },
	{ 0xfc05, KEY_MENU },
	{ 0xfc47, KEY_INFO },
	{ 0xfc01, KEY_TAB },
	{ 0xfc42, KEY_PREVIOUSSONG },/* Replay */
	{ 0xfc49, KEY_VOLUMEUP },
	{ 0xfc09, KEY_VOLUMEDOWN },
	{ 0xfc54, KEY_CHANNELUP },
	{ 0xfc0b, KEY_CHANNELDOWN },
	{ 0xfc16, KEY_CAMERA },
	{ 0xfc40, KEY_TUNER },	/* ATV/DTV */
	{ 0xfc45, KEY_OPEN },
	{ 0xfc19, KEY_1 },
	{ 0xfc18, KEY_2 },
	{ 0xfc1b, KEY_3 },
	{ 0xfc1a, KEY_4 },
	{ 0xfc58, KEY_5 },
	{ 0xfc59, KEY_6 },
	{ 0xfc15, KEY_7 },
	{ 0xfc14, KEY_8 },
	{ 0xfc17, KEY_9 },
	{ 0xfc44, KEY_ANGLE },	/* Aspect */
	{ 0xfc55, KEY_0 },
	{ 0xfc07, KEY_ZOOM },
	{ 0xfc0a, KEY_REWIND },
	{ 0xfc08, KEY_PLAYPAUSE },
	{ 0xfc4b, KEY_FASTFORWARD },
	{ 0xfc5b, KEY_MUTE },
	{ 0xfc04, KEY_STOP },
	{ 0xfc56, KEY_RECORD },
	{ 0xfc57, KEY_POWER },
	{ 0xfc41, KEY_UNKNOWN },    /* INPUT */
	{ 0xfc00, KEY_UNKNOWN },    /* HD */
549 550
};

551
static struct rc_map_table rc_map_d680_dmb_table[] = {
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
	{ 0x0038, KEY_UNKNOWN },	/* TV/AV */
	{ 0x080c, KEY_ZOOM },
	{ 0x0800, KEY_0 },
	{ 0x0001, KEY_1 },
	{ 0x0802, KEY_2 },
	{ 0x0003, KEY_3 },
	{ 0x0804, KEY_4 },
	{ 0x0005, KEY_5 },
	{ 0x0806, KEY_6 },
	{ 0x0007, KEY_7 },
	{ 0x0808, KEY_8 },
	{ 0x0009, KEY_9 },
	{ 0x000a, KEY_MUTE },
	{ 0x0829, KEY_BACK },
	{ 0x0012, KEY_CHANNELUP },
	{ 0x0813, KEY_CHANNELDOWN },
	{ 0x002b, KEY_VOLUMEUP },
	{ 0x082c, KEY_VOLUMEDOWN },
	{ 0x0020, KEY_UP },
	{ 0x0821, KEY_DOWN },
	{ 0x0011, KEY_LEFT },
	{ 0x0810, KEY_RIGHT },
	{ 0x000d, KEY_OK },
	{ 0x081f, KEY_RECORD },
	{ 0x0017, KEY_PLAYPAUSE },
	{ 0x0816, KEY_PLAYPAUSE },
	{ 0x000b, KEY_STOP },
	{ 0x0827, KEY_FASTFORWARD },
	{ 0x0026, KEY_REWIND },
	{ 0x081e, KEY_UNKNOWN },    /* Time Shift */
	{ 0x000e, KEY_UNKNOWN },    /* Snapshot */
	{ 0x082d, KEY_UNKNOWN },    /* Mouse Cursor */
	{ 0x000f, KEY_UNKNOWN },    /* Minimize/Maximize */
	{ 0x0814, KEY_UNKNOWN },    /* Shuffle */
	{ 0x0025, KEY_POWER },
587 588
};

589 590
static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
{
591
	static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x28 };
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
	static u8 reset []         = { RESET,      0x80 };
	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
	static u8 agc_cfg []       = { AGC_TARGET, 0x28, 0x20 };
	static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };

	mt352_write(fe, clock_config,   sizeof(clock_config));
	udelay(200);
	mt352_write(fe, reset,          sizeof(reset));
	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));

	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
	mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));

	return 0;
}

M
 
Michael Krufky 已提交
610 611
static int cxusb_mt352_demod_init(struct dvb_frontend* fe)
{	/* used in both lgz201 and th7579 */
612
	static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x29 };
M
 
Michael Krufky 已提交
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
	static u8 reset []         = { RESET,      0x80 };
	static u8 adc_ctl_1_cfg [] = { ADC_CTL_1,  0x40 };
	static u8 agc_cfg []       = { AGC_TARGET, 0x24, 0x20 };
	static u8 gpp_ctl_cfg []   = { GPP_CTL,    0x33 };
	static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };

	mt352_write(fe, clock_config,   sizeof(clock_config));
	udelay(200);
	mt352_write(fe, reset,          sizeof(reset));
	mt352_write(fe, adc_ctl_1_cfg,  sizeof(adc_ctl_1_cfg));

	mt352_write(fe, agc_cfg,        sizeof(agc_cfg));
	mt352_write(fe, gpp_ctl_cfg,    sizeof(gpp_ctl_cfg));
	mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
	return 0;
}

630
static struct cx22702_config cxusb_cx22702_config = {
631
	.demod_address = 0x63,
632
	.output_mode = CX22702_PARALLEL_OUTPUT,
633 634
};

635
static struct lgdt330x_config cxusb_lgdt3303_config = {
636 637 638 639
	.demod_address = 0x0e,
	.demod_chip    = LGDT3303,
};

640 641 642 643 644 645
static struct lgdt330x_config cxusb_aver_lgdt3303_config = {
	.demod_address       = 0x0e,
	.demod_chip          = LGDT3303,
	.clock_polarity_flip = 2,
};

646
static struct mt352_config cxusb_dee1601_config = {
647 648 649 650
	.demod_address = 0x0f,
	.demod_init    = cxusb_dee1601_demod_init,
};

651 652
static struct zl10353_config cxusb_zl10353_dee1601_config = {
	.demod_address = 0x0f,
653
	.parallel_ts = 1,
654 655
};

656
static struct mt352_config cxusb_mt352_config = {
M
 
Michael Krufky 已提交
657 658 659 660 661
	/* used in both lgz201 and th7579 */
	.demod_address = 0x0f,
	.demod_init    = cxusb_mt352_demod_init,
};

662 663
static struct zl10353_config cxusb_zl10353_xc3028_config = {
	.demod_address = 0x0f,
664
	.if2 = 45600,
665 666 667 668
	.no_tuner = 1,
	.parallel_ts = 1,
};

669 670 671 672 673 674 675 676
static struct zl10353_config cxusb_zl10353_xc3028_config_no_i2c_gate = {
	.demod_address = 0x0f,
	.if2 = 45600,
	.no_tuner = 1,
	.parallel_ts = 1,
	.disable_i2c_gate_ctrl = 1,
};

677 678 679 680 681 682 683
static struct mt352_config cxusb_mt352_xc3028_config = {
	.demod_address = 0x0f,
	.if2 = 4560,
	.no_tuner = 1,
	.demod_init = cxusb_mt352_demod_init,
};

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
/* FIXME: needs tweaking */
static struct mxl5005s_config aver_a868r_tuner = {
	.i2c_address     = 0x63,
	.if_freq         = 6000000UL,
	.xtal_freq       = CRYSTAL_FREQ_16000000HZ,
	.agc_mode        = MXL_SINGLE_AGC,
	.tracking_filter = MXL_TF_C,
	.rssi_enable     = MXL_RSSI_ENABLE,
	.cap_select      = MXL_CAP_SEL_ENABLE,
	.div_out         = MXL_DIV_OUT_4,
	.clock_out       = MXL_CLOCK_OUT_DISABLE,
	.output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
	.top		 = MXL5005S_TOP_25P2,
	.mod_mode        = MXL_DIGITAL_MODE,
	.if_mode         = MXL_ZERO_IF,
	.AgcMasterByte   = 0x00,
};

702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
/* FIXME: needs tweaking */
static struct mxl5005s_config d680_dmb_tuner = {
	.i2c_address     = 0x63,
	.if_freq         = 36125000UL,
	.xtal_freq       = CRYSTAL_FREQ_16000000HZ,
	.agc_mode        = MXL_SINGLE_AGC,
	.tracking_filter = MXL_TF_C,
	.rssi_enable     = MXL_RSSI_ENABLE,
	.cap_select      = MXL_CAP_SEL_ENABLE,
	.div_out         = MXL_DIV_OUT_4,
	.clock_out       = MXL_CLOCK_OUT_DISABLE,
	.output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
	.top		 = MXL5005S_TOP_25P2,
	.mod_mode        = MXL_DIGITAL_MODE,
	.if_mode         = MXL_ZERO_IF,
	.AgcMasterByte   = 0x00,
};

720 721 722 723 724
static struct max2165_config mygica_d689_max2165_cfg = {
	.i2c_address = 0x60,
	.osc_clk = 20
};

725
/* Callbacks for DVB USB */
726
static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
727
{
728
	dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
729 730
		   &adap->dev->i2c_adap, 0x61,
		   TUNER_PHILIPS_FMD1216ME_MK3);
731 732 733
	return 0;
}

734
static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
735
{
736
	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61,
737
		   NULL, DVB_PLL_THOMSON_DTT7579);
738 739 740
	return 0;
}

741
static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
M
 
Michael Krufky 已提交
742
{
743
	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x61, NULL, DVB_PLL_LG_Z201);
M
 
Michael Krufky 已提交
744 745 746
	return 0;
}

747
static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
M
 
Michael Krufky 已提交
748
{
749
	dvb_attach(dvb_pll_attach, adap->fe_adap[0].fe, 0x60,
750
		   NULL, DVB_PLL_THOMSON_DTT7579);
751 752 753
	return 0;
}

754
static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
755
{
756
	dvb_attach(simple_tuner_attach, adap->fe_adap[0].fe,
757
		   &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
M
 
Michael Krufky 已提交
758 759 760
	return 0;
}

761 762
static int dvico_bluebird_xc2028_callback(void *ptr, int component,
					  int command, int arg)
763
{
764 765
	struct dvb_usb_adapter *adap = ptr;
	struct dvb_usb_device *d = adap->dev;
766 767 768

	switch (command) {
	case XC2028_TUNER_RESET:
769
		deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);
770 771 772
		cxusb_bluebird_gpio_pulse(d, 0x01, 1);
		break;
	case XC2028_RESET_CLK:
773
		deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
774 775
		break;
	default:
776
		deb_info("%s: unknown command %d, arg %d\n", __func__,
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
			 command, arg);
		return -EINVAL;
	}

	return 0;
}

static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dvb_frontend	 *fe;
	struct xc2028_config	  cfg = {
		.i2c_adap  = &adap->dev->i2c_adap,
		.i2c_addr  = 0x61,
	};
	static struct xc2028_ctrl ctl = {
792
		.fname       = XC2028_DEFAULT_FIRMWARE,
793
		.max_len     = 64,
794
		.demod       = XC3028_FE_ZARLINK456,
795 796
	};

797
	/* FIXME: generalize & move to common area */
798
	adap->fe_adap[0].fe->callback = dvico_bluebird_xc2028_callback;
799

800
	fe = dvb_attach(xc2028_attach, adap->fe_adap[0].fe, &cfg);
801 802 803 804 805 806 807 808
	if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
		return -EIO;

	fe->ops.tuner_ops.set_config(fe, &ctl);

	return 0;
}

809 810
static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
{
811
	dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
812 813 814 815
		   &adap->dev->i2c_adap, &aver_a868r_tuner);
	return 0;
}

816 817 818
static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dvb_frontend *fe;
819
	fe = dvb_attach(mxl5005s_attach, adap->fe_adap[0].fe,
820 821 822 823
			&adap->dev->i2c_adap, &d680_dmb_tuner);
	return (fe == NULL) ? -EIO : 0;
}

824 825 826
static int cxusb_mygica_d689_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dvb_frontend *fe;
827
	fe = dvb_attach(max2165_attach, adap->fe_adap[0].fe,
828 829 830 831
			&adap->dev->i2c_adap, &mygica_d689_max2165_cfg);
	return (fe == NULL) ? -EIO : 0;
}

832
static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
833
{
834
	u8 b;
835
	if (usb_set_interface(adap->dev->udev, 0, 6) < 0)
836
		err("set interface failed");
837

838
	cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);
839

840 841 842
	adap->fe_adap[0].fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
					 &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) != NULL)
843 844 845 846 847
		return 0;

	return -EIO;
}

848
static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
849
{
850
	if (usb_set_interface(adap->dev->udev, 0, 7) < 0)
851 852
		err("set interface failed");

853
	cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
854

855 856 857 858
	adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach,
					 &cxusb_lgdt3303_config,
					 &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) != NULL)
859 860 861 862 863
		return 0;

	return -EIO;
}

864 865
static int cxusb_aver_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
{
866
	adap->fe_adap[0].fe = dvb_attach(lgdt330x_attach, &cxusb_aver_lgdt3303_config,
867
			      &adap->dev->i2c_adap);
868
	if (adap->fe_adap[0].fe != NULL)
869 870 871 872 873
		return 0;

	return -EIO;
}

874 875 876 877
static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
{
	/* used in both lgz201 and th7579 */
	if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
M
 
Michael Krufky 已提交
878 879
		err("set interface failed");

880
	cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
M
 
Michael Krufky 已提交
881

882 883 884
	adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
					 &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) != NULL)
M
 
Michael Krufky 已提交
885 886 887 888 889
		return 0;

	return -EIO;
}

890
static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
891
{
892
	if (usb_set_interface(adap->dev->udev, 0, 0) < 0)
893 894
		err("set interface failed");

895
	cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
896

897 898 899 900 901 902 903 904 905
	adap->fe_adap[0].fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
					 &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) != NULL)
		return 0;

	adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
					 &cxusb_zl10353_dee1601_config,
					 &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) != NULL)
906 907 908 909 910
		return 0;

	return -EIO;
}

911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
static int cxusb_dualdig4_frontend_attach(struct dvb_usb_adapter *adap)
{
	u8 ircode[4];
	int i;
	struct i2c_msg msg = { .addr = 0x6b, .flags = I2C_M_RD,
			       .buf = ircode, .len = 4 };

	if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
		err("set interface failed");

	cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);

	/* reset the tuner and demodulator */
	cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
	cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
	cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);

928 929 930 931 932
	adap->fe_adap[0].fe =
		dvb_attach(zl10353_attach,
			   &cxusb_zl10353_xc3028_config_no_i2c_gate,
			   &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) == NULL)
933 934 935
		return -EIO;

	/* try to determine if there is no IR decoder on the I2C bus */
936
	for (i = 0; adap->dev->props.rc.legacy.rc_map_table != NULL && i < 5; i++) {
937 938 939 940 941 942 943
		msleep(20);
		if (cxusb_i2c_xfer(&adap->dev->i2c_adap, &msg, 1) != 1)
			goto no_IR;
		if (ircode[0] == 0 && ircode[1] == 0)
			continue;
		if (ircode[2] + ircode[3] != 0xff) {
no_IR:
944
			adap->dev->props.rc.legacy.rc_map_table = NULL;
945 946 947 948 949 950 951 952
			info("No IR receiver detected on this device.");
			break;
		}
	}

	return 0;
}

953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
static struct dibx000_agc_config dib7070_agc_config = {
	.band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,

	/*
	 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
	 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
	 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
	 */
	.setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
		 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
	.inv_gain = 600,
	.time_stabiliz = 10,
	.alpha_level = 0,
	.thlock = 118,
	.wbd_inv = 0,
	.wbd_ref = 3530,
	.wbd_sel = 1,
	.wbd_alpha = 5,
	.agc1_max = 65535,
	.agc1_min = 0,
	.agc2_max = 65535,
	.agc2_min = 0,
	.agc1_pt1 = 0,
	.agc1_pt2 = 40,
	.agc1_pt3 = 183,
	.agc1_slope1 = 206,
	.agc1_slope2 = 255,
	.agc2_pt1 = 72,
	.agc2_pt2 = 152,
	.agc2_slope1 = 88,
	.agc2_slope2 = 90,
	.alpha_mant = 17,
	.alpha_exp = 27,
	.beta_mant = 23,
	.beta_exp = 51,
	.perform_agc_softsplit = 0,
};

static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
	.internal = 60000,
	.sampling = 15000,
	.pll_prediv = 1,
	.pll_ratio = 20,
	.pll_range = 3,
	.pll_reset = 1,
	.pll_bypass = 0,
	.enable_refdiv = 0,
	.bypclk_div = 0,
	.IO_CLK_en_core = 1,
	.ADClkSrc = 1,
	.modulo = 2,
	/* refsel, sel, freq_15k */
	.sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
	.ifreq = (0 << 25) | 0,
	.timf = 20452225,
	.xtal_hz = 12000000,
};

static struct dib7000p_config cxusb_dualdig4_rev2_config = {
	.output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
	.output_mpeg2_in_188_bytes = 1,

	.agc_config_count = 1,
	.agc = &dib7070_agc_config,
	.bw  = &dib7070_bw_config_12_mhz,
	.tuner_is_baseband = 1,
	.spur_protect = 1,

	.gpio_dir = 0xfcef,
	.gpio_val = 0x0110,

	.gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,

	.hostbus_diversity = 1,
};

static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
{
	if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
		err("set interface failed");

	cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);

	cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);

1038
	if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1039 1040
				     &cxusb_dualdig4_rev2_config) < 0) {
		printk(KERN_WARNING "Unable to enumerate dib7000p\n");
1041
		return -ENODEV;
1042
	}
1043

1044
	adap->fe_adap[0].fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
1045
			      &cxusb_dualdig4_rev2_config);
1046
	if (adap->fe_adap[0].fe == NULL)
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
		return -EIO;

	return 0;
}

static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
{
	return dib7000p_set_gpio(fe, 8, 0, !onoff);
}

static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
{
	return 0;
}

static struct dib0070_config dib7070p_dib0070_config = {
	.i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
	.reset = dib7070_tuner_reset,
	.sleep = dib7070_tuner_sleep,
	.clock_khz = 12000,
};

struct dib0700_adapter_state {
1070
	int (*set_param_save) (struct dvb_frontend *);
1071 1072
};

1073
static int dib7070_set_param_override(struct dvb_frontend *fe)
1074
{
1075
	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1076 1077 1078 1079
	struct dvb_usb_adapter *adap = fe->dvb->priv;
	struct dib0700_adapter_state *state = adap->priv;

	u16 offset;
1080
	u8 band = BAND_OF_FREQUENCY(p->frequency/1000);
1081
	switch (band) {
1082 1083 1084
	case BAND_VHF: offset = 950; break;
	default:
	case BAND_UHF: offset = 550; break;
1085 1086 1087 1088
	}

	dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));

1089
	return state->set_param_save(fe);
1090 1091 1092 1093 1094
}

static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
{
	struct dib0700_adapter_state *st = adap->priv;
1095
	struct i2c_adapter *tun_i2c =
1096
		dib7000p_get_i2c_master(adap->fe_adap[0].fe,
1097
					DIBX000_I2C_INTERFACE_TUNER, 1);
1098

1099
	if (dvb_attach(dib0070_attach, adap->fe_adap[0].fe, tun_i2c,
1100 1101 1102
	    &dib7070p_dib0070_config) == NULL)
		return -ENODEV;

1103 1104
	st->set_param_save = adap->fe_adap[0].fe->ops.tuner_ops.set_params;
	adap->fe_adap[0].fe->ops.tuner_ops.set_params = dib7070_set_param_override;
1105 1106 1107
	return 0;
}

1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
{
	if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
		err("set interface failed");

	cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);

	/* reset the tuner and demodulator */
	cxusb_bluebird_gpio_rw(adap->dev, 0x04, 0);
	cxusb_bluebird_gpio_pulse(adap->dev, 0x01, 1);
	cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);

1120 1121 1122 1123
	adap->fe_adap[0].fe = dvb_attach(zl10353_attach,
					 &cxusb_zl10353_xc3028_config,
					 &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) != NULL)
1124 1125
		return 0;

1126 1127 1128 1129
	adap->fe_adap[0].fe = dvb_attach(mt352_attach,
					 &cxusb_mt352_xc3028_config,
					 &adap->dev->i2c_adap);
	if ((adap->fe_adap[0].fe) != NULL)
1130 1131
		return 0;

1132 1133 1134
	return -EIO;
}

1135 1136
static struct lgs8gxx_config d680_lgs8gl5_cfg = {
	.prod = LGS8GXX_PROD_LGS8GL5,
1137
	.demod_address = 0x19,
1138 1139 1140 1141 1142 1143 1144 1145 1146
	.serial_ts = 0,
	.ts_clk_pol = 0,
	.ts_clk_gated = 1,
	.if_clk_freq = 30400, /* 30.4 MHz */
	.if_freq = 5725, /* 5.725 MHz */
	.if_neg_center = 0,
	.ext_adc = 0,
	.adc_signed = 0,
	.if_neg_edge = 0,
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
};

static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dvb_usb_device *d = adap->dev;
	int n;

	/* Select required USB configuration */
	if (usb_set_interface(d->udev, 0, 0) < 0)
		err("set interface failed");

	/* Unblock all USB pipes */
	usb_clear_halt(d->udev,
		usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
	usb_clear_halt(d->udev,
		usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
	usb_clear_halt(d->udev,
1164
		usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185

	/* Drain USB pipes to avoid hang after reboot */
	for (n = 0;  n < 5;  n++) {
		cxusb_d680_dmb_drain_message(d);
		cxusb_d680_dmb_drain_video(d);
		msleep(200);
	}

	/* Reset the tuner */
	if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
		err("clear tuner gpio failed");
		return -EIO;
	}
	msleep(100);
	if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
		err("set tuner gpio failed");
		return -EIO;
	}
	msleep(100);

	/* Attach frontend */
1186 1187
	adap->fe_adap[0].fe = dvb_attach(lgs8gxx_attach, &d680_lgs8gl5_cfg, &d->i2c_adap);
	if (adap->fe_adap[0].fe == NULL)
1188 1189 1190 1191 1192
		return -EIO;

	return 0;
}

1193 1194 1195 1196 1197 1198 1199 1200 1201
static struct atbm8830_config mygica_d689_atbm8830_cfg = {
	.prod = ATBM8830_PROD_8830,
	.demod_address = 0x40,
	.serial_ts = 0,
	.ts_sampling_edge = 1,
	.ts_clk_gated = 0,
	.osc_clk_freq = 30400, /* in kHz */
	.if_freq = 0, /* zero IF */
	.zif_swap_iq = 1,
1202 1203 1204
	.agc_min = 0x2E,
	.agc_max = 0x90,
	.agc_hold_loop = 0,
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
};

static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
{
	struct dvb_usb_device *d = adap->dev;

	/* Select required USB configuration */
	if (usb_set_interface(d->udev, 0, 0) < 0)
		err("set interface failed");

	/* Unblock all USB pipes */
	usb_clear_halt(d->udev,
		usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
	usb_clear_halt(d->udev,
		usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
	usb_clear_halt(d->udev,
1221
		usb_rcvbulkpipe(d->udev, d->props.adapter[0].fe[0].stream.endpoint));
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236


	/* Reset the tuner */
	if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
		err("clear tuner gpio failed");
		return -EIO;
	}
	msleep(100);
	if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
		err("set tuner gpio failed");
		return -EIO;
	}
	msleep(100);

	/* Attach frontend */
1237
	adap->fe_adap[0].fe = dvb_attach(atbm8830_attach, &mygica_d689_atbm8830_cfg,
1238
		&d->i2c_adap);
1239
	if (adap->fe_adap[0].fe == NULL)
1240 1241 1242 1243 1244
		return -EIO;

	return 0;
}

1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
/*
 * DViCO has shipped two devices with the same USB ID, but only one of them
 * needs a firmware download.  Check the device class details to see if they
 * have non-default values to decide whether the device is actually cold or
 * not, and forget a match if it turns out we selected the wrong device.
 */
static int bluebird_fx2_identify_state(struct usb_device *udev,
				       struct dvb_usb_device_properties *props,
				       struct dvb_usb_device_description **desc,
				       int *cold)
{
	int wascold = *cold;

	*cold = udev->descriptor.bDeviceClass == 0xff &&
		udev->descriptor.bDeviceSubClass == 0xff &&
		udev->descriptor.bDeviceProtocol == 0xff;

	if (*cold && !wascold)
		*desc = NULL;

	return 0;
}

1268 1269 1270 1271 1272
/*
 * DViCO bluebird firmware needs the "warm" product ID to be patched into the
 * firmware file before download.
 */

1273
static const int dvico_firmware_id_offsets[] = { 6638, 3204 };
1274 1275
static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
						  const struct firmware *fw)
1276
{
1277 1278 1279 1280
	int pos;

	for (pos = 0; pos < ARRAY_SIZE(dvico_firmware_id_offsets); pos++) {
		int idoff = dvico_firmware_id_offsets[pos];
1281

1282 1283
		if (fw->size < idoff + 4)
			continue;
1284

1285 1286
		if (fw->data[idoff] == (USB_VID_DVICO & 0xff) &&
		    fw->data[idoff + 1] == USB_VID_DVICO >> 8) {
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
			struct firmware new_fw;
			u8 *new_fw_data = vmalloc(fw->size);
			int ret;

			if (!new_fw_data)
				return -ENOMEM;

			memcpy(new_fw_data, fw->data, fw->size);
			new_fw.size = fw->size;
			new_fw.data = new_fw_data;

			new_fw_data[idoff + 2] =
1299
				le16_to_cpu(udev->descriptor.idProduct) + 1;
1300
			new_fw_data[idoff + 3] =
1301
				le16_to_cpu(udev->descriptor.idProduct) >> 8;
1302

1303 1304 1305 1306
			ret = usb_cypress_load_firmware(udev, &new_fw,
							CYPRESS_FX2);
			vfree(new_fw_data);
			return ret;
1307
		}
1308 1309 1310 1311 1312
	}

	return -EINVAL;
}

1313
/* DVB USB Driver stuff */
1314 1315 1316 1317 1318
static struct dvb_usb_device_properties cxusb_medion_properties;
static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties;
static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
1319
static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
1320
static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
1321
static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
1322
static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
1323
static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1324
static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
1325
static struct dvb_usb_device_properties cxusb_mygica_d689_properties;
1326 1327

static int cxusb_probe(struct usb_interface *intf,
1328
		       const struct usb_device_id *id)
1329
{
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
	if (0 == dvb_usb_device_init(intf, &cxusb_medion_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgh064f_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf, &cxusb_bluebird_dee1601_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgz201_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf, &cxusb_bluebird_dtt7579_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf, &cxusb_bluebird_dualdig4_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf, &cxusb_bluebird_nano2_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf,
				&cxusb_bluebird_nano2_needsfirmware_properties,
1346 1347 1348
				     THIS_MODULE, NULL, adapter_nr) ||
	    0 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
1349 1350 1351
	    0 == dvb_usb_device_init(intf,
				     &cxusb_bluebird_dualdig4_rev2_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
1352 1353
	    0 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
1354 1355
	    0 == dvb_usb_device_init(intf, &cxusb_mygica_d689_properties,
				     THIS_MODULE, NULL, adapter_nr) ||
1356
	    0)
1357 1358 1359
		return 0;

	return -EINVAL;
1360 1361 1362
}

static struct usb_device_id cxusb_table [] = {
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
	{ USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) },
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) },
1376
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4) },
1377
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) },
1378
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },
1379
	{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) },
1380
	{ USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2) },
1381
	{ USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB) },
1382
	{ USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_D689) },
1383
	{}		/* Terminating entry */
1384 1385 1386
};
MODULE_DEVICE_TABLE (usb, cxusb_table);

1387
static struct dvb_usb_device_properties cxusb_medion_properties = {
1388 1389 1390 1391 1392 1393
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl = CYPRESS_FX2,

	.size_of_priv     = sizeof(struct cxusb_state),

1394 1395 1396
	.num_adapters = 1,
	.adapter = {
		{
1397 1398
		.num_frontends = 1,
		.fe = {{
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_cx22702_frontend_attach,
			.tuner_attach     = cxusb_fmd1216me_tuner_attach,
			/* parameter for the MPEG2-data transfer */
					.stream = {
						.type = USB_BULK,
				.count = 5,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1413
		}},
1414 1415 1416 1417 1418 1419 1420 1421
		},
	},
	.power_ctrl       = cxusb_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

1422 1423 1424 1425 1426 1427 1428 1429 1430
	.num_device_descs = 1,
	.devices = {
		{   "Medion MD95700 (MDUSBTV-HYBRID)",
			{ NULL },
			{ &cxusb_table[0], NULL },
		},
	}
};

1431
static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
1432 1433
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

1434 1435 1436
	.usb_ctrl          = DEVICE_SPECIFIC,
	.firmware          = "dvb-usb-bluebird-01.fw",
	.download_firmware = bluebird_patch_dvico_firmware_download,
1437 1438
	/* use usb alt setting 0 for EP4 transfer (dvb-t),
	   use usb alt setting 7 for EP2 transfer (atsc) */
1439 1440 1441

	.size_of_priv     = sizeof(struct cxusb_state),

1442 1443 1444
	.num_adapters = 1,
	.adapter = {
		{
1445 1446
		.num_frontends = 1,
		.fe = {{
1447 1448
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_lgdt3303_frontend_attach,
1449
			.tuner_attach     = cxusb_lgh064f_tuner_attach,
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461

			/* parameter for the MPEG2-data transfer */
					.stream = {
						.type = USB_BULK,
				.count = 5,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1462
		}},
1463 1464 1465 1466 1467 1468 1469
		},
	},

	.power_ctrl       = cxusb_bluebird_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

1470 1471
	.rc.legacy = {
		.rc_interval      = 100,
1472 1473
		.rc_map_table     = rc_map_dvico_portable_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_portable_table),
1474 1475
		.rc_query         = cxusb_rc_query,
	},
1476 1477

	.generic_bulk_ctrl_endpoint = 0x01,
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487

	.num_device_descs = 1,
	.devices = {
		{   "DViCO FusionHDTV5 USB Gold",
			{ &cxusb_table[1], NULL },
			{ &cxusb_table[2], NULL },
		},
	}
};

1488
static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
1489 1490
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

1491 1492 1493
	.usb_ctrl          = DEVICE_SPECIFIC,
	.firmware          = "dvb-usb-bluebird-01.fw",
	.download_firmware = bluebird_patch_dvico_firmware_download,
1494 1495 1496 1497 1498
	/* use usb alt setting 0 for EP4 transfer (dvb-t),
	   use usb alt setting 7 for EP2 transfer (atsc) */

	.size_of_priv     = sizeof(struct cxusb_state),

1499 1500 1501
	.num_adapters = 1,
	.adapter = {
		{
1502 1503
		.num_frontends = 1,
		.fe = {{
1504 1505 1506 1507
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_dee1601_frontend_attach,
			.tuner_attach     = cxusb_dee1601_tuner_attach,
			/* parameter for the MPEG2-data transfer */
1508 1509
			.stream = {
				.type = USB_BULK,
1510 1511 1512 1513 1514 1515 1516 1517
				.count = 5,
				.endpoint = 0x04,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1518
		}},
1519 1520 1521 1522 1523 1524 1525
		},
	},

	.power_ctrl       = cxusb_bluebird_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

1526 1527
	.rc.legacy = {
		.rc_interval      = 150,
1528 1529
		.rc_map_table     = rc_map_dvico_mce_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_mce_table),
1530 1531
		.rc_query         = cxusb_rc_query,
	},
1532 1533

	.generic_bulk_ctrl_endpoint = 0x01,
1534

1535
	.num_device_descs = 3,
1536 1537 1538 1539 1540
	.devices = {
		{   "DViCO FusionHDTV DVB-T Dual USB",
			{ &cxusb_table[3], NULL },
			{ &cxusb_table[4], NULL },
		},
1541 1542 1543 1544
		{   "DigitalNow DVB-T Dual USB",
			{ &cxusb_table[9],  NULL },
			{ &cxusb_table[10], NULL },
		},
1545 1546 1547 1548
		{   "DViCO FusionHDTV DVB-T Dual Digital 2",
			{ &cxusb_table[11], NULL },
			{ &cxusb_table[12], NULL },
		},
1549 1550 1551
	}
};

1552
static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
M
 
Michael Krufky 已提交
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl          = DEVICE_SPECIFIC,
	.firmware          = "dvb-usb-bluebird-01.fw",
	.download_firmware = bluebird_patch_dvico_firmware_download,
	/* use usb alt setting 0 for EP4 transfer (dvb-t),
	   use usb alt setting 7 for EP2 transfer (atsc) */

	.size_of_priv     = sizeof(struct cxusb_state),

1563 1564 1565
	.num_adapters = 2,
	.adapter = {
		{
1566 1567
		.num_frontends = 1,
		.fe = {{
1568 1569 1570
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_mt352_frontend_attach,
			.tuner_attach     = cxusb_lgz201_tuner_attach,
M
 
Michael Krufky 已提交
1571

1572
			/* parameter for the MPEG2-data transfer */
1573 1574
			.stream = {
				.type = USB_BULK,
1575 1576 1577 1578 1579 1580 1581 1582
				.count = 5,
				.endpoint = 0x04,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1583
		}},
1584 1585 1586 1587 1588
		},
	},
	.power_ctrl       = cxusb_bluebird_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,
M
 
Michael Krufky 已提交
1589

1590 1591
	.rc.legacy = {
		.rc_interval      = 100,
1592 1593
		.rc_map_table     = rc_map_dvico_portable_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_portable_table),
1594 1595
		.rc_query         = cxusb_rc_query,
	},
1596 1597

	.generic_bulk_ctrl_endpoint = 0x01,
M
 
Michael Krufky 已提交
1598 1599 1600 1601 1602 1603 1604 1605 1606
	.num_device_descs = 1,
	.devices = {
		{   "DViCO FusionHDTV DVB-T USB (LGZ201)",
			{ &cxusb_table[5], NULL },
			{ &cxusb_table[6], NULL },
		},
	}
};

1607
static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
M
 
Michael Krufky 已提交
1608 1609 1610 1611 1612 1613 1614 1615 1616 1617
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl          = DEVICE_SPECIFIC,
	.firmware          = "dvb-usb-bluebird-01.fw",
	.download_firmware = bluebird_patch_dvico_firmware_download,
	/* use usb alt setting 0 for EP4 transfer (dvb-t),
	   use usb alt setting 7 for EP2 transfer (atsc) */

	.size_of_priv     = sizeof(struct cxusb_state),

1618 1619 1620
	.num_adapters = 1,
	.adapter = {
		{
1621 1622
		.num_frontends = 1,
		.fe = {{
1623 1624 1625
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_mt352_frontend_attach,
			.tuner_attach     = cxusb_dtt7579_tuner_attach,
M
 
Michael Krufky 已提交
1626

1627
			/* parameter for the MPEG2-data transfer */
1628 1629
			.stream = {
				.type = USB_BULK,
1630 1631 1632 1633 1634 1635 1636 1637
				.count = 5,
				.endpoint = 0x04,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1638
		}},
1639 1640 1641 1642 1643 1644
		},
	},
	.power_ctrl       = cxusb_bluebird_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

1645 1646
	.rc.legacy = {
		.rc_interval      = 100,
1647 1648
		.rc_map_table     = rc_map_dvico_portable_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_portable_table),
1649 1650
		.rc_query         = cxusb_rc_query,
	},
1651 1652

	.generic_bulk_ctrl_endpoint = 0x01,
M
 
Michael Krufky 已提交
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662

	.num_device_descs = 1,
	.devices = {
		{   "DViCO FusionHDTV DVB-T USB (TH7579)",
			{ &cxusb_table[7], NULL },
			{ &cxusb_table[8], NULL },
		},
	}
};

1663 1664 1665 1666 1667 1668 1669 1670 1671 1672
static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl         = CYPRESS_FX2,

	.size_of_priv     = sizeof(struct cxusb_state),

	.num_adapters = 1,
	.adapter = {
		{
1673 1674
		.num_frontends = 1,
		.fe = {{
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_dualdig4_frontend_attach,
			.tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
			/* parameter for the MPEG2-data transfer */
			.stream = {
				.type = USB_BULK,
				.count = 5,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1689
		}},
1690 1691 1692 1693 1694 1695 1696 1697 1698
		},
	},

	.power_ctrl       = cxusb_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

1699 1700
	.rc.legacy = {
		.rc_interval      = 100,
1701 1702
		.rc_map_table     = rc_map_dvico_mce_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_mce_table),
1703 1704
		.rc_query         = cxusb_bluebird2_rc_query,
	},
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714

	.num_device_descs = 1,
	.devices = {
		{   "DViCO FusionHDTV DVB-T Dual Digital 4",
			{ NULL },
			{ &cxusb_table[13], NULL },
		},
	}
};

1715 1716 1717 1718
static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl         = CYPRESS_FX2,
1719
	.identify_state   = bluebird_fx2_identify_state,
1720 1721 1722 1723 1724 1725

	.size_of_priv     = sizeof(struct cxusb_state),

	.num_adapters = 1,
	.adapter = {
		{
1726 1727
		.num_frontends = 1,
		.fe = {{
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_nano2_frontend_attach,
			.tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
			/* parameter for the MPEG2-data transfer */
			.stream = {
				.type = USB_BULK,
				.count = 5,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1742
		}},
1743 1744 1745 1746 1747 1748 1749 1750 1751
		},
	},

	.power_ctrl       = cxusb_nano2_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

1752 1753
	.rc.legacy = {
		.rc_interval      = 100,
1754 1755
		.rc_map_table     = rc_map_dvico_portable_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_portable_table),
1756 1757
		.rc_query         = cxusb_bluebird2_rc_query,
	},
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767

	.num_device_descs = 1,
	.devices = {
		{   "DViCO FusionHDTV DVB-T NANO2",
			{ NULL },
			{ &cxusb_table[14], NULL },
		},
	}
};

1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties = {
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl          = DEVICE_SPECIFIC,
	.firmware          = "dvb-usb-bluebird-02.fw",
	.download_firmware = bluebird_patch_dvico_firmware_download,
	.identify_state    = bluebird_fx2_identify_state,

	.size_of_priv      = sizeof(struct cxusb_state),

	.num_adapters = 1,
	.adapter = {
		{
1781 1782
		.num_frontends = 1,
		.fe = {{
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
			.streaming_ctrl   = cxusb_streaming_ctrl,
			.frontend_attach  = cxusb_nano2_frontend_attach,
			.tuner_attach     = cxusb_dvico_xc3028_tuner_attach,
			/* parameter for the MPEG2-data transfer */
			.stream = {
				.type = USB_BULK,
				.count = 5,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1797
		}},
1798 1799 1800 1801 1802 1803 1804 1805 1806
		},
	},

	.power_ctrl       = cxusb_nano2_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

1807 1808
	.rc.legacy = {
		.rc_interval      = 100,
1809 1810
		.rc_map_table     = rc_map_dvico_portable_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_portable_table),
1811 1812
		.rc_query         = cxusb_rc_query,
	},
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822

	.num_device_descs = 1,
	.devices = {
		{   "DViCO FusionHDTV DVB-T NANO2 w/o firmware",
			{ &cxusb_table[14], NULL },
			{ &cxusb_table[15], NULL },
		},
	}
};

1823 1824 1825 1826 1827 1828 1829 1830 1831 1832
static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl         = CYPRESS_FX2,

	.size_of_priv     = sizeof(struct cxusb_state),

	.num_adapters = 1,
	.adapter = {
		{
1833 1834
		.num_frontends = 1,
		.fe = {{
1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848
			.streaming_ctrl   = cxusb_aver_streaming_ctrl,
			.frontend_attach  = cxusb_aver_lgdt3303_frontend_attach,
			.tuner_attach     = cxusb_mxl5003s_tuner_attach,
			/* parameter for the MPEG2-data transfer */
			.stream = {
				.type = USB_BULK,
				.count = 5,
				.endpoint = 0x04,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1849
		}},
1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
		},
	},
	.power_ctrl       = cxusb_aver_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

	.num_device_descs = 1,
	.devices = {
		{   "AVerMedia AVerTVHD Volar (A868R)",
			{ NULL },
			{ &cxusb_table[16], NULL },
		},
	}
};

1867 1868
static
struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
1869 1870 1871 1872 1873 1874 1875 1876 1877
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl         = CYPRESS_FX2,

	.size_of_priv     = sizeof(struct cxusb_state),

	.num_adapters = 1,
	.adapter = {
		{
1878 1879 1880
		.size_of_priv    = sizeof(struct dib0700_adapter_state),
		.num_frontends = 1,
		.fe = {{
1881 1882 1883
			.streaming_ctrl  = cxusb_streaming_ctrl,
			.frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
			.tuner_attach    = cxusb_dualdig4_rev2_tuner_attach,
1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894
			/* parameter for the MPEG2-data transfer */
			.stream = {
				.type = USB_BULK,
				.count = 7,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 4096,
					}
				}
			},
1895
		}},
1896 1897 1898 1899 1900 1901 1902 1903 1904
		},
	},

	.power_ctrl       = cxusb_bluebird_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

1905 1906
	.rc.legacy = {
		.rc_interval      = 100,
1907 1908
		.rc_map_table     = rc_map_dvico_mce_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_dvico_mce_table),
1909 1910
		.rc_query         = cxusb_rc_query,
	},
1911 1912 1913 1914 1915 1916 1917 1918 1919 1920

	.num_device_descs = 1,
	.devices = {
		{   "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
			{ NULL },
			{ &cxusb_table[17], NULL },
		},
	}
};

1921 1922 1923 1924 1925 1926 1927 1928 1929 1930
static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl         = CYPRESS_FX2,

	.size_of_priv     = sizeof(struct cxusb_state),

	.num_adapters = 1,
	.adapter = {
		{
1931 1932
		.num_frontends = 1,
		.fe = {{
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
			.streaming_ctrl   = cxusb_d680_dmb_streaming_ctrl,
			.frontend_attach  = cxusb_d680_dmb_frontend_attach,
			.tuner_attach     = cxusb_d680_dmb_tuner_attach,

			/* parameter for the MPEG2-data transfer */
			.stream = {
				.type = USB_BULK,
				.count = 5,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
1948
		}},
1949 1950 1951 1952 1953 1954 1955 1956 1957
		},
	},

	.power_ctrl       = cxusb_d680_dmb_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

1958 1959
	.rc.legacy = {
		.rc_interval      = 100,
1960 1961
		.rc_map_table     = rc_map_d680_dmb_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_d680_dmb_table),
1962 1963
		.rc_query         = cxusb_d680_dmb_rc_query,
	},
1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974

	.num_device_descs = 1,
	.devices = {
		{
			"Conexant DMB-TH Stick",
			{ NULL },
			{ &cxusb_table[18], NULL },
		},
	}
};

1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
	.caps = DVB_USB_IS_AN_I2C_ADAPTER,

	.usb_ctrl         = CYPRESS_FX2,

	.size_of_priv     = sizeof(struct cxusb_state),

	.num_adapters = 1,
	.adapter = {
		{
1985 1986
		.num_frontends = 1,
		.fe = {{
1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001
			.streaming_ctrl   = cxusb_d680_dmb_streaming_ctrl,
			.frontend_attach  = cxusb_mygica_d689_frontend_attach,
			.tuner_attach     = cxusb_mygica_d689_tuner_attach,

			/* parameter for the MPEG2-data transfer */
			.stream = {
				.type = USB_BULK,
				.count = 5,
				.endpoint = 0x02,
				.u = {
					.bulk = {
						.buffersize = 8192,
					}
				}
			},
2002
		}},
2003 2004 2005 2006 2007 2008 2009 2010 2011
		},
	},

	.power_ctrl       = cxusb_d680_dmb_power_ctrl,

	.i2c_algo         = &cxusb_i2c_algo,

	.generic_bulk_ctrl_endpoint = 0x01,

2012 2013
	.rc.legacy = {
		.rc_interval      = 100,
2014 2015
		.rc_map_table     = rc_map_d680_dmb_table,
		.rc_map_size      = ARRAY_SIZE(rc_map_d680_dmb_table),
2016 2017
		.rc_query         = cxusb_d680_dmb_rc_query,
	},
2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028

	.num_device_descs = 1,
	.devices = {
		{
			"Mygica D689 DMB-TH",
			{ NULL },
			{ &cxusb_table[19], NULL },
		},
	}
};

2029
static struct usb_driver cxusb_driver = {
2030
	.name		= "dvb_usb_cxusb",
2031
	.probe		= cxusb_probe,
2032
	.disconnect     = dvb_usb_device_exit,
2033 2034 2035
	.id_table	= cxusb_table,
};

2036
module_usb_driver(cxusb_driver);
2037 2038

MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
2039
MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
2040
MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
2041 2042 2043
MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
MODULE_VERSION("1.0-alpha");
MODULE_LICENSE("GPL");