All of lore.kernel.org
 help / color / mirror / Atom feed
From: laurent.pinchart@ideasonboard.com
To: linux-media@vger.kernel.org
Cc: sakari.ailus@maxwell.research.nokia.com, hverkuil@xs4all.nl,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: [RFC/PATCH 14/14] uvcvideo: Register subdevices for each entity
Date: Tue, 20 Oct 2009 03:12:24 +0200	[thread overview]
Message-ID: <20091020011216.038361298@ideasonboard.com> (raw)
In-Reply-To: 20091020011210.623421213@ideasonboard.com

[-- Attachment #1: uvc-mc.patch --]
[-- Type: text/plain, Size: 4356 bytes --]

Userspace applications can now discover the UVC device topology using
the media controller API.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Index: v4l-dvb-mc/linux/drivers/media/video/uvc/uvc_driver.c
===================================================================
--- v4l-dvb-mc.orig/linux/drivers/media/video/uvc/uvc_driver.c
+++ v4l-dvb-mc/linux/drivers/media/video/uvc/uvc_driver.c
@@ -762,9 +762,12 @@ static struct uvc_entity *uvc_alloc_enti
 	struct uvc_entity *entity;
 	unsigned int num_inputs;
 	unsigned int size;
+	unsigned int i;
 
+	extra_size = ALIGN(extra_size, sizeof(*entity->pads));
 	num_inputs = (type & UVC_TERM_OUTPUT) ? num_pads : num_pads - 1;
-	size = sizeof(*entity) + extra_size + num_inputs;
+	size = sizeof(*entity) + extra_size + sizeof(*entity->pads) * num_pads
+	     + num_inputs;
 	entity = kzalloc(size, GFP_KERNEL);
 	if (entity == NULL)
 		return NULL;
@@ -772,8 +775,17 @@ static struct uvc_entity *uvc_alloc_enti
 	entity->id = id;
 	entity->type = type;
 
+	entity->num_links = 0;
+	entity->num_pads = num_pads;
+	entity->pads = ((void *)(entity + 1)) + extra_size;
+
+	for (i = 0; i < num_inputs; ++i)
+		entity->pads[i].type = V4L2_PAD_TYPE_INPUT;
+	if (!UVC_ENTITY_IS_OTERM(entity))
+		entity->pads[num_pads-1].type = V4L2_PAD_TYPE_OUTPUT;
+
 	entity->bNrInPins = num_inputs;
-	entity->baSourceID = ((__u8 *)entity) + sizeof(*entity) + extra_size;
+	entity->baSourceID = (__u8 *)(&entity->pads[num_pads]);
 
 	return entity;
 }
