From patchwork Thu Dec 14 19:08:25 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: 10113181 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 633DE60327 for ; Thu, 14 Dec 2017 19:09:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 534A828759 for ; Thu, 14 Dec 2017 19:09:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4859F29178; Thu, 14 Dec 2017 19:09:54 +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=unavailable 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 4764828759 for ; Thu, 14 Dec 2017 19:09:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754425AbdLNTJw (ORCPT ); Thu, 14 Dec 2017 14:09:52 -0500 Received: from smtp-3.sys.kth.se ([130.237.48.192]:34172 "EHLO smtp-3.sys.kth.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754300AbdLNTJT (ORCPT ); Thu, 14 Dec 2017 14:09:19 -0500 Received: from smtp-3.sys.kth.se (localhost.localdomain [127.0.0.1]) by smtp-3.sys.kth.se (Postfix) with ESMTP id D0A4F47AD; Thu, 14 Dec 2017 20:09:17 +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 XHYAI-9Reesf; 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 147D64797; Thu, 14 Dec 2017 20:09:16 +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 05/15] rcar-csi2: count usage for each source pad Date: Thu, 14 Dec 2017 20:08:25 +0100 Message-Id: <20171214190835.7672-6-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 The R-Car CSI-2 hardware can output the same virtual channel simultaneously to more then one R-Car VIN. For this reason we need to move the usage counting from the global device to each source pad. If a source pads usage count go from 0 to 1 we need to signal that a new stream should start, likewise if it go from 1 to 0 we need to stop a stream. At the same time we only want to start or stop the R-Car CSI-2 device only on the first or last stream. Signed-off-by: Niklas Söderlund --- drivers/media/platform/rcar-vin/rcar-csi2.c | 38 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c index 8ce0bfeef1113f9c..e0f56cc3d25179a9 100644 --- a/drivers/media/platform/rcar-vin/rcar-csi2.c +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c @@ -328,6 +328,14 @@ enum rcar_csi2_pads { NR_OF_RCAR_CSI2_PAD, }; +static int rcar_csi2_pad_to_vc(unsigned int pad) +{ + if (pad < RCAR_CSI2_SOURCE_VC0 || pad > RCAR_CSI2_SOURCE_VC3) + return -EINVAL; + + return pad - RCAR_CSI2_SOURCE_VC0; +} + struct rcar_csi2_info { const struct phypll_hsfreqrange *hsfreqrange; const struct phtw_testdin_data *testdin_data; @@ -350,7 +358,7 @@ struct rcar_csi2 { struct v4l2_mbus_framefmt mf; struct mutex lock; - int stream_count; + int stream_count[4]; unsigned short lanes; unsigned char lane_swap[4]; @@ -630,7 +638,13 @@ static int rcar_csi2_s_stream(struct v4l2_subdev *sd, unsigned int pad, { struct rcar_csi2 *priv = sd_to_csi2(sd); struct v4l2_subdev *nextsd; - int ret; + unsigned int i, count = 0; + int ret, vc; + + /* Only allow stream control on source pads and valid vc */ + vc = rcar_csi2_pad_to_vc(pad); + if (vc < 0) + return vc; /* Only one stream on each source pad */ if (stream != 0) @@ -642,7 +656,10 @@ static int rcar_csi2_s_stream(struct v4l2_subdev *sd, unsigned int pad, if (ret) goto out; - if (enable && priv->stream_count == 0) { + for (i = 0; i < 4; i++) + count += priv->stream_count[i]; + + if (enable && count == 0) { pm_runtime_get_sync(priv->dev); ret = rcar_csi2_start(priv); @@ -650,20 +667,23 @@ static int rcar_csi2_s_stream(struct v4l2_subdev *sd, unsigned int pad, pm_runtime_put(priv->dev); goto out; } + } else if (!enable && count == 1) { + rcar_csi2_stop(priv); + pm_runtime_put(priv->dev); + } + if (enable && priv->stream_count[vc] == 0) { ret = v4l2_subdev_call(nextsd, video, s_stream, 1); if (ret) { rcar_csi2_stop(priv); pm_runtime_put(priv->dev); goto out; } - } else if (!enable && priv->stream_count == 1) { - rcar_csi2_stop(priv); + } else if (!enable && priv->stream_count[vc] == 1) { ret = v4l2_subdev_call(nextsd, video, s_stream, 0); - pm_runtime_put(priv->dev); } - priv->stream_count += enable ? 1 : -1; + priv->stream_count[vc] += enable ? 1 : -1; out: mutex_unlock(&priv->lock); @@ -919,7 +939,9 @@ static int rcar_csi2_probe(struct platform_device *pdev) priv->dev = &pdev->dev; mutex_init(&priv->lock); - priv->stream_count = 0; + + for (i = 0; i < 4; i++) + priv->stream_count[i] = 0; ret = rcar_csi2_probe_resources(priv, pdev); if (ret) {