devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "André Apitzsch via B4 Relay" <devnull+git.apitzsch.eu@kernel.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	devicetree@vger.kernel.org,
	 Sakari Ailus <sakari.ailus@linux.intel.com>,
	 Daniel Scally <djrscally@gmail.com>
Cc: ~postmarketos/upstreaming@lists.sr.ht,
	phone-devel@vger.kernel.org, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org, "Val Packett" <val@packett.cool>,
	"André Apitzsch" <git@apitzsch.eu>
Subject: [PATCH v2 8/8] media: i2c: dw9719: Fix power on/off sequence
Date: Sat, 20 Sep 2025 14:03:47 +0200	[thread overview]
Message-ID: <20250920-dw9719-v2-8-028cdaa156e5@apitzsch.eu> (raw)
In-Reply-To: <20250920-dw9719-v2-0-028cdaa156e5@apitzsch.eu>

From: Val Packett <val@packett.cool>

The "jiggle" code was not actually expecting failure, which it should
because that's what actually happens when the device wasn't already woken
up by the regulator power-on (i.e. in the case of a shared regulator).

Also, do actually enter the internal suspend mode on shutdown, to save
power in the case of a shared regulator.

Also, wait a bit longer (2x tOPR) on waking up, 1x is not enough at least
on the DW9718S as found on the motorola-nora smartphone.

Signed-off-by: Val Packett <val@packett.cool>
Signed-off-by: André Apitzsch <git@apitzsch.eu>
---
 drivers/media/i2c/dw9719.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/dw9719.c b/drivers/media/i2c/dw9719.c
index a24594523030df7df7fb60afb5248472b4a8ea13..3627e78b8b6668933c4ecd92231465ce4105ff0c 100644
--- a/drivers/media/i2c/dw9719.c
+++ b/drivers/media/i2c/dw9719.c
@@ -95,12 +95,20 @@ struct dw9719_device {
 
 static int dw9719_power_down(struct dw9719_device *dw9719)
 {
+	u32 reg_pwr = dw9719->model == DW9718S ? DW9718S_PD : DW9719_CONTROL;
+
+	/*
+	 * Worth engaging the internal SHUTDOWN mode especially due to the
+	 * regulator being potentially shared with other devices.
+	 */
+	if (cci_write(dw9719->regmap, reg_pwr, DW9719_SHUTDOWN, NULL))
+		dev_err(dw9719->dev, "Error writing to power register\n");
 	return regulator_disable(dw9719->regulator);
 }
 
 static int dw9719_power_up(struct dw9719_device *dw9719, bool detect)
 {
-	u32 reg_pwr;
+	u32 reg_pwr = dw9719->model == DW9718S ? DW9718S_PD : DW9719_CONTROL;
 	u64 val;
 	int ret;
 	int err;
@@ -109,13 +117,17 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect)
 	if (ret)
 		return ret;
 
-	/* Jiggle SCL pin to wake up device */
-	reg_pwr = dw9719->model == DW9718S ? DW9718S_PD : DW9719_CONTROL;
-	cci_write(dw9719->regmap, reg_pwr, DW9719_SHUTDOWN, &ret);
-	fsleep(100);
+	/*
+	 * Need 100us to transition from SHUTDOWN to STANDBY.
+	 * Jiggle the SCL pin to wake up the device (even when the regulator is
+	 * shared) and wait double the time to be sure, as 100us is not enough
+	 * at least on the DW9718S as found on the motorola-nora smartphone,
+	 * then retry the write.
+	 */
+	cci_write(dw9719->regmap, reg_pwr, DW9719_STANDBY, NULL);
+	/* the jiggle is expected to fail, don't even log that as error */
+	fsleep(200);
 	cci_write(dw9719->regmap, reg_pwr, DW9719_STANDBY, &ret);
-	/* Need 100us to transit from SHUTDOWN to STANDBY */
-	fsleep(100);
 
 	if (detect) {
 		/* This model does not have an INFO register */

-- 
2.51.0



  parent reply	other threads:[~2025-09-20 12:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-20 12:03 [PATCH v2 0/8] media: i2c: dw9719: add DT compatible and DW9718S support André Apitzsch via B4 Relay
2025-09-20 12:03 ` [PATCH v2 1/8] dt-bindings: media: i2c: Add DW9718S, DW9719 and DW9761 VCM André Apitzsch via B4 Relay
2025-09-22 20:25   ` Rob Herring (Arm)
2025-10-20 20:44   ` Krzysztof Kozlowski
2025-09-20 12:03 ` [PATCH v2 2/8] media: i2c: dw9719: Deprecate dongwoon,vcm-freq André Apitzsch via B4 Relay
2025-09-20 12:03 ` [PATCH v2 3/8] media: i2c: dw9719: Remove unused i2c device id table André Apitzsch via B4 Relay
2025-09-20 12:03 ` [PATCH v2 4/8] media: i2c: dw9719: Add an of_match_table André Apitzsch via B4 Relay
2025-09-20 12:03 ` [PATCH v2 5/8] media: i2c: dw9719: Add driver_data matching André Apitzsch via B4 Relay
2025-09-20 12:03 ` [PATCH v2 6/8] media: i2c: dw9719: Add DW9718S support André Apitzsch via B4 Relay
2025-09-20 12:03 ` [PATCH v2 7/8] media: i2c: dw9719: Update PM last busy time upon close André Apitzsch via B4 Relay
2025-09-20 12:03 ` André Apitzsch via B4 Relay [this message]
2025-10-20 20:40 ` [PATCH v2 0/8] media: i2c: dw9719: add DT compatible and DW9718S support André Apitzsch
2025-10-20 20:45   ` Krzysztof Kozlowski
2025-10-21  7:29     ` Sakari Ailus
2025-10-21 20:08       ` André Apitzsch
2025-10-22  6:43         ` Sakari Ailus
2025-10-21 19:56     ` André Apitzsch
2025-10-21 20:06       ` Krzysztof Kozlowski

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=20250920-dw9719-v2-8-028cdaa156e5@apitzsch.eu \
    --to=devnull+git.apitzsch.eu@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=djrscally@gmail.com \
    --cc=git@apitzsch.eu \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=phone-devel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=val@packett.cool \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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).