From: Naushir Patuck Date: Fri, 16 Jun 2023 15:24:19 +0000 (+0100) Subject: drivers: media: bcm2835_unicam: Improve frame sequence count handling X-Git-Tag: accepted/tizen/unified/20240422.153132~504 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48d92ac4a50b9f9cd6ec6c125ae3997d1e7eb6da;p=platform%2Fkernel%2Flinux-rpi.git drivers: media: bcm2835_unicam: Improve frame sequence count handling Ensure that the frame sequence counter is incremented only if a previous frame start interrupt has occurred, or a frame start + frame end has occurred simultaneously. This corresponds the sequence number with the actual number of frames produced by the sensor, not the number of frame buffers dequeued back to userland. Signed-off-by: Naushir Patuck --- diff --git a/drivers/media/platform/bcm2835/bcm2835-unicam.c b/drivers/media/platform/bcm2835/bcm2835-unicam.c index 1988777..2fe28172 100644 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c @@ -548,6 +548,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; @@ -940,6 +941,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 @@ -975,11 +978,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) { @@ -1022,6 +1037,7 @@ static irqreturn_t unicam_isr(int irq, void *dev) } unicam_queue_event_sof(unicam); + unicam->frame_started = true; } /* @@ -2626,6 +2642,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);