linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lubomir Rintel <lkundrak@v3.sk>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-media@vger.kernel.org
Cc: Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Lubomir Rintel <lkundrak@v3.sk>, James Cameron <quozl@laptop.org>,
	Pavel Machek <pavel@ucw.cz>, Libin Yang <lbyang@marvell.com>,
	Albert Wang <twang13@marvell.com>
Subject: [PATCH v3 01/14] media: ov7670: split register setting from set_fmt() logic
Date: Tue, 20 Nov 2018 11:03:06 +0100	[thread overview]
Message-ID: <20181120100318.367987-2-lkundrak@v3.sk> (raw)
In-Reply-To: <20181120100318.367987-1-lkundrak@v3.sk>

This will allow us to restore the last set format after the device returns
from a power off.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>

---
Changes since v2:
- This patch was added to the series

 drivers/media/i2c/ov7670.c | 80 ++++++++++++++++++++++----------------
 1 file changed, 46 insertions(+), 34 deletions(-)

diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index bc68a3a5b4ec..ee2302fbdeee 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -240,6 +240,7 @@ struct ov7670_info {
 	};
 	struct v4l2_mbus_framefmt format;
 	struct ov7670_format_struct *fmt;  /* Current format */
+	struct ov7670_win_size *wsize;
 	struct clk *clk;
 	struct gpio_desc *resetb_gpio;
 	struct gpio_desc *pwdn_gpio;
@@ -1003,48 +1004,20 @@ static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
 	return 0;
 }
 
-/*
- * Set a format.
- */
-static int ov7670_set_fmt(struct v4l2_subdev *sd,
-		struct v4l2_subdev_pad_config *cfg,
-		struct v4l2_subdev_format *format)
+static int ov7670_apply_fmt(struct v4l2_subdev *sd)
 {
-	struct ov7670_format_struct *ovfmt;
-	struct ov7670_win_size *wsize;
 	struct ov7670_info *info = to_state(sd);
-#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
-	struct v4l2_mbus_framefmt *mbus_fmt;
-#endif
+	struct ov7670_win_size *wsize = info->wsize;
 	unsigned char com7, com10 = 0;
 	int ret;
 
-	if (format->pad)
-		return -EINVAL;
-
-	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
-		ret = ov7670_try_fmt_internal(sd, &format->format, NULL, NULL);
-		if (ret)
-			return ret;
-#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
-		mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
-		*mbus_fmt = format->format;
-		return 0;
-#else
-		return -ENOTTY;
-#endif
-	}
-
-	ret = ov7670_try_fmt_internal(sd, &format->format, &ovfmt, &wsize);
-	if (ret)
-		return ret;
 	/*
 	 * COM7 is a pain in the ass, it doesn't like to be read then
 	 * quickly written afterward.  But we have everything we need
 	 * to set it absolutely here, as long as the format-specific
 	 * register sets list it first.
 	 */
-	com7 = ovfmt->regs[0].value;
+	com7 = info->fmt->regs[0].value;
 	com7 |= wsize->com7_bit;
 	ret = ov7670_write(sd, REG_COM7, com7);
 	if (ret)
