Skip to content

Commit

Permalink
media: bcm2835-unicam: Correctly handle FS + FE ISR condtion
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
naushir authored and Jacopo Mondi committed Nov 21, 2024
1 parent ca95c84 commit c48f001
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions drivers/media/platform/broadcom/bcm2835-unicam.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,25 @@ static irqreturn_t unicam_isr(int irq, void *dev)
* as complete, as the HW will reuse that buffer.
*/
if (node->cur_frm && node->cur_frm != node->next_frm) {
/*
* This condition checks if FE + FS for the same
* frame has occurred. In such cases, we cannot
* return out the frame, as no buffer handling
* or timestamping has yet been done as part of
* the FS handler.
*/
if (!node->cur_frm->vb.vb2_buf.timestamp) {
dev_dbg(unicam->v4l2_dev.dev,
"ISR: FE without FS, dropping frame\n");
continue;
}

unicam_process_buffer_complete(node, sequence);
node->cur_frm = node->next_frm;
node->next_frm = NULL;
inc_seq = true;
}
node->cur_frm = node->next_frm;
} else
node->cur_frm = node->next_frm;
}

/*
Expand Down Expand Up @@ -820,10 +835,25 @@ static irqreturn_t unicam_isr(int irq, void *dev)
i);
/*
* Set the next frame output to go to a dummy frame
* if we have not managed to obtain another frame
* from the queue.
* if no buffer currently queued.
*/
unicam_schedule_dummy_buffer(node);
if (!node->next_frm ||
node->next_frm == node->cur_frm) {
unicam_schedule_dummy_buffer(node);
} else if (unicam->node[i].cur_frm) {
/*
* Repeated FS without FE. Hardware will have
* swapped buffers, but the cur_frm doesn't
* contain valid data. Return cur_frm to the
* queue.
*/
spin_lock(&node->dma_queue_lock);
list_add_tail(&node->cur_frm->list,
&node->dma_queue);
spin_unlock(&node->dma_queue_lock);
node->cur_frm = node->next_frm;
node->next_frm = NULL;
}
}

unicam_queue_event_sof(unicam);
Expand Down

0 comments on commit c48f001

Please sign in to comment.