V4L/DVB (10242): pwc: add support for webcam snapshot button
authorNam Phạm Thành <phamthanhnam.ptn@gmail.com>
Mon, 12 Jan 2009 05:50:17 +0000 (02:50 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 30 Mar 2009 15:42:22 +0000 (12:42 -0300)
This patch adds support for Philips webcam snapshot button as an
event input device, for consistency with other webcam drivers.

Signed-off-by: Pham Thanh Nam <phamthanhnam.ptn@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/pwc/Kconfig
drivers/media/video/pwc/pwc-if.c
drivers/media/video/pwc/pwc.h

index 7298cf2e1650f53f2c5e90f0873045d295e43c17..8b9f0aa844a19b8f63b5dd66134a43f9d7993aa0 100644 (file)
@@ -35,3 +35,13 @@ config USB_PWC_DEBUG
          Say Y here in order to have the pwc driver generate verbose debugging
          messages.
          A special module options 'trace' is used to control the verbosity.
+
+config USB_PWC_INPUT_EVDEV
+       bool "USB Philips Cameras input events device support"
+       default y
+       depends on USB_PWC && INPUT
+       ---help---
+         This option makes USB Philips cameras register the snapshot button as
+         an input device to report button events.
+
+         If you are in doubt, say Y.
index 0d810189dd87836861e1974267137e6325e5b7e4..a7c2e7284c207897d2907b7024ff0e42b644c515 100644 (file)
@@ -53,6 +53,7 @@
    - Xavier Roche: QuickCam Pro 4000 ID
    - Jens Knudsen: QuickCam Zoom ID
    - J. Debert: QuickCam for Notebooks ID
+   - Pham Thanh Nam: webcam snapshot button as an event input device
 */
 
 #include <linux/errno.h>
@@ -61,6 +62,9 @@
 #include <linux/module.h>
 #include <linux/poll.h>
 #include <linux/slab.h>
+#ifdef CONFIG_USB_PWC_INPUT_EVDEV
+#include <linux/usb/input.h>
+#endif
 #include <linux/vmalloc.h>
 #include <asm/io.h>
 
@@ -586,6 +590,23 @@ static void pwc_frame_dumped(struct pwc_device *pdev)
                                pdev->vframe_count);
 }
 
+static void pwc_snapshot_button(struct pwc_device *pdev, int down)
+{
+       if (down) {
+               PWC_TRACE("Snapshot button pressed.\n");
+               pdev->snapshot_button_status = 1;
+       } else {
+               PWC_TRACE("Snapshot button released.\n");
+       }
+
+#ifdef CONFIG_USB_PWC_INPUT_EVDEV
+       if (pdev->button_dev) {
+               input_report_key(pdev->button_dev, BTN_0, down);
+               input_sync(pdev->button_dev);
+       }
+#endif
+}
+
 static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_buf *fbuf)
 {
        int awake = 0;
@@ -603,13 +624,7 @@ static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_
                        pdev->vframes_error++;
                }
                if ((ptr[0] ^ pdev->vmirror) & 0x01) {
-                       if (ptr[0] & 0x01) {
-                               pdev->snapshot_button_status = 1;
-                               PWC_TRACE("Snapshot button pressed.\n");
-                       }
-                       else {
-                               PWC_TRACE("Snapshot button released.\n");
-                       }
+                       pwc_snapshot_button(pdev, ptr[0] & 0x01);
                }
                if ((ptr[0] ^ pdev->vmirror) & 0x02) {
                        if (ptr[0] & 0x02)
@@ -633,12 +648,7 @@ static int pwc_rcv_short_packet(struct pwc_device *pdev, const struct pwc_frame_
        else if (pdev->type == 740 || pdev->type == 720) {
                unsigned char *ptr = (unsigned char *)fbuf->data;
                if ((ptr[0] ^ pdev->vmirror) & 0x01) {
-                       if (ptr[0] & 0x01) {
-                               pdev->snapshot_button_status = 1;
-                               PWC_TRACE("Snapshot button pressed.\n");
-                       }
-                       else
-                               PWC_TRACE("Snapshot button released.\n");
+                       pwc_snapshot_button(pdev, ptr[0] & 0x01);
                }
                pdev->vmirror = ptr[0] & 0x03;
        }
@@ -1216,6 +1226,15 @@ static void pwc_cleanup(struct pwc_device *pdev)
 {
        pwc_remove_sysfs_files(pdev->vdev);
        video_unregister_device(pdev->vdev);
+
+#ifdef CONFIG_USB_PWC_INPUT_EVDEV
+       if (pdev->button_dev) {
+               input_unregister_device(pdev->button_dev);
+               input_free_device(pdev->button_dev);
+               kfree(pdev->button_dev->phys);
+               pdev->button_dev = NULL;
+       }
+#endif
 }
 
 /* Note that all cleanup is done in the reverse order as in _open */
@@ -1483,6 +1502,9 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
        int features = 0;
        int video_nr = -1; /* default: use next available device */
        char serial_number[30], *name;
+#ifdef CONFIG_USB_PWC_INPUT_EVDEV
+       char *phys = NULL;
+#endif
 
        vendor_id = le16_to_cpu(udev->descriptor.idVendor);
        product_id = le16_to_cpu(udev->descriptor.idProduct);
@@ -1807,6 +1829,35 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
        pwc_set_leds(pdev, 0, 0);
        pwc_camera_power(pdev, 0);
 
+#ifdef CONFIG_USB_PWC_INPUT_EVDEV
+       /* register webcam snapshot button input device */
+       pdev->button_dev = input_allocate_device();
+       if (!pdev->button_dev) {
+               PWC_ERROR("Err, insufficient memory for webcam snapshot button device.");
+               return -ENOMEM;
+       }
+
+       pdev->button_dev->name = "PWC snapshot button";
+       phys = kasprintf(GFP_KERNEL,"usb-%s-%s", pdev->udev->bus->bus_name, pdev->udev->devpath);
+       if (!phys) {
+               input_free_device(pdev->button_dev);
+               return -ENOMEM;
+       }
+       pdev->button_dev->phys = phys;
+       usb_to_input_id(pdev->udev, &pdev->button_dev->id);
+       pdev->button_dev->dev.parent = &pdev->udev->dev;
+       pdev->button_dev->evbit[0] = BIT_MASK(EV_KEY);
+       pdev->button_dev->keybit[BIT_WORD(BTN_0)] = BIT_MASK(BTN_0);
+
+       rc = input_register_device(pdev->button_dev);
+       if (rc) {
+               input_free_device(pdev->button_dev);
+               kfree(pdev->button_dev->phys);
+               pdev->button_dev = NULL;
+               return rc;
+       }
+#endif
+
        return 0;
 
 err_unreg:
index 01411fb2337ae9d0e392d2d0cd611889b1e8b2b7..0be6f814f5396cb7615484201db3a45a46f98ac5 100644 (file)
@@ -37,6 +37,9 @@
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
+#ifdef CONFIG_USB_PWC_INPUT_EVDEV
+#include <linux/input.h>
+#endif
 
 #include "pwc-uncompress.h"
 #include <media/pwc-ioctl.h>
@@ -255,6 +258,9 @@ struct pwc_device
    int pan_angle;                      /* in degrees * 100 */
    int tilt_angle;                     /* absolute angle; 0,0 is home position */
    int snapshot_button_status;         /* set to 1 when the user push the button, reset to 0 when this value is read */
+#ifdef CONFIG_USB_PWC_INPUT_EVDEV
+   struct input_dev *button_dev;       /* webcam snapshot button input */
+#endif
 
    /*** Misc. data ***/
    wait_queue_head_t frameq;           /* When waiting for a frame to finish... */