@@ -1066,7 +1039,7 @@ static int ov7670_set_fmt(struct v4l2_subdev *sd,
 	/*
 	 * Now write the rest of the array.  Also store start/stops
 	 */
-	ret = ov7670_write_array(sd, ovfmt->regs + 1);
+	ret = ov7670_write_array(sd, info->fmt->regs + 1);
 	if (ret)
 		return ret;
 
@@ -1081,8 +1054,6 @@ static int ov7670_set_fmt(struct v4l2_subdev *sd,
 			return ret;
 	}
 
-	info->fmt = ovfmt;
-
 	/*
 	 * If we're running RGB565, we must rewrite clkrc after setting
 	 * the other parameters or the image looks poor.  If we're *not*
@@ -1100,6 +1071,46 @@ static int ov7670_set_fmt(struct v4l2_subdev *sd,
 	return 0;
 }
 
+/*
+ * Set a format.
+ */
+static int ov7670_set_fmt(struct v4l2_subdev *sd,
+		struct v4l2_subdev_pad_config *cfg,
+		struct v4l2_subdev_format *format)
+{
+	struct ov7670_info *info = to_state(sd);
+#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
+	struct v4l2_mbus_framefmt *mbus_fmt;
+#endif
+	int ret;
+
+	if (format->pad)
+		return -EINVAL;
+
+	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
+		ret = ov7670_try_fmt_internal(sd, &format->format, NULL, NULL);
+		if (ret)
+			return ret;
+#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
+		mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
+		*mbus_fmt = format->format;
+		return 0;
+#else
+		return -ENOTTY;
+#endif
+	}
+
+	ret = ov7670_try_fmt_internal(sd, &format->format, &info->fmt, &info->wsize);
+	if (ret)
+		return ret;
+
+	ret = ov7670_apply_fmt(sd);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 static int ov7670_get_fmt(struct v4l2_subdev *sd,
 			  struct v4l2_subdev_pad_config *cfg,
 			  struct v4l2_subdev_format *format)
@@ -1847,6 +1858,7 @@ static int ov7670_probe(struct i2c_client *client,
 
 	info->devtype = &ov7670_devdata[id->driver_data];
 	info->fmt = &ov7670_formats[0];
+	info->wsize = &info->devtype->win_sizes[0];
 
 	ov7670_get_default_format(sd, &info->format);
 
-- 
2.19.1

  reply	other threads:[~2018-11-20 20:32 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20 10:03 [PATCH v3 0/14] media: make Marvell camera work on DT-based OLPC XO-1.75 Lubomir Rintel
2018-11-20 10:03 ` Lubomir Rintel [this message]
2018-11-22 18:37   ` [PATCH v3 01/14] media: ov7670: split register setting from set_fmt() logic jacopo mondi
2018-11-28 17:10     ` Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 02/14] media: ov7670: split register setting from set_framerate() logic Lubomir Rintel
2019-01-14 23:03   ` Sakari Ailus
2019-01-15  8:30     ` Lubomir Rintel
2019-01-15  8:45       ` Sakari Ailus
2018-11-20 10:03 ` [PATCH v3 03/14] media: ov7670: hook s_power onto v4l2 core Lubomir Rintel
2018-11-22 12:21   ` Sakari Ailus
2018-11-28 11:29     ` Lubomir Rintel
2019-01-10 16:59       ` Sakari Ailus
2019-01-13 16:38         ` Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 04/14] media: ov7670: control clock along with power Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 05/14] media: dt-bindings: marvell,mmp2-ccic: Add Marvell MMP2 camera Lubomir Rintel
2018-11-22 20:08   ` jacopo mondi
2019-04-25 14:28     ` Lubomir Rintel
2018-11-27 10:08   ` Sakari Ailus
2018-11-20 10:03 ` [PATCH v3 06/14] [media] marvell-ccic: fix DMA s/g desc number calculation Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 07/14] [media] marvell-ccic: don't generate EOF on parallel bus Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 08/14] Revert "[media] marvell-ccic: reset ccic phy when stop streaming for stability" Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 09/14] [media] marvell-ccic: drop unused stuff Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 10/14] [media] marvell-ccic/mmp: enable clock before accessing registers Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 11/14] [media] marvell-ccic: rename the clocks Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 12/14] [media] marvell-ccic/mmp: add devicetree support Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 13/14] [media] marvell-ccic: use async notifier to get the sensor Lubomir Rintel
2018-11-20 10:03 ` [PATCH v3 14/14] [media] marvell-ccic: provide a clock for " Lubomir Rintel
2018-11-23  7:44   ` jacopo mondi
2019-04-25 13:33     ` Lubomir Rintel

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=20181120100318.367987-2-lkundrak@v3.sk \
    --to=lkundrak@v3.sk \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=lbyang@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=quozl@laptop.org \
    --cc=robh+dt@kernel.org \
    --cc=twang13@marvell.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;
as well as URLs for NNTP newsgroup(s).