devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Dixit Parmar <dixitparmar19@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>,
	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: Sat, 6 Sep 2025 12:07:23 +0300	[thread overview]
Message-ID: <CAHp75Vf0zHU3103xGeO4pt7LO7yWvd_WGssHAM87srQxHyFXvg@mail.gmail.com> (raw)
In-Reply-To: <20250906-tlv493d-sensor-v6_16-rc5-v6-2-b1a62d968353@gmail.com>

On Sat, Sep 6, 2025 at 11:38 AM 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].

This version looks good enough to me.
Reviewed-by: Andy Shevchenko <andy@kernel.org>

...

> +static int tlv493d_read_raw(struct iio_dev *indio_dev,
> +                       const struct iio_chan_spec *chan, int *val,
> +                       int *val2, long mask)
> +{
> +       struct tlv493d_data *data = iio_priv(indio_dev);
> +       s16 x, y, z, t;
> +       int ret;
> +
> +       switch (mask) {
> +       case IIO_CHAN_INFO_RAW:
> +               ret = tlv493d_get_measurements(data, &x, &y, &z, &t);
> +               if (ret)
> +                       return ret;
> +
> +               switch (chan->address) {
> +               case TLV493D_AXIS_X:
> +                       *val = x;
> +                       return IIO_VAL_INT;
> +               case TLV493D_AXIS_Y:
> +                       *val = y;
> +                       return IIO_VAL_INT;
> +               case TLV493D_AXIS_Z:
> +                       *val = z;
> +                       return IIO_VAL_INT;
> +               case TLV493D_TEMPERATURE:
> +                       *val = t;
> +                       return IIO_VAL_INT;
> +               default:
> +                       return -EINVAL;
> +               }
> +       case IIO_CHAN_INFO_SCALE:
> +               switch (chan->type) {
> +               case IIO_MAGN:
> +                       /*
> +                        * Magnetic field scale: 0.0098 mTesla (i.e. 9.8 µT)
> +                        * Magnetic field in Gauss: mT * 10 = 0.098.
> +                        */
> +                       *val = 98;
> +                       *val2 = 1000;
> +                       return IIO_VAL_FRACTIONAL;
> +               case IIO_TEMP:
> +                       /*
> +                        * Temperature scale: 1.1 °C per LSB, expressed as 1100 m°C
> +                        * Returned as integer for IIO core to apply:
> +                        * temp = (raw + offset) * scale
> +                        */
> +                       *val = 1100;
> +                       return IIO_VAL_INT;
> +               default:
> +                       return -EINVAL;
> +               }
> +       case IIO_CHAN_INFO_OFFSET:
> +               switch (chan->type) {
> +               case IIO_TEMP:
> +                       /*
> +                        * Temperature offset includes sensor-specific raw offset
> +                        * plus compensation for +25°C bias in formula.
> +                        * offset = -raw_offset + (25000 / 1100)
> +                        * -340 + 22.72 = -317.28
> +                        */
> +                       *val = -31728;
> +                       *val2 = 100;
> +                       return IIO_VAL_FRACTIONAL;
> +               default:
> +                       return -EINVAL;
> +               }

> +

Inconsistent (redundant) blank line.

> +       default:
> +               return -EINVAL;
> +       }
> +}


-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2025-09-06  9:08 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 [this message]
2025-09-07  9:49   ` Jonathan Cameron

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=CAHp75Vf0zHU3103xGeO4pt7LO7yWvd_WGssHAM87srQxHyFXvg@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --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 \
    /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;
as well as URLs for NNTP newsgroup(s).