Skip to contentSkip to conversation

hwmon: (lm75) add MAX31875 support

PATCH Superseded John Erasmus Mari Geronimo 2 participants 7 messages Oct 9

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover hwmon: (lm75) add MAX31875 support

Add support for the Analog Devices MAX31875 I2C temperature sensor by extending the existing lm75 driver.

The MAX31875 provides a 16-bit configuration register, selectable resolution of 8, 9, 10, or 12 bits, conversion rates of 125 ms, 250 ms, 1 s, or 4 s, and an alarm output.

Changes since v2:
- dt-bindings: expand the commit message to explain why the MAX31875 needs its own compatible string instead of reusing an existing lm75-family one, and pick up Conor Dooley's Acked-by given conditional on that fix.
- driver: drop the bogus .resolutions table, which incorrectly tied resolution to the sample-time index even though the two are independently configurable on this chip (Guenter Roeck).
- driver: use the BIT() idiom for the alarm bit read to match the rest of the file (Guenter Roeck).

Changes since v1:
- Rework the implementation to use the existing lm75 driver instead of the previously selected max31827 base driver.
- Add the MAX31875 Device Tree binding, documentation, and driver configuration for resolution, conversion rate, and alarm reporting.

John Erasmus Mari Geronimo (3):
dt-bindings: hwmon: lm75: add MAX31875
hwmon: (lm75) add MAX31875 documentation
hwmon: (lm75) add MAX31875 support

 .../devicetree/bindings/hwmon/lm75.yaml       |  1 +
 Documentation/hwmon/lm75.rst                  |  6 +++--
 drivers/hwmon/Kconfig                         |  2 +-
 drivers/hwmon/lm75.c                          | 24 +++++++++++++++++++
 4 files changed, 30 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/3 dt-bindings: hwmon: lm75: add MAX31875

Add MAX31875 compatible string to lm75 dt-bindings.

The MAX31875 cannot reuse an existing lm75-family compatible such as adi,adt75: it has a 16-bit configuration register (instead of 8-bit), four independently selectable conversion rates (125 ms, 250 ms, 1 s, 4 s) and four independently selectable resolutions (8, 9, 10, 12 bits), and reports its alarm through a different configuration register bit. These differences require dedicated handling in the lm75 driver, so a distinct compatible string is needed to select it.

---
 Documentation/devicetree/bindings/hwmon/lm75.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/hwmon/lm75.yaml +1 -0
index b48bf3fd721fe..d56f3ec299105 100644
@@ -14,6 +14,7 @@ properties:
   compatible:
     enum:
       - adi,adt75
+      - adi,max31875
       - ams,as6200
       - atmel,at30ts74
       - dallas,ds1775
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/3] dt-bindings: hwmon: lm75: add MAX31875

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

Add MAX31875 compatible string to lm75 dt-bindings.

The MAX31875 cannot reuse an existing lm75-family compatible such as adi,adt75: it has a 16-bit configuration register (instead of 8-bit), four independently selectable conversion rates (125 ms, 250 ms, 1 s, 4 s) and four independently selectable resolutions (8, 9, 10, 12 bits), and reports its alarm through a different configuration register bit. These differences require dedicated handling in the lm75 driver, so a distinct compatible string is needed to select it.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v3 2/3 hwmon: (lm75) add MAX31875 documentation

In reply to John Erasmus Mari Geronimo

Document the Maxim MAX31875 I2C temperature sensor as a supported chip in the lm75 driver documentation.

---
 Documentation/hwmon/lm75.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/hwmon/lm75.rst +4 -2
index ca46754e028b3..54a6a75e8a71b 100644
@@ -66,9 +66,9 @@ Supported chips:
 
 	       http://www.microchip.com/
 
-  * Analog Devices ADT75
+  * Analog Devices ADT75, MAX31875
 
-    Prefix: 'adt75'
+    Prefix: 'adt75', 'max31875'
 
     Addresses scanned: none
 
@@ -76,6 +76,8 @@ Supported chips:
 
 	       https://www.analog.com/adt75
 
+	       https://www.analog.com/max31875
+
   * ST Microelectronics STDS75
 
     Prefix: 'stds75'
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH v3 2/3] hwmon: (lm75) add MAX31875 documentation

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines

Document the Maxim MAX31875 I2C temperature sensor as a supported chip in the lm75 driver documentation.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH v3 3/3 hwmon: (lm75) add MAX31875 support

