linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Puranjay Mohan <puranjay12@gmail.com>
Cc: alexandru.ardelean@analog.com, devicetree@vger.kernel.org,
	knaack.h@gmx.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, lars@metafoo.de,
	andy.shevchenko@gmail.com
Subject: Re: [PATCH v4 2/2] iio: temperature: add driver support for ti tmp117
Date: Sun, 11 Apr 2021 15:54:20 +0100	[thread overview]
Message-ID: <20210411155420.318e866e@jic23-huawei> (raw)
In-Reply-To: <20210407182147.77221-3-puranjay12@gmail.com>

On Wed,  7 Apr 2021 23:51:47 +0530
Puranjay Mohan <puranjay12@gmail.com> wrote:

> TMP117 is a Digital temperature sensor with integrated Non-Volatile 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>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

A few really small things in here that I tidied up whilst applying and
running local build tests.

Note that as IIO is effectively closed for the coming merge window,
I'm queuing this up for the next cycle and it will be in linux-next
after the merge window closes in about 3 weeks time.

Thanks,

Jonathan


> +static int tmp117_read_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);
> +	s32 ret;
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
> +		ret = i2c_smbus_read_word_swapped(data->client,
> +						TMP117_REG_TEMP);
> +		if (ret < 0)
> +			return ret;
> +		*val = sign_extend32(ret, 15);
> +		return IIO_VAL_INT;
> +
> +	case IIO_CHAN_INFO_CALIBBIAS:
> +		ret = i2c_smbus_read_word_swapped(data->client,
> +					TMP117_REG_TEMP_OFFSET);
> +		if (ret < 0)
> +			return ret;
> +		*val = sign_extend32(ret, 15);
> +		return IIO_VAL_INT;
> +
> +	case IIO_CHAN_INFO_SCALE:
> +		/* Conversion from 10s of uC to mC
Totally trivial so I'll fix it whilst applying, but comment convention used
in IIO is

/*
 * Conversion

> +		 * as IIO reports temperature in mC
> +		 */
> +		*val = TMP117_RESOLUTION_10UC / MICRODEGREE_PER_10MILLIDEGREE;
> +		*val2 = (TMP117_RESOLUTION_10UC %
> +					MICRODEGREE_PER_10MILLIDEGREE) * 100;
> +
> +		return IIO_VAL_INT_PLUS_MICRO;
> +
> +	default:
> +		return -EINVAL;
> +	}
> +}
> +
> +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 = clamp(val, S16_MIN, S16_MAX);

With a C=1 W=1 build (sparse an lots of warnings) this causes problems because
the S16_MIN and S16_MAX are as you might imagine s16 values whereas val is
an int.  I've added casts to force S16_MIN and S16_MAX to ints as well.

> +		if (off == data->calibbias)
> +			return 0;
> +		data->calibbias = off;
> +		return i2c_smbus_write_word_swapped(data->client,
> +						TMP117_REG_TEMP_OFFSET, off);
> +
> +	default:
> +		return -EINVAL;
> +	}
> +}
...

  parent reply	other threads:[~2021-04-11 14:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 18:21 [PATCH v4 0/2] iio: temperature: add support for tmp117 Puranjay Mohan
2021-04-07 18:21 ` [PATCH v4 1/2] dt-bindings: iio: temperature: Add DT bindings for TMP117 Puranjay Mohan
2021-04-08 20:22   ` Rob Herring
2021-04-07 18:21 ` [PATCH v4 2/2] iio: temperature: add driver support for ti tmp117 Puranjay Mohan
2021-04-09  6:53   ` Lars-Peter Clausen
2021-04-11 14:54   ` Jonathan Cameron [this message]
2021-04-11 18:07     ` Andy Shevchenko
2021-04-11 18:08       ` Andy Shevchenko
2021-04-18  9:48         ` 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=20210411155420.318e866e@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=alexandru.ardelean@analog.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=puranjay12@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;
as well as URLs for NNTP newsgroup(s).