All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jacopo Mondi <jacopo@jmondi.org>
To: linux-media@vger.kernel.org
Cc: Jacopo Mondi <jacopo@jmondi.org>,
	mchehab@kernel.org, sakari.ailus@linux.intel.com,
	hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com,
	roman.kovalivskyi@globallogic.com,
	dafna.hirschfeld@collabora.com, dave.stevenson@raspberrypi.org,
	naush@raspberrypi.com, erosca@de.adit-jv.com
Subject: [PATCH v3 18/29] media: ov5647: Implement set_fmt pad operation
Date: Mon,  9 Nov 2020 17:49:23 +0100	[thread overview]
Message-ID: <20201109164934.134919-19-jacopo@jmondi.org> (raw)
In-Reply-To: <20201109164934.134919-1-jacopo@jmondi.org>

Now that the driver supports more than a single mode, implement the
.set_fmt pad operation and adjust the existing .get_fmt one to report
the currently applied format.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 drivers/media/i2c/ov5647.c | 66 +++++++++++++++++++++++++++++++++++---
 1 file changed, 62 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index c65aacc0e04d3..68eab61d53493 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -1019,14 +1019,72 @@ static int ov5647_enum_frame_size(struct v4l2_subdev *sd,
 	return 0;
 }
 
-static int ov5647_set_get_fmt(struct v4l2_subdev *sd,
+static int ov5647_get_pad_fmt(struct v4l2_subdev *sd,
 			      struct v4l2_subdev_pad_config *cfg,
 			      struct v4l2_subdev_format *format)
 {
 	struct v4l2_mbus_framefmt *fmt = &format->format;
+	const struct v4l2_mbus_framefmt *sensor_format;
+	struct ov5647 *sensor = to_sensor(sd);
 
 	memset(fmt, 0, sizeof(*fmt));
-	*fmt = OV5647_DEFAULT_FORMAT;
+
+	mutex_lock(&sensor->lock);
+	switch (format->which) {
+	case V4L2_SUBDEV_FORMAT_TRY:
+		sensor_format = v4l2_subdev_get_try_format(sd, cfg, format->pad);
+		break;
+	default:
+		sensor_format = &sensor->mode->format;
+		break;
+	}
+
+	*fmt = *sensor_format;
+	mutex_unlock(&sensor->lock);
+
+	return 0;
+}
+
+static int ov5647_set_pad_fmt(struct v4l2_subdev *sd,
+			      struct v4l2_subdev_pad_config *cfg,
+			      struct v4l2_subdev_format *format)
+{
+	struct v4l2_mbus_framefmt *fmt = &format->format;
+	const struct ov5647_mode *ov5647_mode_list;
+	struct ov5647 *sensor = to_sensor(sd);
+	const struct ov5647_mode *mode;
+	unsigned int num_modes;
+
+	/*
+	 * Default mbus code MEDIA_BUS_FMT_SBGGR10_1X10 if the requested one
+	 * is not supported.
+	 */
+	if (fmt->code == MEDIA_BUS_FMT_SBGGR8_1X8) {
+		ov5647_mode_list = ov5647_8bpp_modes;
+		num_modes = ARRAY_SIZE(ov5647_8bpp_modes);
+	} else {
+		ov5647_mode_list = ov5647_10bpp_modes;
+		num_modes = ARRAY_SIZE(ov5647_10bpp_modes);
+	}
+
+	mode = v4l2_find_nearest_size(ov5647_mode_list, num_modes,
+				      format.width, format.height,
+				      fmt->width, fmt->height);
+
+	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
+		mutex_lock(&sensor->lock);
+		*v4l2_subdev_get_try_format(sd, cfg, format->pad) = mode->format;
+		*fmt = mode->format;
+		mutex_unlock(&sensor->lock);
+
+		return 0;
+	}
+
+	/* Update the sensor mode and apply at it at streamon time. */
+	mutex_lock(&sensor->lock);
+	sensor->mode = mode;
+	*fmt = mode->format;
+	mutex_unlock(&sensor->lock);
 
 	return 0;
 }
