devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: puranjay12@gmail.com, lars@metafoo.de, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH v2 3/4] iio: temperature: tmp117: add TI TMP116 support
Date: Fri, 23 Dec 2022 15:10:56 +0000	[thread overview]
Message-ID: <20221223151056.4f7d4b7e@jic23-huawei> (raw)
In-Reply-To: <20221221092801.1977499-4-m.felsch@pengutronix.de>

On Wed, 21 Dec 2022 10:28:00 +0100
Marco Felsch <m.felsch@pengutronix.de> wrote:

> The TMP116 is the predecessor of the TMP117. The TMP116 don't support
> custom offset calibration data, instead this register is used as generic
> EEPROM storage as well.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
A few comments inline.
Thanks,

Jonathan

> ---
> v2:
> - no changes
> 
>  drivers/iio/temperature/tmp117.c | 40 ++++++++++++++++++++++----------
>  1 file changed, 28 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/temperature/tmp117.c b/drivers/iio/temperature/tmp117.c
> index f9b8f2b570f6..468dafa6fa8e 100644
> --- a/drivers/iio/temperature/tmp117.c
> +++ b/drivers/iio/temperature/tmp117.c
> @@ -31,9 +31,11 @@
>  #define TMP117_REG_DEVICE_ID		0xF
>  
>  #define TMP117_RESOLUTION_10UC		78125
> -#define TMP117_DEVICE_ID		0x0117
>  #define MICRODEGREE_PER_10MILLIDEGREE	10000
>  
> +#define TMP116_DEVICE_ID		0x1116
> +#define TMP117_DEVICE_ID		0x0117
> +
>  struct tmp117_data {
>  	struct i2c_client *client;
>  	s16 calibbias;
> @@ -105,6 +107,13 @@ static const struct iio_chan_spec tmp117_channels[] = {
>  		.type = IIO_TEMP,
>  		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
>  			BIT(IIO_CHAN_INFO_CALIBBIAS) | BIT(IIO_CHAN_INFO_SCALE),
> +};
> +
> +static const struct iio_chan_spec tmp116_channels[] = {
> +	{
> +		.type = IIO_TEMP,
> +		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> +				      BIT(IIO_CHAN_INFO_SCALE),
>  	},
>  };
>  
> @@ -118,27 +127,28 @@ static int tmp117_identify(struct i2c_client *client)
>  	int dev_id;
>  
>  	dev_id = i2c_smbus_read_word_swapped(client, TMP117_REG_DEVICE_ID);
> -	if (dev_id < 0)

Keep this handling of the smbus read returning an error.
Otherwise, you end up replacing the error code with -ENODEV rather than
returning what actually happened.

	if (dev_id < 0)
		return dev_id;

	switch (dev_id) {
...

> +	switch (dev_id) {
> +	case TMP116_DEVICE_ID:
> +	case TMP117_DEVICE_ID:
>  		return dev_id;
> -	if (dev_id != TMP117_DEVICE_ID) {
> -		dev_err(&client->dev, "TMP117 not found\n");
> +	default:
> +		dev_err(&client->dev, "TMP116/117 not found\n");
>  		return -ENODEV;
>  	}
> -	return 0;
>  }
>  
>  static int tmp117_probe(struct i2c_client *client)
>  {
>  	struct tmp117_data *data;
>  	struct iio_dev *indio_dev;
> -	int ret;
> +	int dev_id;
>  
>  	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
>  		return -EOPNOTSUPP;
>  
> -	ret = tmp117_identify(client);
> -	if (ret < 0)
> -		return ret;
> +	dev_id = tmp117_identify(client);
> +	if (dev_id < 0)
> +		return dev_id;
>  
>  	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>  	if (!indio_dev)
> @@ -148,12 +158,18 @@ static int tmp117_probe(struct i2c_client *client)
>  	data->client = client;
>  	data->calibbias = 0;
>  
> -	indio_dev->name = "tmp117";
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->info = &tmp117_info;
>  
> -	indio_dev->channels = tmp117_channels;
> -	indio_dev->num_channels = ARRAY_SIZE(tmp117_channels);
> +	if (dev_id == TMP117_DEVICE_ID) {

Probably better to assume we may get more parts in future and use a
switch statement here to explicitly match each value.

> +		indio_dev->channels = tmp117_channels;
> +		indio_dev->num_channels = ARRAY_SIZE(tmp117_channels);
> +		indio_dev->name = "tmp117";
> +	} else {
> +		indio_dev->channels = tmp116_channels;
> +		indio_dev->num_channels = ARRAY_SIZE(tmp116_channels);
> +		indio_dev->name = "tmp116";
> +	}
>  
>  	return devm_iio_device_register(&client->dev, indio_dev);
>  }


  reply	other threads:[~2022-12-23 14:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21  9:27 [PATCH v2 0/4] Add TI TMP116 Support Marco Felsch
2022-12-21  9:27 ` [PATCH v2 1/4] dt-bindings: iio: ti,tmp117: fix documentation link Marco Felsch
2022-12-21  9:27 ` [PATCH v2 2/4] dt-bindings: iio: ti,tmp117: add binding for the TMP116 Marco Felsch
2022-12-21  9:46   ` Krzysztof Kozlowski
2022-12-23 15:08   ` Jonathan Cameron
2022-12-23 15:03     ` Marco Felsch
2022-12-23 15:37       ` Jonathan Cameron
2022-12-23 16:10         ` Marco Felsch
2022-12-23 17:14           ` Jonathan Cameron
2022-12-23 17:13             ` Marco Felsch
2022-12-27  8:40               ` Krzysztof Kozlowski
2022-12-30 17:59                 ` Jonathan Cameron
2023-01-16  9:23                   ` Marco Felsch
2022-12-21  9:28 ` [PATCH v2 3/4] iio: temperature: tmp117: add TI TMP116 support Marco Felsch
2022-12-23 15:10   ` Jonathan Cameron [this message]
2022-12-23 15:07     ` Marco Felsch
2022-12-23 15:39       ` Jonathan Cameron
2022-12-23 16:13         ` Marco Felsch
2022-12-23 17:16           ` Jonathan Cameron
2022-12-27  8:30             ` Krzysztof Kozlowski
2022-12-30 17:55               ` Jonathan Cameron
2022-12-21  9:28 ` [PATCH v2 4/4] iio: temperature: tmp117: cosmetic alignment cleanup Marco Felsch

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=20221223151056.4f7d4b7e@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=m.felsch@pengutronix.de \
    --cc=puranjay12@gmail.com \
    --cc=robh+dt@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).