Skip to contentSkip to conversation

iio: pressure: ms5637: Add variant specific

PATCH In review Louis Adamian 5 participants 14 messages Jun 10 – Aug 7

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover iio: pressure: ms5637: Add variant specific

Hi all,

This series adds temperature compensation and pressure scaling for the MS5637 series (02B, 30BA), MS5803 series (01BA, 02BA, 05BA, 14BA, 30BA), MS5805, MS5837 series (02BA, 30BA), and MS8607. These all share the same temperature compensation formula, but the constants differ between devices. This series adds a ms_tp_comp_consts structure to store these per-device differences and applies the compensation.

---
Changes in v2:
- Rebased on top of the togreg branch in iio.git.

Patch 1:
- Add SPI bindings for the MS5803 family.
- Add compatible strings for the ms5637-02ba and ms5837-02ba.
- Add vdd-supply as a requirement

Patch 2:
- Fix the sens2 calculation in the 2nd order temperature compensation.
- Fix the pressure scaling in ms5637_read_raw.
- Add datasheet citations to each compensation constant structure initialization.
- Addressed automated review feedback from Sashiko
- Formatting
- Remove unrelated formatting changes.
- Change ms_tp_data struct initializations to match the existing format.
- Sort i2c_device_id alphabetically.

Link to v1: https://lore.kernel.org/linux-iio/[email protected]/

Thank you, Jonathan, for the comments on v1.

Best regards,
Louis

Louis Adamian (2):
dt-bindings: iio: pressure: Add MS5637
iio: pressure: ms5637: Add variant specific temperature compensation

 .../bindings/iio/pressure/meas,ms5637.yaml    |  87 ++++
 .../devicetree/bindings/trivial-devices.yaml  |  10 -
 .../iio/common/ms_sensors/ms_sensors_i2c.c    |  62 ++-
 .../iio/common/ms_sensors/ms_sensors_i2c.h    |  48 +++
 drivers/iio/pressure/ms5637.c                 | 388 +++++++++++++++++-
 5 files changed, 552 insertions(+), 43 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/2 dt-bindings: iio: pressure: Add MS5637

Create meas,ms5637 devicetree binding and move existing devices from trivial-devices.yaml. Explicit compatible strings are added for the different sub-variants because each requires different constants for the second-order temperature compensation formulas. Previously, the driver exposed the generic compatibles for the ms5637, MS5803, MS5805 and MS5837 families and applied the MS5637-02BA compensation to all of them.To preserve the DT ABI the existing compatibles are retained and mapped to the -02BA variant of each family (ms5637-02ba, ms5803-02ba, ms5837-02ba).

---
 .../bindings/iio/pressure/meas,ms5637.yaml    | 87 +++++++++++++++++++
 .../devicetree/bindings/trivial-devices.yaml  | 10 ---
 2 files changed, 87 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml
Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml new file +87 -0
new file mode 100644
index 000000000000..f17ac3ffefc9
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/pressure/meas,ms5637.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+title: Measurement Specialties ms5637 and similar pressure sensors
+
+maintainers:
+  - Louis Adamian <[email protected]>
+
+description:
+  Measurement Specialties pressure and temperature sensors. The MS5803
+  family supports both I2C and SPI interfaces. All other variants are I2C only.
+
+properties:
+  compatible:
+    enum:
+      - meas,ms5637
+      - meas,ms5637-02ba
+      - meas,ms5637-30ba
+      - meas,ms5803
+      - meas,ms5803-01ba
+      - meas,ms5803-02ba
+      - meas,ms5803-05ba
+      - meas,ms5803-14ba
+      - meas,ms5803-30ba
+      - meas,ms5805
+      - meas,ms5837
+      - meas,ms5837-02ba
+      - meas,ms5837-30ba
+      - meas,ms8607-temppressure
+
+  reg:
+    maxItems: 1
+
+  vdd-supply:
+    description: Regulator that provides power to the sensor
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - meas,ms5803
+              - meas,ms5803-01ba
+              - meas,ms5803-02ba
+              - meas,ms5803-05ba
+              - meas,ms5803-14ba
+              - meas,ms5803-30ba
+    then:
+      $ref: /schemas/spi/spi-peripheral-props.yaml#
+      properties:
+        spi-max-frequency:
+          maximum: 20000000
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pressure@76 {
+            compatible = "meas,ms5637-02ba";
+            reg = <0x76>;
+            vdd-supply = <&vcc_3v3>;
+        };
+    };
+  - |
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pressure@0 {
+            compatible = "meas,ms5803-14ba";
+            reg = <0>;
+            vdd-supply = <&vcc_3v3>;
+            spi-max-frequency = <20000000>;
+        };
+    };
Documentation/devicetree/bindings/trivial-devices.yaml +0 -10
index 23fd4513933a..a1516ab50a40 100644
@@ -232,18 +232,8 @@ properties:
           - meas,htu21
             # Measurement Specialities I2C temperature and humidity sensor
           - meas,htu31
-            # Measurement Specialities I2C pressure and temperature sensor
-          - meas,ms5637
-            # Measurement Specialities I2C pressure and temperature sensor
-          - meas,ms5803
-            # Measurement Specialities I2C pressure and temperature sensor
-          - meas,ms5805
-            # Measurement Specialities I2C pressure and temperature sensor
-          - meas,ms5837
             # Measurement Specialities temp and humidity part of ms8607 device
           - meas,ms8607-humidity
-            # Measurement Specialities temp and pressure part of ms8607 device
-          - meas,ms8607-temppressure
             # Measurement Specialties temperature sensor
           - meas,tsys01
             # MEMSIC magnetometer
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: iio: pressure: Add MS5637

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Adding `vdd-supply` as a strictly required property breaks backward compatibility for existing…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Adding vdd-supply as a strictly required property breaks backward compatibility for existing device trees. --

commit 8073eb9fc3f96931b47510a0323c9f632b9db41f
Author: Louis Adamian <[email protected]>

dt-bindings: iio: pressure: Add MS5637

Create meas,ms5637 devicetree binding and move existing devices from trivial-devices.yaml. Explicit compatible strings are added for the different sub-variants because each requires different constants for the second-order temperature compensation formulas.

Quoted 4 lines
Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml new file +0 -0
new file mode 100644

[ ... ]

Quoted 1 line

+properties:

[ ... ]

Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml line 42

Quoted 7 lines
Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml new file +7 -0
+  vdd-supply:
+    description: Regulator that provides power to the sensor
+
+required:
+  - compatible
+  - reg
+  - vdd-supply

[Severity: High]
Does adding vdd-supply to the required list break backward compatibility for existing device trees?

The generic compatibles like meas,ms5637 and meas,ms5803 were moved from trivial-devices.yaml to this new standalone binding. In trivial-devices.yaml, vdd-supply was not defined and additionalProperties was set to false.

This means any valid, existing device tree for these sensors strictly could not have included a vdd-supply property without failing validation. By unconditionally adding vdd-supply to the required list, existing device trees in the wild will fail dtbs_check.

Furthermore, the corresponding Linux driver (drivers/iio/pressure/ms5637.c) does not appear to fetch or use a regulator, confirming it is not functionally required.

Should vdd-supply be omitted from the required list, or only made conditionally required for newly introduced compatibles, to preserve the Device Tree ABI?

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

Re: [PATCH v2 1/2] dt-bindings: iio: pressure: Add MS5637

In reply to Louis Adamian
Quoted 9 lines · Louis Adamian

Create meas,ms5637 devicetree binding and move existing devices from trivial-devices.yaml. Explicit compatible strings are added for the different sub-variants because each requires different constants for the second-order temperature compensation formulas. Previously, the driver exposed the generic compatibles for the ms5637, MS5803, MS5805 and MS5837 families and applied the MS5637-02BA compensation to all of them.To preserve the DT ABI the existing compatibles are retained and mapped to the -02BA variant of each family (ms5637-02ba, ms5803-02ba, ms5837-02ba).

I think this should be made clear by use of fallbacks, or being marked deprecated with a comment.

pw-bot: changes-requested

Otherwise, it looks okay to me.

#4 lore raw

