mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pablo Mazzini <pmazzini@gmail.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: Pablo Mazzini <pmazzini@gmail.com>,
	Alistair Francis <alistair@alistair23.me>,
	Andreas Kemnade <andreas@kemnade.info>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 4/7] regulator: sy7636a: wait for power good, then switch VCOM_EN
Date: Mon, 26 Oct 2026 00:39:15 +0000	[thread overview]
Message-ID: <20261026003918.155321-5-pmazzini@gmail.com> (raw)
In-Reply-To: <20261026003918.155321-1-pmazzini@gmail.com>

Wait for power good on enable, as the TPS65185 and FP9931 drivers do.

The VCOM_EN line was requested but held low. When it is wired, let it
switch VCOM after power good.

Signed-off-by: Pablo Mazzini <pmazzini@gmail.com>
---
 drivers/regulator/sy7636a-regulator.c | 77 +++++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/sy7636a-regulator.c b/drivers/regulator/sy7636a-regulator.c
index 382bab017784..5705599d1b55 100644
--- a/drivers/regulator/sy7636a-regulator.c
+++ b/drivers/regulator/sy7636a-regulator.c
@@ -7,8 +7,10 @@
 // Authors: Lars Ivar Miljeteig <lars.ivar.miljeteig@remarkable.com>
 //          Alistair Francis <alistair@alistair23.me>
 
+#include <linux/completion.h>
 #include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
+#include <linux/interrupt.h>
 #include <linux/mfd/sy7636a.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -17,11 +19,14 @@
 #include <linux/regulator/machine.h>
 #include <linux/regmap.h>
 
+#define PGOOD_TIMEOUT_MSECS 200
+
 struct sy7636a_data {
 	struct regmap *regmap;
 	struct gpio_desc *pgood_gpio;
 	struct gpio_desc *en_gpio;
 	struct gpio_desc *vcom_en_gpio;
+	struct completion pgood_completion;
 };
 
 static int sy7636a_get_vcom_voltage_sel(struct regulator_dev *rdev)
@@ -65,13 +70,58 @@ static int sy7636a_get_status(struct regulator_dev *rdev)
 	return ret;
 }
 
+static irqreturn_t sy7636a_pgood_handler(int irq, void *dev_id)
+{
+	struct sy7636a_data *data = dev_id;
+
+	complete(&data->pgood_completion);
+
+	return IRQ_HANDLED;
+}
+
+/* wait for the rails to be good, then switch VCOM on with VCOM_EN if wired */
+static int sy7636a_enable(struct regulator_dev *rdev)
+{
+	struct sy7636a_data *data = dev_get_drvdata(rdev->dev.parent);
+	int ret;
+
+	reinit_completion(&data->pgood_completion);
+	ret = regulator_enable_regmap(rdev);
+	if (ret)
+		return ret;
+
+	wait_for_completion_timeout(&data->pgood_completion,
+				    msecs_to_jiffies(PGOOD_TIMEOUT_MSECS));
+	ret = gpiod_get_value_cansleep(data->pgood_gpio);
+	if (ret <= 0) {
+		regulator_disable_regmap(rdev);
+		return ret ? ret : -ETIMEDOUT;
+	}
+
+	if (data->vcom_en_gpio) {
+		gpiod_set_value_cansleep(data->vcom_en_gpio, 1);
+		usleep_range(500, 700);
+	}
+
+	return 0;
+}
+
+static int sy7636a_disable(struct regulator_dev *rdev)
+{
+	struct sy7636a_data *data = dev_get_drvdata(rdev->dev.parent);
+
+	gpiod_set_value_cansleep(data->vcom_en_gpio, 0);
+
+	return regulator_disable_regmap(rdev);
+}
+
 static const struct regulator_ops sy7636a_vcom_volt_ops = {
 	.list_voltage = regulator_list_voltage_linear_range,
 	.map_voltage = regulator_map_voltage_linear_range,
 	.get_voltage_sel = sy7636a_get_vcom_voltage_sel,
 	.set_voltage_sel = sy7636a_set_vcom_voltage_sel,
-	.enable = regulator_enable_regmap,
-	.disable = regulator_disable_regmap,
+	.enable = sy7636a_enable,
+	.disable = sy7636a_disable,
 	.is_enabled = regulator_is_enabled_regmap,
 	.get_status = sy7636a_get_status,
 };
