si2168.c 15.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Silicon Labs Si2168 DVB-T/T2/C demodulator driver
 *
 * Copyright (C) 2014 Antti Palosaari <crope@iki.fi>
 *
 *    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.
 *
 *    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.
 */

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#include "si2168_priv.h"

static const struct dvb_frontend_ops si2168_ops;

/* execute firmware command */
static int si2168_cmd_execute(struct si2168 *s, struct si2168_cmd *cmd)
{
	int ret;
	unsigned long timeout;

	mutex_lock(&s->i2c_mutex);

	if (cmd->wlen) {
		/* write cmd and args for firmware */
		ret = i2c_master_send(s->client, cmd->args, cmd->wlen);
		if (ret < 0) {
			goto err_mutex_unlock;
		} else if (ret != cmd->wlen) {
			ret = -EREMOTEIO;
			goto err_mutex_unlock;
		}
	}

	if (cmd->rlen) {
		/* wait cmd execution terminate */
		#define TIMEOUT 50
		timeout = jiffies + msecs_to_jiffies(TIMEOUT);
		while (!time_after(jiffies, timeout)) {
			ret = i2c_master_recv(s->client, cmd->args, cmd->rlen);
			if (ret < 0) {
				goto err_mutex_unlock;
			} else if (ret != cmd->rlen) {
				ret = -EREMOTEIO;
				goto err_mutex_unlock;
			}

			/* firmware ready? */
			if ((cmd->args[0] >> 7) & 0x01)
				break;
		}

O
Olli Salonen 已提交
58
		dev_dbg(&s->client->dev, "cmd execution took %d ms\n",
59 60 61
				jiffies_to_msecs(jiffies) -
				(jiffies_to_msecs(timeout) - TIMEOUT));

62
		if (!((cmd->args[0] >> 7) & 0x01)) {
63 64 65 66 67 68 69 70 71 72 73 74 75 76
			ret = -ETIMEDOUT;
			goto err_mutex_unlock;
		}
	}

	ret = 0;

err_mutex_unlock:
	mutex_unlock(&s->i2c_mutex);
	if (ret)
		goto err;

	return 0;
err:
O
Olli Salonen 已提交
77
	dev_dbg(&s->client->dev, "failed=%d\n", ret);
78 79 80 81 82 83
	return ret;
}

static int si2168_read_status(struct dvb_frontend *fe, fe_status_t *status)
{
	struct si2168 *s = fe->demodulator_priv;
84
	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
85 86 87 88 89 90 91 92 93 94
	int ret;
	struct si2168_cmd cmd;

	*status = 0;

	if (!s->active) {
		ret = -EAGAIN;
		goto err;
	}

95 96
	switch (c->delivery_system) {
	case SYS_DVBT:
97
		memcpy(cmd.args, "\xa0\x01", 2);
98 99 100
		cmd.wlen = 2;
		cmd.rlen = 13;
		break;
101
	case SYS_DVBC_ANNEX_A:
102
		memcpy(cmd.args, "\x90\x01", 2);
103 104 105
		cmd.wlen = 2;
		cmd.rlen = 9;
		break;
106
	case SYS_DVBT2:
107
		memcpy(cmd.args, "\x50\x01", 2);
108 109 110 111 112 113 114 115
		cmd.wlen = 2;
		cmd.rlen = 14;
		break;
	default:
		ret = -EINVAL;
		goto err;
	}

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	/*
	 * Possible values seen, in order from strong signal to weak:
	 * 16 0001 0110 full lock
	 * 1e 0001 1110 partial lock
	 * 1a 0001 1010 partial lock
	 * 18 0001 1000 no lock
	 *
	 * [b3:b1] lock bits
	 * [b4] statistics ready? Set in a few secs after lock is gained.
	 */

131 132
	switch ((cmd.args[2] >> 1) & 0x03) {
	case 0x01:
133 134
		*status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
		break;
135
	case 0x03:
136 137 138 139 140 141 142
		*status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI |
				FE_HAS_SYNC | FE_HAS_LOCK;
		break;
	}

	s->fe_status = *status;

143 144 145 146 147 148 149 150 151
	if (*status & FE_HAS_LOCK) {
		c->cnr.len = 1;
		c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
		c->cnr.stat[0].svalue = cmd.args[3] * 1000 / 4;
	} else {
		c->cnr.len = 1;
		c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
	}

O
Olli Salonen 已提交
152 153
	dev_dbg(&s->client->dev, "status=%02x args=%*ph\n",
			*status, cmd.rlen, cmd.args);
154 155 156

	return 0;
err:
O
Olli Salonen 已提交
157
	dev_dbg(&s->client->dev, "failed=%d\n", ret);
158 159 160 161 162 163 164 165 166
	return ret;
}

static int si2168_set_frontend(struct dvb_frontend *fe)
{
	struct si2168 *s = fe->demodulator_priv;
	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
	int ret;
	struct si2168_cmd cmd;
167
	u8 bandwidth, delivery_system;
168 169

	dev_dbg(&s->client->dev,
170
			"delivery_system=%u modulation=%u frequency=%u bandwidth_hz=%u symbol_rate=%u inversion=%u, stream_id=%d\n",
O
Olli Salonen 已提交
171
			c->delivery_system, c->modulation,
172
			c->frequency, c->bandwidth_hz, c->symbol_rate,
173
			c->inversion, c->stream_id);
174 175 176 177 178 179

	if (!s->active) {
		ret = -EAGAIN;
		goto err;
	}

180 181 182 183
	switch (c->delivery_system) {
	case SYS_DVBT:
		delivery_system = 0x20;
		break;
184 185 186
	case SYS_DVBC_ANNEX_A:
		delivery_system = 0x30;
		break;
187 188 189 190 191 192 193 194
	case SYS_DVBT2:
		delivery_system = 0x70;
		break;
	default:
		ret = -EINVAL;
		goto err;
	}

195
	if (c->bandwidth_hz <= 5000000)
196
		bandwidth = 0x05;
197
	else if (c->bandwidth_hz <= 6000000)
198
		bandwidth = 0x06;
199
	else if (c->bandwidth_hz <= 7000000)
200
		bandwidth = 0x07;
201
	else if (c->bandwidth_hz <= 8000000)
202
		bandwidth = 0x08;
203 204 205 206 207 208
	else if (c->bandwidth_hz <= 9000000)
		bandwidth = 0x09;
	else if (c->bandwidth_hz <= 10000000)
		bandwidth = 0x0a;
	else
		bandwidth = 0x0f;
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223

	/* program tuner */
	if (fe->ops.tuner_ops.set_params) {
		ret = fe->ops.tuner_ops.set_params(fe);
		if (ret)
			goto err;
	}

	memcpy(cmd.args, "\x88\x02\x02\x02\x02", 5);
	cmd.wlen = 5;
	cmd.rlen = 5;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

224 225 226
	/* that has no big effect */
	if (c->delivery_system == SYS_DVBT)
		memcpy(cmd.args, "\x89\x21\x06\x11\xff\x98", 6);
227 228
	else if (c->delivery_system == SYS_DVBC_ANNEX_A)
		memcpy(cmd.args, "\x89\x21\x06\x11\x89\xf0", 6);
229 230
	else if (c->delivery_system == SYS_DVBT2)
		memcpy(cmd.args, "\x89\x21\x06\x11\x89\x20", 6);
231 232 233 234 235 236
	cmd.wlen = 6;
	cmd.rlen = 3;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

237 238 239 240 241 242 243 244 245 246 247 248
	if (c->delivery_system == SYS_DVBT2) {
		/* select PLP */
		cmd.args[0] = 0x52;
		cmd.args[1] = c->stream_id & 0xff;
		cmd.args[2] = c->stream_id == NO_STREAM_ID_FILTER ? 0 : 1;
		cmd.wlen = 3;
		cmd.rlen = 1;
		ret = si2168_cmd_execute(s, &cmd);
		if (ret)
			goto err;
	}

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
	memcpy(cmd.args, "\x51\x03", 2);
	cmd.wlen = 2;
	cmd.rlen = 12;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x12\x08\x04", 3);
	cmd.wlen = 3;
	cmd.rlen = 3;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x14\x00\x0c\x10\x12\x00", 6);
	cmd.wlen = 6;
265
	cmd.rlen = 4;
266 267 268 269 270 271
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x14\x00\x06\x10\x24\x00", 6);
	cmd.wlen = 6;
272
	cmd.rlen = 4;
273 274 275 276 277 278
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x14\x00\x07\x10\x00\x24", 6);
	cmd.wlen = 6;
279
	cmd.rlen = 4;
280 281 282 283 284
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x14\x00\x0a\x10\x00\x00", 6);
285
	cmd.args[4] = delivery_system | bandwidth;
286
	cmd.wlen = 6;
287
	cmd.rlen = 4;
288 289 290 291
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

292 293 294 295 296 297 298 299 300 301 302 303
	/* set DVB-C symbol rate */
	if (c->delivery_system == SYS_DVBC_ANNEX_A) {
		memcpy(cmd.args, "\x14\x00\x02\x11", 4);
		cmd.args[4] = (c->symbol_rate / 1000) & 0xff;
		cmd.args[5] = ((c->symbol_rate / 1000) >> 8) & 0xff;
		cmd.wlen = 6;
		cmd.rlen = 4;
		ret = si2168_cmd_execute(s, &cmd);
		if (ret)
			goto err;
	}

304 305
	memcpy(cmd.args, "\x14\x00\x0f\x10\x10\x00", 6);
	cmd.wlen = 6;
306
	cmd.rlen = 4;
307 308 309 310 311 312
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x14\x00\x09\x10\xe3\x18", 6);
	cmd.wlen = 6;
313
	cmd.rlen = 4;
314 315 316 317 318 319
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x15", 6);
	cmd.wlen = 6;
320
	cmd.rlen = 4;
321 322 323 324 325 326
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	memcpy(cmd.args, "\x14\x00\x01\x12\x00\x00", 6);
	cmd.wlen = 6;
327
	cmd.rlen = 4;
328 329 330 331
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

332 333 334 335 336 337 338
	memcpy(cmd.args, "\x14\x00\x01\x03\x0c\x00", 6);
	cmd.wlen = 6;
	cmd.rlen = 4;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

339
	memcpy(cmd.args, "\x85", 1);
340 341 342 343 344 345 346 347 348 349
	cmd.wlen = 1;
	cmd.rlen = 1;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

	s->delivery_system = c->delivery_system;

	return 0;
err:
O
Olli Salonen 已提交
350
	dev_dbg(&s->client->dev, "failed=%d\n", ret);
351 352 353 354 355 356 357 358
	return ret;
}

static int si2168_init(struct dvb_frontend *fe)
{
	struct si2168 *s = fe->demodulator_priv;
	int ret, len, remaining;
	const struct firmware *fw = NULL;
359
	u8 *fw_file;
360 361
	const unsigned int i2c_wr_max = 8;
	struct si2168_cmd cmd;
362
	unsigned int chip_id;
363

O
Olli Salonen 已提交
364
	dev_dbg(&s->client->dev, "\n");
365

366
	/* initialize */
367
	memcpy(cmd.args, "\xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00", 13);
368 369 370 371 372 373
	cmd.wlen = 13;
	cmd.rlen = 0;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
	if (s->fw_loaded) {
		/* resume */
		memcpy(cmd.args, "\xc0\x06\x08\x0f\x00\x20\x21\x01", 8);
		cmd.wlen = 8;
		cmd.rlen = 1;
		ret = si2168_cmd_execute(s, &cmd);
		if (ret)
			goto err;

		memcpy(cmd.args, "\x85", 1);
		cmd.wlen = 1;
		cmd.rlen = 1;
		ret = si2168_cmd_execute(s, &cmd);
		if (ret)
			goto err;

		goto warm;
	}

	/* power up */
394
	memcpy(cmd.args, "\xc0\x06\x01\x0f\x00\x20\x20\x01", 8);
395 396 397 398 399 400
	cmd.wlen = 8;
	cmd.rlen = 1;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

401
	/* query chip revision */
402
	memcpy(cmd.args, "\x02", 1);
403 404 405 406 407 408
	cmd.wlen = 1;
	cmd.rlen = 13;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

409 410 411
	chip_id = cmd.args[1] << 24 | cmd.args[2] << 16 | cmd.args[3] << 8 |
			cmd.args[4] << 0;

412
	#define SI2168_A20 ('A' << 24 | 68 << 16 | '2' << 8 | '0' << 0)
413 414 415 416
	#define SI2168_A30 ('A' << 24 | 68 << 16 | '3' << 8 | '0' << 0)
	#define SI2168_B40 ('B' << 24 | 68 << 16 | '4' << 8 | '0' << 0)

	switch (chip_id) {
417 418 419
	case SI2168_A20:
		fw_file = SI2168_A20_FIRMWARE;
		break;
420
	case SI2168_A30:
421
		fw_file = SI2168_A30_FIRMWARE;
422 423 424 425 426
		break;
	case SI2168_B40:
		fw_file = SI2168_B40_FIRMWARE;
		break;
	default:
427
		dev_err(&s->client->dev,
O
Olli Salonen 已提交
428 429
				"unknown chip version Si21%d-%c%c%c\n",
				cmd.args[2], cmd.args[1],
430
				cmd.args[3], cmd.args[4]);
431 432 433 434
		ret = -EINVAL;
		goto err;
	}

435
	/* cold state - try to download firmware */
O
Olli Salonen 已提交
436 437
	dev_info(&s->client->dev, "found a '%s' in cold state\n",
			si2168_ops.info.name);
438 439 440 441

	/* request the firmware, this will block and timeout */
	ret = request_firmware(&fw, fw_file, &s->client->dev);
	if (ret) {
442 443
		/* fallback mechanism to handle old name for Si2168 B40 fw */
		if (chip_id == SI2168_B40) {
444 445 446
			fw_file = SI2168_B40_FIRMWARE_FALLBACK;
			ret = request_firmware(&fw, fw_file, &s->client->dev);
		}
447 448 449

		if (ret == 0) {
			dev_notice(&s->client->dev,
O
Olli Salonen 已提交
450 451
					"please install firmware file '%s'\n",
					SI2168_B40_FIRMWARE);
452 453
		} else {
			dev_err(&s->client->dev,
O
Olli Salonen 已提交
454 455
					"firmware file '%s' not found\n",
					fw_file);
456 457
			goto err;
		}
458 459
	}

O
Olli Salonen 已提交
460 461
	dev_info(&s->client->dev, "downloading firmware from file '%s'\n",
			fw_file);
462 463 464 465 466 467 468 469 470 471 472 473

	for (remaining = fw->size; remaining > 0; remaining -= i2c_wr_max) {
		len = remaining;
		if (len > i2c_wr_max)
			len = i2c_wr_max;

		memcpy(cmd.args, &fw->data[fw->size - remaining], len);
		cmd.wlen = len;
		cmd.rlen = 1;
		ret = si2168_cmd_execute(s, &cmd);
		if (ret) {
			dev_err(&s->client->dev,
O
Olli Salonen 已提交
474 475
					"firmware download failed=%d\n",
					ret);
476 477 478 479 480 481 482
			goto err;
		}
	}

	release_firmware(fw);
	fw = NULL;

483
	memcpy(cmd.args, "\x01\x01", 2);
484 485 486 487 488 489
	cmd.wlen = 2;
	cmd.rlen = 1;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

490 491 492 493 494 495 496 497 498
	/* set ts mode */
	memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
	cmd.args[4] |= s->ts_mode;
	cmd.wlen = 6;
	cmd.rlen = 4;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

499 500 501 502 503 504
	s->fw_loaded = true;

warm:
	dev_info(&s->client->dev, "found a '%s' in warm state\n",
			si2168_ops.info.name);

505 506 507 508 509 510 511
	s->active = true;

	return 0;
err:
	if (fw)
		release_firmware(fw);

O
Olli Salonen 已提交
512
	dev_dbg(&s->client->dev, "failed=%d\n", ret);
513 514 515 516 517 518
	return ret;
}

