On Fri Jul 4 11:20:30 2025 +0200, Hans de Goede wrote:
> Move atomisp_stop_streaming() above atomisp_start_streaming(), this is
> a preparation patch for making atomisp_start_streaming() properly cleanup
> if starting the sensor stream fails.
> 
> No functional change, only moving a block of code up.
> 
> Signed-off-by: Hans de Goede <ha...@kernel.org>
> Reviewed-by: Andy Shevchenko <a...@kernel.org>
> Link: https://lore.kernel.org/r/20250505210008.152659-2-hdego...@redhat.com
> Signed-off-by: Mauro Carvalho Chehab <mchehab+hua...@kernel.org>

Patch committed.

Thanks,
Mauro Carvalho Chehab

 drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 148 +++++++++++-----------
 1 file changed, 74 insertions(+), 74 deletions(-)

---

diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c 
b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index 97d99bed1560..705f104a2147 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -856,6 +856,80 @@ static void atomisp_dma_burst_len_cfg(struct 
atomisp_sub_device *asd)
                atomisp_css2_hw_store_32(DMA_BURST_SIZE_REG, 0x00);
 }
 
+void atomisp_stop_streaming(struct vb2_queue *vq)
+{
+       struct atomisp_video_pipe *pipe = vq_to_pipe(vq);
+       struct atomisp_sub_device *asd = pipe->asd;
+       struct atomisp_device *isp = asd->isp;
+       struct pci_dev *pdev = to_pci_dev(isp->dev);
+       unsigned long flags;
+       int ret;
+
+       dev_dbg(isp->dev, "Stop stream\n");
+
+       mutex_lock(&isp->mutex);
+       /*
+        * There is no guarantee that the buffers queued to / owned by the ISP
+        * will properly be returned to the queue when stopping. Set a flag to
+        * avoid new buffers getting queued and then wait for all the current
+        * buffers to finish.
+        */
+       pipe->stopping = true;
+       mutex_unlock(&isp->mutex);
+       /* wait max 1 second */
+       ret = wait_event_timeout(pipe->vb_queue.done_wq,
+                                atomisp_buffers_in_css(pipe) == 0, HZ);
+       mutex_lock(&isp->mutex);
+       pipe->stopping = false;
+       if (ret == 0)
+               dev_warn(isp->dev, "Warning timeout waiting for CSS to return 
buffers\n");
+
+       spin_lock_irqsave(&isp->lock, flags);
+       asd->streaming = false;
+       spin_unlock_irqrestore(&isp->lock, flags);
+
+       atomisp_clear_css_buffer_counters(asd);
+       atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF, false);
+
+       atomisp_css_stop(asd, false);
+
+       atomisp_flush_video_pipe(pipe, VB2_BUF_STATE_ERROR, true);
+
+       atomisp_subdev_cleanup_pending_events(asd);
+
+       ret = v4l2_subdev_call(isp->inputs[asd->input_curr].csi_remote_source,
+                              video, s_stream, 0);
+       if (ret)
+               dev_warn(isp->dev, "Stopping sensor stream failed: %d\n", ret);
+
+       /* Disable the CSI interface on ANN B0/K0 */
+       if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
+                                           ATOMISP_HW_REVISION_SHIFT) | 
ATOMISP_HW_STEPPING_B0)) {
+               pci_write_config_word(pdev, MRFLD_PCI_CSI_CONTROL,
+                                     isp->saved_regs.csi_control & 
~MRFLD_PCI_CSI_CONTROL_CSI_READY);
+       }
+
+       if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_LOW, false))
+               dev_warn(isp->dev, "DFS failed.\n");
+
+       /*
+        * ISP work around, need to reset ISP to allow next stream on to work.
+        * Streams have already been destroyed by atomisp_css_stop().
+        * Disable PUNIT/ISP acknowledge/handshake - SRSE=3 and then reset.
+        */
+       pci_write_config_dword(pdev, PCI_I_CONTROL,
+                              isp->saved_regs.i_control | 
MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK);
+       atomisp_reset(isp);
+
+       /* Streams were destroyed by atomisp_css_stop(), recreate them. */
+       ret = atomisp_create_pipes_stream(&isp->asd);
+       if (ret)
+               dev_warn(isp->dev, "Recreating streams failed: %d\n", ret);
+
+       media_pipeline_stop(&asd->video_out.vdev.entity.pads[0]);
+       mutex_unlock(&isp->mutex);
+}
+
 int atomisp_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
        struct atomisp_video_pipe *pipe = vq_to_pipe(vq);
