]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
media: bcm2835-unicam: Improve frame sequence count handling
authorNaushir Patuck <naush@raspberrypi.com>
Wed, 27 Nov 2024 11:15:12 +0000 (11:15 +0000)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 19 Dec 2024 11:50:18 +0000 (12:50 +0100)
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 <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/broadcom/bcm2835-unicam.c

index 3aed0e493c81f1aef1ac78bd20e1fd6f69d4bd6c..36fb186a042136b2d69166d6fd1020b80c303c6c 100644 (file)
@@ -199,6 +199,7 @@ struct unicam_device {
        /* subdevice async notifier */
        struct v4l2_async_notifier notifier;
        unsigned int sequence;
+       bool frame_started;
 
        /* Sensor node */
        struct {
@@ -742,6 +743,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
@@ -761,11 +764,24 @@ static irqreturn_t unicam_isr(int irq, void *dev)
                         * + FS + LS). In this case, we cannot signal the buffer
                         * as complete, as the HW will reuse that buffer.
                         */
-                       if (node->cur_frm && node->cur_frm != node->next_frm)
+                       if (node->cur_frm && node->cur_frm != node->next_frm) {
                                unicam_process_buffer_complete(node, sequence);
+                               inc_seq = true;
+                       }
                        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) {
@@ -795,6 +811,7 @@ static irqreturn_t unicam_isr(int irq, void *dev)
                }
 
                unicam_queue_event_sof(unicam);
+               unicam->frame_started = true;
        }
 
        /*
@@ -1413,6 +1430,7 @@ static int unicam_sd_enable_streams(struct v4l2_subdev *sd,
                if (unicam->pipe.nodes & BIT(UNICAM_METADATA_NODE))
                        unicam_start_metadata(unicam);
 
+               unicam->frame_started = false;
                unicam_start_rx(unicam, state);
        }