Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Dixit Parmar <dixitparmar19@gmail.com>
Cc: "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-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org
Subject: Re: [PATCH v6 2/2] iio: magnetometer: add support for Infineon TLV493D 3D Magentic sensor
Date: Sun, 7 Sep 2025 10:49:17 +0100	[thread overview]
Message-ID: <20250907104917.5d743db3@jic23-huawei> (raw)
In-Reply-To: <20250906-tlv493d-sensor-v6_16-rc5-v6-2-b1a62d968353@gmail.com>

On Sat, 06 Sep 2025 14:07:57 +0530
Dixit Parmar <dixitparmar19@gmail.com> 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@gmail.com>

Only thing I spotted was trivial enough that I'll tidy that up (and Andy's comment)
whilst applying.  Changes made follow.  Applied to the togreg branch of iio.git and
pushed out as testing for 0-day to take a first look at it.

diff --git a/drivers/iio/magnetometer/tlv493d.c b/drivers/iio/magnetometer/tlv493d.c
index 6b9012889148..ec53fd40277b 100644
--- a/drivers/iio/magnetometer/tlv493d.c
+++ b/drivers/iio/magnetometer/tlv493d.c
@@ -250,10 +250,8 @@ static int tlv493d_init(struct tlv493d_data *data)
         * 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;
-       }
+       if (ret < 0)
+               return dev_err_probe(dev, ret, "i2c read failed\n");
 
        /* Write register 0x0 is reserved. Does not require to be updated.*/
        data->wr_regs[0] = 0;
@@ -262,10 +260,8 @@ static int tlv493d_init(struct tlv493d_data *data)
        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;
-       }
+       if (ret < 0)
+               return dev_err_probe(dev, ret, "failed to set operating mode\n");
 
        return 0;
 }
@@ -336,7 +332,6 @@ static int tlv493d_read_raw(struct iio_dev *indio_dev,
                default:
                        return -EINVAL;
                }
-
        default:
                return -EINVAL;
        }


> diff --git a/drivers/iio/magnetometer/tlv493d.c b/drivers/iio/magnetometer/tlv493d.c
> new file mode 100644
> index 000000000000..6b9012889148
> --- /dev/null
> +++ b/drivers/iio/magnetometer/tlv493d.c

> +static int tlv493d_init(struct tlv493d_data *data)

As this is only called from probe, ideally would just dev_err_probe() for
all error message print.

> +{
> +	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;
> +}
>

      parent reply	other threads:[~2025-09-07  9:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-06  8:37 [PATCH v6 0/2] iio: magnetometer: add support for Infineon TLV493D 3D Magnetic Sensor Dixit Parmar
2025-09-06  8:37 ` [PATCH v6 1/2] dt-bindings: iio: magnetometer: Infineon TLV493D 3D Magnetic sensor Dixit Parmar
2025-09-07  9:36   ` Jonathan Cameron
2025-09-07 11:13     ` Dixit Parmar
2025-09-07 11:49       ` Jonathan Cameron
2025-09-08  7:25   ` Krzysztof Kozlowski
2025-09-06  8:37 ` [PATCH v6 2/2] iio: magnetometer: add support for Infineon TLV493D 3D Magentic sensor Dixit Parmar
2025-09-06  9:07   ` Andy Shevchenko
2025-09-07  9:49   ` Jonathan Cameron [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=20250907104917.5d743db3@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dixitparmar19@gmail.com \
    --cc=dlechner@baylibre.com \
    --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