Re: [PATCH v2 1/2] dt-bindings: iio: pressure: Add MS5637

Quoted 2 lines · On Wed, 10 Jun 2026 17:45:52 +0100 Conor Dooley <[email protected]> wrote:

I think this should be made clear by use of fallbacks, or being marked deprecated with a comment.

I will mark the generic compatibles as deprecated with a comment noting that they previously all received the ms5637-02ba compensation (following solomon,ssd1307fb.yaml).

Thanks,
Louis

#5 lore raw

PATCH v2 2/2 iio: pressure: ms5637: Add variant specific temperature compensation

In reply to Louis Adamian

Add correct temperature compensation for ms5637-30BA, MS5803-01BA,02BA, 05BA, 14BA, 30BA, MS5837-30BA. The temperature compensation formula is shared across these sensors but with different constants. Add ms_tp_comp_consts to capture these per-device differences. Add pressure variant specific pressure scale variable.

---
 .../iio/common/ms_sensors/ms_sensors_i2c.c    |  62 ++-
 .../iio/common/ms_sensors/ms_sensors_i2c.h    |  48 +++
 drivers/iio/pressure/ms5637.c                 | 388 +++++++++++++++++-
 3 files changed, 465 insertions(+), 33 deletions(-)
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +40 -22
index 1960a2ce82a8..d5e217d7ba0b 100644
@@ -604,6 +604,39 @@ int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data)
 }
 EXPORT_SYMBOL_NS(ms_sensors_tp_read_prom, "IIO_MEAS_SPEC_SENSORS");
 
+/* apply second order temperature compensation */
+static void ms_tp_compensate(const struct ms_tp_comp_consts *c,
+			     s32 temp, s32 dt, s64 *t2, s64 *off2, s64 *sens2)
+{
+	if (temp < 2000) {
+		s64 tmp = (s64)temp - 2000;
+
+		*t2 = (c->low_t2_multiplier * ((s64)dt * (s64)dt)) >>
+		      c->low_t2_shift;
+		*off2 = (c->low_off2_multiplier * tmp * tmp) >>
+			c->low_off2_shift;
+		*sens2 = (c->low_sens2_multiplier * tmp * tmp) >>
+			 c->low_sens2_shift;
+
+		if (temp < -1500) {
+			s64 tmp_vlow = (s64)temp + 1500;
+			*off2 += c->vlow_off2_multiplier * tmp_vlow * tmp_vlow;
+			*sens2 +=
+				c->vlow_sens2_multiplier * tmp_vlow * tmp_vlow;
+		}
+	} else {
+		*sens2 = 0;
+		if (c->has_vhigh_temp && temp > 4500)
+			*sens2 -= (((s64)temp - 4500) * ((s64)temp - 4500)) >> 3;
+
+		*t2 = (c->high_t2_multiplier * ((s64)dt * (s64)dt)) >>
+		      c->high_t2_shift;
+		*off2 = (c->high_off2_multiplier *
+			 ((s64)temp - 2000) * ((s64)temp - 2000)) >>
+			c->high_off2_shift;
+	}
+}
+
 /**
  * ms_sensors_read_temp_and_pressure() - read temp and pressure
  * @dev_data:	pointer to temperature/pressure device data
@@ -624,6 +657,7 @@ int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
 	s32 dt, temp;
 	s64 off, sens, t2, off2, sens2;
 	u16 *prom = dev_data->prom, delay;
+	const struct ms_tp_comp_consts *c = dev_data->comp_consts;
 
 	mutex_lock(&dev_data->lock);
 	delay = ms_sensors_tp_conversion_time[dev_data->res_index];
@@ -654,37 +688,21 @@ int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
 	/* Actual temperature = 2000 + dT * TEMPSENS */
 	temp = 2000 + (((s64)dt * prom[6]) >> 23);
 
