All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jacopo Mondi <jacopo+renesas@jmondi.org>
To: niklas.soderlund@ragnatech.se, laurent.pinchart@ideasonboard.com
Cc: Jacopo Mondi <jacopo+renesas@jmondi.org>,
	linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Subject: [PATCH v3 5/9] media: rcar-vin: Parse parallel input on Gen3
Date: Fri, 18 May 2018 16:40:41 +0200	[thread overview]
Message-ID: <1526654445-10702-6-git-send-email-jacopo+renesas@jmondi.org> (raw)
In-Reply-To: <1526654445-10702-1-git-send-email-jacopo+renesas@jmondi.org>

The rcar-vin driver so far had a mutually exclusive code path for
handling parallel and CSI-2 video input subdevices, with only the CSI-2
use case supporting media-controller. As we add support for parallel
inputs to Gen3 media-controller compliant code path now parse both port@0
and port@1, handling the media-controller use case in the parallel
bound/unbind notifier operations and delay notifier registration to the
last probing VIN instance in case we have links to setup between media
entities.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
---
 drivers/media/platform/rcar-vin/rcar-core.c | 114 +++++++++++++++++++++-------
 1 file changed, 85 insertions(+), 29 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c
index 0a35a98..745e8ee 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -397,6 +397,11 @@ static int rvin_parallel_subdevice_attach(struct rvin_dev *vin,
 	ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SINK);
 	vin->parallel->sink_pad = ret < 0 ? 0 : ret;
 
+	vin->parallel->subdev = subdev;
+
+	if (vin->info->use_mc)
+		return 0;
+
 	/* Find compatible subdevices mbus format */
 	vin->mbus_code = 0;
 	code.index = 0;
@@ -422,46 +427,52 @@ static int rvin_parallel_subdevice_attach(struct rvin_dev *vin,
 	if (!vin->mbus_code) {
 		vin_err(vin, "Unsupported media bus format for %s\n",
 			subdev->name);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto error_reset_subdev;
 	}
 
 	/* Read tvnorms */
 	ret = v4l2_subdev_call(subdev, video, g_tvnorms, &vin->vdev.tvnorms);
 	if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
-		return ret;
+		goto error_reset_subdev;
 
 	/* Read standard */
 	vin->std = V4L2_STD_UNKNOWN;
 	ret = v4l2_subdev_call(subdev, video, g_std, &vin->std);
 	if (ret < 0 && ret != -ENOIOCTLCMD)
-		return ret;
+		goto error_reset_subdev;
 
 	/* Add the controls */
 	ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
 	if (ret < 0)
-		return ret;
+		goto error_reset_subdev;
 
 	ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, subdev->ctrl_handler,
 				    NULL);
 	if (ret < 0) {
 		v4l2_ctrl_handler_free(&vin->ctrl_handler);
-		return ret;
+		goto error_reset_subdev;
 	}
 
 	vin->vdev.ctrl_handler = &vin->ctrl_handler;
 
-	vin->parallel->subdev = subdev;
-
 	return 0;
+
+error_reset_subdev:
+	vin->parallel->subdev = NULL;
+
+	return ret;
 }
 
 static void rvin_parallel_subdevice_detach(struct rvin_dev *vin)
 {
 	rvin_v4l2_unregister(vin);
-	v4l2_ctrl_handler_free(&vin->ctrl_handler);
-
-	vin->vdev.ctrl_handler = NULL;
 	vin->parallel->subdev = NULL;
+
+	if (!vin->info->use_mc) {
+		v4l2_ctrl_handler_free(&vin->ctrl_handler);
+		vin->vdev.ctrl_handler = NULL;
+	}
 }
 
 static int rvin_parallel_notify_complete(struct v4l2_async_notifier *notifier)
@@ -551,22 +562,26 @@ static int rvin_parallel_parse_v4l2(struct device *dev,
 	return 0;
 }
 
