From patchwork Wed May 21 13:20:32 2025 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: 891617 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64CE326D4EB; Wed, 21 May 2025 13:21:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747833689; cv=none; b=nlLoqIt7lt4obyJnGWj/sn7ikT9fIDVhRfwNqka3jfSm203Ek+6KKMMQKjX3wrCUnRwQ8zWYdIq9CWJGOvX4oflAPpXIKX21yw+L7E6aQ8juneUbk7ZG7xK4dDEwxyAI0ovN3VEm/JYalDYjynEgf/YUK2GcFMrHJE0YJPqJG/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747833689; c=relaxed/simple; bh=sfWonh8KgG9SVcgst+ESZk9f51EiHh/9IVxE1J6eFok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TbnR65IAPxXb740/ASIRnupXdH+ykb5KjOflLNamjBxSCo8fC7IiuOx/RsXScOqUBzw7hTduEfeeqS8CL6r1wZ/nt3p9EuyhxEB4mUbcujcMSDWVAYSl7e6GynvxpckAqVMXq8nhIu7C8eVtDGb5hllaLKNQSCCjNlZP72fEseo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b=tNYph5Ge; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jpx1ZjB+; arc=none smtp.client-ip=202.12.124.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b="tNYph5Ge"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jpx1ZjB+" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 58C64114012F; Wed, 21 May 2025 09:21:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 21 May 2025 09:21:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1747833686; x=1747920086; bh=ag1sBhpk21cQwhPAldR462s8gAi6uyxSJ+eV/ePJe4g=; b= tNYph5GeRTwHgKVfsdPSvnmDD5b/u51juI50lyM4EU2x9GKmIwXthTTLAvf9qowJ Dd+Tj1Lv9of4CS8OIXVjU0qAXxVALPYykXjg7qyqp8VNwvsBmph9NfkQseSj8wqR 4NidPpdJ8PnfUtDLn7E8eGeMgQ5z1sjHTeZNUOvHKfa0tIaOuyRsZh3h2KZCdk6k +S3YLKBgXdx5hbe17sYp//ONJ6jC5ZuQv6sEbJZW3lEJowh59NP9Uwi6gs2DJLku wsx6j6x1o5g242pDIPFBJX0jRUcLADTNNunlA/3D3AApPCzIzcfKDvAEjSkN5YH1 yTK1P83YCoyLtiMZHx65XA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1747833686; x= 1747920086; bh=ag1sBhpk21cQwhPAldR462s8gAi6uyxSJ+eV/ePJe4g=; b=j px1ZjB+fXf6ol4C7PF+/tVTxOUZMezN7eLsqEEWe9S7kPPMbmb/xAfMrajIuuqpK RIRmup50002n/+lV4+cl/1fs5ONFTHBgjTymNqNxmJohwKSFiPW+QxugkCw91H3x 3vNrGA2xMpau1U+ZFIG/t8zmm3kjSCAR6OrJ9ycfmCs3LJO764sb2a+QA50Ll7yW lMP6U20RwbAhTJ5DhgzN8whwre+M1GDKM6d046e09PGis4g+9UwGJ0VJq9Cpm49m WlLpASpQ2n1JTK+DKJy4va6TeezLTGrgaKQHLHbeNxed5WL+/6v9AR5NXr4oe/SK w4fMYkJOkud73D4n6b6/A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdefudekucdltddurdegfedvrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgf nhhsuhgsshgtrhhisggvpdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttd enucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgj fhggtgfgsehtkeertdertdejnecuhfhrohhmpefpihhklhgrshcuufpnuggvrhhluhhnug cuoehnihhklhgrshdrshhouggvrhhluhhnugdorhgvnhgvshgrshesrhgrghhnrghtvggt hhdrshgvqeenucggtffrrghtthgvrhhnpeehiefgueevuedtfefhheegkeevtdelueeuke evfeduhefhhfejfffggeffleefgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehnihhklhgrshdrshhouggvrhhluhhnugesrhgrghhnrghtvg gthhdrshgvpdhnsggprhgtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphht thhopehsrghkrghrihdrrghilhhusheslhhinhhugidrihhnthgvlhdrtghomhdprhgtph htthhopehmtghhvghhrggssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehtohhmihdr vhgrlhhkvghinhgvnhdorhgvnhgvshgrshesihguvggrshhonhgsohgrrhgurdgtohhmpd hrtghpthhtoheplhgruhhrvghnthdrphhinhgthhgrrhhtsehiuggvrghsohhnsghorghr ugdrtghomhdprhgtphhtthhopehlihhnuhigqdhmvgguihgrsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrhgvnhgvshgrshdqshhotgesvhhgvghr rdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehnihhklhgrshdrshhouggvrhhluhhnug dorhgvnhgvshgrshesrhgrghhnrghtvggthhdrshgv X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 May 2025 09:21:25 -0400 (EDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Mauro Carvalho Chehab , Tomi Valkeinen , Laurent Pinchart , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v4 1/6] media: rcar-vin: Use correct count of remote subdevices Date: Wed, 21 May 2025 15:20:32 +0200 Message-ID: <20250521132037.1463746-2-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250521132037.1463746-1-niklas.soderlund+renesas@ragnatech.se> References: <20250521132037.1463746-1-niklas.soderlund+renesas@ragnatech.se> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When extending the driver with Gen4 support the iteration of over possible remote subdevices changed from being R-Car CSI-2 Rx only to also cover R-Car CSISP instances. In two loops updating the bounds variable was missed. This had no ill effect as the count the two values have always been the same in the past. Fix it before the two diverge. Signed-off-by: Niklas Söderlund --- drivers/media/platform/renesas/rcar-vin/rcar-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/renesas/rcar-vin/rcar-core.c b/drivers/media/platform/renesas/rcar-vin/rcar-core.c index 846ae7989b1d..b9ea5b8db559 100644 --- a/drivers/media/platform/renesas/rcar-vin/rcar-core.c +++ b/drivers/media/platform/renesas/rcar-vin/rcar-core.c @@ -262,7 +262,7 @@ static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, mutex_lock(&vin->group->lock); - for (i = 0; i < RVIN_CSI_MAX; i++) { + for (i = 0; i < RVIN_REMOTES_MAX; i++) { if (vin->group->remotes[i].asc != asc) continue; vin->group->remotes[i].subdev = NULL; @@ -284,7 +284,7 @@ static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier, mutex_lock(&vin->group->lock); - for (i = 0; i < RVIN_CSI_MAX; i++) { + for (i = 0; i < RVIN_REMOTES_MAX; i++) { if (vin->group->remotes[i].asc != asc) continue; vin->group->remotes[i].subdev = subdev; From patchwork Wed May 21 13:20:34 2025 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: 891616 Received: from fhigh-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D2FC26FA4D; Wed, 21 May 2025 13:21:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747833694; cv=none; b=JoLjZRUI+8QJ3hVkfarUJxS76pPhnoR1+Axtr7iasmz6Isp0j+8Zan+cWD0KHJuQASI0KuyrhWmXIHHnwanVmfkjaEX8uxZjwHhK648UNDgNyXQ+7bcx7QfOnF7cGWihp8rXrId+66JtARA5SbX0qFD1X2rOItEYlBPl7TrePFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747833694; c=relaxed/simple; bh=SRGhkB8L2SIIzcO+EheVBy/d9WQCmrT8QC7/nNrKL/s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DChez6OezO/PQvZRzXpgzJQW6vQ/NlnSZxgP3RNCx1IFXYBVLCdt0m/nCbq4gewSnL+/wPmt71fCUmpVXF6bPUMbKKc7YjPzgnWQxPjYAD0pJzRXDzvf3EPkDx7LPkL/AHVmrXCWMUhcWqnf8/0dPvL9NXTFXX/e2JTlLj8Awmo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b=GpUbPfmK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iqnn5V+U; arc=none smtp.client-ip=202.12.124.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b="GpUbPfmK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iqnn5V+U" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 3C8AE254015A; Wed, 21 May 2025 09:21:31 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 21 May 2025 09:21:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1747833691; x=1747920091; bh=l6AGJv4XfRk3YXLHGOwoXmBG5ASC9ljWbmBfx9958vQ=; b= GpUbPfmKNdzZ3wjrKbCggHA68zg8LA98+7gB26UqtgJ+MSgH8ikOmGGWffMarHFJ Mj11LliNfEGAEwOfyCTqY0Zrzd2YyQXgj45pgB8O4N1Ehp6m8tkP5y+4yn3Opw3O cjKDZ54ocM9r96IhC5fLpU8gY8emxDZKhekg7sxv50XHL5Bn+uvI+vWOmQlFErL2 oGHfhpea+/aWtfuTuOw4riVmV9Qn0ZDnhMjwTXKIqEZRZhVM/0F5u6AuBtgcSPDa eqJWo3J7TOLNQm8hb0dYNv5eN41Tqq+llrAFTldCpHSSAy+xDCVuNEWGQI5tNdrm dy40ygWGDX/yISzmAPQPcQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1747833691; x= 1747920091; bh=l6AGJv4XfRk3YXLHGOwoXmBG5ASC9ljWbmBfx9958vQ=; b=i qnn5V+UeeAAF0Dt8J7iU3Jiw/Fhanf43+f6UoNE8LzpquNVxYYfTgRSBFAYm1TtE TSfKyXaZK787rwhg+3NGLirCWvpt2B1my3wXrcxt7mlRMCaIEl7ktIo4m7DZ4yQs 4w4/f60MPmz/7hBI2uawbMpQzS44MyQzpHVeSj3sEOCYmR7N4EvQf/P8JpdnQoDz pQ/LAG7juMBuokX4Z+4zKGep0i+VLquVJcmSbaO6Q6YHlokikWLamZL8K99mzlhH nNItcOYfrZbjubK88TQXA4+4gN8YrEfAa7GzKTvCCh2XqmZJwTcikjQ5tjZxMHAS hvqbBCVaFTpKB/Dx1WX1w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdefudekucdltddurdegfedvrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgf nhhsuhgsshgtrhhisggvpdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttd enucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgj fhggtgfgsehtkeertdertdejnecuhfhrohhmpefpihhklhgrshcuufpnuggvrhhluhhnug cuoehnihhklhgrshdrshhouggvrhhluhhnugdorhgvnhgvshgrshesrhgrghhnrghtvggt hhdrshgvqeenucggtffrrghtthgvrhhnpeehiefgueevuedtfefhheegkeevtdelueeuke evfeduhefhhfejfffggeffleefgeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehnihhklhgrshdrshhouggvrhhluhhnugesrhgrghhnrghtvg gthhdrshgvpdhnsggprhgtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphht thhopehsrghkrghrihdrrghilhhusheslhhinhhugidrihhnthgvlhdrtghomhdprhgtph htthhopehmtghhvghhrggssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehtohhmihdr vhgrlhhkvghinhgvnhdorhgvnhgvshgrshesihguvggrshhonhgsohgrrhgurdgtohhmpd hrtghpthhtoheplhgruhhrvghnthdrphhinhgthhgrrhhtsehiuggvrghsohhnsghorghr ugdrtghomhdprhgtphhtthhopehlihhnuhigqdhmvgguihgrsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrhgvnhgvshgrshdqshhotgesvhhgvghr rdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehnihhklhgrshdrshhouggvrhhluhhnug dorhgvnhgvshgrshesrhgrghhnrghtvggthhdrshgv X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 May 2025 09:21:30 -0400 (EDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Mauro Carvalho Chehab , Tomi Valkeinen , Laurent Pinchart , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v4 3/6] media: rcar-vin: Generate a VIN group ID for Gen2 Date: Wed, 21 May 2025 15:20:34 +0200 Message-ID: <20250521132037.1463746-4-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250521132037.1463746-1-niklas.soderlund+renesas@ragnatech.se> References: <20250521132037.1463746-1-niklas.soderlund+renesas@ragnatech.se> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prepare to move Gen2 and earlier models to media controller by generating a unique VIN group id for each VIN instance. On Gen3 and Gen4 it is important to have a specific id in the group as media graph routes depend on this. On Gen2 and earlier models all that will matter is to have a unique id in the range. Break out the id generation to a own function keeping the logic for Gen3 and Gen4 while generating a sequential id for Gen2 models. Signed-off-by: Niklas Söderlund --- * Changes since v1 - Move ID allocation to probe. - Use ida_alloc_range() instead of implementing our own schema by counting DT nodes. --- .../platform/renesas/rcar-vin/rcar-core.c | 78 ++++++++++++++----- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/drivers/media/platform/renesas/rcar-vin/rcar-core.c b/drivers/media/platform/renesas/rcar-vin/rcar-core.c index 1be408d6c508..d9ad56fb2aa9 100644 --- a/drivers/media/platform/renesas/rcar-vin/rcar-core.c +++ b/drivers/media/platform/renesas/rcar-vin/rcar-core.c @@ -10,6 +10,7 @@ * Based on the soc-camera rcar_vin driver */ +#include #include #include #include @@ -55,6 +56,7 @@ * be only one group for all instances. */ +static DEFINE_IDA(rvin_ida); static DEFINE_MUTEX(rvin_group_lock); static struct rvin_group *rvin_group_data; @@ -119,23 +121,8 @@ static int rvin_group_get(struct rvin_dev *vin, const struct media_device_ops *ops) { struct rvin_group *group; - u32 id; int ret; - /* Make sure VIN id is present and sane */ - ret = of_property_read_u32(vin->dev->of_node, "renesas,id", &id); - if (ret) { - vin_err(vin, "%pOF: No renesas,id property found\n", - vin->dev->of_node); - return -EINVAL; - } - - if (id >= RCAR_VIN_NUM) { - vin_err(vin, "%pOF: Invalid renesas,id '%u'\n", - vin->dev->of_node, id); - return -EINVAL; - } - /* Join or create a VIN group */ mutex_lock(&rvin_group_lock); if (rvin_group_data) { @@ -164,16 +151,15 @@ static int rvin_group_get(struct rvin_dev *vin, /* Add VIN to group */ mutex_lock(&group->lock); - if (group->vin[id]) { - vin_err(vin, "Duplicate renesas,id property value %u\n", id); + if (group->vin[vin->id]) { + vin_err(vin, "Duplicate renesas,id property value %u\n", vin->id); mutex_unlock(&group->lock); kref_put(&group->refcount, rvin_group_release); return -EINVAL; } - group->vin[id] = vin; + group->vin[vin->id] = vin; - vin->id = id; vin->group = group; vin->v4l2_dev.mdev = &group->mdev; @@ -1375,6 +1361,54 @@ static const struct of_device_id rvin_of_id_table[] = { }; MODULE_DEVICE_TABLE(of, rvin_of_id_table); +static int rvin_id_get(struct rvin_dev *vin) +{ + u32 oid; + int id; + + switch (vin->info->model) { + case RCAR_GEN3: + case RCAR_GEN4: + if (of_property_read_u32(vin->dev->of_node, "renesas,id", &oid)) + break; + + if (oid < 0 || oid >= RCAR_VIN_NUM) { + vin_err(vin, "%pOF: Invalid renesas,id '%u'\n", + vin->dev->of_node, oid); + return -EINVAL; + } + + vin->id = oid; + + return 0; + default: + id = ida_alloc_range(&rvin_ida, 0, RCAR_VIN_NUM - 1, + GFP_KERNEL); + if (id < 0) + break; + + vin->id = id; + + return 0; + } + + vin_err(vin, "Can't figure out VIN id\n"); + + return -EINVAL; +} + +static void rvin_id_put(struct rvin_dev *vin) +{ + switch (vin->info->model) { + case RCAR_GEN3: + case RCAR_GEN4: + break; + default: + ida_free(&rvin_ida, vin->id); + break; + } +} + static int rcar_vin_probe(struct platform_device *pdev) { struct rvin_dev *vin; @@ -1402,6 +1436,9 @@ static int rcar_vin_probe(struct platform_device *pdev) platform_set_drvdata(pdev, vin); + if (rvin_id_get(vin)) + return -EINVAL; + if (vin->info->use_isp) { ret = rvin_isp_init(vin); } else if (vin->info->use_mc) { @@ -1419,6 +1456,7 @@ static int rcar_vin_probe(struct platform_device *pdev) if (ret) { rvin_dma_unregister(vin); + rvin_id_put(vin); return ret; } @@ -1443,6 +1481,8 @@ static void rcar_vin_remove(struct platform_device *pdev) else rvin_parallel_cleanup(vin); + rvin_id_put(vin); + rvin_dma_unregister(vin); } From patchwork Wed May 21 13:20:36 2025 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: 891615 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4FCD279324; Wed, 21 May 2025 13:21:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747833699; cv=none; b=h3JPpyT1mhtc2+rjCk2vdDyzddFN2HJhA7ukJ4VDDugwBIAWb3R4r1zL8YpZw6XkHmosHSgLTEUg9OlApoy4xgcIX2IeGALFxVVIhHBcJDRfT00qp/ENQuk3LgFGlVDE8mQPA/vzh3Nqqa+ZxER1RrAAooEaA77sSCQPlvU1sVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747833699; c=relaxed/simple; bh=vo784IM011838g04PzfeCHI1zWn35WWdXB99MQgwldQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uPr7uu61na2DVWUDcjheD2KNGQtqaUIOeP2MxDlMJrEF72295GkhP6y+YNT+4C4Jdtahrnw2mVkun4xHTO3fNWBAIWNbTlehYaMt+ZnwhumhWg1iPZBLqfcG60Yb5E8qgjE1pKDK17lsIjyvyNa7guiU2tDvuRdumQXi/jUbdrQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se; spf=pass smtp.mailfrom=ragnatech.se; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b=uAJPDYey; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=A9rjMGA4; arc=none smtp.client-ip=202.12.124.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ragnatech.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ragnatech.se header.i=@ragnatech.se header.b="uAJPDYey"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="A9rjMGA4" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id CB15B114012F; Wed, 21 May 2025 09:21:35 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Wed, 21 May 2025 09:21:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ragnatech.se; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1747833695; x=1747920095; bh=nvH1V8gUae3vsntgL6q8iJEa5Ap6SH+Q5TaKzpTAbIQ=; b= uAJPDYeycKdnc7Y4fTOHkuLreGEVz3YE3MGezKf3Ts1lYHMtv0qqVuB6T6vMpj0f qnKlqnjxSHTzQwiqWEVtscqrgSiApfRQnM8sJQbfobwMApFCFDW60SaUFYnzRT5g 8oaNTGnkzT8zuudxQWVLvbmVIJYZ2pugV2KppUiwls5ECfL6rANkEiqtGqXajwXD nNZjeP+MVy/kz7VoOT1qd8zOVr0EKjeVmbPQhBX0wvnV0TxAJItYydE3RSuPkUPc poDS1BsoaB0WjL4TMBg/ba0r5a+sdXnB0wXFP5tx1YHw46rrBEwSbyfd5YI+R0di LqhAl7YNxhbyN+k1G63Nig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1747833695; x= 1747920095; bh=nvH1V8gUae3vsntgL6q8iJEa5Ap6SH+Q5TaKzpTAbIQ=; b=A 9rjMGA4vXt6Upd1j2RG/5vKzpdnmITN/mDsU+B0ITyzc10FUh7e2eb5ob2jvIfAP sgEtVOLD+tZdDLQL9NXi+eYPPdBa+XycODE4zPivN7z4zypxOUBYQnWkgiGIKjZK JDSxrvY7SAgsrWv7xQgtHB8EXZdfmZWMQ4dgoLfcsVd+rBcJX3L5PsF3IMIt/6+z JzfTO3U1Bx1jxrMFIaxInVL7sSS/ROH/9XAy1B9UNYmywbiCHOHw4PvFd5Bk34RB dJ4ehH5EoKXrDirNHw/JaB6mV6GQUOgWCKMPIJ4HryaeObulWPpWPM65MpcDDJUn mR0mbkhjHAU8L7nrXOxdw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdefudekucdltddurdegfedvrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgf nhhsuhgsshgtrhhisggvpdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttd enucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgj fhggtgfgsehtkeertdertdejnecuhfhrohhmpefpihhklhgrshcuufpnuggvrhhluhhnug cuoehnihhklhgrshdrshhouggvrhhluhhnugdorhgvnhgvshgrshesrhgrghhnrghtvggt hhdrshgvqeenucggtffrrghtthgvrhhnpeehiefgueevuedtfefhheegkeevtdelueeuke evfeduhefhhfejfffggeffleefgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehnihhklhgrshdrshhouggvrhhluhhnugesrhgrghhnrghtvg gthhdrshgvpdhnsggprhgtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphht thhopehsrghkrghrihdrrghilhhusheslhhinhhugidrihhnthgvlhdrtghomhdprhgtph htthhopehmtghhvghhrggssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehtohhmihdr vhgrlhhkvghinhgvnhdorhgvnhgvshgrshesihguvggrshhonhgsohgrrhgurdgtohhmpd hrtghpthhtoheplhgruhhrvghnthdrphhinhgthhgrrhhtsehiuggvrghsohhnsghorghr ugdrtghomhdprhgtphhtthhopehlihhnuhigqdhmvgguihgrsehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqrhgvnhgvshgrshdqshhotgesvhhgvghr rdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehnihhklhgrshdrshhouggvrhhluhhnug dorhgvnhgvshgrshesrhgrghhnrghtvggthhdrshgv X-ME-Proxy: Feedback-ID: i80c9496c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 May 2025 09:21:35 -0400 (EDT) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: Sakari Ailus , Mauro Carvalho Chehab , Tomi Valkeinen , Laurent Pinchart , linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: =?utf-8?q?Niklas_S=C3=B6derlund?= Subject: [PATCH v4 5/6] media: rcar-vin: Merge all notifiers Date: Wed, 21 May 2025 15:20:36 +0200 Message-ID: <20250521132037.1463746-6-niklas.soderlund+renesas@ragnatech.se> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250521132037.1463746-1-niklas.soderlund+renesas@ragnatech.se> References: <20250521132037.1463746-1-niklas.soderlund+renesas@ragnatech.se> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The VIN usage of v4l-async is complex and stems from organic growth of the driver of supporting both private local subdevices (Gen2, Gen3) and subdevices shared between all VIN instances (Gen3 and Gen4). The driver used a separate notifier for each VIN for the private local ones, and a shared group notifier for the shared ones. This was complex and lead to subtle bugs when unbinding and later rebinding subdevices in on of the notifiers having to handle different edge cases depending on if it also had subdevices in the other notifiers etc. To simplify this have the Gen2 devices allocate and form a VIN group too. This way all subdevices on all models can be collect in a single group notifier. Then there is only a single complete callback for all where the video devices and subdevice nodes can be registered etc. Signed-off-by: Niklas Söderlund --- .../platform/renesas/rcar-vin/rcar-core.c | 263 ++++++++---------- .../platform/renesas/rcar-vin/rcar-vin.h | 2 - 2 files changed, 114 insertions(+), 151 deletions(-) diff --git a/drivers/media/platform/renesas/rcar-vin/rcar-core.c b/drivers/media/platform/renesas/rcar-vin/rcar-core.c index 60ec57d73a12..b0727e98dac6 100644 --- a/drivers/media/platform/renesas/rcar-vin/rcar-core.c +++ b/drivers/media/platform/renesas/rcar-vin/rcar-core.c @@ -43,6 +43,9 @@ #define v4l2_dev_to_vin(d) container_of(d, struct rvin_dev, v4l2_dev) +static int rvin_parallel_subdevice_attach(struct rvin_dev *vin, + struct v4l2_subdev *subdev); + /* ----------------------------------------------------------------------------- * Gen3 Group Allocator */ @@ -232,7 +235,10 @@ static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier) } } - return vin->group->link_setup(vin->group); + if (vin->group->link_setup) + return vin->group->link_setup(vin->group); + + return 0; } static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, @@ -240,22 +246,31 @@ static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier, struct v4l2_async_connection *asc) { struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev); - unsigned int i; + struct rvin_group *group = vin->group; - for (i = 0; i < RCAR_VIN_NUM; i++) - if (vin->group->vin[i]) - rvin_v4l2_unregister(vin->group->vin[i]); + for (unsigned int i = 0; i < RCAR_VIN_NUM; i++) + if (group->vin[i]) + rvin_v4l2_unregister(group->vin[i]); mutex_lock(&vin->group->lock); + for (unsigned int i = 0; i < RCAR_VIN_NUM; i++) { + if (!group->vin[i] || group->vin[i]->parallel.asc != asc) + continue; + + group->vin[i]->parallel.subdev = NULL; + + vin_dbg(group->vin[i], "Unbind parallel subdev %s\n", + subdev->name); + } - for (i = 0; i < RVIN_REMOTES_MAX; i++) { - if (vin->group->remotes[i].asc != asc) + for (unsigned int i = 0; i < RVIN_REMOTES_MAX; i++) { + if (group->remotes[i].asc != asc) continue; - vin->group->remotes[i].subdev = NULL; + + group->remotes[i].subdev = NULL; + vin_dbg(vin, "Unbind %s from slot %u\n", subdev->name, i); - break; } - mutex_unlock(&vin->group->lock); media_device_unregister(&vin->group->mdev); @@ -266,21 +281,38 @@ static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier, struct v4l2_async_connection *asc) { struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev); - unsigned int i; + struct rvin_group *group = vin->group; - mutex_lock(&vin->group->lock); + guard(mutex)(&group->lock); - for (i = 0; i < RVIN_REMOTES_MAX; i++) { + for (unsigned int i = 0; i < RCAR_VIN_NUM; i++) { + int ret; + + if (!group->vin[i] || group->vin[i]->parallel.asc != asc) + continue; + + ret = rvin_parallel_subdevice_attach(group->vin[i], subdev); + if (ret) + return ret; + + v4l2_set_subdev_hostdata(subdev, group->vin[i]); + + vin_dbg(group->vin[i], "Bound subdev %s\n", subdev->name); + + return 0; + } + + for (unsigned int i = 0; i < RVIN_REMOTES_MAX; i++) { if (vin->group->remotes[i].asc != asc) continue; + vin->group->remotes[i].subdev = subdev; vin_dbg(vin, "Bound %s to slot %u\n", subdev->name, i); - break; + + return 0; } - mutex_unlock(&vin->group->lock); - - return 0; + return -ENODEV; } static const struct v4l2_async_notifier_operations rvin_group_notify_ops = { @@ -374,7 +406,7 @@ static int rvin_parallel_parse_of(struct rvin_dev *vin) goto out; } - asc = v4l2_async_nf_add_fwnode(&vin->notifier, fwnode, + asc = v4l2_async_nf_add_fwnode(&vin->group->notifier, fwnode, struct v4l2_async_connection); if (IS_ERR(asc)) { ret = PTR_ERR(asc); @@ -424,6 +456,12 @@ static int rvin_group_notifier_init(struct rvin_dev *vin, unsigned int port, if (!(vin_mask & BIT(i))) continue; + /* Parse local subdevice. */ + ret = rvin_parallel_parse_of(vin->group->vin[i]); + if (ret) + return ret; + + /* Prase shared subdevices. */ for (id = 0; id < max_id; id++) { if (vin->group->remotes[id].asc) continue; @@ -603,124 +641,6 @@ static int rvin_parallel_subdevice_attach(struct rvin_dev *vin, return 0; } -static void rvin_parallel_subdevice_detach(struct rvin_dev *vin) -{ - rvin_v4l2_unregister(vin); - vin->parallel.subdev = NULL; - - if (!vin->info->use_mc) - rvin_free_controls(vin); -} - -static int rvin_parallel_notify_complete(struct v4l2_async_notifier *notifier) -{ - struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev); - struct media_entity *source; - struct media_entity *sink; - int ret; - - ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev); - if (ret < 0) { - vin_err(vin, "Failed to register subdev nodes\n"); - return ret; - } - - if (!video_is_registered(&vin->vdev)) { - ret = rvin_v4l2_register(vin); - if (ret < 0) - return ret; - } - - if (!vin->info->use_mc) - return 0; - - /* If we're running with media-controller, link the subdevs. */ - source = &vin->parallel.subdev->entity; - sink = &vin->vdev.entity; - - ret = media_create_pad_link(source, vin->parallel.source_pad, - sink, vin->parallel.sink_pad, 0); - if (ret) - vin_err(vin, "Error adding link from %s to %s: %d\n", - source->name, sink->name, ret); - - return ret; -} - -static void rvin_parallel_notify_unbind(struct v4l2_async_notifier *notifier, - struct v4l2_subdev *subdev, - struct v4l2_async_connection *asc) -{ - struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev); - - vin_dbg(vin, "unbind parallel subdev %s\n", subdev->name); - - mutex_lock(&vin->lock); - rvin_parallel_subdevice_detach(vin); - mutex_unlock(&vin->lock); -} - -static int rvin_parallel_notify_bound(struct v4l2_async_notifier *notifier, - struct v4l2_subdev *subdev, - struct v4l2_async_connection *asc) -{ - struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev); - int ret; - - mutex_lock(&vin->lock); - ret = rvin_parallel_subdevice_attach(vin, subdev); - mutex_unlock(&vin->lock); - if (ret) - return ret; - - v4l2_set_subdev_hostdata(subdev, vin); - - vin_dbg(vin, "bound subdev %s source pad: %u sink pad: %u\n", - subdev->name, vin->parallel.source_pad, - vin->parallel.sink_pad); - - return 0; -} - -static const struct v4l2_async_notifier_operations rvin_parallel_notify_ops = { - .bound = rvin_parallel_notify_bound, - .unbind = rvin_parallel_notify_unbind, - .complete = rvin_parallel_notify_complete, -}; - -static void rvin_parallel_cleanup(struct rvin_dev *vin) -{ - v4l2_async_nf_unregister(&vin->notifier); - v4l2_async_nf_cleanup(&vin->notifier); -} - -static int rvin_parallel_init(struct rvin_dev *vin) -{ - int ret; - - v4l2_async_nf_init(&vin->notifier, &vin->v4l2_dev); - - ret = rvin_parallel_parse_of(vin); - if (ret) - return ret; - - if (!vin->parallel.asc) - return -ENODEV; - - vin_dbg(vin, "Found parallel subdevice %pOF\n", - to_of_node(vin->parallel.asc->match.fwnode)); - - vin->notifier.ops = &rvin_parallel_notify_ops; - ret = v4l2_async_nf_register(&vin->notifier); - if (ret < 0) { - vin_err(vin, "Notifier registration failed\n"); - v4l2_async_nf_cleanup(&vin->notifier); - return ret; - } - - return 0; -} - /* ----------------------------------------------------------------------------- * CSI-2 */ @@ -895,11 +815,63 @@ static int rvin_csi2_create_link(struct rvin_group *group, unsigned int id, return 0; } +static int rvin_parallel_setup_links(struct rvin_group *group) +{ + u32 flags = MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE; + int ret = 0; + + mutex_lock(&group->lock); + /* If the group also have links don't enable the link. */ + for (unsigned int i = 0; i < RVIN_REMOTES_MAX; i++) { + if (group->remotes[i].subdev) { + flags = 0; + break; + } + } + + /* Create links */ + for (unsigned int i = 0; i < RCAR_VIN_NUM; i++) { + struct rvin_dev *vin = group->vin[i]; + struct media_entity *source; + struct media_entity *sink; + + /* Noting to do if their is no VIN or parallel subdev. */ + if (!vin || !vin->parallel.subdev) + continue; + + source = &vin->parallel.subdev->entity; + sink = &vin->vdev.entity; + + ret = media_create_pad_link(source, vin->parallel.source_pad, + sink, 0, flags); + if (ret) + break; + } + mutex_unlock(&group->lock); + + return ret; +} + static int rvin_csi2_setup_links(struct rvin_group *group) { const struct rvin_group_route *routes, *route; unsigned int id; - int ret = -EINVAL; + int ret; + + /* Find any VIN in group to get route info. */ + routes = NULL; + for (unsigned int i = 0; i < RCAR_VIN_NUM; i++) { + if (group->vin[i]) { + routes = group->vin[i]->info->routes; + break; + } + } + if (!routes) + return -ENODEV; + + ret = rvin_parallel_setup_links(group); + if (ret) + return ret; /* Find any VIN in group to get route info. */ routes = NULL; @@ -914,6 +886,7 @@ static int rvin_csi2_setup_links(struct rvin_group *group) /* Create all media device links between VINs and CSI-2's. */ mutex_lock(&group->lock); + ret = -EINVAL; for (route = routes; route->chsel; route++) { /* Check that VIN' master is part of the group. */ if (!group->vin[route->master]) @@ -941,7 +914,6 @@ static int rvin_csi2_setup_links(struct rvin_group *group) static void rvin_csi2_cleanup(struct rvin_dev *vin) { - rvin_parallel_cleanup(vin); rvin_group_notifier_cleanup(vin); rvin_group_put(vin); rvin_free_controls(vin); @@ -964,18 +936,11 @@ static int rvin_csi2_init(struct rvin_dev *vin) if (ret) goto err_controls; - /* It's OK to not have a parallel subdevice. */ - ret = rvin_parallel_init(vin); - if (ret && ret != -ENODEV) - goto err_group; - ret = rvin_group_notifier_init(vin, 1, RVIN_CSI_MAX); if (ret) - goto err_parallel; + goto err_group; return 0; -err_parallel: - rvin_parallel_cleanup(vin); err_group: rvin_group_put(vin); err_controls: @@ -1448,7 +1413,9 @@ static int rcar_vin_probe(struct platform_device *pdev) rvin_group_id_to_master(vin->id) == vin->id) vin->scaler = vin->info->scaler; } else { - ret = rvin_parallel_init(vin); + ret = rvin_group_get(vin, NULL, NULL); + if (!ret) + ret = rvin_group_notifier_init(vin, 0, 0); if (vin->info->scaler) vin->scaler = vin->info->scaler; @@ -1478,8 +1445,6 @@ static void rcar_vin_remove(struct platform_device *pdev) rvin_isp_cleanup(vin); else if (vin->info->use_mc) rvin_csi2_cleanup(vin); - else - rvin_parallel_cleanup(vin); rvin_id_put(vin); diff --git a/drivers/media/platform/renesas/rcar-vin/rcar-vin.h b/drivers/media/platform/renesas/rcar-vin/rcar-vin.h index 7d4fce248976..a577f4fe4a6c 100644 --- a/drivers/media/platform/renesas/rcar-vin/rcar-vin.h +++ b/drivers/media/platform/renesas/rcar-vin/rcar-vin.h @@ -149,7 +149,6 @@ struct rvin_info { * @vdev: V4L2 video device associated with VIN * @v4l2_dev: V4L2 device * @ctrl_handler: V4L2 control handler - * @notifier: V4L2 asynchronous subdevs notifier * * @parallel: parallel input subdevice descriptor * @@ -189,7 +188,6 @@ struct rvin_dev { struct video_device vdev; struct v4l2_device v4l2_dev; struct v4l2_ctrl_handler ctrl_handler; - struct v4l2_async_notifier notifier; struct rvin_parallel_entity parallel;