Skip to contentSkip to conversation

iio: pressure: ms5611: fixed value compensation bug

PATCH Superseded Mitja Spes 3 participants 9 messages Oct 19, 2022 – Oct 20, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Mitja Spes

author
#0 lore raw

PATCH 1/3 iio: pressure: ms5611: fixed value compensation bug

When using multiple instances of this driver the compensation PROM was overwritten by the last initialized sensor. Now each sensor has own PROM storage.

---
 drivers/iio/pressure/ms5611.h      | 12 +++----
 drivers/iio/pressure/ms5611_core.c | 51 ++++++++++++++++--------------
 2 files changed, 31 insertions(+), 32 deletions(-)
drivers/iio/pressure/ms5611.h +4 -8
index cbc9349c342a..550b75b7186f 100644
@@ -25,13 +25,6 @@ enum {
 	MS5607,
 };
 
-struct ms5611_chip_info {
-	u16 prom[MS5611_PROM_WORDS_NB];
-
-	int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info,
-					    s32 *temp, s32 *pressure);
-};
-
 /*
  * OverSampling Rate descriptor.
  * Warning: cmd MUST be kept aligned on a word boundary (see
@@ -50,12 +43,15 @@ struct ms5611_state {
 	const struct ms5611_osr *pressure_osr;
 	const struct ms5611_osr *temp_osr;
 
+	u16 prom[MS5611_PROM_WORDS_NB];
+
 	int (*reset)(struct ms5611_state *st);
 	int (*read_prom_word)(struct ms5611_state *st, int index, u16 *word);
 	int (*read_adc_temp_and_pressure)(struct ms5611_state *st,
 					  s32 *temp, s32 *pressure);
 
-	struct ms5611_chip_info *chip_info;
+	int (*compensate_temp_and_pressure)(struct ms5611_state *st, s32 *temp,
+					  s32 *pressure);
 	struct regulator *vdd;
 };
 
drivers/iio/pressure/ms5611_core.c +27 -24

101 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 2/3 iio: pressure: ms5611: changed hardcoded SPI speed to value limited

Don't hardcode the ms5611 SPI speed, limit it instead.

---
 drivers/iio/pressure/ms5611_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/pressure/ms5611_spi.c +1 -1
index 281b08398720..1b1e863783ec 100644
@@ -91,7 +91,7 @@ static int ms5611_spi_probe(struct spi_device *spi)
 	spi_set_drvdata(spi, indio_dev);
 
 	spi->mode = SPI_MODE_0;
-	spi->max_speed_hz = 20000000;
+	spi->max_speed_hz = min(spi->max_speed_hz, 20000000U);
 	spi->bits_per_word = 8;
 	ret = spi_setup(spi);
 	if (ret < 0)
Signature · 1 line
2.34.1
#2 lore raw
In reply to Mitja Spes
Quoted 3 lines · Mitja Spes

When using multiple instances of this driver the compensation PROM was overwritten by the last initialized sensor. Now each sensor has own PROM

its own

Quoted 1 line

storage.

This change is just a good example why the chip_info should always be static const, so the volatile data should come through the different sources.

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

PATCH 3/3 doc: iio: pressure: ms5611: added max SPI frequency setting to the example

In reply to Mitja Spes

Added max SPI frequency setting to the example. It is now honored by the driver.

---
 Documentation/devicetree/bindings/iio/pressure/meas,ms5611.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/pressure/meas,ms5611.yaml +1 -0
index 4f06707450bf..08bd06e6dabe 100644
@@ -52,6 +52,7 @@ examples:
             compatible = "meas,ms5611";
             reg = <0>;
             vdd-supply = <&ldo_3v3_gnss>;
+            spi-max-frequency = <20000000>;
         };
     };
 ...
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 3/3] doc: iio: pressure: ms5611: added max SPI frequency setting to the example

Quoted 3 lines · Mitja Spes

Added max SPI frequency setting to the example. It is now honored by the driver.

Is it possible to add a constraint here? So the schema validator will issue the warning / error if the speed is too high.

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

Re: [PATCH 3/3] doc: iio: pressure: ms5611: added max SPI frequency setting to the example

Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Mitja Spes

Added max SPI frequency setting to the example. It is now honored by the driver.

Is it possible to add a constraint here? So the schema validator will issue the warning / error if the speed is too high.

The constraint is already there:
https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/iio/pressure/meas%2Cms5611.yaml

```
spi-max-frequency:
    maximum: 20000000
```

But in any case the patch 2/3 limits the max frequency.

Kind regards,
Mitja Spes

#6 lore raw

Re: [PATCH 3/3] doc: iio: pressure: ms5611: added max SPI frequency setting to the example

In reply to Mitja Spes
Quoted 2 lines · Mitja Spes

Added max SPI frequency setting to the example. It is now honored by the driver.

Use subject prefixes matching the subsystem (git log --oneline -- ...).

Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Quoted 11 lines
---
 Documentation/devicetree/bindings/iio/pressure/meas,ms5611.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/iio/pressure/meas,ms5611.yaml +0 -0
index 4f06707450bf..08bd06e6dabe 100644

Documentation/devicetree/bindings/iio/pressure/meas,ms5611.yaml examples: · line 55

Quoted 4 lines
Documentation/devicetree/bindings/iio/pressure/meas,ms5611.yaml +1 -0
@@ -52,6 +52,7 @@ examples:
             compatible = "meas,ms5611";
             reg = <0>;
             vdd-supply = <&ldo_3v3_gnss>;
+            spi-max-frequency = <20000000>;

Whether it is honored by driver it matters less. More important is how hardware can handle it. This should be included in the bindings/properties.

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH 3/3] doc: iio: pressure: ms5611: added max SPI frequency setting to the example

Quoted 1 line · Krzysztof Kozlowski

Use subject prefixes matching the subsystem (git log --oneline -- ...).

Will do.

Quoted 2 lines

Whether it is honored by driver it matters less. More important is how hardware can handle it. This should be included in the bindings/properties.

The hardware handles frequencies up to 20MHz. That constraint is already written in meas,ms5611.yaml.
What my patch 2 does is allow the user to set a lower frequency and the patch 3 just emphasises that in the example.

Kind regards,
Mitja

#8 lore raw

Re: [PATCH 3/3] doc: iio: pressure: ms5611: added max SPI frequency setting to the example

Quoted 7 lines · Mitja Špes
Quoted 1 line · Krzysztof Kozlowski

Use subject prefixes matching the subsystem (git log --oneline -- ...).

Will do.

Quoted 7 lines
Quoted 2 lines

Whether it is honored by driver it matters less. More important is how hardware can handle it. This should be included in the bindings/properties.

The hardware handles frequencies up to 20MHz. That constraint is already written in meas,ms5611.yaml.
What my patch 2 does is allow the user to set a lower frequency and the patch 3 just emphasises that in the example.

Then I am not sure whether it is worth changing. This is just an example. Old value is correct.

Best regards,
Krzysztof