public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Tsuchiya Yuto <kitakar@gmail.com>,
	Andy Shevchenko <andy@kernel.org>,
	Yury Luneff <yury.lunev@gmail.com>,
	Nable <nable.maininbox@googlemail.com>,
	andrey.i.trufanov@gmail.com, Fabio Aiuto <fabioaiuto83@gmail.com>,
	linux-media@vger.kernel.org, linux-staging@lists.linux.dev
Subject: [PATCH 15/20] media: atomisp: Remove sw_contex.power_state checks
Date: Sun, 20 Nov 2022 23:40:56 +0100	[thread overview]
Message-ID: <20221120224101.746199-16-hdegoede@redhat.com> (raw)
In-Reply-To: <20221120224101.746199-1-hdegoede@redhat.com>

Remove the unnecessary sw_contex.power_state checks:

1. atomisp_freq_scaling() and atomisp_stop_streaming() only run when the
   ISP is powered up through runtime-pm, so the checkes are not necessary

2. atomisp_mrfld_pre_power_down() and atomisp_runtime_resume() are only
   called through the driver-core pm handling code which already
   guarantees they are not called when already powered down / up.

3. atomisp_isr() also checks isp->css_initialized which only gets set
   by atomisp_css_init() which runs *after* powering up the ISP and
   which gets cleared by atomisp_css_uninit() *before* before powering
   down the ISP.

So all the checks are unnecessary, remove them as well as the
sw_contex.power_state field itself.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../staging/media/atomisp/pci/atomisp_cmd.c   | 20 +----
 .../media/atomisp/pci/atomisp_internal.h      |  1 -
 .../staging/media/atomisp/pci/atomisp_ioctl.c | 75 +++++++++----------
 .../staging/media/atomisp/pci/atomisp_v4l2.c  | 19 ++---
 4 files changed, 43 insertions(+), 72 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
index e80038e46e0e..475ba82b858b 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
@@ -207,11 +207,6 @@ int atomisp_freq_scaling(struct atomisp_device *isp,
 	int i, ret;
 	unsigned short fps = 0;
 
-	if (isp->sw_contex.power_state != ATOM_ISP_POWER_UP) {
-		dev_err(isp->dev, "DFS cannot proceed due to no power.\n");
-		return -EINVAL;
-	}
-
 	if ((pdev->device & ATOMISP_PCI_DEVICE_SOC_MASK) ==
 	    ATOMISP_PCI_DEVICE_SOC_CHT && ATOMISP_USE_YUVPP(asd))
 		isp->dfs = &dfs_config_cht_soc;
@@ -511,8 +506,8 @@ irqreturn_t atomisp_isr(int irq, void *dev)
 	int err;
 
 	spin_lock_irqsave(&isp->lock, flags);
-	if (isp->sw_contex.power_state != ATOM_ISP_POWER_UP ||
-	    !isp->css_initialized) {
+
+	if (!isp->css_initialized) {
 		spin_unlock_irqrestore(&isp->lock, flags);
 		return IRQ_HANDLED;
 	}
@@ -5503,7 +5498,6 @@ int atomisp_set_shading_table(struct atomisp_sub_device *asd,
 int atomisp_ospm_dphy_down(struct atomisp_device *isp)
 {
 	struct pci_dev *pdev = to_pci_dev(isp->dev);
-	unsigned long flags;
 	u32 reg;
 
 	dev_dbg(isp->dev, "%s\n", __func__);
@@ -5515,9 +5509,6 @@ int atomisp_ospm_dphy_down(struct atomisp_device *isp)
 	if (!atomisp_dev_users(isp))
 		goto done;
 
-	spin_lock_irqsave(&isp->lock, flags);
-	isp->sw_contex.power_state = ATOM_ISP_POWER_DOWN;
-	spin_unlock_irqrestore(&isp->lock, flags);
 done:
 	/*
 	 * MRFLD IUNIT DPHY is located in an always-power-on island
@@ -5533,14 +5524,7 @@ int atomisp_ospm_dphy_down(struct atomisp_device *isp)
 /*Turn on ISP dphy */
 int atomisp_ospm_dphy_up(struct atomisp_device *isp)
 {
-	unsigned long flags;
-
 	dev_dbg(isp->dev, "%s\n", __func__);
-
-	spin_lock_irqsave(&isp->lock, flags);
-	isp->sw_contex.power_state = ATOM_ISP_POWER_UP;
-	spin_unlock_irqrestore(&isp->lock, flags);
-
 	return 0;
 }
 
diff --git a/drivers/staging/media/atomisp/pci/atomisp_internal.h b/drivers/staging/media/atomisp/pci/atomisp_internal.h
index d9d158cdf09e..653e6d74a966 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_internal.h
+++ b/drivers/staging/media/atomisp/pci/atomisp_internal.h
@@ -195,7 +195,6 @@ struct atomisp_regs {
 };
 
 struct atomisp_sw_contex {
-	int power_state;
 	int running_freq;
 };
 
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index 43e899457b91..cb01ba65c88f 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -1461,10 +1461,11 @@ void atomisp_stop_streaming(struct vb2_queue *vq)
 	struct video_device *vdev = &pipe->vdev;
 	struct atomisp_device *isp = asd->isp;
 	struct pci_dev *pdev = to_pci_dev(isp->dev);
+	bool recreate_streams[MAX_STREAM_NUM] = {0};
 	enum ia_css_pipe_id css_pipe_id;
-	int ret;
-	unsigned long flags;
 	bool first_streamoff = false;
+	unsigned long flags;
+	int i, ret;
 
 	mutex_lock(&isp->mutex);
 
@@ -1563,49 +1564,43 @@ void atomisp_stop_streaming(struct vb2_queue *vq)
 	 * ISP work around, need to reset isp
 	 * Is it correct time to reset ISP when first node does streamoff?
 	 */
-	if (isp->sw_contex.power_state == ATOM_ISP_POWER_UP) {
-		unsigned int i;
-		bool recreate_streams[MAX_STREAM_NUM] = {0};
-
-		if (isp->isp_timeout)
-			dev_err(isp->dev, "%s: Resetting with WA activated",
-				__func__);
-		/*
-		 * It is possible that the other asd stream is in the stage
-		 * that v4l2_setfmt is just get called on it, which will
-		 * create css stream on that stream. But at this point, there
-		 * is no way to destroy the css stream created on that stream.
-		 *
-		 * So force stream destroy here.
-		 */
-		for (i = 0; i < isp->num_of_streams; i++) {
-			if (isp->asd[i].stream_prepared) {
-				atomisp_destroy_pipes_stream_force(&isp->
-								   asd[i]);
-				recreate_streams[i] = true;
-			}
+	if (isp->isp_timeout)
+		dev_err(isp->dev, "%s: Resetting with WA activated",
+			__func__);
+	/*
+	 * It is possible that the other asd stream is in the stage
+	 * that v4l2_setfmt is just get called on it, which will
+	 * create css stream on that stream. But at this point, there
+	 * is no way to destroy the css stream created on that stream.
+	 *
+	 * So force stream destroy here.
+	 */
+	for (i = 0; i < isp->num_of_streams; i++) {
+		if (isp->asd[i].stream_prepared) {
+			atomisp_destroy_pipes_stream_force(&isp->asd[i]);
+			recreate_streams[i] = true;
 		}
+	}
 
-		/* disable  PUNIT/ISP acknowlede/handshake - SRSE=3 */
-		pci_write_config_dword(pdev, PCI_I_CONTROL,
-				       isp->saved_regs.i_control | MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK);
-		dev_err(isp->dev, "atomisp_reset");
-		atomisp_reset(isp);
-		for (i = 0; i < isp->num_of_streams; i++) {
-			if (recreate_streams[i]) {
-				int ret2;
-
-				ret2 = atomisp_create_pipes_stream(&isp->asd[i]);
-				if (ret2) {
-					dev_err(isp->dev, "%s error re-creating streams: %d\n",
-						__func__, ret2);
-					if (!ret)
-						ret = ret2;
-				}
+	/* disable  PUNIT/ISP acknowlede/handshake - SRSE=3 */
+	pci_write_config_dword(pdev, PCI_I_CONTROL,
+			       isp->saved_regs.i_control | MRFLD_PCI_I_CONTROL_SRSE_RESET_MASK);
+	dev_err(isp->dev, "atomisp_reset");
+	atomisp_reset(isp);
+	for (i = 0; i < isp->num_of_streams; i++) {
+		if (recreate_streams[i]) {
+			int ret2;
+
+			ret2 = atomisp_create_pipes_stream(&isp->asd[i]);
+			if (ret2) {
+				dev_err(isp->dev, "%s error re-creating streams: %d\n",
+					__func__, ret2);
+				if (!ret)
+					ret = ret2;
 			}
 		}
-		isp->isp_timeout = false;
 	}
+	isp->isp_timeout = false;
 out_unlock:
 	mutex_unlock(&isp->mutex);
 }
diff --git a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c
index f009a1bfd3ea..579cbf502fd1 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_v4l2.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_v4l2.c
@@ -573,11 +573,7 @@ static int atomisp_mrfld_pre_power_down(struct atomisp_device *isp)
 	unsigned long flags;
 
 	spin_lock_irqsave(&isp->lock, flags);
-	if (isp->sw_contex.power_state == ATOM_ISP_POWER_DOWN) {
-		spin_unlock_irqrestore(&isp->lock, flags);
-		dev_dbg(isp->dev, "<%s %d.\n", __func__, __LINE__);
-		return 0;
-	}
+
 	/*
 	 * MRFLD HAS requirement: cannot power off i-unit if
 	 * ISP has IRQ not serviced.
@@ -753,13 +749,11 @@ int atomisp_runtime_resume(struct device *dev)
 		return ret;
 
 	cpu_latency_qos_update_request(&isp->pm_qos, isp->max_isr_latency);
-	if (isp->sw_contex.power_state == ATOM_ISP_POWER_DOWN) {
-		/*Turn on ISP d-phy */
-		ret = atomisp_ospm_dphy_up(isp);
-		if (ret) {
-			dev_err(isp->dev, "Failed to power up ISP!.\n");
-			return -EINVAL;
-		}
+	/*Turn on ISP d-phy */
+	ret = atomisp_ospm_dphy_up(isp);
+	if (ret) {
+		dev_err(isp->dev, "Failed to power up ISP!.\n");
+		return -EINVAL;
 	}
 
 	/*restore register values for iUnit and iUnitPHY registers*/
@@ -1447,7 +1441,6 @@ static int atomisp_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
 
 	isp->dev = &pdev->dev;
 	isp->base = pcim_iomap_table(pdev)[ATOM_ISP_PCI_BAR];
-	isp->sw_contex.power_state = ATOM_ISP_POWER_UP;
 	isp->saved_regs.ispmmadr = start;
 
 	dev_dbg(&pdev->dev, "atomisp mmio base: %p\n", isp->base);
-- 
2.38.1


  parent reply	other threads:[~2022-11-20 22:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-20 22:40 [PATCH 00/20] media: atomisp: Misc. cleanups / fixes Hans de Goede
2022-11-20 22:40 ` [PATCH 01/20] media: atomisp: Silence: 'atomisp_q_one_s3a_buffer: drop one s3a stat which has exp_id xx' log messages Hans de Goede
2022-11-21  8:54   ` Andy Shevchenko
2022-11-21 12:27     ` Hans de Goede
2022-11-20 22:40 ` [PATCH 02/20] media: atomisp: Remove accelerator pipe creation code Hans de Goede
2022-11-20 22:40 ` [PATCH 03/20] media: atomisp: Remove unused QOS defines / structure member Hans de Goede
2022-11-20 22:40 ` [PATCH 04/20] media: atomisp: Flush queue on atomisp_css_start() error Hans de Goede
2022-11-20 22:40 ` [PATCH 05/20] media: atomisp: Log an error on failing to alloc private-mem Hans de Goede
2022-11-21  8:58   ` Andy Shevchenko
2022-11-21 12:29     ` Hans de Goede
2022-11-20 22:40 ` [PATCH 06/20] media: atomisp: Fix deadlock when the /dev/video# node is closed while still streaming Hans de Goede
2022-11-20 22:40 ` [PATCH 07/20] media: atomisp: Remove 2 unused accelerator mode related functions Hans de Goede
2022-11-20 22:40 ` [PATCH 08/20] media: atomisp: Remove atomisp_css_yuvpp_configure_viewfinder() function Hans de Goede
2022-11-20 22:40 ` [PATCH 09/20] media: atomisp: Remove unused ia_css_frame_*() functions Hans de Goede
2022-11-20 22:40 ` [PATCH 10/20] media: atomisp: Drop userptr support from hmm Hans de Goede
2022-11-21  9:01   ` Andy Shevchenko
2022-11-21 12:31     ` Hans de Goede
2022-11-20 22:40 ` [PATCH 11/20] media: atomisp: Remove double atomisp_mrfld_power_down()/_up() calls from atomisp_reset() Hans de Goede
2022-11-20 22:40 ` [PATCH 12/20] media: atomisp: Remove atomisp_mrfld_power_down()/_up() Hans de Goede
2022-11-20 22:40 ` [PATCH 13/20] media: atomisp: Remove clearing of config from atomisp_css_uninit() Hans de Goede
2022-11-20 22:40 ` [PATCH 14/20] media: atomisp: Remove atomisp_css_suspend()/_resume() Hans de Goede
2022-11-20 22:40 ` Hans de Goede [this message]
2022-11-21  9:09   ` [PATCH 15/20] media: atomisp: Remove sw_contex.power_state checks Andy Shevchenko
2022-11-21  9:16     ` Andy Shevchenko
2022-11-20 22:40 ` [PATCH 16/20] media: atomisp: Remove duplication between runtime-pm and normal-pm code Hans de Goede
2022-11-20 22:40 ` [PATCH 17/20] media: atomisp: Move calling of css_[un]init() to power_on()/_off() Hans de Goede
2022-11-21  9:14   ` Andy Shevchenko
2022-11-21 12:33     ` Hans de Goede
2022-11-20 22:40 ` [PATCH 18/20] media: atomisp: Remove atomisp_ospm_dphy_down() call from probe error path Hans de Goede
2022-11-20 22:41 ` [PATCH 19/20] media: atomisp: Remove atomisp_ospm_dphy_up()/_down() functions Hans de Goede
2022-11-20 22:41 ` [PATCH 20/20] media: atomisp_ov2680: Fix 1280x720 -> 1296x736 resolution Hans de Goede
2022-11-21  9:20 ` [PATCH 00/20] media: atomisp: Misc. cleanups / fixes Andy Shevchenko
2022-11-21 12:40   ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221120224101.746199-16-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andrey.i.trufanov@gmail.com \
    --cc=andy@kernel.org \
    --cc=fabioaiuto83@gmail.com \
    --cc=kitakar@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=nable.maininbox@googlemail.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=yury.lunev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox