Linux Documentation
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com>
Cc: Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Jean Delvare <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: Re: [PATCH v2 3/3] hwmon: (lm75) add MAX31875 support
Date: Thu, 24 Sep 2026 09:46:51 -0700	[thread overview]
Message-ID: <29aade07-55a9-4d32-92e1-c7f410982f29@roeck-us.net> (raw)
In-Reply-To: <20260924084121.82-4-johnerasmusmari.geronimo@analog.com>

On Thu, Sep 24, 2026 at 04:41:21PM +0800, John Erasmus Mari Geronimo wrote:
> Add support for the Maxim MAX31875 I2C temperature sensor by
> extending the lm75 driver. The MAX31875 features a 16-bit
> configuration register, configurable resolution (8, 9, 10, or
> 12 bits), and selectable conversion rates (125ms, 250ms, 1s, 4s).
> 
> Suggested-by: Guenter Roeck <linux@roeck-us.net>
> Signed-off-by: John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com>
> ---
>  drivers/hwmon/Kconfig |  2 +-
>  drivers/hwmon/lm75.c  | 25 +++++++++++++++++++++++++
>  2 files changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index e4c4f2b09732d..c68b6c3c2f866 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -1525,7 +1525,7 @@ config SENSORS_LM75
>  	  If you say yes here you get support for one common type of
>  	  temperature sensor chip, with models including:
>  
> -		- Analog Devices ADT75
> +		- Analog Devices ADT75, MAX31875
>  		- Atmel (now Microchip) AT30TS74
>  		- Dallas Semiconductor DS75, DS1775 and DS7505
>  		- Global Mixed-mode Technology (GMT) G751
> diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
> index 104149a03bad0..886f83c8b0420 100644
> --- a/drivers/hwmon/lm75.c
> +++ b/drivers/hwmon/lm75.c
> @@ -39,6 +39,7 @@ enum lm75_type {		/* keep sorted in alphabetical order */
>  	max6625,
>  	max6626,
>  	max31725,
> +	max31875,
>  	mcp980x,
>  	p3t1750,
>  	p3t1755,
> @@ -223,6 +224,15 @@ static const struct lm75_params device_params[] = {
>  		.default_resolution = 16,
>  		.default_sample_time = MSEC_PER_SEC / 20,
>  	},
> +	[max31875] = {
> +		.config_reg_16bits = true,
> +		.default_resolution = 10,
> +		.resolutions = (u8 []) {8, 9, 10, 12 },

This isn't how resolutions vs. sample time is supposed to be handled.
For most of the lm75 compatible chips, the sample time is associated
with the resolution: Changing the sample time changes the resolution.
This is not the case here: the chip has separate configuration register
bits for sample time and resolution, and the resolution does not change
automatically if the sample time changes.  The above associates
8/9/10/12 bit resolution with the 125/250/1000/4000 sample times,
which is wrong. Instead, .resolutions should not be set at all,
reflecting the default 10 bit resolution.

> +		.default_sample_time = 4000,
> +		.num_sample_times = 4,
> +		.sample_times = (unsigned int []){ 125, 250, 1000, 4000 },
> +		.alarm = true,
> +	},
>  	[tcn75] = {
>  		.default_resolution = 9,
>  		.default_sample_time = MSEC_PER_SEC / 18,
> @@ -421,6 +431,9 @@ static int lm75_read(struct device *dev, enum hwmon_sensor_types type,
>  			case tmp112:
>  				*val = !!(regval & BIT(13)) == !!(regval & BIT(2));
>  				break;
> +			case max31875:
> +				*val = (regval >> 7) & 0x1;

Please use
				*val = !!(regval & BIT(7));
to match the rest of the code. 

Thanks,
Guenter

> +				break;
>  			default:
>  				return -EINVAL;
>  			}
> @@ -495,6 +508,13 @@ static int lm75_update_interval(struct device *dev, long val)
>  			return err;
>  		data->sample_time = data->params->sample_times[index];
>  		break;
> +	case max31875:
> +		err = regmap_update_bits(data->regmap, LM75_REG_CONF,
> +					 0x0600, (3 - index) << 9);
> +		if (err < 0)
> +			return err;
> +		data->sample_time = data->params->sample_times[index];
> +		break;
>  	case pct2075:
>  		err = regmap_write(data->regmap, PCT2075_REG_IDLE, index + 1);
>  		if (err)
> @@ -848,6 +868,7 @@ static const struct i2c_device_id lm75_i2c_ids[] = {
>  	{ .name = "max6626", .driver_data = max6626 },
>  	{ .name = "max31725", .driver_data = max31725 },
>  	{ .name = "max31726", .driver_data = max31725 },
> +	{ .name = "max31875", .driver_data = max31875 },
>  	{ .name = "mcp980x", .driver_data = mcp980x },
>  	{ .name = "p3t1750", .driver_data = p3t1750 },
>  	{ .name = "p3t1755", .driver_data = p3t1755 },
> @@ -905,6 +926,10 @@ static const struct of_device_id lm75_of_match[] = {
>  		.compatible = "adi,adt75",
>  		.data = (void *)adt75
>  	},
> +	{
> +		.compatible = "adi,max31875",
> +		.data = (void *)max31875
> +	},
>  	{
>  		.compatible = "ams,as6200",
>  		.data = (void *)as6200
> -- 
> 2.34.1
> 
> 

      reply	other threads:[~2026-09-24 16:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  8:41 [PATCH v2 0/3] hwmon: (lm75) add MAX31875 support John Erasmus Mari Geronimo
2026-09-24  8:41 ` [PATCH v2 1/3] dt-bindings: hwmon: lm75: add MAX31875 John Erasmus Mari Geronimo
2026-09-24 16:59   ` Conor Dooley
2026-09-24  8:41 ` [PATCH v2 2/3] hwmon: (lm75) add MAX31875 documentation John Erasmus Mari Geronimo
2026-09-24  8:41 ` [PATCH v2 3/3] hwmon: (lm75) add MAX31875 support John Erasmus Mari Geronimo
2026-09-24 16:46   ` Guenter Roeck [this message]

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=29aade07-55a9-4d32-92e1-c7f410982f29@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=johnerasmusmari.geronimo@analog.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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