[media] uvcvideo: Register a v4l2_device
Laurent Pinchart [Thu, 21 Jan 2010 08:39:47 +0000 (05:39 -0300)]
As a first step to the media controller integration register a
v4l2_device for each UVC control interface and make the video_device a
child of the v4l2_device.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

drivers/media/video/uvc/uvc_driver.c
drivers/media/video/uvc/uvcvideo.h

index 823f4b3..0e8cd1f 100644 (file)
@@ -1585,6 +1585,13 @@ static void uvc_delete(struct uvc_device *dev)
        uvc_status_cleanup(dev);
        uvc_ctrl_cleanup_device(dev);
 
+       if (dev->vdev.dev)
+               v4l2_device_unregister(&dev->vdev);
+#ifdef CONFIG_MEDIA_CONTROLLER
+       if (media_devnode_is_registered(&dev->mdev.devnode))
+               media_device_unregister(&dev->mdev);
+#endif
+
        list_for_each_safe(p, n, &dev->chains) {
                struct uvc_video_chain *chain;
                chain = list_entry(p, struct uvc_video_chain, list);
@@ -1682,7 +1689,7 @@ static int uvc_register_video(struct uvc_device *dev,
         * unregistered before the reference is released, so we don't need to
         * get another one.
         */
-       vdev->parent = &dev->intf->dev;
+       vdev->v4l2_dev = &dev->vdev;
        vdev->fops = &uvc_fops;
        vdev->release = uvc_release;
        strlcpy(vdev->name, dev->name, sizeof vdev->name);
@@ -1814,6 +1821,24 @@ static int uvc_probe(struct usb_interface *intf,
                        "linux-uvc-devel mailing list.\n");
        }
 
+       /* Register the media and V4L2 devices. */
+#ifdef CONFIG_MEDIA_CONTROLLER
+       dev->mdev.dev = &intf->dev;
+       strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
+       if (udev->serial)
+               strlcpy(dev->mdev.serial, udev->serial,
+                       sizeof(dev->mdev.serial));
+       strcpy(dev->mdev.bus_info, udev->devpath);
+       dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
+       dev->mdev.driver_version = DRIVER_VERSION_NUMBER;
+       if (media_device_register(&dev->mdev) < 0)
+               goto error;
+
+       dev->vdev.mdev = &dev->mdev;
+#endif
+       if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
+               goto error;
+
        /* Initialize controls. */
        if (uvc_ctrl_init_device(dev) < 0)
                goto error;
@@ -1822,7 +1847,7 @@ static int uvc_probe(struct usb_interface *intf,
        if (uvc_scan_device(dev) < 0)
                goto error;
 
-       /* Register video devices. */
+       /* Register video device nodes. */
        if (uvc_register_chains(dev) < 0)
                goto error;
 
index 7cf224b..aab7508 100644 (file)
@@ -100,6 +100,8 @@ struct uvc_xu_control {
 #include <linux/poll.h>
 #include <linux/usb/video.h>
 #include <linux/uvcvideo.h>
+#include <media/media-device.h>
+#include <media/v4l2-device.h>
 
 /* --------------------------------------------------------------------------
  * UVC constants
@@ -504,6 +506,10 @@ struct uvc_device {
        atomic_t nmappings;
 
        /* Video control interface */
+#ifdef CONFIG_MEDIA_CONTROLLER
+       struct media_device mdev;
+#endif
+       struct v4l2_device vdev;
        __u16 uvc_version;
        __u32 clock_frequency;