Lines Matching +full:i2c +full:- +full:gate
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2012 Hans-Frieder Vogt <hfvogt@gmx.net>
9 #include "fc0012-priv.h"
15 .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 2 in fc0012_writereg()
18 if (i2c_transfer(priv->i2c, &msg, 1) != 1) { in fc0012_writereg()
19 dev_err(&priv->i2c->dev, in fc0012_writereg()
20 "%s: I2C write reg failed, reg: %02x, val: %02x\n", in fc0012_writereg()
22 return -EREMOTEIO; in fc0012_writereg()
30 { .addr = priv->cfg->i2c_address, .flags = 0, in fc0012_readreg()
32 { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD, in fc0012_readreg()
36 if (i2c_transfer(priv->i2c, msg, 2) != 2) { in fc0012_readreg()
37 dev_err(&priv->i2c->dev, in fc0012_readreg()
38 "%s: I2C read reg failed, reg: %02x\n", in fc0012_readreg()
40 return -EREMOTEIO; in fc0012_readreg()
47 kfree(fe->tuner_priv); in fc0012_release()
48 fe->tuner_priv = NULL; in fc0012_release()
53 struct fc0012_priv *priv = fe->tuner_priv; in fc0012_init()
70 0xfc, /* reg. 0x0c: depending on AGC Up-Down mode, may need 0xf8 */ in fc0012_init()
71 0x02, /* reg. 0x0d: AGC Not Forcing & LNA Forcing, 0x02 for DVB-T */ in fc0012_init()
83 switch (priv->cfg->xtal_freq) { in fc0012_init()
93 if (priv->cfg->dual_master) in fc0012_init()
96 if (priv->cfg->loop_through) in fc0012_init()
99 if (fe->ops.i2c_gate_ctrl) in fc0012_init()
100 fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ in fc0012_init()
108 if (fe->ops.i2c_gate_ctrl) in fc0012_init()
109 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ in fc0012_init()
112 dev_err(&priv->i2c->dev, "%s: fc0012_writereg failed: %d\n", in fc0012_init()
120 struct fc0012_priv *priv = fe->tuner_priv; in fc0012_set_params()
122 struct dtv_frontend_properties *p = &fe->dtv_property_cache; in fc0012_set_params()
123 u32 freq = p->frequency / 1000; in fc0012_set_params()
124 u32 delsys = p->delivery_system; in fc0012_set_params()
130 if (fe->callback) { in fc0012_set_params()
131 ret = fe->callback(priv->i2c, DVB_FRONTEND_COMPONENT_TUNER, in fc0012_set_params()
137 switch (priv->cfg->xtal_freq) { in fc0012_set_params()
203 if ((f_vco - xdiv * xtal_freq_khz_2) >= (xtal_freq_khz_2 / 2)) in fc0012_set_params()
207 am = (unsigned char)(xdiv - (8 * pm)); in fc0012_set_params()
211 reg[2] = pm - 1; in fc0012_set_params()
227 xin = (unsigned short)(f_vco - (f_vco / xtal_freq_khz_2) * xtal_freq_khz_2); in fc0012_set_params()
237 switch (p->bandwidth_hz) { in fc0012_set_params()
249 dev_err(&priv->i2c->dev, "%s: modulation type not supported!\n", in fc0012_set_params()
251 return -EINVAL; in fc0012_set_params()
257 if (fe->ops.i2c_gate_ctrl) in fc0012_set_params()
258 fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ in fc0012_set_params()
271 /* VCO Re-Calibration if needed */ in fc0012_set_params()
305 priv->frequency = p->frequency; in fc0012_set_params()
306 priv->bandwidth = p->bandwidth_hz; in fc0012_set_params()
309 if (fe->ops.i2c_gate_ctrl) in fc0012_set_params()
310 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ in fc0012_set_params()
312 dev_warn(&priv->i2c->dev, "%s: %s failed: %d\n", in fc0012_set_params()
319 struct fc0012_priv *priv = fe->tuner_priv; in fc0012_get_frequency()
320 *frequency = priv->frequency; in fc0012_get_frequency()
326 *frequency = 0; /* Zero-IF */ in fc0012_get_if_frequency()
332 struct fc0012_priv *priv = fe->tuner_priv; in fc0012_get_bandwidth()
333 *bandwidth = priv->bandwidth; in fc0012_get_bandwidth()
337 #define INPUT_ADC_LEVEL -8
341 struct fc0012_priv *priv = fe->tuner_priv; in fc0012_get_rf_strength()
347 -63, -58, -99, -73, in fc0012_get_rf_strength()
348 -63, -65, -54, -60, in fc0012_get_rf_strength()
357 if (fe->ops.i2c_gate_ctrl) in fc0012_get_rf_strength()
358 fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ in fc0012_get_rf_strength()
374 if (fe->ops.i2c_gate_ctrl) in fc0012_get_rf_strength()
375 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ in fc0012_get_rf_strength()
379 tot_agc_gain = (abs((int_temp >> 5) - 7) - 2 + in fc0012_get_rf_strength()
381 power = INPUT_ADC_LEVEL - tot_agc_gain - int_lna / 10; in fc0012_get_rf_strength()
385 else if (power < -95) in fc0012_get_rf_strength()
392 ret = -1; in fc0012_get_rf_strength()
398 if (fe->ops.i2c_gate_ctrl) in fc0012_get_rf_strength()
399 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ in fc0012_get_rf_strength()
402 dev_warn(&priv->i2c->dev, "%s: %s failed: %d\n", in fc0012_get_rf_strength()
429 struct i2c_adapter *i2c, const struct fc0012_config *cfg) in fc0012_attach() argument
435 if (fe->ops.i2c_gate_ctrl) in fc0012_attach()
436 fe->ops.i2c_gate_ctrl(fe, 1); in fc0012_attach()
440 ret = -ENOMEM; in fc0012_attach()
441 dev_err(&i2c->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME); in fc0012_attach()
445 priv->cfg = cfg; in fc0012_attach()
446 priv->i2c = i2c; in fc0012_attach()
453 dev_dbg(&i2c->dev, "%s: chip_id=%02x\n", __func__, chip_id); in fc0012_attach()
459 ret = -ENODEV; in fc0012_attach()
463 dev_info(&i2c->dev, "%s: Fitipower FC0012 successfully identified\n", in fc0012_attach()
466 if (priv->cfg->loop_through) { in fc0012_attach()
476 if (priv->cfg->clock_out) { in fc0012_attach()
482 fe->tuner_priv = priv; in fc0012_attach()
483 memcpy(&fe->ops.tuner_ops, &fc0012_tuner_ops, in fc0012_attach()
487 if (fe->ops.i2c_gate_ctrl) in fc0012_attach()
488 fe->ops.i2c_gate_ctrl(fe, 0); in fc0012_attach()
491 dev_dbg(&i2c->dev, "%s: failed: %d\n", __func__, ret); in fc0012_attach()
501 MODULE_AUTHOR("Hans-Frieder Vogt <hfvogt@gmx.net>");