Re: [PATCH v4 1/2] iio: magnetometer: add support for Infineon TLV493D 3D Magentic sensor

From: Jonathan Cameron
Date: Sat Aug 16 2025 - 09:05:06 EST


On Thu, 14 Aug 2025 08:23:43 +0530
Dixit Parmar <dixitparmar19@xxxxxxxxx> wrote:

> The Infineon TLV493D is a Low-Power 3D Magnetic Sensor. The Sensor
> applications includes joysticks, control elements (white goods,
> multifunction knops), or electric meters (anti tampering) and any
> other application that requires accurate angular measurements at
> low power consumptions.
>
> The Sensor is configured over I2C, and as part of Sensor measurement
> data it provides 3-Axis magnetic fields and temperature core measurement.
>
> The driver supports raw value read and buffered input via external trigger
> to allow streaming values with the same sensing timestamp.
>
> While the sensor has an interrupt pin multiplexed with an I2C SCL pin.
> But for bus configurations interrupt(INT) is not recommended, unless timing
> constraints between I2C data transfers and interrupt pulses are monitored
> and aligned.
>
> The Sensor's I2C register map and mode information is described in product
> User Manual [1].
>
> Datasheet: https://www.infineon.com/assets/row/public/documents/24/49/infineon-tlv493d-a1b6-datasheet-en.pdf
> Link: https://www.mouser.com/pdfDocs/Infineon-TLV493D-A1B6_3DMagnetic-UserManual-v01_03-EN.pdf [1]
> Signed-off-by: Dixit Parmar <dixitparmar19@xxxxxxxxx>

Hi Dixit,

A couple of really minor things inline. Given Andy has been doing most of the review
work on this one I'll leave it for a few days to give him chance for a final look.

The stuff below is small so if nothing else comes up I can tweak it whilst applying

Thanks,

Jonathan

> diff --git a/drivers/iio/magnetometer/tlv493d.c b/drivers/iio/magnetometer/tlv493d.c
> new file mode 100644
> index 000000000000..ee72211576a6
> --- /dev/null
> +++ b/drivers/iio/magnetometer/tlv493d.c
> @@ -0,0 +1,530 @@

> + TLV493D_AXIS_X,
> + TLV493D_AXIS_Y,
> + TLV493D_AXIS_Z,
> + TLV493D_TEMPERATURE
As below.

> +};
> +
> +enum tlv493d_op_mode {
> + TLV493D_OP_MODE_POWERDOWN,
> + TLV493D_OP_MODE_FAST,
> + TLV493D_OP_MODE_LOWPOWER,
> + TLV493D_OP_MODE_ULTRA_LOWPOWER,
> + TLV493D_OP_MODE_MASTERCONTROLLED
This is not a terminating entry, so would typically have a trailing comma.
> +};

> +
> +static int tlv493d_init(struct tlv493d_data *data)

I think this is only called from probe, so it would be appropriate
to use return dev_err_probe() in all the error paths.

If nothing else comes up I might tweak that whilst applying.

> +{
> + int ret;
> + u8 buff[TLV493D_RD_REG_MAX];
> + struct device *dev = &data->client->dev;
> +
> + /*
> + * The sensor initialization requires below steps to be followed,
> + * 1. Power-up sensor.
> + * 2. Read and store read-registers map (0x0-0x9).
> + * 3. Copy values from read reserved registers to write reserved fields (0x0-0x3).
> + * 4. Set operating mode.
> + * 5. Write to all registers.
> + */
> + ret = i2c_master_recv(data->client, buff, ARRAY_SIZE(buff));
> + if (ret < 0) {
> + dev_err(dev, "i2c read failed, error %d\n", ret);
> + return ret;
> + }
> +
> + /* Write register 0x0 is reserved. Does not require to be updated.*/
> + data->wr_regs[0] = 0;
> + data->wr_regs[1] = buff[TLV493D_RD_REG_RES1] & TLV493D_RD_REG_RES1_WR_MASK;
> + data->wr_regs[2] = buff[TLV493D_RD_REG_RES2] & TLV493D_RD_REG_RES2_WR_MASK;
> + data->wr_regs[3] = buff[TLV493D_RD_REG_RES3] & TLV493D_RD_REG_RES3_WR_MASK;
> +
> + ret = tlv493d_set_operating_mode(data, data->mode);
> + if (ret < 0) {
> + dev_err(dev, "failed to set operating mode\n");
> + return ret;
> + }
> +
> + return 0;
> +}