From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Hans Verkuil <hverkuil@xs4all.nl>
Cc: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
tomoharu.fukawa.eb@renesas.com,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Geert Uytterhoeven" <geert@linux-m68k.org>,
"Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Subject: [PATCHv2 27/32] media: rcar-vin: start/stop the CSI2 bridge stream
Date: Sat, 12 Nov 2016 14:12:11 +0100 [thread overview]
Message-ID: <20161112131216.22635-28-niklas.soderlund+renesas@ragnatech.se> (raw)
In-Reply-To: <20161112131216.22635-1-niklas.soderlund+renesas@ragnatech.se>
On Gen3 the CSI2 bridge stream needs to be start/stop in conjunction
with the video source. Create helpers to deal with both the Gen2 single
subdevice case and the Gen3 CSI2 group case.
In the Gen3 case there might be other simultaneous users of the bridge
and source devices so examine each entity stream_count before acting on
any particular device.
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
drivers/media/platform/rcar-vin/rcar-dma.c | 84 +++++++++++++++++++++++++++---
1 file changed, 77 insertions(+), 7 deletions(-)
diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c b/drivers/media/platform/rcar-vin/rcar-dma.c
index 322e4c1..872f138 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -1089,15 +1089,87 @@ static void rvin_buffer_queue(struct vb2_buffer *vb)
spin_unlock_irqrestore(&vin->qlock, flags);
}
+static int __rvin_start_streaming(struct rvin_dev *vin)
+{
+ struct v4l2_subdev *source, *bridge = NULL;
+ struct media_pipeline *pipe;
+ int ret;
+
+ source = vin_to_source(vin);
+ if (!source)
+ return -EINVAL;
+
+ if (vin_have_bridge(vin)) {
+ bridge = vin_to_bridge(vin);
+
+ if (!bridge)
+ return -EINVAL;
+
+ mutex_lock(&vin->group->lock);
+
+ pipe = bridge->entity.pipe ? bridge->entity.pipe :
+ &vin->vdev.pipe;
+ ret = media_entity_pipeline_start(&vin->vdev.entity, pipe);
+ if (ret) {
+ mutex_unlock(&vin->group->lock);
+ return ret;
+ }
+
+ /* Only need to start stream if it's not running */
+ if (bridge->entity.stream_count <= 1)
+ v4l2_subdev_call(bridge, video, s_stream, 1);
+ if (source->entity.stream_count <= 1)
+ v4l2_subdev_call(source, video, s_stream, 1);
+
+ mutex_unlock(&vin->group->lock);
+ } else {
+ v4l2_subdev_call(source, video, s_stream, 1);
+ }
+
+ return 0;
+}
+
+static int __rvin_stop_streaming(struct rvin_dev *vin)
+{
+ struct v4l2_subdev *source, *bridge = NULL;
+
+ source = vin_to_source(vin);
+ if (!source)
+ return -EINVAL;
+
+ if (vin_have_bridge(vin)) {
+ bridge = vin_to_bridge(vin);
+
+ if (!bridge)
+ return -EINVAL;
+
+ mutex_lock(&vin->group->lock);
+
+ media_entity_pipeline_stop(&vin->vdev.entity);
+
+ /* Only need to stop stream if there are no other users */
+ if (bridge->entity.stream_count <= 0)
+ v4l2_subdev_call(bridge, video, s_stream, 0);
+ if (source->entity.stream_count <= 0)
+ v4l2_subdev_call(source, video, s_stream, 0);
+
+ mutex_unlock(&vin->group->lock);
+ } else {
+ v4l2_subdev_call(source, video, s_stream, 0);
+ }
+
+ return 0;
+}
+
static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
{
struct rvin_dev *vin = vb2_get_drv_priv(vq);
- struct v4l2_subdev *sd;
unsigned long flags;
int ret;
- sd = vin_to_source(vin);
- v4l2_subdev_call(sd, video, s_stream, 1);
+ ret = __rvin_start_streaming(vin);
+ if (ret)
+ return ret;
spin_lock_irqsave(&vin->qlock, flags);
@@ -1122,7 +1194,7 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
/* Return all buffers if something went wrong */
if (ret) {
return_all_buffers(vin, VB2_BUF_STATE_QUEUED);
- v4l2_subdev_call(sd, video, s_stream, 0);
+ __rvin_stop_streaming(vin);
}
spin_unlock_irqrestore(&vin->qlock, flags);
@@ -1133,7 +1205,6 @@ static int rvin_start_streaming(struct vb2_queue *vq, unsigned int count)
static void rvin_stop_streaming(struct vb2_queue *vq)
{
struct rvin_dev *vin = vb2_get_drv_priv(vq);
- struct v4l2_subdev *sd;
unsigned long flags;
int retries = 0;
@@ -1172,8 +1243,7 @@ static void rvin_stop_streaming(struct vb2_queue *vq)
spin_unlock_irqrestore(&vin->qlock, flags);
- sd = vin_to_source(vin);
- v4l2_subdev_call(sd, video, s_stream, 0);
+ __rvin_stop_streaming(vin);
/* disable interrupts */
rvin_disable_interrupts(vin);
--
2.10.2
next prev parent reply other threads:[~2016-11-12 13:13 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-12 13:11 [PATCHv2 00/32] rcar-vin: Add Gen3 with media controller support Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 01/32] media: entity: Add has_route entity operation Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 02/32] media: entity: Add media_entity_has_route() function Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 03/32] media: rcar-vin: reset bytesperline and sizeimage when resetting format Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 04/32] media: rcar-vin: use rvin_reset_format() in S_DV_TIMINGS Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 05/32] media: rcar-vin: fix how pads are handled for v4l2 subdeivce operations Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 06/32] media: rcar-vin: fix standard in input enumeration Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 07/32] media: rcar-vin: add wrapper to get rvin_graph_entity Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 08/32] media: rcar-vin: move subdev source and sink pad index to rvin_graph_entity Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 09/32] media: rcar-vin: move pad number discovery to async complete handler Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 10/32] media: rcar-vin: use pad information when verifying media bus format Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 11/32] media: rcar-vin: refactor pad lookup code Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 12/32] media: rcar-vin: split rvin_s_fmt_vid_cap() Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 13/32] media: rcar-vin: register the video device early Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 14/32] media: rcar-vin: move chip information to own struct Niklas Söderlund
2016-11-12 13:11 ` [PATCHv2 15/32] media: rcar-vin: move max width and height information to chip information Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 16/32] media: rcar-vin: change name of video device Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 17/32] media: rcar-vin: clarify error message from the digital notifier Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 18/32] media: rcar-vin: enable Gen3 hardware configuration Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 19/32] media: rcar-vin: add functions to manipulate Gen3 CHSEL value Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 20/32] media: rcar-vin: expose a sink pad if we are on Gen3 Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 21/32] media: rcar-vin: add group allocator functions Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 22/32] media: rcar-vin: add chsel information to rvin_info Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 23/32] media: rcar-vin: parse Gen3 OF and setup media graph Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 24/32] media: rcar-vin: add link notify for Gen3 Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 25/32] media: rcar-vin: enable CSI2 group subdevices in lookup helpers Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 26/32] media: rcar-vin: add helpers for bridge Niklas Söderlund
2016-11-12 13:12 ` Niklas Söderlund [this message]
2016-11-12 13:12 ` [PATCHv2 28/32] media: rcar-vin: propagate format to bridge Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 29/32] media: rcar-vin: attach to CSI2 group when the video device is opened Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 30/32] media: rcar-vin: add Gen3 devicetree bindings documentation Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 31/32] media: rcar-vin: enable support for r8a7795 Niklas Söderlund
2016-11-12 13:12 ` [PATCHv2 32/32] media: rcar-vin: enable support for r8a7796 Niklas Söderlund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161112131216.22635-28-niklas.soderlund+renesas@ragnatech.se \
--to=niklas.soderlund+renesas@ragnatech.se \
--cc=geert@linux-m68k.org \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tomoharu.fukawa.eb@renesas.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is 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).