From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Louis Adamian <adamianlouis@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation
Date: Wed, 10 Jun 2026 21:37:58 +0300 [thread overview]
Message-ID: <aimvBvJp8CsNKlPU@ashevche-desk.local> (raw)
In-Reply-To: <20260610020458.104818-3-adamianlouis@gmail.com>
On Tue, Jun 09, 2026 at 10:04:58PM -0400, Louis Adamian 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_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?
...
> +/* 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?
> +
> + *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?
> + *off2 += c->vlow_off2_multiplier * tmp_vlow * tmp_vlow;
> + *sens2 +=
> + c->vlow_sens2_multiplier * tmp_vlow * tmp_vlow;
Make it one line.
> + }
> + } else {
> + *sens2 = 0;
> + if (c->has_vhigh_temp && temp > 4500)
> + *sens2 -= (((s64)temp - 4500) * ((s64)temp - 4500)) >> 3;
Here...
> + *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.
> + 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.
...
> 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;
Try to keep more or less reversed xmas tree order.
...
> * 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 {
> 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.
> };
> struct ms_tp_data {
> 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)?
...
> 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)?
> 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?
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-06-10 18:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 2:04 [PATCH v2 0/2] iio: pressure: ms5637: Add variant specific Louis Adamian
2026-06-10 2:04 ` [PATCH v2 1/2] dt-bindings: iio: pressure: Add MS5637 Louis Adamian
2026-06-10 2:15 ` sashiko-bot
2026-06-10 16:45 ` Conor Dooley
2026-06-11 14:48 ` Louis Adamian
2026-06-10 2:04 ` [PATCH v2 2/2] iio: pressure: ms5637: Add variant specific temperature compensation Louis Adamian
2026-06-10 2:14 ` sashiko-bot
2026-06-10 18:37 ` Andy Shevchenko [this message]
2026-06-11 16:50 ` Jonathan Cameron
2026-06-11 19:10 ` Louis Adamian
2026-06-11 19:32 ` Andy Shevchenko
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=aimvBvJp8CsNKlPU@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=adamianlouis@gmail.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.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