[PATCH 4/7] regulator: sy7636a: wait for power good, then switch VCOM_EN

From: Pablo Mazzini

Date: Sun Oct 25 2026 - 20:43:27 EST


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@xxxxxxxxx>
---
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@xxxxxxxxxxxxxx>
// Alistair Francis <alistair@xxxxxxxxxxxxx>

+#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