1 From 6ef818eed60db70e9caf6bdf74cc1f9943994226 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Fri, 16 Jun 2023 16:24:19 +0100
4 Subject: [PATCH] drivers: media: bcm2835_unicam: Improve frame sequence count
7 Ensure that the frame sequence counter is incremented only if a previous
8 frame start interrupt has occurred, or a frame start + frame end has
9 occurred simultaneously.
11 This corresponds the sequence number with the actual number of frames
12 produced by the sensor, not the number of frame buffers dequeued back
15 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
17 .../media/platform/bcm2835/bcm2835-unicam.c | 19 ++++++++++++++++++-
18 1 file changed, 18 insertions(+), 1 deletion(-)
20 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
21 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
22 @@ -522,6 +522,7 @@ struct unicam_device {
23 /* subdevice async Notifier */
24 struct v4l2_async_notifier notifier;
25 unsigned int sequence;
28 /* ptr to sub device */
29 struct v4l2_subdev *sensor;
30 @@ -914,6 +915,8 @@ static irqreturn_t unicam_isr(int irq, v
34 + bool inc_seq = unicam->frame_started;
37 * Ensure we have swapped buffers already as we can't
38 * stop the peripheral. If no buffer is available, use a
39 @@ -949,11 +952,23 @@ static irqreturn_t unicam_isr(int irq, v
40 unicam_process_buffer_complete(node, sequence);
41 node->cur_frm = node->next_frm;
42 node->next_frm = NULL;
45 node->cur_frm = node->next_frm;
51 + * Increment the sequence number conditionally on either a FS
52 + * having already occurred, or in the FE + FS condition as
53 + * caught in the FE handler above. This ensures the sequence
54 + * number corresponds to the frames generated by the sensor, not
55 + * the frames dequeued to userland.
59 + unicam->frame_started = false;
63 if (ista & UNICAM_FSI) {
64 @@ -996,6 +1011,7 @@ static irqreturn_t unicam_isr(int irq, v
67 unicam_queue_event_sof(unicam);
68 + unicam->frame_started = true;
72 @@ -2600,6 +2616,7 @@ static int unicam_start_streaming(struct
73 vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
76 + dev->frame_started = false;
77 unicam_start_rx(dev, buffer_addr);
79 ret = v4l2_subdev_call(dev->sensor, video, s_stream, 1);