Commit 406827cc authored by Alexey Klimov's avatar Alexey Klimov Committed by Mauro Carvalho Chehab

V4L/DVB (11435): dsbr100 radio: convert to to v4l2_device

dsbr100: convert to v4l2_device.
Signed-off-by: default avatarAlexey Klimov <klimov.linux@gmail.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent ec624803
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
History: History:
Version 0.45:
Converted to v4l2_device.
Version 0.44: Version 0.44:
Add suspend/resume functions, fix unplug of device, Add suspend/resume functions, fix unplug of device,
a lot of cleanups and fixes by Alexey Klimov <klimov.linux@gmail.com> a lot of cleanups and fixes by Alexey Klimov <klimov.linux@gmail.com>
...@@ -88,7 +91,7 @@ ...@@ -88,7 +91,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/v4l2-common.h> #include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
#include <linux/usb.h> #include <linux/usb.h>
...@@ -97,39 +100,8 @@ ...@@ -97,39 +100,8 @@
*/ */
#include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/version.h> /* for KERNEL_VERSION MACRO */
#define DRIVER_VERSION "v0.44" #define DRIVER_VERSION "v0.45"
#define RADIO_VERSION KERNEL_VERSION(0, 4, 4) #define RADIO_VERSION KERNEL_VERSION(0, 4, 5)
static struct v4l2_queryctrl radio_qctrl[] = {
{
.id = V4L2_CID_AUDIO_MUTE,
.name = "Mute",
.minimum = 0,
.maximum = 1,
.default_value = 1,
.type = V4L2_CTRL_TYPE_BOOLEAN,
},
/* HINT: the disabled controls are only here to satify kradio and such apps */
{ .id = V4L2_CID_AUDIO_VOLUME,
.flags = V4L2_CTRL_FLAG_DISABLED,
},
{
.id = V4L2_CID_AUDIO_BALANCE,
.flags = V4L2_CTRL_FLAG_DISABLED,
},
{
.id = V4L2_CID_AUDIO_BASS,
.flags = V4L2_CTRL_FLAG_DISABLED,
},
{
.id = V4L2_CID_AUDIO_TREBLE,
.flags = V4L2_CTRL_FLAG_DISABLED,
},
{
.id = V4L2_CID_AUDIO_LOUDNESS,
.flags = V4L2_CTRL_FLAG_DISABLED,
},
};
#define DRIVER_AUTHOR "Markus Demleitner <msdemlei@tucana.harvard.edu>" #define DRIVER_AUTHOR "Markus Demleitner <msdemlei@tucana.harvard.edu>"
#define DRIVER_DESC "D-Link DSB-R100 USB FM radio driver" #define DRIVER_DESC "D-Link DSB-R100 USB FM radio driver"
...@@ -167,6 +139,8 @@ module_param(radio_nr, int, 0); ...@@ -167,6 +139,8 @@ module_param(radio_nr, int, 0);
struct dsbr100_device { struct dsbr100_device {
struct usb_device *usbdev; struct usb_device *usbdev;
struct video_device videodev; struct video_device videodev;
struct v4l2_device v4l2_dev;
u8 *transfer_buffer; u8 *transfer_buffer;
struct mutex lock; /* buffer locking */ struct mutex lock; /* buffer locking */
int curfreq; int curfreq;
...@@ -384,6 +358,7 @@ static void usb_dsbr100_disconnect(struct usb_interface *intf) ...@@ -384,6 +358,7 @@ static void usb_dsbr100_disconnect(struct usb_interface *intf)
mutex_unlock(&radio->lock); mutex_unlock(&radio->lock);
video_unregister_device(&radio->videodev); video_unregister_device(&radio->videodev);
v4l2_device_disconnect(&radio->v4l2_dev);
} }
...@@ -479,14 +454,11 @@ static int vidioc_g_frequency(struct file *file, void *priv, ...@@ -479,14 +454,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
static int vidioc_queryctrl(struct file *file, void *priv, static int vidioc_queryctrl(struct file *file, void *priv,
struct v4l2_queryctrl *qc) struct v4l2_queryctrl *qc)
{ {
int i; switch (qc->id) {
case V4L2_CID_AUDIO_MUTE:
for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
if (qc->id && qc->id == radio_qctrl[i].id) {
memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
return 0;
}
} }
return -EINVAL; return -EINVAL;
} }
...@@ -656,6 +628,7 @@ static void usb_dsbr100_video_device_release(struct video_device *videodev) ...@@ -656,6 +628,7 @@ static void usb_dsbr100_video_device_release(struct video_device *videodev)
{ {
struct dsbr100_device *radio = videodev_to_radio(videodev); struct dsbr100_device *radio = videodev_to_radio(videodev);
v4l2_device_unregister(&radio->v4l2_dev);
kfree(radio->transfer_buffer); kfree(radio->transfer_buffer);
kfree(radio); kfree(radio);
} }
...@@ -683,22 +656,15 @@ static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = { ...@@ -683,22 +656,15 @@ static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
.vidioc_s_input = vidioc_s_input, .vidioc_s_input = vidioc_s_input,
}; };
/* V4L2 interface */
static struct video_device dsbr100_videodev_data = {
.name = "D-Link DSB-R 100",
.fops = &usb_dsbr100_fops,
.ioctl_ops = &usb_dsbr100_ioctl_ops,
.release = usb_dsbr100_video_device_release,
};
/* check if the device is present and register with v4l and usb if it is */ /* check if the device is present and register with v4l and usb if it is */
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)
{ {
struct dsbr100_device *radio; struct dsbr100_device *radio;
struct v4l2_device *v4l2_dev;
int retval; int retval;
radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL); radio = kzalloc(sizeof(struct dsbr100_device), GFP_KERNEL);
if (!radio) if (!radio)
return -ENOMEM; return -ENOMEM;
...@@ -710,17 +676,35 @@ static int usb_dsbr100_probe(struct usb_interface *intf, ...@@ -710,17 +676,35 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
return -ENOMEM; return -ENOMEM;
} }
v4l2_dev = &radio->v4l2_dev;
retval = v4l2_device_register(&intf->dev, v4l2_dev);
if (retval < 0) {
v4l2_err(v4l2_dev, "couldn't register v4l2_device\n");
kfree(radio->transfer_buffer);
kfree(radio);
return retval;
}
strlcpy(radio->videodev.name, v4l2_dev->name, sizeof(radio->videodev.name));
radio->videodev.v4l2_dev = v4l2_dev;
radio->videodev.fops = &usb_dsbr100_fops;
radio->videodev.ioctl_ops = &usb_dsbr100_ioctl_ops;
radio->videodev.release = usb_dsbr100_video_device_release;
mutex_init(&radio->lock); mutex_init(&radio->lock);
radio->videodev = dsbr100_videodev_data;
radio->removed = 0; radio->removed = 0;
radio->users = 0; radio->users = 0;
radio->usbdev = interface_to_usbdev(intf); radio->usbdev = interface_to_usbdev(intf);
radio->curfreq = FREQ_MIN * FREQ_MUL; radio->curfreq = FREQ_MIN * FREQ_MUL;
video_set_drvdata(&radio->videodev, radio); video_set_drvdata(&radio->videodev, radio);
retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr); retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr);
if (retval < 0) { if (retval < 0) {
dev_err(&intf->dev, "couldn't register video device\n"); v4l2_err(v4l2_dev, "couldn't register video device\n");
v4l2_device_unregister(v4l2_dev);
kfree(radio->transfer_buffer); kfree(radio->transfer_buffer);
kfree(radio); kfree(radio);
return -EIO; return -EIO;
......
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