All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Kemnade <andreas@kemnade.info>
To: Michiel van Beers via B4 Relay
	<devnull+michielvanbeers.gmail.com@kernel.org>
Cc: 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>,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
	Pablo Mazzini <pmazzini@gmail.com>
Subject: Re: [PATCH 3/3] hwmon: Add Maxim MAX17135 temperature sensor driver
Date: Wed, 2 Dec 2026 18:36:02 +0100	[thread overview]
Message-ID: <20261202183602.0dc10175@kemnade.info> (raw)
In-Reply-To: <20261202-max17135-v1-3-beae6b70d575@gmail.com>

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");
> 


  reply	other threads:[~2026-12-02 17:36 UTC|newest]

Thread overview: 11+ 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
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
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
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
2026-12-02 16:43   ` Michiel van Beers via B4 Relay
2026-12-02 17:36   ` Andreas Kemnade [this message]
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=20261202183602.0dc10175@kemnade.info \
    --to=andreas@kemnade.info \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=devnull+michielvanbeers.gmail.com@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.