Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 286408
b: refs/heads/master
c: 8a538a8
h: refs/heads/master
v: v3
  • Loading branch information
Miroslav Slugen authored and Mauro Carvalho Chehab committed Jan 16, 2012
1 parent da4c4f4 commit 0faf09d
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cd4ca7afc61d3b18fcd635002459fb6b1d701099
refs/heads/master: 8a538a8855aa95e5a12ae232a140e6b30c56d0c5
86 changes: 86 additions & 0 deletions trunk/drivers/media/common/tuners/xc4000.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ struct xc4000_priv {
#define XREG_SNR 0x06
#define XREG_VERSION 0x07
#define XREG_PRODUCT_ID 0x08
#define XREG_SIGNAL_LEVEL 0x0A
#define XREG_NOISE_LEVEL 0x0B

/*
Basic firmware description. This will remain with
Expand Down Expand Up @@ -486,6 +488,16 @@ static int xc_get_quality(struct xc4000_priv *priv, u16 *quality)
return xc4000_readreg(priv, XREG_QUALITY, quality);
}

static int xc_get_signal_level(struct xc4000_priv *priv, u16 *signal)
{
return xc4000_readreg(priv, XREG_SIGNAL_LEVEL, signal);
}

static int xc_get_noise_level(struct xc4000_priv *priv, u16 *noise)
{
return xc4000_readreg(priv, XREG_NOISE_LEVEL, noise);
}

static u16 xc_wait_for_lock(struct xc4000_priv *priv)
{
u16 lock_state = 0;
Expand Down Expand Up @@ -1089,6 +1101,8 @@ static void xc_debug_dump(struct xc4000_priv *priv)
u32 hsync_freq_hz = 0;
u16 frame_lines;
u16 quality;
u16 signal = 0;
u16 noise = 0;
u8 hw_majorversion = 0, hw_minorversion = 0;
u8 fw_majorversion = 0, fw_minorversion = 0;

Expand Down Expand Up @@ -1119,6 +1133,12 @@ static void xc_debug_dump(struct xc4000_priv *priv)

xc_get_quality(priv, &quality);
dprintk(1, "*** Quality (0:<8dB, 7:>56dB) = %d\n", quality);

xc_get_signal_level(priv, &signal);
dprintk(1, "*** Signal level = -%ddB (%d)\n", signal >> 8, signal);

xc_get_noise_level(priv, &noise);
dprintk(1, "*** Noise level = %ddB (%d)\n", noise >> 8, noise);
}

static int xc4000_set_params(struct dvb_frontend *fe)
Expand Down Expand Up @@ -1432,6 +1452,71 @@ static int xc4000_set_analog_params(struct dvb_frontend *fe,
return ret;
}

static int xc4000_get_signal(struct dvb_frontend *fe, u16 *strength)
{
struct xc4000_priv *priv = fe->tuner_priv;
u16 value = 0;
int rc;

mutex_lock(&priv->lock);
rc = xc4000_readreg(priv, XREG_SIGNAL_LEVEL, &value);
mutex_unlock(&priv->lock);

if (rc < 0)
goto ret;

/* Informations from real testing of DVB-T and radio part,
coeficient for one dB is 0xff.
*/
tuner_dbg("Signal strength: -%ddB (%05d)\n", value >> 8, value);

/* all known digital modes */
if ((priv->video_standard == XC4000_DTV6) ||
(priv->video_standard == XC4000_DTV7) ||
(priv->video_standard == XC4000_DTV7_8) ||
(priv->video_standard == XC4000_DTV8))
goto digital;

/* Analog mode has NOISE LEVEL important, signal
depends only on gain of antenna and amplifiers,
but it doesn't tell anything about real quality
of reception.
*/
mutex_lock(&priv->lock);
rc = xc4000_readreg(priv, XREG_NOISE_LEVEL, &value);
mutex_unlock(&priv->lock);

tuner_dbg("Noise level: %ddB (%05d)\n", value >> 8, value);

/* highest noise level: 32dB */
if (value >= 0x2000) {
value = 0;
} else {
value = ~value << 3;
}

goto ret;

/* Digital mode has SIGNAL LEVEL important and real
noise level is stored in demodulator registers.
*/
digital:
/* best signal: -50dB */
if (value <= 0x3200) {
value = 0xffff;
/* minimum: -114dB - should be 0x7200 but real zero is 0x713A */
} else if (value >= 0x713A) {
value = 0;
} else {
value = ~(value - 0x3200) << 2;
}

ret:
*strength = value;

return rc;
}

static int xc4000_get_frequency(struct dvb_frontend *fe, u32 *freq)
{
struct xc4000_priv *priv = fe->tuner_priv;
Expand Down Expand Up @@ -1559,6 +1644,7 @@ static const struct dvb_tuner_ops xc4000_tuner_ops = {
.set_params = xc4000_set_params,
.set_analog_params = xc4000_set_analog_params,
.get_frequency = xc4000_get_frequency,
.get_rf_strength = xc4000_get_signal,
.get_bandwidth = xc4000_get_bandwidth,
.get_status = xc4000_get_status
};
Expand Down

0 comments on commit 0faf09d

Please sign in to comment.