1 From 9c7ea3de5ffea4240e97deaa376265d82eaacac1 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 0384/1085] media: bcm2835-unicam: Correctly handle FS + FE ISR
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.
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.
15 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
17 .../media/platform/bcm2835/bcm2835-unicam.c | 28 +++++++++++++------
18 1 file changed, 20 insertions(+), 8 deletions(-)
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
25 for (i = 0; i < ARRAY_SIZE(unicam->node); i++) {
26 - if (!unicam->node[i].streaming)
27 + struct unicam_node *node = &unicam->node[i];
29 + if (!node->streaming)
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.
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],
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) {
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
51 + if (!node->cur_frm->vb.vb2_buf.timestamp) {
52 + unicam_dbg(2, unicam, "ISR: FE without FS, dropping frame\n");
56 + unicam_process_buffer_complete(node, sequence);
57 + node->cur_frm = node->next_frm;
58 + node->next_frm = NULL;
60 - unicam->node[i].cur_frm = unicam->node[i].next_frm;
61 + node->cur_frm = node->next_frm;