29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/string.h>
32 #include <linux/slab.h>
34 #include <asm/div64.h>
52 #define STATUS_UCBLOCKS 1
55 static int debug_legacy_dish_switch;
56 #define dprintk(args...) \
59 printk(KERN_DEBUG "stv0288: " args); \
77 dprintk(
"%s: writereg error (reg == 0x%02x, val == 0x%02x, "
78 "ret == %i)\n", __func__, reg, data, ret);
90 return stv0288_writeregI(state, buf[0], buf[1]);
100 .addr = state->
config->demod_address,
105 .addr = state->
config->demod_address,
115 dprintk(
"%s: readreg error (reg == 0x%02x, ret == %i)\n",
127 if ((srate < 1000000) || (srate > 45000000))
130 stv0288_writeregI(state, 0x22, 0);
131 stv0288_writeregI(state, 0x23, 0);
132 stv0288_writeregI(state, 0x2b, 0xff);
133 stv0288_writeregI(state, 0x2c, 0xf7);
135 temp = (
unsigned int)srate / 1000;
140 b[0] = (
unsigned char)((temp >> 12) & 0xff);
141 b[1] = (
unsigned char)((temp >> 4) & 0xff);
142 b[2] = (
unsigned char)((temp << 4) & 0xf0);
143 stv0288_writeregI(state, 0x28, 0x80);
144 stv0288_writeregI(state, 0x29, 0);
145 stv0288_writeregI(state, 0x2a, 0);
147 stv0288_writeregI(state, 0x28, b[0]);
148 stv0288_writeregI(state, 0x29, b[1]);
149 stv0288_writeregI(state, 0x2a, b[2]);
150 dprintk(
"stv0288: stv0288_set_symbolrate\n");
155 static int stv0288_send_diseqc_msg(
struct dvb_frontend *fe,
164 stv0288_writeregI(state, 0x09, 0);
166 stv0288_writeregI(state, 0x05, 0x12);
168 for (i = 0; i < m->
msg_len; i++) {
169 if (stv0288_writeregI(state, 0x06, m->
msg[i]))
176 static int stv0288_send_diseqc_burst(
struct dvb_frontend *fe,
183 if (stv0288_writeregI(state, 0x05, 0x03))
186 if (stv0288_writeregI(state, 0x06, burst ==
SEC_MINI_A ? 0x00 : 0xff))
190 if (stv0288_writeregI(state, 0x05, 0x12))
202 if (stv0288_writeregI(state, 0x05, 0x10))
207 if (stv0288_writeregI(state, 0x05, 0x12))
217 static u8 stv0288_inittab[] = {
342 dprintk(
"stv0288: init chip\n");
343 stv0288_writeregI(state, 0x41, 0x04);
348 for (i = 0; !(stv0288_inittab[
i] == 0xff &&
349 stv0288_inittab[i + 1] == 0xff); i += 2)
350 stv0288_writeregI(state, stv0288_inittab[i],
351 stv0288_inittab[i + 1]);
353 for (i = 0; ; i += 2) {
354 reg = state->
config->inittab[
i];
355 val = state->
config->inittab[i+1];
356 if (reg == 0xff && val == 0xff)
358 stv0288_writeregI(state, reg, val);
368 u8 sync = stv0288_readreg(state, 0x24);
372 dprintk(
"%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync);
381 dprintk(
"stv0288 has locked\n");
393 *ber = (stv0288_readreg(state, 0x26) << 8) |
394 stv0288_readreg(state, 0x27);
395 dprintk(
"stv0288_read_ber %d\n", *ber);
401 static int stv0288_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
405 s32 signal = 0xffff - ((stv0288_readreg(state, 0x10) << 8));
408 signal = signal * 5 / 4;
409 *strength = (signal > 0xffff) ? 0xffff : (signal < 0) ? 0 : signal;
410 dprintk(
"stv0288_read_signal_strength %d\n", *strength);
418 stv0288_writeregI(state, 0x41, 0x84);
427 s32 xsnr = 0xffff - ((stv0288_readreg(state, 0x2d) << 8)
428 | stv0288_readreg(state, 0x2e));
429 xsnr = 3 * (xsnr - 0xa100);
430 *snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr;
431 dprintk(
"stv0288_read_snr %d\n", *snr);
436 static int stv0288_read_ucblocks(
struct dvb_frontend *fe,
u32 *ucblocks)
442 *ucblocks = (stv0288_readreg(state, 0x26) << 8) |
443 stv0288_readreg(state, 0x27);
444 dprintk(
"stv0288_read_ber %d\n", *ucblocks);
455 static int stv0288_set_frontend(
struct dvb_frontend *fe)
461 unsigned char tda[3];
462 u8 reg, time_out = 0;
464 dprintk(
"%s : FE_SET_FRONTEND\n", __func__);
467 dprintk(
"%s: unsupported delivery "
468 "system selected (%d)\n",
473 if (state->
config->set_ts_params)
474 state->
config->set_ts_params(fe, 0);
477 if (fe->
ops.tuner_ops.set_params) {
478 fe->
ops.tuner_ops.set_params(fe);
479 if (fe->
ops.i2c_gate_ctrl)
480 fe->
ops.i2c_gate_ctrl(fe, 0);
486 stv0288_writeregI(state, 0x15, 0xc5);
489 for (tm = -9; tm < 7;) {
491 reg = stv0288_readreg(state, 0x24);
506 tda[1] = (
unsigned char)tm;
507 stv0288_writeregI(state, 0x2b, tda[1]);
508 stv0288_writeregI(state, 0x2c, tda[2]);
523 stv0288_writeregI(state, 0x01, 0xb5);
525 stv0288_writeregI(state, 0x01, 0x35);
541 .name =
"ST STV0288 DVB-S",
542 .frequency_min = 950000,
543 .frequency_max = 2150000,
544 .frequency_stepsize = 1000,
545 .frequency_tolerance = 0,
546 .symbol_rate_min = 1000000,
547 .symbol_rate_max = 45000000,
548 .symbol_rate_tolerance = 500,
555 .release = stv0288_release,
556 .init = stv0288_init,
557 .sleep = stv0288_sleep,
558 .write = stv0288_write,
559 .i2c_gate_ctrl = stv0288_i2c_gate_ctrl,
560 .read_status = stv0288_read_status,
561 .read_ber = stv0288_read_ber,
562 .read_signal_strength = stv0288_read_signal_strength,
563 .read_snr = stv0288_read_snr,
564 .read_ucblocks = stv0288_read_ucblocks,
565 .diseqc_send_master_cmd = stv0288_send_diseqc_msg,
566 .diseqc_send_burst = stv0288_send_diseqc_burst,
567 .set_tone = stv0288_set_tone,
568 .set_voltage = stv0288_set_voltage,
570 .set_property = stv0288_set_property,
571 .set_frontend = stv0288_set_frontend,
594 stv0288_writeregI(state, 0x41, 0x04);
596 id = stv0288_readreg(state, 0x00);
597 dprintk(
"stv0288 id %x\n",
id);
618 "Enable timing analysis for Dish Network legacy switches");