public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/8] media: Add entity types
@ 2016-03-01 14:57 Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 1/8] v4l: vsp1: Check if an entity is a subdev with the right function Laurent Pinchart
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media
  Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Prabhakar Lad

Hello,

This patch series adds a type field to the media entity structure.

Let's start with a few words about what types are and are not. The purpose of
the entity type is to identify the object type that implements the entity, in
order to safely cast the entity to that object (using container_of()). Three
types are currently defined, for media entities that are instantiated as such
(MEDIA_ENTITY_TYPE_MEDIA_ENTITY), embedded in a struct video_device
(MEDIA_ENTITY_TYPE_VIDEO_DEVICE) or embedded in a struct v4l2_subdev
(MEDIA_ENTITY_TYPE_V4L2_SUBDEV). The naming is pretty straightforward and
self-explicit.

Types do not convey any additional information. They don't tell anything about
the features of the entity or the object that implements it. In particular
they don't report capabilities of video_device instances, which is why the
is_media_entity_v4l2_io() function performs additional checks on the video
device capabilities field, after verifying with the type that it can safely be
cast to a video_device instance.

The series start by two cleanup patches (1/8 and 2/8) that fix incorrect or
unneeded usage of the is_media_entity_v4l2_*() functions in the vsp1 and
exynos4-is drivers. Patch 3/8 then adds the type field to the media_entity
structure and updates the is_media_entity_v4l2_*() functions implementations.
Patch 4/8 renames is_media_entity_v4l2_io() to
is_media_entity_v4l2_video_device() to clarify its purpose.

Patch 5/8 to 8/8 then implement a is_media_entity_v4l2_io() function that does
what its name suggest, check if the entity is a video device that can perform
I/O. To to so it starts by adding a new device_caps field to the video_device
structure (5/8), makes use of it in the v4l2-pci-skeleton (6/8) and vivid (7/8)
drivers, and finally adds the is_media_entity_v4l2_io() function.

Note that the is_media_entity_v4l2_io() function has no user at the moment, se
we could leave that patch out until drivers need it.

Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Prabhakar Lad <prabhakar.csengg@gmail.com>

Hans Verkuil (5):
  media: Rename is_media_entity_v4l2_io to
    is_media_entity_v4l2_video_device
  v4l2: add device_caps to struct video_device
  v4l2-pci-skeleton.c: fill in device_caps in video_device
  vivid: set device_caps in video_device.
  media-entity.h: Add is_media_entity_v4l2_io()

Laurent Pinchart (3):
  v4l: vsp1: Check if an entity is a subdev with the right function
  v4l: exynos4-is: Drop unneeded check when setting up fimc-lite links
  media: Add type field to struct media_entity

 Documentation/video4linux/v4l2-pci-skeleton.c   |  5 +-
 drivers/media/platform/exynos4-is/fimc-lite.c   | 12 +---
 drivers/media/platform/exynos4-is/media-dev.c   |  4 +-
 drivers/media/platform/omap3isp/isp.c           |  2 +-
 drivers/media/platform/omap3isp/ispvideo.c      |  2 +-
 drivers/media/platform/vivid/vivid-core.c       | 22 +++----
 drivers/media/platform/vsp1/vsp1_video.c        |  2 +-
 drivers/media/v4l2-core/v4l2-common.c           | 21 +++++++
 drivers/media/v4l2-core/v4l2-dev.c              |  1 +
 drivers/media/v4l2-core/v4l2-ioctl.c            |  3 +
 drivers/media/v4l2-core/v4l2-subdev.c           |  1 +
 drivers/staging/media/davinci_vpfe/vpfe_video.c |  2 +-
 drivers/staging/media/omap4iss/iss.c            |  2 +-
 drivers/staging/media/omap4iss/iss_video.c      |  2 +-
 include/media/media-entity.h                    | 77 +++++++++++++------------
 include/media/v4l2-common.h                     | 12 ++++
 include/media/v4l2-dev.h                        |  3 +
 17 files changed, 99 insertions(+), 74 deletions(-)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/8] v4l: vsp1: Check if an entity is a subdev with the right function
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 2/8] v4l: exynos4-is: Drop unneeded check when setting up fimc-lite links Laurent Pinchart
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab

Use is_media_entity_v4l2_subdev() instead of is_media_entity_v4l2_io()
to check whether the entity is a subdev.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/platform/vsp1/vsp1_video.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 61ee0f92c1e5..72cc7d3729f8 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -289,7 +289,7 @@ static int vsp1_video_pipeline_validate(struct vsp1_pipeline *pipe,
 		struct vsp1_rwpf *rwpf;
 		struct vsp1_entity *e;
 
-		if (is_media_entity_v4l2_io(entity))
+		if (!is_media_entity_v4l2_subdev(entity))
 			continue;
 
 		subdev = media_entity_to_v4l2_subdev(entity);
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/8] v4l: exynos4-is: Drop unneeded check when setting up fimc-lite links
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 1/8] v4l: vsp1: Check if an entity is a subdev with the right function Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 3/8] media: Add type field to struct media_entity Laurent Pinchart
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media
  Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki

The driver verifies that the type of the remote entity matches its
expectations when setting up fimc-lite links and returns an error if it
doesn't. Those checks can never fail as the links are created by the
driver in a way that always match its expectations (the SINK and
SOURCE_ISP pads are connected to subdevs only and the SOURCE_DMA pad is
connected to a video node only). Remove them.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/platform/exynos4-is/fimc-lite.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>

diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index e85649147dc8..dc1b929f7a33 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -992,10 +992,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 
 	switch (local->index) {
 	case FLITE_SD_PAD_SINK:
-		if (!is_media_entity_v4l2_subdev(remote->entity)) {
-			ret = -EINVAL;
-			break;
-		}
 		if (flags & MEDIA_LNK_FL_ENABLED) {
 			if (fimc->source_subdev_grp_id == 0)
 				fimc->source_subdev_grp_id = sd->grp_id;
@@ -1010,19 +1006,15 @@ static int fimc_lite_link_setup(struct media_entity *entity,
 	case FLITE_SD_PAD_SOURCE_DMA:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (is_media_entity_v4l2_io(remote->entity))
-			atomic_set(&fimc->out_path, FIMC_IO_DMA);
 		else
-			ret = -EINVAL;
+			atomic_set(&fimc->out_path, FIMC_IO_DMA);
 		break;
 
 	case FLITE_SD_PAD_SOURCE_ISP:
 		if (!(flags & MEDIA_LNK_FL_ENABLED))
 			atomic_set(&fimc->out_path, FIMC_IO_NONE);
-		else if (is_media_entity_v4l2_subdev(remote->entity))
-			atomic_set(&fimc->out_path, FIMC_IO_ISP);
 		else
-			ret = -EINVAL;
+			atomic_set(&fimc->out_path, FIMC_IO_ISP);
 		break;
 
 	default:
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/8] media: Add type field to struct media_entity
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 1/8] v4l: vsp1: Check if an entity is a subdev with the right function Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 2/8] v4l: exynos4-is: Drop unneeded check when setting up fimc-lite links Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  2016-03-03 13:32   ` Hans Verkuil
  2016-03-01 14:57 ` [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device Laurent Pinchart
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab

Code that processes media entities can require knowledge of the
structure type that embeds a particular media entity instance in order
to cast the entity to the proper object type. This needs is shown by the
presence of the is_media_entity_v4l2_io and is_media_entity_v4l2_subdev
functions.

The implementation of those two functions relies on the entity function
field, which is both a wrong and an inefficient design, without even
mentioning the maintenance issue involved in updating the functions
every time a new entity function is added. Fix this by adding add a type
field to the media entity structure to carry the information.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-dev.c    |  1 +
 drivers/media/v4l2-core/v4l2-subdev.c |  1 +
 include/media/media-entity.h          | 75 ++++++++++++++++++-----------------
 3 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index d8e5994cccf1..7e766a92e3d9 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -735,6 +735,7 @@ static int video_register_media_controller(struct video_device *vdev, int type)
 	if (!vdev->v4l2_dev->mdev)
 		return 0;
 
+	vdev->entity.type = MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
 	vdev->entity.function = MEDIA_ENT_F_UNKNOWN;
 
 	switch (type) {
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index d63083803144..bb6e79f14bb8 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -584,6 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
 	sd->host_priv = NULL;
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	sd->entity.name = sd->name;
+	sd->entity.type = MEDIA_ENTITY_TYPE_V4L2_SUBDEV;
 	sd->entity.function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
 #endif
 }
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index d58e29d3f239..cbd37530f6b8 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -187,10 +187,37 @@ struct media_entity_operations {
 };
 
 /**
+ * enum media_entity_type - Media entity type
+ *
+ * @MEDIA_ENTITY_TYPE_MEDIA_ENTITY:
+ *	The entity is a struct media_entity instance.
+ * @MEDIA_ENTITY_TYPE_VIDEO_DEVICE:
+ *	The entity is a struct video_device instance.
+ * @MEDIA_ENTITY_TYPE_V4L2_SUBDEV:
+ *	The entity is a struct v4l2_subdev instance.
+ *
+ * The entity type identifies the type of the object instance that implements
+ * the struct media_entity instance. This allows runtime type identification of
+ * media entities and safe casting to the project object type. For instance, a
+ * media entity structure instance embedded in a v4l2_subdev structure instance
+ * will have the type MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a
+ * v4l2_subdev structure using the container_of() macro.
+ *
+ * Media entities can be instantiated without creating any derived object type,
+ * in which case their type will be MEDIA_ENTITY_TYPE_MEDIA_ENTITY.
+ */
+enum media_entity_type {
+	MEDIA_ENTITY_TYPE_MEDIA_ENTITY,
+	MEDIA_ENTITY_TYPE_VIDEO_DEVICE,
+	MEDIA_ENTITY_TYPE_V4L2_SUBDEV,
+};
+
+/**
  * struct media_entity - A media entity graph object.
  *
  * @graph_obj:	Embedded structure containing the media object common data.
  * @name:	Entity name.
+ * @type:	Type of the object that implements the media_entity.
  * @function:	Entity main function, as defined in uapi/media.h
  *		(MEDIA_ENT_F_*)
  * @flags:	Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*)
@@ -219,6 +246,7 @@ struct media_entity_operations {
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
 	const char *name;
+	enum media_entity_type type;
 	u32 function;
 	unsigned long flags;
 
@@ -328,56 +356,29 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id)
 }
 
 /**
- * is_media_entity_v4l2_io() - identify if the entity main function
- *			       is a V4L2 I/O
- *
+ * is_media_entity_v4l2_io() - Check if the entity is a video_device
  * @entity:	pointer to entity
  *
- * Return: true if the entity main function is one of the V4L2 I/O types
- *	(video, VBI or SDR radio); false otherwise.
+ * Return: true if the entity is an instance of a video_device object and can
+ * safely be cast to a struct video_device using the container_of() macro, or
+ * false otherwise.
  */
 static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
 {
-	if (!entity)
-		return false;
-
-	switch (entity->function) {
-	case MEDIA_ENT_F_IO_V4L:
-	case MEDIA_ENT_F_IO_VBI:
-	case MEDIA_ENT_F_IO_SWRADIO:
-		return true;
-	default:
-		return false;
-	}
+	return entity && entity->type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
 }
 
 /**
- * is_media_entity_v4l2_subdev - return true if the entity main function is
- *				 associated with the V4L2 API subdev usage
- *
+ * is_media_entity_v4l2_subdev() - Check if the entity is a v4l2_subdev
  * @entity:	pointer to entity
  *
- * This is an ancillary function used by subdev-based V4L2 drivers.
- * It checks if the entity function is one of functions used by a V4L2 subdev,
- * e. g. camera-relatef functions, analog TV decoder, TV tuner, V4L2 DSPs.
+ * Return: true if the entity is an instance of a v4l2_subdev object and can
+ * safely be cast to a struct v4l2_subdev using the container_of() macro, or
+ * false otherwise.
  */
 static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
 {
-	if (!entity)
-		return false;
-
-	switch (entity->function) {
-	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
-	case MEDIA_ENT_F_CAM_SENSOR:
-	case MEDIA_ENT_F_FLASH:
-	case MEDIA_ENT_F_LENS:
-	case MEDIA_ENT_F_ATV_DECODER:
-	case MEDIA_ENT_F_TUNER:
-		return true;
-
-	default:
-		return false;
-	}
+	return entity && entity->type == MEDIA_ENTITY_TYPE_V4L2_SUBDEV;
 }
 
 /**
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
                   ` (2 preceding siblings ...)
  2016-03-01 14:57 ` [PATCH 3/8] media: Add type field to struct media_entity Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  2016-03-03 13:33   ` Hans Verkuil
  2016-03-07 10:23   ` Lad, Prabhakar
  2016-03-01 14:57 ` [PATCH 5/8] v4l2: add device_caps to struct video_device Laurent Pinchart
                   ` (3 subsequent siblings)
  7 siblings, 2 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media
  Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Prabhakar Lad

All users of is_media_entity_v4l2_io() (the exynos4-is, omap3isp,
davince_vpfe and omap4iss drivers) use the function to check whether
entities are video_device instances, either to ensure they can cast the
entity to a struct video_device, or to count the number of video nodes
users.

The purpose of the function is thus to identify whether the media entity
instance is an instance of the video_device object, not to check whether
it can perform I/O. Rename it accordingly, we will introduce a more
specific is_media_entity_v4l2_io() check when needed.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/platform/exynos4-is/media-dev.c   | 4 ++--
 drivers/media/platform/omap3isp/isp.c           | 2 +-
 drivers/media/platform/omap3isp/ispvideo.c      | 2 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c | 2 +-
 drivers/staging/media/omap4iss/iss.c            | 2 +-
 drivers/staging/media/omap4iss/iss_video.c      | 2 +-
 include/media/media-entity.h                    | 4 ++--
 7 files changed, 9 insertions(+), 9 deletions(-)

Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Prabhakar Lad <prabhakar.csengg@gmail.com>

diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index feb521f28e14..9a377d9dd58a 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1130,7 +1130,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable,
 	media_entity_graph_walk_start(graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(graph))) {
-		if (!is_media_entity_v4l2_io(entity))
+		if (!is_media_entity_v4l2_video_device(entity))
 			continue;
 
 		ret  = __fimc_md_modify_pipeline(entity, enable);
@@ -1145,7 +1145,7 @@ err:
 	media_entity_graph_walk_start(graph, entity_err);
 
 	while ((entity_err = media_entity_graph_walk_next(graph))) {
-		if (!is_media_entity_v4l2_io(entity_err))
+		if (!is_media_entity_v4l2_video_device(entity_err))
 			continue;
 
 		__fimc_md_modify_pipeline(entity_err, !enable);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index f9e5245f26ac..12f07e409f0b 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity,
 	media_entity_graph_walk_start(graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(graph))) {
-		if (is_media_entity_v4l2_io(entity))
+		if (is_media_entity_v4l2_video_device(entity))
 			use += entity->use_count;
 	}
 
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 2aff755ff77c..c4734a5b8886 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -249,7 +249,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 		if (entity == &video->video.entity)
 			continue;
 
-		if (!is_media_entity_v4l2_io(entity))
+		if (!is_media_entity_v4l2_video_device(entity))
 			continue;
 
 		__video = to_isp_video(media_entity_to_video_device(entity));
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index db49af90217e..7d8fa34f31f3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -154,7 +154,7 @@ static int vpfe_prepare_pipeline(struct vpfe_video_device *video)
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		if (entity == &video->video_dev.entity)
 			continue;
-		if (!is_media_entity_v4l2_io(entity))
+		if (!is_media_entity_v4l2_video_device(entity))
 			continue;
 		far_end = to_vpfe_video(media_entity_to_video_device(entity));
 		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 30b473cfb020..d41231521775 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity,
 	media_entity_graph_walk_start(graph, entity);
 
 	while ((entity = media_entity_graph_walk_next(graph))) {
-		if (is_media_entity_v4l2_io(entity))
+		if (is_media_entity_v4l2_video_device(entity))
 			use += entity->use_count;
 	}
 
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 058233a9de67..002d81d4ee45 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -221,7 +221,7 @@ iss_video_far_end(struct iss_video *video)
 		if (entity == &video->video.entity)
 			continue;
 
-		if (!is_media_entity_v4l2_io(entity))
+		if (!is_media_entity_v4l2_video_device(entity))
 			continue;
 
 		far_end = to_iss_video(media_entity_to_video_device(entity));
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index cbd37530f6b8..e5108f052fe2 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -356,14 +356,14 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id)
 }
 
 /**
- * is_media_entity_v4l2_io() - Check if the entity is a video_device
+ * is_media_entity_v4l2_video_device() - Check if the entity is a video_device
  * @entity:	pointer to entity
  *
  * Return: true if the entity is an instance of a video_device object and can
  * safely be cast to a struct video_device using the container_of() macro, or
  * false otherwise.
  */
-static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+static inline bool is_media_entity_v4l2_video_device(struct media_entity *entity)
 {
 	return entity && entity->type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
 }
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/8] v4l2: add device_caps to struct video_device
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
                   ` (3 preceding siblings ...)
  2016-03-01 14:57 ` [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 6/8] v4l2-pci-skeleton.c: fill in device_caps in video_device Laurent Pinchart
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab

