22 #include <linux/kernel.h>
23 #include <linux/module.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
28 #include <asm/div64.h>
46 #define dprintk(args...) \
48 if (debug) printk(KERN_DEBUG "zl10353: " args); \
51 static int debug_regs;
58 .buf =
buf, .len = 2 };
61 printk(
"zl10353: write to reg %x failed (err = %d)!\n", reg, err);
67 static int zl10353_write(
struct dvb_frontend *fe,
const u8 ibuf[],
int ilen)
70 for (i = 0; i < ilen - 1; i++)
71 if ((err = zl10353_single_write(fe, ibuf[0] + i, ibuf[i + 1])))
84 .buf = b0, .len = 1 },
85 { .addr = state->
config.demod_address,
87 .buf = b1, .len = 1 } };
92 printk(
"%s: readreg error (reg=%d, ret==%i)\n",
107 for (reg = 0; ; reg++) {
113 ret = zl10353_read_register(state, reg);
124 static void zl10353_calc_nominal_rate(
struct dvb_frontend *fe,
129 u32 adc_clock = 450560;
131 u8 bw = bandwidth / 1000000;
133 if (state->
config.adc_clock)
134 adc_clock = state->
config.adc_clock;
136 value = (
u64)10 * (1 << 23) / 7 * 125;
137 value = (bw *
value) + adc_clock / 2;
139 *nominal_rate =
value;
141 dprintk(
"%s: bw %d, adc_clock %d => 0x%x\n",
142 __func__, bw, adc_clock, *nominal_rate);
145 static void zl10353_calc_input_freq(
struct dvb_frontend *fe,
149 u32 adc_clock = 450560;
154 if (state->
config.adc_clock)
155 adc_clock = state->
config.adc_clock;
159 if (adc_clock >= if2 * 2)
162 ife = adc_clock - (if2 % adc_clock);
163 if (ife > adc_clock / 2)
164 ife = adc_clock - ife;
166 value = (
u64)65536 * ife + adc_clock / 2;
168 *input_freq = -
value;
170 dprintk(
"%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
171 __func__, if2, ife, adc_clock, -(
int)value, *input_freq);
176 static u8 zl10353_softdown[] = { 0x50, 0x0C, 0x44 };
178 zl10353_write(fe, zl10353_softdown,
sizeof(zl10353_softdown));
182 static int zl10353_set_parameters(
struct dvb_frontend *fe)
186 u16 nominal_rate, input_freq;
187 u8 pllbuf[6] = { 0x67 }, acq_ctl = 0;
192 zl10353_single_write(fe,
RESET, 0x80);
194 zl10353_single_write(fe, 0xEA, 0x01);
196 zl10353_single_write(fe, 0xEA, 0x00);
204 zl10353_single_write(fe,
ACQ_CTL, acq_ctl);
210 zl10353_single_write(fe, 0x64, 0x34);
211 zl10353_single_write(fe, 0xcc, 0xdd);
215 zl10353_single_write(fe, 0x64, 0x35);
216 zl10353_single_write(fe, 0xcc, 0x73);
223 zl10353_single_write(fe, 0x64, 0x36);
224 zl10353_single_write(fe, 0xcc, 0x73);
227 zl10353_calc_nominal_rate(fe, c->
bandwidth_hz, &nominal_rate);
232 zl10353_calc_input_freq(fe, &input_freq);
343 if (fe->
ops.i2c_gate_ctrl)
344 fe->
ops.i2c_gate_ctrl(fe, 0);
351 if (state->
config.no_tuner) {
352 if (fe->
ops.tuner_ops.set_params) {
353 fe->
ops.tuner_ops.set_params(fe);
354 if (fe->
ops.i2c_gate_ctrl)
355 fe->
ops.i2c_gate_ctrl(fe, 0);
357 }
else if (fe->
ops.tuner_ops.calc_regs) {
358 fe->
ops.tuner_ops.calc_regs(fe, pllbuf + 1, 5);
360 zl10353_write(fe, pllbuf,
sizeof(pllbuf));
363 zl10353_single_write(fe, 0x5F, 0x13);
366 if (state->
config.no_tuner || fe->
ops.tuner_ops.calc_regs ==
NULL)
367 zl10353_single_write(fe,
FSM_GO, 0x01);
369 zl10353_single_write(fe,
TUNER_GO, 0x01);
374 static int zl10353_get_parameters(
struct dvb_frontend *fe)
380 static const u8 tps_fec_to_api[8] = {
391 s6 = zl10353_read_register(state,
STATUS_6);
392 s9 = zl10353_read_register(state,
STATUS_9);
393 if (s6 < 0 || s9 < 0)
395 if ((s6 & (1 << 5)) == 0 || (s9 & (1 << 4)) == 0)
404 switch ((tps >> 13) & 3) {
422 switch ((tps >> 2) & 3) {
440 switch ((tps >> 10) & 7) {
470 if ((s6 = zl10353_read_register(state,
STATUS_6)) < 0)
472 if ((s7 = zl10353_read_register(state,
STATUS_7)) < 0)
474 if ((s8 = zl10353_read_register(state,
STATUS_8)) < 0)
500 *ber = zl10353_read_register(state,
RS_ERR_CNT_2) << 16 |
507 static int zl10353_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
511 u16 signal = zl10353_read_register(state,
AGC_GAIN_1) << 10 |
512 zl10353_read_register(state,
AGC_GAIN_0) << 2 | 3;
525 zl10353_dump_regs(fe);
527 _snr = zl10353_read_register(state,
SNR);
528 *snr = 10 * _snr / 8;
538 ubl = zl10353_read_register(state,
RS_UBC_1) << 8 |
539 zl10353_read_register(state,
RS_UBC_0);
547 static int zl10353_get_tune_settings(
struct dvb_frontend *fe,
561 u8 zl10353_reset_attach[6] = { 0x50, 0x03, 0x64, 0x46, 0x15, 0x0F };
564 zl10353_dump_regs(fe);
565 if (state->
config.parallel_ts)
566 zl10353_reset_attach[2] &= ~0x20;
567 if (state->
config.clock_ctl_1)
568 zl10353_reset_attach[3] = state->
config.clock_ctl_1;
570 zl10353_reset_attach[4] = state->
config.pll_0;
573 if (zl10353_read_register(state, 0x50) != zl10353_reset_attach[1] ||
574 zl10353_read_register(state, 0x51) != zl10353_reset_attach[2]) {
575 zl10353_write(fe, zl10353_reset_attach,
576 sizeof(zl10353_reset_attach));
578 zl10353_dump_regs(fe);
589 if (state->
config.disable_i2c_gate_ctrl) {
598 return zl10353_single_write(fe, 0x62, val);
625 id = zl10353_read_register(state,
CHIP_ID);
642 .name =
"Zarlink ZL10353 DVB-T",
643 .frequency_min = 174000000,
644 .frequency_max = 862000000,
645 .frequency_stepsize = 166667,
646 .frequency_tolerance = 0,
656 .release = zl10353_release,
658 .init = zl10353_init,
659 .sleep = zl10353_sleep,
660 .i2c_gate_ctrl = zl10353_i2c_gate_ctrl,
661 .write = zl10353_write,
663 .set_frontend = zl10353_set_parameters,
664 .get_frontend = zl10353_get_parameters,
665 .get_tune_settings = zl10353_get_tune_settings,
667 .read_status = zl10353_read_status,
668 .read_ber = zl10353_read_ber,
669 .read_signal_strength = zl10353_read_signal_strength,
670 .read_snr = zl10353_read_snr,
671 .read_ucblocks = zl10353_read_ucblocks,
678 MODULE_PARM_DESC(debug_regs,
"Turn on/off frontend register dumps (default:off).");