26 #include <linux/kernel.h>
27 #include <linux/module.h>
29 #include <linux/string.h>
30 #include <linux/slab.h>
53 #define dprintk if (debug) printk
55 #define DEMOD_VES1893 0
56 #define DEMOD_VES1993 1
58 static u8 init_1893_tab [] = {
59 0x01, 0xa4, 0x35, 0x80, 0x2a, 0x0b, 0x55, 0xc4,
60 0x09, 0x69, 0x00, 0x86, 0x4c, 0x28, 0x7f, 0x00,
61 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x80, 0x00, 0x21, 0xb0, 0x14, 0x00, 0xdc, 0x00,
63 0x81, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65 0x00, 0x55, 0x00, 0x00, 0x7f, 0x00
68 static u8 init_1993_tab [] = {
69 0x00, 0x9c, 0x35, 0x80, 0x6a, 0x09, 0x72, 0x8c,
70 0x09, 0x6b, 0x00, 0x00, 0x4c, 0x08, 0x00, 0x00,
71 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0x80, 0x40, 0x21, 0xb0, 0x00, 0x00, 0x00, 0x10,
73 0x81, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00,
75 0x00, 0x55, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03,
76 0x00, 0x00, 0x0e, 0x80, 0x00
79 static u8 init_1893_wtab[] =
81 1,1,1,1,1,1,1,1, 1,1,0,0,1,1,0,0,
82 0,1,0,0,0,0,0,0, 1,0,1,1,0,0,0,1,
83 1,1,1,0,0,0,0,0, 0,0,1,1,0,0,0,0,
87 static u8 init_1993_wtab[] =
89 1,1,1,1,1,1,1,1, 1,1,0,0,1,1,0,0,
90 0,1,0,0,0,0,0,0, 1,1,1,1,0,0,0,1,
91 1,1,1,0,0,0,0,0, 0,0,1,1,0,0,0,0,
92 1,1,1,0,1,1,1,1, 1,1,1,1,1
98 struct i2c_msg msg = { .addr = state->
config->demod_address, .flags = 0, .buf =
buf, .len = 3 };
102 dprintk (
"%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __func__, err, reg, data);
112 u8 b0 [] = { 0x00, reg };
114 struct i2c_msg msg [] = { { .
addr = state->
config->demod_address, .flags = 0, .buf = b0, .len = 2 },
115 { .addr = state->
config->demod_address, .flags =
I2C_M_RD, .buf = b1, .len = 1 } };
119 if (ret != 2)
return ret;
156 return ves1x93_writereg (state, 0x0c, (state->
init_1x93_tab[0x0c] & 0x3f) | val);
162 return ves1x93_writereg (state, 0x0d, 0x08);
163 else if (fec < FEC_1_2 || fec >
FEC_8_9)
166 return ves1x93_writereg (state, 0x0d, fec -
FEC_1_2);
171 return FEC_1_2 + ((ves1x93_readreg (state, 0x0d) >> 4) & 0x7);
178 u8 ADCONF, FCONF, FNR, AGCR;
183 dprintk(
"%s: srate == %d\n", __func__, (
unsigned int) srate);
185 if (srate > state->
config->xin/2)
186 srate = state->
config->xin/2;
191 #define MUL (1UL<<26)
193 FIN = (state->
config->xin + 6000) >> 4;
198 tmp = (tmp %
FIN) << 8;
199 ratio = (ratio << 8) + tmp / FIN;
201 tmp = (tmp %
FIN) << 8;
202 ratio = (ratio << 8) + tmp / FIN;
206 if (ratio < MUL/3) FNR = 0;
207 if (ratio < (MUL*11)/50) FNR = 1;
208 if (ratio < MUL/6) FNR = 2;
209 if (ratio < MUL/9) FNR = 3;
210 if (ratio < MUL/12) FNR = 4;
211 if (ratio < (MUL*11)/200) FNR = 5;
212 if (ratio < MUL/24) FNR = 6;
213 if (ratio < (MUL*27)/1000) FNR = 7;
214 if (ratio < MUL/48) FNR = 8;
215 if (ratio < (MUL*137)/10000) FNR = 9;
223 FCONF = 0x88 | (FNR >> 1) | ((FNR & 0x01) << 5);
227 BDR = (( (ratio << (FNR >> 1)) >> 4) + 1) >> 1;
228 BDRI = ( ((FIN << 8) / ((srate << (FNR >> 1)) >> 2)) + 1) >> 1;
231 dprintk(
"ratio= %08x\n", (
unsigned int) ratio);
232 dprintk(
"BDR= %08x\n", (
unsigned int) BDR);
233 dprintk(
"BDRI= %02x\n", (
unsigned int) BDRI);
238 ves1x93_writereg (state, 0x06, 0xff & BDR);
239 ves1x93_writereg (state, 0x07, 0xff & (BDR >> 8));
240 ves1x93_writereg (state, 0x08, 0x0f & (BDR >> 16));
242 ves1x93_writereg (state, 0x09, BDRI);
243 ves1x93_writereg (state, 0x20, ADCONF);
244 ves1x93_writereg (state, 0x21, FCONF);
247 if (state->
config->invert_pwm)
255 ves1x93_writereg (state, 0x05, AGCR);
259 ves1x93_clr_bit (state);
270 dprintk(
"%s: init chip\n", __func__);
272 for (i = 0; i < state->
tab_size; i++) {
276 if (state->
config->invert_pwm && (i == 0x05)) val |= 0x20;
277 ves1x93_writereg (state, i, val);
290 return ves1x93_writereg (state, 0x1f, 0x20);
292 return ves1x93_writereg (state, 0x1f, 0x30);
294 return ves1x93_writereg (state, 0x1f, 0x00);
304 u8 sync = ves1x93_readreg (state, 0x0e);
316 while ((sync & 0x03) != 0x03 && (sync & 0x0c) && maxtry--) {
318 sync = ves1x93_readreg (state, 0x0e);
335 if ((sync & 0x1f) == 0x1f)
345 *ber = ves1x93_readreg (state, 0x15);
346 *ber |= (ves1x93_readreg (state, 0x16) << 8);
347 *ber |= ((ves1x93_readreg (state, 0x17) & 0x0F) << 16);
353 static int ves1x93_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
357 u8 signal = ~ves1x93_readreg (state, 0x0b);
358 *strength = (signal << 8) | signal;
367 u8 _snr = ~ves1x93_readreg (state, 0x1c);
368 *snr = (_snr << 8) | _snr;
373 static int ves1x93_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
377 *ucblocks = ves1x93_readreg (state, 0x18) & 0x7f;
379 if (*ucblocks == 0x7f)
380 *ucblocks = 0xffffffff;
382 ves1x93_writereg (state, 0x18, 0x00);
383 ves1x93_writereg (state, 0x18, 0x80);
388 static int ves1x93_set_frontend(
struct dvb_frontend *fe)
393 if (fe->
ops.tuner_ops.set_params) {
394 fe->
ops.tuner_ops.set_params(fe);
395 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
397 ves1x93_set_inversion (state, p->
inversion);
406 static int ves1x93_get_frontend(
struct dvb_frontend *fe)
412 afc = ((
int)((
char)(ves1x93_readreg (state, 0x0a) << 1)))/2;
422 p->
inversion = (ves1x93_readreg (state, 0x0f) & 2) ?
434 return ves1x93_writereg (state, 0x00, 0x08);
448 return ves1x93_writereg(state, 0x00, 0x11);
450 return ves1x93_writereg(state, 0x00, 0x01);
472 identity = ves1x93_readreg(state, 0x1e);
475 printk(
"ves1x93: Detected ves1893a rev1\n");
479 state->
tab_size =
sizeof(init_1893_tab);
483 printk(
"ves1x93: Detected ves1893a rev2\n");
487 state->
tab_size =
sizeof(init_1893_tab);
491 printk(
"ves1x93: Detected ves1993\n");
495 state->
tab_size =
sizeof(init_1993_tab);
515 .name =
"VLSI VES1x93 DVB-S",
516 .frequency_min = 950000,
517 .frequency_max = 2150000,
518 .frequency_stepsize = 125,
519 .frequency_tolerance = 29500,
520 .symbol_rate_min = 1000000,
521 .symbol_rate_max = 45000000,
529 .release = ves1x93_release,
531 .init = ves1x93_init,
532 .sleep = ves1x93_sleep,
533 .i2c_gate_ctrl = ves1x93_i2c_gate_ctrl,
535 .set_frontend = ves1x93_set_frontend,
536 .get_frontend = ves1x93_get_frontend,
538 .read_status = ves1x93_read_status,
539 .read_ber = ves1x93_read_ber,
540 .read_signal_strength = ves1x93_read_signal_strength,
541 .read_snr = ves1x93_read_snr,
542 .read_ucblocks = ves1x93_read_ucblocks,
544 .set_voltage = ves1x93_set_voltage,