From: Michiel van Beers Date: Wed, 02 Dec 2026 17:43:40 +0100 Subject: [PATCH 3/3] hwmon: Add Maxim MAX17135 temperature sensor driver MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-max17135-v1-3-beae6b70d575@gmail.com> References: <20261202-max17135-v1-0-beae6b70d575@gmail.com> In-Reply-To: <20261202-max17135-v1-0-beae6b70d575@gmail.com> 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@vger.kernel.org, devicetree@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, Andreas Kemnade , Pablo Mazzini X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796229839; l=7979; i=michielvanbeers@gmail.com; s=20261107; h=from:subject:message-id; bh=ig8ckwjbXNhZU/YaGbyRLLO2w8/7nONSdlxon1zxFfc=; b=KbJoRL1tkgLzLHA2knoo/JmVsAGK0JEVjILr2y5W4/TKxw6gKIKdJcXkh0qFszfA7qXFpkQf7 evACw6tcdThAUc89etuPjZpUIIbNnswWitbZipswonBhhNm2wEIiBrQ X-Developer-Key: i=michielvanbeers@gmail.com; a=ed25519; pk=C+lOje7u3+2x3o2NLMXrwz2veP2++eXfIi9MtYsUo4k= X-Endpoint-Received: by B4 Relay for michielvanbeers@gmail.com/20261107 with auth_id=1444 List-Id: B4 Relay Submissions 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 --- 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 + +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 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 "); +MODULE_DESCRIPTION("Maxim MAX17135 temperature sensor driver"); +MODULE_IMPORT_NS("MAX17135"); +MODULE_LICENSE("GPL"); -- 2.43.0