36 #include <linux/kernel.h>
37 #include <linux/module.h>
40 #include <linux/string.h>
41 #include <linux/slab.h>
42 #include <asm/byteorder.h>
55 #define dprintk(args...) \
57 if (debug) printk(KERN_DEBUG "lgdt330x: " args); \
89 for (i=0; i<len-1; i+=2){
113 .flags = 0, .buf =
wr, .len = 1 },
114 { .addr = state->
config->demod_address,
120 printk(
KERN_WARNING "lgdt330x: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __func__, state->
config->demod_address, reg, ret);
139 ret = i2c_write_demod_bytes(state,
140 reset,
sizeof(reset));
145 ret = i2c_write_demod_bytes(state,
146 reset,
sizeof(reset));
159 ret = i2c_write_demod_bytes(state,
160 reset,
sizeof(reset));
165 ret = i2c_write_demod_bytes(state,
166 reset,
sizeof(reset));
173 switch (state->
config->demod_chip) {
175 return lgdt3302_SwReset(state);
177 return lgdt3303_SwReset(state);
195 static u8 lgdt3302_init_data[] = {
227 static u8 lgdt3303_init_data[] = {
231 static u8 flip_1_lgdt3303_init_data[] = {
236 static u8 flip_2_lgdt3303_init_data[] = {
245 switch (state->
config->demod_chip) {
247 chip_name =
"LGDT3302";
248 err = i2c_write_demod_bytes(state, lgdt3302_init_data,
249 sizeof(lgdt3302_init_data));
252 chip_name =
"LGDT3303";
253 switch (state->
config->clock_polarity_flip) {
255 err = i2c_write_demod_bytes(state,
256 flip_2_lgdt3303_init_data,
257 sizeof(flip_2_lgdt3303_init_data));
260 err = i2c_write_demod_bytes(state,
261 flip_1_lgdt3303_init_data,
262 sizeof(flip_1_lgdt3303_init_data));
266 err = i2c_write_demod_bytes(state, lgdt3303_init_data,
267 sizeof(lgdt3303_init_data));
271 chip_name =
"undefined";
275 dprintk(
"%s entered as %s\n", __func__, chip_name);
278 return lgdt330x_SwReset(state);
287 static int lgdt330x_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
295 switch (state->
config->demod_chip) {
306 "Only LGDT3302 and LGDT3303 are supported chips.\n");
312 *ucblocks = (buf[0] << 8) | buf[1];
316 static int lgdt330x_set_parameters(
struct dvb_frontend *fe)
323 static u8 lgdt3303_8vsb_44_data[] = {
335 static u8 lgdt3303_qam_data[] = {
357 dprintk(
"%s: VSB_8 MODE\n", __func__);
360 top_ctrl_cfg[1] = 0x03;
363 if (state->
config->pll_rf_set)
364 state->
config->pll_rf_set(fe, 1);
367 err = i2c_write_demod_bytes(state, lgdt3303_8vsb_44_data,
368 sizeof(lgdt3303_8vsb_44_data));
373 dprintk(
"%s: QAM_64 MODE\n", __func__);
376 top_ctrl_cfg[1] = 0x00;
379 if (state->
config->pll_rf_set)
380 state->
config->pll_rf_set(fe, 0);
383 err = i2c_write_demod_bytes(state, lgdt3303_qam_data,
384 sizeof(lgdt3303_qam_data));
389 dprintk(
"%s: QAM_256 MODE\n", __func__);
392 top_ctrl_cfg[1] = 0x01;
395 if (state->
config->pll_rf_set)
396 state->
config->pll_rf_set(fe, 0);
399 err = i2c_write_demod_bytes(state, lgdt3303_qam_data,
400 sizeof(lgdt3303_qam_data));
409 "bytes to lgdt3303 for modulation type(%d)\n",
417 top_ctrl_cfg[1] |= state->
config->serial_mpeg;
420 i2c_write_demod_bytes(state, top_ctrl_cfg,
421 sizeof(top_ctrl_cfg));
422 if (state->
config->set_ts_params)
423 state->
config->set_ts_params(fe, 0);
428 if (fe->
ops.tuner_ops.set_params) {
429 fe->
ops.tuner_ops.set_params(fe);
430 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
438 lgdt330x_SwReset(state);
442 static int lgdt330x_get_frontend(
struct dvb_frontend *fe)
458 i2c_read_demod_bytes(state,
AGC_STATUS, buf, 1);
459 dprintk(
"%s: AGC_STATUS = 0x%02x\n", __func__, buf[0]);
460 if ((buf[0] & 0x0c) == 0x8){
472 i2c_read_demod_bytes(state,
TOP_CONTROL, buf,
sizeof(buf));
473 dprintk(
"%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __func__, buf[0], buf[1], buf[2]);
477 if ((buf[2] & 0x03) == 0x01) {
482 if ((buf[2] & 0x0c) == 0x08) {
489 dprintk(
"%s: CARRIER_LOCK = 0x%02x\n", __func__, buf[0]);
494 if ((buf[0] & 0x07) == 0x07)
498 if ((buf[0] & 0x80) == 0x80)
517 err = i2c_read_demod_bytes(state, 0x58, buf, 1);
521 dprintk(
"%s: AGC_STATUS = 0x%02x\n", __func__, buf[0]);
522 if ((buf[0] & 0x21) == 0x01){
530 dprintk(
"%s: CARRIER_LOCK = 0x%02x\n", __func__, buf[0]);
535 if ((buf[0] & 0x07) == 0x07)
539 i2c_read_demod_bytes(state, 0x8a, buf, 1);
540 if ((buf[0] & 0x04) == 0x04)
542 if ((buf[0] & 0x01) == 0x01)
544 if ((buf[0] & 0x08) == 0x08)
548 if ((buf[0] & 0x80) == 0x80)
552 i2c_read_demod_bytes(state, 0x38, buf, 1);
553 if ((buf[0] & 0x02) == 0x00)
555 if ((buf[0] & 0x01) == 0x01) {
617 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
622 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
629 noise = ((buf[0] & 3) << 8) | buf[1];
634 printk(
KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n",
639 state->
snr = calculate_snr(noise, c);
640 *snr = (state->
snr) >> 16;
642 dprintk(
"%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise,
643 state->
snr >> 24, (((state->
snr>>8) & 0xffff) * 100) >> 16);
661 noise = ((buf[0] & 0x78) << 13) | (buf[1] << 8) | buf[2];
666 noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4];
673 noise = (buf[0] << 8) | buf[1];
678 printk(
KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n",
683 state->
snr = calculate_snr(noise, c);
684 *snr = (state->
snr) >> 16;
686 dprintk(
"%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise,
687 state->
snr >> 24, (((state->
snr >> 8) & 0xffff) * 100) >> 16);
692 static int lgdt330x_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
701 ret = fe->
ops.read_snr(fe, &
snr);
706 if (state->
snr >= 8960 * 0x10000)
709 *strength = state->
snr / 8960;
761 if (i2c_read_demod_bytes(state, 2, buf, 1))
771 dprintk(
"%s: ERROR\n",__func__);
778 .name=
"LG Electronics LGDT3302 VSB/QAM Frontend",
779 .frequency_min= 54000000,
780 .frequency_max= 858000000,
781 .frequency_stepsize= 62500,
782 .symbol_rate_min = 5056941,
783 .symbol_rate_max = 10762000,
786 .init = lgdt330x_init,
787 .set_frontend = lgdt330x_set_parameters,
788 .get_frontend = lgdt330x_get_frontend,
789 .get_tune_settings = lgdt330x_get_tune_settings,
790 .read_status = lgdt3302_read_status,
791 .read_ber = lgdt330x_read_ber,
792 .read_signal_strength = lgdt330x_read_signal_strength,
793 .read_snr = lgdt3302_read_snr,
794 .read_ucblocks = lgdt330x_read_ucblocks,
795 .release = lgdt330x_release,
801 .name=
"LG Electronics LGDT3303 VSB/QAM Frontend",
802 .frequency_min= 54000000,
803 .frequency_max= 858000000,
804 .frequency_stepsize= 62500,
805 .symbol_rate_min = 5056941,
806 .symbol_rate_max = 10762000,
809 .init = lgdt330x_init,
810 .set_frontend = lgdt330x_set_parameters,
811 .get_frontend = lgdt330x_get_frontend,
812 .get_tune_settings = lgdt330x_get_tune_settings,
813 .read_status = lgdt3303_read_status,
814 .read_ber = lgdt330x_read_ber,
815 .read_signal_strength = lgdt330x_read_signal_strength,
816 .read_snr = lgdt3303_read_snr,
817 .read_ucblocks = lgdt330x_read_ucblocks,
818 .release = lgdt330x_release,
821 MODULE_DESCRIPTION(
"LGDT330X (ATSC 8VSB & ITU-T J.83 AnnexB 64/256 QAM) Demodulator Driver");