From: Hans Verkuil <hans.verkuil@cisco.com>

Instead of letting drivers fill in device_caps at querycap time,
let them fill it in when the video device is registered.

This has the advantage that in the future the v4l2 core can access
the video device's capabilities and take decisions based on that.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 3 +++
 include/media/v4l2-dev.h             | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 86c4c19b5d7b..706bb4251462 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1020,9 +1020,12 @@ static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
 				struct file *file, void *fh, void *arg)
 {
 	struct v4l2_capability *cap = (struct v4l2_capability *)arg;
+	struct video_device *vfd = video_devdata(file);
 	int ret;
 
 	cap->version = LINUX_VERSION_CODE;
+	cap->device_caps = vfd->device_caps;
+	cap->capabilities = vfd->device_caps | V4L2_CAP_DEVICE_CAPS;
 
 	ret = ops->vidioc_querycap(file, fh, cap);
 
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 76056ab5c5bd..25a3190308fb 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -92,6 +92,9 @@ struct video_device
 	/* device ops */
 	const struct v4l2_file_operations *fops;
 
+	/* device capabilities as used in v4l2_capabilities */
+	u32 device_caps;
+
 	/* sysfs */
 	struct device dev;		/* v4l device */
 	struct cdev *cdev;		/* character device */
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 6/8] v4l2-pci-skeleton.c: fill in device_caps in video_device
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
                   ` (4 preceding siblings ...)
  2016-03-01 14:57 ` [PATCH 5/8] v4l2: add device_caps to struct video_device Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 7/8] vivid: set " Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 8/8] media-entity.h: Add is_media_entity_v4l2_io() Laurent Pinchart
  7 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab

From: Hans Verkuil <hans.verkuil@cisco.com>

With the new core support for the caps the driver no longer needs
to set device_caps and capabilities in the querycap call.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 Documentation/video4linux/v4l2-pci-skeleton.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/Documentation/video4linux/v4l2-pci-skeleton.c b/Documentation/video4linux/v4l2-pci-skeleton.c
index 79af0c041056..a55cf94ac907 100644
--- a/Documentation/video4linux/v4l2-pci-skeleton.c
+++ b/Documentation/video4linux/v4l2-pci-skeleton.c
@@ -308,9 +308,6 @@ static int skeleton_querycap(struct file *file, void *priv,
 	strlcpy(cap->card, "V4L2 PCI Skeleton", sizeof(cap->card));
 	snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
 		 pci_name(skel->pdev));
-	cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
-			   V4L2_CAP_STREAMING;
-	cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
 	return 0;
 }
 
@@ -872,6 +869,8 @@ static int skeleton_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	vdev->release = video_device_release_empty;
 	vdev->fops = &skel_fops,
 	vdev->ioctl_ops = &skel_ioctl_ops,
+	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
+			    V4L2_CAP_STREAMING;
 	/*
 	 * The main serialization lock. All ioctls are serialized by this
 	 * lock. Exception: if q->lock is set, then the streaming ioctls
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 7/8] vivid: set device_caps in video_device.
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
                   ` (5 preceding siblings ...)
  2016-03-01 14:57 ` [PATCH 6/8] v4l2-pci-skeleton.c: fill in device_caps in video_device Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  2016-03-01 14:57 ` [PATCH 8/8] media-entity.h: Add is_media_entity_v4l2_io() Laurent Pinchart
  7 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab

From: Hans Verkuil <hans.verkuil@cisco.com>

This simplifies the querycap function.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/platform/vivid/vivid-core.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c
index ec125becb7af..c14da84af09b 100644
--- a/drivers/media/platform/vivid/vivid-core.c
+++ b/drivers/media/platform/vivid/vivid-core.c
@@ -200,27 +200,12 @@ static int vidioc_querycap(struct file *file, void  *priv,
 					struct v4l2_capability *cap)
 {
 	struct vivid_dev *dev = video_drvdata(file);
-	struct video_device *vdev = video_devdata(file);
 
 	strcpy(cap->driver, "vivid");
 	strcpy(cap->card, "vivid");
 	snprintf(cap->bus_info, sizeof(cap->bus_info),
 			"platform:%s", dev->v4l2_dev.name);
 
-	if (vdev->vfl_type == VFL_TYPE_GRABBER && vdev->vfl_dir == VFL_DIR_RX)
-		cap->device_caps = dev->vid_cap_caps;
-	if (vdev->vfl_type == VFL_TYPE_GRABBER && vdev->vfl_dir == VFL_DIR_TX)
-		cap->device_caps = dev->vid_out_caps;
-	else if (vdev->vfl_type == VFL_TYPE_VBI && vdev->vfl_dir == VFL_DIR_RX)
-		cap->device_caps = dev->vbi_cap_caps;
-	else if (vdev->vfl_type == VFL_TYPE_VBI && vdev->vfl_dir == VFL_DIR_TX)
-		cap->device_caps = dev->vbi_out_caps;
-	else if (vdev->vfl_type == VFL_TYPE_SDR)
-		cap->device_caps = dev->sdr_cap_caps;
-	else if (vdev->vfl_type == VFL_TYPE_RADIO && vdev->vfl_dir == VFL_DIR_RX)
-		cap->device_caps = dev->radio_rx_caps;
-	else if (vdev->vfl_type == VFL_TYPE_RADIO && vdev->vfl_dir == VFL_DIR_TX)
-		cap->device_caps = dev->radio_tx_caps;
 	cap->capabilities = dev->vid_cap_caps | dev->vid_out_caps |
 		dev->vbi_cap_caps | dev->vbi_out_caps |
 		dev->radio_rx_caps | dev->radio_tx_caps |
@@ -1135,6 +1120,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		strlcpy(vfd->name, "vivid-vid-cap", sizeof(vfd->name));
 		vfd->fops = &vivid_fops;
 		vfd->ioctl_ops = &vivid_ioctl_ops;
+		vfd->device_caps = dev->vid_cap_caps;
 		vfd->release = video_device_release_empty;
 		vfd->v4l2_dev = &dev->v4l2_dev;
 		vfd->queue = &dev->vb_vid_cap_q;
@@ -1160,6 +1146,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		vfd->vfl_dir = VFL_DIR_TX;
 		vfd->fops = &vivid_fops;
 		vfd->ioctl_ops = &vivid_ioctl_ops;
+		vfd->device_caps = dev->vid_out_caps;
 		vfd->release = video_device_release_empty;
 		vfd->v4l2_dev = &dev->v4l2_dev;
 		vfd->queue = &dev->vb_vid_out_q;
@@ -1184,6 +1171,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		strlcpy(vfd->name, "vivid-vbi-cap", sizeof(vfd->name));
 		vfd->fops = &vivid_fops;
 		vfd->ioctl_ops = &vivid_ioctl_ops;
+		vfd->device_caps = dev->vbi_cap_caps;
 		vfd->release = video_device_release_empty;
 		vfd->v4l2_dev = &dev->v4l2_dev;
 		vfd->queue = &dev->vb_vbi_cap_q;
@@ -1207,6 +1195,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		vfd->vfl_dir = VFL_DIR_TX;
 		vfd->fops = &vivid_fops;
 		vfd->ioctl_ops = &vivid_ioctl_ops;
+		vfd->device_caps = dev->vbi_out_caps;
 		vfd->release = video_device_release_empty;
 		vfd->v4l2_dev = &dev->v4l2_dev;
 		vfd->queue = &dev->vb_vbi_out_q;
@@ -1229,6 +1218,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		strlcpy(vfd->name, "vivid-sdr-cap", sizeof(vfd->name));
 		vfd->fops = &vivid_fops;
 		vfd->ioctl_ops = &vivid_ioctl_ops;
+		vfd->device_caps = dev->sdr_cap_caps;
 		vfd->release = video_device_release_empty;
 		vfd->v4l2_dev = &dev->v4l2_dev;
 		vfd->queue = &dev->vb_sdr_cap_q;
@@ -1247,6 +1237,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		strlcpy(vfd->name, "vivid-rad-rx", sizeof(vfd->name));
 		vfd->fops = &vivid_radio_fops;
 		vfd->ioctl_ops = &vivid_ioctl_ops;
+		vfd->device_caps = dev->radio_rx_caps;
 		vfd->release = video_device_release_empty;
 		vfd->v4l2_dev = &dev->v4l2_dev;
 		vfd->lock = &dev->mutex;
@@ -1265,6 +1256,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
 		vfd->vfl_dir = VFL_DIR_TX;
 		vfd->fops = &vivid_radio_fops;
 		vfd->ioctl_ops = &vivid_ioctl_ops;
+		vfd->device_caps = dev->radio_tx_caps;
 		vfd->release = video_device_release_empty;
 		vfd->v4l2_dev = &dev->v4l2_dev;
 		vfd->lock = &dev->mutex;
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 8/8] media-entity.h: Add is_media_entity_v4l2_io()
  2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
                   ` (6 preceding siblings ...)
  2016-03-01 14:57 ` [PATCH 7/8] vivid: set " Laurent Pinchart
@ 2016-03-01 14:57 ` Laurent Pinchart
  7 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-01 14:57 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab

From: Hans Verkuil <hans.verkuil@cisco.com>

Add a is_media_entity_v4l2_io to v4l2-common.h (since this is V4L2
specific) that checks if the entity is a video_device AND if it does
I/O.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-common.c | 21 +++++++++++++++++++++
 include/media/v4l2-common.h           | 12 ++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 5b808500e7e7..3c57d51d3e90 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -405,3 +405,24 @@ void v4l2_get_timestamp(struct timeval *tv)
 	tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
 }
 EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
+
+#if defined(CONFIG_MEDIA_CONTROLLER)
+bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	struct video_device *vdev;
+
+	if (!is_media_entity_v4l2_video_device(entity))
+		return false;
+	vdev = container_of(entity, struct video_device, entity);
+	/*
+	 * For now assume that is device_caps == 0, then I/O is available
+	 * unless it is a radio device.
+	 * Eventually all drivers should set vdev->device_caps and then
+	 * this assumption should be removed.
+	 */
+	if (vdev->device_caps == 0)
+		return vdev->vfl_type != VFL_TYPE_RADIO;
+	return vdev->device_caps & (V4L2_CAP_READWRITE | V4L2_CAP_STREAMING);
+}
+EXPORT_SYMBOL_GPL(is_media_entity_v4l2_io);
+#endif
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 1cc0c5ba16b3..6dae30493276 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -189,4 +189,16 @@ const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
 
 void v4l2_get_timestamp(struct timeval *tv);
 
