iio: pressure: ms5637: Add variant specific compensation
Subsystems (2)
cover iio: pressure: ms5637: Add variant specific compensation
This series adds correct temperature compensation and pressure scaling constants for the MS5637-30BA, MS5803-01BA/02BA/05BA/14BA/30BA, and MS5837-30BA pressure sensor variants. Additionally, it adds a Device Tree binding document for the MS5637 driver. Without correct compensation, pressure values were measured to be off by 100kPa with the MS5803-14BA at room temperature.
Note: MAINTAINERS has not been updated yet as I am not sure what to add for the MS5637 driver.
Louis Adamian (2):
dt-bindings: iio: pressure: Add binding for MS5637
iio: pressure: ms5637: Add variant specific temperature compensation
.../bindings/iio/pressure/meas,ms5637.yaml | 52 ++++ .../devicetree/bindings/trivial-devices.yaml | 10 - .../iio/common/ms_sensors/ms_sensors_i2c.c | 81 +++--- .../iio/common/ms_sensors/ms_sensors_i2c.h | 47 +++ drivers/iio/pressure/ms5637.c | 273 ++++++++++++++++-- 5 files changed, 403 insertions(+), 60 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml
Signature · 1 line
2.54.0
RFC PATCH 1/2 dt-bindings: iio: pressure: Add binding for MS5637
Create meas,ms5637 devicetree documentation file and move existing devices from trivial-devices.yaml
--- .../bindings/iio/pressure/meas,ms5637.yaml | 52 +++++++++++++++++++ .../devicetree/bindings/trivial-devices.yaml | 10 ---- 2 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml
Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml new file +52 -0
@@ -0,0 +1,52 @@ +# 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 ms5637 pressure and temperature sensors with + I2C interface. + +properties: + compatible: + enum: + - meas,ms5637 + - 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-30ba + - meas,ms8607-temppressure + + reg: + maxItems: 1 + + vdd-supply: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pressure@76 { + compatible = "meas,ms5803-14ba"; + reg = <0x76>; + }; + };
Documentation/devicetree/bindings/trivial-devices.yaml +0 -10
@@ -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
Jonathan Cameron
maintainerRe: [RFC PATCH 1/2] dt-bindings: iio: pressure: Add binding for MS5637
On Tue, 26 May 2026 14:40:30 -0400
Louis Adamian <[email protected]> wrote:
Hi Louis,
Title should just be
dt-bindings: iio: pressure: Add MS5637
as it is obviously a binding from teh dt-bindings bit.
Quoted 2 lines
Create meas,ms5637 devicetree documentation file and move existing devices from
trivial-devices.yaml
Ad something here about why you need to include the variants and what the compatibles with out variants correspond to.
Note that Sashiko calls out that at least some of these devices support SPI so the binding needs to incorporate that as well
https://sashiko.dev/#/patchset/20260526185612.35048-2-adamianlouis%40gmail.com
Note we should do that even though the driver is currently i2c only I think.
One minor thing inline
Thanks
Jonathan
Quoted 42 lines
Signed-off-by Louis Adamian <[email protected]>--- .../bindings/iio/pressure/meas,ms5637.yaml | 52 +++++++++++++++++++ .../devicetree/bindings/trivial-devices.yaml | 10 ---- 2 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yamlDocumentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml new file +28
-0@@ -0,0 +1,52 @@ +# 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 ms5637 pressure and temperature sensors with + I2C interface. + +properties: + compatible: + enum: + - meas,ms5637 + - 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-30ba
Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml line 38
Quoted 10 lines
Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml new file +10
-0+ - meas,ms8607-temppressure + + reg: + maxItems: 1 + + vdd-supply: true + +required: + - compatible + - reg
vdd-supply should be required as well in the binding. (doesn't necessarily need to be in the driver!)
Quoted 37 lines
Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml new file +14
-0+ +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pressure@76 { + compatible = "meas,ms5803-14ba"; + reg = <0x76>; + }; + };Documentation/devicetree/bindings/trivial-devices.yaml +0
-10@@ -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
RFC PATCH 2/2 iio: pressure: ms5637: Add variant specific temperature compensation
In reply to Louis AdamianAdd 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 | 81 +++--- .../iio/common/ms_sensors/ms_sensors_i2c.h | 47 +++ drivers/iio/pressure/ms5637.c | 273 ++++++++++++++++-- 3 files changed, 351 insertions(+), 50 deletions(-)
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +48 -33
@@ -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 *comp_consts, +s32 temp,s32 dt,s64 *t2,s64 *off2,s64 *sens2) +{ +if (temp <2000 ) { +s64 tmp = (s64 )temp -2000 ; + *t2 = (comp_consts->low_t2_multiplier * ((s64 )dt * (s64 )dt)) >> + comp_consts->low_t2_shift; + *off2 = (comp_consts->low_off2_multiplier * tmp * tmp) >> + comp_consts->low_off2_shift; + *sens2 = (comp_consts->low_sens2_multiplier * tmp * tmp) >> + comp_consts->low_sens2_shift; + +if (temp <-1500 ) { +s64 tmp = (s64 )temp +1500 ; + *off2 += comp_consts->vlow_off2_multiplier * tmp * tmp; + *sens2 += + comp_consts->vlow_sens2_multiplier * tmp * tmp; + } + }else { +if (comp_consts->has_vhigh_temp && temp >4500 ) { + *sens2 -= (((s64 )temp -4500 ) * ((s64 )temp -4500 )) >> +3 ; + } + *t2 = (comp_consts->high_t2_multiplier * ((s64 )dt * (s64 )dt)) >> + comp_consts->high_t2_shift; + *off2 = (comp_consts->high_off2_multiplier * + ((s64 )temp -2000 ) * ((s64 )temp -2000 )) >> + comp_consts->high_off2_shift; + *sens2 =0 ; + } +} +/** * ms_sensors_read_temp_and_pressure() - read temp and pressure * @dev_data: pointer to temperature/pressure device data
@@ -629,22 +662,18 @@ int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, delay = ms_sensors_tp_conversion_time[dev_data->res_index]; ret =ms_sensors_convert_and_read ( - dev_data->client, -MS_SENSORS_TP_T_CONVERSION_START + - dev_data->res_index *2 , -MS_SENSORS_TP_ADC_READ , - delay, &t_adc); + dev_data->client, +MS_SENSORS_TP_T_CONVERSION_START + dev_data->res_index *2 , +MS_SENSORS_TP_ADC_READ , delay, &t_adc);if (ret) {mutex_unlock (&dev_data->lock);return ret; } ret =ms_sensors_convert_and_read ( - dev_data->client, -MS_SENSORS_TP_P_CONVERSION_START + - dev_data->res_index *2 , -MS_SENSORS_TP_ADC_READ , - delay, &p_adc); + dev_data->client, +MS_SENSORS_TP_P_CONVERSION_START + dev_data->res_index *2 , +MS_SENSORS_TP_ADC_READ , delay, &p_adc);mutex_unlock (&dev_data->lock);if (ret)return ret;
@@ -654,38 +683,24 @@ 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 (dev_data->comp_consts, 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 ]) << dev_data->comp_consts->off_t1_shift) + + ((((s64 )prom[4 ]) * (s64 )dt) >> dev_data->comp_consts->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 ]) << dev_data->comp_consts->sens_t1_shift) + + (((s64 )prom[3 ] * dt) >> dev_data->comp_consts->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) >> + dev_data->comp_consts->press_sens_shift) - + off) >> + dev_data->comp_consts->press_shift);return 0 ; }EXPORT_SYMBOL_NS (ms_sensors_read_temp_and_pressure,"IIO_MEAS_SPEC_SENSORS" );
drivers/iio/common/ms_sensors/ms_sensors_i2c.h +47 -0
65 lines not on this page · raw message
drivers/iio/pressure/ms5637.c +256 -17
325 lines not on this page · raw message
Signature · 1 line
2.54.0
Jonathan Cameron
maintainerRe: [RFC PATCH 2/2] iio: pressure: ms5637: Add variant specific temperature compensation
Quoted 7 lines · On Tue, 26 May 2026 14:40:31 -0400 Louis Adamian <[email protected]> wrote:
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_conststo capture these per-device differences. Add pressure variant specific pressure scale variable.Signed-off-by Louis Adamian <[email protected]>
Hi Louis
https://sashiko.dev/#/patchset/20260526185612.35048-2-adamianlouis%40gmail.com
Has some feedback. I've not replicated it here but if you disagree with any of it then reply to the original patch to say that.
The calculations need some datasheet references. Make sure to reference both a doc and a named section to make them stable to updates etc (hopefully!)
A few other minor things from me inline. Mostly formatting related.
Welcome to IIO btw. Let this sit on the mailing list for at least 1 week before doing a v2. That will allow other reviewers time to look and so hopefully reduce the number of revisions. If you have any time to spare, look to review other peoples' submissions on the list. No problem if you don't have time though!
Thanks,
Jonathan
Quoted 11 lines
--- .../iio/common/ms_sensors/ms_sensors_i2c.c | 81 +++--- .../iio/common/ms_sensors/ms_sensors_i2c.h | 47 +++ drivers/iio/pressure/ms5637.c | 273 ++++++++++++++++-- 3 files changed, 351 insertions(+), 50 deletions(-)drivers/iio/common/ms_sensors/ms_sensors_i2c.c +0
-0
drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 612
Quoted 9 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +6
-0@@ -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 *comp_consts, +s32 temp,s32 dt,s64 *t2,s64 *off2,s64 *sens2) +{ +if (temp <2000 ) { +s64 tmp = (s64 )temp -2000 ;
Blank line between declarations and rest of code.
Quoted 7 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +7
-0+ *t2 = (comp_consts->low_t2_multiplier * ((s64 )dt * (s64 )dt)) >> + comp_consts->low_t2_shift; + *off2 = (comp_consts->low_off2_multiplier * tmp * tmp) >> + comp_consts->low_off2_shift; + *sens2 = (comp_consts->low_sens2_multiplier * tmp * tmp) >> + comp_consts->low_sens2_shift; +
drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 629
Quoted 10 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +10
-0+if (temp <-1500 ) { +s64 tmp = (s64 )temp +1500 ; + *off2 += comp_consts->vlow_off2_multiplier * tmp * tmp; + *sens2 += + comp_consts->vlow_sens2_multiplier * tmp * tmp; + } + }else { +if (comp_consts->has_vhigh_temp && temp >4500 ) { + *sens2 -= (((s64 )temp -4500 ) * ((s64 )temp -4500 )) >> +3 ;
One thing I will point out that overlaps with sashiko. sens2 is calculated here then
drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data) · line 636
Quoted 7 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +7
-0+ } + *t2 = (comp_consts->high_t2_multiplier * ((s64 )dt * (s64 )dt)) >> + comp_consts->high_t2_shift; + *off2 = (comp_consts->high_off2_multiplier * + ((s64 )temp -2000 ) * ((s64 )temp -2000 )) >> + comp_consts->high_off2_shift; + *sens2 =0 ;
zeroed here which implies something is wrong with the maths.
Quoted 8 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +3
-0+ } +} +/** * ms_sensors_read_temp_and_pressure() - read temp and pressure * @dev_data: pointer to temperature/pressure device data @@ -629,22 +662,18 @@ int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, delay = ms_sensors_tp_conversion_time[dev_data->res_index];
drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, · line 667
Quoted 10 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +3
-5ret =ms_sensors_convert_and_read ( - dev_data->client, -MS_SENSORS_TP_T_CONVERSION_START + - dev_data->res_index *2 , -MS_SENSORS_TP_ADC_READ , - delay, &t_adc); + dev_data->client, +MS_SENSORS_TP_T_CONVERSION_START + dev_data->res_index *2 , +MS_SENSORS_TP_ADC_READ , delay, &t_adc);
As below.
Quoted 4 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +0
-0if (ret) {mutex_unlock (&dev_data->lock);return ret; }
drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, · line 676
Quoted 10 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +3
-5ret =ms_sensors_convert_and_read ( - dev_data->client, -MS_SENSORS_TP_P_CONVERSION_START + - dev_data->res_index *2 , -MS_SENSORS_TP_ADC_READ , - delay, &p_adc); + dev_data->client, +MS_SENSORS_TP_P_CONVERSION_START + dev_data->res_index *2 , +MS_SENSORS_TP_ADC_READ , delay, &p_adc);
Don't reformat existing code in a patch that does anything else. Makes it hard to see if anything changed when reviewing!
If you want to do such a reformat then it needs to be a separate patch that doesn't do anything else.
Quoted 17 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +0
-10mutex_unlock (&dev_data->lock);if (ret)return ret;@@ -654,38 +683,24 @@ 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 ;
drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, · line 686
Quoted 10 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +1
-9- - off2 +=17 * tmp * tmp; - sens2 +=9 * tmp * tmp; - } - }else { - t2 = (5 * ((s64 )dt * (s64 )dt)) >>38 ; - off2 =0 ; - sens2 =0 ; - } +ms_tp_compensate (dev_data->comp_consts, temp, dt, &t2, &off2, &sens2);
There is a lot of data_dev->comp_consts in here I'd be tempted to have a much shorter named local variable. Perhaps even c
making this ms_tp_compensate(c, temp, dt, ...
That will help reduce line lengths in the maths that follows.
Quoted 11 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +4
-2/* OFF = OFF_T1 + TCO * dT */ - off = (((s64 )prom[2 ]) <<17 ) + ((((s64 )prom[4 ]) * (s64 )dt) >>6 ); + off = (((s64 )prom[2 ]) << dev_data->comp_consts->off_t1_shift) + + ((((s64 )prom[4 ]) * (s64 )dt) >> dev_data->comp_consts->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 ]) << dev_data->comp_consts->sens_t1_shift) + + (((s64 )prom[3 ] * dt) >> dev_data->comp_consts->sens_shift);
drivers/iio/common/ms_sensors/ms_sensors_i2c.c int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data, · line 703
Quoted 10 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +4
-2sens -= 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) >> + dev_data->comp_consts->press_sens_shift) - + off) >> + dev_data->comp_consts->press_shift);
Where it helps readability it is fine to go a little long (just stay under 100 chars)
Quoted 11 lines
drivers/iio/common/ms_sensors/ms_sensors_i2c.c +0
-0return 0 ; }EXPORT_SYMBOL_NS (ms_sensors_read_temp_and_pressure,"IIO_MEAS_SPEC_SENSORS" );drivers/iio/pressure/ms5637.c +0
-0@@ -33,11 +33,13 @@struct ms_tp_data {
drivers/iio/pressure/ms5637.c line 42
Quoted 10 lines
drivers/iio/pressure/ms5637.c +3
-1const char *name;const struct ms_tp_hw_data *hw; +const struct ms_tp_comp_consts *comp_consts; };static const int ms5637_samp_freq[6 ] = {960 ,480 ,240 ,120 ,60 ,30 }; -static ssize_t ms5637_show_samp_freq (struct device *dev,struct device_attribute *attr,char *buf) +static ssize_t ms5637_show_samp_freq (struct device *dev, +struct device_attribute *attr,char *buf)
Don't rewrap code you aren't otherwise changing. It might be a reasonable change to make but not in code that does anything else as it just adds noise to that patch.
Quoted 17 lines
drivers/iio/pressure/ms5637.c +4
-2{struct iio_dev *indio_dev =dev_to_iio_dev (dev);struct ms_tp_dev *dev_data =iio_priv (indio_dev);@@ -73,8 +75,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 % + dev_data->comp_consts->press_scale) * + dev_data->comp_consts->press_scale;return IIO_VAL_INT_PLUS_MICRO ;default :
drivers/iio/pressure/ms5637.c static int ms5637_probe(struct i2c_client *client) · line 178
Quoted 5 lines
drivers/iio/pressure/ms5637.c +1
-1@@ -171,7 +175,7 @@ static int ms5637_probe(struct i2c_client *client) dev_data->res_index = data->hw->max_res_index; dev_data->hw = data->hw;mutex_init (&dev_data->lock); - + dev_data->comp_consts = data->comp_consts;
I'd keep a blank line between code filling elements of dev_data and that filling the indio_dev. So blank line here.
Quoted 254 lines
drivers/iio/pressure/ms5637.c +226
-13indio_dev->info = &ms5637_info; indio_dev->name = data->name; indio_dev->modes =INDIO_DIRECT_MODE ;@@ -191,43 +195,278 @@ static int ms5637_probe(struct i2c_client *client)return devm_iio_device_register (&client->dev, indio_dev); } -static const struct ms_tp_hw_data ms5637_hw_data = { - .prom_len =7 , - .max_res_index =5 +static const struct ms_tp_hw_data ms5637_hw_data = { .prom_len =7 , + .max_res_index =5 }; + +static const struct ms_tp_hw_data ms5803_hw_data = { .prom_len =8 , + .max_res_index =4 }; + +static const struct ms_tp_comp_consts ms5637_consts = { + .high_t2_multiplier =5 , + .high_t2_shift =38 , + .high_off2_multiplier =0 , + .high_off2_shift =0 , + .low_t2_multiplier =3 , + .low_t2_shift =33 , + .low_off2_multiplier =61 , + .low_off2_shift =4 , + .low_sens2_multiplier =29 , + .low_sens2_shift =4 , + .vlow_off2_multiplier =17 , + .vlow_sens2_multiplier =9 , + .has_vhigh_temp = false, + .off_t1_shift =17 , + .off_shift =6 , + .sens_t1_shift =16 , + .sens_shift =7 , + .press_sens_shift =21 , + .press_shift =15 , + .press_scale =1000 +}; + +static const struct ms_tp_data ms5637_data = { .name ="ms5637" , + .hw = &ms5637_hw_data, + .comp_consts = &ms5637_consts }; + +static const struct ms_tp_comp_consts ms5637_30_consts = { + .high_t2_multiplier =2 , + .high_t2_shift =37 , + .high_off2_multiplier =1 , + .high_off2_shift =4 , + .low_t2_multiplier =3 , + .low_t2_shift =33 , + .low_off2_multiplier =3 , + .low_off2_shift =1 , + .low_sens2_multiplier =5 , + .low_sens2_shift =3 , + .vlow_off2_multiplier =7 , + .vlow_sens2_multiplier =4 , + .has_vhigh_temp = false, + .off_t1_shift =16 , + .off_shift =7 , + .sens_t1_shift =15 , + .sens_shift =8 , + .press_sens_shift =21 , + .press_shift =13 , + .press_scale =100 }; -static const struct ms_tp_hw_data ms5803_hw_data = { - .prom_len =8 , - .max_res_index =4 +static const struct ms_tp_data ms5637_30_data = { .name ="ms5637-30ba" , + .hw = &ms5637_hw_data, + .comp_consts = + &ms5637_30_consts }; + +static const struct ms_tp_data ms5803_data = { .name ="ms5803" , + .hw = &ms5803_hw_data, + .comp_consts = &ms5637_consts }; + +static const struct ms_tp_data ms5805_data = { .name ="ms5805" , + .hw = &ms5637_hw_data, + .comp_consts = &ms5637_consts }; + +static const struct ms_tp_data ms5837_data = { .name ="ms5837" , + .hw = &ms5637_hw_data, + .comp_consts = &ms5637_consts }; + +static const struct ms_tp_data ms8607_data = { .name ="ms8607-temppressure" , + .hw = &ms5637_hw_data, + .comp_consts = &ms5637_consts }; + +static const struct ms_tp_comp_consts ms5803_01_consts = { + .high_t2_multiplier =0 , + .high_t2_shift =0 , + .high_off2_multiplier =0 , + .high_off2_shift =0 , + .low_t2_multiplier =1 , + .low_t2_shift =31 , + .low_off2_multiplier =3 , + .low_off2_shift =0 , + .low_sens2_multiplier =7 , + .low_sens2_shift =3 , + .vlow_off2_multiplier =0 , + .vlow_sens2_multiplier =2 , + .has_vhigh_temp = true, + .off_t1_shift =16 , + .off_shift =7 , + .sens_t1_shift =15 , + .sens_shift =8 , + .press_sens_shift =21 , + .press_shift =15 , + .press_scale =1000 }; -static const struct ms_tp_data ms5637_data = { .name ="ms5637" , .hw = &ms5637_hw_data }; +static const struct ms_tp_data ms5803_01_data = { .name ="ms5803-01ba" , + .hw = &ms5803_hw_data, + .comp_consts = + &ms5803_01_consts }; + +static const struct ms_tp_comp_consts ms5803_02_consts = { + .high_t2_multiplier =0 , + .high_t2_shift =0 , + .high_off2_multiplier =0 , + .high_off2_shift =0 , + .low_t2_multiplier =1 , + .low_t2_shift =31 , + .low_off2_multiplier =61 , + .low_off2_shift =4 , + .low_sens2_multiplier =2 , + .low_sens2_shift =0 , + .vlow_off2_multiplier =20 , + .vlow_sens2_multiplier =12 , + .has_vhigh_temp = false, + .off_t1_shift =17 , + .off_shift =6 , + .sens_t1_shift =16 , + .sens_shift =7 , + .press_sens_shift =21 , + .press_shift =15 , + .press_scale =1000 +}; -static const struct ms_tp_data ms5803_data = { .name ="ms5803" , .hw = &ms5803_hw_data }; +static const struct ms_tp_data ms5803_02_data = { .name ="ms5803-02ba" , + .hw = &ms5803_hw_data, + .comp_consts = + &ms5803_02_consts }; + +static const struct ms_tp_comp_consts ms5803_05_consts = { + .high_t2_multiplier =0 , + .high_t2_shift =0 , + .high_off2_multiplier =0 , + .high_off2_shift =0 , + .low_t2_multiplier =3 , + .low_t2_shift =33 , + .low_off2_multiplier =3 , + .low_off2_shift =3 , + .low_sens2_multiplier =7 , + .low_sens2_shift =3 , + .vlow_off2_multiplier =0 , + .vlow_sens2_multiplier =3 , + .has_vhigh_temp = false, + .off_t1_shift =18 , + .off_shift =5 , + .sens_t1_shift =17 , + .sens_shift =7 , + .press_sens_shift =21 , + .press_shift =15 , + .press_scale =1000 +}; -static const struct ms_tp_data ms5805_data = { .name ="ms5805" , .hw = &ms5637_hw_data }; +static const struct ms_tp_data ms5803_05_data = { .name ="ms5803-05ba" , + .hw = &ms5803_hw_data, + .comp_consts = + &ms5803_05_consts }; + +static const struct ms_tp_comp_consts ms5803_14_consts = { + .high_t2_multiplier =7 , + .high_t2_shift =37 , + .high_off2_multiplier =1 , + .high_off2_shift =4 , + .low_t2_multiplier =3 , + .low_t2_shift =33 , + .low_off2_multiplier =3 , + .low_off2_shift =1 , + .low_sens2_multiplier =5 , + .low_sens2_shift =3 , + .vlow_off2_multiplier =7 , + .vlow_sens2_multiplier =4 , + .has_vhigh_temp = false, + .off_t1_shift =16 , + .off_shift =7 , + .sens_t1_shift =15 , + .sens_shift =8 , + .press_sens_shift =21 , + .press_shift =15 , + .press_scale =100 +}; -static const struct ms_tp_data ms5837_data = { .name ="ms5837" , .hw = &ms5637_hw_data }; +static const struct ms_tp_data ms5803_14_data = { .name ="ms5803-14ba" , + .hw = &ms5803_hw_data, + .comp_consts = + &ms5803_14_consts }; + +static const struct ms_tp_comp_consts ms5803_30_consts = { + .high_t2_multiplier =7 , + .high_t2_shift =37 , + .high_off2_multiplier =1 , + .high_off2_shift =4 , + .low_t2_multiplier =3 , + .low_t2_shift =33 , + .low_off2_multiplier =3 , + .low_off2_shift =1 , + .low_sens2_multiplier =5 , + .low_sens2_shift =3 , + .vlow_off2_multiplier =7 , + .vlow_sens2_multiplier =4 , + .has_vhigh_temp = false, + .off_t1_shift =16 , + .off_shift =7 , + .sens_t1_shift =15 , + .sens_shift =8 , + .press_sens_shift =21 , + .press_shift =13 , + .press_scale =100 +}; -static const struct ms_tp_data ms8607_data = { - .name ="ms8607-temppressure" , - .hw = &ms5637_hw_data, +static const struct ms_tp_data ms5803_30_data = { .name ="ms5803-30ba" , + .hw = &ms5803_hw_data, + .comp_consts = + &ms5803_30_consts }; + +static const struct ms_tp_comp_consts ms5837_30_consts = { + .high_t2_multiplier =7 , + .high_t2_shift =37 , + .high_off2_multiplier =1 , + .high_off2_shift =4 , + .low_t2_multiplier =3 , + .low_t2_shift =33 , + .low_off2_multiplier =3 , + .low_off2_shift =1 , + .low_sens2_multiplier =5 , + .low_sens2_shift =3 , + .vlow_off2_multiplier =7 , + .vlow_sens2_multiplier =4 , + .has_vhigh_temp = false, + .off_t1_shift =16 , + .off_shift =7 , + .sens_t1_shift =15 ,
drivers/iio/pressure/ms5637.c static int ms5637_probe(struct i2c_client *client) · line 441
Quoted 10 lines
drivers/iio/pressure/ms5637.c +8
-0+ .sens_shift = 8, + .press_sens_shift = 21, + .press_shift = 13, + .press_scale = 100 }; +static const struct ms_tp_data ms5837_30_data = { .name ="ms5837-30ba" , + .hw = &ms5803_hw_data, + .comp_consts = + &ms5837_30_consts };
Formatting is rather ugly. I'd do it as:
static const struct ms_tp_data ms5837_30_data = {
.name = "ms5837-30ba",
.hw = &ms5803_hw_data,
.comp_consts = &ms5837_30_consts,
};Similar for all the other cases above.
drivers/iio/pressure/ms5637.c static int ms5637_probe(struct i2c_client *client) · line 448
Quoted 6 lines
drivers/iio/pressure/ms5637.c +1
-0static const struct i2c_device_id ms5637_id[] = { {"ms5637" , (kernel_ulong_t)&ms5637_data }, {"ms5805" , (kernel_ulong_t)&ms5805_data }, {"ms5837" , (kernel_ulong_t)&ms5837_data }, {"ms8607-temppressure" , (kernel_ulong_t)&ms8607_data }, + {"ms5803" , (kernel_ulong_t)&ms5803_01_data },
Alphabetical order.
Also this got refactored to use named initializers in a patch I took last week. To make my life easy when I pick this up please base your next version on the togreg branch of iio.git on kernel.org. Note I don't normally ask for this so only do it when specifically asked to. Otherwise use rc1 of the current cycle or last release kernel.
Quoted 24 lines
drivers/iio/pressure/ms5637.c +12
-0+ {"ms5803-01ba", (kernel_ulong_t)&ms5803_01_data }, + {"ms5803-02ba", (kernel_ulong_t)&ms5803_02_data }, + {"ms5803-05ba", (kernel_ulong_t)&ms5803_05_data }, + {"ms5803-14ba", (kernel_ulong_t)&ms5803_14_data }, + {"ms5803-30ba", (kernel_ulong_t)&ms5803_30_data }, { } };MODULE_DEVICE_TABLE (i2c, ms5637_id);static const struct of_device_id ms5637_of_match[] = { { .compatible ="meas,ms5637" , .data = &ms5637_data }, + { .compatible ="meas,ms5637-30ba" , .data = &ms5637_30_data }, { .compatible ="meas,ms5803" , .data = &ms5803_data }, + { .compatible ="meas,ms5803-01ba" , .data = &ms5803_01_data }, + { .compatible ="meas,ms5803-02ba" , .data = &ms5803_02_data }, + { .compatible ="meas,ms5803-05ba" , .data = &ms5803_05_data }, + { .compatible ="meas,ms5803-14ba" , .data = &ms5803_14_data }, + { .compatible ="meas,ms5803-30ba" , .data = &ms5803_30_data }, { .compatible ="meas,ms5805" , .data = &ms5805_data }, { .compatible ="meas,ms5837" , .data = &ms5837_data }, + { .compatible ="meas,ms5837-30ba" , .data = &ms5837_30_data }, { .compatible ="meas,ms8607-temppressure" , .data = &ms8607_data }, { } };
Jonathan Cameron
maintainerQuoted 10 lines · On Tue, 26 May 2026 14:40:29 -0400 Louis Adamian <[email protected]> wrote:
This series adds correct temperature compensation and pressure scaling constants for the MS5637-30BA, MS5803-01BA/02BA/05BA/14BA/30BA, and MS5837-30BA pressure sensor variants. Additionally, it adds a Device Tree binding document for the MS5637 driver. Without correct compensation, pressure values were measured to be off by 100kPa with the MS5803-14BA at room temperature.
Note:
MAINTAINERShas not been updated yet as I am not sure what to add for the MS5637 driver.
Hi Louis
For a cover letter of an RFC there should be some questions, or other reason that it's an RFC. To me this looks like a proposal for something to upstream.
Key is that RFCs and normal postings get different types of review - and different people in general look at each type.
Thanks,
Jonathan
Quoted 12 lines
Louis Adamian (2):
dt-bindings: iio: pressure: Add binding for MS5637
iio: pressure: ms5637: Add variant specific temperature compensation.../bindings/iio/pressure/meas,ms5637.yaml | 52 ++++ .../devicetree/bindings/trivial-devices.yaml | 10 - .../iio/common/ms_sensors/ms_sensors_i2c.c | 81 +++--- .../iio/common/ms_sensors/ms_sensors_i2c.h | 47 +++ drivers/iio/pressure/ms5637.c | 273 ++++++++++++++++-- 5 files changed, 403 insertions(+), 60 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/pressure/meas,ms5637.yaml