Devicetree
 help / color / mirror / Atom feed
* [PATCH 0/3] regulator: Add Maxim MAX17135 E-paper PMIC driver
@ 2026-12-02 16:43 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
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Michiel van Beers via B4 Relay @ 2026-12-02 16:43 UTC (permalink / raw)
  To: Michiel van Beers, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Guenter Roeck, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: linux-kernel, devicetree, linux-hwmon, linux-doc, Andreas Kemnade,
	Pablo Mazzini

This series adds support for the Maxim MAX17135, a power management IC
for E-paper displays. It provides the source and gate driver rails, a
VCOM amplifier and a temperature sensor. My use case is the Onyx Boox
Leaf e-reader (SDM636). The board devicetree is not upstream yet.

The layout follows the TPS65185, FP9931 and SY7636A drivers. Patch 1
adds the binding, patch 2 the regulator driver and patch 3 the hwmon
driver, which needs the header that patch 2 adds.

The chip keeps VCOM and the sequencing delays in a non-volatile memory
that survives only a few writes. The driver never writes it; both are
only set through the volatile registers.

Testing:
- Onyx Boox Leaf, 7.2.y kernel (sdm660-mainline) with this series and
  two local patches: devm_kzalloc() instead of devm_kzalloc_obj(), which
  7.2 lacks, and a board specific supply and preset check. 14 display
  updates, one of them after a suspend to idle and resume, all drew
  correctly. The die temperature reads 22.5 to 25.5 degrees C.
- dt_binding_check, arm64 build with W=1 and sparse, x86_64 build with
  W=1 and CONFIG_OF disabled, htmldocs: no warnings.

Not tested, as this board does not use them: switching with the EN and
CEN GPIOs, and setting VCOM and the delays from the devicetree. The
power good timeout and fault paths did not trigger.

AI disclosure: I prepared this series with Claude Code (Anthropic,
Claude Fable 5.2). It drafted the binding, the drivers and the commit
messages from the datasheet and my requirements. The builds and tests
above were run under my supervision; I checked the display in the
hardware tests, reviewed every line, and take responsibility for the
patches.

---
Michiel van Beers (3):
      regulator: dt-bindings: Add Maxim MAX17135
      regulator: Add Maxim MAX17135 driver
      hwmon: Add Maxim MAX17135 temperature sensor driver

 .../bindings/regulator/maxim,max17135.yaml         | 155 +++++
 Documentation/hwmon/index.rst                      |   1 +
 Documentation/hwmon/max17135.rst                   |  37 ++
 MAINTAINERS                                        |  10 +
 drivers/hwmon/Kconfig                              |  11 +
 drivers/hwmon/Makefile                             |   1 +
 drivers/hwmon/max17135-hwmon.c                     | 135 +++++
 drivers/regulator/Kconfig                          |  14 +
 drivers/regulator/Makefile                         |   1 +
 drivers/regulator/max17135.c                       | 643 +++++++++++++++++++++
 include/linux/regulator/max17135.h                 |  18 +
 11 files changed, 1026 insertions(+)
---
base-commit: b042f5dd8365861242946476b0e298bb95a32927
change-id: 20261202-max17135-0e9cb4752f8f

Best regards,
--  
Michiel van Beers <michielvanbeers@gmail.com>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] regulator: dt-bindings: Add Maxim MAX17135
  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 ` Michiel van Beers via B4 Relay
  2026-12-02 16:43 ` [PATCH 2/3] regulator: Add Maxim MAX17135 driver Michiel van Beers via B4 Relay
  2026-12-02 16:43 ` [PATCH 3/3] hwmon: Add Maxim MAX17135 temperature sensor driver Michiel van Beers via B4 Relay
  2 siblings, 0 replies; 6+ messages in thread
From: Michiel van Beers via B4 Relay @ 2026-12-02 16:43 UTC (permalink / raw)
  To: Michiel van Beers, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Guenter Roeck, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: linux-kernel, devicetree, linux-hwmon, linux-doc, Andreas Kemnade,
	Pablo Mazzini

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

The MAX17135 is a power management IC for E-paper displays. It provides
the source and gate driver rails, a VCOM amplifier with a non-volatile
preset and a temperature sensor.

Describe the whole chip, including the pins and settings that a first
driver does not use yet.

Signed-off-by: Michiel van Beers <michielvanbeers@gmail.com>
---
 .../bindings/regulator/maxim,max17135.yaml         | 155 +++++++++++++++++++++
 1 file changed, 155 insertions(+)

diff --git a/Documentation/devicetree/bindings/regulator/maxim,max17135.yaml b/Documentation/devicetree/bindings/regulator/maxim,max17135.yaml
new file mode 100644
index 000000000000..a4883827e58f
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/maxim,max17135.yaml
@@ -0,0 +1,155 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/maxim,max17135.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Maxim MAX17135 Power Management IC for E-Paper Displays
+
+maintainers:
+  - Michiel van Beers <michielvanbeers@gmail.com>
+
+description: |
+  The MAX17135 powers an electrophoretic (E-paper) display. It provides the
+  source driver rails POS and NEG (+15 V and -15 V), the gate driver rails
+  GVDD and GVEE, a VCOM amplifier with a non-volatile preset, and a
+  temperature sensor with an internal and an external diode channel.
+
+  POS, NEG, GVDD and GVEE are sequenced together and are described as one
+  regulator, vposneg. VCOM is a second regulator supplied by the first.
+
+  Datasheet:
+  https://www.analog.com/media/en/technical-documentation/data-sheets/MAX17135.pdf
+
+properties:
+  compatible:
+    const: maxim,max17135
+
+  reg:
+    maxItems: 1
+
+  enable-gpios:
+    description:
+      EN pin. Starts the power-up sequence of the display rails. If absent,
+      the rails are switched through the Enable register and the pin must be
+      low or unconnected.
+    maxItems: 1
+
+  vcom-ctrl-gpios:
+    description:
+      CEN pin. Enables the VCOM output. If absent, VCOM is switched through
+      the Enable register and the pin must be low or unconnected.
+    maxItems: 1
+
+  pwr-good-gpios:
+    description:
+      POK pin. High when all display rails are in regulation.
+    maxItems: 1
+
+  interrupts:
+    description:
+      FLT pin. Open drain, low while a fault is latched.
+    maxItems: 1
+
+  vin-supply:
+    description:
+      Supply of the IN and INN pins (2.7 V to 5.5 V).
+
+  vdd-supply:
+    description:
+      Supply of the VDD pin, the logic and I2C supply (1.6 V to 5.5 V).
+
+  maxim,power-up-delays-ms:
+    description:
+      Delays t1 to t4 of the power-up sequence, for GVEE, NEG, POS and GVDD
+      in that order. If absent, the values preset in the non-volatile memory
+      are used.
+    minItems: 4
+    maxItems: 4
+    items:
+      maximum: 255
+
+  maxim,power-down-delays-ms:
+    description:
+      Delays t5 to t8 of the power-down sequence, for GVDD, POS, NEG and
+      GVEE in that order. If absent, the values preset in the non-volatile
+      memory are used.
+    minItems: 4
+    maxItems: 4
+    items:
+      maximum: 255
+
+  regulators:
+    type: object
+    additionalProperties: false
+
+    properties:
+      vposneg:
+        type: object
+        $ref: /schemas/regulator/regulator.yaml#
+        unevaluatedProperties: false
+        description:
+          The display rails POS, NEG, GVDD and GVEE.
+
+      vcom:
+        type: object
+        $ref: /schemas/regulator/regulator.yaml#
+        unevaluatedProperties: false
+        description:
+          The VCOM output. The voltage is negative; it is given as a
+          positive magnitude from 500000 to 3050000 microvolts. If no
+          voltage is given, the value preset in the non-volatile memory is
+          used.
+
+        properties:
+          vposneg-supply:
+            description:
+              The vposneg regulator of this chip.
+
+        required:
+          - vposneg-supply
+
+required:
+  - compatible
+  - reg
+  - pwr-good-gpios
+  - vin-supply
+  - regulators
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@48 {
+            compatible = "maxim,max17135";
+            reg = <0x48>;
+            pwr-good-gpios = <&gpio2 7 GPIO_ACTIVE_HIGH>;
+            enable-gpios = <&gpio2 8 GPIO_ACTIVE_HIGH>;
+            vcom-ctrl-gpios = <&gpio2 9 GPIO_ACTIVE_HIGH>;
+            interrupts-extended = <&gpio2 0 IRQ_TYPE_LEVEL_LOW>;
+            vin-supply = <&reg_epd_3v3>;
+            vdd-supply = <&reg_1v8>;
+            maxim,power-up-delays-ms = <30 60 90 120>;
+            maxim,power-down-delays-ms = <30 60 90 120>;
+
+            regulators {
+                epd_vposneg: vposneg {
+                    regulator-name = "epd-vposneg";
+                };
+
+                vcom {
+                    regulator-name = "epd-vcom";
+                    regulator-min-microvolt = <1250000>;
+                    regulator-max-microvolt = <1250000>;
+                    vposneg-supply = <&epd_vposneg>;
+                };
+            };
+        };
+    };

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] regulator: Add Maxim MAX17135 driver
  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
  2026-12-02 16:54   ` sashiko-bot
  2026-12-02 16:43 ` [PATCH 3/3] hwmon: Add Maxim MAX17135 temperature sensor driver Michiel van Beers via B4 Relay
  2 siblings, 1 reply; 6+ messages in thread
From: Michiel van Beers via B4 Relay @ 2026-12-02 16:43 UTC (permalink / raw)
  To: Michiel van Beers, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Guenter Roeck, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: linux-kernel, devicetree, linux-hwmon, linux-doc, Andreas Kemnade,
	Pablo Mazzini

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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] hwmon: Add Maxim MAX17135 temperature sensor driver
  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 ` [PATCH 2/3] regulator: Add Maxim MAX17135 driver Michiel van Beers via B4 Relay
