diff options
author | Michael Krufky <mkrufky@linuxtv.org> | 2007-08-31 15:39:57 -0400 |
---|---|---|
committer | Michael Krufky <mkrufky@linuxtv.org> | 2007-08-31 15:39:57 -0400 |
commit | 254dc53c714918c22c4234d99e60ccb1b71b52ca (patch) | |
tree | 67b00d1c5af000e1d429bfcd299198db414d7845 /linux/drivers/media/video/tea5761.c | |
parent | cf898a9e25f6f2174034a221ca67749306c26b0d (diff) | |
download | mediapointer-dvb-s2-254dc53c714918c22c4234d99e60ccb1b71b52ca.tar.gz mediapointer-dvb-s2-254dc53c714918c22c4234d99e60ccb1b71b52ca.tar.bz2 |
tea5761: add get_rf_strength and improve status reading efficiency
From: Michael Krufky <mkrufky@linuxtv.org>
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org>
Diffstat (limited to 'linux/drivers/media/video/tea5761.c')
-rw-r--r-- | linux/drivers/media/video/tea5761.c | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/linux/drivers/media/video/tea5761.c b/linux/drivers/media/video/tea5761.c index 3b661d8dc..d5f83818d 100644 --- a/linux/drivers/media/video/tea5761.c +++ b/linux/drivers/media/video/tea5761.c @@ -178,49 +178,66 @@ static int set_radio_freq(struct dvb_frontend *fe, return 0; } -static int tea5761_signal(struct dvb_frontend *fe) +static int tea5761_read_status(struct dvb_frontend *fe, char *buffer) { - unsigned char buffer[16]; - int rc; struct tea5761_priv *priv = fe->tuner_priv; + int rc; - memset(buffer, 0, sizeof(buffer)); - if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) - tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); + memset(buffer, 0, 16); + if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) { + tuner_warn("i2c i/o error: rc == %d (should be 16)\n", rc); + return -EREMOTEIO; + } - return ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4)); + return 0; } -static int tea5761_stereo(struct dvb_frontend *fe) +static inline int tea5761_signal(struct dvb_frontend *fe, const char *buffer) { - unsigned char buffer[16]; - int rc; struct tea5761_priv *priv = fe->tuner_priv; - memset(buffer, 0, sizeof(buffer)); - if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) - tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); + int signal = ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4)); + + tuner_dbg("Signal strength: %d\n", signal); - rc = buffer[9] & TEA5761_TUNCHECK_STEREO; + return signal; +} - tuner_dbg("TEA5761 radio ST GET = %02x\n", rc); +static inline int tea5761_stereo(struct dvb_frontend *fe, const char *buffer) +{ + struct tea5761_priv *priv = fe->tuner_priv; - return (rc ? V4L2_TUNER_SUB_STEREO : 0); + int stereo = buffer[9] & TEA5761_TUNCHECK_STEREO; + + tuner_dbg("Radio ST GET = %02x\n", stereo); + + return (stereo ? V4L2_TUNER_SUB_STEREO : 0); } static int tea5761_get_status(struct dvb_frontend *fe, u32 *status) { - struct tea5761_priv *priv = fe->tuner_priv; - int signal = tea5761_signal(fe); + unsigned char buffer[16]; *status = 0; - if (signal) - *status = TUNER_STATUS_LOCKED; - if (tea5761_stereo(fe)) - *status |= TUNER_STATUS_STEREO; + if (0 == tea5761_read_status(fe, buffer)) { + if (tea5761_signal(fe, buffer)) + *status = TUNER_STATUS_LOCKED; + if (tea5761_stereo(fe, buffer)) + *status |= TUNER_STATUS_STEREO; + } + + return 0; +} + +static int tea5761_get_rf_strength(struct dvb_frontend *fe, u16 *strength) +{ + unsigned char buffer[16]; + + *strength = 0; - tuner_dbg("tea5761: Signal strength: %d\n", signal); + if (0 == tea5761_read_status(fe, buffer)) + *strength = tea5761_signal(fe, buffer); return 0; } @@ -272,6 +289,7 @@ static struct dvb_tuner_ops tea5761_tuner_ops = { .release = tea5761_release, .get_frequency = tea5761_get_frequency, .get_status = tea5761_get_status, + .get_rf_strength = tea5761_get_rf_strength, }; struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe, |