From: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org
Cc: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Subject: [PATCH v4 3/6] media: rcar-vin: Generate a VIN group ID for Gen2
Date: Wed, 21 May 2025 15:20:34 +0200 [thread overview]
Message-ID: <20250521132037.1463746-4-niklas.soderlund+renesas@ragnatech.se> (raw)
In-Reply-To: <20250521132037.1463746-1-niklas.soderlund+renesas@ragnatech.se>
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 <niklas.soderlund+renesas@ragnatech.se>
---
* 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 <linux/idr.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
@@ -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);
}
--
2.49.0
next prev parent reply other threads:[~2025-05-21 13:21 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 13:20 [PATCH v4 0/6] media: rcar-vin: Unify notifiers and enable MC on Gen2 Niklas Söderlund
2025-05-21 13:20 ` [PATCH v4 1/6] media: rcar-vin: Use correct count of remote subdevices Niklas Söderlund
2025-05-27 11:11 ` Laurent Pinchart
2025-05-21 13:20 ` [PATCH v4 2/6] media: rcar-vin: Change link setup argument Niklas Söderlund
2025-05-27 11:19 ` Laurent Pinchart
2025-05-21 13:20 ` Niklas Söderlund [this message]
2025-05-27 11:31 ` [PATCH v4 3/6] media: rcar-vin: Generate a VIN group ID for Gen2 Laurent Pinchart
2025-05-21 13:20 ` [PATCH v4 4/6] media: rcar-vin: Prepare for unifying all v4l-async notifiers Niklas Söderlund
2025-05-27 7:01 ` Sakari Ailus
2025-05-27 11:06 ` Laurent Pinchart
2025-05-28 10:27 ` Sakari Ailus
2025-06-06 13:50 ` Niklas Söderlund
2025-06-07 11:13 ` Sakari Ailus
2025-06-07 11:59 ` Niklas Söderlund
2025-05-27 11:32 ` Laurent Pinchart
2025-05-21 13:20 ` [PATCH v4 5/6] media: rcar-vin: Merge all notifiers Niklas Söderlund
2025-05-27 11:45 ` Laurent Pinchart
2025-06-06 14:09 ` Niklas Söderlund
2025-06-07 14:02 ` Laurent Pinchart
2025-05-21 13:20 ` [PATCH v4 6/6] media: rcar-vin: Enable media-graph on Gen2 Niklas Söderlund
2025-05-27 11:48 ` Laurent Pinchart
2025-05-30 12:41 ` [PATCH v4 0/6] media: rcar-vin: Unify notifiers and enable MC " Tomi Valkeinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250521132037.1463746-4-niklas.soderlund+renesas@ragnatech.se \
--to=niklas.soderlund+renesas@ragnatech.se \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen+renesas@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).