@ 2026-12-02 16:43 ` Michiel van Beers via B4 Relay
  2026-12-02 17:36   ` Andreas Kemnade
  2 siblings, 1 reply; 6+ messages in thread
From: Michiel van Beers via B4 Relay @ 2026-12-02 16:43 UTC (permalink / raw)
  To: Michiel van Beers, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Guenter Roeck, Jonathan Corbet,
	Shuah Khan, Randy Dunlap
  Cc: linux-kernel, devicetree, linux-hwmon, linux-doc, Andreas Kemnade,
	Pablo Mazzini

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

The MAX17135 E-paper display PMIC has a temperature sensor that measures
the die and an external diode. Add a driver for it. The driver binds to
the auxiliary device that the regulator driver creates.

Reading the external channel fails with -ENODATA while the chip reports
the diode as open or shorted.

Signed-off-by: Michiel van Beers <michielvanbeers@gmail.com>
---
 Documentation/hwmon/index.rst    |   1 +
 Documentation/hwmon/max17135.rst |  37 +++++++++++
 MAINTAINERS                      |   2 +
 drivers/hwmon/Kconfig            |  11 ++++
 drivers/hwmon/Makefile           |   1 +
 drivers/hwmon/max17135-hwmon.c   | 135 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 187 insertions(+)

diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
index 199ca79621e9..a4207f737197 100644
--- a/Documentation/hwmon/index.rst
+++ b/Documentation/hwmon/index.rst
@@ -164,6 +164,7 @@ Hardware Monitoring Kernel Drivers
    max1619
    max16601
    max1668
+   max17135
    max17616
    max197
    max20730
