dst.c 43.5 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3 4
	Frontend/Card driver for TwinHan DST Frontend
	Copyright (C) 2003 Jamie Honan
	Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com)
L
Linus Torvalds 已提交
5

6 7 8 9
	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; either version 2 of the License, or
	(at your option) any later version.
L
Linus Torvalds 已提交
10

11 12 13 14
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
L
Linus Torvalds 已提交
15

16 17 18
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
L
Linus Torvalds 已提交
19 20 21 22 23 24 25 26 27 28 29 30
*/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <asm/div64.h>
#include "dvb_frontend.h"
#include "dst_priv.h"
31 32 33 34 35 36 37 38
#include "dst_common.h"

static unsigned int verbose = 1;
module_param(verbose, int, 0644);
MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");

static unsigned int dst_addons;
module_param(dst_addons, int, 0644);
39
MODULE_PARM_DESC(dst_addons, "CA daughterboard, default is 0 (No addons)");
L
Linus Torvalds 已提交
40

41 42 43 44
static unsigned int dst_algo;
module_param(dst_algo, int, 0644);
MODULE_PARM_DESC(dst_algo, "tuning algo: default is 0=(SW), 1=(HW)");

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#define HAS_LOCK		1
#define ATTEMPT_TUNE		2
#define HAS_POWER		4

#define DST_ERROR		0
#define DST_NOTICE		1
#define DST_INFO		2
#define DST_DEBUG		3

#define dprintk(x, y, z, format, arg...) do {						\
	if (z) {									\
		if	((x > DST_ERROR) && (x > y))					\
			printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg);	\
		else if	((x > DST_NOTICE) && (x > y))					\
			printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg);	\
		else if ((x > DST_INFO) && (x > y))					\
			printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg);	\
		else if ((x > DST_DEBUG) && (x > y))					\
			printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg);	\
	} else {									\
		if (x > y)								\
			printk(format, ##arg);						\
	}										\
} while(0)


static void dst_packsize(struct dst_state *state, int psize)
L
Linus Torvalds 已提交
72 73 74 75 76 77 78
{
	union dst_gpio_packet bits;

	bits.psize = psize;
	bt878_device_control(state->bt, DST_IG_TS, &bits);
}

79
int dst_gpio_outb(struct dst_state *state, u32 mask, u32 enbb, u32 outhigh, int delay)
L
Linus Torvalds 已提交
80 81 82 83 84 85 86
{
	union dst_gpio_packet enb;
	union dst_gpio_packet bits;
	int err;

	enb.enb.mask = mask;
	enb.enb.enable = enbb;
87

88
	dprintk(verbose, DST_INFO, 1, "mask=[%04x], enbb=[%04x], outhigh=[%04x]", mask, enbb, outhigh);
L
Linus Torvalds 已提交
89
	if ((err = bt878_device_control(state->bt, DST_IG_ENABLE, &enb)) < 0) {
90
		dprintk(verbose, DST_INFO, 1, "dst_gpio_enb error (err == %i, mask == %02x, enb == %02x)", err, mask, enbb);
L
Linus Torvalds 已提交
91 92
		return -EREMOTEIO;
	}
93
	udelay(1000);
L
Linus Torvalds 已提交
94 95 96
	/* because complete disabling means no output, no need to do output packet */
	if (enbb == 0)
		return 0;
97 98
	if (delay)
		msleep(10);
L
Linus Torvalds 已提交
99 100 101
	bits.outp.mask = enbb;
	bits.outp.highvals = outhigh;
	if ((err = bt878_device_control(state->bt, DST_IG_WRITE, &bits)) < 0) {
102
		dprintk(verbose, DST_INFO, 1, "dst_gpio_outb error (err == %i, enbb == %02x, outhigh == %02x)", err, enbb, outhigh);
L
Linus Torvalds 已提交
103 104
		return -EREMOTEIO;
	}
105

L
Linus Torvalds 已提交
106 107
	return 0;
}
108
EXPORT_SYMBOL(dst_gpio_outb);
L
Linus Torvalds 已提交
109

110
int dst_gpio_inb(struct dst_state *state, u8 *result)
L
Linus Torvalds 已提交
111 112 113 114 115 116
{
	union dst_gpio_packet rd_packet;
	int err;

	*result = 0;
	if ((err = bt878_device_control(state->bt, DST_IG_READ, &rd_packet)) < 0) {
117
		dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb error (err == %i)\n", err);
L
Linus Torvalds 已提交
118 119 120
		return -EREMOTEIO;
	}
	*result = (u8) rd_packet.rd.value;
121

L
Linus Torvalds 已提交
122 123
	return 0;
}
124
EXPORT_SYMBOL(dst_gpio_inb);
L
Linus Torvalds 已提交
125

126
int rdc_reset_state(struct dst_state *state)
L
Linus Torvalds 已提交
127
{
128
	dprintk(verbose, DST_INFO, 1, "Resetting state machine");
129
	if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, 0, NO_DELAY) < 0) {
130
		dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
131 132
		return -1;
	}
L
Linus Torvalds 已提交
133
	msleep(10);
134
	if (dst_gpio_outb(state, RDC_8820_INT, RDC_8820_INT, RDC_8820_INT, NO_DELAY) < 0) {
135
		dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
136 137 138 139
		msleep(10);
		return -1;
	}

L
Linus Torvalds 已提交
140 141
	return 0;
}
142
EXPORT_SYMBOL(rdc_reset_state);
L
Linus Torvalds 已提交
143

144
int rdc_8820_reset(struct dst_state *state)
L
Linus Torvalds 已提交
145
{
146
	dprintk(verbose, DST_DEBUG, 1, "Resetting DST");
147
	if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, 0, NO_DELAY) < 0) {
148
		dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
149 150
		return -1;
	}
151
	udelay(1000);
152
	if (dst_gpio_outb(state, RDC_8820_RESET, RDC_8820_RESET, RDC_8820_RESET, DELAY) < 0) {
153
		dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
154 155 156
		return -1;
	}

L
Linus Torvalds 已提交
157 158
	return 0;
}
159
EXPORT_SYMBOL(rdc_8820_reset);
L
Linus Torvalds 已提交
160

161
int dst_pio_enable(struct dst_state *state)
L
Linus Torvalds 已提交
162
{
163
	if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_ENABLE, 0, NO_DELAY) < 0) {
164
		dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
165 166
		return -1;
	}
167
	udelay(1000);
168

169 170 171 172 173 174 175
	return 0;
}
EXPORT_SYMBOL(dst_pio_enable);

int dst_pio_disable(struct dst_state *state)
{
	if (dst_gpio_outb(state, ~0, RDC_8820_PIO_0_DISABLE, RDC_8820_PIO_0_DISABLE, NO_DELAY) < 0) {
176
		dprintk(verbose, DST_ERROR, 1, "dst_gpio_outb ERROR !");
177 178
		return -1;
	}
179 180
	if (state->type_flags & DST_TYPE_HAS_FW_1)
		udelay(1000);
181

L
Linus Torvalds 已提交
182 183
	return 0;
}
184
EXPORT_SYMBOL(dst_pio_disable);
L
Linus Torvalds 已提交
185

186
int dst_wait_dst_ready(struct dst_state *state, u8 delay_mode)
L
Linus Torvalds 已提交
187 188 189
{
	u8 reply;
	int i;
190

L
Linus Torvalds 已提交
191
	for (i = 0; i < 200; i++) {
192
		if (dst_gpio_inb(state, &reply) < 0) {
193
			dprintk(verbose, DST_ERROR, 1, "dst_gpio_inb ERROR !");
194 195 196
			return -1;
		}
		if ((reply & RDC_8820_PIO_0_ENABLE) == 0) {
197
			dprintk(verbose, DST_INFO, 1, "dst wait ready after %d", i);
L
Linus Torvalds 已提交
198 199
			return 1;
		}
200
		msleep(10);
201
	}
202
	dprintk(verbose, DST_NOTICE, 1, "dst wait NOT ready after %d", i);
203 204 205 206 207 208 209

	return 0;
}
EXPORT_SYMBOL(dst_wait_dst_ready);

int dst_error_recovery(struct dst_state *state)
{
210
	dprintk(verbose, DST_NOTICE, 1, "Trying to return from previous errors.");
211 212 213 214 215 216 217 218 219 220 221
	dst_pio_disable(state);
	msleep(10);
	dst_pio_enable(state);
	msleep(10);

	return 0;
}
EXPORT_SYMBOL(dst_error_recovery);

int dst_error_bailout(struct dst_state *state)
{
222
	dprintk(verbose, DST_INFO, 1, "Trying to bailout from previous error.");
223 224 225 226 227 228 229 230
	rdc_8820_reset(state);
	dst_pio_disable(state);
	msleep(10);

	return 0;
}
EXPORT_SYMBOL(dst_error_bailout);

231
int dst_comm_init(struct dst_state *state)
232
{
233
	dprintk(verbose, DST_INFO, 1, "Initializing DST.");
234
	if ((dst_pio_enable(state)) < 0) {
235
		dprintk(verbose, DST_ERROR, 1, "PIO Enable Failed");
236 237 238
		return -1;
	}
	if ((rdc_reset_state(state)) < 0) {
239
		dprintk(verbose, DST_ERROR, 1, "RDC 8820 State RESET Failed.");
240
		return -1;
L
Linus Torvalds 已提交
241
	}
242 243 244 245 246
	if (state->type_flags & DST_TYPE_HAS_FW_1)
		msleep(100);
	else
		msleep(5);

L
Linus Torvalds 已提交
247 248
	return 0;
}
249
EXPORT_SYMBOL(dst_comm_init);
L
Linus Torvalds 已提交
250

251
int write_dst(struct dst_state *state, u8 *data, u8 len)
L
Linus Torvalds 已提交
252 253
{
	struct i2c_msg msg = {
254 255 256 257
		.addr = state->config->demod_address,
		.flags = 0,
		.buf = data,
		.len = len
L
Linus Torvalds 已提交
258
	};
259

L
Linus Torvalds 已提交
260
	int err;
261 262 263 264 265 266 267
	u8 cnt, i;

	dprintk(verbose, DST_NOTICE, 0, "writing [ ");
	for (i = 0; i < len; i++)
		dprintk(verbose, DST_NOTICE, 0, "%02x ", data[i]);
	dprintk(verbose, DST_NOTICE, 0, "]\n");

268
	for (cnt = 0; cnt < 2; cnt++) {
L
Linus Torvalds 已提交
269
		if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
270
			dprintk(verbose, DST_INFO, 1, "_write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, data[0]);
271
			dst_error_recovery(state);
L
Linus Torvalds 已提交
272 273 274 275
			continue;
		} else
			break;
	}
276
	if (cnt >= 2) {
277
		dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
278 279 280 281 282
		dst_error_bailout(state);

		return -1;
	}

L
Linus Torvalds 已提交
283 284
	return 0;
}
285
EXPORT_SYMBOL(write_dst);
L
Linus Torvalds 已提交
286

287
int read_dst(struct dst_state *state, u8 *ret, u8 len)
L
Linus Torvalds 已提交
288
{
289 290 291 292 293 294 295
	struct i2c_msg msg = {
		.addr = state->config->demod_address,
		.flags = I2C_M_RD,
		.buf = ret,
		.len = len
	};

L
Linus Torvalds 已提交
296 297 298
	int err;
	int cnt;

299
	for (cnt = 0; cnt < 2; cnt++) {
L
Linus Torvalds 已提交
300
		if ((err = i2c_transfer(state->i2c, &msg, 1)) < 0) {
301
			dprintk(verbose, DST_INFO, 1, "read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)", err, len, ret[0]);
302
			dst_error_recovery(state);
L
Linus Torvalds 已提交
303 304 305 306
			continue;
		} else
			break;
	}
307
	if (cnt >= 2) {
308
		dprintk(verbose, DST_INFO, 1, "RDC 8820 RESET");
309 310 311 312
		dst_error_bailout(state);

		return -1;
	}
313 314 315 316 317
	dprintk(verbose, DST_DEBUG, 1, "reply is 0x%x", ret[0]);
	for (err = 1; err < len; err++)
		dprintk(verbose, DST_DEBUG, 0, " 0x%x", ret[err]);
	if (err > 1)
		dprintk(verbose, DST_DEBUG, 0, "\n");
318

L
Linus Torvalds 已提交
319 320
	return 0;
}
321
EXPORT_SYMBOL(read_dst);
L
Linus Torvalds 已提交
322

323
static int dst_set_polarization(struct dst_state *state)
L
Linus Torvalds 已提交
324
{
325
	switch (state->voltage) {
326 327 328 329 330 331 332 333 334 335
	case SEC_VOLTAGE_13:	/*	Vertical	*/
		dprintk(verbose, DST_INFO, 1, "Polarization=[Vertical]");
		state->tx_tuna[8] &= ~0x40;
		break;
	case SEC_VOLTAGE_18:	/*	Horizontal	*/
		dprintk(verbose, DST_INFO, 1, "Polarization=[Horizontal]");
		state->tx_tuna[8] |= 0x40;
		break;
	case SEC_VOLTAGE_OFF:
		break;
336 337 338 339 340 341 342
	}

	return 0;
}

static int dst_set_freq(struct dst_state *state, u32 freq)
{
L
Linus Torvalds 已提交
343
	state->frequency = freq;
344
	dprintk(verbose, DST_INFO, 1, "set Frequency %u", freq);
L
Linus Torvalds 已提交
345 346 347 348 349

	if (state->dst_type == DST_TYPE_IS_SAT) {
		freq = freq / 1000;
		if (freq < 950 || freq > 2150)
			return -EINVAL;
350 351 352 353 354 355 356 357
		state->tx_tuna[2] = (freq >> 8);
		state->tx_tuna[3] = (u8) freq;
		state->tx_tuna[4] = 0x01;
		state->tx_tuna[8] &= ~0x04;
		if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
			if (freq < 1531)
				state->tx_tuna[8] |= 0x04;
		}
L
Linus Torvalds 已提交
358 359 360 361
	} else if (state->dst_type == DST_TYPE_IS_TERR) {
		freq = freq / 1000;
		if (freq < 137000 || freq > 858000)
			return -EINVAL;
362 363 364
		state->tx_tuna[2] = (freq >> 16) & 0xff;
		state->tx_tuna[3] = (freq >> 8) & 0xff;
		state->tx_tuna[4] = (u8) freq;
L
Linus Torvalds 已提交
365
	} else if (state->dst_type == DST_TYPE_IS_CABLE) {
366
		freq = freq / 1000;
367 368 369
		state->tx_tuna[2] = (freq >> 16) & 0xff;
		state->tx_tuna[3] = (freq >> 8) & 0xff;
		state->tx_tuna[4] = (u8) freq;
370 371 372 373 374 375 376 377 378 379 380
	} else if (state->dst_type == DST_TYPE_IS_ATSC) {
		freq = freq / 1000;
		if (freq < 51000 || freq > 858000)
			return -EINVAL;
		state->tx_tuna[2] = (freq >> 16) & 0xff;
		state->tx_tuna[3] = (freq >>  8) & 0xff;
		state->tx_tuna[4] = (u8) freq;
		state->tx_tuna[5] = 0x00;		/*	ATSC	*/
		state->tx_tuna[6] = 0x00;
		if (state->dst_hw_cap & DST_TYPE_HAS_ANALOG)
			state->tx_tuna[7] = 0x00;	/*	Digital	*/
L
Linus Torvalds 已提交
381 382
	} else
		return -EINVAL;
383

L
Linus Torvalds 已提交
384 385 386
	return 0;
}

387
static int dst_set_bandwidth(struct dst_state *state, fe_bandwidth_t bandwidth)
L
Linus Torvalds 已提交
388 389 390 391 392 393 394
{
	state->bandwidth = bandwidth;

	if (state->dst_type != DST_TYPE_IS_TERR)
		return 0;

	switch (bandwidth) {
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
	case BANDWIDTH_6_MHZ:
		if (state->dst_hw_cap & DST_TYPE_HAS_CA)
			state->tx_tuna[7] = 0x06;
		else {
			state->tx_tuna[6] = 0x06;
			state->tx_tuna[7] = 0x00;
		}
		break;
	case BANDWIDTH_7_MHZ:
		if (state->dst_hw_cap & DST_TYPE_HAS_CA)
			state->tx_tuna[7] = 0x07;
		else {
			state->tx_tuna[6] = 0x07;
			state->tx_tuna[7] = 0x00;
		}
		break;
	case BANDWIDTH_8_MHZ:
		if (state->dst_hw_cap & DST_TYPE_HAS_CA)
			state->tx_tuna[7] = 0x08;
		else {
			state->tx_tuna[6] = 0x08;
			state->tx_tuna[7] = 0x00;
		}
		break;
	default:
		return -EINVAL;
L
Linus Torvalds 已提交
421
	}
422

L
Linus Torvalds 已提交
423 424 425
	return 0;
}

