33 #include <linux/kernel.h>
34 #include <linux/module.h>
37 #include <linux/string.h>
38 #include <linux/slab.h>
53 #define dprintk(args...) \
55 if (debug) printk(KERN_DEBUG "mt352: " args); \
63 .buf =
buf, .len = 2 };
66 printk(
"mt352_write() to reg %x failed (err = %d)!\n", reg, err);
72 static int _mt352_write(
struct dvb_frontend* fe,
const u8 ibuf[],
int ilen)
75 for (i=0; i < ilen-1; i++)
76 if ((err = mt352_single_write(fe,ibuf[0]+i,ibuf[i+1])))
89 .buf = b0, .len = 1 },
90 { .addr = state->
config.demod_address,
92 .buf = b1, .len = 1 } };
97 printk(
"%s: readreg error (reg=%d, ret==%i)\n",
107 static u8 mt352_softdown[] = {
CLOCK_CTL, 0x20, 0x08 };
109 _mt352_write(fe, mt352_softdown,
sizeof(mt352_softdown));
113 static void mt352_calc_nominal_rate(
struct mt352_state* state,
117 u32 adc_clock = 20480;
132 if (state->
config.adc_clock)
133 adc_clock = state->
config.adc_clock;
135 value = 64 * bw * (1<<16) / (7 * 8);
136 value = value * 1000 / adc_clock;
137 dprintk(
"%s: bw %d, adc_clock %d => 0x%x\n",
138 __func__, bw, adc_clock, value);
143 static void mt352_calc_input_freq(
struct mt352_state* state,
146 int adc_clock = 20480;
150 if (state->
config.adc_clock)
151 adc_clock = state->
config.adc_clock;
155 if (adc_clock >= if2 * 2)
158 ife = adc_clock - (if2 % adc_clock);
159 if (ife > adc_clock / 2)
160 ife = adc_clock - ife;
162 value = -16374 * ife / adc_clock;
163 dprintk(
"%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
164 __func__, if2, ife, adc_clock, value, value & 0x3fff);
169 static int mt352_set_parameters(
struct dvb_frontend *fe)
173 unsigned char buf[13];
174 static unsigned char tuner_go[] = { 0x5d, 0x01 };
175 static unsigned char fsm_go[] = { 0x5e, 0x01 };
176 unsigned int tps = 0;
290 mt352_calc_nominal_rate(state, op->
bandwidth_hz, buf+4);
291 mt352_calc_input_freq(state, buf+6);
293 if (state->
config.no_tuner) {
294 if (fe->
ops.tuner_ops.set_params) {
295 fe->
ops.tuner_ops.set_params(fe);
296 if (fe->
ops.i2c_gate_ctrl)
297 fe->
ops.i2c_gate_ctrl(fe, 0);
300 _mt352_write(fe, buf, 8);
301 _mt352_write(fe, fsm_go, 2);
303 if (fe->
ops.tuner_ops.calc_regs) {
304 fe->
ops.tuner_ops.calc_regs(fe, buf+8, 5);
306 _mt352_write(fe, buf,
sizeof(buf));
307 _mt352_write(fe, tuner_go, 2);
314 static int mt352_get_parameters(
struct dvb_frontend* fe)
321 static const u8 tps_fec_to_api[8] =
333 if ( (mt352_read_register(state,0x00) & 0xC0) != 0xC0 )
346 switch ( (tps >> 13) & 3)
364 switch ( (tps >> 2) & 3)
383 switch ( (tps >> 10) & 7)
406 else if (trl == 0x64)
412 if (mt352_read_register(state,
STATUS_2) & 0x02)
437 if ((s0 = mt352_read_register(state,
STATUS_0)) < 0)
439 if ((s1 = mt352_read_register(state,
STATUS_1)) < 0)
441 if ((s3 = mt352_read_register(state,
STATUS_3)) < 0)
467 *ber = (mt352_read_register (state,
RS_ERR_CNT_2) << 16) |
474 static int mt352_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
479 u16 signal = ((mt352_read_register(state,
AGC_GAIN_1) & 0x0f) << 12) |
480 (mt352_read_register(state,
AGC_GAIN_0) << 4);
491 u8 _snr = mt352_read_register (state,
SNR);
492 *snr = (_snr << 8) | _snr;
501 *ucblocks = (mt352_read_register (state,
RS_UBC_1) << 8) |
502 (mt352_read_register (state,
RS_UBC_0));
520 static u8 mt352_reset_attach [] = {
RESET, 0xC0 };
522 dprintk(
"%s: hello\n",__func__);
524 if ((mt352_read_register(state,
CLOCK_CTL) & 0x10) == 0 ||
525 (mt352_read_register(state,
CONFIG) & 0x20) == 0) {
528 _mt352_write(fe, mt352_reset_attach,
sizeof(mt352_reset_attach));
529 return state->
config.demod_init(fe);
572 .name =
"Zarlink MT352 DVB-T",
573 .frequency_min = 174000000,
574 .frequency_max = 862000000,
575 .frequency_stepsize = 166667,
576 .frequency_tolerance = 0,
586 .release = mt352_release,
589 .sleep = mt352_sleep,
590 .write = _mt352_write,
592 .set_frontend = mt352_set_parameters,
593 .get_frontend = mt352_get_parameters,
594 .get_tune_settings = mt352_get_tune_settings,
596 .read_status = mt352_read_status,
597 .read_ber = mt352_read_ber,
598 .read_signal_strength = mt352_read_signal_strength,
599 .read_snr = mt352_read_snr,
600 .read_ucblocks = mt352_read_ucblocks,
607 MODULE_AUTHOR(
"Holger Waechtler, Daniel Mack, Antonio Mancuso");