diff --git a/Documentation/hwmon/max17135.rst b/Documentation/hwmon/max17135.rst
new file mode 100644
index 000000000000..dad24d6f677e
--- /dev/null
+++ b/Documentation/hwmon/max17135.rst
@@ -0,0 +1,37 @@
+.. SPDX-License-Identifier: GPL-2.0-only
+
+Kernel driver max17135-hwmon
+============================
+
+Supported chips:
+
+  * Maxim MAX17135
+
+    Prefix: 'max17135'
+
+    Datasheet:
+
+	https://www.analog.com/media/en/technical-documentation/data-sheets/MAX17135.pdf
+
+Author: Michiel van Beers <michielvanbeers@gmail.com>
+
+Description
+-----------
+
+The MAX17135 is a power management IC for E-paper displays. This driver
+supports its temperature sensor, which measures the temperature of the die and
+of an external diode.
+
+Both channels have a resolution of 0.5 degrees Celsius. The chip converts once
+per second by default.
+
+Sysfs entries
+-------------
+
+=============== ==============================================================
+temp1_input     Die temperature
+temp2_input     Temperature of the external diode. Reading it fails with
+                ENODATA while temp2_fault is set.
+temp2_fault     1 if the external diode is open or shorted, for example
+                because the board has none
+=============== ==============================================================
diff --git a/MAINTAINERS b/MAINTAINERS
index 6b2af23ec2bf..6bc6d22339f8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16496,6 +16496,8 @@ M:	Michiel van Beers <michielvanbeers@gmail.com>
 L:	linux-kernel@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/regulator/maxim,max17135.yaml
+F:	Documentation/hwmon/max17135.rst
+F:	drivers/hwmon/max17135-hwmon.c
 F:	drivers/regulator/max17135.c
 F:	include/linux/regulator/max17135.h
 
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 247507a4ddde..2f6d5d9517ef 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1311,6 +1311,17 @@ config SENSORS_MAX1668
 	  This driver can also be built as a module. If so, the module
 	  will be called max1668.
 
+config SENSORS_MAX17135
+	tristate "Maxim MAX17135 temperature sensor"
+	depends on REGULATOR_MAX17135
+	help
+	  If you say yes here you get support for the temperature sensor
+	  of the Maxim MAX17135 E-paper display PMIC: the die temperature
+	  and an external diode.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called max17135-hwmon.
+
 config SENSORS_MAX197
 	tristate "Maxim MAX197 and compatibles"
 	help
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index d4c345ed7261..a96bdb037592 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -162,6 +162,7 @@ obj-$(CONFIG_SENSORS_MAX127)	+= max127.o
 obj-$(CONFIG_SENSORS_MAX16065)	+= max16065.o
 obj-$(CONFIG_SENSORS_MAX1619)	+= max1619.o
 obj-$(CONFIG_SENSORS_MAX1668)	+= max1668.o
+obj-$(CONFIG_SENSORS_MAX17135)	+= max17135-hwmon.o
 obj-$(CONFIG_SENSORS_MAX197)	+= max197.o
 obj-$(CONFIG_SENSORS_MAX31722)	+= max31722.o
 obj-$(CONFIG_SENSORS_MAX31730)	+= max31730.o