+#ifdef CONFIG_MEDIA_CONTROLLER
+/**
+ * is_media_entity_v4l2_io() - Check if the entity is an I/O video_device
+ * @entity:	pointer to entity
+ *
+ * Return: true if the entity is an instance of a video_device object (and can
+ * safely be cast to a struct video_device using the container_of() macro) and
+ * can do I/O, or false otherwise.
+ */
+bool is_media_entity_v4l2_io(struct media_entity *entity);
+#endif
+
 #endif /* V4L2_COMMON_H_ */
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/8] media: Add type field to struct media_entity
  2016-03-01 14:57 ` [PATCH 3/8] media: Add type field to struct media_entity Laurent Pinchart
@ 2016-03-03 13:32   ` Hans Verkuil
  0 siblings, 0 replies; 13+ messages in thread
From: Hans Verkuil @ 2016-03-03 13:32 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media; +Cc: Sakari Ailus, Mauro Carvalho Chehab

On 03/01/16 15:57, Laurent Pinchart wrote:
> Code that processes media entities can require knowledge of the
> structure type that embeds a particular media entity instance in order
> to cast the entity to the proper object type. This needs is shown by the
> presence of the is_media_entity_v4l2_io and is_media_entity_v4l2_subdev
> functions.
> 
> The implementation of those two functions relies on the entity function
> field, which is both a wrong and an inefficient design, without even
> mentioning the maintenance issue involved in updating the functions
> every time a new entity function is added. Fix this by adding add a type
> field to the media entity structure to carry the information.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Thanks!

	Hans

