Linux Hotplug development
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: work-around for video4linux sysfs
Date: Wed, 08 Aug 2007 10:48:59 +0000	[thread overview]
Message-ID: <1186570139.2573.5.camel@lov.localdomain> (raw)
In-Reply-To: <20070731195136.GW9881@outflux.net>

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

On Tue, 2007-08-07 at 16:18 -0700, Kees Cook wrote:
> On Wed, Aug 08, 2007 at 12:58:43AM +0200, Kay Sievers wrote:
> > Look at drivers/media/video/videodev.c how the "name" attribute is
> > created. There should probably be common "function" names added to
> > the v4l core which are just referenced by the drivers, like the
> > defines for the device type in include/media/v4l2-dev.h which are
> > replaced by strings in drivers/media/video/videodev.c.
> 
> Okay, thanks.  I'll try to find some time to investigate this.

Try the attached patch as a start. It adds a "function" attribute to
every v4l device. You need to add the classification to the drivers you
use, to see if that will work for you.

I added V4L2_FN_VIDEO_CAP to my ancient webcam:
  $ grep . /sys/class/video4linux/*/*
  /sys/class/video4linux/video0/bridge:OV511+
  /sys/class/video4linux/video0/brightness:126
  /sys/class/video4linux/video0/contrast:86
  /sys/class/video4linux/video0/custom_id:21
  /sys/class/video4linux/video0/dev:81:0
  /sys/class/video4linux/video0/exposure:0
  /sys/class/video4linux/video0/function:video-cap
  /sys/class/video4linux/video0/hue:128
  /sys/class/video4linux/video0/model:Creative Labs WebCam 3
  /sys/class/video4linux/video0/name:OV511 USB Camera
  /sys/class/video4linux/video0/saturation:192
  /sys/class/video4linux/video0/sensor:OV7620

Good luck,  
Kay


[-- Attachment #2: v4l-function-attr.patch --]
[-- Type: text/x-patch, Size: 5187 bytes --]

diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index e5edff1..511d094 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -4668,6 +4668,7 @@ static struct video_device vdev_template = {
 	.owner =	THIS_MODULE,
 	.name =		"OV511 USB Camera",
 	.type =		VID_TYPE_CAPTURE,
+	.function = 	V4L2_FN_VIDEO_CAP,
 	.hardware =	VID_HARDWARE_OV511,
 	.fops =		&ov511_fops,
 	.release =	video_device_release,
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index d2915d3..84ded35 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -247,6 +247,45 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
 	return 0;
 }
 
+/*
+ * Exports "function" string to userspace to identify the type of device
+ * if multiple streams are available for a single device.
+ *
+ * Types/string names should be reused if possible, instead of adding
+ * new very device specific types, they must _uniquely_ identify all
+ * streams belonging to the _same_ device though.
+ *
+ * No single device must export multiple streams with the same function
+ * string, because userspace this to find the correct device node.
+ *
+ * Unlike the free-text "name", it must be an easily machine useable
+ * string containing only [a-z0-9._-] characters.
+ *
+ * Strings must not change without a valid reason, they are part of the
+ * sysfs ABI.
+ *
+ */
+static const char *v4l2_function_type_names[] = {
+	[V4L2_FN_UNDEFINED]		= "undefined",
+	[V4L2_FN_VIDEO_CAP]		= "video-cap",
+	[V4L2_FN_VIDEO_OUT]		= "video-out",
+	[V4L2_FN_MPEG_CAP]		= "mpeg-cap",
+	[V4L2_FN_MPEG_OUT]		= "mpeg-out",
+	[V4L2_FN_YUV_CAP]		= "yuv-cap",
+	[V4L2_FN_YUV_OUT]		= "yuv-out",
+	[V4L2_FN_VBI_CAP]		= "vbi-cap",
+	[V4L2_FN_VBI_OUT]		= "vbi-out",
+	[V4L2_FN_PCM_CAP]		= "pcm-cap",
+	[V4L2_FN_PCM_OUT]		= "pcm-out",
+};
+
+const char *v4l2_function_name(enum v4l2_function_type function)
+{
+	if (function >= 0 && function < ARRAY_SIZE(v4l2_function_type_names))
+		return v4l2_function_type_names[function];
+	printk(KERN_ERR "v4ls: unknown v4l2_function_type\n");
+	return "error";
+}
 
 /* ----------------------------------------------------------------- */
 /* some arrays for pretty-printing debug messages of enum types      */
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index b876aca..582773c 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -61,7 +61,12 @@ static ssize_t show_name(struct class_device *cd, char *buf)
 	return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name);
 }
 
