Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b7300892 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab
Browse files

[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: default avatarHans Verkuil <hans.verkuil@cisco.com>
Cc: Fabio Belavenuto <belavenuto@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 090fdf6a
Loading
Loading
Loading
Loading
+13 −11
Original line number Original line Diff line number Diff line
@@ -60,8 +60,8 @@


/* Frequency limits in MHz -- these are European values.  For Japanese
/* Frequency limits in MHz -- these are European values.  For Japanese
devices, that would be 76000 and 91000.  */
devices, that would be 76000 and 91000.  */
#define FREQ_MIN  87500
#define FREQ_MIN  87500U
#define FREQ_MAX 108000
#define FREQ_MAX 108000U
#define FREQ_MUL 16
#define FREQ_MUL 16


/* TEA5764 registers */
/* TEA5764 registers */
@@ -309,8 +309,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
	if (v->index > 0)
	if (v->index > 0)
		return -EINVAL;
		return -EINVAL;


	memset(v, 0, sizeof(*v));
	strlcpy(v->name, "FM", sizeof(v->name));
	strcpy(v->name, "FM");
	v->type = V4L2_TUNER_RADIO;
	v->type = V4L2_TUNER_RADIO;
	tea5764_i2c_read(radio);
	tea5764_i2c_read(radio);
	v->rangelow   = FREQ_MIN * FREQ_MUL;
	v->rangelow   = FREQ_MIN * FREQ_MUL;
@@ -343,19 +342,23 @@ static int vidioc_s_frequency(struct file *file, void *priv,
				const struct v4l2_frequency *f)
				const struct v4l2_frequency *f)
{
{
	struct tea5764_device *radio = video_drvdata(file);
	struct tea5764_device *radio = video_drvdata(file);
	unsigned freq = f->frequency;


	if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
	if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
		return -EINVAL;
		return -EINVAL;
	if (f->frequency == 0) {
	if (freq == 0) {
		/* We special case this as a power down control. */
		/* We special case this as a power down control. */
		tea5764_power_down(radio);
		tea5764_power_down(radio);
	}
		/* Yes, that's what is returned in this case. This
	if (f->frequency < (FREQ_MIN * FREQ_MUL))
		   whole special case is non-compliant and should really
		return -EINVAL;
		   be replaced with something better, but changing this
	if (f->frequency > (FREQ_MAX * FREQ_MUL))
		   might well break code that depends on this behavior.
		   So we keep it as-is. */
		return -EINVAL;
		return -EINVAL;
	}
	clamp(freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL);
	tea5764_power_up(radio);
	tea5764_power_up(radio);
	tea5764_tune(radio, (f->frequency * 125) / 2);
	tea5764_tune(radio, (freq * 125) / 2);
	return 0;
	return 0;
}
}


@@ -368,7 +371,6 @@ static int vidioc_g_frequency(struct file *file, void *priv,
	if (f->tuner != 0)
	if (f->tuner != 0)
		return -EINVAL;
		return -EINVAL;
	tea5764_i2c_read(radio);
	tea5764_i2c_read(radio);
	memset(f, 0, sizeof(*f));
	f->type = V4L2_TUNER_RADIO;
	f->type = V4L2_TUNER_RADIO;
	if (r->tnctrl & TEA5764_TNCTRL_PUPD0)
	if (r->tnctrl & TEA5764_TNCTRL_PUPD0)
		f->frequency = (tea5764_get_freq(radio) * 2) / 125;
		f->frequency = (tea5764_get_freq(radio) * 2) / 125;