Skip to content

drivers: media: bcm2835_unicam: Improve frame sequence count handling #5507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion drivers/media/platform/bcm2835/bcm2835-unicam.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ struct unicam_device {
/* subdevice async Notifier */
struct v4l2_async_notifier notifier;
unsigned int sequence;
bool frame_started;

/* ptr to sub device */
struct v4l2_subdev *sensor;
Expand Down Expand Up @@ -914,6 +915,8 @@ static irqreturn_t unicam_isr(int irq, void *dev)
* buffer forever.
*/
if (fe) {
bool inc_seq = unicam->frame_started;

/*
* Ensure we have swapped buffers already as we can't
* stop the peripheral. If no buffer is available, use a
Expand Down Expand Up @@ -949,11 +952,23 @@ static irqreturn_t unicam_isr(int irq, void *dev)
unicam_process_buffer_complete(node, sequence);
node->cur_frm = node->next_frm;
node->next_frm = NULL;
inc_seq = true;
} else {
node->cur_frm = node->next_frm;
}
}
unicam->sequence++;

/*
* Increment the sequence number conditionally on either a FS
* having already occurred, or in the FE + FS condition as
* caught in the FE handler above. This ensures the sequence
* number corresponds to the frames generated by the sensor, not
* the frames dequeued to userland.
*/
if (inc_seq) {
unicam->sequence++;
unicam->frame_started = false;
}
}

if (ista & UNICAM_FSI) {
Expand Down Expand Up @@ -996,6 +1011,7 @@ static irqreturn_t unicam_isr(int irq, void *dev)
}

unicam_queue_event_sof(unicam);
unicam->frame_started = true;
}

/*
Expand Down Expand Up @@ -2600,6 +2616,7 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
}

dev->frame_started = false;
unicam_start_rx(dev, buffer_addr);

ret = v4l2_subdev_call(dev->sensor, video, s_stream, 1);
Expand Down