23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/string.h>
28 #include <linux/slab.h>
43 #define dprintk(x...) printk(x)
48 #define STV0297_CLOCK_KHZ 28900
60 dprintk(
"%s: writereg error (reg == 0x%02x, val == 0x%02x, "
61 "ret == %i)\n", __func__, reg, data, ret);
63 return (ret != 1) ? -1 : 0;
71 struct i2c_msg msg[] = { {.addr = state->
config->demod_address,.flags = 0,.buf = b0,.len = 1},
72 {.addr = state->
config->demod_address,.flags =
I2C_M_RD,.buf = b1,.len = 1}
76 if (state->
config->stop_during_read) {
78 dprintk(
"%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg, ret);
82 dprintk(
"%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg, ret);
87 dprintk(
"%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg, ret);
99 val = stv0297_readreg(state, reg);
101 val |= (data &
mask);
102 stv0297_writereg(state, reg, val);
112 {.addr = state->
config->demod_address,.flags =
I2C_M_RD,.buf =
b,.len = len}
116 if (state->
config->stop_during_read) {
118 dprintk(
"%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg1, ret);
122 dprintk(
"%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg1, ret);
127 dprintk(
"%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg1, ret);
139 tmp = stv0297_readreg(state, 0x55);
140 tmp |= stv0297_readreg(state, 0x56) << 8;
141 tmp |= stv0297_readreg(state, 0x57) << 16;
142 tmp |= stv0297_readreg(state, 0x58) << 24;
154 tmp = 131072
L * srate;
158 stv0297_writereg(state, 0x55, (
unsigned char) (tmp & 0xFF));
159 stv0297_writereg(state, 0x56, (
unsigned char) (tmp >> 8));
160 stv0297_writereg(state, 0x57, (
unsigned char) (tmp >> 16));
161 stv0297_writereg(state, 0x58, (
unsigned char) (tmp >> 24));
164 static void stv0297_set_sweeprate(
struct stv0297_state *state,
short fshift,
long symrate)
168 tmp = (
long) fshift *262144L;
180 stv0297_writereg(state, 0x60, tmp & 0xFF);
181 stv0297_writereg_mask(state, 0x69, 0xF0, (tmp >> 4) & 0xf0);
189 tmp = offset * 26844L;
194 stv0297_writereg(state, 0x66, (
unsigned char) (tmp & 0xFF));
195 stv0297_writereg(state, 0x67, (
unsigned char) (tmp >> 8));
196 stv0297_writereg(state, 0x68, (
unsigned char) (tmp >> 16));
197 stv0297_writereg_mask(state, 0x69, 0x0F, (tmp >> 24) & 0x0f);
227 tmp = (freq * 1000) / tmp;
231 stv0297_writereg_mask(state, 0x25, 0x80, 0x80);
232 stv0297_writereg(state, 0x21, tmp >> 8);
233 stv0297_writereg(state, 0x20, tmp);
240 switch (modulation) {
265 stv0297_writereg_mask(state, 0x00, 0x70, val << 4);
287 stv0297_writereg_mask(state, 0x83, 0x08, val << 3);
297 stv0297_writereg(state, 0x87, 0x78);
298 stv0297_writereg(state, 0
x86, 0xc8);
310 for (i=0; !(state->
config->inittab[
i] == 0xff && state->
config->inittab[i+1] == 0xff); i+=2)
311 stv0297_writereg(state, state->
config->inittab[i], state->
config->inittab[i+1]);
323 stv0297_writereg_mask(state, 0x80, 1, 1);
332 u8 sync = stv0297_readreg(state, 0xDF);
346 stv0297_readregs(state, 0xA0, BER, 3);
347 if (!(BER[0] & 0x80)) {
348 state->
last_ber = BER[2] << 8 | BER[1];
349 stv0297_writereg_mask(state, 0xA0, 0x80, 0x80);
358 static int stv0297_read_signal_strength(
struct dvb_frontend *fe,
u16 * strength)
364 stv0297_readregs(state, 0x41, STRENGTH, 3);
365 tmp = (STRENGTH[1] & 0x03) << 8 | STRENGTH[0];
366 if (STRENGTH[2] & 0x20) {
377 *strength = (tmp << 7) | (tmp >> 2);
386 stv0297_readregs(state, 0x07, SNR, 2);
387 *snr = SNR[1] << 8 | SNR[0];
392 static int stv0297_read_ucblocks(
struct dvb_frontend *fe,
u32 * ucblocks)
396 stv0297_writereg_mask(state, 0xDF, 0x03, 0x03);
398 *ucblocks = (stv0297_readreg(state, 0xD5) << 8)
399 | stv0297_readreg(state, 0xD4);
401 stv0297_writereg_mask(state, 0xDF, 0x03, 0x02);
402 stv0297_writereg_mask(state, 0xDF, 0x03, 0x01);
407 static int stv0297_set_frontend(
struct dvb_frontend *fe)
440 if (state->
config->invert)
442 carrieroffset = -330;
448 sweeprate = -sweeprate;
449 carrieroffset = -carrieroffset;
457 if (fe->
ops.tuner_ops.set_params) {
458 fe->
ops.tuner_ops.set_params(fe);
459 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
463 stv0297_writereg(state, 0x82, 0x0);
466 stv0297_set_initialdemodfreq(state, 7250);
469 stv0297_writereg_mask(state, 0x43, 0x10, 0x00);
470 stv0297_writereg(state, 0x41, 0x00);
471 stv0297_writereg_mask(state, 0x42, 0x03, 0x01);
472 stv0297_writereg_mask(state, 0x36, 0x60, 0x00);
473 stv0297_writereg_mask(state, 0x36, 0x18, 0x00);
474 stv0297_writereg_mask(state, 0x71, 0x80, 0x80);
475 stv0297_writereg(state, 0x72, 0x00);
476 stv0297_writereg(state, 0x73, 0x00);
477 stv0297_writereg_mask(state, 0x74, 0x0F, 0x00);
478 stv0297_writereg_mask(state, 0x43, 0x08, 0x00);
479 stv0297_writereg_mask(state, 0x71, 0x80, 0x00);
482 stv0297_writereg_mask(state, 0x5a, 0x20, 0x20);
483 stv0297_writereg_mask(state, 0x5b, 0x02, 0x02);
484 stv0297_writereg_mask(state, 0x5b, 0x02, 0x00);
485 stv0297_writereg_mask(state, 0x5b, 0x01, 0x00);
486 stv0297_writereg_mask(state, 0x5a, 0x40, 0x40);
489 stv0297_writereg_mask(state, 0x6a, 0x01, 0x00);
492 stv0297_writereg_mask(state, 0x81, 0x01, 0x01);
493 stv0297_writereg_mask(state, 0x81, 0x01, 0x00);
496 stv0297_writereg_mask(state, 0x83, 0x20, 0x20);
497 stv0297_writereg_mask(state, 0x83, 0x20, 0x00);
500 u_threshold = stv0297_readreg(state, 0x00) & 0xf;
501 initial_u = stv0297_readreg(state, 0x01) >> 4;
502 blind_u = stv0297_readreg(state, 0x01) & 0xf;
503 stv0297_writereg_mask(state, 0x84, 0x01, 0x01);
504 stv0297_writereg_mask(state, 0x84, 0x01, 0x00);
505 stv0297_writereg_mask(state, 0x00, 0x0f, u_threshold);
506 stv0297_writereg_mask(state, 0x01, 0xf0, initial_u << 4);
507 stv0297_writereg_mask(state, 0x01, 0x0f, blind_u);
510 stv0297_writereg_mask(state, 0x87, 0x80, 0x00);
513 stv0297_writereg(state, 0x63, 0x00);
514 stv0297_writereg(state, 0x64, 0x00);
515 stv0297_writereg(state, 0x65, 0x00);
516 stv0297_writereg(state, 0x66, 0x00);
517 stv0297_writereg(state, 0x67, 0x00);
518 stv0297_writereg(state, 0x68, 0x00);
519 stv0297_writereg_mask(state, 0x69, 0x0f, 0x00);
523 stv0297_set_symbolrate(state, p->
symbol_rate / 1000);
524 stv0297_set_sweeprate(state, sweeprate, p->
symbol_rate / 1000);
525 stv0297_set_carrieroffset(state, carrieroffset);
526 stv0297_set_inversion(state, inversion);
532 stv0297_writereg_mask(state, 0x88, 0x08, 0x00);
534 stv0297_writereg_mask(state, 0x88, 0x08, 0x08);
536 stv0297_writereg_mask(state, 0x5a, 0x20, 0x00);
537 stv0297_writereg_mask(state, 0x6a, 0x01, 0x01);
538 stv0297_writereg_mask(state, 0x43, 0x40, 0x40);
539 stv0297_writereg_mask(state, 0x5b, 0x30, 0x00);
540 stv0297_writereg_mask(state, 0x03, 0x0c, 0x0c);
541 stv0297_writereg_mask(state, 0x03, 0x03, 0x03);
542 stv0297_writereg_mask(state, 0x43, 0x10, 0x10);
548 if (stv0297_readreg(state, 0x43) & 0x08)
561 if (stv0297_readreg(state, 0x82) & 0x04) {
574 if (stv0297_readreg(state, 0x82) & 0x08) {
583 stv0297_writereg_mask(state, 0x6a, 1, 0);
584 stv0297_writereg_mask(state, 0x88, 8, 0);
591 if (stv0297_readreg(state, 0xDF) & 0x80) {
601 if (!(stv0297_readreg(state, 0xDF) & 0x80)) {
606 stv0297_writereg_mask(state, 0x5a, 0x40, 0x00);
611 stv0297_writereg_mask(state, 0x6a, 0x01, 0x00);
615 static int stv0297_get_frontend(
struct dvb_frontend *fe)
621 reg_00 = stv0297_readreg(state, 0x00);
622 reg_83 = stv0297_readreg(state, 0x83);
626 if (state->
config->invert)
628 p->
symbol_rate = stv0297_get_symbolrate(state) * 1000;
631 switch ((reg_00 >> 4) & 0x7) {
677 if ((stv0297_readreg(state, 0x80) & 0x70) != 0x20)
693 .name =
"ST STV0297 DVB-C",
694 .frequency_min = 47000000,
695 .frequency_max = 862000000,
696 .frequency_stepsize = 62500,
697 .symbol_rate_min = 870000,
698 .symbol_rate_max = 11700000,
702 .release = stv0297_release,
704 .init = stv0297_init,
705 .sleep = stv0297_sleep,
706 .i2c_gate_ctrl = stv0297_i2c_gate_ctrl,
708 .set_frontend = stv0297_set_frontend,
709 .get_frontend = stv0297_get_frontend,
711 .read_status = stv0297_read_status,
712 .read_ber = stv0297_read_ber,
713 .read_signal_strength = stv0297_read_signal_strength,
714 .read_snr = stv0297_read_snr,
715 .read_ucblocks = stv0297_read_ucblocks,