24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
41 #define dprintk(args...) \
43 if (debug) printk(KERN_DEBUG "l64781: " args); \
56 struct i2c_msg msg = { .addr = state->
config->demod_address, .flags = 0, .buf =
buf, .len = 2 };
59 dprintk (
"%s: write_reg error (reg == %02x) = %02x!\n",
62 return (ret != 1) ? -1 : 0;
70 struct i2c_msg msg [] = { { .
addr = state->
config->demod_address, .flags = 0, .buf = b0, .len = 1 },
71 { .addr = state->
config->demod_address, .flags =
I2C_M_RD, .buf = b1, .len = 1 } };
75 if (ret != 2)
return ret;
82 l64781_writereg (state, 0x2a, 0x00);
83 l64781_writereg (state, 0x2a, 0x01);
90 l64781_writereg (state, 0x2a, 0x02);
98 l64781_writereg (state, 0x07, 0x9e);
99 l64781_writereg (state, 0x08, 0);
100 l64781_writereg (state, 0x09, 0);
101 l64781_writereg (state, 0x0a, 0);
102 l64781_writereg (state, 0x07, 0x8e);
103 l64781_writereg (state, 0x0e, 0);
104 l64781_writereg (state, 0x11, 0x80);
105 l64781_writereg (state, 0x10, 0);
106 l64781_writereg (state, 0x12, 0);
107 l64781_writereg (state, 0x13, 0);
108 l64781_writereg (state, 0x11, 0x00);
111 static int reset_and_configure (
struct l64781_state* state)
113 u8 buf [] = { 0x06 };
114 struct i2c_msg msg = { .
addr = 0x00, .flags = 0, .buf =
buf, .len = 1 };
120 static int apply_frontend_param(
struct dvb_frontend *fe)
125 static const u8 fec_tab[] = { 7, 0, 1, 2, 9, 3, 10, 4 };
127 static const u8 qam_tab [] = { 2, 4, 0, 6 };
128 static const u8 guard_tab [] = { 1, 2, 4, 8 };
130 static const u32 ppm = 8000;
131 u32 ddfs_offset_fixed;
155 if (fe->
ops.tuner_ops.set_params) {
156 fe->
ops.tuner_ops.set_params(fe);
157 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
191 ddfs_offset_fixed = 0x4000-(ppm<<16)/bw/1000000;
194 init_freq = (((8
UL<<25) + (8
UL<<19) / 25*ppm / (15625/25)) /
199 spi_bias = 378 * (1 << 10);
206 spi_bias /= 1000 + ppm/1000;
217 l64781_writereg (state, 0x04, val0x04);
218 l64781_writereg (state, 0x05, val0x05);
219 l64781_writereg (state, 0x06, val0x06);
224 l64781_writereg (state, 0x15,
226 l64781_writereg (state, 0x16, init_freq & 0xff);
227 l64781_writereg (state, 0x17, (init_freq >> 8) & 0xff);
228 l64781_writereg (state, 0x18, (init_freq >> 16) & 0xff);
230 l64781_writereg (state, 0x1b, spi_bias & 0xff);
231 l64781_writereg (state, 0x1c, (spi_bias >> 8) & 0xff);
232 l64781_writereg (state, 0x1d, ((spi_bias >> 16) & 0x7f) |
235 l64781_writereg (state, 0x22, ddfs_offset_fixed & 0xff);
236 l64781_writereg (state, 0x23, (ddfs_offset_fixed >> 8) & 0x3f);
238 l64781_readreg (state, 0x00);
239 l64781_readreg (state, 0x01);
253 tmp = l64781_readreg(state, 0x04);
268 switch((tmp >> 2) & 3) {
279 tmp = l64781_readreg(state, 0x05);
297 printk(
"Unexpected value for code_rate_HP\n");
299 switch((tmp >> 3) & 7) {
316 printk(
"Unexpected value for code_rate_LP\n");
319 tmp = l64781_readreg(state, 0x06);
333 switch((tmp >> 2) & 7) {
347 printk(
"Unexpected value for hierarchy\n");
351 tmp = l64781_readreg (state, 0x1d);
354 tmp = (
int) (l64781_readreg (state, 0x08) |
355 (l64781_readreg (state, 0x09) << 8) |
356 (l64781_readreg (state, 0x0a) << 16));
365 int sync = l64781_readreg (state, 0x32);
366 int gain = l64781_readreg (state, 0x0e);
368 l64781_readreg (state, 0x00);
369 l64781_readreg (state, 0x01);
397 *ber = l64781_readreg (state, 0x39)
398 | (l64781_readreg (state, 0x3a) << 8);
403 static int l64781_read_signal_strength(
struct dvb_frontend* fe,
u16* signal_strength)
407 u8 gain = l64781_readreg (state, 0x0e);
408 *signal_strength = (gain << 8) | gain;
417 u8 avg_quality = 0xff - l64781_readreg (state, 0x33);
418 *snr = (avg_quality << 8) | avg_quality;
423 static int l64781_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
427 *ucblocks = l64781_readreg (state, 0x37)
428 | (l64781_readreg (state, 0x38) << 8);
438 return l64781_writereg (state, 0x3e, 0x5a);
445 reset_and_configure (state);
448 l64781_writereg (state, 0x3e, 0xa5);
451 l64781_writereg (state, 0x2a, 0x04);
452 l64781_writereg (state, 0x2a, 0x00);
456 l64781_writereg (state, 0x07, 0x8e);
459 l64781_writereg (state, 0x0b, 0x81);
462 l64781_writereg (state, 0x0c, 0x84);
465 l64781_writereg (state, 0x0d, 0x8c);
473 l64781_writereg (state, 0x1e, 0x09);
484 static int l64781_get_tune_settings(
struct dvb_frontend* fe,
524 if (reset_and_configure(state) < 0) {
525 dprintk(
"No response to reset and configure broadcast...\n");
531 dprintk(
"No response to read on I2C bus\n");
536 reg0x3e = l64781_readreg(state, 0x3e);
540 dprintk(
"Device doesn't look like L64781\n");
545 l64781_writereg (state, 0x3e, 0x5a);
548 if (l64781_readreg(state, 0x1a) != 0) {
549 dprintk(
"Read 1 returned unexpcted value\n");
554 l64781_writereg (state, 0x3e, 0xa5);
557 if (l64781_readreg(state, 0x1a) != 0xa1) {
558 dprintk(
"Read 2 returned unexpcted value\n");
569 l64781_writereg (state, 0x3e, reg0x3e);
577 .name =
"LSI L64781 DVB-T",
580 .frequency_stepsize = 166666,
589 .release = l64781_release,
592 .sleep = l64781_sleep,
594 .set_frontend = apply_frontend_param,
596 .get_tune_settings = l64781_get_tune_settings,
598 .read_status = l64781_read_status,
599 .read_ber = l64781_read_ber,
600 .read_signal_strength = l64781_read_signal_strength,
601 .read_snr = l64781_read_snr,
602 .read_ucblocks = l64781_read_ucblocks,