> ---
>  drivers/media/v4l2-core/v4l2-dev.c    |  1 +
>  drivers/media/v4l2-core/v4l2-subdev.c |  1 +
>  include/media/media-entity.h          | 75 ++++++++++++++++++-----------------
>  3 files changed, 40 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
> index d8e5994cccf1..7e766a92e3d9 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -735,6 +735,7 @@ static int video_register_media_controller(struct video_device *vdev, int type)
>  	if (!vdev->v4l2_dev->mdev)
>  		return 0;
>  
> +	vdev->entity.type = MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
>  	vdev->entity.function = MEDIA_ENT_F_UNKNOWN;
>  
>  	switch (type) {
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index d63083803144..bb6e79f14bb8 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -584,6 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
>  	sd->host_priv = NULL;
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>  	sd->entity.name = sd->name;
> +	sd->entity.type = MEDIA_ENTITY_TYPE_V4L2_SUBDEV;
>  	sd->entity.function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
>  #endif
>  }
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index d58e29d3f239..cbd37530f6b8 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -187,10 +187,37 @@ struct media_entity_operations {
>  };
>  
>  /**
> + * enum media_entity_type - Media entity type
> + *
> + * @MEDIA_ENTITY_TYPE_MEDIA_ENTITY:
> + *	The entity is a struct media_entity instance.
> + * @MEDIA_ENTITY_TYPE_VIDEO_DEVICE:
> + *	The entity is a struct video_device instance.
> + * @MEDIA_ENTITY_TYPE_V4L2_SUBDEV:
> + *	The entity is a struct v4l2_subdev instance.
> + *
> + * The entity type identifies the type of the object instance that implements
> + * the struct media_entity instance. This allows runtime type identification of
> + * media entities and safe casting to the project object type. For instance, a
> + * media entity structure instance embedded in a v4l2_subdev structure instance
> + * will have the type MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a
> + * v4l2_subdev structure using the container_of() macro.
> + *
> + * Media entities can be instantiated without creating any derived object type,
> + * in which case their type will be MEDIA_ENTITY_TYPE_MEDIA_ENTITY.
> + */
> +enum media_entity_type {
> +	MEDIA_ENTITY_TYPE_MEDIA_ENTITY,
> +	MEDIA_ENTITY_TYPE_VIDEO_DEVICE,
> +	MEDIA_ENTITY_TYPE_V4L2_SUBDEV,
> +};
> +
> +/**
>   * struct media_entity - A media entity graph object.
>   *
>   * @graph_obj:	Embedded structure containing the media object common data.
>   * @name:	Entity name.
> + * @type:	Type of the object that implements the media_entity.
>   * @function:	Entity main function, as defined in uapi/media.h
>   *		(MEDIA_ENT_F_*)
>   * @flags:	Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*)
> @@ -219,6 +246,7 @@ struct media_entity_operations {
>  struct media_entity {
>  	struct media_gobj graph_obj;	/* must be first field in struct */
>  	const char *name;
> +	enum media_entity_type type;
>  	u32 function;
>  	unsigned long flags;
>  
> @@ -328,56 +356,29 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id)
>  }
>  
>  /**
> - * is_media_entity_v4l2_io() - identify if the entity main function
> - *			       is a V4L2 I/O
> - *
> + * is_media_entity_v4l2_io() - Check if the entity is a video_device
>   * @entity:	pointer to entity
>   *
> - * Return: true if the entity main function is one of the V4L2 I/O types
> - *	(video, VBI or SDR radio); false otherwise.
> + * Return: true if the entity is an instance of a video_device object and can
> + * safely be cast to a struct video_device using the container_of() macro, or
> + * false otherwise.
>   */
>  static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
>  {
> -	if (!entity)
> -		return false;
> -
> -	switch (entity->function) {
> -	case MEDIA_ENT_F_IO_V4L:
> -	case MEDIA_ENT_F_IO_VBI:
> -	case MEDIA_ENT_F_IO_SWRADIO:
> -		return true;
> -	default:
> -		return false;
> -	}
> +	return entity && entity->type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
>  }
>  
>  /**
> - * is_media_entity_v4l2_subdev - return true if the entity main function is
> - *				 associated with the V4L2 API subdev usage
> - *
> + * is_media_entity_v4l2_subdev() - Check if the entity is a v4l2_subdev
>   * @entity:	pointer to entity
>   *
> - * This is an ancillary function used by subdev-based V4L2 drivers.
> - * It checks if the entity function is one of functions used by a V4L2 subdev,
> - * e. g. camera-relatef functions, analog TV decoder, TV tuner, V4L2 DSPs.
> + * Return: true if the entity is an instance of a v4l2_subdev object and can
> + * safely be cast to a struct v4l2_subdev using the container_of() macro, or
> + * false otherwise.
>   */
>  static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
>  {
> -	if (!entity)
> -		return false;
> -
> -	switch (entity->function) {
> -	case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
> -	case MEDIA_ENT_F_CAM_SENSOR:
> -	case MEDIA_ENT_F_FLASH:
> -	case MEDIA_ENT_F_LENS:
> -	case MEDIA_ENT_F_ATV_DECODER:
> -	case MEDIA_ENT_F_TUNER:
> -		return true;
> -
> -	default:
> -		return false;
> -	}
> +	return entity && entity->type == MEDIA_ENTITY_TYPE_V4L2_SUBDEV;
>  }
>  
>  /**
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device
  2016-03-01 14:57 ` [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device Laurent Pinchart
@ 2016-03-03 13:33   ` Hans Verkuil
  2016-03-04 20:05     ` Laurent Pinchart
  2016-03-07 10:23   ` Lad, Prabhakar
  1 sibling, 1 reply; 13+ messages in thread
From: Hans Verkuil @ 2016-03-03 13:33 UTC (permalink / raw)
  To: Laurent Pinchart, linux-media
  Cc: Sakari Ailus, Mauro Carvalho Chehab, Kyungmin Park,
	Sylwester Nawrocki, Prabhakar Lad

On 03/01/16 15:57, Laurent Pinchart wrote:
> All users of is_media_entity_v4l2_io() (the exynos4-is, omap3isp,
> davince_vpfe and omap4iss drivers) use the function to check whether
> entities are video_device instances, either to ensure they can cast the
> entity to a struct video_device, or to count the number of video nodes
> users.
> 
> The purpose of the function is thus to identify whether the media entity
> instance is an instance of the video_device object, not to check whether
> it can perform I/O. Rename it accordingly, we will introduce a more
> specific is_media_entity_v4l2_io() check when needed.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Thanks for the much clearer commit text, that makes it much more understandable
what is going on here.

	Hans

> ---
>  drivers/media/platform/exynos4-is/media-dev.c   | 4 ++--
>  drivers/media/platform/omap3isp/isp.c           | 2 +-
>  drivers/media/platform/omap3isp/ispvideo.c      | 2 +-
>  drivers/staging/media/davinci_vpfe/vpfe_video.c | 2 +-
>  drivers/staging/media/omap4iss/iss.c            | 2 +-
>  drivers/staging/media/omap4iss/iss_video.c      | 2 +-
>  include/media/media-entity.h                    | 4 ++--
>  7 files changed, 9 insertions(+), 9 deletions(-)
> 
> Cc: Kyungmin Park <kyungmin.park@samsung.com>
> Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Cc: Prabhakar Lad <prabhakar.csengg@gmail.com>
> 
> diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
> index feb521f28e14..9a377d9dd58a 100644
> --- a/drivers/media/platform/exynos4-is/media-dev.c
> +++ b/drivers/media/platform/exynos4-is/media-dev.c
> @@ -1130,7 +1130,7 @@ static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable,
>  	media_entity_graph_walk_start(graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(graph))) {
> -		if (!is_media_entity_v4l2_io(entity))
> +		if (!is_media_entity_v4l2_video_device(entity))
>  			continue;
>  
>  		ret  = __fimc_md_modify_pipeline(entity, enable);
> @@ -1145,7 +1145,7 @@ err:
>  	media_entity_graph_walk_start(graph, entity_err);
>  
>  	while ((entity_err = media_entity_graph_walk_next(graph))) {
> -		if (!is_media_entity_v4l2_io(entity_err))
> +		if (!is_media_entity_v4l2_video_device(entity_err))
>  			continue;
>  
>  		__fimc_md_modify_pipeline(entity_err, !enable);
> diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
> index f9e5245f26ac..12f07e409f0b 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -691,7 +691,7 @@ static int isp_pipeline_pm_use_count(struct media_entity *entity,
>  	media_entity_graph_walk_start(graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(graph))) {
> -		if (is_media_entity_v4l2_io(entity))
> +		if (is_media_entity_v4l2_video_device(entity))
>  			use += entity->use_count;
>  	}
>  
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
> index 2aff755ff77c..c4734a5b8886 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -249,7 +249,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (!is_media_entity_v4l2_io(entity))
> +		if (!is_media_entity_v4l2_video_device(entity))
>  			continue;
>  
>  		__video = to_isp_video(media_entity_to_video_device(entity));
> diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> index db49af90217e..7d8fa34f31f3 100644
> --- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
> +++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
> @@ -154,7 +154,7 @@ static int vpfe_prepare_pipeline(struct vpfe_video_device *video)
>  	while ((entity = media_entity_graph_walk_next(&graph))) {
>  		if (entity == &video->video_dev.entity)
>  			continue;
> -		if (!is_media_entity_v4l2_io(entity))
> +		if (!is_media_entity_v4l2_video_device(entity))
>  			continue;
>  		far_end = to_vpfe_video(media_entity_to_video_device(entity));
>  		if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
> diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
> index 30b473cfb020..d41231521775 100644
> --- a/drivers/staging/media/omap4iss/iss.c
> +++ b/drivers/staging/media/omap4iss/iss.c
> @@ -397,7 +397,7 @@ static int iss_pipeline_pm_use_count(struct media_entity *entity,
>  	media_entity_graph_walk_start(graph, entity);
>  
>  	while ((entity = media_entity_graph_walk_next(graph))) {
> -		if (is_media_entity_v4l2_io(entity))
> +		if (is_media_entity_v4l2_video_device(entity))
>  			use += entity->use_count;
>  	}
>  
> diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
> index 058233a9de67..002d81d4ee45 100644
> --- a/drivers/staging/media/omap4iss/iss_video.c
> +++ b/drivers/staging/media/omap4iss/iss_video.c
> @@ -221,7 +221,7 @@ iss_video_far_end(struct iss_video *video)
>  		if (entity == &video->video.entity)
>  			continue;
>  
> -		if (!is_media_entity_v4l2_io(entity))
> +		if (!is_media_entity_v4l2_video_device(entity))
>  			continue;
>  
>  		far_end = to_iss_video(media_entity_to_video_device(entity));
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index cbd37530f6b8..e5108f052fe2 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -356,14 +356,14 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id)
>  }
>  
>  /**
> - * is_media_entity_v4l2_io() - Check if the entity is a video_device
> + * is_media_entity_v4l2_video_device() - Check if the entity is a video_device
>   * @entity:	pointer to entity
>   *
>   * Return: true if the entity is an instance of a video_device object and can
>   * safely be cast to a struct video_device using the container_of() macro, or
>   * false otherwise.
>   */
> -static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
> +static inline bool is_media_entity_v4l2_video_device(struct media_entity *entity)
>  {
>  	return entity && entity->type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
>  }
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device
  2016-03-03 13:33   ` Hans Verkuil
@ 2016-03-04 20:05     ` Laurent Pinchart
  0 siblings, 0 replies; 13+ messages in thread
