30 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
37 static int zl10036_debug;
38 #define dprintk(level, args...) \
39 do { if (zl10036_debug & level) printk(KERN_DEBUG "zl10036: " args); \
42 #define deb_info(args...) dprintk(0x01, args)
43 #define deb_i2c(args...) dprintk(0x02, args)
63 #define _RDIV_REG 0x0a
64 #define _FR (_XTAL/_RDIV)
66 #define STATUS_POR 0x80
67 #define STATUS_FL 0x40
81 __func__, state->
config->tuner_address);
85 deb_i2c(
"R(status): %02x [FL=%d]\n", status,
88 deb_info(
"%s: Power-On-Reset bit enabled - "
89 "need to initialize the tuner\n", __func__);
97 { .
addr = state->
config->tuner_address, .flags = 0,
98 .buf =
buf, .len = count },
103 if (zl10036_debug & 0x02) {
106 if ((buf[0] & 0x80) == 0x00)
108 else if ((buf[0] & 0xc0) == 0x80)
110 else if ((buf[0] & 0xf0) == 0xc0)
112 else if ((buf[0] & 0xf0) == 0xd0)
114 else if ((buf[0] & 0xf0) == 0xe0)
116 else if ((buf[0] & 0xf0) == 0xf0)
122 for (i = 0; i <
count; i++)
150 u8 buf[] = { 0xf0, 0x80 };
155 if (fe->
ops.i2c_gate_ctrl)
156 fe->
ops.i2c_gate_ctrl(fe, 1);
158 ret = zl10036_write(state, buf,
sizeof(buf));
160 if (fe->
ops.i2c_gate_ctrl)
161 fe->
ops.i2c_gate_ctrl(fe, 0);
189 div = (frequency +
_FR/2) /
_FR;
194 buf[0] = (div >> 8) & 0x7f;
195 buf[1] = (div >> 0) & 0xff;
197 deb_info(
"%s: ftodo=%u fpriv=%u ferr=%d div=%u\n", __func__,
198 frequency, state->
frequency, foffset, div);
200 return zl10036_write(state, buf,
sizeof(buf));
214 u8 zl10036_rsd_off[] = { 0xc8 };
222 #define _BR_MAXIMUM (_XTAL/575)
232 br = ((
_XTAL * 21 * 1000) / (fbw * 419));
245 bf = (fbw * br * 1257) / (
_XTAL * 1000) - 1;
251 buf_bf[1] = (bf << 1) & 0x7e;
252 buf_br[1] = (br << 2) & 0x7c;
253 deb_info(
"%s: BW=%d br=%u bf=%u\n", __func__, fbw, br, bf);
255 if (br != state->
br) {
256 ret = zl10036_write(state, buf_br,
sizeof(buf_br));
261 if (bf != state->
bf) {
262 ret = zl10036_write(state, buf_bf,
sizeof(buf_bf));
271 ret = zl10036_write(state, zl10036_rsd_off,
272 sizeof(zl10036_rsd_off));
283 static int zl10036_set_gain_params(
struct zl10036_state *state,
295 buf[0] = 0x80 | ((rfg << 5) & 0x20)
296 | ((ba << 3) & 0x18) | ((bg << 1) & 0x06);
298 if (!state->
config->rf_loop_enable)
304 deb_info(
"%s: c=%u rfg=%u ba=%u bg=%u\n", __func__, c, rfg, ba, bg);
305 return zl10036_write(state, buf,
sizeof(buf));
320 if ((frequency < fe->
ops.info.frequency_min)
321 || (frequency > fe->
ops.info.frequency_max))
338 if (frequency < 950000)
340 else if (frequency < 1250000)
342 else if (frequency < 1750000)
344 else if (frequency < 2175000)
349 if (fe->
ops.i2c_gate_ctrl)
350 fe->
ops.i2c_gate_ctrl(fe, 1);
352 ret = zl10036_set_gain_params(state, c);
356 ret = zl10036_set_frequency(state, p->
frequency);
360 ret = zl10036_set_bandwidth(state, fbw);
365 for (i = 0; i < 20; i++) {
366 ret = zl10036_read_status_reg(state);
378 if (fe->
ops.i2c_gate_ctrl)
379 fe->
ops.i2c_gate_ctrl(fe, 0);
384 static int zl10036_get_frequency(
struct dvb_frontend *fe,
u32 *frequency)
399 u8 zl10036_init_tab[][2] = {
414 if (!state->
config->rf_loop_enable)
415 zl10036_init_tab[1][0] |= 0x01;
419 for (i = 0; i <
ARRAY_SIZE(zl10036_init_tab); i++) {
420 ret = zl10036_write(state, zl10036_init_tab[i], 2);
433 if (fe->
ops.i2c_gate_ctrl)
434 fe->
ops.i2c_gate_ctrl(fe, 1);
436 ret = zl10036_read_status_reg(state);
441 ret = zl10036_init_regs(state);
443 if (fe->
ops.i2c_gate_ctrl)
444 fe->
ops.i2c_gate_ctrl(fe, 0);
451 .name =
"Zarlink ZL10036",
452 .frequency_min = 950000,
453 .frequency_max = 2175000
455 .init = zl10036_init,
456 .release = zl10036_release,
457 .sleep = zl10036_sleep,
458 .set_params = zl10036_set_params,
459 .get_frequency = zl10036_get_frequency,
481 if (fe->
ops.i2c_gate_ctrl)
482 fe->
ops.i2c_gate_ctrl(fe, 1);
484 ret = zl10036_read_status_reg(state);
490 ret = zl10036_init_regs(state);
497 if (fe->
ops.i2c_gate_ctrl)
498 fe->
ops.i2c_gate_ctrl(fe, 0);
502 memcpy(&fe->
ops.tuner_ops, &zl10036_tuner_ops,