aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tea5767.c
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2007-08-31 15:40:14 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-10-09 21:07:49 -0400
commit6b897f2c3982af51134ba83f4b6de71d28d35944 (patch)
treec042c0dc48408f45e7c54b528fdb222119bc2e97 /drivers/media/video/tea5767.c
parentfd443f7444180c1cd9cbcb816ebf65c8b8e35301 (diff)
V4L/DVB (6139): tea5767: 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/tea5767.c')
-rw-r--r--drivers/media/video/tea5767.c63
1 files changed, 41 insertions, 22 deletions
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index cf908d853195..71df419df7bc 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -264,48 +264,66 @@ static int set_radio_freq(struct dvb_frontend *fe,
264 return 0; 264 return 0;
265} 265}
266 266
267static int tea5767_signal(struct dvb_frontend *fe) 267static int tea5767_read_status(struct dvb_frontend *fe, char *buffer)
268{ 268{
269 unsigned char buffer[5];
270 int rc;
271 struct tea5767_priv *priv = fe->tuner_priv; 269 struct tea5767_priv *priv = fe->tuner_priv;
270 int rc;
272 271
273 memset(buffer, 0, sizeof(buffer)); 272 memset(buffer, 0, 5);
274 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) 273 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) {
275 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 274 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
275 return -EREMOTEIO;
276 }
276 277
277 return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8); 278 return 0;
278} 279}
279 280
280static int tea5767_stereo(struct dvb_frontend *fe) 281static inline int tea5767_signal(struct dvb_frontend *fe, const char *buffer)
281{ 282{
282 unsigned char buffer[5];
283 int rc;
284 struct tea5767_priv *priv = fe->tuner_priv; 283 struct tea5767_priv *priv = fe->tuner_priv;
285 284
286 memset(buffer, 0, sizeof(buffer)); 285 int signal = ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8);
287 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) 286
288 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 287 tuner_dbg("Signal strength: %d\n", signal);
288
289 return signal;
290}
289 291
290 rc = buffer[2] & TEA5767_STEREO_MASK; 292static inline int tea5767_stereo(struct dvb_frontend *fe, const char *buffer)
293{
294 struct tea5767_priv *priv = fe->tuner_priv;
291 295
292 tuner_dbg("radio ST GET = %02x\n", rc); 296 int stereo = buffer[2] & TEA5767_STEREO_MASK;
293 297
294 return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); 298 tuner_dbg("Radio ST GET = %02x\n", stereo);
299
300 return (stereo ? V4L2_TUNER_SUB_STEREO : 0);
295} 301}
296 302
297static int tea5767_get_status(struct dvb_frontend *fe, u32 *status) 303static int tea5767_get_status(struct dvb_frontend *fe, u32 *status)
298{ 304{
299 struct tea5767_priv *priv = fe->tuner_priv; 305 unsigned char buffer[5];
300 int signal = tea5767_signal(fe); 306
301 *status = 0; 307 *status = 0;
302 308
303 if (signal) 309 if (0 == tea5767_read_status(fe, buffer)) {
304 *status = TUNER_STATUS_LOCKED; 310 if (tea5767_signal(fe, buffer))
305 if (tea5767_stereo(fe)) 311 *status = TUNER_STATUS_LOCKED;
306 *status |= TUNER_STATUS_STEREO; 312 if (tea5767_stereo(fe, buffer))
313 *status |= TUNER_STATUS_STEREO;
314 }
315
316 return 0;
317}
318
319static int tea5767_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
320{
321 unsigned char buffer[5];
322
323 *strength = 0;
307 324
308 tuner_dbg("tea5767: Signal strength: %d\n", signal); 325 if (0 == tea5767_read_status(fe, buffer))
326 *strength = tea5767_signal(fe, buffer);
309 327
310 return 0; 328 return 0;
311} 329}
@@ -393,6 +411,7 @@ static struct dvb_tuner_ops tea5767_tuner_ops = {
393 .release = tea5767_release, 411 .release = tea5767_release,
394 .get_frequency = tea5767_get_frequency, 412 .get_frequency = tea5767_get_frequency,
395 .get_status = tea5767_get_status, 413 .get_status = tea5767_get_status,
414 .get_rf_strength = tea5767_get_rf_strength,
396}; 415};
397 416
398struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe, 417struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,