From patchwork Sat Nov 27 16:41:33 2021 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: 12642417 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35F76C433F5 for ; Sat, 27 Nov 2021 16:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234670AbhK0Qre (ORCPT ); Sat, 27 Nov 2021 11:47:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233268AbhK0Qpc (ORCPT ); Sat, 27 Nov 2021 11:45:32 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4886C061746 for ; Sat, 27 Nov 2021 08:42:15 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id r9-20020a7bc089000000b00332f4abf43fso8959113wmh.0 for ; Sat, 27 Nov 2021 08:42:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jp77MKE/U4T9c+FwNAWUTuF78plz492lxF0sUt5DL5w=; b=LXPH7JjwQXdBgbG0YwR/1WEauHe52AyQ6DmrBqulBAn9Lf3dVVAALwslKjA7COT6yB MULBlrE4UFbm7mwaZ6/Y7xznJPOhvyUNmF/V4/s3dH66tTgLcNujubcTEmgvDRbQUMRT uKa88/SnPBY3KqfLxdHDWiI6GkXTCX9XVG/ku0crNdbblSNj69jB8fwhVk/HWrr2Eoo4 rx4Q5oN44Hh18Kw0GQlNiTWRaj9cxFywVMdLTU+onWnhmZbC3TzFOscEk+yGnU0oDnvC eUKEL1r9q2c6J+CuyGKr/Lm0nZ2cEjokemVJzBAZOFXvDhg2S0B0nvf3S/TmDSm4me06 pozw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jp77MKE/U4T9c+FwNAWUTuF78plz492lxF0sUt5DL5w=; b=COAVNWhp5S/0rfrPst7W/xUz9jwp5XOldS6u6/DEtOnCBemTT5G/fs/ZJ9t69r3MnY FvQu6ZBNv2lMbdtY0aakD0oU98/78eL3xtaLVLKDn1Tt2uyqKAdBjcyGDQrZSyyc2KeJ 9H4idtsDiwZj9ZjfPQ/p08obea1SHHSx2h2N/bftVoyXyUzyUB4H8Kn9JMXFqHqDiz34 Io00b0AbVBZufyMhz8QvnZ4f9n/3XJcJLg60MQFyH0yQmoHKcQWbLkwB7b9LNPDQU6/6 0mnVTRi0yZ4TQxH6Kig4muzV7ynL7mh7GMPbxjlwTAH2kR+XPGXLAp9HF7pZWgpFNyMR Rz/g== X-Gm-Message-State: AOAM532eYKZFC7y1hXnXJr9T9wAnmk0P/1qpT4T1Os2LiBWnRFtubPv1 VjxEJZAQZcxwI3l0B01L4RZklQ== X-Google-Smtp-Source: ABdhPJzDXEZznePExCfd/hxbrc9D9+67a6gSP54xWkC5SS/EPwpk/jj1yLB40pjECT+5K7xqDNYTxg== X-Received: by 2002:a1c:f20e:: with SMTP id s14mr24320938wmc.186.1638031334197; Sat, 27 Nov 2021 08:42:14 -0800 (PST) Received: from bismarck.berto.se (p54ac5892.dip0.t-ipconnect.de. [84.172.88.146]) by smtp.googlemail.com with ESMTPSA id u13sm2900104wmq.14.2021.11.27.08.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Nov 2021 08:42:13 -0800 (PST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Hans Verkuil , Jacopo Mondi , Laurent Pinchart , linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v2 1/3] media: rcar-vin: Refactor link notify Date: Sat, 27 Nov 2021 17:41:33 +0100 Message-Id: <20211127164135.2617686-2-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211127164135.2617686-1-niklas.soderlund+renesas@ragnatech.se> References: <20211127164135.2617686-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org The code has grown organically and a lot of checks are performed for the CSI-2 use-case even if the link notify is for a subdevice connected to the parallel interface. Before reworking the CSI-2 routing logic split the CSI-2 and parallel link notify code in two separate blocks to make it clearer. There is no functional change. Signed-off-by: Niklas Söderlund Tested-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changers since v1 - Fix spelling in commit message. - Removed extra blank line in rvin_csi2_link_notify(). - Move vdev and vin lookup outside the mutex. --- drivers/media/platform/rcar-vin/rcar-core.c | 90 +++++++++++---------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 1d92cc8ede8f8a3e..4c3c092a7cb9476b 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -795,12 +795,10 @@ static int rvin_csi2_link_notify(struct media_link *link, u32 flags, { struct rvin_group *group = container_of(link->graph_obj.mdev, struct rvin_group, mdev); - unsigned int master_id, channel, mask_new, i; - unsigned int mask = ~0; struct media_entity *entity; struct video_device *vdev; - struct media_pad *csi_pad; - struct rvin_dev *vin = NULL; + struct rvin_dev *vin; + unsigned int i; int csi_id, ret; ret = v4l2_pipeline_link_notify(link, flags, notification); @@ -821,38 +819,13 @@ static int rvin_csi2_link_notify(struct media_link *link, u32 flags, if (entity->stream_count) return -EBUSY; - mutex_lock(&group->lock); - /* Find the master VIN that controls the routes. */ vdev = media_entity_to_video_device(link->sink->entity); vin = container_of(vdev, struct rvin_dev, vdev); - master_id = rvin_group_id_to_master(vin->id); - if (WARN_ON(!group->vin[master_id])) { - ret = -ENODEV; - goto out; - } + mutex_lock(&group->lock); - /* Build a mask for already enabled links. */ - for (i = master_id; i < master_id + 4; i++) { - if (!group->vin[i]) - continue; - - /* Get remote CSI-2, if any. */ - csi_pad = media_entity_remote_pad( - &group->vin[i]->vdev.entity.pads[0]); - if (!csi_pad) - continue; - - csi_id = rvin_group_entity_to_remote_id(group, csi_pad->entity); - channel = rvin_group_csi_pad_to_channel(csi_pad->index); - - mask &= rvin_csi2_get_mask(group->vin[i], csi_id, channel); - } - - /* Add the new link to the existing mask and check if it works. */ csi_id = rvin_group_entity_to_remote_id(group, link->source->entity); - if (csi_id == -ENODEV) { struct v4l2_subdev *sd; @@ -877,25 +850,54 @@ static int rvin_csi2_link_notify(struct media_link *link, u32 flags, vin_err(vin, "Subdevice %s not registered to any VIN\n", link->source->entity->name); ret = -ENODEV; - goto out; - } + } else { + unsigned int master_id, channel, mask_new; + unsigned int mask = ~0; + struct media_pad *csi_pad; - channel = rvin_group_csi_pad_to_channel(link->source->index); - mask_new = mask & rvin_csi2_get_mask(vin, csi_id, channel); - vin_dbg(vin, "Try link change mask: 0x%x new: 0x%x\n", mask, mask_new); + master_id = rvin_group_id_to_master(vin->id); - if (!mask_new) { - ret = -EMLINK; - goto out; - } + if (WARN_ON(!group->vin[master_id])) { + ret = -ENODEV; + goto out; + } + + /* Build a mask for already enabled links. */ + for (i = master_id; i < master_id + 4; i++) { + if (!group->vin[i]) + continue; + + /* Get remote CSI-2, if any. */ + csi_pad = media_entity_remote_pad( + &group->vin[i]->vdev.entity.pads[0]); + if (!csi_pad) + continue; - /* New valid CHSEL found, set the new value. */ - ret = rvin_set_channel_routing(group->vin[master_id], __ffs(mask_new)); - if (ret) - goto out; + csi_id = rvin_group_entity_to_remote_id(group, + csi_pad->entity); + channel = rvin_group_csi_pad_to_channel(csi_pad->index); - vin->is_csi = true; + mask &= rvin_csi2_get_mask(group->vin[i], csi_id, channel); + } + channel = rvin_group_csi_pad_to_channel(link->source->index); + mask_new = mask & rvin_csi2_get_mask(vin, csi_id, channel); + vin_dbg(vin, "Try link change mask: 0x%x new: 0x%x\n", mask, + mask_new); + + if (!mask_new) { + ret = -EMLINK; + goto out; + } + + /* New valid CHSEL found, set the new value. */ + ret = rvin_set_channel_routing(group->vin[master_id], + __ffs(mask_new)); + if (ret) + goto out; + + vin->is_csi = true; + } out: mutex_unlock(&group->lock);