-static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
+static ssize_t show_function(struct class_device *cd, char *buf)
+{
+	struct video_device *vfd = container_of(cd, struct video_device,
+								class_dev);
+	return sprintf(buf, "%s\n", v4l2_function_name(vfd->function));
+}
 
 struct video_device *video_device_alloc(void)
 {
@@ -89,8 +94,15 @@ static void video_release(struct class_device *cd)
 	vfd->release(vfd);
 }
 
+static struct class_device_attribute video_device_attrs[] = {
+	__ATTR(name, S_IRUGO, show_name, NULL),
+	__ATTR(function, S_IRUGO, show_function, NULL),
+	__ATTR_NULL
+};
+
 static struct class video_class = {
 	.name    = VIDEO_NAME,
+	.class_dev_attrs = video_device_attrs,
 	.release = video_release,
 };
 
@@ -1763,12 +1775,6 @@ int video_register_device(struct video_device *vfd, int type, int nr)
 		       __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 */
@@ -1779,8 +1785,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;
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index c66c8a3..d048d46 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -138,6 +138,23 @@ enum v4l2_field {
 	 (field) == V4L2_FIELD_SEQ_TB ||\
 	 (field) == V4L2_FIELD_SEQ_BT)
 
+/* Exports "function" string to userspace to identify type of device */
+enum v4l2_function_type {
+	V4L2_FN_UNDEFINED,
+	V4L2_FN_VIDEO_CAP,
+	V4L2_FN_VIDEO_OUT,
+	V4L2_FN_MPEG_CAP,
+	V4L2_FN_MPEG_OUT,
+	V4L2_FN_YUV_CAP,
+	V4L2_FN_YUV_OUT,
+	V4L2_FN_VBI_CAP,
+	V4L2_FN_VBI_OUT,
+	V4L2_FN_PCM_CAP,
+	V4L2_FN_PCM_OUT,
+};
+
+extern const char *v4l2_function_name(enum v4l2_function_type function);
+
 enum v4l2_buf_type {
 	V4L2_BUF_TYPE_VIDEO_CAPTURE        = 1,
 	V4L2_BUF_TYPE_VIDEO_OUTPUT         = 2,
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index d62847f..0141b6c 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -93,6 +93,7 @@ struct video_device
 	char name[32];
 	int type;       /* v4l1 */
 	int type2;      /* v4l2 */
+	enum v4l2_function_type function; /* sysfs string */
 	int hardware;
 	int minor;
 

[-- Attachment #3: Type: text/plain, Size: 315 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/

[-- Attachment #4: Type: text/plain, Size: 226 bytes --]

_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

  parent reply	other threads:[~2007-08-08 10:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-31 19:51 work-around for video4linux sysfs Kees Cook
2007-08-01 20:52 ` Greg KH
2007-08-01 21:31 ` Kees Cook
2007-08-01 21:58 ` Greg KH
2007-08-01 22:22 ` Kees Cook
2007-08-01 22:39 ` Greg KH
2007-08-01 23:14 ` Kees Cook
2007-08-01 23:28 ` Greg KH
2007-08-01 23:48 ` Kees Cook
2007-08-02  9:24 ` Kay Sievers
2007-08-02 14:05 ` Kees Cook
2007-08-02 22:30 ` Kay Sievers
2007-08-02 22:39 ` Linas Vepstas
2007-08-02 23:02 ` Kay Sievers
2007-08-07  0:39 ` Kees Cook
2007-08-07  9:24 ` Kay Sievers
2007-08-07 19:36 ` Kees Cook
2007-08-07 22:58 ` Kay Sievers
2007-08-07 23:18 ` Kees Cook
2007-08-08 10:48 ` Kay Sievers [this message]
2007-08-09 19:38 ` Kees Cook

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=1186570139.2573.5.camel@lov.localdomain \
    --to=kay.sievers@vrfy.org \
    --cc=linux-hotplug@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