22 #include <linux/errno.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
28 #include <asm/div64.h>
49 static u8 ves1820_inittab[] = {
50 0x69, 0x6A, 0x93, 0x1A, 0x12, 0x46, 0x26, 0x1A,
51 0x43, 0x6A, 0xAA, 0xAA, 0x1E, 0x85, 0x43, 0x20,
52 0xE0, 0x00, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
54 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56 0x00, 0x00, 0x00, 0x00, 0x40
62 struct i2c_msg msg = {.addr = state->
config->demod_address,.flags = 0,.buf =
buf,.len = 3 };
68 printk(
"ves1820: %s(): writereg error (reg == 0x%02x, "
69 "val == 0x%02x, ret == %i)\n", __func__, reg, data, ret);
76 u8 b0[] = { 0x00, reg };
79 {.
addr = state->
config->demod_address,.flags = 0,.buf = b0,.len = 2},
80 {.addr = state->
config->demod_address,.flags =
I2C_M_RD,.buf = b1,.len = 1}
87 printk(
"ves1820: %s(): readreg error (reg == 0x%02x, "
88 "ret == %i)\n", __func__, reg, ret);
95 reg0 |= state->
reg0 & 0x62;
98 if (!state->
config->invert) reg0 |= 0x20;
101 if (!state->
config->invert) reg0 &= ~0x20;
105 ves1820_writereg(state, 0x00, reg0 & 0xfe);
106 ves1820_writereg(state, 0x00, reg0 | 0x01);
113 static int ves1820_set_symbolrate(
struct ves1820_state *state,
u32 symbolrate)
125 if (symbolrate > state->
config->xin / 2)
126 symbolrate = state->
config->xin / 2;
128 if (symbolrate < 500000)
131 if (symbolrate < state->
config->xin / 16)
133 if (symbolrate < state->
config->xin / 32)
135 if (symbolrate < state->
config->xin / 64)
139 fpxin = state->
config->xin * 10;
140 fptmp = fpxin;
do_div(fptmp, 123);
141 if (symbolrate < fptmp)
143 fptmp = fpxin;
do_div(fptmp, 160);
144 if (symbolrate < fptmp)
146 fptmp = fpxin;
do_div(fptmp, 246);
147 if (symbolrate < fptmp)
149 fptmp = fpxin;
do_div(fptmp, 320);
150 if (symbolrate < fptmp)
152 fptmp = fpxin;
do_div(fptmp, 492);
153 if (symbolrate < fptmp)
155 fptmp = fpxin;
do_div(fptmp, 640);
156 if (symbolrate < fptmp)
158 fptmp = fpxin;
do_div(fptmp, 984);
159 if (symbolrate < fptmp)
162 fin = state->
config->xin >> 4;
164 ratio = (symbolrate << 4) / fin;
165 tmp = ((symbolrate << 4) % fin) << 8;
166 ratio = (ratio << 8) + tmp / fin;
167 tmp = (tmp % fin) << 8;
171 BDRI = (((state->
config->xin << 5) / symbolrate) + 1) / 2;
176 SFIL = (SFIL << 4) | ves1820_inittab[0x0E];
178 NDEC = (NDEC << 6) | ves1820_inittab[0x03];
180 ves1820_writereg(state, 0x03, NDEC);
181 ves1820_writereg(state, 0x0a, BDR & 0xff);
182 ves1820_writereg(state, 0x0b, (BDR >> 8) & 0xff);
183 ves1820_writereg(state, 0x0c, (BDR >> 16) & 0x3f);
185 ves1820_writereg(state, 0x0d, BDRI);
186 ves1820_writereg(state, 0x0e, SFIL);
196 ves1820_writereg(state, 0, 0);
198 for (i = 0; i <
sizeof(ves1820_inittab); i++)
199 ves1820_writereg(state, i, ves1820_inittab[i]);
200 if (state->
config->selagc)
201 ves1820_writereg(state, 2, ves1820_inittab[2] | 0x08);
203 ves1820_writereg(state, 0x34, state->
pwm);
208 static int ves1820_set_parameters(
struct dvb_frontend *fe)
212 static const u8 reg0x00[] = { 0x00, 0x04, 0x08, 0x0c, 0x10 };
213 static const u8 reg0x01[] = { 140, 140, 106, 100, 92 };
214 static const u8 reg0x05[] = { 135, 100, 70, 54, 38 };
215 static const u8 reg0x08[] = { 162, 116, 67, 52, 35 };
216 static const u8 reg0x09[] = { 145, 150, 106, 126, 107 };
219 if (real_qam < 0 || real_qam > 4)
222 if (fe->
ops.tuner_ops.set_params) {
223 fe->
ops.tuner_ops.set_params(fe);
224 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
228 ves1820_writereg(state, 0x34, state->
pwm);
230 ves1820_writereg(state, 0x01, reg0x01[real_qam]);
231 ves1820_writereg(state, 0x05, reg0x05[real_qam]);
232 ves1820_writereg(state, 0x08, reg0x08[real_qam]);
233 ves1820_writereg(state, 0x09, reg0x09[real_qam]);
235 ves1820_setup_reg0(state, reg0x00[real_qam], p->
inversion);
236 ves1820_writereg(state, 2, ves1820_inittab[2] | (state->
config->selagc ? 0x08 : 0));
246 sync = ves1820_readreg(state, 0x11);
270 u32 _ber = ves1820_readreg(state, 0x14) |
271 (ves1820_readreg(state, 0x15) << 8) |
272 ((ves1820_readreg(state, 0x16) & 0x0f) << 16);
278 static int ves1820_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
282 u8 gain = ves1820_readreg(state, 0x17);
283 *strength = (gain << 8) | gain;
292 u8 quality = ~ves1820_readreg(state, 0x18);
293 *snr = (quality << 8) | quality;
298 static int ves1820_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
302 *ucblocks = ves1820_readreg(state, 0x13) & 0x7f;
303 if (*ucblocks == 0x7f)
304 *ucblocks = 0xffffffff;
307 ves1820_writereg(state, 0x10, ves1820_inittab[0x10] & 0xdf);
308 ves1820_writereg(state, 0x10, ves1820_inittab[0x10]);
313 static int ves1820_get_frontend(
struct dvb_frontend *fe)
320 sync = ves1820_readreg(state, 0x11);
321 afc = ves1820_readreg(state, 0x19);
324 printk(sync & 2 ?
"ves1820: AFC (%d) %dHz\n" :
325 "ves1820: [AFC (%d) %dHz]\n", afc, -((
s32) p->
symbol_rate * afc) >> 10);
328 if (!state->
config->invert) {
349 ves1820_writereg(state, 0x1b, 0x02);
350 ves1820_writereg(state, 0x00, 0x80);
384 state->
reg0 = ves1820_inittab[0];
390 if ((ves1820_readreg(state, 0x1a) & 0xf0) != 0x70)
394 printk(
"ves1820: pwm=0x%02x\n", state->
pwm);
398 state->
frontend.ops.info.symbol_rate_min = (state->
config->xin / 2) / 64;
399 state->
frontend.ops.info.symbol_rate_max = (state->
config->xin / 2) / 4;
412 .name =
"VLSI VES1820 DVB-C",
413 .frequency_stepsize = 62500,
414 .frequency_min = 47000000,
415 .frequency_max = 862000000,
424 .release = ves1820_release,
426 .init = ves1820_init,
427 .sleep = ves1820_sleep,
429 .set_frontend = ves1820_set_parameters,
430 .get_frontend = ves1820_get_frontend,
431 .get_tune_settings = ves1820_get_tune_settings,
433 .read_status = ves1820_read_status,
434 .read_ber = ves1820_read_ber,
435 .read_signal_strength = ves1820_read_signal_strength,
436 .read_snr = ves1820_read_snr,
437 .read_ucblocks = ves1820_read_ucblocks,