V4L/DVB (10873): w9968cf: add v4l2_device.
authorHans Verkuil <hverkuil@xs4all.nl>
Sun, 8 Mar 2009 09:56:19 +0000 (06:56 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 30 Mar 2009 15:43:11 +0000 (12:43 -0300)
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/w9968cf.c
drivers/media/video/w9968cf.h

index 105a832531f2529a61a6c45cbb0855f79b514bfa..3318be5688c9aa65cdca3686ae4b8c9ff1f9ff1a 100644 (file)
@@ -3495,12 +3495,14 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
        if (!cam)
                return -ENOMEM;
 
+       err = v4l2_device_register(&udev->dev, &cam->v4l2_dev);
+       if (err)
+               goto fail0;
+
        mutex_init(&cam->dev_mutex);
        mutex_lock(&cam->dev_mutex);
 
        cam->usbdev = udev;
-       /* NOTE: a local copy is used to avoid possible race conditions */
-       memcpy(&cam->dev, &udev->dev, sizeof(struct device));
 
        DBG(2, "%s detected", symbolic(camlist, mod_id))
 
@@ -3549,7 +3551,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
        cam->v4ldev->minor = video_nr[dev_nr];
        cam->v4ldev->release = video_device_release;
        video_set_drvdata(cam->v4ldev, cam);
-       cam->v4ldev->parent = &cam->dev;
+       cam->v4ldev->v4l2_dev = &cam->v4l2_dev;
 
        err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
                                    video_nr[dev_nr]);
@@ -3579,6 +3581,9 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
 
        usb_set_intfdata(intf, cam);
        mutex_unlock(&cam->dev_mutex);
+
+       if (ovmod_load)
+               request_module("ovcamchip");
        return 0;
 
 fail: /* Free unused memory */
@@ -3587,6 +3592,8 @@ fail: /* Free unused memory */
        if (cam->v4ldev)
                video_device_release(cam->v4ldev);
        mutex_unlock(&cam->dev_mutex);
+       v4l2_device_unregister(&cam->v4l2_dev);
+fail0:
        kfree(cam);
        return err;
 }
@@ -3622,8 +3629,10 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf)
 
                mutex_unlock(&cam->dev_mutex);
 
-               if (!cam->users)
+               if (!cam->users) {
+                       v4l2_device_unregister(&cam->v4l2_dev);
                        kfree(cam);
+               }
        }
 
        up_write(&w9968cf_disconnect);
@@ -3650,9 +3659,6 @@ static int __init w9968cf_module_init(void)
        KDBG(2, W9968CF_MODULE_NAME" "W9968CF_MODULE_VERSION)
        KDBG(3, W9968CF_MODULE_AUTHOR)
 
-       if (ovmod_load)
-               request_module("ovcamchip");
-
        if ((err = usb_register(&w9968cf_usb_driver)))
                return err;
 
index 30032e15e23c2761fc9461462466c0cf82eb381c..c5988355254525577f024b1997c1069987b74ea9 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/rwsem.h>
 #include <linux/mutex.h>
 
+#include <media/v4l2-device.h>
 #include <media/ovcamchip.h>
 
 #include "w9968cf_vpp.h"
@@ -195,10 +196,9 @@ enum w9968cf_vpp_flag {
 
 /* Main device driver structure */
 struct w9968cf_device {
-       struct device dev; /* device structure */
-
        enum w9968cf_model_id id;   /* private device identifier */
 
+       struct v4l2_device v4l2_dev;
        struct video_device* v4ldev; /* -> V4L structure */
        struct list_head v4llist;    /* entry of the list of V4L cameras */
 
@@ -291,14 +291,14 @@ struct w9968cf_device {
        if ( ((specific_debug) && (debug == (level))) ||                      \
             ((!specific_debug) && (debug >= (level))) ) {                    \
                if ((level) == 1)                                             \
-                       dev_err(&cam->dev, fmt "\n", ## args);                \
+                       v4l2_err(&cam->v4l2_dev, fmt "\n", ## args);          \
                else if ((level) == 2 || (level) == 3)                        \
-                       dev_info(&cam->dev, fmt "\n", ## args);               \
+                       v4l2_info(&cam->v4l2_dev, fmt "\n", ## args);         \
                else if ((level) == 4)                                        \
-                       dev_warn(&cam->dev, fmt "\n", ## args);               \
+                       v4l2_warn(&cam->v4l2_dev, fmt "\n", ## args);         \
                else if ((level) >= 5)                                        \
-                       dev_info(&cam->dev, "[%s:%d] " fmt "\n",              \
-                                __func__, __LINE__ , ## args);           \
+                       v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n",        \
+                                __func__, __LINE__ , ## args);               \
        }                                                                     \
 }
 /* For generic kernel (not device specific) messages */
@@ -321,7 +321,7 @@ struct w9968cf_device {
 
 #undef PDBG
 #define PDBG(fmt, args...)                                                    \
-dev_info(&cam->dev, "[%s:%d] " fmt "\n", __func__, __LINE__ , ## args);
+v4l2_info(&cam->v4l2_dev, "[%s:%d] " fmt "\n", __func__, __LINE__ , ## args);
 
 #undef PDBGG
 #define PDBGG(fmt, args...) do {;} while(0); /* nothing: it's a placeholder */