Skip to content

Commit c48f001

Browse files
naushirJacopo Mondi
authored and
Jacopo Mondi
committed
media: bcm2835-unicam: Correctly handle FS + FE ISR condtion
This change aligns the FS/FE interrupt handling with the Raspberry Pi kernel downstream Unicam driver. If we get a simultaneous FS + FE interrupt for the same frame, it cannot be marked as completed and returned to userland as the framebuffer will be refilled by Unicam on the next sensor frame. Additionally, the timestamp will be set to 0 as the FS interrupt handling code will not have run yet. To avoid these problems, the frame is considered dropped in the FE handler, and will be returned to userland on the subsequent sensor frame. Signed-off-by: Naushir Patuck <[email protected]>
1 parent ca95c84 commit c48f001

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

drivers/media/platform/broadcom/bcm2835-unicam.c

+35-5
Original file line numberDiff line numberDiff line change
@@ -777,10 +777,25 @@ static irqreturn_t unicam_isr(int irq, void *dev)
777777
* as complete, as the HW will reuse that buffer.
778778
*/
779779
if (node->cur_frm && node->cur_frm != node->next_frm) {
780+
/*
781+
* This condition checks if FE + FS for the same
782+
* frame has occurred. In such cases, we cannot
783+
* return out the frame, as no buffer handling
784+
* or timestamping has yet been done as part of
785+
* the FS handler.
786+
*/
787+
if (!node->cur_frm->vb.vb2_buf.timestamp) {
788+
dev_dbg(unicam->v4l2_dev.dev,
789+
"ISR: FE without FS, dropping frame\n");
790+
continue;
791+
}
792+
780793
unicam_process_buffer_complete(node, sequence);
794+
node->cur_frm = node->next_frm;
795+
node->next_frm = NULL;
781796
inc_seq = true;
782-
}
783-
node->cur_frm = node->next_frm;
797+
} else
798+
node->cur_frm = node->next_frm;
784799
}
785800

786801
/*
@@ -820,10 +835,25 @@ static irqreturn_t unicam_isr(int irq, void *dev)
820835
i);
821836
/*
822837
* Set the next frame output to go to a dummy frame
823-
* if we have not managed to obtain another frame
824-
* from the queue.
838+
* if no buffer currently queued.
825839
*/
826-
unicam_schedule_dummy_buffer(node);
840+
if (!node->next_frm ||
841+
node->next_frm == node->cur_frm) {
842+
unicam_schedule_dummy_buffer(node);
843+
} else if (unicam->node[i].cur_frm) {
844+
/*
845+
* Repeated FS without FE. Hardware will have
846+
* swapped buffers, but the cur_frm doesn't
847+
* contain valid data. Return cur_frm to the
848+
* queue.
849+
*/
850+
spin_lock(&node->dma_queue_lock);
851+
list_add_tail(&node->cur_frm->list,
852+
&node->dma_queue);
853+
spin_unlock(&node->dma_queue_lock);
854+
node->cur_frm = node->next_frm;
855+
node->next_frm = NULL;
856+
}
827857
}
828858

829859
unicam_queue_event_sof(unicam);

0 commit comments

Comments
 (0)