1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Support for LGDT3302 and LGDT3303 - VSB/QAM
9 * NOTES ABOUT THIS DRIVER
11 * This Linux driver supports:
12 * DViCO FusionHDTV 3 Gold-Q
13 * DViCO FusionHDTV 3 Gold-T
14 * DViCO FusionHDTV 5 Gold
15 * DViCO FusionHDTV 5 Lite
16 * DViCO FusionHDTV 5 USB Gold
17 * Air2PC/AirStar 2 ATSC 3rd generation (HD5000)
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
28 #include <asm/byteorder.h>
30 #include <media/dvb_frontend.h>
31 #include <linux/int_log.h>
32 #include "lgdt330x_priv.h"
35 /* Use Equalizer Mean Squared Error instead of Phaser Tracker MSE */
36 /* #define USE_EQMSE */
39 module_param(debug, int, 0644);
40 MODULE_PARM_DESC(debug, "Turn on/off lgdt330x frontend debugging (default:off).");
42 #define dprintk(state, fmt, arg...) do { \
44 dev_printk(KERN_DEBUG, &state->client->dev, fmt, ##arg);\
47 struct lgdt330x_state {
48 struct i2c_client *client;
50 /* Configuration settings */
51 struct lgdt330x_config config;
53 struct dvb_frontend frontend;
55 /* Demodulator private data */
56 enum fe_modulation current_modulation;
57 u32 snr; /* Result of last SNR calculation */
59 unsigned long last_stats_time;
61 /* Tuner private data */
62 u32 current_frequency;
65 static int i2c_write_demod_bytes(struct lgdt330x_state *state,
66 const u8 *buf, /* data bytes to send */
67 int len /* number of bytes to send */)
72 for (i = 0; i < len - 1; i += 2) {
73 err = i2c_master_send(state->client, buf, 2);
75 dev_warn(&state->client->dev,
76 "%s: error (addr %02x <- %02x, err = %i)\n",
77 __func__, buf[0], buf[1], err);
89 * This routine writes the register (reg) to the demod bus
90 * then reads the data returned for (len) bytes.
92 static int i2c_read_demod_bytes(struct lgdt330x_state *state,
93 enum I2C_REG reg, u8 *buf, int len)
96 struct i2c_msg msg[] = {
98 .addr = state->client->addr,
103 .addr = state->client->addr,
111 ret = i2c_transfer(state->client->adapter, msg, 2);
113 dev_warn(&state->client->dev,
114 "%s: addr 0x%02x select 0x%02x error (ret == %i)\n",
115 __func__, state->client->addr, reg, ret);
125 static int lgdt3302_sw_reset(struct lgdt330x_state *state)
131 * bit 6 is active low software reset
132 * bits 5-0 are 1 to mask interrupts
137 ret = i2c_write_demod_bytes(state,
138 reset, sizeof(reset));
140 /* force reset high (inactive) and unmask interrupts */
142 ret = i2c_write_demod_bytes(state,
143 reset, sizeof(reset));
148 static int lgdt3303_sw_reset(struct lgdt330x_state *state)
153 0x00 /* bit 0 is active low software reset */
156 ret = i2c_write_demod_bytes(state,
157 reset, sizeof(reset));
159 /* force reset high (inactive) */
161 ret = i2c_write_demod_bytes(state,
162 reset, sizeof(reset));
167 static int lgdt330x_sw_reset(struct lgdt330x_state *state)
169 switch (state->config.demod_chip) {
171 return lgdt3302_sw_reset(state);
173 return lgdt3303_sw_reset(state);
179 static int lgdt330x_init(struct dvb_frontend *fe)
181 struct lgdt330x_state *state = fe->demodulator_priv;
182 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
186 * Array of byte pairs <address, value>
187 * to initialize each different chip
189 static const u8 lgdt3302_init_data[] = {
190 /* Use 50MHz param values from spec sheet since xtal is 50 */
192 * Change the value of NCOCTFV[25:0] of carrier
193 * recovery center frequency register
195 VSB_CARRIER_FREQ0, 0x00,
196 VSB_CARRIER_FREQ1, 0x87,
197 VSB_CARRIER_FREQ2, 0x8e,
198 VSB_CARRIER_FREQ3, 0x01,
200 * Change the TPCLK pin polarity
201 * data is valid on falling clock
205 * Change the value of IFBW[11:0] of
206 * AGC IF/RF loop filter bandwidth register
208 AGC_RF_BANDWIDTH0, 0x40,
209 AGC_RF_BANDWIDTH1, 0x93,
210 AGC_RF_BANDWIDTH2, 0x00,
212 * Change the value of bit 6, 'nINAGCBY' and
213 * 'NSSEL[1:0] of ACG function control register 2
215 AGC_FUNC_CTRL2, 0xc6,
217 * Change the value of bit 6 'RFFIX'
218 * of AGC function control register 3
220 AGC_FUNC_CTRL3, 0x40,
222 * Set the value of 'INLVTHD' register 0x2a/0x2c
228 * Change the value of IAGCBW[15:8]
229 * of inner AGC loop filter bandwidth
231 AGC_LOOP_BANDWIDTH0, 0x08,
232 AGC_LOOP_BANDWIDTH1, 0x9a
234 static const u8 lgdt3303_init_data[] = {
237 static const u8 flip_1_lgdt3303_init_data[] = {
241 static const u8 flip_2_lgdt3303_init_data[] = {
247 * Hardware reset is done using gpio[0] of cx23880x chip.
248 * I'd like to do it here, but don't know how to find chip address.
249 * cx88-cards.c arranges for the reset bit to be inactive (high).
250 * Maybe there needs to be a callable function in cx88-core or
251 * the caller of this function needs to do it.
254 switch (state->config.demod_chip) {
256 chip_name = "LGDT3302";
257 err = i2c_write_demod_bytes(state, lgdt3302_init_data,
258 sizeof(lgdt3302_init_data));
261 chip_name = "LGDT3303";
262 switch (state->config.clock_polarity_flip) {
264 err = i2c_write_demod_bytes(state,
265 flip_2_lgdt3303_init_data,
266 sizeof(flip_2_lgdt3303_init_data));
269 err = i2c_write_demod_bytes(state,
270 flip_1_lgdt3303_init_data,
271 sizeof(flip_1_lgdt3303_init_data));
275 err = i2c_write_demod_bytes(state, lgdt3303_init_data,
276 sizeof(lgdt3303_init_data));
280 chip_name = "undefined";
281 dev_warn(&state->client->dev,
282 "Only LGDT3302 and LGDT3303 are supported chips.\n");
285 dprintk(state, "Initialized the %s chip\n", chip_name);
290 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
291 p->block_error.len = 1;
292 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
293 p->block_count.len = 1;
294 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
295 state->last_stats_time = 0;
297 return lgdt330x_sw_reset(state);
300 static int lgdt330x_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
302 struct lgdt330x_state *state = fe->demodulator_priv;
304 *ucblocks = state->ucblocks;
309 static int lgdt330x_set_parameters(struct dvb_frontend *fe)
311 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
312 struct lgdt330x_state *state = fe->demodulator_priv;
314 * Array of byte pairs <address, value>
315 * to initialize 8VSB for lgdt3303 chip 50 MHz IF
317 static const u8 lgdt3303_8vsb_44_data[] = {
326 * Array of byte pairs <address, value>
327 * to initialize QAM for lgdt3303 chip
329 static const u8 lgdt3303_qam_data[] = {
342 u8 top_ctrl_cfg[] = { TOP_CONTROL, 0x03 };
345 /* Change only if we are actually changing the modulation */
346 if (state->current_modulation != p->modulation) {
347 switch (p->modulation) {
349 dprintk(state, "VSB_8 MODE\n");
351 /* Select VSB mode */
352 top_ctrl_cfg[1] = 0x03;
354 /* Select ANT connector if supported by card */
355 if (state->config.pll_rf_set)
356 state->config.pll_rf_set(fe, 1);
358 if (state->config.demod_chip == LGDT3303) {
359 err = i2c_write_demod_bytes(state,
360 lgdt3303_8vsb_44_data,
361 sizeof(lgdt3303_8vsb_44_data));
366 dprintk(state, "QAM_64 MODE\n");
368 /* Select QAM_64 mode */
369 top_ctrl_cfg[1] = 0x00;
371 /* Select CABLE connector if supported by card */
372 if (state->config.pll_rf_set)
373 state->config.pll_rf_set(fe, 0);
375 if (state->config.demod_chip == LGDT3303) {
376 err = i2c_write_demod_bytes(state,
378 sizeof(lgdt3303_qam_data));
383 dprintk(state, "QAM_256 MODE\n");
385 /* Select QAM_256 mode */
386 top_ctrl_cfg[1] = 0x01;
388 /* Select CABLE connector if supported by card */
389 if (state->config.pll_rf_set)
390 state->config.pll_rf_set(fe, 0);
392 if (state->config.demod_chip == LGDT3303) {
393 err = i2c_write_demod_bytes(state,
395 sizeof(lgdt3303_qam_data));
399 dev_warn(&state->client->dev,
400 "%s: Modulation type(%d) UNSUPPORTED\n",
401 __func__, p->modulation);
405 dev_warn(&state->client->dev,
406 "%s: error blasting bytes to lgdt3303 for modulation type(%d)\n",
407 __func__, p->modulation);
410 * select serial or parallel MPEG hardware interface
411 * Serial: 0x04 for LGDT3302 or 0x40 for LGDT3303
414 top_ctrl_cfg[1] |= state->config.serial_mpeg;
416 /* Select the requested mode */
417 i2c_write_demod_bytes(state, top_ctrl_cfg,
418 sizeof(top_ctrl_cfg));
419 if (state->config.set_ts_params)
420 state->config.set_ts_params(fe, 0);
421 state->current_modulation = p->modulation;
424 /* Tune to the specified frequency */
425 if (fe->ops.tuner_ops.set_params) {
426 fe->ops.tuner_ops.set_params(fe);
427 if (fe->ops.i2c_gate_ctrl)
428 fe->ops.i2c_gate_ctrl(fe, 0);
431 /* Keep track of the new frequency */
433 * FIXME this is the wrong way to do this...
434 * The tuner is shared with the video4linux analog API
436 state->current_frequency = p->frequency;
438 lgdt330x_sw_reset(state);
442 static int lgdt330x_get_frontend(struct dvb_frontend *fe,
443 struct dtv_frontend_properties *p)
445 struct lgdt330x_state *state = fe->demodulator_priv;
447 p->frequency = state->current_frequency;
452 * Calculate SNR estimation (scaled by 2^24)
454 * 8-VSB SNR equations from LGDT3302 and LGDT3303 datasheets, QAM
455 * equations from LGDT3303 datasheet. VSB is the same between the '02
456 * and '03, so maybe QAM is too? Perhaps someone with a newer datasheet
457 * that has QAM information could verify?
459 * For 8-VSB: (two ways, take your pick)
461 * SNR_EQ = 10 * log10(25 * 24^2 / EQ_MSE)
463 * SNR_EQ = 10 * log10(25 * 32^2 / EQ_MSE)
464 * LGDT3302 & LGDT3303:
465 * SNR_PT = 10 * log10(25 * 32^2 / PT_MSE) (we use this one)
467 * SNR = 10 * log10( 688128 / MSEQAM)
469 * SNR = 10 * log10( 696320 / MSEQAM)
471 * We re-write the snr equation as:
472 * SNR * 2^24 = 10*(c - intlog10(MSE))
473 * Where for 256-QAM, c = log10(696320) * 2^24, and so on.
475 static u32 calculate_snr(u32 mse, u32 c)
477 if (mse == 0) /* No signal */
483 * Negative SNR, which is possible, but realisticly the
484 * demod will lose lock before the signal gets this bad.
485 * The API only allows for unsigned values, so just return 0
489 return 10 * (c - mse);
492 static int lgdt3302_read_snr(struct dvb_frontend *fe)
494 struct lgdt330x_state *state = fe->demodulator_priv;
495 u8 buf[5]; /* read data buffer */
496 u32 noise; /* noise value */
497 u32 c; /* per-modulation SNR calculation constant */
499 switch (state->current_modulation) {
501 i2c_read_demod_bytes(state, LGDT3302_EQPH_ERR0, buf, 5);
503 /* Use Equalizer Mean-Square Error Register */
504 /* SNR for ranges from -15.61 to +41.58 */
505 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
506 c = 69765745; /* log10(25*24^2)*2^24 */
508 /* Use Phase Tracker Mean-Square Error Register */
509 /* SNR for ranges from -13.11 to +44.08 */
510 noise = ((buf[0] & 7 << 3) << 13) | (buf[3] << 8) | buf[4];
511 c = 73957994; /* log10(25*32^2)*2^24 */
516 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
517 noise = ((buf[0] & 3) << 8) | buf[1];
518 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
519 /* log10(688128)*2^24 and log10(696320)*2^24 */
522 dev_err(&state->client->dev,
523 "%s: Modulation set to unsupported value\n",
528 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
531 state->snr = calculate_snr(noise, c);
533 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
534 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
539 static int lgdt3303_read_snr(struct dvb_frontend *fe)
541 struct lgdt330x_state *state = fe->demodulator_priv;
542 u8 buf[5]; /* read data buffer */
543 u32 noise; /* noise value */
544 u32 c; /* per-modulation SNR calculation constant */
546 switch (state->current_modulation) {
548 i2c_read_demod_bytes(state, LGDT3303_EQPH_ERR0, buf, 5);
550 /* Use Equalizer Mean-Square Error Register */
551 /* SNR for ranges from -16.12 to +44.08 */
552 noise = ((buf[0] & 0x78) << 13) | (buf[1] << 8) | buf[2];
553 c = 73957994; /* log10(25*32^2)*2^24 */
555 /* Use Phase Tracker Mean-Square Error Register */
556 /* SNR for ranges from -13.11 to +44.08 */
557 noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4];
558 c = 73957994; /* log10(25*32^2)*2^24 */
563 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
564 noise = (buf[0] << 8) | buf[1];
565 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
566 /* log10(688128)*2^24 and log10(696320)*2^24 */
569 dev_err(&state->client->dev,
570 "%s: Modulation set to unsupported value\n",
573 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
576 state->snr = calculate_snr(noise, c);
578 dprintk(state, "noise = 0x%08x, snr = %d.%02d dB\n", noise,
579 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
584 static int lgdt330x_read_snr(struct dvb_frontend *fe, u16 *snr)
586 struct lgdt330x_state *state = fe->demodulator_priv;
588 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */
593 static int lgdt330x_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
595 /* Calculate Strength from SNR up to 35dB */
597 * Even though the SNR can go higher than 35dB, there is some comfort
598 * factor in having a range of strong signals that can show at 100%
600 struct lgdt330x_state *state = fe->demodulator_priv;
604 ret = fe->ops.read_snr(fe, &snr);
607 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
608 /* scale the range 0 - 35*2^24 into 0 - 65535 */
609 if (state->snr >= 8960 * 0x10000)
612 *strength = state->snr / 8960;
618 static int lgdt3302_read_status(struct dvb_frontend *fe,
619 enum fe_status *status)
621 struct lgdt330x_state *state = fe->demodulator_priv;
622 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
626 *status = 0; /* Reset status result */
628 /* AGC status register */
629 i2c_read_demod_bytes(state, AGC_STATUS, buf, 1);
630 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
631 if ((buf[0] & 0x0c) == 0x8) {
633 * Test signal does not exist flag
634 * as well as the AGC lock flag.
636 *status |= FE_HAS_SIGNAL;
640 * You must set the Mask bits to 1 in the IRQ_MASK in order
641 * to see that status bit in the IRQ_STATUS register.
642 * This is done in SwReset();
646 i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf));
648 "TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n",
649 buf[0], buf[1], buf[2]);
652 if ((buf[2] & 0x03) == 0x01)
653 *status |= FE_HAS_SYNC;
655 /* FEC error status */
656 if ((buf[2] & 0x0c) == 0x08)
657 *status |= FE_HAS_LOCK | FE_HAS_VITERBI;
659 /* Carrier Recovery Lock Status Register */
660 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
661 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
662 switch (state->current_modulation) {
665 /* Need to understand why there are 3 lock levels here */
666 if ((buf[0] & 0x07) == 0x07)
667 *status |= FE_HAS_CARRIER;
670 if ((buf[0] & 0x80) == 0x80)
671 *status |= FE_HAS_CARRIER;
674 dev_warn(&state->client->dev,
675 "%s: Modulation set to unsupported value\n",
679 if (!(*status & FE_HAS_LOCK)) {
680 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
681 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
682 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
686 if (state->last_stats_time &&
687 time_is_after_jiffies(state->last_stats_time))
690 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
692 err = lgdt3302_read_snr(fe);
694 p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
695 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
697 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
700 err = i2c_read_demod_bytes(state, LGDT3302_PACKET_ERR_COUNTER1,
703 state->ucblocks = (buf[0] << 8) | buf[1];
705 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
707 p->block_error.stat[0].uvalue += state->ucblocks;
708 /* FIXME: what's the basis for block count */
709 p->block_count.stat[0].uvalue += 10000;
711 p->block_error.stat[0].scale = FE_SCALE_COUNTER;
712 p->block_count.stat[0].scale = FE_SCALE_COUNTER;
714 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
715 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
721 static int lgdt3303_read_status(struct dvb_frontend *fe,
722 enum fe_status *status)
724 struct lgdt330x_state *state = fe->demodulator_priv;
725 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
729 *status = 0; /* Reset status result */
731 /* lgdt3303 AGC status register */
732 err = i2c_read_demod_bytes(state, 0x58, buf, 1);
736 dprintk(state, "AGC_STATUS = 0x%02x\n", buf[0]);
737 if ((buf[0] & 0x21) == 0x01) {
739 * Test input signal does not exist flag
740 * as well as the AGC lock flag.
742 *status |= FE_HAS_SIGNAL;
745 /* Carrier Recovery Lock Status Register */
746 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
747 dprintk(state, "CARRIER_LOCK = 0x%02x\n", buf[0]);
748 switch (state->current_modulation) {
751 /* Need to understand why there are 3 lock levels here */
752 if ((buf[0] & 0x07) == 0x07)
753 *status |= FE_HAS_CARRIER;
756 i2c_read_demod_bytes(state, 0x8a, buf, 1);
757 dprintk(state, "QAM LOCK = 0x%02x\n", buf[0]);
759 if ((buf[0] & 0x04) == 0x04)
760 *status |= FE_HAS_SYNC;
761 if ((buf[0] & 0x01) == 0x01)
762 *status |= FE_HAS_LOCK;
763 if ((buf[0] & 0x08) == 0x08)
764 *status |= FE_HAS_VITERBI;
767 if ((buf[0] & 0x80) == 0x80)
768 *status |= FE_HAS_CARRIER;
771 i2c_read_demod_bytes(state, 0x38, buf, 1);
772 dprintk(state, "8-VSB LOCK = 0x%02x\n", buf[0]);
774 if ((buf[0] & 0x02) == 0x00)
775 *status |= FE_HAS_SYNC;
776 if ((buf[0] & 0x01) == 0x01)
777 *status |= FE_HAS_VITERBI | FE_HAS_LOCK;
780 dev_warn(&state->client->dev,
781 "%s: Modulation set to unsupported value\n",
785 if (!(*status & FE_HAS_LOCK)) {
786 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
787 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
788 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
792 if (state->last_stats_time &&
793 time_is_after_jiffies(state->last_stats_time))
796 state->last_stats_time = jiffies + msecs_to_jiffies(1000);
798 err = lgdt3303_read_snr(fe);
800 p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
801 p->cnr.stat[0].svalue = (((u64)state->snr) * 1000) >> 24;
803 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
806 err = i2c_read_demod_bytes(state, LGDT3303_PACKET_ERR_COUNTER1,
809 state->ucblocks = (buf[0] << 8) | buf[1];
811 dprintk(state, "UCB = 0x%02x\n", state->ucblocks);
813 p->block_error.stat[0].uvalue += state->ucblocks;
814 /* FIXME: what's the basis for block count */
815 p->block_count.stat[0].uvalue += 10000;
817 p->block_error.stat[0].scale = FE_SCALE_COUNTER;
818 p->block_count.stat[0].scale = FE_SCALE_COUNTER;
820 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
821 p->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
828 lgdt330x_get_tune_settings(struct dvb_frontend *fe,
829 struct dvb_frontend_tune_settings *fe_tune_settings)
831 /* I have no idea about this - it may not be needed */
832 fe_tune_settings->min_delay_ms = 500;
833 fe_tune_settings->step_size = 0;
834 fe_tune_settings->max_drift = 0;
838 static void lgdt330x_release(struct dvb_frontend *fe)
840 struct lgdt330x_state *state = fe->demodulator_priv;
841 struct i2c_client *client = state->client;
843 dev_dbg(&client->dev, "\n");
845 i2c_unregister_device(client);
848 static struct dvb_frontend *lgdt330x_get_dvb_frontend(struct i2c_client *client)
850 struct lgdt330x_state *state = i2c_get_clientdata(client);
852 dev_dbg(&client->dev, "\n");
854 return &state->frontend;
857 static const struct dvb_frontend_ops lgdt3302_ops;
858 static const struct dvb_frontend_ops lgdt3303_ops;
860 static int lgdt330x_probe(struct i2c_client *client)
862 struct lgdt330x_state *state = NULL;
865 /* Allocate memory for the internal state */
866 state = kzalloc(sizeof(*state), GFP_KERNEL);
870 /* Setup the state */
871 memcpy(&state->config, client->dev.platform_data,
872 sizeof(state->config));
873 i2c_set_clientdata(client, state);
874 state->client = client;
876 /* Create dvb_frontend */
877 switch (state->config.demod_chip) {
879 memcpy(&state->frontend.ops, &lgdt3302_ops,
880 sizeof(struct dvb_frontend_ops));
883 memcpy(&state->frontend.ops, &lgdt3303_ops,
884 sizeof(struct dvb_frontend_ops));
889 state->frontend.demodulator_priv = state;
891 /* Setup get frontend callback */
892 state->config.get_dvb_frontend = lgdt330x_get_dvb_frontend;
894 /* Verify communication with demod chip */
895 if (i2c_read_demod_bytes(state, 2, buf, 1))
898 state->current_frequency = -1;
899 state->current_modulation = -1;
901 dev_info(&state->client->dev,
902 "Demod loaded for LGDT330%s chip\n",
903 state->config.demod_chip == LGDT3302 ? "2" : "3");
910 dev_printk(KERN_DEBUG, &client->dev, "Error loading lgdt330x driver\n");
913 struct dvb_frontend *lgdt330x_attach(const struct lgdt330x_config *_config,
915 struct i2c_adapter *i2c)
917 struct i2c_client *client;
918 struct i2c_board_info board_info = {};
919 struct lgdt330x_config config = *_config;
921 strscpy(board_info.type, "lgdt330x", sizeof(board_info.type));
922 board_info.addr = demod_address;
923 board_info.platform_data = &config;
924 client = i2c_new_client_device(i2c, &board_info);
925 if (!i2c_client_has_driver(client))
928 return lgdt330x_get_dvb_frontend(client);
930 EXPORT_SYMBOL_GPL(lgdt330x_attach);
932 static const struct dvb_frontend_ops lgdt3302_ops = {
933 .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
935 .name = "LG Electronics LGDT3302 VSB/QAM Frontend",
936 .frequency_min_hz = 54 * MHz,
937 .frequency_max_hz = 858 * MHz,
938 .frequency_stepsize_hz = 62500,
939 .symbol_rate_min = 5056941, /* QAM 64 */
940 .symbol_rate_max = 10762000, /* VSB 8 */
941 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
943 .init = lgdt330x_init,
944 .set_frontend = lgdt330x_set_parameters,
945 .get_frontend = lgdt330x_get_frontend,
946 .get_tune_settings = lgdt330x_get_tune_settings,
947 .read_status = lgdt3302_read_status,
948 .read_signal_strength = lgdt330x_read_signal_strength,
949 .read_snr = lgdt330x_read_snr,
950 .read_ucblocks = lgdt330x_read_ucblocks,
951 .release = lgdt330x_release,
954 static const struct dvb_frontend_ops lgdt3303_ops = {
955 .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
957 .name = "LG Electronics LGDT3303 VSB/QAM Frontend",
958 .frequency_min_hz = 54 * MHz,
959 .frequency_max_hz = 858 * MHz,
960 .frequency_stepsize_hz = 62500,
961 .symbol_rate_min = 5056941, /* QAM 64 */
962 .symbol_rate_max = 10762000, /* VSB 8 */
963 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
965 .init = lgdt330x_init,
966 .set_frontend = lgdt330x_set_parameters,
967 .get_frontend = lgdt330x_get_frontend,
968 .get_tune_settings = lgdt330x_get_tune_settings,
969 .read_status = lgdt3303_read_status,
970 .read_signal_strength = lgdt330x_read_signal_strength,
971 .read_snr = lgdt330x_read_snr,
972 .read_ucblocks = lgdt330x_read_ucblocks,
973 .release = lgdt330x_release,
976 static void lgdt330x_remove(struct i2c_client *client)
978 struct lgdt330x_state *state = i2c_get_clientdata(client);
980 dev_dbg(&client->dev, "\n");
985 static const struct i2c_device_id lgdt330x_id_table[] = {
989 MODULE_DEVICE_TABLE(i2c, lgdt330x_id_table);
991 static struct i2c_driver lgdt330x_driver = {
994 .suppress_bind_attrs = true,
996 .probe = lgdt330x_probe,
997 .remove = lgdt330x_remove,
998 .id_table = lgdt330x_id_table,
1001 module_i2c_driver(lgdt330x_driver);
1004 MODULE_DESCRIPTION("LGDT330X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");
1005 MODULE_AUTHOR("Wilson Michaels");
1006 MODULE_LICENSE("GPL");