efec3af2a1a76a4e6ea9eedacefcf6eae183b4ab
[openwrt/staging/neocturne.git] /
1 From 1ecf9ebf26821996ae3344765e1b770d7bc4bfc2 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Mon, 8 Aug 2022 10:01:41 +0100
4 Subject: [PATCH] media: bcm2835-unicam: Correctly handle FS + FE ISR
5 condtion
6
7 If we get a simultaneous FS + FE interrupt for the same frame, it cannot be
8 marked as completed and returned to userland as the framebuffer will be refilled
9 by Unicam on the next sensor frame. Additionally, the timestamp will be set to 0
10 as the FS interrupt handling code will not have run yet.
11
12 To avoid these problems, the frame is considered dropped in the FE handler,
13 and will be returned to userland on the subsequent sensor frame.
14
15 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
16 ---
17 .../media/platform/bcm2835/bcm2835-unicam.c | 28 +++++++++++++------
18 1 file changed, 20 insertions(+), 8 deletions(-)
19
20 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
21 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
22 @@ -919,7 +919,9 @@ static irqreturn_t unicam_isr(int irq, v
23 * to use.
24 */
25 for (i = 0; i < ARRAY_SIZE(unicam->node); i++) {
26 - if (!unicam->node[i].streaming)
27 + struct unicam_node *node = &unicam->node[i];
28 +
29 + if (!node->streaming)
30 continue;
31
32 /*
33 @@ -929,14 +931,24 @@ static irqreturn_t unicam_isr(int irq, v
34 * + FS + LS). In this case, we cannot signal the buffer
35 * as complete, as the HW will reuse that buffer.
36 */
37 - if (unicam->node[i].cur_frm &&
38 - unicam->node[i].cur_frm != unicam->node[i].next_frm) {
39 - unicam_process_buffer_complete(&unicam->node[i],
40 - sequence);
41 - unicam->node[i].cur_frm = unicam->node[i].next_frm;
42 - unicam->node[i].next_frm = NULL;
43 + if (node->cur_frm && node->cur_frm != node->next_frm) {
44 + /*
45 + * This condition checks if FE + FS for the same
46 + * frame has occurred. In such cases, we cannot
47 + * return out the frame, as no buffer handling
48 + * or timestamping has yet been done as part of
49 + * the FS handler.
50 + */
51 + if (!node->cur_frm->vb.vb2_buf.timestamp) {
52 + unicam_dbg(2, unicam, "ISR: FE without FS, dropping frame\n");
53 + continue;
54 + }
55 +
56 + unicam_process_buffer_complete(node, sequence);
57 + node->cur_frm = node->next_frm;
58 + node->next_frm = NULL;
59 } else {
60 - unicam->node[i].cur_frm = unicam->node[i].next_frm;
61 + node->cur_frm = node->next_frm;
62 }
63 }
64 unicam->sequence++;