Merge branches 'topic/fix/asoc', 'topic/fix/hda', 'topic/fix/misc' and 'topic/pci...
[firefly-linux-kernel-4.4.55.git] / drivers / media / radio / radio-sf16fmr2.c
index 6290553d24beef56cf55ecfbe55aab32ae0ad620..b1f47c322e02637e58b2117a3c7df2e51656dd76 100644 (file)
@@ -64,6 +64,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
 /* this should be static vars for module size */
 struct fmr2_device
 {
+       unsigned long in_use;
        int port;
        int curvol; /* 0-15 */
        int mute;
@@ -229,8 +230,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
        int mult;
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -262,8 +262,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        if (!(fmr2->flags & V4L2_TUNER_CAP_LOW))
                f->frequency *= 1000;
@@ -286,8 +285,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = fmr2->curfreq;
@@ -313,8 +311,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -330,8 +327,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -400,10 +396,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static struct fmr2_device fmr2_unit;
 
+static int fmr2_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &fmr2_unit.in_use) ? -EBUSY : 0;
+}
+
+static int fmr2_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &fmr2_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations fmr2_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = fmr2_exclusive_open,
+       .release        = fmr2_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -430,6 +437,7 @@ static struct video_device fmr2_radio = {
        .name           = "SF16FMR2 radio",
        .fops           = &fmr2_fops,
        .ioctl_ops      = &fmr2_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init fmr2_init(void)
@@ -441,7 +449,7 @@ static int __init fmr2_init(void)
        fmr2_unit.stereo = 1;
        fmr2_unit.flags = V4L2_TUNER_CAP_LOW;
        fmr2_unit.card_type = 0;
-       fmr2_radio.priv = &fmr2_unit;
+       video_set_drvdata(&fmr2_radio, &fmr2_unit);
 
        mutex_init(&lock);