@@ -1158,6 +1170,77 @@ next_descriptor:
 }
 
 /* ------------------------------------------------------------------------
+ * Video subdevices registration and unregistration
+ */
+
+static int uvc_mc_register_subdev(struct uvc_video_chain *chain,
+	struct uvc_entity *entity)
+{
+	const u32 flags = V4L2_LINK_FLAG_ACTIVE | V4L2_LINK_FLAG_PERMANENT;
+	struct uvc_entity *remote;
+	unsigned int i;
+	u8 remote_pad;
+	int ret;
+
+	for (i = 0; i < entity->num_pads; ++i) {
+		if (entity->pads[i].type != V4L2_PAD_TYPE_INPUT)
+			continue;
+
+		remote = uvc_entity_by_id(chain->dev, entity->baSourceID[i]);
+		if (remote == NULL)
+			return -EINVAL;
+
+		remote_pad = remote->num_pads - 1;
+		ret = v4l2_entity_connect(&remote->subdev.entity, remote_pad,
+					  &entity->subdev.entity, i, flags);
+		if (ret < 0)
+			return ret;
+	}
+
+	return v4l2_device_register_subdev(&chain->dev->vdev, &entity->subdev);
+}
+
+static struct v4l2_subdev_ops uvc_subdev_ops = {
+};
+
+static int uvc_mc_init_subdev(struct uvc_video_chain *chain,
+	struct uvc_entity *entity)
+{
+	v4l2_subdev_init(&entity->subdev, &uvc_subdev_ops);
+	snprintf(entity->subdev.name, sizeof(entity->subdev.name), "uvc-%u",
+		 entity->id);
+
+	return v4l2_entity_init(&entity->subdev.entity, entity->num_pads,
+				entity->pads, 0);
+}
+
+static int uvc_mc_register_subdevs(struct uvc_video_chain *chain)
+{
+	struct uvc_entity *entity;
+	int ret;
+
+	list_for_each_entry(entity, &chain->entities, chain) {
+		ret = uvc_mc_init_subdev(chain, entity);
+		if (ret < 0) {
+			uvc_printk(KERN_INFO, "Failed to initialize subdev for "
+				   "entity %u\n", entity->id);
+			return ret;
+		}
+	}
+
+	list_for_each_entry(entity, &chain->entities, chain) {
+		ret = uvc_mc_register_subdev(chain, entity);
+		if (ret < 0) {
+			uvc_printk(KERN_INFO, "Failed to register subdev for "
+				   "entity %u\n", entity->id);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+/* ------------------------------------------------------------------------
  * UVC device scan
  */
 
@@ -1708,6 +1791,12 @@ static int uvc_register_chains(struct uv
 		ret = uvc_register_terms(dev, chain);
 		if (ret < 0)
 			return ret;
+
+		ret = uvc_mc_register_subdevs(chain);
+		if (ret < 0) {
+			uvc_printk(KERN_INFO, "Failed to register subdevs "
+				"(%d).\n", ret);
+		}
 	}
 
 	return 0;
Index: v4l-dvb-mc/linux/drivers/media/video/uvc/uvcvideo.h
===================================================================
--- v4l-dvb-mc.orig/linux/drivers/media/video/uvc/uvcvideo.h
+++ v4l-dvb-mc/linux/drivers/media/video/uvc/uvcvideo.h
@@ -278,6 +278,12 @@ struct uvc_entity {
 	__u16 type;
 	char name[64];
 
+	/* Media controller-related fields. */
+	struct v4l2_subdev subdev;
+	unsigned int num_pads;
+	unsigned int num_links;
+	struct v4l2_entity_pad *pads;
+
 	union {
 		struct {
 			__u16 wObjectiveFocalLengthMin;



  parent reply	other threads:[~2009-10-20  8:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-20  1:12 [RFC/PATCH 00/14] Media controller update based on Hans' v4l-dvb-mc tree laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 01/14] v4l-mc: Rename pins to pads laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 02/14] v4l-mc: Merge input and output pads laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 03/14] v4l-mc: Replace the active pads bitmask by a link flag laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 04/14] v4l-subdev: Add pads operations laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 05/14] v4l-mc: Clean up link API laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 06/14] v4l-mc: Remove subdev v4l2_dev field laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 07/14] v4l-mc: Remove devnode " laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 08/14] uvcvideo: Rely on videodev to reference-count the device laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 09/14] uvcvideo: Merge iterms, oterms and extensions linked lists laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 10/14] uvcvideo: Fix extension units parsing laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 11/14] uvcvideo: Refactor chain scan laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 12/14] uvcvideo: Factorize common field in uvc_entity structure laurent.pinchart
2009-10-20  1:12 ` [RFC/PATCH 13/14] uvcvideo: Register a v4l2_device laurent.pinchart
2009-10-20  1:12 ` laurent.pinchart [this message]
2009-10-20 22:15 ` [RFC/PATCH 00/14] Media controller update based on Hans' v4l-dvb-mc tree Hans Verkuil
2009-10-20 22:32   ` Laurent Pinchart

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=20091020011216.038361298@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@maxwell.research.nokia.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.