22 #include <linux/module.h>
24 #include <linux/videodev2.h>
27 #include <linux/i2c.h>
28 #include <linux/slab.h>
36 #define dprintk(args...) \
39 printk(KERN_DEBUG "max2165: " args); \
55 dprintk(
"%s: reg=0x%02X, data=0x%02X\n", __func__, reg, data);
60 dprintk(
"%s: error reg=0x%x, data=0x%x, ret=%i\n",
61 __func__, reg, data, ret);
63 return (ret != 1) ? -
EIO : 0;
74 { .
addr = dev_addr, .flags = 0, .buf = b0, .len = 1 },
75 { .addr = dev_addr, .flags =
I2C_M_RD, .buf = b1, .len = 1 },
80 dprintk(
"%s: error reg=0x%x, ret=%i\n", __func__, reg, ret);
86 dprintk(
"%s: reg=0x%02X, data=0x%02X\n",
87 __func__, reg, b1[0]);
91 static int max2165_mask_write_reg(
struct max2165_priv *priv,
u8 reg,
98 ret = max2165_read_reg(priv, reg, &v);
103 ret = max2165_write_reg(priv, reg, v);
108 static int max2165_read_rom_table(
struct max2165_priv *priv)
113 for (i = 0; i < 3; i++) {
145 max2165_mask_write_reg(priv,
REG_PLL_CFG, 0x07, v);
174 remainder = dividend - q *
divisor;
176 for (i = 0; i < 31; i++) {
178 if (remainder >= divisor) {
196 u32 quotient, fraction;
201 "ient, &fraction);
209 max2165_mask_write_reg(priv,
REG_NDIV_FRAC2, 0x0F, fraction >> 16);
214 tf_ntch = (freq < 725000000) ?
220 * (freq / 1000 - 470000) / (780000 - 470000);
231 static void max2165_debug_status(
struct max2165_priv *priv)
234 u8 auto_vco_success, auto_vco_active;
236 u8 dc_offset_low, dc_offset_hi;
237 u8 signal_lv_over_threshold;
238 u8 vco, vco_sub_band,
adc;
243 auto_vco_success = (status >> 6) & 0x01;
244 auto_vco_active = (status >> 5) & 0x01;
245 pll_locked = (status >> 4) & 0x01;
246 dc_offset_low = (status >> 3) & 0x01;
247 dc_offset_hi = (status >> 2) & 0x01;
248 signal_lv_over_threshold = status & 0x01;
251 vco_sub_band = (autotune >> 3) & 0x7;
252 adc = autotune & 0x7;
254 dprintk(
"auto VCO active: %d, auto VCO success: %d\n",
255 auto_vco_active, auto_vco_success);
256 dprintk(
"PLL locked: %d\n", pll_locked);
257 dprintk(
"DC offset low: %d, DC offset high: %d\n",
258 dc_offset_low, dc_offset_hi);
259 dprintk(
"Signal lvl over threshold: %d\n", signal_lv_over_threshold);
260 dprintk(
"VCO: %d, VCO Sub-band: %d, ADC: %d\n", vco, vco_sub_band, adc);
282 if (fe->
ops.i2c_gate_ctrl)
283 fe->
ops.i2c_gate_ctrl(fe, 1);
285 ret = max2165_set_rf(priv, priv->
frequency);
287 max2165_debug_status(priv);
288 if (fe->
ops.i2c_gate_ctrl)
289 fe->
ops.i2c_gate_ctrl(fe, 0);
321 if (fe->
ops.i2c_gate_ctrl)
322 fe->
ops.i2c_gate_ctrl(fe, 1);
324 max2165_debug_status(priv);
325 *status = lock_status;
327 if (fe->
ops.i2c_gate_ctrl)
328 fe->
ops.i2c_gate_ctrl(fe, 0);
344 if (fe->
ops.i2c_gate_ctrl)
345 fe->
ops.i2c_gate_ctrl(fe, 1);
351 max2165_write_reg(priv,
REG_LNA, 0x01);
353 max2165_write_reg(priv,
REG_TEST, 0x08);
361 max2165_set_osc(priv, priv->
config->osc_clk);
363 max2165_read_rom_table(priv);
365 max2165_set_bandwidth(priv, 8000000);
367 if (fe->
ops.i2c_gate_ctrl)
368 fe->
ops.i2c_gate_ctrl(fe, 0);
386 .name =
"Maxim MAX2165",
387 .frequency_min = 470000000,
388 .frequency_max = 780000000,
389 .frequency_step = 50000,
392 .release = max2165_release,
393 .init = max2165_init,
394 .sleep = max2165_sleep,
396 .set_params = max2165_set_params,
397 .set_analog_params =
NULL,
398 .get_frequency = max2165_get_frequency,
399 .get_bandwidth = max2165_get_bandwidth,
400 .get_status = max2165_get_status
409 dprintk(
"%s(%d-%04x)\n", __func__,
410 i2c ? i2c_adapter_id(i2c) : -1,
417 memcpy(&fe->
ops.tuner_ops, &max2165_tuner_ops,
425 max2165_debug_status(priv);