V4L/DVB (6293): V4L: convert struct class_device to struct device
[powerpc.git] / drivers / media / video / videodev.c
index dc9b1ef..0fbe8a1 100644 (file)
@@ -30,7 +30,6 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/smp_lock.h>
 #include <linux/mm.h>
 #include <linux/string.h>
 #include <linux/errno.h>
  *     sysfs stuff
  */
 
-static ssize_t show_name(struct class_device *cd, char *buf)
+static ssize_t show_name(struct device *cd,
+                        struct device_attribute *attr, char *buf)
 {
        struct video_device *vfd = container_of(cd, struct video_device,
-                                                               class_dev);
-       return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name);
+                                               class_dev);
+       return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
 }
 
-static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
-
 struct video_device *video_device_alloc(void)
 {
        struct video_device *vfd;
@@ -77,10 +75,9 @@ void video_device_release(struct video_device *vfd)
        kfree(vfd);
 }
 
-static void video_release(struct class_device *cd)
+static void video_release(struct device *cd)
 {
-       struct video_device *vfd = container_of(cd, struct video_device,
-                                                               class_dev);
+       struct video_device *vfd = container_of(cd, struct video_device, class_dev);
 
 #if 1
        /* needed until all drivers are fixed */
@@ -90,9 +87,15 @@ static void video_release(struct class_device *cd)
        vfd->release(vfd);
 }
 
+static struct device_attribute video_device_attrs[] = {
+       __ATTR(name, S_IRUGO, show_name, NULL),
+       __ATTR_NULL
+};
+
 static struct class video_class = {
        .name    = VIDEO_NAME,
-       .release = video_release,
+       .dev_attrs = video_device_attrs,
+       .dev_release = video_release,
 };
 
 /*
@@ -318,6 +321,7 @@ static char *v4l2_type_names_FIXME[] = {
        [V4L2_BUF_TYPE_VBI_OUTPUT]         = "vbi-out",
        [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT]  = "sliced-vbi-out",
        [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-capture",
+       [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "video-out-over",
        [V4L2_BUF_TYPE_PRIVATE]            = "private",
 };
 
@@ -330,6 +334,8 @@ static char *v4l2_field_names_FIXME[] = {
        [V4L2_FIELD_SEQ_TB]     = "seq-tb",
        [V4L2_FIELD_SEQ_BT]     = "seq-bt",
        [V4L2_FIELD_ALTERNATE]  = "alternate",
+       [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
+       [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
 };
 
 #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
@@ -411,6 +417,10 @@ static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
                if (vfd->vidioc_try_fmt_vbi_output)
                        return (0);
                break;
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+               if (vfd->vidioc_try_fmt_output_overlay)
+                       return (0);
+               break;
        case V4L2_BUF_TYPE_PRIVATE:
                if (vfd->vidioc_try_fmt_type_private)
                        return (0);
@@ -427,13 +437,43 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
        int                  ret = -EINVAL;
 
        if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
-                               !(vfd->debug | V4L2_DEBUG_IOCTL_ARG)) {
+                               !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
                v4l_print_ioctl(vfd->name, cmd);
        }
 
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       /***********************************************************
+        Handles calls to the obsoleted V4L1 API
+        Due to the nature of VIDIOCGMBUF, each driver that supports
+        V4L1 should implement its own handler for this ioctl.
+        ***********************************************************/
+
+       /* --- streaming capture ------------------------------------- */
+       if (cmd == VIDIOCGMBUF) {
+               struct video_mbuf *p=arg;
+
+               memset(p, 0, sizeof(*p));
+
+               if (!vfd->vidiocgmbuf)
+                       return ret;
+               ret=vfd->vidiocgmbuf(file, fh, p);
+               if (!ret)
+                       dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
+                                               p->size, p->frames,
+                                               (unsigned long)p->offsets);
+               return ret;
+       }
+
+       /********************************************************
+        All other V4L1 calls are handled by v4l1_compat module.
+        Those calls will be translated into V4L2 calls, and
+        __video_do_ioctl will be called again, with one or more
+        V4L2 ioctls.
+        ********************************************************/
        if (_IOC_TYPE(cmd)=='v')
                return v4l_compat_translate_ioctl(inode,file,cmd,arg,
                                                __video_do_ioctl);
+#endif
 
        switch(cmd) {
        /* --- capabilities ------------------------------------------ */
@@ -525,6 +565,10 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                                ret=vfd->vidioc_enum_fmt_vbi_output(file,
                                                                fh, f);
                        break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+                       if (vfd->vidioc_enum_fmt_output_overlay)
+                               ret=vfd->vidioc_enum_fmt_output_overlay(file, fh, f);
+                       break;
                case V4L2_BUF_TYPE_PRIVATE:
                        if (vfd->vidioc_enum_fmt_type_private)
                                ret=vfd->vidioc_enum_fmt_type_private(file,
@@ -582,6 +626,10 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                                ret=vfd->vidioc_g_fmt_video_output(file,
                                                                fh, f);
                        break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+                       if (vfd->vidioc_g_fmt_output_overlay)
+                               ret=vfd->vidioc_g_fmt_output_overlay(file, fh, f);
+                       break;
                case V4L2_BUF_TYPE_VBI_OUTPUT:
                        if (vfd->vidioc_g_fmt_vbi_output)
                                ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
@@ -630,6 +678,10 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                                ret=vfd->vidioc_s_fmt_video_output(file,
                                                                fh, f);
                        break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+                       if (vfd->vidioc_s_fmt_output_overlay)
+                               ret=vfd->vidioc_s_fmt_output_overlay(file, fh, f);
+                       break;
                case V4L2_BUF_TYPE_VBI_OUTPUT:
                        if (vfd->vidioc_s_fmt_vbi_output)
                                ret=vfd->vidioc_s_fmt_vbi_output(file,
@@ -680,6 +732,10 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                                ret=vfd->vidioc_try_fmt_video_output(file,
                                                                fh, f);
                        break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+                       if (vfd->vidioc_try_fmt_output_overlay)
+                               ret=vfd->vidioc_try_fmt_output_overlay(file, fh, f);
+                       break;
                case V4L2_BUF_TYPE_VBI_OUTPUT:
                        if (vfd->vidioc_try_fmt_vbi_output)
                                ret=vfd->vidioc_try_fmt_vbi_output(file,
@@ -769,24 +825,6 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                ret=vfd->vidioc_overlay(file, fh, *i);
                break;
        }
-#ifdef CONFIG_VIDEO_V4L1_COMPAT
-       /* --- streaming capture ------------------------------------- */
-       case VIDIOCGMBUF:
-       {
-               struct video_mbuf *p=arg;
-
-               memset(p,0,sizeof(p));
-
-               if (!vfd->vidiocgmbuf)
-                       break;
-               ret=vfd->vidiocgmbuf(file, fh, p);
-               if (!ret)
-                       dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
-                                               p->size, p->frames,
-                                               (unsigned long)p->offsets);
-               break;
-       }
-#endif
        case VIDIOC_G_FBUF:
        {
                struct v4l2_framebuffer *p=arg;
@@ -1342,9 +1380,50 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                        ret=vfd->vidioc_s_jpegcomp(file, fh, p);
                break;
        }
+       case VIDIOC_G_ENC_INDEX:
+       {
+               struct v4l2_enc_idx *p=arg;
+
+               if (!vfd->vidioc_g_enc_index)
+                       break;
+               ret=vfd->vidioc_g_enc_index(file, fh, p);
+               if (!ret)
+                       dbgarg (cmd, "entries=%d, entries_cap=%d\n",
+                                       p->entries,p->entries_cap);
+               break;
+       }
+       case VIDIOC_ENCODER_CMD:
+       {
+               struct v4l2_encoder_cmd *p=arg;
+
+               if (!vfd->vidioc_encoder_cmd)
+                       break;
+               ret=vfd->vidioc_encoder_cmd(file, fh, p);
+               if (!ret)
+                       dbgarg (cmd, "cmd=%d, flags=%d\n",
+                                       p->cmd,p->flags);
+               break;
+       }
+       case VIDIOC_TRY_ENCODER_CMD:
+       {
+               struct v4l2_encoder_cmd *p=arg;
+
+               if (!vfd->vidioc_try_encoder_cmd)
+                       break;
+               ret=vfd->vidioc_try_encoder_cmd(file, fh, p);
+               if (!ret)
+                       dbgarg (cmd, "cmd=%d, flags=%d\n",
+                                       p->cmd,p->flags);
+               break;
+       }
        case VIDIOC_G_PARM:
        {
                struct v4l2_streamparm *p=arg;
+               __u32 type=p->type;
+
+               memset(p,0,sizeof(*p));
+               p->type=type;
+
                if (vfd->vidioc_g_parm) {
                        ret=vfd->vidioc_g_parm(file, fh, p);
                } else {
@@ -1356,8 +1435,6 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                        v4l2_video_std_construct(&s, vfd->current_norm,
                                                 v4l2_norm_to_name(vfd->current_norm));
 
-                       memset(p,0,sizeof(*p));
-
                        p->parm.capture.timeperframe = s.frameperiod;
                        ret=0;
                }
@@ -1473,6 +1550,16 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                break;
        }
 #endif
+       case VIDIOC_G_CHIP_IDENT:
+       {
+               struct v4l2_chip_ident *p=arg;
+               if (!vfd->vidioc_g_chip_ident)
+                       break;
+               ret=vfd->vidioc_g_chip_ident(file, fh, p);
+               if (!ret)
+                       dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
+               break;
+       }
        } /* switch */
 
        if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
@@ -1670,22 +1757,16 @@ int video_register_device(struct video_device *vfd, int type, int nr)
        /* sysfs class */
        memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
        if (vfd->dev)
-               vfd->class_dev.dev = vfd->dev;
+               vfd->class_dev.parent = vfd->dev;
        vfd->class_dev.class       = &video_class;
        vfd->class_dev.devt        = MKDEV(VIDEO_MAJOR, vfd->minor);
-       sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
-       ret = class_device_register(&vfd->class_dev);
+       sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
+       ret = device_register(&vfd->class_dev);
        if (ret < 0) {
-               printk(KERN_ERR "%s: class_device_register failed\n",
+               printk(KERN_ERR "%s: device_register failed\n",
                       __FUNCTION__);
                goto fail_minor;
        }
-       ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
-       if (ret < 0) {
-               printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
-                      __FUNCTION__);
-               goto fail_classdev;
-       }
 
 #if 1
        /* needed until all drivers are fixed */
@@ -1696,8 +1777,6 @@ int video_register_device(struct video_device *vfd, int type, int nr)
 #endif
        return 0;
 
-fail_classdev:
-       class_device_unregister(&vfd->class_dev);
 fail_minor:
        mutex_lock(&videodev_lock);
        video_device[vfd->minor] = NULL;
@@ -1721,7 +1800,7 @@ void video_unregister_device(struct video_device *vfd)
                panic("videodev: bad unregister");
 
        video_device[vfd->minor]=NULL;
-       class_device_unregister(&vfd->class_dev);
+       device_unregister(&vfd->class_dev);
        mutex_unlock(&videodev_lock);
 }