public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Andy Shevchenko <andy@kernel.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Kate Hsuan <hpa@redhat.com>, Tsuchiya Yuto <kitakar@gmail.com>,
	Fabio Aiuto <fabioaiuto83@gmail.com>,
	linux-media@vger.kernel.org, linux-staging@lists.linux.dev
Subject: [PATCH 01/23] media: atomisp: Add atomisp_s_sensor_power() helper
Date: Mon, 15 Apr 2024 14:01:58 +0200	[thread overview]
Message-ID: <20240415120220.219480-2-hdegoede@redhat.com> (raw)
In-Reply-To: <20240415120220.219480-1-hdegoede@redhat.com>

Since the atomisp driver only supports 1 stream / only has 1 asd now,
there is no longer a need to track which stream owns the sensor.

So the asd owner-pointer of struct atomisp_input_subdev can be dropped,
replace this with a simple camera_on boolean and add a new
atomisp_s_sensor_power() helper which takes care of avoiding unbalanced
s_power() subdev calls as well as takes care of handling the special
-ENOIOCTLCMD return for subdevs which don't implement s_power().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 .../staging/media/atomisp/pci/atomisp_cmd.c   | 17 +++++++++++++++
 .../staging/media/atomisp/pci/atomisp_cmd.h   |  3 +++
 .../staging/media/atomisp/pci/atomisp_fops.c  | 14 +------------
 .../media/atomisp/pci/atomisp_internal.h      |  6 +-----
 .../staging/media/atomisp/pci/atomisp_ioctl.c | 21 ++++---------------
 5 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
index 3a56cf68b688..6b8ff9f1ae63 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
@@ -3722,6 +3722,23 @@ void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
 	*padding_h = max_t(u32, *padding_h, min_pad_h);
 }
 
+int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on)
+{
+	int ret;
+
+	if (isp->inputs[input].camera_on == on)
+		return 0;
+
+	ret = v4l2_subdev_call(isp->inputs[input].camera, core, s_power, on);
+	if (ret && ret != -ENOIOCTLCMD) {
+		dev_err(isp->dev, "Error setting sensor power %d: %d\n", on, ret);
+		return ret;
+	}
+
+	isp->inputs[input].camera_on = on;
+	return 0;
+}
+
 static int atomisp_set_sensor_crop_and_fmt(struct atomisp_device *isp,
 					   struct v4l2_mbus_framefmt *ffmt,
 					   int which)
diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.h b/drivers/staging/media/atomisp/pci/atomisp_cmd.h
index b8cd957eebdc..2676236ee015 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.h
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.h
@@ -241,6 +241,9 @@ int atomisp_compare_grid(struct atomisp_sub_device *asd,
 void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
 			 u32 *padding_w, u32 *padding_h);
 
+/* Set sensor power (no-op if already on/off) */
+int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on);
+
 /* This function looks up the closest available resolution. */
 int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
 		    const struct atomisp_format_bridge **fmt_ret,
diff --git a/drivers/staging/media/atomisp/pci/atomisp_fops.c b/drivers/staging/media/atomisp/pci/atomisp_fops.c
index 4dba6120af39..b464a6bd0bad 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_fops.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_fops.c
@@ -445,12 +445,8 @@ const struct vb2_ops atomisp_vb2_ops = {
 
 static void atomisp_dev_init_struct(struct atomisp_device *isp)
 {
-	unsigned int i;
-
 	isp->isp_fatal_error = false;
 
-	for (i = 0; i < isp->input_cnt; i++)
-		isp->inputs[i].asd = NULL;
 	/*
 	 * For Merrifield, frequency is scalable.
 	 * After boot-up, the default frequency is 200MHz.
@@ -584,15 +580,7 @@ static int atomisp_release(struct file *file)
 	atomisp_css_free_stat_buffers(asd);
 	atomisp_free_internal_buffers(asd);
 
-	if (isp->inputs[asd->input_curr].asd == asd) {
-		ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
-				       core, s_power, 0);
-		if (ret && ret != -ENOIOCTLCMD)
-			dev_warn(isp->dev, "Failed to power-off sensor\n");
-
-		/* clear the asd field to show this camera is not used */
-		isp->inputs[asd->input_curr].asd = NULL;
-	}
+	atomisp_s_sensor_power(isp, asd->input_curr, 0);
 
 	atomisp_destroy_pipes_stream(asd);
 
diff --git a/drivers/staging/media/atomisp/pci/atomisp_internal.h b/drivers/staging/media/atomisp/pci/atomisp_internal.h
index d6e86d013be9..02fffa7f65e1 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_internal.h
+++ b/drivers/staging/media/atomisp/pci/atomisp_internal.h
@@ -127,17 +127,13 @@ struct atomisp_input_subdev {
 	u32 code; /* MEDIA_BUS_FMT_* */
 	bool binning_support;
 	bool crop_support;
+	bool camera_on;
 	struct v4l2_subdev *camera;
 	/* Sensor rects for sensors which support crop */
 	struct v4l2_rect native_rect;
 	struct v4l2_rect active_rect;
 	/* Sensor state for which == V4L2_SUBDEV_FORMAT_TRY calls */
 	struct v4l2_subdev_state *try_sd_state;
-	/*
-	 * To show this resource is used by
-	 * which stream, in ISP multiple stream mode
-	 */
-	struct atomisp_sub_device *asd;
 };
 
 enum atomisp_dfs_mode {
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index d602bda134f9..be1f3f2ee63e 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -469,28 +469,15 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
 	}
 
 	/* power off the current owned sensor, as it is not used this time */
-	if (isp->inputs[asd->input_curr].asd == asd &&
-	    asd->input_curr != input) {
-		ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
-				       core, s_power, 0);
-		if (ret && ret != -ENOIOCTLCMD)
-			dev_warn(isp->dev,
-				 "Failed to power-off sensor\n");
-		/* clear the asd field to show this camera is not used */
-		isp->inputs[asd->input_curr].asd = NULL;
-	}
+	if (input != isp->asd.input_curr)
+		atomisp_s_sensor_power(isp, isp->asd.input_curr, 0);
 
 	/* powe on the new sensor */