@@ -1071,8 +1129,8 @@ static int ov5647_get_selection(struct v4l2_subdev *sd,
 static const struct v4l2_subdev_pad_ops ov5647_subdev_pad_ops = {
 	.enum_mbus_code		= ov5647_enum_mbus_code,
 	.enum_frame_size	= ov5647_enum_frame_size,
-	.set_fmt		= ov5647_set_get_fmt,
-	.get_fmt		= ov5647_set_get_fmt,
+	.set_fmt		= ov5647_set_pad_fmt,
+	.get_fmt		= ov5647_get_pad_fmt,
 	.get_selection		= ov5647_get_selection,
 };
 
-- 
2.29.1


  parent reply	other threads:[~2020-11-09 16:50 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-09 16:49 [PATCH v3 00/29] media: ov5647: Support RaspberryPi Camera Module v1 Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 01/29] media: ov5647: Add support for PWDN GPIO Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 02/29] media: ov5647: Add support for non-continuous clock mode Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 03/29] media: ov5647: Add set_fmt and get_fmt calls Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 04/29] media: ov5647: Fix format initialization Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 05/29] media: ov5647: Fix style issues Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 06/29] media: ov5647: Replace license with SPDX identifier Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 07/29] media: ov5647: Fix return value from read/write Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 08/29] media: ov5647: Program mode at s_stream(1) time Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 09/29] media: ov5647: Implement enum_frame_size() Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 10/29] media: ov5647: Protect s_stream() with mutex Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 11/29] media: ov5647: Support gain, exposure and AWB controls Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 12/29] media: ov5647: Rationalize driver structure name Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 13/29] media: ov5647: Break out format handling Jacopo Mondi
2020-11-18 20:18   ` Sakari Ailus
2020-11-09 16:49 ` [PATCH v3 14/29] media: ov5647: Add support for get_selection() Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 15/29] media: ov5647: Rename SBGGR8 VGA mode Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 16/29] media: ov5647: Add SGGBR10_1X10 modes Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 17/29] media: ov5647: Use SBGGR10_1X10 640x480 as default Jacopo Mondi
2020-11-09 16:49 ` Jacopo Mondi [this message]
2020-11-18 20:42   ` [PATCH v3 18/29] media: ov5647: Implement set_fmt pad operation Sakari Ailus
2020-11-19 11:39     ` Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 19/29] media: ov5647: Set V4L2_SUBDEV_FL_HAS_EVENTS flag Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 20/29] media: ov5647: Support V4L2_CID_PIXEL_RATE Jacopo Mondi
2020-11-18 20:43   ` Sakari Ailus
2020-11-09 16:49 ` [PATCH v3 21/29] media: ov5647: Support V4L2_CID_HBLANK control Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 22/29] media: ov5647: Support V4L2_CID_VBLANK control Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 23/29] media: ov5647: Advertise the correct exposure range Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 24/29] media: ov5647: Use pm_runtime infrastructure Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 25/29] media: ov5647: Rework s_stream() operation Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 26/29] media: ov5647: Apply controls only when powered Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 27/29] media: ov5647: Constify oe_enable/disable reglist Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 28/29] media: ov5647: Support VIDIOC_SUBSCRIBE_EVENT Jacopo Mondi
2020-11-09 16:49 ` [PATCH v3 29/29] media: ov5647: Remove 640x480 SBGGR8 mode Jacopo Mondi
2020-11-18 20:48   ` Sakari Ailus
2020-11-19 10:07     ` Jacopo Mondi
2020-11-18 20:50 ` [PATCH v3 00/29] media: ov5647: Support RaspberryPi Camera Module v1 Sakari Ailus

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=20201109164934.134919-19-jacopo@jmondi.org \
    --to=jacopo@jmondi.org \
    --cc=dafna.hirschfeld@collabora.com \
    --cc=dave.stevenson@raspberrypi.org \
    --cc=erosca@de.adit-jv.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=naush@raspberrypi.com \
    --cc=roman.kovalivskyi@globallogic.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.