* [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture
2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
@ 2026-11-29 13:28 ` Siddharth Vadapalli
2026-11-30 15:21 ` Nicolas Dufresne
2026-11-29 13:28 ` [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames Siddharth Vadapalli
2 siblings, 1 reply; 5+ messages in thread
From: Siddharth Vadapalli @ 2026-11-29 13:28 UTC (permalink / raw)
To: mchehab, jai.luthra, nicolas.dufresne, detlev.casanova,
hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk,
s-vadapalli
A capture buffer is only returned by VIDIOC_DQBUF once the whole frame
has been captured. For low latency pipelines that want to start processing
sub-frames (group of lines in a frame), there is currently no way to
identify how much of the capture buffer has been filled. This results in a
fixed latency overhead corresponding to the frame-rate because the
processing can only start after the entire frame has been captured.
Add V4L2_EVENT_BUF_PROGRESS, which reports the number of bytes from the
start of a buffer that have been written so far, thereby allowing
subscribers to determine the valid portion of the capture buffer and
start processing the valid sub-frame. When a buffer is completed
successfully, the last event for it is queued before the buffer is
returned by VIDIOC_DQBUF, so a subscriber can determine the end-of-frame
from that event alone.
The event payload has space reserved for future extensions. The bytesused
field is only defined for queues of a single-planar buffer type. This event
is generic and does not depend on the format.
Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
.../media/v4l/videodev2.h.rst.exceptions | 1 +
.../media/v4l/vidioc-dqevent.rst | 74 +++++++++++++++++++
include/uapi/linux/videodev2.h | 18 +++++
3 files changed, 93 insertions(+)
diff --git a/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions b/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
index 6182b4e2d2ee..b02f5dd07cab 100644
--- a/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
+++ b/Documentation/userspace-api/media/v4l/videodev2.h.rst.exceptions
@@ -524,6 +524,7 @@ replace define V4L2_EVENT_CTRL event-type
replace define V4L2_EVENT_FRAME_SYNC event-type
replace define V4L2_EVENT_SOURCE_CHANGE event-type
replace define V4L2_EVENT_MOTION_DET event-type
+replace define V4L2_EVENT_BUF_PROGRESS event-type
replace define V4L2_EVENT_PRIVATE_START event-type
replace define V4L2_EVENT_CTRL_CH_VALUE ctrl-changes-flags
diff --git a/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst b/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
index 8db103760930..1421ccadab8e 100644
--- a/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
+++ b/Documentation/userspace-api/media/v4l/vidioc-dqevent.rst
@@ -64,6 +64,9 @@ call.
* - struct :c:type:`v4l2_event_motion_det`
- ``motion_det``
- Event data for event V4L2_EVENT_MOTION_DET.
+ * - struct :c:type:`v4l2_event_buf_progress`
+ - ``buf_progress``
+ - Event data for event ``V4L2_EVENT_BUF_PROGRESS``.
* - struct :c:type:`v4l2_event_src_change`
- ``src_change``
- Event data for event V4L2_EVENT_SOURCE_CHANGE.
@@ -182,6 +185,50 @@ call.
the regions changes. This event has a struct
:c:type:`v4l2_event_motion_det`
associated with it.
+ * - ``V4L2_EVENT_BUF_PROGRESS``
+ - 7
+ - Triggered while a capture buffer is being filled, to report how many
+ bytes from its start have already been written. This allows the
+ leading part of a frame to be processed before the buffer is ready
+ to be dequeued. This event has a struct
+ :c:type:`v4l2_event_buf_progress`
+ associated with it.
+
+ Events are only generated by drivers that support them, and only
+ while the ``V4L2_CID_BUF_PROGRESS_SIZE`` control is non-zero (see
+ :ref:`User Controls <control>`).
+
+ Within one buffer, the ``bytesused`` field only grows. When a buffer
+ is completed successfully, the last event for it, with ``bytesused``
+ equal to the ``bytesused`` of the buffer, is queued before the
+ buffer is returned by :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>`. This last
+ event is always queued, even if fewer than
+ ``V4L2_CID_BUF_PROGRESS_SIZE`` lines were written since the previous
+ event.
+
+ No last event is guaranteed for a buffer that is returned with the
+ ``V4L2_BUF_FLAG_ERROR`` flag set, or for a buffer that is returned
+ because streaming was stopped with
+ :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`. Events that were queued
+ for such a buffer have to be ignored. Applications must therefore
+ consider :ref:`VIDIOC_DQBUF <VIDIOC_QBUF>` as the authoritative
+ indication of the state of a buffer.
+
+ Events are dropped, oldest first, when the application does not
+ dequeue them in time. Lost events can be detected by a gap in the
+ ``sequence`` field of struct :c:type:`v4l2_event`, which is not
+ related to the ``sequence`` field of struct
+ :c:type:`v4l2_event_buf_progress`. Applications must be prepared
+ for intermediate values of ``bytesused`` to be skipped.
+
+ The buffer remains owned by the driver until it is dequeued, and the
+ driver does not perform any cache maintenance on the part of the
+ buffer that was reported. An application that reads that part before
+ the buffer is dequeued must make sure that its mapping is coherent
+ with DMA, which is not the case for memory allocated with
+ ``V4L2_MEMORY_FLAG_NON_COHERENT``. For buffers with memory type
+ ``V4L2_MEMORY_DMABUF``, cache management is the responsibility of
+ the exporter of the buffer.
* - ``V4L2_EVENT_PRIVATE_START``
- 0x08000000
- Base event number for driver-private events.
@@ -309,6 +356,33 @@ call.
automatically assigned to the default region 0.
+.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|
+
+.. c:type:: v4l2_event_buf_progress
+
+.. flat-table:: struct v4l2_event_buf_progress
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 1 1 2
+
+ * - __u32
+ - ``index``
+ - The index of the buffer that is being filled.
+ * - __u32
+ - ``sequence``
+ - The sequence number the buffer will be dequeued with.
+ * - __u32
+ - ``bytesused``
+ - The number of bytes from the start of the buffer that have been
+ written so far. This field is only defined for queues of a
+ single-planar buffer type. A driver that generates this event on a
+ multi-planar queue has to document the meaning of this field.
+ * - __u32
+ - ``reserved``\ [5]
+ - Reserved for future extensions. Drivers must set the array to
+ zero.
+
+
.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
.. _ctrl-changes-flags:
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 5373dba640fa..a019f481167e 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -2558,6 +2558,7 @@ struct v4l2_streamparm {
#define V4L2_EVENT_FRAME_SYNC 4
#define V4L2_EVENT_SOURCE_CHANGE 5
#define V4L2_EVENT_MOTION_DET 6
+#define V4L2_EVENT_BUF_PROGRESS 7
#define V4L2_EVENT_PRIVATE_START 0x08000000
/* Payload for V4L2_EVENT_VSYNC */
@@ -2611,6 +2612,22 @@ struct v4l2_event_motion_det {
__u32 region_mask;
};
+/**
+ * struct v4l2_event_buf_progress - buffer fill progress event
+ * @index: index of the buffer that is being filled.
+ * @sequence: sequence number the buffer will be dequeued with.
+ * @bytesused: number of bytes from the start of the buffer that
+ * have been written so far.
+ * @reserved: reserved for future extensions, drivers must set
+ * the array to zero.
+ */
+struct v4l2_event_buf_progress {
+ __u32 index;
+ __u32 sequence;
+ __u32 bytesused;
+ __u32 reserved[5];
+};
+
struct v4l2_event {
__u32 type;
union {
@@ -2619,6 +2636,7 @@ struct v4l2_event {
struct v4l2_event_frame_sync frame_sync;
struct v4l2_event_src_change src_change;
struct v4l2_event_motion_det motion_det;
+ struct v4l2_event_buf_progress buf_progress;
__u8 data[64];
} u;
__u32 pending;
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality
2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Siddharth Vadapalli
@ 2026-11-29 13:28 ` Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames Siddharth Vadapalli
2 siblings, 0 replies; 5+ messages in thread
From: Siddharth Vadapalli @ 2026-11-29 13:28 UTC (permalink / raw)
To: mchehab, jai.luthra, nicolas.dufresne, detlev.casanova,
hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk,
s-vadapalli
The V4L2_EVENT_BUF_PROGRESS event is generated whenever N lines in a
capture buffer are ready to be consumed by a subscriber. Two controls
associated with this event are:
1. Number of lines 'N' after which the event should be generated.
2. Interval 'I' at which the buffer progress has to be queried by the
driver to detect the readiness of the next 'N' lines.
Hence, add V4L2_CID_BUF_PROGRESS_SIZE and V4L2_CID_BUF_PROGRESS_INTERVAL
controls which respectively correspond to the controls described above.
Since the event is generated by the capture DMA engine and not by the
image source, the controls are not specific to cameras. Hence, add them to
the user control class instead of the camera control class.
Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
.../userspace-api/media/v4l/control.rst | 21 +++++++++++++++++++
drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++
include/uapi/linux/v4l2-controls.h | 5 ++++-
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/Documentation/userspace-api/media/v4l/control.rst b/Documentation/userspace-api/media/v4l/control.rst
index 19372bb32c4b..7dcf7c80a0d8 100644
--- a/Documentation/userspace-api/media/v4l/control.rst
+++ b/Documentation/userspace-api/media/v4l/control.rst
@@ -316,6 +316,27 @@ Control IDs
set the alpha component value of all pixels for further processing
in the device.
+``V4L2_CID_BUF_PROGRESS_SIZE`` ``(integer)``
+ Granularity of the :ref:`V4L2_EVENT_BUF_PROGRESS <event-type>` event, in
+ lines. While a capture buffer is being filled, the driver queues the
+ event each time at least this many additional complete lines have been
+ written to it. The event that reports the completion of the buffer is
+ always queued, even if fewer lines were written since the previous
+ event. If the value is not smaller than the height of the frame, the
+ only event that is queued for a buffer is the one that reports its
+ completion. The value 0, which is the default, disables the event. The
+ control is only supported by drivers that generate the event, and its
+ value cannot be changed while the device is streaming.
+
+``V4L2_CID_BUF_PROGRESS_INTERVAL`` ``(integer)``
+ Interval, in microseconds, at which a driver that has to sample the
+ progress of the buffer being filled does so for the
+ :ref:`V4L2_EVENT_BUF_PROGRESS <event-type>` event. A shorter interval
+ reduces the delay between lines being written and the event being
+ queued, at the cost of a higher CPU load. The control is only supported
+ by drivers that have to sample the progress, and its value cannot be
+ changed while the device is streaming.
+
``V4L2_CID_LASTP1``
End of the predefined control IDs (currently
``V4L2_CID_ALPHA_COMPONENT`` + 1).
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index e062f2088490..e9bbe40e8d33 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -831,6 +831,8 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_ALPHA_COMPONENT: return "Alpha Component";
case V4L2_CID_COLORFX_CBCR: return "Color Effects, CbCr";
case V4L2_CID_COLORFX_RGB: return "Color Effects, RGB";
+ case V4L2_CID_BUF_PROGRESS_SIZE: return "Buffer Progress Size";
+ case V4L2_CID_BUF_PROGRESS_INTERVAL: return "Buffer Progress Interval";
/*
* Codec controls
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index d17e41d51d2e..4e05f63bcf12 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -110,8 +110,11 @@ enum v4l2_colorfx {
#define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
#define V4L2_CID_COLORFX_RGB (V4L2_CID_BASE+43)
+#define V4L2_CID_BUF_PROGRESS_SIZE (V4L2_CID_BASE+44)
+#define V4L2_CID_BUF_PROGRESS_INTERVAL (V4L2_CID_BASE+45)
+
/* last CID + 1 */
-#define V4L2_CID_LASTP1 (V4L2_CID_BASE+44)
+#define V4L2_CID_LASTP1 (V4L2_CID_BASE+46)
/* USER-class private control IDs */
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] media: ti: j721e-csi2rx: Generate capture-progress events for sub-frames
2026-11-29 13:28 [PATCH 0/3] media: Add V4L2_EVENT_BUF_PROGRESS and use it in j721e-csi2rx Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 1/3] media: v4l2: Add V4L2_EVENT_BUF_PROGRESS to report progress of capture Siddharth Vadapalli
2026-11-29 13:28 ` [PATCH 2/3] media: v4l2-ctrls: Add buffer progress controls for sub-frame functionality Siddharth Vadapalli
@ 2026-11-29 13:28 ` Siddharth Vadapalli
2 siblings, 0 replies; 5+ messages in thread
From: Siddharth Vadapalli @ 2026-11-29 13:28 UTC (permalink / raw)
To: mchehab, jai.luthra, nicolas.dufresne, detlev.casanova,
hverkuil+cisco, sakari.ailus, richard.leitner, jackson.lee
Cc: linux-media, linux-arm-kernel, devarsht, vigneshr, srk,
s-vadapalli
A capture buffer is only returned to userspace once the whole frame has
been captured. For low latency use-cases, generate capture-progress events
(V4L2_EVENT_BUF_PROGRESS) to allow userspace applications to consume and
start processing sub-frames.
Since a single DMA descriptor is associated with an entire video frame,
completion of descriptors queued to DMA cannot be an indicator of the
readiness of sub-frames. Hence, use the standard dmaengine_tx_status()
dmaengine API to query progress of the capture. Additionally, use the
High Resolution Timers in Linux to trigger the query periodically.
The number of lines in a sub-frame for which the capture-progress event
has to be generated is set using V4L2_CID_BUF_PROGRESS_SIZE. If number
of lines is set to '0', the capture-progress event is disabled. For a
valid value of the number of lines in a sub-frame, the event is generated.
Similarly, the interval at which the capture-progress has to be sampled
is set using V4L2_CID_BUF_PROGRESS_INTERVAL, which is limited to a minimum
of 100 microseconds to bound the CPU load that userspace can cause.
The parameters are sampled at the start and cannot be modified in the
middle of streaming. They can however be modified when streaming is not in
progress.
Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
---
.../platform/ti/j721e-csi2rx/j721e-csi2rx.c | 251 +++++++++++++++++-
1 file changed, 246 insertions(+), 5 deletions(-)
diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
index ba7abb723da6..79d2118301fe 100644
--- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
+++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
@@ -10,6 +10,7 @@
#include <linux/bitfield.h>
#include <linux/dmaengine.h>
+#include <linux/hrtimer.h>
#include <linux/module.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
@@ -18,7 +19,9 @@
#include <media/cadence/cdns-csi2rx.h>
#include <media/mipi-csi2.h>
+#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
+#include <media/v4l2-event.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-mc.h>
#include <media/videobuf2-dma-contig.h>
@@ -66,6 +69,11 @@
#define CSI2RX_BRIDGE_SOURCE_PAD 1
+#define TI_CSI2RX_PROGRESS_EVENTS 32
+#define TI_CSI2RX_PROGRESS_INTERVAL_MIN 100
+#define TI_CSI2RX_PROGRESS_INTERVAL_MAX 5000
+#define TI_CSI2RX_PROGRESS_INTERVAL_DEF 200
+
struct ti_csi2rx_fmt {
u32 fourcc; /* Four character code. */
u32 code; /* Mbus code. */
@@ -79,6 +87,7 @@ struct ti_csi2rx_buffer {
struct vb2_v4l2_buffer vb;
struct list_head list;
struct ti_csi2rx_ctx *ctx;
+ dma_cookie_t cookie;
};
enum ti_csi2rx_dma_state {
@@ -100,6 +109,16 @@ struct ti_csi2rx_dma {
struct list_head submitted;
};
+struct ti_csi2rx_progress {
+ struct hrtimer timer;
+ ktime_t period;
+ u32 lines;
+ struct ti_csi2rx_buffer *cur;
+ u32 last;
+ u32 base;
+ bool have_base;
+};
+
struct ti_csi2rx_dev;
struct ti_csi2rx_ctx {
@@ -109,6 +128,10 @@ struct ti_csi2rx_ctx {
struct mutex mutex; /* To serialize ioctls. */
struct v4l2_format v_fmt;
struct ti_csi2rx_dma dma;
+ struct ti_csi2rx_progress progress;
+ struct v4l2_ctrl_handler ctrl_hdl;
+ struct v4l2_ctrl *ctrl_progress_size;
+ struct v4l2_ctrl *ctrl_progress_interval;
struct media_pad pad;
struct completion drain_complete;
u32 sequence;
@@ -427,6 +450,20 @@ static int ti_csi2rx_enum_framesizes(struct file *file, void *fh,
return 0;
}
+static int ti_csi2rx_subscribe_event(struct v4l2_fh *fh,
+ const struct v4l2_event_subscription *sub)
+{
+ switch (sub->type) {
+ case V4L2_EVENT_CTRL:
+ return v4l2_ctrl_subscribe_event(fh, sub);
+ case V4L2_EVENT_BUF_PROGRESS:
+ return v4l2_event_subscribe(fh, sub, TI_CSI2RX_PROGRESS_EVENTS,
+ NULL);
+ default:
+ return -EINVAL;
+ }
+}
+
static const struct v4l2_ioctl_ops csi_ioctl_ops = {
.vidioc_querycap = ti_csi2rx_querycap,
.vidioc_enum_fmt_vid_cap = ti_csi2rx_enum_fmt_vid_cap,
@@ -443,6 +480,8 @@ static const struct v4l2_ioctl_ops csi_ioctl_ops = {
.vidioc_expbuf = vb2_ioctl_expbuf,
.vidioc_streamon = vb2_ioctl_streamon,
.vidioc_streamoff = vb2_ioctl_streamoff,
+ .vidioc_subscribe_event = ti_csi2rx_subscribe_event,
+ .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
};
static const struct v4l2_file_operations csi_fops = {
@@ -728,6 +767,157 @@ static int ti_csi2rx_dma_submit_pending(struct ti_csi2rx_ctx *ctx)
return ret;
}
+static void ti_csi2rx_progress_event(struct ti_csi2rx_buffer *buf,
+ struct ti_csi2rx_ctx *ctx, u32 sequence,
+ u32 bytesused)
+{
+ struct v4l2_event ev = {
+ .type = V4L2_EVENT_BUF_PROGRESS,
+ .u.buf_progress = {
+ .index = buf->vb.vb2_buf.index,
+ .sequence = sequence,
+ .bytesused = bytesused,
+ },
+ };
+
+ v4l2_event_queue(&ctx->vdev, &ev);
+}
+
+static void ti_csi2rx_progress_sample(struct ti_csi2rx_ctx *ctx,
+ struct ti_csi2rx_buffer *buf)
+{
+ struct ti_csi2rx_progress *prog = &ctx->progress;
+ struct v4l2_pix_format *pix = &ctx->v_fmt.fmt.pix;
+ struct dma_tx_state st = { };
+ u32 bytes, lines;
+
+ if (buf != prog->cur) {
+ prog->cur = buf;
+ prog->last = 0;
+ prog->have_base = false;
+ }
+
+ if (dmaengine_tx_status(ctx->dma.chan, buf->cookie, &st) !=
+ DMA_IN_PROGRESS)
+ return;
+
+ if (st.residue > pix->sizeimage)
+ return;
+
+ if (!prog->have_base) {
+ prog->base = st.residue;
+ prog->have_base = true;
+ }
+
+ bytes = (prog->base + pix->sizeimage - st.residue) % pix->sizeimage;
+
+ lines = bytes / pix->bytesperline;
+ lines -= lines % prog->lines;
+ if (lines <= prog->last || lines >= pix->height)
+ return;
+
+ prog->last = lines;
+ ti_csi2rx_progress_event(buf, ctx, ctx->sequence,
+ lines * pix->bytesperline);
+}
+
+static enum hrtimer_restart ti_csi2rx_progress_timer(struct hrtimer *timer)
+{
+ struct ti_csi2rx_ctx *ctx = container_of(timer, struct ti_csi2rx_ctx,
+ progress.timer);
+ struct ti_csi2rx_dma *dma = &ctx->dma;
+ struct ti_csi2rx_buffer *buf;
+ unsigned long flags;
+
+ spin_lock_irqsave(&dma->lock, flags);
+
+ buf = list_first_entry_or_null(&dma->submitted,
+ struct ti_csi2rx_buffer, list);
+ if (buf && dma->state == TI_CSI2RX_DMA_ACTIVE && ctx->progress.lines)
+ ti_csi2rx_progress_sample(ctx, buf);
+
+ spin_unlock_irqrestore(&dma->lock, flags);
+
+ hrtimer_forward_now(timer, ctx->progress.period);
+
+ return HRTIMER_RESTART;
+}
+
+static void ti_csi2rx_progress_start(struct ti_csi2rx_ctx *ctx)
+{
+ struct ti_csi2rx_progress *prog = &ctx->progress;
+ u32 lines, interval;
+ unsigned long flags;
+
+ v4l2_ctrl_grab(ctx->ctrl_progress_size, true);
+ v4l2_ctrl_grab(ctx->ctrl_progress_interval, true);
+
+ lines = v4l2_ctrl_g_ctrl(ctx->ctrl_progress_size);
+ interval = v4l2_ctrl_g_ctrl(ctx->ctrl_progress_interval);
+
+ if (!lines)
+ return;
+
+ prog->period = ns_to_ktime((u64)interval * NSEC_PER_USEC);
+
+ spin_lock_irqsave(&ctx->dma.lock, flags);
+ prog->lines = lines;
+ prog->cur = NULL;
+ spin_unlock_irqrestore(&ctx->dma.lock, flags);
+
+ hrtimer_start(&prog->timer, prog->period, HRTIMER_MODE_REL_SOFT);
+}
+
+static void ti_csi2rx_progress_pause(struct ti_csi2rx_ctx *ctx)
+{
+ struct ti_csi2rx_progress *prog = &ctx->progress;
+ unsigned long flags;
+
+ hrtimer_cancel(&prog->timer);
+
+ spin_lock_irqsave(&ctx->dma.lock, flags);
+ prog->cur = NULL;
+ spin_unlock_irqrestore(&ctx->dma.lock, flags);
+}
+
+static void ti_csi2rx_progress_resume(struct ti_csi2rx_ctx *ctx)
+{
+ struct ti_csi2rx_progress *prog = &ctx->progress;
+ unsigned long flags;
+
+ spin_lock_irqsave(&ctx->dma.lock, flags);
+ if (prog->lines)
+ hrtimer_start(&prog->timer, prog->period,
+ HRTIMER_MODE_REL_SOFT);
+ spin_unlock_irqrestore(&ctx->dma.lock, flags);
+}
+
+static void ti_csi2rx_progress_stop(struct ti_csi2rx_ctx *ctx)
+{
+ struct ti_csi2rx_progress *prog = &ctx->progress;
+ unsigned long flags;
+
+ spin_lock_irqsave(&ctx->dma.lock, flags);
+ prog->lines = 0;
+ prog->cur = NULL;
+ spin_unlock_irqrestore(&ctx->dma.lock, flags);
+
+ hrtimer_cancel(&prog->timer);
+
+ v4l2_ctrl_grab(ctx->ctrl_progress_size, false);
+ v4l2_ctrl_grab(ctx->ctrl_progress_interval, false);
+}
+
+static void ti_csi2rx_progress_done(struct ti_csi2rx_ctx *ctx,
+ struct ti_csi2rx_buffer *buf)
+{
+ if (!ctx->progress.lines)
+ return;
+
+ ti_csi2rx_progress_event(buf, ctx, buf->vb.sequence,
+ ctx->v_fmt.fmt.pix.sizeimage);
+}
+
static void ti_csi2rx_dma_callback(void *param)
{
struct ti_csi2rx_buffer *buf = param;
@@ -735,21 +925,23 @@ static void ti_csi2rx_dma_callback(void *param)
struct ti_csi2rx_dma *dma = &ctx->dma;
unsigned long flags;
+ spin_lock_irqsave(&dma->lock, flags);
+
+ WARN_ON(!list_is_first(&buf->list, &dma->submitted));
+
/*
* TODO: Derive the sequence number from the CSI2RX frame number
* hardware monitor registers.
*/
buf->vb.vb2_buf.timestamp = ktime_get_ns();
buf->vb.sequence = ctx->sequence++;
-
- spin_lock_irqsave(&dma->lock, flags);
-
- WARN_ON(!list_is_first(&buf->list, &dma->submitted));
+ ctx->progress.cur = NULL;
if (dma->state == TI_CSI2RX_DMA_DRAINING) {
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
dma->state = TI_CSI2RX_DMA_ACTIVE;
} else {
+ ti_csi2rx_progress_done(ctx, buf);
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
}
@@ -790,6 +982,8 @@ static int ti_csi2rx_start_dma(struct ti_csi2rx_ctx *ctx,
if (ret)
return ret;
+ buf->cookie = cookie;
+
dma_async_issue_pending(ctx->dma.chan);
return 0;
@@ -1013,6 +1207,8 @@ static int ti_csi2rx_start_streaming(struct vb2_queue *vq, unsigned int count)
if (ret)
goto err_dma;
+ ti_csi2rx_progress_start(ctx);
+
return 0;
err_dma:
@@ -1033,6 +1229,8 @@ static void ti_csi2rx_stop_streaming(struct vb2_queue *vq)
struct ti_csi2rx_dev *csi = ctx->csi;
int ret;
+ ti_csi2rx_progress_stop(ctx);
+
video_device_pipeline_stop(&ctx->vdev);
ret = v4l2_subdev_disable_streams(&csi->subdev,
@@ -1297,6 +1495,8 @@ static void ti_csi2rx_cleanup_ctx(struct ti_csi2rx_ctx *ctx)
video_unregister_device(&ctx->vdev);
+ v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
+
mutex_destroy(&ctx->mutex);
}
@@ -1480,6 +1680,33 @@ static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi)
return ret;
}
+static int ti_csi2rx_init_ctrls(struct ti_csi2rx_ctx *ctx)
+{
+ struct v4l2_ctrl_handler *hdl = &ctx->ctrl_hdl;
+
+ v4l2_ctrl_handler_init(hdl, 2);
+
+ ctx->ctrl_progress_size = v4l2_ctrl_new_std(hdl, NULL,
+ V4L2_CID_BUF_PROGRESS_SIZE,
+ 0, MAX_HEIGHT_LINES, 1, 0);
+ ctx->ctrl_progress_interval =
+ v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_BUF_PROGRESS_INTERVAL,
+ TI_CSI2RX_PROGRESS_INTERVAL_MIN,
+ TI_CSI2RX_PROGRESS_INTERVAL_MAX, 1,
+ TI_CSI2RX_PROGRESS_INTERVAL_DEF);
+
+ if (hdl->error) {
+ int ret = hdl->error;
+
+ v4l2_ctrl_handler_free(hdl);
+ return ret;
+ }
+
+ ctx->vdev.ctrl_handler = hdl;
+
+ return 0;
+}
+
static int ti_csi2rx_init_ctx(struct ti_csi2rx_ctx *ctx)
{
struct ti_csi2rx_dev *csi = ctx->csi;
@@ -1526,11 +1753,17 @@ static int ti_csi2rx_init_ctx(struct ti_csi2rx_ctx *ctx)
INIT_LIST_HEAD(&ctx->dma.submitted);
spin_lock_init(&ctx->dma.lock);
ctx->dma.state = TI_CSI2RX_DMA_STOPPED;
+ hrtimer_setup(&ctx->progress.timer, ti_csi2rx_progress_timer,
+ CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
- ret = ti_csi2rx_init_dma(ctx);
+ ret = ti_csi2rx_init_ctrls(ctx);
if (ret)
return ret;
+ ret = ti_csi2rx_init_dma(ctx);
+ if (ret)
+ goto cleanup_ctrls;
+
ret = ti_csi2rx_init_vb2q(ctx);
if (ret)
goto cleanup_dma;
@@ -1539,6 +1772,8 @@ static int ti_csi2rx_init_ctx(struct ti_csi2rx_ctx *ctx)
cleanup_dma:
dma_release_channel(ctx->dma.chan);
+cleanup_ctrls:
+ v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
return ret;
}
@@ -1597,6 +1832,8 @@ static int ti_csi2rx_suspend(struct device *dev)
spin_unlock_irqrestore(&dma->lock, flags);
if (state != TI_CSI2RX_DMA_STOPPED) {
+ ti_csi2rx_progress_pause(ctx);
+
/* Disable source */
ret = v4l2_subdev_disable_streams(&csi->subdev,
TI_CSI2RX_PAD_FIRST_SOURCE + ctx->idx,
@@ -1643,6 +1880,8 @@ static int ti_csi2rx_resume(struct device *dev)
dma = &ctx->dma;
spin_lock_irqsave(&dma->lock, flags);
if (dma->state != TI_CSI2RX_DMA_STOPPED) {
+ ctx->progress.cur = NULL;
+
/* Re-submit all previously submitted buffers to DMA */
list_for_each_entry(buf, &ctx->dma.submitted, list) {
ti_csi2rx_start_dma(ctx, buf);
@@ -1657,6 +1896,8 @@ static int ti_csi2rx_resume(struct device *dev)
BIT(0));
if (ret)
dev_err(ctx->csi->dev, "Failed to start subdev\n");
+
+ ti_csi2rx_progress_resume(ctx);
} else {
spin_unlock_irqrestore(&dma->lock, flags);
}
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread