linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] media add change_source handler support
@ 2016-03-10  5:07 Shuah Khan
  2016-03-10  5:07 ` [PATCH 1/4] media: add change_source handler function pointer Shuah Khan
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Shuah Khan @ 2016-03-10  5:07 UTC (permalink / raw)
  To: mchehab, hans.verkuil, chehabrafael, javier, inki.dae,
	jh1009.sung, sakari.ailus
  Cc: Shuah Khan, linux-media, linux-kernel

This patch series:
1. Adds change_source function pointer to struct media_device. Using
   the change_source handler, driver can disable current source and
   enable new one in one step when user selects a new input.
2. Add a new common v4l interface to call change_source handler
3. Add change_source hanlder to au0828-core
4. Change change vidioc_s_input() to call v4l_change_media_source()

Shuah Khan (4):
  media: add change_source handler function pointer
  media: v4l2-mc add v4l_change_media_source() to invoke change_source
  media: au0828 add media device change_source handler
  media: au0828 change vidioc_s_input() to call
    v4l_change_media_source()

 drivers/media/usb/au0828/au0828-core.c  | 64 +++++++++++++++++++++++----------
 drivers/media/usb/au0828/au0828-video.c |  8 ++---
 drivers/media/v4l2-core/v4l2-mc.c       | 14 ++++++++
 include/media/media-device.h            | 18 ++++++++--
 include/media/v4l2-mc.h                 | 20 ++++++++++-
 5 files changed, 97 insertions(+), 27 deletions(-)

-- 
2.5.0

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

* [PATCH 1/4] media: add change_source handler function pointer
  2016-03-10  5:07 [PATCH 0/4] media add change_source handler support Shuah Khan
@ 2016-03-10  5:07 ` Shuah Khan
  2016-03-10  5:07 ` [PATCH 2/4] media: v4l2-mc add v4l_change_media_source() to invoke change_source Shuah Khan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2016-03-10  5:07 UTC (permalink / raw)
  To: mchehab, hans.verkuil, chehabrafael, javier, inki.dae,
	jh1009.sung, sakari.ailus
  Cc: Shuah Khan, linux-media, linux-kernel

Add change_source handler function pointer to struct media_device. Using
the change_source handler, driver can disable current source and enable
new one in one step when user selects a new input.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 include/media/media-device.h | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/include/media/media-device.h b/include/media/media-device.h
index df74cfa..d9867ed 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -309,9 +309,11 @@ struct media_entity_notify {
  * @pm_count_walk: Graph walk for power state walk. Access serialised using
  *		   graph_mutex.
  *
- * @source_priv: Driver Private data for enable/disable source handlers
+ * @source_priv: Driver Private data for enable/disable/change source
+ *		 handlers
  * @enable_source: Enable Source Handler function pointer
  * @disable_source: Disable Source Handler function pointer
+ * @change_source: Change Source Handler function pointer
  *
  * @link_notify: Link state change notification callback
  *
@@ -326,14 +328,22 @@ struct media_entity_notify {
  * be unique.
  *
  * @enable_source is a handler to find source entity for the
- * sink entity  and activate the link between them if source
+ * sink entity and activate the link between them if source
  * entity is free. Drivers should call this handler before
  * accessing the source.
  *
  * @disable_source is a handler to find source entity for the
- * sink entity  and deactivate the link between them. Drivers
+ * sink entity and deactivate the link between them. Drivers
  * should call this handler to release the source.
  *
+ * @change_source is a handler to find source entity for the
+ * sink entity and deactivate the link between them. Once the
+ * existing link is deactivated, it will find and activate the
+ * source for the sink for the newly selected input. Drivers
+ * should call this handler to change the source when user
+ * changes input. Using change_source helps not loose the hold
+ * on the media resource when a new input is selected.
+ *
  * Note: Bridge driver is expected to implement and set the
  * handler when media_device is registered or when
  * bridge driver finds the media_device during probe.
@@ -381,6 +391,8 @@ struct media_device {
 	int (*enable_source)(struct media_entity *entity,
 			     struct media_pipeline *pipe);
 	void (*disable_source)(struct media_entity *entity);
+	int (*change_source)(struct media_entity *entity,
+			     struct media_pipeline *pipe);
 
 	int (*link_notify)(struct media_link *link, u32 flags,
 			   unsigned int notification);
-- 
2.5.0

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

* [PATCH 2/4] media: v4l2-mc add v4l_change_media_source() to invoke change_source
  2016-03-10  5:07 [PATCH 0/4] media add change_source handler support Shuah Khan
  2016-03-10  5:07 ` [PATCH 1/4] media: add change_source handler function pointer Shuah Khan
@ 2016-03-10  5:07 ` Shuah Khan
  2016-03-10  5:07 ` [PATCH 3/4] media: au0828 add media device change_source handler Shuah Khan
  2016-03-10  5:07 ` [PATCH 4/4] media: au0828 change vidioc_s_input() to call v4l_change_media_source() Shuah Khan
  3 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2016-03-10  5:07 UTC (permalink / raw)
  To: mchehab, hans.verkuil, chehabrafael, javier, inki.dae,
	jh1009.sung, sakari.ailus
  Cc: Shuah Khan, linux-media, linux-kernel

Add a common routine to invoke media device change_source handler.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/v4l2-core/v4l2-mc.c | 14 ++++++++++++++
 include/media/v4l2-mc.h           | 20 +++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c
index ae661ac..478b2768 100644
--- a/drivers/media/v4l2-core/v4l2-mc.c
+++ b/drivers/media/v4l2-core/v4l2-mc.c
@@ -217,6 +217,20 @@ void v4l_disable_media_source(struct video_device *vdev)
 }
 EXPORT_SYMBOL_GPL(v4l_disable_media_source);
 
+int v4l_change_media_source(struct video_device *vdev)
+{
+	struct media_device *mdev = vdev->entity.graph_obj.mdev;
+	int ret;
+
+	if (!mdev || !mdev->change_source)
+		return 0;
+	ret = mdev->change_source(&vdev->entity, &vdev->pipe);
+	if (ret)
+		return -EBUSY;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(v4l_change_media_source);
+
 int v4l_vb2q_enable_media_source(struct vb2_queue *q)
 {
 	struct v4l2_fh *fh = q->owner;
diff --git a/include/media/v4l2-mc.h b/include/media/v4l2-mc.h
index 98a938a..884b969 100644
--- a/include/media/v4l2-mc.h
+++ b/include/media/v4l2-mc.h
@@ -154,8 +154,26 @@ int v4l_enable_media_source(struct video_device *vdev);
  */
 void v4l_disable_media_source(struct video_device *vdev);
 
+/**
+ * v4l_change_media_source() -	Hold media source for exclusive use
+ *				if free
+ *
+ * @vdev:	pointer to struct video_device
+ *
+ * This interface calls change_source handler to change
+ * the current source it is holding. The change_source
+ * disables the current source and starts pipeline to
+ * the new source. This interface should be used when
+ * user changes source using s_input handler to keep
+ * the previously granted permission for exclusive use
+ * with a new input source.
+ *
+ * Return: returns zero on success or a negative error code.
+ */
+int v4l_change_media_source(struct video_device *vdev);
+
 /*
- * v4l_vb2q_enable_media_tuner -  Hold media source for exclusive use
+ * v4l_vb2q_enable_media_source - Hold media source for exclusive use
  *				  if free.
  * @q - pointer to struct vb2_queue
  *
-- 
2.5.0

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

* [PATCH 3/4] media: au0828 add media device change_source handler
  2016-03-10  5:07 [PATCH 0/4] media add change_source handler support Shuah Khan
  2016-03-10  5:07 ` [PATCH 1/4] media: add change_source handler function pointer Shuah Khan
  2016-03-10  5:07 ` [PATCH 2/4] media: v4l2-mc add v4l_change_media_source() to invoke change_source Shuah Khan
@ 2016-03-10  5:07 ` Shuah Khan
  2016-03-10  5:07 ` [PATCH 4/4] media: au0828 change vidioc_s_input() to call v4l_change_media_source() Shuah Khan
  3 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2016-03-10  5:07 UTC (permalink / raw)
  To: mchehab, hans.verkuil, chehabrafael, javier, inki.dae,
	jh1009.sung, sakari.ailus
  Cc: Shuah Khan, linux-media, linux-kernel

Add media device change_source handler. Using the change_source handler,
driver can disable current source and enable new one in one step when
user selects a new input.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-core.c | 64 ++++++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 18 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 5dc82e8..01dba5a 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -258,8 +258,8 @@ create_link:
 	}
 }
 
-static int au0828_enable_source(struct media_entity *entity,
-				struct media_pipeline *pipe)
+static int __au0828_enable_source(struct media_entity *entity,
+				  struct media_pipeline *pipe)
 {
 	struct media_entity  *source, *find_source;
 	struct media_entity *sink;
@@ -268,11 +268,6 @@ static int au0828_enable_source(struct media_entity *entity,
 	struct media_device *mdev = entity->graph_obj.mdev;
 	struct au0828_dev *dev;
 
-	if (!mdev)
-		return -ENODEV;
-
-	mutex_lock(&mdev->graph_mutex);
-
 	dev = mdev->source_priv;
 
 	/*
@@ -399,28 +394,36 @@ static int au0828_enable_source(struct media_entity *entity,
 		 dev->active_source->name, dev->active_sink->name,
 		 dev->active_link_owner->name, ret);
 end:
-	mutex_unlock(&mdev->graph_mutex);
 	pr_debug("au0828_enable_source() end %s %d %d\n",
 		 entity->name, entity->function, ret);
 	return ret;
 }
 
-static void au0828_disable_source(struct media_entity *entity)
+static int au0828_enable_source(struct media_entity *entity,
+				struct media_pipeline *pipe)
 {
-	int ret = 0;
 	struct media_device *mdev = entity->graph_obj.mdev;
-	struct au0828_dev *dev;
+	int ret;
 
 	if (!mdev)
-		return;
+		return -ENODEV;
 
 	mutex_lock(&mdev->graph_mutex);
+	ret = __au0828_enable_source(entity, pipe);
+	mutex_unlock(&mdev->graph_mutex);
+	return ret;
+}
+
+static void __au0828_disable_source(struct media_entity *entity)
+{
+	int ret = 0;
+	struct media_device *mdev = entity->graph_obj.mdev;
+	struct au0828_dev *dev;
+
 	dev = mdev->source_priv;
 
-	if (!dev->active_link) {
-		ret = -ENODEV;
-		goto end;
-	}
+	if (!dev->active_link)
+		return;
 
 	/* link is active - stop pipeline from source (tuner) */
 	if (dev->active_link->sink->entity == dev->active_sink &&
@@ -430,7 +433,7 @@ static void au0828_disable_source(struct media_entity *entity)
 		 * has active pipeline
 		*/
 		if (dev->active_link_owner != entity)
-			goto end;
+			return;
 		__media_entity_pipeline_stop(entity);
 		ret = __media_entity_setup_link(dev->active_link, 0);
 		if (ret)
@@ -445,10 +448,34 @@ static void au0828_disable_source(struct media_entity *entity)
 		dev->active_source = NULL;
 		dev->active_sink = NULL;
 	}
+}
 
-end:
+static void au0828_disable_source(struct media_entity *entity)
+{
+	struct media_device *mdev = entity->graph_obj.mdev;
+
+	if (!mdev)
+		return;
+
+	mutex_lock(&mdev->graph_mutex);
+	__au0828_disable_source(entity);
 	mutex_unlock(&mdev->graph_mutex);
 }
+static int au0828_change_source(struct media_entity *entity,
+				struct media_pipeline *pipe)
+{
+	struct media_device *mdev = entity->graph_obj.mdev;
+	int ret;
+
+	if (!mdev)
+		return -ENODEV;
+
+	mutex_lock(&mdev->graph_mutex);
+	__au0828_disable_source(entity);
+	ret = __au0828_enable_source(entity, pipe);
+	mutex_unlock(&mdev->graph_mutex);
+	return ret;
+}
 #endif
 
 static int au0828_media_device_register(struct au0828_dev *dev,
@@ -520,6 +547,7 @@ static int au0828_media_device_register(struct au0828_dev *dev,
 	dev->media_dev->source_priv = (void *) dev;
 	dev->media_dev->enable_source = au0828_enable_source;
 	dev->media_dev->disable_source = au0828_disable_source;
+	dev->media_dev->change_source = au0828_change_source;
 #endif
 	return 0;
 }
-- 
2.5.0

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

* [PATCH 4/4] media: au0828 change vidioc_s_input() to call v4l_change_media_source()
  2016-03-10  5:07 [PATCH 0/4] media add change_source handler support Shuah Khan
                   ` (2 preceding siblings ...)
  2016-03-10  5:07 ` [PATCH 3/4] media: au0828 add media device change_source handler Shuah Khan
@ 2016-03-10  5:07 ` Shuah Khan
  2016-03-10  6:55   ` kbuild test robot
  3 siblings, 1 reply; 6+ messages in thread
From: Shuah Khan @ 2016-03-10  5:07 UTC (permalink / raw)
  To: mchehab, hans.verkuil, chehabrafael, javier, inki.dae,
	jh1009.sung, sakari.ailus
  Cc: Shuah Khan, linux-media, linux-kernel

Change vidioc_s_input() to call v4l_change_media_source() to disable
current source and enable new source when user switches input.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
---
 drivers/media/usb/au0828/au0828-video.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index aeaf27e..020c9d5 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -1545,12 +1545,10 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
 	au0828_s_input(dev, index);
 
 	/*
-	 * Input has been changed. Disable the media source
-	 * associated with the old input and enable source
-	 * for the newly set input
+	 * Input has been changed. Change to media source
+	 * associated with the for the newly set input.
 	 */
-	v4l_disable_media_source(vfd);
-	return v4l_enable_media_source(vfd);
+	return v4l_change_media_source(vfd);
 }
 
 static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a)
-- 
2.5.0

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

* Re: [PATCH 4/4] media: au0828 change vidioc_s_input() to call v4l_change_media_source()
  2016-03-10  5:07 ` [PATCH 4/4] media: au0828 change vidioc_s_input() to call v4l_change_media_source() Shuah Khan
