22 #include <linux/module.h>
24 #include <linux/string.h>
25 #include <linux/slab.h>
33 #define dprintk(args...) \
36 printk(KERN_DEBUG args); \
72 u8 regbuf[] = { reg };
90 dprintk(
"%s: i2c read error\n", __func__);
112 memcpy(&buf[1], src, count);
114 dprintk(
"%s: i2c write error\n", __func__);
121 static inline int zl10039_readreg(
struct zl10039_state *state,
124 return zl10039_read(state, reg, val, 1);
127 static inline int zl10039_writereg(
struct zl10039_state *state,
131 return zl10039_write(state, reg, &val, 1);
140 if (fe->
ops.i2c_gate_ctrl)
141 fe->
ops.i2c_gate_ctrl(fe, 1);
143 ret = zl10039_writereg(state,
GENERAL, 0x40);
145 dprintk(
"Note: i2c write error normal when resetting the "
149 ret = zl10039_writereg(state,
GENERAL, 0x01);
151 dprintk(
"Tuner power up failed\n");
154 if (fe->
ops.i2c_gate_ctrl)
155 fe->
ops.i2c_gate_ctrl(fe, 0);
166 if (fe->
ops.i2c_gate_ctrl)
167 fe->
ops.i2c_gate_ctrl(fe, 1);
168 ret = zl10039_writereg(state,
GENERAL, 0x80);
170 dprintk(
"Tuner sleep failed\n");
173 if (fe->
ops.i2c_gate_ctrl)
174 fe->
ops.i2c_gate_ctrl(fe, 0);
190 dprintk(
"Set frequency = %d, symbol rate = %d\n",
198 bf = ((fbw * 5088) / 1011100) - 1;
201 buf[0] = (div >> 8) & 0x7f;
202 buf[1] = (div >> 0) & 0xff;
214 if (fe->
ops.i2c_gate_ctrl)
215 fe->
ops.i2c_gate_ctrl(fe, 1);
217 ret = zl10039_writereg(state,
BASE1, 0x0A);
221 ret = zl10039_write(state,
PLL0, buf,
sizeof(buf));
225 ret = zl10039_writereg(state,
BASE1, 0x6A);
230 if (fe->
ops.i2c_gate_ctrl)
231 fe->
ops.i2c_gate_ctrl(fe, 0);
234 dprintk(
"Error setting tuner\n");
249 .release = zl10039_release,
250 .init = zl10039_init,
251 .sleep = zl10039_sleep,
252 .set_params = zl10039_set_params,
269 if (fe->
ops.i2c_gate_ctrl)
270 fe->
ops.i2c_gate_ctrl(fe, 1);
272 if (zl10039_readreg(state,
GENERAL, &state->
id) < 0) {
274 if (fe->
ops.i2c_gate_ctrl)
275 fe->
ops.i2c_gate_ctrl(fe, 0);
279 if (fe->
ops.i2c_gate_ctrl)
280 fe->
ops.i2c_gate_ctrl(fe, 0);
282 state->
id = state->
id & 0x0f;
286 "Zarlink ZL10039 DVB-S tuner");
289 dprintk(
"Chip ID=%x does not match a known type\n", state->
id);
295 dprintk(
"Tuner attached @ i2c address 0x%02x\n", i2c_addr);