@@ -104,7 +154,7 @@ static int sy7636a_regulator_probe(struct platform_device *pdev)
 	struct regulator_dev *rdev;
 	struct gpio_desc *gdp;
 	struct sy7636a_data *data;
-	int ret;
+	int irq, ret;
 
 	if (!regmap)
 		return -EPROBE_DEFER;
@@ -136,7 +186,6 @@ static int sy7636a_regulator_probe(struct platform_device *pdev)
 				     PTR_ERR(data->en_gpio),
 				     "failed to get en gpio\n");
 
-	/* Let VCOM just follow the default power on sequence */
 	data->vcom_en_gpio = devm_gpiod_get_optional(&pdev->dev,
 						     "vcom-en", GPIOD_OUT_LOW);
 	if (IS_ERR(data->vcom_en_gpio))
@@ -156,6 +205,26 @@ static int sy7636a_regulator_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	irq = gpiod_to_irq(data->pgood_gpio);
+	if (irq < 0)
+		return dev_err_probe(&pdev->dev, irq, "no power good interrupt\n");
+
+	init_completion(&data->pgood_completion);
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, sy7636a_pgood_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					"sy7636a-pgood", data);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "failed to request power good interrupt\n");
+
+	/* VCOM switched by the VCOM_EN line; otherwise it follows the power on sequence */
+	if (data->vcom_en_gpio) {
+		ret = regmap_set_bits(regmap, SY7636A_REG_OPERATION_MODE_CRL,
+				      SY7636A_OPERATION_MODE_CRL_VCOMCTL);
+		if (ret)
+			return ret;
+	}
+
 	config.dev = &pdev->dev;
 	config.regmap = regmap;
 
-- 
2.52.0


  parent reply	other threads:[~2026-10-26  0:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26  0:39 [PATCH 0/7] sy7636a: power the panel only during updates Pablo Mazzini
2026-10-26  0:39 ` [PATCH 1/7] ARM: dts: imx: keep the SY7636A VCOM on Pablo Mazzini
2026-10-26  7:30   ` Andreas Kemnade
2026-10-26  8:21     ` Pablo Mazzini
2026-10-26  0:39 ` [PATCH 2/7] regulator: sy7636a: fix the chip name Pablo Mazzini
2026-10-26  7:39   ` Andreas Kemnade
2026-10-26  0:39 ` [PATCH 3/7] regulator: sy7636a: add VCOM voltage control Pablo Mazzini
2026-10-26  7:41   ` Andreas Kemnade
2026-10-26  0:39 ` Pablo Mazzini [this message]
2026-10-26  8:10   ` [PATCH 4/7] regulator: sy7636a: wait for power good, then switch VCOM_EN Andreas Kemnade
2026-10-26  8:44     ` Pablo Mazzini
2026-10-26  0:39 ` [PATCH 5/7] regulator: sy7636a: report the temperature Pablo Mazzini
2026-10-26  8:42   ` Andreas Kemnade
2026-10-26 14:35   ` Guenter Roeck
2026-10-26  0:39 ` [PATCH 6/7] regulator: sy7636a: bind to the I2C device directly Pablo Mazzini
2026-10-26  0:39 ` [PATCH 7/7] ARM: imx_v6_v7_defconfig: drop the SY7636A MFD and hwmon options Pablo Mazzini
2026-10-26  9:37 ` [PATCH 0/7] sy7636a: power the panel only during updates Andreas Kemnade
2026-10-26 11:28   ` Pablo Mazzini

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=20261026003918.155321-5-pmazzini@gmail.com \
    --to=pmazzini@gmail.com \
    --cc=alistair@alistair23.me \
    --cc=andreas@kemnade.info \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@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

all inboxes | Powered by JetHome®