426
static int dst_set_inversion(struct dst_state *state, fe_spectral_inversion_t inversion)
L
Linus Torvalds 已提交
427 428 429
{
	state->inversion = inversion;
	switch (inversion) {
430 431 432 433 434 435 436 437
	case INVERSION_OFF:	/*	Inversion = Normal	*/
		state->tx_tuna[8] &= ~0x80;
		break;
	case INVERSION_ON:
		state->tx_tuna[8] |= 0x80;
		break;
	default:
		return -EINVAL;
L
Linus Torvalds 已提交
438
	}
439

L
Linus Torvalds 已提交
440 441 442
	return 0;
}

443
static int dst_set_fec(struct dst_state *state, fe_code_rate_t fec)
L
Linus Torvalds 已提交
444 445 446 447 448
{
	state->fec = fec;
	return 0;
}

449
static fe_code_rate_t dst_get_fec(struct dst_state *state)
L
Linus Torvalds 已提交
450 451 452 453
{
	return state->fec;
}

454
static int dst_set_symbolrate(struct dst_state *state, u32 srate)
L
Linus Torvalds 已提交
455 456 457 458 459 460 461 462
{
	u32 symcalc;
	u64 sval;

	state->symbol_rate = srate;
	if (state->dst_type == DST_TYPE_IS_TERR) {
		return 0;
	}
463
	dprintk(verbose, DST_INFO, 1, "set symrate %u", srate);
L
Linus Torvalds 已提交
464 465 466 467 468 469
	srate /= 1000;
	if (state->type_flags & DST_TYPE_HAS_SYMDIV) {
		sval = srate;
		sval <<= 20;
		do_div(sval, 88000);
		symcalc = (u32) sval;
470
		dprintk(verbose, DST_INFO, 1, "set symcalc %u", symcalc);
471 472 473
		state->tx_tuna[5] = (u8) (symcalc >> 12);
		state->tx_tuna[6] = (u8) (symcalc >> 4);
		state->tx_tuna[7] = (u8) (symcalc << 4);
L
Linus Torvalds 已提交
474
	} else {
475 476 477 478 479 480 481 482
		state->tx_tuna[5] = (u8) (srate >> 16) & 0x7f;
		state->tx_tuna[6] = (u8) (srate >> 8);
		state->tx_tuna[7] = (u8) srate;
	}
	state->tx_tuna[8] &= ~0x20;
	if (state->type_flags & DST_TYPE_HAS_OBS_REGS) {
		if (srate > 8000)
			state->tx_tuna[8] |= 0x20;
L
Linus Torvalds 已提交
483 484 485 486
	}
	return 0;
}

487 488 489 490 491 492 493 494

static int dst_set_modulation(struct dst_state *state, fe_modulation_t modulation)
{
	if (state->dst_type != DST_TYPE_IS_CABLE)
		return 0;

	state->modulation = modulation;
	switch (modulation) {
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
	case QAM_16:
		state->tx_tuna[8] = 0x10;
		break;
	case QAM_32:
		state->tx_tuna[8] = 0x20;
		break;
	case QAM_64:
		state->tx_tuna[8] = 0x40;
		break;
	case QAM_128:
		state->tx_tuna[8] = 0x80;
		break;
	case QAM_256:
		state->tx_tuna[8] = 0x00;
		break;
	case QPSK:
	case QAM_AUTO:
	case VSB_8:
	case VSB_16:
	default:
		return -EINVAL;
516 517 518 519 520 521 522 523 524 525 526 527

	}

	return 0;
}

static fe_modulation_t dst_get_modulation(struct dst_state *state)
{
	return state->modulation;
}


528
u8 dst_check_sum(u8 *buf, u32 len)
L
Linus Torvalds 已提交
529 530 531 532 533 534 535 536 537 538
{
	u32 i;
	u8 val = 0;
	if (!len)
		return 0;
	for (i = 0; i < len; i++) {
		val += buf[i];
	}
	return ((~val) + 1);
}
539
EXPORT_SYMBOL(dst_check_sum);
L
Linus Torvalds 已提交
540 541 542

static void dst_type_flags_print(u32 type_flags)
{
543
	dprintk(verbose, DST_ERROR, 0, "DST type flags :");
L
Linus Torvalds 已提交
544
	if (type_flags & DST_TYPE_HAS_NEWTUNE)
545
		dprintk(verbose, DST_ERROR, 0, " 0x%x newtuner", DST_TYPE_HAS_NEWTUNE);
L
Linus Torvalds 已提交
546
	if (type_flags & DST_TYPE_HAS_TS204)
547
		dprintk(verbose, DST_ERROR, 0, " 0x%x ts204", DST_TYPE_HAS_TS204);
L
Linus Torvalds 已提交
548
	if (type_flags & DST_TYPE_HAS_SYMDIV)
549
		dprintk(verbose, DST_ERROR, 0, " 0x%x symdiv", DST_TYPE_HAS_SYMDIV);
550
	if (type_flags & DST_TYPE_HAS_FW_1)
551
		dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 1", DST_TYPE_HAS_FW_1);
552
	if (type_flags & DST_TYPE_HAS_FW_2)
553
		dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 2", DST_TYPE_HAS_FW_2);
554
	if (type_flags & DST_TYPE_HAS_FW_3)
555 556
		dprintk(verbose, DST_ERROR, 0, " 0x%x firmware version = 3", DST_TYPE_HAS_FW_3);
	dprintk(verbose, DST_ERROR, 0, "\n");
L
Linus Torvalds 已提交
557 558
}

559

560
static int dst_type_print(u8 type)
L
Linus Torvalds 已提交
561 562 563 564 565 566
{
	char *otype;
	switch (type) {
	case DST_TYPE_IS_SAT:
		otype = "satellite";
		break;
567

L
Linus Torvalds 已提交
568 569 570
	case DST_TYPE_IS_TERR:
		otype = "terrestrial";
		break;
571

L
Linus Torvalds 已提交
572 573 574
	case DST_TYPE_IS_CABLE:
		otype = "cable";
		break;
575

576 577 578 579
	case DST_TYPE_IS_ATSC:
		otype = "atsc";
		break;

L
Linus Torvalds 已提交
580
	default:
581
		dprintk(verbose, DST_INFO, 1, "invalid dst type %d", type);
L
Linus Torvalds 已提交
582 583
		return -EINVAL;
	}
584
	dprintk(verbose, DST_INFO, 1, "DST type: %s", otype);
585

L
Linus Torvalds 已提交
586 587 588
	return 0;
}

589 590 591 592
/*
	Known cards list
	Satellite
	-------------------
593
		  200103A
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
	VP-1020   DST-MOT	LG(old), TS=188

	VP-1020   DST-03T	LG(new), TS=204
	VP-1022   DST-03T	LG(new), TS=204
	VP-1025   DST-03T	LG(new), TS=204

	VP-1030   DSTMCI,	LG(new), TS=188
	VP-1032   DSTMCI,	LG(new), TS=188

	Cable
	-------------------
	VP-2030   DCT-CI,	Samsung, TS=204
	VP-2021   DCT-CI,	Unknown, TS=204
	VP-2031   DCT-CI,	Philips, TS=188
	VP-2040   DCT-CI,	Philips, TS=188, with CA daughter board
	VP-2040   DCT-CI,	Philips, TS=204, without CA daughter board

	Terrestrial
	-------------------
	VP-3050  DTTNXT			 TS=188
	VP-3040  DTT-CI,	Philips, TS=188
	VP-3040  DTT-CI,	Philips, TS=204

	ATSC
	-------------------
	VP-3220  ATSCDI,		 TS=188
	VP-3250  ATSCAD,		 TS=188

*/

624
static struct dst_types dst_tlist[] = {
625 626 627 628
	{
		.device_id = "200103A",
		.offset = 0,
		.dst_type =  DST_TYPE_IS_SAT,
629
		.type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1 | DST_TYPE_HAS_OBS_REGS,
630 631
		.dst_feature = 0,
		.tuner_type = 0
632 633
	},	/*	obsolete	*/

634 635 636 637 638
	{
		.device_id = "DST-020",
		.offset = 0,
		.dst_type =  DST_TYPE_IS_SAT,
		.type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
639 640
		.dst_feature = 0,
		.tuner_type = 0
641 642 643 644 645 646 647
	},	/*	obsolete	*/

	{
		.device_id = "DST-030",
		.offset =  0,
		.dst_type = DST_TYPE_IS_SAT,
		.type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
648 649
		.dst_feature = 0,
		.tuner_type = 0
650 651 652 653 654 655 656 657
	},	/*	obsolete	*/

	{
		.device_id = "DST-03T",
		.offset = 0,
		.dst_type = DST_TYPE_IS_SAT,
		.type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_2,
		.dst_feature = DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4 | DST_TYPE_HAS_DISEQC5
658 659
							 | DST_TYPE_HAS_MAC | DST_TYPE_HAS_MOTO,
		.tuner_type = TUNER_TYPE_STV0299
660 661 662 663 664 665 666
	 },

	{
		.device_id = "DST-MOT",
		.offset =  0,
		.dst_type = DST_TYPE_IS_SAT,
		.type_flags = DST_TYPE_HAS_SYMDIV | DST_TYPE_HAS_FW_1,
667 668
		.dst_feature = 0,
		.tuner_type = 0
669 670 671 672 673 674
	},	/*	obsolete	*/

	{
		.device_id = "DST-CI",
		.offset = 1,
		.dst_type = DST_TYPE_IS_SAT,
675
		.type_flags = DST_TYPE_HAS_TS204 | DST_TYPE_HAS_FW_1,
676 677
		.dst_feature = DST_TYPE_HAS_CA,
		.tuner_type = 0
678
	},	/*	An OEM board	*/
679 680 681 682 683

	{
		.device_id = "DSTMCI",
		.offset = 1,
		.dst_type = DST_TYPE_IS_SAT,
684
		.type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD | DST_TYPE_HAS_INC_COUNT,
685
		.dst_feature = DST_TYPE_HAS_CA | DST_TYPE_HAS_DISEQC3 | DST_TYPE_HAS_DISEQC4
686 687
							| DST_TYPE_HAS_MOTO | DST_TYPE_HAS_MAC,
		.tuner_type = TUNER_TYPE_MULTI
688 689 690 691 692 693 694
	},

	{
		.device_id = "DSTFCI",
		.offset = 1,
		.dst_type = DST_TYPE_IS_SAT,
		.type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_1,
695 696
		.dst_feature = 0,
		.tuner_type = 0
697 698 699 700 701 702
	},	/* unknown to vendor	*/

	{
		.device_id = "DCT-CI",
		.offset = 1,
		.dst_type = DST_TYPE_IS_CABLE,
703
		.type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_1	| DST_TYPE_HAS_FW_2,
704 705
		.dst_feature = DST_TYPE_HAS_CA,
		.tuner_type = 0
706 707 708 709 710 711
	},

	{
		.device_id = "DCTNEW",
		.offset = 1,
		.dst_type = DST_TYPE_IS_CABLE,
M
Manu Abraham 已提交
712
		.type_flags = DST_TYPE_HAS_NEWTUNE | DST_TYPE_HAS_FW_3 | DST_TYPE_HAS_FW_BUILD,
713 714
		.dst_feature = 0,
		.tuner_type = 0
715 716 717 718 719 720
	},

	{
		.device_id = "DTT-CI",
		.offset = 1,
		.dst_type = DST_TYPE_IS_TERR,
721
		.type_flags = DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_MULTI_FE,
722 723
		.dst_feature = DST_TYPE_HAS_CA,
		.tuner_type = 0
724 725 726 727 728 729 730
	},

	{
		.device_id = "DTTDIG",
		.offset = 1,
		.dst_type = DST_TYPE_IS_TERR,
		.type_flags = DST_TYPE_HAS_FW_2,
731 732
		.dst_feature = 0,
		.tuner_type = 0
733 734 735 736 737 738 739
	},

	{
		.device_id = "DTTNXT",
		.offset = 1,
		.dst_type = DST_TYPE_IS_TERR,
		.type_flags = DST_TYPE_HAS_FW_2,
740 741
		.dst_feature = DST_TYPE_HAS_ANALOG,
		.tuner_type = 0
742 743 744 745 746 747 748
	},

	{
		.device_id = "ATSCDI",
		.offset = 1,
		.dst_type = DST_TYPE_IS_ATSC,
		.type_flags = DST_TYPE_HAS_FW_2,
749 750
		.dst_feature = 0,
		.tuner_type = 0
751 752 753 754 755 756
	},

	{
		.device_id = "ATSCAD",
		.offset = 1,
		.dst_type = DST_TYPE_IS_ATSC,
757
		.type_flags = DST_TYPE_HAS_MULTI_FE | DST_TYPE_HAS_FW_2 | DST_TYPE_HAS_FW_BUILD,
758 759
		.dst_feature = DST_TYPE_HAS_MAC | DST_TYPE_HAS_ANALOG,
		.tuner_type = 0
760 761 762 763 764 765
	},

	{ }

};

