25 #include <linux/slab.h>
26 #include <linux/module.h>
29 #include <linux/types.h>
45 #define dprintk(args...) \
48 printk(KERN_DEBUG args); \
84 memcpy(&cmdbuf[1], buf, len);
87 if (fe->
ops.i2c_gate_ctrl)
88 fe->
ops.i2c_gate_ctrl(fe, 1);
92 dprintk(
"%s: i2c error\n", __func__);
94 if (fe->
ops.i2c_gate_ctrl)
95 fe->
ops.i2c_gate_ctrl(fe, 0);
105 u8 reg[] = { start };
120 if (fe->
ops.i2c_gate_ctrl)
121 fe->
ops.i2c_gate_ctrl(fe, 1);
125 dprintk(
"%s: i2c error\n", __func__);
127 if (fe->
ops.i2c_gate_ctrl)
128 fe->
ops.i2c_gate_ctrl(fe, 0);
135 static int stv6110_read_reg(
struct dvb_frontend *fe,
int start)
138 stv6110_read_regs(fe, buf, start, 1);
146 stv6110_write_regs(fe, reg, 0, 1);
167 return symbol_rate + ((symbol_rate * rlf) / 100);
176 if ((bandwidth / 2) > 36000000)
178 else if ((bandwidth / 2) < 5000000)
181 r8 = (bandwidth / 2) / 1000000 - 5;
194 while ((i < 10) && (ret != 0)) {
209 u8 buf0[] = { 0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e };
215 ((((priv->
mclk / 1000000) - 16) & 0x1f) << 3);
223 stv6110_set_bandwidth(fe, 72000000);
231 u32 nbsteps, divider, psd2,
freq;
232 u8 regs[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
234 stv6110_read_regs(fe, regs, 0, 8);
244 freq = divider * (priv->
mclk / 1000);
245 freq /= (1 << (nbsteps + psd2));
258 u32 divider, ref,
p, presc,
i, result_freq, vco_freq;
259 s32 p_calc, p_calc_opt = 1000, r_div, r_div_opt = 0, p_val;
262 dprintk(
"%s, freq=%d kHz, mclk=%d Hz\n", __func__,
263 frequency, priv->
mclk);
268 ((((priv->
mclk / 1000000) - 16) & 0x1f) << 3);
271 if (fe->
ops.set_property && fe->
ops.get_property) {
273 dprintk(
"%s: Get Frontend parameters: srate=%d\n",
281 if (frequency <= 1023000) {
284 }
else if (frequency <= 1300000) {
287 }
else if (frequency <= 2046000) {
302 p_val = (
int)(1 << (p + 1)) * 10;
303 for (r_div = 0; r_div <= 3; r_div++) {
304 p_calc = (priv->
mclk / 100000);
305 p_calc /= (1 << (r_div + 1));
306 if ((abssub(p_calc, p_val)) < (abssub(p_calc_opt, p_val)))
309 p_calc_opt = (priv->
mclk / 100000);
310 p_calc_opt /= (1 << (r_div_opt + 1));
313 ref = priv->
mclk / ((1 << (r_div_opt + 1)) * (1 << (p + 1)));
314 divider = (((frequency * 1000) + (ref >> 1)) / ref);
334 while ((i < 10) && (ret != 0)) {
341 stv6110_get_frequency(fe, &result_freq);
343 vco_freq = divider * ((priv->
mclk / 1000) / ((1 << (r_div_opt + 1))));
344 dprintk(
"%s, stat1=%x, lo_freq=%d kHz, vco_frec=%d kHz\n", __func__,
345 ret, result_freq, vco_freq);
356 stv6110_set_bandwidth(fe, bandwidth);
361 static int stv6110_get_bandwidth(
struct dvb_frontend *fe,
u32 *bandwidth)
365 u8 regs[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
366 stv6110_read_regs(fe, regs, 0, 8);
370 *bandwidth = (r8 + 5) * 2000000;
377 .name =
"ST STV6110",
378 .frequency_min = 950000,
379 .frequency_max = 2150000,
380 .frequency_step = 1000,
382 .init = stv6110_init,
383 .release = stv6110_release,
384 .sleep = stv6110_sleep,
385 .set_params = stv6110_set_params,
386 .get_frequency = stv6110_get_frequency,
387 .set_frequency = stv6110_set_frequency,
388 .get_bandwidth = stv6110_get_bandwidth,
389 .set_bandwidth = stv6110_set_bandwidth,
398 u8 reg0[] = { 0x00, 0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e };
412 reg0[2] |= (config->
clk_div << 6);
414 if (fe->
ops.i2c_gate_ctrl)
415 fe->
ops.i2c_gate_ctrl(fe, 1);
419 if (fe->
ops.i2c_gate_ctrl)
420 fe->
ops.i2c_gate_ctrl(fe, 0);
437 memcpy(&fe->
ops.tuner_ops, &stv6110_tuner_ops,