V4L/DVB (5623): Dsbr100.c Replace usb_dsbr100_do_ioctl to use video_ioctl2

Convert dsbr100 to use video_ioctl2

Signed-off-by:  Douglas Schilling Landgraf <dougsland@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
This commit is contained in:
Douglas Landgraf 2007-05-07 16:43:01 -03:00 committed by Mauro Carvalho Chehab
parent 2437c6d47c
commit 7002a4f350

View file

@ -33,6 +33,10 @@
History: History:
Version 0.42:
Converted dsbr100 to use video_ioctl2
by Douglas Landgraf <dougsland@gmail.com>
Version 0.41-ac1: Version 0.41-ac1:
Alan Cox: Some cleanups and fixes Alan Cox: Some cleanups and fixes
@ -121,8 +125,6 @@ devices, that would be 76 and 91. */
static int usb_dsbr100_probe(struct usb_interface *intf, static int usb_dsbr100_probe(struct usb_interface *intf,
const struct usb_device_id *id); const struct usb_device_id *id);
static void usb_dsbr100_disconnect(struct usb_interface *intf); static void usb_dsbr100_disconnect(struct usb_interface *intf);
static int usb_dsbr100_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg);
static int usb_dsbr100_open(struct inode *inode, struct file *file); static int usb_dsbr100_open(struct inode *inode, struct file *file);
static int usb_dsbr100_close(struct inode *inode, struct file *file); static int usb_dsbr100_close(struct inode *inode, struct file *file);
@ -142,26 +144,6 @@ struct dsbr100_device {
}; };
/* File system interface */
static const struct file_operations usb_dsbr100_fops = {
.owner = THIS_MODULE,
.open = usb_dsbr100_open,
.release = usb_dsbr100_close,
.ioctl = usb_dsbr100_ioctl,
.compat_ioctl = v4l_compat_ioctl32,
.llseek = no_llseek,
};
/* V4L interface */
static struct video_device dsbr100_videodev_template=
{
.owner = THIS_MODULE,
.name = "D-Link DSB-R 100",
.type = VID_TYPE_TUNER,
.fops = &usb_dsbr100_fops,
.release = video_device_release,
};
static struct usb_device_id usb_dsbr100_device_table [] = { static struct usb_device_id usb_dsbr100_device_table [] = {
{ USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) }, { USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) },
{ } /* Terminating entry */ { } /* Terminating entry */
@ -252,37 +234,6 @@ static void dsbr100_getstat(struct dsbr100_device *radio)
/* USB subsystem interface begins here */ /* USB subsystem interface begins here */
/* check if the device is present and register with v4l and
usb if it is */
static int usb_dsbr100_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct dsbr100_device *radio;
if (!(radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL)))
return -ENOMEM;
if (!(radio->videodev = video_device_alloc())) {
kfree(radio);
return -ENOMEM;
}
memcpy(radio->videodev, &dsbr100_videodev_template,
sizeof(dsbr100_videodev_template));
radio->removed = 0;
radio->users = 0;
radio->usbdev = interface_to_usbdev(intf);
radio->curfreq = FREQ_MIN*FREQ_MUL;
video_set_drvdata(radio->videodev, radio);
if (video_register_device(radio->videodev, VFL_TYPE_RADIO,
radio_nr)) {
warn("Could not register video device");
video_device_release(radio->videodev);
kfree(radio);
return -EIO;
}
usb_set_intfdata(intf, radio);
return 0;
}
/* handle unplugging of the device, release data structures /* handle unplugging of the device, release data structures
if nothing keeps us from doing it. If something is still if nothing keeps us from doing it. If something is still
keeping us busy, the release callback of v4l will take care keeping us busy, the release callback of v4l will take care
@ -307,42 +258,28 @@ static void usb_dsbr100_disconnect(struct usb_interface *intf)
} }
/* Video for Linux interface */ static int vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *v)
static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *arg)
{ {
struct dsbr100_device *radio=video_get_drvdata(video_devdata(file));
if (!radio)
return -EIO;
switch(cmd) {
case VIDIOC_QUERYCAP:
{
struct v4l2_capability *v = arg;
memset(v,0,sizeof(*v));
strlcpy(v->driver, "dsbr100", sizeof(v->driver)); strlcpy(v->driver, "dsbr100", sizeof(v->driver));
strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card)); strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card));
sprintf(v->bus_info, "ISA"); sprintf(v->bus_info, "ISA");
v->version = RADIO_VERSION; v->version = RADIO_VERSION;
v->capabilities = V4L2_CAP_TUNER; v->capabilities = V4L2_CAP_TUNER;
return 0; return 0;
} }
case VIDIOC_G_TUNER:
static int vidioc_g_tuner(struct file *file, void *priv,
struct v4l2_tuner *v)
{ {
struct v4l2_tuner *v = arg; struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
if (v->index > 0) if (v->index > 0)
return -EINVAL; return -EINVAL;
dsbr100_getstat(radio); dsbr100_getstat(radio);
memset(v,0,sizeof(*v));
strcpy(v->name, "FM"); strcpy(v->name, "FM");
v->type = V4L2_TUNER_RADIO; v->type = V4L2_TUNER_RADIO;
v->rangelow = FREQ_MIN*FREQ_MUL; v->rangelow = FREQ_MIN*FREQ_MUL;
v->rangehigh = FREQ_MAX*FREQ_MUL; v->rangehigh = FREQ_MAX*FREQ_MUL;
v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
@ -351,40 +288,43 @@ static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
v->audmode = V4L2_TUNER_MODE_STEREO; v->audmode = V4L2_TUNER_MODE_STEREO;
else else
v->audmode = V4L2_TUNER_MODE_MONO; v->audmode = V4L2_TUNER_MODE_MONO;
v->signal = 0xFFFF; /* We can't get the signal strength */ v->signal = 0xffff; /* We can't get the signal strength */
return 0; return 0;
} }
case VIDIOC_S_TUNER:
{
struct v4l2_tuner *v = arg;
static int vidioc_s_tuner(struct file *file, void *priv,
struct v4l2_tuner *v)
{
if (v->index > 0) if (v->index > 0)
return -EINVAL; return -EINVAL;
return 0; return 0;
} }
case VIDIOC_S_FREQUENCY:
static int vidioc_s_frequency(struct file *file, void *priv,
struct v4l2_frequency *f)
{ {
struct v4l2_frequency *f = arg; struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
radio->curfreq = f->frequency; radio->curfreq = f->frequency;
if (dsbr100_setfreq(radio, radio->curfreq)==-1) if (dsbr100_setfreq(radio, radio->curfreq)==-1)
warn("Set frequency failed"); warn("Set frequency failed");
return 0; return 0;
} }
case VIDIOC_G_FREQUENCY:
static int vidioc_g_frequency(struct file *file, void *priv,
struct v4l2_frequency *f)
{ {
struct v4l2_frequency *f = arg; struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
f->type = V4L2_TUNER_RADIO; f->type = V4L2_TUNER_RADIO;
f->frequency = radio->curfreq; f->frequency = radio->curfreq;
return 0; return 0;
} }
case VIDIOC_QUERYCTRL:
static int vidioc_queryctrl(struct file *file, void *priv,
struct v4l2_queryctrl *qc)
{ {
struct v4l2_queryctrl *qc = arg;
int i; int i;
for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
@ -396,9 +336,11 @@ static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
} }
return -EINVAL; return -EINVAL;
} }
case VIDIOC_G_CTRL:
static int vidioc_g_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)
{ {
struct v4l2_control *ctrl= arg; struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
@ -407,9 +349,11 @@ static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
} }
return -EINVAL; return -EINVAL;
} }
case VIDIOC_S_CTRL:
static int vidioc_s_ctrl(struct file *file, void *priv,
struct v4l2_control *ctrl)
{ {
struct v4l2_control *ctrl= arg; struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_AUDIO_MUTE: case V4L2_CID_AUDIO_MUTE:
@ -424,16 +368,37 @@ static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file,
} }
return -EINVAL; return -EINVAL;
} }
default:
return v4l_compat_translate_ioctl(inode,file,cmd,arg, static int vidioc_g_audio(struct file *file, void *priv,
usb_dsbr100_do_ioctl); struct v4l2_audio *a)
} {
if (a->index > 1)
return -EINVAL;
strcpy(a->name, "Radio");
a->capability = V4L2_AUDCAP_STEREO;
return 0;
} }
static int usb_dsbr100_ioctl(struct inode *inode, struct file *file, static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
unsigned int cmd, unsigned long arg)
{ {
return video_usercopy(inode, file, cmd, arg, usb_dsbr100_do_ioctl); *i = 0;
return 0;
}
static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
{
if (i != 0)
return -EINVAL;
return 0;
}
static int vidioc_s_audio(struct file *file, void *priv,
struct v4l2_audio *a)
{
if (a->index != 0)
return -EINVAL;
return 0;
} }
static int usb_dsbr100_open(struct inode *inode, struct file *file) static int usb_dsbr100_open(struct inode *inode, struct file *file)
@ -465,6 +430,68 @@ static int usb_dsbr100_close(struct inode *inode, struct file *file)
return 0; return 0;
} }
/* File system interface */
static const struct file_operations usb_dsbr100_fops = {
.owner = THIS_MODULE,
.open = usb_dsbr100_open,
.release = usb_dsbr100_close,
.ioctl = video_ioctl2,
.compat_ioctl = v4l_compat_ioctl32,
.llseek = no_llseek,
};
/* V4L2 interface */
static struct video_device dsbr100_videodev_template =
{
.owner = THIS_MODULE,
.name = "D-Link DSB-R 100",
.type = VID_TYPE_TUNER,
.fops = &usb_dsbr100_fops,
.release = video_device_release,
.vidioc_querycap = vidioc_querycap,
.vidioc_g_tuner = vidioc_g_tuner,
.vidioc_s_tuner = vidioc_s_tuner,
.vidioc_g_frequency = vidioc_g_frequency,
.vidioc_s_frequency = vidioc_s_frequency,
.vidioc_queryctrl = vidioc_queryctrl,
.vidioc_g_ctrl = vidioc_g_ctrl,
.vidioc_s_ctrl = vidioc_s_ctrl,
.vidioc_g_audio = vidioc_g_audio,
.vidioc_s_audio = vidioc_s_audio,
.vidioc_g_input = vidioc_g_input,
.vidioc_s_input = vidioc_s_input,
};
/* check if the device is present and register with v4l and
usb if it is */
static int usb_dsbr100_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct dsbr100_device *radio;
if (!(radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL)))
return -ENOMEM;
if (!(radio->videodev = video_device_alloc())) {
kfree(radio);
return -ENOMEM;
}
memcpy(radio->videodev, &dsbr100_videodev_template,
sizeof(dsbr100_videodev_template));
radio->removed = 0;
radio->users = 0;
radio->usbdev = interface_to_usbdev(intf);
radio->curfreq = FREQ_MIN*FREQ_MUL;
video_set_drvdata(radio->videodev, radio);
if (video_register_device(radio->videodev, VFL_TYPE_RADIO,radio_nr)) {
warn("Could not register video device");
video_device_release(radio->videodev);
kfree(radio);
return -EIO;
}
usb_set_intfdata(intf, radio);
return 0;
}
static int __init dsbr100_init(void) static int __init dsbr100_init(void)
{ {
int retval = usb_register(&usb_dsbr100_driver); int retval = usb_register(&usb_dsbr100_driver);