M
Manu Abraham 已提交
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
static int dst_get_mac(struct dst_state *state)
{
	u8 get_mac[] = { 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
	get_mac[7] = dst_check_sum(get_mac, 7);
	if (dst_command(state, get_mac, 8) < 0) {
		dprintk(verbose, DST_INFO, 1, "Unsupported Command");
		return -1;
	}
	memset(&state->mac_address, '\0', 8);
	memcpy(&state->mac_address, &state->rxbuffer, 6);
	dprintk(verbose, DST_ERROR, 1, "MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]",
		state->mac_address[0], state->mac_address[1], state->mac_address[2],
		state->mac_address[4], state->mac_address[5], state->mac_address[6]);

	return 0;
}

static int dst_fw_ver(struct dst_state *state)
{
	u8 get_ver[] = { 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
	get_ver[7] = dst_check_sum(get_ver, 7);
	if (dst_command(state, get_ver, 8) < 0) {
		dprintk(verbose, DST_INFO, 1, "Unsupported Command");
		return -1;
	}
	memset(&state->fw_version, '\0', 8);
	memcpy(&state->fw_version, &state->rxbuffer, 8);
	dprintk(verbose, DST_ERROR, 1, "Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x",
		state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
		state->fw_version[1],
		state->fw_version[5], state->fw_version[6],
		state->fw_version[4], state->fw_version[3], state->fw_version[2]);

	return 0;
}

static int dst_card_type(struct dst_state *state)
{
	u8 get_type[] = { 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
	get_type[7] = dst_check_sum(get_type, 7);
	if (dst_command(state, get_type, 8) < 0) {
		dprintk(verbose, DST_INFO, 1, "Unsupported Command");
		return -1;
	}
	memset(&state->card_info, '\0', 8);
	memcpy(&state->card_info, &state->rxbuffer, 8);
	dprintk(verbose, DST_ERROR, 1, "Device Model=[%s]", &state->card_info[0]);

	return 0;
}

static int dst_get_vendor(struct dst_state *state)
{
	u8 get_vendor[] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
	get_vendor[7] = dst_check_sum(get_vendor, 7);
	if (dst_command(state, get_vendor, 8) < 0) {
		dprintk(verbose, DST_INFO, 1, "Unsupported Command");
		return -1;
	}
	memset(&state->vendor, '\0', 8);
	memcpy(&state->vendor, &state->rxbuffer, 8);
	dprintk(verbose, DST_ERROR, 1, "Vendor=[%s]", &state->vendor[0]);

	return 0;
}
831

832 833 834 835 836 837 838
static int dst_get_tuner_info(struct dst_state *state)
{
	u8 get_tuner_1[] = { 0x00, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
	u8 get_tuner_2[] = { 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

	get_tuner_1[7] = dst_check_sum(get_tuner_1, 7);
	get_tuner_2[7] = dst_check_sum(get_tuner_2, 7);
839
	dprintk(verbose, DST_ERROR, 1, "DST TYpe = MULTI FE");
840
	if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
841 842 843
//		if (dst_command(state, get_tuner_2, 8) < 0) {
		if (dst_command(state, get_tuner_1, 8) < 0) {
			dprintk(verbose, DST_INFO, 1, "Cmd=[0x13], Unsupported");
844 845 846
			return -1;
		}
	} else {
847 848 849
//		if (dst_command(state, get_tuner_1, 8) < 0) {
		if (dst_command(state, get_tuner_2, 8) < 0) {
			dprintk(verbose, DST_INFO, 1, "Cmd=[0xb], Unsupported");
850 851 852 853 854 855
			return -1;
		}
	}
	memset(&state->board_info, '\0', 8);
	memcpy(&state->board_info, &state->rxbuffer, 8);
	if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
856 857
		dprintk(verbose, DST_ERROR, 1, "DST type has TS=188");
/*
858 859 860 861 862 863 864 865 866 867 868 869
		if (state->board_info[1] == 0x0b) {
			if (state->type_flags & DST_TYPE_HAS_TS204)
				state->type_flags &= ~DST_TYPE_HAS_TS204;
			state->type_flags |= DST_TYPE_HAS_NEWTUNE;
			dprintk(verbose, DST_INFO, 1, "DST type has TS=188");
		} else {
			if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
				state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
			state->type_flags |= DST_TYPE_HAS_TS204;
			dprintk(verbose, DST_INFO, 1, "DST type has TS=204");
		}
	} else {
870 871 872 873 874 875 876 877 878 879 880 881 882
*/
	}
	if (state->board_info[0] == 0xbc) {
//		if (state->type_flags & DST_TYPE_HAS_TS204)
//			state->type_flags &= ~DST_TYPE_HAS_TS204;
		state->type_flags |= DST_TYPE_HAS_NEWTUNE;
		dprintk(verbose, DST_INFO, 1, "DST type has TS=188, Daughterboard=[%d]", state->board_info[1]);

	} else if (state->board_info[0] == 0xcc) {
//		if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
//			state->type_flags &= ~DST_TYPE_HAS_NEWTUNE;
		state->type_flags |= DST_TYPE_HAS_TS204;
		dprintk(verbose, DST_INFO, 1, "DST type has TS=204 Daughterboard=[%d]", state->board_info[1]);
883
	}
884
//	}
885 886 887 888

	return 0;
}

889
static int dst_get_device_id(struct dst_state *state)
L
Linus Torvalds 已提交
890
{
891 892
	u8 reply;

L
Linus Torvalds 已提交
893
	int i;
894 895 896
	struct dst_types *p_dst_type;
	u8 use_dst_type = 0;
	u32 use_type_flags = 0;
L
Linus Torvalds 已提交
897

898
	static u8 device_type[8] = {0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff};
L
Linus Torvalds 已提交
899

900 901 902 903 904 905 906 907 908
	device_type[7] = dst_check_sum(device_type, 7);

	if (write_dst(state, device_type, FIXED_COMM))
		return -1;		/*	Write failed		*/
	if ((dst_pio_disable(state)) < 0)
		return -1;
	if (read_dst(state, &reply, GET_ACK))
		return -1;		/*	Read failure		*/
	if (reply != ACK) {
909
		dprintk(verbose, DST_INFO, 1, "Write not Acknowledged! [Reply=0x%02x]", reply);
910
		return -1;		/*	Unack'd write		*/
L
Linus Torvalds 已提交
911
	}
912 913 914 915 916 917 918
	if (!dst_wait_dst_ready(state, DEVICE_INIT))
		return -1;		/*	DST not ready yet	*/
	if (read_dst(state, state->rxbuffer, FIXED_COMM))
		return -1;

	dst_pio_disable(state);
	if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
919
		dprintk(verbose, DST_INFO, 1, "Checksum failure!");
920
		return -1;		/*	Checksum failure	*/
L
Linus Torvalds 已提交
921
	}
922 923
	state->rxbuffer[7] = '\0';

924
	for (i = 0, p_dst_type = dst_tlist; i < ARRAY_SIZE(dst_tlist); i++, p_dst_type++) {
925 926 927 928 929 930
		if (!strncmp (&state->rxbuffer[p_dst_type->offset], p_dst_type->device_id, strlen (p_dst_type->device_id))) {
			use_type_flags = p_dst_type->type_flags;
			use_dst_type = p_dst_type->dst_type;

			/*	Card capabilities	*/
			state->dst_hw_cap = p_dst_type->dst_feature;
931
			dprintk(verbose, DST_ERROR, 1, "Recognise [%s]\n", p_dst_type->device_id);
932

L
Linus Torvalds 已提交
933 934 935
			break;
		}
	}
936 937

	if (i >= sizeof (dst_tlist) / sizeof (dst_tlist [0])) {
938 939
		dprintk(verbose, DST_ERROR, 1, "Unable to recognize %s or %s", &state->rxbuffer[0], &state->rxbuffer[1]);
		dprintk(verbose, DST_ERROR, 1, "please email linux-dvb@linuxtv.org with this type in");
L
Linus Torvalds 已提交
940 941 942
		use_dst_type = DST_TYPE_IS_SAT;
		use_type_flags = DST_TYPE_HAS_SYMDIV;
	}
943
	dst_type_print(use_dst_type);
L
Linus Torvalds 已提交
944 945 946 947 948 949 950
	state->type_flags = use_type_flags;
	state->dst_type = use_dst_type;
	dst_type_flags_print(state->type_flags);

	return 0;
}

951 952
static int dst_probe(struct dst_state *state)
{
953
	mutex_init(&state->dst_mutex);
954 955 956 957 958
	if (dst_addons & DST_TYPE_HAS_CA) {
		if ((rdc_8820_reset(state)) < 0) {
			dprintk(verbose, DST_ERROR, 1, "RDC 8820 RESET Failed.");
			return -1;
		}
959
		msleep(4000);
960
	} else {
961
		msleep(100);
962
	}
963
	if ((dst_comm_init(state)) < 0) {
964
		dprintk(verbose, DST_ERROR, 1, "DST Initialization Failed.");
965 966
		return -1;
	}
967
	msleep(100);
968
	if (dst_get_device_id(state) < 0) {
969
		dprintk(verbose, DST_ERROR, 1, "unknown device.");
970 971
		return -1;
	}
M
Manu Abraham 已提交
972 973 974 975
	if (dst_get_mac(state) < 0) {
		dprintk(verbose, DST_INFO, 1, "MAC: Unsupported command");
		return 0;
	}
976 977 978 979
	if ((state->type_flags & DST_TYPE_HAS_MULTI_FE) || (state->type_flags & DST_TYPE_HAS_FW_BUILD)) {
		if (dst_get_tuner_info(state) < 0)
			dprintk(verbose, DST_INFO, 1, "Tuner: Unsupported command");
	}
980 981 982
	if (state->type_flags & DST_TYPE_HAS_TS204) {
		dst_packsize(state, 204);
	}
M
Manu Abraham 已提交
983 984 985 986 987 988 989 990 991 992 993 994 995 996
	if (state->type_flags & DST_TYPE_HAS_FW_BUILD) {
		if (dst_fw_ver(state) < 0) {
			dprintk(verbose, DST_INFO, 1, "FW: Unsupported command");
			return 0;
		}
		if (dst_card_type(state) < 0) {
			dprintk(verbose, DST_INFO, 1, "Card: Unsupported command");
			return 0;
		}
		if (dst_get_vendor(state) < 0) {
			dprintk(verbose, DST_INFO, 1, "Vendor: Unsupported command");
			return 0;
		}
	}
997 998 999 1000

	return 0;
}

1001
int dst_command(struct dst_state *state, u8 *data, u8 len)
L
Linus Torvalds 已提交
1002 1003
{
	u8 reply;
1004

1005
	mutex_lock(&state->dst_mutex);
1006
	if ((dst_comm_init(state)) < 0) {
1007
		dprintk(verbose, DST_NOTICE, 1, "DST Communication Initialization Failed.");
1008
		goto error;
1009 1010
	}
	if (write_dst(state, data, len)) {
1011
		dprintk(verbose, DST_INFO, 1, "Tring to recover.. ");
1012
		if ((dst_error_recovery(state)) < 0) {
1013
			dprintk(verbose, DST_ERROR, 1, "Recovery Failed.");
1014
			goto error;
1015
		}
1016
		goto error;
L
Linus Torvalds 已提交
1017
	}
1018
	if ((dst_pio_disable(state)) < 0) {
1019
		dprintk(verbose, DST_ERROR, 1, "PIO Disable Failed.");
1020
		goto error;
L
Linus Torvalds 已提交
1021
	}
1022 1023
	if (state->type_flags & DST_TYPE_HAS_FW_1)
		udelay(3000);
1024
	if (read_dst(state, &reply, GET_ACK)) {
1025
		dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
1026
		if ((dst_error_recovery(state)) < 0) {
1027
			dprintk(verbose, DST_INFO, 1, "Recovery Failed.");
1028
			goto error;
1029
		}
1030
		goto error;
1031 1032
	}
	if (reply != ACK) {
1033
		dprintk(verbose, DST_INFO, 1, "write not acknowledged 0x%02x ", reply);
1034
		goto error;
L
Linus Torvalds 已提交
1035 1036
	}
	if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3))
1037
		goto error;
1038 1039 1040 1041
	if (state->type_flags & DST_TYPE_HAS_FW_1)
		udelay(3000);
	else
		udelay(2000);
1042
	if (!dst_wait_dst_ready(state, NO_DELAY))
1043
		goto error;
1044
	if (read_dst(state, state->rxbuffer, FIXED_COMM)) {
1045
		dprintk(verbose, DST_DEBUG, 1, "Trying to recover.. ");
1046
		if ((dst_error_recovery(state)) < 0) {
1047
			dprintk(verbose, DST_INFO, 1, "Recovery failed.");
1048
			goto error;
1049
		}
1050
		goto error;
L
Linus Torvalds 已提交
1051 1052
	}
	if (state->rxbuffer[7] != dst_check_sum(state->rxbuffer, 7)) {
1053
		dprintk(verbose, DST_INFO, 1, "checksum failure");
1054
		goto error;
L
Linus Torvalds 已提交
1055
	}
1056
	mutex_unlock(&state->dst_mutex);
L
Linus Torvalds 已提交
1057
	return 0;
1058 1059

error:
1060
	mutex_unlock(&state->dst_mutex);
1061 1062
	return -EIO;

L
Linus Torvalds 已提交
1063
}
1064
EXPORT_SYMBOL(dst_command);
L
Linus Torvalds 已提交
1065

1066
static int dst_get_signal(struct dst_state *state)
L
Linus Torvalds 已提交
1067 1068 1069
{
	int retval;
	u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
1070
	//dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__);
L
Linus Torvalds 已提交
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
	if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
		state->decode_lock = state->decode_strength = state->decode_snr = 0;
		return 0;
	}
	if (0 == (state->diseq_flags & HAS_LOCK)) {
		state->decode_lock = state->decode_strength = state->decode_snr = 0;
		return 0;
	}
	if (time_after_eq(jiffies, state->cur_jiff + (HZ / 5))) {
		retval = dst_command(state, get_signal, 8);
		if (retval < 0)
			return retval;
		if (state->dst_type == DST_TYPE_IS_SAT) {
			state->decode_lock = ((state->rxbuffer[6] & 0x10) == 0) ? 1 : 0;
			state->decode_strength = state->rxbuffer[5] << 8;
			state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
		} else if ((state->dst_type == DST_TYPE_IS_TERR) || (state->dst_type == DST_TYPE_IS_CABLE)) {
			state->decode_lock = (state->rxbuffer[1]) ? 1 : 0;
			state->decode_strength = state->rxbuffer[4] << 8;
			state->decode_snr = state->rxbuffer[3] << 8;
1091 1092 1093 1094
		} else if (state->dst_type == DST_TYPE_IS_ATSC) {
			state->decode_lock = (state->rxbuffer[6] == 0x00) ? 1 : 0;
			state->decode_strength = state->rxbuffer[4] << 8;
			state->decode_snr = state->rxbuffer[2] << 8 | state->rxbuffer[3];
L
Linus Torvalds 已提交
1095 1096 1097 1098 1099 1100
		}
		state->cur_jiff = jiffies;
	}
	return 0;
}

1101
static int dst_tone_power_cmd(struct dst_state *state)
L
Linus Torvalds 已提交
1102 1103 1104 1105 1106
{
	u8 paket[8] = { 0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00 };

	if (state->dst_type == DST_TYPE_IS_TERR)
		return 0;
1107
	paket[4] = state->tx_tuna[4];
M
Manu Abraham 已提交
1108
	paket[2] = state->tx_tuna[2];
M
Manu Abraham 已提交
1109
	paket[3] = state->tx_tuna[3];
1110
	paket[7] = dst_check_sum (paket, 7);
L
Linus Torvalds 已提交
1111
	dst_command(state, paket, 8);
M
Manu Abraham 已提交
1112

L
Linus Torvalds 已提交
1113 1114 1115
	return 0;
}

1116
static int dst_get_tuna(struct dst_state *state)
L
Linus Torvalds 已提交
1117 1118
{
	int retval;
1119

L
Linus Torvalds 已提交
1120 1121 1122
	if ((state->diseq_flags & ATTEMPT_TUNE) == 0)
		return 0;
	state->diseq_flags &= ~(HAS_LOCK);
1123
	if (!dst_wait_dst_ready(state, NO_DELAY))
1124
		return -EIO;
1125
	if (state->type_flags & DST_TYPE_HAS_NEWTUNE)
L
Linus Torvalds 已提交
1126 1127
		/* how to get variable length reply ???? */
		retval = read_dst(state, state->rx_tuna, 10);
1128
	else
1129
		retval = read_dst(state, &state->rx_tuna[2], FIXED_COMM);
L
Linus Torvalds 已提交
1130
	if (retval < 0) {
1131
		dprintk(verbose, DST_DEBUG, 1, "read not successful");
1132
		return retval;
L
Linus Torvalds 已提交
1133 1134 1135
	}
	if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
		if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
1136
			dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
1137
			return -EIO;
L
Linus Torvalds 已提交
1138 1139 1140
		}
	} else {
		if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[2], 7)) {
1141
			dprintk(verbose, DST_INFO, 1, "checksum failure? ");
1142
			return -EIO;
L
Linus Torvalds 已提交
1143 1144 1145 1146
		}
	}
	if (state->rx_tuna[2] == 0 && state->rx_tuna[3] == 0)
		return 0;
1147 1148 1149 1150 1151 1152
	if (state->dst_type == DST_TYPE_IS_SAT) {
		state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 8) + state->rx_tuna[3];
	} else {
		state->decode_freq = ((state->rx_tuna[2] & 0x7f) << 16) + (state->rx_tuna[3] << 8) + state->rx_tuna[4];
	}
	state->decode_freq = state->decode_freq * 1000;
L
Linus Torvalds 已提交
1153 1154
	state->decode_lock = 1;
	state->diseq_flags |= HAS_LOCK;
1155

L
Linus Torvalds 已提交
1156 1157 1158
	return 1;
}

1159
static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
L
Linus Torvalds 已提交
1160

1161
static int dst_write_tuna(struct dvb_frontend *fe)
L
Linus Torvalds 已提交
1162
{
1163
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1164 1165 1166
	int retval;
	u8 reply;

1167
	dprintk(verbose, DST_INFO, 1, "type_flags 0x%x ", state->type_flags);
L
Linus Torvalds 已提交
1168 1169 1170 1171 1172 1173 1174
	state->decode_freq = 0;
	state->decode_lock = state->decode_strength = state->decode_snr = 0;
	if (state->dst_type == DST_TYPE_IS_SAT) {
		if (!(state->diseq_flags & HAS_POWER))
			dst_set_voltage(fe, SEC_VOLTAGE_13);
	}
	state->diseq_flags &= ~(HAS_LOCK | ATTEMPT_TUNE);
1175
	mutex_lock(&state->dst_mutex);
1176
	if ((dst_comm_init(state)) < 0) {
1177
		dprintk(verbose, DST_DEBUG, 1, "DST Communication initialization failed.");
1178
		goto error;
1179
	}
L
Linus Torvalds 已提交
1180 1181 1182 1183 1184
	if (state->type_flags & DST_TYPE_HAS_NEWTUNE) {
		state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[0], 9);
		retval = write_dst(state, &state->tx_tuna[0], 10);
	} else {
		state->tx_tuna[9] = dst_check_sum(&state->tx_tuna[2], 7);
1185
		retval = write_dst(state, &state->tx_tuna[2], FIXED_COMM);
L
Linus Torvalds 已提交
1186 1187
	}
	if (retval < 0) {
1188
		dst_pio_disable(state);
1189
		dprintk(verbose, DST_DEBUG, 1, "write not successful");
1190
		goto werr;
L
Linus Torvalds 已提交
1191
	}
1192
	if ((dst_pio_disable(state)) < 0) {
1193
		dprintk(verbose, DST_DEBUG, 1, "DST PIO disable failed !");
1194
		goto error;
1195 1196
	}
	if ((read_dst(state, &reply, GET_ACK) < 0)) {
1197
		dprintk(verbose, DST_DEBUG, 1, "read verify not successful.");
1198
		goto error;
L
Linus Torvalds 已提交
1199
	}
1200
	if (reply != ACK) {
1201
		dprintk(verbose, DST_DEBUG, 1, "write not acknowledged 0x%02x ", reply);
1202
		goto error;
L
Linus Torvalds 已提交
1203 1204
	}
	state->diseq_flags |= ATTEMPT_TUNE;
1205 1206
	retval = dst_get_tuna(state);
werr:
1207
	mutex_unlock(&state->dst_mutex);
1208
	return retval;
1209

1210
error:
1211
	mutex_unlock(&state->dst_mutex);
1212
	return -EIO;
L
Linus Torvalds 已提交
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228
}

/*
 * line22k0    0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00
 * line22k1    0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00
 * line22k2    0x00, 0x09, 0x02, 0xff, 0x01, 0x00, 0x00, 0x00
 * tone        0x00, 0x09, 0xff, 0x00, 0x01, 0x00, 0x00, 0x00
 * data        0x00, 0x09, 0xff, 0x01, 0x01, 0x00, 0x00, 0x00
 * power_off   0x00, 0x09, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
 * power_on    0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00
 * Diseqc 1    0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec
 * Diseqc 2    0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf4, 0xe8
 * Diseqc 3    0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf8, 0xe4
 * Diseqc 4    0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0
 */