@ 2016-03-10  6:55   ` kbuild test robot
  0 siblings, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2016-03-10  6:55 UTC (permalink / raw)
  To: Shuah Khan
  Cc: kbuild-all, mchehab, hans.verkuil, chehabrafael, javier,
	inki.dae, jh1009.sung, sakari.ailus, Shuah Khan, linux-media,
	linux-kernel

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

Hi Shuah,

[auto build test ERROR on sailus-media/master]
[cannot apply to v4.5-rc7 next-20160309]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Shuah-Khan/media-add-change_source-handler-support/20160310-131140
base:   git://linuxtv.org/media_tree.git master
config: x86_64-rhel (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/media/usb/au0828/au0828-video.c: In function 'vidioc_s_input':
>> drivers/media/usb/au0828/au0828-video.c:1474:2: error: implicit declaration of function 'v4l_change_media_source' [-Werror=implicit-function-declaration]
     return v4l_change_media_source(vfd);
     ^
   cc1: some warnings being treated as errors

vim +/v4l_change_media_source +1474 drivers/media/usb/au0828/au0828-video.c

  1468		au0828_s_input(dev, index);
  1469	
  1470		/*
  1471		 * Input has been changed. Change to media source
  1472		 * associated with the for the newly set input.
  1473		 */
> 1474		return v4l_change_media_source(vfd);
  1475	}
  1476	
  1477	static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a)

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 36083 bytes --]

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10  5:07 [PATCH 0/4] media add change_source handler support Shuah Khan
2016-03-10  5:07 ` [PATCH 1/4] media: add change_source handler function pointer Shuah Khan
2016-03-10  5:07 ` [PATCH 2/4] media: v4l2-mc add v4l_change_media_source() to invoke change_source Shuah Khan
2016-03-10  5:07 ` [PATCH 3/4] media: au0828 add media device change_source handler Shuah Khan
2016-03-10  5:07 ` [PATCH 4/4] media: au0828 change vidioc_s_input() to call v4l_change_media_source() Shuah Khan
2016-03-10  6:55   ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).