@@ -961,80 +1035,6 @@ out_unlock:
        return ret;
 }
 
-void atomisp_stop_streaming(struct vb2_queue *vq)
-{
-       struct atomisp_video_pipe *pipe = vq_to_pipe(vq);
-       struct atomisp_sub_device *asd = pipe->asd;
-       struct atomisp_device *isp = asd->isp;
-       struct pci_dev *pdev = to_pci_dev(isp->dev);
-       unsigned long flags;
-       int ret;
-
-       dev_dbg(isp->dev, "Stop stream\n");
-
-       mutex_lock(&isp->mutex);
-       /*
-        * There is no guarantee that the buffers queued to / owned by the ISP
-        * will properly be returned to the queue when stopping. Set a flag to
-        * avoid new buffers getting queued and then wait for all the current
-        * buffers to finish.
-        */
-       pipe->stopping = true;
-       mutex_unlock(&isp->mutex);
-       /* wait max 1 second */
-       ret = wait_event_timeout(pipe->vb_queue.done_wq,
-                                atomisp_buffers_in_css(pipe) == 0, HZ);
-       mutex_lock(&isp->mutex);
-       pipe->stopping = false;
-       if (ret == 0)
-               dev_warn(isp->dev, "Warning timeout waiting for CSS to return 
buffers\n");
-
-       spin_lock_irqsave(&isp->lock, flags);
-       asd->streaming = false;
-       spin_unlock_irqrestore(&isp->lock, flags);
-
-       atomisp_clear_css_buffer_counters(asd);
-       atomisp_css_irq_enable(isp, IA_CSS_IRQ_INFO_CSS_RECEIVER_SOF, false);
-
-       atomisp_css_stop(asd, false);
-
-       atomisp_flush_video_pipe(pipe, VB2_BUF_STATE_ERROR, true);
-
-       atomisp_subdev_cleanup_pending_events(asd);
-
-       ret = v4l2_subdev_call(isp->inputs[asd->input_curr].csi_remote_source,
-                              video, s_stream, 0);
-       if (ret)
-               dev_warn(isp->dev, "Stopping sensor stream failed: %d\n", ret);
-
-       /* Disable the CSI interface on ANN B0/K0 */
-       if (isp->media_dev.hw_revision >= ((ATOMISP_HW_REVISION_ISP2401 <<
-                                           ATOMISP_HW_REVISION_SHIFT) | 
ATOMISP_HW_STEPPING_B0)) {
-               pci_write_config_word(pdev, MRFLD_PCI_CSI_CONTROL,
-                                     isp->saved_regs.csi_control & 
~MRFLD_PCI_CSI_CONTROL_CSI_READY);
-       }
-
-       if (atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_LOW, false))
-               dev_warn(isp->dev, "DFS failed.\n");
-
-       /*
-        * ISP work around, need to reset ISP to allow next stream on to work.
-        * Streams have already been destroyed by atomisp_css_stop().
-        * Disable PUNIT/ISP acknowledge/handshake - SRSE=3 and then reset.
-        */
-       pci_write_config_dword(pdev, PCI_I_CONTROL,
-                              isp->saved_regs.i_control | 
MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK);
-       atomisp_reset(isp);
-
-       /* Streams were destroyed by atomisp_css_stop(), recreate them. */
-       ret = atomisp_create_pipes_stream(&isp->asd);
-       if (ret)
-               dev_warn(isp->dev, "Recreating streams failed: %d\n", ret);
-
-       media_pipeline_stop(&asd->video_out.vdev.entity.pads[0]);
-       mutex_unlock(&isp->mutex);
-}
-
 /*
  * To get the current value of a control.
  * applications initialize the id field of a struct v4l2_control and

Reply via email to