Re: [PATCH v2] media: atomisp: flatten pre_power_down logic and clean up staging code

From: Andy Shevchenko

Date: Sun Jul 05 2026 - 02:47:24 EST


On Sun, Jul 05, 2026 at 12:08:54AM +0500, Ruziev Miraly wrote:
> Refactor atomisp_mrfld_pre_power_down() by removing the redundant
> nested 'else' block, making the function structure linear and easier
> to follow.

I don't see this. There is no 'else' removal, what did I miss?

> Keep both error logging branches intact to ensure consistency
> in hardware failure reporting.
>
> In addition, fix minor checkpatch.pl style warnings in the same file
> regarding code alignment and hanging open parentheses.

These are a few things that probably need to be split to different patches.

...

> struct pci_dev *pdev = to_pci_dev(isp->dev);
> u32 irq;
> unsigned long flags;
> + int ret = 0;

Don't do like this. It makes code harder to maintain and prone to mistakes.

> spin_lock_irqsave(&isp->lock, flags);
>
> /*
> * MRFLD HAS requirement: cannot power off i-unit if
> * ISP has IRQ not serviced.
> - * So, here we need to check if there is any pending
> - * IRQ, if so, waiting for it to be served
> + * Wait for pending IRQs to be served.
> */

Hmm... Why is this wording changed?

> pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
> if (!(irq & BIT(INTR_IIR)))
> - goto done;
> + goto power_down;
>
> + /* Clear and check interrupt status registers */
> atomisp_css2_hw_store_32(MRFLD_INTR_CLEAR_REG, 0xFFFFFFFF);
> atomisp_load_uint32(MRFLD_INTR_STATUS_REG, &irq);
> +
> if (irq != 0) {
> dev_err(isp->dev,
> "%s: fail to clear isp interrupt status reg=0x%x\n",
> __func__, irq);
> - spin_unlock_irqrestore(&isp->lock, flags);
> - return -EAGAIN;
> + ret = -EAGAIN;
> + goto unlock_exit;
> }
> +
> pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
> irq &= BIT(INTR_IIR);
> pci_write_config_dword(pdev, PCI_INTERRUPT_CTRL, irq);
>
> pci_read_config_dword(pdev, PCI_INTERRUPT_CTRL, &irq);
> - if (!(irq & BIT(INTR_IIR))) {
> - atomisp_css2_hw_store_32(MRFLD_INTR_ENABLE_REG, 0x0);
> - goto done;
> + if (irq & BIT(INTR_IIR)) {
> + dev_err(isp->dev,
> + "%s: error in iunit interrupt. status reg=0x%x\n",
> + __func__, irq);
> + ret = -EAGAIN;
> + goto unlock_exit;
> }
> - spin_unlock_irqrestore(&isp->lock, flags);
> - return -EAGAIN;
> -done:
> +
> + atomisp_css2_hw_store_32(MRFLD_INTR_ENABLE_REG, 0x0);
> +
> +power_down:
> /*
> * MRFLD WORKAROUND:
> * before powering off IUNIT, clear the pending interrupts
> @@ -490,9 +497,10 @@ static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp)
>
> atomisp_msi_irq_uninit(isp);
> atomisp_freq_scaling(isp, ATOMISP_DFS_MODE_LOW, true);
> - spin_unlock_irqrestore(&isp->lock, flags);
>
> - return 0;
> +unlock_exit:
> + spin_unlock_irqrestore(&isp->lock, flags);
> + return ret;
> }

Are you sending an update on top of your v1?! You must use the same base for
the each version of the patches. The incremental changes in Git means something
different.

...

> @@ -839,7 +847,7 @@ static int atomisp_register_entities(struct atomisp_device *isp)
> /* Register internal entities */
> for (i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++) {
> ret = atomisp_mipi_csi2_register_entities(&isp->csi2_port[i],
> - &isp->v4l2_dev);
> + &isp->v4l2_dev);
> if (ret == 0)
> continue;

This change is not related. Split it.

...

> @@ -847,8 +855,7 @@ static int atomisp_register_entities(struct atomisp_device *isp)
> dev_err(isp->dev, "failed to register the CSI port: %d\n", i);
> /* deregister all registered CSI ports */
> while (i--)
> - atomisp_mipi_csi2_unregister_entities(
> - &isp->csi2_port[i]);
> + atomisp_mipi_csi2_unregister_entities(&isp->csi2_port[i]);
>
> goto csi_and_subdev_probe_failed;
> }

As previous, should be in another patch.

--
With Best Regards,
Andy Shevchenko