2 * Support for LGDT3305 - VSB/QAM
4 * Copyright (C) 2008, 2009 Michael Krufky <mkrufky@linuxtv.org>
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/dvb/frontend.h>
27 module_param(debug, int, 0644);
28 MODULE_PARM_DESC(debug, "set debug level (info=1, reg=2 (or-able))");
33 #define lg_printk(kern, fmt, arg...) \
34 printk(kern "%s: " fmt, __func__, ##arg)
36 #define lg_info(fmt, arg...) printk(KERN_INFO "lgdt3305: " fmt, ##arg)
37 #define lg_warn(fmt, arg...) lg_printk(KERN_WARNING, fmt, ##arg)
38 #define lg_err(fmt, arg...) lg_printk(KERN_ERR, fmt, ##arg)
39 #define lg_dbg(fmt, arg...) if (debug & DBG_INFO) \
40 lg_printk(KERN_DEBUG, fmt, ##arg)
41 #define lg_reg(fmt, arg...) if (debug & DBG_REG) \
42 lg_printk(KERN_DEBUG, fmt, ##arg)
44 #define lg_fail(ret) \
49 lg_err("error %d on line %d\n", ret, __LINE__); \
53 struct lgdt3305_state {
54 struct i2c_adapter *i2c_adap;
55 const struct lgdt3305_config *cfg;
57 struct dvb_frontend frontend;
59 fe_modulation_t current_modulation;
60 u32 current_frequency;
64 /* ------------------------------------------------------------------------ */
66 #define LGDT3305_GEN_CTRL_1 0x0000
67 #define LGDT3305_GEN_CTRL_2 0x0001
68 #define LGDT3305_GEN_CTRL_3 0x0002
69 #define LGDT3305_GEN_STATUS 0x0003
70 #define LGDT3305_GEN_CONTROL 0x0007
71 #define LGDT3305_GEN_CTRL_4 0x000a
72 #define LGDT3305_DGTL_AGC_REF_1 0x0012
73 #define LGDT3305_DGTL_AGC_REF_2 0x0013
74 #define LGDT3305_CR_CTR_FREQ_1 0x0106
75 #define LGDT3305_CR_CTR_FREQ_2 0x0107
76 #define LGDT3305_CR_CTR_FREQ_3 0x0108
77 #define LGDT3305_CR_CTR_FREQ_4 0x0109
78 #define LGDT3305_CR_MSE_1 0x011b
79 #define LGDT3305_CR_MSE_2 0x011c
80 #define LGDT3305_CR_LOCK_STATUS 0x011d
81 #define LGDT3305_CR_CTRL_7 0x0126
82 #define LGDT3305_AGC_POWER_REF_1 0x0300
83 #define LGDT3305_AGC_POWER_REF_2 0x0301
84 #define LGDT3305_AGC_DELAY_PT_1 0x0302
85 #define LGDT3305_AGC_DELAY_PT_2 0x0303
86 #define LGDT3305_RFAGC_LOOP_FLTR_BW_1 0x0306
87 #define LGDT3305_RFAGC_LOOP_FLTR_BW_2 0x0307
88 #define LGDT3305_IFBW_1 0x0308
89 #define LGDT3305_IFBW_2 0x0309
90 #define LGDT3305_AGC_CTRL_1 0x030c
91 #define LGDT3305_AGC_CTRL_4 0x0314
92 #define LGDT3305_EQ_MSE_1 0x0413
93 #define LGDT3305_EQ_MSE_2 0x0414
94 #define LGDT3305_EQ_MSE_3 0x0415
95 #define LGDT3305_PT_MSE_1 0x0417
96 #define LGDT3305_PT_MSE_2 0x0418
97 #define LGDT3305_PT_MSE_3 0x0419
98 #define LGDT3305_FEC_BLOCK_CTRL 0x0504
99 #define LGDT3305_FEC_LOCK_STATUS 0x050a
100 #define LGDT3305_FEC_PKT_ERR_1 0x050c
101 #define LGDT3305_FEC_PKT_ERR_2 0x050d
102 #define LGDT3305_TP_CTRL_1 0x050e
103 #define LGDT3305_BERT_PERIOD 0x0801
104 #define LGDT3305_BERT_ERROR_COUNT_1 0x080a
105 #define LGDT3305_BERT_ERROR_COUNT_2 0x080b
106 #define LGDT3305_BERT_ERROR_COUNT_3 0x080c
107 #define LGDT3305_BERT_ERROR_COUNT_4 0x080d
109 static int lgdt3305_write_reg(struct lgdt3305_state *state, u16 reg, u8 val)
112 u8 buf[] = { reg >> 8, reg & 0xff, val };
113 struct i2c_msg msg = {
114 .addr = state->cfg->i2c_addr, .flags = 0,
115 .buf = buf, .len = 3,
118 lg_reg("reg: 0x%04x, val: 0x%02x\n", reg, val);
120 ret = i2c_transfer(state->i2c_adap, &msg, 1);
123 lg_err("error (addr %02x %02x <- %02x, err = %i)\n",
124 msg.buf[0], msg.buf[1], msg.buf[2], ret);
133 static int lgdt3305_read_reg(struct lgdt3305_state *state, u16 reg, u8 *val)
136 u8 reg_buf[] = { reg >> 8, reg & 0xff };
137 struct i2c_msg msg[] = {
138 { .addr = state->cfg->i2c_addr,
139 .flags = 0, .buf = reg_buf, .len = 2 },
140 { .addr = state->cfg->i2c_addr,
141 .flags = I2C_M_RD, .buf = val, .len = 1 },
144 lg_reg("reg: 0x%04x\n", reg);
146 ret = i2c_transfer(state->i2c_adap, msg, 2);
149 lg_err("error (addr %02x reg %04x error (ret == %i)\n",
150 state->cfg->i2c_addr, reg, ret);
159 #define read_reg(state, reg) \
162 int ret = lgdt3305_read_reg(state, reg, &__val); \
168 static int lgdt3305_set_reg_bit(struct lgdt3305_state *state,
169 u16 reg, int bit, int onoff)
174 lg_reg("reg: 0x%04x, bit: %d, level: %d\n", reg, bit, onoff);
176 ret = lgdt3305_read_reg(state, reg, &val);
181 val |= (onoff & 1) << bit;
183 ret = lgdt3305_write_reg(state, reg, val);
188 struct lgdt3305_reg {
193 static int lgdt3305_write_regs(struct lgdt3305_state *state,
194 struct lgdt3305_reg *regs, int len)
198 lg_reg("writing %d registers...\n", len);
200 for (i = 0; i < len - 1; i++) {
201 ret = lgdt3305_write_reg(state, regs[i].reg, regs[i].val);
208 /* ------------------------------------------------------------------------ */
210 static int lgdt3305_soft_reset(struct lgdt3305_state *state)
216 ret = lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_3, 0, 0);
221 ret = lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_3, 0, 1);
226 static inline int lgdt3305_mpeg_mode(struct lgdt3305_state *state,
227 enum lgdt3305_mpeg_mode mode)
229 lg_dbg("(%d)\n", mode);
230 return lgdt3305_set_reg_bit(state, LGDT3305_TP_CTRL_1, 5, mode);
233 static int lgdt3305_mpeg_mode_polarity(struct lgdt3305_state *state,
234 enum lgdt3305_tp_clock_edge edge,
235 enum lgdt3305_tp_valid_polarity valid)
240 lg_dbg("edge = %d, valid = %d\n", edge, valid);
242 ret = lgdt3305_read_reg(state, LGDT3305_TP_CTRL_1, &val);
253 ret = lgdt3305_write_reg(state, LGDT3305_TP_CTRL_1, val);
257 ret = lgdt3305_soft_reset(state);
262 static int lgdt3305_set_modulation(struct lgdt3305_state *state,
263 struct dvb_frontend_parameters *param)
270 ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_1, &opermode);
276 switch (param->u.vsb.modulation) {
289 ret = lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_1, opermode);
294 static int lgdt3305_set_filter_extension(struct lgdt3305_state *state,
295 struct dvb_frontend_parameters *param)
299 switch (param->u.vsb.modulation) {
310 lg_dbg("val = %d\n", val);
312 return lgdt3305_set_reg_bit(state, 0x043f, 2, val);
315 /* ------------------------------------------------------------------------ */
317 static int lgdt3305_passband_digital_agc(struct lgdt3305_state *state,
318 struct dvb_frontend_parameters *param)
322 switch (param->u.vsb.modulation) {
336 lg_dbg("agc ref: 0x%04x\n", agc_ref);
338 lgdt3305_write_reg(state, LGDT3305_DGTL_AGC_REF_1, agc_ref >> 8);
339 lgdt3305_write_reg(state, LGDT3305_DGTL_AGC_REF_2, agc_ref & 0xff);
344 static int lgdt3305_rfagc_loop(struct lgdt3305_state *state,
345 struct dvb_frontend_parameters *param)
347 u16 ifbw, rfbw, agcdelay;
349 switch (param->u.vsb.modulation) {
365 if (state->cfg->rf_agc_loop) {
366 lg_dbg("agcdelay: 0x%04x, rfbw: 0x%04x\n", agcdelay, rfbw);
368 /* rf agc loop filter bandwidth */
369 lgdt3305_write_reg(state, LGDT3305_AGC_DELAY_PT_1,
371 lgdt3305_write_reg(state, LGDT3305_AGC_DELAY_PT_2,
374 lgdt3305_write_reg(state, LGDT3305_RFAGC_LOOP_FLTR_BW_1,
376 lgdt3305_write_reg(state, LGDT3305_RFAGC_LOOP_FLTR_BW_2,
379 lg_dbg("ifbw: 0x%04x\n", ifbw);
381 /* if agc loop filter bandwidth */
382 lgdt3305_write_reg(state, LGDT3305_IFBW_1, ifbw >> 8);
383 lgdt3305_write_reg(state, LGDT3305_IFBW_2, ifbw & 0xff);
389 static int lgdt3305_agc_setup(struct lgdt3305_state *state,
390 struct dvb_frontend_parameters *param)
394 switch (param->u.vsb.modulation) {
408 lg_dbg("lockdten = %d, acqen = %d\n", lockdten, acqen);
410 /* control agc function */
411 lgdt3305_write_reg(state, LGDT3305_AGC_CTRL_4, 0xe1 | lockdten << 1);
412 lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 2, acqen);
414 return lgdt3305_rfagc_loop(state, param);
417 static int lgdt3305_set_agc_power_ref(struct lgdt3305_state *state,
418 struct dvb_frontend_parameters *param)
422 switch (param->u.vsb.modulation) {
424 if (state->cfg->usref_8vsb)
425 usref = state->cfg->usref_8vsb;
428 if (state->cfg->usref_qam64)
429 usref = state->cfg->usref_qam64;
432 if (state->cfg->usref_qam256)
433 usref = state->cfg->usref_qam256;
440 lg_dbg("set manual mode: 0x%04x\n", usref);
442 lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 3, 1);
444 lgdt3305_write_reg(state, LGDT3305_AGC_POWER_REF_1,
445 0xff & (usref >> 8));
446 lgdt3305_write_reg(state, LGDT3305_AGC_POWER_REF_2,
447 0xff & (usref >> 0));
452 /* ------------------------------------------------------------------------ */
454 static int lgdt3305_spectral_inversion(struct lgdt3305_state *state,
455 struct dvb_frontend_parameters *param,
460 lg_dbg("(%d)\n", inversion);
462 switch (param->u.vsb.modulation) {
464 ret = lgdt3305_write_reg(state, LGDT3305_CR_CTRL_7,
465 inversion ? 0xf9 : 0x79);
469 ret = lgdt3305_write_reg(state, LGDT3305_FEC_BLOCK_CTRL,
470 inversion ? 0xfd : 0xff);
478 static int lgdt3305_set_if(struct lgdt3305_state *state,
479 struct dvb_frontend_parameters *param)
482 u8 nco1, nco2, nco3, nco4;
485 switch (param->u.vsb.modulation) {
487 if_freq_khz = state->cfg->vsb_if_khz;
491 if_freq_khz = state->cfg->qam_if_khz;
497 nco = if_freq_khz / 10;
499 #define LGDT3305_64BIT_DIVISION_ENABLED 0
500 /* FIXME: 64bit division disabled to avoid linking error:
501 * WARNING: "__udivdi3" [lgdt3305.ko] undefined!
503 switch (param->u.vsb.modulation) {
505 #if LGDT3305_64BIT_DIVISION_ENABLED
509 nco *= ((1 << 24) / 625);
514 #if LGDT3305_64BIT_DIVISION_ENABLED
518 nco *= ((1 << 28) / 625);
525 nco1 = (nco >> 24) & 0x3f;
527 nco2 = (nco >> 16) & 0xff;
528 nco3 = (nco >> 8) & 0xff;
531 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_1, nco1);
532 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_2, nco2);
533 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_3, nco3);
534 lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_4, nco4);
536 lg_dbg("%d KHz -> [%02x%02x%02x%02x]\n",
537 if_freq_khz, nco1, nco2, nco3, nco4);
542 /* ------------------------------------------------------------------------ */
544 static int lgdt3305_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
546 struct lgdt3305_state *state = fe->demodulator_priv;
548 if (state->cfg->deny_i2c_rptr)
551 lg_dbg("(%d)\n", enable);
553 return lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_2, 5,
557 static int lgdt3305_sleep(struct dvb_frontend *fe)
559 struct lgdt3305_state *state = fe->demodulator_priv;
560 u8 gen_ctrl_3, gen_ctrl_4;
564 gen_ctrl_3 = read_reg(state, LGDT3305_GEN_CTRL_3);
565 gen_ctrl_4 = read_reg(state, LGDT3305_GEN_CTRL_4);
567 /* hold in software reset while sleeping */
569 /* tristate the IF-AGC pin */
571 /* tristate the RF-AGC pin */
574 /* disable vsb/qam module */
576 /* disable adc module */
579 lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_3, gen_ctrl_3);
580 lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_4, gen_ctrl_4);
585 static int lgdt3305_init(struct dvb_frontend *fe)
587 struct lgdt3305_state *state = fe->demodulator_priv;
590 static struct lgdt3305_reg lgdt3305_init_data[] = {
591 { .reg = LGDT3305_GEN_CTRL_1,
593 { .reg = LGDT3305_GEN_CTRL_2,
595 { .reg = LGDT3305_GEN_CTRL_3,
597 { .reg = LGDT3305_GEN_CONTROL,
599 { .reg = LGDT3305_GEN_CTRL_4,
601 { .reg = LGDT3305_DGTL_AGC_REF_1,
603 { .reg = LGDT3305_DGTL_AGC_REF_2,
605 { .reg = LGDT3305_CR_CTR_FREQ_1,
607 { .reg = LGDT3305_CR_CTR_FREQ_2,
609 { .reg = LGDT3305_CR_CTR_FREQ_3,
611 { .reg = LGDT3305_CR_CTR_FREQ_4,
613 { .reg = LGDT3305_CR_CTRL_7,
615 { .reg = LGDT3305_AGC_POWER_REF_1,
617 { .reg = LGDT3305_AGC_POWER_REF_2,
619 { .reg = LGDT3305_AGC_DELAY_PT_1,
621 { .reg = LGDT3305_AGC_DELAY_PT_2,
623 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_1,
625 { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_2,
627 { .reg = LGDT3305_IFBW_1,
629 { .reg = LGDT3305_IFBW_2,
631 { .reg = LGDT3305_AGC_CTRL_1,
633 { .reg = LGDT3305_AGC_CTRL_4,
635 { .reg = LGDT3305_FEC_BLOCK_CTRL,
637 { .reg = LGDT3305_TP_CTRL_1,
643 ret = lgdt3305_write_regs(state, lgdt3305_init_data,
644 ARRAY_SIZE(lgdt3305_init_data));
648 ret = lgdt3305_soft_reset(state);
653 static int lgdt3305_set_parameters(struct dvb_frontend *fe,
654 struct dvb_frontend_parameters *param)
656 struct lgdt3305_state *state = fe->demodulator_priv;
659 lg_dbg("(%d, %d)\n", param->frequency, param->u.vsb.modulation);
661 if (fe->ops.tuner_ops.set_params) {
662 ret = fe->ops.tuner_ops.set_params(fe, param);
663 if (fe->ops.i2c_gate_ctrl)
664 fe->ops.i2c_gate_ctrl(fe, 0);
667 state->current_frequency = param->frequency;
670 ret = lgdt3305_set_modulation(state, param);
674 ret = lgdt3305_passband_digital_agc(state, param);
677 ret = lgdt3305_set_agc_power_ref(state, param);
680 ret = lgdt3305_agc_setup(state, param);
685 ret = lgdt3305_write_reg(state, LGDT3305_GEN_CONTROL, 0x2f);
688 ret = lgdt3305_set_reg_bit(state, LGDT3305_CR_CTR_FREQ_1, 6, 1);
692 ret = lgdt3305_set_if(state, param);
695 ret = lgdt3305_spectral_inversion(state, param,
696 state->cfg->spectral_inversion
701 ret = lgdt3305_set_filter_extension(state, param);
705 state->current_modulation = param->u.vsb.modulation;
707 ret = lgdt3305_mpeg_mode(state, state->cfg->mpeg_mode);
711 /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */
712 ret = lgdt3305_mpeg_mode_polarity(state,
713 state->cfg->tpclk_edge,
714 state->cfg->tpvalid_polarity);
719 static int lgdt3305_get_frontend(struct dvb_frontend *fe,
720 struct dvb_frontend_parameters *param)
722 struct lgdt3305_state *state = fe->demodulator_priv;
726 param->u.vsb.modulation = state->current_modulation;
727 param->frequency = state->current_frequency;
731 /* ------------------------------------------------------------------------ */
733 static int lgdt3305_read_cr_lock_status(struct lgdt3305_state *state,
738 char *cr_lock_state = "";
742 ret = lgdt3305_read_reg(state, LGDT3305_CR_LOCK_STATUS, &val);
746 switch (state->current_modulation) {
752 switch (val & 0x07) {
754 cr_lock_state = "QAM UNLOCK";
757 cr_lock_state = "QAM 1stLock";
760 cr_lock_state = "QAM 2ndLock";
763 cr_lock_state = "QAM FinalLock";
766 cr_lock_state = "CLOCKQAM-INVALID!";
771 if (val & (1 << 7)) {
773 cr_lock_state = "CLOCKVSB";
779 lg_dbg("(%d) %s\n", *locked, cr_lock_state);
784 static int lgdt3305_read_fec_lock_status(struct lgdt3305_state *state,
788 int ret, mpeg_lock, fec_lock, viterbi_lock;
792 switch (state->current_modulation) {
795 ret = lgdt3305_read_reg(state,
796 LGDT3305_FEC_LOCK_STATUS, &val);
800 mpeg_lock = (val & (1 << 0)) ? 1 : 0;
801 fec_lock = (val & (1 << 2)) ? 1 : 0;
802 viterbi_lock = (val & (1 << 3)) ? 1 : 0;
804 *locked = mpeg_lock && fec_lock && viterbi_lock;
806 lg_dbg("(%d) %s%s%s\n", *locked,
807 mpeg_lock ? "mpeg lock " : "",
808 fec_lock ? "fec lock " : "",
809 viterbi_lock ? "viterbi lock" : "");
819 static int lgdt3305_read_status(struct dvb_frontend *fe, fe_status_t *status)
821 struct lgdt3305_state *state = fe->demodulator_priv;
823 int ret, signal, inlock, nofecerr, snrgood,
824 cr_lock, fec_lock, sync_lock;
828 ret = lgdt3305_read_reg(state, LGDT3305_GEN_STATUS, &val);
832 signal = (val & (1 << 4)) ? 1 : 0;
833 inlock = (val & (1 << 3)) ? 0 : 1;
834 sync_lock = (val & (1 << 2)) ? 1 : 0;
835 nofecerr = (val & (1 << 1)) ? 1 : 0;
836 snrgood = (val & (1 << 0)) ? 1 : 0;
838 lg_dbg("%s%s%s%s%s\n",
839 signal ? "SIGNALEXIST " : "",
840 inlock ? "INLOCK " : "",
841 sync_lock ? "SYNCLOCK " : "",
842 nofecerr ? "NOFECERR " : "",
843 snrgood ? "SNRGOOD " : "");
845 ret = lgdt3305_read_cr_lock_status(state, &cr_lock);
850 *status |= FE_HAS_SIGNAL;
852 *status |= FE_HAS_CARRIER;
854 *status |= FE_HAS_VITERBI;
856 *status |= FE_HAS_SYNC;
858 switch (state->current_modulation) {
861 ret = lgdt3305_read_fec_lock_status(state, &fec_lock);
866 *status |= FE_HAS_LOCK;
870 *status |= FE_HAS_LOCK;
879 /* ------------------------------------------------------------------------ */
881 /* borrowed from lgdt330x.c */
882 static u32 calculate_snr(u32 mse, u32 c)
884 if (mse == 0) /* no signal */
889 /* Negative SNR, which is possible, but realisticly the
890 demod will lose lock before the signal gets this bad. The
891 API only allows for unsigned values, so just return 0 */
897 static int lgdt3305_read_snr(struct dvb_frontend *fe, u16 *snr)
899 struct lgdt3305_state *state = fe->demodulator_priv;
900 u32 noise; /* noise value */
901 u32 c; /* per-modulation SNR calculation constant */
903 switch (state->current_modulation) {
906 /* Use Phase Tracker Mean-Square Error Register */
907 /* SNR for ranges from -13.11 to +44.08 */
908 noise = ((read_reg(state, LGDT3305_PT_MSE_1) & 0x07) << 16) |
909 (read_reg(state, LGDT3305_PT_MSE_2) << 8) |
910 (read_reg(state, LGDT3305_PT_MSE_3) & 0xff);
911 c = 73957994; /* log10(25*32^2)*2^24 */
913 /* Use Equalizer Mean-Square Error Register */
914 /* SNR for ranges from -16.12 to +44.08 */
915 noise = ((read_reg(state, LGDT3305_EQ_MSE_1) & 0x0f) << 16) |
916 (read_reg(state, LGDT3305_EQ_MSE_2) << 8) |
917 (read_reg(state, LGDT3305_EQ_MSE_3) & 0xff);
918 c = 73957994; /* log10(25*32^2)*2^24 */
923 noise = (read_reg(state, LGDT3305_CR_MSE_1) << 8) |
924 (read_reg(state, LGDT3305_CR_MSE_2) & 0xff);
926 c = (state->current_modulation == QAM_64) ?
928 /* log10(688128)*2^24 and log10(696320)*2^24 */
933 state->snr = calculate_snr(noise, c);
934 /* report SNR in dB * 10 */
935 *snr = (state->snr / ((1 << 24) / 10));
936 lg_dbg("noise = 0x%08x, snr = %d.%02d dB\n", noise,
937 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
942 static int lgdt3305_read_signal_strength(struct dvb_frontend *fe,
945 /* borrowed from lgdt330x.c
947 * Calculate strength from SNR up to 35dB
948 * Even though the SNR can go higher than 35dB,
949 * there is some comfort factor in having a range of
950 * strong signals that can show at 100%
952 struct lgdt3305_state *state = fe->demodulator_priv;
958 ret = fe->ops.read_snr(fe, &snr);
961 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
962 /* scale the range 0 - 35*2^24 into 0 - 65535 */
963 if (state->snr >= 8960 * 0x10000)
966 *strength = state->snr / 8960;
971 /* ------------------------------------------------------------------------ */
973 static int lgdt3305_read_ber(struct dvb_frontend *fe, u32 *ber)
979 static int lgdt3305_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
981 struct lgdt3305_state *state = fe->demodulator_priv;
984 (read_reg(state, LGDT3305_FEC_PKT_ERR_1) << 8) |
985 (read_reg(state, LGDT3305_FEC_PKT_ERR_2) & 0xff);
990 static int lgdt3305_get_tune_settings(struct dvb_frontend *fe,
991 struct dvb_frontend_tune_settings
994 fe_tune_settings->min_delay_ms = 500;
999 static void lgdt3305_release(struct dvb_frontend *fe)
1001 struct lgdt3305_state *state = fe->demodulator_priv;
1006 static struct dvb_frontend_ops lgdt3305_ops;
1008 struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config,
1009 struct i2c_adapter *i2c_adap)
1011 struct lgdt3305_state *state = NULL;
1015 lg_dbg("(%d-%04x)\n",
1016 i2c_adap ? i2c_adapter_id(i2c_adap) : 0,
1017 config ? config->i2c_addr : 0);
1019 state = kzalloc(sizeof(struct lgdt3305_state), GFP_KERNEL);
1023 state->cfg = config;
1024 state->i2c_adap = i2c_adap;
1026 memcpy(&state->frontend.ops, &lgdt3305_ops,
1027 sizeof(struct dvb_frontend_ops));
1028 state->frontend.demodulator_priv = state;
1030 /* verify that we're talking to a lg dt3305 */
1031 ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_2, &val);
1032 if ((lg_fail(ret)) | (val == 0))
1034 ret = lgdt3305_write_reg(state, 0x0808, 0x80);
1037 ret = lgdt3305_read_reg(state, 0x0808, &val);
1038 if ((lg_fail(ret)) | (val != 0x80))
1040 ret = lgdt3305_write_reg(state, 0x0808, 0x00);
1044 state->current_frequency = -1;
1045 state->current_modulation = -1;
1047 return &state->frontend;
1049 lg_warn("unable to detect LGDT3305 hardware\n");
1053 EXPORT_SYMBOL(lgdt3305_attach);
1055 static struct dvb_frontend_ops lgdt3305_ops = {
1057 .name = "LG Electronics LGDT3305 VSB/QAM Frontend",
1059 .frequency_min = 54000000,
1060 .frequency_max = 858000000,
1061 .frequency_stepsize = 62500,
1062 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
1064 .i2c_gate_ctrl = lgdt3305_i2c_gate_ctrl,
1065 .init = lgdt3305_init,
1066 .sleep = lgdt3305_sleep,
1067 .set_frontend = lgdt3305_set_parameters,
1068 .get_frontend = lgdt3305_get_frontend,
1069 .get_tune_settings = lgdt3305_get_tune_settings,
1070 .read_status = lgdt3305_read_status,
1071 .read_ber = lgdt3305_read_ber,
1072 .read_signal_strength = lgdt3305_read_signal_strength,
1073 .read_snr = lgdt3305_read_snr,
1074 .read_ucblocks = lgdt3305_read_ucblocks,
1075 .release = lgdt3305_release,
1078 MODULE_DESCRIPTION("LG Electronics LGDT3305 ATSC/QAM-B Demodulator Driver");
1079 MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1080 MODULE_LICENSE("GPL");
1081 MODULE_VERSION("0.1");