23 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
43 #define dprintk(args...) \
45 if (debug) printk(KERN_DEBUG "cx22700: " args); \
48 static u8 init_tab [] = {
74 struct i2c_msg msg = { .addr = state->
config->demod_address, .flags = 0, .buf =
buf, .len = 2 };
81 printk(
"%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
82 __func__, reg, data, ret);
84 return (ret != 1) ? -1 : 0;
92 struct i2c_msg msg [] = { { .
addr = state->
config->demod_address, .flags = 0, .buf = b0, .len = 1 },
93 { .addr = state->
config->demod_address, .flags =
I2C_M_RD, .buf = b1, .len = 1 } };
99 if (ret != 2)
return -
EIO;
104 static int cx22700_set_inversion (
struct cx22700_state* state,
int inversion)
114 val = cx22700_readreg (state, 0x09);
115 return cx22700_writereg (state, 0x09, val | 0x01);
117 val = cx22700_readreg (state, 0x09);
118 return cx22700_writereg (state, 0x09, val & 0xfe);
127 static const u8 qam_tab [4] = { 0, 1, 0, 2 };
128 static const u8 fec_tab [6] = { 0, 1, 2, 0, 3, 4 };
163 cx22700_writereg (state, 0x09, cx22700_readreg (state, 0x09 | 0x10));
165 cx22700_writereg (state, 0x09, cx22700_readreg (state, 0x09 & ~0x10));
170 cx22700_writereg (state, 0x04, val);
175 cx22700_writereg (state, 0x05, val);
180 cx22700_writereg (state, 0x06, val);
182 cx22700_writereg (state, 0x08, 0x04 | 0x02);
183 cx22700_writereg (state, 0x08, 0x04);
198 if (!(cx22700_readreg(state, 0x07) & 0x20))
201 val = cx22700_readreg (state, 0x01);
208 if (((val >> 3) & 0x3) > 2)
213 val = cx22700_readreg (state, 0x02);
215 if (((val >> 3) & 0x07) > 4)
220 if ((val & 0x07) > 4)
225 val = cx22700_readreg (state, 0x03);
238 dprintk(
"cx22700_init: init chip\n");
240 cx22700_writereg (state, 0x00, 0x02);
241 cx22700_writereg (state, 0x00, 0x00);
245 for (i=0; i<
sizeof(init_tab); i+=2)
246 cx22700_writereg (state, init_tab[i], init_tab[i+1]);
248 cx22700_writereg (state, 0x00, 0x01);
257 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9)
258 | (cx22700_readreg (state, 0x0e) << 1);
259 u8 sync = cx22700_readreg (state, 0x07);
285 *ber = cx22700_readreg (state, 0x0c) & 0x7f;
286 cx22700_writereg (state, 0x0c, 0x00);
291 static int cx22700_read_signal_strength(
struct dvb_frontend* fe,
u16* signal_strength)
295 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9)
296 | (cx22700_readreg (state, 0x0e) << 1);
297 *signal_strength = ~rs_ber;
306 u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9)
307 | (cx22700_readreg (state, 0x0e) << 1);
313 static int cx22700_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
317 *ucblocks = cx22700_readreg (state, 0x0f);
318 cx22700_writereg (state, 0x0f, 0x00);
323 static int cx22700_set_frontend(
struct dvb_frontend *fe)
328 cx22700_writereg (state, 0x00, 0x02);
329 cx22700_writereg (state, 0x00, 0x00);
331 if (fe->
ops.tuner_ops.set_params) {
332 fe->
ops.tuner_ops.set_params(fe);
333 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
336 cx22700_set_inversion(state, c->
inversion);
337 cx22700_set_tps(state, c);
338 cx22700_writereg (state, 0x37, 0x01);
339 cx22700_writereg (state, 0x00, 0x01);
344 static int cx22700_get_frontend(
struct dvb_frontend *fe)
348 u8 reg09 = cx22700_readreg (state, 0x09);
351 return cx22700_get_tps(state, c);
359 return cx22700_writereg(state, 0x0a, 0x00);
361 return cx22700_writereg(state, 0x0a, 0x01);
395 if (cx22700_readreg(state, 0x07) < 0)
goto error;
410 .name =
"Conexant CX22700 DVB-T",
411 .frequency_min = 470000000,
412 .frequency_max = 860000000,
413 .frequency_stepsize = 166667,
420 .release = cx22700_release,
422 .init = cx22700_init,
423 .i2c_gate_ctrl = cx22700_i2c_gate_ctrl,
425 .set_frontend = cx22700_set_frontend,
426 .get_frontend = cx22700_get_frontend,
427 .get_tune_settings = cx22700_get_tune_settings,
429 .read_status = cx22700_read_status,
430 .read_ber = cx22700_read_ber,
431 .read_signal_strength = cx22700_read_signal_strength,
432 .read_snr = cx22700_read_snr,
433 .read_ucblocks = cx22700_read_ucblocks,