From: David Lechner <dlechner@baylibre.com>
To: Vladislav Kulikov <vlad.kulikov.c@gmail.com>,
jic23@kernel.org, nuno.sa@analog.com, andy@kernel.org,
robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] iio: magnetometer: add driver for MEMSIC MMC5983MA
Date: Sat, 9 May 2026 17:09:33 -0500 [thread overview]
Message-ID: <880e0d0c-da84-484e-869b-ff77454874e1@baylibre.com> (raw)
In-Reply-To: <20260507205033.951990-3-vlad.kulikov.c@gmail.com>
On 5/7/26 3:50 PM, Vladislav Kulikov wrote:
> Add support for the MEMSIC MMC5983MA 3-axis magnetometer. The driver
> provides raw magnetic field readings via IIO sysfs with SET/RESET
> offset cancellation for each measurement.
>
> Signed-off-by: Vladislav Kulikov <vlad.kulikov.c@gmail.com>
> ---
I gave my RB tag already, but if we do another revision, a couple of
suggestions.
> +static int mmc5983_take_measurement(struct mmc5983_data *data, int m[3])
> +{
> + unsigned int status;
> + u8 buf[7];
> + int ret;
> +
> + ret = regmap_write(data->regmap, MMC5983_REG_CTRL0,
> + MMC5983_CTRL0_TM_M_BIT);
> + if (ret)
> + return ret;
> +
> + /*
> + * Datasheet page 15: measurement time is 8 ms at BW=00 (default,
> + * slowest setting). Use a 50 ms timeout for margin.
> + */
> + ret = regmap_read_poll_timeout(data->regmap, MMC5983_REG_STATUS,
> + status,
> + status & MMC5983_STATUS_MEAS_M_DONE_BIT,
> + 10000, 50000);
I wouldn't mind seeing 10 * KILO, 50 * KILO here to make it easier to read.
> + if (ret)
> + return ret;
> +
> + ret = regmap_bulk_read(data->regmap, MMC5983_REG_XOUT0, buf,
> + sizeof(buf));
> + if (ret)
> + return ret;
> +
> + m[0] = (buf[0] << 10) | (buf[1] << 2) | ((buf[6] >> 6) & 0x3);
> + m[1] = (buf[2] << 10) | (buf[3] << 2) | ((buf[6] >> 4) & 0x3);
> + m[2] = (buf[4] << 10) | (buf[5] << 2) | ((buf[6] >> 2) & 0x3);
> +
> + return 0;
> +}
> +
> +static int mmc5983_read_raw(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, int *val,
> + int *val2, long mask)
> +{
> + struct mmc5983_data *data = iio_priv(indio_dev);
> + int m1[3], m2[3];
> + int ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW: {
> + guard(mutex)(&data->mutex);
> +
> + ret = regmap_write(data->regmap, MMC5983_REG_CTRL0,
> + MMC5983_CTRL0_SET_BIT);
> + if (ret)
> + return ret;
> +
> + /*
> + * Datasheet page 15: SET/RESET coil pulse is 500 ns.
> + * Vendor sample code waits 500 us before the next operation.
> + */
> + fsleep(500);
> +
> + ret = mmc5983_take_measurement(data, m1);
> + if (ret)
> + return ret;
> +
> + ret = regmap_write(data->regmap, MMC5983_REG_CTRL0,
> + MMC5983_CTRL0_RESET_BIT);
> + if (ret)
> + return ret;
> +
> + /*
> + * Datasheet page 15: SET/RESET coil pulse is 500 ns.
> + * Vendor sample code waits 500 us before the next operation.
> + */
> + fsleep(500);
It looks like this SET/RESET sequence is also repeated during init. Maybe
refactor that out into a separate function.
> +
> + ret = mmc5983_take_measurement(data, m2);
> + if (ret)
> + return ret;
> +
> + *val = (m1[chan->address] - m2[chan->address]) / 2;
> + return IIO_VAL_INT;
> + }
> + case IIO_CHAN_INFO_SCALE:
> + *val = 0;
> + *val2 = 61035;
> + return IIO_VAL_INT_PLUS_NANO;
> + default:
> + return -EINVAL;
> + }
> +}
> +
next prev parent reply other threads:[~2026-05-09 22:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 20:50 [PATCH v2 0/2] iio: magnetometer: add MEMSIC MMC5983MA driver Vladislav Kulikov
2026-05-07 20:50 ` [PATCH v2 1/2] dt-bindings: iio: magnetometer: add MEMSIC MMC5983MA Vladislav Kulikov
2026-05-08 15:06 ` Conor Dooley
2026-05-09 21:51 ` David Lechner
2026-05-07 20:50 ` [PATCH v2 2/2] iio: magnetometer: add driver for " Vladislav Kulikov
2026-05-09 22:09 ` David Lechner [this message]
2026-05-10 7:02 ` Andy Shevchenko
2026-05-08 10:03 ` [PATCH v2 0/2] iio: magnetometer: add MEMSIC MMC5983MA driver Andy Shevchenko
2026-05-08 10:40 ` Vlad
2026-05-09 7:58 ` Andy Shevchenko
2026-05-09 22:06 ` David Lechner
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=880e0d0c-da84-484e-869b-ff77454874e1@baylibre.com \
--to=dlechner@baylibre.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--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 \
--cc=vlad.kulikov.c@gmail.com \
/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