1229
static int dst_set_diseqc(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
L
Linus Torvalds 已提交
1230
{
1231
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1232 1233
	u8 paket[8] = { 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec };

M
Manu Abraham 已提交
1234
	if (state->dst_type != DST_TYPE_IS_SAT)
L
Linus Torvalds 已提交
1235 1236 1237 1238 1239 1240 1241 1242 1243
		return 0;
	if (cmd->msg_len == 0 || cmd->msg_len > 4)
		return -EINVAL;
	memcpy(&paket[3], cmd->msg, cmd->msg_len);
	paket[7] = dst_check_sum(&paket[0], 7);
	dst_command(state, paket, 8);
	return 0;
}

1244
static int dst_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
L
Linus Torvalds 已提交
1245 1246
{
	int need_cmd;
1247
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1248 1249

	state->voltage = voltage;
M
Manu Abraham 已提交
1250
	if (state->dst_type != DST_TYPE_IS_SAT)
L
Linus Torvalds 已提交
1251 1252 1253
		return 0;

	need_cmd = 0;
1254

1255 1256 1257 1258
	switch (voltage) {
	case SEC_VOLTAGE_13:
	case SEC_VOLTAGE_18:
		if ((state->diseq_flags & HAS_POWER) == 0)
L
Linus Torvalds 已提交
1259
			need_cmd = 1;
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269
		state->diseq_flags |= HAS_POWER;
		state->tx_tuna[4] = 0x01;
		break;
	case SEC_VOLTAGE_OFF:
		need_cmd = 1;
		state->diseq_flags &= ~(HAS_POWER | HAS_LOCK | ATTEMPT_TUNE);
		state->tx_tuna[4] = 0x00;
		break;
	default:
		return -EINVAL;
L
Linus Torvalds 已提交
1270
	}
1271

1272
	if (need_cmd)
L
Linus Torvalds 已提交
1273
		dst_tone_power_cmd(state);
1274

L
Linus Torvalds 已提交
1275 1276 1277
	return 0;
}

1278
static int dst_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
L
Linus Torvalds 已提交
1279
{
1280
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1281 1282

	state->tone = tone;
M
Manu Abraham 已提交
1283
	if (state->dst_type != DST_TYPE_IS_SAT)
L
Linus Torvalds 已提交
1284 1285 1286
		return 0;

	switch (tone) {
1287 1288 1289 1290 1291 1292
	case SEC_TONE_OFF:
		if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
		    state->tx_tuna[2] = 0x00;
		else
		    state->tx_tuna[2] = 0xff;
		break;
1293

1294 1295 1296 1297 1298
	case SEC_TONE_ON:
		state->tx_tuna[2] = 0x02;
		break;
	default:
		return -EINVAL;
L
Linus Torvalds 已提交
1299 1300
	}
	dst_tone_power_cmd(state);
1301

L
Linus Torvalds 已提交
1302 1303 1304
	return 0;
}

M
Manu Abraham 已提交
1305 1306 1307 1308
static int dst_send_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t minicmd)
{
	struct dst_state *state = fe->demodulator_priv;

M
Manu Abraham 已提交
1309
	if (state->dst_type != DST_TYPE_IS_SAT)
M
Manu Abraham 已提交
1310 1311 1312
		return 0;
	state->minicmd = minicmd;
	switch (minicmd) {
1313 1314 1315 1316 1317 1318
	case SEC_MINI_A:
		state->tx_tuna[3] = 0x02;
		break;
	case SEC_MINI_B:
		state->tx_tuna[3] = 0xff;
		break;
M
Manu Abraham 已提交
1319 1320 1321 1322 1323 1324 1325
	}
	dst_tone_power_cmd(state);

	return 0;
}


1326
static int dst_init(struct dvb_frontend *fe)
L
Linus Torvalds 已提交
1327
{
1328 1329 1330 1331 1332 1333 1334 1335
	struct dst_state *state = fe->demodulator_priv;

	static u8 sat_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x00, 0x73, 0x21, 0x00, 0x00 };
	static u8 sat_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x55, 0xbd, 0x50, 0x00, 0x00 };
	static u8 ter_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
	static u8 ter_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
	static u8 cab_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
	static u8 cab_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1336 1337
	static u8 atsc_tuna_188[] = { 0x09, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
	static u8 atsc_tuna_204[] = { 0x00, 0x00, 0x03, 0xb6, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00 };
1338

1339
	state->inversion = INVERSION_OFF;
L
Linus Torvalds 已提交
1340 1341 1342 1343 1344 1345
	state->voltage = SEC_VOLTAGE_13;
	state->tone = SEC_TONE_OFF;
	state->diseq_flags = 0;
	state->k22 = 0x02;
	state->bandwidth = BANDWIDTH_7_MHZ;
	state->cur_jiff = jiffies;
1346 1347 1348 1349 1350 1351
	if (state->dst_type == DST_TYPE_IS_SAT)
		memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? sat_tuna_188 : sat_tuna_204), sizeof (sat_tuna_204));
	else if (state->dst_type == DST_TYPE_IS_TERR)
		memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? ter_tuna_188 : ter_tuna_204), sizeof (ter_tuna_204));
	else if (state->dst_type == DST_TYPE_IS_CABLE)
		memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? cab_tuna_188 : cab_tuna_204), sizeof (cab_tuna_204));
1352 1353
	else if (state->dst_type == DST_TYPE_IS_ATSC)
		memcpy(state->tx_tuna, ((state->type_flags & DST_TYPE_HAS_NEWTUNE) ? atsc_tuna_188 : atsc_tuna_204), sizeof (atsc_tuna_204));
L
Linus Torvalds 已提交
1354 1355 1356 1357

	return 0;
}

1358
static int dst_read_status(struct dvb_frontend *fe, fe_status_t *status)
L
Linus Torvalds 已提交
1359
{
1360
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1361 1362 1363

	*status = 0;
	if (state->diseq_flags & HAS_LOCK) {
1364
//		dst_get_signal(state);	// don't require(?) to ask MCU
L
Linus Torvalds 已提交
1365 1366 1367 1368 1369 1370 1371
		if (state->decode_lock)
			*status |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC | FE_HAS_VITERBI;
	}

	return 0;
}

1372
static int dst_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
L
Linus Torvalds 已提交
1373
{
1374
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1375 1376 1377 1378 1379 1380 1381

	dst_get_signal(state);
	*strength = state->decode_strength;

	return 0;
}

1382
static int dst_read_snr(struct dvb_frontend *fe, u16 *snr)
L
Linus Torvalds 已提交
1383
{
1384
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1385 1386 1387 1388 1389 1390 1391

	dst_get_signal(state);
	*snr = state->decode_snr;

	return 0;
}

1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
static int dst_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
{
	struct dst_state *state = fe->demodulator_priv;

	if (p != NULL) {
		dst_set_freq(state, p->frequency);
		dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);

		if (state->dst_type == DST_TYPE_IS_SAT) {
			if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
				dst_set_inversion(state, p->inversion);
			dst_set_fec(state, p->u.qpsk.fec_inner);
			dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
			dst_set_polarization(state);
			dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);

		} else if (state->dst_type == DST_TYPE_IS_TERR)
			dst_set_bandwidth(state, p->u.ofdm.bandwidth);
		else if (state->dst_type == DST_TYPE_IS_CABLE) {
			dst_set_fec(state, p->u.qam.fec_inner);
			dst_set_symbolrate(state, p->u.qam.symbol_rate);
			dst_set_modulation(state, p->u.qam.modulation);
		}
		dst_write_tuna(fe);
	}

	return 0;
}

static int dst_tune_frontend(struct dvb_frontend* fe,
1422 1423 1424 1425
			    struct dvb_frontend_parameters* p,
			    unsigned int mode_flags,
			    int *delay,
			    fe_status_t *status)
L
Linus Torvalds 已提交
1426
{
1427
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1428

1429 1430 1431
	if (p != NULL) {
		dst_set_freq(state, p->frequency);
		dprintk(verbose, DST_DEBUG, 1, "Set Frequency=[%d]", p->frequency);
1432

1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
		if (state->dst_type == DST_TYPE_IS_SAT) {
			if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
				dst_set_inversion(state, p->inversion);
			dst_set_fec(state, p->u.qpsk.fec_inner);
			dst_set_symbolrate(state, p->u.qpsk.symbol_rate);
			dst_set_polarization(state);
			dprintk(verbose, DST_DEBUG, 1, "Set Symbolrate=[%d]", p->u.qpsk.symbol_rate);

		} else if (state->dst_type == DST_TYPE_IS_TERR)
			dst_set_bandwidth(state, p->u.ofdm.bandwidth);
		else if (state->dst_type == DST_TYPE_IS_CABLE) {
			dst_set_fec(state, p->u.qam.fec_inner);
			dst_set_symbolrate(state, p->u.qam.symbol_rate);
			dst_set_modulation(state, p->u.qam.modulation);
		}
		dst_write_tuna(fe);
L
Linus Torvalds 已提交
1449 1450
	}

1451 1452 1453 1454
	if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
		dst_read_status(fe, status);

	*delay = HZ/10;
L
Linus Torvalds 已提交
1455 1456 1457
	return 0;
}

