From patchwork Thu Dec 14 19:08:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 10113173 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0DDF560327 for ; Thu, 14 Dec 2017 19:09:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F141D28759 for ; Thu, 14 Dec 2017 19:09:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E626929178; Thu, 14 Dec 2017 19:09:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C35F28759 for ; Thu, 14 Dec 2017 19:09:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754417AbdLNTJs (ORCPT ); Thu, 14 Dec 2017 14:09:48 -0500 Received: from smtp-3.sys.kth.se ([130.237.48.192]:34210 "EHLO smtp-3.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754305AbdLNTJU (ORCPT ); Thu, 14 Dec 2017 14:09:20 -0500 Received: from smtp-3.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-3.sys.kth.se (Postfix) with ESMTP id BD33747CA; Thu, 14 Dec 2017 20:09:18 +0100 (CET) X-Virus-Scanned: by amavisd-new at kth.se Received: from smtp-3.sys.kth.se ([127.0.0.1]) by smtp-3.sys.kth.se (smtp-3.sys.kth.se [127.0.0.1]) (amavisd-new, port 10024) with LMTP id p0KQqn6_pizc; Thu, 14 Dec 2017 20:09:17 +0100 (CET) X-KTH-Auth: niso [89.233.230.99] X-KTH-mail-from: niklas.soderlund+renesas@ragnatech.se Received: from bismarck.berto.se (89-233-230-99.cust.bredband2.com [89.233.230.99]) by smtp-3.sys.kth.se (Postfix) with ESMTPSA id 44E9046F6; Thu, 14 Dec 2017 20:09:17 +0100 (CET) From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= To: linux-media@vger.kernel.org, Sakari Ailus Cc: linux-renesas-soc@vger.kernel.org, Laurent Pinchart , Kieran Bingham , Jacopo Mondi , Benoit Parrot , Maxime Ripard , =?UTF-8?q?Niklas=20S=C3=B6derlund?= Subject: [PATCH/RFC v2 06/15] rcar-csi2: use frame description information when propagating .s_stream() Date: Thu, 14 Dec 2017 20:08:26 +0100 Message-Id: <20171214190835.7672-7-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171214190835.7672-1-niklas.soderlund+renesas@ragnatech.se> References: <20171214190835.7672-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the frame description from the remote subdevice of the rcar-csi2's sink pad to get the remote pad and stream pad needed to propagate the .s_stream() operation. The CSI-2 virtual channel which should be acted upon can be determined by looking at which of the rcar-csi2 source pad the .s_stream() was called on. This is because the rcar-csi2 acts as a demultiplexer for the CSI-2 link on the one sink pad and outputs each virtual channel on a distinct and known source pad. Signed-off-by: Niklas Söderlund --- drivers/media/platform/rcar-vin/rcar-csi2.c | 58 ++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index e0f56cc3d25179a9..6b607b2e31e26063 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -614,20 +614,31 @@ static void rcar_csi2_stop(struct rcar_csi2 *priv) rcar_csi2_reset(priv); } -static int rcar_csi2_sd_info(struct rcar_csi2 *priv, struct v4l2_subdev **sd) +static int rcar_csi2_get_source_info(struct rcar_csi2 *priv, + struct v4l2_subdev **subdev, + unsigned int *pad, + struct v4l2_mbus_frame_desc *fd) { - struct media_pad *pad; + struct media_pad *remote_pad; - pad = media_entity_remote_pad(&priv->pads[RCAR_CSI2_SINK]); - if (!pad) { - dev_err(priv->dev, "Could not find remote pad\n"); + /* Get source subdevice and pad */ + remote_pad = media_entity_remote_pad(&priv->pads[RCAR_CSI2_SINK]); + if (!remote_pad) { + dev_err(priv->dev, "Could not find remote source pad\n"); return -ENODEV; } + *subdev = media_entity_to_v4l2_subdev(remote_pad->entity); + *pad = remote_pad->index; - *sd = media_entity_to_v4l2_subdev(pad->entity); - if (!*sd) { - dev_err(priv->dev, "Could not find remote subdevice\n"); - return -ENODEV; + /* Get frame descriptor */ + if (v4l2_subdev_call(*subdev, pad, get_frame_desc, *pad, fd)) { + dev_err(priv->dev, "Could not read frame desc\n"); + return -EINVAL; + } + + if (fd->type != V4L2_MBUS_FRAME_DESC_TYPE_CSI2) { + dev_err(priv->dev, "Frame desc do not describe CSI-2 link"); + return -EINVAL; } return 0; @@ -637,9 +648,10 @@ static int rcar_csi2_s_stream(struct v4l2_subdev *sd, unsigned int pad, unsigned int stream, int enable) { struct rcar_csi2 *priv = sd_to_csi2(sd); + struct v4l2_mbus_frame_desc fd; struct v4l2_subdev *nextsd; - unsigned int i, count = 0; - int ret, vc; + unsigned int i, rpad, count = 0; + int ret, vc, rstream = -1; /* Only allow stream control on source pads and valid vc */ vc = rcar_csi2_pad_to_vc(pad); @@ -650,11 +662,23 @@ static int rcar_csi2_s_stream(struct v4l2_subdev *sd, unsigned int pad, if (stream != 0) return -EINVAL; - mutex_lock(&priv->lock); - - ret = rcar_csi2_sd_info(priv, &nextsd); + /* Get information about multiplexed link */ + ret = rcar_csi2_get_source_info(priv, &nextsd, &rpad, &fd); if (ret) - goto out; + return ret; + + /* Get stream on multiplexed link */ + for (i = 0; i < fd.num_entries; i++) + if (fd.entry[i].bus.csi2.channel == vc) + rstream = fd.entry[i].stream; + + if (rstream < 0) { + dev_err(priv->dev, "Could not find stream for vc %u\n", vc); + return -EINVAL; + } + + /* Start or stop the requested stream */ + mutex_lock(&priv->lock); for (i = 0; i < 4; i++) count += priv->stream_count[i]; @@ -673,14 +697,14 @@ static int rcar_csi2_s_stream(struct v4l2_subdev *sd, unsigned int pad, } if (enable && priv->stream_count[vc] == 0) { - ret = v4l2_subdev_call(nextsd, video, s_stream, 1); + ret = v4l2_subdev_call(nextsd, pad, s_stream, rpad, rstream, 1); if (ret) { rcar_csi2_stop(priv); pm_runtime_put(priv->dev); goto out; } } else if (!enable && priv->stream_count[vc] == 1) { - ret = v4l2_subdev_call(nextsd, video, s_stream, 0); + ret = v4l2_subdev_call(nextsd, pad, s_stream, rpad, rstream, 0); } priv->stream_count[vc] += enable ? 1 : -1;