From: Vaishnav Achath <vaishnav.a@ti.com>
To: <linux-media@vger.kernel.org>, <devicetree@vger.kernel.org>,
<mripard@kernel.org>, <mchehab@kernel.org>, <robh+dt@kernel.org>,
<krzysztof.kozlowski+dt@linaro.org>,
<laurent.pinchart@ideasonboard.com>,
<sakari.ailus@linux.intel.com>, <tomi.valkeinen@ideasonboard.com>
Cc: <linux-kernel@vger.kernel.org>, <bparrot@ti.com>,
<niklas.soderlund+renesas@ragnatech.se>, <j-luthra@ti.com>,
<devarsht@ti.com>, <praneeth@ti.com>, <u-kumar1@ti.com>,
<vigneshr@ti.com>, <nm@ti.com>, <martyn.welch@collabora.com>,
<vaishnav.a@ti.com>
Subject: [PATCH v7 03/13] media: cadence: csi2rx: Add get_fmt and set_fmt pad ops
Date: Tue, 14 Mar 2023 17:25:06 +0530 [thread overview]
Message-ID: <20230314115516.667-4-vaishnav.a@ti.com> (raw)
In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com>
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.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes in v7:
- Add Laurent's R-by.
Changes in v6:
- Move the lock around the dereference for framefmt in
csi2rx_{get,set}_fmt() instead of when we get the pointer.
- Do not return an error when an unsupported format is set. Instead
adjust the code to the first format in the list.
- Not adding Laurent's R-by since I am making changes in
csi2rx_set_fmt() that he didn't explicitly recommend.
Changes in v5:
- Use YUV 1X16 formats instead of 2X8.
- New in v5.
drivers/media/platform/cadence/cdns-csi2rx.c | 131 +++++++++++++++++++
1 file changed, 131 insertions(+)
diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index 2547903f2e8e..ae3ebdb3890d 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -54,6 +54,11 @@ enum csi2rx_pads {
CSI2RX_PAD_MAX,
};
+struct csi2rx_fmt {
+ u32 code;
+ u8 bpp;
+};
+
struct csi2rx_priv {
struct device *dev;
unsigned int count;
@@ -79,12 +84,43 @@ struct csi2rx_priv {
struct v4l2_subdev subdev;
struct v4l2_async_notifier notifier;
struct media_pad pads[CSI2RX_PAD_MAX];
+ struct v4l2_mbus_framefmt fmt;
/* Remote source */
struct v4l2_subdev *source_subdev;
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,
+ },
+};
+
+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)
{
@@ -236,12 +272,103 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable)
return ret;
}
+static struct v4l2_mbus_framefmt *
+csi2rx_get_pad_format(struct csi2rx_priv *csi2rx,
+ struct v4l2_subdev_state *state,
+ unsigned int pad, u32 which)
+{
+ switch (which) {
+ case V4L2_SUBDEV_FORMAT_TRY:
+ return v4l2_subdev_get_try_format(&csi2rx->subdev, state, pad);
+ case V4L2_SUBDEV_FORMAT_ACTIVE:
+ return &csi2rx->fmt;
+ default:
+ return NULL;
+ }
+}
+
+static int csi2rx_get_fmt(struct v4l2_subdev *subdev,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct csi2rx_priv *csi2rx = v4l2_subdev_to_csi2rx(subdev);
+ struct v4l2_mbus_framefmt *framefmt;
+
+ framefmt = csi2rx_get_pad_format(csi2rx, state, format->pad,
+ format->which);
+ if (!framefmt)
+ return -EINVAL;
+
+ mutex_lock(&csi2rx->lock);
+ format->format = *framefmt;
+ mutex_unlock(&csi2rx->lock);
+
+ return 0;
+}
+
+static int csi2rx_set_fmt(struct v4l2_subdev *subdev,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct csi2rx_priv *csi2rx = v4l2_subdev_to_csi2rx(subdev);
+ struct v4l2_mbus_framefmt *framefmt;
+
+ /* No transcoding, source and sink formats must match. */
+ if (format->pad != CSI2RX_PAD_SINK)
+ return csi2rx_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;
+
+ framefmt = csi2rx_get_pad_format(csi2rx, state, format->pad,
+ format->which);
+ if (!framefmt)
+ return -EINVAL;
+
+ mutex_lock(&csi2rx->lock);
+ *framefmt = format->format;
+ mutex_unlock(&csi2rx->lock);
+
+ return 0;
+}
+
+static int csi2rx_init_cfg(struct v4l2_subdev *subdev,
+ struct v4l2_subdev_state *state)
+{
+ struct v4l2_subdev_format format = {
+ .which = state ? V4L2_SUBDEV_FORMAT_TRY
+ : V4L2_SUBDEV_FORMAT_ACTIVE,
+ .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 = csi2rx_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,
@@ -457,6 +584,10 @@ static int csi2rx_probe(struct platform_device *pdev)
if (ret)
goto err_cleanup;
+ ret = csi2rx_init_cfg(&csi2rx->subdev, NULL);
+ if (ret)
+ goto err_cleanup;
+
ret = v4l2_async_register_subdev(&csi2rx->subdev);
if (ret < 0)
goto err_cleanup;
--
2.17.1
next prev parent reply other threads:[~2023-03-14 11:55 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-14 11:55 [PATCH v7 00/13] CSI2RX support on J721E Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 01/13] media: cadence: csi2rx: Unregister v4l2 async notifier Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 02/13] media: cadence: csi2rx: Cleanup media entity properly Vaishnav Achath
2023-03-14 11:55 ` Vaishnav Achath [this message]
2023-03-14 11:55 ` [PATCH v7 04/13] media: cadence: csi2rx: Add external DPHY support Vaishnav Achath
2023-03-31 13:19 ` Sakari Ailus
2023-03-14 11:55 ` [PATCH v7 05/13] media: cadence: csi2rx: Soft reset the streams before starting capture Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 06/13] media: cadence: csi2rx: Set the STOP bit when stopping a stream Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 07/13] media: cadence: csi2rx: Fix stream data configuration Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 08/13] media: cadence: csi2rx: Populate subdev devnode Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 09/13] media: cadence: csi2rx: Add link validation Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 10/13] media: ti: Add CSI2RX support for J721E Vaishnav Achath
2023-03-20 12:51 ` Jai Luthra
2023-03-24 18:14 ` Laurent Pinchart
2023-03-28 8:19 ` Vaishnav Achath
2023-04-04 11:43 ` Tomi Valkeinen
2023-03-31 13:27 ` Sakari Ailus
2023-03-14 11:55 ` [PATCH v7 11/13] media: dt-bindings: Make sure items in data-lanes are unique Vaishnav Achath
2023-03-14 11:55 ` [PATCH v7 12/13] media: dt-bindings: Add DT bindings for TI J721E CSI2RX driver Vaishnav Achath
2023-03-14 14:10 ` Rob Herring
2023-03-15 7:44 ` Krzysztof Kozlowski
2023-03-14 11:55 ` [PATCH v7 13/13] media: dt-bindings: Convert Cadence CSI2RX binding to YAML Vaishnav Achath
2023-03-15 7:45 ` Krzysztof Kozlowski
2023-03-20 5:34 ` Vaishnav Achath
2023-03-23 19:36 ` [PATCH v7 00/13] CSI2RX support on J721E Martyn Welch
2023-03-28 6:01 ` Jai Luthra
2023-03-29 15:17 ` Martyn Welch
2023-04-04 8:44 ` Tomi Valkeinen
2023-06-22 9:18 ` Julien Massot
2023-06-22 11:04 ` Jai Luthra
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=20230314115516.667-4-vaishnav.a@ti.com \
--to=vaishnav.a@ti.com \
--cc=bparrot@ti.com \
--cc=devarsht@ti.com \
--cc=devicetree@vger.kernel.org \
--cc=j-luthra@ti.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=martyn.welch@collabora.com \
--cc=mchehab@kernel.org \
--cc=mripard@kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=nm@ti.com \
--cc=praneeth@ti.com \
--cc=robh+dt@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tomi.valkeinen@ideasonboard.com \
--cc=u-kumar1@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
all inboxes | Powered by JetHome®