diff --git a/drivers/hwmon/max17135-hwmon.c b/drivers/hwmon/max17135-hwmon.c
new file mode 100644
index 000000000000..c49f98e8c8e3
--- /dev/null
+++ b/drivers/hwmon/max17135-hwmon.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Temperature sensor of the Maxim MAX17135 E-paper display PMIC
+ *
+ * Copyright (C) 2026 Michiel van Beers
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/bits.h>
+#include <linux/device.h>
+#include <linux/device/devres.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/hwmon.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/regulator/max17135.h>
+#include <linux/types.h>
+
+#define MAX17135_REG_STATUS	0x05
+#define MAX17135_STATUS_OPEN	BIT(1)
+#define MAX17135_STATUS_SHORT	BIT(2)
+
+struct max17135_hwmon {
+	struct device *chip;
+	struct regmap *regmap;
+};
+
+static int max17135_hwmon_diode_fault(struct max17135_hwmon *hwmon, long *val)
+{
+	unsigned int status;
+	int ret;
+
+	ret = regmap_read(hwmon->regmap, MAX17135_REG_STATUS, &status);
+	if (ret)
+		return ret;
+
+	*val = !!(status & (MAX17135_STATUS_OPEN | MAX17135_STATUS_SHORT));
+
+	return 0;
+}
+
+static int max17135_hwmon_read_input(struct max17135_hwmon *hwmon, int channel,
+				     long *val)
+{
+	long fault;
+	int ret;
+
+	if (channel == 0)
+		return max17135_read_temp(hwmon->chip, MAX17135_TEMP_INTERNAL,
+					  val);
+
+	/* Without a working diode the register holds a dummy value. */
+	ret = max17135_hwmon_diode_fault(hwmon, &fault);
+	if (ret)
+		return ret;
+	if (fault)
+		return -ENODATA;
+
+	return max17135_read_temp(hwmon->chip, MAX17135_TEMP_EXTERNAL, val);
+}
+
+static int max17135_hwmon_read(struct device *dev,
+			       enum hwmon_sensor_types type, u32 attr,
+			       int channel, long *val)
+{
+	struct max17135_hwmon *hwmon = dev_get_drvdata(dev);
+
+	switch (attr) {
+	case hwmon_temp_input:
+		return max17135_hwmon_read_input(hwmon, channel, val);
+	case hwmon_temp_fault:
+		return max17135_hwmon_diode_fault(hwmon, val);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static const struct hwmon_channel_info * const max17135_hwmon_info[] = {
+	HWMON_CHANNEL_INFO(temp,
+			   HWMON_T_INPUT,
+			   HWMON_T_INPUT | HWMON_T_FAULT),
+	NULL
+};
+
+static const struct hwmon_ops max17135_hwmon_ops = {
+	.visible = 0444,
+	.read = max17135_hwmon_read,
+};
+
+static const struct hwmon_chip_info max17135_hwmon_chip_info = {
+	.ops = &max17135_hwmon_ops,
+	.info = max17135_hwmon_info,
+};
+
+static int max17135_hwmon_probe(struct auxiliary_device *adev,
+				const struct auxiliary_device_id *id)
+{
+	struct device *dev = &adev->dev;
+	struct max17135_hwmon *hwmon;
+	struct device *hwmon_dev;
+
+	hwmon = devm_kzalloc_obj(dev, *hwmon);
+	if (!hwmon)
+		return -ENOMEM;
+
+	hwmon->chip = dev->parent;
+	hwmon->regmap = dev_get_regmap(dev->parent, NULL);
+	if (!hwmon->regmap)
+		return -ENODEV;
+
+	hwmon_dev = devm_hwmon_device_register_with_info(dev, "max17135",
+							 hwmon,
+							 &max17135_hwmon_chip_info,
+							 NULL);
+
+	return PTR_ERR_OR_ZERO(hwmon_dev);
+}
+
+static const struct auxiliary_device_id max17135_hwmon_ids[] = {
+	{ .name = "max17135.hwmon" },
+	{ }
+};
+MODULE_DEVICE_TABLE(auxiliary, max17135_hwmon_ids);
+
+static struct auxiliary_driver max17135_hwmon_driver = {
+	.probe = max17135_hwmon_probe,
+	.id_table = max17135_hwmon_ids,
+};
+module_auxiliary_driver(max17135_hwmon_driver);
+
+MODULE_AUTHOR("Michiel van Beers <michielvanbeers@gmail.com>");
+MODULE_DESCRIPTION("Maxim MAX17135 temperature sensor driver");
+MODULE_IMPORT_NS("MAX17135");
+MODULE_LICENSE("GPL");

-- 
2.43.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] regulator: Add Maxim MAX17135 driver
  2026-12-02 16:43 ` [PATCH 2/3] regulator: Add Maxim MAX17135 driver Michiel van Beers via B4 Relay
@ 2026-12-02 16:54   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-02 16:54 UTC (permalink / raw)
  To: Michiel van Beers; +Cc: devicetree, linux-hwmon, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] regulator: max17135: range clamping marks VCOM programmed in
  max17135_probe()
--

commit 35331644fea93af4e5f64e9e127a8eda105b1887
Author: Michiel van Beers <michielvanbeers@gmail.com>

regulator: Add Maxim MAX17135 driver

This commit adds a regulator driver for the Maxim MAX17135 E-paper display
PMIC, exposing the vposneg and vcom regulators and creating an auxiliary
device for the temperature sensor.

> diff --git a/drivers/regulator/max17135.c b/drivers/regulator/max17135.c
> new file mode 100644
> index 0000000000000..b192a228d0aa6
> --- /dev/null
> +++ b/drivers/regulator/max17135.c
[ ... ]
> +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;
> +}

[Severity: Medium]
Can constraint clamping during devm_regulator_register() prematurely mark
ddata->vcom_programmed true when the device tree defines a voltage range
(min < max)?

When both regulator-min-microvolt and regulator-max-microvolt are
specified, of_get_regulation_constraints() sets constraints->apply_uV =
true.  If the chip's default MAX17135_REG_DVR value (such as
MAX17135_DVR_POR at 3.05 V or MAX17135_DVR_FACTORY at 1.77 V) falls
outside [min, max], machine_constraints_voltage() clamps the voltage into
range by calling max17135_vcom_set_voltage_sel() before
devm_regulator_register() returns.

That writes the uncalibrated range boundary into MAX17135_REG_DVR and sets
ddata->vcom_programmed = true, which suppresses the uncalibrated VCOM
warning in max17135_probe() and allows max17135_vcom_enable() to enable
VCOM at the boundary voltage before a consumer sets a calibrated value.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-max17135-v1-0-beae6b70d575@gmail.com?part=2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] hwmon: Add Maxim MAX17135 temperature sensor driver
  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
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Kemnade @ 2026-12-02 17:36 UTC (permalink / raw)
  To: Michiel van Beers via B4 Relay
  Cc: michielvanbeers, Liam Girdwood, Mark Brown, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Guenter Roeck, Jonathan Corbet,
	Shuah Khan, Randy Dunlap, linux-kernel, devicetree, linux-hwmon,
	linux-doc, Pablo Mazzini

On Wed, 02 Dec 2026 17:43:40 +0100
Michiel van Beers via B4 Relay <devnull+michielvanbeers.gmail.com@kernel.org> wrote:

> From: Michiel van Beers <michielvanbeers@gmail.com>
> 
> The MAX17135 E-paper display PMIC has a temperature sensor that measures
> the die and an external diode. Add a driver for it. The driver binds to
> the auxiliary device that the regulator driver creates.
> 
> Reading the external channel fails with -ENODATA while the chip reports
> the diode as open or shorted.
> 
just in general: do have something cooking to use temperature you graphics
driver? Pinebook folks use an non-mainline iio driver instead and
use the iio in-kernel driver.  

bindings/display/repaper.txt
defines a separate thermal-zone and the corresponding  the drm driver
uses thermal zone api to get temperature. For Kobos (display is not in mainline)
I currntly do the same. Another dirty way of doing things...

It is on my todo list to provide a clean interface.

Regards,
Andreas

> Signed-off-by: Michiel van Beers <michielvanbeers@gmail.com>
> ---
>  Documentation/hwmon/index.rst    |   1 +
>  Documentation/hwmon/max17135.rst |  37 +++++++++++
>  MAINTAINERS                      |   2 +
>  drivers/hwmon/Kconfig            |  11 ++++
>  drivers/hwmon/Makefile           |   1 +
>  drivers/hwmon/max17135-hwmon.c   | 135 +++++++++++++++++++++++++++++++++++++++
>  6 files changed, 187 insertions(+)
> 
> diff --git a/Documentation/hwmon/index.rst b/Documentation/hwmon/index.rst
> index 199ca79621e9..a4207f737197 100644
> --- a/Documentation/hwmon/index.rst
> +++ b/Documentation/hwmon/index.rst
> @@ -164,6 +164,7 @@ Hardware Monitoring Kernel Drivers
>     max1619
>     max16601
>     max1668
> +   max17135
>     max17616
>     max197
>     max20730
> diff --git a/Documentation/hwmon/max17135.rst b/Documentation/hwmon/max17135.rst
> new file mode 100644
> index 000000000000..dad24d6f677e
> --- /dev/null
> +++ b/Documentation/hwmon/max17135.rst
> @@ -0,0 +1,37 @@
> +.. SPDX-License-Identifier: GPL-2.0-only
> +
> +Kernel driver max17135-hwmon
> +============================
> +
> +Supported chips:
> +
> +  * Maxim MAX17135
> +
> +    Prefix: 'max17135'
> +
> +    Datasheet:
> +
> +	https://www.analog.com/media/en/technical-documentation/data-sheets/MAX17135.pdf
> +
> +Author: Michiel van Beers <michielvanbeers@gmail.com>
> +
> +Description
> +-----------
> +
> +The MAX17135 is a power management IC for E-paper displays. This driver
> +supports its temperature sensor, which measures the temperature of the die and
> +of an external diode.
> +
> +Both channels have a resolution of 0.5 degrees Celsius. The chip converts once
> +per second by default.
> +
> +Sysfs entries
> +-------------
> +
> +=============== ==============================================================
> +temp1_input     Die temperature
> +temp2_input     Temperature of the external diode. Reading it fails with
> +                ENODATA while temp2_fault is set.
> +temp2_fault     1 if the external diode is open or shorted, for example
> +                because the board has none
> +=============== ==============================================================
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 6b2af23ec2bf..6bc6d22339f8 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -16496,6 +16496,8 @@ M:	Michiel van Beers <michielvanbeers@gmail.com>
>  L:	linux-kernel@vger.kernel.org
>  S:	Maintained
>  F:	Documentation/devicetree/bindings/regulator/maxim,max17135.yaml
> +F:	Documentation/hwmon/max17135.rst
> +F:	drivers/hwmon/max17135-hwmon.c
>  F:	drivers/regulator/max17135.c
>  F:	include/linux/regulator/max17135.h
>  
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 247507a4ddde..2f6d5d9517ef 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1311,6 +1311,17 @@ config SENSORS_MAX1668
>  	  This driver can also be built as a module. If so, the module
>  	  will be called max1668.
>  
> +config SENSORS_MAX17135
> +	tristate "Maxim MAX17135 temperature sensor"
> +	depends on REGULATOR_MAX17135
> +	help
> +	  If you say yes here you get support for the temperature sensor
> +	  of the Maxim MAX17135 E-paper display PMIC: the die temperature
> +	  and an external diode.
> +
> +	  This driver can also be built as a module. If so, the module
> +	  will be called max17135-hwmon.
> +
>  config SENSORS_MAX197
>  	tristate "Maxim MAX197 and compatibles"
>  	help
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index d4c345ed7261..a96bdb037592 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -162,6 +162,7 @@ obj-$(CONFIG_SENSORS_MAX127)	+= max127.o
>  obj-$(CONFIG_SENSORS_MAX16065)	+= max16065.o
>  obj-$(CONFIG_SENSORS_MAX1619)	+= max1619.o
>  obj-$(CONFIG_SENSORS_MAX1668)	+= max1668.o
> +obj-$(CONFIG_SENSORS_MAX17135)	+= max17135-hwmon.o
>  obj-$(CONFIG_SENSORS_MAX197)	+= max197.o
>  obj-$(CONFIG_SENSORS_MAX31722)	+= max31722.o
>  obj-$(CONFIG_SENSORS_MAX31730)	+= max31730.o
> diff --git a/drivers/hwmon/max17135-hwmon.c b/drivers/hwmon/max17135-hwmon.c
> new file mode 100644
> index 000000000000..c49f98e8c8e3
> --- /dev/null
> +++ b/drivers/hwmon/max17135-hwmon.c
> @@ -0,0 +1,135 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Temperature sensor of the Maxim MAX17135 E-paper display PMIC
> + *
> + * Copyright (C) 2026 Michiel van Beers
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/bits.h>
> +#include <linux/device.h>
> +#include <linux/device/devres.h>
> +#include <linux/err.h>
> +#include <linux/errno.h>
> +#include <linux/hwmon.h>
> +#include <linux/module.h>
> +#include <linux/regmap.h>
> +#include <linux/regulator/max17135.h>
> +#include <linux/types.h>
> +
> +#define MAX17135_REG_STATUS	0x05
> +#define MAX17135_STATUS_OPEN	BIT(1)
> +#define MAX17135_STATUS_SHORT	BIT(2)
> +
> +struct max17135_hwmon {
> +	struct device *chip;
> +	struct regmap *regmap;
> +};
> +
> +static int max17135_hwmon_diode_fault(struct max17135_hwmon *hwmon, long *val)
> +{
> +	unsigned int status;
> +	int ret;
> +
> +	ret = regmap_read(hwmon->regmap, MAX17135_REG_STATUS, &status);
> +	if (ret)
> +		return ret;
> +
> +	*val = !!(status & (MAX17135_STATUS_OPEN | MAX17135_STATUS_SHORT));
> +
> +	return 0;
> +}
> +
> +static int max17135_hwmon_read_input(struct max17135_hwmon *hwmon, int channel,
> +				     long *val)
> +{
> +	long fault;
> +	int ret;
> +
> +	if (channel == 0)
> +		return max17135_read_temp(hwmon->chip, MAX17135_TEMP_INTERNAL,
> +					  val);
> +
> +	/* Without a working diode the register holds a dummy value. */
> +	ret = max17135_hwmon_diode_fault(hwmon, &fault);
> +	if (ret)
> +		return ret;
> +	if (fault)
> +		return -ENODATA;
> +
> +	return max17135_read_temp(hwmon->chip, MAX17135_TEMP_EXTERNAL, val);
> +}
> +
> +static int max17135_hwmon_read(struct device *dev,
> +			       enum hwmon_sensor_types type, u32 attr,
> +			       int channel, long *val)
> +{
> +	struct max17135_hwmon *hwmon = dev_get_drvdata(dev);
> +
> +	switch (attr) {
> +	case hwmon_temp_input:
> +		return max17135_hwmon_read_input(hwmon, channel, val);
> +	case hwmon_temp_fault:
> +		return max17135_hwmon_diode_fault(hwmon, val);
> +	default:
> +		return -EOPNOTSUPP;
> +	}
> +}
> +
> +static const struct hwmon_channel_info * const max17135_hwmon_info[] = {
> +	HWMON_CHANNEL_INFO(temp,
> +			   HWMON_T_INPUT,
> +			   HWMON_T_INPUT | HWMON_T_FAULT),
> +	NULL
> +};
> +
> +static const struct hwmon_ops max17135_hwmon_ops = {
> +	.visible = 0444,
> +	.read = max17135_hwmon_read,
> +};
> +
> +static const struct hwmon_chip_info max17135_hwmon_chip_info = {
> +	.ops = &max17135_hwmon_ops,
> +	.info = max17135_hwmon_info,
> +};
> +
> +static int max17135_hwmon_probe(struct auxiliary_device *adev,
> +				const struct auxiliary_device_id *id)
> +{
> +	struct device *dev = &adev->dev;
> +	struct max17135_hwmon *hwmon;
> +	struct device *hwmon_dev;
> +
> +	hwmon = devm_kzalloc_obj(dev, *hwmon);
> +	if (!hwmon)
> +		return -ENOMEM;
> +
> +	hwmon->chip = dev->parent;
> +	hwmon->regmap = dev_get_regmap(dev->parent, NULL);
> +	if (!hwmon->regmap)
> +		return -ENODEV;
> +
> +	hwmon_dev = devm_hwmon_device_register_with_info(dev, "max17135",
> +							 hwmon,
> +							 &max17135_hwmon_chip_info,
> +							 NULL);
> +
> +	return PTR_ERR_OR_ZERO(hwmon_dev);
> +}
> +
> +static const struct auxiliary_device_id max17135_hwmon_ids[] = {
> +	{ .name = "max17135.hwmon" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(auxiliary, max17135_hwmon_ids);
> +
> +static struct auxiliary_driver max17135_hwmon_driver = {
> +	.probe = max17135_hwmon_probe,
> +	.id_table = max17135_hwmon_ids,
> +};
> +module_auxiliary_driver(max17135_hwmon_driver);
> +
> +MODULE_AUTHOR("Michiel van Beers <michielvanbeers@gmail.com>");
> +MODULE_DESCRIPTION("Maxim MAX17135 temperature sensor driver");
> +MODULE_IMPORT_NS("MAX17135");
> +MODULE_LICENSE("GPL");
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-02 17:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 2/3] regulator: Add Maxim MAX17135 driver Michiel van Beers via B4 Relay
2026-12-02 16:54   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox