public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/10] Some cleanups after the Media Controller Next gen
@ 2015-12-11 13:34 Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 01/10] media-device: put headers in alphabetic order Mauro Carvalho Chehab
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

This series address the comments from Laurent to this patch:
	[PATCH v8.4 24/83] [media] media: convert links from array to list

Most of the patches here are trivial. The most relevant one is the patch
that updates the media framework documentation,  moving it from a
pure text file into the device-drivers.xml DocBook and updating the documentation
to reflect the MC next generation changes.

Mauro Carvalho Chehab (10):
  media-device: put headers in alphabetic order
  media-device: better name Kernelspace/Userspace links
  media framework: rename pads init function to media_entity_pads_init()
  media-entity.h: get rid of revision and group_id fields
  DocBook: Move media-framework.txt contend to media-device.h
  media-entity.h: convert media_entity_cleanup to inline
  media-device.h: Improve documentation and update it
  media-entity.c: remove two extra blank lines
  media-entity: get rid of forward __media_entity_remove_link()
    declaration
  media_entity: get rid of an unused var

 Documentation/DocBook/device-drivers.tmpl          |   1 +
 .../DocBook/media/v4l/media-ioc-enum-entities.xml  |  13 +-
 Documentation/media-framework.txt                  | 371 ---------------------
 Documentation/video4linux/v4l2-framework.txt       |   8 +-
 Documentation/zh_CN/video4linux/v4l2-framework.txt |   8 +-
 drivers/media/dvb-core/dvbdev.c                    |   4 +-
 drivers/media/dvb-frontends/au8522_decoder.c       |   2 +-
 drivers/media/i2c/ad9389b.c                        |   2 +-
 drivers/media/i2c/adp1653.c                        |   2 +-
 drivers/media/i2c/adv7180.c                        |   2 +-
 drivers/media/i2c/adv7511.c                        |   2 +-
 drivers/media/i2c/adv7604.c                        |   2 +-
 drivers/media/i2c/adv7842.c                        |   2 +-
 drivers/media/i2c/as3645a.c                        |   2 +-
 drivers/media/i2c/cx25840/cx25840-core.c           |   2 +-
 drivers/media/i2c/lm3560.c                         |   2 +-
 drivers/media/i2c/lm3646.c                         |   2 +-
 drivers/media/i2c/m5mols/m5mols_core.c             |   2 +-
 drivers/media/i2c/mt9m032.c                        |   2 +-
 drivers/media/i2c/mt9p031.c                        |   2 +-
 drivers/media/i2c/mt9t001.c                        |   2 +-
 drivers/media/i2c/mt9v032.c                        |   2 +-
 drivers/media/i2c/noon010pc30.c                    |   2 +-
 drivers/media/i2c/ov2659.c                         |   2 +-
 drivers/media/i2c/ov9650.c                         |   2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   4 +-
 drivers/media/i2c/s5k4ecgx.c                       |   2 +-
 drivers/media/i2c/s5k5baf.c                        |   4 +-
 drivers/media/i2c/s5k6a3.c                         |   2 +-
 drivers/media/i2c/s5k6aa.c                         |   2 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |   6 +-
 drivers/media/i2c/tc358743.c                       |   2 +-
 drivers/media/i2c/tvp514x.c                        |   2 +-
 drivers/media/i2c/tvp7002.c                        |   2 +-
 drivers/media/media-device.c                       |  35 +-
 drivers/media/media-entity.c                       |  84 ++---
 drivers/media/platform/exynos4-is/fimc-capture.c   |   4 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   2 +-
 drivers/media/platform/exynos4-is/fimc-isp.c       |   2 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |   4 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c       |   2 +-
 drivers/media/platform/exynos4-is/mipi-csis.c      |   2 +-
 drivers/media/platform/omap3isp/ispccdc.c          |   2 +-
 drivers/media/platform/omap3isp/ispccp2.c          |   2 +-
 drivers/media/platform/omap3isp/ispcsi2.c          |   2 +-
 drivers/media/platform/omap3isp/isppreview.c       |   2 +-
 drivers/media/platform/omap3isp/ispresizer.c       |   2 +-
 drivers/media/platform/omap3isp/ispstat.c          |   2 +-
 drivers/media/platform/omap3isp/ispvideo.c         |   2 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   4 +-
 drivers/media/platform/vsp1/vsp1_entity.c          |   2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |   2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |   2 +-
 drivers/media/platform/xilinx/xilinx-tpg.c         |   2 +-
 drivers/media/usb/au0828/au0828-video.c            |   6 +-
 drivers/media/usb/cx231xx/cx231xx-video.c          |   4 +-
 drivers/media/usb/uvc/uvc_entity.c                 |   4 +-
 drivers/media/v4l2-core/tuner-core.c               |   2 +-
 drivers/media/v4l2-core/v4l2-flash-led-class.c     |   2 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c   |   2 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |   2 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |   2 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |   6 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |   2 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |   2 +-
 drivers/staging/media/omap4iss/iss_ipipe.c         |   2 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |   2 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |   2 +-
 drivers/staging/media/omap4iss/iss_video.c         |   2 +-
 include/media/media-device.h                       | 331 ++++++++++++++++++
 include/media/media-entity.h                       | 157 ++++++++-
 71 files changed, 621 insertions(+), 539 deletions(-)
 delete mode 100644 Documentation/media-framework.txt

-- 
2.5.0



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

* [PATCH 01/10] media-device: put headers in alphabetic order
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 02/10] media-device: better name Kernelspace/Userspace links Mauro Carvalho Chehab
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

It is better to keep the headers in alphabetic order.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/media-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 3d0a77c1c899..61883abaf095 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -24,8 +24,8 @@
 #include <linux/export.h>
 #include <linux/ioctl.h>
 #include <linux/media.h>
-#include <linux/types.h>
 #include <linux/slab.h>
+#include <linux/types.h>
 
 #include <media/media-device.h>
 #include <media/media-devnode.h>
-- 
2.5.0



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

* [PATCH 02/10] media-device: better name Kernelspace/Userspace links
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 01/10] media-device: put headers in alphabetic order Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 03/10] media framework: rename pads init function to media_entity_pads_init() Mauro Carvalho Chehab
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

The __media_device_enum_links() copies links definitions from
Kernelspace to userspace. It has to work with 3 structs that
handle with links. Better name them to:
	link: Kernelspace internal link representation, of the
		type media_link;
	klink_desc:  struct media_link_desc pointer to the
		kernel memory where the data will be filled;
	ulink_desc:  struct media_link_desc pointer to the
		memory where the data will be copied to
		userspace.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/media-device.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 61883abaf095..14bd568e2f41 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -151,24 +151,25 @@ static long __media_device_enum_links(struct media_device *mdev,
 	}
 
 	if (links->links) {
-		struct media_link *ent_link;
-		struct media_link_desc __user *ulink = links->links;
+		struct media_link *link;
+		struct media_link_desc __user *ulink_desc = links->links;
 
-		list_for_each_entry(ent_link, &entity->links, list) {
-			struct media_link_desc link;
+		list_for_each_entry(link, &entity->links, list) {
+			struct media_link_desc klink_desc;
 
 			/* Ignore backlinks. */
-			if (ent_link->source->entity != entity)
+			if (link->source->entity != entity)
 				continue;
-			memset(&link, 0, sizeof(link));
-			media_device_kpad_to_upad(ent_link->source,
-						  &link.source);
-			media_device_kpad_to_upad(ent_link->sink,
-						  &link.sink);
-			link.flags = ent_link->flags;
-			if (copy_to_user(ulink, &link, sizeof(*ulink)))
+			memset(&klink_desc, 0, sizeof(klink_desc));
+			media_device_kpad_to_upad(link->source,
+						  &klink_desc.source);
+			media_device_kpad_to_upad(link->sink,
+						  &klink_desc.sink);
+			klink_desc.flags = link->flags;
+			if (copy_to_user(ulink_desc, &klink_desc,
+					 sizeof(*ulink_desc)))
 				return -EFAULT;
-			ulink++;
+			ulink_desc++;
 		}
 	}
 
-- 
2.5.0



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

* [PATCH 03/10] media framework: rename pads init function to media_entity_pads_init()
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 01/10] media-device: put headers in alphabetic order Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 02/10] media-device: better name Kernelspace/Userspace links Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 14:04   ` Jacek Anaszewski
  2015-12-11 13:34 ` [PATCH 04/10] media-entity.h: get rid of revision and group_id fields Mauro Carvalho Chehab
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab, Jonathan Corbet, Harry Wei, Hans Verkuil,
	Sakari Ailus, Lars-Peter Clausen, Laurent Pinchart, Kyungmin Park,
	Heungjun Kim, Lad, Prabhakar, Andrzej Hajda, Mats Randgaard,
	Sylwester Nawrocki, Kukjin Kim, Krzysztof Kozlowski, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Rafael Lourenço de Lima Chehab, Arnd Bergmann, Andrew Morton,
	Javier Martinez Canillas, Guennadi Liakhovetski,
	Ricardo Ribalda Delgado, Shuah Khan, Junghak Sung, Geunyoung Kim,
	Julia Lawall, Steven Rostedt, Bryan Wu, Jacek Anaszewski,
	Shraddha Barke, Aya Mahfouz, Junsu Shin, Haneen Mohammed,
	Navya Sri Nizamkari, Nicholas Mc Guire, Inki Dae, linux-doc,
	linux-kernel, linux-arm-kernel, linux-samsung-soc, linux-sh,
	devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=true, Size: 52121 bytes --]

With the MC next gen rework, what's left for media_entity_init()
is to just initialize the PADs. However, certain devices, like
a FLASH led/light doesn't have any input or output PAD.

So, there's no reason why calling media_entity_init() would be
mandatory. Also, despite its name, what this function actually
does is to initialize the PADs data. So, rename it to
media_entity_pads_init() in order to reflect that.

The media entity actual init happens during entity register,
at media_device_register_entity(). We should move init of
num_links and num_backlinks to it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 Documentation/media-framework.txt                  | 18 +++++++++++-------
 Documentation/video4linux/v4l2-framework.txt       |  8 ++++----
 Documentation/zh_CN/video4linux/v4l2-framework.txt |  8 ++++----
 drivers/media/dvb-core/dvbdev.c                    |  4 ++--
 drivers/media/dvb-frontends/au8522_decoder.c       |  2 +-
 drivers/media/i2c/ad9389b.c                        |  2 +-
 drivers/media/i2c/adp1653.c                        |  2 +-
 drivers/media/i2c/adv7180.c                        |  2 +-
 drivers/media/i2c/adv7511.c                        |  2 +-
 drivers/media/i2c/adv7604.c                        |  2 +-
 drivers/media/i2c/adv7842.c                        |  2 +-
 drivers/media/i2c/as3645a.c                        |  2 +-
 drivers/media/i2c/cx25840/cx25840-core.c           |  2 +-
 drivers/media/i2c/lm3560.c                         |  2 +-
 drivers/media/i2c/lm3646.c                         |  2 +-
 drivers/media/i2c/m5mols/m5mols_core.c             |  2 +-
 drivers/media/i2c/mt9m032.c                        |  2 +-
 drivers/media/i2c/mt9p031.c                        |  2 +-
 drivers/media/i2c/mt9t001.c                        |  2 +-
 drivers/media/i2c/mt9v032.c                        |  2 +-
 drivers/media/i2c/noon010pc30.c                    |  2 +-
 drivers/media/i2c/ov2659.c                         |  2 +-
 drivers/media/i2c/ov9650.c                         |  2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |  4 ++--
 drivers/media/i2c/s5k4ecgx.c                       |  2 +-
 drivers/media/i2c/s5k5baf.c                        |  4 ++--
 drivers/media/i2c/s5k6a3.c                         |  2 +-
 drivers/media/i2c/s5k6aa.c                         |  2 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |  6 +++---
 drivers/media/i2c/tc358743.c                       |  2 +-
 drivers/media/i2c/tvp514x.c                        |  2 +-
 drivers/media/i2c/tvp7002.c                        |  2 +-
 drivers/media/media-device.c                       |  2 ++
 drivers/media/media-entity.c                       | 11 ++++-------
 drivers/media/platform/exynos4-is/fimc-capture.c   |  4 ++--
 drivers/media/platform/exynos4-is/fimc-isp-video.c |  2 +-
 drivers/media/platform/exynos4-is/fimc-isp.c       |  2 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |  4 ++--
 drivers/media/platform/exynos4-is/fimc-m2m.c       |  2 +-
 drivers/media/platform/exynos4-is/mipi-csis.c      |  2 +-
 drivers/media/platform/omap3isp/ispccdc.c          |  2 +-
 drivers/media/platform/omap3isp/ispccp2.c          |  2 +-
 drivers/media/platform/omap3isp/ispcsi2.c          |  2 +-
 drivers/media/platform/omap3isp/isppreview.c       |  2 +-
 drivers/media/platform/omap3isp/ispresizer.c       |  2 +-
 drivers/media/platform/omap3isp/ispstat.c          |  2 +-
 drivers/media/platform/omap3isp/ispvideo.c         |  2 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |  4 ++--
 drivers/media/platform/vsp1/vsp1_entity.c          |  2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |  2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |  2 +-
 drivers/media/platform/xilinx/xilinx-tpg.c         |  2 +-
 drivers/media/usb/au0828/au0828-video.c            |  6 +++---
 drivers/media/usb/cx231xx/cx231xx-video.c          |  4 ++--
 drivers/media/usb/uvc/uvc_entity.c                 |  4 ++--
 drivers/media/v4l2-core/tuner-core.c               |  2 +-
 drivers/media/v4l2-core/v4l2-flash-led-class.c     |  2 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c   |  2 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |  2 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |  2 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |  6 +++---
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |  2 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |  2 +-
 drivers/staging/media/omap4iss/iss_ipipe.c         |  2 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |  2 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |  2 +-
 drivers/staging/media/omap4iss/iss_video.c         |  2 +-
 include/media/media-entity.h                       |  2 +-
 68 files changed, 102 insertions(+), 99 deletions(-)

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index b424de6c3bb3..7fbfe4bd1f47 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -101,14 +101,18 @@ include/media/media-entity.h. The structure is usually embedded into a
 higher-level structure, such as a v4l2_subdev or video_device instance,
 although drivers can allocate entities directly.
 
-Drivers initialize entities by calling
+Drivers initialize entity pads by calling
 
-	media_entity_init(struct media_entity *entity, u16 num_pads,
+	media_entity_pads_init(struct media_entity *entity, u16 num_pads,
 			  struct media_pad *pads);
 
-The media_entity name, type, flags, revision and group_id fields can be
-initialized before or after calling media_entity_init. Entities embedded in
-higher-level standard structures can have some of those fields set by the
+If no pads are needed, drivers could directly fill entity->num_pads
+with 0 and entity->pads with NULL or to call the above function that
+will do the same.
+
+The media_entity name, type, flags, revision and group_id fields should be
+initialized before calling media_device_register_entity(). Entities embedded
+in higher-level standard structures can have some of those fields set by the
 higher-level framework.
 
 As the number of pads is known in advance, the pads array is not allocated
@@ -116,10 +120,10 @@ dynamically but is managed by the entity driver. Most drivers will embed the
 pads array in a driver-specific structure, avoiding dynamic allocation.
 
 Drivers must set the direction of every pad in the pads array before calling
-media_entity_init. The function will initialize the other pads fields.
+media_entity_pads_init. The function will initialize the other pads fields.
 
 Unlike the number of pads, the total number of links isn't always known in
-advance by the entity driver. As an initial estimate, media_entity_init
+advance by the entity driver. As an initial estimate, media_entity_pads_init
 pre-allocates a number of links equal to the number of pads. The links array
 will be reallocated if it grows beyond the initial estimate.
 
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index 2e0fc28fa12f..fa41608ab2b4 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -295,12 +295,12 @@ module owner. This is done for you if you use the i2c helper functions.
 
 If integration with the media framework is needed, you must initialize the
 media_entity struct embedded in the v4l2_subdev struct (entity field) by
-calling media_entity_init():
+calling media_entity_pads_init(), if the entity has pads:
 
 	struct media_pad *pads = &my_sd->pads;
 	int err;
 
-	err = media_entity_init(&sd->entity, npads, pads);
+	err = media_entity_pads_init(&sd->entity, npads, pads);
 
 The pads array must have been previously initialized. There is no need to
 manually set the struct media_entity function and name fields, but the
@@ -695,12 +695,12 @@ difference is that the inode argument is omitted since it is never used.
 
 If integration with the media framework is needed, you must initialize the
 media_entity struct embedded in the video_device struct (entity field) by
-calling media_entity_init():
+calling media_entity_pads_init():
 
 	struct media_pad *pad = &my_vdev->pad;
 	int err;
 
-	err = media_entity_init(&vdev->entity, 1, pad);
+	err = media_entity_pads_init(&vdev->entity, 1, pad);
 
 The pads array must have been previously initialized. There is no need to
 manually set the struct media_entity type and name fields.
diff --git a/Documentation/zh_CN/video4linux/v4l2-framework.txt b/Documentation/zh_CN/video4linux/v4l2-framework.txt
index ff815cb92031..698660b7f21f 100644
--- a/Documentation/zh_CN/video4linux/v4l2-framework.txt
+++ b/Documentation/zh_CN/video4linux/v4l2-framework.txt
@@ -289,13 +289,13 @@ struct v4l2_subdev_ops {
 然后,你必须用一个唯一的名字初始化 subdev->name,并初始化模块的
 owner 域。若使用 i2c 辅助函数,这些都会帮你处理好。
 
-若需同媒体框架整合,你必须调用 media_entity_init() 初始化 v4l2_subdev
+若需同媒体框架整合,你必须调用 media_entity_pads_init() 初始化 v4l2_subdev
 结构体中的 media_entity 结构体(entity 域):
 
 	struct media_pad *pads = &my_sd->pads;
 	int err;
 
-	err = media_entity_init(&sd->entity, npads, pads);
+	err = media_entity_pads_init(&sd->entity, npads, pads);
 
 pads 数组必须预先初始化。无须手动设置 media_entity 的 type 和
 name 域,但如有必要,revision 域必须初始化。
@@ -596,13 +596,13 @@ void v4l2_disable_ioctl(struct video_device *vdev, unsigned int cmd);
 v4l2_file_operations 结构体是 file_operations 的一个子集。其主要
 区别在于:因 inode 参数从未被使用,它将被忽略。
 
-如果需要与媒体框架整合,你必须通过调用 media_entity_init() 初始化
+如果需要与媒体框架整合,你必须通过调用 media_entity_pads_init() 初始化
 嵌入在 video_device 结构体中的 media_entity(entity 域)结构体:
 
 	struct media_pad *pad = &my_vdev->pad;
 	int err;
 
-	err = media_entity_init(&vdev->entity, 1, pad);
+	err = media_entity_pads_init(&vdev->entity, 1, pad);
 
 pads 数组必须预先初始化。没有必要手动设置 media_entity 的 type 和
 name 域。
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 1d4e35693d09..b56e00817d3f 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -245,7 +245,7 @@ static int dvb_create_tsout_entity(struct dvb_device *dvbdev,
 		entity->function = MEDIA_ENT_F_IO_DTV;
 		pads->flags = MEDIA_PAD_FL_SINK;
 
-		ret = media_entity_init(entity, 1, pads);
+		ret = media_entity_pads_init(entity, 1, pads);
 		if (ret < 0)
 			return ret;
 
@@ -340,7 +340,7 @@ static int dvb_create_media_entity(struct dvb_device *dvbdev,
 	}
 
 	if (npads) {
-		ret = media_entity_init(dvbdev->entity, npads, dvbdev->pads);
+		ret = media_entity_pads_init(dvbdev->entity, npads, dvbdev->pads);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 39fab1ab921c..9674cefcf232 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -777,7 +777,7 @@ static int au8522_probe(struct i2c_client *client,
 	state->pads[AU8522_PAD_VBI_OUT].flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
 
-	ret = media_entity_init(&sd->entity, ARRAY_SIZE(state->pads),
+	ret = media_entity_pads_init(&sd->entity, ARRAY_SIZE(state->pads),
 				state->pads);
 	if (ret < 0) {
 		v4l_info(client, "failed to initialize media entity!\n");
diff --git a/drivers/media/i2c/ad9389b.c b/drivers/media/i2c/ad9389b.c
index a02dc4925707..788967dadd29 100644
--- a/drivers/media/i2c/ad9389b.c
+++ b/drivers/media/i2c/ad9389b.c
@@ -1158,7 +1158,7 @@ static int ad9389b_probe(struct i2c_client *client, const struct i2c_device_id *
 	state->rgb_quantization_range_ctrl->is_private = true;
 
 	state->pad.flags = MEDIA_PAD_FL_SINK;
-	err = media_entity_init(&sd->entity, 1, &state->pad);
+	err = media_entity_pads_init(&sd->entity, 1, &state->pad);
 	if (err)
 		goto err_hdl;
 
diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c
index 7150f35d5935..7e9cbf757e95 100644
--- a/drivers/media/i2c/adp1653.c
+++ b/drivers/media/i2c/adp1653.c
@@ -512,7 +512,7 @@ static int adp1653_probe(struct i2c_client *client,
 	if (ret)
 		goto free_and_quit;
 
-	ret = media_entity_init(&flash->subdev.entity, 0, NULL);
+	ret = media_entity_pads_init(&flash->subdev.entity, 0, NULL);
 	if (ret < 0)
 		goto free_and_quit;
 
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 2ebe9efdfc1b..ff57c1dcb8af 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -1214,7 +1214,7 @@ static int adv7180_probe(struct i2c_client *client,
 
 	state->pad.flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.flags |= MEDIA_ENT_F_ATV_DECODER;
-	ret = media_entity_init(&sd->entity, 1, &state->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &state->pad);
 	if (ret)
 		goto err_free_ctrl;
 
diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index cbcf81b1d29e..471fd23b5c5c 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -1482,7 +1482,7 @@ static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *
 	state->rgb_quantization_range_ctrl->is_private = true;
 
 	state->pad.flags = MEDIA_PAD_FL_SINK;
-	err = media_entity_init(&sd->entity, 1, &state->pad);
+	err = media_entity_pads_init(&sd->entity, 1, &state->pad);
 	if (err)
 		goto err_hdl;
 
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index c2df7e8053f3..f8dd7505b529 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -3208,7 +3208,7 @@ static int adv76xx_probe(struct i2c_client *client,
 		state->pads[i].flags = MEDIA_PAD_FL_SINK;
 	state->pads[state->source_pad].flags = MEDIA_PAD_FL_SOURCE;
 
-	err = media_entity_init(&sd->entity, state->source_pad + 1,
+	err = media_entity_pads_init(&sd->entity, state->source_pad + 1,
 				state->pads);
 	if (err)
 		goto err_work_queues;
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index b5013a937254..5fbb788e7b59 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -3309,7 +3309,7 @@ static int adv7842_probe(struct i2c_client *client,
 			adv7842_delayed_work_enable_hotplug);
 
 	state->pad.flags = MEDIA_PAD_FL_SOURCE;
-	err = media_entity_init(&sd->entity, 1, &state->pad);
+	err = media_entity_pads_init(&sd->entity, 1, &state->pad);
 	if (err)
 		goto err_work_queues;
 
diff --git a/drivers/media/i2c/as3645a.c b/drivers/media/i2c/as3645a.c
index b1bc4d0f76f2..2e90e4094b79 100644
--- a/drivers/media/i2c/as3645a.c
+++ b/drivers/media/i2c/as3645a.c
@@ -827,7 +827,7 @@ static int as3645a_probe(struct i2c_client *client,
 	if (ret < 0)
 		goto done;
 
-	ret = media_entity_init(&flash->subdev.entity, 0, NULL);
+	ret = media_entity_pads_init(&flash->subdev.entity, 0, NULL);
 	if (ret < 0)
 		goto done;
 
diff --git a/drivers/media/i2c/cx25840/cx25840-core.c b/drivers/media/i2c/cx25840/cx25840-core.c
index f2f0992c7e54..f4ac54027f15 100644
--- a/drivers/media/i2c/cx25840/cx25840-core.c
+++ b/drivers/media/i2c/cx25840/cx25840-core.c
@@ -5210,7 +5210,7 @@ static int cx25840_probe(struct i2c_client *client,
 	state->pads[CX25840_PAD_VBI_OUT].flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
 
-	ret = media_entity_init(&sd->entity, ARRAY_SIZE(state->pads),
+	ret = media_entity_pads_init(&sd->entity, ARRAY_SIZE(state->pads),
 				state->pads);
 	if (ret < 0) {
 		v4l_info(client, "failed to initialize media entity!\n");
diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
index 98266f707ea0..251a2aaf98c3 100644
--- a/drivers/media/i2c/lm3560.c
+++ b/drivers/media/i2c/lm3560.c
@@ -365,7 +365,7 @@ static int lm3560_subdev_init(struct lm3560_flash *flash,
 	rval = lm3560_init_controls(flash, led_no);
 	if (rval)
 		goto err_out;
-	rval = media_entity_init(&flash->subdev_led[led_no].entity, 0, NULL);
+	rval = media_entity_pads_init(&flash->subdev_led[led_no].entity, 0, NULL);
 	if (rval < 0)
 		goto err_out;
 	flash->subdev_led[led_no].entity.function = MEDIA_ENT_F_FLASH;
diff --git a/drivers/media/i2c/lm3646.c b/drivers/media/i2c/lm3646.c
index ba5ee0d7a78e..7e9967af36ec 100644
--- a/drivers/media/i2c/lm3646.c
+++ b/drivers/media/i2c/lm3646.c
@@ -282,7 +282,7 @@ static int lm3646_subdev_init(struct lm3646_flash *flash)
 	rval = lm3646_init_controls(flash);
 	if (rval)
 		goto err_out;
-	rval = media_entity_init(&flash->subdev_led.entity, 0, NULL);
+	rval = media_entity_pads_init(&flash->subdev_led.entity, 0, NULL);
 	if (rval < 0)
 		goto err_out;
 	flash->subdev_led.entity.function = MEDIA_ENT_F_FLASH;
diff --git a/drivers/media/i2c/m5mols/m5mols_core.c b/drivers/media/i2c/m5mols/m5mols_core.c
index bec5cea23b65..acb804bceccb 100644
--- a/drivers/media/i2c/m5mols/m5mols_core.c
+++ b/drivers/media/i2c/m5mols/m5mols_core.c
@@ -975,7 +975,7 @@ static int m5mols_probe(struct i2c_client *client,
 
 	sd->internal_ops = &m5mols_subdev_internal_ops;
 	info->pad.flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&sd->entity, 1, &info->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &info->pad);
 	if (ret < 0)
 		return ret;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
diff --git a/drivers/media/i2c/mt9m032.c b/drivers/media/i2c/mt9m032.c
index a2a450839ca1..da076796999e 100644
--- a/drivers/media/i2c/mt9m032.c
+++ b/drivers/media/i2c/mt9m032.c
@@ -799,7 +799,7 @@ static int mt9m032_probe(struct i2c_client *client,
 
 	sensor->subdev.ctrl_handler = &sensor->ctrls;
 	sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&sensor->subdev.entity, 1, &sensor->pad);
+	ret = media_entity_pads_init(&sensor->subdev.entity, 1, &sensor->pad);
 	if (ret < 0)
 		goto error_ctrl;
 
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index 165f29cddca6..237737fec09c 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -1112,7 +1112,7 @@ static int mt9p031_probe(struct i2c_client *client,
 	mt9p031->subdev.internal_ops = &mt9p031_subdev_internal_ops;
 
 	mt9p031->pad.flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&mt9p031->subdev.entity, 1, &mt9p031->pad);
+	ret = media_entity_pads_init(&mt9p031->subdev.entity, 1, &mt9p031->pad);
 	if (ret < 0)
 		goto done;
 
diff --git a/drivers/media/i2c/mt9t001.c b/drivers/media/i2c/mt9t001.c
index 7d3df84651d8..702d562f8e39 100644
--- a/drivers/media/i2c/mt9t001.c
+++ b/drivers/media/i2c/mt9t001.c
@@ -933,7 +933,7 @@ static int mt9t001_probe(struct i2c_client *client,
 	mt9t001->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 
 	mt9t001->pad.flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&mt9t001->subdev.entity, 1, &mt9t001->pad);
+	ret = media_entity_pads_init(&mt9t001->subdev.entity, 1, &mt9t001->pad);
 
 done:
 	if (ret < 0) {
diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index b4f0f042c6c3..2e1d116a64e7 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -1046,7 +1046,7 @@ static int mt9v032_probe(struct i2c_client *client,
 	mt9v032->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 
 	mt9v032->pad.flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&mt9v032->subdev.entity, 1, &mt9v032->pad);
+	ret = media_entity_pads_init(&mt9v032->subdev.entity, 1, &mt9v032->pad);
 	if (ret < 0)
 		goto err;
 
diff --git a/drivers/media/i2c/noon010pc30.c b/drivers/media/i2c/noon010pc30.c
index 47ea3f79eacc..30cb90b88d75 100644
--- a/drivers/media/i2c/noon010pc30.c
+++ b/drivers/media/i2c/noon010pc30.c
@@ -780,7 +780,7 @@ static int noon010_probe(struct i2c_client *client,
 
 	info->pad.flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	ret = media_entity_init(&sd->entity, 1, &info->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &info->pad);
 	if (ret < 0)
 		goto np_err;
 
diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c
index cf8e71610248..02b9a3440557 100644
--- a/drivers/media/i2c/ov2659.c
+++ b/drivers/media/i2c/ov2659.c
@@ -1446,7 +1446,7 @@ static int ov2659_probe(struct i2c_client *client,
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	ov2659->pad.flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	ret = media_entity_init(&sd->entity, 1, &ov2659->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &ov2659->pad);
 	if (ret < 0) {
 		v4l2_ctrl_handler_free(&ov2659->ctrls);
 		return ret;
diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
index adb4aab45c10..a0b3c9bde53d 100644
--- a/drivers/media/i2c/ov9650.c
+++ b/drivers/media/i2c/ov9650.c
@@ -1501,7 +1501,7 @@ static int ov965x_probe(struct i2c_client *client,
 
 	ov965x->pad.flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	ret = media_entity_init(&sd->entity, 1, &ov965x->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &ov965x->pad);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 3d578f2ce7b2..57b3d27993a4 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1690,7 +1690,7 @@ static int s5c73m3_probe(struct i2c_client *client,
 	state->sensor_pads[S5C73M3_ISP_PAD].flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
 
-	ret = media_entity_init(&sd->entity, S5C73M3_NUM_PADS,
+	ret = media_entity_pads_init(&sd->entity, S5C73M3_NUM_PADS,
 							state->sensor_pads);
 	if (ret < 0)
 		return ret;
@@ -1706,7 +1706,7 @@ static int s5c73m3_probe(struct i2c_client *client,
 	state->oif_pads[OIF_SOURCE_PAD].flags = MEDIA_PAD_FL_SOURCE;
 	oif_sd->entity.function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
 
-	ret = media_entity_init(&oif_sd->entity, OIF_NUM_PADS,
+	ret = media_entity_pads_init(&oif_sd->entity, OIF_NUM_PADS,
 							state->oif_pads);
 	if (ret < 0)
 		return ret;
diff --git a/drivers/media/i2c/s5k4ecgx.c b/drivers/media/i2c/s5k4ecgx.c
index bacec84e773f..8a0f22da590f 100644
--- a/drivers/media/i2c/s5k4ecgx.c
+++ b/drivers/media/i2c/s5k4ecgx.c
@@ -962,7 +962,7 @@ static int s5k4ecgx_probe(struct i2c_client *client,
 
 	priv->pad.flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	ret = media_entity_init(&sd->entity, 1, &priv->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &priv->pad);
 	if (ret)
 		return ret;
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 564938ab2abd..fc3a5a8e6c9c 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1905,7 +1905,7 @@ static int s5k5baf_configure_subdevs(struct s5k5baf *state,
 
 	state->cis_pad.flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	ret = media_entity_init(&sd->entity, NUM_CIS_PADS, &state->cis_pad);
+	ret = media_entity_pads_init(&sd->entity, NUM_CIS_PADS, &state->cis_pad);
 	if (ret < 0)
 		goto err;
 
@@ -1920,7 +1920,7 @@ static int s5k5baf_configure_subdevs(struct s5k5baf *state,
 	state->pads[PAD_CIS].flags = MEDIA_PAD_FL_SINK;
 	state->pads[PAD_OUT].flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
-	ret = media_entity_init(&sd->entity, NUM_ISP_PADS, state->pads);
+	ret = media_entity_pads_init(&sd->entity, NUM_ISP_PADS, state->pads);
 
 	if (!ret)
 		return 0;
diff --git a/drivers/media/i2c/s5k6a3.c b/drivers/media/i2c/s5k6a3.c
index 2434a7944781..b9e43ffa5085 100644
--- a/drivers/media/i2c/s5k6a3.c
+++ b/drivers/media/i2c/s5k6a3.c
@@ -333,7 +333,7 @@ static int s5k6a3_probe(struct i2c_client *client,
 	sensor->format.height = S5K6A3_DEFAULT_HEIGHT;
 
 	sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&sd->entity, 1, &sensor->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &sensor->pad);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index d71d104441bd..faee11383cb7 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -1578,7 +1578,7 @@ static int s5k6aa_probe(struct i2c_client *client,
 
 	s5k6aa->pad.flags = MEDIA_PAD_FL_SOURCE;
 	sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
-	ret = media_entity_init(&sd->entity, 1, &s5k6aa->pad);
+	ret = media_entity_pads_init(&sd->entity, 1, &s5k6aa->pad);
 	if (ret)
 		return ret;
 
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 3eaa69ee341b..a215efe7a8ba 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2487,11 +2487,11 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 		if (!last)
 			continue;
 
-		rval = media_entity_init(&this->sd.entity,
+		rval = media_entity_pads_init(&this->sd.entity,
 					 this->npads, this->pads);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_init failed\n");
+				"media_entity_pads_init failed\n");
 			return rval;
 		}
 
@@ -3077,7 +3077,7 @@ static int smiapp_probe(struct i2c_client *client,
 	sensor->src->sensor = sensor;
 
 	sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE;
-	rval = media_entity_init(&sensor->src->sd.entity, 2,
+	rval = media_entity_pads_init(&sensor->src->sd.entity, 2,
 				 sensor->src->pads);
 	if (rval < 0)
 		return rval;
diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index 78e5b644d400..3397eb99c67b 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1889,7 +1889,7 @@ static int tc358743_probe(struct i2c_client *client,
 	}
 
 	state->pad.flags = MEDIA_PAD_FL_SOURCE;
-	err = media_entity_init(&sd->entity, 1, &state->pad);
+	err = media_entity_pads_init(&sd->entity, 1, &state->pad);
 	if (err < 0)
 		goto err_hdl;
 
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 455dd4e6a1da..7fa5f1e4fe37 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -1097,7 +1097,7 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	decoder->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 	decoder->sd.entity.flags |= MEDIA_ENT_F_ATV_DECODER;
 
-	ret = media_entity_init(&decoder->sd.entity, 1, &decoder->pad);
+	ret = media_entity_pads_init(&decoder->sd.entity, 1, &decoder->pad);
 	if (ret < 0) {
 		v4l2_err(sd, "%s decoder driver failed to register !!\n",
 			 sd->name);
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index 216a07956fe9..83c79fa5f61d 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -1014,7 +1014,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
 	device->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 	device->sd.entity.flags |= MEDIA_ENT_F_ATV_DECODER;
 
-	error = media_entity_init(&device->sd.entity, 1, &device->pad);
+	error = media_entity_pads_init(&device->sd.entity, 1, &device->pad);
 	if (error < 0)
 		return error;
 #endif
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 14bd568e2f41..b8cd7733a31c 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -623,6 +623,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
 	INIT_LIST_HEAD(&entity->links);
+	entity->num_links = 0;
+	entity->num_backlinks = 0;
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 07f2dc6c2df6..ef2102ac0c66 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -197,7 +197,7 @@ void media_gobj_remove(struct media_gobj *gobj)
 }
 
 /**
- * media_entity_init - Initialize a media entity
+ * media_entity_pads_init - Initialize a media entity
  *
  * @num_pads: Total number of sink and source pads.
  * @pads: Array of 'num_pads' pads.
@@ -216,18 +216,15 @@ void media_gobj_remove(struct media_gobj *gobj)
  * number of allocated elements.
  *
  * The pads array is managed by the entity driver and passed to
- * media_entity_init() where its pointer will be stored in the entity structure.
+ * media_entity_pads_init() where its pointer will be stored in the entity structure.
  */
 int
-media_entity_init(struct media_entity *entity, u16 num_pads,
+media_entity_pads_init(struct media_entity *entity, u16 num_pads,
 		  struct media_pad *pads)
 {
 	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int i;
 
-	entity->group_id = 0;
-	entity->num_links = 0;
-	entity->num_backlinks = 0;
 	entity->num_pads = num_pads;
 	entity->pads = pads;
 
@@ -247,7 +244,7 @@ media_entity_init(struct media_entity *entity, u16 num_pads,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_init);
+EXPORT_SYMBOL_GPL(media_entity_pads_init);
 
 void
 media_entity_cleanup(struct media_entity *entity)
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 45745fd16271..7518c36f9ff7 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -1800,7 +1800,7 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
 	vid_cap->wb_fmt.code = fmt->mbus_code;
 
 	vid_cap->vd_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&vfd->entity, 1, &vid_cap->vd_pad);
+	ret = media_entity_pads_init(&vfd->entity, 1, &vid_cap->vd_pad);
 	if (ret)
 		goto err_free_ctx;
 
@@ -1892,7 +1892,7 @@ int fimc_initialize_capture_subdev(struct fimc_dev *fimc)
 	fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK_CAM].flags = MEDIA_PAD_FL_SINK;
 	fimc->vid_cap.sd_pads[FIMC_SD_PAD_SINK_FIFO].flags = MEDIA_PAD_FL_SINK;
 	fimc->vid_cap.sd_pads[FIMC_SD_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&sd->entity, FIMC_SD_PADS_NUM,
+	ret = media_entity_pads_init(&sd->entity, FIMC_SD_PADS_NUM,
 				fimc->vid_cap.sd_pads);
 	if (ret)
 		return ret;
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 17e9d66cdaf6..be150e7c2241 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -619,7 +619,7 @@ int fimc_isp_video_device_register(struct fimc_isp *isp,
 	vdev->lock = &isp->video_lock;
 
 	iv->pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&vdev->entity, 1, &iv->pad);
+	ret = media_entity_pads_init(&vdev->entity, 1, &iv->pad);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
index f52eebf765c1..293b807020c4 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -708,7 +708,7 @@ int fimc_isp_subdev_create(struct fimc_isp *isp)
 	isp->subdev_pads[FIMC_ISP_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
 	isp->subdev_pads[FIMC_ISP_SD_PAD_SRC_FIFO].flags = MEDIA_PAD_FL_SOURCE;
 	isp->subdev_pads[FIMC_ISP_SD_PAD_SRC_DMA].flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&sd->entity, FIMC_ISP_SD_PADS_NUM,
+	ret = media_entity_pads_init(&sd->entity, FIMC_ISP_SD_PADS_NUM,
 				isp->subdev_pads);
 	if (ret)
 		return ret;
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index 2e043cb3776e..2a00a12963ec 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -1317,7 +1317,7 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
 		return ret;
 
 	fimc->vd_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&vfd->entity, 1, &fimc->vd_pad);
+	ret = media_entity_pads_init(&vfd->entity, 1, &fimc->vd_pad);
 	if (ret < 0)
 		return ret;
 
@@ -1431,7 +1431,7 @@ static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc)
 	fimc->subdev_pads[FLITE_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
 	fimc->subdev_pads[FLITE_SD_PAD_SOURCE_DMA].flags = MEDIA_PAD_FL_SOURCE;
 	fimc->subdev_pads[FLITE_SD_PAD_SOURCE_ISP].flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&sd->entity, FLITE_SD_PADS_NUM,
+	ret = media_entity_pads_init(&sd->entity, FLITE_SD_PADS_NUM,
 				fimc->subdev_pads);
 	if (ret)
 		return ret;
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index 777b510991b6..af4372a4bb71 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -739,7 +739,7 @@ int fimc_register_m2m_device(struct fimc_dev *fimc,
 		return PTR_ERR(fimc->m2m.m2m_dev);
 	}
 
-	ret = media_entity_init(&vfd->entity, 0, NULL);
+	ret = media_entity_pads_init(&vfd->entity, 0, NULL);
 	if (ret)
 		goto err_me;
 
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index 8847797b0d0b..ac5e50e595be 100644
--- a/drivers/media/platform/exynos4-is/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -866,7 +866,7 @@ static int s5pcsis_probe(struct platform_device *pdev)
 
 	state->pads[CSIS_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
 	state->pads[CSIS_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
-	ret = media_entity_init(&state->sd.entity,
+	ret = media_entity_pads_init(&state->sd.entity,
 				CSIS_PADS_NUM, state->pads);
 	if (ret < 0)
 		goto e_clkdis;
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index f0e530c98188..dae674cd3f74 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2655,7 +2655,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 	pads[CCDC_PAD_SOURCE_OF].flags = MEDIA_PAD_FL_SOURCE;
 
 	me->ops = &ccdc_media_ops;
-	ret = media_entity_init(me, CCDC_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, CCDC_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index ae3038e643cc..0c790b25f6f9 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1076,7 +1076,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 	pads[CCP2_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
 
 	me->ops = &ccp2_media_ops;
-	ret = media_entity_init(me, CCP2_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, CCP2_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index b1617f7efdee..f50f6b305204 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1250,7 +1250,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 				    | MEDIA_PAD_FL_MUST_CONNECT;
 
 	me->ops = &csi2_media_ops;
-	ret = media_entity_init(me, CSI2_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, CSI2_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index cfb2debb02bf..c300cb7219e9 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2287,7 +2287,7 @@ static int preview_init_entities(struct isp_prev_device *prev)
 	pads[PREV_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
 
 	me->ops = &preview_media_ops;
-	ret = media_entity_init(me, PREV_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, PREV_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index e3ecf1787fc4..cd0a9f6e1fed 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1733,7 +1733,7 @@ static int resizer_init_entities(struct isp_res_device *res)
 	pads[RESZ_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
 
 	me->ops = &resizer_media_ops;
-	ret = media_entity_init(me, RESZ_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, RESZ_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c
index f7a5eee9f11d..1b9217d3b1b6 100644
--- a/drivers/media/platform/omap3isp/ispstat.c
+++ b/drivers/media/platform/omap3isp/ispstat.c
@@ -1028,7 +1028,7 @@ static int isp_stat_init_entities(struct ispstat *stat, const char *name,
 	stat->pad.flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT;
 	me->ops = NULL;
 
-	return media_entity_init(me, 1, &stat->pad);
+	return media_entity_pads_init(me, 1, &stat->pad);
 }
 
 int omap3isp_stat_init(struct ispstat *stat, const char *name,
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 0d6bc70eba44..a631228c2750 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -1369,7 +1369,7 @@ int omap3isp_video_init(struct isp_video *video, const char *name)
 	if (IS_ERR(video->alloc_ctx))
 		return PTR_ERR(video->alloc_ctx);
 
-	ret = media_entity_init(&video->video.entity, 1, &video->pad);
+	ret = media_entity_pads_init(&video->video.entity, 1, &video->pad);
 	if (ret < 0) {
 		vb2_dma_contig_cleanup_ctx(video->alloc_ctx);
 		return ret;
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index c12ff728cb05..78de2c466a4e 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -1155,7 +1155,7 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
 		goto err_vd_rel;
 
 	vp->pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&vfd->entity, 1, &vp->pad);
+	ret = media_entity_pads_init(&vfd->entity, 1, &vp->pad);
 	if (ret)
 		goto err_vd_rel;
 
@@ -1570,7 +1570,7 @@ int s3c_camif_create_subdev(struct camif_dev *camif)
 	camif->pads[CAMIF_SD_PAD_SOURCE_C].flags = MEDIA_PAD_FL_SOURCE;
 	camif->pads[CAMIF_SD_PAD_SOURCE_P].flags = MEDIA_PAD_FL_SOURCE;
 
-	ret = media_entity_init(&sd->entity, CAMIF_SD_PADS_NUM,
+	ret = media_entity_pads_init(&sd->entity, CAMIF_SD_PADS_NUM,
 				camif->pads);
 	if (ret)
 		return ret;
diff --git a/drivers/media/platform/vsp1/vsp1_entity.c b/drivers/media/platform/vsp1/vsp1_entity.c
index 619942ff2058..d7308530952f 100644
--- a/drivers/media/platform/vsp1/vsp1_entity.c
+++ b/drivers/media/platform/vsp1/vsp1_entity.c
@@ -219,7 +219,7 @@ int vsp1_entity_init(struct vsp1_device *vsp1, struct vsp1_entity *entity,
 	entity->pads[num_pads - 1].flags = MEDIA_PAD_FL_SOURCE;
 
 	/* Initialize the media entity. */
-	return media_entity_init(&entity->subdev.entity, num_pads,
+	return media_entity_pads_init(&entity->subdev.entity, num_pads,
 				 entity->pads);
 }
 
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 8131e65517d7..43f98eeaebce 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -1223,7 +1223,7 @@ int vsp1_video_init(struct vsp1_video *video, struct vsp1_entity *rwpf)
 	video->pipe.state = VSP1_PIPELINE_STOPPED;
 
 	/* Initialize the media entity... */
-	ret = media_entity_init(&video->video.entity, 1, &video->pad);
+	ret = media_entity_pads_init(&video->video.entity, 1, &video->pad);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/media/platform/xilinx/xilinx-dma.c b/drivers/media/platform/xilinx/xilinx-dma.c
index 06eb74344507..33d2fe5fd45e 100644
--- a/drivers/media/platform/xilinx/xilinx-dma.c
+++ b/drivers/media/platform/xilinx/xilinx-dma.c
@@ -677,7 +677,7 @@ int xvip_dma_init(struct xvip_composite_device *xdev, struct xvip_dma *dma,
 	dma->pad.flags = type == V4L2_BUF_TYPE_VIDEO_CAPTURE
 		       ? MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
 
-	ret = media_entity_init(&dma->video.entity, 1, &dma->pad);
+	ret = media_entity_pads_init(&dma->video.entity, 1, &dma->pad);
 	if (ret < 0)
 		goto error;
 
diff --git a/drivers/media/platform/xilinx/xilinx-tpg.c b/drivers/media/platform/xilinx/xilinx-tpg.c
index c09ca513a9dc..2ec1f6c4b274 100644
--- a/drivers/media/platform/xilinx/xilinx-tpg.c
+++ b/drivers/media/platform/xilinx/xilinx-tpg.c
@@ -838,7 +838,7 @@ static int xtpg_probe(struct platform_device *pdev)
 	subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 	subdev->entity.ops = &xtpg_media_ops;
 
-	ret = media_entity_init(&subdev->entity, xtpg->npads, xtpg->pads);
+	ret = media_entity_pads_init(&subdev->entity, xtpg->npads, xtpg->pads);
 	if (ret < 0)
 		goto error;
 
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 150824fe382a..3ea9d4f13797 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -1814,12 +1814,12 @@ static void au0828_analog_create_entities(struct au0828_dev *dev)
 
 	/* Initialize Video and VBI pads */
 	dev->video_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&dev->vdev.entity, 1, &dev->video_pad);
+	ret = media_entity_pads_init(&dev->vdev.entity, 1, &dev->video_pad);
 	if (ret < 0)
 		pr_err("failed to initialize video media entity!\n");
 
 	dev->vbi_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&dev->vbi_dev.entity, 1, &dev->vbi_pad);
+	ret = media_entity_pads_init(&dev->vbi_dev.entity, 1, &dev->vbi_pad);
 	if (ret < 0)
 		pr_err("failed to initialize vbi media entity!\n");
 
@@ -1851,7 +1851,7 @@ static void au0828_analog_create_entities(struct au0828_dev *dev)
 			break;
 		}
 
-		ret = media_entity_init(ent, 1, &dev->input_pad[i]);
+		ret = media_entity_pads_init(ent, 1, &dev->input_pad[i]);
 		if (ret < 0)
 			pr_err("failed to initialize input pad[%d]!\n", i);
 
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 86c9cbd02016..9ea5a9e60a70 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -2174,7 +2174,7 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
 	cx231xx_vdev_init(dev, &dev->vdev, &cx231xx_video_template, "video");
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	dev->video_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&dev->vdev.entity, 1, &dev->video_pad);
+	ret = media_entity_pads_init(&dev->vdev.entity, 1, &dev->video_pad);
 	if (ret < 0)
 		dev_err(dev->dev, "failed to initialize video media entity!\n");
 #endif
@@ -2201,7 +2201,7 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	dev->vbi_pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_init(&dev->vbi_dev.entity, 1, &dev->vbi_pad);
+	ret = media_entity_pads_init(&dev->vbi_dev.entity, 1, &dev->vbi_pad);
 	if (ret < 0)
 		dev_err(dev->dev, "failed to initialize vbi media entity!\n");
 #endif
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 7f82b65b238e..38e893a1408b 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -94,10 +94,10 @@ static int uvc_mc_init_entity(struct uvc_entity *entity)
 		strlcpy(entity->subdev.name, entity->name,
 			sizeof(entity->subdev.name));
 
-		ret = media_entity_init(&entity->subdev.entity,
+		ret = media_entity_pads_init(&entity->subdev.entity,
 					entity->num_pads, entity->pads);
 	} else if (entity->vdev != NULL) {
-		ret = media_entity_init(&entity->vdev->entity,
+		ret = media_entity_pads_init(&entity->vdev->entity,
 					entity->num_pads, entity->pads);
 		if (entity->flags & UVC_ENTITY_FLAG_DEFAULT)
 			entity->vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT;
diff --git a/drivers/media/v4l2-core/tuner-core.c b/drivers/media/v4l2-core/tuner-core.c
index 05fc4df61b85..76496fd282aa 100644
--- a/drivers/media/v4l2-core/tuner-core.c
+++ b/drivers/media/v4l2-core/tuner-core.c
@@ -701,7 +701,7 @@ register_client:
 	t->sd.entity.function = MEDIA_ENT_F_TUNER;
 	t->sd.entity.name = t->name;
 
-	ret = media_entity_init(&t->sd.entity, TUNER_NUM_PADS, &t->pad[0]);
+	ret = media_entity_pads_init(&t->sd.entity, TUNER_NUM_PADS, &t->pad[0]);
 	if (ret < 0) {
 		tuner_err("failed to initialize media entity!\n");
 		kfree(t);
diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c
index 5c686a24712b..13d5a36bc5d8 100644
--- a/drivers/media/v4l2-core/v4l2-flash-led-class.c
+++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c
@@ -651,7 +651,7 @@ struct v4l2_flash *v4l2_flash_init(
 	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
 	strlcpy(sd->name, config->dev_name, sizeof(sd->name));
 
-	ret = media_entity_init(&sd->entity, 0, NULL);
+	ret = media_entity_pads_init(&sd->entity, 0, NULL);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
index 77837afab0ce..ac78ed2f8bcc 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
@@ -1843,7 +1843,7 @@ vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe, struct platform_device *pdev)
 	v4l2_ctrl_handler_setup(&ipipe->ctrls);
 	sd->ctrl_handler = &ipipe->ctrls;
 
-	return media_entity_init(me, IPIPE_PADS_NUM, pads);
+	return media_entity_pads_init(me, IPIPE_PADS_NUM, pads);
 }
 
 /*
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index b66584ecb693..a54c60fce3d5 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -1031,7 +1031,7 @@ int vpfe_ipipeif_init(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->output = IPIPEIF_OUTPUT_NONE;
 	me->ops = &ipipeif_media_ops;
 
-	ret = media_entity_init(me, IPIPEIF_NUM_PADS, pads);
+	ret = media_entity_pads_init(me, IPIPEIF_NUM_PADS, pads);
 	if (ret)
 		goto fail;
 
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index 8ca0c1297ec8..b35667afb73f 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -2057,7 +2057,7 @@ int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev)
 	isif->input = ISIF_INPUT_NONE;
 	isif->output = ISIF_OUTPUT_NONE;
 	me->ops = &isif_media_ops;
-	status = media_entity_init(me, ISIF_PADS_NUM, pads);
+	status = media_entity_pads_init(me, ISIF_PADS_NUM, pads);
 	if (status)
 		goto isif_fail;
 	isif->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index ba887efd226a..669ae3f9791f 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1915,7 +1915,7 @@ int vpfe_resizer_init(struct vpfe_resizer_device *vpfe_rsz,
 	vpfe_rsz->crop_resizer.output2 = RESIZER_CROP_OUTPUT_NONE;
 	vpfe_rsz->crop_resizer.rsz_device = vpfe_rsz;
 	me->ops = &resizer_media_ops;
-	ret = media_entity_init(me, RESIZER_CROP_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, RESIZER_CROP_PADS_NUM, pads);
 	if (ret)
 		return ret;
 
@@ -1937,7 +1937,7 @@ int vpfe_resizer_init(struct vpfe_resizer_device *vpfe_rsz,
 	vpfe_rsz->resizer_a.output = RESIZER_OUTPUT_NONE;
 	vpfe_rsz->resizer_a.rsz_device = vpfe_rsz;
 	me->ops = &resizer_media_ops;
-	ret = media_entity_init(me, RESIZER_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, RESIZER_PADS_NUM, pads);
 	if (ret)
 		return ret;
 
@@ -1959,7 +1959,7 @@ int vpfe_resizer_init(struct vpfe_resizer_device *vpfe_rsz,
 	vpfe_rsz->resizer_b.output = RESIZER_OUTPUT_NONE;
 	vpfe_rsz->resizer_b.rsz_device = vpfe_rsz;
 	me->ops = &resizer_media_ops;
-	ret = media_entity_init(me, RESIZER_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, RESIZER_PADS_NUM, pads);
 	if (ret)
 		return ret;
 
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index a1fafddd671e..25ba878f06ad 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -1599,7 +1599,7 @@ int vpfe_video_init(struct vpfe_video_device *video, const char *name)
 	spin_lock_init(&video->irqlock);
 	spin_lock_init(&video->dma_queue_lock);
 	mutex_init(&video->lock);
-	ret = media_entity_init(&video->video_dev.entity,
+	ret = media_entity_pads_init(&video->video_dev.entity,
 				1, &video->pad);
 	if (ret < 0)
 		return ret;
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index 2b9a36cd8fa8..226366a03661 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1276,7 +1276,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 	pads[CSI2_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
 
 	me->ops = &csi2_media_ops;
-	ret = media_entity_init(me, CSI2_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, CSI2_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/staging/media/omap4iss/iss_ipipe.c b/drivers/staging/media/omap4iss/iss_ipipe.c
index dd9d7d54e6f8..d38782e8e84c 100644
--- a/drivers/staging/media/omap4iss/iss_ipipe.c
+++ b/drivers/staging/media/omap4iss/iss_ipipe.c
@@ -516,7 +516,7 @@ static int ipipe_init_entities(struct iss_ipipe_device *ipipe)
 	pads[IPIPE_PAD_SOURCE_VP].flags = MEDIA_PAD_FL_SOURCE;
 
 	me->ops = &ipipe_media_ops;
-	ret = media_entity_init(me, IPIPE_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, IPIPE_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index 8cbb9840a989..c2b5638a0898 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -748,7 +748,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 	pads[IPIPEIF_PAD_SOURCE_VP].flags = MEDIA_PAD_FL_SOURCE;
 
 	me->ops = &ipipeif_media_ops;
-	ret = media_entity_init(me, IPIPEIF_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, IPIPEIF_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index a3925ecd0ed7..fea13ab4041f 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -790,7 +790,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 	pads[RESIZER_PAD_SOURCE_MEM].flags = MEDIA_PAD_FL_SOURCE;
 
 	me->ops = &resizer_media_ops;
-	ret = media_entity_init(me, RESIZER_PADS_NUM, pads);
+	ret = media_entity_pads_init(me, RESIZER_PADS_NUM, pads);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index 0eb6eac8debf..ac73065ae56f 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -1102,7 +1102,7 @@ int omap4iss_video_init(struct iss_video *video, const char *name)
 		return -EINVAL;
 	}
 
-	ret = media_entity_init(&video->video.entity, 1, &video->pad);
+	ret = media_entity_pads_init(&video->video.entity, 1, &video->pad);
 	if (ret < 0)
 		return ret;
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index cd3f3a77df2d..32fef503d950 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -347,7 +347,7 @@ void media_gobj_init(struct media_device *mdev,
 		    struct media_gobj *gobj);
 void media_gobj_remove(struct media_gobj *gobj);
 
-int media_entity_init(struct media_entity *entity, u16 num_pads,
+int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
 		      struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-- 
2.5.0



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

* [PATCH 04/10] media-entity.h: get rid of revision and group_id fields
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
                   ` (2 preceding siblings ...)
  2015-12-11 13:34 ` [PATCH 03/10] media framework: rename pads init function to media_entity_pads_init() Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 05/10] DocBook: Move media-framework.txt contend to media-device.h Mauro Carvalho Chehab
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab, Jonathan Corbet, Hans Verkuil, linux-doc

Both revision and group_id fields were never used and were always
initialized to zero. Remove them.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml | 13 ++-----------
 Documentation/media-framework.txt                           | 12 +++++-------
 drivers/media/media-device.c                                |  4 ++--
 include/media/media-entity.h                                |  4 ----
 4 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
index 27f8817e7abe..9f7614a01234 100644
--- a/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
+++ b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml
@@ -59,15 +59,6 @@
     <para>Entity IDs can be non-contiguous. Applications must
     <emphasis>not</emphasis> try to enumerate entities by calling
     MEDIA_IOC_ENUM_ENTITIES with increasing id's until they get an error.</para>
-    <para>Two or more entities that share a common non-zero
-    <structfield>group_id</structfield> value are considered as logically
-    grouped. Groups are used to report
-    <itemizedlist>
-      <listitem><para>ALSA, VBI and video nodes that carry the same media
-      stream</para></listitem>
-      <listitem><para>lens and flash controllers associated with a sensor</para></listitem>
-    </itemizedlist>
-    </para>
 
     <table pgwide="1" frame="none" id="media-entity-desc">
       <title>struct <structname>media_entity_desc</structname></title>
@@ -106,7 +97,7 @@
 	    <entry><structfield>revision</structfield></entry>
 	    <entry></entry>
 	    <entry></entry>
-	    <entry>Entity revision in a driver/hardware specific format.</entry>
+	    <entry>Entity revision. Always zero (obsolete)</entry>
 	  </row>
 	  <row>
 	    <entry>__u32</entry>
@@ -120,7 +111,7 @@
 	    <entry><structfield>group_id</structfield></entry>
 	    <entry></entry>
 	    <entry></entry>
-	    <entry>Entity group ID</entry>
+	    <entry>Entity group ID. Always zero (obsolete)</entry>
 	  </row>
 	  <row>
 	    <entry>__u16</entry>
diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 7fbfe4bd1f47..ef3663af1db3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -110,10 +110,10 @@ If no pads are needed, drivers could directly fill entity->num_pads
 with 0 and entity->pads with NULL or to call the above function that
 will do the same.
 
-The media_entity name, type, flags, revision and group_id fields should be
-initialized before calling media_device_register_entity(). Entities embedded
-in higher-level standard structures can have some of those fields set by the
-higher-level framework.
+The media_entity name, type and flags fields should be initialized before
+calling media_device_register_entity(). Entities embedded in higher-level
+standard structures can have some of those fields set by the higher-level
+framework.
 
 As the number of pads is known in advance, the pads array is not allocated
 dynamically but is managed by the entity driver. Most drivers will embed the
@@ -164,9 +164,7 @@ Entities have flags that describe the entity capabilities and state.
 
 Logical entity groups can be defined by setting the group ID of all member
 entities to the same non-zero value. An entity group serves no purpose in the
-kernel, but is reported to userspace during entities enumeration. The group_id
-field belongs to the media device driver and must not by touched by entity
-drivers.
+kernel, but is reported to userspace during entities enumeration.
 
 Media device drivers should define groups if several entities are logically
 bound together. Example usages include reporting
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index b8cd7733a31c..537160bb461e 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -109,9 +109,9 @@ static long media_device_enum_entities(struct media_device *mdev,
 	if (ent->name)
 		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
 	u_ent.type = ent->function;
-	u_ent.revision = ent->revision;
+	u_ent.revision = 0;		/* Unused */
 	u_ent.flags = ent->flags;
-	u_ent.group_id = ent->group_id;
+	u_ent.group_id = 0;		/* Unused */
 	u_ent.pads = ent->num_pads;
 	u_ent.links = ent->num_links - ent->num_backlinks;
 	memcpy(&u_ent.raw, &ent->info, sizeof(ent->info));
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 32fef503d950..031536723d8c 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -153,9 +153,7 @@ struct media_entity_operations {
  * @name:	Entity name.
  * @function:	Entity main function, as defined in uapi/media.h
  *		(MEDIA_ENT_F_*)
- * @revision:	Entity revision - OBSOLETE - should be removed soon.
  * @flags:	Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*)
- * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
  * @num_pads:	Number of sink and source pads.
  * @num_links:	Total number of links, forward and back, enabled and disabled.
  * @num_backlinks: Number of backlinks
@@ -180,9 +178,7 @@ struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
 	const char *name;
 	u32 function;
-	u32 revision;
 	unsigned long flags;
-	u32 group_id;
 
 	u16 num_pads;
 	u16 num_links;
-- 
2.5.0



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

* [PATCH 05/10] DocBook: Move media-framework.txt contend to media-device.h
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
                   ` (3 preceding siblings ...)
  2015-12-11 13:34 ` [PATCH 04/10] media-entity.h: get rid of revision and group_id fields Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 06/10] media-entity.h: convert media_entity_cleanup to inline Mauro Carvalho Chehab
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab, Jonathan Corbet, Thierry Reding, linux-doc

Instead of using a text file, let's put it together with the struct documentation
for the Media Controller.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 Documentation/DocBook/device-drivers.tmpl |   1 +
 Documentation/media-framework.txt         | 373 -----------------------------
 include/media/media-device.h              | 378 ++++++++++++++++++++++++++++++
 3 files changed, 379 insertions(+), 373 deletions(-)
 delete mode 100644 Documentation/media-framework.txt

diff --git a/Documentation/DocBook/device-drivers.tmpl b/Documentation/DocBook/device-drivers.tmpl
index 7b3fcc5effcd..cdd8b24db68d 100644
--- a/Documentation/DocBook/device-drivers.tmpl
+++ b/Documentation/DocBook/device-drivers.tmpl
@@ -263,6 +263,7 @@ X!Isound/sound_firmware.c
 !Iinclude/media/lirc_dev.h
     </sect1>
     <sect1><title>Media Controller devices</title>
+!Pinclude/media/media-device.h Media Controller
 !Iinclude/media/media-device.h
 !Iinclude/media/media-devnode.h
 !Iinclude/media/media-entity.h
diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
deleted file mode 100644
index ef3663af1db3..000000000000
--- a/Documentation/media-framework.txt
+++ /dev/null
@@ -1,373 +0,0 @@
-Linux kernel media framework
-============================
-
-This document describes the Linux kernel media framework, its data structures,
-functions and their usage.
-
-
-Introduction
-------------
-
-The media controller API is documented in DocBook format in
-Documentation/DocBook/media/v4l/media-controller.xml. This document will focus
-on the kernel-side implementation of the media framework.
-
-
-Abstract media device model
----------------------------
-
-Discovering a device internal topology, and configuring it at runtime, is one
-of the goals of the media framework. To achieve this, hardware devices are
-modelled as an oriented graph of building blocks called entities connected
-through pads.
-
-An entity is a basic media hardware building block. It can correspond to
-a large variety of logical blocks such as physical hardware devices
-(CMOS sensor for instance), logical hardware devices (a building block
-in a System-on-Chip image processing pipeline), DMA channels or physical
-connectors.
-
-A pad is a connection endpoint through which an entity can interact with
-other entities. Data (not restricted to video) produced by an entity
-flows from the entity's output to one or more entity inputs. Pads should
-not be confused with physical pins at chip boundaries.
-
-A link is a point-to-point oriented connection between two pads, either
-on the same entity or on different entities. Data flows from a source
-pad to a sink pad.
-
-
-Media device
-------------
-
-A media device is represented by a struct media_device instance, defined in
-include/media/media-device.h. Allocation of the structure is handled by the
-media device driver, usually by embedding the media_device instance in a
-larger driver-specific structure.
-
-Drivers register media device instances by calling
-
-	media_device_register(struct media_device *mdev);
-
-The caller is responsible for initializing the media_device structure before
-registration. The following fields must be set:
-
- - dev must point to the parent device (usually a pci_dev, usb_interface or
-   platform_device instance).
-
- - model must be filled with the device model name as a NUL-terminated UTF-8
-   string. The device/model revision must not be stored in this field.
-
-The following fields are optional:
-
- - serial is a unique serial number stored as a NUL-terminated ASCII string.
-   The field is big enough to store a GUID in text form. If the hardware
-   doesn't provide a unique serial number this field must be left empty.
-
- - bus_info represents the location of the device in the system as a
-   NUL-terminated ASCII string. For PCI/PCIe devices bus_info must be set to
-   "PCI:" (or "PCIe:") followed by the value of pci_name(). For USB devices,
-   the usb_make_path() function must be used. This field is used by
-   applications to distinguish between otherwise identical devices that don't
-   provide a serial number.
-
- - hw_revision is the hardware device revision in a driver-specific format.
-   When possible the revision should be formatted with the KERNEL_VERSION
-   macro.
-
- - driver_version is formatted with the KERNEL_VERSION macro. The version
-   minor must be incremented when new features are added to the userspace API
-   without breaking binary compatibility. The version major must be
-   incremented when binary compatibility is broken.
-
-Upon successful registration a character device named media[0-9]+ is created.
-The device major and minor numbers are dynamic. The model name is exported as
-a sysfs attribute.
-
-Drivers unregister media device instances by calling
-
-	media_device_unregister(struct media_device *mdev);
-
-Unregistering a media device that hasn't been registered is *NOT* safe.
-
-
-Entities, pads and links
-------------------------
-
-- Entities
-
-Entities are represented by a struct media_entity instance, defined in
-include/media/media-entity.h. The structure is usually embedded into a
-higher-level structure, such as a v4l2_subdev or video_device instance,
-although drivers can allocate entities directly.
-
-Drivers initialize entity pads by calling
-
-	media_entity_pads_init(struct media_entity *entity, u16 num_pads,
-			  struct media_pad *pads);
-
-If no pads are needed, drivers could directly fill entity->num_pads
-with 0 and entity->pads with NULL or to call the above function that
-will do the same.
-
-The media_entity name, type and flags fields should be initialized before
-calling media_device_register_entity(). Entities embedded in higher-level
-standard structures can have some of those fields set by the higher-level
-framework.
-
-As the number of pads is known in advance, the pads array is not allocated
-dynamically but is managed by the entity driver. Most drivers will embed the
-pads array in a driver-specific structure, avoiding dynamic allocation.
-
-Drivers must set the direction of every pad in the pads array before calling
-media_entity_pads_init. The function will initialize the other pads fields.
-
-Unlike the number of pads, the total number of links isn't always known in
-advance by the entity driver. As an initial estimate, media_entity_pads_init
-pre-allocates a number of links equal to the number of pads. The links array
-will be reallocated if it grows beyond the initial estimate.
-
-Drivers register entities with a media device by calling
-
-	media_device_register_entity(struct media_device *mdev,
-				     struct media_entity *entity);
-
-Entities are identified by a unique positive integer ID. Drivers can provide an
-ID by filling the media_entity id field prior to registration, or request the
-media controller framework to assign an ID automatically. Drivers that provide
-IDs manually must ensure that all IDs are unique. IDs are not guaranteed to be
-contiguous even when they are all assigned automatically by the framework.
-
-Drivers unregister entities by calling
-
-	media_device_unregister_entity(struct media_entity *entity);
-
-Unregistering an entity will not change the IDs of the other entities, and the
-ID will never be reused for a newly registered entity.
-
-When a media device is unregistered, all its entities are unregistered
-automatically. No manual entities unregistration is then required.
-
-Drivers free resources associated with an entity by calling
-
-	media_entity_cleanup(struct media_entity *entity);
-
-This function must be called during the cleanup phase after unregistering the
-entity. Note that the media_entity instance itself must be freed explicitly by
-the driver if required.
-
-Entities have flags that describe the entity capabilities and state.
-
-	MEDIA_ENT_FL_DEFAULT indicates the default entity for a given type.
-	This can be used to report the default audio and video devices or the
-	default camera sensor.
-
-Logical entity groups can be defined by setting the group ID of all member
-entities to the same non-zero value. An entity group serves no purpose in the
-kernel, but is reported to userspace during entities enumeration.
-
-Media device drivers should define groups if several entities are logically
-bound together. Example usages include reporting
-
-	- ALSA, VBI and video nodes that carry the same media stream
-	- lens and flash controllers associated with a sensor
-
-- Pads
-
-Pads are represented by a struct media_pad instance, defined in
-include/media/media-entity.h. Each entity stores its pads in a pads array
-managed by the entity driver. Drivers usually embed the array in a
-driver-specific structure.
-
-Pads are identified by their entity and their 0-based index in the pads array.
-Both information are stored in the media_pad structure, making the media_pad
-pointer the canonical way to store and pass link references.
-
-Pads have flags that describe the pad capabilities and state.
-
-	MEDIA_PAD_FL_SINK indicates that the pad supports sinking data.
-	MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data.
-
-One and only one of MEDIA_PAD_FL_SINK and MEDIA_PAD_FL_SOURCE must be set for
-each pad.
-
-- Links
-
-Links are represented by a struct media_link instance, defined in
-include/media/media-entity.h. Each entity stores all links originating at or
-targeting any of its pads in a links array. A given link is thus stored
-twice, once in the source entity and once in the target entity. The array is
-pre-allocated and grows dynamically as needed.
-
-Drivers create links by calling
-
-	media_create_pad_link(struct media_entity *source, u16 source_pad,
-				 struct media_entity *sink,   u16 sink_pad,
-				 u32 flags);
-
-An entry in the link array of each entity is allocated and stores pointers
-to source and sink pads.
-
-Links have flags that describe the link capabilities and state.
-
-	MEDIA_LNK_FL_ENABLED indicates that the link is enabled and can be used
-	to transfer media data. When two or more links target a sink pad, only
-	one of them can be enabled at a time.
-	MEDIA_LNK_FL_IMMUTABLE indicates that the link enabled state can't be
-	modified at runtime. If MEDIA_LNK_FL_IMMUTABLE is set, then
-	MEDIA_LNK_FL_ENABLED must also be set since an immutable link is always
-	enabled.
-
-
-Graph traversal
----------------
-
-The media framework provides APIs to iterate over entities in a graph.
-
-To iterate over all entities belonging to a media device, drivers can use the
-media_device_for_each_entity macro, defined in include/media/media-device.h.
-
-	struct media_entity *entity;
-
-	media_device_for_each_entity(entity, mdev) {
-		/* entity will point to each entity in turn */
-		...
-	}
-
-Drivers might also need to iterate over all entities in a graph that can be
-reached only through enabled links starting at a given entity. The media
-framework provides a depth-first graph traversal API for that purpose.
-
-Note that graphs with cycles (whether directed or undirected) are *NOT*
-supported by the graph traversal API. To prevent infinite loops, the graph
-traversal code limits the maximum depth to MEDIA_ENTITY_ENUM_MAX_DEPTH,
-currently defined as 16.
-
-Drivers initiate a graph traversal by calling
-
-	media_entity_graph_walk_start(struct media_entity_graph *graph,
-				      struct media_entity *entity);
-
-The graph structure, provided by the caller, is initialized to start graph
-traversal at the given entity.
-
-Drivers can then retrieve the next entity by calling
-
-	media_entity_graph_walk_next(struct media_entity_graph *graph);
-
-When the graph traversal is complete the function will return NULL.
-
-Graph traversal can be interrupted at any moment. No cleanup function call is
-required and the graph structure can be freed normally.
-
-Helper functions can be used to find a link between two given pads, or a pad
-connected to another pad through an enabled link
-
-	media_entity_find_link(struct media_pad *source,
-			       struct media_pad *sink);
-
-	media_entity_remote_pad(struct media_pad *pad);
-
-Refer to the kerneldoc documentation for more information.
-
-
-Use count and power handling
-----------------------------
-
-Due to the wide differences between drivers regarding power management needs,
-the media controller does not implement power management. However, the
-media_entity structure includes a use_count field that media drivers can use to
-track the number of users of every entity for power management needs.
-
-The use_count field is owned by media drivers and must not be touched by entity
-drivers. Access to the field must be protected by the media device graph_mutex
-lock.
-
-
-Links setup
------------
-
-Link properties can be modified at runtime by calling
-
-	media_entity_setup_link(struct media_link *link, u32 flags);
-
-The flags argument contains the requested new link flags.
-
-The only configurable property is the ENABLED link flag to enable/disable a
-link. Links marked with the IMMUTABLE link flag can not be enabled or disabled.
-
-When a link is enabled or disabled, the media framework calls the
-link_setup operation for the two entities at the source and sink of the link,
-in that order. If the second link_setup call fails, another link_setup call is
-made on the first entity to restore the original link flags.
-
-Media device drivers can be notified of link setup operations by setting the
-media_device::link_notify pointer to a callback function. If provided, the
-notification callback will be called before enabling and after disabling
-links.
-
-Entity drivers must implement the link_setup operation if any of their links
-is non-immutable. The operation must either configure the hardware or store
-the configuration information to be applied later.
-
-Link configuration must not have any side effect on other links. If an enabled
-link at a sink pad prevents another link at the same pad from being enabled,
-the link_setup operation must return -EBUSY and can't implicitly disable the
-first enabled link.
-
-
-Pipelines and media streams
----------------------------
-
-When starting streaming, drivers must notify all entities in the pipeline to
-prevent link states from being modified during streaming by calling
-
-	media_entity_pipeline_start(struct media_entity *entity,
-				    struct media_pipeline *pipe);
-
-The function will mark all entities connected to the given entity through
-enabled links, either directly or indirectly, as streaming.
-
-The media_pipeline instance pointed to by the pipe argument will be stored in
-every entity in the pipeline. Drivers should embed the media_pipeline structure
-in higher-level pipeline structures and can then access the pipeline through
-the media_entity pipe field.
-
-Calls to media_entity_pipeline_start() can be nested. The pipeline pointer must
-be identical for all nested calls to the function.
-
-media_entity_pipeline_start() may return an error. In that case, it will
-clean up any of the changes it did by itself.
-
-When stopping the stream, drivers must notify the entities with
-
-	media_entity_pipeline_stop(struct media_entity *entity);
-
-If multiple calls to media_entity_pipeline_start() have been made the same
-number of media_entity_pipeline_stop() calls are required to stop streaming. The
-media_entity pipe field is reset to NULL on the last nested stop call.
-
-Link configuration will fail with -EBUSY by default if either end of the link is
-a streaming entity. Links that can be modified while streaming must be marked
-with the MEDIA_LNK_FL_DYNAMIC flag.
-
-If other operations need to be disallowed on streaming entities (such as
-changing entities configuration parameters) drivers can explicitly check the
-media_entity stream_count field to find out if an entity is streaming. This
-operation must be done with the media_device graph_mutex held.
-
-
-Link validation
----------------
-
-Link validation is performed by media_entity_pipeline_start() for any
-entity which has sink pads in the pipeline. The
-media_entity::link_validate() callback is used for that purpose. In
-link_validate() callback, entity driver should check that the properties of
-the source pad of the connected entity and its own sink pad match. It is up
-to the type of the entity (and in the end, the properties of the hardware)
-what matching actually means.
-
-Subsystems should facilitate link validation by providing subsystem specific
-helper functions to provide easy access for commonly needed information, and
-in the end provide a way to use driver-specific callbacks.
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 87ff299e1265..6728528df9e2 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -30,6 +30,384 @@
 #include <media/media-devnode.h>
 #include <media/media-entity.h>
 
+/**
+ * DOC: Media Controller
+ *
+ * Linux kernel media framework
+ * ============================
+ *
+ * This document describes the Linux kernel media framework, its data structures,
+ * functions and their usage.
+ *
+ *
+ * Introduction
+ * ------------
+ *
+ * The media controller API is documented in DocBook format in
+ * Documentation/DocBook/media/v4l/media-controller.xml. This document will focus
+ * on the kernel-side implementation of the media framework.
+ *
+ *
+ * Abstract media device model
+ * ---------------------------
+ *
+ * Discovering a device internal topology, and configuring it at runtime, is one
+ * of the goals of the media framework. To achieve this, hardware devices are
+ * modelled as an oriented graph of building blocks called entities connected
+ * through pads.
+ *
+ * An entity is a basic media hardware building block. It can correspond to
+ * a large variety of logical blocks such as physical hardware devices
+ * (CMOS sensor for instance), logical hardware devices (a building block
+ * in a System-on-Chip image processing pipeline), DMA channels or physical
+ * connectors.
+ *
+ * A pad is a connection endpoint through which an entity can interact with
+ * other entities. Data (not restricted to video) produced by an entity
+ * flows from the entity's output to one or more entity inputs. Pads should
+ * not be confused with physical pins at chip boundaries.
+ *
+ * A link is a point-to-point oriented connection between two pads, either
+ * on the same entity or on different entities. Data flows from a source
+ * pad to a sink pad.
+ *
+ *
+ * Media device
+ * ------------
+ *
+ * A media device is represented by a struct media_device instance, defined in
+ * include/media/media-device.h. Allocation of the structure is handled by the
+ * media device driver, usually by embedding the media_device instance in a
+ * larger driver-specific structure.
+ *
+ * Drivers register media device instances by calling
+ *
+ * 	media_device_register(struct media_device *mdev);
+ *
+ * The caller is responsible for initializing the media_device structure before
+ * registration. The following fields must be set:
+ *
+ *  - dev must point to the parent device (usually a pci_dev, usb_interface or
+ *    platform_device instance).
+ *
+ *  - model must be filled with the device model name as a NUL-terminated UTF-8
+ *    string. The device/model revision must not be stored in this field.
+ *
+ * The following fields are optional:
+ *
+ *  - serial is a unique serial number stored as a NUL-terminated ASCII string.
+ *    The field is big enough to store a GUID in text form. If the hardware
+ *    doesn't provide a unique serial number this field must be left empty.
+ *
+ *  - bus_info represents the location of the device in the system as a
+ *    NUL-terminated ASCII string. For PCI/PCIe devices bus_info must be set to
+ *    "PCI:" (or "PCIe:") followed by the value of pci_name(). For USB devices,
+ *    the usb_make_path() function must be used. This field is used by
+ *    applications to distinguish between otherwise identical devices that don't
+ *    provide a serial number.
+ *
+ *  - hw_revision is the hardware device revision in a driver-specific format.
+ *    When possible the revision should be formatted with the KERNEL_VERSION
+ *    macro.
+ *
+ *  - driver_version is formatted with the KERNEL_VERSION macro. The version
+ *    minor must be incremented when new features are added to the userspace API
+ *    without breaking binary compatibility. The version major must be
+ *    incremented when binary compatibility is broken.
+ *
+ * Upon successful registration a character device named media[0-9]+ is created.
+ * The device major and minor numbers are dynamic. The model name is exported as
+ * a sysfs attribute.
+ *
+ * Drivers unregister media device instances by calling
+ *
+ * 	media_device_unregister(struct media_device *mdev);
+ *
+ * Unregistering a media device that hasn't been registered is *NOT* safe.
+ *
+ *
+ * Entities, pads and links
+ * ------------------------
+ *
+ * - Entities
+ *
+ * Entities are represented by a struct media_entity instance, defined in
+ * include/media/media-entity.h. The structure is usually embedded into a
+ * higher-level structure, such as a v4l2_subdev or video_device instance,
+ * although drivers can allocate entities directly.
+ *
+ * Drivers initialize entity pads by calling
+ *
+ * 	media_entity_pads_init(struct media_entity *entity, u16 num_pads,
+ * 			  struct media_pad *pads);
+ *
+ * If no pads are needed, drivers could directly fill entity->num_pads
+ * with 0 and entity->pads with NULL or to call the above function that
+ * will do the same.
+ *
+ * The media_entity name, type and flags fields should be initialized before
+ * calling media_device_register_entity(). Entities embedded in higher-level
+ * standard structures can have some of those fields set by the higher-level
+ * framework.
+ *
+ * As the number of pads is known in advance, the pads array is not allocated
+ * dynamically but is managed by the entity driver. Most drivers will embed the
+ * pads array in a driver-specific structure, avoiding dynamic allocation.
+ *
+ * Drivers must set the direction of every pad in the pads array before calling
+ * media_entity_pads_init. The function will initialize the other pads fields.
+ *
+ * Unlike the number of pads, the total number of links isn't always known in
+ * advance by the entity driver. As an initial estimate, media_entity_pads_init
+ * pre-allocates a number of links equal to the number of pads. The links array
+ * will be reallocated if it grows beyond the initial estimate.
+ *
+ * Drivers register entities with a media device by calling
+ *
+ * 	media_device_register_entity(struct media_device *mdev,
+ * 				     struct media_entity *entity);
+ *
+ * Entities are identified by a unique positive integer ID. Drivers can provide an
+ * ID by filling the media_entity id field prior to registration, or request the
+ * media controller framework to assign an ID automatically. Drivers that provide
+ * IDs manually must ensure that all IDs are unique. IDs are not guaranteed to be
+ * contiguous even when they are all assigned automatically by the framework.
+ *
+ * Drivers unregister entities by calling
+ *
+ * 	media_device_unregister_entity(struct media_entity *entity);
+ *
+ * Unregistering an entity will not change the IDs of the other entities, and the
+ * ID will never be reused for a newly registered entity.
+ *
+ * When a media device is unregistered, all its entities are unregistered
+ * automatically. No manual entities unregistration is then required.
+ *
+ * Drivers free resources associated with an entity by calling
+ *
+ * 	media_entity_cleanup(struct media_entity *entity);
+ *
+ * This function must be called during the cleanup phase after unregistering the
+ * entity. Note that the media_entity instance itself must be freed explicitly by
+ * the driver if required.
+ *
+ * Entities have flags that describe the entity capabilities and state.
+ *
+ * 	MEDIA_ENT_FL_DEFAULT indicates the default entity for a given type.
+ * 	This can be used to report the default audio and video devices or the
+ * 	default camera sensor.
+ *
+ * Logical entity groups can be defined by setting the group ID of all member
+ * entities to the same non-zero value. An entity group serves no purpose in the
+ * kernel, but is reported to userspace during entities enumeration.
+ *
+ * Media device drivers should define groups if several entities are logically
+ * bound together. Example usages include reporting
+ *
+ * 	- ALSA, VBI and video nodes that carry the same media stream
+ * 	- lens and flash controllers associated with a sensor
+ *
+ * - Pads
+ *
+ * Pads are represented by a struct media_pad instance, defined in
+ * include/media/media-entity.h. Each entity stores its pads in a pads array
+ * managed by the entity driver. Drivers usually embed the array in a
+ * driver-specific structure.
+ *
+ * Pads are identified by their entity and their 0-based index in the pads array.
+ * Both information are stored in the media_pad structure, making the media_pad
+ * pointer the canonical way to store and pass link references.
+ *
+ * Pads have flags that describe the pad capabilities and state.
+ *
+ * 	MEDIA_PAD_FL_SINK indicates that the pad supports sinking data.
+ * 	MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data.
+ *
+ * One and only one of MEDIA_PAD_FL_SINK and MEDIA_PAD_FL_SOURCE must be set for
+ * each pad.
+ *
+ * - Links
+ *
+ * Links are represented by a struct media_link instance, defined in
+ * include/media/media-entity.h. Each entity stores all links originating at or
+ * targeting any of its pads in a links array. A given link is thus stored
+ * twice, once in the source entity and once in the target entity. The array is
+ * pre-allocated and grows dynamically as needed.
+ *
+ * Drivers create links by calling
+ *
+ * 	media_create_pad_link(struct media_entity *source, u16 source_pad,
+ * 				 struct media_entity *sink,   u16 sink_pad,
+ * 				 u32 flags);
+ *
+ * An entry in the link array of each entity is allocated and stores pointers
+ * to source and sink pads.
+ *
+ * Links have flags that describe the link capabilities and state.
+ *
+ * 	MEDIA_LNK_FL_ENABLED indicates that the link is enabled and can be used
+ * 	to transfer media data. When two or more links target a sink pad, only
+ * 	one of them can be enabled at a time.
+ * 	MEDIA_LNK_FL_IMMUTABLE indicates that the link enabled state can't be
+ * 	modified at runtime. If MEDIA_LNK_FL_IMMUTABLE is set, then
+ * 	MEDIA_LNK_FL_ENABLED must also be set since an immutable link is always
+ * 	enabled.
+ *
+ *
+ * Graph traversal
+ * ---------------
+ *
+ * The media framework provides APIs to iterate over entities in a graph.
+ *
+ * To iterate over all entities belonging to a media device, drivers can use the
+ * media_device_for_each_entity macro, defined in include/media/media-device.h.
+ *
+ * 	struct media_entity *entity;
+ *
+ * 	media_device_for_each_entity(entity, mdev) {
+ * 		// entity will point to each entity in turn
+ * 		...
+ * 	}
+ *
+ * Drivers might also need to iterate over all entities in a graph that can be
+ * reached only through enabled links starting at a given entity. The media
+ * framework provides a depth-first graph traversal API for that purpose.
+ *
+ * Note that graphs with cycles (whether directed or undirected) are *NOT*
+ * supported by the graph traversal API. To prevent infinite loops, the graph
+ * traversal code limits the maximum depth to MEDIA_ENTITY_ENUM_MAX_DEPTH,
+ * currently defined as 16.
+ *
+ * Drivers initiate a graph traversal by calling
+ *
+ * 	media_entity_graph_walk_start(struct media_entity_graph *graph,
+ * 				      struct media_entity *entity);
+ *
+ * The graph structure, provided by the caller, is initialized to start graph
+ * traversal at the given entity.
+ *
+ * Drivers can then retrieve the next entity by calling
+ *
+ * 	media_entity_graph_walk_next(struct media_entity_graph *graph);
+ *
+ * When the graph traversal is complete the function will return NULL.
+ *
+ * Graph traversal can be interrupted at any moment. No cleanup function call is
+ * required and the graph structure can be freed normally.
+ *
+ * Helper functions can be used to find a link between two given pads, or a pad
+ * connected to another pad through an enabled link
+ *
+ * 	media_entity_find_link(struct media_pad *source,
+ * 			       struct media_pad *sink);
+ *
+ * 	media_entity_remote_pad(struct media_pad *pad);
+ *
+ * Refer to the kerneldoc documentation for more information.
+ *
+ *
+ * Use count and power handling
+ * ----------------------------
+ *
+ * Due to the wide differences between drivers regarding power management needs,
+ * the media controller does not implement power management. However, the
+ * media_entity structure includes a use_count field that media drivers can use to
+ * track the number of users of every entity for power management needs.
+ *
+ * The use_count field is owned by media drivers and must not be touched by entity
+ * drivers. Access to the field must be protected by the media device graph_mutex
+ * lock.
+ *
+ *
+ * Links setup
+ * -----------
+ *
+ * Link properties can be modified at runtime by calling
+ *
+ * 	media_entity_setup_link(struct media_link *link, u32 flags);
+ *
+ * The flags argument contains the requested new link flags.
+ *
+ * The only configurable property is the ENABLED link flag to enable/disable a
+ * link. Links marked with the IMMUTABLE link flag can not be enabled or disabled.
+ *
+ * When a link is enabled or disabled, the media framework calls the
+ * link_setup operation for the two entities at the source and sink of the link,
+ * in that order. If the second link_setup call fails, another link_setup call is
+ * made on the first entity to restore the original link flags.
+ *
+ * Media device drivers can be notified of link setup operations by setting the
+ * media_device::link_notify pointer to a callback function. If provided, the
+ * notification callback will be called before enabling and after disabling
+ * links.
+ *
+ * Entity drivers must implement the link_setup operation if any of their links
+ * is non-immutable. The operation must either configure the hardware or store
+ * the configuration information to be applied later.
+ *
+ * Link configuration must not have any side effect on other links. If an enabled
+ * link at a sink pad prevents another link at the same pad from being enabled,
+ * the link_setup operation must return -EBUSY and can't implicitly disable the
+ * first enabled link.
+ *
+ *
+ * Pipelines and media streams
+ * ---------------------------
+ *
+ * When starting streaming, drivers must notify all entities in the pipeline to
+ * prevent link states from being modified during streaming by calling
+ *
+ * 	media_entity_pipeline_start(struct media_entity *entity,
+ * 				    struct media_pipeline *pipe);
+ *
+ * The function will mark all entities connected to the given entity through
+ * enabled links, either directly or indirectly, as streaming.
+ *
+ * The media_pipeline instance pointed to by the pipe argument will be stored in
+ * every entity in the pipeline. Drivers should embed the media_pipeline structure
+ * in higher-level pipeline structures and can then access the pipeline through
+ * the media_entity pipe field.
+ *
+ * Calls to media_entity_pipeline_start() can be nested. The pipeline pointer must
+ * be identical for all nested calls to the function.
+ *
+ * media_entity_pipeline_start() may return an error. In that case, it will
+ * clean up any of the changes it did by itself.
+ *
+ * When stopping the stream, drivers must notify the entities with
+ *
+ * 	media_entity_pipeline_stop(struct media_entity *entity);
+ *
+ * If multiple calls to media_entity_pipeline_start() have been made the same
+ * number of media_entity_pipeline_stop() calls are required to stop streaming. The
+ * media_entity pipe field is reset to NULL on the last nested stop call.
+ *
+ * Link configuration will fail with -EBUSY by default if either end of the link is
+ * a streaming entity. Links that can be modified while streaming must be marked
+ * with the MEDIA_LNK_FL_DYNAMIC flag.
+ *
+ * If other operations need to be disallowed on streaming entities (such as
+ * changing entities configuration parameters) drivers can explicitly check the
+ * media_entity stream_count field to find out if an entity is streaming. This
+ * operation must be done with the media_device graph_mutex held.
+ *
+ *
+ * Link validation
+ * ---------------
+ *
+ * Link validation is performed by media_entity_pipeline_start() for any
+ * entity which has sink pads in the pipeline. The
+ * media_entity::link_validate() callback is used for that purpose. In
+ * link_validate() callback, entity driver should check that the properties of
+ * the source pad of the connected entity and its own sink pad match. It is up
+ * to the type of the entity (and in the end, the properties of the hardware)
+ * what matching actually means.
+ *
+ * Subsystems should facilitate link validation by providing subsystem specific
+ * helper functions to provide easy access for commonly needed information, and
+ * in the end provide a way to use driver-specific callbacks.
+ */
+
 struct device;
 
 /**
-- 
2.5.0



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

* [PATCH 06/10] media-entity.h: convert media_entity_cleanup to inline
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
                   ` (4 preceding siblings ...)
  2015-12-11 13:34 ` [PATCH 05/10] DocBook: Move media-framework.txt contend to media-device.h Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 07/10] media-device.h: Improve documentation and update it Mauro Carvalho Chehab
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

This function was used in the past to free the links
that were allocated by the media controller core.

However, this is not needed anymore. We should likely
get rid of the funcion on some function, but, for now,
let's just convert into an inlined function and let the
compiler to get rid of it.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/media-entity.c | 6 ------
 include/media/media-entity.h | 3 ++-
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index ef2102ac0c66..849db4f6f1f3 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -246,12 +246,6 @@ media_entity_pads_init(struct media_entity *entity, u16 num_pads,
 }
 EXPORT_SYMBOL_GPL(media_entity_pads_init);
 
-void
-media_entity_cleanup(struct media_entity *entity)
-{
-}
-EXPORT_SYMBOL_GPL(media_entity_cleanup);
-
 /* -----------------------------------------------------------------------------
  * Graph traversal
  */
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 031536723d8c..e9bc5857899c 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -345,7 +345,8 @@ void media_gobj_remove(struct media_gobj *gobj);
 
 int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
 		      struct media_pad *pads);
-void media_entity_cleanup(struct media_entity *entity);
+
+static inline void media_entity_cleanup(struct media_entity *entity) {};
 
 __must_check int media_create_pad_link(struct media_entity *source,
 			u16 source_pad, struct media_entity *sink,
-- 
2.5.0



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

* [PATCH 07/10] media-device.h: Improve documentation and update it
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
                   ` (5 preceding siblings ...)
  2015-12-11 13:34 ` [PATCH 06/10] media-entity.h: convert media_entity_cleanup to inline Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 08/10] media-entity.c: remove two extra blank lines Mauro Carvalho Chehab
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

Now that we moved the content of the media-framework.txt into
the kerneldoc documentation, move the per-function specific
documentation to the corresponding functions and clean it up.

It would be good if we had already the markdown kernel-doc
patches merged upstream, but, while we doesn't have it,
let's make it less ugly at device-drivers.xml.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 include/media/media-device.h | 429 +++++++++++++++++++------------------------
 include/media/media-entity.h | 148 +++++++++++++++
 2 files changed, 339 insertions(+), 238 deletions(-)

diff --git a/include/media/media-device.h b/include/media/media-device.h
index 6728528df9e2..7cfcc08a09ea 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -33,23 +33,11 @@
 /**
  * DOC: Media Controller
  *
- * Linux kernel media framework
- * ============================
- *
- * This document describes the Linux kernel media framework, its data structures,
- * functions and their usage.
- *
- *
- * Introduction
- * ------------
- *
- * The media controller API is documented in DocBook format in
- * Documentation/DocBook/media/v4l/media-controller.xml. This document will focus
+ * The media controller userspace API is documented in DocBook format in
+ * Documentation/DocBook/media/v4l/media-controller.xml. This document focus
  * on the kernel-side implementation of the media framework.
  *
- *
- * Abstract media device model
- * ---------------------------
+ * * Abstract media device model:
  *
  * Discovering a device internal topology, and configuring it at runtime, is one
  * of the goals of the media framework. To achieve this, hardware devices are
@@ -72,195 +60,104 @@
  * pad to a sink pad.
  *
  *
- * Media device
- * ------------
+ * * Media device:
  *
- * A media device is represented by a struct media_device instance, defined in
+ * A media device is represented by a struct &media_device instance, defined in
  * include/media/media-device.h. Allocation of the structure is handled by the
- * media device driver, usually by embedding the media_device instance in a
+ * media device driver, usually by embedding the &media_device instance in a
  * larger driver-specific structure.
  *
  * Drivers register media device instances by calling
+ *	__media_device_register() via the macro media_device_register()
+ * and unregistered by calling
+ * 	media_device_unregister().
  *
- * 	media_device_register(struct media_device *mdev);
- *
- * The caller is responsible for initializing the media_device structure before
- * registration. The following fields must be set:
- *
- *  - dev must point to the parent device (usually a pci_dev, usb_interface or
- *    platform_device instance).
- *
- *  - model must be filled with the device model name as a NUL-terminated UTF-8
- *    string. The device/model revision must not be stored in this field.
- *
- * The following fields are optional:
- *
- *  - serial is a unique serial number stored as a NUL-terminated ASCII string.
- *    The field is big enough to store a GUID in text form. If the hardware
- *    doesn't provide a unique serial number this field must be left empty.
- *
- *  - bus_info represents the location of the device in the system as a
- *    NUL-terminated ASCII string. For PCI/PCIe devices bus_info must be set to
- *    "PCI:" (or "PCIe:") followed by the value of pci_name(). For USB devices,
- *    the usb_make_path() function must be used. This field is used by
- *    applications to distinguish between otherwise identical devices that don't
- *    provide a serial number.
- *
- *  - hw_revision is the hardware device revision in a driver-specific format.
- *    When possible the revision should be formatted with the KERNEL_VERSION
- *    macro.
- *
- *  - driver_version is formatted with the KERNEL_VERSION macro. The version
- *    minor must be incremented when new features are added to the userspace API
- *    without breaking binary compatibility. The version major must be
- *    incremented when binary compatibility is broken.
- *
- * Upon successful registration a character device named media[0-9]+ is created.
- * The device major and minor numbers are dynamic. The model name is exported as
- * a sysfs attribute.
- *
- * Drivers unregister media device instances by calling
- *
- * 	media_device_unregister(struct media_device *mdev);
- *
- * Unregistering a media device that hasn't been registered is *NOT* safe.
- *
- *
- * Entities, pads and links
- * ------------------------
+ * * Entities, pads and links:
  *
  * - Entities
  *
- * Entities are represented by a struct media_entity instance, defined in
+ * Entities are represented by a struct &media_entity instance, defined in
  * include/media/media-entity.h. The structure is usually embedded into a
  * higher-level structure, such as a v4l2_subdev or video_device instance,
  * although drivers can allocate entities directly.
  *
  * Drivers initialize entity pads by calling
- *
- * 	media_entity_pads_init(struct media_entity *entity, u16 num_pads,
- * 			  struct media_pad *pads);
- *
- * If no pads are needed, drivers could directly fill entity->num_pads
- * with 0 and entity->pads with NULL or to call the above function that
- * will do the same.
- *
- * The media_entity name, type and flags fields should be initialized before
- * calling media_device_register_entity(). Entities embedded in higher-level
- * standard structures can have some of those fields set by the higher-level
- * framework.
- *
- * As the number of pads is known in advance, the pads array is not allocated
- * dynamically but is managed by the entity driver. Most drivers will embed the
- * pads array in a driver-specific structure, avoiding dynamic allocation.
- *
- * Drivers must set the direction of every pad in the pads array before calling
- * media_entity_pads_init. The function will initialize the other pads fields.
- *
- * Unlike the number of pads, the total number of links isn't always known in
- * advance by the entity driver. As an initial estimate, media_entity_pads_init
- * pre-allocates a number of links equal to the number of pads. The links array
- * will be reallocated if it grows beyond the initial estimate.
+ *	media_entity_pads_init().
  *
  * Drivers register entities with a media device by calling
+ *	media_device_register_entity()
+ * and unregistred by calling
+ *	media_device_unregister_entity().
  *
- * 	media_device_register_entity(struct media_device *mdev,
- * 				     struct media_entity *entity);
+ * - Interfaces
  *
- * Entities are identified by a unique positive integer ID. Drivers can provide an
- * ID by filling the media_entity id field prior to registration, or request the
- * media controller framework to assign an ID automatically. Drivers that provide
- * IDs manually must ensure that all IDs are unique. IDs are not guaranteed to be
- * contiguous even when they are all assigned automatically by the framework.
+ * Interfaces are represented by a struct &media_interface instance, defined in
+ * include/media/media-entity.h. Currently, only one type of interface is
+ * defined: a device node. Such interfaces are represented by a struct
+ * &media_intf_devnode.
  *
- * Drivers unregister entities by calling
- *
- * 	media_device_unregister_entity(struct media_entity *entity);
- *
- * Unregistering an entity will not change the IDs of the other entities, and the
- * ID will never be reused for a newly registered entity.
- *
- * When a media device is unregistered, all its entities are unregistered
- * automatically. No manual entities unregistration is then required.
- *
- * Drivers free resources associated with an entity by calling
- *
- * 	media_entity_cleanup(struct media_entity *entity);
- *
- * This function must be called during the cleanup phase after unregistering the
- * entity. Note that the media_entity instance itself must be freed explicitly by
- * the driver if required.
- *
- * Entities have flags that describe the entity capabilities and state.
- *
- * 	MEDIA_ENT_FL_DEFAULT indicates the default entity for a given type.
- * 	This can be used to report the default audio and video devices or the
- * 	default camera sensor.
- *
- * Logical entity groups can be defined by setting the group ID of all member
- * entities to the same non-zero value. An entity group serves no purpose in the
- * kernel, but is reported to userspace during entities enumeration.
- *
- * Media device drivers should define groups if several entities are logically
- * bound together. Example usages include reporting
- *
- * 	- ALSA, VBI and video nodes that carry the same media stream
- * 	- lens and flash controllers associated with a sensor
+ * Drivers initialize and create device node interfaces by calling
+ *	media_devnode_create()
+ * and remove them by calling:
+ *	media_devnode_remove().
  *
  * - Pads
  *
- * Pads are represented by a struct media_pad instance, defined in
+ * Pads are represented by a struct &media_pad instance, defined in
  * include/media/media-entity.h. Each entity stores its pads in a pads array
  * managed by the entity driver. Drivers usually embed the array in a
  * driver-specific structure.
  *
- * Pads are identified by their entity and their 0-based index in the pads array.
- * Both information are stored in the media_pad structure, making the media_pad
- * pointer the canonical way to store and pass link references.
+ * Pads are identified by their entity and their 0-based index in the pads
+ * array.
+ * Both information are stored in the &media_pad structure, making the
+ * &media_pad pointer the canonical way to store and pass link references.
  *
  * Pads have flags that describe the pad capabilities and state.
  *
- * 	MEDIA_PAD_FL_SINK indicates that the pad supports sinking data.
- * 	MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data.
+ *	%MEDIA_PAD_FL_SINK indicates that the pad supports sinking data.
+ *	%MEDIA_PAD_FL_SOURCE indicates that the pad supports sourcing data.
  *
- * One and only one of MEDIA_PAD_FL_SINK and MEDIA_PAD_FL_SOURCE must be set for
- * each pad.
+ * NOTE: One and only one of %MEDIA_PAD_FL_SINK and %MEDIA_PAD_FL_SOURCE must
+ * be set for each pad.
  *
  * - Links
  *
- * Links are represented by a struct media_link instance, defined in
- * include/media/media-entity.h. Each entity stores all links originating at or
- * targeting any of its pads in a links array. A given link is thus stored
- * twice, once in the source entity and once in the target entity. The array is
- * pre-allocated and grows dynamically as needed.
+ * Links are represented by a struct &media_link instance, defined in
+ * include/media/media-entity.h. There are two types of links:
  *
- * Drivers create links by calling
+ * 1. pad to pad links:
  *
- * 	media_create_pad_link(struct media_entity *source, u16 source_pad,
- * 				 struct media_entity *sink,   u16 sink_pad,
- * 				 u32 flags);
+ * Associate two entities via their PADs. Each entity has a list that points
+ * to all links originating at or targeting any of its pads.
+ * A given link is thus stored twice, once in the source entity and once in
+ * the target entity.
  *
- * An entry in the link array of each entity is allocated and stores pointers
- * to source and sink pads.
+ * Drivers create pad to pad links by calling:
+ * 	media_create_pad_link() and remove with media_entity_remove_links().
  *
- * Links have flags that describe the link capabilities and state.
+ * 2. interface to entity links:
  *
- * 	MEDIA_LNK_FL_ENABLED indicates that the link is enabled and can be used
- * 	to transfer media data. When two or more links target a sink pad, only
- * 	one of them can be enabled at a time.
- * 	MEDIA_LNK_FL_IMMUTABLE indicates that the link enabled state can't be
- * 	modified at runtime. If MEDIA_LNK_FL_IMMUTABLE is set, then
- * 	MEDIA_LNK_FL_ENABLED must also be set since an immutable link is always
- * 	enabled.
+ * Associate one interface to a Link.
  *
+ * Drivers create interface to entity links by calling:
+ *	media_create_intf_link() and remove with media_remove_intf_links().
  *
- * Graph traversal
- * ---------------
+ * NOTE:
+ *
+ * Links can only be created after having both ends already created.
+ *
+ * Links have flags that describe the link capabilities and state. The
+ * valid values are described at media_create_pad_link() and
+ * media_create_intf_link().
+ *
+ * Graph traversal:
  *
  * The media framework provides APIs to iterate over entities in a graph.
  *
- * To iterate over all entities belonging to a media device, drivers can use the
- * media_device_for_each_entity macro, defined in include/media/media-device.h.
+ * To iterate over all entities belonging to a media device, drivers can use
+ * the media_device_for_each_entity macro, defined in
+ * include/media/media-device.h.
  *
  * 	struct media_entity *entity;
  *
@@ -279,126 +176,82 @@
  * currently defined as 16.
  *
  * Drivers initiate a graph traversal by calling
- *
- * 	media_entity_graph_walk_start(struct media_entity_graph *graph,
- * 				      struct media_entity *entity);
+ * 	media_entity_graph_walk_start()
  *
  * The graph structure, provided by the caller, is initialized to start graph
  * traversal at the given entity.
  *
  * Drivers can then retrieve the next entity by calling
- *
- * 	media_entity_graph_walk_next(struct media_entity_graph *graph);
+ * 	media_entity_graph_walk_next()
  *
  * When the graph traversal is complete the function will return NULL.
  *
- * Graph traversal can be interrupted at any moment. No cleanup function call is
- * required and the graph structure can be freed normally.
+ * Graph traversal can be interrupted at any moment. No cleanup function call
+ * is required and the graph structure can be freed normally.
  *
  * Helper functions can be used to find a link between two given pads, or a pad
  * connected to another pad through an enabled link
+ * 	media_entity_find_link() and media_entity_remote_pad()
  *
- * 	media_entity_find_link(struct media_pad *source,
- * 			       struct media_pad *sink);
+ * Use count and power handling:
  *
- * 	media_entity_remote_pad(struct media_pad *pad);
+ * Due to the wide differences between drivers regarding power management
+ * needs, the media controller does not implement power management. However,
+ * the &media_entity structure includes a use_count field that media drivers
+ * can use to track the number of users of every entity for power management
+ * needs.
  *
- * Refer to the kerneldoc documentation for more information.
+ * The &media_entity.@use_count field is owned by media drivers and must not be
+ * touched by entity drivers. Access to the field must be protected by the
+ * &media_device.@graph_mutex lock.
  *
- *
- * Use count and power handling
- * ----------------------------
- *
- * Due to the wide differences between drivers regarding power management needs,
- * the media controller does not implement power management. However, the
- * media_entity structure includes a use_count field that media drivers can use to
- * track the number of users of every entity for power management needs.
- *
- * The use_count field is owned by media drivers and must not be touched by entity
- * drivers. Access to the field must be protected by the media device graph_mutex
- * lock.
- *
- *
- * Links setup
- * -----------
+ * Links setup:
  *
  * Link properties can be modified at runtime by calling
+ * 	media_entity_setup_link()
  *
- * 	media_entity_setup_link(struct media_link *link, u32 flags);
- *
- * The flags argument contains the requested new link flags.
- *
- * The only configurable property is the ENABLED link flag to enable/disable a
- * link. Links marked with the IMMUTABLE link flag can not be enabled or disabled.
- *
- * When a link is enabled or disabled, the media framework calls the
- * link_setup operation for the two entities at the source and sink of the link,
- * in that order. If the second link_setup call fails, another link_setup call is
- * made on the first entity to restore the original link flags.
- *
- * Media device drivers can be notified of link setup operations by setting the
- * media_device::link_notify pointer to a callback function. If provided, the
- * notification callback will be called before enabling and after disabling
- * links.
- *
- * Entity drivers must implement the link_setup operation if any of their links
- * is non-immutable. The operation must either configure the hardware or store
- * the configuration information to be applied later.
- *
- * Link configuration must not have any side effect on other links. If an enabled
- * link at a sink pad prevents another link at the same pad from being enabled,
- * the link_setup operation must return -EBUSY and can't implicitly disable the
- * first enabled link.
- *
- *
- * Pipelines and media streams
- * ---------------------------
+ * Pipelines and media streams:
  *
  * When starting streaming, drivers must notify all entities in the pipeline to
  * prevent link states from being modified during streaming by calling
- *
- * 	media_entity_pipeline_start(struct media_entity *entity,
- * 				    struct media_pipeline *pipe);
+ * 	media_entity_pipeline_start().
  *
  * The function will mark all entities connected to the given entity through
  * enabled links, either directly or indirectly, as streaming.
  *
- * The media_pipeline instance pointed to by the pipe argument will be stored in
- * every entity in the pipeline. Drivers should embed the media_pipeline structure
- * in higher-level pipeline structures and can then access the pipeline through
- * the media_entity pipe field.
+ * The &media_pipeline instance pointed to by the pipe argument will be stored
+ * in every entity in the pipeline. Drivers should embed the &media_pipeline
+ * structure in higher-level pipeline structures and can then access the
+ * pipeline through the &media_entity pipe field.
  *
- * Calls to media_entity_pipeline_start() can be nested. The pipeline pointer must
- * be identical for all nested calls to the function.
+ * Calls to media_entity_pipeline_start() can be nested. The pipeline pointer
+ * must be identical for all nested calls to the function.
  *
  * media_entity_pipeline_start() may return an error. In that case, it will
  * clean up any of the changes it did by itself.
  *
  * When stopping the stream, drivers must notify the entities with
- *
- * 	media_entity_pipeline_stop(struct media_entity *entity);
+ * 	media_entity_pipeline_stop().
  *
  * If multiple calls to media_entity_pipeline_start() have been made the same
- * number of media_entity_pipeline_stop() calls are required to stop streaming. The
- * media_entity pipe field is reset to NULL on the last nested stop call.
+ * number of media_entity_pipeline_stop() calls are required to stop streaming.
+ * The &media_entity pipe field is reset to NULL on the last nested stop call.
  *
- * Link configuration will fail with -EBUSY by default if either end of the link is
- * a streaming entity. Links that can be modified while streaming must be marked
- * with the MEDIA_LNK_FL_DYNAMIC flag.
+ * Link configuration will fail with -%EBUSY by default if either end of the
+ * link is a streaming entity. Links that can be modified while streaming must
+ * be marked with the %MEDIA_LNK_FL_DYNAMIC flag.
  *
  * If other operations need to be disallowed on streaming entities (such as
  * changing entities configuration parameters) drivers can explicitly check the
  * media_entity stream_count field to find out if an entity is streaming. This
  * operation must be done with the media_device graph_mutex held.
  *
- *
- * Link validation
- * ---------------
+ * Link validation:
  *
  * Link validation is performed by media_entity_pipeline_start() for any
  * entity which has sink pads in the pipeline. The
- * media_entity::link_validate() callback is used for that purpose. In
- * link_validate() callback, entity driver should check that the properties of
+ * &media_entity.@link_validate() callback is used for that purpose. In
+ * @link_validate() callback, entity driver should check that the properties of
  * the source pad of the connected entity and its own sink pad match. It is up
  * to the type of the entity (and in the end, the properties of the hardware)
  * what matching actually means.
@@ -484,13 +337,113 @@ struct media_device {
 /* media_devnode to media_device */
 #define to_media_device(node) container_of(node, struct media_device, devnode)
 
+/**
+ * __media_device_register() - Registers a media device element
+ *
+ * @mdev:	pointer to struct &media_device
+ * @owner:	should be filled with %THIS_MODULE
+ *
+ * Users, should, instead, call the media_device_register() macro.
+ *
+ * The caller is responsible for initializing the media_device structure before
+ * registration. The following fields must be set:
+ *
+ *  - dev must point to the parent device (usually a &pci_dev, &usb_interface or
+ *    &platform_device instance).
+ *
+ *  - model must be filled with the device model name as a NUL-terminated UTF-8
+ *    string. The device/model revision must not be stored in this field.
+ *
+ * The following fields are optional:
+ *
+ *  - serial is a unique serial number stored as a NUL-terminated ASCII string.
+ *    The field is big enough to store a GUID in text form. If the hardware
+ *    doesn't provide a unique serial number this field must be left empty.
+ *
+ *  - bus_info represents the location of the device in the system as a
+ *    NUL-terminated ASCII string. For PCI/PCIe devices bus_info must be set to
+ *    "PCI:" (or "PCIe:") followed by the value of pci_name(). For USB devices,
+ *    the usb_make_path() function must be used. This field is used by
+ *    applications to distinguish between otherwise identical devices that don't
+ *    provide a serial number.
+ *
+ *  - hw_revision is the hardware device revision in a driver-specific format.
+ *    When possible the revision should be formatted with the KERNEL_VERSION
+ *    macro.
+ *
+ *  - driver_version is formatted with the KERNEL_VERSION macro. The version
+ *    minor must be incremented when new features are added to the userspace API
+ *    without breaking binary compatibility. The version major must be
+ *    incremented when binary compatibility is broken.
+ *
+ * Notes:
+ *
+ * Upon successful registration a character device named media[0-9]+ is created.
+ * The device major and minor numbers are dynamic. The model name is exported as
+ * a sysfs attribute.
+ *
+ * Unregistering a media device that hasn't been registered is *NOT* safe.
+ */
 int __must_check __media_device_register(struct media_device *mdev,
 					 struct module *owner);
 #define media_device_register(mdev) __media_device_register(mdev, THIS_MODULE)
+
+/**
+ * __media_device_unregister() - Unegisters a media device element
+ *
+ * @mdev:	pointer to struct &media_device
+ */
 void media_device_unregister(struct media_device *mdev);
 
+/**
+ * media_device_register_entity() - registers a media entity inside a
+ *	previously registered media device.
+ *
+ * @mdev:	pointer to struct &media_device
+ * @entity:	pointer to struct &media_entity to be registered
+ *
+ * Entities are identified by a unique positive integer ID. The media
+ * controller framework will such ID automatically. IDs are not guaranteed
+ * to be contiguous, and the ID number can change on newer Kernel versions.
+ * So, neither the driver nor userspace should hardcode ID numbers to refer
+ * to the entities, but, instead, use the framework to find the ID, when
+ * needed.
+ *
+ * The media_entity name, type and flags fields should be initialized before
+ * calling media_device_register_entity(). Entities embedded in higher-level
+ * standard structures can have some of those fields set by the higher-level
+ * framework.
+ *
+ * If the device has pads, media_entity_pads_init() should be called before
+ * this function. Otherwise, the &media_entity.@pad and &media_entity.@num_pads
+ * should be zeroed before calling this function.
+ *
+ * Entities have flags that describe the entity capabilities and state:
+ *
+ * %MEDIA_ENT_FL_DEFAULT indicates the default entity for a given type.
+ * 	This can be used to report the default audio and video devices or the
+ * 	default camera sensor.
+ */
 int __must_check media_device_register_entity(struct media_device *mdev,
 					      struct media_entity *entity);
+
+/*
+ * media_device_unregister_entity() - unregisters a media entity.
+ *
+ * @entity:	pointer to struct &media_entity to be unregistered
+ *
+ * All links associated with the entity and all PADs are automatically
+ * unregistered from the media_device when this function is called.
+ *
+ * Unregistering an entity will not change the IDs of the other entities and
+ * the previoully used ID will never be reused for a newly registered entities.
+ *
+ * When a media device is unregistered, all its entities are unregistered
+ * automatically. No manual entities unregistration is then required.
+ *
+ * Note: the media_entity instance itself must be freed explicitly by
+ * the driver if required.
+ */
 void media_device_unregister_entity(struct media_entity *entity);
 struct media_device *media_device_get_devres(struct device *dev);
 struct media_device *media_device_find_devres(struct device *dev);
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index e9bc5857899c..51a7353effd0 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -343,18 +343,112 @@ void media_gobj_init(struct media_device *mdev,
 		    struct media_gobj *gobj);
 void media_gobj_remove(struct media_gobj *gobj);
 
+/**
+ * media_entity_pads_init() - Initialize the entity pads
+ *
+ * @entity:	entity where the pads belong
+ * @num_pads:	number of pads to be initialized
+ * @pads:	pads array
+ *
+ * If no pads are needed, drivers could either directly fill
+ * &media_entity->@num_pads with 0 and &media_entity->@pads with NULL or call
+ * this function that will do the same.
+ *
+ * As the number of pads is known in advance, the pads array is not allocated
+ * dynamically but is managed by the entity driver. Most drivers will embed the
+ * pads array in a driver-specific structure, avoiding dynamic allocation.
+ *
+ * Drivers must set the direction of every pad in the pads array before calling
+ * media_entity_pads_init(). The function will initialize the other pads fields.
+ */
 int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
 		      struct media_pad *pads);
 
+/**
+ * media_entity_cleanup() - free resources associated with an entity
+ *
+ * @entity:	entity where the pads belong
+ *
+ * This function must be called during the cleanup phase after unregistering
+ * the entity (currently, it does nothing).
+ */
 static inline void media_entity_cleanup(struct media_entity *entity) {};
 
+/**
+ * media_create_pad_link() - creates a link between two entities.
+ *
+ * @source:	pointer to &media_entity of the source pad.
+ * @source_pad:	number of the source pad in the pads array
+ * @sink:	pointer to &media_entity of the sink pad.
+ * @sink_pad:	number of the sink pad in the pads array.
+ * @flags:	Link flags, as defined in include/uapi/linux/media.h.
+ *
+ * Valid values for flags:
+ * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be
+ *	used to transfer media data. When two or more links target a sink pad,
+ *	only one of them can be enabled at a time.
+ *
+ * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't
+ *	be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then
+ *	%MEDIA_LNK_FL_ENABLED must also be set since an immutable link is
+ *	always enabled.
+ *
+ * NOTE:
+ *
+ * Before calling this function, media_entity_pads_init() and
+ * media_device_register_entity() should be called previously for both ends.
+ */
 __must_check int media_create_pad_link(struct media_entity *source,
 			u16 source_pad, struct media_entity *sink,
 			u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
+
+/**
+ * media_entity_remove_links() - remove all links associated with an entity
+ *
+ * @entity:	pointer to &media_entity
+ *
+ * Note: this is called automatically when an entity is unregistered via
+ * media_device_register_entity().
+ */
 void media_entity_remove_links(struct media_entity *entity);
 
 int __media_entity_setup_link(struct media_link *link, u32 flags);
+
+/**
+ * media_entity_setup_link() - changes the link flags properties in runtime
+ *
+ * @link:	pointer to &media_link
+ * @flags:	the requested new link flags
+ *
+ * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag
+ * flag to enable/disable a link. Links marked with the
+ * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled.
+ *
+ * When a link is enabled or disabled, the media framework calls the
+ * link_setup operation for the two entities at the source and sink of the
+ * link, in that order. If the second link_setup call fails, another
+ * link_setup call is made on the first entity to restore the original link
+ * flags.
+ *
+ * Media device drivers can be notified of link setup operations by setting the
+ * media_device::link_notify pointer to a callback function. If provided, the
+ * notification callback will be called before enabling and after disabling
+ * links.
+ *
+ * Entity drivers must implement the link_setup operation if any of their links
+ * is non-immutable. The operation must either configure the hardware or store
+ * the configuration information to be applied later.
+ *
+ * Link configuration must not have any side effect on other links. If an
+ * enabled link at a sink pad prevents another link at the same pad from
+ * being enabled, the link_setup operation must return -EBUSY and can't
+ * implicitly disable the first enabled link.
+ *
+ * NOTE: the valid values of the flags for the link is the same as described
+ * on media_create_pad_link(), for pad to pad links or the same as described
+ * on media_create_intf_link(), for interface to entity links.
+ */
 int media_entity_setup_link(struct media_link *link, u32 flags);
 struct media_link *media_entity_find_link(struct media_pad *source,
 		struct media_pad *sink);
@@ -371,18 +465,72 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe);
 void media_entity_pipeline_stop(struct media_entity *entity);
 
+/**
+ * media_devnode_create() - creates and initializes a device node interface
+ *
+ * @mdev:	pointer to struct &media_device
+ * @type:	type of the interface, as given by MEDIA_INTF_T_* macros
+ *		as defined in the uapi/media/media.h header.
+ * @flags:	Interface flags as defined in uapi/media/media.h.
+ * @major:	Device node major number.
+ * @minor:	Device node minor number.
+ *
+ * Return: if succeeded, returns a pointer to the newly allocated
+ *	&media_intf_devnode pointer.
+ */
 struct media_intf_devnode *
 __must_check media_devnode_create(struct media_device *mdev,
 				  u32 type, u32 flags,
 				  u32 major, u32 minor);
+/**
+ * media_devnode_remove() - removes a device node interface
+ *
+ * @devnode:	pointer to &media_intf_devnode to be freed.
+ *
+ * When a device node interface is removed, all links to it are automatically
+ * removed.
+ */
 void media_devnode_remove(struct media_intf_devnode *devnode);
 struct media_link *
+
+/**
+ * media_create_intf_link() - creates a link between an entity and an interface
+ *
+ * @entity:	pointer to %media_entity
+ * @intf:	pointer to %media_interface
+ * @flags:	Link flags, as defined in include/uapi/linux/media.h.
+ *
+ *
+ * Valid values for flags:
+ * The %MEDIA_LNK_FL_ENABLED flag indicates that the interface is connected to
+ *	the entity hardware. That's the default value for interfaces. An
+ *	interface may be disabled if the hardware is busy due to the usage
+ *	of some other interface that it is currently controlling the hardware.
+ *	A typical example is an hybrid TV device that handle only one type of
+ *	stream on a given time. So, when the digital TV is streaming,
+ *	the V4L2 interfaces won't be enabled, as such device is not able to
+ *	also stream analog TV or radio.
+ *
+ * Note:
+ *
+ * Before calling this function, media_devnode_create() should be called for
+ * the interface and media_device_register_entity() should be called for the
+ * interface that will be part of the link.
+ */
 __must_check 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_link(struct media_link *link);
 void __media_remove_intf_links(struct media_interface *intf);
+/**
+ * media_remove_intf_links() - remove all links associated with an interface
+ *
+ * @intf:	pointer to &media_interface
+ *
+ * Note: this is called automatically when an entity is unregistered via
+ * media_device_register_entity() and by media_devnode_remove().
+ */
 void media_remove_intf_links(struct media_interface *intf);
 
 
-- 
2.5.0



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

* [PATCH 08/10] media-entity.c: remove two extra blank lines
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
                   ` (6 preceding siblings ...)
  2015-12-11 13:34 ` [PATCH 07/10] media-device.h: Improve documentation and update it Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 09/10] media-entity: get rid of forward __media_entity_remove_link() declaration Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 10/10] media_entity: get rid of an unused var Mauro Carvalho Chehab
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

No functional changes.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/media-entity.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 849db4f6f1f3..5a5432524c10 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -310,7 +310,6 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
 
-
 /**
  * media_entity_graph_walk_next - Get the next entity in the graph
  * @graph: Media graph structure
@@ -850,7 +849,6 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
 
-
 static void media_interface_init(struct media_device *mdev,
 				 struct media_interface *intf,
 				 u32 gobj_type,
@@ -915,7 +913,6 @@ struct media_link *media_create_intf_link(struct media_entity *entity,
 }
 EXPORT_SYMBOL_GPL(media_create_intf_link);
 
-
 void __media_remove_intf_link(struct media_link *link)
 {
 	list_del(&link->list);
-- 
2.5.0



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

* [PATCH 09/10] media-entity: get rid of forward __media_entity_remove_link() declaration
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
                   ` (7 preceding siblings ...)
  2015-12-11 13:34 ` [PATCH 08/10] media-entity.c: remove two extra blank lines Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  2015-12-11 13:34 ` [PATCH 10/10] media_entity: get rid of an unused var Mauro Carvalho Chehab
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

Move this function to happen earlier, in order to avoid
a uneeded forward declaration.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/media-entity.c | 67 +++++++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 35 deletions(-)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 5a5432524c10..452af1d5a20d 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -588,7 +588,38 @@ static struct media_link *media_add_link(struct list_head *head)
 }
 
 static void __media_entity_remove_link(struct media_entity *entity,
-				       struct media_link *link);
+				       struct media_link *link)
+{
+	struct media_link *rlink, *tmp;
+	struct media_entity *remote;
+	unsigned int r = 0;
+
+	if (link->source->entity == entity)
+		remote = link->sink->entity;
+	else
+		remote = link->source->entity;
+
+	list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
+		if (rlink != link->reverse) {
+			r++;
+			continue;
+		}
+
+		if (link->source->entity == entity)
+			remote->num_backlinks--;
+
+		/* Remove the remote link */
+		list_del(&rlink->list);
+		media_gobj_remove(&rlink->graph_obj);
+		kfree(rlink);
+
+		if (--remote->num_links == 0)
+			break;
+	}
+	list_del(&link->list);
+	media_gobj_remove(&link->graph_obj);
+	kfree(link);
+}
 
 int
 media_create_pad_link(struct media_entity *source, u16 source_pad,
@@ -642,40 +673,6 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 }
 EXPORT_SYMBOL_GPL(media_create_pad_link);
 
-static void __media_entity_remove_link(struct media_entity *entity,
-				       struct media_link *link)
-{
-	struct media_link *rlink, *tmp;
-	struct media_entity *remote;
-	unsigned int r = 0;
-
-	if (link->source->entity == entity)
-		remote = link->sink->entity;
-	else
-		remote = link->source->entity;
-
-	list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
-		if (rlink != link->reverse) {
-			r++;
-			continue;
-		}
-
-		if (link->source->entity == entity)
-			remote->num_backlinks--;
-
-		/* Remove the remote link */
-		list_del(&rlink->list);
-		media_gobj_remove(&rlink->graph_obj);
-		kfree(rlink);
-
-		if (--remote->num_links == 0)
-			break;
-	}
-	list_del(&link->list);
-	media_gobj_remove(&link->graph_obj);
-	kfree(link);
-}
-
 void __media_entity_remove_links(struct media_entity *entity)
 {
 	struct media_link *link, *tmp;
-- 
2.5.0



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

* [PATCH 10/10] media_entity: get rid of an unused var
  2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
                   ` (8 preceding siblings ...)
  2015-12-11 13:34 ` [PATCH 09/10] media-entity: get rid of forward __media_entity_remove_link() declaration Mauro Carvalho Chehab
@ 2015-12-11 13:34 ` Mauro Carvalho Chehab
  9 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2015-12-11 13:34 UTC (permalink / raw)
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List,
	Mauro Carvalho Chehab

> > > +		if (rlink != link->reverse) {
> > > +			r++;
> >
> > The variable is incremented here but otherwise never used, you can remove it.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
---
 drivers/media/media-entity.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 452af1d5a20d..57de11281af1 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -592,7 +592,6 @@ static void __media_entity_remove_link(struct media_entity *entity,
 {
 	struct media_link *rlink, *tmp;
 	struct media_entity *remote;
-	unsigned int r = 0;
 
 	if (link->source->entity == entity)
 		remote = link->sink->entity;
@@ -600,10 +599,8 @@ static void __media_entity_remove_link(struct media_entity *entity,
 		remote = link->source->entity;
 
 	list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
-		if (rlink != link->reverse) {
-			r++;
+		if (rlink != link->reverse)
 			continue;
-		}
 
 		if (link->source->entity == entity)
 			remote->num_backlinks--;
-- 
2.5.0



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

* Re: [PATCH 03/10] media framework: rename pads init function to media_entity_pads_init()
  2015-12-11 13:34 ` [PATCH 03/10] media framework: rename pads init function to media_entity_pads_init() Mauro Carvalho Chehab
@ 2015-12-11 14:04   ` Jacek Anaszewski
  0 siblings, 0 replies; 12+ messages in thread
From: Jacek Anaszewski @ 2015-12-11 14:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, Jonathan Corbet,
	Harry Wei, Hans Verkuil, Sakari Ailus, Lars-Peter Clausen,
	Laurent Pinchart, Kyungmin Park, Lad, Prabhakar, Andrzej Hajda,
	Mats Randgaard, Sylwester Nawrocki, Kukjin Kim,
	Krzysztof Kozlowski, Hyun Kwon, Michal Simek,
	S철ren Brinkmann, Greg Kroah-Hartman,
	Rafael Louren챌o de Lima Chehab, Arnd Bergmann,
	Andrew Morton, Javier Martinez Canillas, Guennadi Liakhovetski,
	Ricardo Ribalda Delgado, Shuah Khan, Junghak Sung, Geunyoung Kim,
	Julia Lawall, Steven Rostedt, Bryan Wu, Shraddha Barke,
	Aya Mahfouz, Junsu Shin, Haneen Mohammed, Navya Sri Nizamkari,
	Nicholas Mc Guire, Inki Dae, linux-doc, linux-kernel,
	linux-arm-kernel, linux-samsung-soc, linux-sh, devel

On 12/11/2015 02:34 PM, Mauro Carvalho Chehab wrote:
> With the MC next gen rework, what's left for media_entity_init()
> is to just initialize the PADs. However, certain devices, like
> a FLASH led/light doesn't have any input or output PAD.
>
> So, there's no reason why calling media_entity_init() would be
> mandatory. Also, despite its name, what this function actually
> does is to initialize the PADs data. So, rename it to
> media_entity_pads_init() in order to reflect that.
>
> The media entity actual init happens during entity register,
> at media_device_register_entity(). We should move init of
> num_links and num_backlinks to it.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
[...]
> diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c
> index 5c686a24712b..13d5a36bc5d8 100644
> --- a/drivers/media/v4l2-core/v4l2-flash-led-class.c
> +++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c
> @@ -651,7 +651,7 @@ struct v4l2_flash *v4l2_flash_init(
>   	sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
>   	strlcpy(sd->name, config->dev_name, sizeof(sd->name));
>
> -	ret = media_entity_init(&sd->entity, 0, NULL);
> +	ret = media_entity_pads_init(&sd->entity, 0, NULL);
>   	if (ret < 0)
>   		return ERR_PTR(ret);
>

For this part:

Acked-by: Jacek Anaszewski <j.anaszewski@samsung.com>

-- 
Best Regards,
Jacek Anaszewski

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

end of thread, other threads:[~2015-12-11 14:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-11 13:34 [PATCH 00/10] Some cleanups after the Media Controller Next gen Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 01/10] media-device: put headers in alphabetic order Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 02/10] media-device: better name Kernelspace/Userspace links Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 03/10] media framework: rename pads init function to media_entity_pads_init() Mauro Carvalho Chehab
2015-12-11 14:04   ` Jacek Anaszewski
2015-12-11 13:34 ` [PATCH 04/10] media-entity.h: get rid of revision and group_id fields Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 05/10] DocBook: Move media-framework.txt contend to media-device.h Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 06/10] media-entity.h: convert media_entity_cleanup to inline Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 07/10] media-device.h: Improve documentation and update it Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 08/10] media-entity.c: remove two extra blank lines Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 09/10] media-entity: get rid of forward __media_entity_remove_link() declaration Mauro Carvalho Chehab
2015-12-11 13:34 ` [PATCH 10/10] media_entity: get rid of an unused var Mauro Carvalho Chehab

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