From: Laurent Pinchart @ 2016-03-04 20:05 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Laurent Pinchart, linux-media, Sakari Ailus,
	Mauro Carvalho Chehab, Kyungmin Park, Sylwester Nawrocki,
	Prabhakar Lad

Hi Hans,

On Thursday 03 March 2016 14:33:19 Hans Verkuil wrote:
> On 03/01/16 15:57, Laurent Pinchart wrote:
> > All users of is_media_entity_v4l2_io() (the exynos4-is, omap3isp,
> > davince_vpfe and omap4iss drivers) use the function to check whether
> > entities are video_device instances, either to ensure they can cast the
> > entity to a struct video_device, or to count the number of video nodes
> > users.
> > 
> > The purpose of the function is thus to identify whether the media entity
> > instance is an instance of the video_device object, not to check whether
> > it can perform I/O. Rename it accordingly, we will introduce a more
> > specific is_media_entity_v4l2_io() check when needed.
> > 
> > Signed-off-by: Laurent Pinchart
> > <laurent.pinchart+renesas@ideasonboard.com>
> 
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Thanks for the much clearer commit text, that makes it much more
> understandable what is going on here.

You're welcome, my pleasure.

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device
  2016-03-01 14:57 ` [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device Laurent Pinchart
  2016-03-03 13:33   ` Hans Verkuil
