From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Jai Luthra <j-luthra@ti.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
Mauro Carvalho Chehab <mchehab+samsung@kernel.org>,
Maxime Ripard <mripard@kernel.org>,
niklas.soderlund+renesas@ragnatech.se,
Benoit Parrot <bparrot@ti.com>,
Vaishnav Achath <vaishnav.a@ti.com>,
Vignesh Raghavendra <vigneshr@ti.com>,
nm@ti.com, devarsht@ti.com, a-bhatia1@ti.com,
Martyn Welch <martyn.welch@collabora.com>,
Julien Massot <julien.massot@collabora.com>
Subject: Re: [PATCH v9 05/13] media: cadence: csi2rx: Add get_fmt and set_fmt pad ops
Date: Fri, 25 Aug 2023 06:48:58 +0300 [thread overview]
Message-ID: <20230825034858.GF6477@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20230811-upstream_csi-v9-5-8943f7a68a81@ti.com>
Hi Jai,
Thank you for the patch.
On Fri, Aug 11, 2023 at 04:17:27PM +0530, Jai Luthra wrote:
> From: Pratyush Yadav <p.yadav@ti.com>
>
> The format is needed to calculate the link speed for the external DPHY
> configuration. It is not right to query the format from the source
> subdev. Add get_fmt and set_fmt pad operations so that the format can be
> configured and correct bpp be selected.
>
> Initialize and use the v4l2 subdev active state to keep track of the
> active formats. Also propagate the new format from the sink pad to all
> the source pads.
>
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Co-authored-by: Jai Luthra <j-luthra@ti.com>
> Reviewed-by: Maxime Ripard <mripard@kernel.org>
> Signed-off-by: Jai Luthra <j-luthra@ti.com>
> ---
> Changes from v8:
> - Squash the patch adding RAW8 and RAW10 formats within this one
> - Single line struct entries in formats[] array
> - Skip specifiying redundant format.which entry in init_cfg()
>
> drivers/media/platform/cadence/cdns-csi2rx.c | 101 ++++++++++++++++++++++++++-
> 1 file changed, 100 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
> index 9de3240e261c..047e74ee2443 100644
> --- a/drivers/media/platform/cadence/cdns-csi2rx.c
> +++ b/drivers/media/platform/cadence/cdns-csi2rx.c
> @@ -61,6 +61,11 @@ enum csi2rx_pads {
> CSI2RX_PAD_MAX,
> };
>
> +struct csi2rx_fmt {
> + u32 code;
> + u8 bpp;
> +};
> +
> struct csi2rx_priv {
> struct device *dev;
> unsigned int count;
> @@ -95,6 +100,32 @@ struct csi2rx_priv {
> int source_pad;
> };
>
> +static const struct csi2rx_fmt formats[] = {
> + { .code = MEDIA_BUS_FMT_YUYV8_1X16, .bpp = 16, },
> + { .code = MEDIA_BUS_FMT_UYVY8_1X16, .bpp = 16, },
> + { .code = MEDIA_BUS_FMT_YVYU8_1X16, .bpp = 16, },
> + { .code = MEDIA_BUS_FMT_VYUY8_1X16, .bpp = 16, },
> + { .code = MEDIA_BUS_FMT_SBGGR8_1X8, .bpp = 8, },
> + { .code = MEDIA_BUS_FMT_SGBRG8_1X8, .bpp = 8, },
> + { .code = MEDIA_BUS_FMT_SGRBG8_1X8, .bpp = 8, },
> + { .code = MEDIA_BUS_FMT_SRGGB8_1X8, .bpp = 8, },
> + { .code = MEDIA_BUS_FMT_SBGGR10_1X10, .bpp = 10, },
> + { .code = MEDIA_BUS_FMT_SGBRG10_1X10, .bpp = 10, },
> + { .code = MEDIA_BUS_FMT_SGRBG10_1X10, .bpp = 10, },
> + { .code = MEDIA_BUS_FMT_SRGGB10_1X10, .bpp = 10, },
> +};
> +
> +static const struct csi2rx_fmt *csi2rx_get_fmt_by_code(u32 code)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < ARRAY_SIZE(formats); i++)
> + if (formats[i].code == code)
> + return &formats[i];
> +
> + return NULL;
> +}
> +
> static inline
> struct csi2rx_priv *v4l2_subdev_to_csi2rx(struct v4l2_subdev *subdev)
> {
> @@ -303,12 +334,73 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)
> return ret;
> }
>
> +static int csi2rx_set_fmt(struct v4l2_subdev *subdev,
> + struct v4l2_subdev_state *state,
> + struct v4l2_subdev_format *format)
> +{
> + struct v4l2_mbus_framefmt *fmt;
> + unsigned int i;
> +
> + /* No transcoding, source and sink formats must match. */
> + if (format->pad != CSI2RX_PAD_SINK)
> + return v4l2_subdev_get_fmt(subdev, state, format);
> +
> + if (!csi2rx_get_fmt_by_code(format->format.code))
> + format->format.code = formats[0].code;
> +
> + format->format.field = V4L2_FIELD_NONE;
> +
> + /* Set sink format */
> + fmt = v4l2_subdev_get_pad_format(subdev, state, format->pad);
> + if (!fmt)
> + return -EINVAL;
You can drop this check, as format->pad is CSI2RX_PAD_SINK, this is
guaranteed to succeed.
> +
> + *fmt = format->format;
> +
> + /* Propagate to source formats */
> + for (i = CSI2RX_PAD_SOURCE_STREAM0; i < CSI2RX_PAD_MAX; i++) {
> + fmt = v4l2_subdev_get_pad_format(subdev, state, i);
> + if (!fmt)
> + return -EINVAL;
Same here.
With these minor issues addressed,
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> + *fmt = format->format;
> + }
> +
> + return 0;
> +}
> +
> +static int csi2rx_init_cfg(struct v4l2_subdev *subdev,
> + struct v4l2_subdev_state *state)
> +{
> + struct v4l2_subdev_format format = {
> + .pad = CSI2RX_PAD_SINK,
> + .format = {
> + .width = 640,
> + .height = 480,
> + .code = MEDIA_BUS_FMT_UYVY8_1X16,
> + .field = V4L2_FIELD_NONE,
> + .colorspace = V4L2_COLORSPACE_SRGB,
> + .ycbcr_enc = V4L2_YCBCR_ENC_601,
> + .quantization = V4L2_QUANTIZATION_LIM_RANGE,
> + .xfer_func = V4L2_XFER_FUNC_SRGB,
> + },
> + };
> +
> + return csi2rx_set_fmt(subdev, state, &format);
> +}
> +
> +static const struct v4l2_subdev_pad_ops csi2rx_pad_ops = {
> + .get_fmt = v4l2_subdev_get_fmt,
> + .set_fmt = csi2rx_set_fmt,
> + .init_cfg = csi2rx_init_cfg,
> +};
> +
> static const struct v4l2_subdev_video_ops csi2rx_video_ops = {
> .s_stream = csi2rx_s_stream,
> };
>
> static const struct v4l2_subdev_ops csi2rx_subdev_ops = {
> .video = &csi2rx_video_ops,
> + .pad = &csi2rx_pad_ops,
> };
>
> static int csi2rx_async_bound(struct v4l2_async_notifier *notifier,
> @@ -532,9 +624,13 @@ static int csi2rx_probe(struct platform_device *pdev)
> if (ret)
> goto err_cleanup;
>
> + ret = v4l2_subdev_init_finalize(&csi2rx->subdev);
> + if (ret)
> + goto err_cleanup;
> +
> ret = v4l2_async_register_subdev(&csi2rx->subdev);
> if (ret < 0)
> - goto err_cleanup;
> + goto err_free_state;
>
> dev_info(&pdev->dev,
> "Probed CSI2RX with %u/%u lanes, %u streams, %s D-PHY\n",
> @@ -544,6 +640,8 @@ static int csi2rx_probe(struct platform_device *pdev)
>
> return 0;
>
> +err_free_state:
> + v4l2_subdev_cleanup(&csi2rx->subdev);
> err_cleanup:
> v4l2_async_nf_unregister(&csi2rx->notifier);
> v4l2_async_nf_cleanup(&csi2rx->notifier);
> @@ -560,6 +658,7 @@ static void csi2rx_remove(struct platform_device *pdev)
> v4l2_async_nf_unregister(&csi2rx->notifier);
> v4l2_async_nf_cleanup(&csi2rx->notifier);
> v4l2_async_unregister_subdev(&csi2rx->subdev);
> + v4l2_subdev_cleanup(&csi2rx->subdev);
> media_entity_cleanup(&csi2rx->subdev.entity);
> kfree(csi2rx);
> }
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2023-08-25 3:49 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 10:47 [PATCH v9 00/13] CSI2RX support on J721E and AM62 Jai Luthra
2023-08-11 10:47 ` [PATCH v9 01/13] media: dt-bindings: Make sure items in data-lanes are unique Jai Luthra
2023-08-11 10:47 ` [PATCH v9 02/13] media: dt-bindings: cadence-csi2rx: Add TI compatible string Jai Luthra
2023-08-25 3:44 ` Laurent Pinchart
2023-08-11 10:47 ` [PATCH v9 03/13] media: cadence: csi2rx: Unregister v4l2 async notifier Jai Luthra
2023-08-11 10:47 ` [PATCH v9 04/13] media: cadence: csi2rx: Cleanup media entity properly Jai Luthra
2023-08-11 10:47 ` [PATCH v9 05/13] media: cadence: csi2rx: Add get_fmt and set_fmt pad ops Jai Luthra
2023-08-15 12:05 ` Tomi Valkeinen
2023-08-25 3:48 ` Laurent Pinchart [this message]
2023-08-11 10:47 ` [PATCH v9 06/13] media: cadence: csi2rx: Configure DPHY using link freq Jai Luthra
2023-08-11 10:47 ` [PATCH v9 07/13] media: cadence: csi2rx: Soft reset the streams before starting capture Jai Luthra
2023-08-15 12:10 ` Tomi Valkeinen
2023-08-11 10:47 ` [PATCH v9 08/13] media: cadence: csi2rx: Set the STOP bit when stopping a stream Jai Luthra
2023-08-11 10:47 ` [PATCH v9 09/13] media: cadence: csi2rx: Fix stream data configuration Jai Luthra
2023-08-11 10:47 ` [PATCH v9 10/13] media: cadence: csi2rx: Populate subdev devnode Jai Luthra
2023-08-11 10:47 ` [PATCH v9 11/13] media: cadence: csi2rx: Add link validation Jai Luthra
2023-08-11 10:47 ` [PATCH v9 12/13] media: dt-bindings: Add TI J721E CSI2RX Jai Luthra
2023-08-11 14:00 ` Rob Herring
2023-08-11 14:54 ` Rob Herring
2023-08-11 10:47 ` [PATCH v9 13/13] media: ti: Add CSI2RX support for J721E Jai Luthra
2023-08-15 13:00 ` Tomi Valkeinen
2023-08-18 10:25 ` Jai Luthra
2023-08-29 15:55 ` Laurent Pinchart
2023-10-04 13:51 ` Vinod Koul
2023-10-04 20:03 ` Laurent Pinchart
2023-10-05 4:10 ` Vinod Koul
2023-10-06 10:26 ` Jai Luthra
2023-08-29 16:44 ` Laurent Pinchart
2023-10-05 8:34 ` Jai Luthra
2023-08-24 15:18 ` [PATCH v9 00/13] CSI2RX support on J721E and AM62 Julien Massot
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=20230825034858.GF6477@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=a-bhatia1@ti.com \
--cc=bparrot@ti.com \
--cc=conor+dt@kernel.org \
--cc=devarsht@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=j-luthra@ti.com \
--cc=julien.massot@collabora.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=martyn.welch@collabora.com \
--cc=mchehab+samsung@kernel.org \
--cc=mchehab@kernel.org \
--cc=mripard@kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=nm@ti.com \
--cc=robh+dt@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=vaishnav.a@ti.com \
--cc=vigneshr@ti.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