V4L/DVB (4358): V4L2 conversion: radio-zoltrix
authorMauro Carvalho Chehab <mchehab@infradead.org>
Tue, 8 Aug 2006 12:10:04 +0000 (09:10 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Tue, 26 Sep 2006 14:53:15 +0000 (11:53 -0300)
Driver conversion to V4L2 API.
Require some testing, since this obsolete hardware is not
common those days.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/radio/Kconfig
drivers/media/radio/radio-zoltrix.c

index e64f0aae7deae905712790686ca0facf2f6376d2..1fe960c0f7e0c34ba4c4ab37ff9994900c57d16d 100644 (file)
@@ -330,7 +330,7 @@ config RADIO_TYPHOON_MUTEFREQ
 
 config RADIO_ZOLTRIX
        tristate "Zoltrix Radio"
-       depends on ISA && VIDEO_V4L1
+       depends on ISA && VIDEO_V4L2
        ---help---
          Choose Y here if you have one of these FM radio cards, and then fill
          in the port address below.
index 432c3e2222d028e3d2b9a8a86bcf4e424b1a6436..671fe1b1e5bcec6a028c71804699db75dfb976d4 100644 (file)
@@ -24,6 +24,9 @@
  *           - Added unmute function
  *           - Reworked ioctl functions
  * 2002-07-15 - Fix Stereo typo
+ *
+ * 2006-07-24 - Converted to V4L2 API
+ *             by Mauro Carvalho Chehab <mchehab@infradead.org>
  */
 
 #include <linux/module.h>      /* Modules                        */
 #include <linux/delay.h>       /* udelay, msleep                 */
 #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 <linux/version.h>      /* for KERNEL_VERSION MACRO     */
+#define RADIO_VERSION KERNEL_VERSION(0,0,2)
+
+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       = 65535,
+               .step          = 4096,
+               .default_value = 0xff,
+               .type          = V4L2_CTRL_TYPE_INTEGER,
+       }
+};
+
 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
 #define CONFIG_RADIO_ZOLTRIX_PORT -1
 #endif
@@ -212,78 +237,116 @@ static int zol_do_ioctl(struct inode *inode, struct file *file,
        struct zol_device *zol = dev->priv;
 
        switch (cmd) {
-       case VIDIOCGCAP:
+               case VIDIOC_QUERYCAP:
                {
-                       struct video_capability *v = arg;
-
+                       struct v4l2_capability *v = arg;
                        memset(v,0,sizeof(*v));
-                       v->type = VID_TYPE_TUNER;
-                       v->channels = 1 + zol->stereo;
-                       v->audios = 1;
-                       strcpy(v->name, "Zoltrix Radio");
+                       strlcpy(v->driver, "radio-zoltrix", sizeof (v->driver));
+                       strlcpy(v->card, "Zoltrix Radio", sizeof (v->card));
+                       sprintf(v->bus_info,"ISA");
+                       v->version = RADIO_VERSION;
+                       v->capabilities = V4L2_CAP_TUNER;
+
                        return 0;
                }
-       case VIDIOCGTUNER:
+               case VIDIOC_G_TUNER:
                {
-                       struct video_tuner *v = arg;
-                       if (v->tuner)
+                       struct v4l2_tuner *v = arg;
+
+                       if (v->index > 0)
                                return -EINVAL;
+
+                       memset(v,0,sizeof(*v));
                        strcpy(v->name, "FM");
-                       v->rangelow = (int) (88.0 * 16000);
-                       v->rangehigh = (int) (108.0 * 16000);
-                       v->flags = zol_is_stereo(zol)
-                                       ? VIDEO_TUNER_STEREO_ON : 0;
-                       v->flags |= VIDEO_TUNER_LOW;
-                       v->mode = VIDEO_MODE_AUTO;
-                       v->signal = 0xFFFF * zol_getsigstr(zol);
+                       v->type = V4L2_TUNER_RADIO;
+
+                       v->rangelow=(88*16000);
+                       v->rangehigh=(108*16000);
+                       v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
+                       v->capability=V4L2_TUNER_CAP_LOW;
+                       if(zol_is_stereo(zol))
+                               v->audmode = V4L2_TUNER_MODE_STEREO;
+                       else
+                               v->audmode = V4L2_TUNER_MODE_MONO;
+                       v->signal=0xFFFF*zol_getsigstr(zol);
+
                        return 0;
                }
-       case VIDIOCSTUNER:
+               case VIDIOC_S_TUNER:
                {
-                       struct video_tuner *v = arg;
-                       if (v->tuner != 0)
+                       struct v4l2_tuner *v = arg;
+
+                       if (v->index > 0)
                                return -EINVAL;
-                       /* Only 1 tuner so no setting needed ! */
+
                        return 0;
                }
-       case VIDIOCGFREQ:
-       {
-               unsigned long *freq = arg;
-               *freq = zol->curfreq;
-               return 0;
-       }
-       case VIDIOCSFREQ:
-       {
-               unsigned long *freq = arg;
-               zol->curfreq = *freq;
-               zol_setfreq(zol, zol->curfreq);
-               return 0;
-       }
-       case VIDIOCGAUDIO:
+               case VIDIOC_S_FREQUENCY:
                {
-                       struct video_audio *v = arg;
-                       memset(v, 0, sizeof(*v));
-                       v->flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME;
-                       v->mode |= zol_is_stereo(zol)
-                               ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
-                       v->volume = zol->curvol * 4096;
-                       v->step = 4096;
-                       strcpy(v->name, "Zoltrix Radio");
+                       struct v4l2_frequency *f = arg;
+
+                       zol->curfreq = f->frequency;
+                       zol_setfreq(zol, zol->curfreq);
                        return 0;
                }
-       case VIDIOCSAUDIO:
+               case VIDIOC_G_FREQUENCY:
                {
-                       struct video_audio *v = arg;
-                       if (v->audio)
-                               return -EINVAL;
+                       struct v4l2_frequency *f = arg;
 
-                       if (v->flags & VIDEO_AUDIO_MUTE)
-                               zol_mute(zol);
-                       else {
-                               zol_unmute(zol);
-                               zol_setvol(zol, v->volume / 4096);
-                       }
+                       f->type = V4L2_TUNER_RADIO;
+                       f->frequency = zol->curfreq;
 
+                       return 0;
+               }
+               case VIDIOC_QUERYCTRL:
+               {
+                       struct v4l2_queryctrl *qc = arg;
+                       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);
+                               }
+                       }
+                       return -EINVAL;
+               }
+               case VIDIOC_G_CTRL:
+               {
+                       struct v4l2_control *ctrl= arg;
+
+                       switch (ctrl->id) {
+                               case V4L2_CID_AUDIO_MUTE:
+                                       ctrl->value=zol->muted;
+                                       return (0);
+                               case V4L2_CID_AUDIO_VOLUME:
+                                       ctrl->value=zol->curvol * 4096;
+                                       return (0);
+                       }
+                       return -EINVAL;
+               }
+               case VIDIOC_S_CTRL:
+               {
+                       struct v4l2_control *ctrl= arg;
+
+                       switch (ctrl->id) {
+                               case V4L2_CID_AUDIO_MUTE:
+                                       if (ctrl->value) {
+                                               zol_mute(zol);
+                                       } else {
+                                               zol_unmute(zol);
+                                               zol_setvol(zol,zol->curvol);
+                                       }
+                                       return (0);
+                               case V4L2_CID_AUDIO_VOLUME:
+                                       zol_setvol(zol,ctrl->value/4096);
+                                       return (0);
+                       }
+                       zol->stereo = 1;
+                       zol_setfreq(zol, zol->curfreq);
+#if 0
+/* FIXME: Implement stereo/mono switch on V4L2 */
                        if (v->mode & VIDEO_SOUND_STEREO) {
                                zol->stereo = 1;
                                zol_setfreq(zol, zol->curfreq);
@@ -292,10 +355,13 @@ static int zol_do_ioctl(struct inode *inode, struct file *file,
                                zol->stereo = 0;
                                zol_setfreq(zol, zol->curfreq);
                        }
-                       return 0;
+#endif
+                       return -EINVAL;
                }
-       default:
-               return -ENOIOCTLCMD;
+
+               default:
+                       return v4l_compat_translate_ioctl(inode,file,cmd,arg,
+                                                         zol_do_ioctl);
        }
 }
 
@@ -322,7 +388,7 @@ static struct video_device zoltrix_radio =
        .owner          = THIS_MODULE,
        .name           = "Zoltrix Radio Plus",
        .type           = VID_TYPE_TUNER,
-       .hardware       = VID_HARDWARE_ZOLTRIX,
+       .hardware       = 0,
        .fops           = &zoltrix_fops,
 };