1458 1459 1460 1461 1462
static int dst_get_tuning_algo(struct dvb_frontend *fe)
{
	return dst_algo;
}

1463
static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
L
Linus Torvalds 已提交
1464
{
1465
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1466 1467 1468

	p->frequency = state->decode_freq;
	if (state->dst_type == DST_TYPE_IS_SAT) {
1469 1470
		if (state->type_flags & DST_TYPE_HAS_OBS_REGS)
			p->inversion = state->inversion;
L
Linus Torvalds 已提交
1471 1472 1473 1474 1475 1476 1477
		p->u.qpsk.symbol_rate = state->symbol_rate;
		p->u.qpsk.fec_inner = dst_get_fec(state);
	} else if (state->dst_type == DST_TYPE_IS_TERR) {
		p->u.ofdm.bandwidth = state->bandwidth;
	} else if (state->dst_type == DST_TYPE_IS_CABLE) {
		p->u.qam.symbol_rate = state->symbol_rate;
		p->u.qam.fec_inner = dst_get_fec(state);
1478
		p->u.qam.modulation = dst_get_modulation(state);
L
Linus Torvalds 已提交
1479 1480 1481 1482 1483
	}

	return 0;
}

1484
static void dst_release(struct dvb_frontend *fe)
L
Linus Torvalds 已提交
1485
{
1486
	struct dst_state *state = fe->demodulator_priv;
L
Linus Torvalds 已提交
1487 1488 1489 1490 1491 1492
	kfree(state);
}

static struct dvb_frontend_ops dst_dvbt_ops;
static struct dvb_frontend_ops dst_dvbs_ops;
static struct dvb_frontend_ops dst_dvbc_ops;
1493
static struct dvb_frontend_ops dst_atsc_ops;
L
Linus Torvalds 已提交
1494

1495
struct dst_state *dst_attach(struct dst_state *state, struct dvb_adapter *dvb_adapter)
L
Linus Torvalds 已提交
1496
{
1497 1498
	/* check if the ASIC is there */
	if (dst_probe(state) < 0) {
J
Jesper Juhl 已提交
1499
		kfree(state);
1500 1501
		return NULL;
	}
L
Linus Torvalds 已提交
1502
	/* determine settings based on type */
1503
	/* create dvb_frontend */
L
Linus Torvalds 已提交
1504 1505
	switch (state->dst_type) {
	case DST_TYPE_IS_TERR:
1506
		memcpy(&state->frontend.ops, &dst_dvbt_ops, sizeof(struct dvb_frontend_ops));
L
Linus Torvalds 已提交
1507 1508
		break;
	case DST_TYPE_IS_CABLE:
1509
		memcpy(&state->frontend.ops, &dst_dvbc_ops, sizeof(struct dvb_frontend_ops));
L
Linus Torvalds 已提交
1510 1511
		break;
	case DST_TYPE_IS_SAT:
1512
		memcpy(&state->frontend.ops, &dst_dvbs_ops, sizeof(struct dvb_frontend_ops));
L
Linus Torvalds 已提交
1513
		break;
1514 1515 1516
	case DST_TYPE_IS_ATSC:
		memcpy(&state->frontend.ops, &dst_atsc_ops, sizeof(struct dvb_frontend_ops));
		break;
L
Linus Torvalds 已提交
1517
	default:
1518
		dprintk(verbose, DST_ERROR, 1, "unknown DST type. please report to the LinuxTV.org DVB mailinglist.");
J
Jesper Juhl 已提交
1519
		kfree(state);
1520
		return NULL;
L
Linus Torvalds 已提交
1521 1522 1523
	}
	state->frontend.demodulator_priv = state;

1524
	return state;				/*	Manu (DST is a card not a frontend)	*/
L
Linus Torvalds 已提交
1525 1526
}

1527 1528
EXPORT_SYMBOL(dst_attach);

L
Linus Torvalds 已提交
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541
static struct dvb_frontend_ops dst_dvbt_ops = {

	.info = {
		.name = "DST DVB-T",
		.type = FE_OFDM,
		.frequency_min = 137000000,
		.frequency_max = 858000000,
		.frequency_stepsize = 166667,
		.caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
	},

	.release = dst_release,
	.init = dst_init,
1542 1543
	.tune = dst_tune_frontend,
	.set_frontend = dst_set_frontend,
L
Linus Torvalds 已提交
1544
	.get_frontend = dst_get_frontend,
1545
	.get_frontend_algo = dst_get_tuning_algo,
L
Linus Torvalds 已提交
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
	.read_status = dst_read_status,
	.read_signal_strength = dst_read_signal_strength,
	.read_snr = dst_read_snr,
};

static struct dvb_frontend_ops dst_dvbs_ops = {

	.info = {
		.name = "DST DVB-S",
		.type = FE_QPSK,
		.frequency_min = 950000,
		.frequency_max = 2150000,
		.frequency_stepsize = 1000,	/* kHz for QPSK frontends */
		.frequency_tolerance = 29500,
		.symbol_rate_min = 1000000,
		.symbol_rate_max = 45000000,
	/*     . symbol_rate_tolerance	=	???,*/
		.caps = FE_CAN_FEC_AUTO | FE_CAN_QPSK
	},

	.release = dst_release,
	.init = dst_init,
1568 1569
	.tune = dst_tune_frontend,
	.set_frontend = dst_set_frontend,
L
Linus Torvalds 已提交
1570
	.get_frontend = dst_get_frontend,
1571
	.get_frontend_algo = dst_get_tuning_algo,
L
Linus Torvalds 已提交
1572 1573 1574
	.read_status = dst_read_status,
	.read_signal_strength = dst_read_signal_strength,
	.read_snr = dst_read_snr,
M
Manu Abraham 已提交
1575
	.diseqc_send_burst = dst_send_burst,
L
Linus Torvalds 已提交
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
	.diseqc_send_master_cmd = dst_set_diseqc,
	.set_voltage = dst_set_voltage,
	.set_tone = dst_set_tone,
};

static struct dvb_frontend_ops dst_dvbc_ops = {

	.info = {
		.name = "DST DVB-C",
		.type = FE_QAM,
		.frequency_stepsize = 62500,
		.frequency_min = 51000000,
		.frequency_max = 858000000,
		.symbol_rate_min = 1000000,
		.symbol_rate_max = 45000000,
	/*     . symbol_rate_tolerance	=	???,*/
		.caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO
	},

	.release = dst_release,
	.init = dst_init,
1597 1598
	.tune = dst_tune_frontend,
	.set_frontend = dst_set_frontend,
L
Linus Torvalds 已提交
1599
	.get_frontend = dst_get_frontend,
1600
	.get_frontend_algo = dst_get_tuning_algo,
L
Linus Torvalds 已提交
1601 1602 1603 1604 1605
	.read_status = dst_read_status,
	.read_signal_strength = dst_read_signal_strength,
	.read_snr = dst_read_snr,
};

1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
static struct dvb_frontend_ops dst_atsc_ops = {
	.info = {
		.name = "DST ATSC",
		.type = FE_ATSC,
		.frequency_stepsize = 62500,
		.frequency_min = 510000000,
		.frequency_max = 858000000,
		.symbol_rate_min = 1000000,
		.symbol_rate_max = 45000000,
		.caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO | FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
	},

	.release = dst_release,
	.init = dst_init,
1620 1621
	.tune = dst_tune_frontend,
	.set_frontend = dst_set_frontend,
1622
	.get_frontend = dst_get_frontend,
1623
	.get_frontend_algo = dst_get_tuning_algo,
1624 1625 1626 1627 1628 1629
	.read_status = dst_read_status,
	.read_signal_strength = dst_read_signal_strength,
	.read_snr = dst_read_snr,
};

MODULE_DESCRIPTION("DST DVB-S/T/C/ATSC Combo Frontend driver");
1630
MODULE_AUTHOR("Jamie Honan, Manu Abraham");
L
Linus Torvalds 已提交
1631
MODULE_LICENSE("GPL");