Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Michiel van Beers via B4 Relay <devnull+michielvanbeers.gmail.com@kernel.org>
To: Michiel van Beers <michielvanbeers@gmail.com>,
	 Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,  Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	Guenter Roeck <linux@roeck-us.net>,
	 Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
	 Andreas Kemnade <andreas@kemnade.info>,
	Pablo Mazzini <pmazzini@gmail.com>
Subject: [PATCH 2/3] regulator: Add Maxim MAX17135 driver
Date: Wed, 02 Dec 2026 17:43:39 +0100	[thread overview]
Message-ID: <20261202-max17135-v1-2-beae6b70d575@gmail.com> (raw)
In-Reply-To: <20261202-max17135-v1-0-beae6b70d575@gmail.com>

From: Michiel van Beers <michielvanbeers@gmail.com>

Add a driver for the MAX17135 E-paper display PMIC.

The display rails POS, NEG, GVDD and GVEE share one enable and one power
good signal, so implement them as a single regulator, vposneg. VCOM is a
second regulator, supplied by vposneg.

VCOM is only set through the volatile DVR register; the non-volatile
memory is never written. As VCOM is panel specific, refuse to enable it
while the chip holds a default value and the device tree gives no
voltage.

The temperature sensor is exposed to a hwmon driver through an auxiliary
device.

Signed-off-by: Michiel van Beers <michielvanbeers@gmail.com>
---
 MAINTAINERS                        |   8 +
 drivers/regulator/Kconfig          |  14 +
 drivers/regulator/Makefile         |   1 +
 drivers/regulator/max17135.c       | 643 +++++++++++++++++++++++++++++++++++++
 include/linux/regulator/max17135.h |  18 ++
 5 files changed, 684 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 9eaee28958b6..6b2af23ec2bf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16491,6 +16491,14 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/power/supply/maxim,max17042.yaml
 F:	drivers/power/supply/max17042_battery.c
 
+MAXIM MAX17135 E-PAPER DISPLAY PMIC DRIVER
+M:	Michiel van Beers <michielvanbeers@gmail.com>
+L:	linux-kernel@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/regulator/maxim,max17135.yaml
+F:	drivers/regulator/max17135.c
+F:	include/linux/regulator/max17135.h
+
 MAXIM MAX20086 CAMERA POWER PROTECTOR DRIVER
 M:	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
 L:	linux-kernel@vger.kernel.org
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 390d109ad932..08f92967d427 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -622,6 +622,20 @@ config REGULATOR_MAX1586
 	  regulator via I2C bus. The provided regulator is suitable
 	  for PXA27x chips to control VCC_CORE and VCC_USIM voltages.
 
+config REGULATOR_MAX17135
+	tristate "Maxim MAX17135 E-paper display PMIC"
+	depends on I2C
+	select REGMAP_I2C
+	select AUXILIARY_BUS
+	help
+	  This driver supports the Maxim MAX17135 power management IC for
+	  E-paper displays. It provides the display rails and the VCOM
+	  output as regulators. The temperature sensor of the chip is
+	  supported by a separate hardware monitoring driver.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called max17135.
+
 config REGULATOR_MAX5970
 	tristate "Maxim 5970/5978 power switch and monitor"
 	depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 9332c68a90f6..ab562e775b28 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -75,6 +75,7 @@ obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o
 obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o
 obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
 obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
+obj-$(CONFIG_REGULATOR_MAX17135) += max17135.o
 obj-$(CONFIG_REGULATOR_MAX5970) += max5970-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77503) += max77503-regulator.o
 obj-$(CONFIG_REGULATOR_MAX77541) += max77541-regulator.o
