]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/radio/radio-typhoon.c
V4L/DVB (7995): si470x: a lot of small code cleanups
[linux-2.6-omap-h63xx.git] / drivers / media / radio / radio-typhoon.c
index 3031fef178cb491d8ab7f02bc9df062e50d3b863..18f2abd7e2552e985d670551b1abc729c0d24d5f 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/init.h>                /* Initdata                       */
 #include <linux/ioport.h>      /* request_region                 */
 #include <linux/proc_fs.h>     /* radio card status report       */
+#include <linux/seq_file.h>
 #include <asm/io.h>            /* outb, outb_p                   */
 #include <asm/uaccess.h>       /* copy to/from user              */
 #include <linux/videodev2.h>   /* kernel radio structs           */
@@ -93,11 +94,6 @@ static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency);
 static void typhoon_mute(struct typhoon_device *dev);
 static void typhoon_unmute(struct typhoon_device *dev);
 static int typhoon_setvol(struct typhoon_device *dev, int vol);
-static int typhoon_ioctl(struct inode *inode, struct file *file,
-                        unsigned int cmd, unsigned long arg);
-#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
-static int typhoon_get_info(char *buf, char **start, off_t offset, int len);
-#endif
 
 static void typhoon_setvol_generic(struct typhoon_device *dev, int vol)
 {
@@ -186,129 +182,148 @@ static int typhoon_setvol(struct typhoon_device *dev, int vol)
        return 0;
 }
 
+static int vidioc_querycap(struct file *file, void  *priv,
+                                       struct v4l2_capability *v)
+{
+       strlcpy(v->driver, "radio-typhoon", sizeof(v->driver));
+       strlcpy(v->card, "Typhoon Radio", sizeof(v->card));
+       sprintf(v->bus_info, "ISA");
+       v->version = RADIO_VERSION;
+       v->capabilities = V4L2_CAP_TUNER;
+       return 0;
+}
 
-static int typhoon_do_ioctl(struct inode *inode, struct file *file,
-                           unsigned int cmd, void *arg)
+static int vidioc_g_tuner(struct file *file, void *priv,
+                                       struct v4l2_tuner *v)
+{
+       if (v->index > 0)
+               return -EINVAL;
+
+       strcpy(v->name, "FM");
+       v->type = V4L2_TUNER_RADIO;
+       v->rangelow = (87.5*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;     /* We can't get the signal strength */
+       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 video_device *dev = video_devdata(file);
        struct typhoon_device *typhoon = dev->priv;
 
-       switch (cmd) {
-               case VIDIOC_QUERYCAP:
-               {
-                       struct v4l2_capability *v = arg;
-                       memset(v,0,sizeof(*v));
-                       strlcpy(v->driver, "radio-typhoon", sizeof (v->driver));
-                       strlcpy(v->card, "Typhoon Radio", sizeof (v->card));
-                       sprintf(v->bus_info,"ISA");
-                       v->version = RADIO_VERSION;
-                       v->capabilities = V4L2_CAP_TUNER;
+       typhoon->curfreq = f->frequency;
+       typhoon_setfreq(typhoon, typhoon->curfreq);
+       return 0;
+}
 
-                       return 0;
-               }
-               case VIDIOC_G_TUNER:
-               {
-                       struct v4l2_tuner *v = arg;
+static int vidioc_g_frequency(struct file *file, void *priv,
+                                       struct v4l2_frequency *f)
+{
+       struct video_device *dev = video_devdata(file);
+       struct typhoon_device *typhoon = dev->priv;
 
-                       if (v->index > 0)
-                               return -EINVAL;
+       f->type = V4L2_TUNER_RADIO;
+       f->frequency = typhoon->curfreq;
 
-                       memset(v,0,sizeof(*v));
-                       strcpy(v->name, "FM");
-                       v->type = V4L2_TUNER_RADIO;
+       return 0;
+}
 
-                       v->rangelow=(87.5*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;     /* We can't get the signal strength */
+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;
                }
-               case VIDIOC_S_TUNER:
-               {
-                       struct v4l2_tuner *v = arg;
+       }
+       return -EINVAL;
+}
 
-                       if (v->index > 0)
-                               return -EINVAL;
+static int vidioc_g_ctrl(struct file *file, void *priv,
+                                       struct v4l2_control *ctrl)
+{
+       struct video_device *dev = video_devdata(file);
+       struct typhoon_device *typhoon = dev->priv;
 
-                       return 0;
-               }
-               case VIDIOC_S_FREQUENCY:
-               {
-                       struct v4l2_frequency *f = arg;
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_MUTE:
+               ctrl->value = typhoon->muted;
+               return 0;
+       case V4L2_CID_AUDIO_VOLUME:
+               ctrl->value = typhoon->curvol;
+               return 0;
+       }
+       return -EINVAL;
+}
 
-                       typhoon->curfreq = f->frequency;
-                       typhoon_setfreq(typhoon, typhoon->curfreq);
-                       return 0;
-               }
-               case VIDIOC_G_FREQUENCY:
-               {
-                       struct v4l2_frequency *f = arg;
+static int vidioc_s_ctrl (struct file *file, void *priv,
+                                       struct v4l2_control *ctrl)
+{
+       struct video_device *dev = video_devdata(file);
+       struct typhoon_device *typhoon = dev->priv;
 
-                       f->type = V4L2_TUNER_RADIO;
-                       f->frequency = typhoon->curfreq;
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_MUTE:
+               if (ctrl->value)
+                       typhoon_mute(typhoon);
+               else
+                       typhoon_unmute(typhoon);
+               return 0;
+       case V4L2_CID_AUDIO_VOLUME:
+               typhoon_setvol(typhoon, ctrl->value);
+               return 0;
+       }
+       return -EINVAL;
+}
 
-                       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=typhoon->muted;
-                                       return (0);
-                               case V4L2_CID_AUDIO_VOLUME:
-                                       ctrl->value=typhoon->curvol;
-                                       return (0);
-                       }
-                       return -EINVAL;
-               }
-               case VIDIOC_S_CTRL:
-               {
-                       struct v4l2_control *ctrl= arg;
-
-                       switch (ctrl->id) {
-                               case V4L2_CID_AUDIO_MUTE:
-                                       if (ctrl->value) {
-                                               typhoon_mute(typhoon);
-                                       } else {
-                                               typhoon_unmute(typhoon);
-                                       }
-                                       return (0);
-                               case V4L2_CID_AUDIO_VOLUME:
-                                       typhoon_setvol(typhoon, 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;
 
-               default:
-                       return v4l_compat_translate_ioctl(inode,file,cmd,arg,
-                                                         typhoon_do_ioctl);
-       }
+       strcpy(a->name, "Radio");
+       a->capability = V4L2_AUDCAP_STEREO;
+       return 0;
 }
 
-static int typhoon_ioctl(struct inode *inode, struct file *file,
-                        unsigned int cmd, unsigned long arg)
+static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
 {
-       return video_usercopy(inode, file, cmd, arg, typhoon_do_ioctl);
+       *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 typhoon_device typhoon_unit =
@@ -322,8 +337,10 @@ static const struct file_operations typhoon_fops = {
        .owner          = THIS_MODULE,
        .open           = video_exclusive_open,
        .release        = video_exclusive_release,
-       .ioctl          = typhoon_ioctl,
+       .ioctl          = video_ioctl2,
+#ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
+#endif
        .llseek         = no_llseek,
 };
 
@@ -332,36 +349,56 @@ static struct video_device typhoon_radio =
        .owner          = THIS_MODULE,
        .name           = "Typhoon Radio",
        .type           = VID_TYPE_TUNER,
-       .hardware       = 0,
        .fops           = &typhoon_fops,
+       .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,
 };
 
 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
 
-static int typhoon_get_info(char *buf, char **start, off_t offset, int len)
+static int typhoon_proc_show(struct seq_file *m, void *v)
 {
-       char *out = buf;
-
        #ifdef MODULE
            #define MODULEPROCSTRING "Driver loaded as a module"
        #else
            #define MODULEPROCSTRING "Driver compiled into kernel"
        #endif
 
-       /* output must be kept under PAGE_SIZE */
-       out += sprintf(out, BANNER);
-       out += sprintf(out, "Load type: " MODULEPROCSTRING "\n\n");
-       out += sprintf(out, "frequency = %lu kHz\n",
+       seq_puts(m, BANNER);
+       seq_puts(m, "Load type: " MODULEPROCSTRING "\n\n");
+       seq_printf(m, "frequency = %lu kHz\n",
                typhoon_unit.curfreq >> 4);
-       out += sprintf(out, "volume = %d\n", typhoon_unit.curvol);
-       out += sprintf(out, "mute = %s\n", typhoon_unit.muted ?
+       seq_printf(m, "volume = %d\n", typhoon_unit.curvol);
+       seq_printf(m, "mute = %s\n", typhoon_unit.muted ?
                "on" : "off");
-       out += sprintf(out, "iobase = 0x%x\n", typhoon_unit.iobase);
-       out += sprintf(out, "mute frequency = %lu kHz\n",
+       seq_printf(m, "iobase = 0x%x\n", typhoon_unit.iobase);
+       seq_printf(m, "mute frequency = %lu kHz\n",
                typhoon_unit.mutefreq >> 4);
-       return out - buf;
+       return 0;
 }
 
+static int typhoon_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, typhoon_proc_show, NULL);
+}
+
+static const struct file_operations typhoon_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = typhoon_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 #endif /* CONFIG_RADIO_TYPHOON_PROC_FS */
 
 MODULE_AUTHOR("Dr. Henrik Seidel");
@@ -376,7 +413,7 @@ MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)");
 module_param(radio_nr, int, 0);
 
 #ifdef MODULE
-static unsigned long mutefreq = 0;
+static unsigned long mutefreq;
 module_param(mutefreq, ulong, 0);
 MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)");
 #endif
@@ -422,8 +459,7 @@ static int __init typhoon_init(void)
        typhoon_mute(&typhoon_unit);
 
 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
-       if (!create_proc_info_entry("driver/radio-typhoon", 0, NULL,
-                                   typhoon_get_info))
+       if (!proc_create("driver/radio-typhoon", 0, NULL, &typhoon_proc_fops))
                printk(KERN_ERR "radio-typhoon: registering /proc/driver/radio-typhoon failed\n");
 #endif