28 #include <linux/errno.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/string.h>
33 #include <linux/slab.h>
52 #define dprintk(args...) \
55 printk(KERN_DEBUG "mt312: " args); \
58 #define MT312_PLL_CLK 10000000UL
59 #define MT312_PLL_CLK_10_111 10111000UL
66 u8 regbuf[1] = { reg };
87 for (i = 0; i <
count; i++)
105 for (i = 0; i <
count; i++)
111 memcpy(&buf[1], src, count);
121 dprintk(
"%s: ret == %d\n", __func__, ret);
128 static inline int mt312_readreg(
struct mt312_state *state,
131 return mt312_read(state, reg, val, 1);
134 static inline int mt312_writereg(
struct mt312_state *state,
137 return mt312_write(state, reg, &val, 1);
142 return (a + (b / 2)) /
b;
147 return mt312_writereg(state,
RESET, full ? 0x80 : 0x40);
150 static int mt312_get_inversion(
struct mt312_state *state,
156 ret = mt312_readreg(state,
VIT_MODE, &vit_mode);
175 ret = mt312_readreg(state,
SYM_RATE_H, &sym_rate_h);
179 if (sym_rate_h & 0x80) {
181 ret = mt312_writereg(state,
MON_CTRL, 0x03);
185 ret = mt312_read(state,
MONITOR_H, buf,
sizeof(buf));
189 monitor = (buf[0] << 8) | buf[1];
192 mt312_div(monitor * 15625, 4));
194 ret = mt312_writereg(state,
MON_CTRL, 0x05);
198 ret = mt312_read(state,
MONITOR_H, buf,
sizeof(buf));
202 dec_ratio = ((buf[0] >> 5) & 0x07) * 32;
204 ret = mt312_read(state,
SYM_RAT_OP_H, buf,
sizeof(buf));
208 sym_rat_op = (buf[0] << 8) | buf[1];
210 dprintk(
"sym_rat_op=%d dec_ratio=%d\n",
211 sym_rat_op, dec_ratio);
213 (((state->
xtal * 8192) / (sym_rat_op + 8192)) *
229 ret = mt312_readreg(state,
FEC_STATUS, &fec_status);
233 *cr = fec_tab[(fec_status >> 4) & 0x07];
245 ret = mt312_writereg(state,
CONFIG,
254 ret = mt312_reset(state, 1);
261 u8 buf_def[8] = { 0x14, 0x12, 0x03, 0x02,
262 0x01, 0x00, 0x00, 0x00 };
264 ret = mt312_write(state,
VIT_SETUP, buf_def,
sizeof(buf_def));
272 ret = mt312_writereg(state,
GPP_CTRL, 0x80);
279 ret = mt312_write(state,
HW_CTRL, buf, 2);
284 ret = mt312_writereg(state,
HW_CTRL, 0x00);
288 ret = mt312_writereg(state,
MPEG_CTRL, 0x00);
296 buf[0] = mt312_div(state->
xtal * state->
freq_mult * 2, 1000000);
299 buf[1] = mt312_div(state->
xtal, 22000 * 4);
301 ret = mt312_write(state,
SYS_CLK, buf,
sizeof(buf));
319 ret = mt312_writereg(state,
OP_CTRL, buf[0]);
327 ret = mt312_write(state,
TS_SW_LIM_L, buf,
sizeof(buf));
331 ret = mt312_writereg(state,
CS_SW_LIM, 0x69);
338 static int mt312_send_master_cmd(
struct dvb_frontend *fe,
348 ret = mt312_readreg(state,
DISEQC_MODE, &diseqc_mode);
357 (diseqc_mode & 0x40) | ((c->
msg_len - 1) << 3)
366 if (c->
msg[0] & 0x02) {
367 ret = mt312_writereg(state,
DISEQC_MODE, (diseqc_mode & 0x40));
378 const u8 mini_tab[2] = { 0x02, 0x03 };
386 ret = mt312_readreg(state,
DISEQC_MODE, &diseqc_mode);
391 (diseqc_mode & 0x40) | mini_tab[c]);
401 const u8 tone_tab[2] = { 0x01, 0x00 };
409 ret = mt312_readreg(state,
DISEQC_MODE, &diseqc_mode);
414 (diseqc_mode & 0x40) | tone_tab[t]);
424 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 };
431 if (state->
config->voltage_inverted)
445 ret = mt312_read(state,
QPSK_STAT_H, status,
sizeof(status));
449 dprintk(
"QPSK_STAT_H: 0x%02x, QPSK_STAT_L: 0x%02x,"
450 " FEC_STATUS: 0x%02x\n", status[0], status[1], status[2]);
452 if (status[0] & 0xc0)
454 if (status[0] & 0x04)
456 if (status[2] & 0x02)
458 if (status[2] & 0x04)
460 if (status[0] & 0x01)
476 *ber = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) * 64;
481 static int mt312_read_signal_strength(
struct dvb_frontend *fe,
482 u16 *signal_strength)
490 ret = mt312_read(state,
AGC_H, buf,
sizeof(buf));
494 agc = (buf[0] << 6) | (buf[1] >> 2);
495 err_db = (
s16) (((buf[1] & 0x03) << 14) | buf[2] << 6) >> 6;
497 *signal_strength = agc;
499 dprintk(
"agc=%08x err_db=%hd\n", agc, err_db);
510 ret = mt312_read(state,
M_SNR_H, buf,
sizeof(buf));
514 *snr = 0xFFFF - ((((buf[0] & 0x7f) << 8) | buf[1]) << 1);
525 ret = mt312_read(state,
RS_UBC_H, buf,
sizeof(buf));
529 *ubc = (buf[0] << 8) | buf[1];
539 u8 buf[5], config_val;
542 const u8 fec_tab[10] =
543 { 0x00, 0x01, 0x02, 0x04, 0x3f, 0x08, 0x10, 0x20, 0x3f, 0x3f };
544 const u8 inv_tab[3] = { 0x00, 0x40, 0x80 };
574 ret = mt312_readreg(state,
CONFIG, &config_val);
582 ret = mt312_initfe(fe);
590 ret = mt312_initfe(fe);
605 if (fe->
ops.tuner_ops.set_params) {
606 fe->
ops.tuner_ops.set_params(fe);
607 if (fe->
ops.i2c_gate_ctrl)
608 fe->
ops.i2c_gate_ctrl(fe, 0);
615 buf[0] = (sr >> 8) & 0x3f;
616 buf[1] = (sr >> 0) & 0xff;
630 ret = mt312_write(state,
SYM_RATE_H, buf,
sizeof(buf));
634 mt312_reset(state, 0);
645 ret = mt312_get_inversion(state, &p->
inversion);
649 ret = mt312_get_symbol_rate(state, &p->
symbol_rate);
653 ret = mt312_get_code_rate(state, &p->
fec_inner);
669 ret = mt312_readreg(state,
GPP_CTRL, &val);
683 ret = mt312_writereg(state,
GPP_CTRL, val);
696 ret = mt312_reset(state, 1);
702 ret = mt312_writereg(state,
GPP_CTRL, 0x00);
707 ret = mt312_writereg(state,
HW_CTRL, 0x0d);
712 ret = mt312_readreg(state,
CONFIG, &config);
717 ret = mt312_writereg(state,
CONFIG, config & 0x7f);
724 static int mt312_get_tune_settings(
struct dvb_frontend *fe,
739 #define MT312_SYS_CLK 90000000UL
743 .name =
"Zarlink ???? DVB-S",
744 .frequency_min = 950000,
745 .frequency_max = 2150000,
759 .
init = mt312_initfe,
760 .
sleep = mt312_sleep,
794 if (mt312_readreg(state,
ID, &state->
id) < 0)
820 " are supported chips.\n");