From nobody Fri Oct 3 16:41:01 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (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 EFDDD2FF17F for ; Thu, 28 Aug 2025 08:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756371587; cv=none; b=ezuNlq/pLm8blV0OA0qriRXOwv6qAvSH1Z8IoGgu1XRU8sDQ0KFFFXQtO6CA2P0wXA+LpFRULA2vrLDORWIs6jDnDYc3auZRTu/fHYBFl7HwabBXS4/cVQG4BA5BllZjCLWqwsKDqosY+uvWu+sTbzNlOEkbwEPC4Jw9HyUyl4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756371587; c=relaxed/simple; bh=y69aJvaC7ciZ5Hf9QaOQ87FPgv9BOZJHu+NQjvRatRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:MIME-Version: Content-Type:References; b=Jc5zQ6UxmbFySDewD3gSqwaC5BGRF7uL4WIvIL41XWIWXjDJJp9w6vsXRf/VEzdI2vezjKihpQkChYl0x3YFckAw+L4BxalT5yJQJdjRAULL3UapjecQeGFOB9PAQR96/5HRCFRDzhA6dE+5I2JYqoF5jW7cpZ/hQvXx/k/O99o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=aI9Np7hy; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="aI9Np7hy" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250828085944epoutp044340b2c24f5e381210e9f59c90ef549e~f4qaAy8Tx2432424324epoutp04T for ; Thu, 28 Aug 2025 08:59:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250828085944epoutp044340b2c24f5e381210e9f59c90ef549e~f4qaAy8Tx2432424324epoutp04T DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1756371584; bh=MiHBdJbfHrVtpDhp68bjMjb9GJcwMtqCUnZwS8iakKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aI9Np7hyuBLbHIWLY0jpDY7dsMh/oXWangAfqzVGy2BjMExfkD8HDLTqQfWIQfBvB vCDaAxcbUylGe9nfbShqx8TZoiuM+clQqBCsQdMV+hnZMgExL6/0k68lMutJs8EfRH VF4Uaavl1LgH7jTyk8oCNByXJV/yaQz1AYx7bRCc= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250828085943epcas5p2abc570ed0afce51201230b0a623628f4~f4qZiduZm0593805938epcas5p2s; Thu, 28 Aug 2025 08:59:43 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.86]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4cCFhZ6w18z2SSKZ; Thu, 28 Aug 2025 08:59:42 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20250828085942epcas5p3724f3184a1b12c20a8016c89f7e47ba7~f4qX9omGJ1633316333epcas5p3d; Thu, 28 Aug 2025 08:59:42 +0000 (GMT) Received: from cheetah.samsungds.net (unknown [107.109.115.53]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250828085939epsmtip2842c1ef84d867f70baaae3e4d034b56d~f4qVS88A00283502835epsmtip2X; Thu, 28 Aug 2025 08:59:39 +0000 (GMT) From: Inbaraj E To: rmfrfs@gmail.com, laurent.pinchart@ideasonboard.com, martink@posteo.de, kernel@puri.sm, mchehab@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de Cc: kernel@pengutronix.de, festevam@gmail.com, linux-media@vger.kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, pankaj.dubey@samsung.com, ravi.patel@samsung.com, shradha.t@samsung.com, Inbaraj E Subject: [PATCH v3 5/7] media: imx-mipi-csis: Add support for dynamic VC selection Date: Thu, 28 Aug 2025 14:29:09 +0530 Message-ID: <20250828085911.81266-6-inbaraj.e@samsung.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250828085911.81266-1-inbaraj.e@samsung.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-CMS-MailID: 20250828085942epcas5p3724f3184a1b12c20a8016c89f7e47ba7 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-541,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250828085942epcas5p3724f3184a1b12c20a8016c89f7e47ba7 References: <20250828085911.81266-1-inbaraj.e@samsung.com> The existing implementation configures VC0 by default for streaming. This patch adds support to obtain the VC dynamically from the subdevice(Sensor) through the get_frame_desc() operation and configure the corresponding VC when starting the stream. If get_frame_desc() is not implemented by the subdevice, VC0 will be selected by default for configuration and streaming. Signed-off-by: Inbaraj E --- drivers/media/platform/nxp/imx-mipi-csis.c | 61 ++++++++++++++++++---- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/nxp/imx-mipi-csis.c b/drivers/media/pla= tform/nxp/imx-mipi-csis.c index 2443906377bd..b7ab441cc78a 100644 --- a/drivers/media/platform/nxp/imx-mipi-csis.c +++ b/drivers/media/platform/nxp/imx-mipi-csis.c @@ -334,6 +334,7 @@ struct mipi_csis_device { struct regulator *mipi_phy_regulator; =20 const struct mipi_csis_info *info; + unsigned int vc; unsigned int num_channels; =20 struct v4l2_subdev sd; @@ -585,7 +586,7 @@ static void __mipi_csis_set_format(struct mipi_csis_dev= ice *csis, u32 val; =20 /* Color format */ - val =3D mipi_csis_read(csis, MIPI_CSIS_ISP_CONFIG_CH(0)); + val =3D mipi_csis_read(csis, MIPI_CSIS_ISP_CONFIG_CH(csis->vc)); val &=3D ~(MIPI_CSIS_ISPCFG_PARALLEL | MIPI_CSIS_ISPCFG_PIXEL_MODE_MASK | MIPI_CSIS_ISPCFG_DATAFORMAT_MASK); =20 @@ -606,10 +607,10 @@ static void __mipi_csis_set_format(struct mipi_csis_d= evice *csis, val |=3D MIPI_CSIS_ISPCFG_PIXEL_MODE_DUAL; =20 val |=3D MIPI_CSIS_ISPCFG_DATAFORMAT(csis_fmt->data_type); - mipi_csis_write(csis, MIPI_CSIS_ISP_CONFIG_CH(0), val); + mipi_csis_write(csis, MIPI_CSIS_ISP_CONFIG_CH(csis->vc), val); =20 /* Pixel resolution */ - mipi_csis_write(csis, MIPI_CSIS_ISP_RESOL_CH(0), + mipi_csis_write(csis, MIPI_CSIS_ISP_RESOL_CH(csis->vc), MIPI_CSIS_ISP_RESOL_VRESOL(format->height) | MIPI_CSIS_ISP_RESOL_HRESOL(format->width)); } @@ -683,14 +684,14 @@ static void mipi_csis_set_params(struct mipi_csis_dev= ice *csis, MIPI_CSIS_DPHY_CMN_CTRL_HSSETTLE(csis->hs_settle) | MIPI_CSIS_DPHY_CMN_CTRL_CLKSETTLE(csis->clk_settle)); =20 - mipi_csis_write(csis, MIPI_CSIS_ISP_SYNC_CH(0), + mipi_csis_write(csis, MIPI_CSIS_ISP_SYNC_CH(csis->vc), MIPI_CSIS_ISP_SYNC_HSYNC_LINTV(0) | MIPI_CSIS_ISP_SYNC_VSYNC_SINTV(0) | MIPI_CSIS_ISP_SYNC_VSYNC_EINTV(0)); =20 val =3D mipi_csis_read(csis, MIPI_CSIS_CLK_CTRL); - val |=3D MIPI_CSIS_CLK_CTRL_WCLK_SRC(0); - val |=3D MIPI_CSIS_CLK_CTRL_CLKGATE_TRAIL(0, 15); + val |=3D MIPI_CSIS_CLK_CTRL_WCLK_SRC(csis->vc); + val |=3D MIPI_CSIS_CLK_CTRL_CLKGATE_TRAIL(csis->vc, 15); val &=3D ~MIPI_CSIS_CLK_CTRL_CLKGATE_EN_MSK; mipi_csis_write(csis, MIPI_CSIS_CLK_CTRL, val); =20 @@ -707,7 +708,7 @@ static void mipi_csis_set_params(struct mipi_csis_devic= e *csis, /* Update the shadow register. */ val =3D mipi_csis_read(csis, MIPI_CSIS_CMN_CTRL); mipi_csis_write(csis, MIPI_CSIS_CMN_CTRL, - val | MIPI_CSIS_CMN_CTRL_UPDATE_SHADOW(0) | + val | MIPI_CSIS_CMN_CTRL_UPDATE_SHADOW(csis->vc) | MIPI_CSIS_CMN_CTRL_UPDATE_SHADOW_CTRL); } =20 @@ -778,7 +779,7 @@ static void mipi_csis_queue_event_sof(struct mipi_csis_= device *csis) }; u32 frame; =20 - frame =3D mipi_csis_read(csis, MIPI_CSIS_FRAME_COUNTER_CH(0)); + frame =3D mipi_csis_read(csis, MIPI_CSIS_FRAME_COUNTER_CH(csis->vc)); event.u.frame_sync.frame_sequence =3D frame; v4l2_event_queue(csis->sd.devnode, &event); } @@ -810,7 +811,7 @@ static irqreturn_t mipi_csis_irq_handler(int irq, void = *dev_id) } } =20 - if (status & MIPI_CSIS_INT_SRC_FRAME_START(0)) + if (status & MIPI_CSIS_INT_SRC_FRAME_START(csis->vc)) mipi_csis_queue_event_sof(csis); =20 spin_unlock_irqrestore(&csis->slock, flags); @@ -1191,7 +1192,7 @@ static int mipi_csis_get_frame_desc(struct v4l2_subde= v *sd, unsigned int pad, =20 entry->flags =3D 0; entry->pixelcode =3D csis_fmt->code; - entry->bus.csi2.vc =3D 0; + entry->bus.csi2.vc =3D csis->vc; entry->bus.csi2.dt =3D csis_fmt->data_type; =20 return 0; @@ -1269,6 +1270,39 @@ static const struct v4l2_subdev_internal_ops mipi_cs= is_internal_ops =3D { .init_state =3D mipi_csis_init_state, }; =20 +static int mipi_csis_get_vc(struct mipi_csis_device *csis) +{ + struct v4l2_mbus_frame_desc fd =3D { }; + int ret; + + ret =3D v4l2_subdev_call(csis->source.sd, pad, get_frame_desc, csis->sour= ce.pad->index, &fd); + if (ret < 0 && ret !=3D -ENOIOCTLCMD) { + dev_err(csis->dev, "get_frame_desc failed on source subdev\n"); + return ret; + } + + /* If remote subdev does not implement .get_frame_desc default to VC0 */ + if (ret =3D=3D -ENOIOCTLCMD) + return 0; + + if (fd.type !=3D V4L2_MBUS_FRAME_DESC_TYPE_CSI2) { + dev_err(csis->dev, "get_frame_desc returned invalid bus type %d\n", fd.t= ype); + return -EINVAL; + } + + if (!fd.num_entries) { + dev_err(csis->dev, "get_frame_desc returned zero enteries\n"); + return -EINVAL; + } + + if (fd.entry[0].bus.csi2.vc >=3D csis->num_channels) { + dev_err(csis->dev, "get_frame_desc returned invalid virtual channel\n"); + return -EINVAL; + } + + return fd.entry[0].bus.csi2.vc; +} + /* -----------------------------------------------------------------------= ------ * Media entity operations */ @@ -1296,6 +1330,13 @@ static int mipi_csis_link_setup(struct media_entity = *entity, =20 csis->source.sd =3D remote_sd; csis->source.pad =3D remote_pad; + + ret =3D mipi_csis_get_vc(csis); + + if (ret < 0) + return -EBUSY; + + csis->vc =3D ret; } else { csis->source.sd =3D NULL; csis->source.pad =3D NULL; --=20 2.49.0