In reply to John Erasmus Mari Geronimo

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).

---
 drivers/hwmon/Kconfig |  2 +-
 drivers/hwmon/lm75.c  | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/hwmon/Kconfig +1 -1
index e4c4f2b09732d..c68b6c3c2f866 100644
@@ -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
drivers/hwmon/lm75.c +24 -0
index 104149a03bad0..2fc5659a3d6bf 100644
@@ -39,6 +39,7 @@ enum lm75_type {		/* keep sorted in alphabetical order */
 	max6625,
 	max6626,
 	max31725,
+	max31875,
 	mcp980x,
 	p3t1750,
 	p3t1755,
@@ -223,6 +224,14 @@ 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,
+		.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 +430,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 & BIT(7));
+				break;
 			default:
 				return -EINVAL;
 			}
@@ -495,6 +507,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 +867,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 +925,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
Signature · 1 line
2.34.1
#6 lore raw
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] hwmon: lm75: unconditional 16-bit polarity mask corrupts max31875 conversion rate - [Medium]…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] hwmon: lm75: unconditional 16-bit polarity mask corrupts max31875 conversion rate
- [Medium] hwmon: lm75: Fix incorrect bit mask for MAX31875 conversion rate
- [Medium] hwmon: lm75: max31875 state desynchronization on probe
--

commit 5136e5422ce7bd39a8f47ef8a45e61f3dcdb4cf8
Author: John Erasmus Mari Geronimo <[email protected]>

hwmon: (lm75) add MAX31875 support

This commit adds support for the Maxim MAX31875 I2C temperature sensor by extending the lm75 driver. The new device supports a 16-bit configuration register with configurable resolutions and selectable conversion rates.

Quoted 4 lines
drivers/hwmon/lm75.c +0 -0
index 2d2d752aeac9d..cda28b9b093c1 100644

[ ... ]

drivers/hwmon/lm75.c static const struct lm75_params device_params[] = { · line 233

Quoted 12 lines
drivers/hwmon/lm75.c +8 -0
@@ -222,6 +223,14 @@ 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,
+		.default_sample_time = 4000,
+		.num_sample_times = 4,
+		.sample_times = (unsigned int []){ 125, 250, 1000, 4000 },
+		.alarm = true,
+	},

[Severity: High]
Does setting .config_reg_16bits to true for max31875 cause a regression where the conversion rate is corrupted during initialization?

In lm75_generic_probe(), the polarity mask is unconditionally set to BIT(10) for 16-bit chips:

    if (!data->params->config_reg_16bits)
        pol_mask = LM75_ALERT_POLARITY_HIGH_8_BIT;
    else
        pol_mask = LM75_ALERT_POLARITY_HIGH_16_BIT;

This mask is then applied to the configuration register:

    clr_mask = data->params->clr_mask | pol_mask;
    ...
    err = lm75_write_config(data, set_mask, clr_mask);

Because the max31875 conversion rate mask includes BIT(10) and BIT(9), could probing the max31875 forcefully clear or set the MSB of its conversion rate, causing mutual corruption between the alarm polarity and conversion rate settings?

[Severity: Medium]
Since .set_mask and .clr_mask are not defined here, does this result in a state desynchronization on probe?

In lm75_generic_probe(), the software state is unconditionally initialized to the defaults:

    data->sample_time = data->params->default_sample_time;
    data->resolution = data->params->default_resolution;

But since the configuration masks are 0, lm75_write_config() fails to enforce these defaults on the hardware.

If a bootloader or prior system state configured the conversion rate or resolution differently, will the driver state become desynchronized from the actual hardware state?

[ ... ]

drivers/hwmon/lm75.c static int lm75_update_interval(struct device *dev, long val) · line 511

Quoted 7 lines
drivers/hwmon/lm75.c +3 -0
@@ -494,6 +506,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);

[Severity: Medium]
Is the bit mask for the MAX31875 conversion rate correct here?

Because lm75_i2c_reg_read() uses i2c_smbus_read_word_data() for 16-bit configuration registers, the chip's MSB is placed in the lower 8 bits of the returned value to maintain compatibility with 8-bit standard LM75 features.

This means D10 and D9 map to bits 2 and 1 of regval.

Using the mask 0x0600 and shifting by 9 modifies bits 10 and 9 of regval, which alters bits D2 and D1 of the chip's LSB instead of setting the conversion rate.

Should the mask be 0x0006 and the shift be 1?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3