From nobody Fri Oct 3 21:02:27 2025 Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (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 0430A2FF67B; Mon, 25 Aug 2025 14:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756131986; cv=none; b=pUmc+NSoueUzi3GAK3LuS7jAgxsLaQMwp1KK7//neOYEHqq4m8Mu6vi4qBWcQ5jW4YhrbAulsRLAwhbc47lsn/48Jw9VUqrrNEeBfxqUQOu7UOBVbmED3SpnwnH/JKz2MnpLbiy7VfvFhfifIgtNxVMF09a7yVlcThNH8+l/6B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756131986; c=relaxed/simple; bh=iU4Icrhk08GVVh+7H2LLbXCkLV/Dj6WRu+thq96nEzY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WJRFwyUEvisTKmmSwBxh60x//W5pDOnPGvV66/DVZ+iID7dN9Oz5ni8/wu5n8b0f7IioTLYVj8jhnJ7V/COgmG7mvIn35lBjIZmDsXLXepbMaaWKkg09I3aaeuIJHR82+gF17U5ppcHltu98NzyRQQ7njnHXMwTARAdch4K/9yE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=p+3ca5q1; arc=none smtp.client-ip=198.47.23.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="p+3ca5q1" Received: from lelvem-sh02.itg.ti.com ([10.180.78.226]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTP id 57PEQDue831199; Mon, 25 Aug 2025 09:26:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1756131973; bh=raNyCGBxsEPWRO5KFB+JiEWgm4eWn5oB0tKhlmULuNE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=p+3ca5q1OncqsiXxjzWvl2grvOzoCApWXcFsXN2VSuOIU2p/1ZZSe9g93xS7hOugW M3cYtVaQLfFBQHuXjzYYSmNvBP+iQmcNjsdWuHIfnxpUbXnXvZi2rsgvJnxnmgusnf bZ5g1b5jZ0eJeoOozUjIcIlDjpJhKwXTP9Z6IIQA= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by lelvem-sh02.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 57PEQD4B1235858 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Mon, 25 Aug 2025 09:26:13 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Mon, 25 Aug 2025 09:26:12 -0500 Received: from lelvem-mr06.itg.ti.com (10.180.75.8) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55 via Frontend Transport; Mon, 25 Aug 2025 09:26:12 -0500 Received: from ws.dhcp.ti.com (ws.dhcp.ti.com [172.24.233.149]) by lelvem-mr06.itg.ti.com (8.18.1/8.18.1) with ESMTP id 57PEPN3u3747540; Mon, 25 Aug 2025 09:26:07 -0500 From: Rishikesh Donadkar To: , , CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 07/14] media: ti: j721e-csi2rx: get number of contexts from device tree Date: Mon, 25 Aug 2025 19:55:15 +0530 Message-ID: <20250825142522.1826188-8-r-donadkar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250825142522.1826188-1-r-donadkar@ti.com> References: <20250825142522.1826188-1-r-donadkar@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" From: Pratyush Yadav Different platforms that use this driver might have different number of DMA channels allocated for CSI. So only as many DMA contexts can be used as the number of DMA channels available. Get the number of channels provided via device tree and only configure that many contexts, and hence only that many pads. Reviewed-by: Yemike Abhilash Chandra Signed-off-by: Pratyush Yadav Co-developed-by: Jai Luthra Signed-off-by: Jai Luthra Signed-off-by: Rishikesh Donadkar --- .../platform/ti/j721e-csi2rx/j721e-csi2rx.c | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/driver= s/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c index 4e1c9db0dcf5..6cab7642aa10 100644 --- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c @@ -44,7 +44,7 @@ =20 #define TI_CSI2RX_MAX_PIX_PER_CLK 4 #define PSIL_WORD_SIZE_BYTES 16 -#define TI_CSI2RX_NUM_CTX 1 +#define TI_CSI2RX_MAX_CTX 32 =20 /* * There are no hard limits on the width or height. The DMA engine can han= dle @@ -57,8 +57,8 @@ =20 #define TI_CSI2RX_PAD_SINK 0 #define TI_CSI2RX_PAD_FIRST_SOURCE 1 -#define TI_CSI2RX_NUM_SOURCE_PADS 1 -#define TI_CSI2RX_NUM_PADS (1 + TI_CSI2RX_NUM_SOURCE_PADS) +#define TI_CSI2RX_MAX_SOURCE_PADS TI_CSI2RX_MAX_CTX +#define TI_CSI2RX_MAX_PADS (1 + TI_CSI2RX_MAX_SOURCE_PADS) =20 #define DRAIN_TIMEOUT_MS 50 #define DRAIN_BUFFER_SIZE SZ_32K @@ -118,14 +118,15 @@ struct ti_csi2rx_dev { void __iomem *shim; struct mutex mutex; /* To serialize ioctls. */ unsigned int enable_count; + unsigned int num_ctx; struct v4l2_device v4l2_dev; struct media_device mdev; struct media_pipeline pipe; - struct media_pad pads[TI_CSI2RX_NUM_PADS]; + struct media_pad pads[TI_CSI2RX_MAX_PADS]; struct v4l2_async_notifier notifier; struct v4l2_subdev *source; struct v4l2_subdev subdev; - struct ti_csi2rx_ctx ctx[TI_CSI2RX_NUM_CTX]; + struct ti_csi2rx_ctx ctx[TI_CSI2RX_MAX_CTX]; u8 pix_per_clk; /* Buffer to drain stale data from PSI-L endpoint */ struct { @@ -463,7 +464,7 @@ static int csi_async_notifier_complete(struct v4l2_asyn= c_notifier *notifier) return ret; =20 /* Create and link video nodes for all DMA contexts */ - for (i =3D 0; i < TI_CSI2RX_NUM_CTX; i++) { + for (i =3D 0; i < csi->num_ctx; i++) { struct ti_csi2rx_ctx *ctx =3D &csi->ctx[i]; struct video_device *vdev =3D &ctx->vdev; =20 @@ -1250,10 +1251,11 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev= *csi) csi->pads[TI_CSI2RX_PAD_SINK].flags =3D MEDIA_PAD_FL_SINK; =20 for (unsigned int i =3D TI_CSI2RX_PAD_FIRST_SOURCE; - i < TI_CSI2RX_NUM_PADS; i++) + i < TI_CSI2RX_PAD_FIRST_SOURCE + csi->num_ctx; i++) csi->pads[i].flags =3D MEDIA_PAD_FL_SOURCE; =20 - ret =3D media_entity_pads_init(&sd->entity, ARRAY_SIZE(csi->pads), + ret =3D media_entity_pads_init(&sd->entity, + TI_CSI2RX_PAD_FIRST_SOURCE + csi->num_ctx, csi->pads); if (ret) goto unregister_media; @@ -1344,8 +1346,9 @@ static int ti_csi2rx_init_ctx(struct ti_csi2rx_ctx *c= tx) =20 static int ti_csi2rx_probe(struct platform_device *pdev) { + struct device_node *np =3D pdev->dev.of_node; struct ti_csi2rx_dev *csi; - int ret, i; + int ret, i, count; =20 csi =3D devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); if (!csi) @@ -1367,13 +1370,29 @@ static int ti_csi2rx_probe(struct platform_device *= pdev) if (!csi->drain.vaddr) return -ENOMEM; =20 + /* Only use as many contexts as the number of DMA channels allocated. */ + count =3D of_property_count_strings(np, "dma-names"); + if (count < 0) { + dev_err(csi->dev, "Failed to get DMA channel count: %d\n", count); + ret =3D count; + goto err_dma_chan; + } + + csi->num_ctx =3D count; + if (csi->num_ctx > TI_CSI2RX_MAX_CTX) { + dev_err(csi->dev, + "%u DMA channels passed. Maximum is %u.\n", + csi->num_ctx, TI_CSI2RX_MAX_CTX); + goto err_dma_chan; + } + mutex_init(&csi->mutex); =20 ret =3D ti_csi2rx_v4l2_init(csi); if (ret) goto err_v4l2; =20 - for (i =3D 0; i < TI_CSI2RX_NUM_CTX; i++) { + for (i =3D 0; i < csi->num_ctx; i++) { csi->ctx[i].idx =3D i; csi->ctx[i].csi =3D csi; ret =3D ti_csi2rx_init_ctx(&csi->ctx[i]); @@ -1402,6 +1421,7 @@ static int ti_csi2rx_probe(struct platform_device *pd= ev) ti_csi2rx_cleanup_v4l2(csi); err_v4l2: mutex_destroy(&csi->mutex); +err_dma_chan: dma_free_coherent(csi->dev, csi->drain.len, csi->drain.vaddr, csi->drain.paddr); return ret; @@ -1412,7 +1432,7 @@ static void ti_csi2rx_remove(struct platform_device *= pdev) struct ti_csi2rx_dev *csi =3D platform_get_drvdata(pdev); unsigned int i; =20 - for (i =3D 0; i < TI_CSI2RX_NUM_CTX; i++) + for (i =3D 0; i < csi->num_ctx; i++) ti_csi2rx_cleanup_ctx(&csi->ctx[i]); =20 ti_csi2rx_cleanup_notifier(csi); --=20 2.34.1