-	/* Second order temperature compensation */
-	if (temp < 2000) {
-		s64 tmp = (s64)temp - 2000;
-
-		t2 = (3 * ((s64)dt * (s64)dt)) >> 33;
-		off2 = (61 * tmp * tmp) >> 4;
-		sens2 = (29 * tmp * tmp) >> 4;
-
-		if (temp < -1500) {
-			s64 tmp = (s64)temp + 1500;
-
-			off2 += 17 * tmp * tmp;
-			sens2 += 9 * tmp * tmp;
-		}
-	} else {
-		t2 = (5 * ((s64)dt * (s64)dt)) >> 38;
-		off2 = 0;
-		sens2 = 0;
-	}
+	ms_tp_compensate(c, temp, dt, &t2, &off2, &sens2);
 
 	/* OFF = OFF_T1 + TCO * dT */
-	off = (((s64)prom[2]) << 17) + ((((s64)prom[4]) * (s64)dt) >> 6);
+	off = (((s64)prom[2]) << c->off_t1_shift) +
+	      ((((s64)prom[4]) * (s64)dt) >> c->off_shift);
 	off -= off2;
 
 	/* Sensitivity at actual temperature = SENS_T1 + TCS * dT */
-	sens = (((s64)prom[1]) << 16) + (((s64)prom[3] * dt) >> 7);
+	sens = (((s64)prom[1]) << c->sens_t1_shift) +
+	       (((s64)prom[3] * dt) >> c->sens_shift);
 	sens -= sens2;
 
 	/* Temperature compensated pressure = D1 * SENS - OFF */
 	*temperature = (temp - t2) * 10;
-	*pressure = (u32)(((((s64)p_adc * sens) >> 21) - off) >> 15);
+	*pressure = (u32)(((((s64)p_adc * sens) >> c->press_sens_shift) - off) >> c->press_shift);
 
 	return 0;
 }
drivers/iio/common/ms_sensors/ms_sensors_i2c.h +48 -0

66 lines not on this page · raw message

drivers/iio/pressure/ms5637.c +377 -11

430 lines not on this page · raw message

Signature · 1 line
2.54.0
#6 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Explicit cast to 64-bit in modulo operation causes build failure on 32-bit architectures. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Explicit cast to 64-bit in modulo operation causes build failure on 32-bit architectures. --

commit 5b2cfee8f94f3621de42a9388dafb2dae478fda9
Author: Louis Adamian <[email protected]>

iio: pressure: ms5637: Add variant specific temperature compensation

This commit adds variant-specific temperature compensation and pressure scaling for ms5637, ms5803, and ms5837 sensors. It extracts the compensation constants into a per-device structure to handle differences across the sensor variants.

Quoted 4 lines
drivers/iio/pressure/ms5637.c +0 -0
index 03945a4fc7188..36bda9694b4c4 100644

[ ... ]

drivers/iio/pressure/ms5637.c static int ms5637_read_raw(struct iio_dev *indio_dev, · line 80

Quoted 10 lines
drivers/iio/pressure/ms5637.c +4 -2
@@ -73,8 +74,10 @@ static int ms5637_read_raw(struct iio_dev *indio_dev,
 
 			return IIO_VAL_INT;
 		case IIO_PRESSURE:	/* in kPa */
-			*val = pressure / 1000;
-			*val2 = (pressure % 1000) * 1000;
+			*val = pressure / dev_data->comp_consts->press_scale;
+			*val2 = (pressure %
+				 (s64)dev_data->comp_consts->press_scale) *
+				(1000000 / dev_data->comp_consts->press_scale);

[Severity: Low]
Does casting this modulo divisor to a 64-bit integer cause a build failure on 32-bit architectures?

Since pressure is an unsigned int and press_scale is a u32, the s64 cast promotes the modulo operation to 64-bit. On 32-bit platforms, this typically results in an undefined reference to __moddi3 because the kernel does not link libgcc.

Since the modulo result easily fits within a 32-bit integer, can this s64 cast be removed to prevent breaking 32-bit compile targets?

Quoted 3 lines
drivers/iio/pressure/ms5637.c +0 -0
 			return IIO_VAL_INT_PLUS_MICRO;
 		default:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

In reply to Louis Adamian
Quoted 5 lines · Louis Adamian

Add correct temperature compensation for ms5637-30BA, MS5803-01BA,02BA, 05BA, 14BA, 30BA, MS5837-30BA. The temperature compensation formula is shared across these sensors but with different constants. Add ms_tp_comp_consts to capture these per-device differences. Add pressure variant specific pressure scale variable.

Is there SPI driver? If so, why only i2c is affected?

...

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 612

Quoted 6 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +6 -0
+/* apply second order temperature compensation */
+static void ms_tp_compensate(const struct ms_tp_comp_consts *c,
+			     s32 temp, s32 dt, s64 *t2, s64 *off2, s64 *sens2)
+{
+	if (temp < 2000) {
+		s64 tmp = (s64)temp - 2000;

Why casting?

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 622

Quoted 11 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +9 -0
+
+		*t2 = (c->low_t2_multiplier * ((s64)dt * (s64)dt)) >>
+		      c->low_t2_shift;
+		*off2 = (c->low_off2_multiplier * tmp * tmp) >>
+			c->low_off2_shift;
+		*sens2 = (c->low_sens2_multiplier * tmp * tmp) >>
+			 c->low_sens2_shift;
 
 
+		if (temp < -1500) {
+			s64 tmp_vlow = (s64)temp + 1500;

Missing blank line. But Q here is why tmp can't be used here?

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 625

Quoted 3 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +3 -0
+			*off2 += c->vlow_off2_multiplier * tmp_vlow * tmp_vlow;
+			*sens2 +=
+				c->vlow_sens2_multiplier * tmp_vlow * tmp_vlow;

Make it one line.

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 630

Quoted 5 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +5 -0
+		}
+	} else {
+		*sens2 = 0;
+		if (c->has_vhigh_temp && temp > 4500)
+			*sens2 -= (((s64)temp - 4500) * ((s64)temp - 4500)) >> 3;

Here...

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 635

Quoted 4 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +4 -0
+		*t2 = (c->high_t2_multiplier * ((s64)dt * (s64)dt)) >>
+		      c->high_t2_shift;
+		*off2 = (c->high_off2_multiplier *
+			 ((s64)temp - 2000) * ((s64)temp - 2000)) >>

...and here you may also use tmp, just make it global to the function.

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 638

Quoted 3 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +3 -0
+			c->high_off2_shift;
+	}
+}

Overall this all needs a good comment or even comments to explain all calculations with the references to the respective sections / tables / pages in the datasheet.

...

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, · line 660

Quoted 6 lines

int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,

drivers/iio/common/ms_sensors/ms_sensors_i2c.c +1 -0
 	s32 dt, temp;
 	s64 off, sens, t2, off2, sens2;
 	u16 *prom = dev_data->prom, delay;
+	const struct ms_tp_comp_consts *c = dev_data->comp_consts;

Try to keep more or less reversed xmas tree order.

...

Quoted 9 lines

* struct ms_tp_dev - Temperature/Pressure sensor device structure
* @client: i2c client

* @prom: array of PROM coefficients used for conversion. Added element
* for CRC computation
* @res_index: index to selected sensor resolution
+ * @comp_consts: temperature compensation constants */
struct ms_tp_dev {

drivers/iio/common/ms_sensors/ms_sensors_i2c.h struct ms_tp_dev { · line 99

Quoted 6 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.h +1 -0
 	struct i2c_client *client;
 
 	const struct ms_tp_hw_data *hw;
 	u16 prom[MS_SENSORS_TP_PROM_WORDS_NB];
 	u8 res_index;
+	const struct ms_tp_comp_consts *comp_consts;

Please, check with pahole if this is the best layout.

drivers/iio/pressure/ms5637.c line 37

Quoted 7 lines

};

struct ms_tp_data {

drivers/iio/pressure/ms5637.c +1 -0
 	const char *name;
 	const struct ms_tp_hw_data *hw;
+	const struct ms_tp_comp_consts *comp_consts;
 };

Can this be simply embedded into ms_tp_dev (and copied there if required)?

...

drivers/iio/pressure/ms5637.c static int ms5637_read_raw(struct iio_dev *indio_dev, · line 80

Quoted 7 lines
drivers/iio/pressure/ms5637.c +4 -2
 		case IIO_PRESSURE:	/* in kPa */
-			*val = pressure / 1000;
-			*val2 = (pressure % 1000) * 1000;
+			*val = pressure / dev_data->comp_consts->press_scale;
+			*val2 = (pressure %
+				 (s64)dev_data->comp_consts->press_scale) *
+				(1000000 / dev_data->comp_consts->press_scale);

MICRO (might need units.h)?

Quoted 1 line

return IIO_VAL_INT_PLUS_MICRO;

...

Have you considered to prepare the infrastructure in one patch and add the actual compensation data tables in another?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

Quoted 8 lines · On Wed, 10 Jun 2026 21:37:58 +0300 Andy Shevchenko…
Quoted 5 lines · Louis Adamian

Add correct temperature compensation for ms5637-30BA, MS5803-01BA,02BA, 05BA, 14BA, 30BA, MS5837-30BA. The temperature compensation formula is shared across these sensors but with different constants. Add ms_tp_comp_consts to capture these per-device differences. Add pressure variant specific pressure scale variable.

Is there SPI driver? If so, why only i2c is affected?

Excellent question. I went digging.

The library is used by the tsys01 driver which has both SPI and I2C interfaces. Seems the SPI side never got added. The particular driver being modified here is I2C only and the modified library function is only used in that driver.

Feels like maybe we should revisit the division of library and driver, but probably not as part of this series!

I also too a quick look through and with the stuff Andy raised acted on this looks fine to me.

Jonathan

#9 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

In reply to Andy Shevchenko
Quoted 9 lines · On Wed, 10 Jun 2026 21:37:58 +0300 Andy Shevchenko…
Quoted 6 lines · Louis Adamian

Add correct temperature compensation for ms5637-30BA, MS5803-01BA,02BA, 05BA, 14BA, 30BA, MS5837-30BA. The temperature compensation formula is shared across these sensors but with different constants. Add ms_tp_comp_consts to capture these per-device differences. Add pressure variant specific pressure scale variable.

Is there SPI driver? If so, why only i2c is affected?

As Jonathan noted, there is no SPI driver currently and the modified function is only used by i2c.

Quoted 3 lines

drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 612

Quoted 1 line
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +1 -0
+		s64 tmp = (s64)temp - 2000;  

Why casting?

This is extraneous, I will remove it.

Quoted 3 lines

Overall this all needs a good comment or even comments to explain all calculations with the references to the respective sections / tables / pages in the datasheet.

I'll add comments here explaining the shared equations. There are also references to the individual datasheets in the constant structures because they differ per device.

Quoted 9 lines

drivers/iio/common/ms_sensors/ms_sensors_i2c.h struct ms_tp_dev { · line 99

Quoted 7 lines

struct ms_tp_dev {

drivers/iio/common/ms_sensors/ms_sensors_i2c.h +1 -0
 	struct i2c_client *client;  
 
 	const struct ms_tp_hw_data *hw;
 	u16 prom[MS_SENSORS_TP_PROM_WORDS_NB];
 	u8 res_index;
+	const struct ms_tp_comp_consts *comp_consts;  

Please, check with pahole if this is the best layout.

I will correct the packing on this per pahole's finding.

Quoted 8 lines

drivers/iio/pressure/ms5637.c line 37

Quoted 5 lines

struct ms_tp_data {

drivers/iio/pressure/ms5637.c +1 -0
 	const char *name;
 	const struct ms_tp_hw_data *hw;
+	const struct ms_tp_comp_consts *comp_consts;
 };  

Can this be simply embedded into ms_tp_dev (and copied there if required)?

Copying in ms_tp_comp_consts provides no benefit over referencing the pointer; the values are per-descriptor, not per-instance and never modified. I'll keep the pointer (same as ms_tp_hw_data).

Quoted 2 lines

Have you considered to prepare the infrastructure in one patch and add the actual compensation data tables in another?

I can split this patch for V3 and I will fix the other formatting issues.

Thanks,
Louis

#10 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

Quoted 3 lines · Louis Adamian
Quoted 1 line · On Wed, 10 Jun 2026 21:37:58 +0300 Andy Shevchenko…

On Tue, Jun 09, 2026 at 10:04:58PM -0400, Louis Adamian wrote:

...

Quoted 20 lines
Quoted 9 lines

drivers/iio/common/ms_sensors/ms_sensors_i2c.h struct ms_tp_dev { · line 99

Quoted 7 lines

struct ms_tp_dev {

drivers/iio/common/ms_sensors/ms_sensors_i2c.h +1 -0
 	struct i2c_client *client;  
 
 	const struct ms_tp_hw_data *hw;
 	u16 prom[MS_SENSORS_TP_PROM_WORDS_NB];
 	u8 res_index;
+	const struct ms_tp_comp_consts *comp_consts;  

Please, check with pahole if this is the best layout.

I will correct the packing on this per pahole's finding.

Quoted 8 lines

drivers/iio/pressure/ms5637.c line 37

Quoted 5 lines

struct ms_tp_data {

drivers/iio/pressure/ms5637.c +1 -0
 	const char *name;
 	const struct ms_tp_hw_data *hw;
+	const struct ms_tp_comp_consts *comp_consts;
 };  

Can this be simply embedded into ms_tp_dev (and copied there if required)?

Quoted 4 lines

Copying in ms_tp_comp_consts provides no benefit over referencing the pointer; the values are per-descriptor, not per-instance and never modified. I'll keep the pointer (same as ms_tp_hw_data).

Okay, let me ask differently then: Can we use the same data type in ms_tp_dev instead of adding basically the same fields as in ms_tp_data?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

Quoted 27 lines · On Thu, 11 Jun 2026 22:32:02 +0300 Andy Shevchenko…
Quoted 3 lines · Louis Adamian
Quoted 1 line · On Wed, 10 Jun 2026 21:37:58 +0300 Andy Shevchenko…

On Tue, Jun 09, 2026 at 10:04:58PM -0400, Louis Adamian wrote:

...

Quoted 20 lines
Quoted 9 lines

drivers/iio/common/ms_sensors/ms_sensors_i2c.h struct ms_tp_dev { · line 99

Quoted 7 lines

struct ms_tp_dev {

drivers/iio/common/ms_sensors/ms_sensors_i2c.h +1 -0
 	struct i2c_client *client;    
 
 	const struct ms_tp_hw_data *hw;
 	u16 prom[MS_SENSORS_TP_PROM_WORDS_NB];
 	u8 res_index;
+	const struct ms_tp_comp_consts *comp_consts;    

Please, check with pahole if this is the best layout.

I will correct the packing on this per pahole's finding.

Quoted 8 lines

drivers/iio/pressure/ms5637.c line 37

Quoted 5 lines

struct ms_tp_data {

drivers/iio/pressure/ms5637.c +1 -0
 	const char *name;
 	const struct ms_tp_hw_data *hw;
+	const struct ms_tp_comp_consts *comp_consts;
 };    

Can this be simply embedded into ms_tp_dev (and copied there if required)?

Quoted 9 lines
Quoted 4 lines

Copying in ms_tp_comp_consts provides no benefit over referencing the pointer; the values are per-descriptor, not per-instance and never modified. I'll keep the pointer (same as ms_tp_hw_data).

Okay, let me ask differently then: Can we use the same data type in ms_tp_dev instead of adding basically the same fields as in ms_tp_data?

Sorry for the very slow reply. Yes, for v3 ms_tp_dev will hold a single const ms_tp_data *data instead of its own hw and comp_consts. This drops the duplicated hw that predates this series.

One thing worth noting before I do that: ms_tp_data is currently private to ms5637.c and will need to be moved to ms_sensors_i2c.h for ms_tp_dev to point to it. I don't think this is a problem; it matches how ms_tp_hw_data is defined now, but let me know if you would like to avoid it.

Thanks,
Louis

#12 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

Quoted 6 lines · Louis Adamian
Quoted 4 lines · On Thu, 11 Jun 2026 22:32:02 +0300 Andy Shevchenko…
Quoted 3 lines · Louis Adamian
Quoted 1 line · On Wed, 10 Jun 2026 21:37:58 +0300 Andy Shevchenko…

On Tue, Jun 09, 2026 at 10:04:58PM -0400, Louis Adamian wrote:

...

Quoted 33 lines
Quoted 20 lines
Quoted 20 lines
Quoted 9 lines

drivers/iio/common/ms_sensors/ms_sensors_i2c.h struct ms_tp_dev { · line 99

Quoted 7 lines

struct ms_tp_dev {

drivers/iio/common/ms_sensors/ms_sensors_i2c.h +1 -0
 	struct i2c_client *client;    
 
 	const struct ms_tp_hw_data *hw;
 	u16 prom[MS_SENSORS_TP_PROM_WORDS_NB];
 	u8 res_index;
+	const struct ms_tp_comp_consts *comp_consts;    

Please, check with pahole if this is the best layout.

I will correct the packing on this per pahole's finding.

Quoted 8 lines

drivers/iio/pressure/ms5637.c line 37

Quoted 5 lines

struct ms_tp_data {

drivers/iio/pressure/ms5637.c +1 -0
 	const char *name;
 	const struct ms_tp_hw_data *hw;
+	const struct ms_tp_comp_consts *comp_consts;
 };    

Can this be simply embedded into ms_tp_dev (and copied there if required)?

Quoted 9 lines
Quoted 4 lines

Copying in ms_tp_comp_consts provides no benefit over referencing the pointer; the values are per-descriptor, not per-instance and never modified. I'll keep the pointer (same as ms_tp_hw_data).

Okay, let me ask differently then: Can we use the same data type in ms_tp_dev instead of adding basically the same fields as in ms_tp_data?

Sorry for the very slow reply. Yes, for v3 ms_tp_dev will hold a single const ms_tp_data *data instead of its own hw and comp_consts. This drops the duplicated hw that predates this series.

Quoted 5 lines

One thing worth noting before I do that: ms_tp_data is currently private to ms5637.c and will need to be moved to ms_sensors_i2c.h for ms_tp_dev to point to it. I don't think this is a problem; it matches how ms_tp_hw_data is defined now, but let me know if you would like to avoid it.

The pointer may be opaque, in that case it's not needed to be exposed.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation

Quoted 38 lines · On Fri, 7 Aug 2026 00:27:30 +0300 Andy Shevchenko…
Quoted 7 lines · Louis Adamian
Quoted 5 lines · On Thu, 11 Jun 2026 22:32:02 +0300 Andy Shevchenko…
Quoted 4 lines · Louis Adamian
Quoted 2 lines · On Wed, 10 Jun 2026 21:37:58 +0300 Andy Shevchenko…

On Tue, Jun 09, 2026 at 10:04:58PM -0400, Louis Adamian wrote:

...

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

struct ms_tp_dev {
struct i2c_client *client;

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

Please, check with pahole if this is the best layout.

I will correct the packing on this per pahole's finding.

[...]

Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

Can this be simply embedded into ms_tp_dev (and copied there if required)?

Quoted 9 lines
Quoted 4 lines

Copying in ms_tp_comp_consts provides no benefit over referencing the pointer; the values are per-descriptor, not per-instance and never modified. I'll keep the pointer (same as ms_tp_hw_data).

Okay, let me ask differently then: Can we use the same data type in ms_tp_dev instead of adding basically the same fields as in ms_tp_data?

Sorry for the very slow reply. Yes, for v3 ms_tp_dev will hold a single const ms_tp_data *data instead of its own hw and comp_consts. This drops the duplicated hw that predates this series.

Quoted 8 lines
Quoted 5 lines

One thing worth noting before I do that: ms_tp_data is currently private to ms5637.c and will need to be moved to ms_sensors_i2c.h for ms_tp_dev to point to it. I don't think this is a problem; it matches how ms_tp_hw_data is defined now, but let me know if you would like to avoid it.

The pointer may be opaque, in that case it's not needed to be exposed.

ms_sensors_i2c.c dereferences both ->hw->prom_len in ms_sensors_tp_read_prom and ->comp_consts in ms_sensors_read_temp_and_pressure, so an opaque ms_tp_data would require passing both pointers as parameters. I plan on moving ms_tp_data into ms_sensors_i2c.h, dropping the original duplicate hw, unless you prefer otherwise.

Signature · 2 lines
Thanks,
Louis