From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Frank Li <Frank.Li@nxp.com>
Cc: "Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, linux-iio@vger.kernel.org,
joshua.yeong@starfivetech.com, devicetree@vger.kernel.org,
linux@roeck-us.net, "Carlos Song" <carlos.song@nxp.com>,
"Adrian Fluturel" <fluturel.adrian@gmail.com>
Subject: Re: [PATCH v10 6/6] iio: magnetometer: Add mmc5633 sensor
Date: Tue, 4 Nov 2025 19:07:24 +0200 [thread overview]
Message-ID: <aQoyzHrQB-egSPqR@smile.fi.intel.com> (raw)
In-Reply-To: <20251104-i3c_ddr-v10-6-e3e4cbc17034@nxp.com>
On Tue, Nov 04, 2025 at 10:46:44AM -0500, Frank Li wrote:
> Add mmc5633 sensor basic support.
> - Support read 20 bits X/Y/Z magnetic.
> - Support I3C HDR mode to send start measurememt command.
> - Support I3C HDR mode to read all sensors data by one command.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
with some nit-picks below.
...
> +static int mmc5633_take_measurement(struct mmc5633_data *data, int address)
> +{
> + unsigned int reg_status;
> + int ret;
> + int val;
regmap API uses unsigned int for value field.
> + val = (address == MMC5633_TEMPERATURE) ? MMC5633_CTRL0_MEAS_T : MMC5633_CTRL0_MEAS_M;
> + ret = regmap_write(data->regmap, MMC5633_REG_CTRL0, val);
> + if (ret < 0)
> + return ret;
> +
> + val = (address == MMC5633_TEMPERATURE) ?
> + MMC5633_STATUS1_MEAS_T_DONE_BIT : MMC5633_STATUS1_MEAS_M_DONE_BIT;
> + ret = regmap_read_poll_timeout(data->regmap, MMC5633_REG_STATUS1, reg_status,
> + reg_status & val,
> + 10 * USEC_PER_MSEC,
> + 100 * 10 * USEC_PER_MSEC);
> + if (ret) {
> + dev_err(regmap_get_device(data->regmap), "data not ready\n");
> + return ret;
> + }
> +
> + return 0;
> +}
...
> +static int mmc5633_read_measurement(struct mmc5633_data *data, int address, void *buf, size_t sz)
> +{
> + struct device *dev = regmap_get_device(data->regmap);
> + u8 data_cmd[2], status[2];
> + int ret, val, ready;
Ditto.
> + if (mmc5633_is_support_hdr(data)) {
> + struct i3c_xfer xfers_wr_cmd[] = {
> + {
> + .cmd = 0x3b,
> + .len = 2,
> + .data.out = data_cmd,
> + }
> + };
> + struct i3c_xfer xfers_rd_sta_cmd[] = {
> + {
> + .cmd = 0x23 | BIT(7), /* RDSTA CMD */
> + .len = 2,
> + .data.in = status,
> + },
> + };
> + struct i3c_xfer xfers_rd_data_cmd[] = {
> + {
> + .cmd = 0x22 | BIT(7), /* RDLONG CMD */
> + .len = sz,
> + .data.in = buf,
> + },
> + };
Still do not see a justification for an array to use, but as I said I leave it
to Jonathan to decide.
> + data_cmd[0] = 0;
> + data_cmd[1] = (address == MMC5633_TEMPERATURE) ?
> + MMC5633_HDR_CTRL0_MEAS_T : MMC5633_HDR_CTRL0_MEAS_M;
> +
> + ret = i3c_device_do_xfers(data->i3cdev, xfers_wr_cmd,
> + ARRAY_SIZE(xfers_wr_cmd), I3C_HDR_DDR);
> + if (ret < 0)
> + return ret;
> +
> + ready = (address == MMC5633_TEMPERATURE) ?
> + MMC5633_STATUS1_MEAS_T_DONE_BIT : MMC5633_STATUS1_MEAS_M_DONE_BIT;
> + ret = read_poll_timeout(i3c_device_do_xfers, val,
> + val ||
> + status[0] & ready,
One line and probably you want to add parentheses for better understanding, not
everybody remembers the operator precedence by heart.
> + 10 * USEC_PER_MSEC,
> + 100 * 10 * USEC_PER_MSEC, 0,
> + data->i3cdev, xfers_rd_sta_cmd,
> + ARRAY_SIZE(xfers_rd_sta_cmd), I3C_HDR_DDR);
> + if (ret) {
> + dev_err(dev, "data not ready\n");
> + return ret;
> + }
> + if (val) {
> + dev_err(dev, "i3c transfer error\n");
> + return val;
> + }
> + return i3c_device_do_xfers(data->i3cdev, xfers_rd_data_cmd,
> + ARRAY_SIZE(xfers_rd_data_cmd), I3C_HDR_DDR);
> + }
> +
> + /* Fallback to use SDR/I2C mode */
> + ret = mmc5633_take_measurement(data, address);
> + if (ret < 0)
> + return ret;
> +
> + if (address == MMC5633_TEMPERATURE)
> + /*
> + * Put tempeature to last byte of buff to align HDR case.
> + * I3C will early terminate data read if previous data is not
> + * available.
> + */
> + return regmap_bulk_read(data->regmap, MMC5633_REG_TOUT, buf + sz - 1, 1);
> +
> + return regmap_bulk_read(data->regmap, MMC5633_REG_XOUT0, buf, sz);
> +}
...
> +static int mmc5633_read_avail(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + const int **vals,
> + int *type,
> + int *length,
> + long mask)
Other functions use different style, I believe it can occupy less LoCs.
...
> +static int mmc5633_i3c_probe(struct i3c_device *i3cdev)
> +{
> + struct device *dev = i3cdev_to_dev(i3cdev);
> + struct regmap *regmap;
> + char *name;
> + name = devm_kasprintf(dev, GFP_KERNEL, "mmc5633(%s)", dev_name(dev));
I agree on idea behind this, but I think () can be problematic for some shell
scripts, I would go with the simple mmc5633_%s or similar.
> + if (!name)
> + return -ENOMEM;
> +
> + regmap = devm_regmap_init_i3c(i3cdev, &mmc5633_regmap_config);
> + if (IS_ERR(regmap))
> + return dev_err_probe(dev, PTR_ERR(regmap),
> + "Failed to register i3c regmap\n");
> +
> + return mmc5633_common_probe(regmap, name, i3cdev);
> +}
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2025-11-04 17:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 15:46 [PATCH v10 0/6] i3c: Add basic HDR mode support Frank Li
2025-11-04 15:46 ` [PATCH v10 1/6] i3c: Add HDR API support Frank Li
2025-11-04 15:46 ` [PATCH v10 2/6] i3c: Switch to use new i3c_xfer from i3c_priv_xfer Frank Li
2025-11-04 15:46 ` [PATCH v10 3/6] i3c: master: svc: Replace bool rnw with union for HDR support Frank Li
2025-11-04 15:46 ` [PATCH v10 4/6] i3c: master: svc: Add basic HDR mode support Frank Li
2025-11-04 15:46 ` [PATCH v10 5/6] dt-bindings: trivial-devices: add MEMSIC 3-axis magnetometer Frank Li
2025-11-04 15:46 ` [PATCH v10 6/6] iio: magnetometer: Add mmc5633 sensor Frank Li
2025-11-04 17:07 ` Andy Shevchenko [this message]
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=aQoyzHrQB-egSPqR@smile.fi.intel.com \
--to=andriy.shevchenko@intel.com \
--cc=Frank.Li@nxp.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andy@kernel.org \
--cc=carlos.song@nxp.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=fluturel.adrian@gmail.com \
--cc=imx@lists.linux.dev \
--cc=jic23@kernel.org \
--cc=joshua.yeong@starfivetech.com \
--cc=krzk+dt@kernel.org \
--cc=linux-i3c@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=miquel.raynal@bootlin.com \
--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
all inboxes | Powered by JetHome®