aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tea5761.c
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2007-08-31 15:39:57 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-10-09 21:07:46 -0400
commitfd443f7444180c1cd9cbcb816ebf65c8b8e35301 (patch)
tree43004b92dbda99cd2f189458f9bfa28a52e11dec /drivers/media/video/tea5761.c
parent735f0b9af1748602bb7f3a8009c31cf5f133eec8 (diff)
V4L/DVB (6138): tea5761: add get_rf_strength and improve status reading efficiency
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/tea5761.c')
-rw-r--r--drivers/media/video/tea5761.c64
1 files changed, 41 insertions, 23 deletions
diff --git a/drivers/media/video/tea5761.c b/drivers/media/video/tea5761.c
index 8cdaf474ffdd..2150222a3860 100644
--- a/drivers/media/video/tea5761.c
+++ b/drivers/media/video/tea5761.c
@@ -177,49 +177,66 @@ static int set_radio_freq(struct dvb_frontend *fe,
177 return 0; 177 return 0;
178} 178}
179 179
180static int tea5761_signal(struct dvb_frontend *fe) 180static int tea5761_read_status(struct dvb_frontend *fe, char *buffer)
181{ 181{
182 unsigned char buffer[16];
183 int rc;
184 struct tea5761_priv *priv = fe->tuner_priv; 182 struct tea5761_priv *priv = fe->tuner_priv;
183 int rc;
185 184
186 memset(buffer, 0, sizeof(buffer)); 185 memset(buffer, 0, 16);
187 if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) 186 if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) {
188 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 187 tuner_warn("i2c i/o error: rc == %d (should be 16)\n", rc);
188 return -EREMOTEIO;
189 }
189 190
190 return ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4)); 191 return 0;
191} 192}
192 193
193static int tea5761_stereo(struct dvb_frontend *fe) 194static inline int tea5761_signal(struct dvb_frontend *fe, const char *buffer)
194{ 195{
195 unsigned char buffer[16];
196 int rc;
197 struct tea5761_priv *priv = fe->tuner_priv; 196 struct tea5761_priv *priv = fe->tuner_priv;
198 197
199 memset(buffer, 0, sizeof(buffer)); 198 int signal = ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4));
200 if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) 199
201 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 200 tuner_dbg("Signal strength: %d\n", signal);
202 201
203 rc = buffer[9] & TEA5761_TUNCHECK_STEREO; 202 return signal;
203}
204 204
205 tuner_dbg("TEA5761 radio ST GET = %02x\n", rc); 205static inline int tea5761_stereo(struct dvb_frontend *fe, const char *buffer)
206{
207 struct tea5761_priv *priv = fe->tuner_priv;
206 208
207 return (rc ? V4L2_TUNER_SUB_STEREO : 0); 209 int stereo = buffer[9] & TEA5761_TUNCHECK_STEREO;
210
211 tuner_dbg("Radio ST GET = %02x\n", stereo);
212
213 return (stereo ? V4L2_TUNER_SUB_STEREO : 0);
208} 214}
209 215
210static int tea5761_get_status(struct dvb_frontend *fe, u32 *status) 216static int tea5761_get_status(struct dvb_frontend *fe, u32 *status)
211{ 217{
212 struct tea5761_priv *priv = fe->tuner_priv; 218 unsigned char buffer[16];
213 int signal = tea5761_signal(fe);
214 219
215 *status = 0; 220 *status = 0;
216 221
217 if (signal) 222 if (0 == tea5761_read_status(fe, buffer)) {
218 *status = TUNER_STATUS_LOCKED; 223 if (tea5761_signal(fe, buffer))
219 if (tea5761_stereo(fe)) 224 *status = TUNER_STATUS_LOCKED;
220 *status |= TUNER_STATUS_STEREO; 225 if (tea5761_stereo(fe, buffer))
226 *status |= TUNER_STATUS_STEREO;
227 }
228
229 return 0;
230}
231
232static int tea5761_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
233{
234 unsigned char buffer[16];
235
236 *strength = 0;
221 237
222 tuner_dbg("tea5761: Signal strength: %d\n", signal); 238 if (0 == tea5761_read_status(fe, buffer))
239 *strength = tea5761_signal(fe, buffer);
223 240
224 return 0; 241 return 0;
225} 242}
@@ -266,6 +283,7 @@ static struct dvb_tuner_ops tea5761_tuner_ops = {
266 .release = tea5761_release, 283 .release = tea5761_release,
267 .get_frequency = tea5761_get_frequency, 284 .get_frequency = tea5761_get_frequency,
268 .get_status = tea5761_get_status, 285 .get_status = tea5761_get_status,
286 .get_rf_strength = tea5761_get_rf_strength,
269}; 287};
270 288
271struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe, 289struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,