Skip to contentSkip to conversation

MC next gen: add sub-device interfaces

PATCH In review Mauro Carvalho Chehab 2 participants 5 messages Aug 24, 2015 – Aug 28, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover MC next gen: add sub-device interfaces

This patch depends on my MC next gen previous series. It creates interfaces for V4L2-subdev when the corresponding device nodes are created.

Mauro Carvalho Chehab (2):
[media] media-entity: unregister entity links
[media] v4l2-subdev: create interfaces at MC

 drivers/media/media-entity.c          | 23 +++++++++++++++++++++++
 drivers/media/v4l2-core/v4l2-device.c | 15 +++++++++++++++
 include/media/media-entity.h          |  3 +++
 include/media/v4l2-subdev.h           |  1 +
 4 files changed, 42 insertions(+)
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/2 media-entity: unregister entity links

Add functions to explicitly unregister all entity links. This function is called automatically when an entity link is destroyed.

drivers/media/media-entity.c +23 -0
index fc6bb48027ab..7e6fb5a86b21 100644
@@ -896,6 +896,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+	media_remove_intf_links(&devnode->intf);
 	media_gobj_remove(&devnode->intf.graph_obj);
 	kfree(devnode);
 }
@@ -937,3 +938,25 @@ void media_remove_intf_link(struct media_link *link)
 	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &intf->links, list)
+		media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);
+
+void media_remove_intf_links(struct media_interface *intf)
+{
+	/* Do nothing if the intf is not registered. */
+	if (intf->graph_obj.mdev == NULL)
+		return;
+
+	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_links(intf);
+	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);
include/media/media-entity.h +3 -0
index d89ceaf7bcc4..8c26934c97fe 100644
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct media_entity *entity,
 					    struct media_interface *intf,
 					    u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
Signature · 1 line
2.4.3
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] [media] media-entity: unregister entity links

Quoted 5 lines · Mauro Carvalho Chehab

Add functions to explicitly unregister all entity links. This function is called automatically when an entity link is destroyed.

Quoted 54 lines
drivers/media/media-entity.c +23 -0
index fc6bb48027ab..7e6fb5a86b21 100644
@@ -896,6 +896,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+	media_remove_intf_links(&devnode->intf);
 	media_gobj_remove(&devnode->intf.graph_obj);
 	kfree(devnode);
 }
@@ -937,3 +938,25 @@ void media_remove_intf_link(struct media_link *link)
 	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &intf->links, list)
+		media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);
+
+void media_remove_intf_links(struct media_interface *intf)
+{
+	/* Do nothing if the intf is not registered. */
+	if (intf->graph_obj.mdev == NULL)
+		return;
+
+	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_links(intf);
+	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);
include/media/media-entity.h +3 -0
index d89ceaf7bcc4..8c26934c97fe 100644
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct media_entity *entity,
 					    struct media_interface *intf,
 					    u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
#3 lore raw

PATCH 2/2 v4l2-subdev: create interfaces at MC

In reply to Mauro Carvalho Chehab

Now that the Media Controller has support for interfaces, create them when v4l-subdev interfaces are created.

drivers/media/v4l2-core/v4l2-device.c +15 -0
index 5b0a30b9252b..1e5176c558bf 100644
@@ -247,8 +247,22 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
 			goto clean_up;
 		}
 #if defined(CONFIG_MEDIA_CONTROLLER)
+		/* Needed just for backward compatibility with legacy MC API */
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+
+		sd->intf_devnode = media_devnode_create(sd->entity.graph_obj.mdev,
+							MEDIA_INTF_T_V4L_SUBDEV,
+							0, VIDEO_MAJOR,
+							vdev->minor,
+							GFP_KERNEL);
+		if (!sd->intf_devnode) {
+			err = -ENOMEM;
+			kfree(vdev);
+			goto clean_up;
+		}
+
+		media_create_intf_link(&sd->entity, &sd->intf_devnode->intf, 0);
 #endif
 		sd->devnode = vdev;
 	}
@@ -286,6 +300,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
 		media_entity_remove_links(&sd->entity);
+		media_devnode_remove(sd->intf_devnode);
 		media_device_unregister_entity(&sd->entity);
 	}
 #endif
include/media/v4l2-subdev.h +1 -0
index 370fc38c34f1..1aa44f11eeb5 100644
@@ -584,6 +584,7 @@ struct v4l2_subdev_platform_data {
 struct v4l2_subdev {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	struct list_head list;
 	struct module *owner;
Signature · 1 line
2.4.3
#4 lore raw

Re: [PATCH 2/2] [media] v4l2-subdev: create interfaces at MC

Quoted 17 lines · Mauro Carvalho Chehab

Now that the Media Controller has support for interfaces, create them when v4l-subdev interfaces are created.

drivers/media/v4l2-core/v4l2-device.c +2 -0
index 5b0a30b9252b..1e5176c558bf 100644
@@ -247,8 +247,22 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
 			goto clean_up;
 		}
 #if defined(CONFIG_MEDIA_CONTROLLER)
+		/* Needed just for backward compatibility with legacy MC API */
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+

drivers/media/v4l2-core/v4l2-device.c int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev) · line 263

Quoted 10 lines
drivers/media/v4l2-core/v4l2-device.c +10 -0
+		sd->intf_devnode = media_devnode_create(sd->entity.graph_obj.mdev,
+							MEDIA_INTF_T_V4L_SUBDEV,
+							0, VIDEO_MAJOR,
+							vdev->minor,
+							GFP_KERNEL);
+		if (!sd->intf_devnode) {
+			err = -ENOMEM;
+			kfree(vdev);
+			goto clean_up;
+		}

Why not let __video_register_device() create the interface? It needs to do that for all other device types as well. That would make much more sense rather than having subdevs as a weird exception.

drivers/media/v4l2-core/v4l2-device.c int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev) · line 265

Quoted 2 lines
drivers/media/v4l2-core/v4l2-device.c +2 -0
+
+		media_create_intf_link(&sd->entity, &sd->intf_devnode->intf, 0);

Linking the entity and interface together is the only thing that should happen here.

drivers/media/v4l2-core/v4l2-device.c void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) · line 303

Quoted 8 lines
drivers/media/v4l2-core/v4l2-device.c +1 -0
 #endif
 		sd->devnode = vdev;
 	}
@@ -286,6 +300,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
 		media_entity_remove_links(&sd->entity);
+		media_devnode_remove(sd->intf_devnode);

This can be removed as well in that case since it will be called from video_unregister_device().

Quoted 9 lines
drivers/media/v4l2-core/v4l2-device.c +0 -0
 		media_device_unregister_entity(&sd->entity);
 	}
 #endif
include/media/v4l2-subdev.h +0 -0
index 370fc38c34f1..1aa44f11eeb5 100644

include/media/v4l2-subdev.h struct v4l2_subdev_platform_data { · line 590

Quoted 7 lines
include/media/v4l2-subdev.h +1 -0
@@ -584,6 +584,7 @@ struct v4l2_subdev_platform_data {
 struct v4l2_subdev {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	struct list_head list;
 	struct module *owner;

Regards,

Hans