devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Puranjay Mohan <puranjay12@gmail.com>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: alexandru.ardelean@analog.com,
	Jonathan Cameron <jic23@kernel.org>,
	devicetree@vger.kernel.org, knaack.h@gmx.de,
	linux-iio <linux-iio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117
Date: Sat, 3 Apr 2021 20:28:25 +0530	[thread overview]
Message-ID: <CANk7y0gwSZgxzmxtOZayyy_TrUP+rbjtN4WXZAsZE7E46UmUDg@mail.gmail.com> (raw)
In-Reply-To: <7a9097bf-9f8d-0fe7-7b5e-84643bcff760@metafoo.de>

On Fri, Apr 2, 2021 at 1:43 PM Lars-Peter Clausen <lars@metafoo.de> wrote:
>
> On 4/1/21 11:16 AM, Puranjay Mohan wrote:
> > TMP117 is a Digital temperature sensor with integrated NV memory.
> >
> > Add support for tmp117 driver in iio subsystem.
> > Datasheet:-https://www.ti.com/lit/gpn/tmp117
> >
> > Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
>
> Nice and clean driver. Just some comments about the CALIBBIAS.
>
> > [...]
> > +#define TMP117_RESOLUTION_10UC               78125
> Isn't the unit here 100 uC?

it is 7.8125 milli degrees_C so 78125 x 10^-4 milli degrees_C
which is 78125 x 10^-4 x 10^3 micro degrees_C
so it becomes 78125 x 10^-1 micro degrees_C = 78125 10_microdegrees_C.
Did it in detail so I remember it in the future. I guess you thought
it as 0.78125 millidegrees_C?

> > +#define TMP117_DEVICE_ID             0x0117
> > +
> > +struct tmp117_data {
> > +     struct i2c_client *client;
> > +};
> > +
> > +static int tmp117_read_raw(struct iio_dev *indio_dev,
> > +             struct iio_chan_spec const *channel, int *val,
> > +             int *val2, long mask)
> > +{
> > [...]
> > +     case IIO_CHAN_INFO_CALIBBIAS:
> > +             ret = i2c_smbus_read_word_swapped(data->client,
> > +                                     TMP117_REG_TEMP_OFFSET);
> > +             if (ret < 0)
> > +                     return ret;
> > +             *val = ((int16_t)ret * (int32_t)TMP117_RESOLUTION_10UC)
> > +                                                             / 10000;
> > +             *val2 = ((int16_t)ret * (int32_t)TMP117_RESOLUTION_10UC)
> > +                                                             % 10000;
>
> If I understand this right CALBBIAS is written in one unit, but read in
> another unit. E.g. if you do `echo 100 > ..._calibbias` and then `cat
> ..._calibbias` you'd read a different value back.
>
yes, reading it will return the value in milli degrees_C. but to write
it should be in the register format according to the datasheet.

> I think that would be quite unexpected behavior. The unit should be the
> same. Here in the read function you can just return the register value.

Okay, if you feel that would be right then I will do it.
> Just make sure to properly sign extend like for the RAW property.
>
> > +             return IIO_VAL_INT_PLUS_MICRO;
> > [...]
> > +}
> > +
> > +static int tmp117_write_raw(struct iio_dev *indio_dev,
> > +             struct iio_chan_spec const *channel, int val,
> > +             int val2, long mask)
> > +{
> > +     struct tmp117_data *data = iio_priv(indio_dev);
> > +     s16 off;
> > +
> > +     switch (mask) {
> > +     case IIO_CHAN_INFO_CALIBBIAS:
> > +             off = (s16)val;
> This should have some input validation to avoid writing bogus values to
> the register when the value is out of range. You can either reject out
> of range values or clamp them into the valid range (using the clamp()
> macro).
the maximum value which this register takes is 0xffff, so it should
get clamped automatically when casting to s16?
I might be wrong here.

> > +             return i2c_smbus_write_word_swapped(data->client,
> > +                                             TMP117_REG_TEMP_OFFSET, off);
> > +
> > +     default:
> > +             return -EINVAL;
> > +     }
> > +}
> > +
> [...]



-- 
Thanks and Regards

Yours Truly,

Puranjay Mohan

  reply	other threads:[~2021-04-03 14:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01  9:16 [PATCH v2 0/2] iio: temperature: add support for tmp117 Puranjay Mohan
2021-04-01  9:16 ` [PATCH v2 1/2] dt-bindings: iio: temperature: Add DT bindings for TMP117 Puranjay Mohan
2021-04-01 14:56   ` Rob Herring
2021-04-01 15:13   ` Jonathan Cameron
2021-04-01 16:09   ` Rob Herring
2021-04-01  9:16 ` [PATCH v2 2/2] iio: temperature: add driver support for ti tmp117 Puranjay Mohan
2021-04-01  9:36   ` Andy Shevchenko
2021-04-02  8:14     ` Lars-Peter Clausen
2021-04-03 13:52       ` Andy Shevchenko
2021-04-02  8:13   ` Lars-Peter Clausen
2021-04-03 14:58     ` Puranjay Mohan [this message]
2021-04-03 15:03       ` Lars-Peter Clausen

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=CANk7y0gwSZgxzmxtOZayyy_TrUP+rbjtN4WXZAsZE7E46UmUDg@mail.gmail.com \
    --to=puranjay12@gmail.com \
    --cc=alexandru.ardelean@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.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).