2 * Support for LGDT3302 and LGDT3303 - VSB/QAM
4 * Copyright (C) 2005 Wilson Michaels <wilsonmichaels@earthlink.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
19 * NOTES ABOUT THIS DRIVER
21 * This Linux driver supports:
22 * DViCO FusionHDTV 3 Gold-Q
23 * DViCO FusionHDTV 3 Gold-T
24 * DViCO FusionHDTV 5 Gold
25 * DViCO FusionHDTV 5 Lite
26 * DViCO FusionHDTV 5 USB Gold
27 * Air2PC/AirStar 2 ATSC 3rd generation (HD5000)
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/delay.h>
36 #include <linux/string.h>
37 #include <linux/slab.h>
38 #include <asm/byteorder.h>
40 #include <media/dvb_frontend.h>
41 #include <media/dvb_math.h>
42 #include "lgdt330x_priv.h"
45 /* Use Equalizer Mean Squared Error instead of Phaser Tracker MSE */
46 /* #define USE_EQMSE */
49 module_param(debug, int, 0644);
50 MODULE_PARM_DESC(debug, "Turn on/off lgdt330x frontend debugging (default:off).");
52 #define dprintk(state, fmt, arg...) do { \
54 dev_printk(KERN_DEBUG, &state->client->dev, fmt, ##arg);\
57 struct lgdt330x_state {
58 struct i2c_client *client;
60 /* Configuration settings */
61 struct lgdt330x_config config;
63 struct dvb_frontend frontend;
65 /* Demodulator private data */
66 enum fe_modulation current_modulation;
67 u32 snr; /* Result of last SNR calculation */
69 unsigned long last_stats_time;
71 /* Tuner private data */
72 u32 current_frequency;
75 static int i2c_write_demod_bytes(struct lgdt330x_state *state,
76 const u8 *buf, /* data bytes to send */
77 int len /* number of bytes to send */)
82 for (i = 0; i < len - 1; i += 2) {
83 err = i2c_master_send(state->client, buf, 2);
85 dev_warn(&state->client->dev,
86 "%s: error (addr %02x <- %02x, err = %i)\n",
87 __func__, buf[0], buf[1], err);
99 * This routine writes the register (reg) to the demod bus
100 * then reads the data returned for (len) bytes.
102 static int i2c_read_demod_bytes(struct lgdt330x_state *state,
103 enum I2C_REG reg, u8 *buf, int len)
106 struct i2c_msg msg[] = {
108 .addr = state->client->addr,
113 .addr = state->client->addr,
121 ret = i2c_transfer(state->client->adapter, msg, 2);
123 dev_warn(&state->client->dev,
124 "%s: addr 0x%02x select 0x%02x error (ret == %i)\n",
125 __func__, state->client->addr, reg, ret);
135 static int lgdt3302_sw_reset(struct lgdt330x_state *state)
141 * bit 6 is active low software reset
142 * bits 5-0 are 1 to mask interrupts
147 ret = i2c_write_demod_bytes(state,
148 reset, sizeof(reset));
150 /* force reset high (inactive) and unmask interrupts */
152 ret = i2c_write_demod_bytes(state,
153 reset, sizeof(reset));
158 static int lgdt3303_sw_reset(struct lgdt330x_state *state)
163 0x00 /* bit 0 is active low software reset */
166 ret = i2c_write_demod_bytes(state,
167 reset, sizeof(reset));
169 /* force reset high (inactive) */
171 ret = i2c_write_demod_bytes(state,
172 reset, sizeof(reset));
177 static int lgdt330x_sw_reset(struct lgdt330x_state *state)
179 switch (state->config.demod_chip) {
181 return lgdt3302_sw_reset(state);
183 return lgdt3303_sw_reset(state);
189 static int lgdt330x_init(struct dvb_frontend *fe)
191 struct lgdt330x_state *state = fe->demodulator_priv;
192 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
196 * Array of byte pairs <address, value>
197 * to initialize each different chip
199 static const u8 lgdt3302_init_data[] = {
200 /* Use 50MHz param values from spec sheet since xtal is 50 */
202 * Change the value of NCOCTFV[25:0] of carrier
203 * recovery center frequency register
205 VSB_CARRIER_FREQ0, 0x00,
206 VSB_CARRIER_FREQ1, 0x87,
207 VSB_CARRIER_FREQ2, 0x8e,
208 VSB_CARRIER_FREQ3, 0x01,
210 * Change the TPCLK pin polarity
211 * data is valid on falling clock
215 * Change the value of IFBW[11:0] of
216 * AGC IF/RF loop filter bandwidth register
218 AGC_RF_BANDWIDTH0, 0x40,
219 AGC_RF_BANDWIDTH1, 0x93,
220 AGC_RF_BANDWIDTH2, 0x00,
222 * Change the value of bit 6, 'nINAGCBY' and
223 * 'NSSEL[1:0] of ACG function control register 2
225 AGC_FUNC_CTRL2, 0xc6,
227 * Change the value of bit 6 'RFFIX'
228 * of AGC function control register 3
230 AGC_FUNC_CTRL3, 0x40,
232 * Set the value of 'INLVTHD' register 0x2a/0x2c
238 * Change the value of IAGCBW[15:8]
239 * of inner AGC loop filter bandwidth
241 AGC_LOOP_BANDWIDTH0, 0x08,
242 AGC_LOOP_BANDWIDTH1, 0x9a
244 static const u8 lgdt3303_init_data[] = {
247 static const u8 flip_1_lgdt3303_init_data[] = {
251 static const u8 flip_2_lgdt3303_init_data[] = {
257 * Hardware reset is done using gpio[0] of cx23880x chip.
258 * I'd like to do it here, but don't know how to find chip address.
259 * cx88-cards.c arranges for the reset bit to be inactive (high).
260 * Maybe there needs to be a callable function in cx88-core or
261 * the caller of this function needs to do it.
264 switch (state->config.demod_chip) {
266 chip_name = "LGDT3302";
267 err = i2c_write_demod_bytes(state, lgdt3302_init_data,
268 sizeof(lgdt3302_init_data));
271 chip_name = "LGDT3303";
272 switch (state->config.clock_polarity_flip) {
274 err = i2c_write_demod_bytes(state,
275 flip_2_lgdt3303_init_data,
276 sizeof(flip_2_lgdt3303_init_data));
279 err = i2c_write_demod_bytes(state,
280 flip_1_lgdt3303_init_data,
281 sizeof(flip_1_lgdt3303_init_data));
285 err = i2c_write_demod_bytes(state, lgdt3303_init_data,
286 sizeof(lgdt3303_init_data));
290 chip_name = "undefined";
291 dev_warn(&state->client->dev,
292 "Only LGDT3302 and LGDT3303 are supported chips.\n");
295 dprintk(state, "Initialized the %s chip\n", chip_name);
300 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
301 p->block_error.len = 1;
302 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
303 p->block_count.len = 1;
304 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
305 state->last_stats_time = 0;
307 return lgdt330x_sw_reset(state);
310 static int lgdt330x_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
312 struct lgdt330x_state *state = fe->demodulator_priv;
314 *ucblocks = state->ucblocks;
319 static int lgdt330x_set_parameters(struct dvb_frontend *fe)
321 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
322 struct lgdt330x_state *state = fe->demodulator_priv;
324 * Array of byte pairs <address, value>
325 * to initialize 8VSB for lgdt3303 chip 50 MHz IF
327 static const u8 lgdt3303_8vsb_44_data[] = {
336 * Array of byte pairs <address, value>
337 * to initialize QAM for lgdt3303 chip
339 static const u8 lgdt3303_qam_data[] = {
352 u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 };
355 /* Change only if we are actually changing the modulation */
356 if (state->current_modulation != p->modulation) {
357 switch (p->modulation) {
359 dprintk(state, "VSB_8 MODE\n");
361 /* Select VSB mode */
362 top_ctrl_cfg[1] = 0x03;
364 /* Select ANT connector if supported by card */
365 if (state->config.pll_rf_set)
366 state->config.pll_rf_set(fe, 1);
368 if (state->config.demod_chip == LGDT3303) {
369 err = i2c_write_demod_bytes(state,
370 lgdt3303_8vsb_44_data,
371 sizeof(lgdt3303_8vsb_44_data));
376 dprintk(state, "QAM_64 MODE\n");
378 /* Select QAM_64 mode */
379 top_ctrl_cfg[1] = 0x00;
381 /* Select CABLE connector if supported by card */
382 if (state->config.pll_rf_set)
383 state->config.pll_rf_set(fe, 0);
385 if (state->config.demod_chip == LGDT3303) {
386 err = i2c_write_demod_bytes(state,
388 sizeof(lgdt3303_qam_data));
393 dprintk(state, "QAM_256 MODE\n");
395 /* Select QAM_256 mode */
396 top_ctrl_cfg[1] = 0x01;
398 /* Select CABLE connector if supported by card */
399 if (state->config.pll_rf_set)
400 state->config.pll_rf_set(fe, 0);
402 if (state->config.demod_chip == LGDT3303) {
403 err = i2c_write_demod_bytes(state,
405 sizeof(lgdt3303_qam_data));
409 dev_warn(&state->client->dev,
410 "%s: Modulation type(%d) UNSUPPORTED\n",
411 __func__, p->modulation);
415 dev_warn(&state->client->dev,
416 "%s: error blasting bytes to lgdt3303 for modulation type(%d)\n",
417 __func__, p->modulation);
420 * select serial or parallel MPEG hardware interface
421 * Serial: 0x04 for LGDT3302 or 0x40 for LGDT3303
424 top_ctrl_cfg[1] |= state->config.serial_mpeg;
426 /* Select the requested mode */
427 i2c_write_demod_bytes(state, top_ctrl_cfg,
428 sizeof(top_ctrl_cfg));
429 if (state->config.set_ts_params)
430 state->config.set_ts_params(fe, 0);
431 state->current_modulation = p->modulation;
434 /* Tune to the specified frequency */
435 if (fe->ops.tuner_ops.set_params) {
436 fe->ops.tuner_ops.set_params(fe);
437 if (fe->ops.i2c_gate_ctrl)
438 fe->ops.i2c_gate_ctrl(fe, 0);
441 /* Keep track of the new frequency */
443 * FIXME this is the wrong way to do this...
444 * The tuner is shared with the video4linux analog API
446 state->current_frequency = p->frequency;
448 lgdt330x_sw_reset(state);
452 static int lgdt330x_get_frontend(struct dvb_frontend *fe,
453 struct dtv_frontend_properties *p)
455 struct lgdt330x_state *state = fe->demodulator_priv;
457 p->frequency = state->current_frequency;
462 * Calculate SNR estimation (scaled by 2^24)
464 * 8-VSB SNR equations from LGDT3302 and LGDT3303 datasheets, QAM
465 * equations from LGDT3303 datasheet. VSB is the same between the '02
466 * and '03, so maybe QAM is too? Perhaps someone with a newer datasheet
467 * that has QAM information could verify?
469 * For 8-VSB: (two ways, take your pick)
471 * SNR_EQ = 10 * log10(25 * 24^2 / EQ_MSE)
473 * SNR_EQ = 10 * log10(25 * 32^2 / EQ_MSE)
474 * LGDT3302 & LGDT3303:
475 * SNR_PT = 10 * log10(25 * 32^2 / PT_MSE) (we use this one)
477 * SNR = 10 * log10( 688128 / MSEQAM)
479 * SNR = 10 * log10( 696320 / MSEQAM)
481 * We re-write the snr equation as:
482 * SNR * 2^24 = 10*(c - intlog10(MSE))
483 * Where for 256-QAM, c = log10(696320) * 2^24, and so on.
485 static u32 calculate_snr(u32 mse, u32 c)
487 if (mse == 0) /* No signal */
493 * Negative SNR, which is possible, but realisticly the
494 * demod will lose lock before the signal gets this bad.
495 * The API only allows for unsigned values, so just return 0
499 return 10 * (c - mse);
502 static int lgdt3302_read_snr(struct dvb_frontend *fe)
504 struct lgdt330x_state *state = fe->demodulator_priv;
505 u8 buf[5]; /* read data buffer */
506 u32 noise; /* noise value */
507 u32 c; /* per-modulation SNR calculation constant */
509 switch (state->current_modulation) {
511 i2c_read_demod_bytes(state, LGDT3302_EQPH_ERR0, buf, 5);
513 /* Use Equalizer Mean-Square Error Register */
514 /* SNR for ranges from -15.61 to +41.58 */
515 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
516 c = 69765745; /* log10(25*24^2)*2^24 */
518 /* Use Phase Tracker Mean-Square Error Register */
519 /* SNR for ranges from -13.11 to +44.08 */
520 noise = ((buf[0] & 7 << 3) << 13) | (buf[3] << 8) | buf[4];
521 c = 73957994; /* log10(25*32^2)*2^24 */
526 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
527 noise = ((buf[0] & 3) << 8) | buf[1];
528 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
529 /* log10(688128)*2^24 and log10(696320)*2^24 */
532 dev_err(&state->client->dev,
533 "%s: Modulation set to unsupported value\n",
538 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
541 state->snr = calculate_snr(noise, c);
543 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
544 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
549 static int lgdt3303_read_snr(struct dvb_frontend *fe)
551 struct lgdt330x_state *state = fe->demodulator_priv;
552 u8 buf[5]; /* read data buffer */
553 u32 noise; /* noise value */
554 u32 c; /* per-modulation SNR calculation constant */
556 switch (state->current_modulation) {
558 i2c_read_demod_bytes(state, LGDT3303_EQPH_ERR0, buf, 5);
560 /* Use Equalizer Mean-Square Error Register */
561 /* SNR for ranges from -16.12 to +44.08 */
562 noise = ((buf[0] & 0x78) << 13) | (buf[1] << 8) | buf[2];
563 c = 73957994; /* log10(25*32^2)*2^24 */
565 /* Use Phase Tracker Mean-Square Error Register */
566 /* SNR for ranges from -13.11 to +44.08 */
567 noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4];
568 c = 73957994; /* log10(25*32^2)*2^24 */
573 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
574 noise = (buf[0] << 8) | buf[1];
575 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
576 /* log10(688128)*2^24 and log10(696320)*2^24 */
579 dev_err(&state->client->dev,
580 "%s: Modulation set to unsupported value\n",
583 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
586 state->snr = calculate_snr(noise, c);
588 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
589 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
594 static int lgdt330x_read_snr(struct dvb_frontend *fe, u16 *snr)
596 struct lgdt330x_state *state = fe->demodulator_priv;
598 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */
603 static int lgdt330x_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
605 /* Calculate Strength from SNR up to 35dB */
607 * Even though the SNR can go higher than 35dB, there is some comfort
608 * factor in having a range of strong signals that can show at 100%
610 struct lgdt330x_state *state = fe->demodulator_priv;
614 ret = fe->ops.read_snr(fe, &snr);
617 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
618 /* scale the range 0 - 35*2^24 into 0 - 65535 */
619 if (state->snr >= 8960 * 0x10000)
622 *strength = state->snr / 8960;
628 static int lgdt3302_read_status(struct dvb_frontend *fe,
629 enum fe_status *status)
631 struct lgdt330x_state *state = fe->demodulator_priv;
632 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
636 *status = 0; /* Reset status result */
638 /* AGC status register */
639 i2c_read_demod_bytes(state, AGC_STATUS, buf, 1);
640 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
641 if ((buf[0] & 0x0c) == 0x8) {
643 * Test signal does not exist flag
644 * as well as the AGC lock flag.
646 *status |= FE_HAS_SIGNAL;
650 * You must set the Mask bits to 1 in the IRQ_MASK in order
651 * to see that status bit in the IRQ_STATUS register.
652 * This is done in SwReset();
656 i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf));
658 "TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n",
659 buf[0], buf[1], buf[2]);
662 if ((buf[2] & 0x03) == 0x01)
663 *status |= FE_HAS_SYNC;
665 /* FEC error status */
666 if ((buf[2] & 0x0c) == 0x08)
667 *status |= FE_HAS_LOCK | FE_HAS_VITERBI;
669 /* Carrier Recovery Lock Status Register */
670 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
671 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
672 switch (state->current_modulation) {
675 /* Need to understand why there are 3 lock levels here */
676 if ((buf[0] & 0x07) == 0x07)
677 *status |= FE_HAS_CARRIER;
680 if ((buf[0] & 0x80) == 0x80)
681 *status |= FE_HAS_CARRIER;
684 dev_warn(&state->client->dev,
685 "%s: Modulation set to unsupported value\n",
689 if (!(*status & FE_HAS_LOCK)) {
690 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
691 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
692 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
696 if (state->last_stats_time &&
697 time_is_after_jiffies(state->last_stats_time))
700 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
702 err = lgdt3302_read_snr(fe);
704 p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
705 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
707 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
710 err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1,
713 state->ucblocks = (buf[0] << 8) | buf[1];
715 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
717 p->block_error.stat[0].uvalue += state->ucblocks;
718 /* FIXME: what's the basis for block count */
719 p->block_count.stat[0].uvalue += 10000;
721 p->block_error.stat[0].scale = FE_SCALE_COUNTER;
722 p->block_count.stat[0].scale = FE_SCALE_COUNTER;
724 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
725 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
731 static int lgdt3303_read_status(struct dvb_frontend *fe,
732 enum fe_status *status)
734 struct lgdt330x_state *state = fe->demodulator_priv;
735 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
739 *status = 0; /* Reset status result */
741 /* lgdt3303 AGC status register */
742 err = i2c_read_demod_bytes(state, 0x58, buf, 1);
746 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
747 if ((buf[0] & 0x21) == 0x01) {
749 * Test input signal does not exist flag
750 * as well as the AGC lock flag.
752 *status |= FE_HAS_SIGNAL;
755 /* Carrier Recovery Lock Status Register */
756 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
757 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
758 switch (state->current_modulation) {
761 /* Need to understand why there are 3 lock levels here */
762 if ((buf[0] & 0x07) == 0x07)
763 *status |= FE_HAS_CARRIER;
766 i2c_read_demod_bytes(state, 0x8a, buf, 1);
767 dprintk(state, "QAM LOCK = 0x%02x\n", buf[0]);
769 if ((buf[0] & 0x04) == 0x04)
770 *status |= FE_HAS_SYNC;
771 if ((buf[0] & 0x01) == 0x01)
772 *status |= FE_HAS_LOCK;
773 if ((buf[0] & 0x08) == 0x08)
774 *status |= FE_HAS_VITERBI;
777 if ((buf[0] & 0x80) == 0x80)
778 *status |= FE_HAS_CARRIER;
781 i2c_read_demod_bytes(state, 0x38, buf, 1);
782 dprintk(state, "8-VSB LOCK = 0x%02x\n", buf[0]);
784 if ((buf[0] & 0x02) == 0x00)
785 *status |= FE_HAS_SYNC;
786 if ((buf[0] & 0x01) == 0x01)
787 *status |= FE_HAS_VITERBI | FE_HAS_LOCK;
790 dev_warn(&state->client->dev,
791 "%s: Modulation set to unsupported value\n",
795 if (!(*status & FE_HAS_LOCK)) {
796 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
797 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
798 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
802 if (state->last_stats_time &&
803 time_is_after_jiffies(state->last_stats_time))
806 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
808 err = lgdt3303_read_snr(fe);
810 p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
811 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
813 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
816 err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1,
819 state->ucblocks = (buf[0] << 8) | buf[1];
821 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
823 p->block_error.stat[0].uvalue += state->ucblocks;
824 /* FIXME: what's the basis for block count */
825 p->block_count.stat[0].uvalue += 10000;
827 p->block_error.stat[0].scale = FE_SCALE_COUNTER;
828 p->block_count.stat[0].scale = FE_SCALE_COUNTER;
830 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
831 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
838 lgdt330x_get_tune_settings(struct dvb_frontend *fe,
839 struct dvb_frontend_tune_settings *fe_tune_settings)
841 /* I have no idea about this - it may not be needed */
842 fe_tune_settings->min_delay_ms = 500;
843 fe_tune_settings->step_size = 0;
844 fe_tune_settings->max_drift = 0;
848 static void lgdt330x_release(struct dvb_frontend *fe)
850 struct lgdt330x_state *state = fe->demodulator_priv;
851 struct i2c_client *client = state->client;
853 dev_dbg(&client->dev, "\n");
855 i2c_unregister_device(client);
858 static struct dvb_frontend *lgdt330x_get_dvb_frontend(struct i2c_client *client)
860 struct lgdt330x_state *state = i2c_get_clientdata(client);
862 dev_dbg(&client->dev, "\n");
864 return &state->frontend;
867 static const struct dvb_frontend_ops lgdt3302_ops;
868 static const struct dvb_frontend_ops lgdt3303_ops;
870 static int lgdt330x_probe(struct i2c_client *client,
871 const struct i2c_device_id *id)
873 struct lgdt330x_state *state = NULL;
876 /* Allocate memory for the internal state */
877 state = kzalloc(sizeof(*state), GFP_KERNEL);
881 /* Setup the state */
882 memcpy(&state->config, client->dev.platform_data,
883 sizeof(state->config));
884 i2c_set_clientdata(client, state);
885 state->client = client;
887 /* Create dvb_frontend */
888 switch (state->config.demod_chip) {
890 memcpy(&state->frontend.ops, &lgdt3302_ops,
891 sizeof(struct dvb_frontend_ops));
894 memcpy(&state->frontend.ops, &lgdt3303_ops,
895 sizeof(struct dvb_frontend_ops));
900 state->frontend.demodulator_priv = state;
902 /* Setup get frontend callback */
903 state->config.get_dvb_frontend = lgdt330x_get_dvb_frontend;
905 /* Verify communication with demod chip */
906 if (i2c_read_demod_bytes(state, 2, buf, 1))
909 state->current_frequency = -1;
910 state->current_modulation = -1;
912 dev_info(&state->client->dev,
913 "Demod loaded for LGDT330%s chip\n",
914 state->config.demod_chip == LGDT3302 ? "2" : "3");
921 dev_printk(KERN_DEBUG, &client->dev, "Error loading lgdt330x driver\n");
924 struct dvb_frontend *lgdt330x_attach(const struct lgdt330x_config *_config,
926 struct i2c_adapter *i2c)
928 struct i2c_client *client;
929 struct i2c_board_info board_info = {};
930 struct lgdt330x_config config = *_config;
932 strlcpy(board_info.type, "lgdt330x", sizeof(board_info.type));
933 board_info.addr = demod_address;
934 board_info.platform_data = &config;
935 client = i2c_new_device(i2c, &board_info);
936 if (!client || !client->dev.driver)
939 return lgdt330x_get_dvb_frontend(client);
941 EXPORT_SYMBOL(lgdt330x_attach);
943 static const struct dvb_frontend_ops lgdt3302_ops = {
944 .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
946 .name = "LG Electronics LGDT3302 VSB/QAM Frontend",
947 .frequency_min_hz = 54 * MHz,
948 .frequency_max_hz = 858 * MHz,
949 .frequency_stepsize_hz = 62500,
950 .symbol_rate_min = 5056941, /* QAM 64 */
951 .symbol_rate_max = 10762000, /* VSB 8 */
952 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
954 .init = lgdt330x_init,
955 .set_frontend = lgdt330x_set_parameters,
956 .get_frontend = lgdt330x_get_frontend,
957 .get_tune_settings = lgdt330x_get_tune_settings,
958 .read_status = lgdt3302_read_status,
959 .read_signal_strength = lgdt330x_read_signal_strength,
960 .read_snr = lgdt330x_read_snr,
961 .read_ucblocks = lgdt330x_read_ucblocks,
962 .release = lgdt330x_release,
965 static const struct dvb_frontend_ops lgdt3303_ops = {
966 .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
968 .name = "LG Electronics LGDT3303 VSB/QAM Frontend",
969 .frequency_min_hz = 54 * MHz,
970 .frequency_max_hz = 858 * MHz,
971 .frequency_stepsize_hz = 62500,
972 .symbol_rate_min = 5056941, /* QAM 64 */
973 .symbol_rate_max = 10762000, /* VSB 8 */
974 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
976 .init = lgdt330x_init,
977 .set_frontend = lgdt330x_set_parameters,
978 .get_frontend = lgdt330x_get_frontend,
979 .get_tune_settings = lgdt330x_get_tune_settings,
980 .read_status = lgdt3303_read_status,
981 .read_signal_strength = lgdt330x_read_signal_strength,
982 .read_snr = lgdt330x_read_snr,
983 .read_ucblocks = lgdt330x_read_ucblocks,
984 .release = lgdt330x_release,
987 static int lgdt330x_remove(struct i2c_client *client)
989 struct lgdt330x_state *state = i2c_get_clientdata(client);
991 dev_dbg(&client->dev, "\n");
998 static const struct i2c_device_id lgdt330x_id_table[] = {
1002 MODULE_DEVICE_TABLE(i2c, lgdt330x_id_table);
1004 static struct i2c_driver lgdt330x_driver = {
1007 .suppress_bind_attrs = true,
1009 .probe = lgdt330x_probe,
1010 .remove = lgdt330x_remove,
1011 .id_table = lgdt330x_id_table,
1014 module_i2c_driver(lgdt330x_driver);
1017 MODULE_DESCRIPTION("LGDT330X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
1018 MODULE_AUTHOR("Wilson Michaels");
1019 MODULE_LICENSE("GPL");