Commit b955c567 authored by Gerd Knorr's avatar Gerd Knorr Committed by Linus Torvalds

[PATCH] v4l: miro radio update

The updates for the radio driver are all very similar:  The individual
open functions are gone and replaced by the video_exclusive_open/release
functions in videodev.c.  All userspace copying in the ioctl function is
gone because video_generic_ioctl handles this now.  The driver source
files all become slightly shorter because of this.
parent a653099c
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "../../../sound/oss/aci.h" #include "../../../sound/oss/aci.h"
#include "miropcm20-rds-core.h" #include "miropcm20-rds-core.h"
static int users = 0;
static int radio_nr = -1; static int radio_nr = -1;
MODULE_PARM(radio_nr, "i"); MODULE_PARM(radio_nr, "i");
...@@ -122,96 +121,86 @@ static int pcm20_getflags(struct pcm20_device *dev, __u32 *flags, __u16 *signal) ...@@ -122,96 +121,86 @@ static int pcm20_getflags(struct pcm20_device *dev, __u32 *flags, __u16 *signal)
return 0; return 0;
} }
static int pcm20_ioctl(struct video_device *dev, unsigned int cmd, void *arg) static int pcm20_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, void *arg)
{ {
struct pcm20_device *pcm20=dev->priv; struct video_device *dev = video_devdata(file);
struct pcm20_device *pcm20 = dev->priv;
int i; int i;
switch(cmd) switch(cmd)
{ {
case VIDIOCGCAP: case VIDIOCGCAP:
{ {
struct video_capability v; struct video_capability *v = arg;
v.type=VID_TYPE_TUNER; memset(v,0,sizeof(*v));
strcpy(v.name, "Miro PCM20"); v->type=VID_TYPE_TUNER;
v.channels=1; strcpy(v->name, "Miro PCM20");
v.audios=1; v->channels=1;
/* No we don't do pictures */ v->audios=1;
v.maxwidth=0;
v.maxheight=0;
v.minwidth=0;
v.minheight=0;
if(copy_to_user(arg,&v,sizeof(v)))
return -EFAULT;
return 0; return 0;
} }
case VIDIOCGTUNER: case VIDIOCGTUNER:
{ {
struct video_tuner v; struct video_tuner *v = arg;
if(copy_from_user(&v, arg,sizeof(v))!=0) if(v->tuner) /* Only 1 tuner */
return -EFAULT;
if(v.tuner) /* Only 1 tuner */
return -EINVAL; return -EINVAL;
v.rangelow=87*16000; v->rangelow=87*16000;
v.rangehigh=108*16000; v->rangehigh=108*16000;
pcm20_getflags(pcm20, &v.flags, &v.signal); pcm20_getflags(pcm20, &v->flags, &v->signal);
v.flags|=VIDEO_TUNER_LOW; v->flags|=VIDEO_TUNER_LOW;
v.mode=VIDEO_MODE_AUTO; v->mode=VIDEO_MODE_AUTO;
strcpy(v.name, "FM"); strcpy(v->name, "FM");
if(copy_to_user(arg,&v, sizeof(v)))
return -EFAULT;
return 0; return 0;
} }
case VIDIOCSTUNER: case VIDIOCSTUNER:
{ {
struct video_tuner v; struct video_tuner *v = arg;
if(copy_from_user(&v, arg, sizeof(v))) if(v->tuner!=0)
return -EFAULT;
if(v.tuner!=0)
return -EINVAL; return -EINVAL;
/* Only 1 tuner so no setting needed ! */ /* Only 1 tuner so no setting needed ! */
return 0; return 0;
} }
case VIDIOCGFREQ: case VIDIOCGFREQ:
if(copy_to_user(arg, &pcm20->freq, sizeof(pcm20->freq))) {
return -EFAULT; unsigned long *freq = arg;
*freq = pcm20->freq;
return 0; return 0;
}
case VIDIOCSFREQ: case VIDIOCSFREQ:
if(copy_from_user(&pcm20->freq, arg, sizeof(pcm20->freq))) {
return -EFAULT; unsigned long *freq = arg;
pcm20->freq = *freq;
i=pcm20_setfreq(pcm20, pcm20->freq); i=pcm20_setfreq(pcm20, pcm20->freq);
#if DEBUG #if DEBUG
printk("First view (setfreq): 0x%x\n", i); printk("First view (setfreq): 0x%x\n", i);
#endif #endif
return i; return i;
}
case VIDIOCGAUDIO: case VIDIOCGAUDIO:
{ {
struct video_audio v; struct video_audio *v = arg;
memset(&v,0, sizeof(v)); memset(v,0, sizeof(*v));
v.flags=VIDEO_AUDIO_MUTABLE; v->flags=VIDEO_AUDIO_MUTABLE;
if (pcm20->muted) if (pcm20->muted)
v.flags|=VIDEO_AUDIO_MUTE; v->flags|=VIDEO_AUDIO_MUTE;
v.mode=VIDEO_SOUND_STEREO; v->mode=VIDEO_SOUND_STEREO;
if (pcm20->stereo) if (pcm20->stereo)
v.mode|=VIDEO_SOUND_MONO; v->mode|=VIDEO_SOUND_MONO;
/* v.step=2048; */ /* v->step=2048; */
strcpy(v.name, "Radio"); strcpy(v->name, "Radio");
if(copy_to_user(arg,&v, sizeof(v)))
return -EFAULT;
return 0; return 0;
} }
case VIDIOCSAUDIO: case VIDIOCSAUDIO:
{ {
struct video_audio v; struct video_audio *v = arg;
if(copy_from_user(&v, arg, sizeof(v))) if(v->audio)
return -EFAULT;
if(v.audio)
return -EINVAL; return -EINVAL;
pcm20_mute(pcm20, !!(v.flags&VIDEO_AUDIO_MUTE)); pcm20_mute(pcm20, !!(v->flags&VIDEO_AUDIO_MUTE));
if(v.flags&VIDEO_SOUND_MONO) if(v->flags&VIDEO_SOUND_MONO)
pcm20_stereo(pcm20, 0); pcm20_stereo(pcm20, 0);
if(v.flags&VIDEO_SOUND_STEREO) if(v->flags&VIDEO_SOUND_STEREO)
pcm20_stereo(pcm20, 1); pcm20_stereo(pcm20, 1);
return 0; return 0;
...@@ -221,35 +210,27 @@ static int pcm20_ioctl(struct video_device *dev, unsigned int cmd, void *arg) ...@@ -221,35 +210,27 @@ static int pcm20_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
} }
} }
static int pcm20_open(struct video_device *dev, int flags)
{
if(users)
return -EBUSY;
users++;
MOD_INC_USE_COUNT;
return 0;
}
static void pcm20_close(struct video_device *dev)
{
users--;
MOD_DEC_USE_COUNT;
}
static struct pcm20_device pcm20_unit = { static struct pcm20_device pcm20_unit = {
freq: 87*16000, freq: 87*16000,
muted: 1, muted: 1,
stereo: 0 stereo: 0
}; };
static struct file_operations pcm20_fops = {
owner: THIS_MODULE,
open: video_exclusive_open,
release: video_exclusive_release,
ioctl: video_generic_ioctl,
llseek: no_llseek,
};
static struct video_device pcm20_radio = { static struct video_device pcm20_radio = {
owner: THIS_MODULE, owner: THIS_MODULE,
name: "Miro PCM 20 radio", name: "Miro PCM 20 radio",
type: VID_TYPE_TUNER, type: VID_TYPE_TUNER,
hardware: VID_HARDWARE_RTRACK, hardware: VID_HARDWARE_RTRACK,
open: pcm20_open, fops: &pcm20_fops,
close: pcm20_close, kernel_ioctl: pcm20_ioctl,
ioctl: pcm20_ioctl,
priv: &pcm20_unit priv: &pcm20_unit
}; };
......
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