Skip to content

Instantly share code, notes, and snippets.

@jailuthra
Created October 9, 2023 12:58
Show Gist options
  • Save jailuthra/dab73c3949a6271cf3d0fd3d3b111c5b to your computer and use it in GitHub Desktop.
Save jailuthra/dab73c3949a6271cf3d0fd3d3b111c5b to your computer and use it in GitHub Desktop.
CSI v10-v9 range-diff
1: d2be01bcbab8 ! 1: 5075d1ec93c8 media: dt-bindings: Make sure items in data-lanes are unique
@@ Commit message
uniqueItems constraint on the property to enforce this.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
2: f10c8ca7da1b ! 2: 76afcce671f5 media: dt-bindings: cadence-csi2rx: Add TI compatible string
@@ Commit message
Add a SoC-specific compatible string for TI's integration of this IP in
J7 and AM62 line of SoCs.
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
+ Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
3: df179f7bbb95 ! 3: d299647ee41c media: cadence: csi2rx: Unregister v4l2 async notifier
@@ Commit message
Fixes: 1fc3b37f34f6 ("media: v4l: cadence: Add Cadence MIPI-CSI2 RX driver")
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
4: 91babdee0058 ! 4: f15d16b11783 media: cadence: csi2rx: Cleanup media entity properly
@@ Commit message
Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
5: aa7c9cf6ed24 ! 5: a3b8bc5136f0 media: cadence: csi2rx: Add get_fmt and set_fmt pad ops
@@ Commit message
the source pads.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
- Co-authored-by: Jai Luthra <j-luthra@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
+ Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
+ Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
+ Co-developed-by: Jai Luthra <j-luthra@ti.com>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
## drivers/media/platform/cadence/cdns-csi2rx.c ##
@@ drivers/media/platform/cadence/cdns-csi2rx.c: static int csi2rx_s_stream(struct
+
+ /* Set sink format */
+ fmt = v4l2_subdev_get_pad_format(subdev, state, format->pad);
-+ if (!fmt)
-+ return -EINVAL;
-+
+ *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;
+ *fmt = format->format;
+ }
+
6: d1c17e4b2d91 ! 6: e611eead775d media: cadence: csi2rx: Configure DPHY using link freq
@@ Commit message
the correct link frequency.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
- Co-authored-by: Jai Luthra <j-luthra@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
+ Co-developed-by: Jai Luthra <j-luthra@ti.com>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
## drivers/media/platform/cadence/cdns-csi2rx.c ##
7: 3e9d8a228f62 ! 7: bd0aeceb9e37 media: cadence: csi2rx: Soft reset the streams before starting capture
@@ Commit message
after the first.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
+ Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
## drivers/media/platform/cadence/cdns-csi2rx.c ##
8: 6296b387cf1c ! 8: e2ab01a9d702 media: cadence: csi2rx: Set the STOP bit when stopping a stream
@@ Commit message
register polled to make sure the STOP operation is finished.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
9: 6e84a191038b ! 9: e2bd69b3561e media: cadence: csi2rx: Fix stream data configuration
@@ Commit message
are supported.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
10: 006bc8ae9e02 ! 10: 5c5a995d46cd media: cadence: csi2rx: Populate subdev devnode
@@ Commit message
ENOENT when setting format on the sensor subdev.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
11: b86c99479dce ! 11: 1bf94204a967 media: cadence: csi2rx: Add link validation
@@ Commit message
are caught.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Maxime Ripard <mripard@kernel.org>
12: b44925339a53 ! 12: 20c667d5f4da media: dt-bindings: Add TI J721E CSI2RX
@@ Commit message
parts together.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
13: c7b34683713a ! 13: 227422bfdd44 media: ti: Add CSI2RX support for J721E
@@
## Metadata ##
-Author: Pratyush Yadav <p.yadav@ti.com>
+Author: Jai Luthra <j-luthra@ti.com>
## Commit message ##
media: ti: Add CSI2RX support for J721E
@@ Commit message
DMA via the dmaengine API to finally return the data to a buffer
supplied by the application.
+ Co-developed-by: Pratyush Yadav <p.yadav@ti.com>
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
- Co-authored-by: Vaishnav Achath <vaishnav.a@ti.com>
+ Co-developed-by: Vaishnav Achath <vaishnav.a@ti.com>
Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
Tested-by: Vaishnav Achath <vaishnav.a@ti.com>
- Co-authored-by: Jai Luthra <j-luthra@ti.com>
+ Tested-by: Julien Massot <julien.massot@collabora.com>
+ Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
## MAINTAINERS ##
@@ drivers/media/platform/ti/Kconfig: config VIDEO_TI_VPE_DEBUG
+ tristate "TI J721E CSI2RX wrapper layer driver"
+ depends on VIDEO_DEV && VIDEO_V4L2_SUBDEV_API
+ depends on MEDIA_SUPPORT && MEDIA_CONTROLLER
-+ depends on PHY_CADENCE_DPHY_RX && VIDEO_CADENCE_CSI2RX
++ depends on (PHY_CADENCE_DPHY_RX && VIDEO_CADENCE_CSI2RX) || COMPILE_TEST
+ depends on ARCH_K3 || COMPILE_TEST
+ select VIDEOBUF2_DMA_CONTIG
+ select V4L2_FWNODE
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+#define SHIM_DMACNTX_YUV422 GENMASK(27, 26)
+#define SHIM_DMACNTX_SIZE GENMASK(21, 20)
+#define SHIM_DMACNTX_FMT GENMASK(5, 0)
-+#define SHIM_DMACNTX_UYVY 0
-+#define SHIM_DMACNTX_VYUY 1
-+#define SHIM_DMACNTX_YUYV 2
-+#define SHIM_DMACNTX_YVYU 3
++#define SHIM_DMACNTX_YUV422_MODE_11 3
+#define SHIM_DMACNTX_SIZE_8 0
+#define SHIM_DMACNTX_SIZE_16 1
+#define SHIM_DMACNTX_SIZE_32 2
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+#define MAX_HEIGHT_LINES SZ_16K
+
+#define DRAIN_TIMEOUT_MS 50
++#define DRAIN_BUFFER_SIZE SZ_32K
+
+struct ti_csi2rx_fmt {
+ u32 fourcc; /* Four character code. */
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ u32 sequence;
+};
+
-+static const struct ti_csi2rx_fmt formats[] = {
++static const struct ti_csi2rx_fmt ti_csi2rx_formats[] = {
+ {
+ .fourcc = V4L2_PIX_FMT_YUYV,
+ .code = MEDIA_BUS_FMT_YUYV8_1X16,
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ /* More formats can be supported but they are not listed for now. */
+};
+
-+static const unsigned int num_formats = ARRAY_SIZE(formats);
-+
+/* Forward declaration needed by ti_csi2rx_dma_callback. */
+static int ti_csi2rx_start_dma(struct ti_csi2rx_dev *csi,
+ struct ti_csi2rx_buffer *buf);
+
-+static const struct ti_csi2rx_fmt *find_format_by_pix(u32 pixelformat)
++static const struct ti_csi2rx_fmt *find_format_by_fourcc(u32 pixelformat)
+{
+ unsigned int i;
+
-+ for (i = 0; i < num_formats; i++) {
-+ if (formats[i].fourcc == pixelformat)
-+ return &formats[i];
++ for (i = 0; i < ARRAY_SIZE(ti_csi2rx_formats); i++) {
++ if (ti_csi2rx_formats[i].fourcc == pixelformat)
++ return &ti_csi2rx_formats[i];
+ }
+
+ return NULL;
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+{
+ unsigned int i;
+
-+ for (i = 0; i < num_formats; i++) {
-+ if (formats[i].code == code)
-+ return &formats[i];
++ for (i = 0; i < ARRAY_SIZE(ti_csi2rx_formats); i++) {
++ if (ti_csi2rx_formats[i].code == code)
++ return &ti_csi2rx_formats[i];
+ }
+
+ return NULL;
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+{
+ struct v4l2_pix_format *pix = &v4l2_fmt->fmt.pix;
+ unsigned int pixels_in_word;
-+ u8 bpp = ALIGN(csi_fmt->bpp, 8);
+
-+ pixels_in_word = PSIL_WORD_SIZE_BYTES * 8 / bpp;
++ pixels_in_word = PSIL_WORD_SIZE_BYTES * 8 / csi_fmt->bpp;
+
+ /* Clamp width and height to sensible maximums (16K x 16K) */
+ pix->width = clamp_t(unsigned int, pix->width,
+ pixels_in_word,
-+ MAX_WIDTH_BYTES * 8 / bpp);
++ MAX_WIDTH_BYTES * 8 / csi_fmt->bpp);
+ pix->height = clamp_t(unsigned int, pix->height, 1, MAX_HEIGHT_LINES);
+
+ /* Width should be a multiple of transfer word-size */
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+
+ v4l2_fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ pix->pixelformat = csi_fmt->fourcc;
-+ pix->colorspace = V4L2_COLORSPACE_SRGB;
-+ pix->bytesperline = pix->width * (bpp / 8);
++ pix->bytesperline = pix->width * (csi_fmt->bpp / 8);
+ pix->sizeimage = pix->bytesperline * pix->height;
+}
+
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+
+ fmt = find_format_by_code(f->mbus_code);
+ } else {
-+ if (f->index >= num_formats)
++ if (f->index >= ARRAY_SIZE(ti_csi2rx_formats))
+ return -EINVAL;
+
-+ fmt = &formats[f->index];
++ fmt = &ti_csi2rx_formats[f->index];
+ }
+
+ if (!fmt)
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ * Default to the first format if the requested pixel format code isn't
+ * supported.
+ */
-+ fmt = find_format_by_pix(f->fmt.pix.pixelformat);
++ fmt = find_format_by_fourcc(f->fmt.pix.pixelformat);
+ if (!fmt)
-+ fmt = &formats[0];
++ fmt = &ti_csi2rx_formats[0];
+
+ /* Interlaced formats are not supported. */
+ f->fmt.pix.field = V4L2_FIELD_NONE;
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+{
+ const struct ti_csi2rx_fmt *fmt;
+ unsigned int pixels_in_word;
-+ u8 bpp;
+
-+ fmt = find_format_by_pix(fsize->pixel_format);
++ fmt = find_format_by_fourcc(fsize->pixel_format);
+ if (!fmt || fsize->index != 0)
+ return -EINVAL;
+
-+ bpp = ALIGN(fmt->bpp, 8);
-+
+ /*
+ * Number of pixels in one PSI-L word. The transfer happens in multiples
+ * of PSI-L word sizes.
+ */
-+ pixels_in_word = PSIL_WORD_SIZE_BYTES * 8 / bpp;
++ pixels_in_word = PSIL_WORD_SIZE_BYTES * 8 / fmt->bpp;
+
+ fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
+ fsize->stepwise.min_width = pixels_in_word;
-+ fsize->stepwise.max_width = rounddown(MAX_WIDTH_BYTES * 8 / bpp,
++ fsize->stepwise.max_width = rounddown(MAX_WIDTH_BYTES * 8 / fmt->bpp,
+ pixels_in_word);
+ fsize->stepwise.step_width = pixels_in_word;
+ fsize->stepwise.min_height = 1;
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ return ret;
+ }
+
-+ return v4l2_device_register_subdev_nodes(&csi->v4l2_dev);
++ ret = v4l2_device_register_subdev_nodes(&csi->v4l2_dev);
++ if (ret)
++ video_unregister_device(vdev);
++
++ return ret;
+}
+
+static const struct v4l2_async_notifier_operations csi_async_notifier_ops = {
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ return 0;
+}
+
-+static int ti_csi2rx_setup_shim(struct ti_csi2rx_dev *csi)
++static void ti_csi2rx_setup_shim(struct ti_csi2rx_dev *csi)
+{
+ const struct ti_csi2rx_fmt *fmt;
+ unsigned int reg;
+
-+ fmt = find_format_by_pix(csi->v_fmt.fmt.pix.pixelformat);
-+ if (!fmt) {
-+ dev_err(csi->dev, "Pixelformat 0x%x is not supported\n",
-+ csi->v_fmt.fmt.pix.pixelformat);
-+ return -EINVAL;
-+ }
++ fmt = find_format_by_fourcc(csi->v_fmt.fmt.pix.pixelformat);
+
+ /* De-assert the pixel interface reset. */
+ reg = SHIM_CNTL_PIX_RST;
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ reg |= FIELD_PREP(SHIM_DMACNTX_FMT, fmt->csi_dt);
+
+ /*
-+ * Using the values from the documentation gives incorrect ordering for
-+ * the luma and chroma components. In practice, the "reverse" format
-+ * gives the correct image. So for example, if the image is in UYVY, the
-+ * reverse would be YVYU.
++ * The hardware assumes incoming YUV422 8-bit data on MIPI CSI2 bus
++ * follows the spec and is packed in the order U0 -> Y0 -> V0 -> Y1 ->
++ * ...
++ *
++ * There is an option to swap the bytes around before storing in
++ * memory, to achieve different pixel formats:
++ *
++ * Byte3 <----------- Byte0
++ * [ Y1 ][ V0 ][ Y0 ][ U0 ] MODE 11
++ * [ Y1 ][ U0 ][ Y0 ][ V0 ] MODE 10
++ * [ V0 ][ Y1 ][ U0 ][ Y0 ] MODE 01
++ * [ U0 ][ Y1 ][ V0 ][ Y0 ] MODE 00
++ *
++ * We don't have any requirement to change pixelformat from what is
++ * coming from the source, so we keep it in MODE 11, which does not
++ * swap any bytes when storing in memory.
+ */
+ switch (fmt->fourcc) {
+ case V4L2_PIX_FMT_UYVY:
-+ reg |= FIELD_PREP(SHIM_DMACNTX_YUV422,
-+ SHIM_DMACNTX_YVYU);
-+ break;
+ case V4L2_PIX_FMT_VYUY:
-+ reg |= FIELD_PREP(SHIM_DMACNTX_YUV422,
-+ SHIM_DMACNTX_YUYV);
-+ break;
+ case V4L2_PIX_FMT_YUYV:
-+ reg |= FIELD_PREP(SHIM_DMACNTX_YUV422,
-+ SHIM_DMACNTX_VYUY);
-+ break;
+ case V4L2_PIX_FMT_YVYU:
+ reg |= FIELD_PREP(SHIM_DMACNTX_YUV422,
-+ SHIM_DMACNTX_UYVY);
++ SHIM_DMACNTX_YUV422_MODE_11);
+ break;
+ default:
+ /* Ignore if not YUV 4:2:2 */
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ reg = FIELD_PREP(SHIM_PSI_CFG0_SRC_TAG, 0) |
+ FIELD_PREP(SHIM_PSI_CFG0_DST_TAG, 0);
+ writel(reg, csi->shim + SHIM_PSI_CFG0);
-+
-+ return 0;
+}
+
+static void ti_csi2rx_drain_callback(void *param)
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ complete(drain_complete);
+}
+
-+/** Drain the stale data left at the PSI-L endpoint.
++/*
++ * Drain the stale data left at the PSI-L endpoint.
+ *
+ * This might happen if no buffers are queued in time but source is still
-+ * streaming. Or rarely it may happen while stopping the stream. To prevent
-+ * that stale data corrupting the subsequent transactions, it is required to
-+ * issue DMA requests to drain it out.
++ * streaming. In multi-stream scenarios this can happen when one stream is
++ * stopped but other is still streaming, and thus module-level pixel reset is
++ * not asserted.
++ *
++ * To prevent that stale data corrupting the subsequent transactions, it is
++ * required to issue DMA requests to drain it out.
+ */
+static int ti_csi2rx_drain_dma(struct ti_csi2rx_dev *csi)
+{
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ if (!wait_for_completion_timeout(&drain_complete,
+ msecs_to_jiffies(DRAIN_TIMEOUT_MS))) {
+ dmaengine_terminate_sync(csi->dma.chan);
++ dev_dbg(csi->dev, "DMA transfer timed out for drain buffer\n");
+ ret = -ETIMEDOUT;
+ goto out;
+ }
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ return 0;
+}
+
-+static void ti_csi2rx_cleanup_buffers(struct ti_csi2rx_dev *csi,
-+ enum vb2_buffer_state buf_state)
++static void ti_csi2rx_stop_dma(struct ti_csi2rx_dev *csi)
+{
+ struct ti_csi2rx_dma *dma = &csi->dma;
-+ struct ti_csi2rx_buffer *buf, *tmp;
+ enum ti_csi2rx_dma_state state;
+ unsigned long flags;
+ int ret;
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+
+ if (state != TI_CSI2RX_DMA_STOPPED) {
+ /*
-+ * Normal DMA termination sometimes does not clean up pending
-+ * data on the endpoint.
++ * Normal DMA termination does not clean up pending data on
++ * the endpoint if multiple streams are running and only one
++ * is stopped, as the module-level pixel reset cannot be
++ * enforced before terminating DMA.
+ */
+ ret = ti_csi2rx_drain_dma(csi);
-+ if (ret)
-+ dev_dbg(csi->dev,
-+ "Failed to drain DMA. Next frame might be bogus\n");
++ if (ret && ret != -ETIMEDOUT)
++ dev_warn(csi->dev,
++ "Failed to drain DMA. Next frame might be bogus\n");
+ }
++
+ ret = dmaengine_terminate_sync(csi->dma.chan);
+ if (ret)
+ dev_err(csi->dev, "Failed to stop DMA: %d\n", ret);
++}
+
-+ dma_free_coherent(csi->dev, dma->drain.len,
-+ dma->drain.vaddr, dma->drain.paddr);
-+ dma->drain.vaddr = NULL;
++static void ti_csi2rx_cleanup_buffers(struct ti_csi2rx_dev *csi,
++ enum vb2_buffer_state state)
++{
++ struct ti_csi2rx_dma *dma = &csi->dma;
++ struct ti_csi2rx_buffer *buf, *tmp;
++ unsigned long flags;
+
+ spin_lock_irqsave(&dma->lock, flags);
+ list_for_each_entry_safe(buf, tmp, &csi->dma.queue, list) {
+ list_del(&buf->list);
-+ vb2_buffer_done(&buf->vb.vb2_buf, buf_state);
++ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+ list_for_each_entry_safe(buf, tmp, &csi->dma.submitted, list) {
+ list_del(&buf->list);
-+ vb2_buffer_done(&buf->vb.vb2_buf, buf_state);
++ vb2_buffer_done(&buf->vb.vb2_buf, state);
+ }
+ spin_unlock_irqrestore(&dma->lock, flags);
+}
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ * transaction to drain that up.
+ */
+ ret = ti_csi2rx_drain_dma(csi);
-+ if (ret)
++ if (ret && ret != -ETIMEDOUT)
+ dev_warn(csi->dev,
+ "Failed to drain DMA. Next frame might be bogus\n");
+
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ if (ret)
+ return ret;
+
-+ dma->drain.len = csi->v_fmt.fmt.pix.sizeimage;
-+ dma->drain.vaddr = dma_alloc_coherent(csi->dev, dma->drain.len,
-+ &dma->drain.paddr, GFP_KERNEL);
-+ if (!dma->drain.vaddr)
-+ return -ENOMEM;
-+
+ ret = video_device_pipeline_start(&csi->vdev, &csi->pipe);
+ if (ret)
+ goto err;
+
-+ ret = ti_csi2rx_setup_shim(csi);
-+ if (ret)
-+ goto err;
++ ti_csi2rx_setup_shim(csi);
+
+ csi->sequence = 0;
+
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ return 0;
+
+err_dma:
-+ dmaengine_terminate_sync(csi->dma.chan);
-+ writel(0, csi->shim + SHIM_DMACNTX);
++ ti_csi2rx_stop_dma(csi);
+err_pipeline:
+ video_device_pipeline_stop(&csi->vdev);
++ writel(0, csi->shim + SHIM_CNTL);
++ writel(0, csi->shim + SHIM_DMACNTX);
+err:
+ ti_csi2rx_cleanup_buffers(csi, VB2_BUF_STATE_QUEUED);
+ return ret;
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ if (ret)
+ dev_err(csi->dev, "Failed to stop subdev stream\n");
+
++ ti_csi2rx_stop_dma(csi);
+ ti_csi2rx_cleanup_buffers(csi, VB2_BUF_STATE_ERROR);
+}
+
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ return ret;
+ }
+
++ csi->dma.drain.len = DRAIN_BUFFER_SIZE;
++ csi->dma.drain.vaddr = dma_alloc_coherent(csi->dev, csi->dma.drain.len,
++ &csi->dma.drain.paddr,
++ GFP_KERNEL);
++ if (!csi->dma.drain.vaddr)
++ return -ENOMEM;
++
+ return 0;
+}
+
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+ struct v4l2_pix_format *pix_fmt = &csi->v_fmt.fmt.pix;
+ int ret;
+
-+ fmt = find_format_by_pix(V4L2_PIX_FMT_UYVY);
++ fmt = find_format_by_fourcc(V4L2_PIX_FMT_UYVY);
+ if (!fmt)
+ return -EINVAL;
+
+ pix_fmt->width = 640;
+ pix_fmt->height = 480;
+ pix_fmt->field = V4L2_FIELD_NONE;
++ pix_fmt->colorspace = V4L2_COLORSPACE_SRGB;
++ pix_fmt->ycbcr_enc = V4L2_YCBCR_ENC_601,
++ pix_fmt->quantization = V4L2_QUANTIZATION_LIM_RANGE,
++ pix_fmt->xfer_func = V4L2_XFER_FUNC_SRGB,
+
+ ti_csi2rx_fill_fmt(fmt, &csi->v_fmt);
+
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+
+static void ti_csi2rx_cleanup_dma(struct ti_csi2rx_dev *csi)
+{
++ dma_free_coherent(csi->dev, csi->dma.drain.len,
++ csi->dma.drain.vaddr, csi->dma.drain.paddr);
++ csi->dma.drain.vaddr = NULL;
+ dma_release_channel(csi->dma.chan);
+}
+
@@ drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c (new)
+module_platform_driver(ti_csi2rx_pdrv);
+
+MODULE_DESCRIPTION("TI J721E CSI2 RX Driver");
-+MODULE_AUTHOR("Pratyush Yadav <p.yadav@ti.com>");
++MODULE_AUTHOR("Jai Luthra <j-luthra@ti.com>");
+MODULE_LICENSE("GPL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment