Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 242127
b: refs/heads/master
c: e64d07c
h: refs/heads/master
i:
  242125: 45f521f
  242123: bb66dec
  242119: c765b74
  242111: bf5ced2
v: v3
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Mar 22, 2011
1 parent c9562fb commit 0190bff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 49 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2335e2b817186cf79a07311f14560ef8b30f6a9a
refs/heads/master: e64d07c92daa5c7973c1d4433f939a4e0fa3beb9
79 changes: 31 additions & 48 deletions trunk/drivers/media/radio/dsbr100.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct dsbr100_device {
struct v4l2_device v4l2_dev;

u8 *transfer_buffer;
struct mutex lock; /* buffer locking */
struct mutex v4l2_lock;
int curfreq;
int stereo;
int removed;
Expand Down Expand Up @@ -182,8 +182,6 @@ static int dsbr100_start(struct dsbr100_device *radio)
int retval;
int request;

mutex_lock(&radio->lock);

retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0),
USB_REQ_GET_STATUS,
Expand All @@ -207,11 +205,9 @@ static int dsbr100_start(struct dsbr100_device *radio)
}

radio->status = STARTED;
mutex_unlock(&radio->lock);
return (radio->transfer_buffer)[0];

usb_control_msg_failed:
mutex_unlock(&radio->lock);
dev_err(&radio->usbdev->dev,
"%s - usb_control_msg returned %i, request %i\n",
__func__, retval, request);
Expand All @@ -225,8 +221,6 @@ static int dsbr100_stop(struct dsbr100_device *radio)
int retval;
int request;

mutex_lock(&radio->lock);

retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0),
USB_REQ_GET_STATUS,
Expand All @@ -250,11 +244,9 @@ static int dsbr100_stop(struct dsbr100_device *radio)
}

radio->status = STOPPED;
mutex_unlock(&radio->lock);
return (radio->transfer_buffer)[0];

usb_control_msg_failed:
mutex_unlock(&radio->lock);
dev_err(&radio->usbdev->dev,
"%s - usb_control_msg returned %i, request %i\n",
__func__, retval, request);
Expand All @@ -269,8 +261,6 @@ static int dsbr100_setfreq(struct dsbr100_device *radio)
int request;
int freq = (radio->curfreq / 16 * 80) / 1000 + 856;

mutex_lock(&radio->lock);

retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0),
DSB100_TUNE,
Expand Down Expand Up @@ -306,12 +296,10 @@ static int dsbr100_setfreq(struct dsbr100_device *radio)
}

radio->stereo = !((radio->transfer_buffer)[0] & 0x01);
mutex_unlock(&radio->lock);
return (radio->transfer_buffer)[0];

usb_control_msg_failed:
radio->stereo = -1;
mutex_unlock(&radio->lock);
dev_err(&radio->usbdev->dev,
"%s - usb_control_msg returned %i, request %i\n",
__func__, retval, request);
Expand All @@ -324,8 +312,6 @@ static void dsbr100_getstat(struct dsbr100_device *radio)
{
int retval;

mutex_lock(&radio->lock);

retval = usb_control_msg(radio->usbdev,
usb_rcvctrlpipe(radio->usbdev, 0),
USB_REQ_GET_STATUS,
Expand All @@ -340,33 +326,8 @@ static void dsbr100_getstat(struct dsbr100_device *radio)
} else {
radio->stereo = !(radio->transfer_buffer[0] & 0x01);
}

mutex_unlock(&radio->lock);
}

/* USB subsystem interface begins here */

/*
* Handle unplugging of the device.
* We call video_unregister_device in any case.
* The last function called in this procedure is
* usb_dsbr100_video_device_release
*/
static void usb_dsbr100_disconnect(struct usb_interface *intf)
{
struct dsbr100_device *radio = usb_get_intfdata(intf);

usb_set_intfdata (intf, NULL);

mutex_lock(&radio->lock);
radio->removed = 1;
mutex_unlock(&radio->lock);

video_unregister_device(&radio->videodev);
v4l2_device_disconnect(&radio->v4l2_dev);
}


static int vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *v)
{
Expand Down Expand Up @@ -432,9 +393,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
if (radio->removed)
return -EIO;

mutex_lock(&radio->lock);
radio->curfreq = f->frequency;
mutex_unlock(&radio->lock);

retval = dsbr100_setfreq(radio);
if (retval < 0)
Expand Down Expand Up @@ -548,12 +507,36 @@ static int vidioc_s_audio(struct file *file, void *priv,
return 0;
}

/* USB subsystem interface begins here */

/*
* Handle unplugging of the device.
* We call video_unregister_device in any case.
* The last function called in this procedure is
* usb_dsbr100_video_device_release
*/
static void usb_dsbr100_disconnect(struct usb_interface *intf)
{
struct dsbr100_device *radio = usb_get_intfdata(intf);

usb_set_intfdata(intf, NULL);

mutex_lock(&radio->v4l2_lock);
radio->removed = 1;
mutex_unlock(&radio->v4l2_lock);

video_unregister_device(&radio->videodev);
v4l2_device_disconnect(&radio->v4l2_dev);
}


/* Suspend device - stop device. */
static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message)
{
struct dsbr100_device *radio = usb_get_intfdata(intf);
int retval;

mutex_lock(&radio->v4l2_lock);
if (radio->status == STARTED) {
retval = dsbr100_stop(radio);
if (retval < 0)
Expand All @@ -564,11 +547,9 @@ static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message)
* we set status equal to STARTED.
* On resume we will check status and run radio if needed.
*/

mutex_lock(&radio->lock);
radio->status = STARTED;
mutex_unlock(&radio->lock);
}
mutex_unlock(&radio->v4l2_lock);

dev_info(&intf->dev, "going into suspend..\n");

Expand All @@ -581,11 +562,13 @@ static int usb_dsbr100_resume(struct usb_interface *intf)
struct dsbr100_device *radio = usb_get_intfdata(intf);
int retval;

mutex_lock(&radio->v4l2_lock);
if (radio->status == STARTED) {
retval = dsbr100_start(radio);
if (retval < 0)
dev_warn(&intf->dev, "dsbr100_start failed\n");
}
mutex_unlock(&radio->v4l2_lock);

dev_info(&intf->dev, "coming out of suspend..\n");

Expand All @@ -605,7 +588,7 @@ static void usb_dsbr100_video_device_release(struct video_device *videodev)
/* File system interface */
static const struct v4l2_file_operations usb_dsbr100_fops = {
.owner = THIS_MODULE,
.ioctl = video_ioctl2,
.unlocked_ioctl = video_ioctl2,
};

static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
Expand Down Expand Up @@ -653,13 +636,13 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
return retval;
}

mutex_init(&radio->v4l2_lock);
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);
radio->videodev.lock = &radio->v4l2_lock;

radio->removed = 0;
radio->usbdev = interface_to_usbdev(intf);
Expand Down

0 comments on commit 0190bff

Please sign in to comment.