-static int rvin_parallel_graph_init(struct rvin_dev *vin)
+static int rvin_parallel_init(struct rvin_dev *vin)
 {
 	int ret;
 
-	ret = v4l2_async_notifier_parse_fwnode_endpoints(
-		vin->dev, &vin->notifier,
-		sizeof(struct rvin_parallel_entity), rvin_parallel_parse_v4l2);
+	ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
+		vin->dev, &vin->notifier, sizeof(struct rvin_parallel_entity),
+		0, rvin_parallel_parse_v4l2);
 	if (ret)
 		return ret;
 
 	if (!vin->parallel)
-		return -ENODEV;
+		return -ENOTCONN;
 
 	vin_dbg(vin, "Found parallel subdevice %pOF\n",
 		to_of_node(vin->parallel->asd.match.fwnode));
 
+	/* If we use media-controller, notifier registration is post-poned. */
+	if (vin->info->use_mc)
+		return 0;
+
 	vin->notifier.ops = &rvin_parallel_notify_ops;
 	ret = v4l2_async_notifier_register(&vin->v4l2_dev, &vin->notifier);
 	if (ret < 0) {
@@ -766,6 +781,30 @@ static int rvin_mc_parse_of_graph(struct rvin_dev *vin)
 
 	mutex_unlock(&vin->group->lock);
 
+	/*
+	 * Go and register all notifiers for parallel subdevs, and
+	 * the group notifier for CSI-2 subdevs, if any.
+	 */
+	for (i = 0; i < RCAR_VIN_NUM; i++) {
+		struct rvin_dev *ivin = vin->group->vin[i];
+		struct v4l2_async_notifier *inotifier;
+
+		if (!ivin)
+			continue;
+
+		inotifier = &ivin->notifier;
+		if (!inotifier->num_subdevs)
+			continue;
+
+		inotifier->ops = &rvin_parallel_notify_ops;
+		ret = v4l2_async_notifier_register(&ivin->v4l2_dev, inotifier);
+		if (ret < 0) {
+			vin_err(ivin,
+				"Notifier registration failed: %d\n", ret);
+			goto error_unregister_notifiers;
+		}
+	}
+
 	if (!vin->group->notifier.num_subdevs)
 		return 0;
 
@@ -773,25 +812,29 @@ static int rvin_mc_parse_of_graph(struct rvin_dev *vin)
 	ret = v4l2_async_notifier_register(&vin->v4l2_dev,
 					   &vin->group->notifier);
 	if (ret < 0) {
-		vin_err(vin, "Notifier registration failed\n");
+		vin_err(vin, "Notifier registration failed: %d\n", ret);
 		return ret;
 	}
 
 	return 0;
+
+error_unregister_notifiers:
+	for (i = 0; i < RCAR_VIN_NUM; i++) {
+		if (!vin->group->vin[i])
+			continue;
+
+		v4l2_async_notifier_unregister(&vin->group->vin[i]->notifier);
+	}
+
+	return ret;
 }
 
 static int rvin_mc_init(struct rvin_dev *vin)
 {
 	int ret;
 
-	vin->pad.flags = MEDIA_PAD_FL_SINK;
-	ret = media_entity_pads_init(&vin->vdev.entity, 1, &vin->pad);
-	if (ret)
-		return ret;
-
-	ret = rvin_group_get(vin);
-	if (ret)
-		return ret;
+	if (!vin->info->use_mc)
+		return 0;
 
 	ret = rvin_mc_parse_of_graph(vin);
 	if (ret)
@@ -1074,13 +1117,26 @@ static int rcar_vin_probe(struct platform_device *pdev)
 		return ret;
 
 	platform_set_drvdata(pdev, vin);
-	if (vin->info->use_mc)
-		ret = rvin_mc_init(vin);
-	else
-		ret = rvin_parallel_graph_init(vin);
-	if (ret < 0)
+
+	if (vin->info->use_mc) {
+		vin->pad.flags = MEDIA_PAD_FL_SINK;
+		ret = media_entity_pads_init(&vin->vdev.entity, 1, &vin->pad);
+		if (ret)
+			return ret;
+
+		ret = rvin_group_get(vin);
+		if (ret)
+			return ret;
+	}
+
+	ret = rvin_parallel_init(vin);
+	if (ret < 0 && ret != -ENOTCONN)
 		goto error;
 
+	ret = rvin_mc_init(vin);
+	if (ret)
+		return ret;
+
 	pm_suspend_ignore_children(&pdev->dev, true);
 	pm_runtime_enable(&pdev->dev);
 
-- 
2.7.4

  parent reply	other threads:[~2018-05-18 14:41 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-18 14:40 [PATCH v3 0/9] rcar-vin: Add support for parallel input on Gen3 Jacopo Mondi
2018-05-18 14:40 ` [PATCH v3 1/9] media: rcar-vin: Rename 'digital' to 'parallel' Jacopo Mondi
2018-05-23 22:42   ` Niklas Söderlund
2018-05-23 22:42     ` Niklas Söderlund
2018-05-24 20:19     ` jacopo mondi
2018-05-18 14:40 ` [PATCH v3 2/9] media: rcar-vin: Remove two empty lines Jacopo Mondi
2018-05-23 22:43   ` Niklas Söderlund
2018-05-23 22:43     ` Niklas Söderlund
2018-05-18 14:40 ` [PATCH v3 3/9] media: rcar-vin: Create a group notifier Jacopo Mondi
2018-05-24 10:14   ` Niklas Söderlund
2018-05-24 10:14     ` Niklas Söderlund
2019-04-05 16:16     ` Eugeniu Rosca
2019-04-06  0:04       ` Steve Longerbeam
2019-04-08 11:12         ` Niklas Söderlund
2019-04-09  3:58           ` Steve Longerbeam
2019-04-09  9:10             ` Kieran Bingham
2019-04-09 13:25               ` Niklas Söderlund
2019-04-09 22:52                 ` Steve Longerbeam
2019-04-09 20:57             ` Laurent Pinchart
2019-04-09 22:22               ` Steve Longerbeam
2019-04-09 22:59                 ` Laurent Pinchart
2019-04-09 23:29                   ` Steve Longerbeam
2019-04-11 20:28                     ` Eugeniu Rosca
2019-04-11 20:42                       ` Niklas Söderlund
2019-04-12 14:12                         ` Eugeniu Rosca
2019-04-12 15:10                           ` Niklas Söderlund
2018-05-18 14:40 ` [PATCH v3 4/9] media: rcar-vin: Cache the mbus configuration flags Jacopo Mondi
2018-05-24 10:20   ` Niklas Söderlund
2018-05-24 10:20     ` Niklas Söderlund
2018-05-18 14:40 ` Jacopo Mondi [this message]
2018-05-24 10:30   ` [PATCH v3 5/9] media: rcar-vin: Parse parallel input on Gen3 Niklas Söderlund
2018-05-24 10:30     ` Niklas Söderlund
2018-05-18 14:40 ` [PATCH v3 6/9] media: rcar-vin: Link parallel input media entities Jacopo Mondi
2018-05-24 10:32   ` Niklas Söderlund
2018-05-24 10:32     ` Niklas Söderlund
2018-05-18 14:40 ` [PATCH v3 7/9] media: rcar-vin: Handle parallel subdev in link_notify Jacopo Mondi
2018-05-24 10:37   ` Niklas Söderlund
2018-05-24 10:37     ` Niklas Söderlund
2018-05-18 14:40 ` [PATCH v3 8/9] media: rcar-vin: Rename _rcar_info to rcar_info Jacopo Mondi
2018-05-19  9:33   ` Sergei Shtylyov
2018-05-24 10:38   ` Niklas Söderlund
2018-05-24 10:38     ` Niklas Söderlund
2018-05-18 14:40 ` [PATCH v3 9/9] media: rcar-vin: Add support for R-Car R8A77995 SoC Jacopo Mondi

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=1526654445-10702-6-git-send-email-jacopo+renesas@jmondi.org \
    --to=jacopo+renesas@jmondi.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.