-	ret = v4l2_subdev_call(isp->inputs[input].camera, core, s_power, 1);
-	if (ret && ret != -ENOIOCTLCMD) {
-		dev_err(isp->dev, "Failed to power-on sensor\n");
+	ret = atomisp_s_sensor_power(isp, input, 1);
+	if (ret)
 		return ret;
-	}
 
 	asd->input_curr = input;
-	/* mark this camera is used by the current stream */
-	isp->inputs[input].asd = asd;
-
 	return 0;
 }
 
-- 
2.44.0


  reply	other threads:[~2024-04-15 12:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15 12:01 [PATCH 00/23] media: atomisp: Further media-controller related fixes + dead code removal Hans de Goede
2024-04-15 12:01 ` Hans de Goede [this message]
2024-04-15 12:01 ` [PATCH 02/23] media: atomisp: Turn on sensor power from atomisp_set_fmt() Hans de Goede
2024-04-15 12:02 ` [PATCH 03/23] media: atomisp: Add atomisp_select_input() helper Hans de Goede
2024-04-15 12:02 ` [PATCH 04/23] media: atomisp: Simplify atomisp_s_input() input argument checking Hans de Goede
2024-04-15 12:02 ` [PATCH 05/23] media: atomisp: Ensure CSI-receiver[x] -> ISP links correctly reflect current sensor Hans de Goede
2024-04-15 12:02 ` [PATCH 06/23] media: atomisp: Propagate set_fmt on sensor results to CSI port Hans de Goede
2024-04-15 12:02 ` [PATCH 07/23] media: atomisp: Propagate v4l2_mbus_framefmt.field to CSI port sink pad Hans de Goede
2024-04-15 12:02 ` [PATCH 08/23] media: atomisp: Call media_pipeline_alloc_start() in stream start Hans de Goede
2024-04-15 12:02 ` [PATCH 09/23] media: atomisp: Drop atomisp_pipe_check() from atomisp_link_setup() Hans de Goede
2024-04-15 12:02 ` [PATCH 10/23] media: atomisp: ov2722: Remove power on sensor from set_fmt() callback Hans de Goede
2024-04-15 12:02 ` [PATCH 11/23] media: atomisp: Remove test pattern generator (TPG) support Hans de Goede
2024-04-15 14:40   ` Andy Shevchenko
2024-04-16  9:25     ` Hans de Goede
2024-04-16 13:34       ` Andy Shevchenko
2024-04-16 14:37         ` Kieran Bingham
2024-04-16 14:40           ` Kieran Bingham
2024-04-16 14:50             ` Andy Shevchenko
2024-04-16 14:52               ` Andy Shevchenko
2024-04-15 12:02 ` [PATCH 12/23] media: atomisp: Remove input_port_ID_t Hans de Goede
2024-04-15 12:02 ` [PATCH 13/23] media: atomisp: Drop the atomisp custom lm3554 flash driver Hans de Goede
2024-04-15 14:49   ` Andy Shevchenko
2024-04-15 14:50     ` Andy Shevchenko
2024-04-15 12:02 ` [PATCH 14/23] media: atomisp: Drop custom flash support Hans de Goede
2024-04-15 14:53   ` Andy Shevchenko
2024-04-15 12:02 ` [PATCH 15/23] media: atomisp: Drop unused frame_status tracking Hans de Goede
2024-04-15 12:02 ` [PATCH 16/23] media: atomisp: Drop intel_v4l2_subdev_type Hans de Goede
2024-04-15 14:55   ` Andy Shevchenko
2024-04-15 12:02 ` [PATCH 17/23] media: atomisp: Remove gmin_platform VCM code Hans de Goede
2024-04-15 12:02 ` [PATCH 18/23] media: atomisp: Remove struct atomisp_platform_data Hans de Goede
2024-04-15 12:02 ` [PATCH 19/23] media: atomisp: Remove clearing of ISP crop / compose rectangles on file release Hans de Goede
2024-04-15 12:02 ` [PATCH 20/23] media: atomisp: Remove empty s_power() op from ISP subdev Hans de Goede
2024-04-15 12:02 ` [PATCH 21/23] media: atomisp: Remove empty s_stream() op from CSI subdev Hans de Goede
2024-04-15 12:02 ` [PATCH 22/23] media: atomisp: Cleanup atomisp_isr_thread() spinlock handling Hans de Goede
2024-04-15 12:02 ` [PATCH 23/23] media: atomisp: Remove setting of f->fmt.pix.priv from atomisp_set_fmt() Hans de Goede
2024-04-15 14:58 ` [PATCH 00/23] media: atomisp: Further media-controller related fixes + dead code removal Andy Shevchenko

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=20240415120220.219480-2-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andy@kernel.org \
    --cc=fabioaiuto83@gmail.com \
    --cc=hpa@redhat.com \
    --cc=kitakar@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.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