6de340c2a9cca9824c5d3d950d4d95758a066f91
[openwrt/staging/xback.git] /
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
5 handling
6
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.
10
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
13 to userland.
14
15 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
16 ---
17 .../media/platform/bcm2835/bcm2835-unicam.c | 19 ++++++++++++++++++-
18 1 file changed, 18 insertions(+), 1 deletion(-)
19
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;
26 + bool frame_started;
27
28 /* ptr to sub device */
29 struct v4l2_subdev *sensor;
30 @@ -914,6 +915,8 @@ static irqreturn_t unicam_isr(int irq, v
31 * buffer forever.
32 */
33 if (fe) {
34 + bool inc_seq = unicam->frame_started;
35 +
36 /*
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;
43 + inc_seq = true;
44 } else {
45 node->cur_frm = node->next_frm;
46 }
47 }
48 - unicam->sequence++;
49 +
50 + /*
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.
56 + */
57 + if (inc_seq) {
58 + unicam->sequence++;
59 + unicam->frame_started = false;
60 + }
61 }
62
63 if (ista & UNICAM_FSI) {
64 @@ -996,6 +1011,7 @@ static irqreturn_t unicam_isr(int irq, v
65 }
66
67 unicam_queue_event_sof(unicam);
68 + unicam->frame_started = true;
69 }
70
71 /*
72 @@ -2600,6 +2616,7 @@ static int unicam_start_streaming(struct
73 vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
74 }
75
76 + dev->frame_started = false;
77 unicam_start_rx(dev, buffer_addr);
78
79 ret = v4l2_subdev_call(dev->sensor, video, s_stream, 1);