From nobody Thu Oct 2 21:54:44 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 B520F312817; Thu, 11 Sep 2025 10:29:45 +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=1757586587; cv=none; b=jw8tOlvT9TIHOkrkp67jKA/x5MVkkkoP9pMsnpKlMbAv4ROah/cgPJIBzRI3V6zNLay6JJnS7v1kdrCTp7wlbrJzlk2/kcqEFzCIDZXkFeGbSI4lbRWvOVYBvHb2u/VS1FYQnDjiPa78rWEwAMw5XIWhyL2XT+N3X1e6ac28mos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757586587; c=relaxed/simple; bh=2zzsam66fM4OYH6RRIr81VS9XLd4m3OkMy8Q+XvDxrs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OS3Uq3aFT1lxmSo5SA4Igl2GBTfjt5BkFTsM2vXMFetRDyXyWdVlspm3BPHuGqF11mXCQpQ70Ng5rSdNA19cEW0ldiOmpG8dKBAXsfEWqE5cJ7kwDrJOtp/PP2qJMUBQxPs5yvJy2cytLZ/bzAA/fmu09Qp49v6o+3fVLtIkOBc= 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=wiAv0mk1; 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="wiAv0mk1" Received: from fllvem-sh03.itg.ti.com ([10.64.41.86]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTP id 58BATU76355702; Thu, 11 Sep 2025 05:29:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1757586570; bh=U+nw1qfOf9J4/BbSowFtNNmCfqq+JcUZvwaJ7/ty9jc=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=wiAv0mk1EsPLJhOoalfhftT0ma6QBQQKCyHmfWCpXtFtnlYfuUj98E0h7ESgCbVcb TR+Ato0P53vEmbmi3ToSAyv+KXc8yHS5VP1Q4mheSinQzbV0ykLNyv9EiHSRIrC2Ak ro05qk1dmpffLOweHTqV7+e9w6CdC0Wg2GvpHFgI= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by fllvem-sh03.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 58BATTJS1092072 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Thu, 11 Sep 2025 05:29:29 -0500 Received: from DLEE209.ent.ti.com (157.170.170.98) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Thu, 11 Sep 2025 05:29:29 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DLEE209.ent.ti.com (157.170.170.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend Transport; Thu, 11 Sep 2025 05:29:29 -0500 Received: from ws.dhcp.ti.com (ws.dhcp.ti.com [172.24.233.149]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 58BASXbl1985821; Thu, 11 Sep 2025 05:29:23 -0500 From: Rishikesh Donadkar To: , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v7 07/16] media: ti: j721e-csi2rx: get number of contexts from device tree Date: Thu, 11 Sep 2025 15:58:23 +0530 Message-ID: <20250911102832.1583440-8-r-donadkar@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250911102832.1583440-1-r-donadkar@ti.com> References: <20250911102832.1583440-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 Reviewed-by: Tomi Valkeinen --- .../platform/ti/j721e-csi2rx/j721e-csi2rx.c | 43 ++++++++++++++----- 1 file changed, 32 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 e49448e1f2ad..f3443c3ab01a 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 { @@ -459,7 +460,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 @@ -1247,10 +1248,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; @@ -1341,8 +1343,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 =3D 0, i, count; =20 csi =3D devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); if (!csi) @@ -1364,13 +1367,30 @@ 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); + ret =3D -EINVAL; + 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]); @@ -1399,6 +1419,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; @@ -1409,7 +1430,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