@ 2016-03-07 10:23   ` Lad, Prabhakar
  1 sibling, 0 replies; 13+ messages in thread
From: Lad, Prabhakar @ 2016-03-07 10:23 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Sakari Ailus, Hans Verkuil, Mauro Carvalho Chehab,
	Kyungmin Park, Sylwester Nawrocki

Hi Laurent,

Thanks for the patch.

On Tue, Mar 1, 2016 at 2:57 PM, Laurent Pinchart
<laurent.pinchart+renesas@ideasonboard.com> wrote:
> All users of is_media_entity_v4l2_io() (the exynos4-is, omap3isp,
> davince_vpfe and omap4iss drivers) use the function to check whether
> entities are video_device instances, either to ensure they can cast the
> entity to a struct video_device, or to count the number of video nodes
> users.
>
> The purpose of the function is thus to identify whether the media entity
> instance is an instance of the video_device object, not to check whether
> it can perform I/O. Rename it accordingly, we will introduce a more
> specific is_media_entity_v4l2_io() check when needed.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>

Cheers,
--Prabhakar Lad

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2016-03-07 10:24 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01 14:57 [PATCH v3 0/8] media: Add entity types Laurent Pinchart
2016-03-01 14:57 ` [PATCH 1/8] v4l: vsp1: Check if an entity is a subdev with the right function Laurent Pinchart
2016-03-01 14:57 ` [PATCH 2/8] v4l: exynos4-is: Drop unneeded check when setting up fimc-lite links Laurent Pinchart
2016-03-01 14:57 ` [PATCH 3/8] media: Add type field to struct media_entity Laurent Pinchart
2016-03-03 13:32   ` Hans Verkuil
2016-03-01 14:57 ` [PATCH 4/8] media: Rename is_media_entity_v4l2_io to is_media_entity_v4l2_video_device Laurent Pinchart
2016-03-03 13:33   ` Hans Verkuil
2016-03-04 20:05     ` Laurent Pinchart
2016-03-07 10:23   ` Lad, Prabhakar
2016-03-01 14:57 ` [PATCH 5/8] v4l2: add device_caps to struct video_device Laurent Pinchart
2016-03-01 14:57 ` [PATCH 6/8] v4l2-pci-skeleton.c: fill in device_caps in video_device Laurent Pinchart
2016-03-01 14:57 ` [PATCH 7/8] vivid: set " Laurent Pinchart
2016-03-01 14:57 ` [PATCH 8/8] media-entity.h: Add is_media_entity_v4l2_io() Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox