Staging: w35und: inline DRIVER_AUTHOR and DRIVER_DESC macros
[safe/jmp/linux-2.6] / drivers / media / radio / radio-aimslab.c
index 5a9c1f1..bfa13b8 100644 (file)
@@ -1,6 +1,7 @@
 /* radiotrack (radioreveal) driver for Linux radio support
  * (c) 1997 M. Kirkwood
- * Converted to new API by Alan Cox <Alan.Cox@linux.org>
+ * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
+ * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
  * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
  *
  * History:
 #include <linux/delay.h>       /* udelay                       */
 #include <asm/io.h>            /* outb, outb_p                 */
 #include <asm/uaccess.h>       /* copy to/from user            */
-#include <linux/videodev.h>    /* kernel radio structs         */
+#include <linux/videodev2.h>   /* kernel radio structs         */
 #include <media/v4l2-common.h>
-#include <asm/semaphore.h>     /* Lock for the I/O             */
+#include <media/v4l2-ioctl.h>
+
+#include <linux/version.h>     /* for KERNEL_VERSION MACRO     */
+#define RADIO_VERSION KERNEL_VERSION(0,0,2)
 
 #ifndef CONFIG_RADIO_RTRACK_PORT
 #define CONFIG_RADIO_RTRACK_PORT -1
@@ -47,6 +51,7 @@ static struct mutex lock;
 
 struct rt_device
 {
+       unsigned long in_use;
        int port;
        int curvol;
        unsigned long curfreq;
@@ -59,7 +64,7 @@ struct rt_device
 static void sleep_delay(long n)
 {
        /* Sleep nicely for 'n' uS */
-       int d=n/(1000000/HZ);
+       int d=n/msecs_to_jiffies(1000);
        if(!d)
                udelay(n);
        else
@@ -208,108 +213,205 @@ static int rt_getsigstr(struct rt_device *dev)
        return 1;               /* signal present               */
 }
 
-static int rt_do_ioctl(struct inode *inode, struct file *file,
-                      unsigned int cmd, void *arg)
+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,
+       },{
+               .id            = V4L2_CID_AUDIO_VOLUME,
+               .name          = "Volume",
+               .minimum       = 0,
+               .maximum       = 0xff,
+               .step          = 1,
+               .default_value = 0xff,
+               .type          = V4L2_CTRL_TYPE_INTEGER,
+       }
+};
+
+static int vidioc_querycap(struct file *file, void  *priv,
+                                       struct v4l2_capability *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt=dev->priv;
+       strlcpy(v->driver, "radio-aimslab", sizeof(v->driver));
+       strlcpy(v->card, "RadioTrack", sizeof(v->card));
+       sprintf(v->bus_info, "ISA");
+       v->version = RADIO_VERSION;
+       v->capabilities = V4L2_CAP_TUNER;
+       return 0;
+}
 
-       switch(cmd)
-       {
-               case VIDIOCGCAP:
-               {
-                       struct video_capability *v = arg;
-                       memset(v,0,sizeof(*v));
-                       v->type=VID_TYPE_TUNER;
-                       v->channels=1;
-                       v->audios=1;
-                       strcpy(v->name, "RadioTrack");
-                       return 0;
-               }
-               case VIDIOCGTUNER:
-               {
-                       struct video_tuner *v = arg;
-                       if(v->tuner)    /* Only 1 tuner */
-                               return -EINVAL;
-                       v->rangelow=(87*16000);
-                       v->rangehigh=(108*16000);
-                       v->flags=VIDEO_TUNER_LOW;
-                       v->mode=VIDEO_MODE_AUTO;
-                       strcpy(v->name, "FM");
-                       v->signal=0xFFFF*rt_getsigstr(rt);
-                       return 0;
-               }
-               case VIDIOCSTUNER:
-               {
-                       struct video_tuner *v = arg;
-                       if(v->tuner!=0)
-                               return -EINVAL;
-                       /* Only 1 tuner so no setting needed ! */
-                       return 0;
-               }
-               case VIDIOCGFREQ:
-               {
-                       unsigned long *freq = arg;
-                       *freq = rt->curfreq;
-                       return 0;
-               }
-               case VIDIOCSFREQ:
-               {
-                       unsigned long *freq = arg;
-                       rt->curfreq = *freq;
-                       rt_setfreq(rt, rt->curfreq);
-                       return 0;
-               }
-               case VIDIOCGAUDIO:
-               {
-                       struct video_audio *v = arg;
-                       memset(v,0, sizeof(*v));
-                       v->flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME;
-                       v->volume=rt->curvol * 6554;
-                       v->step=6554;
-                       strcpy(v->name, "Radio");
-                       return 0;
-               }
-               case VIDIOCSAUDIO:
-               {
-                       struct video_audio *v = arg;
-                       if(v->audio)
-                               return -EINVAL;
-                       if(v->flags&VIDEO_AUDIO_MUTE)
-                               rt_mute(rt);
-                       else
-                               rt_setvol(rt,v->volume/6554);
+static int vidioc_g_tuner(struct file *file, void *priv,
+                                       struct v4l2_tuner *v)
+{
+       struct rt_device *rt = video_drvdata(file);
+
+       if (v->index > 0)
+               return -EINVAL;
+
+       strcpy(v->name, "FM");
+       v->type = V4L2_TUNER_RADIO;
+       v->rangelow = (87*16000);
+       v->rangehigh = (108*16000);
+       v->rxsubchans = V4L2_TUNER_SUB_MONO;
+       v->capability = V4L2_TUNER_CAP_LOW;
+       v->audmode = V4L2_TUNER_MODE_MONO;
+       v->signal = 0xffff*rt_getsigstr(rt);
+       return 0;
+}
+
+static int vidioc_s_tuner(struct file *file, void *priv,
+                                       struct v4l2_tuner *v)
+{
+       if (v->index > 0)
+               return -EINVAL;
+       return 0;
+}
+
+static int vidioc_s_frequency(struct file *file, void *priv,
+                                       struct v4l2_frequency *f)
+{
+       struct rt_device *rt = video_drvdata(file);
+
+       rt->curfreq = f->frequency;
+       rt_setfreq(rt, rt->curfreq);
+       return 0;
+}
+
+static int vidioc_g_frequency(struct file *file, void *priv,
+                                       struct v4l2_frequency *f)
+{
+       struct rt_device *rt = video_drvdata(file);
+
+       f->type = V4L2_TUNER_RADIO;
+       f->frequency = rt->curfreq;
+       return 0;
+}
+
+static int vidioc_queryctrl(struct file *file, void *priv,
+                                       struct v4l2_queryctrl *qc)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
+               if (qc->id && qc->id == radio_qctrl[i].id) {
+                       memcpy(qc, &(radio_qctrl[i]),
+                                               sizeof(*qc));
                        return 0;
                }
-               default:
-                       return -ENOIOCTLCMD;
        }
+       return -EINVAL;
 }
 
-static int rt_ioctl(struct inode *inode, struct file *file,
-                   unsigned int cmd, unsigned long arg)
+static int vidioc_g_ctrl(struct file *file, void *priv,
+                                       struct v4l2_control *ctrl)
 {
-       return video_usercopy(inode, file, cmd, arg, rt_do_ioctl);
+       struct rt_device *rt = video_drvdata(file);
+
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_MUTE:
+               ctrl->value = rt->muted;
+               return 0;
+       case V4L2_CID_AUDIO_VOLUME:
+               ctrl->value = rt->curvol * 6554;
+               return 0;
+       }
+       return -EINVAL;
+}
+
+static int vidioc_s_ctrl(struct file *file, void *priv,
+                                       struct v4l2_control *ctrl)
+{
+       struct rt_device *rt = video_drvdata(file);
+
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_MUTE:
+               if (ctrl->value)
+                       rt_mute(rt);
+               else
+                       rt_setvol(rt,rt->curvol);
+               return 0;
+       case V4L2_CID_AUDIO_VOLUME:
+               rt_setvol(rt,ctrl->value);
+               return 0;
+       }
+       return -EINVAL;
+}
+
+static int vidioc_g_audio (struct file *file, void *priv,
+                                       struct v4l2_audio *a)
+{
+       if (a->index > 1)
+               return -EINVAL;
+
+       strcpy(a->name, "Radio");
+       a->capability = V4L2_AUDCAP_STEREO;
+       return 0;
+}
+
+static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
+{
+       *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 struct rt_device rtrack_unit;
 
-static struct file_operations rtrack_fops = {
-       .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
-       .ioctl          = rt_ioctl,
-       .compat_ioctl   = v4l_compat_ioctl32,
-       .llseek         = no_llseek,
-};
+static int rtrack_exclusive_open(struct file *file)
+{
+       return test_and_set_bit(0, &rtrack_unit.in_use) ? -EBUSY : 0;
+}
 
-static struct video_device rtrack_radio=
+static int rtrack_exclusive_release(struct file *file)
 {
+       clear_bit(0, &rtrack_unit.in_use);
+       return 0;
+}
+
+static const struct v4l2_file_operations rtrack_fops = {
        .owner          = THIS_MODULE,
+       .open           = rtrack_exclusive_open,
+       .release        = rtrack_exclusive_release,
+       .ioctl          = video_ioctl2,
+};
+
+static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
+       .vidioc_querycap    = vidioc_querycap,
+       .vidioc_g_tuner     = vidioc_g_tuner,
+       .vidioc_s_tuner     = vidioc_s_tuner,
+       .vidioc_g_audio     = vidioc_g_audio,
+       .vidioc_s_audio     = vidioc_s_audio,
+       .vidioc_g_input     = vidioc_g_input,
+       .vidioc_s_input     = vidioc_s_input,
+       .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,
+};
+
+static struct video_device rtrack_radio = {
        .name           = "RadioTrack radio",
-       .type           = VID_TYPE_TUNER,
-       .hardware       = VID_HARDWARE_RTRACK,
        .fops           = &rtrack_fops,
+       .ioctl_ops      = &rtrack_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init rtrack_init(void)
@@ -326,10 +428,9 @@ static int __init rtrack_init(void)
                return -EBUSY;
        }
 
-       rtrack_radio.priv=&rtrack_unit;
+       video_set_drvdata(&rtrack_radio, &rtrack_unit);
 
-       if(video_register_device(&rtrack_radio, VFL_TYPE_RADIO, radio_nr)==-1)
-       {
+       if (video_register_device(&rtrack_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
                release_region(io, 2);
                return -EINVAL;
        }