mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bastien Nocera <hadess@hadess.net>
To: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] [ov511] Export snapshot button through input layer
Date: Tue, 02 Dec 2008 19:07:03 +0000	[thread overview]
Message-ID: <1228244823.8307.1458.camel@cookie.hadess.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 107 bytes --]

Patch says it all.

Comments appreciated, but please keep me on CC: as I'm not subscribed to
LKML.

Cheers

[-- Attachment #2: 0001--ov511-Export-snapshot-button-through-input-layer.patch --]
[-- Type: text/x-patch, Size: 4533 bytes --]

>From dea35acfe9ef161fb44cc0efbbd700472f5f1bc9 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Tue, 2 Dec 2008 19:03:06 +0000
Subject: [PATCH] [ov511] Export snapshot button through input layer

Register an input device with one button, and for the supported
OV511 webcams, poll and check whether the snapshot button has been
pressed on each new frame.
---
 drivers/media/video/ov511.c |   84 +++++++++++++++++++++++++++++++++++++++++-
 drivers/media/video/ov511.h |    1 +
 2 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index 210f124..bad665b 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -352,6 +352,73 @@ rvfree(void *mem, unsigned long size)
 
 /**********************************************************************
  *
+ * Input device
+ *
+ **********************************************************************/
+#ifdef CONFIG_OV511_INPUT_EVDEV
+#warn foobar
+static int ov511_input_init(struct usb_ov511 *ov)
+{
+	struct usb_device *udev = ov->udev;
+	struct input_dev *input;
+	char *phys = NULL;
+	int ret;
+
+	input = input_allocate_device();
+	if (input == NULL)
+		return -ENOMEM;
+
+	phys = kmalloc(6 + strlen(udev->bus->bus_name) + strlen(udev->devpath),
+			GFP_KERNEL);
+	if (phys == NULL) {
+		ret = -ENOMEM;
+		goto error;
+	}
+	sprintf(phys, "usb-%s-%s", udev->bus->bus_name, udev->devpath);
+
+	input->name = ov->name;
+	input->phys = phys;
+	usb_to_input_id(udev, &input->id);
+	input->dev.parent = &ov->intf->dev;
+
+	set_bit(EV_KEY, input->evbit);
+	set_bit(KEY_CAMERA, input->keybit);
+
+	if ((ret = input_register_device(input)) < 0)
+		goto error;
+
+	ov->key_input = input;
+	return 0;
+
+error:
+	input_free_device(input);
+	kfree(phys);
+	return ret;
+}
+
+static void ov511_input_cleanup(struct usb_ov511 *ov)
+{
+	if (ov->key_input)
+		input_unregister_device(ov->key_input);
+}
+
+static void ov511_input_report_key(struct usb_ov511 *ov, unsigned int code,
+	int value)
+{
+	if (ov->key_input) {
+		input_report_key(ov->key_input, code, value);
+		input_sync(ov->key_input);
+	}
+}
+
+#else
+#define ov511_input_init(dev) 0
+#define ov511_input_cleanup(dev)
+#define ov511_input_report_key(dev, code, value)
+#endif /* CONFIG_OV511_INPUT_EVDEV */
+
+/**********************************************************************
+ *
  * Register I/O
  *
  **********************************************************************/
@@ -1105,7 +1172,6 @@ ov51x_clear_snapshot(struct usb_ov511 *ov)
 	}
 }
 
-#if 0
 /* Checks the status of the snapshot button. Returns 1 if it was pressed since
  * it was last cleared, and zero in all other cases (including errors) */
 static int
@@ -1130,7 +1196,6 @@ ov51x_check_snapshot(struct usb_ov511 *ov)
 
 	return status;
 }
-#endif
 
 /* This does an initial reset of an OmniVision sensor and ensures that I2C
  * is synchronized. Returns <0 for failure.
@@ -4388,6 +4453,12 @@ redo:
 			if ((ov->snap_enabled) && (frame->snapshot)) {
 				frame->snapshot = 0;
 				ov51x_clear_snapshot(ov);
+			} else if (!ov->snap_enabled && ov->bclass == BCL_OV511) {
+				if (ov51x_check_snapshot(ov) == 1) {
+					ov511_input_report_key(ov, KEY_CAMERA, 1);
+					ov511_input_report_key(ov, KEY_CAMERA, 0);
+					ov51x_clear_snapshot(ov);
+				}
 			}
 
 			/* Decompression, format conversion, etc... */
@@ -5877,6 +5948,13 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
 		goto error;
 	}
 
+	/* Snapshot is currently only supported on OV511,
+	 * so no need to register the input device if it's not supported */
+	if (!ov->snap_enabled && ov->bclass == BCL_OV511) {
+		if (ov511_input_init(dev) < 0)
+			dev_warn(&ov->dev->dev, "Could not register input device\n");
+	}
+
 	return 0;
 
 error:
@@ -5919,6 +5997,8 @@ ov51x_disconnect(struct usb_interface *intf)
 	if (ov->vdev)
 		video_unregister_device(ov->vdev);
 
+	ov511_input_cleanup(ov);
+
 	for (n = 0; n < OV511_NUMFRAMES; n++)
 		ov->frame[n].grabstate = FRAME_ERROR;
 
diff --git a/drivers/media/video/ov511.h b/drivers/media/video/ov511.h
index 70d99e5..a9346c7 100644
--- a/drivers/media/video/ov511.h
+++ b/drivers/media/video/ov511.h
@@ -468,6 +468,7 @@ struct usb_ov511 {
 	wait_queue_head_t wq;	/* Processes waiting */
 
 	int snap_enabled;	/* Snapshot mode enabled */
+	struct input_dev *key_input;/* The input device for the snapshot button */
 
 	int bridge;		/* Type of bridge (BRG_*) */
 	int bclass;		/* Class of bridge (BCL_*) */
-- 
1.6.0.4


             reply	other threads:[~2008-12-02 19:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-02 19:07 Bastien Nocera [this message]
2008-12-02 20:13 ` Alan Cox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1228244823.8307.1458.camel@cookie.hadess.net \
    --to=hadess@hadess.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®