28 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/string.h>
32 #include <linux/slab.h>
54 #define dprintk if (debug) printk
57 static const u8 init_tab[] = {
90 .addr = state->
config->demod_address, .flags = 0,
91 .buf =
buf, .len = 2 };
97 "%s: error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
98 __func__, reg, data, ret);
111 { .
addr = state->
config->demod_address, .flags = 0,
112 .buf = &
reg, .len = 1 },
114 .buf = &
data, .len = 1 } };
127 static int cx22702_set_inversion(
struct cx22702_state *state,
int inversion)
131 val = cx22702_readreg(state, 0x0C);
144 return cx22702_writereg(state, 0x0C, val);
154 if (!(cx22702_readreg(state, 0x0A) & 0x20))
157 val = cx22702_readreg(state, 0x01);
158 switch ((val & 0x18) >> 3) {
169 switch (val & 0x07) {
185 val = cx22702_readreg(state, 0x02);
186 switch ((val & 0x38) >> 3) {
203 switch (val & 0x07) {
221 val = cx22702_readreg(state, 0x03);
222 switch ((val & 0x0c) >> 2) {
236 switch (val & 0x03) {
253 dprintk(
"%s(%d)\n", __func__, enable);
254 val = cx22702_readreg(state, 0x0D);
259 return cx22702_writereg(state, 0x0D, val);
269 if (fe->
ops.tuner_ops.set_params) {
270 fe->
ops.tuner_ops.set_params(fe);
271 if (fe->
ops.i2c_gate_ctrl)
272 fe->
ops.i2c_gate_ctrl(fe, 0);
276 cx22702_set_inversion(state, p->
inversion);
279 val = cx22702_readreg(state, 0x0C) & 0xcf;
290 dprintk(
"%s: invalid bandwidth\n", __func__);
293 cx22702_writereg(state, 0x0C, val);
306 cx22702_writereg(state, 0x06, 0x10);
307 cx22702_writereg(state, 0x07, 0x9);
308 cx22702_writereg(state, 0x08, 0xC1);
309 cx22702_writereg(state, 0x0B, cx22702_readreg(state, 0x0B)
311 cx22702_writereg(state, 0x0C,
312 (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40);
313 cx22702_writereg(state, 0x00, 0x01);
314 dprintk(
"%s: Autodetecting\n", __func__);
330 dprintk(
"%s: invalid modulation\n", __func__);
346 dprintk(
"%s: invalid hierarchy\n", __func__);
349 cx22702_writereg(state, 0x06, val);
369 dprintk(
"%s: invalid code_rate_HP\n", __func__);
389 dprintk(
"%s: invalid code_rate_LP\n", __func__);
392 cx22702_writereg(state, 0x07, val);
408 dprintk(
"%s: invalid guard_interval\n", __func__);
418 dprintk(
"%s: invalid transmission_mode\n", __func__);
421 cx22702_writereg(state, 0x08, val);
422 cx22702_writereg(state, 0x0B,
423 (cx22702_readreg(state, 0x0B) & 0xfc) | 0x02);
424 cx22702_writereg(state, 0x0C,
425 (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40);
428 cx22702_writereg(state, 0x00, 0x01);
440 cx22702_writereg(state, 0x00, 0x02);
445 cx22702_writereg(state, init_tab[i], init_tab[i + 1]);
447 cx22702_writereg(state, 0xf8, (state->
config->output_mode << 1)
450 cx22702_i2c_gate_ctrl(fe, 0);
463 reg0A = cx22702_readreg(state, 0x0A);
464 reg23 = cx22702_readreg(state, 0x23);
466 dprintk(
"%s: status demod=0x%02x agc=0x%02x\n"
467 , __func__, reg0A, reg23);
488 if (cx22702_readreg(state, 0xE4) & 0x02) {
490 *ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7
491 | (cx22702_readreg(state, 0xDF) & 0x7F);
494 *ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7
495 | cx22702_readreg(state, 0xDF);
501 static int cx22702_read_signal_strength(
struct dvb_frontend *fe,
502 u16 *signal_strength)
517 reg23 = cx22702_readreg(state, 0x23);
519 *signal_strength = 0;
521 reg23 = ~reg23 & 0x7f;
523 *signal_strength = (reg23 << 9) | (reg23 << 2) | (reg23 >> 5);
534 if (cx22702_readreg(state, 0xE4) & 0x02) {
536 rs_ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7
537 | (cx22702_readreg(state, 0xDF) & 0x7F);
540 rs_ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 8
541 | cx22702_readreg(state, 0xDF);
548 static int cx22702_read_ucblocks(
struct dvb_frontend *fe,
u32 *ucblocks)
555 _ucblocks = cx22702_readreg(state, 0xE3);
565 static int cx22702_get_frontend(
struct dvb_frontend *fe)
570 u8 reg0C = cx22702_readreg(state, 0x0C);
573 return cx22702_get_tps(state, c);
576 static int cx22702_get_tune_settings(
struct dvb_frontend *fe,
606 if (cx22702_readreg(state, 0x1f) != 0x3)
624 .name =
"Conexant CX22702 DVB-T",
625 .frequency_min = 177000000,
626 .frequency_max = 858000000,
627 .frequency_stepsize = 166666,
635 .release = cx22702_release,
637 .init = cx22702_init,
638 .i2c_gate_ctrl = cx22702_i2c_gate_ctrl,
640 .set_frontend = cx22702_set_tps,
641 .get_frontend = cx22702_get_frontend,
642 .get_tune_settings = cx22702_get_tune_settings,
644 .read_status = cx22702_read_status,
645 .read_ber = cx22702_read_ber,
646 .read_signal_strength = cx22702_read_signal_strength,
647 .read_snr = cx22702_read_snr,
648 .read_ucblocks = cx22702_read_ucblocks,