Commit f5e7cc4a authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] radio-miropcm20: Fix audmode/tuner/frequency handling

- instead of a mute module option, use audmode as per the spec.
- clamp the frequency before setting it.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent f7c096f7
...@@ -26,44 +26,27 @@ static int radio_nr = -1; ...@@ -26,44 +26,27 @@ static int radio_nr = -1;
module_param(radio_nr, int, 0); module_param(radio_nr, int, 0);
MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
static bool mono;
module_param(mono, bool, 0);
MODULE_PARM_DESC(mono, "Force tuner into mono mode.");
struct pcm20 { struct pcm20 {
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
struct video_device vdev; struct video_device vdev;
struct v4l2_ctrl_handler ctrl_handler; struct v4l2_ctrl_handler ctrl_handler;
unsigned long freq; unsigned long freq;
int muted; u32 audmode;
struct snd_miro_aci *aci; struct snd_miro_aci *aci;
struct mutex lock; struct mutex lock;
}; };
static struct pcm20 pcm20_card = { static struct pcm20 pcm20_card = {
.freq = 87*16000, .freq = 87 * 16000,
.muted = 1, .audmode = V4L2_TUNER_MODE_STEREO,
}; };
static int pcm20_mute(struct pcm20 *dev, unsigned char mute)
{
dev->muted = mute;
return snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, mute, -1);
}
static int pcm20_stereo(struct pcm20 *dev, unsigned char stereo)
{
return snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO, !stereo, -1);
}
static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq) static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
{ {
unsigned char freql; unsigned char freql;
unsigned char freqh; unsigned char freqh;
struct snd_miro_aci *aci = dev->aci; struct snd_miro_aci *aci = dev->aci;
dev->freq = freq;
freq /= 160; freq /= 160;
if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0)) if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0))
freq /= 10; /* I don't know exactly which version freq /= 10; /* I don't know exactly which version
...@@ -71,7 +54,6 @@ static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq) ...@@ -71,7 +54,6 @@ static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
freql = freq & 0xff; freql = freq & 0xff;
freqh = freq >> 8; freqh = freq >> 8;
pcm20_stereo(dev, !mono);
return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh); return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh);
} }
...@@ -99,7 +81,9 @@ static int vidioc_querycap(struct file *file, void *priv, ...@@ -99,7 +81,9 @@ static int vidioc_querycap(struct file *file, void *priv,
static int vidioc_g_tuner(struct file *file, void *priv, static int vidioc_g_tuner(struct file *file, void *priv,
struct v4l2_tuner *v) struct v4l2_tuner *v)
{ {
if (v->index) /* Only 1 tuner */ struct pcm20 *dev = video_drvdata(file);
if (v->index)
return -EINVAL; return -EINVAL;
strlcpy(v->name, "FM", sizeof(v->name)); strlcpy(v->name, "FM", sizeof(v->name));
v->type = V4L2_TUNER_RADIO; v->type = V4L2_TUNER_RADIO;
...@@ -107,15 +91,23 @@ static int vidioc_g_tuner(struct file *file, void *priv, ...@@ -107,15 +91,23 @@ static int vidioc_g_tuner(struct file *file, void *priv,
v->rangehigh = 108*16000; v->rangehigh = 108*16000;
v->signal = 0xffff; v->signal = 0xffff;
v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
v->capability = V4L2_TUNER_CAP_LOW; v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
v->audmode = V4L2_TUNER_MODE_MONO; v->audmode = dev->audmode;
return 0; return 0;
} }
static int vidioc_s_tuner(struct file *file, void *priv, static int vidioc_s_tuner(struct file *file, void *priv,
struct v4l2_tuner *v) struct v4l2_tuner *v)
{ {
return v->index ? -EINVAL : 0; struct pcm20 *dev = video_drvdata(file);
if (v->index)
return -EINVAL;
if (v->audmode > V4L2_TUNER_MODE_STEREO)
v->audmode = V4L2_TUNER_MODE_STEREO;
snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO,
v->audmode == V4L2_TUNER_MODE_MONO, -1);
return 0;
} }
static int vidioc_g_frequency(struct file *file, void *priv, static int vidioc_g_frequency(struct file *file, void *priv,
...@@ -140,8 +132,8 @@ static int vidioc_s_frequency(struct file *file, void *priv, ...@@ -140,8 +132,8 @@ static int vidioc_s_frequency(struct file *file, void *priv,
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
return -EINVAL; return -EINVAL;
dev->freq = f->frequency; dev->freq = clamp(f->frequency, 87 * 16000U, 108 * 16000U);
pcm20_setfreq(dev, f->frequency); pcm20_setfreq(dev, dev->freq);
return 0; return 0;
} }
...@@ -151,7 +143,7 @@ static int pcm20_s_ctrl(struct v4l2_ctrl *ctrl) ...@@ -151,7 +143,7 @@ static int pcm20_s_ctrl(struct v4l2_ctrl *ctrl)
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
pcm20_mute(dev, ctrl->val); snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, ctrl->val, -1);
return 0; return 0;
} }
return -EINVAL; return -EINVAL;
...@@ -212,6 +204,9 @@ static int __init pcm20_init(void) ...@@ -212,6 +204,9 @@ static int __init pcm20_init(void)
dev->vdev.lock = &dev->lock; dev->vdev.lock = &dev->lock;
set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags); set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
video_set_drvdata(&dev->vdev, dev); video_set_drvdata(&dev->vdev, dev);
snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO,
dev->audmode == V4L2_TUNER_MODE_MONO, -1);
pcm20_setfreq(dev, dev->freq);
if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0)
goto err_hdl; goto err_hdl;
...@@ -233,6 +228,7 @@ static void __exit pcm20_cleanup(void) ...@@ -233,6 +228,7 @@ static void __exit pcm20_cleanup(void)
struct pcm20 *dev = &pcm20_card; struct pcm20 *dev = &pcm20_card;
video_unregister_device(&dev->vdev); video_unregister_device(&dev->vdev);
snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, 1, -1);
v4l2_ctrl_handler_free(&dev->ctrl_handler); v4l2_ctrl_handler_free(&dev->ctrl_handler);
v4l2_device_unregister(&dev->v4l2_dev); v4l2_device_unregister(&dev->v4l2_dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment