From patchwork Fri Jul 9 14:25:50 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: 472115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FD57C07E9B for ; Fri, 9 Jul 2021 14:26:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44DA6613BA for ; Fri, 9 Jul 2021 14:26:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232023AbhGIO3P (ORCPT ); Fri, 9 Jul 2021 10:29:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbhGIO3O (ORCPT ); Fri, 9 Jul 2021 10:29:14 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5284DC0613DD for ; Fri, 9 Jul 2021 07:26:30 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id r11so7146739wro.9 for ; Fri, 09 Jul 2021 07:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GJbTV9HbgtZtuGVRujZ4GmQHg/F2jWWQ4ik4RBG2kic=; b=vxhAEW7zhvlhX1tmL1Es4zdOvj03oJQSfNkveAAEXCP1DDEHWHcz4fnRyPlXSj7Gf6 CZFEyb2Uq4IUsJkQMFkxt5ovOSOj2ECDm+78mGOuCbimFfJpYf9oVhNDri3Y1Umt+w4e 3vvcVR35P2RwveluJ9J1Yz/hES8eBe+7qLpu48shxJGS7O2eignH/xMLaIJ5S3kfRdeN TkgqUB63VvANg7EBkV1zQktlD4CeDeVGqT5Z9bJ2KNO230N9wBcMBiEzZshUIqmyVZxf rziS+h+yhRHYz1tvTGr2rwLWBa/TKeQqkoBQFdVYXERHT2l9dmGXKIN9BLo4+pg2pe+J 2m9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GJbTV9HbgtZtuGVRujZ4GmQHg/F2jWWQ4ik4RBG2kic=; b=c168TNOO2gg3AMwIMZ3pCu3Ko7Ln779AvTJw5bg4EtNBiDZ++z6cDM9uzoOcXTpATk 5vnCcYxdePo8nruLgLo/d+FToeqhWyDCVXRzXI73uwNehClGCMJzBNDar+WhwQCjHRca SdQ8JPq8q+ViRI1IXxH/kFhbBLfpdRr+Pp813whmDp7EE5Ql6dYge5K5EcVEOBsPk6Co BCMKnAwuOtCxPlN39WJzf+2jm8Gxqogbz7tN5jYX1wGo2+OR7yYGll2WD+eKDOsj1Uyj lKu2ZASw1jReq/KQ/VdMUs80NSMp7T3dNaCxV00HW0DQY4ChfC0U0CJp7V1ahZOKbDKp p9Kg== X-Gm-Message-State: AOAM531HVOSnUqjlAwMIxh6PRm/C1vwK8EzTokduaqmIyKgZFf9eGNur v5Ix/6jrmnnKh467blsu+HlCZA== X-Google-Smtp-Source: ABdhPJx3ApCr0sZhk8mSA2m/gLQ108Z6k9mAMVDM6a+qusTKVElEZ5VXEmVWkg4rAbGZT1Zc0AKJAg== X-Received: by 2002:a5d:46cc:: with SMTP id g12mr40516250wrs.136.1625840788960; Fri, 09 Jul 2021 07:26:28 -0700 (PDT) Received: from bismarck.berto.se (p4fca2710.dip0.t-ipconnect.de. [79.202.39.16]) by smtp.googlemail.com with ESMTPSA id f82sm11034245wmf.25.2021.07.09.07.26.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 07:26:28 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org Cc: Jacopo Mondi , =?utf-8?q?Niklas_S=C3=B6derlund?= , Jacopo Mondi Subject: [PATCH v2 01/11] rcar-vin: Refactor controls creation for video device Date: Fri, 9 Jul 2021 16:25:50 +0200 Message-Id: <20210709142600.651718-2-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> References: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The controls for the video device are created in different code paths depending on if the driver is using the media graph centric model (Gen3) or the device centric model (Gen2 and earlier). This have lead to code duplication that can be consolidated. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- drivers/media/platform/rcar-vin/rcar-core.c | 82 +++++++++++---------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 33957cc9118ca79e..6ea561fcd7a394fa 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -405,6 +405,45 @@ static const struct v4l2_ctrl_ops rvin_ctrl_ops = { .s_ctrl = rvin_s_ctrl, }; +static void rvin_free_controls(struct rvin_dev *vin) +{ + v4l2_ctrl_handler_free(&vin->ctrl_handler); + vin->vdev.ctrl_handler = NULL; +} + +static int rvin_create_controls(struct rvin_dev *vin, struct v4l2_subdev *subdev) +{ + int ret; + + ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16); + if (ret < 0) + return ret; + + /* The VIN directly deals with alpha component. */ + v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops, + V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255); + + if (vin->ctrl_handler.error) { + ret = vin->ctrl_handler.error; + rvin_free_controls(vin); + return ret; + } + + /* For the non-MC mode add controls from the subdevice. */ + if (subdev) { + ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, + subdev->ctrl_handler, NULL, true); + if (ret < 0) { + rvin_free_controls(vin); + return ret; + } + } + + vin->vdev.ctrl_handler = &vin->ctrl_handler; + + return 0; +} + /* ----------------------------------------------------------------------------- * Async notifier */ @@ -490,28 +529,10 @@ static int rvin_parallel_subdevice_attach(struct rvin_dev *vin, return ret; /* Add the controls */ - ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16); + ret = rvin_create_controls(vin, subdev); if (ret < 0) return ret; - v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops, - V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255); - - if (vin->ctrl_handler.error) { - ret = vin->ctrl_handler.error; - v4l2_ctrl_handler_free(&vin->ctrl_handler); - return ret; - } - - ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, subdev->ctrl_handler, - NULL, true); - if (ret < 0) { - v4l2_ctrl_handler_free(&vin->ctrl_handler); - return ret; - } - - vin->vdev.ctrl_handler = &vin->ctrl_handler; - vin->parallel.subdev = subdev; return 0; @@ -522,10 +543,8 @@ static void rvin_parallel_subdevice_detach(struct rvin_dev *vin) rvin_v4l2_unregister(vin); vin->parallel.subdev = NULL; - if (!vin->info->use_mc) { - v4l2_ctrl_handler_free(&vin->ctrl_handler); - vin->vdev.ctrl_handler = NULL; - } + if (!vin->info->use_mc) + rvin_free_controls(vin); } static int rvin_parallel_notify_complete(struct v4l2_async_notifier *notifier) @@ -935,21 +954,10 @@ static int rvin_mc_init(struct rvin_dev *vin) if (ret) rvin_group_put(vin); - ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 1); + ret = rvin_create_controls(vin, NULL); if (ret < 0) return ret; - v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops, - V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255); - - if (vin->ctrl_handler.error) { - ret = vin->ctrl_handler.error; - v4l2_ctrl_handler_free(&vin->ctrl_handler); - return ret; - } - - vin->vdev.ctrl_handler = &vin->ctrl_handler; - return ret; } @@ -1450,7 +1458,7 @@ static int rcar_vin_probe(struct platform_device *pdev) return 0; error_group_unregister: - v4l2_ctrl_handler_free(&vin->ctrl_handler); + rvin_free_controls(vin); if (vin->info->use_mc) { mutex_lock(&vin->group->lock); @@ -1485,7 +1493,7 @@ static int rcar_vin_remove(struct platform_device *pdev) rvin_group_put(vin); } - v4l2_ctrl_handler_free(&vin->ctrl_handler); + rvin_free_controls(vin); rvin_dma_unregister(vin); From patchwork Fri Jul 9 14:25:51 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: 472116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29EC8C07E9C for ; Fri, 9 Jul 2021 14:26:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12581613BC for ; Fri, 9 Jul 2021 14:26:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231921AbhGIO3O (ORCPT ); Fri, 9 Jul 2021 10:29:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbhGIO3O (ORCPT ); Fri, 9 Jul 2021 10:29:14 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02D70C0613E5 for ; Fri, 9 Jul 2021 07:26:31 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id v5so12419906wrt.3 for ; Fri, 09 Jul 2021 07:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=REDzv9+6s/N+X5U5gFn/O0gbvXr5/Mxy0tkymEivpfM=; b=J8xPdC7LNcVfyQebl8RoVRlVv8lBRl9wsbT0WT0MibpfwU4KCFRfMB+rBJuox3qZ+w d9cklezxxRTB0yFO8U/hbGpdjA7T4OhN4a2dGZhtEvBjRT7Kww77cG4HVNxzkw/mKP2i TOCKOuVCLCmawep3pBglQFTth9rXthEL2Y5MFdRcmI4UXB/EOKaou/ZGX71NN2eSfuwc 1j57zpW1cnnWizohwBF9UVmy5CcpjVrr0VkiIivqxDZhUVyO0DQPdVkjsVHpDpfU9XZb D0FWOFkA8DANcRNQmHVV8OjRgWM7q3382DQLpFxp8Yd2JxErvrF5XRhGSUm0ln7VKTwr 6RBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=REDzv9+6s/N+X5U5gFn/O0gbvXr5/Mxy0tkymEivpfM=; b=aBhjz0qhqgwMoHrT+bAnw2Il8V+OwyKoNUmNbDFU4dR5b0N9IT/JZnl7s5p3v/hRYH UvFShxIp/R0Vv4wF9Ca8NzSzid8KSjSsfTfNjIKYFeemIEdzUTWHirmnpDyeQSkXEIzQ FH45Mec5xuy3s0/9Zal2RDBEdzktxKNGi/kULw5A2HDd8XwsUkscMQ83g8F/3B8cXR/S 9+Yzew4kFFb9lKGY6stgaiE+PDpjgY0ArpMdNHKvrlrYRtwNAXR8ChTsdklhK/GIklmq Hh/TY68Iu1C55jbkHWEx/K7iOvRdnVr+Gp76N425VD3TV8VkZLhIoeN0qVYLNJOonkGm neSg== X-Gm-Message-State: AOAM532srNb682HrUG8Fnh0/5rF+k4tKBeitF4K/ivqQm8q3x51hU74s KlXTpCDaI2rkX567FgrXYM5DNA== X-Google-Smtp-Source: ABdhPJzhiqwYFKTzIvTfyAQDaCoU6v/bYZ7b3ymddCIRsPCtD/0ElCBXcGC+/ASQxujm+vflsroK8A== X-Received: by 2002:adf:ee4f:: with SMTP id w15mr2983931wro.311.1625840789638; Fri, 09 Jul 2021 07:26:29 -0700 (PDT) Received: from bismarck.berto.se (p4fca2710.dip0.t-ipconnect.de. [79.202.39.16]) by smtp.googlemail.com with ESMTPSA id f82sm11034245wmf.25.2021.07.09.07.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 07:26:29 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org Cc: Jacopo Mondi , =?utf-8?q?Niklas_S=C3=B6derlund?= , Jacopo Mondi Subject: [PATCH v2 02/11] rcar-vin: Fix error paths for rvin_mc_init() Date: Fri, 9 Jul 2021 16:25:51 +0200 Message-Id: <20210709142600.651718-3-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> References: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The error paths of rvin_mc_init() do not clean up properly, fix this. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- drivers/media/platform/rcar-vin/rcar-core.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 6ea561fcd7a394fa..bea3880752169344 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -946,17 +946,23 @@ static int rvin_mc_init(struct rvin_dev *vin) if (ret) return ret; + ret = rvin_create_controls(vin, NULL); + if (ret < 0) + return ret; + ret = rvin_group_get(vin); if (ret) - return ret; + goto err_controls; ret = rvin_mc_parse_of_graph(vin); if (ret) - rvin_group_put(vin); + goto err_group; - ret = rvin_create_controls(vin, NULL); - if (ret < 0) - return ret; + return 0; +err_group: + rvin_group_put(vin); +err_controls: + rvin_free_controls(vin); return ret; } From patchwork Fri Jul 9 14:25:54 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: 472114 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95F50C07E9C for ; Fri, 9 Jul 2021 14:26:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7975E613B7 for ; Fri, 9 Jul 2021 14:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232267AbhGIO3S (ORCPT ); Fri, 9 Jul 2021 10:29:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbhGIO3R (ORCPT ); Fri, 9 Jul 2021 10:29:17 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95C74C0613DD for ; Fri, 9 Jul 2021 07:26:33 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id m2so1381077wrq.2 for ; Fri, 09 Jul 2021 07:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dIjTTygeZbv7LtQc+CXznZBMY8ib1/JEXHAQGomqmb4=; b=UL25GC+7CLmiuJnX9dR2EdAxAzLbaB/3x8LUZLp4bagroHUG6pOwERyLwBu41NnaJ+ iJzoGRPfkhVbPyZvjpvLrMiwt+rYvWoXifBeCD4Q4EODrlwqd8bW0FDnONQGJz/lq83c JfGZhAgBDja5z9TnIbpRdbKGAdMD3iu9q4Y7McV3pmaT0Kuz03VM2OdpMZRo6gfVx90P jt6RfLE9RVCbWh8Z/ebXWjfZp82l5VWxsur7Gfhi3aTWSDyojOsGiWoPANl0Jg6EsHbT OCdD9553x4kJV05TSGqg5JHwVdiZfxeA2OHhN0Qv4jK+3cy4Vd0DHL1zBmuyH2dF7woB VkgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dIjTTygeZbv7LtQc+CXznZBMY8ib1/JEXHAQGomqmb4=; b=LizR2l9sTR2GP/bhBZZYj7tqhEdkIHcZREo4egmQfe0BxBn7wEt/iq8NmSwWx6MgzL T7Z7lho4pS7xXgCaApA8FEImDzIHC4GsZXvlZK2KCH1jKpksRxqm+YhjeOm26ENpytNn JfQ7xUf6v8x0iR3N9mBapvxIAYaG3q3GC4JrXnwHGrWmxLn8bAy3BETRKqxjwQ8+qUpe GaC8fAK7WZ+a+Z4pn+FHUa9Uv9GX1U/BCTJAx1qtFTNyMeNmHVsj2KZPF5SGT2sAeUKL BA4Fjr5KqZiEL8hnLyTUuJXf/DHAGc5gA6bTzTUjHUWEJckHyc9a53pnJ+T1b/Gyrdi4 ZAKg== X-Gm-Message-State: AOAM531nBRBeggK5Bnk90J7bQnH2GXPpGrE2bmg0eLng7WaTR9IOTBI4 yYYKCHBePxmn4GmtJJDDXsMz7g== X-Google-Smtp-Source: ABdhPJwvj2CVc25NMv1Z7BTdTj/pTk8SXWP/SiE2AhEwEIIAlxJnPRB6HNPpfBFHNc7ZnuhOnwVr4g== X-Received: by 2002:a5d:48ce:: with SMTP id p14mr42795588wrs.170.1625840792107; Fri, 09 Jul 2021 07:26:32 -0700 (PDT) Received: from bismarck.berto.se (p4fca2710.dip0.t-ipconnect.de. [79.202.39.16]) by smtp.googlemail.com with ESMTPSA id f82sm11034245wmf.25.2021.07.09.07.26.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 07:26:31 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org Cc: Jacopo Mondi , =?utf-8?q?Niklas_S=C3=B6derlund?= , Jacopo Mondi Subject: [PATCH v2 05/11] rcar-vin: Rename array storing subdevice information Date: Fri, 9 Jul 2021 16:25:54 +0200 Message-Id: <20210709142600.651718-6-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> References: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The VIN group have always been connected to CSI-2 receivers and this have spilled over to the naming of the array storing the subdevice information. In preparation for connecting other types of subdevices rename the array to remotes. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- drivers/media/platform/rcar-vin/rcar-core.c | 32 ++++++++++----------- drivers/media/platform/rcar-vin/rcar-vin.h | 8 ++++-- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 674766be1ad590a7..a44cfa993ec8893d 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -49,16 +49,16 @@ */ /* group lock should be held when calling this function. */ -static int rvin_group_entity_to_csi_id(struct rvin_group *group, - struct media_entity *entity) +static int rvin_group_entity_to_remote_id(struct rvin_group *group, + struct media_entity *entity) { struct v4l2_subdev *sd; unsigned int i; sd = media_entity_to_v4l2_subdev(entity); - for (i = 0; i < RVIN_CSI_MAX; i++) - if (group->csi[i].subdev == sd) + for (i = 0; i < RVIN_REMOTES_MAX; i++) + if (group->remotes[i].subdev == sd) return i; return -ENODEV; @@ -163,14 +163,14 @@ static int rvin_group_link_notify(struct media_link *link, u32 flags, if (!csi_pad) continue; - csi_id = rvin_group_entity_to_csi_id(group, csi_pad->entity); + csi_id = rvin_group_entity_to_remote_id(group, csi_pad->entity); channel = rvin_group_csi_pad_to_channel(csi_pad->index); mask &= rvin_group_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_csi_id(group, link->source->entity); + csi_id = rvin_group_entity_to_remote_id(group, link->source->entity); if (csi_id == -ENODEV) { struct v4l2_subdev *sd; @@ -766,10 +766,10 @@ static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) continue; /* Check that CSI-2 is part of the group. */ - if (!vin->group->csi[route->csi].subdev) + if (!vin->group->remotes[route->csi].subdev) continue; - source = &vin->group->csi[route->csi].subdev->entity; + source = &vin->group->remotes[route->csi].subdev->entity; source_idx = rvin_group_csi_channel_to_pad(route->channel); source_pad = &source->pads[source_idx]; @@ -806,10 +806,10 @@ static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, mutex_lock(&vin->group->lock); for (i = 0; i < RVIN_CSI_MAX; i++) { - if (vin->group->csi[i].asd != asd) + if (vin->group->remotes[i].asd != asd) continue; - vin->group->csi[i].subdev = NULL; - vin_dbg(vin, "Unbind CSI-2 %s from slot %u\n", subdev->name, i); + vin->group->remotes[i].subdev = NULL; + vin_dbg(vin, "Unbind %s from slot %u\n", subdev->name, i); break; } @@ -828,10 +828,10 @@ static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier, mutex_lock(&vin->group->lock); for (i = 0; i < RVIN_CSI_MAX; i++) { - if (vin->group->csi[i].asd != asd) + if (vin->group->remotes[i].asd != asd) continue; - vin->group->csi[i].subdev = subdev; - vin_dbg(vin, "Bound CSI-2 %s to slot %u\n", subdev->name, i); + vin->group->remotes[i].subdev = subdev; + vin_dbg(vin, "Bound %s to slot %u\n", subdev->name, i); break; } @@ -883,7 +883,7 @@ static int rvin_mc_parse_of(struct rvin_dev *vin, unsigned int id) goto out; } - vin->group->csi[vep.base.id].asd = asd; + vin->group->remotes[vep.base.id].asd = asd; vin_dbg(vin, "Add group OF device %pOF to slot %u\n", to_of_node(fwnode), vep.base.id); @@ -928,7 +928,7 @@ static int rvin_mc_parse_of_graph(struct rvin_dev *vin) continue; for (id = 0; id < RVIN_CSI_MAX; id++) { - if (vin->group->csi[id].asd) + if (vin->group->remotes[id].asd) continue; ret = rvin_mc_parse_of(vin->group->vin[i], id); diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index b263ead4db2bfb08..39207aaf39ef9391 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -48,6 +48,8 @@ enum rvin_csi_id { RVIN_CSI_MAX, }; +#define RVIN_REMOTES_MAX RVIN_CSI_MAX + /** * enum rvin_dma_state - DMA states * @STOPPED: No operation in progress @@ -267,8 +269,8 @@ struct rvin_dev { * @count: number of enabled VIN instances found in DT * @notifier: group notifier for CSI-2 async subdevices * @vin: VIN instances which are part of the group - * @csi: array of pairs of fwnode and subdev pointers - * to all CSI-2 subdevices. + * @remotes: array of pairs of fwnode and subdev pointers + * to all remote subdevices. */ struct rvin_group { struct kref refcount; @@ -283,7 +285,7 @@ struct rvin_group { struct { struct v4l2_async_subdev *asd; struct v4l2_subdev *subdev; - } csi[RVIN_CSI_MAX]; + } remotes[RVIN_REMOTES_MAX]; }; int rvin_dma_register(struct rvin_dev *vin, int irq); From patchwork Fri Jul 9 14:25:56 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: 472112 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B03F4C07E9E for ; Fri, 9 Jul 2021 14:26:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 997C4613BC for ; Fri, 9 Jul 2021 14:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232291AbhGIO3T (ORCPT ); Fri, 9 Jul 2021 10:29:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbhGIO3S (ORCPT ); Fri, 9 Jul 2021 10:29:18 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FA23C0613E5 for ; Fri, 9 Jul 2021 07:26:35 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id l18-20020a1ced120000b029014c1adff1edso9212925wmh.4 for ; Fri, 09 Jul 2021 07:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lVYndLyj3uerm193pKMzGgivY6yXF4tA+XFaFHPGQK4=; b=RpcKkLquo8tfZs7GMzXITV7Cld04/VHjdnYx3IzO0sGX5kCMnnMebKF3oO30dj0Ioz +EMw3Jau27QO7ALn5k2oQkuEFozBvcG2Kw5oHUpNlF/i1tjZR+ieWXNLo4/fb2FdSNUV nzfWWCN9nar96qgQGeuO7aoaXCT5S2uNtHltziD5Om9UcptN5q/l7gYOeNEPxj7nZd1p fTJ67GblNmnh4aI14Ol5YMOXEX42aB5IzJs/5MV9YRMd9/J7r6dfYh9jiSK0kZIZnML/ evTtix8xQaKtbfRAA4VgFlnJG4tyP47J0zHlA1RkQFstxfhVye7v/NHRGTyEhSDxfglO AGQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lVYndLyj3uerm193pKMzGgivY6yXF4tA+XFaFHPGQK4=; b=SxC4yLAyRurU08d1LbD9SWLBE+hqePcgX552Wjr4zOSLmlPOtXeRk2IzJOYnzTaVFr yto+y43NwnR9Eb2CUB9QHgW7Iut4USH8FRhVmSDgQId/tLYtzsfQY0wNyXGXDVUwIOGY AWvaEtFDkAOphHEhuIEEqEsbFrg3bMYsFr9MUy8Fq5R+cTYMWyoUHxpOrHH9GQlRvYqB 6jT/tP5dHQdi73nunB/1AJKdojeZoBwT9tBmD7D6/YzYB/Qf1MFAPw6GkcEUz+hKtL6h IBMcLX4G2l7Vaxp1mdlFmZH2Gd80fZQ0LLAIlhnlpn1LaupNY1zMhIKkQMP+Tjf9ibFq u/dQ== X-Gm-Message-State: AOAM5333I+sJgI7O64zt4mWQ2NJpzIFRb+kHmRWrKqNRHUJdM7yRME07 P9BX01uot84Re2z1Is9xPx5xqBSXJT7JSJOs X-Google-Smtp-Source: ABdhPJwrePiBzsjJ4n4b0zF0BE+ZyHNQAlXZ+xnSEl/U7Xc4dxcbHToxNmsbaoD5Jm3OdH7/pUfpDA== X-Received: by 2002:a1c:1bd0:: with SMTP id b199mr22793507wmb.108.1625840793709; Fri, 09 Jul 2021 07:26:33 -0700 (PDT) Received: from bismarck.berto.se (p4fca2710.dip0.t-ipconnect.de. [79.202.39.16]) by smtp.googlemail.com with ESMTPSA id f82sm11034245wmf.25.2021.07.09.07.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 07:26:33 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org Cc: Jacopo Mondi , =?utf-8?q?Niklas_S=C3=B6derlund?= , Jacopo Mondi Subject: [PATCH v2 07/11] rcar-vin: Extend group notifier DT parser to work with any port Date: Fri, 9 Jul 2021 16:25:56 +0200 Message-Id: <20210709142600.651718-8-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> References: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The R-Car VIN group notifier will be extend to support a new group of subdevices, the R-Car ISP channel selector in addition to the existing R-Car CSI-2 receiver subdevices. The existing DT parsing code can be reused if the port and max number of endpoints are provided as parameters instead of being hard-coded. While at it align the group notifier parser function names with the rest of the driver. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- drivers/media/platform/rcar-vin/rcar-core.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 3585985e822560ea..ae2a145b04f681f8 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -506,7 +506,8 @@ static const struct v4l2_async_notifier_operations rvin_group_notify_ops = { .complete = rvin_group_notify_complete, }; -static int rvin_mc_parse_of(struct rvin_dev *vin, unsigned int id) +static int rvin_group_parse_of(struct rvin_dev *vin, unsigned int port, + unsigned int id) { struct fwnode_handle *ep, *fwnode; struct v4l2_fwnode_endpoint vep = { @@ -515,7 +516,7 @@ static int rvin_mc_parse_of(struct rvin_dev *vin, unsigned int id) struct v4l2_async_subdev *asd; int ret; - ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(vin->dev), 1, id, 0); + ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(vin->dev), port, id, 0); if (!ep) return 0; @@ -563,7 +564,8 @@ static void rvin_group_notifier_cleanup(struct rvin_dev *vin) mutex_unlock(&vin->group->lock); } -static int rvin_mc_parse_of_graph(struct rvin_dev *vin) +static int rvin_group_notifier_init(struct rvin_dev *vin, unsigned int port, + unsigned int max_id) { unsigned int count = 0, vin_mask = 0; unsigned int i, id; @@ -589,19 +591,18 @@ static int rvin_mc_parse_of_graph(struct rvin_dev *vin) v4l2_async_notifier_init(&vin->group->notifier); /* - * Have all VIN's look for CSI-2 subdevices. Some subdevices will - * overlap but the parser function can handle it, so each subdevice - * will only be registered once with the group notifier. + * Some subdevices may overlap but the parser function can handle it and + * each subdevice will only be registered once with the group notifier. */ for (i = 0; i < RCAR_VIN_NUM; i++) { if (!(vin_mask & BIT(i))) continue; - for (id = 0; id < RVIN_CSI_MAX; id++) { + for (id = 0; id < max_id; id++) { if (vin->group->remotes[id].asd) continue; - ret = rvin_mc_parse_of(vin->group->vin[i], id); + ret = rvin_group_parse_of(vin->group->vin[i], port, id); if (ret) return ret; } @@ -982,7 +983,7 @@ static int rvin_csi2_init(struct rvin_dev *vin) if (ret && ret != -ENODEV) goto err_group; - ret = rvin_mc_parse_of_graph(vin); + ret = rvin_group_notifier_init(vin, 1, RVIN_CSI_MAX); if (ret) goto err_parallel; From patchwork Fri Jul 9 14:25:57 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: 472113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28E2CC11F66 for ; Fri, 9 Jul 2021 14:26:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11CA5613BD for ; Fri, 9 Jul 2021 14:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232295AbhGIO3U (ORCPT ); Fri, 9 Jul 2021 10:29:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231622AbhGIO3T (ORCPT ); Fri, 9 Jul 2021 10:29:19 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA8B0C0613DD for ; Fri, 9 Jul 2021 07:26:35 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id j34so6433130wms.5 for ; Fri, 09 Jul 2021 07:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IzvsPA56XjfGrMtR024sg8gAMCpe1sF+gkqcNbFn0jQ=; b=jVmi4Dkyg3UZoArxkkiEnxlYWbKaaCNWE0C3XdDGG+V0QbxSgZqWW03XirLZAIn3Y3 jadEeAcfHXuZVCsk24fKCMPE/SCPabRzs/tnGnQCdV78NFQcAgdPqmhJr7Fg6h04u11s ADvBXjJNfFxYZAwV5v/JyKpfWy+Mf8BhCKmjnhRokZyVZl5cHYFV4LJDBVCu10nqYaCV B0YpIcPyi09santt97/e8IafHfN3ZKKG+TyjH647oEqNQPMmEDQc5WeGO3TFkxRksiRN p6p0Xw0ExrMsx0hov7SKKdrsQb/n4advDM1U1i00JjU16T8EK3ITtq07Zh3phBG9dGpD /5+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IzvsPA56XjfGrMtR024sg8gAMCpe1sF+gkqcNbFn0jQ=; b=XSx2aM/XmecqprG6iSS5S7VqkVPJmDC7pCeQdykdbv6bqhkHjyc1rlQYxIwIBWa/J5 X59U20R9K419xajoK/4LDH6XxBMZoHy7FS8/NnRoxW2Bii87o9Z2luNysCNQkXnkMiR0 +S/NpabNV3ErhHqEKrXDWkmsveKAN6WYBSuKCby8HkJQEHNprUKGkF0RHsYjdzh+q3UE O9GPQkpp7boE0U1upP6lTacB7ag4OHChUzHin+08nFYZ7Ll2RKNr+mDrmZyPKahrXaG3 OFF9ZnKuJhjZrGOYy863EvW6Gfn0U7S4NDrU7ZS4LbvNmIjQhMgaZ+W9RBeov/MaC5tj W4Eg== X-Gm-Message-State: AOAM532fB0SnBraRt2dUX7pWC8Ss4fYX597QX6JwP1hV3rxOpjhC8IMO L2YMheQ+RsYdvAAwmuCx2g4GQQ== X-Google-Smtp-Source: ABdhPJy3hNKvS/Kv4mYUfJb5ESQhiAVqHMh2blcrWKTbBM8vfKA2PSFjQfH2tr3EJamxEzuwWLTnqQ== X-Received: by 2002:a05:600c:3b9f:: with SMTP id n31mr33049881wms.123.1625840794389; Fri, 09 Jul 2021 07:26:34 -0700 (PDT) Received: from bismarck.berto.se (p4fca2710.dip0.t-ipconnect.de. [79.202.39.16]) by smtp.googlemail.com with ESMTPSA id f82sm11034245wmf.25.2021.07.09.07.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 07:26:34 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org Cc: Jacopo Mondi , =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v2 08/11] rcar-vin: Create a callback to setup media links Date: Fri, 9 Jul 2021 16:25:57 +0200 Message-Id: <20210709142600.651718-9-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> References: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org New IP versions will have different media graphs and require a different link setup. Breakout the specific link setup to a callback that are associated with the group. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- * Changes since v1 - Allow the link_setup() to return an error code. --- drivers/media/platform/rcar-vin/rcar-core.c | 101 +++++++++++--------- drivers/media/platform/rcar-vin/rcar-vin.h | 3 + 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index ae2a145b04f681f8..d04c222702ba03d1 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -247,7 +247,8 @@ static void rvin_group_cleanup(struct rvin_group *group) mutex_destroy(&group->lock); } -static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin) +static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin, + int (*link_setup)(struct rvin_dev *)) { struct media_device *mdev = &group->mdev; const struct of_device_id *match; @@ -263,6 +264,8 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin) vin_dbg(vin, "found %u enabled VIN's in DT", group->count); + group->link_setup = link_setup; + mdev->dev = vin->dev; mdev->ops = &rvin_media_ops; @@ -295,7 +298,8 @@ static void rvin_group_release(struct kref *kref) mutex_unlock(&rvin_group_lock); } -static int rvin_group_get(struct rvin_dev *vin) +static int rvin_group_get(struct rvin_dev *vin, + int (*link_setup)(struct rvin_dev *)) { struct rvin_group *group; u32 id; @@ -327,7 +331,7 @@ static int rvin_group_get(struct rvin_dev *vin) goto err_group; } - ret = rvin_group_init(group, vin); + ret = rvin_group_init(group, vin, link_setup); if (ret) { kfree(group); vin_err(vin, "Failed to initialize group\n"); @@ -386,7 +390,6 @@ static void rvin_group_put(struct rvin_dev *vin) static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) { struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev); - const struct rvin_group_route *route; unsigned int i; int ret; @@ -410,46 +413,7 @@ static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) } } - /* Create all media device links between VINs and CSI-2's. */ - mutex_lock(&vin->group->lock); - for (route = vin->info->routes; route->mask; route++) { - struct media_pad *source_pad, *sink_pad; - struct media_entity *source, *sink; - unsigned int source_idx; - - /* Check that VIN is part of the group. */ - if (!vin->group->vin[route->vin]) - continue; - - /* Check that VIN' master is part of the group. */ - if (!vin->group->vin[rvin_group_id_to_master(route->vin)]) - continue; - - /* Check that CSI-2 is part of the group. */ - if (!vin->group->remotes[route->csi].subdev) - continue; - - source = &vin->group->remotes[route->csi].subdev->entity; - source_idx = rvin_group_csi_channel_to_pad(route->channel); - source_pad = &source->pads[source_idx]; - - sink = &vin->group->vin[route->vin]->vdev.entity; - sink_pad = &sink->pads[0]; - - /* Skip if link already exists. */ - if (media_entity_find_link(source_pad, sink_pad)) - continue; - - ret = media_create_pad_link(source, source_idx, sink, 0, 0); - if (ret) { - vin_err(vin, "Error adding link from %s to %s\n", - source->name, sink->name); - break; - } - } - mutex_unlock(&vin->group->lock); - - return ret; + return vin->group->link_setup(vin); } static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, @@ -953,6 +917,53 @@ static int rvin_parallel_init(struct rvin_dev *vin) * CSI-2 */ +static int rvin_csi2_setup_links(struct rvin_dev *vin) +{ + const struct rvin_group_route *route; + int ret = -EINVAL; + + /* Create all media device links between VINs and CSI-2's. */ + mutex_lock(&vin->group->lock); + for (route = vin->info->routes; route->mask; route++) { + struct media_pad *source_pad, *sink_pad; + struct media_entity *source, *sink; + unsigned int source_idx; + + /* Check that VIN is part of the group. */ + if (!vin->group->vin[route->vin]) + continue; + + /* Check that VIN' master is part of the group. */ + if (!vin->group->vin[rvin_group_id_to_master(route->vin)]) + continue; + + /* Check that CSI-2 is part of the group. */ + if (!vin->group->remotes[route->csi].subdev) + continue; + + source = &vin->group->remotes[route->csi].subdev->entity; + source_idx = rvin_group_csi_channel_to_pad(route->channel); + source_pad = &source->pads[source_idx]; + + sink = &vin->group->vin[route->vin]->vdev.entity; + sink_pad = &sink->pads[0]; + + /* Skip if link already exists. */ + if (media_entity_find_link(source_pad, sink_pad)) + continue; + + ret = media_create_pad_link(source, source_idx, sink, 0, 0); + if (ret) { + vin_err(vin, "Error adding link from %s to %s\n", + source->name, sink->name); + break; + } + } + mutex_unlock(&vin->group->lock); + + return ret; +} + static void rvin_csi2_cleanup(struct rvin_dev *vin) { rvin_parallel_cleanup(vin); @@ -974,7 +985,7 @@ static int rvin_csi2_init(struct rvin_dev *vin) if (ret < 0) return ret; - ret = rvin_group_get(vin); + ret = rvin_group_get(vin, rvin_csi2_setup_links); if (ret) goto err_controls; diff --git a/drivers/media/platform/rcar-vin/rcar-vin.h b/drivers/media/platform/rcar-vin/rcar-vin.h index 39207aaf39ef9391..49c148c40ea52b79 100644 --- a/drivers/media/platform/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/rcar-vin/rcar-vin.h @@ -269,6 +269,7 @@ struct rvin_dev { * @count: number of enabled VIN instances found in DT * @notifier: group notifier for CSI-2 async subdevices * @vin: VIN instances which are part of the group + * @link_setup: Callback to create all links for the media graph * @remotes: array of pairs of fwnode and subdev pointers * to all remote subdevices. */ @@ -282,6 +283,8 @@ struct rvin_group { struct v4l2_async_notifier notifier; struct rvin_dev *vin[RCAR_VIN_NUM]; + int (*link_setup)(struct rvin_dev *vin); + struct { struct v4l2_async_subdev *asd; struct v4l2_subdev *subdev; From patchwork Fri Jul 9 14:25:59 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: 472111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81080C11F68 for ; Fri, 9 Jul 2021 14:26:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AA90613BD for ; Fri, 9 Jul 2021 14:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232310AbhGIO3W (ORCPT ); Fri, 9 Jul 2021 10:29:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232305AbhGIO3V (ORCPT ); Fri, 9 Jul 2021 10:29:21 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A48CC0613DD for ; Fri, 9 Jul 2021 07:26:37 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id i8so12367487wrp.12 for ; Fri, 09 Jul 2021 07:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LfLrhSqXgUTyC6zm1rNKNMjeoTtRgEMqAjUYBFFVPaY=; b=A1jTj/ZX3KBxXMR3ws5EaRRWwFDkh17JLf4CVmw2OhXxe8tpcp+7nv/k4PW6UI3q6S An9aY73aGG5IaIXyQ7U1NInV6BBqqRzg3+N78j9S2d0gqCc5ZSP8NeGcAOfEmiAzwtlk RQhPwkiGYe34EdTA6WH972Ie6U/VlZ8ROP2hqeUqHdtsMJbtk/OUBSXaqAXLHtC/nXK9 ad13gNdNSka9pupf5cOfy56ckgnxXdGkP2k1jltadCXzYGKpIELJIAxqg9gDMzHNqy7j buimIqeK1hGnkzHP/qP3iE6Ce38yqENCP62h1zAukEoiwxEWVpyNtMtaoJ2MS34L/ftM 6zlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LfLrhSqXgUTyC6zm1rNKNMjeoTtRgEMqAjUYBFFVPaY=; b=bwW40Lsu8z8Jx5Z47C3ODQevTsXiWFWVBh96eoN0MCGxzd/jGAAvbTIFe5hYnHOMNm GIy22NdsfPUtztBLGe3t/c5uS1TNBT/XocVLQEVllLDckW8Ibag36VgfLCwcXDZUVN3j jKdgdxUHDFMRdEakmrZyl+DedRYKxTsV3/2aBMLyeLIJWP58prk1NDZkRxxZbn0gjgpT WN1pJ/TyVBPFumKRBs2nxfOueozIMrs+rBOh4M2PZ+ntCBP25Hsul8x20a7F0Gl+Nwdi xxXACBJS1PNk/HDpGHZi/XpYXOi0q8fdnuqZWZ4kSezfO1kxSYAkRR64GTihNueXEGrF FNNg== X-Gm-Message-State: AOAM530aGuasf+3y1JBovANbo+x12R4GJf7u1L2C6qqp1yMTpCArkdky Y9jhXPISpxrjaehLZRd+do0UAg== X-Google-Smtp-Source: ABdhPJzHL/uPMe6Gxx8EvNkSi6/SAvBV+uyBd7ojoRNE6gWMePewgCXPeyy2w4Pc7LbYa+4fgxMpyw== X-Received: by 2002:adf:fa4c:: with SMTP id y12mr42699763wrr.302.1625840795960; Fri, 09 Jul 2021 07:26:35 -0700 (PDT) Received: from bismarck.berto.se (p4fca2710.dip0.t-ipconnect.de. [79.202.39.16]) by smtp.googlemail.com with ESMTPSA id f82sm11034245wmf.25.2021.07.09.07.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 07:26:35 -0700 (PDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Hans Verkuil , linux-media@vger.kernel.org Cc: Jacopo Mondi , =?utf-8?q?Niklas_S=C3=B6derlund?= , Jacopo Mondi Subject: [PATCH v2 10/11] rcar-vin: Move and rename CSI-2 link notifications Date: Fri, 9 Jul 2021 16:25:59 +0200 Message-Id: <20210709142600.651718-11-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> References: <20210709142600.651718-1-niklas.soderlund+renesas@ragnatech.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The CSI-2 link notifications are no longer the only option for the VIN group. Change the symbol prefix to rvin_csi2_ for all CSI-2 specific code and move the link notification code to the correct section not to mix it with the soon to be added R-Car ISP channel selector notification helpers. There is no functional change and apart from the symbol prefix change all functions are moved verbatim. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- * Changes since v1 - Fix a comment in the code that no long is CSI2 exclusive. - Fix spelling in commit message. --- drivers/media/platform/rcar-vin/rcar-core.c | 362 ++++++++++---------- 1 file changed, 179 insertions(+), 183 deletions(-) diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c index 8c27d9d5ca7e42b5..0653e1ce144860fe 100644 --- a/drivers/media/platform/rcar-vin/rcar-core.c +++ b/drivers/media/platform/rcar-vin/rcar-core.c @@ -45,188 +45,7 @@ #define v4l2_dev_to_vin(d) container_of(d, struct rvin_dev, v4l2_dev) /* ----------------------------------------------------------------------------- - * Media Controller link notification - */ - -/* group lock should be held when calling this function. */ -static int rvin_group_entity_to_remote_id(struct rvin_group *group, - struct media_entity *entity) -{ - struct v4l2_subdev *sd; - unsigned int i; - - sd = media_entity_to_v4l2_subdev(entity); - - for (i = 0; i < RVIN_REMOTES_MAX; i++) - if (group->remotes[i].subdev == sd) - return i; - - return -ENODEV; -} - -static unsigned int rvin_group_get_mask(struct rvin_dev *vin, - enum rvin_csi_id csi_id, - unsigned char channel) -{ - const struct rvin_group_route *route; - unsigned int mask = 0; - - for (route = vin->info->routes; route->mask; route++) { - if (route->vin == vin->id && - route->csi == csi_id && - route->channel == channel) { - vin_dbg(vin, - "Adding route: vin: %d csi: %d channel: %d\n", - route->vin, route->csi, route->channel); - mask |= route->mask; - } - } - - return mask; -} - -/* - * Link setup for the links between a VIN and a CSI-2 receiver is a bit - * complex. The reason for this is that the register controlling routing - * is not present in each VIN instance. There are special VINs which - * control routing for themselves and other VINs. There are not many - * different possible links combinations that can be enabled at the same - * time, therefor all already enabled links which are controlled by a - * master VIN need to be taken into account when making the decision - * if a new link can be enabled or not. - * - * 1. Find out which VIN the link the user tries to enable is connected to. - * 2. Lookup which master VIN controls the links for this VIN. - * 3. Start with a bitmask with all bits set. - * 4. For each previously enabled link from the master VIN bitwise AND its - * route mask (see documentation for mask in struct rvin_group_route) - * with the bitmask. - * 5. Bitwise AND the mask for the link the user tries to enable to the bitmask. - * 6. If the bitmask is not empty at this point the new link can be enabled - * while keeping all previous links enabled. Update the CHSEL value of the - * master VIN and inform the user that the link could be enabled. - * - * Please note that no link can be enabled if any VIN in the group is - * currently open. - */ -static int rvin_group_link_notify(struct media_link *link, u32 flags, - unsigned int notification) -{ - 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; - int csi_id, ret; - - ret = v4l2_pipeline_link_notify(link, flags, notification); - if (ret) - return ret; - - /* Only care about link enablement for VIN nodes. */ - if (!(flags & MEDIA_LNK_FL_ENABLED) || - !is_media_entity_v4l2_video_device(link->sink->entity)) - return 0; - - /* - * Don't allow link changes if any entity in the graph is - * streaming, modifying the CHSEL register fields can disrupt - * running streams. - */ - media_device_for_each_entity(entity, &group->mdev) - 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; - } - - /* 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_group_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; - - /* - * Make sure the source entity subdevice is registered as - * a parallel input of one of the enabled VINs if it is not - * one of the CSI-2 subdevices. - * - * No hardware configuration required for parallel inputs, - * we can return here. - */ - sd = media_entity_to_v4l2_subdev(link->source->entity); - for (i = 0; i < RCAR_VIN_NUM; i++) { - if (group->vin[i] && - group->vin[i]->parallel.subdev == sd) { - group->vin[i]->is_csi = false; - ret = 0; - goto out; - } - } - - vin_err(vin, "Subdevice %s not registered to any VIN\n", - link->source->entity->name); - ret = -ENODEV; - goto out; - } - - channel = rvin_group_csi_pad_to_channel(link->source->index); - mask_new = mask & rvin_group_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); - - return ret; -} - -static const struct media_device_ops rvin_media_ops = { - .link_notify = rvin_group_link_notify, -}; - -/* ----------------------------------------------------------------------------- - * Gen3 CSI2 Group Allocator + * Gen3 Group Allocator */ /* FIXME: This should if we find a system that supports more @@ -389,6 +208,22 @@ static void rvin_group_put(struct rvin_dev *vin) kref_put(&group->refcount, rvin_group_release); } +/* group lock should be held when calling this function. */ +static int rvin_group_entity_to_remote_id(struct rvin_group *group, + struct media_entity *entity) +{ + struct v4l2_subdev *sd; + unsigned int i; + + sd = media_entity_to_v4l2_subdev(entity); + + for (i = 0; i < RVIN_REMOTES_MAX; i++) + if (group->remotes[i].subdev == sd) + return i; + + return -ENODEV; +} + static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) { struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev); @@ -919,6 +754,167 @@ static int rvin_parallel_init(struct rvin_dev *vin) * CSI-2 */ +static unsigned int rvin_csi2_get_mask(struct rvin_dev *vin, + enum rvin_csi_id csi_id, + unsigned char channel) +{ + const struct rvin_group_route *route; + unsigned int mask = 0; + + for (route = vin->info->routes; route->mask; route++) { + if (route->vin == vin->id && + route->csi == csi_id && + route->channel == channel) { + vin_dbg(vin, + "Adding route: vin: %d csi: %d channel: %d\n", + route->vin, route->csi, route->channel); + mask |= route->mask; + } + } + + return mask; +} + +/* + * Link setup for the links between a VIN and a CSI-2 receiver is a bit + * complex. The reason for this is that the register controlling routing + * is not present in each VIN instance. There are special VINs which + * control routing for themselves and other VINs. There are not many + * different possible links combinations that can be enabled at the same + * time, therefor all already enabled links which are controlled by a + * master VIN need to be taken into account when making the decision + * if a new link can be enabled or not. + * + * 1. Find out which VIN the link the user tries to enable is connected to. + * 2. Lookup which master VIN controls the links for this VIN. + * 3. Start with a bitmask with all bits set. + * 4. For each previously enabled link from the master VIN bitwise AND its + * route mask (see documentation for mask in struct rvin_group_route) + * with the bitmask. + * 5. Bitwise AND the mask for the link the user tries to enable to the bitmask. + * 6. If the bitmask is not empty at this point the new link can be enabled + * while keeping all previous links enabled. Update the CHSEL value of the + * master VIN and inform the user that the link could be enabled. + * + * Please note that no link can be enabled if any VIN in the group is + * currently open. + */ +static int rvin_csi2_link_notify(struct media_link *link, u32 flags, + unsigned int notification) +{ + 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; + int csi_id, ret; + + ret = v4l2_pipeline_link_notify(link, flags, notification); + if (ret) + return ret; + + /* Only care about link enablement for VIN nodes. */ + if (!(flags & MEDIA_LNK_FL_ENABLED) || + !is_media_entity_v4l2_video_device(link->sink->entity)) + return 0; + + /* + * Don't allow link changes if any entity in the graph is + * streaming, modifying the CHSEL register fields can disrupt + * running streams. + */ + media_device_for_each_entity(entity, &group->mdev) + 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; + } + + /* 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; + + /* + * Make sure the source entity subdevice is registered as + * a parallel input of one of the enabled VINs if it is not + * one of the CSI-2 subdevices. + * + * No hardware configuration required for parallel inputs, + * we can return here. + */ + sd = media_entity_to_v4l2_subdev(link->source->entity); + for (i = 0; i < RCAR_VIN_NUM; i++) { + if (group->vin[i] && + group->vin[i]->parallel.subdev == sd) { + group->vin[i]->is_csi = false; + ret = 0; + goto out; + } + } + + vin_err(vin, "Subdevice %s not registered to any VIN\n", + link->source->entity->name); + ret = -ENODEV; + goto out; + } + + 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); + + return ret; +} + +static const struct media_device_ops rvin_csi2_media_ops = { + .link_notify = rvin_csi2_link_notify, +}; + static int rvin_csi2_setup_links(struct rvin_dev *vin) { const struct rvin_group_route *route; @@ -987,7 +983,7 @@ static int rvin_csi2_init(struct rvin_dev *vin) if (ret < 0) return ret; - ret = rvin_group_get(vin, rvin_csi2_setup_links, &rvin_media_ops); + ret = rvin_group_get(vin, rvin_csi2_setup_links, &rvin_csi2_media_ops); if (ret) goto err_controls;