[media] radio-sf16fmi: convert to the control framework

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
Hans Verkuil 2013-02-03 09:51:06 -03:00 committed by Mauro Carvalho Chehab
parent 96bb42b8ab
commit 268d06bb76
1 changed files with 25 additions and 31 deletions

View File

@ -27,6 +27,7 @@
#include <linux/io.h> /* outb, outb_p */ #include <linux/io.h> /* outb, outb_p */
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
#include <media/v4l2-ctrls.h>
#include "lm7000.h" #include "lm7000.h"
MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood"); MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood");
@ -44,6 +45,7 @@ module_param(radio_nr, int, 0);
struct fmi struct fmi
{ {
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
struct v4l2_ctrl_handler hdl;
struct video_device vdev; struct video_device vdev;
int io; int io;
bool mute; bool mute;
@ -178,46 +180,26 @@ static int vidioc_g_frequency(struct file *file, void *priv,
return 0; return 0;
} }
static int vidioc_queryctrl(struct file *file, void *priv, static int fmi_s_ctrl(struct v4l2_ctrl *ctrl)
struct v4l2_queryctrl *qc)
{ {
switch (qc->id) { struct fmi *fmi = container_of(ctrl->handler, struct fmi, hdl);
case V4L2_CID_AUDIO_MUTE:
return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
}
return -EINVAL;
}
static int vidioc_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)
{
struct fmi *fmi = video_drvdata(file);
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
ctrl->value = fmi->mute; if (ctrl->val)
return 0;
}
return -EINVAL;
}
static int vidioc_s_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)
{
struct fmi *fmi = video_drvdata(file);
switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE:
if (ctrl->value)
fmi_mute(fmi); fmi_mute(fmi);
else else
fmi_unmute(fmi); fmi_unmute(fmi);
fmi->mute = ctrl->value; fmi->mute = ctrl->val;
return 0; return 0;
} }
return -EINVAL; return -EINVAL;
} }
static const struct v4l2_ctrl_ops fmi_ctrl_ops = {
.s_ctrl = fmi_s_ctrl,
};
static const struct v4l2_file_operations fmi_fops = { static const struct v4l2_file_operations fmi_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.unlocked_ioctl = video_ioctl2, .unlocked_ioctl = video_ioctl2,
@ -229,9 +211,6 @@ static const struct v4l2_ioctl_ops fmi_ioctl_ops = {
.vidioc_s_tuner = vidioc_s_tuner, .vidioc_s_tuner = vidioc_s_tuner,
.vidioc_g_frequency = vidioc_g_frequency, .vidioc_g_frequency = vidioc_g_frequency,
.vidioc_s_frequency = vidioc_s_frequency, .vidioc_s_frequency = vidioc_s_frequency,
.vidioc_queryctrl = vidioc_queryctrl,
.vidioc_g_ctrl = vidioc_g_ctrl,
.vidioc_s_ctrl = vidioc_s_ctrl,
}; };
/* ladis: this is my card. does any other types exist? */ /* ladis: this is my card. does any other types exist? */
@ -281,6 +260,7 @@ static int __init fmi_init(void)
{ {
struct fmi *fmi = &fmi_card; struct fmi *fmi = &fmi_card;
struct v4l2_device *v4l2_dev = &fmi->v4l2_dev; struct v4l2_device *v4l2_dev = &fmi->v4l2_dev;
struct v4l2_ctrl_handler *hdl = &fmi->hdl;
int res, i; int res, i;
int probe_ports[] = { 0, 0x284, 0x384 }; int probe_ports[] = { 0, 0x284, 0x384 };
@ -333,6 +313,18 @@ static int __init fmi_init(void)
return res; return res;
} }
v4l2_ctrl_handler_init(hdl, 1);
v4l2_ctrl_new_std(hdl, &fmi_ctrl_ops,
V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
v4l2_dev->ctrl_handler = hdl;
if (hdl->error) {
res = hdl->error;
v4l2_err(v4l2_dev, "Could not register controls\n");
v4l2_ctrl_handler_free(hdl);
v4l2_device_unregister(v4l2_dev);
return res;
}
strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name)); strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name));
fmi->vdev.v4l2_dev = v4l2_dev; fmi->vdev.v4l2_dev = v4l2_dev;
fmi->vdev.fops = &fmi_fops; fmi->vdev.fops = &fmi_fops;
@ -346,6 +338,7 @@ static int __init fmi_init(void)
fmi_mute(fmi); fmi_mute(fmi);
if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
v4l2_ctrl_handler_free(hdl);
v4l2_device_unregister(v4l2_dev); v4l2_device_unregister(v4l2_dev);
release_region(fmi->io, 2); release_region(fmi->io, 2);
if (pnp_attached) if (pnp_attached)
@ -361,6 +354,7 @@ static void __exit fmi_exit(void)
{ {
struct fmi *fmi = &fmi_card; struct fmi *fmi = &fmi_card;
v4l2_ctrl_handler_free(&fmi->hdl);
video_unregister_device(&fmi->vdev); video_unregister_device(&fmi->vdev);
v4l2_device_unregister(&fmi->v4l2_dev); v4l2_device_unregister(&fmi->v4l2_dev);
release_region(fmi->io, 2); release_region(fmi->io, 2);