aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/radio/radio-tea5764.c
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-05-31 05:19:04 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-06-17 08:29:56 -0400
commitb73008920a69669d253b2f9268f9f51884684718 (patch)
treec8e45a04ac30d6fc6c01068896737a7a69f54c1a /drivers/media/radio/radio-tea5764.c
parent090fdf6af8d1baafcdaf44796058f62a73a637bf (diff)
[media] radio-tea5764: some cleanups and clamp frequency when out-of-range
Some small cleanups and when setting the frequency it is now clamped to the valid frequency range instead of returning an error. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Cc: Fabio Belavenuto <belavenuto@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/radio/radio-tea5764.c')
-rw-r--r--drivers/media/radio/radio-tea5764.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/drivers/media/radio/radio-tea5764.c b/drivers/media/radio/radio-tea5764.c
index c22feedb36f5..036e2f54f4db 100644
--- a/drivers/media/radio/radio-tea5764.c
+++ b/drivers/media/radio/radio-tea5764.c
@@ -60,8 +60,8 @@
60 60
61/* Frequency limits in MHz -- these are European values. For Japanese 61/* Frequency limits in MHz -- these are European values. For Japanese
62devices, that would be 76000 and 91000. */ 62devices, that would be 76000 and 91000. */
63#define FREQ_MIN 87500 63#define FREQ_MIN 87500U
64#define FREQ_MAX 108000 64#define FREQ_MAX 108000U
65#define FREQ_MUL 16 65#define FREQ_MUL 16
66 66
67/* TEA5764 registers */ 67/* TEA5764 registers */
@@ -309,8 +309,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
309 if (v->index > 0) 309 if (v->index > 0)
310 return -EINVAL; 310 return -EINVAL;
311 311
312 memset(v, 0, sizeof(*v)); 312 strlcpy(v->name, "FM", sizeof(v->name));
313 strcpy(v->name, "FM");
314 v->type = V4L2_TUNER_RADIO; 313 v->type = V4L2_TUNER_RADIO;
315 tea5764_i2c_read(radio); 314 tea5764_i2c_read(radio);
316 v->rangelow = FREQ_MIN * FREQ_MUL; 315 v->rangelow = FREQ_MIN * FREQ_MUL;
@@ -343,19 +342,23 @@ static int vidioc_s_frequency(struct file *file, void *priv,
343 const struct v4l2_frequency *f) 342 const struct v4l2_frequency *f)
344{ 343{
345 struct tea5764_device *radio = video_drvdata(file); 344 struct tea5764_device *radio = video_drvdata(file);
345 unsigned freq = f->frequency;
346 346
347 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 347 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
348 return -EINVAL; 348 return -EINVAL;
349 if (f->frequency == 0) { 349 if (freq == 0) {
350 /* We special case this as a power down control. */ 350 /* We special case this as a power down control. */
351 tea5764_power_down(radio); 351 tea5764_power_down(radio);
352 } 352 /* Yes, that's what is returned in this case. This
353 if (f->frequency < (FREQ_MIN * FREQ_MUL)) 353 whole special case is non-compliant and should really
354 return -EINVAL; 354 be replaced with something better, but changing this
355 if (f->frequency > (FREQ_MAX * FREQ_MUL)) 355 might well break code that depends on this behavior.
356 So we keep it as-is. */
356 return -EINVAL; 357 return -EINVAL;
358 }
359 clamp(freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL);
357 tea5764_power_up(radio); 360 tea5764_power_up(radio);
358 tea5764_tune(radio, (f->frequency * 125) / 2); 361 tea5764_tune(radio, (freq * 125) / 2);
359 return 0; 362 return 0;
360} 363}
361 364
@@ -368,7 +371,6 @@ static int vidioc_g_frequency(struct file *file, void *priv,
368 if (f->tuner != 0) 371 if (f->tuner != 0)
369 return -EINVAL; 372 return -EINVAL;
370 tea5764_i2c_read(radio); 373 tea5764_i2c_read(radio);
371 memset(f, 0, sizeof(*f));
372 f->type = V4L2_TUNER_RADIO; 374 f->type = V4L2_TUNER_RADIO;
373 if (r->tnctrl & TEA5764_TNCTRL_PUPD0) 375 if (r->tnctrl & TEA5764_TNCTRL_PUPD0)
374 f->frequency = (tea5764_get_freq(radio) * 2) / 125; 376 f->frequency = (tea5764_get_freq(radio) * 2) / 125;