49 .addr = priv->
cfg->i2c_addr,
63 dev_warn(&priv->
i2c->dev,
"%s: i2c wr failed=%d reg=%02x " \
64 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
71 static int fc2580_rd_regs(
struct fc2580_priv *priv,
u8 reg,
u8 *val,
int len)
82 .addr = priv->
cfg->i2c_addr,
94 dev_warn(&priv->
i2c->dev,
"%s: i2c rd failed=%d reg=%02x " \
95 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
105 return fc2580_wr_regs(priv, reg, &val, 1);
111 return fc2580_rd_regs(priv, reg, val, 1);
119 unsigned int r_val, n_val, k_val, k_val_reg, f_ref;
131 dev_dbg(&priv->
i2c->dev,
"%s: delivery_system=%d frequency=%d " \
132 "bandwidth_hz=%d\n", __func__,
135 if (fe->
ops.i2c_gate_ctrl)
136 fe->
ops.i2c_gate_ctrl(fe, 1);
148 f_vco *= fc2580_pll_lut[
i].div;
150 if (f_vco >= 2600000000
UL)
151 tmp_val = 0x0e | fc2580_pll_lut[
i].band;
153 tmp_val = 0x06 | fc2580_pll_lut[
i].band;
155 ret = fc2580_wr_reg(priv, 0x02, tmp_val);
159 if (f_vco >= 2
UL * 76 * priv->
cfg->clock) {
162 }
else if (f_vco >= 1
UL * 76 * priv->
cfg->clock) {
170 f_ref = 2
UL * priv->
cfg->clock / r_val;
171 n_val = div_u64_rem(f_vco, f_ref, &k_val);
172 k_val_reg = 1
UL * k_val * (1 << 20) / f_ref;
174 ret = fc2580_wr_reg(priv, 0x18, r18_val | ((k_val_reg >> 16) & 0xff));
178 ret = fc2580_wr_reg(priv, 0x1a, (k_val_reg >> 8) & 0xff);
182 ret = fc2580_wr_reg(priv, 0x1b, (k_val_reg >> 0) & 0xff);
186 ret = fc2580_wr_reg(priv, 0x1c, n_val);
190 if (priv->
cfg->clock >= 28000000) {
191 ret = fc2580_wr_reg(priv, 0x4b, 0x22);
196 if (fc2580_pll_lut[
i].band == 0x00) {
202 ret = fc2580_wr_reg(priv, 0x2d, tmp_val);
209 if (c->
frequency <= fc2580_freq_regs_lut[
i].freq)
216 ret = fc2580_wr_reg(priv, 0x25, fc2580_freq_regs_lut[
i].r25_val);
220 ret = fc2580_wr_reg(priv, 0x27, fc2580_freq_regs_lut[
i].r27_val);
224 ret = fc2580_wr_reg(priv, 0x28, fc2580_freq_regs_lut[
i].r28_val);
228 ret = fc2580_wr_reg(priv, 0x29, fc2580_freq_regs_lut[
i].r29_val);
232 ret = fc2580_wr_reg(priv, 0x2b, fc2580_freq_regs_lut[
i].r2b_val);
236 ret = fc2580_wr_reg(priv, 0x2c, fc2580_freq_regs_lut[
i].r2c_val);
240 ret = fc2580_wr_reg(priv, 0x2d, fc2580_freq_regs_lut[
i].r2d_val);
244 ret = fc2580_wr_reg(priv, 0x30, fc2580_freq_regs_lut[
i].r30_val);
248 ret = fc2580_wr_reg(priv, 0x44, fc2580_freq_regs_lut[
i].r44_val);
252 ret = fc2580_wr_reg(priv, 0x50, fc2580_freq_regs_lut[
i].r50_val);
256 ret = fc2580_wr_reg(priv, 0x53, fc2580_freq_regs_lut[
i].r53_val);
260 ret = fc2580_wr_reg(priv, 0x5f, fc2580_freq_regs_lut[
i].r5f_val);
264 ret = fc2580_wr_reg(priv, 0x61, fc2580_freq_regs_lut[
i].r61_val);
268 ret = fc2580_wr_reg(priv, 0x62, fc2580_freq_regs_lut[
i].r62_val);
272 ret = fc2580_wr_reg(priv, 0x63, fc2580_freq_regs_lut[
i].r63_val);
276 ret = fc2580_wr_reg(priv, 0x67, fc2580_freq_regs_lut[
i].r67_val);
280 ret = fc2580_wr_reg(priv, 0x68, fc2580_freq_regs_lut[
i].r68_val);
284 ret = fc2580_wr_reg(priv, 0x69, fc2580_freq_regs_lut[
i].r69_val);
288 ret = fc2580_wr_reg(priv, 0x6a, fc2580_freq_regs_lut[
i].r6a_val);
292 ret = fc2580_wr_reg(priv, 0x6b, fc2580_freq_regs_lut[
i].r6b_val);
296 ret = fc2580_wr_reg(priv, 0x6c, fc2580_freq_regs_lut[
i].r6c_val);
300 ret = fc2580_wr_reg(priv, 0x6d, fc2580_freq_regs_lut[
i].r6d_val);
304 ret = fc2580_wr_reg(priv, 0x6e, fc2580_freq_regs_lut[
i].r6e_val);
308 ret = fc2580_wr_reg(priv, 0x6f, fc2580_freq_regs_lut[
i].r6f_val);
321 ret = fc2580_wr_reg(priv, 0x36, fc2580_if_filter_lut[
i].r36_val);
325 ret = fc2580_wr_reg(priv, 0x37, 1
UL * priv->
cfg->clock * \
326 fc2580_if_filter_lut[
i].mul / 1000000000);
330 ret = fc2580_wr_reg(priv, 0x39, fc2580_if_filter_lut[
i].r39_val);
335 ret = fc2580_wr_reg(priv, 0x2e, 0x09);
339 for (
i = 0;
i < 5;
i++) {
340 ret = fc2580_rd_reg(priv, 0x2f, &tmp_val);
345 if ((tmp_val & 0xc0) == 0xc0)
348 ret = fc2580_wr_reg(priv, 0x2e, 0x01);
352 ret = fc2580_wr_reg(priv, 0x2e, 0x09);
359 dev_dbg(&priv->
i2c->dev,
"%s: loop=%i\n", __func__,
i);
361 ret = fc2580_wr_reg(priv, 0x2e, 0x01);
365 if (fe->
ops.i2c_gate_ctrl)
366 fe->
ops.i2c_gate_ctrl(fe, 0);
370 if (fe->
ops.i2c_gate_ctrl)
371 fe->
ops.i2c_gate_ctrl(fe, 0);
373 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
384 if (fe->
ops.i2c_gate_ctrl)
385 fe->
ops.i2c_gate_ctrl(fe, 1);
387 for (i = 0; i <
ARRAY_SIZE(fc2580_init_reg_vals); i++) {
388 ret = fc2580_wr_reg(priv, fc2580_init_reg_vals[i].reg,
389 fc2580_init_reg_vals[i].val);
394 if (fe->
ops.i2c_gate_ctrl)
395 fe->
ops.i2c_gate_ctrl(fe, 0);
399 if (fe->
ops.i2c_gate_ctrl)
400 fe->
ops.i2c_gate_ctrl(fe, 0);
402 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
413 if (fe->
ops.i2c_gate_ctrl)
414 fe->
ops.i2c_gate_ctrl(fe, 1);
416 ret = fc2580_wr_reg(priv, 0x02, 0x0a);
420 if (fe->
ops.i2c_gate_ctrl)
421 fe->
ops.i2c_gate_ctrl(fe, 0);
425 if (fe->
ops.i2c_gate_ctrl)
426 fe->
ops.i2c_gate_ctrl(fe, 0);
428 dev_dbg(&priv->
i2c->dev,
"%s: failed=%d\n", __func__, ret);
456 .name =
"FCI FC2580",
457 .frequency_min = 174000000,
458 .frequency_max = 862000000,
461 .release = fc2580_release,
464 .sleep = fc2580_sleep,
465 .set_params = fc2580_set_params,
467 .get_if_frequency = fc2580_get_if_frequency,
477 if (fe->
ops.i2c_gate_ctrl)
478 fe->
ops.i2c_gate_ctrl(fe, 1);
483 dev_err(&i2c->
dev,
"%s: kzalloc() failed\n", KBUILD_MODNAME);
491 ret = fc2580_rd_reg(priv, 0x01, &chip_id);
495 dev_dbg(&priv->
i2c->dev,
"%s: chip_id=%02x\n", __func__, chip_id);
506 "%s: FCI FC2580 successfully identified\n",
510 memcpy(&fe->
ops.tuner_ops, &fc2580_tuner_ops,
513 if (fe->
ops.i2c_gate_ctrl)
514 fe->
ops.i2c_gate_ctrl(fe, 0);
518 if (fe->
ops.i2c_gate_ctrl)
519 fe->
ops.i2c_gate_ctrl(fe, 0);
521 dev_dbg(&i2c->
dev,
"%s: failed=%d\n", __func__, ret);