diff --git a/drivers/regulator/max17135.c b/drivers/regulator/max17135.c
new file mode 100644
index 000000000000..b192a228d0aa
--- /dev/null
+++ b/drivers/regulator/max17135.c
@@ -0,0 +1,643 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Maxim MAX17135 power management IC for E-paper displays
+ *
+ * Copyright (C) 2026 Michiel van Beers
+ *
+ * Datasheet:
+ * https://www.analog.com/media/en/technical-documentation/data-sheets/MAX17135.pdf
+ */
+
+#include <linux/array_size.h>
+#include <linux/auxiliary_bus.h>
+#include <linux/bitops.h>
+#include <linux/bits.h>
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/dev_printk.h>
+#include <linux/device.h>
+#include <linux/device/devres.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/minmax.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/pm.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/max17135.h>
+#include <linux/types.h>
+
+#define MAX17135_REG_TEMP_EXT		0x00	/* 16 bit, word read only */
+#define MAX17135_REG_CONFIG		0x01
+#define MAX17135_REG_TEMP_INT		0x04	/* 16 bit, word read only */
+#define MAX17135_REG_STATUS		0x05
+#define MAX17135_REG_ID			0x07
+#define MAX17135_REG_DVR		0x08
+#define MAX17135_REG_ENABLE		0x09
+#define MAX17135_REG_FAULT		0x0a
+#define MAX17135_REG_HVINP		0x0b
+#define MAX17135_REG_CONV_RATE		0x0f
+#define MAX17135_REG_T1			0x10
+#define MAX17135_REG_T5			0x14
+#define MAX17135_REG_T8			0x17
+
+#define MAX17135_CONFIG_SHUTDOWN	BIT(0)
+#define MAX17135_ENABLE_EN		BIT(0)
+#define MAX17135_ENABLE_CEN		BIT(1)
+#define MAX17135_FAULT_MASK		GENMASK(6, 0)
+
+#define MAX17135_ID			0x4d
+#define MAX17135_DVR_POR		0xff
+#define MAX17135_DVR_FACTORY		0x7f
+
+#define MAX17135_NUM_DELAYS		4
+#define MAX17135_STARTUP_MS		10
+/*
+ * Typical worst case: two 5 ms converter soft starts, t1-t4 of up to 255 ms
+ * and a 10 ms rail soft start.
+ */
+#define MAX17135_POK_TIMEOUT_MS		400
+#define MAX17135_OFF_MARGIN_MS		5
+
+struct max17135 {
+	struct device *dev;
+	struct regmap *regmap;
+	struct gpio_desc *pok_gpio;
+	struct gpio_desc *en_gpio;
+	struct gpio_desc *cen_gpio;
+	struct completion pok_done;
+	u32 up_delays[MAX17135_NUM_DELAYS];
+	u32 down_delays[MAX17135_NUM_DELAYS];
+	bool has_up_delays;
+	bool has_down_delays;
+	unsigned int off_delay_ms;
+	/* The DT or a consumer chose the VCOM voltage, DVR may be written */
+	bool vcom_programmed;
+	unsigned int vcom_sel;
+};
+
+/*
+ * 0x0b (HVINP) sets the level of the display rails and 0x0c (PCR) burns the
+ * non-volatile memory, which survives only a few writes. Neither is ever
+ * written.
+ */
+static const struct regmap_range max17135_wr_ranges[] = {
+	regmap_reg_range(MAX17135_REG_CONFIG, MAX17135_REG_CONFIG),
+	regmap_reg_range(MAX17135_REG_DVR, MAX17135_REG_ENABLE),
+	regmap_reg_range(MAX17135_REG_T1, MAX17135_REG_T8),
+};
+
+static const struct regmap_access_table max17135_wr_table = {
+	.yes_ranges = max17135_wr_ranges,
+	.n_yes_ranges = ARRAY_SIZE(max17135_wr_ranges),
+};
+
+/*
+ * The temperature registers 0x00 and 0x04 are 16 bits wide. A byte read of
+ * them can leave the chip holding SDA low, so they are kept out of the regmap
+ * and are only read by max17135_read_temp(). 0x0c is write only.
+ */
+static const struct regmap_range max17135_rd_ranges[] = {
+	regmap_reg_range(MAX17135_REG_CONFIG, MAX17135_REG_CONFIG),
+	regmap_reg_range(MAX17135_REG_STATUS, MAX17135_REG_HVINP),
+	regmap_reg_range(MAX17135_REG_CONV_RATE, MAX17135_REG_T8),
+};
+
+static const struct regmap_access_table max17135_rd_table = {
+	.yes_ranges = max17135_rd_ranges,
+	.n_yes_ranges = ARRAY_SIZE(max17135_rd_ranges),
+};
+
+static const struct regmap_config max17135_regmap_config = {
+	.reg_bits = 8,
+	.val_bits = 8,
+	.max_register = MAX17135_REG_T8,
+	.wr_table = &max17135_wr_table,
+	.rd_table = &max17135_rd_table,
+};
+
+/**
+ * max17135_read_temp() - read one of the temperature channels
+ * @dev: the I2C device of the MAX17135
+ * @channel: internal sensor or external diode
+ * @millicelsius: result
+ *
+ * Return: 0 on success, a negative errno otherwise.
+ */
+int max17135_read_temp(struct device *dev,
+		       enum max17135_temp_channel channel,
+		       long *millicelsius)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	u8 reg = channel == MAX17135_TEMP_EXTERNAL ?
+		 MAX17135_REG_TEMP_EXT : MAX17135_REG_TEMP_INT;
+	int ret;
+
+	ret = i2c_smbus_read_word_swapped(client, reg);
+	if (ret < 0)
+		return ret;
+
+	/* 9 bits, two's complement, in D15..D7; 0.5 degrees per step */
+	*millicelsius = sign_extend32(ret >> 7, 8) * 500;
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(max17135_read_temp, "MAX17135");
+
+static int max17135_set_en(struct max17135 *ddata, bool on)
+{
+	if (ddata->en_gpio)
+		return gpiod_set_value_cansleep(ddata->en_gpio, on);
+
+	return regmap_update_bits(ddata->regmap, MAX17135_REG_ENABLE,
+				  MAX17135_ENABLE_EN,
+				  on ? MAX17135_ENABLE_EN : 0);
+}
+
+static int max17135_set_cen(struct max17135 *ddata, bool on)
+{
+	if (ddata->cen_gpio)
+		return gpiod_set_value_cansleep(ddata->cen_gpio, on);
+
+	return regmap_update_bits(ddata->regmap, MAX17135_REG_ENABLE,
+				  MAX17135_ENABLE_CEN,
+				  on ? MAX17135_ENABLE_CEN : 0);
+}
+
+/* Switch everything off and wait for the power-down sequence to end. */
+static void max17135_power_off(struct max17135 *ddata)
+{
+	max17135_set_cen(ddata, false);
+	max17135_set_en(ddata, false);
+	msleep(ddata->off_delay_ms);
+}
+
+static void max17135_power_off_action(void *data)
+{
+	max17135_power_off(data);
+}
+
+static irqreturn_t max17135_pok_handler(int irq, void *dev_id)
+{
+	struct max17135 *ddata = dev_id;
+
+	complete(&ddata->pok_done);
+
+	return IRQ_HANDLED;
+}
+
+static int max17135_vposneg_enable(struct regulator_dev *rdev)
+{
+	struct max17135 *ddata = rdev_get_drvdata(rdev);
+	unsigned int fault;
+	int ret;
+
+	ret = regmap_read(ddata->regmap, MAX17135_REG_FAULT, &fault);
+	if (ret)
+		return ret;
+
+	/* A latched fault is only cleared by cycling VDD. */
+	if (fault & MAX17135_FAULT_MASK) {
+		dev_err(ddata->dev, "fault 0x%02lx latched, rails stay off\n",
+			fault & MAX17135_FAULT_MASK);
+		return -EIO;
+	}
+
+	reinit_completion(&ddata->pok_done);
+
+	ret = max17135_set_en(ddata, true);
+	if (ret)
+		goto err_off;
+
+	wait_for_completion_timeout(&ddata->pok_done,
+				    msecs_to_jiffies(MAX17135_POK_TIMEOUT_MS));
+
+	ret = gpiod_get_value_cansleep(ddata->pok_gpio);
+	if (ret < 0)
+		goto err_off;
+	if (!ret) {
+		/* On a fault the chip switches itself off and says why. */
+		if (!regmap_read(ddata->regmap, MAX17135_REG_FAULT, &fault))
+			dev_err(ddata->dev, "no power good, fault 0x%02lx\n",
+				fault & MAX17135_FAULT_MASK);
+		ret = -ETIMEDOUT;
+		goto err_off;
+	}
+
+	return 0;
+
+err_off:
+	/* Never leave the high voltage half on. */
+	max17135_power_off(ddata);
+	return ret;
+}
+
+static int max17135_vposneg_disable(struct regulator_dev *rdev)
+{
+	struct max17135 *ddata = rdev_get_drvdata(rdev);
+	int ret;
+
+	ret = max17135_set_en(ddata, false);
+	if (ret)
+		return ret;
+
+	msleep(ddata->off_delay_ms);
+
+	return 0;
+}
+
+static int max17135_vposneg_is_enabled(struct regulator_dev *rdev)
+{
+	struct max17135 *ddata = rdev_get_drvdata(rdev);
+
+	return gpiod_get_value_cansleep(ddata->pok_gpio);
+}
+
+static const struct regulator_ops max17135_vposneg_ops = {
+	.enable = max17135_vposneg_enable,
+	.disable = max17135_vposneg_disable,
+	.is_enabled = max17135_vposneg_is_enabled,
+};
+
+static bool max17135_dvr_is_default(unsigned int dvr)
+{
+	return dvr == MAX17135_DVR_POR || dvr == MAX17135_DVR_FACTORY;
+}
+
+static int max17135_vcom_enable(struct regulator_dev *rdev)
+{
+	struct max17135 *ddata = rdev_get_drvdata(rdev);
+	unsigned int dvr;
+	int ret;
+
+	if (!ddata->vcom_programmed) {
+		ret = regmap_read(ddata->regmap, MAX17135_REG_DVR, &dvr);
+		if (ret)
+			return ret;
+
+		/* VCOM is panel specific; a default value is not calibrated. */
+		if (max17135_dvr_is_default(dvr)) {
+			dev_err(ddata->dev, "VCOM is not calibrated\n");
+			return -EINVAL;
+		}
+	}
+
+	return max17135_set_cen(ddata, true);
+}
+
+static int max17135_vcom_disable(struct regulator_dev *rdev)
+{
+	struct max17135 *ddata = rdev_get_drvdata(rdev);
+
+	return max17135_set_cen(ddata, false);
+}
+
+static int max17135_vcom_is_enabled(struct regulator_dev *rdev)
+{
+	struct max17135 *ddata = rdev_get_drvdata(rdev);
+	unsigned int val;
+	int ret;
+
+	if (ddata->cen_gpio)
+		return gpiod_get_value_cansleep(ddata->cen_gpio);
+
+	ret = regmap_read(ddata->regmap, MAX17135_REG_ENABLE, &val);
+	if (ret)
+		return ret;
+
+	return !!(val & MAX17135_ENABLE_CEN);
+}
+
+static int max17135_vcom_set_voltage_sel(struct regulator_dev *rdev,
+					 unsigned int selector)
+{
+	struct max17135 *ddata = rdev_get_drvdata(rdev);
+	int ret;
+
+	ret = regulator_set_voltage_sel_regmap(rdev, selector);
+	if (ret)
+		return ret;
+
+	ddata->vcom_sel = selector;
+	ddata->vcom_programmed = true;
+
+	return 0;
+}
+
+static const struct regulator_ops max17135_vcom_ops = {
+	.list_voltage = regulator_list_voltage_linear,
+	.map_voltage = regulator_map_voltage_linear,
+	.get_voltage_sel = regulator_get_voltage_sel_regmap,
+	.set_voltage_sel = max17135_vcom_set_voltage_sel,
+	.enable = max17135_vcom_enable,
+	.disable = max17135_vcom_disable,
+	.is_enabled = max17135_vcom_is_enabled,
+};
+
+static int max17135_vcom_of_parse(struct device_node *np,
+				  const struct regulator_desc *desc,
+				  struct regulator_config *config)
+{
+	struct max17135 *ddata = config->driver_data;
+	u32 min, max;
+
+	/* A single voltage in the DT is the calibration of this panel. */
+	if (!of_property_read_u32(np, "regulator-min-microvolt", &min) &&
+	    !of_property_read_u32(np, "regulator-max-microvolt", &max) &&
+	    min == max)
+		ddata->vcom_programmed = true;
+
+	return 0;
+}
+
+static const struct regulator_desc max17135_vposneg_desc = {
+	.name = "vposneg",
+	.of_match = "vposneg",
+	.regulators_node = "regulators",
+	.id = 0,
+	.ops = &max17135_vposneg_ops,
+	.type = REGULATOR_VOLTAGE,
+	.owner = THIS_MODULE,
+};
+
+/* VCOM is negative; it is exposed as its magnitude, 0.5 V to 3.05 V. */
+static const struct regulator_desc max17135_vcom_desc = {
+	.name = "vcom",
+	.of_match = "vcom",
+	.regulators_node = "regulators",
+	.of_parse_cb = max17135_vcom_of_parse,
+	.supply_name = "vposneg",
+	.id = 1,
+	.ops = &max17135_vcom_ops,
+	.type = REGULATOR_VOLTAGE,
+	.owner = THIS_MODULE,
+	.n_voltages = 256,
+	.min_uV = 500000,
+	.uV_step = 10000,
+	.vsel_reg = MAX17135_REG_DVR,
+	.vsel_mask = 0xff,
+};
+
+static int max17135_read_delays(struct max17135 *ddata, const char *prop,
+				u32 *delays, bool *present)
+{
+	int ret, i;
+
+	if (!device_property_present(ddata->dev, prop))
+		return 0;
+
+	ret = device_property_read_u32_array(ddata->dev, prop, delays,
+					     MAX17135_NUM_DELAYS);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < MAX17135_NUM_DELAYS; i++)
+		if (delays[i] > 255)
+			return -EINVAL;
+
+	*present = true;
+
+	return 0;
+}
+
+/* The timing registers are volatile; the preset in the NVM is not touched. */
+static int max17135_write_delays(struct max17135 *ddata)
+{
+	int ret, i;
+
+	for (i = 0; i < MAX17135_NUM_DELAYS; i++) {
+		if (ddata->has_up_delays) {
+			ret = regmap_write(ddata->regmap, MAX17135_REG_T1 + i,
+					   ddata->up_delays[i]);
+			if (ret)
+				return ret;
+		}
+
+		if (ddata->has_down_delays) {
+			ret = regmap_write(ddata->regmap, MAX17135_REG_T5 + i,
+					   ddata->down_delays[i]);
+			if (ret)
+				return ret;
+		}
+	}
+
+	return 0;
+}
+
+static int max17135_read_off_delay(struct max17135 *ddata)
+{
+	unsigned int val, longest = 0;
+	int ret, i;
+
+	for (i = 0; i < MAX17135_NUM_DELAYS; i++) {
+		ret = regmap_read(ddata->regmap, MAX17135_REG_T5 + i, &val);
+		if (ret)
+			return ret;
+
+		longest = max(longest, val);
+	}
+
+	ddata->off_delay_ms = longest + MAX17135_OFF_MARGIN_MS;
+
+	return 0;
+}
+
+static int max17135_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct regulator_config config = { };
+	struct auxiliary_device *adev;
+	struct regulator_dev *rdev;
+	struct max17135 *ddata;
+	unsigned int val;
+	int id, irq, ret;
+
+	if (!i2c_check_functionality(client->adapter,
+				     I2C_FUNC_SMBUS_READ_WORD_DATA))
+		return -ENODEV;
+
+	ddata = devm_kzalloc_obj(dev, *ddata);
+	if (!ddata)
+		return -ENOMEM;
+
+	ddata->dev = dev;
+	init_completion(&ddata->pok_done);
+	i2c_set_clientdata(client, ddata);
+
+	ddata->regmap = devm_regmap_init_i2c(client, &max17135_regmap_config);
+	if (IS_ERR(ddata->regmap))
+		return dev_err_probe(dev, PTR_ERR(ddata->regmap),
+				     "failed to init regmap\n");
+
+	ddata->pok_gpio = devm_gpiod_get(dev, "pwr-good", GPIOD_IN);
+	if (IS_ERR(ddata->pok_gpio))
+		return dev_err_probe(dev, PTR_ERR(ddata->pok_gpio),
+				     "failed to get pwr-good gpio\n");
+
+	ddata->en_gpio = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+	if (IS_ERR(ddata->en_gpio))
+		return dev_err_probe(dev, PTR_ERR(ddata->en_gpio),
+				     "failed to get enable gpio\n");
+
+	ddata->cen_gpio = devm_gpiod_get_optional(dev, "vcom-ctrl",
+						  GPIOD_OUT_LOW);
+	if (IS_ERR(ddata->cen_gpio))
+		return dev_err_probe(dev, PTR_ERR(ddata->cen_gpio),
+				     "failed to get vcom-ctrl gpio\n");
+
+	ret = max17135_read_delays(ddata, "maxim,power-up-delays-ms",
+				   ddata->up_delays, &ddata->has_up_delays);
+	if (ret)
+		return dev_err_probe(dev, ret, "invalid power-up delays\n");
+
+	ret = max17135_read_delays(ddata, "maxim,power-down-delays-ms",
+				   ddata->down_delays, &ddata->has_down_delays);
+	if (ret)
+		return dev_err_probe(dev, ret, "invalid power-down delays\n");
+
+	ret = devm_regulator_get_enable(dev, "vin");
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to enable vin\n");
+
+	ret = devm_regulator_get_enable_optional(dev, "vdd");
+	if (ret && ret != -ENODEV)
+		return dev_err_probe(dev, ret, "failed to enable vdd\n");
+
+	/* The datasheet gives no start-up time; 10 ms is ample in practice. */
+	msleep(MAX17135_STARTUP_MS);
+
+	ret = regmap_read(ddata->regmap, MAX17135_REG_ID, &val);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to read the ID\n");
+	if (val != MAX17135_ID)
+		return dev_err_probe(dev, -ENODEV, "unexpected ID 0x%02x\n",
+				     val);
+
+	/* Start with everything off, also after a warm reboot. */
+	ret = regmap_update_bits(ddata->regmap, MAX17135_REG_ENABLE,
+				 MAX17135_ENABLE_EN | MAX17135_ENABLE_CEN, 0);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to clear enables\n");
+
+	ret = max17135_write_delays(ddata);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to write delays\n");
+
+	ret = max17135_read_off_delay(ddata);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to read delays\n");
+
+	ret = devm_add_action_or_reset(dev, max17135_power_off_action, ddata);
+	if (ret)
+		return ret;
+
+	irq = gpiod_to_irq(ddata->pok_gpio);
+	if (irq < 0)
+		return dev_err_probe(dev, irq, "failed to get pwr-good irq\n");
+
+	ret = devm_request_threaded_irq(dev, irq, NULL, max17135_pok_handler,
+					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+					"max17135-pok", ddata);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to request irq\n");
+
+	config.dev = dev;
+	config.driver_data = ddata;
+	config.regmap = ddata->regmap;
+
+	rdev = devm_regulator_register(dev, &max17135_vposneg_desc, &config);
+	if (IS_ERR(rdev))
+		return dev_err_probe(dev, PTR_ERR(rdev),
+				     "failed to register vposneg\n");
+
+	rdev = devm_regulator_register(dev, &max17135_vcom_desc, &config);
+	if (IS_ERR(rdev))
+		return dev_err_probe(dev, PTR_ERR(rdev),
+				     "failed to register vcom\n");
+
+	ret = regmap_read(ddata->regmap, MAX17135_REG_DVR, &val);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to read VCOM\n");
+
+	if (ddata->vcom_programmed)
+		ddata->vcom_sel = val;
+	else if (max17135_dvr_is_default(val))
+		dev_warn(dev, "VCOM is not calibrated, vcom stays off\n");
+
+	/* Last, so that it is removed first: the hwmon driver uses our I2C. */
+	id = (client->adapter->nr << 10) | client->addr;
+	adev = __devm_auxiliary_device_create(dev, KBUILD_MODNAME, "hwmon",
+					      NULL, id);
+	if (!adev)
+		return dev_err_probe(dev, -ENODEV,
+				     "failed to create hwmon device\n");
+
+	return 0;
+}
+
+static void max17135_shutdown(struct i2c_client *client)
+{
+	max17135_power_off(i2c_get_clientdata(client));
+}
+
+static int max17135_suspend(struct device *dev)
+{
+	struct max17135 *ddata = dev_get_drvdata(dev);
+
+	/* This only stops the temperature sensor. */
+	return regmap_set_bits(ddata->regmap, MAX17135_REG_CONFIG,
+			       MAX17135_CONFIG_SHUTDOWN);
+}
+
+static int max17135_resume(struct device *dev)
+{
+	struct max17135 *ddata = dev_get_drvdata(dev);
+	int ret;
+
+	/* The chip reloads its NVM presets if it lost power. */
+	ret = max17135_write_delays(ddata);
+	if (ret)
+		return ret;
+
+	if (ddata->vcom_programmed) {
+		ret = regmap_update_bits(ddata->regmap, MAX17135_REG_DVR,
+					 0xff, ddata->vcom_sel);
+		if (ret)
+			return ret;
+	}
+
+	return regmap_clear_bits(ddata->regmap, MAX17135_REG_CONFIG,
+				 MAX17135_CONFIG_SHUTDOWN);
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(max17135_pm_ops, max17135_suspend,
+				max17135_resume);
+
+static const struct of_device_id max17135_of_match[] = {
+	{ .compatible = "maxim,max17135" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, max17135_of_match);
+
+static struct i2c_driver max17135_driver = {
+	.driver = {
+		.name = "max17135",
+		.of_match_table = max17135_of_match,
+		.pm = pm_sleep_ptr(&max17135_pm_ops),
+	},
+	.probe = max17135_probe,
+	.shutdown = max17135_shutdown,
+};
+module_i2c_driver(max17135_driver);
+
+MODULE_AUTHOR("Michiel van Beers <michielvanbeers@gmail.com>");
+MODULE_DESCRIPTION("Maxim MAX17135 E-paper display PMIC driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/regulator/max17135.h b/include/linux/regulator/max17135.h
new file mode 100644
index 000000000000..8116e484ec39
--- /dev/null
+++ b/include/linux/regulator/max17135.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Maxim MAX17135 E-paper display PMIC */
+
+#ifndef __LINUX_REGULATOR_MAX17135_H
+#define __LINUX_REGULATOR_MAX17135_H
+
+struct device;
+
+enum max17135_temp_channel {
+	MAX17135_TEMP_INTERNAL,
+	MAX17135_TEMP_EXTERNAL,
+};
+
+int max17135_read_temp(struct device *dev,
+		       enum max17135_temp_channel channel,
+		       long *millicelsius);
+
+#endif

-- 
2.43.0



  parent reply	other threads:[~2026-12-02 16:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 16:43 [PATCH 0/3] regulator: Add Maxim MAX17135 E-paper PMIC driver Michiel van Beers via B4 Relay
2026-12-02 16:43 ` [PATCH 1/3] regulator: dt-bindings: Add Maxim MAX17135 Michiel van Beers via B4 Relay
2026-12-02 16:43 ` Michiel van Beers via B4 Relay [this message]
2026-12-02 16:54   ` [PATCH 2/3] regulator: Add Maxim MAX17135 driver sashiko-bot
2026-12-02 16:43 ` [PATCH 3/3] hwmon: Add Maxim MAX17135 temperature sensor driver Michiel van Beers via B4 Relay
2026-12-02 17:36   ` Andreas Kemnade
2026-12-02 16:54 ` [PATCH 0/3] regulator: Add Maxim MAX17135 E-paper PMIC driver sashiko-bot

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=20261202-max17135-v1-2-beae6b70d575@gmail.com \
    --to=devnull+michielvanbeers.gmail.com@kernel.org \
    --cc=andreas@kemnade.info \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=michielvanbeers@gmail.com \
    --cc=pmazzini@gmail.com \
    --cc=rdunlap@infradead.org \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.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