From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Viral Patel <viral8854@gmail.com>
Cc: "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>,
"Dixit Parmar" <dixitparmar19@gmail.com>,
"Victor Chernyakin" <chernyakin.victor.j@outlook.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver
Date: Sat, 5 Dec 2026 13:56:30 +0200 [thread overview]
Message-ID: <axP77ultnBR88noG@ashevche-desk.local> (raw)
In-Reply-To: <20261205-tle493d-v3-2-19fc44f81339@gmail.com>
On Sat, Dec 05, 2026 at 12:51:25PM +0530, Viral Patel wrote:
> Add a driver for a 3-axis Hall effect magnetometer with 12-bit
> resolution and a built-in temperature sensor. Communication is via I2C.
>
> The driver runs the sensor in master-controlled mode. As /INT is
> combined with the SCL pin, the interrupt and clock stretching are
> turned off.
>
> Communication uses raw I2C transfers rather than regmap. Once the PR
> bit has been set, a plain read always begins at register 0x00, and the
> register address byte of a write also carries trigger bits.
>
> Channel data can be read through sysfs and through a triggered buffer.
...
> +static int tle493d_read_raw(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan, int *val,
> + int *val2, long mask)
Wrap logically
static int tle493d_read_raw(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
int *val, int *val2, long mask)
...
> +static void tle493d_reset(struct tle493d_data *data)
> +{
> + struct i2c_adapter *adap = data->client->adapter;
> + static const struct {
> + u16 addr;
> + char read_write;
> + } frames[] = {
> + { 0x7f, I2C_SMBUS_READ },
> + { 0x7f, I2C_SMBUS_READ },
> + { 0x00, I2C_SMBUS_WRITE },
> + { 0x00, I2C_SMBUS_WRITE },
> + };
No need, see below how.
> + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_QUICK)) {
> + dev_dbg(&data->client->dev, "adapter cannot send the reset sequence\n");
> + return;
> + }
> +
> + /* The reset frames are not acknowledged, so ignore the return values */
> + for (unsigned int i = 0; i < ARRAY_SIZE(frames); i++)
> + i2c_smbus_xfer(adap, frames[i].addr, 0, frames[i].read_write, 0,
> + I2C_SMBUS_QUICK, NULL);
You don't need the above table, just do two loops:
for (unsigned int i = 0; i < 2; i++)
i2c_smbus_xfer(adap, 0x7f, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK, NULL);
for (unsigned int i = 0; i < 2; i++)
i2c_smbus_xfer(adap, 0x00, 0, I2C_SMBUS_WRITE, 0, I2C_SMBUS_QUICK, NULL);
The comment has to explain double reads and writes
> + fsleep(TLE493D_RESET_DELAY_US);
> +}
...
> +static int tle493d_init(struct tle493d_data *data, unsigned int iicadr)
> +{
> + struct device *dev = &data->client->dev;
> + unsigned int hwv, id;
> + u8 mod1;
> + int ret;
> +
> + /*
> + * After reset the sensor uses a 2-byte read protocol which plain I2C
> + * reads cannot handle, so MOD1 has to be written before any read. MOD2
> + * is not known yet and FP is computed with its reset value, PRD = 0.
> + * Clock stretching and the interrupt are disabled because /INT shares
> + * the SCL pin.
> + *
> + * Every MOD1 write also sets IICadr, which selects the address the
> + * sensor responds on, so it must match the address the device is
> + * already on or the sensor moves to another address.
> + */
> + mod1 = FIELD_PREP(TLE493D_MOD1_IICADR, iicadr) | TLE493D_MOD1_PR |
> + TLE493D_MOD1_CA | TLE493D_MOD1_INT |
> + FIELD_PREP(TLE493D_MOD1_MODE, TLE493D_MOD1_MODE_MASTER);
Rewrap to improve readability:
mod1 = FIELD_PREP(TLE493D_MOD1_MODE, TLE493D_MOD1_MODE_MASTER) |
FIELD_PREP(TLE493D_MOD1_IICADR, iicadr) |
TLE493D_MOD1_PR | TLE493D_MOD1_CA | TLE493D_MOD1_INT;
> + ret = tle493d_write(data, TLE493D_REG_MOD1, mod1, 0);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to write MOD1\n");
> +
> + ret = tle493d_read(data, data->regs, TLE493D_NUM_REGS);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to read registers\n");
> +
> + hwv = FIELD_GET(TLE493D_VER_HWV, data->regs[TLE493D_REG_VER]);
> + if (hwv != TLE493D_VER_HWV_B21)
> + dev_info(dev, "unknown hardware version %u\n", hwv);
> +
> + id = FIELD_GET(TLE493D_TEMP2_ID, data->regs[TLE493D_REG_TEMP2]);
> + if (id != iicadr)
> + dev_info(dev, "unexpected ID %u, expected %u\n", id, iicadr);
> +
> + /*
> + * Full range, temperature and Bz enabled, no trigger via Config. This
> + * also sets a valid CP, which is not the case after reset.
> + */
> + ret = tle493d_write(data, TLE493D_REG_CONFIG, 0, 0);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to write Config\n");
> +
> + return 0;
> +}
...
With the above being addressed, feel free to add
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-12-05 11:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 7:21 [PATCH v3 0/2] iio: magnetometer: add Infineon TLE493D-W2B6 support Viral Patel
2026-12-05 7:21 ` [PATCH v3 1/2] dt-bindings: iio: magnetometer: infineon,tlv493d-a1b6: add TLE493D-W2B6 Viral Patel
2026-12-05 7:21 ` [PATCH v3 2/2] iio: magnetometer: add Infineon TLE493D-W2B6 driver Viral Patel
2026-12-05 11:56 ` 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=axP77ultnBR88noG@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=chernyakin.victor.j@outlook.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dixitparmar19@gmail.com \
--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 \
--cc=viral8854@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
all inboxes | Powered by JetHome®