From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Dirk Bender <d.bender@phytec.de>,
Stefan Riedmueller <s.riedmueller@phytec.de>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
Sasha Levin <sashal@kernel.org>,
laurent.pinchart@ideasonboard.com, mchehab@kernel.org,
linux-media@vger.kernel.org
Subject: [PATCH AUTOSEL 4.9 10/33] media: mt9p031: Fix corrupted frame after restarting stream
Date: Mon, 8 Nov 2021 20:07:44 -0500 [thread overview]
Message-ID: <20211109010807.1191567-10-sashal@kernel.org> (raw)
In-Reply-To: <20211109010807.1191567-1-sashal@kernel.org>
From: Dirk Bender <d.bender@phytec.de>
[ Upstream commit 0961ba6dd211a4a52d1dd4c2d59be60ac2dc08c7 ]
To prevent corrupted frames after starting and stopping the sensor its
datasheet specifies a specific pause sequence to follow:
Stopping:
Set Pause_Restart Bit -> Set Restart Bit -> Set Chip_Enable Off
Restarting:
Set Chip_Enable On -> Clear Pause_Restart Bit
The Restart Bit is cleared automatically and must not be cleared
manually as this would cause undefined behavior.
Signed-off-by: Dirk Bender <d.bender@phytec.de>
Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/media/i2c/mt9p031.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index 237737fec09c1..e6159faff45af 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -81,7 +81,9 @@
#define MT9P031_PIXEL_CLOCK_INVERT (1 << 15)
#define MT9P031_PIXEL_CLOCK_SHIFT(n) ((n) << 8)
#define MT9P031_PIXEL_CLOCK_DIVIDE(n) ((n) << 0)
-#define MT9P031_FRAME_RESTART 0x0b
+#define MT9P031_RESTART 0x0b
+#define MT9P031_FRAME_PAUSE_RESTART (1 << 1)
+#define MT9P031_FRAME_RESTART (1 << 0)
#define MT9P031_SHUTTER_DELAY 0x0c
#define MT9P031_RST 0x0d
#define MT9P031_RST_ENABLE 1
@@ -448,9 +450,23 @@ static int mt9p031_set_params(struct mt9p031 *mt9p031)
static int mt9p031_s_stream(struct v4l2_subdev *subdev, int enable)
{
struct mt9p031 *mt9p031 = to_mt9p031(subdev);
+ struct i2c_client *client = v4l2_get_subdevdata(subdev);
+ int val;
int ret;
if (!enable) {
+ /* enable pause restart */
+ val = MT9P031_FRAME_PAUSE_RESTART;
+ ret = mt9p031_write(client, MT9P031_RESTART, val);
+ if (ret < 0)
+ return ret;
+
+ /* enable restart + keep pause restart set */
+ val |= MT9P031_FRAME_RESTART;
+ ret = mt9p031_write(client, MT9P031_RESTART, val);
+ if (ret < 0)
+ return ret;
+
/* Stop sensor readout */
ret = mt9p031_set_output_control(mt9p031,
MT9P031_OUTPUT_CONTROL_CEN, 0);
@@ -470,6 +486,16 @@ static int mt9p031_s_stream(struct v4l2_subdev *subdev, int enable)
if (ret < 0)
return ret;
+ /*
+ * - clear pause restart
+ * - don't clear restart as clearing restart manually can cause
+ * undefined behavior
+ */
+ val = MT9P031_FRAME_RESTART;
+ ret = mt9p031_write(client, MT9P031_RESTART, val);
+ if (ret < 0)
+ return ret;
+
return mt9p031_pll_enable(mt9p031);
}
--
2.33.0
next prev parent reply other threads:[~2021-11-09 1:23 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-09 1:07 [PATCH AUTOSEL 4.9 01/33] Bluetooth: sco: Fix lock_sock() blockage by memcpy_from_msg() Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 02/33] Bluetooth: fix use-after-free error in lock_sock_nested() Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 03/33] platform/x86: wmi: do not fail if disabling fails Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 04/33] MIPS: lantiq: dma: add small delay after reset Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 05/33] MIPS: lantiq: dma: reset correct number of channel Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 06/33] locking/lockdep: Avoid RCU-induced noinstr fail Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 07/33] smackfs: Fix use-after-free in netlbl_catmap_walk() Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 08/33] NET: IPV4: fix error "do not initialise globals to 0" Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 09/33] x86: Increase exception stack sizes Sasha Levin
2021-11-09 1:07 ` Sasha Levin [this message]
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 11/33] media: netup_unidvb: handle interrupt properly according to the firmware Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 12/33] media: uvcvideo: Set capability in s_param Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 13/33] media: s5p-mfc: fix possible null-pointer dereference in s5p_mfc_probe() Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 14/33] media: mceusb: return without resubmitting URB in case of -EPROTO error Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 15/33] ia64: don't do IA64_CMPXCHG_DEBUG without CONFIG_PRINTK Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 16/33] ACPICA: Avoid evaluating methods too early during system resume Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 17/33] media: usb: dvd-usb: fix uninit-value bug in dibusb_read_eeprom_byte() Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 18/33] tracefs: Have tracefs directories not set OTH permission bits by default Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 19/33] ath: dfs_pattern_detector: Fix possible null-pointer dereference in channel_detector_create() Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 20/33] ACPI: battery: Accept charges over the design capacity as full Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 21/33] memstick: r592: Fix a UAF bug when removing the driver Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 22/33] lib/xz: Avoid overlapping memcpy() with invalid input with in-place decompression Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 23/33] lib/xz: Validate the value before assigning it to an enum variable Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 24/33] tracing/cfi: Fix cmp_entries_* functions signature mismatch Sasha Levin
2021-11-09 1:07 ` [PATCH AUTOSEL 4.9 25/33] mwl8k: Fix use-after-free in mwl8k_fw_state_machine() Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 26/33] PM: hibernate: Get block device exclusively in swsusp_check() Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 27/33] iwlwifi: mvm: disable RX-diversity in powersave Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 28/33] smackfs: use __GFP_NOFAIL for smk_cipso_doi() Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 29/33] ARM: clang: Do not rely on lr register for stacktrace Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 30/33] ARM: 9136/1: ARMv7-M uses BE-8, not BE-32 Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 31/33] spi: bcm-qspi: Fix missing clk_disable_unprepare() on error in bcm_qspi_probe() Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 32/33] parisc: fix warning in flush_tlb_all Sasha Levin
2021-11-09 1:08 ` [PATCH AUTOSEL 4.9 33/33] parisc/kgdb: add kgdb_roundup() to make kgdb work with idle polling Sasha Levin
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=20211109010807.1191567-10-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=d.bender@phytec.de \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab+huawei@kernel.org \
--cc=mchehab@kernel.org \
--cc=s.riedmueller@phytec.de \
--cc=sakari.ailus@linux.intel.com \
--cc=stable@vger.kernel.org \
/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).