static int si2168_sleep(struct dvb_frontend *fe)
{
	struct si2168 *s = fe->demodulator_priv;
519 520
	int ret;
	struct si2168_cmd cmd;
521

O
Olli Salonen 已提交
522
	dev_dbg(&s->client->dev, "\n");
523 524 525

	s->active = false;

526 527 528 529 530 531 532
	memcpy(cmd.args, "\x13", 1);
	cmd.wlen = 1;
	cmd.rlen = 0;
	ret = si2168_cmd_execute(s, &cmd);
	if (ret)
		goto err;

533
	return 0;
534
err:
O
Olli Salonen 已提交
535
	dev_dbg(&s->client->dev, "failed=%d\n", ret);
536
	return ret;
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
}

static int si2168_get_tune_settings(struct dvb_frontend *fe,
	struct dvb_frontend_tune_settings *s)
{
	s->min_delay_ms = 900;

	return 0;
}

/*
 * I2C gate logic
 * We must use unlocked i2c_transfer() here because I2C lock is already taken
 * by tuner driver.
 */
static int si2168_select(struct i2c_adapter *adap, void *mux_priv, u32 chan)
{
	struct si2168 *s = mux_priv;
	int ret;
	struct i2c_msg gate_open_msg = {
		.addr = s->client->addr,
		.flags = 0,
		.len = 3,
		.buf = "\xc0\x0d\x01",
	};

	mutex_lock(&s->i2c_mutex);

	/* open tuner I2C gate */
	ret = __i2c_transfer(s->client->adapter, &gate_open_msg, 1);
	if (ret != 1) {
O
Olli Salonen 已提交
568
		dev_warn(&s->client->dev, "i2c write failed=%d\n", ret);
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
		if (ret >= 0)
			ret = -EREMOTEIO;
	} else {
		ret = 0;
	}

	return ret;
}

static int si2168_deselect(struct i2c_adapter *adap, void *mux_priv, u32 chan)
{
	struct si2168 *s = mux_priv;
	int ret;
	struct i2c_msg gate_close_msg = {
		.addr = s->client->addr,
		.flags = 0,
		.len = 3,
		.buf = "\xc0\x0d\x00",
	};

	/* close tuner I2C gate */
	ret = __i2c_transfer(s->client->adapter, &gate_close_msg, 1);
	if (ret != 1) {
O
Olli Salonen 已提交
592
		dev_warn(&s->client->dev, "i2c write failed=%d\n", ret);
593 594 595 596 597 598 599 600 601 602 603 604
		if (ret >= 0)
			ret = -EREMOTEIO;
	} else {
		ret = 0;
	}

	mutex_unlock(&s->i2c_mutex);

	return ret;
}

static const struct dvb_frontend_ops si2168_ops = {
605
	.delsys = {SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A},
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
	.info = {
		.name = "Silicon Labs Si2168",
		.caps =	FE_CAN_FEC_1_2 |
			FE_CAN_FEC_2_3 |
			FE_CAN_FEC_3_4 |
			FE_CAN_FEC_5_6 |
			FE_CAN_FEC_7_8 |
			FE_CAN_FEC_AUTO |
			FE_CAN_QPSK |
			FE_CAN_QAM_16 |
			FE_CAN_QAM_32 |
			FE_CAN_QAM_64 |
			FE_CAN_QAM_128 |
			FE_CAN_QAM_256 |
			FE_CAN_QAM_AUTO |
			FE_CAN_TRANSMISSION_MODE_AUTO |
			FE_CAN_GUARD_INTERVAL_AUTO |
			FE_CAN_HIERARCHY_AUTO |
			FE_CAN_MUTE_TS |
			FE_CAN_2G_MODULATION
	},

	.get_tune_settings = si2168_get_tune_settings,

	.init = si2168_init,
	.sleep = si2168_sleep,

	.set_frontend = si2168_set_frontend,

	.read_status = si2168_read_status,
};

static int si2168_probe(struct i2c_client *client,
		const struct i2c_device_id *id)
{
	struct si2168_config *config = client->dev.platform_data;
	struct si2168 *s;
	int ret;

O
Olli Salonen 已提交
645
	dev_dbg(&client->dev, "\n");
646 647 648 649

	s = kzalloc(sizeof(struct si2168), GFP_KERNEL);
	if (!s) {
		ret = -ENOMEM;
O
Olli Salonen 已提交
650
		dev_err(&client->dev, "kzalloc() failed\n");
651 652 653 654 655 656 657 658 659
		goto err;
	}

	s->client = client;
	mutex_init(&s->i2c_mutex);

	/* create mux i2c adapter for tuner */
	s->adapter = i2c_add_mux_adapter(client->adapter, &client->dev, s,
			0, 0, 0, si2168_select, si2168_deselect);
660 661
	if (s->adapter == NULL) {
		ret = -ENODEV;
662
		goto err;
663
	}
664 665 666 667 668 669 670

	/* create dvb_frontend */
	memcpy(&s->fe.ops, &si2168_ops, sizeof(struct dvb_frontend_ops));
	s->fe.demodulator_priv = s;

	*config->i2c_adapter = s->adapter;
	*config->fe = &s->fe;
671
	s->ts_mode = config->ts_mode;
672
	s->fw_loaded = false;
673 674 675 676

	i2c_set_clientdata(client, s);

	dev_info(&s->client->dev,
O
Olli Salonen 已提交
677
			"Silicon Labs Si2168 successfully attached\n");
678 679 680
	return 0;
err:
	kfree(s);
O
Olli Salonen 已提交
681
	dev_dbg(&client->dev, "failed=%d\n", ret);
682 683 684 685 686 687 688
	return ret;
}

static int si2168_remove(struct i2c_client *client)
{
	struct si2168 *s = i2c_get_clientdata(client);

O
Olli Salonen 已提交
689
	dev_dbg(&client->dev, "\n");
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721

	i2c_del_mux_adapter(s->adapter);

	s->fe.ops.release = NULL;
	s->fe.demodulator_priv = NULL;

	kfree(s);

	return 0;
}

static const struct i2c_device_id si2168_id[] = {
	{"si2168", 0},
	{}
};
MODULE_DEVICE_TABLE(i2c, si2168_id);

static struct i2c_driver si2168_driver = {
	.driver = {
		.owner	= THIS_MODULE,
		.name	= "si2168",
	},
	.probe		= si2168_probe,
	.remove		= si2168_remove,
	.id_table	= si2168_id,
};

module_i2c_driver(si2168_driver);

MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
MODULE_DESCRIPTION("Silicon Labs Si2168 DVB-T/T2/C demodulator driver");
MODULE_LICENSE("GPL");
722
MODULE_FIRMWARE(SI2168_A20_FIRMWARE);
723
MODULE_FIRMWARE(SI2168_A30_FIRMWARE);
724
MODULE_FIRMWARE(SI2168_B40_FIRMWARE);